[MDEV-5555] Incorrect index_merge on BTREE indices Created: 2014-01-23 Updated: 2014-02-26 Resolved: 2014-02-17 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.5.34, 10.0.8 |
| Fix Version/s: | 5.5.36, 10.0.9 |
| Type: | Bug | Priority: | Major |
| Reporter: | Nicholas Hwang | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
mysql Ver 15.1 Distrib 5.5.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.1 Ubuntu 12.04 LTS |
||
| Attachments: |
|
| Description |
|
Trying to simplify the context for this problem, but let me know if you require additional information. I have a table named base with several columns, including a field named id. Each field has a BTREE index created via create index X on base(X) I've found that queries of the type select id from base where X = 'value1' and Y = 'value2' do not return the correct number of results. If I do a select id, X from base where Y = 'value2' order by X, I can see a full and accurate list of all combinations of X and Y = 'value2', since this query does not execute an index_merge (running an explain on this shows that its a ref query using the index on Y). But running select id from base where X = 'value1' and Y = 'value2' clearly shows that some rows are dropped from the results when compared to what you see with select id, X from base where Y = 'value2' order by X. Running an explain shows that an index_merge is run on the indices on both X and Y. Rebuilding the indices does not fix the problem, and results in the same rows consistently being dropped from the query results. I can provide firmer context with actual query outputs if this is too abstract. Thanks for your help. |
| Comments |
| Comment by Elena Stepanova [ 2014-01-28 ] | ||||||||||
|
Hi, Yes, it would be great if you could provide a data dump for the tables involved into the query, and the actual query. If the data is sensitive, you can upload it to the private section of our FTP (ftp://ftp.askmonty.org/private/) We have some open bugs regarding index_merge, but it's difficult to say whether your case is related to them or not without the actual data. | ||||||||||
| Comment by Michael Reschly [ 2014-02-07 ] | ||||||||||
|
Hi Elena, I work with Nick. I put a data dump in the private FTP folder you referenced (10krows_bugtest.sql.gz). The data isn't private (it's synthetically generated), but it's ~1GB compressed/1.4GB uncompressed, which seemed too big to attach to attach to JIRA. As for queries which give differing results: select id, fname, race, state from base where fname = 'Michael' and race = 'White' and state = 'California'; returns 7 rows | ||||||||||
| Comment by Michael Reschly [ 2014-02-10 ] | ||||||||||
|
Significantly smaller database dump that demonstrates the index_merge issue. All data contained within this file is fully synthetic. Any similarity to any persons, real or fictional, is purely coincidental. | ||||||||||
| Comment by Michael Reschly [ 2014-02-10 ] | ||||||||||
|
I attached a much smaller database that demonstrates the same issue, which should be easier to work with. As for queries: Query using index: Query 2 of three terms, order by third: | ||||||||||
| Comment by Elena Stepanova [ 2014-02-13 ] | ||||||||||
|
Thank you for creating the test case! I reduced it a bit further, and replaced data with generic values, it is attached as mdev5555.test. Output of the queries:
| ||||||||||
| Comment by Sergei Petrunia [ 2014-02-14 ] | ||||||||||
|
index_merge and partitioned tables- this could be the same issue as | ||||||||||
| Comment by Sergei Petrunia [ 2014-02-15 ] | ||||||||||
|
Records are read this way: #0 key_rec_cmp QUICK_ROR_INTERSECT_SELECT requires that its inputs are ordered by Rowid. ha_partition does an ordered index scan. The scan is done as follows: get a row from each partition, put them into a priority queue, then get the row from the top of the priority queue. Put another row there, repeat. The problem is that ha_partition will not produce records in rowid order when using this strategy. Rowid for ha_partition table is {partition_no, underlying_table_rowid}, and ha_partition::cmp_ref() compares rowid tuples in lexicographic order (ie. partition_no is compared first, then rowid). | ||||||||||
| Comment by Sergei Petrunia [ 2014-02-15 ] | ||||||||||
|
Elena has found MySQL's fix for Bug#17588348. (See That fix changes ha_partition::cmp_ref() to compare {partition_no, underlying_table_rowid}pairs by comparing underlying_table_rowid first, and partition_no second. The problem is that this still doesn't make ha_partition to produce rowid-ordered streams. | ||||||||||
| Comment by Sergei Petrunia [ 2014-02-17 ] | ||||||||||
|
Fix pushed into 5.5 tree and will be in the next 5.5 release. Thanks for the detailed bug report, and for the testcase. | ||||||||||
| Comment by Nicholas Hwang [ 2014-02-18 ] | ||||||||||
|
Wonderful, thanks! We have some very large existing datasets that we'd like to use as is, if possible. Does this bug require that these datasets be regenerated using the patched server? Or just that the indices be re-created? Or just that the patched server be running? | ||||||||||
| Comment by Sergei Petrunia [ 2014-02-18 ] | ||||||||||
|
The patch only changes the way data is read. There is no need to regenerate data or to rebuild indexes. It should be sufficient to start the patched server on the existing data directory. | ||||||||||
| Comment by Nicholas Hwang [ 2014-02-19 ] | ||||||||||
|
Excellent, thanks so much for the quick turn around. | ||||||||||
| Comment by Michael Reschly [ 2014-02-26 ] | ||||||||||
|
> There is no need to regenerate data or to rebuild indexes. It should be sufficient to start the patched server on the existing data directory. Hi Sergi, I just wanted to confirm that this was the case. I used patched binaries on our existing data and the correct results were returned without regenerating data or re-indexing. Thanks again. |