mysql varchar類型條件查詢不加引號

一張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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章