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: failed to parse locale "": language: tag is not well-formed #101418

Closed
DerZc opened this issue Apr 13, 2023 · 5 comments · Fixed by #108199
Closed

internal error: failed to parse locale "": language: tag is not well-formed #101418

DerZc opened this issue Apr 13, 2023 · 5 comments · Fixed by #108199
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. C-test-failure Broken test (automatically or manually discovered). 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 13, 2023

Describe the problem

Please describe the issue you observed, and any steps we can take to reproduce it:

The following program triggers an internal error:

USE test;
DROP DATABASE IF EXISTS database16 CASCADE;
CREATE DATABASE database16;
USE database16;
CREATE TABLE t0 (c0 SMALLINT, c1 STRING COLLATE cmn);
CREATE TABLE t1 (c0 BOOL);
UPSERT INTO t1 (c0) VALUES(true);
SELECT t1.rowid FROM t1 WHERE ((CASE  WHEN false THEN CASE  WHEN (NOT (false)) THEN NULL END ELSE ((((''))) COLLATE es) END)>=(SELECT MAX(t0.c1) AS c0 FROM t0));

The error message:

> SELECT t1.rowid FROM t1 WHERE ((CASE  WHEN false THEN CASE  WHEN (NOT (false)) THEN NULL END ELSE ((((''))) COLLATE es) END)>=(SELECT MAX(t0.c1) AS c0 FROM t0));
ERROR: internal error: failed to parse locale "": language: tag is not well-formed
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/sem/tree/datum.go:1381: getCacheEntry()
github.com/cockroachdb/cockroach/pkg/sql/sem/tree/datum.go:1396: NewDCollatedString()
github.com/cockroachdb/cockroach/pkg/sql/sem/eval/cast.go:525: performCastWithoutPrecisionTruncation()
github.com/cockroachdb/cockroach/pkg/sql/sem/eval/cast.go:68: PerformCast()
github.com/cockroachdb/cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/colexec/colexecbase/cast.eg.go:14918: func1()
github.com/cockroachdb/cockroach/pkg/sql/colmem/allocator.go:460: PerformOperation()
github.com/cockroachdb/cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/colexec/colexecbase/cast.eg.go:14784: Next()
github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecutils/operator.go:157: Next()
github.com/cockroachdb/cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/colexec/colexecbase/const.eg.go:611: Next()
github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecutils/operator.go:157: Next()
github.com/cockroachdb/cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/colexec/colexecbase/cast.eg.go:1199: Next()
github.com/cockroachdb/cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/colexec/colexecsel/selection_ops.eg.go:56977: Next()
github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecbase/simple_project.go:124: Next()
github.com/cockroachdb/cockroach/pkg/sql/colflow/stats.go:118: next()
github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:92: CatchVectorizedRuntimeError()
github.com/cockroachdb/cockroach/pkg/sql/colflow/stats.go:126: Next()
github.com/cockroachdb/cockroach/pkg/sql/colflow/flow_coordinator.go:250: nextAdapter()
github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:92: CatchVectorizedRuntimeError()
github.com/cockroachdb/cockroach/pkg/sql/colflow/flow_coordinator.go:254: next()
github.com/cockroachdb/cockroach/pkg/sql/colflow/flow_coordinator.go:286: Run()
github.com/cockroachdb/cockroach/pkg/sql/colflow/vectorized_flow.go:317: Run()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:902: Run()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1913: PlanAndRun()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1645: func3()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1648: PlanAndRunAll()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:2090: execWithDistSQLEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1648: dispatchToExecutionEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:963: execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:141: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:2979: execWithProfiling()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:140: execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2169: func1()

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 CockroachDB from last commit version (678cfd4), run the program with CLI

Expected behavior
No error.

Environment:

  • CockroachDB version 678cfd4
  • Server OS: [Ubuntu 22.04]
  • Client app [CLI]

Jira issue: CRDB-26936

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

blathers-crl bot commented Apr 13, 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-schema (found keywords: DROP DATABASE)
  • @cockroachdb/sql-queries (found keywords: Vectorized,distsql,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 13, 2023
@mgartner mgartner added this to Triage in SQL Queries via automation Apr 13, 2023
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Apr 13, 2023
@mgartner mgartner moved this from Triage to Bugs to Fix in SQL Queries Apr 13, 2023
@cucaroach
Copy link
Contributor

I hit this issue trying to get #101068 over the line as well.

@cucaroach
Copy link
Contributor

Simpler repro:

SELECT t1.rowid FROM t1 WHERE ((CASE  WHEN false THEN CASE  WHEN (NOT (false)) THEN NULL END ELSE ('' COLLATE es) END)>=('' COLLATE es));   

@cucaroach
Copy link
Contributor

Postgres throws this error:

treilly=# SELECT * FROM t1 WHERE ((CASE  WHEN false THEN CASE  WHEN (NOT (false)) THEN NULL END ELSE ((((''))) COLLATE es) END)>=(SELECT MAX(t0.c1) AS c0 FROM t0));
ERROR:  collation "es" for encoding "UTF8" does not exist
LINE 1: ...  WHEN (NOT (false)) THEN NULL END ELSE ((((''))) COLLATE es...
                                                             ^

@cucaroach
Copy link
Contributor

Actually here's a repro that works in PG but throws this error in CRDB:

CREATE TABLE t0 (c0 SMALLINT, c1 VARCHAR COLLATE "es_ES");
CREATE TABLE t1 (c0 BOOL);
INSERT INTO t1 (c0) VALUES(true);
SELECT * FROM t1 WHERE ((CASE  WHEN false THEN CASE  WHEN (NOT (false)) THEN NULL END ELSE ((((''))) COLLATE "es_ES") END)>=(SELECT MAX(t0.c1) AS c0 FROM t0));

cucaroach added a commit to cucaroach/cockroach that referenced this issue Aug 4, 2023
If we have a nested case expression where the inner case expression
is ambiguous the AnyCollatedString type would be selected and it would
leak to the execution engine causing the 'failed to parse locale ""'
internal error. Instead have the overload type checker remember if
it saw a AnyCollatedString type and go back and repair types if a
concrete type is found in any of the other exprs.

Release note: none
Epic: none
Fixes: cockroachdb#101418
craig bot pushed a commit that referenced this issue Aug 8, 2023
108199: sql: fix overload type checking of nested case expressions r=mgartner a=cucaroach

If we have a nested case expression where the inner case expression
is ambiguous the AnyCollatedString type would be selected and it would
leak to the execution engine causing the 'failed to parse locale ""'
internal error. Instead have the overload type checker remember if
it saw a AnyCollatedString type and go back and repair types if a
concrete type is found in any of the other exprs.

Release note: none
Epic: none
Fixes: #101418


Co-authored-by: Tommy Reilly <treilly@cockroachlabs.com>
@craig craig bot closed this as completed in 6038c50 Aug 8, 2023
cucaroach added a commit that referenced this issue Aug 8, 2023
If we have a nested case expression where the inner case expression
is ambiguous the AnyCollatedString type would be selected and it would
leak to the execution engine causing the 'failed to parse locale ""'
internal error. Instead have the overload type checker remember if
it saw a AnyCollatedString type and go back and repair types if a
concrete type is found in any of the other exprs.

Release note (bug fix): Fix a bug with collated string type checking
with nested case expressions where inner case had no explicit collated
type.
Epic: none
Fixes: #101418
Release justification: Low risk fix for edge case SQL construct.
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. C-test-failure Broken test (automatically or manually discovered). 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
SQL Queries
Bugs to Fix
Development

Successfully merging a pull request may close this issue.

3 participants