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: index recommendations should be aware of hash sharding #84681

Open
rytaft opened this issue Jul 19, 2022 · 1 comment
Open

opt: index recommendations should be aware of hash sharding #84681

rytaft opened this issue Jul 19, 2022 · 1 comment
Labels
A-hash-sharding Hash-sharded indexes A-sql-explain Issues related to EXPLAIN and EXPLAIN ANALYZE improvements 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-queries SQL Queries Team

Comments

@rytaft
Copy link
Collaborator

rytaft commented Jul 19, 2022

Is your feature request related to a problem? Please describe.
Today we give sub-optimal index recommendations for tables that contain hash-sharded indexes. For example:

CREATE DATABASE IF NOT EXISTS employees;
USE employees;
IMPORT PGDUMP 'https://s3-us-west-1.amazonaws.com/cockroachdb-movr/datasets/employees-db/pg_dump/employees-full.sql.gz' WITH ignore_unsupported_statements;
ALTER TABLE employees ALTER PRIMARY KEY USING COLUMNS (emp_no) USING HASH WITH BUCKET_COUNT = 8;
EXPLAIN SELECT * FROM employees AS OF SYSTEM TIME '-1s' WHERE emp_no > 10000 ORDER BY emp_no LIMIT 25;

The recommendation in this case is to recreate the non-hash-sharded pk as an index:

  index recommendations: 1
  1. type: index creation
     SQL command: CREATE INDEX ON employees (emp_no) STORING (birth_date, first_name, last_name, gender, hire_date);

Describe the solution you'd like
We should not recommend creating an index on a column if an equivalent hash-sharded index already exists. If a hash-sharded index already exists but does not store all of the needed columns, we could suggest dropping it and re-creating the hash-sharded index with additional STORING columns.

Epic: CRDB-14532
Jira issue: CRDB-17795

@rytaft rytaft added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-explain Issues related to EXPLAIN and EXPLAIN ANALYZE improvements labels Jul 19, 2022
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Jul 19, 2022
@mgartner mgartner added the E-quick-win Likely to be a quick win for someone experienced. label Sep 29, 2022
@michae2
Copy link
Collaborator

michae2 commented Apr 25, 2023

See also #41058 (comment) about providing a recommendation to hash-shard an index.

@michae2 michae2 added the A-hash-sharding Hash-sharded indexes label Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-hash-sharding Hash-sharded indexes A-sql-explain Issues related to EXPLAIN and EXPLAIN ANALYZE improvements 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-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

4 participants