SQL执行计划顺序是:id如果相同,可以认为是一组,从上往下顺序执行;在所有组中,id值越大,优先级越高,越先执行。不过,对于标量子查询,
并非是id值越大,越先执行。如下面的执行计划顺序是:
r(1)->o(1)->ds(1)->(icd(3)+d(2))
EXPLAIN SELECT ds . OPERATING_UNIT_CODE AS OPERATING_UNIT_CODE,
ds.OPERATING_UNIT AS OPERATING_UNIT,o.ORDER_END_TIME AS PAYMENT_TIME,
IFNULL(o.CHARGE_QUANTITY, 0) AS CHARGE_QUANTITY,
IFNULL(o.CHARGE_ELECTRICITY, 0) AS TOTAL_FEE,
(SELECT IFNULL(d . TIME_CHARGE, 0)
FROM gg_bm_o_order_charge_detail d
WHERE ((o.ID = d.ORDER_ID) AND (d.PRICE_TYPE = 6))) AS FEE,
IFNULL((SELECT SUM(icd . TOTAL_FEE)
FROM gg_p_elec_detail_pay icd
WHERE ((icd.TRADE_NO = r . TRADE_NO) AND
(icd.PAYMENT_TYPE = 2))),
0) AS retrieveFEE
FROM ((gg_p_elec_currency_pay r LEFT JOIN gg_bm_o_order o
ON((r.TRADE_NO = o.ORDER_CODE))) LEFT JOIN gg_om_dm_site ds
ON((o.SITE_CODE = ds.SITE_CODE)))
WHERE (r . PAYMENT_TYPE = 1);
id select_type table type possible_keys key key_len ref rows Extra
------ ------------------ ------ ------ ------------------------------- ------------------------------- ------- --------------------- ------ -------------
1 PRIMARY r ALL (NULL) (NULL) (NULL) (NULL) 68926 Using where
1 PRIMARY o ref IDX_ORDER_CODE IDX_ORDER_CODE 99 r.TRADE_NO 1 Using where
1 PRIMARY ds ref IDX_SITE_CODE IDX_SITE_CODE 99 o.SITE_CODE 1 Using where
3 DEPENDENT SUBQUERY icd ref ind_ipedp_TRADE_NO_PAYMENT_TYPE ind_ipedp_TRADE_NO_PAYMENT_TYPE 101 r.TRADE_NO,const 1
2 DEPENDENT SUBQUERY d ref FK_ORDER_DETAIL_ORDER_ID FK_ORDER_DETAIL_ORDER_ID 99 o.ID 2 Using where