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

opt: better validation of column numeric references #61563

Open
RaduBerinde opened this issue Mar 5, 2021 · 1 comment
Open

opt: better validation of column numeric references #61563

RaduBerinde opened this issue Mar 5, 2021 · 1 comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team

Comments

@RaduBerinde
Copy link
Member

RaduBerinde commented Mar 5, 2021

When a query refers to a table by numeric reference (descriptor ID), it can also select a subset of columns (by column ID). It is possible that one of the specified columns is a computed column that depends on a column that is not specified. At least with virtual columns, this is not handled correctly:

  CREATE TABLE public.t (
      a INT8 NOT NULL,
      b INT8 NULL,
      c INT8 NULL AS (a + b) VIRTUAL,
      CONSTRAINT "primary" PRIMARY KEY (a ASC),
      FAMILY "primary" (a, b)
  )
> select * from [52(1,3) AS t];
ERROR: internal error: scanned virtual column depends on non-scanned column
SQLSTATE: XX000
DETAIL: stack trace:
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:560: func1()
github.com/cockroachdb/cockroach/pkg/sql/opt/colset.go:55: func1()
github.com/cockroachdb/cockroach/pkg/util/fast_int_set.go:165: ForEach()
github.com/cockroachdb/cockroach/pkg/sql/opt/colset.go:55: ForEach()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:557: buildScan()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:410: buildScanFromTableRef()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:219: buildDataSource()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:59: buildDataSource()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1190: buildFromTablesRightDeep()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1167: buildFromTables()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1094: buildFrom()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:1015: buildSelectClause()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:963: buildSelectStmtWithoutParens()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:936: func1()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/with.go:29: processWiths()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:935: buildSelect()
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:265: buildStmt()

I think this operation should be disallowed.

Jira issue: CRDB-2995

@RaduBerinde RaduBerinde added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Mar 5, 2021
@jlinder jlinder added the T-sql-queries SQL Queries Team label Jun 16, 2021
@github-actions
Copy link

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

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. T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

3 participants