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

Поделиться
HTML-код
  • Опубликовано: 4 июл 2024
  • If you like what you see here, you'll love my advanced performance tuning training:
    training.erikdarling.com/?cou...
    From my post here: erikdarling.com/whats-the-poi... Click here for 50% off a health check: training.erikdarling.com/darl...
  • НаукаНаука

Комментарии • 15

  • @bbksvb
    @bbksvb 28 дней назад +1

    I was wondering about this. Thanks for the info!

  • @christopherstyle878
    @christopherstyle878 28 дней назад +3

    Mezcal and brisket, got it.

  • @douglascoats7081
    @douglascoats7081 28 дней назад +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.

  • @mortezasafaee6981
    @mortezasafaee6981 28 дней назад +2

    Keep going... i like you haircut😊

  • @worldfromtheair
    @worldfromtheair 28 дней назад +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  28 дней назад

      Just space. I don't care about logical reads: ruclips.net/video/kxwEkeBCbdE/видео.html

  • @andreysamykin1143
    @andreysamykin1143 28 дней назад

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

  • @IcarianHeights
    @IcarianHeights 28 дней назад +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  28 дней назад

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