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.13k stars 3.81k forks source link

sql: executing prepared "observer" statements result in an internal error #98729

Open yuzefovich opened 1 year ago

yuzefovich commented 1 year ago
PREPARE p AS SET TRACING = $1;
EXECUTE p('on'); 

results in

ERROR: internal error: no type for placeholder $1
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/execute.go:44: fillInPlaceholders()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:463: execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:137: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:2683: execWithProfiling()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:136: execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1991: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1996: execCmd()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1913: run()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:868: ServeConn()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:733: func1()
GOROOT/src/runtime/asm_arm64.s:1172: goexit()

This is because "observer statements" don't go through the execute engine.

We probably should just disallow making prepared "observer" statements to make the error nicer.

Jira issue: CRDB-25468

mgartner commented 1 year ago

I think we should disallow PREPARE with a SET statement entirely. Postgres does not support it:

marcus=# PREPARE p AS SET TRACING = $1;
ERROR:  42601: syntax error at or near "SET"
LINE 1: PREPARE p AS SET TRACING = $1;