There's several TypeCheck methods that replace the semaCtx's reject flags with new ones, causing the original reject flags set by the caller to be ignored. For example:
|
semaCtx.Properties.Require("CASE", RejectGenerators) |
This can cause subtle bugs where expressions that should be rejected in certain contexts are not rejected when wrapped in expressions whose TypeCheck method replaces the flags.
As one example, aggregate functions are not allowed in ORDER BY clauses of DELETE and UPDATE as of #107641. But the rejection fails and we get an internal error if we wrap the aggregate function in a COALESCE:
CREATE TABLE t (a INT);
DELETE FROM t WHERE a > 0 ORDER BY COALESCE(sum(a), 1) LIMIT 1;
-- ERROR: internal error: top-level relational expression cannot have outer columns: (9
-- )
-- SQLSTATE: XX000
-- DETAIL: stack trace:
-- github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:280: Optimize()
-- github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:592: buildExecMemo()
-- github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:240: makeOptimizerPlan()
-- github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1969: makeExecPlan()
-- github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1485: dispatchToExecu
-- tionEngine()
-- github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:965: execStmtInOpenState()
-- github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:142: func1()
-- github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:2991: execWithProfiling()
-- github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:141: execStmt()
-- github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2220: func1()
-- github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2225: execCmd()
-- github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2142: run()
-- github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:954: ServeConn()
-- github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:244: processCommands()
-- github.com/cockroachdb/cockroach/pkg/sql/pgwire/server.go:996: func3()
-- GOROOT/src/runtime/asm_arm64.s:1172: goexit()
Jira issue: CRDB-30341
There's several
TypeCheckmethods that replace thesemaCtx's reject flags with new ones, causing the original reject flags set by the caller to be ignored. For example:cockroach/pkg/sql/sem/tree/type_check.go
Line 395 in c5c821a
This can cause subtle bugs where expressions that should be rejected in certain contexts are not rejected when wrapped in expressions whose
TypeCheckmethod replaces the flags.As one example, aggregate functions are not allowed in
ORDER BYclauses ofDELETEandUPDATEas of #107641. But the rejection fails and we get an internal error if we wrap the aggregate function in aCOALESCE:Jira issue: CRDB-30341