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: error caused by collated string comparison #56335

Closed
rafiss opened this issue Nov 5, 2020 · 2 comments · Fixed by #56352 or #62562
Closed

sql: error caused by collated string comparison #56335

rafiss opened this issue Nov 5, 2020 · 2 comments · Fixed by #56352 or #62562
Assignees
Labels
A-sql-typing SQLtype inference, typing rules, type compatibility. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Comments

@rafiss
Copy link
Collaborator

rafiss commented Nov 5, 2020

Describe the problem

A normal SELECT query over collated strings can cause an error. A customer bug report also claims there was a panic and node crash.

Even if only collatedstring{en-US-u-ks-level2} is used, the error message says that the query doesn't work because it thinks collatedstring{en-us-u-ks-level2} is being used.

ERROR: internal error: "$0" = 'bbb' COLLATE en_us_u_ks_level2: unsupported comparison operator: <collatedstring{en-US-u-ks-level2}> = <collatedstring{en_us_u_ks_level2}>
SQLSTATE: XX000
DETAIL: stack trace:
/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/expr.go:78: processExpression()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/expr.go:162: Init()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:108: Init()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:805: InitWithEvalCtx()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:775: Init()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowexec/tablereader.go:95: newTableReader()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowexec/processors.go:138: NewProcessor()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowflow/row_based_flow.go:228: makeProcessor()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowflow/row_based_flow.go:81: setupProcessors()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/rowflow/row_based_flow.go:64: Setup()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql/server.go:366: setupFlow()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql/server.go:480: SetupLocalSyncFlow()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:265: setupFlows()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:388: Run()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1008: PlanAndRun()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:903: execWithDistSQLEngine()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:800: dispatchToExecutionEngine()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:488: execStmtInOpenState()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:99: execStmt()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1356: execCmd()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1285: run()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:490: ServeConn()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:595: func1()
/usr/local/go/src/runtime/asm_amd64.s:1357: goexit()

To Reproduce

CREATE TABLE nocase_strings (s STRING COLLATE "en-US-u-ks-level2");
INSERT INTO nocase_strings VALUES ('Aaa' COLLATE "en-US-u-ks-level2"), ('Bbb' COLLATE "en-US-u-ks-level2");
SELECT s FROM nocase_strings WHERE s = ('bbb' COLLATE "en-US-u-ks-level2");

Environment:
v20.1

Additional context
The error seems fixed in v20.2.0-alpha.2

@rafiss rafiss added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-sql-typing SQLtype inference, typing rules, type compatibility. labels Nov 5, 2020
@rafiss rafiss changed the title sql: error in v20.1 caused by collated string comparison sql: error caused by collated string comparison Nov 5, 2020
@rafiss
Copy link
Collaborator Author

rafiss commented Nov 5, 2020

Actually this also fails in logic tests on 20.2, with the fakedist config. This comment explains why #56267 (comment)

@mgartner
Copy link
Collaborator

It looks like this is bug still exists. The logic tests below cause the same internal error. However, the I can't get the same SQL to produce an error in cockroach demo.

statement ok
CREATE TABLE nocase_strings (
  i INT,
  s STRING COLLATE "en-US-u-ks-level2"
);

statement ok
INSERT INTO nocase_strings VALUES (1, 'Aaa' COLLATE "en-US-u-ks-level2"), (2, 'Bbb' COLLATE "en-US-u-ks-level2");

If i is removed from the table, there is no internal error.

cc @rafiss

@mgartner mgartner reopened this Mar 24, 2021
craig bot pushed a commit that referenced this issue Mar 25, 2021
62562: sql: fix internal error when comparing collation names r=otan,mgartner a=rafiss

fixes #56335
(that issue was previously closed and just got reopened)

Release note (bug fix): An internal error caused by comparing
collation names that had different upper/lower case is now fixed.

Co-authored-by: Rafi Shamim <[email protected]>
@craig craig bot closed this as completed in aaac3ae Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-typing SQLtype inference, typing rules, type compatibility. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Projects
None yet
2 participants