-
Notifications
You must be signed in to change notification settings - Fork 4.1k
udf: select * in a udf combined with edited table can cause crashes #86070
Copy link
Copy link
Closed
Labels
A-sql-routineUDFs and Stored ProceduresUDFs and Stored ProceduresC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-queriesSQL Queries TeamSQL Queries Teambranch-release-22.2Used to mark GA and release blockers, technical advisories, and bugs for 22.2Used to mark GA and release blockers, technical advisories, and bugs for 22.2release-blockerIndicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked.Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked.
Description
It's possible to use SELECT * within a UDF, which seems to cause issues after editing the table that's being SELECT *'d from. In other contexts we just ban SELECT *.
demo@127.0.0.1:26257/defaultdb> create table t (a int);
CREATE TABLE
demo@127.0.0.1:26257/defaultdb> create function f() returns int language sql as 'select * from t';
CREATE FUNCTION
demo@127.0.0.1:26257/defaultdb> alter table t add column b int;
ALTER TABLE
demo@127.0.0.1:26257/defaultdb> select f();
f
--------
NULL
(1 row)
demo@127.0.0.1:26257/defaultdb> insert into t values(1);
INSERT 0 1
demo@127.0.0.1:26257/defaultdb> select f();
*
* ERROR: a SQL panic has occurred while executing the following statement:
* SELECT f()
*
*
* ERROR: a panic has occurred!
* runtime error: index out of range [1] with length 1
* (1) attached stack trace
* -- stack trace:
* | github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn.func1
* | github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:806
* | [...repeated from below...]
* Wraps: (2) while executing: SELECT f()
* Wraps: (3) attached stack trace
* -- stack trace:
* | github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn.func1
* | github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:806
* | runtime.gopanic
* | GOROOT/src/runtime/panic.go:838
* | github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError.func1
* | github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:58
* | runtime.gopanic
* | GOROOT/src/runtime/panic.go:838
* | runtime.goPanicIndex
* | GOROOT/src/runtime/panic.go:89
* | github.com/cockroachdb/cockroach/pkg/sql.(*rowContainerHelper).AddRow
* | github.com/cockroachdb/cockroach/pkg/sql/buffer_util.go:90
* | github.com/cockroachdb/cockroach/pkg/sql.(*RowResultWriter).AddRow
* | github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:908
* | github.com/cockroachdb/cockroach/pkg/sql.(*DistSQLReceiver).Push
* | github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1241
* | github.com/cockroachdb/cockroach/pkg/sql/execinfra.Run
* | github.com/cockroachdb/cockroach/pkg/sql/execinfra/base.go:189
* | github.com/cockroachdb/cockroach/pkg/sql/execinfra.(*ProcessorBaseNoHelper).Run
* | github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:722
For the record, the equivalent sequence in Postgres does this:
jordan=> select f();
ERROR: return type mismatch in function declared to return integer
DETAIL: Final statement must return exactly one column.
CONTEXT: SQL function "f" during startup
Jira issue: CRDB-18552
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-sql-routineUDFs and Stored ProceduresUDFs and Stored ProceduresC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-queriesSQL Queries TeamSQL Queries Teambranch-release-22.2Used to mark GA and release blockers, technical advisories, and bugs for 22.2Used to mark GA and release blockers, technical advisories, and bugs for 22.2release-blockerIndicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked.Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked.
Type
Projects
Status
Done