Conversation
EnRaiha
force-pushed
the
fix/issue311-insert-select-source-engine
branch
from
September 17, 2026 02:16
064ba63 to
73f1835
Compare
The document materializer scanned every source. A kv source read an empty document store, so INSERT ... SELECT copied no rows and reported INSERT 0 0. - route on the catalog engine in clone_materializer/auto_source.rs - kv normalizes the materialize-scan page to the copy entry shape - refuse columnar, timeseries, spatial, array by name
The test copies two kv rows into a document target with an expression cell and asserts both the row count and the evaluated cells. The kv arm also refuses a point-in-time or transactional read by name: the materialize-scan carries no snapshot fields, so the read had nothing to honor.
… key column - a point-in-time or transactional read from a kv source is refused by name; an in-transaction INSERT ... SELECT reaches that path - a source engine with no materializer (columnar) is refused by name - a kv collection whose key column is the key sentinel now carries the key: the arm uses the one shaping rule every scan path uses, so the copied column reads the row's own key instead of NULL
EnRaiha
force-pushed
the
fix/issue311-insert-select-source-engine
branch
from
September 17, 2026 04:39
73f1835 to
af1a7aa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
INSERT … SELECTwith a kv-engine source copied nothing. The copy pipeline scanned every source with the document materializer, and a kv collection keeps nothing in the document store, so the scan returned no rows and the statement reportedINSERT 0 0— while the filed symptom was expression cells over the copied rows reading NULL because no row arrived at all.This PR routes the source scan on the catalog engine: a kv source scans through its own materializer and each
(key, value)pair is normalized with the one shaping rule every scan path uses. Engines with no materializer, and reads the kv scan cannot honour, are refused by name instead of silently copying nothing.Behaviour changes
INSERT INTO dst SELECT … FROM kv_srcINSERT 0 0keyINSERT … SELECTfrom a kv source42601, naming the unsupported read42601, naming the engineCloses #311.
Root cause
clone_materializerscanned every source throughdocument::scan_source_page(the name itself says so), regardless of the source's engine. A kv collection's rows live in the kv store, so the document scan returned an empty page; the copy then reportedINSERT 0 0with no error.SELECT,RETURNING, single-keyGet) shapes a kv entry withmsgpack_scan::kv_row_msgpack, which injects the key into the body at the binary level; a body that already carries its ownkeykeeps it. The new copy arm initially used the raw(key, value)pair, so a kv collection whose key column is thekeysentinel copied SQL NULL — silent data loss the audit caught.KvOp::MaterializeScan { collection, cursor, count }) carries no snapshot fields, and its dispatch passestxn_id = None. The document arm threadssystem_as_of_msandtxn_id; for kv there was nothing to thread.What changed
Commit
1bf454c4e— engine routing:clone_materializer/auto_source.rs(new): one dispatcher that reads the catalog engine and routes document sources to the document materializer and kv sources to their own scan.INSERT … SELECTmaterializer (columnar, timeseries, spatial, array) are refused by name: a silent copy with the wrong materializer reads nothing.expand_staged.rsand the insert-select orchestrator call the dispatcher; the document re-export inclone_materializer/mod.rsis retired with its callers;catalog_adapterexposes the engine lookup this needs at the minimum visibility.Commit
64554ec7a— coverage and one refusal:upper(v)→HELLO/WORLD)INSERT … SELECTreaches this path.Commit
73f1835bd— audit-round coverage and the key column:nodedb_query::msgpack_scan::kv_row_msgpack— the same rule the scan,RETURNING, andGetpaths use — so thekeycolumn carries the row's own key instead of NULLRegression proof
On base
main, without this change: the kv-source copy reports an empty result, both refusals are absent, and thekeycolumn copies NULL. With this change the copy carries both rows with evaluated cells, both refusals answer42601naming the cause, and the key column carries the row's key.Tested
cargo nextest run -p nodedb --test wire -E 'test(cases::insert_select_cross_engine) | test(cases::sql_transactions_insert_select_overlay)'— 4 new cases and the neighbouring module tests passinsert_select_cross_engine,sql_transactions_insert_select_cross_engine,sql_transactions_insert_select_overlay,vector_index_txn_insert_select_stmt_stage— 17 passedcargo fmt --all -- --check— cleancargo clippy -p nodedb --lib -- -D warnings— cleanReview
A separate, read-only parity audit ran over this branch before submission. Its findings and their resolutions:
INSERT … SELECT73f1835bd)keycopied NULLExclusions
KvOp::MaterializeScan); refusing by name is the honest option in this PR, and the refusal is tested. Threading is a follow-up if the kv read path gains snapshot support.Commits
1bf454c4e—fix(insert-select): scan a source in its own engine64554ec7a— kv source coverage, and refuse a snapshot read by name73f1835bd— refusals and the key column (one shaping rule)