tsql - Code is executed although condition is false -
i have view
v. selecting data view takes ten seconds execute because of referencing many many other views , tables. there's no way change this.
furthermore, there changelog table ( cl ) holds information whether datasets of v ( , / or other tables / views have reloaded, e.g.:
id, refid, table 1, 1, v 2, 2, v 3, 3, 4, 1, b
id
pk, auto-increment. refid
refers id-column of each referring table / view. table
holds name of referring table / view
now, there query checks if there datasets in cl referring view v.
q1:
select v.* cl inner join v on v."id" = cl."refid" , cl."table" = 'v'
in above example, 2 records cl affected ( id 1 , 2 ).
if no record affected @ ( no record "table" = 'v' in cl ) expect instant result of 0 executing second query q1 ( thought optimizer determine join-condition returns 0 results in cl , therefore there no need execute select on view v bottleneck, does. )
what have tried after this:
a) moving part of join-condition ( cl."table" = 'v'
) where
clause.
b) removing join , rewrite
if (( select count(1) cl "table" = 'v' ) > 0 ) begin <do references bottleneck-view v> end
if if-condition returns false, hoped code between begin , end not executed. is. runtime of query in b) same select * v
, if there's no record table ='v'
in cl).
what doing wrong?
Comments
Post a Comment