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

handle more than one 'equal' or 'in' function for a column in ranger #7279

Closed
zz-jason opened this issue Aug 5, 2018 · 3 comments
Closed
Assignees
Labels
sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@zz-jason
Copy link
Member

zz-jason commented Aug 5, 2018

Take this as an example:

drop table if exists t;
create table t(a bigint, b bigint, index idx(a, b));

Now let's issue a query on column 'a':

TiDB(localhost:4000) > explain select * from t where a in (1, 2) and a in (1, 3);
+---------------------+-------+------+-------------------------------------------------------------------------+
| id                  | count | task | operator info                                                           |
+---------------------+-------+------+-------------------------------------------------------------------------+
| IndexReader_10      | 0.04  | root | index:Selection_9                                                       |
| └─Selection_9       | 0.04  | cop  | in(test.t.a, 1, 2)                                                      |
|   └─IndexScan_8     | 20.00 | cop  | table:t, index:a, b, range:[1,1], [3,3], keep order:false, stats:pseudo |
+---------------------+-------+------+-------------------------------------------------------------------------+
3 rows in set (0.00 sec)

As you can see, this results in a IndexScan_8 followed by a Selection_9, and the query range in IndexScan_8 is [1,1], [3,3].

If we could handle more than one 'equal' or 'in' function for a column in the ranger, we can optimize the query to only one IndexScan with the query range [1, 1].

In "util/ranger/detacher.go", we have to enhance the extractEqAndInCondition function to break this limit.

@zz-jason zz-jason added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner labels Aug 5, 2018
@zz-jason zz-jason self-assigned this Aug 5, 2018
@laidahe
Copy link
Contributor

laidahe commented Aug 20, 2018

Seems like what we need to do is combining multiple “in” into single "in".

@zz-jason
Copy link
Member Author

@laidahe Um.. yes, much like that. You can take a look at the code and do some investigation to decide the best solution.

@eurekaka eurekaka self-assigned this Aug 29, 2018
@eurekaka
Copy link
Contributor

some more queries to be verified for the solution of this issue:

MySQL [test]> explain select * from t where a = 1 and a = 1;
+---------------------+-------+------+------------------------------------------------------------------+
| id                  | count | task | operator info                                                    |
+---------------------+-------+------+------------------------------------------------------------------+
| IndexReader_10      | 10.00 | root | index:Selection_9                                                |
| └─Selection_9       | 10.00 | cop  | eq(test.t.a, 1)                                                  |
|   └─IndexScan_8     | 10.00 | cop  | table:t, index:a, b, range:[1,1], keep order:false, stats:pseudo |
+---------------------+-------+------+------------------------------------------------------------------+

MySQL [test]> explain select * from t where a = 1 and a = 2;
+---------------------+-------+------+------------------------------------------------------------------+
| id                  | count | task | operator info                                                    |
+---------------------+-------+------+------------------------------------------------------------------+
| IndexReader_10      | 0.01  | root | index:Selection_9                                                |
| └─Selection_9       | 0.01  | cop  | eq(test.t.a, 1)                                                  |
|   └─IndexScan_8     | 10.00 | cop  | table:t, index:a, b, range:[2,2], keep order:false, stats:pseudo |
+---------------------+-------+------+------------------------------------------------------------------+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

3 participants