tsql - SQL NOT IN possibly performance issues -
i attempting refactor several old pieces of code... have refactored current piece below , have highlighted not in
statement causing performance issues. attempting rewrite not in
section left outer join.
can help, or suggest better way if possible?
select left(unique_id,16) casino_id , right(unique_id,24) game_id ( select distinct o.casino_id + g.game_id unique_id game g inner join bet b on g.game_id = b.game_id inner join casinouser u on b.user_id = u.user_id inner join onewalletcasino o on u.casino_id = o.casino_id game_start between dateadd(mi, -180, getdate()) , dateadd(mi, -5, getdate()) , b.[status] <> 'p' ) t unique_id not in ( select casino_id + game_id casino_id thirdpartysettlecalled [status] = 'y') order casino_id
you have column concatenation prevents use of indexes
try not exists support 2 columns separately
select distinct o.casino_id, g.game_id game g inner join bet b on g.game_id = b.game_id inner join casinouser u on b.user_id = u.user_id inner join onewalletcasino o on u.casino_id = o.casino_id game_start between dateadd(mi, -180, getdate()) , dateadd(mi, -5, getdate()) , b.[status] <> 'p' , not exists (select * thirdpartysettlecalled tp tp.[status] = 'y' , tp.casino_id = o.casino_id , tp.game_id = g.game_id) order casino_id
after that, check indexes or course...
this use of except (order goes @ end union: @damien_the_unbeliever)
select distinct o.casino_id, g.game_id game g inner join bet b on g.game_id = b.game_id inner join casinouser u on b.user_id = u.user_id inner join onewalletcasino o on u.casino_id = o.casino_id game_start between dateadd(mi, -180, getdate()) , dateadd(mi, -5, getdate()) , b.[status] <> 'p' except select tp.casino_id, tp.game_id thirdpartysettlecalled tp tp.[status] = 'y' order casino_id
Comments
Post a Comment