SQL performance tuning and query optimization using execution plan

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 มิ.ย. 2024
  • Performance tuning begins with understanding execution plan and finding & fixing expensive operators one by one in below flow:
    First Lazy spool: Lazy spool is most expensive operator among all, which happens because of duplicate aggregation. We can remove duplicate aggregation by temporary tables, cte, etc.
    Second Hash match: which is always because of unsorted data. Which means either missing index or indexes are not properly utilized, which can be because of :
    1. function use in join or where condition
    2. First column of existing index is not part of where clause or join
    We can address this by adding new index, fixing query to utilize existing index or altering index to new filter configurations.
    Keylookup: Keylookup just indicate, that index is missing some data. We can easily resolve it by adding missing column to index key or include part. But there is a catch as, we don't have privilege to alter index all the time. So, some times, we cannot avoid keylookup.
    Index Suggestion:
    Index key columns are the one which are part of where clause or joins.
    Index include columns are the one which are part of only selection.
    Partition Elimination: we check if partition are getting eliminated in query or not. As sometimes even tables have partitions still query go for scan instead partition elimination.
    A lot of times, I have seen, developer use different datatype in storedprocedure parameters which don't match to actual column. And end up in no partition elimination.
    Two reasons why query is not eliminating partition:
    1. Data type mismatch or function used on where clause or type casting
    2. Partition key column is not part of where clause
    BAD Views: Views sometimes becomes bad when developer don't alter them instead they join same table to view which is already part of view to get some extra data. Instead they should write new view or alter existing view to get extra columns
    Minimizing sub queries: We can minimize sub queries, if subquries belong to same table to get different column using cross apply or outer apply.
    Example we have to get most recent orderdate, order amount, order shipped date, etc for each customer. So instead of writing different sub query for each column, we can use cross apply or outer apply to get data in single query.
    Scripts: drive.google.com/file/d/1RUNg...

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

  • @srinubathina9096
    @srinubathina9096 4 ปีที่แล้ว +4

    This is the best class in terms of SQL Performance Tuning. Thank You..

  • @mohammedminhajulhaq5542
    @mohammedminhajulhaq5542 2 ปีที่แล้ว +24

    We need to share this kind of videos to maximum people. This is much underrated in terms of views. A lot to learn from this video. Thank you sooo much for keeping it simple and understandable. We can't get this much of advise and knowledge after paying also. Attended some pluralsite videos of some SQL experts but didn't understand a bit but in this 1 video got so much of information. Thanks a ton once again. Keep it up good work 👍👍👍👍

    • @techsapphire
      @techsapphire  2 ปีที่แล้ว +5

      Thanks. Note:
      I also provide commercial support. Please contact if needed.
      If you find this solution helpful than donate comfortable amount on papal to my email ID or link www.paypal.me/bimlamehla.
      Donation is not mandatory is it just request to support free tutorial.

    • @parthasarathiramachandran8189
      @parthasarathiramachandran8189 11 หลายเดือนก่อน

      @@techsapphire can we have your contact number or whatsapp number/ email id

  • @prabasmessi
    @prabasmessi 2 หลายเดือนก่อน

    Thank you so much for sharing the knowledge. Best explanation for query optimization i have seen till now.

  • @sharmavasundhara
    @sharmavasundhara 4 หลายเดือนก่อน +2

    This is by far the best SQL query optimization videos I've watched! I'm going to share this with everyone I know who can benefit from this. Thanks @techsapphire 🙌🏽

  • @palashmondal9088
    @palashmondal9088 3 ปีที่แล้ว +1

    I asked to optimize query by product owner after that start watching your video, it help me a lot. Thank you so much!!

  • @mithunraj31
    @mithunraj31 2 ปีที่แล้ว +1

    Really this is one of the BEST video ever, so easy to understand. Very very very helpful. Thanks a lot for this brilliant one.

  • @kaustubhpradhan82
    @kaustubhpradhan82 3 ปีที่แล้ว +4

    Extremely helpful. Searched a lot for help and video stands out to be unique. Thank you. :-)

  • @venkatasumanbhavanasi6939
    @venkatasumanbhavanasi6939 3 ปีที่แล้ว +4

    Hi yogesh, this is really helpful for developers who donno the concepts and tricks to optimize queries and simply writing the queries as their own which makes client in bad situation. This video helped me alot. Thank you..

  • @kaushikkrishnan5828
    @kaushikkrishnan5828 3 ปีที่แล้ว +1

    Amazing, super helpful to get a direction on how to go about optimizing queries

  • @saikumarramisetty
    @saikumarramisetty 4 ปีที่แล้ว +1

    Thank you so much for the awesome video, I got a clear idea about the Performance tuning

  • @satheeshkandukurii5251
    @satheeshkandukurii5251 4 ปีที่แล้ว +5

    Really awesome...pls do more videos on performance tuning

  • @mrkamranumer
    @mrkamranumer ปีที่แล้ว

    Wonderful and Excellent Knowledge based in-depth Performance Tuning Video

  • @radha040
    @radha040 2 หลายเดือนก่อน

    Very informative and core knowledge for every level of SQL developer. Thank you

    • @techsapphire
      @techsapphire  หลายเดือนก่อน

      Glad it was helpful!

  • @jagjeetrathore9122
    @jagjeetrathore9122 4 ปีที่แล้ว +2

    i watched many videos , found this one awesome for beginners

    • @techsapphire
      @techsapphire  4 ปีที่แล้ว +1

      Thank you for your feedback.

  • @NareshDama-qv3iu
    @NareshDama-qv3iu 4 ปีที่แล้ว

    Very useful information.. thank you so much!!

  • @saurabhashok2857
    @saurabhashok2857 ปีที่แล้ว

    Simply outstanding explanation. Thanks!

  • @jaredlising-simplybrewedph
    @jaredlising-simplybrewedph ปีที่แล้ว +2

    Thank you so much for such detailed explanation! Appreciate it so much! 😊

  • @devarakondasankararao3802
    @devarakondasankararao3802 2 ปีที่แล้ว

    Very excellent video .Thank you so much for this explanation.

  • @xx_ggplot2_xx
    @xx_ggplot2_xx ปีที่แล้ว

    Insanely good video. Helped for my DE interview

    • @techsapphire
      @techsapphire  ปีที่แล้ว

      Glad it helped! I provide training as well.

  • @nitsz07
    @nitsz07 ปีที่แล้ว

    Thanks! Thanks a lot Yogesh for your time and efforts in this particular video. This helped me a lot..

  • @user-zl4vf1pk8r
    @user-zl4vf1pk8r 3 หลายเดือนก่อน

    Amazing tutorial on query tuning... thanks a lot

  • @Sk8erBhai
    @Sk8erBhai ปีที่แล้ว

    Great video, brother. Have learnt so much so quick

  • @anuragjains2195
    @anuragjains2195 4 ปีที่แล้ว

    Nicely explained. Thank you very much!

    • @techsapphire
      @techsapphire  4 ปีที่แล้ว

      Thank you for your feedback.

  • @dizssoftwareservices
    @dizssoftwareservices ปีที่แล้ว

    Very Good Lecture gives me so much clarity.

  • @priyankasarkar6600
    @priyankasarkar6600 4 ปีที่แล้ว +5

    Awesome Sir..:) On point tutorial! Please make more videos on triggers, cluster, cursor.. Thanks in advance..:)

    • @techsapphire
      @techsapphire  4 ปีที่แล้ว +1

      Sure thing! Keep learning :)

  • @DD-dp6ge
    @DD-dp6ge ปีที่แล้ว

    Amazing, very well explained, thanks!

  • @ravindark646
    @ravindark646 3 ปีที่แล้ว

    Nice explanation and got clear Idea on the such things. Thanks :)

  • @karanrewari6482
    @karanrewari6482 3 ปีที่แล้ว

    amazing video!! very helpful, thanks!

    • @techsapphire
      @techsapphire  3 ปีที่แล้ว

      Glad you found it helpful.

  • @mahaalsalman2323
    @mahaalsalman2323 3 ปีที่แล้ว

    Thank you for good teaching you explained it very clearly

  • @shreyadutta5817
    @shreyadutta5817 2 ปีที่แล้ว

    Very informative... Brilliantly explained

  • @ranjitreddy6316
    @ranjitreddy6316 3 ปีที่แล้ว

    Thanks Much For this video! Really appreciate it! :)

  • @dattakashiwale
    @dattakashiwale ปีที่แล้ว

    Excellent ! outstanding video., most of the concept were unknown.., really helped a lot., thanks a lot Bhai.., pls create more stuff like this..,

  • @dishantrana341
    @dishantrana341 8 หลายเดือนก่อน

    This is just amazing, going to share with all mates.

    • @techsapphire
      @techsapphire  8 หลายเดือนก่อน

      Glad you find it helpful

  • @vijayalakshmibadigeru4479
    @vijayalakshmibadigeru4479 2 ปีที่แล้ว

    Really great video... We look forward to learn more ✌️

  • @pravaspatra3849
    @pravaspatra3849 4 ปีที่แล้ว

    Its very helpful. Please share more videos

  • @nandiniguntur4509
    @nandiniguntur4509 2 ปีที่แล้ว

    Good job. The explanation is very succint

  • @ganeshvarma370
    @ganeshvarma370 2 ปีที่แล้ว

    Learned So much, Keep doing more videos. Respect++

  • @calvinball1
    @calvinball1 2 ปีที่แล้ว

    This is an astoundingly good video

  • @maruthibachu8854
    @maruthibachu8854 ปีที่แล้ว

    Really its awesome.. Its helped lot and easy to understand.. please make more videos. thank you

  • @ashwineemehta9449
    @ashwineemehta9449 ปีที่แล้ว

    I went though this video and found it very useful.

  • @ashutoshsrivastava2275
    @ashutoshsrivastava2275 2 ปีที่แล้ว

    Thank you very much for all your effort.

  • @ManOfAdventure2011
    @ManOfAdventure2011 ปีที่แล้ว

    Great tutorial! I learned a lot!

  • @Latif127
    @Latif127 3 ปีที่แล้ว

    Very helpful tutorial, thank you.

  • @SandeepYadav-vm5hd
    @SandeepYadav-vm5hd 2 ปีที่แล้ว

    Amazing Video Very useful !!!

  • @deepak21000
    @deepak21000 ปีที่แล้ว

    Excellent performance tuning tutorial

  • @codearabawy
    @codearabawy 2 ปีที่แล้ว

    That's awesome, thank you very much!

  • @ManishPurohit-gl6lq
    @ManishPurohit-gl6lq ปีที่แล้ว

    It's a brilliant explanation.

  • @parixitsinhchauhan5186
    @parixitsinhchauhan5186 ปีที่แล้ว

    nicely explained every topic. Good Video

  • @srikanthkurra9513
    @srikanthkurra9513 ปีที่แล้ว

    Thanks for the complete explanation

  • @niha46
    @niha46 3 ปีที่แล้ว

    nice explanation, very helpful.

  • @gokuls3000
    @gokuls3000 9 หลายเดือนก่อน

    this is best video for performance tuning

    • @techsapphire
      @techsapphire  8 หลายเดือนก่อน

      Thank you for positive feedback

  • @user-td6hr7qd1b
    @user-td6hr7qd1b 7 หลายเดือนก่อน

    Thanks for your detail explanation

    • @techsapphire
      @techsapphire  7 หลายเดือนก่อน

      Glad it was helpful!

  • @dbatexas
    @dbatexas 3 ปีที่แล้ว +1

    thanks for details, video could be more in depth like why nested loop join vs hash join, what is lazy pool or eager spool/spills. but other than all good concepts and topics. it takes times to explain all details so we could give links for people to learn like nested loop runtime is O(n2) Vs merge join O(nLogN) etc etc

    • @techsapphire
      @techsapphire  3 ปีที่แล้ว +2

      Thank you for your feedback. Reason why I haven't covered details about latches and waits and why nested loops, etc is, mostly I make video for intermediate learner to expert level. And if I add these stuff, video become confusing for them, I tried to cover in best lehman terms. But I agree for some viewer details make more sense, but mostly people I train are not good with basics so, difficult to bring them in same page.

  • @haribabunaiduyasanoor5233
    @haribabunaiduyasanoor5233 ปีที่แล้ว

    Excellent session Sir!!

  • @kjkanishk7575
    @kjkanishk7575 3 ปีที่แล้ว

    thanks ... :) ... really great presentation.

  • @bluerays5384
    @bluerays5384 7 หลายเดือนก่อน

    very explained Sir, Thank you for the video.

    • @techsapphire
      @techsapphire  6 หลายเดือนก่อน +1

      Glad it helped

    • @bluerays5384
      @bluerays5384 4 หลายเดือนก่อน

      I watched your video might be 4th or 5th time today, N every time I learn something new n brings my knowledge to next level..Very well explained sir. Keep Sharing such a live scenario n knowledge..This helped me lot..lots of love sir #bow ❤❤❤❤

  • @rickmemmer5625
    @rickmemmer5625 3 ปีที่แล้ว

    Exceptional presentation!! Much appreciated!! :o)

    • @techsapphire
      @techsapphire  3 ปีที่แล้ว

      Thank you kindly!
      Note:
      I also provide commercial support. Please contact if needed.
      If you find this solution helpful than donate comfortable amount on papal to my email ID or link www.paypal.me/bimlamehla.
      Donation is not mandatory, it is just a request to support free tutorials.

  • @P5toraskar1986
    @P5toraskar1986 2 ปีที่แล้ว

    Superb information.

  • @waqarbaig1402
    @waqarbaig1402 4 ปีที่แล้ว

    this is realy good picture of optimization .. also please add sql profiler in terms of optmization

    • @techsapphire
      @techsapphire  4 ปีที่แล้ว

      Thank you for your feedback. I will add session on sql profiler too.

  • @yashpatil2536
    @yashpatil2536 ปีที่แล้ว

    Amazing Thank you so much!

  • @mallikarjuna9209
    @mallikarjuna9209 ปีที่แล้ว

    to the point. Thank you sir!!!!!

  • @karthikkeyan4460
    @karthikkeyan4460 2 ปีที่แล้ว +10

    Timstamps for various topics covered..
    18:21 Hashmatch
    23:54 KeyLookup

  • @yogisawant9891
    @yogisawant9891 2 ปีที่แล้ว

    Nice video. Thank you sir

  • @dishaverma3522
    @dishaverma3522 2 ปีที่แล้ว

    Thanks allot it's really helpful

  • @poojagarg5673
    @poojagarg5673 ปีที่แล้ว +2

    Thanks a lot for sharing this video, it's very informative and helped me understand many concepts.
    Right now, I am looking at a complex query plan which is timing out(query) pretty often. That execution plan has many operations like Index seek (NonClusered), Clustered Index Scan, Clustered Index Seek etc. Please explain these terms as well. These are quite confusing when reading the definition of these.

    • @techsapphire
      @techsapphire  ปีที่แล้ว

      I provide 1 to 1 session which comes up with a fee to clear your all doubts, if you are interested kindly reach me on yogesh.mehla@gmail.com

  • @Rprakaash
    @Rprakaash 4 หลายเดือนก่อน

    have you used sql sentry plan explorer? what is your opinion about it. I find it really facinating. I wish they had more vidoes on that.

  • @Jkprasad
    @Jkprasad 4 ปีที่แล้ว

    outstanding Sir

  • @etlpro4940
    @etlpro4940 11 วันที่ผ่านมา

    Awesome, just below excellent,

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

      Thank you so much 😀

  • @amiya217
    @amiya217 3 ปีที่แล้ว

    good explanation..

  • @Shad0wMonkey5
    @Shad0wMonkey5 ปีที่แล้ว

    This was such a good video I’m shocked ahahaha! Do you have any more optimisation tips and how diagnosing slow queries?

    • @techsapphire
      @techsapphire  ปีที่แล้ว

      Yes I do! Alot are on my channel kindly check, I also provide commercial sessions

  • @surupgurugm2523
    @surupgurugm2523 2 ปีที่แล้ว

    AWESOME 👌

  • @PrakashPatil-dw5be
    @PrakashPatil-dw5be 3 ปีที่แล้ว

    good information...

  • @Firatayrilik
    @Firatayrilik 3 ปีที่แล้ว +1

    Hello. Thanks for the video. What exactly 'Double Aggregation' means? I mean I only see one aggregation query which is MAX in first query and also in the second. Can you please explain?

    • @techsapphire
      @techsapphire  3 ปีที่แล้ว +1

      it is duplicate aggregation, not double aggregation. Kindly re refer video again

  • @Santosh-bx2ub
    @Santosh-bx2ub 4 หลายเดือนก่อน

    Thanks a lot..

  • @Ali-or8wb
    @Ali-or8wb 2 ปีที่แล้ว

    well explained.

    • @techsapphire
      @techsapphire  2 ปีที่แล้ว

      Glad you found it helpful.

  • @krishnakumargupta741
    @krishnakumargupta741 3 ปีที่แล้ว

    thx you sir very nice video

  • @sajidbhat2374
    @sajidbhat2374 ปีที่แล้ว

    thanks is amazing

  • @RajeshKumar-nc5gg
    @RajeshKumar-nc5gg ปีที่แล้ว

    Very very nice

  • @jegadeesr7213
    @jegadeesr7213 3 ปีที่แล้ว +1

    While
    optimizing T-SQL Queries, in the logical query execution plan, what are the top
    3 operators which we should eliminate / optimize?

    • @techsapphire
      @techsapphire  3 ปีที่แล้ว +2

      Lazy spool one and only other are more dependent on situation

  • @kaushikbudi8819
    @kaushikbudi8819 ปีที่แล้ว +1

    Hello Sir great video just had a small doubt how would the performance be if we used last value for the example problem for minimizing sub queries

    • @techsapphire
      @techsapphire  ปีที่แล้ว +1

      single query will not have major impact, its important to have most of the queries to be optimized to ensure good performance

  • @kiran3243
    @kiran3243 2 ปีที่แล้ว

    nice video sir

  • @valijoneshniyazov2553
    @valijoneshniyazov2553 3 ปีที่แล้ว

    AWESOME

  • @afzaalawan
    @afzaalawan 3 ปีที่แล้ว

    excellent

  • @aloksinha6342
    @aloksinha6342 4 ปีที่แล้ว

    Very nice explanation.One of the best.Could you please share the scripts also..

  • @rajeshchittiprolu5281
    @rajeshchittiprolu5281 4 ปีที่แล้ว

    short and sweet. Well explained brother. Would you mind sending me the presentation.

  • @martinhedmanjohnson6687
    @martinhedmanjohnson6687 3 ปีที่แล้ว

    Hi Yogesh, at one point you mention "group before, not after" what do yuo mean by that?

    • @techsapphire
      @techsapphire  3 ปีที่แล้ว

      I am confused about reference, if you want to discuss in detail, kindly reach me on skype yogesh.mehla@live.com

  • @sandeepkumar-ol5lg
    @sandeepkumar-ol5lg ปีที่แล้ว

    Great content, as you mentioned it’s one out of two parts, could you please comment the second video link here

    • @techsapphire
      @techsapphire  ปีที่แล้ว

      Post this video, there are many videos on how to capture expensive queries etc. You can check

  • @anonymous8633
    @anonymous8633 2 ปีที่แล้ว

    how to avoid key lookup when PK_clusteredIndex seek is in the exec. plan? I know if, non clustered on exec. plan, I can add those columns to the index but what to do with key lookup and PK_seek?

    • @techsapphire
      @techsapphire  2 ปีที่แล้ว

      lookup are tricky to fix, depends on your instinct to fix them as they can cause more locks for insert delete and update if you add more columns

  • @sqlservertutorialin3minute485
    @sqlservertutorialin3minute485 2 ปีที่แล้ว

    Nice one

  • @bharath.vkumar5941
    @bharath.vkumar5941 3 ปีที่แล้ว

    really like this video........may get any suggestions currently, i working for my thesis on the topic of RESEARCH ON AI APPLICATION FOR OPTIMIZATION OF THE SQL QUERIES..

    • @techsapphire
      @techsapphire  3 ปีที่แล้ว

      Is your research only SQL Server or other databases as well?

  • @010_it_daithiyasudanks3
    @010_it_daithiyasudanks3 หลายเดือนก่อน

    I am trying to reproduce the same steps in my machine. I am not able to find Student table under Northwind database. Can you please where I can find the scripts for that? This video is starting to be very useful for me.

  • @sid5201
    @sid5201 4 ปีที่แล้ว +1

    Hash Join is not always bad, especially dealing with very large tables.

    • @techsapphire
      @techsapphire  4 ปีที่แล้ว +2

      There is no term like always bad. It depends, if you are joining complex views, you may not be able to avoid hash join. So SQL decision is good, we have to form are query accordingly.

    • @sid5201
      @sid5201 4 ปีที่แล้ว

      @@techsapphire agree

  • @pavankumarcheruvu8207
    @pavankumarcheruvu8207 ปีที่แล้ว

    Hi sir,
    It was nice video. I have one doubt while explaining you're telling everytime about sql server but I'm not using sql server in my project I'm using sql developer tool and I'm working as sql developer, So it is same for all ?
    Please reply me.

    • @techsapphire
      @techsapphire  ปีที่แล้ว

      Yes, correct. Performance optimization using query tuning is mainly job of SQL Dev not DBA

  • @gabrielegbenya7479
    @gabrielegbenya7479 4 ปีที่แล้ว +1

    Hi Yogesh! Thank you for the lecture; it was very educative, can you please share me the script and ppt presentation . Also do we need to SET STATISTICS IO OFF after the query optimization project? Thank you.

    • @techsapphire
      @techsapphire  4 ปีที่แล้ว +3

      Sure, please share your email. You don't need to set it off as it is session level. So moment you close query window, it is gone

    • @krishanajangid1763
      @krishanajangid1763 3 ปีที่แล้ว

      Hi yogesh, thanks you for the lecture. It was very educative. Please share the ppt, quries, and database back used in the video. My email id is krishanajangid2011@gmail.com.

    • @katabathinadamodar732
      @katabathinadamodar732 3 ปีที่แล้ว

      @@techsapphire have you send to damukatabathina@gmail.com also...thanks

    • @ravindrabisht7520
      @ravindrabisht7520 2 ปีที่แล้ว

      @@katabathinadamodar732 if u got script, would u, please share with me?

    • @ravindrabisht7520
      @ravindrabisht7520 2 ปีที่แล้ว

      @@krishanajangid1763 if u got script, would u, please share with me?

  • @PrakashPatil-dw5be
    @PrakashPatil-dw5be 3 ปีที่แล้ว

    I have a table with more than 100 columns, so how many indexes can create for a single table?

    • @techsapphire
      @techsapphire  3 ปีที่แล้ว

      there is no hard rule for it, depends upon you infrastructure and also sql version. Enterprise can go manage crazy load of indexes. Index should be created sensibly.

  • @dinsharma1409
    @dinsharma1409 2 ปีที่แล้ว

    What version is the NorthWind database? Mine doesn't have the 'Student' column. Would you please paste the URL here to get the same Database you have on your presentation?

    • @techsapphire
      @techsapphire  2 ปีที่แล้ว

      follow link in description for database backup

    • @dinsharma1409
      @dinsharma1409 2 ปีที่แล้ว

      @@techsapphire Where is the link?

  • @ArdianUmam
    @ArdianUmam 3 ปีที่แล้ว

    Thanks so much for the great video!
    Where can I get the slide and the script?

    • @techsapphire
      @techsapphire  3 ปีที่แล้ว

      Kindly share your email for it.

    • @ArdianUmam
      @ArdianUmam 3 ปีที่แล้ว

      techsapphire : ardianumam@gmail.com. Thanks in advance.

    • @SN-zr3rf
      @SN-zr3rf 3 ปีที่แล้ว

      Sir,
      I need this script and requesting you to forward sheiknainar@yahoo.co.in

  • @gomathyelango5574
    @gomathyelango5574 ปีที่แล้ว

    Is this query tuning applicable to oracle database as well?

    • @techsapphire
      @techsapphire  11 หลายเดือนก่อน

      yes query mistakes are common

  • @nilamsherkar
    @nilamsherkar 3 หลายเดือนก่อน

    can i get this database to practice the questions

  • @hearttouchingsoul
    @hearttouchingsoul ปีที่แล้ว

    Please share download database link, which you are using in this