diff --git a/data_test.go b/data_test.go index 50bb16a640..5ab1f117c6 100644 --- a/data_test.go +++ b/data_test.go @@ -510,6 +510,11 @@ func runBuildRemoteCmd(td *datadriven.TestData, d *DB, storage remote.Storage) e } writeOpts := d.opts.MakeWriterOptions(0 /* level */, tableFormat) + if rand.Intn(4) == 0 { + // Force two-level indexes. + writeOpts.BlockSize = 5 + writeOpts.IndexBlockSize = 5 + } f, err := storage.CreateObject(path) if err != nil { diff --git a/sstable/reader_iter.go b/sstable/reader_iter.go index 2b5a267a16..492854ea54 100644 --- a/sstable/reader_iter.go +++ b/sstable/reader_iter.go @@ -280,9 +280,10 @@ func (i *compactionIterator) skipForward( *i.bytesIterated += uint64(curOffset - i.prevOffset) i.prevOffset = curOffset - if i.vState != nil && key != nil { - cmp := i.cmp(key.UserKey, i.vState.upper.UserKey) - if cmp > 0 || (i.vState.upper.IsExclusiveSentinel() && cmp == 0) { + // We have an upper bound when the table is virtual. + if i.upper != nil && key != nil { + cmp := i.cmp(key.UserKey, i.upper) + if cmp > 0 || (!i.endKeyInclusive && cmp == 0) { return nil, base.LazyValue{} } } diff --git a/sstable/reader_iter_two_lvl.go b/sstable/reader_iter_two_lvl.go index f59438ae41..e6292f54a5 100644 --- a/sstable/reader_iter_two_lvl.go +++ b/sstable/reader_iter_two_lvl.go @@ -1113,9 +1113,10 @@ func (i *twoLevelCompactionIterator) skipForward( *i.bytesIterated += uint64(curOffset - i.prevOffset) i.prevOffset = curOffset - if i.vState != nil && key != nil { - cmp := i.cmp(key.UserKey, i.vState.upper.UserKey) - if cmp > 0 || (i.vState.upper.IsExclusiveSentinel() && cmp == 0) { + // We have an upper bound when the table is virtual. + if i.upper != nil && key != nil { + cmp := i.cmp(key.UserKey, i.upper) + if cmp > 0 || (!i.endKeyInclusive && cmp == 0) { return nil, base.LazyValue{} } } diff --git a/testdata/ingest_external b/testdata/ingest_external index a4626b5ea7..d01198bca4 100644 --- a/testdata/ingest_external +++ b/testdata/ingest_external @@ -418,3 +418,65 @@ iter seek-lt de ---- a1: (foo, .) + + +# Test compactions with synthetic prefix. +reset +---- + +build-remote ext +set ax ax +set da da +set db db +set dc dc +set ux ux +---- + +# Replace prefix with one greater than the original one. +ingest-external prefix-replace=(d,e) +ext,10,ea,ed +---- + +# Replace prefix with one smaller than the original one. +ingest-external prefix-replace=(d,b) +ext,10,ba,bd +---- + +# Write some keys so we actually perform a compaction. +batch +set a a +set c c +set f f +---- + +compact a z +---- + +lsm +---- +6: + 000008:[a#0,SET-f#0,SET] + +# Make sure we see both ba..bc and ea..ec. +iter +first +next +next +next +next +next +next +next +next +next +---- +a: (a, .) +ba: (da, .) +bb: (db, .) +bc: (dc, .) +c: (c, .) +ea: (da, .) +eb: (db, .) +ec: (dc, .) +f: (f, .) +.