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: panic when interacting with BIT array #95543

Closed
SteveLeungYL opened this issue Jan 19, 2023 · 1 comment · Fixed by #96002
Closed

sql: panic when interacting with BIT array #95543

SteveLeungYL opened this issue Jan 19, 2023 · 1 comment · Fixed by #96002
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

Comments

@SteveLeungYL
Copy link

SteveLeungYL commented Jan 19, 2023

Describe the problem

The latest version of the CockroachDB (9735954) shows Internal Error when executing the following query:

CREATE TABLE v0 (c1 BIT PRIMARY KEY ); -- PRIMARY KEY is required to trigger the bug
SELECT * FROM [SHOW RANGE FROM TABLE v0 FOR ROW ( b'\x68')];

To Reproduce

Here is the detail steps to reproduce the bug.

  1. In operating system Ubuntu 20.04, download the CockroachDB source code from the github source.
  2. Use the latest version of the CockroachDB code (tested version: 9735954)
  3. Directly make install in the root repository folder.
  4. Run ./cockroach demo, and then paste the PoC query to the cockroach cli environment.
  5. Observe the Internal Error and log the stack information.

Expected behavior
The select statement should be executed correctly and outputs empty result.

Additional data / screenshots

Here is the outputted stack trace:

[email protected]:26257/movr> CREATE TABLE v0 (c1 BIT PRIMARY KEY ); -- PRIMARY KEY is required to trigger the bug
CREATE TABLE

Time: 3ms total (execution 3ms / network 0ms)

[email protected]:26257/movr> SELECT * FROM [SHOW RANGE FROM TABLE v0 FOR ROW ( b'\x68')];
ERROR: internal error: runtime error: invalid memory address or nil pointer dereference
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/util/errorutil/catch.go:29: ShouldCatch()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:193: func1()
runtime/panic.go:884: gopanic()
runtime/panic.go:260: panicmem()
runtime/signal_unix.go:835: sigpanic()
github.com/cockroachdb/cockroach/pkg/sql/sem/tree/parse_string.go:129: FormatBitArrayToType()
github.com/cockroachdb/cockroach/pkg/sql/sem/eval/cast.go:153: performCastWithoutPrecisionTruncation()
github.com/cockroachdb/cockroach/pkg/sql/sem/eval/cast.go:67: PerformCast()
github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtins.go:5087: 1()
github.com/cockroachdb/cockroach/pkg/sql/evalcatalog/encode_table_index_key.go:114: EncodeTableIndexKey()
github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtins.go:5082: func239()
github.com/cockroachdb/cockroach/pkg/sql/sem/eval/expr.go:479: EvalFuncExpr()
github.com/cockroachdb/cockroach/pkg/sql/sem/tree/eval_expr_generated.go:276: Eval()
github.com/cockroachdb/cockroach/pkg/sql/sem/eval/expr.go:26: Expr()
github.com/cockroachdb/cockroach/pkg/sql/opt/norm/fold_constants_funcs.go:687: FoldFunction()
github.com/cockroachdb/cockroach/pkg/sql/opt/norm/factory.og.go:20127: ConstructFunction()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/scalar.go:569: buildFunction()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/scalar.go:333: buildScalar()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/scalar.go:321: buildScalar()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/scalar.go:126: buildScalar()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/util.go:463: resolveAndBuildScalar()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1165: buildWhere()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1047: buildSelectClause()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:992: buildSelectStmtWithoutParens()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:961: func1()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/with.go:117: processWiths()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:960: buildSelect()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:307: buildStmt()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:405: buildStmt()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:172: buildDataSource()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:67: buildDataSource()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1219: buildFromTablesRightDeep()

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-1099-g97359549f1
Build Time:       2023/01/19 20:06:56
Distribution:     CCL
Platform:         linux arm64 (aarch64-linux-gnu)
Go Version:       go1.19
C Compiler:       gcc 9.4.0
Build Commit ID:  97359549f19a64113965331164e7aff005a766be
Build Type:       development

Additional context

The Internal Error can be reproduced by CockroachDB v23.1 Testing Releases , v22.2.2 and v22.1. We haven't tested earlier versions.

Jira issue: CRDB-23581

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

blathers-crl bot commented Jan 19, 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 was unable to automatically find someone to ping.

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-untriaged blathers was unable to find an owner labels Jan 19, 2023
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Jan 19, 2023
@yuzefovich yuzefovich removed the X-blathers-untriaged blathers was unable to find an owner label Jan 20, 2023
@msirek msirek self-assigned this Jan 26, 2023
craig bot pushed a commit that referenced this issue Jan 27, 2023
95153: sql/schemachanger: Drop function in declarative schema changer r=chengxiong-ruan a=chengxiong-ruan

This pr contains 3 commits:
1. add function descriptor elements definition
2. a simple rename of RemoveViewBackReferencesInRelation to RemoveBackReferencesInRelation
3. drop function logics
Part of: https://cockroachlabs.atlassian.net/browse/CRDB-19495

95524: kvserver: fix race on Replica.tenantLimiter r=tbg a=pavelkalinnikov

When Replica is being destroyed, it can set tenantLimiter to nil. However, all accessors assume synchronization through IsInitialized atomic check and that this field can't be modified after the replica is initialized.

There is no particular need in nullifying this limiter, the replica is going away soon, so this commit removes this line in order to fix the data race.

Fixes #95345
Epic: none
Release note: none

96002: eval: fix internal error casting bytes to bit r=msirek a=msirek

Fixes #95543

Release note (bug fix): This patch fixes an internal error which may occur in the SHOW RANGE FROM TABLE statement when the FOR ROW clause specifies a BYTE literal and the corresponding column data type is BIT.

96030: docgen: remove redundant SQL diagrams r=nickvigilante a=taroface

Diagrams updated in #95591 were not generating HTML files as intended because of some redundant lines in the code. This removes the redundancies per `@nickvigilante.`

Epic: none

Release note: none

Release justification: non-production code change

96048: optbuilder: fix internal error in LATERAL queries with redundant function calls r=DrewKimball,mgartner a=msirek

Fixes #95615

Function `optbuilder.Builder.buildZip` may try to build 2 identical function
calls into 2 zip expressions, each one adding one or more columns to the
output. However, if buildZip's called to `buildScalar` recognizes a scalar
expression has already been built, it skips adding a new output columns and
returns the previously-built output column. This mismatch in the number of
output columns actually built, and the number of columns communicated to
the parent expression via `outScope` confuses the execution engine, and in
this case we error out because the expected data type of one column doesn't
match the actual data type.

The fix is to skip building zip expressions with redundant expressions which
already exist in `outScope`.

Release note (bug fix): This patch fixes rare internal errors in LATERAL
queries with redundant function calls.

96099: upgrades: share a column family for the new tenant columns r=ajwerner a=knz

Fixes #96093.

The previous change in that area was causing the new columns to be (implicitly) added into separate column families. However, we're expecting (from the bootstrap schema) to use a single column family for them. This patch fixes that.

Release note: None

Co-authored-by: Chengxiong Ruan <[email protected]>
Co-authored-by: Pavel Kalinnikov <[email protected]>
Co-authored-by: Tobias Grieger <[email protected]>
Co-authored-by: Mark Sirek <[email protected]>
Co-authored-by: Ryan Kuo <[email protected]>
Co-authored-by: Raphael 'kena' Poss <[email protected]>
@craig craig bot closed this as completed in c335a4e Jan 27, 2023
msirek pushed a commit to msirek/cockroach that referenced this issue Jan 27, 2023
Fixes cockroachdb#95543

Release note (bug fix): This patch fixes an internal error which may
occur in the SHOW RANGE FROM TABLE statement when the FOR ROW clause
specifies a BYTE literal and the corresponding column data type is BIT.
@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
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants