SQL NOT IN可能存在性能问题

SQL NOT IN可能存在性能问题,第1张

SQL NOT IN可能存在性能问题

您有一个列级联,可防止任何索引的使用

尝试不存在将分别支持2列

SELECt distinct     o.casino_id, g.game_idFROM     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_idWHERe     game_start between dateadd(mi, -180, getdate())  and dateadd(mi, -5, getdate())      and    b.[status] <> 'P'    AND    NOT EXISTS (SELECt *FROM    thirdpartysettlecalled   tpWHERe    tp.[status] = 'Y'   AND   tp.casino_id = o.casino_id AND tp.game_id = g.game_id)ORDER BY    casino_id

之后,检查您的索引或课程…

这也是EXCEPT的一个很好的用法(ORDER BY像UNIOn一样结束了:感谢@Damien_The_Unbeliever)

SELECt distinct     o.casino_id, g.game_idFROM     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_idWHERe     game_start between dateadd(mi, -180, getdate())  and dateadd(mi, -5, getdate())      and    b.[status] <> 'P'EXCEPTSELECt tp.casino_id, tp.game_idFROM thirdpartysettlecalled   tpWHERe tp.[status] = 'Y'ORDER BY    casino_id


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5021332.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存