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: allow expression indexes to reference computed columns #67900

Open
mgartner opened this issue Jul 22, 2021 · 2 comments
Open

sql: allow expression indexes to reference computed columns #67900

mgartner opened this issue Jul 22, 2021 · 2 comments
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-done docs-known-limitation E-quick-win Likely to be a quick win for someone experienced. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@mgartner
Copy link
Collaborator

mgartner commented Jul 22, 2021

Currently we do not allow expression indexes to reference computed columns. This restriction comes from the restriction that computed column cannot reference other computed columns, presumably to prevent cycles. Because expression indexes are backed by inaccessible virtual computed columns, which cannot be referenced by any other schema expressions, we may be able to lift this restriction for expression indexes.

More context from #65703 (review):

rytaft:

statement error index element expression cannot reference computed columns
CREATE TABLE err (a INT, comp INT AS (a + 10) STORED, INDEX ((comp + 10)))

not sure if we care, but this doesn't cause an error in Postgres

mgartner:

Good point. If preventing cycles is the only reason why computed columns can't reference other computed columns, then we may be able to lift this restriction. Because these expression index computed columns will be inaccessible (they can't be referenced in other expressions), then it is guaranteed that there will not be a cycle.

Jira issue: CRDB-8766

@mgartner mgartner added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-pgcompat Semantic compatibility with PostgreSQL T-sql-queries SQL Queries Team E-quick-win Likely to be a quick win for someone experienced. labels Jul 22, 2021
@mgartner mgartner added this to Triage in SQL Queries via automation Jul 22, 2021
@mgartner mgartner moved this from Triage to Backlog in SQL Queries Jul 22, 2021
@mgartner mgartner moved this from Backlog to 21.2 Low Likelihood (10%) in SQL Queries Jul 22, 2021
@mgartner mgartner self-assigned this Jul 22, 2021
@mgartner
Copy link
Collaborator Author

@ianjevans this will likely be a known limitation for expression indexes in the 21.2 release.

@ajwerner
Copy link
Contributor

ajwerner commented Mar 2, 2022

I think there's two approaches here, but the easiest is to special case the columns which are used for these expression indexes and allow them to have references to regular computed columns because we know there won't be cycles by construction.

@ajwerner ajwerner added this to Triage in SQL Foundations via automation Mar 2, 2022
@blathers-crl blathers-crl bot added the T-sql-schema-deprecated Use T-sql-foundations instead label Mar 2, 2022
@ajwerner ajwerner removed this from 22.1 Low Likelihood (10%) in SQL Queries Mar 2, 2022
@ajwerner ajwerner moved this from Triage to Backlog in SQL Foundations Mar 8, 2022
@mgartner mgartner removed their assignment May 5, 2022
@mgartner mgartner added this to Triage in SQL Queries via automation May 5, 2022
@mgartner mgartner moved this from Triage to Backlog in SQL Queries May 5, 2022
@postamar postamar moved this from Backlog to Cold storage in SQL Foundations Nov 10, 2022
@exalate-issue-sync exalate-issue-sync bot added T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) and removed T-sql-schema-deprecated Use T-sql-foundations instead T-sql-queries SQL Queries Team labels May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-done docs-known-limitation E-quick-win Likely to be a quick win for someone experienced. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
SQL Foundations
  
Cold storage
SQL Queries
Backlog (DO NOT ADD NEW ISSUES)
Development

No branches or pull requests

4 participants