Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal error: expected subquery to be lazily planned as a routine #101980

Closed
DerZc opened this issue Apr 21, 2023 · 5 comments · Fixed by #102336
Closed

internal error: expected subquery to be lazily planned as a routine #101980

DerZc opened this issue Apr 21, 2023 · 5 comments · Fixed by #102336
Assignees
Labels
A-sql-optimizer SQL logical planning and optimizations. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-community Originated from the community T-sql-queries SQL Queries Team X-blathers-triaged blathers was able to find an owner
Projects

Comments

@DerZc
Copy link

DerZc commented Apr 21, 2023

Describe the problem

Please describe the issue you observed, and any steps we can take to reproduce it:

To Reproduce

The following program triggers this error

CREATE DATABASE database7;
USE database7;
SET CLUSTER SETTING diagnostics.reporting.enabled    = false;
SET CLUSTER SETTING diagnostics.reporting.send_crash_reports = false;
SET CLUSTER SETTING sql.metrics.statement_details.plan_collection.enabled = 'off';
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = 'off';
SET CLUSTER SETTING timeseries.storage.enabled = 'off';
set experimental_enable_hash_sharded_indexes='on';


CREATE TABLE t0 (c0 FLOAT);
CREATE TABLE t1 (c0 SERIAL4);
CREATE TABLE t2 (c0 SERIAL2);

UPSERT INTO t0 (c0) VALUES(1);
UPSERT INTO t2 (rowid) VALUES(1);

SELECT t2.c0 FROM t0 FULL OUTER JOIN t2 ON (((t2.rowid) IN (SELECT t0.rowid FROM t2, t0 WHERE (((0) NOT BETWEEN (t0.rowid) AND ((0)))OR((t2.c0) IN (SELECT ALL BIT_AND(t2.rowid) FROM t2, t1 WHERE false))))));

This is the error message:

> SELECT t2.c0 FROM t0 FULL OUTER JOIN t2 ON (((t2.rowid) IN (SELECT t0.rowid FROM t2, t0 WHERE (((0) NOT BETWEEN (t0.rowid) AND ((0)))OR((t2.c0) IN (SELECT ALL BIT_AND(t2.rowid) FROM t2, t1 WHERE false))
))));
ERROR: internal error: expected subquery to be lazily planned as a routine
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/scalar.go:1107: expectedLazyRoutineError()
github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/scalar.go:1087: func2()
github.com/cockroachdb/cockroach/pkg/sql/routine.go:147: Start()
github.com/cockroachdb/cockroach/pkg/sql/routine.go:49: EvalRoutineExpr()
github.com/cockroachdb/cockroach/pkg/sql/sem/eval/expr.go:625: EvalRoutineExpr()
github.com/cockroachdb/cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/sem/tree/eval_expr_generated.go:346: Eval()
github.com/cockroachdb/cockroach/pkg/sql/sem/eval/expr.go:197: EvalCoalesceExpr()
github.com/cockroachdb/cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/sem/tree/eval_expr_generated.go:101: Eval()
github.com/cockroachdb/cockroach/pkg/sql/sem/eval/expr.go:26: Expr()
github.com/cockroachdb/cockroach/pkg/sql/execinfrapb/pkg/sql/execinfrapb/expr.go:229: RunFilter()
github.com/cockroachdb/cockroach/pkg/sql/execinfrapb/pkg/sql/execinfrapb/expr.go:218: EvalFilter()                                                                                                 [56/1891]
github.com/cockroachdb/cockroach/pkg/sql/rowexec/joinerbase.go:172: render()
github.com/cockroachdb/cockroach/pkg/sql/rowexec/hashjoiner.go:348: probeRow()
github.com/cockroachdb/cockroach/pkg/sql/rowexec/hashjoiner.go:188: Next()
github.com/cockroachdb/cockroach/pkg/sql/colexec/columnarizer.go:239: Next()
github.com/cockroachdb/cockroach/pkg/sql/colflow/stats.go:118: next()
github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:92: CatchVectorizedRuntimeError()
github.com/cockroachdb/cockroach/pkg/sql/colflow/stats.go:126: Next()
github.com/cockroachdb/cockroach/pkg/sql/colflow/flow_coordinator.go:250: nextAdapter()
github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:92: CatchVectorizedRuntimeError()
github.com/cockroachdb/cockroach/pkg/sql/colflow/flow_coordinator.go:254: next()
github.com/cockroachdb/cockroach/pkg/sql/colflow/flow_coordinator.go:286: Run()
github.com/cockroachdb/cockroach/pkg/sql/colflow/vectorized_flow.go:317: Run()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:902: Run()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1913: PlanAndRun()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1645: func3()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1648: PlanAndRunAll()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:2091: execWithDistSQLEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1649: 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:2980: execWithProfiling()

HINT: You have encountered an unexpected error.

Please check the public issue tracker to check whether this problem is
already tracked. If you cannot find it there, please report the error
with details by creating a new issue.

If you would rather not post publicly, please contact us directly
using the support form.

We appreciate your feedback.

If possible, provide steps to reproduce the behavior:

I build CockroachDB from the last commit version 8124bff, and run it with ./cockroach start-single-node --insecure

Expected behavior
A clear and concise description of what you expected to happen.
No error.

Environment:

  • CockroachDB version 8124bff
  • Server OS: Ubuntu 22.04
  • Client app CLI

Jira issue: CRDB-27198

@DerZc DerZc added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Apr 21, 2023
@blathers-crl
Copy link

blathers-crl bot commented Apr 21, 2023

Hello, I am Blathers. I am here to help you get the issue triaged.

Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here.

I have CC'd a few people who may be able to assist you:

  • @cockroachdb/sql-queries (found keywords: Vectorized,distsql,plan)
  • @dhartunian (found keywords: metrics)

If we have not gotten back to your issue within a few business days, you can try the following:

  • Join our community slack channel and ask on #cockroachdb.
  • Try find someone from here if you know they worked closely on the area and CC them.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels Apr 21, 2023
@knz
Copy link
Contributor

knz commented Apr 21, 2023

Very nice find. Thank you!

cc @mgartner for triage.

@knz knz added the T-sql-queries SQL Queries Team label Apr 21, 2023
@blathers-crl blathers-crl bot added this to Triage in SQL Queries Apr 21, 2023
@michae2 michae2 added the A-sql-optimizer SQL logical planning and optimizations. label Apr 21, 2023
@blathers-crl
Copy link

blathers-crl bot commented Apr 24, 2023

Hi @mgartner, please add branch-* labels to identify which branch(es) this release-blocker affects.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@mgartner mgartner added branch-release-23.1 Used to mark GA and release blockers and technical advisories for 23.1 branch-release-23.1.0 labels Apr 24, 2023
@mgartner mgartner self-assigned this Apr 24, 2023
@mgartner mgartner moved this from Triage to Active in SQL Queries Apr 24, 2023
@mgartner
Copy link
Collaborator

Simplified reproduction:

CREATE TABLE t1 (i INT);
CREATE TABLE t2 (i INT);

INSERT INTO t1 (i) VALUES (1);
INSERT INTO t2 (i) VALUES (1);

SELECT t2.i FROM t1
FULL JOIN t2 ON t2.i IN (
  SELECT t2.i FROM t2, t1
  WHERE t1.i = 0
    OR t2.i IN (SELECT t2.i FROM t2)
);

@mgartner
Copy link
Collaborator

Removing the GA-blocker label. This is very minor - it's an internal error instead of a user-error "could not decorrelate subquery". This can wait until 23.1.1.

craig bot pushed a commit that referenced this issue Apr 26, 2023
102336: opt: fix internal error when planning correlated ANY subqueries r=mgartner a=mgartner

This commit fixes a bug where a decorrelation error was not returned
when trying to build uncorrelated ANY subqueries within a
lazily-evaluated routine, which is not yet supported. Instead of the
error, the ANY subquery would be planned as an eagerly-evaluate
subquery. This violated the requirement that no eagerly-evaluated
subqueries are planned within a lazily-evaluated routine, and caused an
internal error.

Fixes #101980

Release note (bug fix): A minor bug has been fixed that caused an
internal error for some queries with nested subqueries instead of the
more appropriate "could not decorrelate subquery" error. This bug was
only present in pre-release alpha and beta versions of 23.1.


Co-authored-by: Marcus Gartner <marcus@cockroachlabs.com>
@craig craig bot closed this as completed in 8bcc6e4 Apr 26, 2023
SQL Queries automation moved this from Active to Done Apr 26, 2023
blathers-crl bot pushed a commit that referenced this issue Apr 26, 2023
This commit fixes a bug where a decorrelation error was not returned
when trying to build uncorrelated ANY subqueries within a
lazily-evaluated routine, which is not yet supported. Instead of the
error, the ANY subquery would be planned as an eagerly-evaluate
subquery. This violated the requirement that no eagerly-evaluated
subqueries are planned within a lazily-evaluated routine, and caused an
internal error.

Fixes #101980

Release note (bug fix): A minor bug has been fixed that caused an
internal error for some queries with nested subqueries instead of the
more appropriate "could not decorrelate subquery" error. This bug was
only present in pre-release alpha and beta versions of 23.1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-optimizer SQL logical planning and optimizations. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-community Originated from the community T-sql-queries SQL Queries Team X-blathers-triaged blathers was able to find an owner
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants