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: null rejection requested on non-null column #100559

Closed
DerZc opened this issue Apr 4, 2023 · 3 comments · Fixed by #100565
Closed

internal error: null rejection requested on non-null column #100559

DerZc opened this issue Apr 4, 2023 · 3 comments · Fixed by #100565
Assignees
Labels
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 4, 2023

Describe the problem

The following program triggers an internal error:

CREATE DATABASE database5;
USE database5;
CREATE TABLE t0 (c0 INTERVAL);
CREATE TABLE t1 (c0 INTERVAL);
CREATE TABLE t2 (c0 FLOAT);
SELECT t1.c0 AS c0 FROM t0, t2 FULL OUTER JOIN t1 ON true WHERE (((t0.c0) IN (t1.c0)) AND ((t2.c0) IN (SELECT STDDEV(t2.c0) FROM t2)));

This is the error message:

> SELECT t1.c0 AS c0 FROM t0, t2 FULL OUTER JOIN t1 ON true WHERE (((t0.c0) IN (t1.c0)) AND ((t2.c0) IN (SELECT STDDEV(t2.c0) FROM t2)));
ERROR: internal error: null rejection requested on non-null column
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/opt/norm/reject_nulls_funcs.go:218: DeriveRejectNullCols()
github.com/cockroachdb/cockroach/pkg/sql/opt/norm/reject_nulls_funcs.go:25: RejectNullCols()
github.com/cockroachdb/cockroach/bazel-out/k8-opt/bin/pkg/sql/opt/norm/factory.og.go:3474: ConstructInnerJoin()
github.com/cockroachdb/cockroach/bazel-out/k8-opt/bin/pkg/sql/opt/xform/explorer.og.go:1677: exploreSemiJoin()
github.com/cockroachdb/cockroach/bazel-out/k8-opt/bin/pkg/sql/opt/xform/explorer.og.go:34: exploreGroupMember()
github.com/cockroachdb/cockroach/pkg/sql/opt/xform/explorer.go:181: exploreGroup()
github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:528: optimizeGroup()
github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:291: optimizeExpr()
github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:570: optimizeGroupMember()
github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:515: optimizeGroup()
github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:261: Optimize()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:575: buildExecMemo()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:232: makeOptimizerPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1474: makeExecPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1086: dispatchToExecutionEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:696: execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:131: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:2428: execWithProfiling()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:130: execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1973: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1977: execCmd()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1898: run()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:857: ServeConn()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:730: func1()
GOROOT/src/runtime/asm_amd64.s:1594: goexit()

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.

To Reproduce

I build cockroach from the last commit in github repo (07c7d4b), but this bug can reproduce with the last release version v22.2.7.

I run cockroach in a single machine, and execute the query with CLI cockroach sql --echo-sql --insecure --port 26257 --user root < database5.sql

Expected behavior
No error.

Environment:

  • CockroachDB version [last commit version and last release version v22.2.7]
  • Server OS: [ubuntu 22.04]
  • Client app [CLI]

Jira issue: CRDB-26492

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

blathers-crl bot commented Apr 4, 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: optimizer,plan)

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 4, 2023
@DrewKimball
Copy link
Collaborator

Hi @DerZc, thanks for submitting this find! It looks like the problem is that our null-rejection rules (which simplify outer joins like LEFT JOIN into non-outer joins like INNER JOIN) assume that a child operator should always carry out null-rejection before its parent. This assumption is violated for cases like this one, where query plan exploration uncovers that null-rejection is possible after normalization fails to do so.

@DerZc
Copy link
Author

DerZc commented Apr 4, 2023

Hi @DrewKimball, I got it, thank you for such a quick and detailed explanation!

@DrewKimball DrewKimball added this to Triage in SQL Queries via automation Apr 4, 2023
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Apr 4, 2023
@DrewKimball DrewKimball self-assigned this Apr 4, 2023
@DrewKimball DrewKimball moved this from Triage to Active in SQL Queries Apr 4, 2023
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Apr 4, 2023
It is possible for exploration rules to reveal opportunities to
null-reject (simplify) an outer join that were not visible during
normalization. Previously, this would cause an internal error, since
it was assumed null-rejection would never be requested by an expression
that can prove the requested column is non-null. This patch removes the
assertion and instead removes any proven non-null columns from the
requested null-rejection column set. Note that this solution is
orthogonal to improving null-rejection during normalization - one
instance of this is tracked in cockroachdb#100564.

Fixes cockroachdb#100559

Release note (bug fix): Fixed a bug existing since before 22.1 that
could cause an internal error in rare cases for a query with outer joins
that can be simplified to non-outer joins and at least one semi-join.
craig bot pushed a commit that referenced this issue Apr 4, 2023
99423: roachprod: apply (VM) labels to persistent disks r=renatolabs a=srosenberg

Previously, roachprod provisioning in GCE and AWS didn't propagate VM labels to the corresponding persistent disks. In GCE, the labels specified via
 `--labels` [1] are applied only to the VM instances, and not their persistent disks.
There is further evidence [2] this isn't supported in GCE, although the documentation doesn't make it explicit. In AWS, `--tag-specifications` supports multiple resources as of ~2017; roachprod was passing only 'ResourceType=instance'. In Azure, labels appear to be propagated by default; i.e., no change is required.

The missing storage labels made it difficult to accurately determine the cost of a roachprod cluster, based on the usage label. This change ensures the usage (and other) labels are propagated to all persistent disks provisioned via roachprod.

Resolves: #90592

Epic: CRDB-10428
Release note: None

[1] https://cloud.google.com/sdk/gcloud/reference/compute/instances/create
[2] https://issuetracker.google.com/issues/163152709

99987: logictest: correctly disable auto stats on system tables r=yuzefovich a=yuzefovich

This commit fixes an oversight of 9c6fcd1
where we attempted to disable the auto stats collection on system tables
by overriding the corresponding cluster setting before the cluster is
started. The problem with that change was that we overrode the cluster
setting object that is only used by the temp storage config and has no
bearing on the settings used by each node in the cluster. As it turns
out, previously we didn't explicitly initialize the `Settings` field of
the arguments for each node, so a fresh copy was always created. This
oversight is now fixed - we explicitly create a settings object for each
node / tenant and then override the auto stats on system tables to be
disabled on it.

Fixes: #99897.

Release note: None

100565: opt: fix internal error when exploration uncovers null-rejection r=DrewKimball a=DrewKimball

It is possible for exploration rules to reveal opportunities to null-reject (simplify) an outer join that were not visible during normalization. Previously, this would cause an internal error, since it was assumed null-rejection would never be requested by an expression that can prove the requested column is non-null. This patch removes the assertion and instead removes any proven non-null columns from the requested null-rejection column set. Note that this solution is orthogonal to improving null-rejection during normalization - one instance of this is tracked in #100564.

Fixes #100559

Release note (bug fix): Fixed a bug existing since before 22.1 that could cause an internal error in rare cases for a query with outer joins that can be simplified to non-outer joins and at least one semi-join.

Co-authored-by: Stan Rosenberg <stan.rosenberg@gmail.com>
Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
Co-authored-by: Drew Kimball <drewk@cockroachlabs.com>
@craig craig bot closed this as completed in 02eb239 Apr 5, 2023
SQL Queries automation moved this from Active to Done Apr 5, 2023
blathers-crl bot pushed a commit that referenced this issue Apr 5, 2023
It is possible for exploration rules to reveal opportunities to
null-reject (simplify) an outer join that were not visible during
normalization. Previously, this would cause an internal error, since
it was assumed null-rejection would never be requested by an expression
that can prove the requested column is non-null. This patch removes the
assertion and instead removes any proven non-null columns from the
requested null-rejection column set. Note that this solution is
orthogonal to improving null-rejection during normalization - one
instance of this is tracked in #100564.

Fixes #100559

Release note (bug fix): Fixed a bug existing since before 22.1 that
could cause an internal error in rare cases for a query with outer joins
that can be simplified to non-outer joins and at least one semi-join.
blathers-crl bot pushed a commit that referenced this issue Apr 5, 2023
It is possible for exploration rules to reveal opportunities to
null-reject (simplify) an outer join that were not visible during
normalization. Previously, this would cause an internal error, since
it was assumed null-rejection would never be requested by an expression
that can prove the requested column is non-null. This patch removes the
assertion and instead removes any proven non-null columns from the
requested null-rejection column set. Note that this solution is
orthogonal to improving null-rejection during normalization - one
instance of this is tracked in #100564.

Fixes #100559

Release note (bug fix): Fixed a bug existing since before 22.1 that
could cause an internal error in rare cases for a query with outer joins
that can be simplified to non-outer joins and at least one semi-join.
DrewKimball added a commit that referenced this issue Apr 18, 2023
It is possible for exploration rules to reveal opportunities to
null-reject (simplify) an outer join that were not visible during
normalization. Previously, this would cause an internal error, since
it was assumed null-rejection would never be requested by an expression
that can prove the requested column is non-null. This patch removes the
assertion and instead removes any proven non-null columns from the
requested null-rejection column set. Note that this solution is
orthogonal to improving null-rejection during normalization - one
instance of this is tracked in #100564.

Fixes #100559

Release note (bug fix): Fixed a bug existing since before 22.1 that
could cause an internal error in rare cases for a query with outer joins
that can be simplified to non-outer joins and at least one semi-join.
DrewKimball added a commit that referenced this issue Apr 18, 2023
It is possible for exploration rules to reveal opportunities to
null-reject (simplify) an outer join that were not visible during
normalization. Previously, this would cause an internal error, since
it was assumed null-rejection would never be requested by an expression
that can prove the requested column is non-null. This patch removes the
assertion and instead removes any proven non-null columns from the
requested null-rejection column set. Note that this solution is
orthogonal to improving null-rejection during normalization - one
instance of this is tracked in #100564.

Fixes #100559

Release note (bug fix): Fixed a bug existing since before 22.1 that
could cause an internal error in rare cases for a query with outer joins
that can be simplified to non-outer joins and at least one semi-join.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

2 participants