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

roachtest: internal error: output cols mismatch #136250

Open
yuzefovich opened this issue Nov 26, 2024 · 1 comment
Open

roachtest: internal error: output cols mismatch #136250

yuzefovich opened this issue Nov 26, 2024 · 1 comment
Labels
B-runtime-assertions-enabled branch-master Failures and bugs on the master branch. C-test-failure Broken test (automatically or manually discovered). O-roachtest O-rsg Random Syntax Generator T-sql-queries SQL Queries Team

Comments

@yuzefovich
Copy link
Member

yuzefovich commented Nov 26, 2024

Extracted from here. On crdb_test binaries we get

ERROR: internal error: output cols mismatch: (118-143,146-149) vs (118-128,130-143,146-149)
SQLSTATE: XX000
DETAIL: stack trace:
pkg/sql/opt/props/verify.go:82: VerifyAgainst()
pkg/sql/opt/memo/check_expr.go:52: CheckExpr()
bazel-out/darwin_arm64-fastbuild/bin/pkg/sql/opt/memo/expr.og.go:26322: AddLookupJoinToGroup()
pkg/sql/opt/xform/join_funcs.go:514: func1()
pkg/sql/opt/xform/scan_index_iter.go:299: ForEachStartingAfter()
pkg/sql/opt/xform/scan_index_iter.go:202: ForEach()
pkg/sql/opt/xform/join_funcs.go:411: generateLookupJoinsImpl()
pkg/sql/opt/xform/join_funcs.go:259: GenerateLookupJoins()
...
CREATE TABLE table_1 (
  col1_0 BOOL,
  col1_1 REFCURSOR,
  col1_2 PG_LSN,
  col1_3 BOX2D,
  col1_4 INT8,
  col1_5 STRING,
  col1_6 STRING,
  col1_7 INT8,
  col1_8 STRING AS (lower(NULL)) VIRTUAL,
  col1_9 STRING,
  PRIMARY KEY (col1_8),
  INDEX (lower(CAST(col1_3 AS STRING)), lower(CAST(col1_2 AS STRING)) DESC) STORING(col1_2)
);

SET testing_optimizer_random_seed = 4882365012661120111;

SET testing_optimizer_disable_rule_probability = 0.500000;

SELECT NULL
  FROM table_1 AS tab_879
  JOIN table_1 AS tab_880 ON true
       FULL JOIN table_1 AS tab_881 JOIN table_1 ON true JOIN table_1 AS tab_883 ON true ON true
 WHERE (
        NOT (
              EXISTS(
                  SELECT NULL
                    FROM table_1 AS tab_884 JOIN table_1 ON true
                ORDER BY tab_884.crdb_internal_origin_timestamp DESC NULLS FIRST,
                         tab_884.col1_4 ASC NULLS LAST,
                         tab_884.col1_0 ASC NULLS LAST,
                         tab_884.col1_2 ASC NULLS LAST
              )
            )
       )
    OR (
        (
          tab_881.col1_0
          AND 0
            NOT IN (
                SELECT NULL
                  FROM table_1 AS tab_886
                  JOIN table_1 AS tab_887 ON tab_886.col1_5 = tab_887.col1_5
                                         AND tab_886.col1_0 = tab_887.col1_0
              )
        )
        OR (tab_883.col1_0 AND tab_879.col1_0)
       );

Jira issue: CRDB-44942

@yuzefovich yuzefovich added C-test-failure Broken test (automatically or manually discovered). O-roachtest O-rsg Random Syntax Generator branch-master Failures and bugs on the master branch. T-sql-queries SQL Queries Team B-runtime-assertions-enabled labels Nov 26, 2024
@github-project-automation github-project-automation bot moved this to Triage in SQL Queries Nov 26, 2024
@DrewKimball
Copy link
Collaborator

Here's an optimizer test repro:

exec-ddl
CREATE TABLE table_1 (
  col1_0 BOOL,
  col1_1 REFCURSOR,
  col1_2 PG_LSN,
  col1_3 BOX2D,
  col1_4 INT8,
  col1_5 STRING,
  col1_6 STRING,
  col1_7 INT8,
  col1_8 STRING AS (lower(NULL)) VIRTUAL,
  col1_9 STRING,
  foo_col DECIMAL,
  PRIMARY KEY (col1_8),
  INDEX (CAST(col1_3 AS STRING), CAST(col1_2 AS STRING))
);
----

opt disable=(MergeProjects,PruneProjectCols)
SELECT NULL
  FROM table_1 AS tab_879
  JOIN table_1 AS tab_880 ON true
  FULL JOIN table_1 AS tab_881 ON true
  JOIN table_1 ON true
  JOIN table_1 AS tab_883 ON true
 WHERE NOT EXISTS (SELECT NULL FROM table_1 AS tab_884 JOIN table_1 ON true)
    OR NOT EXISTS (SELECT NULL FROM table_1 AS tab_886 JOIN table_1 AS tab_887 ON tab_886.col1_5 = tab_887.col1_5);
----

There's a bug in InlineProjectProject, where we're mutating a Project operator's Passthrough set rather than copying it:

--- a/pkg/sql/opt/norm/inline_funcs.go
+++ b/pkg/sql/opt/norm/inline_funcs.go
@@ -245,7 +245,7 @@ func (c *CustomFuncs) InlineProjectProject(
        }

        // Add any outer passthrough columns that refer to inner synthesized columns.
-       newPassthrough := passthrough
+       newPassthrough := passthrough.Copy()
        if !newPassthrough.Empty() {
                for i := range innerProjections {
                        item := &innerProjections[i]

The large number of columns and joins in the test is necessary to spill the removed columns into the large set, which is shared between passthrough and newPassthrough without the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-runtime-assertions-enabled branch-master Failures and bugs on the master branch. C-test-failure Broken test (automatically or manually discovered). O-roachtest O-rsg Random Syntax Generator T-sql-queries SQL Queries Team
Projects
Status: Triage
Development

No branches or pull requests

2 participants