這個sql運行很慢,4秒鐘
SELECT (op.cash_payment+op.pos_payment+op.online_payment+op.charge_card_payment) AS real_payment,op.* FROM db_order.`order_payment` AS op WHERE op.order_payment_id in (SELECT oi.order_payment_id FROM db_order.`order_info` AS oi WHERE oi.batch_order_id = '123456') ORDER BY op.insert_time DESC
SELECT (op.cash_payment+op.pos_payment+op.online_payment+op.charge_card_payment) AS real_payment,op.* FROM db_order.`order_payment` AS op,db_order.`order_info` oi WHERE op.order_payment_id=oi.order_payment_id and oi.batch_order_id = '123456' ORDER BY op.insert_time DESC
發給朋友,朋友說相當快,在0.011S。
看來 這個IN確實需要謹慎使用,特別是在兩表關聯的時候,應該把in替換成內鏈接