したがって、2 つのクエリがあります。first が second よりもはるかに高速に実行されるのはなぜですか? 内部結合を最初のものと同じくらい高速に最適化するにはどうすればよいですか?
合計レコード数 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