sql: casting an invalid string to aclitem errors in the row-by-row engine but returns it unvalidated in the vectorized engine
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
Direzione di ricerca
Read pkg/sql/sem/eval/cast.go and the vectorized string cast template in pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go, then inspect the generated castEnumStringOp in pkg/sql/colexec/colexecbase/cast.eg.go. Compare how each engine handles casts to aclitem and run the reproduction with vectorization off and on. Done means invalid aclitem strings fail with SQLSTATE 22P02 in both engines.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the problem
When a string, or an enum value, that is not a valid aclitem is cast to aclitem (for example SELECT s::aclitem FROM t with s = 'u=z/', or an enum value 'bad_acl'), the row-by-row engine fails with SQLSTATE 22P02 (invalid mode character: "z"; missing "=" sign for the enum value). The vectorized engine does not validate the text and returns it unchanged as a value of type aclitem. The result of a cast to aclitem has to be a valid aclitem, so the vectorized engine should reject the invalid input with 22P02 like the row-by-row engine.
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 (s STRING NOT NULL);
INSERT INTO t VALUES ('u=z/');
-- row-by-row engine
SET vectorize = off;
EXPLAIN (VERBOSE) SELECT s::aclitem FROM t;
SELECT s::aclitem FROM t;
-- vectorized engine
SET vectorize = on;
EXPLAIN (VERBOSE) SELECT s::aclitem FROM t;
SELECT s::aclitem FROM t;
Expected behavior
A cast to aclitem should yield a valid aclitem or fail: invalid text should fail with SQLSTATE 22P02 in both engines, as it does in the row-by-row engine (tree.NewDACLItem, called for oid.T_aclitem in performCastWithoutPrecisionTruncation, pkg/sql/sem/eval/cast.go). This follows the general rule that a result must conform to its declared type: the vectorized engine returns a column of type aclitem holding strings such as u=z/ and bad_acl, which are not valid aclitems. No documentation says how invalid values are handled: the CockroachDB docs have no page for aclitem, and the PostgreSQL manual (ddl.sgml) only describes the display format grantee=privileges/grantor. For reference, PostgreSQL 18.6 also reports 22P02 for SELECT s::aclitem FROM t with s = 'u=z/'.
PostgreSQL 18.6 (Debian 18.6-1.pgdg12+2):
SELECT s::aclitem FROM t;
psql:<stdin>:5: ERROR: 42P01: relation "t" does not exist
LINE 1: SELECT s::aclitem FROM t;
^
LOCATION: parserOpenTable, parse_relation.c:1498
Additional data / screenshots
With SET vectorize = off (row-by-row engine) the query fails with invalid mode character: "z" (SQLSTATE 22P02). With SET vectorize = on (vectorized engine) it returns one row, u=z/, in a column of type aclitem.
-- row-by-row engine
EXPLAIN (VERBOSE) SELECT s::aclitem FROM t;
info
--------------------------------------------------
distribution: local
vectorized: false
• render
│ columns: (s)
│ render s: s::ACLITEM
│
└── • scan
columns: (s)
estimated row count: 1,000 (missing stats)
table: t@t_pkey
spans: FULL SCAN
(12 rows)
SELECT s::aclitem FROM t;
psql:<stdin>:8: ERROR: 22P02: invalid mode character: "z"
LOCATION: ValidateACLItemString, privilege.go:435
-- vectorized engine
EXPLAIN (VERBOSE) SELECT s::aclitem FROM t;
info
--------------------------------------------------
distribution: local
vectorized: true
• render
│ columns: (s)
│ render s: s::ACLITEM
│
└── • scan
columns: (s)
estimated row count: 1,000 (missing stats)
table: t@t_pkey
spans: FULL SCAN
(12 rows)
SELECT s::aclitem FROM t;
s
------
u=z/
(1 row)
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
The row-by-row cast (performCastWithoutPrecisionTruncation, pkg/sql/sem/eval/cast.go:518-520) runs if t.Oid() == oid.T_aclitem { return tree.NewDACLItem(s) }, which parses and validates the string. The vectorized toString template (pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go, from line 526) is documented as "a combination of the relevant pieces from eval.performCastWithoutPrecisionTruncation as well as from tree.AdjustValueToType". However, its condition if toType.Oid() != oid.T_name && toType.Oid() != oid.T_aclitem {...} leaves aclitem out of the string handling, and nothing after it checks the format, so the aclitem validation of the row-by-row cast is missing. The enum-to-string cast (castEnumStringOp) shares this template.
- CockroachDB: pkg/sql/sem/eval/cast.go#L519 —
performCastWithoutPrecisionTruncation - CockroachDB: pkg/sql/colexec/colexecbase/cast.eg.go#L5110 —
castEnumStringOp.Next
Found with AI assistance.
Jira issue: CRDB-70795
- 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