[MDEV-21628] Index condition pushdown for a simple condition over index fields is not used for ref access of partitioned tables when employing BKA Created: 2020-02-01  Updated: 2020-02-25  Resolved: 2020-02-14

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.3.20, 10.4.10, 10.5.0
Fix Version/s: 10.3.23, 10.4.13

Type: Bug Priority: Major
Reporter: Igor Babaev Assignee: Sergei Petrunia
Resolution: Fixed Votes: 0
Labels: None


 Description   

Create and populate tables t0,t1,t2 as in MDEV-21625.
The tables t0 and t1 are of the same structure and populated with the same set of rows. The only difference is that t1 is partitioned.

Execute the commands

set join_cache_level=6;
set optimizer_switch='mrr=on';

You'll see that for the query:

select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = 4;

index condition pushdown is empoyed when joining table t0

MariaDB [test]> explain extended select * from t0,t2 where t2.a in (3,4) and t0.a=t2.a and (t0.b / 10) = 4;
+------+-------------+-------+-------+---------------+------+---------+-----------+------+----------+-------------------------------------------------------------------------------+
| id   | select_type | table | type  | possible_keys | key  | key_len | ref       | rows | filtered | Extra                                                                         |
+------+-------------+-------+-------+---------------+------+---------+-----------+------+----------+-------------------------------------------------------------------------------+
|    1 | SIMPLE      | t2    | range | idx           | idx  | 5       | NULL      |    2 |   100.00 | Using where; Using index                                                      |
|    1 | SIMPLE      | t0    | ref   | idx           | idx  | 5       | test.t2.a |    13 |   100.00 | Using index condition; Using join buffer (flat, BKA join); Rowid-ordered scan |
+------+-------------+-------+-------+---------------+------+---------+-----------+------+----------+-------------------------------------------------------------------------------+

while for the similar query that uses tables t1,t2

select * from t1,t2 where t2.a in (3,4) and t1.a=t2.a and (t1.b / 10) = 4

no index condition pushdown is employed

MariaDB [test]> explain extended select * from t1,t2 where t2.a in (3,4) and t1.a=t2.a and (t1.b / 10) = 4;
+------+-------------+-------+-------+---------------+------+---------+-----------+------+----------+---------------------------------------------------------------------+
| id   | select_type | table | type  | possible_keys | key  | key_len | ref       | rows | filtered | Extra                                                               |
+------+-------------+-------+-------+---------------+------+---------+-----------+------+----------+---------------------------------------------------------------------+
|    1 | SIMPLE      | t2    | range | idx           | idx  | 5       | NULL      |    2 |   100.00 | Using where; Using index                                            |
|    1 | SIMPLE      | t1    | ref   | idx           | idx  | 5       | test.t2.a |    5 |   100.00 | Using where; Using join buffer (flat, BKA join); Rowid-ordered scan |
+------+-------------+-------+-------+---------------+------+---------+-----------+------+----------+---------------------------------------------------------------------+

Setting a breakpoint in handler_index_cond_check confirms the above.

Interesting that if to make the pushable condition in the second query dependent on table t2

select * from t1,t2 where t2.a in (3,4) and t1.a=t2.a and (t1.b / 10) = t2.a-1

then the optimizer chooses using index condition pushdown

MariaDB [test]> explain extended select * from t1,t2 where t2.a in (3,4) and t1.a=t2.a and (t1.b / 10) = t2.a-1;
+------+-------------+-------+-------+---------------+------+---------+-----------+------+----------+------------------------------------------------------------------------------------+
| id   | select_type | table | type  | possible_keys | key  | key_len | ref       | rows | filtered | Extra                                                                              |
+------+-------------+-------+-------+---------------+------+---------+-----------+------+----------+------------------------------------------------------------------------------------+
|    1 | SIMPLE      | t2    | range | idx           | idx  | 5       | NULL      |    2 |   100.00 | Using where; Using index                                                           |
|    1 | SIMPLE      | t1    | ref   | idx           | idx  | 5       | test.t2.a |    5 |   100.00 | Using index condition(BKA); Using join buffer (flat, BKA join); Rowid-ordered scan |
+------+-------------+-------+-------+---------------+------+---------+-----------+------+----------+------------------------------------------------------------------------------------+

though the execution of the query is incorrect due to the bug MDEV-21554.



 Comments   
Comment by Sergei Petrunia [ 2020-02-13 ]

http://lists.askmonty.org/pipermail/commits/2020-February/014157.html

@igor, please review.

Comment by Sergei Petrunia [ 2020-02-13 ]

Which version do we need the fix to be in?

Generated at Thu Feb 08 09:08:35 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.