resolves #4258 ## Summary - document how indexed partial-column merges patch columns across touched fragments - explain how full-scan merges rewrite rows and can materialize the target table - describe the index-coverage, batching, and memory tradeoffs - align the Python, Rust, and TypeScript `use_index` API documentation ## Verification - `git diff --check` - Ruff 0.15.20 formatting check for `python/python/lancedb/merge.py` - Biome 1.9.4 check for `nodejs/lancedb/merge.ts` - reviewed the rendered MDX structure and cross-SDK wording The TypeDoc generation command was also attempted. It cannot complete in this checkout because the Rust-generated `nodejs/lancedb/native.d.ts` artifact is absent and Rust tooling is not installed; TypeDoc stops on the resulting pre-existing module-resolution errors before generating output. --------- Signed-off-by: Himanshu S <me.mrhimanshu@gmail.com> Co-authored-by: Himanshu <18554133+mrhimanshu@users.noreply.github.com> Co-authored-by: Himanshu S <me.mrhimanshu@gmail.com>
5.5 KiB
@lancedb/lancedb • Docs
@lancedb/lancedb / MergeInsertBuilder
Class: MergeInsertBuilder
A builder used to create and run a merge insert operation
Constructors
new MergeInsertBuilder()
new MergeInsertBuilder(native, schema): MergeInsertBuilder
Construct a MergeInsertBuilder. Internal use only.
Parameters
-
native:
NativeMergeInsertBuilder -
schema:
Schema<any> |Promise<Schema<any>>
Returns
Methods
execute()
execute(data, execOptions?): Promise<MergeResult>
Executes the merge insert operation
Parameters
-
data:
Data -
execOptions?:
Partial<WriteExecutionOptions>
Returns
Promise<MergeResult>
the merge result
useIndex()
useIndex(useIndex): MergeInsertBuilder
Controls the join and write strategy for the merge operation.
When true (the default), the operation can use scalar indexes on the join
keys when the operation supports the indexed path and all join keys have
usable indexes. When a partial-column update actually takes this path, it
patches the supplied non-key columns, rewriting those columns for every row
in each fragment containing a match.
An indexed partial update preserves index coverage on the join keys, but indexes on the rewritten non-key columns, including vector indexes, lose coverage in the patched fragments. Newly written rows, including inserted rows and full-row replacements, are not covered by existing indexes until the indexes are optimized.
When false, the operation performs a full-scan join and rewrites matched rows
by deleting and appending them. This can also happen with true, for example
when a join key lacks a usable index or a partial-column update includes a
blob column. Any full-scan plan can materialize the entire target table on the
hash-join build side and exhaust the server on large tables. The default flag
alone is not a memory safeguard. Do not treat false as a general-purpose
row-rewrite switch.
See How merge insert executes for the performance and index-coverage tradeoffs.
Parameters
- useIndex:
booleanWhether to allow index use for the merge. Defaults totrue.
Returns
useRTE()
useRTE(enable): MergeInsertBuilder
Control RTE routing for this merge.
By default (unset), a mergeInsert on a table with an RTE write spec is
routed through Lance's MemWAL shard writer, and a table without one uses the
standard path.
Parameters
- enable:
booleantrueforces RTE routing and errors if the table has no RTE write spec.falseforces the standard write path even when a spec is set.
Returns
validateSingleShard()
validateSingleShard(validateSingleShard): MergeInsertBuilder
Controls how an LSM merge checks that its input targets a single shard.
When a table has an RTE write spec, every row in a mergeInsert call must
route to the same shard. When true (the default), every row is inspected
to verify this. When false, only the first row is inspected and the
shard it routes to is used for the whole input — a faster path for callers
that have already pre-sharded their input. Has no effect on tables without
an RTE write spec.
Parameters
- validateSingleShard:
booleanWhether to check every row routes to one shard. Defaults totrue.
Returns
whenMatchedUpdateAll()
whenMatchedUpdateAll(options?): MergeInsertBuilder
Rows that exist in both the source table (new data) and the target table (old data) will be updated, replacing the old row with the corresponding matching row.
If there are multiple matches then the behavior is undefined. Currently this causes multiple copies of the row to be created but that behavior is subject to change.
An optional condition may be specified. If it is, then only matched rows that satisfy the condition will be updated. Any rows that do not satisfy the condition will be left as they are. Failing to satisfy the condition does not cause a "matched row" to become a "not matched" row.
The condition should be an SQL string. Use the prefix target. to refer to rows in the target table (old data) and the prefix source. to refer to rows in the source table (new data).
For example, "target.last_update < source.last_update"
Parameters
-
options?
-
options.where?:
string
Returns
whenNotMatchedBySourceDelete()
whenNotMatchedBySourceDelete(options?): MergeInsertBuilder
Rows that exist only in the target table (old data) will be deleted. An optional condition can be provided to limit what data is deleted.
Parameters
-
options?
-
options.where?:
stringAn optional condition to limit what data is deleted
Returns
whenNotMatchedInsertAll()
whenNotMatchedInsertAll(): MergeInsertBuilder
Rows that exist only in the source table (new data) should be inserted into the target table.