永遠に実行し続ける複雑なクエリがあります。
SELECT tr.`Fund Name`,
tr.`Fund ID`
FROM
(SELECT `Fund Name`,
`Fund ID`
FROM (
(SELECT *
FROM `trendmetrics`)
UNION
(SELECT *
FROM `trendmetrics_custom`
WHERE `user_id`=361)) trendmetrics
WHERE `FactorName`='MSCI in $'
AND trendmetrics.`Annualmean 2`>0.061
AND trendmetrics.`VaR 95 2`>-0.04
AND `Fund ID` IN
(SELECT `Fund ID`
FROM (
(SELECT *
FROM `trendmetrics`)
UNION
(SELECT *
FROM `trendmetrics_custom`
WHERE `user_id`=361)) trendmetrics
WHERE `FactorName`='Oil (Spot West Texas)'
AND trendmetrics.`Annualmean 1`>0.061
AND trendmetrics.`VaR 95 1`>-0.04)
AND `Fund ID` IN
(SELECT `Fund ID`
FROM (
(SELECT *
FROM `trendmetrics`)
UNION
(SELECT *
FROM `trendmetrics_custom`
WHERE `user_id`=361)) trendmetrics
WHERE `FactorName`='Credit Spread (BAA-AAA Moodys)'
AND trendmetrics.`Annualmean 1`>0.061
AND trendmetrics.`VaR 95 1`>-0.04)) tr
INNER JOIN (
(SELECT *
FROM `quant1`)
UNION
(SELECT *
FROM `quant1_cust`
WHERE `user_id`=361)) quant1 ON (`tr`.`Fund ID` = `quant1`.`Fund ID`)
問題は、単純なテーブル trendmetrics を 2 つのテーブルの結合に変更した後に始まりました。
((SELECT * FROM `trendmetrics`) UNION (SELECT * FROM `trendmetrics_custom` WHERE `user_id`=$user_id)) trendmetrics
実行を妨げるものは何ですか?エラーはありませんが、実行を中止するまで実行を続けます。
更新: EXPLAIN レポート: