抱歉这里面的数据是再用的,不太好发过来,可以远程操作查看;
sql:
EXPLAIN ANALYZE SELECT COUNT(*) FROM(select a.Acc_authorize ,a.Acc_SF_FirstName ,a.Acct_Cust_Name ,a.ID,a.Acc_ISTopCustomer,a.Acc_IsVip,a.Acc_AccountName,a.Acc_CustomerName,a.Acc_AccountID,a.Acc_ALevel,a.Acc_BLevel,b.Sys_DeptName,a.Acc_CompanyID from work_account a left join sys_dept b on a.Acc_CompanyID=b.Sys_DeptID and b.Sys_DeptLevel=2 where 1=1 ) as t;
greatsql:
| -> Aggregate: count(0) (cost=2689843.84 rows=1) (actual time=18842.025..18842.025 rows=1 loops=1)
-> Nested loop left join (cost=2208423.44 rows=4814204) (actual time=0.097..18277.875 rows=4914510 loops=1)
-> Covering index scan on a using index_companyID (cost=523452.04 rows=4814204) (actual time=0.083..1353.213 rows=4914510 loops=1)
-> Filter: (b.Sys_DeptLevel = 2) (cost=0.25 rows=1) (actual time=0.003..0.003 rows=0 loops=4914510)
-> Single-row index lookup on b using PRIMARY (Sys_DeptID=a.Acc_CompanyID) (cost=0.25 rows=1) (actual time=0.003..0.003 rows=0 loops=4914510)
Mysql:
| -> Aggregate: count(0) (cost=2.39e+6 rows=1) (actual time=2287..2287 rows=1 loops=1)
-> Nested loop left join (cost=1.96e+6 rows=4.32e+6) (actual time=0.104..2107 rows=4.92e+6 loops=1)
-> Covering index scan on a using index_companyID (cost=451138 rows=4.32e+6) (actual time=0.0798..912 rows=4.92e+6 loops=1)
-> Filter: (b.Sys_DeptLevel = 2) (cost=0.25 rows=1) (actual time=142e-6..153e-6 rows=0.201 loops=4.92e+6)
-> Single-row index lookup on b using PRIMARY (Sys_DeptID=a.Acc_CompanyID) (cost=0.25 rows=1) (actual time=65.8e-6..69.3e-6 rows=0.201 loops=4.92e+6) |