一張160w數據量的表
select * from order_promotion where order_no='15441913435665186'
select * from order_promotion where order_no=15441913435665186
使用兩條sql的查詢時間查了一百多倍。
orde_no存在索引。
通過explain select * from order_promotion where order_no=15441913435665186
可以發現 並沒有使用索引,而加引號之後纔會使用索引。
參數類型與數據庫類型不同,雖然能自動轉換,但無法走索引
You are comparing indexed columns with constant values and MySQL has calculated (based on the index tree) that the constants cover too large a part of the table and that a table scan would be faster.
https://dev.mysql.com/doc/refman/8.0/en/table-scan-avoidance.html