所以有两个查询。为什么第一个比第二个运行得快得多?如何优化我的内部连接以与第一个连接一样快?
总记录超过 4 000 000
idTerminals 已编入索引
select (select name
from terminals
where terminals.idTerminals = AnalyzeProfitResults.idTerminals),
currency,
count(*)
from AnalyzeProfitResults
group by AnalyzeProfitResults.idTerminals,currency;
select name,
currency,
count(*)
from AnalyzeProfitResults
inner join terminals on terminals.idTerminals = AnalyzeProfitResults.idTerminals
group by AnalyzeProfitResults.idTerminals,currency;
结果是一样的:
name,currency,count(*)
"Buy or sell",EURUSD,235105
"Buy or sell",GBPUSD,14515
"Buy or sell",USDJPY,235298
"very strict",AUDJPY,234787
"very strict",AUDUSD,235298
"very strict",CHFJPY,235298
"very strict",EURJPY,235298
"very strict",EURUSD,235298
"very strict",GBPJPY,235298
"very strict",GBPUSD,235298
"very strict",NZDUSD,235298
"very strict",USDCHF,235298
"very strict",USDJPY,235298
",normal",AUDJPY,235298
",normal",AUDUSD,36391
",normal",EURUSD,234985
",normal",GBPJPY,117649
",normal",NZDUSD,198552
",normal",USDCHF,235298
",normal",USDJPY,235298