# Simple sanity test with single level index.
build table-format=Pebble,v4
a.SET.1:a
b.SET.1:b
c.SET.1:c
d.SET.1:d
----
point:    [a#1,SET-d#1,SET]
seqnums:  [1-1]

# Note that the raw key/value sizes aren't accurate here because we use
# Reader.EstimateDiskUsage with virtual sstables bounds to determine virtual
# sstable size which is then used to extrapolate virtual sstable properties, and
# for tiny sstables, virtual sstable sizes aren't accurate. In this testcase,
# the virtual sstable size is 50, whereas the backing sstable size is 850.
virtualize lower=b.SET.1 upper=c.SET.1 show-props
----
bounds:  [b#1,SET-c#1,SET]
filenum: 000001
props:
  rocksdb.num.entries: 1
  rocksdb.raw.key.size: 3
  rocksdb.raw.value.size: 1
  rocksdb.num.data.blocks: 1
  rocksdb.compression: Snappy
  rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;

# Repeat the above with (Pebble,v5).

build table-format=Pebble,v5
a.SET.1:a
b.SET.1:b
c.SET.1:c
d.SET.1:d
----
point:    [a#1,SET-d#1,SET]
seqnums:  [1-1]

# Note that the raw key/value sizes aren't accurate here because we use
# Reader.EstimateDiskUsage with virtual sstables bounds to determine virtual
# sstable size which is then used to extrapolate virtual sstable properties, and
# for tiny sstables, virtual sstable sizes aren't accurate.
virtualize lower=b.SET.1 upper=c.SET.1 show-props
----
bounds:  [b#1,SET-c#1,SET]
filenum: 000002
props:
  rocksdb.num.entries: 1
  rocksdb.raw.key.size: 4
  rocksdb.raw.value.size: 1
  rocksdb.num.data.blocks: 1
  rocksdb.compression: Snappy
  rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;


# Test 2: Similar to test 1 but force two level iterators.
build block-size=1 index-block-size=1 table-format=Pebble,v4
a.SET.1:a
b.SET.1:b
c.SET.1:c
d.SET.1:d
----
point:    [a#1,SET-d#1,SET]
seqnums:  [1-1]

virtualize lower=b.SET.1 upper=c.SET.1 show-props
----
bounds:  [b#1,SET-c#1,SET]
filenum: 000003
props:
  rocksdb.num.entries: 1
  rocksdb.raw.key.size: 2
  rocksdb.raw.value.size: 1
  rocksdb.num.data.blocks: 1
  rocksdb.compression: Snappy
  rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;

# Test the constrain bounds function. It performs some subtle shrinking and
# expanding of bounds. The current virtual sstable bounds are [b,c].
# 1. start key < virtual sstable start key, end key is exclusive.
constrain a,bb,false
----
b,bb,false

# 2. start key < virtual sstable start key, end key is inclusive.
constrain a,bb,true
----
b,bb,true

# 3. start key is within virtual sstable bounds, end key is at virtual sstable
# end bound, but is exclusive.
constrain bb,c,false
----
bb,c,false

# 3. start key is within virtual sstable bounds, end key is at virtual sstable
# end bound, but is inclusive.
constrain bb,c,true
----
bb,c,true

# 4. start key is within virtual sstable bounds, end key is above virtual
# sstable end bound and is exclusive.
constrain bb,e,false
----
bb,c,true

# 5. start key is within virtual sstable bounds, end key is above virtual
# sstable end bound and is inclusive.
constrain bb,e,true
----
bb,c,true

# 6. Both start, end keys fit within virtual sstable bounds.
constrain bb,bbb,false
----
bb,bbb,false

# 6. Both start, end keys are out of bounds, but overlap.
constrain a,d,false
----
b,c,true

# 7. start, end keys have no overlap with virtual sstable bounds. Note that
# lower becomes greater than upper here. We support this in the iterators
# and don't return any keys for this case.
constrain a,aa,false
----
b,aa,false

# Repeat the above with (Pebble,v5).

build block-size=1 index-block-size=1 table-format=Pebble,v5
a.SET.1:a
b.SET.1:b
c.SET.1:c
d.SET.1:d
----
point:    [a#1,SET-d#1,SET]
seqnums:  [1-1]

virtualize lower=b.SET.1 upper=c.SET.1 show-props
----
bounds:  [b#1,SET-c#1,SET]
filenum: 000004
props:
  rocksdb.num.entries: 1
  rocksdb.raw.key.size: 5
  rocksdb.raw.value.size: 1
  rocksdb.num.data.blocks: 1
  rocksdb.compression: Snappy
  rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;

# Test the constrain bounds function. It performs some subtle shrinking and
# expanding of bounds. The current virtual sstable bounds are [b,c].
# 1. start key < virtual sstable start key, end key is exclusive.
constrain a,bb,false
----
b,bb,false

# 2. start key < virtual sstable start key, end key is inclusive.
constrain a,bb,true
----
b,bb,true

# 3. start key is within virtual sstable bounds, end key is at virtual sstable
# end bound, but is exclusive.
constrain bb,c,false
----
bb,c,false

# 3. start key is within virtual sstable bounds, end key is at virtual sstable
# end bound, but is inclusive.
constrain bb,c,true
----
bb,c,true

# 4. start key is within virtual sstable bounds, end key is above virtual
# sstable end bound and is exclusive.
constrain bb,e,false
----
bb,c,true

# 5. start key is within virtual sstable bounds, end key is above virtual
# sstable end bound and is inclusive.
constrain bb,e,true
----
bb,c,true

# 6. Both start, end keys fit within virtual sstable bounds.
constrain bb,bbb,false
----
bb,bbb,false

# 6. Both start, end keys are out of bounds, but overlap.
constrain a,d,false
----
b,c,true

# 7. start, end keys have no overlap with virtual sstable bounds. Note that
# lower becomes greater than upper here. We support this in the iterators
# and don't return any keys for this case.
constrain a,aa,false
----
b,aa,false

build block-size=1 index-block-size=1 table-format=Pebble,v4
a.SET.1:a
d.SET.2:d
f.SET.3:f
Span: d-e:{(#4,RANGEDEL)}
Span: a-d:{(#11,RANGEKEYSET,@10,foo)}
Span: g-l:{(#5,RANGEDEL)}
Span: y-z:{(#12,RANGEKEYSET,@11,foo)}
----
point:    [a#1,SET-f#3,SET]
rangedel: [d#4,RANGEDEL-l#inf,RANGEDEL]
rangekey: [a#11,RANGEKEYSET-z#inf,RANGEKEYSET]
seqnums:  [1-12]

# Note that we shouldn't have range del spans which cross virtual sstable
# boundaries; num.range-key-sets must be >= 1.
virtualize lower=a.SET.1 upper=f.SET.1 show-props
----
bounds:  [a#1,SET-f#1,SET]
filenum: 000005
props:
  rocksdb.num.entries: 1
  rocksdb.raw.key.size: 4
  rocksdb.raw.value.size: 1
  rocksdb.deleted.keys: 1
  rocksdb.num.range-deletions: 1
  pebble.num.range-key-sets: 1
  rocksdb.num.data.blocks: 1
  rocksdb.compression: Snappy
  rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;

# Repeat the above with (Pebble,v5).

build block-size=1 index-block-size=1 table-format=Pebble,v5
a.SET.1:a
d.SET.2:d
f.SET.3:f
Span: d-e:{(#4,RANGEDEL)}
Span: a-d:{(#11,RANGEKEYSET,@10,foo)}
Span: g-l:{(#5,RANGEDEL)}
Span: y-z:{(#12,RANGEKEYSET,@11,foo)}
----
point:    [a#1,SET-f#3,SET]
rangedel: [d#4,RANGEDEL-l#inf,RANGEDEL]
rangekey: [a#11,RANGEKEYSET-z#inf,RANGEKEYSET]
seqnums:  [1-12]

# Note that we shouldn't have range del spans which cross virtual sstable
# boundaries; num.range-key-sets must be >= 1.
virtualize lower=a.SET.1 upper=f.SET.1 show-props
----
bounds:  [a#1,SET-f#1,SET]
filenum: 000006
props:
  rocksdb.num.entries: 1
  rocksdb.raw.key.size: 5
  rocksdb.raw.value.size: 1
  rocksdb.deleted.keys: 1
  rocksdb.num.range-deletions: 1
  pebble.num.range-key-sets: 1
  rocksdb.num.data.blocks: 1
  rocksdb.compression: Snappy
  rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;

build table-format=Pebble,v4
a.SET.1:a
b.SET.2:b
c.SET.3:c
d.SET.4:d
dd.SET.5:dd
ddd.SET.6:ddd
g.SET.8:g
h.SET.9:h
----
point:    [a#1,SET-h#9,SET]
seqnums:  [1-9]

virtualize lower=dd.SET.5 upper=ddd.SET.6 show-props
----
bounds:  [dd#5,SET-ddd#6,SET]
filenum: 000007
props:
  rocksdb.num.entries: 2
  rocksdb.raw.key.size: 10
  rocksdb.raw.value.size: 2
  rocksdb.num.data.blocks: 1
  rocksdb.compression: Snappy
  rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;

# Repeat the above with (Pebble,v5).

build table-format=Pebble,v5
a.SET.1:a
b.SET.2:b
c.SET.3:c
d.SET.4:d
dd.SET.5:dd
ddd.SET.6:ddd
g.SET.8:g
h.SET.9:h
----
point:    [a#1,SET-h#9,SET]
seqnums:  [1-9]

virtualize lower=dd.SET.5 upper=ddd.SET.6 show-props
----
bounds:  [dd#5,SET-ddd#6,SET]
filenum: 000008
props:
  rocksdb.num.entries: 1
  rocksdb.raw.key.size: 9
  rocksdb.raw.value.size: 2
  rocksdb.num.data.blocks: 1
  rocksdb.compression: Snappy
  rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;

build
a.DEL.1:
b.DELSIZED.1:
Span: c-d:{(#1,RANGEDEL)}
----
point:    [a#1,DEL-b#1,DELSIZED]
rangedel: [c#1,RANGEDEL-d#inf,RANGEDEL]
seqnums:  [1-1]

# Verify that we get 3 deletions instead of 1 (because it has to be the sum of
# its components).
virtualize lower=a.DEL.1 upper=a0.SET.1 show-props
----
bounds:  [a#1,DEL-a0#1,SET]
filenum: 000009
props:
  rocksdb.num.entries: 1
  rocksdb.raw.key.size: 2
  pebble.raw.point-tombstone.key.size: 1
  pebble.num.deletions.sized: 1
  rocksdb.deleted.keys: 3
  rocksdb.num.range-deletions: 1
  rocksdb.num.data.blocks: 1
  rocksdb.compression: Snappy
  rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;
