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/tests: TestRandomSyntaxFunctions failed [array_cat_agg: 9 trailing bytes in encoded value] #109629

Closed
mgartner opened this issue Aug 28, 2023 · 3 comments · Fixed by #109635
Closed
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-rsg Random Syntax Generator T-sql-queries SQL Queries Team

Comments

@mgartner
Copy link
Collaborator

mgartner commented Aug 28, 2023

Found in a random syntax test here:

SELECT array_cat_agg(
  ARRAY[(416644234484367676:::INT8,),(NULL,),((-0.12116245180368423):::FLOAT8,)]
);

Causes the error:

ERROR: internal error: 9 trailing bytes in encoded value: [4 191 191 4 128 160 0 0 0]
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/rowenc/encoded_datum.go:263: EnsureDecoded()
github.com/cockroachdb/cockroach/bazel-out/darwin_arm64-fastbuild/bin/pkg/sql/colexec/rowtovec.eg.go:50: EncDatumRowToColVecs()
github.com/cockroachdb/cockroach/pkg/sql/colexec/values.go:121: 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/colexec/colexecbase/fn_op.go:32: Next()
github.com/cockroachdb/cockroach/pkg/sql/colexec/ordered_aggregator.go:207: 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:316: Run()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:907: Run()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1960: PlanAndRun()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1674: func3()
github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1677: PlanAndRunAll()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:2291: execWithDistSQLEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1839: dispatchToExecutionEngine()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1070: execStmtInOpenState()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:144: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:3232: execWithProfiling()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:143: execStmt()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2220: func1()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2225: execCmd()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2142: run()
github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:954: ServeConn()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:247: processCommands()
github.com/cockroachdb/cockroach/pkg/sql/pgwire/server.go:999: func3()

Jira issue: CRDB-31026

@mgartner mgartner added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Aug 28, 2023
@mgartner mgartner self-assigned this Aug 28, 2023
@mgartner
Copy link
Collaborator Author

Reduced:

SELECT array_cat_agg(ARRAY[(1::INT,), (1::FLOAT8,)]);

I have a hunch that we're not correctly type-checking this expression correctly. It should maybe be a type error.

@mgartner
Copy link
Collaborator Author

This was introduced in #108387. It allows ARRAY[(1::INT,), (1::FLOAT)] to be type checked:

  1. INT is the first candidate type of the first element of the tuple, so it is the selected first as the "candidate" type.
  2. The INT "candidate" type can be implicitly cast to FLOAT8, so FLOAT8 becomes the new candidate type.
  3. The array is typed as ARRAY[tuple(FLOAT8)].

However, the implicit cast from 1::INT to FLOAT8 is never added, so the values during execution don't match expectations, and we get an execution-time error.

mgartner added a commit to mgartner/cockroach that referenced this issue Aug 28, 2023
PR cockroachdb#108387 introduced new logic to type-checking that allows nested
expressions of a single expression to have different types in some cases
when the types can be implicitly casted to a common type. For example,
the expression `ARRAY[1::INT, 1::FLOAT8]` would have failed
type-checking but is not successfully typed as `[]FLOAT8`.

However, cockroachdb#108387 does not add an implicit cast to ensure that each
nested expression actually has that type during execution, which causes
internal errors in some cases. This commit add the necessary implicit
casts.

Fixes cockroachdb#109629

There is no release note because the bug is not present in any releases.

Release note: None
@rafiss
Copy link
Collaborator

rafiss commented Aug 29, 2023

This was previously reported in #109486, but that issue was closed as a dupe of #109105. I don't know enough to understand why it's a duplicate.

mgartner added a commit to mgartner/cockroach that referenced this issue Aug 30, 2023
PR cockroachdb#108387 introduced new logic to type-checking that allows nested
expressions of a single expression to have different types in some cases
when the types can be implicitly casted to a common type. For example,
the expression `ARRAY[1::INT, 1::FLOAT8]` would have failed
type-checking but is not successfully typed as `[]FLOAT8`.

However, cockroachdb#108387 does not add an implicit cast to ensure that each
nested expression actually has that type during execution, which causes
internal errors in some cases. This commit add the necessary implicit
casts.

Fixes cockroachdb#109629

There is no release note because the bug is not present in any releases.

Release note: None
@github-project-automation github-project-automation bot moved this to Triage in SQL Queries Aug 31, 2023
@mgartner mgartner added C-test-failure Broken test (automatically or manually discovered). O-rsg Random Syntax Generator T-sql-queries SQL Queries Team labels Aug 31, 2023
@mgartner mgartner moved this from Triage to Active in SQL Queries Aug 31, 2023
craig bot pushed a commit that referenced this issue Aug 31, 2023
109635: sql: fix nested expression type-checking r=mgartner a=mgartner

PR #108387 introduced new logic to type-checking that allows nested
expressions of a single expression to have different types in some cases
when the types can be implicitly casted to a common type. For example,
the expression `ARRAY[1::INT, 1::FLOAT8]` would have failed
type-checking but is not successfully typed as `[]FLOAT8`.

However, #108387 does not add an implicit cast to ensure that each
nested expression actually has that type during execution, which causes
internal errors in some cases. This commit add the necessary implicit
casts.

Fixes #109629

There is no release note because the bug is not present in any releases.

Release note: None


109704: roachprod: use more recent ubuntu 20.04 images r=RaduBerinde a=RaduBerinde

Epic: none
Release note: None

Co-authored-by: Marcus Gartner <[email protected]>
Co-authored-by: Radu Berinde <[email protected]>
@craig craig bot closed this as completed in 1758e91 Aug 31, 2023
@github-project-automation github-project-automation bot moved this from Active to Done in SQL Queries Aug 31, 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. C-test-failure Broken test (automatically or manually discovered). O-rsg Random Syntax Generator T-sql-queries SQL Queries Team
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants