3
我有一個大約有3mil行的表。雖然我用這個查詢來選擇: SELECT WITH WITH在多列上的速度很慢
SELECT order_code, store_debit, total_price
FROM orders
WHERE 4624603 IN (id, pid) AND `status` = -6;
或此查詢(使用OR)
SELECT order_code, store_debit, total_price
FROM orders
WHERE (id = 4624603 OR pid = 4624603) AND `status` = -6;
和一個帶> 17secs。 但是當我把它分成2個查詢:
SELECT order_code, store_debit, total_price
FROM orders
WHERE id = 4624603 AND `status` = -6;
和
SELECT order_code, store_debit, total_price
FROM orders
WHERE pid = 4624603 AND `status` = -6;
返回像瞬間結果。 我怎麼能優化第一個查詢,使其運行速度與其他2.
謝謝大家!
UPDATE: 這些表
cop_type payment_type, cod_type, cash_transfer, pid, status, created Normal BTREE
all_type payment_type, cash_transfer, pid, status, created Normal BTREE
theodoi user_id, pid, payment_type, cash_transfer, status, report_atm, pay_status, created Normal BTREE
item_lib item_id, status, pay_status, payment_type, created Normal BTREE
search_phone phone Normal BTREE
search_order_code order_code Normal BTREE
search_order_email email Normal BTREE
order_work cod_id, status, district, payment_type, pay_status, cash_transfer, cod_type, free_ship Normal BTREE
select_hot province, status, type, created, payment_type, pay_status, item_id Normal BTREE
coupon_after_buy id, pid, status, free_ship Normal BTREE
search_ofice office, created, status, ship_status Normal BTREE
search_item item_id, office, created, status, ship_status Normal BTREE
idx_ward_id ward_id Normal BTREE
idx_street street_id Normal BTREE
idx_group_code group_code, pid Normal BTREE
idx_paytime payment_time Normal BTREE
search_all pid, status, created Normal BTREE
idx_country_type country_type Normal BTREE
idx_book_time book_time Normal BTREE
索引'id'和'pid' – 2013-03-27 04:27:03
對不起,我用** OR **和** IN **更新了這個問題,他們都很慢 – CasperPas 2013-03-27 04:28:48
@HankyPankyㇱ:我更新了我的問題。我應該只索引id和pid在一個新的索引鍵嗎?我已經在** coupon_after_buy **索引 – CasperPas 2013-03-27 04:32:38