I am new to MySQL. So I found that someone wrote some SQL in our production environment:
SELECT o.`erp_orders_id` FROM `erp_orders` o WHERE o.`orders_status`> 2 AND o.`orders_status`< 5 AND o.`shipmentAutoMatched` IN (SELECT s.`shipmentID` FROM `erp_shipment` s WHERE s.`shipmentScanLocal` = 2)
where s.shipmentID is int(11) and o.shipmentAutoMatched is int(6) .
This query is indexed.
IDX_OR_OR_CU(orders_status, orders_type, currency_type)
So far I have another index:
IDX_OR_SH(orders_status, shipmentAutoMatched)
which, I think, could be more effective. and if I change the IN directive to numbers like:
IN(10, 11, 12)
IDX_OR_SH is IDX_OR_SH . so I think the only problem might be regarding int(11) and int(6) .
So the questions are:
- Am I right?
- How does this problem occur when
int(11) and int(6) are both int and they are actually saved as INT32 - How can I solve this problem?
source share