Repository navigation
Description
LanceDB version
lancedb 0.30.2
What happened?
I expect to be able to execute the merge_insert operation multiple times.
Are there known steps to reproduce?
table_name = "test_table"
ns = ['test']
db = lancedb.connect_namespace(
"dir",
{"root": "/root/test/"}
)
if table_name in db.list_tables(ns).tables:
db.drop_table(table_name, ns)
cols = [
pa.field("id", pa.uint64()),
pa.field("time", pa.uint64()),
]
db.create_table(table_name, schema=pa.schema(cols), namespace=ns, mode="create")
table = db.open_table(table_name, namespace=ns)
print(f"init table num:{table.count_rows()}, index:{table.list_indices()}")
data = pd.DataFrame({
"id": pd.Series(range(0, 10), dtype="uint64"),
})
table.add(data)
data = pd.DataFrame({
"id": pd.Series(range(10, 20), dtype="uint64"),
})
table.add(data)
print(f"after add table num:{table.count_rows()}, index:{table.list_indices()}")
vecs = np.random.randn(1, 4096).astype(np.float16)
vecs = vecs / np.linalg.norm(vecs, axis=1, keepdims=True)
vec_col = pa.FixedSizeListArray.from_arrays(pa.array(vecs.flatten(), type=pa.float16()),4096)
update_data = pd.DataFrame({"id": [1], "value": vec_col})
table.add_columns([pa.field("value", pa.list_(pa.float16(), 4096))])
print("--------begin test no index")
try:
st = time.time()
table.merge_insert("id") \
.when_matched_update_all() \
.execute(update_data)
table.merge_insert("id") \
.when_matched_update_all() \
.execute(update_data)
print(f"cost {time.time() - st}")
except Exception as e:
print(e)
print(traceback.format_exc())
print(f"No index after two updates table num:{table.count_rows()}, index:{table.list_indices()}")
print("--------begin test add index")
table.create_scalar_index("id", index_type="BTREE")
try:
st = time.time()
table.merge_insert("id") \
.when_matched_update_all() \
.execute(update_data)
table.merge_insert("id") \
.when_matched_update_all() \
.execute(update_data)
print(f"cost {time.time() - st}")
except Exception as e:
print(e)
print(traceback.format_exc())
print(f"index after two updates table num:{table.count_rows()}, index:{table.list_indices()}")
print("--------begin test drop index")
table.drop_index("id_idx")
try:
st = time.time()
table.merge_insert("id") \
.when_matched_update_all() \
.execute(update_data)
table.merge_insert("id") \
.when_matched_update_all() \
.execute(update_data)
print(f"cost {time.time() - st}")
except Exception as e:
print(e)
print(traceback.format_exc())
print(f"drop index after two updates table num:{table.count_rows()}, index:{table.list_indices()}")When I specify two columns in cols, it throws an error.
RuntimeError: lance error: LanceError(IO): External error: Invalid user input: Ambiguous merge inserts are prohibited: multiple source rows match the same target row on (id = 1). Please ensure each target row is matched by at most one source row., /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/lance-4.0.0/src/dataset/write/merge_insert.rs:195:40, /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/lance-4.0.0/src/dataset/write/merge_insert.rs:897:46
When I put
cols = [
pa.field("id", pa.uint64()),
# pa.field("time", pa.uint64()),
]
Commenting it out will fix the problem.
It's worth noting that I executed merge_insert twice; the first time it worked fine, but the second time it threw an error.
Activity
westonpace commentedon Apr 16, 2026
This is a symptom of github.com/lance-format/lance/pull/6514 so will hopefully be fixed in the next release. Though I am waiting on lance-format/lance#6529 at the moment
wl1447215262 commentedon Apr 17, 2026
So, is there any way I can avoid this now?
prrao87 commentedon Jul 2, 2026
Hi @wl1447215262 could you confirm if the recent 0.33.0 release of LanceDB (from May 28) fixed this issue for you?
Xuanwo commentedon Aug 6, 2026
Hi, this issue is invalid because it is already fixed by upstream lance#6563 (merged): the fragment bitmap allow-list is now applied to index search results, and the fix is included in the lance version pinned by current main. I'm closing this now. Feel free to create a new issue if the problem still exists.
fix(python): preserve repeated indexed merge inserts (#3850)