i have some code that runs really slow when a variable is NOT defined. I can't leave the variable in the code as it is going to into PowerBi and it doesnt recognise variables, but when i remove it the query times out.
I have searched all day can not find anything, i was hoping someone could help. Query below.
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;
Thanks in advance.