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

Crashing by EXPLAIN Statement #83965

Closed
bajinsheng opened this issue Jul 7, 2022 · 3 comments · Fixed by #84169
Closed

Crashing by EXPLAIN Statement #83965

bajinsheng opened this issue Jul 7, 2022 · 3 comments · Fixed by #84169
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

Comments

@bajinsheng
Copy link

bajinsheng commented Jul 7, 2022

Describe the problem

An EXPLAIN statement triggers a crash.

To Reproduce

CREATE TABLE t0 (c0 INT);
CREATE TABLE t1 (c0 INT);
CREATE TABLE t2 (c0 INT);
CREATE TABLE t3 (c0 INT);
CREATE TABLE t4 (c0 VARBIT(1)[]);
CREATE TABLE t5 (c0 INT);

EXPLAIN SELECT bool_and(t4.c0 < t4.c0) FROM t5, t0, t2, t1, t3, t4; -- runtime error: index out of range [1] with length 1

Expected behavior
No error.

Additional data / screenshots

ERROR: a SQL panic has occurred while executing the following statement:
EXPLAIN SELECT bool_and(t4.c0 < t4.c0) FROM t5, t0, t2, t1, t3, t4
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:755
| [...repeated from below...]
Wraps: (2) while executing: EXPLAIN SELECT bool_and(. < .) FROM _, _, _, _, _, _
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:755
| runtime.gopanic
| GOROOT/src/runtime/panic.go:1038
| runtime.goPanicIndex
| GOROOT/src/runtime/panic.go:90
| github.com/cockroachdb/cockroach/pkg/sql/opt/indexrec.(*HypotheticalTable).Column
| github.com/cockroachdb/cockroach/pkg/sql/opt/indexrec/hypothetical_table.go:110
| github.com/cockroachdb/cockroach/pkg/sql/opt.(*Metadata).UpdateTableMeta
| github.com/cockroachdb/cockroach/pkg/sql/opt/metadata.go:618
| github.com/cockroachdb/cockroach/pkg/sql.(*optPlanningCtx).makeQueryIndexRecommendation
| github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:737
| github.com/cockroachdb/cockroach/pkg/sql.(*optPlanningCtx).buildExecMemo
| github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:560
| github.com/cockroachdb/cockroach/pkg/sql.(*planner).makeOptimizerPlan
| github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:225
| github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).makeExecPlan
| github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1363
| github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).dispatchToExecutionEngine
| github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1045
| github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execStmtInOpenState
| github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:690
| github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execStmt
| github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:145
| github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execCmd.func1
| github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1892
| github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).execCmd
| github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1896
| github.com/cockroachdb/cockroach/pkg/sql.(*connExecutor).run
| github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1818
| github.com/cockroachdb/cockroach/pkg/sql.(*Server).ServeConn
| github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:757
| github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*conn).processCommandsAsync.func1
| github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:724
| runtime.goexit
| GOROOT/src/runtime/asm_amd64.s:1581
Wraps: (4) runtime error: index out of range [1] with length 1
Error types: (1) *withstack.withStack (2) *safedetails.withSafeDetails (3) *withstack.withStack (4) runtime.boundsError

Environment:

  • CockroachDB version [02dcb38]
  • Server OS: [Ubuntu 20.04]
  • Client app [cockroach sql]

Additional context

Jira issue: CRDB-17374

@bajinsheng bajinsheng added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Jul 7, 2022
@blathers-crl
Copy link

blathers-crl bot commented Jul 7, 2022

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 otan.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels Jul 7, 2022
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Jul 7, 2022
@mgartner mgartner self-assigned this Jul 8, 2022
@mgartner
Copy link
Collaborator

Thank you for the report! We have identified the bug and the fix in #84169 should merge soon.

craig bot pushed a commit that referenced this issue Jul 11, 2022
83719: storage: remove dependency to sql/catalog/bootstrap r=Xiang-Gu a=Xiang-Gu

Previously, tests in `pkg/storage` depended on `sql/catalog/bootstrap`.
This was inadequate/weird because `storage` is a much lower layer in the
architectural stack. It will also help prevent dependency cycles in
other PRs when we introduce depencies (see #82172 if interested).

Release note: None

83958: colexecbase: add all remaining casts from strings r=yuzefovich a=yuzefovich

**tree: minor cleanup**

This commit does a few minor things:
- actually uses the error in a few places when constructing a ParseError
- refactors some of the interval-parsing functions to expose them to be
used in the follow-up commit
- extracts a helper method to construct an error when timestamp exceeds
bounds.

Release note: None

**colexecbase: sort native cast info lexicographically**

This commit sorts the information about natively supported casts
lexicographically so that it is easier to see what is actually
supported. This is simply a mechanical change.

Release note: None

**colexecbase: add all remaining casts from strings**

This commit adds the native casts from strings to all remaining
natively-supported types (dates, decimals, floats, ints, intervals,
timestamps, jsons).

I was inspired to do this because the combination of this
commit and the vectorized rendering on top of the wrapped row-by-row
processors would expose some bugs (e.g. #83094).

Addresses: #48135.

Release note: None

83984: storageccl: use NewPebbleIterator in restore data processor r=erikgrinaker a=msbutler

This PR replaces the multiIterator used in the restore data processor with the
PebbleSSTIterator, which has baked in range key support.

This patch is apart of a larger effort to teach backup and restore about MVCC
bulk operations. Next, the readAsOfIterator will need to learn how to
deal with range keys.

Informs #71155

Release note: none

84049: sql: fix memory accounting of prepared statements and portals in error cases r=yuzefovich a=yuzefovich

**sql: make sure to close mem acc of prepared stmt in case of an error**

Previously, it was possible that we would not close the memory account
created for a prepared statement when an error is encountered. This was
the case because we would not include the prepared stmt into the prep
stmts namespace, so it would just get lost. However, up until recently
this was not an issue since we mistakenly cleared that memory account
when creating the prepared statement.

Release note: None

**sql: only increment ref count of prep stmt in non-error case of portals**

Previously, it was possible to "leak" a reference to a prepared
statement if we made a portal from it (i.e. took a reference to the
prepared statement) and the memory reservation was denied. This could
lead to "leftover bytes" errors when stopping the "session" monitors.
However, the impact is minor because on release builds we'd still return
those "leftover bytes" and would just file a sentry issue. This is now
fixed.

Fixes: #83935

Release note: None

84097: DOC-4899: Remove linking on subdirectory from show_backup diagram r=RichardJCai a=nickvigilante

Release note: None

84143: Revert "kvstreamer: reuse incomplete Get requests on resume batches" r=yuzefovich a=yuzefovich

This reverts commit 21f2390.

Previously, I didn't realize that the KV layer would modify all requests
included into the BatchRequest in `txnSeqNumAllocator`, so we cannot
reuse even incomplete GetRequests. It is unfortunate, but not a big
deal.

Fixes: #83974.

Release note: None

84169: opt: fix incorrect column indexing in index recommendations r=mgartner a=mgartner

#### opt: fix incorrect column indexing in index recommendations

Fixes #83965

Release note (bug fix): A minor bug has been fixed that caused internal
errors and poor index recommendations when running `EXPLAIN` statements.

#### opt: clarify logic in Metadata.UpdateTableMeta

Release note: None


84188: roachtest: update supported tag for gorm r=ZhouXing19 a=ZhouXing19

fixes #83794
fixes #83797
fixes #83885

Release note: None

Co-authored-by: Xiang Gu <[email protected]>
Co-authored-by: Yahor Yuzefovich <[email protected]>
Co-authored-by: Michael Butler <[email protected]>
Co-authored-by: Nick Vigilante <[email protected]>
Co-authored-by: Marcus Gartner <[email protected]>
Co-authored-by: Jane Xing <[email protected]>
@craig craig bot closed this as completed in f678273 Jul 11, 2022
mgartner added a commit to mgartner/cockroach that referenced this issue Jul 11, 2022
Fixes cockroachdb#83965

Release note (bug fix): A minor bug has been fixed that caused internal
errors and poor index recommendations when running `EXPLAIN` statements.
@bajinsheng
Copy link
Author

Thanks for your prompt reply!

@mgartner mgartner moved this to Done in SQL Queries Jul 24, 2023
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