Commit ffad6cf
committed
Bug#35952353 SELECT COUNT(*) degraded performance on 8.0 compared to 5.7
Symptoms
----------
The SELECT COUNT(*) query that uses secondary index for scan, takes more
than 6X with 8.0 compared to 5.7. Performance of the query that use the
clustered index for scan is at par with 5.7.
Background
----------
In 8.0.14, we introduced parallel scan of subtrees of a clustered index
through 'WL#11720 InnoDB: Parallel read of index'. This feature was
further improved through 'WL#12978 InnoDB:Fix imbalance during parallel
scan' in 8.0.17.
The idea of the second worklog was to utilize the parallel read threads
which were introduced through first worklog.
Second worklog also made another intentional change(not documented!)
that is, secondary index scan in InnoDB started using the parallel scan
of clustered index. In other words, even if Optimizer hints InnoDB to
use secondary index for scan, InnoDB ignores that, and uses clustered
index for scan. This observation was reported in the following bugs:
'Bug#31791868 INDEX HINT DOES NOT AFFECT COUNT(*) EXECUTION'
'Bug#35981123 SELECT COUNT is slow with O_DIRECT'
The second worklog enabled the clustered index (parallel) scan even for
secondary index scan for the following two reasons :
- Post WL#12978, performance of clustered index scan was much improved.
- Cost of scanning the secondary index is much higher to support the
MVCC semantics i.e. read-committed, repeatable-read isolation levels.
That is because before reporting a record from a secondary index,
InnoDB must ensure it is visible to the query's read-view. That might
require a dive into clustered index to consult corresponding row's
undo chain. This can be avoided in case InnoDB sees that a secondary
index record was not modified since read-view's creation, but
unfortunately this information is not available per-row, only
per-page. So, if any of the records on the page was modified since
read-view's creation, the heuristic will not help, and dives to
clustered index will be needed for all records from this secondary
index page.
The second reason is main argument behind this change which can be
easily reproduced by modifying a few records in the table and then
executing the query in a session that has read_view created before
the modification, for example by having opened transaction on
isolation level of Repeatable Read before the modifications.
In my experiment, I found with secondary index scan(or with this fix),
query performed 30X worse than the query performed without a read view.
Thus it is really a trade off between using the clustered scan that is
better in worst case vs using the secondary index as Optimizer hints
which is better in most of the cases.
Fix
----
- Do not break the contract with Optimizer(Bug#31791868). User now
(again) has an option to provide index hint to the query, to force
using clustered index.
- We must improve Optimizer's heuristic so that it can hints the
correct index to use. Created 'Bug#36297856 Query performance
dropped by 30X with secondary index scan due to MVCC checks',
for Optimizer team to improve the heuristic in Optimizer.
- Reverted part of the WL#12978 changes that forced clustered index
(parallel) scan for secondary index scan.
Change-Id: Icb081d076cb6875e7b973e68ff6cfcce8ae3f82a1 parent 43fc874 commit ffad6cf
File tree
3 files changed
+24
-34
lines changed- mysql-test/r
- storage/innobase/handler
3 files changed
+24
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
| 55 | + | |
| 56 | + | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | | - | |
| 103 | + | |
| 104 | + | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
152 | | - | |
| 151 | + | |
| 152 | + | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
229 | | - | |
| 228 | + | |
| 229 | + | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | | - | |
283 | | - | |
| 282 | + | |
| 283 | + | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
408 | | - | |
| 407 | + | |
| 408 | + | |
409 | 409 | | |
410 | | - | |
| 410 | + | |
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
| |||
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
455 | | - | |
456 | | - | |
| 455 | + | |
| 456 | + | |
457 | 457 | | |
458 | | - | |
| 458 | + | |
459 | 459 | | |
460 | 460 | | |
461 | 461 | | |
| |||
487 | 487 | | |
488 | 488 | | |
489 | 489 | | |
490 | | - | |
491 | | - | |
| 490 | + | |
| 491 | + | |
492 | 492 | | |
493 | | - | |
| 493 | + | |
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | 256 | | |
262 | 257 | | |
263 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1114 | 1114 | | |
1115 | 1115 | | |
1116 | 1116 | | |
1117 | | - | |
1118 | | - | |
1119 | | - | |
1120 | | - | |
1121 | | - | |
1122 | 1117 | | |
1123 | 1118 | | |
1124 | 1119 | | |
| |||
0 commit comments