How To Write SQL Server Queries Correctly: Where Clauses With OR In Them

Поделиться
HTML-код
  • Опубликовано: 16 янв 2025

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

  • @TorgeirFredriksen
    @TorgeirFredriksen 2 дня назад +1

    Great video, and very relevant. Been using this "trick" many times, and looking forward to when the optimizer will actually be able to sort it out if the required indexes do exist

    • @ErikDarlingData
      @ErikDarlingData  2 дня назад +1

      It can often figure that out, but the better plans get costed out of consideration. It’s a real shame.

  • @SQLDevDBA
    @SQLDevDBA 18 дней назад +1

    Awesome video! Thanks very much!

  • @jessegador
    @jessegador 2 дня назад

    I think I saw 10 or so OR statements in our stored procedures.

  • @marwanhefnawy1137
    @marwanhefnawy1137 20 дней назад +2

    Why don't you use SQL Sentry Plan Explorer for examining your execution plans? I think it is more clear than the built in tool in ssms

    • @ErikDarlingData
      @ErikDarlingData  20 дней назад +2

      I've only ever found it useful for long stored procedures. In recent years it has not kept up with SSMS in exposing various query plan details. Solar Winds has really dropped the ball on it. The last couple versions won't even open up on my computer, they just crash instantly.

    • @StuartQuinn
      @StuartQuinn 13 дней назад +1

      ​@@ErikDarlingDatait's an absolute tragedy. The biggest problem I have it is crashing whenever the memory grant feedback kicks in. I wish they would open source it, I use it often enough that I would happily contribute.

    • @ErikDarlingData
      @ErikDarlingData  13 дней назад

      Yep - I get why they keep it and why they don’t care. It probably generates email leads and doesn’t make any money. It would probably be more valuable on both fronts if it were open source.

  • @FlaggedStar
    @FlaggedStar 20 дней назад +1

    13:07 This feels like one big jab at sp_BlitzIndex's mode 3.

    • @ErikDarlingData
      @ErikDarlingData  20 дней назад +1

      Hahaha, no, just the people who copy and paste from it without any due diligence.

  • @wplegend
    @wplegend 20 дней назад +1

    Would the expanded query with the union all be good to keep instead of the or, or are there performance implications?

    • @ErikDarlingData
      @ErikDarlingData  20 дней назад +2

      I'd generally opt for the union all query for a number of reasons.

    • @wplegend
      @wplegend 19 дней назад +1

      @ErikDarlingData thanks!

  • @Cahangir
    @Cahangir 19 дней назад

    Not sure if I could think of UNION ALL in that situation but regardless, thanks for the tip. Hope I'll use it sometime

    • @ErikDarlingData
      @ErikDarlingData  19 дней назад +2

      Once you get going with it, it gets easier and more intuitive.