sql: vectorized engine evaluates `CAST` in the SELECT list on rows skipped by OFFSET and fails with 22007, row-by-row engine returns the row
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 58/100
Direzione di ricerca
Start with pkg/sql/colexec/colbuilder/execplan.go, especially planPostProcessSpec and the calls to planProjectionOperators and colexec.NewOffsetOp; compare their ordering with ProcOutputHelper.ProcessRow in pkg/sql/execinfra/processorsbase.go. Then inspect the vectorized execution tests for OFFSET and projections. Done means the vectorized query skips the invalid timestamp row before evaluating its SELECT expression and returns the same single row as the row-by-row engine.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the problem
For a table t with the values 'not-a-timestamp' and '2000-01-01' in column s, SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1 returns 2000-01-01 00:00:00 in the row-by-row engine, but fails with SQLSTATE 22007 (parsing as type timestamp: could not parse "not-a-timestamp") in the vectorized engine. The row skipped by OFFSET is not part of the result, yet the vectorized engine evaluates the CAST on it. The expected result is a single row, as in the row-by-row engine: in the plan printed by both engines the render (projection) sits above limit (offset: 1), so skipped rows should not be projected. The vectorized engine is the one that needs to change.
To Reproduce
Deployment: a single-node CockroachDB cluster started with cockroach start-single-node --insecure (tested: v26.2.7, 1 node, default settings except sql.stats.automatic_collection.enabled = false). Run the script in an empty database. The script runs the query twice in one session: first with vectorize = off (row-by-row engine), then with vectorize = on (vectorized engine).
SET TIME ZONE 'UTC';
CREATE TABLE t (id INT PRIMARY KEY, s STRING);
INSERT INTO t VALUES (1, 'not-a-timestamp'), (2, '2000-01-01');
-- row-by-row engine
SET vectorize = off;
EXPLAIN (VERBOSE) SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1;
SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1;
-- vectorized engine
SET vectorize = on;
EXPLAIN (VERBOSE) SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1;
SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1;
Expected behavior
The query should return one row, 2000-01-01 00:00:00. EXPLAIN shows render -> limit (offset: 1) -> scan in both engines, and the optimizer rule PushOffsetIntoProject (pkg/sql/opt/norm/rules/limit.opt) states: "PushOffsetIntoProject pushes the Offset operator into its Project input. It is desirable to push the Offset operator as low in the query as possible, in order to minimize the number of rows that other operators need to process." So a row skipped by OFFSET is not projected. Neither the CockroachDB documentation (limit-offset.md, scalar-expressions.md) nor the PostgreSQL manual says explicitly whether an error in the SELECT list on a skipped row has to be raised: the manual (queries-limit) only says "The rows skipped by an OFFSET clause still have to be computed inside the server; therefore a large OFFSET might be inefficient." PostgreSQL 18.6 itself raises 22007 for this query, so this expectation rests on CockroachDB's own plan and on the row-by-row engine.
PostgreSQL 18.6 (Debian 18.6-1.pgdg12+2):
SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1;
psql:<stdin>:5: ERROR: 42P01: relation "t" does not exist
LINE 1: SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1;
^
LOCATION: parserOpenTable, parse_relation.c:1498
Additional data / screenshots
Row-by-row engine (vectorize = off): one row, 2000-01-01 00:00:00. Vectorized engine (vectorize = on): error, SQLSTATE 22007, parsing as type timestamp: could not parse "not-a-timestamp".
-- row-by-row engine
EXPLAIN (VERBOSE) SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1;
info
--------------------------------------------------
distribution: local
vectorized: false
• render
│ columns: (s)
│ render s: s::TIMESTAMP
│
└── • limit
│ columns: (s)
│ offset: 1
│
└── • scan
columns: (s)
estimated row count: 2 (missing stats)
table: t@t_pkey
spans: LIMITED SCAN
limit: 2
(17 rows)
SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1;
s
---------------------
2000-01-01 00:00:00
(1 row)
-- vectorized engine
EXPLAIN (VERBOSE) SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1;
info
--------------------------------------------------
distribution: local
vectorized: true
• render
│ columns: (s)
│ render s: s::TIMESTAMP
│
└── • limit
│ columns: (s)
│ offset: 1
│
└── • scan
columns: (s)
estimated row count: 2 (missing stats)
table: t@t_pkey
spans: LIMITED SCAN
limit: 2
(17 rows)
SELECT CAST(s AS TIMESTAMP) FROM t OFFSET 1 LIMIT 1;
psql:<stdin>:12: ERROR: 22007: parsing as type timestamp: could not parse "not-a-timestamp"
LOCATION: inputErrorf, parsing.go:300
Environment:
- CockroachDB version:
CockroachDB CCL v26.2.7-dev-8652ac22d9f90501e48ae4f24efd7faab33cf7c5 (x86_64-pc-linux-gnu, built 2026/10/23 21:35:41, go1.25.13)
- Server OS: Linux 6.8.0-138-generic x86_64, AMD EPYC 7J13 64-Core Processor
- Client app:
psql
Additional context
Row-by-row engine: ProcOutputHelper.ProcessRow (pkg/sql/execinfra/processorsbase.go) increments rowIdx and, while rowIdx <= offset, suppresses the row (// Suppress row.). This happens before the // Rendering. step, so render expressions are evaluated only on rows that survive the offset.
Vectorized engine: planPostProcessSpec (pkg/sql/colexec/colbuilder/execplan.go) first plans a projection operator for every render expression with planProjectionOperators and only afterwards wraps the result with colexec.NewOffsetOp(r.Op, post.Offset). The executed operator tree is therefore limitOp -> offsetOp -> castStringTimestampOp -> ColBatchScan: the cast runs over the whole input batch, including the rows that offsetOp is going to drop, and raises the error before the offset is applied. This is the reverse of the order in the logical plan.
- CockroachDB: pkg/sql/execinfra/processorsbase.go#L288 —
ProcOutputHelper.ProcessRow - CockroachDB: pkg/sql/colexec/colbuilder/execplan.go#L2091 —
postProcessResult.planPostProcessSpec
Found with AI assistance.
Jira issue: CRDB-70797
- Lingua principale
- Go
- Stelle
- 32.6k
- Fork
- 4.2k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di cockroachdb/cockroach
-
C-bug O-community X-blathers-untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
cockroachdb/cockroach#176245 · 1 commento ·
-
sql: pg_database.dattablespace is 0 but pg_tablespace.oid is 1663, so they no longer joinForse già presa @1AbdullahButt l’ha presa 14 giorni fa. ApertaC-bug O-community X-blathers-triaged X-move-internal
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
cockroachdb/cockroach#176228 · 1 commento ·
-
PG compat: overflow in integer power calculation triggers incompatible SQLSTATEForse di nuovo libera @darshpatel1052 l’ha presa 18 giorni fa e non c’è nessuna pull request aperta. ApertaC-bug O-community X-blathers-untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
cockroachdb/cockroach#176223 · 2 commenti ·
-
util/log: bufferedSinkCloser.Close leaks a goroutine after timeoutForse già presa @dajiaohuang l’ha presa 14 giorni fa. ApertaC-bug O-community X-blathers-untriaged
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
cockroachdb/cockroach#176210 · 1 commento ·
-
C-bug O-community T-sql-queries X-blathers-triaged X-move-internal
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
cockroachdb/cockroach#176150 · 1 commento ·
Tutte le issue di cockroachdb/cockroach
Issue simili
-
☢️ Bug v3
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
area/import-export area/projects concern/ux
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
go-vikunja/vikunja#4455 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Dependabot PRs no longer merge automaticallyForse già presa @dwisiswant0 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
projectdiscovery/urlfinder#160 ·
I maintainer di solito rispondono entro 1 giorno
-
database
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
chnm/legal-modernism#450 ·
I maintainer di solito rispondono entro 1 giorno
-
tech-debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno