cockroachdb / cockroachdb/cockroach
opt: internal error when ordering `EXPLAIN` subquer
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
```sql
CREATE TABLE t (
k INT PRIMARY KEY,
a INT,
b INT
);
SELECT info FROM [
EXPLAIN (OPT) SELECT k+1 FROM t WHERE k = 1
] ORDER BY info;
-- ERROR: internal error: runtime error: invalid memory address or nil pointer dereference
-- SQLSTATE: XX000
-- DETAIL: stack trace:
-- pkg/util/errorutil/catch.go:24: ShouldCatch()
-- pkg/sql/opt/xform/optimizer.go:259: func1()
-- GOROOT/src/runtime/panic.go:791: gopanic()
-- GOROOT/src/runtime/panic.go:262: panicmem()
-- GOROOT/src/runtime/signal_unix.go:917: sigpanic()
-- pkg/sql/opt/xform/optimizer.go:840: setLowestCostTree()
-- pkg/sql/opt/xform/optimizer.go:847: setLowestCostTree()
-- pkg/sql/opt/xform/optimizer.go:285: Optimize()
-- pkg/sql/plan_opt.go:876: buildExecMemo()
-- pkg/sql/plan_opt.go:261: makeOptimizerPlan()
-- pkg/sql/conn_executor_exec.go:3209: makeExecPlan()
-- pkg/sql/conn_executor_exec.go:2786: dispatchToExecutionEngine()
-- pkg/sql/conn_executor_exec.go:1071: execStmtInOpenState()
-- pkg/sql/conn_executor_exec.go:173: func2()
-- pkg/sql/conn_executor_exec.go:4400: execWithProfiling()
-- pkg/sql/conn_executor_exec.go:172: execStmt()
-- pkg/sql/conn_executor.go:2371: func1()
-- pkg/sql/conn_executor.go:2376: execCmd()
-- pkg/sql/conn_executor.go:2284: run()
-- pkg/sql/conn_executor.go:1062: ServeConn()
-- pkg/sql/pgwire/conn.go:253: processCommands()
-- pkg/sql/pgwire/server.go:1224: func4()
-- src/runtime/asm_arm64.s:1223: goexit()
```
Jira issue: CRDB-54436
Contributor guide
Research direction
Start by running the SQL reproducer with EXPLAIN (OPT) and ORDER BY info. Read pkg/sql/opt/xform/optimizer.go, especially setLowestCostTree and Optimize, then trace the call into pkg/sql/plan_opt.go. Done means the query executes without the nil-pointer internal error and produces ordered EXPLAIN output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100