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: improve tuple index spans #6390

Closed
maddyblue opened this issue Apr 28, 2016 · 3 comments · Fixed by #21317
Closed

sql: improve tuple index spans #6390

maddyblue opened this issue Apr 28, 2016 · 3 comments · Fixed by #21317
Assignees
Milestone

Comments

@maddyblue
Copy link
Contributor

Things missing from the current tuple index selection code:

@maddyblue
Copy link
Contributor Author

The prefix thing appears to be fixed, although I'm not sure when or how:

> create table t (a int, b int, c int, index (a, b, c));
root@:26257> explain select * from t where (a, b) > (1, 2);
+-------+------+---------------------+
| Level | Type |     Description     |
+-------+------+---------------------+
|     0 | scan | t@t_a_b_c_idx /1/3- |
+-------+------+---------------------+
(1 row)
root@:26257> explain select * from t where (a, b) < (1, 2);
+-------+------+-----------------------+
| Level | Type |      Description      |
+-------+------+-----------------------+
|     0 | scan | t@t_a_b_c_idx /#-/1/2 |
+-------+------+-----------------------+
(1 row)
root@:26257>  

@RaduBerinde
Copy link
Member

I think the prefix thing was the other way around - having an index on (a, b) and having a condition with more columns (a, b, c) > (1, 2, 3). That condition implies (a, b) >= (1, 2) so we could use that to make a span with that index.

@petermattis petermattis added this to the Later milestone Feb 22, 2017
RaduBerinde added a commit to RaduBerinde/cockroach that referenced this issue Dec 20, 2017
Support for tuple inequalities like `(a, b, c) > (1, 2, 3)`.

This code is more functional than the legacy index constraints code:
 - we support restricting the inequalities to a prefix, e.g.
   `(a, b, c) > (1, 2, 3)  ->  (a, b) >= (1, 2)` (cockroachdb#6390).
 - we correctly handle cases like `(a, b) BETWEEN (1, 2) AND (3, 4))`
   (cockroachdb#20504).

Minor changes to opt test: support `asc/desc` and switch the order of
`legacy-normalize` and `build-scalar` in tests (we don't want to build
a scalar before doing the normalization).

Release note: None
RaduBerinde added a commit to RaduBerinde/cockroach that referenced this issue Dec 21, 2017
Support for tuple inequalities like `(a, b, c) > (1, 2, 3)`.

This code is more functional than the legacy index constraints code:
 - we support restricting the inequalities to a prefix, e.g.
   `(a, b, c) > (1, 2, 3)  ->  (a, b) >= (1, 2)` (cockroachdb#6390).
 - we correctly handle cases like `(a, b) BETWEEN (1, 2) AND (3, 4))`
   (cockroachdb#20504).

Minor changes to opt test: support `asc/desc` and switch the order of
`legacy-normalize` and `build-scalar` in tests (we don't want to build
a scalar before doing the normalization).

Release note: None
@RaduBerinde
Copy link
Member

Regarding the second bullet point: if we have (a,b,c) > (1,2,3) and an index on (a ASC, b DESC, c ASC), we can't do better than just restrict to a >= 1. To get a constraints on all columns, the expression would need to be e.g. (a, -b, c) > (1, -2, 3).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants