約300万行のテーブルがあります。そして、私がこのクエリを使用して選択している間:
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;
そしてそれは>17秒かかりました。しかし、それを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つと同じ速度で実行できるようにするにはどうすればよいですか。
皆さん、ありがとうございました!
更新:これらはテーブルのインデックスです
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