cockroachdb / cockroachdb/cockroach

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

Open
#98,729 1 comment 0 reactions 0 assignees View on GitHub
A-prepared-stmts C-bug T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

```sql
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

Contributor guide

Open the contributing guide

Research direction

Start with the failing PREPARE/EXECUTE example and the stack-trace entry points in pkg/sql/execute.go and pkg/sql/conn_executor_exec.go. Trace how observer statements are prepared versus executed, then add coverage for this example and ensure prepared observer statements produce a clear disallowed-operation error instead of an internal placeholder error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.