-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: support range based lookup join spans
Informs #51576 If filters exist on a lookup join that match columns that we are doing the lookup against add them to the lookupExpr in the join reader spec and build those filters into the multispan generator. Remove map based key to input row index and replace it with a binary search against a new span+inputRowIndices slice. Release note (sql change): support range based lookup joins when join conditions align with index/table being looked up into. This can greatly reduce the amount of rows we need to process, essentially a form of predicate push down. 51576 also encompasses allowing inequalities on columns from the index to reference columns from the input, that will come in a later commit.
- Loading branch information
Showing
15 changed files
with
822 additions
and
166 deletions.
There are no files selected for viewing
232 changes: 232 additions & 0 deletions
232
pkg/sql/logictest/testdata/logic_test/lookup_join_spans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
statement ok | ||
CREATE TABLE metrics ( | ||
id SERIAL PRIMARY KEY, | ||
name STRING, | ||
INDEX name_index (name) | ||
) | ||
|
||
statement ok | ||
insert into metrics (id,name) values (1,'cpu'), (2,'cpu'), (3,'mem'), (4,'disk') | ||
|
||
statement ok | ||
CREATE TABLE metric_values ( | ||
metric_id INT8, | ||
time TIMESTAMPTZ, | ||
value INT8, | ||
PRIMARY KEY (metric_id, time) | ||
) | ||
|
||
statement ok | ||
insert into metric_values (metric_id, time, value) values | ||
(1,'2020-01-01 00:00:00+00:00',0), | ||
(1,'2020-01-01 00:00:01+00:00',1), | ||
(2,'2020-01-01 00:00:00+00:00',3), | ||
(2,'2020-01-01 00:00:01+00:00',4) | ||
|
||
statement ok | ||
CREATE TABLE metric_valuesd ( | ||
metric_id INT8, | ||
time TIMESTAMPTZ, | ||
value INT8, | ||
PRIMARY KEY (metric_id, time DESC) | ||
) | ||
|
||
statement ok | ||
insert into metric_valuesd (metric_id, time, value) values | ||
(1,'2020-01-01 00:00:00+00:00',0), | ||
(1,'2020-01-01 00:00:01+00:00',1), | ||
(2,'2020-01-01 00:00:00+00:00',3), | ||
(2,'2020-01-01 00:00:01+00:00',4) | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_values | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time > '2020-01-01 00:00:00+00:00' AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:01 +0000 UTC 1 1 cpu | ||
2 2020-01-01 00:00:01 +0000 UTC 4 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_valuesd | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time > '2020-01-01 00:00:00+00:00' AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:01 +0000 UTC 1 1 cpu | ||
2 2020-01-01 00:00:01 +0000 UTC 4 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_values | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time >= '2020-01-01 00:00:00+00:00' AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:00 +0000 UTC 0 1 cpu | ||
1 2020-01-01 00:00:01 +0000 UTC 1 1 cpu | ||
2 2020-01-01 00:00:00 +0000 UTC 3 2 cpu | ||
2 2020-01-01 00:00:01 +0000 UTC 4 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_valuesd | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time >= '2020-01-01 00:00:00+00:00' AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:00 +0000 UTC 0 1 cpu | ||
1 2020-01-01 00:00:01 +0000 UTC 1 1 cpu | ||
2 2020-01-01 00:00:00 +0000 UTC 3 2 cpu | ||
2 2020-01-01 00:00:01 +0000 UTC 4 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_values | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time < '2020-01-01 00:00:00+00:00' AND | ||
name='cpu' | ||
---- | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_valuesd | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time < '2020-01-01 00:00:00+00:00' AND | ||
name='cpu' | ||
---- | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_values | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time <= '2020-01-01 00:00:00+00:00' AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:00 +0000 UTC 0 1 cpu | ||
2 2020-01-01 00:00:00 +0000 UTC 3 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_valuesd | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time <= '2020-01-01 00:00:00+00:00' AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:00 +0000 UTC 0 1 cpu | ||
2 2020-01-01 00:00:00 +0000 UTC 3 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_values | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time in ('2020-01-01 00:00:00+00:00','2020-01-01 00:00:01+00:00') AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:00 +0000 UTC 0 1 cpu | ||
1 2020-01-01 00:00:01 +0000 UTC 1 1 cpu | ||
2 2020-01-01 00:00:00 +0000 UTC 3 2 cpu | ||
2 2020-01-01 00:00:01 +0000 UTC 4 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_valuesd | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time in ('2020-01-01 00:00:00+00:00','2020-01-01 00:00:01+00:00') AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:00 +0000 UTC 0 1 cpu | ||
1 2020-01-01 00:00:01 +0000 UTC 1 1 cpu | ||
2 2020-01-01 00:00:00 +0000 UTC 3 2 cpu | ||
2 2020-01-01 00:00:01 +0000 UTC 4 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_values | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time < '2020-01-01 00:00:10+00:00' AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:00 +0000 UTC 0 1 cpu | ||
1 2020-01-01 00:00:01 +0000 UTC 1 1 cpu | ||
2 2020-01-01 00:00:00 +0000 UTC 3 2 cpu | ||
2 2020-01-01 00:00:01 +0000 UTC 4 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_valuesd | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time < '2020-01-01 00:00:10+00:00' AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:00 +0000 UTC 0 1 cpu | ||
1 2020-01-01 00:00:01 +0000 UTC 1 1 cpu | ||
2 2020-01-01 00:00:00 +0000 UTC 3 2 cpu | ||
2 2020-01-01 00:00:01 +0000 UTC 4 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_values | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time BETWEEN '2020-01-01 00:00:00+00:00' AND '2020-01-01 00:10:00+00:00' AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:00 +0000 UTC 0 1 cpu | ||
1 2020-01-01 00:00:01 +0000 UTC 1 1 cpu | ||
2 2020-01-01 00:00:00 +0000 UTC 3 2 cpu | ||
2 2020-01-01 00:00:01 +0000 UTC 4 2 cpu | ||
|
||
query ITIIT | ||
SELECT * | ||
FROM metric_valuesd | ||
INNER JOIN metrics | ||
ON metric_id=id | ||
WHERE | ||
time BETWEEN '2020-01-01 00:00:00+00:00' AND '2020-01-01 00:10:00+00:00' AND | ||
name='cpu' | ||
ORDER BY value | ||
---- | ||
1 2020-01-01 00:00:00 +0000 UTC 0 1 cpu | ||
1 2020-01-01 00:00:01 +0000 UTC 1 1 cpu | ||
2 2020-01-01 00:00:00 +0000 UTC 3 2 cpu | ||
2 2020-01-01 00:00:01 +0000 UTC 4 2 cpu | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.