What’s The Point of 1 = (SELECT 1) In SQL Server Queries?

แชร์
ฝัง

ความคิดเห็น • 17

  • @bbksvb
    @bbksvb 16 วันที่ผ่านมา +1

    I was wondering about this. Thanks for the info!

  • @douglascoats7081
    @douglascoats7081 16 วันที่ผ่านมา +1

    When dealing with wonky nonsense in plans, Instead of WHERE 1 = (SELECT 1), I smack the monitor and then blow in the USB port.

    • @ErikDarlingData
      @ErikDarlingData  15 วันที่ผ่านมา +1

      Throw the controller against the wall

  • @christopherstyle878
    @christopherstyle878 16 วันที่ผ่านมา +3

    Mezcal and brisket, got it.

    • @ErikDarlingData
      @ErikDarlingData  16 วันที่ผ่านมา

      It’s a fairly simple checklist

  • @worldfromtheair
    @worldfromtheair 15 วันที่ผ่านมา +1

    Slightly off topic, but I guess you also use DATA_COMPRESSION = PAGE on all your index creates too? I guess just to save space and logical reads

    • @ErikDarlingData
      @ErikDarlingData  15 วันที่ผ่านมา

      Just space. I don't care about logical reads: th-cam.com/video/kxwEkeBCbdE/w-d-xo.html

  • @andreysamykin1143
    @andreysamykin1143 16 วันที่ผ่านมา

    Thanks for an interesting video! I wonder if “when 1=1” has the same effect.

    • @ErikDarlingData
      @ErikDarlingData  15 วันที่ผ่านมา

      I’m not sure I follow this one

  • @IcarianHeights
    @IcarianHeights 15 วันที่ผ่านมา +1

    Apologies for being dense, but even after watching the video and reading the blog post, though I better understand why you're using `1 = (SELECT 1)`, I still don't understand why that pattern forces the optimizer to skip assigning the query as having a `trivial plan` or `simple parameterization`.
    Is it simply because it's a sub-query, where the optimizer doesn't know what may be in it at runtime so it has to in fact go down the actual road of optimizing the query further than if it were a known/constant value?

    • @ErikDarlingData
      @ErikDarlingData  15 วันที่ผ่านมา

      Yep, you can even simplify it in some cases to be something like SELECT (SELECT Id) FROM dbo.Whatever;

  • @clerincg
    @clerincg 10 วันที่ผ่านมา +1

    Could you make the (SELECT 1) sub-query a CTE??? LOL 😂😂 (I know how much you like CTE's from other videos)

    • @ErikDarlingData
      @ErikDarlingData  10 วันที่ผ่านมา

      Well, I actually don’t know if that would work. Hah.

  • @mortezasafaee6981
    @mortezasafaee6981 16 วันที่ผ่านมา +2

    Keep going... i like you haircut😊