Skip to content

INSERT..SELECT with a kv-engine source silently NULLs expression cells #311

Description

@EnRaiha

Summary

INSERT INTO dst (id) SELECT <expr> FROM src silently writes NULL for the
expression column when the source is a kv-engine collection. The
copy_rows column-map drops expression projections for kv sources, so the
cell is never evaluated — no error, no value.

Evidence

  • SELECT 1 + 1 FROM kv returned an empty column until kv scan projections
    were fixed in feat(sql): evaluate sequence accessors in constant contexts and kv projections #307 (KvOp::Scan now carries projection + computed columns).
  • The same gap remains on the INSERT..SELECT source path for kv: an
    accessor there (SELECT nextval('s') FROM kvsrc) inserts NULL silently
    instead of raising 0A000 like document/columnar sources do. Pinned as a
    known gap in the sequence_matrix wire suite (in-test note).

Expected

Expression cells over kv sources evaluate per row with the same semantics
as other engines (or fail loudly, never silently NULL).

Related: #303, #307, #294

Reproduction

CREATE COLLECTION kvsrc (id BIGINT PRIMARY KEY, v TEXT) WITH (engine = 'kv');
INSERT INTO kvsrc (id, v) VALUES (1, 'hello');
CREATE COLLECTION dst (id BIGINT PRIMARY KEY, v TEXT) WITH (engine = 'document_schemaless');
INSERT INTO dst (id) SELECT upper(v) FROM kvsrc;
SELECT * FROM dst;   -- v is NULL instead of 'HELLO'
-- accessor form: INSERT INTO dst (id) SELECT nextval('s') FROM kvsrc; -- NULL, no 0A000

Reproduced on main dd2ed01 and on the PR #307 branch (the gap is in the
copy_rows column-map for kv sources, independent of the kv scan fix).

Status on main @ 1ff3551 (re-verified 2026-09-28)

  • Accessor form: fixed. INSERT INTO t2 (id) SELECT nextval('s') FROM t over a kv source returns 0A000. Pinned by nextval_as_an_insert_select_source_is_refused in nodedb/tests/wire/cases/sql_sequence_row_scope_refusals.rs (source t is engine = 'kv').
  • The reproduction above is not a defect. INSERT INTO dst (id) SELECT upper(v) FROM kvsrc writes only the id column, so v is NULL by definition. It also puts a TEXT expression into a BIGINT key.
  • Still unconfirmed: whether an expression cell reaches a written column over a kv source. The case to run:
CREATE COLLECTION kvsrc (id BIGINT PRIMARY KEY, v TEXT) WITH (engine = 'kv');
INSERT INTO kvsrc (id, v) VALUES (1, 'hello');
CREATE COLLECTION dst (id BIGINT PRIMARY KEY, v TEXT) WITH (engine = 'document_schemaless');
INSERT INTO dst (id, v) SELECT id, upper(v) FROM kvsrc;
SELECT v FROM dst WHERE id = 1;   -- expected 'HELLO'

If that returns 'HELLO', this issue can close with that case added as a wire test.

Activity

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

Metadata

Metadata

Assignees

Labels

area:sqlParser, planner, SQL semanticsengine:kvKey-Value enginepriority:P2Scheduled, not urgentsev:3-mediumFeature wrong, but operational and a workaround existsstatus:confirmedReproduced by a maintainertype:bugA defect — broken, incorrect, or lost data

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions