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

[YSQL] implement predicate pushdown to optimize basic range queries #1223

Closed
kmuthukk opened this issue Apr 18, 2019 · 0 comments
Closed

[YSQL] implement predicate pushdown to optimize basic range queries #1223

kmuthukk opened this issue Apr 18, 2019 · 0 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL)
Milestone

Comments

@kmuthukk
Copy link
Collaborator

Sample table:

     CREATE TABLE IF NOT EXISTS user_actions(
           id     text,
           msg_id integer,
           msg    text,
           PRIMARY KEY(id, msg_id)
        )

Insert about 1000 msg_ids for each user. Confirm that user 'u-0-10' has 1000 rows.

postgres=# select count(*) from user_actions where id='u-0-10';
 count
-------
  1000
(1 row)

Time: 8.730 ms

Looking up a specific msg with equality predicate is pretty fast:

postgres=# select * from user_actions where id='u-0-10' and msg_id=10;
   id   | msg_id |     msg
--------+--------+-------------
 u-0-10 |     10 | msg--10--10
(1 row)

Time: 0.883 ms

Looking up a specific msg or few msgs with a range predicate seems to go scan all the 1000 rows of user 'u-0-10' (since time seems similar to the count(*) query above) instead of pushing the range predicate down to the DocDB layer, and hence much slower than expected:

postgres=# select * from user_actions where id='u-0-10' and msg_id>=10 and msg_id<11;
   id   | msg_id |     msg
--------+--------+-------------
 u-0-10 |     10 | msg--10--10
(1 row)

Time: 8.116 ms
@kmuthukk kmuthukk added the area/ysql Yugabyte SQL (YSQL) label Apr 18, 2019
@ndeodhar ndeodhar modified the milestones: Future, v2.0 Apr 18, 2019
rajukumaryb added a commit that referenced this issue Aug 2, 2019
Summary:
  Usage: SELECT ... FROM ... WHERE INEQUALITY_EXPR1 AND INEQUALITY_EXPR2 AND ...

  INEQUALITY_EXPR for range column r:    \and_i{r >[=] A_i} AND \and_j{r <[=] B_j}    where A_i and B_j are constants

  Before:       Client --------- \and_i{r >[=] A_i} AND \and_j{r <[=] B_j} ---------> Postgres ---------------------------------------------------------> DocDB
  After:        Client --------- \and_i{r >[=] A_i} AND \and_j{r <[=] B_j} ---------> Postgres --------- r >= \max_i{A_i} AND r <= \min_j{B_j} ---------> DocDB

Test Plan:
  ./yb_build.sh debug --scb --java-test org.yb.pgsql.TestPgInequality
  ./yb_build.sh debug --cxx-test pggate_pggate_test_select_inequality --gtest_filter PggateTestSelectInequality.TestSelectInequality

Reviewers: mihnea, neil

Reviewed By: neil

Subscribers: srhickma, yql, neha, mikhail, kannan

Differential Revision: https://phabricator.dev.yugabyte.com/D6899
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL)
Projects
None yet
Development

No branches or pull requests

4 participants