0

このクエリを最適化する方法はありますか?

select 
orders_id,
orders_products_id,
sum(CASE products_options_id WHEN 1 THEN products_options_values_id ELSE 0 END) as color,
sum(CASE products_options_id WHEN 2 THEN products_options_values_id ELSE 0 END) as talle

from 
orders_products_attributes 

group by 
orders_products_id

これはEXPLAIN出力です。

id  select_type   table                       type   possible_keys   key   key_len   ref     rows   Extra
1   SIMPLE        orders_products_attributes  ALL    NULL            NULL  NULL      NULL  69006  Using temporary; Using filesort

ありがとう!

ルチアーノ

4

1 に答える 1

0

列 (orders_product_id、products_options_id、orders_id) を使用して、このクエリのカバリング インデックスを作成することをお勧めします。

CREATE INDEX ix_opa_opid_poid_oid
    ON orders_products_attributes (orders_product_id, products_options_id, orders_id)
于 2012-10-29T16:22:56.900 に答える