[MDEV-5177] ha_partition and innodb index intersection produce fewer rows (MySQL Bug#70703) Created: 2013-10-23 Updated: 2014-03-11 Resolved: 2014-03-11 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.5.33a |
| Fix Version/s: | 5.5.37 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
Even after fix for Testcase:
|
| Comments |
| Comment by Arnaud Gadal [ 2014-02-07 ] | |||||||||||||||||||||||||||||||||||||||||
|
It seems it's ok with MySQL 5.6.16, I obtain 802 rows in either cases. | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-14 ] | |||||||||||||||||||||||||||||||||||||||||
|
Repeatable on MySQL 5.6.15 though. | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-14 ] | |||||||||||||||||||||||||||||||||||||||||
|
But not on mysql-5.5.35. It seems the bug is somewhere in the code common between mariadb-5.5 and mysql-5.6. | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-14 ] | |||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2014-02-14 ] | |||||||||||||||||||||||||||||||||||||||||
|
The bug was fixed in mysql/5.6 tree by the following revision:
But it does not fix the test case from | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-17 ] | |||||||||||||||||||||||||||||||||||||||||
|
Again, full analysis:
MySQL's solution is to change ha_partition::cmp_ref() so that the rowid order Our solution is to make ha_partition::handle_ordered_index_scan() to produce rows in the order of (key_value, partition_id). | |||||||||||||||||||||||||||||||||||||||||
| Comment by Arnaud Gadal [ 2014-02-26 ] | |||||||||||||||||||||||||||||||||||||||||
|
I've just tried on the latest MariaDB 5.5.36 and I still get 794 and 802 rows although this bug is tagged as fixed... | |||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2014-02-26 ] | |||||||||||||||||||||||||||||||||||||||||
|
Indeed, the bug was fixed by revno 4074, but immediately re-appered with the postfix 4075:
| |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-27 ] | |||||||||||||||||||||||||||||||||||||||||
|
It is interesting, how the bug could reappear.. mysql-test/t/partition.test has a testcase for | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-27 ] | |||||||||||||||||||||||||||||||||||||||||
|
Still, somehow it reappeared. If I run manually the testcase provided here, I'm able to observe different numbers of rows to be returned. | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-27 ] | |||||||||||||||||||||||||||||||||||||||||
|
Ok, the problem with the testcase is that I've added into a file that runs with storage_engine=myisam. This was appropriate for | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-27 ] | |||||||||||||||||||||||||||||||||||||||||
|
Debugging the query, I see that merged index scans do not return records in Debugging further, one can see the reason of this. The table's keys are: primary key (pk), extended_keys feature causes the key to be (pk, a) When I added cmp_key_then_part_id(), it defined the ordering as index scan is done on a=1, which means #1 is constant. From that it followed that cmp_key_then_part_id will return records ordered by part_id. That ordering will match the ordering defined by ha_partition::cmp_ref() which starts by comparing part_id. In reality, the following happens: cmp_key_then_part_id() defines ordering as index scan returns values with a=1, but different values of pk. The ordering doesn't match ordering of ha_partition::cmp_ref anymore. | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-27 ] | |||||||||||||||||||||||||||||||||||||||||
|
== Ideas on how this could be fixed == Ordered index scans over ha_partition return records in the order of (key, extended_key_parts, ...). It could be nice to get index_merge to inform the storage engine that it needs the index scans to be rowid-ordered but not key-ordered, but this is a too big change for a GA version. | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-27 ] | |||||||||||||||||||||||||||||||||||||||||
|
A possible solution: index scan on ha_partition must return records ordered by key_value, ext_key_parts (if there are any) When ROR-index_merge is used, the key_value part is fixed, which means that ext_key_parts (if there are any) On the other hand, ROR-index_merge requires that rows come in the order that The solution is: key_rec_cmp, then part_id - for tables with extended keys (we do this now) 2. Let ha_partition::cmp_ref() compare rowids by comparing underlying_rowid | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-27 ] | |||||||||||||||||||||||||||||||||||||||||
|
Committed another fix. I'll need a review for it. | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-03-04 ] | |||||||||||||||||||||||||||||||||||||||||
|
igor, as you have requested: please find the attached testcase (mdev5555-innodb.test) which fails in MySQL 5.6. | |||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-03-11 ] | |||||||||||||||||||||||||||||||||||||||||
|
Fix pushed into 5.5 tree |