github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/internal/keyspan/testdata/bounded_iter (about) 1 define 2 a-b:{(#10,RANGEKEYSET,@5,apples)} 3 d-e:{(#4,RANGEKEYSET,@3,coconut)} 4 g-h:{(#20,RANGEKEYSET,@5,pineapple) (#20,RANGEKEYSET,@3,guava)} 5 ---- 6 7 # Nothing out of bounds. 8 9 iter lower=a upper=z 10 first 11 next 12 next 13 next 14 last 15 prev 16 prev 17 prev 18 ---- 19 a-b:{(#10,RANGEKEYSET,@5,apples)} 20 d-e:{(#4,RANGEKEYSET,@3,coconut)} 21 g-h:{(#20,RANGEKEYSET,@5,pineapple) (#20,RANGEKEYSET,@3,guava)} 22 <nil> 23 g-h:{(#20,RANGEKEYSET,@5,pineapple) (#20,RANGEKEYSET,@3,guava)} 24 d-e:{(#4,RANGEKEYSET,@3,coconut)} 25 a-b:{(#10,RANGEKEYSET,@5,apples)} 26 <nil> 27 28 # Test out of upper bound, but undiscovered until we Next. 29 30 iter lower=a upper=f 31 first 32 next 33 next 34 prev 35 ---- 36 a-b:{(#10,RANGEKEYSET,@5,apples)} 37 d-e:{(#4,RANGEKEYSET,@3,coconut)} 38 <nil> 39 d-e:{(#4,RANGEKEYSET,@3,coconut)} 40 41 # Test out of upper bound, but discovered before we Next. 42 43 iter lower=a upper=dog 44 first 45 next 46 next 47 prev 48 ---- 49 a-b:{(#10,RANGEKEYSET,@5,apples)} 50 d-e:{(#4,RANGEKEYSET,@3,coconut)} 51 <nil> 52 d-e:{(#4,RANGEKEYSET,@3,coconut)} 53 54 # Test out of lower bound, but undiscovered until we Prev. 55 56 iter lower=c upper=z 57 last 58 prev 59 prev 60 next 61 ---- 62 g-h:{(#20,RANGEKEYSET,@5,pineapple) (#20,RANGEKEYSET,@3,guava)} 63 d-e:{(#4,RANGEKEYSET,@3,coconut)} 64 <nil> 65 d-e:{(#4,RANGEKEYSET,@3,coconut)} 66 67 # Test out of lower bound, but discovered before we Prev. 68 69 iter lower=d upper=z 70 last 71 prev 72 prev 73 next 74 ---- 75 g-h:{(#20,RANGEKEYSET,@5,pineapple) (#20,RANGEKEYSET,@3,guava)} 76 d-e:{(#4,RANGEKEYSET,@3,coconut)} 77 <nil> 78 d-e:{(#4,RANGEKEYSET,@3,coconut)} 79 80 # Test a single span ([b-g)) within the bounds, overlapping on both ends. 81 82 define 83 a-b:{(#10,RANGEKEYSET,@5)} 84 b-g:{(#4,RANGEKEYSET,@3)} 85 g-h:{(#20,RANGEKEYSET,@5)} 86 ---- 87 88 iter lower=c upper=f 89 seek-ge b 90 next 91 next 92 seek-ge b 93 prev 94 prev 95 seek-lt f 96 prev 97 prev 98 seek-lt f 99 next 100 next 101 prev 102 prev 103 ---- 104 b-g:{(#4,RANGEKEYSET,@3)} 105 <nil> 106 <nil> 107 b-g:{(#4,RANGEKEYSET,@3)} 108 <nil> 109 <nil> 110 b-g:{(#4,RANGEKEYSET,@3)} 111 <nil> 112 <nil> 113 b-g:{(#4,RANGEKEYSET,@3)} 114 <nil> 115 <nil> 116 b-g:{(#4,RANGEKEYSET,@3)} 117 <nil> 118 119 set-prefix bar 120 ---- 121 set prefix to "bar" 122 123 # Test seeking to a portion of the keyspace that contains no range keys with 124 # start bounds ≥ the seek key such that the range key also overlaps the current 125 # prefix. 126 127 iter lower=a upper=z 128 seek-ge bar 129 prev 130 prev 131 ---- 132 b-g:{(#4,RANGEKEYSET,@3)} 133 <nil> 134 <nil> 135 136 # Test seeking to a portion of the keyspace that contains a range key with a 137 # start bound < the seek key, and the range key also overlaps the current 138 # prefix. 139 140 iter lower=a upper=z 141 seek-lt bar 142 next 143 prev 144 prev 145 ---- 146 b-g:{(#4,RANGEKEYSET,@3)} 147 <nil> 148 b-g:{(#4,RANGEKEYSET,@3)} 149 <nil> 150 151 # Test seeking with bounds narrower than the range of the seek prefix. This is 152 # possible in practice because the bounded iterator iterates over fragments, not 153 # pre-defragmented range keys. 154 155 iter lower=bar@9 upper=bar@3 156 seek-lt bar 157 next 158 prev 159 prev 160 ---- 161 b-g:{(#4,RANGEKEYSET,@3)} 162 <nil> 163 b-g:{(#4,RANGEKEYSET,@3)} 164 <nil> 165 166 # Test a similar scenario but on the start prefix of a key. 167 168 iter lower=b@9 upper=b@3 169 seek-lt b 170 next 171 next 172 prev 173 prev 174 ---- 175 <nil> 176 b-g:{(#4,RANGEKEYSET,@3)} 177 <nil> 178 b-g:{(#4,RANGEKEYSET,@3)} 179 <nil> 180 181 # Test a scenario where the prefix overlaps a span, but the bounds exclude it. 182 183 iter lower=z@9 upper=z@3 184 seek-lt z@3 185 next 186 ---- 187 <nil> 188 <nil> 189 190 # Test many spans matching the prefix, due to fragmentation within a prefix. 191 192 define 193 b-boo:{(#1,RANGEKEYSET,@1)} 194 c@9-c@8:{(#1,RANGEKEYSET,@1)} 195 c@8-c@7:{(#1,RANGEKEYSET,@1)} 196 c@7-c@6:{(#1,RANGEKEYSET,@1)} 197 c@6-c@5:{(#1,RANGEKEYSET,@1)} 198 c@5-c@4:{(#1,RANGEKEYSET,@1)} 199 ---- 200 201 set-prefix c 202 ---- 203 set prefix to "c" 204 205 iter 206 seek-lt c 207 next 208 next 209 next 210 next 211 next 212 next 213 ---- 214 <nil> 215 c@9-c@8:{(#1,RANGEKEYSET,@1)} 216 c@8-c@7:{(#1,RANGEKEYSET,@1)} 217 c@7-c@6:{(#1,RANGEKEYSET,@1)} 218 c@6-c@5:{(#1,RANGEKEYSET,@1)} 219 c@5-c@4:{(#1,RANGEKEYSET,@1)} 220 <nil> 221 222 # Test the same scenario with bounds limiting iteration to a subset of the 223 # keys. 224 225 iter lower=c@7 upper=c@5 226 seek-lt c@7 227 next 228 next 229 next 230 ---- 231 <nil> 232 c@7-c@6:{(#1,RANGEKEYSET,@1)} 233 c@6-c@5:{(#1,RANGEKEYSET,@1)} 234 <nil> 235 236 define 237 a@7-a@5:{(#1,RANGEKEYSET,@1)} 238 b-boo:{(#1,RANGEKEYSET,@1)} 239 c@9-c@8:{(#1,RANGEKEYSET,@1)} 240 ---- 241 242 set-prefix b 243 ---- 244 set prefix to "b" 245 246 iter 247 seek-lt c@8 248 seek-ge a@9 249 ---- 250 <nil> 251 <nil>