Repository navigation
Commit 14701a0
committed
fix(sql): raise 42703 for unknown column references instead of folding to NULL
A column reference that names nothing in scope planned as a field lookup and
evaluated to NULL on every row. On collections whose row shape is known at
plan time that is silent misbehavior: projection returned NULL-filled rows,
WHERE matched nothing (IS NULL matched everything), ORDER BY no-oped, and
UPDATE/DELETE predicates touched zero rows — no error anywhere. The
function-existence gate already raised for undefined functions; column
resolution had no counterpart.
Closed-schema collections now validate every reference at plan time and
raise SQLSTATE 42703 (undefined_column):
- document_strict, kv, columnar, timeseries and spatial are closed by
construction.
- document (schemaless) is closed when the user declared columns on it; a
collection carrying only the auto-injected id stays open, so dynamic
fields that appear only in the data keep resolving (the NULL fold remains
the documented behavior there).
The gate covers the single-table SELECT path (projection, WHERE, GROUP BY,
HAVING, ORDER BY) and the UPDATE/DELETE target path (SET targets and
predicates). Qualified references validate against the collection they name.
Schemaless writes stay open: INSERT column lists may still carry undeclared
dynamic fields.
The error is typed end to end: SqlError::UnknownColumn maps to a new
crate::Error::UndefinedColumn, to the public NodeDbError code 1206 with
msgpack tag 79, and to SQLSTATE 42703 on pgwire and the native protocol —
mirroring the undefined_function path added for the same folding class.
Out of scope (pre-existing folds, tracked separately): JOIN/derived/lateral
paths, aggregate ORDER BY, UPDATE ... FROM predicates, and INSERT ... SELECT.
Fixes #2921 parent 9998320 commit 14701a0
17 files changed
Lines changed: 1003 additions & 1 deletion
File tree
- nodedb-sql/src/planner
- select
- nodedb-types/src/error
- ctors
- msgpack
- decode
- nodedb
- src
- control
- planner/context/query
- server/pgwire/types
- error
- tests/wire/cases
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
53 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
54 | 68 | | |
55 | 69 | | |
56 | 70 | | |
| |||
358 | 372 | | |
359 | 373 | | |
360 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
361 | 385 | | |
362 | 386 | | |
363 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
176 | 188 | | |
177 | 189 | | |
178 | 190 | | |
| |||
289 | 301 | | |
290 | 302 | | |
291 | 303 | | |
292 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
293 | 310 | | |
294 | 311 | | |
295 | 312 | | |
| |||
0 commit comments