Skip to content

bug(python): After building the index, executing create_scalar_index multiple times with merge_insert will result in an error. #3280

Closed

Description

@wl1447215262

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

  1. added
    bug
    on Apr 16, 2026
  2. westonpace commented on Apr 16, 2026

    @westonpace
    Contributor

    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

  3. wl1447215262 commented on Apr 17, 2026

    @wl1447215262
    Author

    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这是 github.com/ 的症状 lance-format/lance/pull/6514 ,希望下次版本能修复。不过我 lance-format/lance#6529 现在还在等

    So, is there any way I can avoid this now?

  4. prrao87 commented on Jul 2, 2026

    @prrao87
    Contributor

    Hi @wl1447215262 could you confirm if the recent 0.33.0 release of LanceDB (from May 28) fixed this issue for you?

  5. Xuanwo commented on Aug 6, 2026

    @Xuanwo
    Member

    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.

  6. added a commit that references this issue on Aug 6, 2026
    c1a3fa7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions