Create index where the included columns would be maintained by CRDB as all the columns needed to delete records from the base table. #80244
Labels
C-enhancement
Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
T-sql-foundations
SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
Is your feature request related to a problem? Please describe.
When you try to delete records from a table (i.e.,
DELETE FROM tbl WHERE id BETWEEN 10 AND 20
), not only do you need an index that helps resolve the predicate, but the SQL optimizer also needs to retrieve all the key fields used in the primary index and all the secondary indexes. The query plan will show an INDEX scan/seek, then an INDEX JOIN back to the primary table, and then a DELETE.This index join can be expensive. The need for this index join can be removed by creating a covering index that includes all the fields that are keys for the primary/secondary indexes. However, this is not very intuitive. Nor is it easy to maintain. For instance, if you created a covering index to help with deletes and later created another index on the table but failed to alter your "delete index" to include the fields used in your new index, then your DELETE queries would revert to having an INDEX JOIN in their execution plan.
Example:
Describe the solution you'd like
I would like to suggest an index that worked like:
where this index would handle updating itself whenever schema events occurred that necessitated adding a field to the index to support more performant DELETEs.
Describe alternatives you've considered
Maintaining these indexes manually.
Additional context
I'm testing this on CRDB 21.2.9
Jira issue: CRDB-15794
The text was updated successfully, but these errors were encountered: