Skip to content
Advertisement

OR clause takes longer time

I have a query as an example below, but its running forever .. If I do union then I have copy entire large query .. Any help on this fix

Advertisement

Answer

The inner part

can be written using the QUALIFY clause like so:

which can be pushed into a CTE like:

which means you can union that whole thing or just the table a and raw_rows o

but this will give you a slightly different result if o.src_id == o.id for any row, as it will match both verse the OR vesion will have those lines once. You can pay the GROUP BY cost by swapping to UNION to de-dup, but then if you have many lines you want to keep those will be lost. Or you can change second half of the union to not included those line with

depends on your data and needs.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement