Repository navigation
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
There was a problem hiding this comment.
The dependency pins and object_store patch match Lance beta.16, and the fixture changes preserve query-result coverage. For stable-row-ID tables, follow standalone compaction with index optimization, or use OptimizeAction::All, to restore B-tree acceleration.
Validation: 1,525 core Rust tests passed (one existing ignored test), 37 Java tests passed, and the two B-tree maintenance experiments preserved results and verified recovery.
Lance changes the B-tree training schema exposed to custom index plugins. Please mark this PR with the breaking-change label.
| lance-datafusion = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-encoding = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-arrow = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance = { "version" = "=14.0.0-beta.16", default-features = false, "tag" = "v14.0.0-beta.16", "git" = "https://github.com/lance-format/lance.git" } |
There was a problem hiding this comment.
Standalone compaction now removes coverage from newly built B-tree indexes on stable-row-ID tables. Queries remain correct, but affected fragments use a full scan until index optimization. This follows the upstream switch to row addresses: default compaction neither preserves those addresses nor records their moves.
The experiment below uses ScalarIndexQuery before compaction and after index optimization. Immediately after compaction, the stable-ID case uses LanceRead with a full filter; the physical-ID case retains index use. All result assertions pass. Running OptimizeAction::Index after compaction restores acceleration; OptimizeAction::All already includes that step. This is a recoverable performance risk and does not require a fix before merge.
Executed reproduction on 517cb15
Save as rust/lancedb/tests/gate_pr4539.rs and run:
cargo test --locked --quiet --profile ci -p lancedb --features remote --test gate_pr4539// Disposable review experiment for PR #4539; not part of the proposed change.
use std::sync::Arc;
use arrow_array::{Int32Array, RecordBatch, RecordBatchIterator};
use arrow_schema::{DataType, Field, Schema};
use futures::TryStreamExt;
use lance::{Dataset, dataset::WriteParams, index::DatasetIndexExt};
use lance_index::{
IndexType,
scalar::{BuiltinIndexType, ScalarIndexParams},
};
use lancedb::{
connect,
query::{ExecutableQuery, QueryBase, Select},
table::OptimizeAction,
};
#[rstest::rstest]
#[case(false)]
#[case(true)]
#[tokio::test]
async fn btree_multi_fragment_lancedb_results_survive_maintenance(#[case] stable: bool) {
let dir = tempfile::tempdir().unwrap();
let schema = Arc::new(Schema::new(vec![Field::new("id", DataType::Int32, false)]));
let batch = RecordBatch::try_new(
schema.clone(),
vec![Arc::new(Int32Array::from(vec![0, 1, 2, 3]))],
)
.unwrap();
let uri = dir.path().join("t.lance").to_str().unwrap().to_string();
let mut dataset = Dataset::write(
RecordBatchIterator::new(vec![Ok(batch)], schema.clone()),
&uri,
Some(WriteParams {
max_rows_per_file: 2,
enable_stable_row_ids: stable,
..Default::default()
}),
)
.await
.unwrap();
assert_eq!(dataset.get_fragments().len(), 2);
let params = ScalarIndexParams::for_builtin(BuiltinIndexType::BTree);
dataset
.create_index_builder(&["id"], IndexType::BTree, ¶ms)
.name("id_idx".into())
.await
.unwrap();
let indices = dataset.load_indices().await.unwrap();
assert_eq!(indices[0].index_version, if stable { 1 } else { 0 });
drop(dataset);
let conn = connect(dir.path().to_str().unwrap())
.execute()
.await
.unwrap();
let table = conn.open_table("t").execute().await.unwrap();
async fn ids(table: &lancedb::Table, require_index: bool) -> Vec<i32> {
let plan = table
.query()
.only_if("id >= 2")
.explain_plan(false)
.await
.unwrap();
assert_eq!(plan.contains("ScalarIndexQuery"), require_index, "{plan}");
let batches: Vec<RecordBatch> = table
.query()
.only_if("id >= 2")
.select(Select::Columns(vec!["id".into()]))
.execute()
.await
.unwrap()
.try_collect()
.await
.unwrap();
let mut ids: Vec<i32> = batches
.iter()
.flat_map(|batch| {
batch
.column(0)
.as_any()
.downcast_ref::<Int32Array>()
.unwrap()
.values()
.iter()
.copied()
})
.collect();
ids.sort_unstable();
ids
}
assert_eq!(ids(&table, true).await, vec![2, 3]);
let batch = RecordBatch::try_new(schema, vec![Arc::new(Int32Array::from(vec![4, 5]))]).unwrap();
table.add(batch).execute().await.unwrap();
table
.optimize(OptimizeAction::Index(Default::default()))
.await
.unwrap();
assert_eq!(ids(&table, true).await, vec![2, 3, 4, 5]);
table.delete("id = 2").await.unwrap();
table
.optimize(OptimizeAction::Compact {
options: Default::default(),
remap_options: None,
})
.await
.unwrap();
assert_eq!(ids(&table, !stable).await, vec![3, 4, 5]);
table
.optimize(OptimizeAction::Index(Default::default()))
.await
.unwrap();
assert_eq!(ids(&table, true).await, vec![3, 4, 5]);
}Both cases passed. The stable-ID case explicitly checks that the plan lacks ScalarIndexQuery after standalone compaction, then verifies that index optimization restores it without changing the returned rows.
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
Hold this dependency bump until a corrected Lance revision preserves indexed-query results across staged index publication and replacement-column maintenance. The new probes independently reproduce silent row omissions in beta.16, so the passing core and Java suites no longer establish that this revision is safe to adopt.
Keep the existing dependency pin until those upstream corrections are available, then update the pins together and verify indexed queries against flat scans for both cases.
The standalone-compaction performance risk remains non-blocking: follow compaction with index optimization, or use OptimizeAction::All, to restore B-tree acceleration.
| lance-datafusion = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-encoding = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-arrow = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance = { "version" = "=14.0.0-beta.16", default-features = false, "tag" = "v14.0.0-beta.16", "git" = "https://github.com/lance-format/lance.git" } |
There was a problem hiding this comment.
Staged B-tree publication can combine legacy row-ID segments with beta.16 row-address segments on stable-row-ID tables and silently lose query results. The upstream domain migration adds version 1, but commit_existing_index_segments accepts version 0 and version 1 under the same logical name. LogicalScalarIndex checks only the index type, then interprets every segment using the first segment's result domain.
This is reachable when upgrading a table with legacy segments and publishing a newly built segment. The reproduced id = 7 query returns 0 rows through the index versus 1 through a flat scan, without an error; the all-version-1 control returns 1. Reject incompatible domains at staged publication, or rebuild the whole logical index into one domain before committing. Please use an upstream revision containing that correction before landing the bump.
Executed regression probe on 517cb15
Save as rust/lancedb/tests/gate_pr4539_btree_domains.rs and run:
cargo test --locked --quiet --profile ci -p lancedb --features remote --test gate_pr4539_btree_domains -- --nocaptureThe first segment covers fragment 0, where the stable IDs and row addresses are both 0..5. Its encoded postings are therefore valid legacy postings; selecting version 0 models a beta.15 segment without changing those bytes. Its indexed queries pass before the new segment is committed.
// Disposable review probes; not part of PR #4539.
use std::sync::Arc;
use arrow_array::{Int32Array, RecordBatch, RecordBatchIterator};
use arrow_schema::{DataType, Field, Schema};
use lance::{Dataset, dataset::WriteParams, index::DatasetIndexExt};
use lance_index::{
IndexType,
scalar::{BuiltinIndexType, ScalarIndexParams},
};
fn batch(columns: &[&str], value: i32) -> RecordBatch {
let schema = Arc::new(Schema::new(
columns
.iter()
.map(|name| Field::new(*name, DataType::Int32, false))
.collect::<Vec<_>>(),
));
let arrays = columns
.iter()
.map(|name| {
Arc::new(Int32Array::from(if *name == "id" {
(0..10).collect::<Vec<_>>()
} else {
vec![value; 10]
})) as arrow_array::ArrayRef
})
.collect();
RecordBatch::try_new(schema, arrays).unwrap()
}
async fn count(dataset: &Dataset, filter: &str, indexed: bool) -> u64 {
dataset
.scan()
.filter(filter)
.unwrap()
.use_scalar_index(indexed)
.count_rows()
.await
.unwrap()
}
#[rstest::rstest]
#[case(false)]
#[case(true)]
#[tokio::test]
async fn staged_btree_domains(#[case] legacy_first: bool) {
let dir = tempfile::tempdir().unwrap();
let input = batch(&["id"], 0);
let mut dataset = Dataset::write(
RecordBatchIterator::new([Ok(input.clone())], input.schema()),
dir.path().to_str().unwrap(),
Some(WriteParams {
max_rows_per_file: 5,
enable_stable_row_ids: true,
..Default::default()
}),
)
.await
.unwrap();
let fragments = dataset.get_fragments();
assert_eq!(fragments.len(), 2);
let params = ScalarIndexParams::for_builtin(BuiltinIndexType::BTree);
let mut first = dataset
.create_index_builder(&["id"], IndexType::BTree, ¶ms)
.fragments(vec![fragments[0].id() as u32])
.execute_uncommitted()
.await
.unwrap();
// On fragment 0, stable IDs 0..5 equal addresses 0..5. The B-tree payload
// is identical in both domains, so version 0 faithfully represents a
// beta.15 segment without changing any encoded postings.
if legacy_first {
first.index_version = 0;
}
let second = dataset
.create_index_builder(&["id"], IndexType::BTree, ¶ms)
.fragments(vec![fragments[1].id() as u32])
.execute_uncommitted()
.await
.unwrap();
eprintln!(
"legacy_first={legacy_first}; segment versions={},{}",
first.index_version, second.index_version
);
dataset
.commit_existing_index_segments("id_idx", "id", vec![first])
.await
.unwrap();
assert_eq!(count(&dataset, "id = 1", true).await, 1);
assert_eq!(count(&dataset, "id = 7", true).await, 1);
dataset
.commit_existing_index_segments("id_idx", "id", vec![second])
.await
.unwrap();
let indexed = count(&dataset, "id = 7", true).await;
let flat = count(&dataset, "id = 7", false).await;
eprintln!("legacy_first={legacy_first}; indexed={indexed}, flat={flat}");
assert_eq!(indexed, flat);
}Observed: the all-new control passes (indexed=1, flat=1); the mixed-domain case fails the final equality assertion (indexed=0, flat=1).
| lance-datafusion = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-encoding = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-arrow = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance = { "version" = "=14.0.0-beta.16", default-features = false, "tag" = "v14.0.0-beta.16", "git" = "https://github.com/lance-format/lance.git" } |
There was a problem hiding this comment.
ZoneMap maintenance can consume stale seeds after replacement-column writes and silently prune current rows. The new seed-writing paths put seeds in replacement files, while try_harvest_seeds still reads fragment.files.first() without checking whether that file currently serves the indexed field. A later partial replacement can leave that first file serving another column, with the old indexed column tombstoned but its obsolete seed still in the footer.
With an unaffected fragment retaining the index, rewrite id,val to val=100, then replace only val with 200 and optimize the index. The indexed val = 200 query returns 0 rows versus 10 through a flat scan; disabling seeds returns 10 through both paths. The stored values are correct, but the rebuilt coverage uses the old bounds. Harvest seeds from the file currently serving the indexed field, or fall back to scanning when provenance cannot be proved. Please wait for that upstream correction before adopting this revision.
Executed regression probe on 517cb15
Save as rust/lancedb/tests/gate_pr4539_zonemap_seeds.rs and run:
cargo test --locked --quiet --profile ci -p lancedb --features remote --test gate_pr4539_zonemap_seeds -- --nocapture// Disposable review probes; not part of PR #4539.
use std::sync::Arc;
use arrow_array::{Int32Array, RecordBatch, RecordBatchIterator};
use arrow_schema::{DataType, Field, Schema};
use futures::stream;
use lance::{
Dataset,
dataset::{WriteDestination, WriteParams, transaction::Operation},
index::DatasetIndexExt,
};
use lance_core::datatypes::Schema as LanceSchema;
use lance_index::{
IndexType,
scalar::{BuiltinIndexType, ScalarIndexParams},
};
fn batch(columns: &[&str], value: i32) -> RecordBatch {
let schema = Arc::new(Schema::new(
columns
.iter()
.map(|name| Field::new(*name, DataType::Int32, false))
.collect::<Vec<_>>(),
));
let arrays = columns
.iter()
.map(|name| {
Arc::new(Int32Array::from(if *name == "id" {
(0..10).collect::<Vec<_>>()
} else {
vec![value; 10]
})) as arrow_array::ArrayRef
})
.collect();
RecordBatch::try_new(schema, arrays).unwrap()
}
async fn count(dataset: &Dataset, filter: &str, indexed: bool) -> u64 {
dataset
.scan()
.filter(filter)
.unwrap()
.use_scalar_index(indexed)
.count_rows()
.await
.unwrap()
}
async fn replace(dataset: Dataset, columns: &[&str], value: i32) -> Dataset {
let column_schema = LanceSchema {
fields: columns
.iter()
.map(|name| dataset.schema().field(name).unwrap().clone())
.collect(),
metadata: Default::default(),
};
let mut replacements = Vec::new();
for fragment in dataset.get_fragments() {
if fragment.id() == 0 {
continue;
}
replacements.push(
fragment
.write_columns(stream::iter([Ok(batch(columns, value))]), &column_schema)
.await
.unwrap(),
);
}
let version = dataset.version().version;
let session = dataset.session();
Dataset::commit(
WriteDestination::Dataset(Arc::new(dataset)),
Operation::DataReplacement { replacements },
Some(version),
None,
None,
session,
false,
)
.await
.unwrap()
}
#[rstest::rstest]
#[case(false)]
#[case(true)]
#[tokio::test]
async fn zone_map_replacements(#[case] use_seeds: bool) {
let dir = tempfile::tempdir().unwrap();
let input = batch(&["id", "val"], 0);
let mut dataset = Dataset::write(
RecordBatchIterator::new([Ok(input.clone()), Ok(input.clone())], input.schema()),
dir.path().to_str().unwrap(),
Some(WriteParams {
max_rows_per_file: 10,
..Default::default()
}),
)
.await
.unwrap();
let params = ScalarIndexParams::for_builtin(BuiltinIndexType::ZoneMap)
.with_params(&serde_json::json!({"rows_per_zone": 4, "use_seeds": use_seeds}));
dataset
.create_index_builder(&["val"], IndexType::ZoneMap, ¶ms)
.name("val_idx".into())
.await
.unwrap();
dataset = replace(dataset, &["id", "val"], 100).await;
dataset = replace(dataset, &["val"], 200).await;
eprintln!(
"use_seeds={use_seeds}; files={:?}",
dataset.fragments()[1].files
);
assert_eq!(count(&dataset, "val = 200", false).await, 10);
dataset.optimize_indices(&Default::default()).await.unwrap();
assert!(!dataset.load_indices().await.unwrap().is_empty());
eprintln!(
"{}",
dataset
.scan()
.filter("val = 200")
.unwrap()
.explain_plan(false)
.await
.unwrap()
);
let indexed = count(&dataset, "val = 200", true).await;
let flat = count(&dataset, "val = 200", false).await;
eprintln!("use_seeds={use_seeds}; indexed={indexed}, flat={flat}");
assert_eq!(indexed, flat);
}Both plans contain ScalarIndexQuery. Observed: the no-seed control passes (indexed=10, flat=10); the seeded case fails the final equality assertion (indexed=0, flat=10). Compared with beta.15, write_columns now collects and flushes seeds into the first replacement file, making this previously unseeded replacement sequence reach the stale-seed reader.
There was a problem hiding this comment.
Fixed in f24c16c5: the beta.17 pin includes the serving-file and field-identity seed selection from Lance #10003. I reran the two-fragment replacement probe on this head: after replacing id,val, replacing only val, and optimizing, the seeded indexed query and flat scan both return 10 rows. The no-seed control also passes.
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
Two independent index regressions still silently omit rows. Land the matching upstream corrections in Lance #10004 and Lance #10003 first; both remain unmerged and absent from beta.16. Then adopt a Lance revision containing both, update the dependency pins together, and verify the two indexed-query reproductions against flat scans.
The newly reproduced ANN _rowoffset planning panic is a non-blocking query limitation. Avoid that projection, or disable scoring autoprojection and omit _distance when scores are unnecessary; that control returned rows successfully. The statistics correction in Lance #8566 addresses this mechanism; its wider draft planner changes need not become part of this dependency bump.
The standalone-compaction performance risk also remains non-blocking: follow compaction with index optimization, or use OptimizeAction::All, to restore B-tree acceleration.
| lance-datafusion = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-encoding = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-arrow = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance = { "version" = "=14.0.0-beta.16", default-features = false, "tag" = "v14.0.0-beta.16", "git" = "https://github.com/lance-format/lance.git" } |
There was a problem hiding this comment.
ANN queries selecting _rowoffset can panic during planning with beta.16. The new ordering wrapper makes EnforceDistribution request statistics from the final projection. AddRowOffsetExec appends _rowoffset to its schema but forwards the shorter input statistics unchanged, so DataFusion's projection indexes past the statistics vector. The statistics implementation predates this bump, but the new wrapper expands its exposure.
The narrow statistics correction in Lance #8566 adds the missing entry. Until then, avoiding _rowoffset, or disabling scoring autoprojection and omitting _distance when scores are unnecessary, avoids the demonstrated trigger. This is a visible query failure without write side effects, so I am treating it as a non-blocking adoption limitation.
Reproducer
Add this as rust/lancedb/tests/gate_rowoffset_probe.rs and run:
cargo test --locked --quiet --profile ci -p lancedb --features remote --test gate_rowoffset_probeExpected: each query returns three rows. On this head, ann_rowoffset panics at DataFusion projection.rs:664 with index out of bounds: the len is 3 but the index is 3; the other two tests pass, including the query that retains _rowoffset but omits the scoring projection.
use std::sync::Arc;
use arrow_array::{FixedSizeListArray, Float32Array, RecordBatch, RecordBatchIterator};
use arrow_schema::{DataType, Field, Schema};
use lance::{
Dataset,
index::{DatasetIndexExt, vector::VectorIndexParams},
};
use lance_index::IndexType;
use lance_linalg::distance::MetricType;
async fn run(offset: bool, scoring: bool) -> anyhow::Result<()> {
let dir = tempfile::tempdir()?;
let vectors = FixedSizeListArray::try_new(
Arc::new(Field::new("item", DataType::Float32, true)),
2,
Arc::new(Float32Array::from_iter_values(
(0..32).flat_map(|x| [x as f32, 0.0]),
)),
None,
)?;
let schema = Arc::new(Schema::new(vec![Field::new(
"vector",
vectors.data_type().clone(),
false,
)]));
let batch = RecordBatch::try_new(schema.clone(), vec![Arc::new(vectors)])?;
let mut ds = Dataset::write(
RecordBatchIterator::new(vec![Ok(batch)], schema),
dir.path().to_str().unwrap(),
None,
)
.await?;
ds.create_index(
&["vector"],
IndexType::Vector,
Some("vector_idx".into()),
&VectorIndexParams::ivf_flat(1, MetricType::L2),
true,
)
.await?;
let query = Float32Array::from(vec![7.0, 0.0]);
let mut scanner = ds.scan();
scanner.nearest("vector", &query, 3)?.target_parallelism(1);
if !scoring {
scanner.disable_scoring_autoprojection();
}
if offset {
scanner.project(&["_rowoffset"])?;
}
let result = scanner.try_into_batch().await?;
assert_eq!(result.num_rows(), 3);
Ok(())
}
use arrow_array::Array;
#[tokio::test]
async fn ann_control() -> anyhow::Result<()> {
run(false, true).await
}
#[tokio::test]
async fn ann_rowoffset() -> anyhow::Result<()> {
run(true, true).await
}
#[tokio::test]
async fn ann_rowoffset_without_scoring_projection() -> anyhow::Result<()> {
run(true, false).await
}There was a problem hiding this comment.
❌ Gate recommendation: request changes.
Beta.17 fixes the ZoneMap seed-selection blocker; the replacement-column probe now agrees with its flat scan. The staged B-tree row-domain mismatch still silently omits rows. Wait for Lance #10004 to land, then adopt a Lance revision containing that guard and verify mixed-domain publication is rejected while indexed queries preserve the flat-scan results.
Two non-blocking limitations remain. ANN queries projecting _rowoffset can panic; avoid that projection, or disable scoring autoprojection and omit _distance when scores are unnecessary. The narrow statistics correction in Lance #8566 addresses that mechanism. Standalone compaction can temporarily remove B-tree acceleration; follow it with index optimization, or use OptimizeAction::All.
| lance-datafusion = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-encoding = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-arrow = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance = { "version" = "=14.0.0-beta.17", default-features = false, "tag" = "v14.0.0-beta.17", "git" = "https://github.com/lance-format/lance.git" } |
There was a problem hiding this comment.
Staged B-tree publication can combine legacy row-ID segments with beta.17 row-address segments on stable-row-ID tables and silently lose query results. The upstream domain migration adds version 1, but commit_existing_index_segments accepts version 0 and version 1 under the same logical name. LogicalScalarIndex checks only the index type, then interprets every segment using the first segment's result domain.
This is reachable when upgrading a table with legacy segments and publishing a newly built segment. The reproduced id = 7 query returns 0 rows through the index versus 1 through a flat scan, without an error; the all-version-1 control returns 1. Reject incompatible domains at staged publication, or rebuild the whole logical index into one domain before committing. The matching correction in Lance #10004 is still open and absent from beta.17; land it upstream, then adopt a revision containing it before this bump. This continues the earlier finding.
Executed regression probe on f24c16c
Save as rust/lancedb/tests/gate_pr4539_btree_domains.rs and run:
cargo test --locked --quiet --profile ci -p lancedb --features remote --test gate_pr4539_btree_domains -- --nocaptureThe first segment covers fragment 0, where the stable IDs and row addresses are both 0..5. Its encoded postings are therefore valid legacy postings; selecting version 0 models a beta.15 segment without changing those bytes. Its indexed queries pass before the new segment is committed.
// Disposable review probes; not part of PR #4539.
use std::sync::Arc;
use arrow_array::{Int32Array, RecordBatch, RecordBatchIterator};
use arrow_schema::{DataType, Field, Schema};
use lance::{Dataset, dataset::WriteParams, index::DatasetIndexExt};
use lance_index::{
IndexType,
scalar::{BuiltinIndexType, ScalarIndexParams},
};
fn batch(columns: &[&str], value: i32) -> RecordBatch {
let schema = Arc::new(Schema::new(
columns
.iter()
.map(|name| Field::new(*name, DataType::Int32, false))
.collect::<Vec<_>>(),
));
let arrays = columns
.iter()
.map(|name| {
Arc::new(Int32Array::from(if *name == "id" {
(0..10).collect::<Vec<_>>()
} else {
vec![value; 10]
})) as arrow_array::ArrayRef
})
.collect();
RecordBatch::try_new(schema, arrays).unwrap()
}
async fn count(dataset: &Dataset, filter: &str, indexed: bool) -> u64 {
dataset
.scan()
.filter(filter)
.unwrap()
.use_scalar_index(indexed)
.count_rows()
.await
.unwrap()
}
#[rstest::rstest]
#[case(false)]
#[case(true)]
#[tokio::test]
async fn staged_btree_domains(#[case] legacy_first: bool) {
let dir = tempfile::tempdir().unwrap();
let input = batch(&["id"], 0);
let mut dataset = Dataset::write(
RecordBatchIterator::new([Ok(input.clone())], input.schema()),
dir.path().to_str().unwrap(),
Some(WriteParams {
max_rows_per_file: 5,
enable_stable_row_ids: true,
..Default::default()
}),
)
.await
.unwrap();
let fragments = dataset.get_fragments();
assert_eq!(fragments.len(), 2);
let params = ScalarIndexParams::for_builtin(BuiltinIndexType::BTree);
let mut first = dataset
.create_index_builder(&["id"], IndexType::BTree, ¶ms)
.fragments(vec![fragments[0].id() as u32])
.execute_uncommitted()
.await
.unwrap();
// On fragment 0, stable IDs 0..5 equal addresses 0..5. The B-tree payload
// is identical in both domains, so version 0 faithfully represents a
// beta.15 segment without changing any encoded postings.
if legacy_first {
first.index_version = 0;
}
let second = dataset
.create_index_builder(&["id"], IndexType::BTree, ¶ms)
.fragments(vec![fragments[1].id() as u32])
.execute_uncommitted()
.await
.unwrap();
eprintln!(
"legacy_first={legacy_first}; segment versions={},{}",
first.index_version, second.index_version
);
dataset
.commit_existing_index_segments("id_idx", "id", vec![first])
.await
.unwrap();
assert_eq!(count(&dataset, "id = 1", true).await, 1);
assert_eq!(count(&dataset, "id = 7", true).await, 1);
dataset
.commit_existing_index_segments("id_idx", "id", vec![second])
.await
.unwrap();
let indexed = count(&dataset, "id = 7", true).await;
let flat = count(&dataset, "id = 7", false).await;
eprintln!("legacy_first={legacy_first}; indexed={indexed}, flat={flat}");
assert_eq!(indexed, flat);
}Observed: the all-new control passes (indexed=1, flat=1); the mixed-domain case fails the final equality assertion (indexed=0, flat=1).
There was a problem hiding this comment.
lance-format/lance#10004 merged, will consider create lance v14.0.0-beta.18 soon
There was a problem hiding this comment.
Confirmed: Lance #10004 has merged. This head still pins beta.17, which lacks the mixed-domain guard, so the finding remains. Adopt a release or revision containing the fix, then verify mixed-domain publication is rejected and indexed queries agree with flat scans.
| lance-datafusion = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-encoding = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-arrow = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance = { "version" = "=14.0.0-beta.17", default-features = false, "tag" = "v14.0.0-beta.17", "git" = "https://github.com/lance-format/lance.git" } |
There was a problem hiding this comment.
Standalone compaction still removes coverage from newly built B-tree indexes on stable-row-ID tables. Queries remain correct, but affected fragments use a full scan until index optimization. This follows the upstream switch to row addresses: default compaction neither preserves those addresses nor records their moves.
The experiment below uses ScalarIndexQuery before compaction and after index optimization. Immediately after compaction, the stable-ID case uses LanceRead with a full filter; the physical-ID case retains index use. All result assertions pass. Running OptimizeAction::Index after compaction restores acceleration; OptimizeAction::All already includes that step. This is a recoverable performance risk and does not require a fix before merge.
The earlier experiment also passes on beta.17 with the same scan fallback and recovery.
Executed reproduction on 517cb15
Save as rust/lancedb/tests/gate_pr4539.rs and run:
cargo test --locked --quiet --profile ci -p lancedb --features remote --test gate_pr4539// Disposable review experiment for PR #4539; not part of the proposed change.
use std::sync::Arc;
use arrow_array::{Int32Array, RecordBatch, RecordBatchIterator};
use arrow_schema::{DataType, Field, Schema};
use futures::TryStreamExt;
use lance::{Dataset, dataset::WriteParams, index::DatasetIndexExt};
use lance_index::{
IndexType,
scalar::{BuiltinIndexType, ScalarIndexParams},
};
use lancedb::{
connect,
query::{ExecutableQuery, QueryBase, Select},
table::OptimizeAction,
};
#[rstest::rstest]
#[case(false)]
#[case(true)]
#[tokio::test]
async fn btree_multi_fragment_lancedb_results_survive_maintenance(#[case] stable: bool) {
let dir = tempfile::tempdir().unwrap();
let schema = Arc::new(Schema::new(vec![Field::new("id", DataType::Int32, false)]));
let batch = RecordBatch::try_new(
schema.clone(),
vec![Arc::new(Int32Array::from(vec![0, 1, 2, 3]))],
)
.unwrap();
let uri = dir.path().join("t.lance").to_str().unwrap().to_string();
let mut dataset = Dataset::write(
RecordBatchIterator::new(vec![Ok(batch)], schema.clone()),
&uri,
Some(WriteParams {
max_rows_per_file: 2,
enable_stable_row_ids: stable,
..Default::default()
}),
)
.await
.unwrap();
assert_eq!(dataset.get_fragments().len(), 2);
let params = ScalarIndexParams::for_builtin(BuiltinIndexType::BTree);
dataset
.create_index_builder(&["id"], IndexType::BTree, ¶ms)
.name("id_idx".into())
.await
.unwrap();
let indices = dataset.load_indices().await.unwrap();
assert_eq!(indices[0].index_version, if stable { 1 } else { 0 });
drop(dataset);
let conn = connect(dir.path().to_str().unwrap())
.execute()
.await
.unwrap();
let table = conn.open_table("t").execute().await.unwrap();
async fn ids(table: &lancedb::Table, require_index: bool) -> Vec<i32> {
let plan = table
.query()
.only_if("id >= 2")
.explain_plan(false)
.await
.unwrap();
assert_eq!(plan.contains("ScalarIndexQuery"), require_index, "{plan}");
let batches: Vec<RecordBatch> = table
.query()
.only_if("id >= 2")
.select(Select::Columns(vec!["id".into()]))
.execute()
.await
.unwrap()
.try_collect()
.await
.unwrap();
let mut ids: Vec<i32> = batches
.iter()
.flat_map(|batch| {
batch
.column(0)
.as_any()
.downcast_ref::<Int32Array>()
.unwrap()
.values()
.iter()
.copied()
})
.collect();
ids.sort_unstable();
ids
}
assert_eq!(ids(&table, true).await, vec![2, 3]);
let batch = RecordBatch::try_new(schema, vec![Arc::new(Int32Array::from(vec![4, 5]))]).unwrap();
table.add(batch).execute().await.unwrap();
table
.optimize(OptimizeAction::Index(Default::default()))
.await
.unwrap();
assert_eq!(ids(&table, true).await, vec![2, 3, 4, 5]);
table.delete("id = 2").await.unwrap();
table
.optimize(OptimizeAction::Compact {
options: Default::default(),
remap_options: None,
})
.await
.unwrap();
assert_eq!(ids(&table, !stable).await, vec![3, 4, 5]);
table
.optimize(OptimizeAction::Index(Default::default()))
.await
.unwrap();
assert_eq!(ids(&table, true).await, vec![3, 4, 5]);
}Both cases passed. The stable-ID case explicitly checks that the plan lacks ScalarIndexQuery after standalone compaction, then verifies that index optimization restores it without changing the returned rows.
There was a problem hiding this comment.
@westonpace could you confirm whether the loss of B-tree acceleration after standalone compaction on stable-row-ID tables should block this LanceDB dependency upgrade?
The reproduction above reports correct results, with full-scan fallback until index optimization; OptimizeAction::All restores acceleration. Is that an acceptable maintenance requirement for this release, or should we wait for an upstream fix that preserves acceleration across standalone compaction?
Since lance-format/lance#10004 has merged and we are considering a new Lance beta, do we need to include a fix for this performance regression in that release before updating LanceDB's Lance pins? If so, which upstream PR should we track?
There was a problem hiding this comment.
This remains a non-blocking performance risk. The tested queries preserve correct results, and running OptimizeAction::Index after standalone compaction, or using OptimizeAction::All, restores B-tree acceleration. An upstream change that preserves acceleration across standalone compaction is not a prerequisite for this dependency bump.
| lance-datafusion = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-encoding = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance-arrow = { "version" = "=14.0.0-beta.15", "tag" = "v14.0.0-beta.15", "git" = "https://github.com/lance-format/lance.git" } | ||
| lance = { "version" = "=14.0.0-beta.17", default-features = false, "tag" = "v14.0.0-beta.17", "git" = "https://github.com/lance-format/lance.git" } |
There was a problem hiding this comment.
ANN queries selecting _rowoffset can panic during planning with beta.17. The new ordering wrapper makes EnforceDistribution request statistics from the final projection. AddRowOffsetExec appends _rowoffset to its schema but forwards the shorter input statistics unchanged, so DataFusion's projection indexes past the statistics vector. The statistics implementation predates this bump, but the new wrapper expands its exposure.
The narrow statistics correction in Lance #8566 adds the missing entry. Until then, avoiding _rowoffset, or disabling scoring autoprojection and omitting _distance when scores are unnecessary, avoids the demonstrated trigger. This is a visible query failure without write side effects, so I am treating it as a non-blocking adoption limitation.
The earlier finding remains reproducible on this head: the affected query panics and both controls pass.
Reproducer
Add this as rust/lancedb/tests/gate_rowoffset_probe.rs and run:
cargo test --locked --quiet --profile ci -p lancedb --features remote --test gate_rowoffset_probeExpected: each query returns three rows. On this head, ann_rowoffset panics at DataFusion projection.rs:664 with index out of bounds: the len is 3 but the index is 3; the other two tests pass, including the query that retains _rowoffset but omits the scoring projection.
use std::sync::Arc;
use arrow_array::{FixedSizeListArray, Float32Array, RecordBatch, RecordBatchIterator};
use arrow_schema::{DataType, Field, Schema};
use lance::{
Dataset,
index::{DatasetIndexExt, vector::VectorIndexParams},
};
use lance_index::IndexType;
use lance_linalg::distance::MetricType;
async fn run(offset: bool, scoring: bool) -> anyhow::Result<()> {
let dir = tempfile::tempdir()?;
let vectors = FixedSizeListArray::try_new(
Arc::new(Field::new("item", DataType::Float32, true)),
2,
Arc::new(Float32Array::from_iter_values(
(0..32).flat_map(|x| [x as f32, 0.0]),
)),
None,
)?;
let schema = Arc::new(Schema::new(vec![Field::new(
"vector",
vectors.data_type().clone(),
false,
)]));
let batch = RecordBatch::try_new(schema.clone(), vec![Arc::new(vectors)])?;
let mut ds = Dataset::write(
RecordBatchIterator::new(vec![Ok(batch)], schema),
dir.path().to_str().unwrap(),
None,
)
.await?;
ds.create_index(
&["vector"],
IndexType::Vector,
Some("vector_idx".into()),
&VectorIndexParams::ivf_flat(1, MetricType::L2),
true,
)
.await?;
let query = Float32Array::from(vec![7.0, 0.0]);
let mut scanner = ds.scan();
scanner.nearest("vector", &query, 3)?.target_parallelism(1);
if !scoring {
scanner.disable_scoring_autoprojection();
}
if offset {
scanner.project(&["_rowoffset"])?;
}
let result = scanner.try_into_batch().await?;
assert_eq!(result.num_rows(), 3);
Ok(())
}
use arrow_array::Array;
#[tokio::test]
async fn ann_control() -> anyhow::Result<()> {
run(false, true).await
}
#[tokio::test]
async fn ann_rowoffset() -> anyhow::Result<()> {
run(true, true).await
}
#[tokio::test]
async fn ann_rowoffset_without_scoring_projection() -> anyhow::Result<()> {
run(true, false).await
}There was a problem hiding this comment.
@wjones127 @BubbleCal could you confirm whether this ANN _rowoffset planning panic should block merging this LanceDB dependency bump?
The focused fix is now available in lance-format/lance#10030 (still open). Since lance-format/lance#10004 has merged and we are considering a new Lance beta, should we include #10030 in that release and update this PR's Rust and Java Lance pins to it before merging? Or is it acceptable to proceed with the documented workaround and take the panic fix in a follow-up upgrade?
There was a problem hiding this comment.
I still consider this non-blocking: the failure is visible, has no write side effects, and the tested projection workarounds return rows. Lance #10030 is open and contains the focused statistics correction for this mechanism. Including it in the next release would remove the limitation, but it is not a prerequisite for this bump; the documented workaround can cover a follow-up upgrade.
There was a problem hiding this comment.
I don't think it needs to be blocking
There was a problem hiding this comment.
Agreed. This remains a non-blocking limitation with the documented projection workaround; the focused fix can be adopted in a follow-up upgrade.
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
Lance #10004 has now merged, as reported. This PR still pins beta.17, so the staged B-tree row-domain mismatch remains the merge blocker. Update the Rust and Java pins together to a release or revision containing that guard, then verify mixed-domain publication is rejected and indexed queries agree with flat scans. Beta.17 already fixes the ZoneMap seed-selection blocker.
The ANN _rowoffset panic remains non-blocking. Lance #10030 is the focused, still-open fix; it can accompany the next release or a follow-up upgrade. Until included, avoid _rowoffset, or disable scoring autoprojection and omit _distance when scores are unnecessary.
The standalone-compaction slowdown also remains non-blocking: follow compaction with index optimization, or use OptimizeAction::All, to restore B-tree acceleration. Neither of these two risks requires an upstream fix before this dependency bump.
… age policy (#4551) The \`deny\` job fails on main and on every open PR (for example #4539) because RustSec published four advisories against rustls 0.23.45: - RUSTSEC-2026-0346: \`Debug\` impls for client session values expose TLS secrets - RUSTSEC-2026-0347: buffered application data sent to the outer server after ECH rejection - RUSTSEC-2026-0348: Brotli certificate decompression can allocate up to 1 GiB before authentication - RUSTSEC-2026-0349: unauthenticated ServerHello can downgrade later connections to classical key exchange All four are fixed in rustls 0.23.46, published 2026-10-14 09:54 UTC. The 48-hour dependency age policy does not allow that upgrade until 2026-10-16 09:54 UTC, so this mirrors lance-format/lance#9985 and ignores the four advisories with that reason. rustls reaches us only through lance-io -> aws-config -> aws-smithy-http-client. It also ignores RUSTSEC-2024-0449 (\`unsafe-libyaml\` unmaintained), reached through lance-tokenizer -> lindera -> serde_yaml_ng. No maintained upgrade exists, so this one stays until lindera moves off serde_yaml_ng. Follow-up once the window passes: drop the four rustls entries and run \`cargo update -p rustls\`. Validation: \`cargo deny --all-features check advisories bans licenses sources\` (the CI invocation) passes locally with cargo-deny 0.20.2: \`advisories ok, bans ok, licenses ok, sources ok\`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5.1 <[email protected]>
The beta.18 bump adds a [patch.crates-io] entry pointing object_store at an apache/arrow-rs-object-store revision, matching Lance's own pin. cargo-deny's sources check rejects git sources that are not explicitly allowed, so the `deny` job failed with `source-not-allowed`. Allow that host, as #4539 did for beta.17. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Update Lance to v14.0.0-beta.17, including stable spilled row lineage and the ZoneMap seed serving-file fix. Retain the required object_store revision and the query/memtable compatibility fixtures from the beta.16 update.
Validation: workspace formatting and full workspace/all-features Clippy passed; core Rust tests passed (1,525 passed, 1 existing ignored). The full Java clean install passed all 37 tests, and Java CI passed after the beta.17 Maven artifacts were published. Java Checkstyle passed with 23 existing non-blocking diagnostics.
Cargo-deny reports the same five advisories as current main (RUSTSEC-2026-0346 through 0349, and RUSTSEC-2024-0449); bans, licenses, and sources pass. No advisory exceptions were added.