我有一个复杂的查询,它会永远执行:
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 更改为两个表的并集之后,问题就开始了:
((SELECT * FROM `trendmetrics`) UNION (SELECT * FROM `trendmetrics_custom` WHERE `user_id`=$user_id)) trendmetrics
是什么阻止它执行?我没有任何错误,但它会一直运行,直到我中止它的执行。
更新:解释报告: