Skip to content

sql: Internal Error: column x not in input. #107634

@SteveLeungYL

Description

@SteveLeungYL

Describe the problem

The latest release version of CockroachDB (v23.1.6) shows Internal Error when executing the following query.

SET sql_safe_updates = false;

CREATE TABLE v0 AS (SELECT '123' ); 
TABLE [DELETE FROM v0 ORDER BY STRING_AGG(b'\x90\x490\x90\x90\x90\x90\x90\x90\x90\x90\x90', b'\x90\x90\x90\x90\x90\x90\x90') LIMIT NULL RETURNING DATE_TRUNC('random_str', '0:0:0'::INTERVAL) ]; 

To Reproduce

  1. In operating system Ubuntu 20.04 LTS, download the CockroachDB source code from the github source.
  2. Download the pre-build CockroachDB binaries (v23.1.6) from the official release page: link
  3. Run ./cockroach demo, and then paste the PoC query to the cockroach cli environment.
  4. Observe the Internal Error and log the stack information.

Expected behavior
The DBMS should return a semantic error indicating that the parameters given to the functions are not of expected formats.

Additional data / screenshots

Here is the stack trace from v23.1.6:

ERROR: internal error: column 11 not in input
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:118: getNodeColumnOrdinal()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:1012: applySimpleProject()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:1042: buildProject()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:227: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:1939: buildSort()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:243: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:1916: buildLimitOffset()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:240: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/mutation.go:45: buildMutationInput()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/mutation.go:513: buildDelete()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:291: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:1034: buildProject()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:227: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:2912: buildWith()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:303: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:2068: buildDistribute()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/relational.go:246: buildRelational()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/builder.go:310: build()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/builder.go:257: Build()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:646: runExecBuilder()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:310: makeOptimizerPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1978: makeExecPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1484: dispatchToExecutionEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:964: execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:142: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:2986: execWithProfiling()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:141: execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2181: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2186: execCmd()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2103: run()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:900: ServeConn()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:310: func1()

HINT: You have encountered an unexpected error.

Environment:

Here is the detailed CockroachDB version information:

cockroach version details:
Build Tag:        v23.1.6
Build Time:       2023/07/20 05:55:49
Distribution:     CCL
Platform:         linux arm64 (aarch64-unknown-linux-gnu)
Go Version:       go1.19.10
C Compiler:       gcc 6.5.0
Build Commit ID:  3bacdbe302c436675605f3256025829e63c45330
Build Type:       release
Enabled Assertions: false

Additional context

This report is a duplication of #99243, #92730, #92610, #87170. But these reports have been stated as unactionable. Not sure whether it is because no PoC is available or the bug is not reproducible on the developer side. The PoC provided in this report should reliably reproduce the buggy behavior.

Jira issue: CRDB-30137

Metadata

Metadata

Assignees

Labels

C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.O-communityOriginated from the communityX-blathers-triagedblathers was able to find an owner

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions