cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.11k stars 3.81k forks source link

sql: Internal Error when executing query #131121

Open SteveLeungYL opened 1 month ago

SteveLeungYL commented 1 month ago

Describe the problem

The latest version of the CockroachDB v24.2.0 encounters Internal Error when executing the following query:

CREATE TABLE v0 ( c1 ) AS ( WITH ta2 AS ( EXPLAIN COMMENT ON SCHEMA public IS NULL ) VALUES ( 0 ) );

To Reproduce

  1. In operating system Ubuntu 20.04 LTS, download the pre-build CockroachDB binaries (v24.2.0) from link
  2. Run ./cockroach demo, and then paste the PoC query to the cockroach cli environment.
  3. Observe the crash and log the stack information.

Expected behavior The CockroachDB should return error from the statement.

Additional data / screenshots

This is the stack frame from the crash (v24.2.0):

ERROR: internal error: runtime error: invalid memory address or nil pointer dereference
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/util/errorutil/catch.go:29: ShouldCatch()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:225: func1()
GOROOT/src/runtime/panic.go:770: gopanic()
GOROOT/src/runtime/panic.go:261: panicmem()
GOROOT/src/runtime/signal_unix.go:881: sigpanic()
github.com/cockroachdb/cockroach/pkg/sql/schema_change_plan_node.go:59: SchemaChange()
github.com/cockroachdb/cockroach/pkg/sql/opaque.go:57: buildOpaque()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/opaque.go:70: tryBuildOpaque()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:467: buildStmt()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:299: buildStmtAtRootWithScope()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:280: buildStmtAtRoot()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/explain.go:31: buildExplain()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:389: buildStmt()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/with.go:198: buildCTE()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/with.go:143: buildCTEs()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/with.go:113: processWiths()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1127: buildSelect()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:356: buildStmt()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:299: buildStmtAtRootWithScope()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:280: buildStmtAtRoot()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:259: Build()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:862: buildExecMemo()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:251: makeOptimizerPlan()
github.com/cockroachdb/cockroach/pkg/sql/schema_changer.go:381: 2()
github.com/cockroachdb/cockroach/pkg/sql/schema_resolver.go:444: runWithOptions()
github.com/cockroachdb/cockroach/pkg/sql/schema_changer.go:380: func2()
github.com/cockroachdb/cockroach/pkg/sql/internal.go:1940: func1()
github.com/cockroachdb/cockroach/pkg/sql/internal.go:2027: func4()
github.com/cockroachdb/cockroach/pkg/kv/txn.go:1049: exec()
github.com/cockroachdb/cockroach/pkg/kv/db.go:1103: runTxn()
github.com/cockroachdb/cockroach/pkg/kv/db.go:1066: TxnWithAdmissionControl()
github.com/cockroachdb/cockroach/pkg/kv/db.go:1041: Txn()

Environment:

cockroach version details:
Build Tag:        v24.2.0
Build Time:       2024/08/08 01:50:30
Distribution:     CCL
Platform:         linux arm64 (aarch64-unknown-linux-gnu)
Go Version:       go1.22.5 X:nocoverageredesign
C Compiler:       gcc 6.5.0
Build Commit ID:  953d09cce5a01cc0053e138516d80a27454f027c
Build Type:       release

Additional Information

The bug is automatically reported when I am triggering it locally, in https://github.com/cockroachdb/cockroach/issues/131117 and https://github.com/cockroachdb/cockroach/issues/131118.

Jira issue: CRDB-42386

blathers-crl[bot] commented 1 month ago

Hi @SteveLeungYL, please add branch-* labels to identify which branch(es) this C-bug affects.

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

blathers-crl[bot] commented 1 month ago

Hello, I am Blathers. I am here to help you get the issue triaged.

Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here.

I have CC'd a few people who may be able to assist you:

If we have not gotten back to your issue within a few business days, you can try the following:

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

mgartner commented 1 month ago

In general, we're not going to support things like EXPLAIN nested within other queries. This should result in a user error.