Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 删除@variable减慢查询速度_Mysql_Sql_Variables - Fatal编程技术网

Mysql 删除@variable减慢查询速度

Mysql 删除@variable减慢查询速度,mysql,sql,variables,Mysql,Sql,Variables,我有一些代码在未定义变量时运行非常慢。我不能将变量留在代码中,因为它将进入PowerBi,并且它无法识别变量,但当我删除它时,查询超时 我找了一整天都找不到任何东西,我希望有人能帮忙。查询如下 select s.date,si.name, coalesce(gics_sector,si.security_type), @weight := s.market_value / fundval.val, p.name, si.currency, t1.div_yield from matilda.s

我有一些代码在未定义变量时运行非常慢。我不能将变量留在代码中,因为它将进入PowerBi,并且它无法识别变量,但当我删除它时,查询超时

我找了一整天都找不到任何东西,我希望有人能帮忙。查询如下

select s.date,si.name, coalesce(gics_sector,si.security_type),  @weight := s.market_value / fundval.val, p.name, si.currency, t1.div_yield
from matilda.security_info si
left join(select * from matilda.synth_exp where date = WORKDAY_ADD(current_date(),-1)) as s on si.ticker = s.ticker
left join (select fund_id, sum(market_value), sum(synth_value) as val, date from matilda.synth_exp where date = WORKDAY_ADD(current_date(),-1) group by fund_id,date) as fundval on fundval.fund_id = s.fund_id
left join (select * from matilda.stocks where date = LAST_DAY(DATE_ADD(current_date(), INTERVAL -1 MONTH))) as gics on gics.id = si.id
left join (select * from matilda.dailies where date = WORKDAY_ADD(current_date(),-1)) as t1 on t1.id = si.id
left join matilda.portfolio p on p.fund_id = s.fund_id
where s.market_value is not null;

提前谢谢。

您是说发布的查询有效,但如果您省略“@weight:=”则它会超时吗?那真是太奇怪了!确切地我在网上搜索到的所有东西都与减慢速度而不是加快速度的变量有关。有什么想法吗?s.market_值和fundval.val是否保证不为空,fundval.val是否保证不为零?s.market_值可以为空,但fundval.val始终有一个值。我应该事先过滤掉空值吗?事实上,我的坏,空值不应该有什么区别。您确定fundval.val永远不为0吗?这真的很奇怪-因为我知道输入错误有多容易,你介意再测试一次并添加超时的查询吗?你是说发布的查询可以工作,但是如果你省略“@weight:=”那么它就会超时?那真是太奇怪了!确切地我在网上搜索到的所有东西都与减慢速度而不是加快速度的变量有关。有什么想法吗?s.market_值和fundval.val是否保证不为空,fundval.val是否保证不为零?s.market_值可以为空,但fundval.val始终有一个值。我应该事先过滤掉空值吗?事实上,我的坏,空值不应该有什么区别。您确定fundval.val永远不为0吗?这真的很奇怪——因为我知道输入错误是多么容易,你介意再测试一次并添加超时的查询吗?