index_merge/intersection is used when ref(const) is faster
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
In Progress
|
Medium
|
Sergey Petrunia |
Bug Description
The queries were provided by Stephane Varoqui here: http://
The dataset is lots.tgz, uploaded to ftp.askmonty.
EXPLAIN outputs and query time:
MariaDB [lots]> explain SELECT count(*) AS amount FROM lots WHERE contractNumber=
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | SIMPLE | lots | index_merge | tsClosed,
+----+-
1.85 sec.
MariaDB [lots]> explain SELECT count(*) AS amount FROM lots ignore index(tsClosed) WHERE contractNumber=
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | SIMPLE | lots | ref | contractNumber | contractNumber | 5 | const | 28600 | Using where |
+----+-
0.30 sec
MariaDB [lots]> explain SELECT count(*) AS amount FROM lots ignore index(contractN
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | SIMPLE | lots | ref | tsClosed | tsClosed | 5 | const | 243422 | Using index condition; Using where |
+----+-
4.50 sec
As one can see, index_merge/
Changed in maria: | |
assignee: | nobody → Sergey Petrunia (sergefp) |
Changed in maria: | |
status: | New → Confirmed |
status: | Confirmed → In Progress |
Let's explore the dataset: here's numbers of matching records for both parts of the WHERE:
Total rows: 2 137 152 '1478876' - 30 000 (estimate: 28 600) '1478876' AND lots.tsClosed IS NULL - 10 000 (index_merge's estimate: 3257)
lots.tsClosed IS NULL - 544 288 (estimate: 243 422)
contractNumber=
contractNumber=
* index_merge's estimate of 3257 was obtained assuming both parts of WHERE are not correlated. In fact, they're strongly correlated.
* Estimate for "lots.tsClosed IS NULL" misses the real value by the order of two.