Bug #115227 | prepared statement encounter performance degradation compared with normal select | ||
---|---|---|---|
Submitted: | 5 Jun 2024 10:45 | Modified: | 5 Jun 2024 11:22 |
Reporter: | Qingping Zhu | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S5 (Performance) |
Version: | 8.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[5 Jun 2024 10:45]
Qingping Zhu
[5 Jun 2024 11:22]
MySQL Verification Team
Hi Mr. Zhu, Thank you for your bug report. We have repeated your test successfully. The other two EXPLAINs are with default Optimiser hint: Table Op Msg_type Msg_text test.t1 analyze status OK *************************** 1. row *************************** EXPLAIN: -> Limit: 100 row(s) (cost=246421 rows=100) (actual time=0.0166..0.282 rows=100 loops=1) -> Filter: ((t1.`status` = 0) and (t1.o_id = '054a579e5ea7415ab3afd2eeb14038c1') and (t1.update_time between '2024-02-15 00:00:00' and '2024-02-21 23:59:59')) (cost=246421 rows=55542) (actual time=0.0161..0.274 rows=100 loops=1) -> Index range scan on t1 using idx_1 over (o_id = '054a579e5ea7415ab3afd2eeb14038c1' AND status = 0 AND '2024-02-15 00:00:00' <= update_time <= '2024-02-21 23:59:59') (cost=246421 rows=55542) (actual time=0.0138..0.209 rows=100 loops=1) EXPLAIN -> Limit: 100 row(s) (cost=1625 rows=100) (actual time=222..222 rows=100 loops=1)\n -> Filter: (t1.update_time between '2024-02-15 00:00:00' and '2024-02-21 23:59:59') (cost=1625 rows=1583) (actual time=222..222 rows=100 loops=1)\n -> Index lookup on t1 using idx_1 (o_id='054a579e5ea7415ab3afd2eeb14038c1', status=0) (cost=1625 rows=142443) (actual time=0.208..213 rows=122980 loops=1)\n *************************** 1. row *************************** EXPLAIN: -> Limit: 100 row(s) (cost=246421 rows=100) (actual time=0.0136..0.257 rows=100 loops=1) -> Index range scan on t1 using idx_1 over (o_id = '054a579e5ea7415ab3afd2eeb14038c1' AND status = 0 AND '2024-02-15 00:00:00' <= update_time <= '2024-02-21 23:59:59'), with index condition: ((t1.`status` = 0) and (t1.o_id = '054a579e5ea7415ab3afd2eeb14038c1') and (t1.update_time between '2024-02-15 00:00:00' and '2024-02-21 23:59:59')) (cost=246421 rows=55542) (actual time=0.0132..0.249 rows=100 loops=1) EXPLAIN -> Limit: 100 row(s) (cost=1625 rows=100) (actual time=53.4..53.4 rows=100 loops=1)\n -> Index lookup on t1 using idx_1 (o_id='054a579e5ea7415ab3afd2eeb14038c1', status=0), with index condition: (t1.update_time between '2024-02-15 00:00:00' and '2024-02-21 23:59:59') (cost=1625 rows=142443) (actual time=53.4..53.4 rows=100 loops=1)\n This is now a verified performance bug for the version 8.0 and higher. Thank you, especially for your patch !!
[8 Aug 2024 17:44]
Jon Stephens
Documented fix as follows in the MySQL 9.1.0 changelog: A query, which normally used an index range scan, used a less efficient index lookup when run as a prepared statement. Closed.
[9 Aug 2024 9:32]
MySQL Verification Team
Thank you, Jon.