简体   繁体   中英

Replacement for a Case statement

I have a function that works off of a view with two case statement. The problem is that because of this case statement, it is taking 25+ seconds to run the function. Where as it should only be taking ~3 seconds (comparing to an identical function with a view that doesnt call a case statement.)

The case statement is done within the select.

Interestingly enough(for me), If I changed one of the case statements to something direct ie D.CARS instead of

CASE WHEN D.CAR IS NOT NULL 
THEN D.CAR              
ELSE C.CAR
END AS CAR,

Then it speeds up to ~3 seconds to run the function but shows some off results. So it only seems to take~25 seconds if there is TWO case statements in the select statement.

The views regardless of number of case statements or not take less than 1 second to populate.

Is there a way to speed it up while still getting the correct results?

而不是CASE表达式,为什么不使用COALESCE

COALESCE(D.CAR, C.CAR) AS CAR

您是否尝试过使用函数而不是case语句?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM