You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -339,7 +339,15 @@ When this optimizer flag is off, the function that does the cost calculations de
339
339
340
340
[^1]: [WL#13929: Introduce new optimizer switch to disable limit optimization](https://dev.mysql.com/worklog/task/?id=13929)
341
341
342
-
Then everyone asks: "Should I disable this optimization (globally)?"
342
+
Should you disable this optimization (globally)?
343
+
344
+
**MySQL ≥ 8.0.40**
345
+
346
+
Yes.
347
+
Disabling `prefer_ordering_index` is safe and recommended in MySQL ≥ 8.0.40 because I [fixed the bug](https://bugs.mysql.com/bug.php?id=113699) mentioned below.
348
+
This flag defaults to on, so disabling it requires explicitly configuring [`optimizer_switch`](https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html#sysvar_optimizer_switch).
349
+
350
+
**MySQL ≤ 8.0.39**
343
351
344
352
Yes
345
353
: But only for _new development_.
@@ -362,11 +370,12 @@ If you lose, you can quickly re-enable it, or use `FORCE INDEX` to force the sec
Disabling <code>prefer_ordering_index</code> causes another bug: MySQL does not scan the primary key for <code>SELECT ... FROM t ORDER BY pk_col LIMIT n</code>.
373
+
Disabling <code>prefer_ordering_index</code> in MySQL ≤ 8.0.39 causes another bug: MySQL does not scan the primary key for <code>SELECT ... FROM t ORDER BY pk_col LIMIT n</code>.
366
374
Instead, it does a <em><b>full</b> table scan</em> plus sort, which is unnecessary and very likely to cause problems.
367
375
Unlike the main subject of this blog post, I would call this a real bug.
368
376
Thank you to Jay Janssen and Morgan Tocker for brining this to my attention.
369
-
When I have time, I'll debug the source code for this and write another blog post.
377
+
<br><br>
378
+
I fixed <a href="https://bugs.mysql.com/bug.php?id=113699">this bug</a> in MySQL 8.0.40.
0 commit comments