下面是同一查询的EXPLAIN输出。一个使用STRAIGHT_JOIN,另一个没有。哪一个是更好的计划?
以下是详情
第一个(使用STRAIGHT_JOIN) -
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: main_table
type: range
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: NULL
rows: 345
Extra: Using where
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: broker
type: ref
possible_keys: UNQ_CATALOG_PRODUCT_ENTITY_INT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_INT_ATTRIBUTE_ID,IDX_CATALOG_PRODUCT_ENTITY_INT_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_INT_ENTITY_ID
key: IDX_CATALOG_PRODUCT_ENTITY_INT_ATTRIBUTE_ID
key_len: 2
ref: const
rows: 1
Extra: Using where
*************************** 3. row ***************************
id: 1
select_type: SIMPLE
table: category_product
type: eq_ref
possible_keys: PRIMARY,IDX_CATALOG_CATEGORY_PRODUCT_PRODUCT_ID
key: PRIMARY
key_len: 8
ref: ma.main_table.entity_id,ma.broker.entity_id
rows: 1
Extra: Using index
*************************** 4. row ***************************
id: 1
select_type: SIMPLE
table: price_index
type: eq_ref
possible_keys: PRIMARY,IDX_MULTIVENDOR_WEBSITE_INDEX_PRICE_CATEGORY_ID
key: PRIMARY
key_len: 6
ref: const,ma.main_table.entity_id
rows: 1
Extra:
第二个(没有STRAIGHT_JOIN) -
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: broker
type: ref
possible_keys: UNQ_CATALOG_PRODUCT_ENTITY_INT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_INT_ATTRIBUTE_ID,IDX_CATALOG_PRODUCT_ENTITY_INT_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_INT_ENTITY_ID
key: IDX_CATALOG_PRODUCT_ENTITY_INT_ATTRIBUTE_ID
key_len: 2
ref: const
rows: 1
Extra: Using where; Using temporary; Using filesort
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: category_product
type: ref
possible_keys: PRIMARY,IDX_CATALOG_CATEGORY_PRODUCT_PRODUCT_ID
key: IDX_CATALOG_CATEGORY_PRODUCT_PRODUCT_ID
key_len: 4
ref: ma.broker.entity_id
rows: 1
Extra: Using where; Using index
*************************** 3. row ***************************
id: 1
select_type: SIMPLE
table: main_table
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: ma.category_product.category_id
rows: 1
Extra: Using where
*************************** 4. row ***************************
id: 1
select_type: SIMPLE
table: price_index
type: eq_ref
possible_keys: PRIMARY,IDX_MULTIVENDOR_WEBSITE_INDEX_PRICE_CATEGORY_ID
key: PRIMARY
key_len: 6
ref: const,ma.main_table.entity_id
rows: 1
Extra: Using where