[MDEV-6255] DUPLICATE KEY Errors on SELECT .. GROUP BY that uses temporary and filesort Created: 2014-05-20 Updated: 2014-10-11 Resolved: 2014-09-12 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5.37, 10.0.10 |
| Fix Version/s: | 10.0.14 |
| Type: | Bug | Priority: | Major |
| Reporter: | Chris Calender (Inactive) | Assignee: | Michael Widenius |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Windows, Linux |
||
| Attachments: |
|
| Description |
|
Import the table provided into a MariaDB 5.5 and/or 10.0 instance, ensure your max_heap_table_size and tmp_table_size are 32M or less, and issue these queries:
It returns DUPLICATE KEY errors: Here is the table structure:
The GROUP BY must be in the query to trigger the error. Notice that if I increase max_heap_table_size and tmp_table_size (512M seems to work here), then the query runs as expected.
After-thought: With the same tmp/heap table sizes, the query runs fine in MySQL 5.5.37, though the bug looks somewhat similar to this open MySQL bug: http://bugs.mysql.com/bug.php?id=58081 |
| Comments |
| Comment by Elena Stepanova [ 2014-05-21 ] | |||||||||||||||||||||||||||
|
On a debug version, the same scenario causes an assertion failure:
Stack trace from:
| |||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2014-09-09 ] | |||||||||||||||||||||||||||
|
The reason it fails in the debug version is that we have an assert to catch any bugs when re-creating keys (under normal circumstances this should never fail). The problem here is that one of the composers contains 0x20C2A0 (space, no-break space) at the end (id_album= 116996). This end-string is sorted differently in my_hash_sort() and my_strnncollsp() which causes a duplicated key when we convert the internal hash table to an aria table. The fix is to ensure that both sort methods will work identically. | |||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2014-09-10 ] | |||||||||||||||||||||||||||
|
This SQL script demonstrates the same problem using partitions:
The first query correctly returns all values:
The second query returns only one value:
This happens because different hash values are erroneously calculated for the four equal values, Note, 0x20 and 0x60 are equal in cp1251_ukrainian_ci. | |||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2014-09-12 ] | |||||||||||||||||||||||||||
|
Fix pushed |