Repository navigation
Closed
Labels
bugSomething isn't working
Description
What happens
A filter of the form NOT <indexed predicate> OR <range> returns fewer rows with scalar indexes than without them, when the range column has a zone map index. The rows the right side matches only through the zone map are dropped.
Reproduced on main at 5af7354 (14.0.0-beta.5).
Reproduction
3,000 rows: id and seq both 0..3000; colour is null when id % 20 == 0, else c{id % 80}. Bitmap index on colour, zone map index on seq. Each filter is run with use_scalar_index(true) and use_scalar_index(false):
| Filter | With indexes | Without |
|---|---|---|
(NOT (colour = 'c41')) OR (seq >= 34 AND seq < 64) |
2,813 | 2,816 |
NOT (colour = 'c41') OR seq = 40 |
2,813 | 2,814 |
colour <> 'c41' OR seq = 40 |
2,813 | 2,814 |
NOT (colour = 'c41') |
2,813 | 2,813 |
The missing rows are those the left side does not match: ids 40 and 60 (colour null) and id 41 (colour = 'c41'). With a B-tree on seq instead of a zone map, or no index on seq, every count matches the full scan.
let n = 3000i64;
let schema = Arc::new(Schema::new(vec![
Field::new("id", DataType::Int64, false),
Field::new("colour", DataType::Utf8, true),
Field::new("seq", DataType::Int64, true),
]));
let batch = RecordBatch::try_new(
schema.clone(),
vec![
Arc::new(Int64Array::from_iter_values(0..n)),
Arc::new(StringArray::from_iter(
(0..n).map(|id| (id % 20 != 0).then(|| format!("c{}", id % 80))),
)),
Arc::new(Int64Array::from_iter_values(0..n)),
],
)?;
let mut ds = Dataset::write(
RecordBatchIterator::new(vec![Ok(batch)], schema),
"memory://not_or_zonemap",
None,
)
.await?;
ds.create_index(&["colour"], IndexType::Bitmap, None,
&ScalarIndexParams::for_builtin(BuiltinIndexType::Bitmap), false).await?;
ds.create_index(&["seq"], IndexType::ZoneMap, None,
&ScalarIndexParams::for_builtin(BuiltinIndexType::ZoneMap), false).await?;
let filter = "NOT (colour = 'c41') OR seq = 40";
for use_index in [true, false] {
let mut scan = ds.scan();
scan.filter(filter)?;
scan.use_scalar_index(use_index);
println!("{use_index}: {}", scan.try_into_batch().await?.num_rows()); // 2813 vs 2814
}Expected
The same rows with and without scalar indexes.
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
fix(scan): preserve candidates from inexact scalar index results (lan…