Skip to content

fix(python): handle scalar-indexed merge inserts#3612

Open
goutamadwant wants to merge 1 commit into
lancedb:mainfrom
goutamadwant:fix-merge-insert-scalar-index
Open

fix(python): handle scalar-indexed merge inserts#3612
goutamadwant wants to merge 1 commit into
lancedb:mainfrom
goutamadwant:fix-merge-insert-scalar-index

Conversation

@goutamadwant

Copy link
Copy Markdown

Summary

Fix merge_insert(...).when_matched_update_all() for tables that have a scalar index on the merge key when the key is not one of the leading target fields.

The indexed merge path can silently report zero updated rows in that shape. This keeps the indexed path for schemas where the merge keys are leading fields, and falls back to a full scan otherwise.

Adds a Python regression covering a BTREE scalar index on path with partial update data, matching the reported failure mode.

Test Plan

  • python -m pytest python/tests/test_table.py::test_merge_insert_update_all_with_scalar_index
  • python -m pytest python/tests/test_table.py::test_merge_insert python/tests/test_table.py::test_merge_insert_subschema python/tests/test_table.py::test_merge_insert_update_all_with_scalar_index
  • ruff check python/tests/test_table.py
  • ruff format --check python/tests/test_table.py
  • cargo fmt --all -- --check
  • cargo test -p lancedb table::merge::tests::test_merge_insert_use_index

Breaking Changes

None.

Fixes #3515

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

builder.when_not_matched_by_source(WhenNotMatchedBySource::Keep);
}
builder.use_index(params.use_index);
builder.use_index(use_index);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue(blocking): this will cause performance regressions in some cases. We should probably fix whatever bug is upstream. I think I'd rather do that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, lance-format/lance#7251, should have fixed this. Is your test failing without that change? if so, we should raise a bug issue in the lance-format/lance repo.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wjones127 I checked this locally.

With the LanceDB-side fallback removed, the regression still fails on the currently pinned Lance v9.0.0-beta.10: the merge result reports num_updated_rows=0 instead of updating the expected rows.

I also confirmed that v9.0.0-beta.10 already contains lance-format/lance#7251, and tested the same regression against Lance main at dca65b904ce7b6398ff9b3e7aa5c9fbb4951af40 (9.0.0-beta.11). It still fails there with the same num_updated_rows=0 behavior.

So I agree this should be raised upstream in lance-format/lance. I’ll open a focused Lance issue with the LanceDB regression and link it back here before changing this PR further. Does that make sense or any suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Python Python SDK Rust Rust related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(python): Create scalar index on merge column make merge_insert update all fail completely without raising error

2 participants