MySQL query optimizer doesn't necessarily use unique key in BuildUniqueKeyRangeEndPreparedQueryViaOffset's query
Maintainer antworten meist innerhalb von 10 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Suche nach BuildUniqueKeyRangeEndPreparedQueryViaOffset und untersuche, wie diese MySQL-Abfrage erstellt wird. Reproduziere das gemeldete EXPLAIN- und SELECT-Verhalten mit und ohne USE INDEX (PRIMARY) und ermittle anschließend, ob das Erzwingen des Index sicher ist. Als erledigt gilt die Aufgabe, wenn das Optimizer-Problem mit einer Abdeckung für den betroffenen Abfragepfad behoben ist, sofern dieser Ansatz geeignet ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
We've run into an issue where the gh-ost migration starts off fine, but at some point, the MySQL query optimizer behavior changes for this query, and this query starts taking ~15m.
The explain query shows that the MySQL query optimizer is doing an index scan
mysql> explain select `applicationId`, `id` from `_workflowActionExecutions` where ((`applicationId` > _binary'appAAAA') or (((`applicationId` = _binary'appAAAA')) AND (`id` > _binary'waxAAAA'))) and ((`applicationId` < _binary'appZZZZ') or (((`applicationId` =
_binary'appZZZZ')) AND (`id` < _binary'waxZZZZ')) or ((`applicationId` = _binary'appZZZZ') and (`id` = _binary'waxZZZZ'))) order by `applicationId` asc, `id` asc limit 1 offset 999;
+----+-------------+---------------------------+------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+---------+------+------+----------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+---------------------------+------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+---------+------+------+----------+--------------------------+
| 1 | SIMPLE | _workflowActionExecutions | NULL | index | PRIMARY,IDX_applicationId_workflowGraphExecutionId,IDX_applicationId_workflowExecutionId_status_branchId,IDX_applicationId_status_workflowId,IDX_applicationId_workflowId_status_processTime,IDX_id | PRIMARY | 34 | NULL | 1000 | 100.00 | Using where; Using index |
+----+-------------+---------------------------+------------+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+---------+------+------+----------+--------------------------+
1 row in set, 1 warning (0.47 sec)
(ids fuzzed)
This is because MySQL thinks that if we USE INDEX (PRIMARY), it will end up doing a massive range scan
mysql> explain select `applicationId`, `id`
-> from `_workflowActionExecutions` USE INDEX (PRIMARY)
-> where ((`applicationId` > _binary'appAAAA') or (((`applicationId` = _binary'appAAAA')) AND (`id` > _binary'waxAAAA'))) and ((`applicationId` < _binary'appZZZZ') or (((`applicationId` = _binary'appZZZZ')) AND (`id` < _binary'waxZZZZ')) or ((`applicationId` = _binary'appZZZZ') and (`id` = _binary'waxZZZZ')))
-> order by `applicationId` asc, `id` asc
-> limit 1
-> offset 999;
+----+-------------+---------------------------+------------+-------+---------------+---------+---------+------+----------+----------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+---------------------------+------------+-------+---------------+---------+---------+------+----------+----------+--------------------------+
| 1 | SIMPLE | _workflowActionExecutions | NULL | range | PRIMARY | PRIMARY | 34 | NULL | 95809902 | 100.00 | Using where; Using index |
+----+-------------+---------------------------+------------+-------+---------------+---------+---------+------+----------+----------+--------------------------+
1 row in set, 1 warning (0.46 sec)
(note the massive amount of rows)
But if I run the query with USE INDEX (PRIMARY), it's actually really fast, instead of taking ~15m
mysql> select `applicationId`, `id`
-> from `_workflowActionExecutions` USE INDEX (PRIMARY)
-> where ((`applicationId` > _binary'appAAAA') or (((`applicationId` = _binary'appAAAA')) AND (`id` > _binary'waxAAAA'))) and ((`applicationId` < _binary'appZZZZ') or (((`applicationId` = _binary'appZZZZ')) AND (`id` < _binary'waxZZZZ')) or ((`applicationId` = _binary'appZZZZ') and (`id` = _binary'waxZZZZ')))
-> order by `applicationId` asc, `id` asc
-> limit 1
-> offset 999;
+-------------------+-------------------+
| applicationId | id |
+-------------------+-------------------+
...
+-------------------+-------------------+
1 row in set (0.53 sec)
Is it possible to force the use of the index when constructing the query? Is that an appropriate solution?
- Vorherrschende Sprache
- Go
- Sterne
- 13.6k
- Forks
- 1.4k
- Ø Merge
- 9 T. 19 Std.
- Gemergte PRs (30 T.)
- 1
Entwicklungsumgebung
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus github/gh-ost
-
`--resume` without `--execute` drops the ghost table it correctly skipped alteringEvtl. vergeben @ajm188 hat das vor 56 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
Maintainer antworten meist innerhalb von 10 Tagen
-
[Suggestion] Apply simple validation to alter commandEvtl. vergeben @drkemp187 hat das vor 106 Tagen übernommen. Offenenhancement good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
github/gh-ost#1431 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 10 Tagen
-
Migration hangs when --attempt-instant-ddl succeedsEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 30/100
Maintainer antworten meist innerhalb von 10 Tagen
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
Maintainer antworten meist innerhalb von 10 Tagen
-
Atomic cut-over always fails on MySQL 9.1+: information_schema.processlist errors out (3854) while another session runs a non-BMP utf8mb4 statementEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
github/gh-ost#1780 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 10 Tagen
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
oxc-project/tsgolint#1362 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
hashicorp/terraform-provider-google#30703 ·
Maintainer antworten meist innerhalb von 1 Tag
-
UpdateSchema.BuildUpdates should select newly added schemas with schema-id: -1Evtl. vergeben @nisan1101 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
apache/iceberg-go#2586 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
FR: update golang.org/x/sys to v0.50.0Evtl. vergeben @wrenix hat das heute übernommen. Offenfr needs-triage
Schwierigkeit 2/5 Unter einer Stunde Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Docs] Four internal links return 404 (Models concept, Contributing to Docs, Providers reference)Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
meshery/meshery#23520 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag