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: store column IDs in index predicates instead of column names #49766

Open
mgartner opened this issue Jun 1, 2020 · 4 comments
Open

sql: store column IDs in index predicates instead of column names #49766

mgartner opened this issue Jun 1, 2020 · 4 comments
Labels
A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team

Comments

@mgartner
Copy link
Collaborator

mgartner commented Jun 1, 2020

Storing column names in partial index predicates (like CREATE INDEX ... WHERE s = 'foo') has disadvantages, such as maintaining code to handle column renames.

Storing column IDs instead (like `CREATE INDEX ... WHERE @11 = 'foo') would eliminate this issue.

Note that we'd need to convert these column IDs to column names whenever the predicate is shown to users.

More context: #49672 (comment)

Jira issue: CRDB-4199

@mgartner mgartner added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-optimizer SQL logical planning and optimizations. labels Jun 1, 2020
@mgartner mgartner self-assigned this Jun 1, 2020
@mgartner mgartner added this to Plan enhancements (lower priority) in BACKLOG, NO NEW ISSUES: SQL Optimizer Jun 1, 2020
@jordanlewis jordanlewis changed the title Store column IDs in index predicates instead of column names sql: store column IDs in index predicates instead of column names Jun 1, 2020
@jordanlewis
Copy link
Member

Some things that I've been talking over with @RichardJCai in this regard:

  1. Not relevant here, but for views, we can't just store a column ordinal - we have to also store a table id. So whatever we do, we should make sure to make the syntax for this usable in both situations or risk having extra serialization formats.
  2. Truncating a table bumps its table id. Maybe also not relevant here.
  3. Column IDs can be modified by alter column type, which replaces a column with another. It's important to use the logical column ID, which should be stable in the face of this kind of operation.

There may be other gotchas. Anything else you noticed, Richard?

@rohany
Copy link
Contributor

rohany commented Jun 1, 2020

@mgartner, also index predicates will need to be using this sort of stable representation when there are user defined types in the predicate -- see #49565. I'll probably be doing the change, but just to keep it on your radar.

@RichardJCai
Copy link
Contributor

Some things that I've been talking over with @RichardJCai in this regard:

  1. Not relevant here, but for views, we can't just store a column ordinal - we have to also store a table id. So whatever we do, we should make sure to make the syntax for this usable in both situations or risk having extra serialization formats.
  2. Truncating a table bumps its table id. Maybe also not relevant here.
  3. Column IDs can be modified by alter column type, which replaces a column with another. It's important to use the logical column ID, which should be stable in the face of this kind of operation.

There may be other gotchas. Anything else you noticed, Richard?

No I think you've covered everything. I don't think table id will be too difficult to update right?

@mgartner mgartner removed their assignment Sep 1, 2020
@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!

@mgartner mgartner removed this from Plan enhancements (lower priority) in BACKLOG, NO NEW ISSUES: SQL Optimizer Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

5 participants