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

sql: Internal Error when executing query #96288

Closed
SteveLeungYL opened this issue Jan 31, 2023 · 9 comments · Fixed by #98092 or #100776
Closed

sql: Internal Error when executing query #96288

SteveLeungYL opened this issue Jan 31, 2023 · 9 comments · Fixed by #98092 or #100776
Assignees
Labels
branch-master Failures and bugs on the master branch. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. E-quick-win Likely to be a quick win for someone experienced. GA-blocker O-community Originated from the community T-sql-queries SQL Queries Team X-blathers-triaged blathers was able to find an owner

Comments

@SteveLeungYL
Copy link

SteveLeungYL commented Jan 31, 2023

Describe the problem

The latest version of the CockroachDB (version v22.2.3 and v23.1.0 alpha) shows Internal Error when executing the following query:

To Reproduce

CREATE TABLE v0 (c1 BYTES PRIMARY KEY, c2 TIMESTAMP, INDEX i3(c2));
SELECT * FROM v0 WHERE (c1 = c1 AND c2 = '01-31-2023 00:00:00'::TIMESTAMP) OR (c1 = b'00' AND c1 = b'0') OR (c1 IS NULL AND c2 IS NULL );

To Reproduce

Here is the detail steps to reproduce the bug.

  1. In operating system Ubuntu 20.04 LTS, download the CockroachDB source code from the github source.
  2. Use the latest version of the CockroachDB code (tested version: 778b6fb) (I am not able to compile the latest master branch of CockroachDB through make)
  3. Directly make install in the root repository folder.
  4. Alternatively, we can download the pre-build CockroachDB binaries (v22.2.3 and v23.1.0 alpha) from link
  5. Run ./cockroach demo, and then paste the PoC query to the cockroach cli environment.
  6. Observe the Internal Error and log the stack information.

Expected behavior
The SELECT statement should return empty result, indicating that no data in the table v0 is matching the given constraints.

Additional data / screenshots

Here is the outputted stack trace from version: 778b6fb

ERROR: internal error: no output column equivalent to 6
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/opt/ordering/ordering.go:370: remapProvided()
github.com/cockroachdb/cockroach/pkg/sql/opt/ordering/project.go:93: projectBuildProvided()
github.com/cockroachdb/cockroach/pkg/sql/opt/ordering/ordering.go:90: BuildProvided()
github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:816: setLowestCostTree()
github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:803: setLowestCostTree()
github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:274: Optimize()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:584: buildExecMemo()
github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:237: makeOptimizerPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1532: makeExecPlan()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1139: dispatchToExecutionEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:744: execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:130: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:2527: execWithProfiling()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:129: execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1959: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1964: execCmd()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1882: run()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:836: ServeConn()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:731: func1()
runtime/asm_arm64.s:1165: goexit()

HINT: You have encountered an unexpected error.

Environment:

  • CockroachDB version: v23.1.0-alpha
  • Server OS: Ubuntu 20.04 LTS
  • Client app: CockroachDB demo command. (./cockroach demo)
  • Detailed CockroachDB version output:
cockroach version details:
Build Tag:        v23.1.0-alpha.1-1216-g778b6fbb15
Build Time:       2023/01/24 16:47:34
Distribution:     CCL
Platform:         linux arm64 (aarch64-linux-gnu)
Go Version:       go1.19
C Compiler:       gcc 9.4.0
Build Commit ID:  778b6fbb15ebc9dfcb519b47b0afdeda9aade3a8
Build Type:       development

Additional context

The bug can be reproduced by CockroachDB release version: CockroachDB v23.1 Testing Releases , v22.2.3, v22.2.2 and v22.2.1. However, the PoC does work find in v22.2.0, The bug may be introduced in a commit between the time frame of v22.2.2 and v22.2.1.

Jira issue: CRDB-24046

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

blathers-crl bot commented Jan 31, 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 Jan 31, 2023
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Jan 31, 2023
@michae2 michae2 added the E-quick-win Likely to be a quick win for someone experienced. label Feb 7, 2023
@msirek msirek self-assigned this Mar 6, 2023
@knz knz added the GA-blocker label Mar 6, 2023
@blathers-crl
Copy link

blathers-crl bot commented Mar 6, 2023

Hi @knz, 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.

@knz knz added the branch-master Failures and bugs on the master branch. label Mar 6, 2023
@cucaroach
Copy link
Contributor

Bisected to: #87735

@cucaroach cucaroach assigned cucaroach and unassigned msirek Mar 6, 2023
cucaroach added a commit to cucaroach/cockroach that referenced this issue Mar 6, 2023
In PR cockroachdb#87735 we allowed extra cols that were constant constrained provide
orderings but the remapOrdering code couldn't handle these extra
columns and would panic. Fix it by allowing these extra columns to be
remapped.

Fixes: cockroachdb#96288
craig bot pushed a commit that referenced this issue Mar 6, 2023
98092: sql/opt: fix "no output column" internal error r=cucaroach a=cucaroach

In PR #87735 we allowed extra cols that were constant constrained provide
orderings but the remapOrdering code couldn't handle these extra
columns and would panic. Fix it by allowing these extra columns to be
remapped.

Fixes: #96288

Co-authored-by: Tommy Reilly <[email protected]>
@craig craig bot closed this as completed in 2372d7a Mar 6, 2023
cucaroach added a commit to cucaroach/cockroach that referenced this issue Mar 7, 2023
In PR cockroachdb#87735 we allowed extra cols that were constant constrained provide
orderings but the remapOrdering code couldn't handle these extra
columns and would panic. Fix it by allowing these extra columns to be
remapped.

Fixes: cockroachdb#96288
@cucaroach
Copy link
Contributor

Reopen to explore Drew's thoughts on #98092

@cucaroach cucaroach reopened this Mar 8, 2023
@mgartner
Copy link
Collaborator

@DrewKimball is there still something we need to do here?

What was the motiviation for the GA-blocker label? It looks like this reproduces on v22.2.

@DrewKimball
Copy link
Collaborator

is there still something we need to do here?

We should probably try and figure out why we're unable to tell that a column is constant/redundant in remapProvided. @cucaroach do you have bandwidth to do that? I can take a look if not.

@cucaroach
Copy link
Contributor

I was hoping to get to it later this week but focusing on getting copy in before branch cut ATM.

@DrewKimball
Copy link
Collaborator

Looking into this one. There's a filter ((c1:5 IS NULL) AND (c2:6 IS NULL)) OR (((c1:5 IS DISTINCT FROM CAST(NULL AS BYTES)) OR CAST(NULL AS BOOL)) AND (c2:6 = '2023-01-31 00:00:00')) [outer=(5,6), constraints=(/6: [/NULL - /NULL] [/'2023-01-31 00:00:00' - /'2023-01-31 00:00:00'])] that could be simplified to c2:6 = '2023-01-31 00:00:00' but isn't. At some point it is used to build a constrained scan, at which the optimizer is able to prove that the rest of the filter is unnecessary. The new constrained scan "knows" that column 6 is constant and therefore optional in any ordering, but none of its ancestor operators can prove this.

While this probably points to some missing filter simplification logic, we can't guarantee that we'll prevent all cases like this, where transformations further down in the tree expose properties that can't be (or weren't) proven further up the tree. The ordering logic needs to be able to correctly handle these cases.

@DrewKimball
Copy link
Collaborator

It's possible to trigger the error even with the fix in #98092 with this case:

CREATE TABLE v0 (c1 BYTES PRIMARY KEY, c2 TIMESTAMP, INDEX i3(c2));
SELECT c1 FROM v0 WHERE (c1 = c1 AND c2 = '01-31-2023 00:00:00'::TIMESTAMP) OR (c1 = b'00' AND c1 = b'0') OR (c1 IS NULL AND c2 IS NULL ) ORDER BY c1;

@cucaroach cucaroach assigned DrewKimball and unassigned cucaroach Apr 4, 2023
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Apr 6, 2023
It is possible for some functional-dependency information to be visible
to a child operator but invisible to its parent. This could previously
cause panics when a child provided an ordering that could be proven to
satisfy the required ordering with the child FDs, but not with the
parent's FDs.

This patch adds a step to the logic that builds provided orderings that
ensures a provided ordering can be proven to respect the required ordering
without needing additional FD information. This ensures that a parent never
needs to know its child's FDs in order to prove that the provided ordering
is correct. The extra step is a no-op in the common case when the provided
ordering can already be proven to respect the required ordering.

Informs cockroachdb#85393
Informs cockroachdb#87806
Fixes cockroachdb#96288

Release note (bug fix): Fixed a rare internal error in the optimizer that has
existed since before version 22.1, which could occur while enforcing orderings
between SQL operators.
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Apr 6, 2023
This patch separates the responsibility of constructing the provided
ordering for each operator and verifying its correctness, from that of
remapping it to the set of output columns and simplifying it to reflect
known functional dependencies. This decreases the complexity of provided
ordering construction, and unifies the logic for ensuring provided
orderings can be mapped back to their required ordering choices.

Informs cockroachdb#96288

Release note: None
craig bot pushed a commit that referenced this issue Apr 10, 2023
100533: workload: jitter the teardown of connections to prevent thundering herd r=sean- a=sean-

This change upgrades workload's use of pgx from v4 to v5 in order to allow jittering the teardown of connections.  This change sets a max connection age of 5min and jitters the teardown by 30s.  Upgrading to pgx v5 also adds non-blocking pgxpool connection acquisition.

workload: add flags to manage the age and lifecycle of connection pool

Add flags to all workload types to specify:

* the max connection age: `--max-conn-lifetime duration`
* the max connection age jitter: `--max-conn-lifetime-jitter duration`
* the max connection idle time: `--max-conn-idle-time duration`
* the connection health check interval: `--conn-healthcheck-period duration`
* the min number of connections in the pool: `--min-conns int`

workload: add support for remaining pgx query modes

Add support for pgx.QueryExecModeCacheDescribe and pgx.QueryExecModeDescribeExec.  Previously, only three of the five query modes were available.

workload: fix race condition when recording histogram data

Release note (cli change): workload jitters teardown of connections to prevent thundering herd impacting P99 latency results.

Release note (cli change): workload utility now has flags to tune the connection pool used for testing.  See `--conn-healthcheck-period`, `--min-conns`, and the `--max-conn-*` flags for details.

Release note (cli change): workload now supports every [PostgreSQL query mode](https://github.com/jackc/pgx/blob/fa5fbed497bc75acee05c1667a8760ce0d634cba/conn.go#L167-L182) available via the underlying pgx driver.

100776: opt: fix ordering-related optimizer panics r=DrewKimball a=DrewKimball

It is possible for some functional-dependency information to be visible to a child operator but invisible to its parent. This could previously cause panics when a child provided an ordering that could be proven to satisfy the required ordering with the child FDs, but not with the parent's FDs.

This patch adds a step to the logic that builds provided orderings that ensures a provided ordering can be proven to respect the required ordering without needing additional FD information. This ensures that a parent never needs to know its child's FDs in order to prove that the provided ordering is correct. The extra step is a no-op in the common case when the provided ordering can already be proven to respect the required ordering.

Informs #85393
Informs #87806
Fixes #96288

Release note (bug fix): Fixed a rare internal error in the optimizer that has existed since before version 22.1, which could occur while enforcing orderings between SQL operators.

101076: autoconfig: prevent a data race in TestAutoConfig r=adityamaru a=knz

Needed for #101069.

The calls to Peek and Pop can run concurrently.

Release note: None
Epic: CRDB-23559

101078: roachtest: move copyfrom test suite to SQL Queries r=srosenberg a=nvanbenschoten

See https://cockroachlabs.slack.com/archives/C0168LW5THS/p1679508254391039.

Epic: None
Release note: None

Co-authored-by: Sean Chittenden <[email protected]>
Co-authored-by: Drew Kimball <[email protected]>
Co-authored-by: Raphael 'kena' Poss <[email protected]>
Co-authored-by: Nathan VanBenschoten <[email protected]>
@craig craig bot closed this as completed in b9b8da6 Apr 10, 2023
blathers-crl bot pushed a commit that referenced this issue Apr 10, 2023
It is possible for some functional-dependency information to be visible
to a child operator but invisible to its parent. This could previously
cause panics when a child provided an ordering that could be proven to
satisfy the required ordering with the child FDs, but not with the
parent's FDs.

This patch adds a step to the logic that builds provided orderings that
ensures a provided ordering can be proven to respect the required ordering
without needing additional FD information. This ensures that a parent never
needs to know its child's FDs in order to prove that the provided ordering
is correct. The extra step is a no-op in the common case when the provided
ordering can already be proven to respect the required ordering.

Informs #85393
Informs #87806
Fixes #96288

Release note (bug fix): Fixed a rare internal error in the optimizer that has
existed since before version 22.1, which could occur while enforcing orderings
between SQL operators.
blathers-crl bot pushed a commit that referenced this issue Apr 12, 2023
It is possible for some functional-dependency information to be visible
to a child operator but invisible to its parent. This could previously
cause panics when a child provided an ordering that could be proven to
satisfy the required ordering with the child FDs, but not with the
parent's FDs.

This patch adds a step to the logic that builds provided orderings that
ensures a provided ordering can be proven to respect the required ordering
without needing additional FD information. This ensures that a parent never
needs to know its child's FDs in order to prove that the provided ordering
is correct. The extra step is a no-op in the common case when the provided
ordering can already be proven to respect the required ordering.

Informs #85393
Informs #87806
Fixes #96288

Release note (bug fix): Fixed a rare internal error in the optimizer that has
existed since before version 22.1, which could occur while enforcing orderings
between SQL operators.
@mgartner mgartner moved this to Done in SQL Queries Jul 24, 2023
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Oct 25, 2023
It is possible for some functional-dependency information to be visible
to a child operator but invisible to its parent. This could previously
cause panics when a child provided an ordering that could be proven to
satisfy the required ordering with the child FDs, but not with the
parent's FDs.

This patch adds a step to the logic that builds provided orderings that
ensures a provided ordering can be proven to respect the required ordering
without needing additional FD information. This ensures that a parent never
needs to know its child's FDs in order to prove that the provided ordering
is correct. The extra step is a no-op in the common case when the provided
ordering can already be proven to respect the required ordering.

Informs cockroachdb#85393
Informs cockroachdb#87806
Fixes cockroachdb#96288

Release note (bug fix): Fixed a rare internal error in the optimizer that has
existed since before version 22.1, which could occur while enforcing orderings
between SQL operators.
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue Oct 26, 2023
It is possible for some functional-dependency information to be visible
to a child operator but invisible to its parent. This could previously
cause panics when a child provided an ordering that could be proven to
satisfy the required ordering with the child FDs, but not with the
parent's FDs.

This patch adds a step to the logic that builds provided orderings that
ensures a provided ordering can be proven to respect the required ordering
without needing additional FD information. This ensures that a parent never
needs to know its child's FDs in order to prove that the provided ordering
is correct. The extra step is a no-op in the common case when the provided
ordering can already be proven to respect the required ordering.

Informs cockroachdb#85393
Informs cockroachdb#87806
Fixes cockroachdb#96288

Release note (bug fix): Fixed a rare internal error in the optimizer that has
existed since before version 22.1, which could occur while enforcing orderings
between SQL operators.
blathers-crl bot pushed a commit that referenced this issue Nov 1, 2023
It is possible for some functional-dependency information to be visible
to a child operator but invisible to its parent. This could previously
cause panics when a child provided an ordering that could be proven to
satisfy the required ordering with the child FDs, but not with the
parent's FDs.

This patch adds a step to the logic that builds provided orderings that
ensures a provided ordering can be proven to respect the required ordering
without needing additional FD information. This ensures that a parent never
needs to know its child's FDs in order to prove that the provided ordering
is correct. The extra step is a no-op in the common case when the provided
ordering can already be proven to respect the required ordering.

Informs #85393
Informs #87806
Fixes #96288

Release note (bug fix): Fixed a rare internal error in the optimizer that has
existed since before version 22.1, which could occur while enforcing orderings
between SQL operators.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch-master Failures and bugs on the master branch. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. E-quick-win Likely to be a quick win for someone experienced. GA-blocker 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
7 participants