cockroachdb / cockroachdb/cockroach

sql: simple statements cannot use uncorrelated subqueries in scalar anymore

Open
#95,266 12 comments 0 reactions 0 assignees View on GitHub
A-sql-optimizer C-bug regression T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the problem**

At some point since CockroachDB v2.x, it has become impossible to use _uncorrelated_ subqueries in simple statements.
For example, in CockroachDB v2.1:
```
root@127.0.0.1:61098/defaultdb> set application_name = (select string_agg(x::string,'') from generate_series(1,10) as t(x));
SET

root@127.0.0.1:61098/defaultdb> show application_name;
application_name
+------------------+
12345678910
(1 row)
```

In v22.2:
```
demo@127.0.0.1:26257/defaultdb> set application_name = (select string_agg(x::string,'') from generate_series(1,10) as t(x));
ERROR: invalid value for parameter "application_name": ...: subqueries are not allowed in SET
```

**To Reproduce**

See above.

**Expected behavior**

_Uncorrelated_ subqueries should still be allowed.

**Additional data / screenshots**

The underlying mechanism (the `subqueries` plart of planTop in sql/planner) is still there. The `analyzeExpr` function still mentions that it should be able to handle subqueries in its docstring. So it should.

Jira issue: CRDB-23434

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.