Тёмный

An Index Reduces Performance of SELECT Queries 

Pinal Dave
Подписаться 34 тыс.
Просмотров 51 тыс.
50% 1

Наука

Опубликовано:

 

4 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 83   
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
Hi All, Those who want free scripts to identify unused indexes, can register here: go.sqlauthority.com and it will send you script immediately.
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
Please sign up now.
@chuck7494
@chuck7494 4 года назад
That is really surprising. I would never had noticed that an index could cause such performance degradation!!! THANK YOU!!! I ALWAYS look to you for answers to the really tough ones. Glad you are here!!!!!!! KEEP UP THE GREAT WORK!
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
Appreciate your kind note
@smwnl9072
@smwnl9072 5 лет назад
Power. No one explains Tsql as clear and interesting as you ❤
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
Thanks!
@sanujss
@sanujss 4 года назад
Have attended one of your sessions in Bangalore Microsoft TechEd few years back. Following you from then on blog. No one else explains these things better. Thanks a ton
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
Thank you so much!
@RalphDon21
@RalphDon21 Год назад
There's my teacher, right there. Thanks, sir!
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority Год назад
Thanks!
@ericrouach
@ericrouach 4 года назад
You are a Saint! Thanks a lot!
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
You are very kind.
@Harshk2501
@Harshk2501 4 года назад
Very nice explanation sir. I request you to please provide a explanation video for understanding deadlock graph.
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
Sure....
@mehdighapanvari9950
@mehdighapanvari9950 Год назад
Hi Pinal! Please use temporary table instead of subquery in your scenario. Thanks!
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority Год назад
Noted!
@mjzvsuiza
@mjzvsuiza 5 лет назад
If you show the execution plan as XML you will probably see that the index is ACTUALLY being used. The statistics of the new index are being used to determine the execution plan. I agree in a detrimental way. but the index is being used.
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
Great point. However, what I wanted to stress in this video was also the point that when we create an index, it can also reduce the performance of SELECT statement which people usually do not think. Many people just leave their indexes as it is and have no idea how they impact other queries and particularly SELECT queries. This is just one of the tip, there are so many misconceptions out there and lots of people need to learn about them, otherwise, they will spend countless hours in doing performance debugging.
@nareshkoudagani6969
@nareshkoudagani6969 5 лет назад
The subject of the Video should be, a Un used INDEX Reduces Performance of SELECT Queries
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
Thank you so much. Good point
@marufkhan1395
@marufkhan1395 4 года назад
I would have love to see the video including a cluster index and then creating a non cluster index would have shown some different results.
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
Sure will focus on them.
@ThierryC2373
@ThierryC2373 5 лет назад
I think it is more how you define your index(es) than anything else that impacts the performances.
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
That is correct point
@thearchibaldtuttle
@thearchibaldtuttle 3 года назад
Wow! Didn't knew this happens but I'm only a manager :-)
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 3 года назад
Glas you liked the video...thanks for watching.
@meghanatoraskar5301
@meghanatoraskar5301 2 года назад
Cool thanks
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 2 года назад
You bet
@baidya4272
@baidya4272 3 года назад
Can you pls suggest on below: Table A with cols ID, Name, Message There are two non clustered indexes 1. Index1 with index_keys as Name,Message 2. Index2 with index_keys as Message,Name These are duplicate indexes but column order is different. Is this ok or probable reason of performance issues?
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 3 года назад
I do not think they are duplicate. They are unique.
@gafajardog
@gafajardog 5 лет назад
Just as a new index affects the performance of existing queries, so an existing index can affect future queries
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
That is very correct assessment. Thank you so much sir
@fitnessgroupofindia4423
@fitnessgroupofindia4423 5 лет назад
Sir your voice is very good...
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
Thank you for your kind words.
@IrawanSoetomo
@IrawanSoetomo 4 года назад
have you tried to use OPTION (RECOMPILE) at the bottom? how would it affect this behavior?
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
In longer demo we do experiment with that... Absolutely no difference in results you are seeing.
@ArindamGangulyKolkata
@ArindamGangulyKolkata 4 года назад
Hi Pinal here the performance gets degraded when you create two indexes in the order of A, B and B, A. Are they not covering index ? Should B, A be used ? What happens if I add another index of the order C, D ? Just a query,
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
Your question is very valid and it should be investigated. I will have to try myself.
@paruchurusurendra
@paruchurusurendra 3 года назад
did we can retrieve the JSON data as early as possible from the table we have 30 columns
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 3 года назад
Sorry, I do not understand your question
@slavamurygin4849
@slavamurygin4849 4 года назад
Pinal, saw that presentation on PASS Summit. Which version of SQL Server you are using? 2016 does not show that behavior: Microsoft SQL Server 2016 (SP2-GDR) (KB4293802) - 13.0.5081.1 (X64) Jul 20 2018 22:12:40 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows 8.1 Enterprise 6.3 (Build 9600: ) (Hypervisor)
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
I used SQL Server 2017 for this demo and SQL Server 2019 for PASS.
@slavamurygin4849
@slavamurygin4849 4 года назад
@@PinalDaveSQLAuthority Thanks. I can see it now
@allentertainmentin1565
@allentertainmentin1565 4 года назад
Hey Pinal, if scan 20% and lookeup 10% update 70%.Is it unused index? Yes/No ? then how
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
It is difficult to answer without looking at the all the indexes.
@Ganeshay-996
@Ganeshay-996 2 года назад
are u provide training of sql basic to advance
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 2 года назад
All videos online.
@Ganeshay-996
@Ganeshay-996 2 года назад
@@PinalDaveSQLAuthority paid cource. And fees?
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 2 года назад
@@Ganeshay-996 It is free. Just watch all the videos on RU-vid.
@Chinnurockbells
@Chinnurockbells 2 года назад
How to reset indexes sir,
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 2 года назад
Sorry, I do not understand.
@Chinnurockbells
@Chinnurockbells 2 года назад
@@PinalDaveSQLAuthority I create indexes long back then how can I reset the indexes. Is it requires? If requires how to reset existing indexes
@richard75013U
@richard75013U 5 лет назад
​ Pinal Dave You are exploiting a rare scenario and attempting to invoke fear for those that don’t know that this can occur so they will hire you as identified by the quote from you below "we can discuss during the consultation or during training". Another person is asking you how to identify missing indexes and you tell him to subscribe to some site and you will hand out 3 free scripts when you could have just replied back informing he/she to use the built-in DMV sys.dm_db_index_usage_stats. I have seen some of your videos and liked them, but this is a step a little too far in my opinion. 99.99999% of the time your performance problem will NOT be from an index but from an overwhelmed subsystem resource, mis/non-configured server settings, mis/non-configured database settings, missing indexes, your query and yes the poor architecture a db may have which can help to induce performance issues.
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
Hi Richard, Thanks for your comment. I appreciate your comment and I totally agree there are lots of things beyond the index. During SQL Server consultancy, along with the index, you need to look at lots of different things - just to name few - Server/Instance Level Configuration Check I/O distribution Analysis SQL Server Resource Wait Stats Analysis TempDB Review Database Files (MDF, NDF) and Log File Inspection Log Reviews (Windows Event Logs, SQL Server Error Logs and Agent Logs) DBCC Best Practices Implementations When you subscribe to get free scripts you get the complete script which also generates the drop script of the unused index. However, for advanced users, you can use sys.dm_db_index_usage_stats as well. Here is the link for my consultancy, where we discuss indexes and lot more content: blog.sqlauthority.com/comprehensive-database-performance-health-check/ All the advanced users do not need any consultants, as they can just do all of them myself. However, those who are busy can consider hiring others to do the task for them. Again, truly appreciate you taking time to leave a comment. Thank you!
@ChintanCG
@ChintanCG 5 лет назад
how do i find unused indices in the database?
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
Chintan, You can go to go.sqlauthority.com and subscribe there and in the response, you will get three free performance tuning scripts.
@natalirozin6965
@natalirozin6965 5 лет назад
sys.dm_db_index_usage_stats
@lookingforronfalter
@lookingforronfalter 5 лет назад
you've just happened to come across a bug in the qry optimizer. It picked a poor plan! I would say this is more rare than you think. Not impossible of course, but probably not to lose sleep over. If you have adequate IO/CPU headroom, and your server is humming along performing well, don't waste your time looking for these obscure problems
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
Hi there, honestly no. This is what I have been seeing at many of my clients from the last 10 years. During consultation, we have found many cases which are similar to this one and also this is not a bug but rather expected behavior.
@lookingforronfalter
@lookingforronfalter 5 лет назад
@@PinalDaveSQLAuthority if you're looking at high resource consuming queries, you should detect this and fix it any way.. but I disagree, it's a bug when it comes to query optimization. It's a failure on the optimizer.. I'm sure David DeWitt would agree
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
@@lookingforronfalter let us agree to disagree. However, as I mentioned Indwx Tuning is not I start my day with... There are many more stuff you need to do it before it, and I am sure you agree with that part.
@mohsenbolhasani7880
@mohsenbolhasani7880 5 лет назад
Hi Why did this happen? Is there any explanation?
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
Great question, I really wish the explanation was that simple. It is pretty long and I usually cover that in my training. However, for the simple version, you can watch some of my free videos here and I explain it there. blog.sqlauthority.com/free-learning-videos/
@martinsmith8670
@martinsmith8670 4 года назад
explanation here dba.stackexchange.com/questions/259780/creating-an-index-that-is-not-used-by-a-select-query-reduces-performance-of-th/259853#259853
@curtisbrowne2710
@curtisbrowne2710 4 года назад
I was not able to reproduce this behavior on SQL2019. I was using AdventureWorks2017. As long as the first index is there is behaves nicely even if the second one exists. I tried compatibility levels 130, 140 and 150. Are we sure what you present is true? Does it depend on the database?
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
I tried it and it works in SQL Server 2019 as well just like the other one.
@curtisbrowne2710
@curtisbrowne2710 4 года назад
@@PinalDaveSQLAuthority Yes, it works on AdventureWorks2014, but I it doesn't seem to work on the AdventureWorks2017 version of the database.What would cause the behavior to change?
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
@@curtisbrowne2710 I tried with 2017 with different compatibility and it works too. I am really not sure.
@martinsmith8670
@martinsmith8670 4 года назад
@@curtisbrowne2710 did you take into account that the behaviour depends on index id? So it matters what order the indexes are created in? dba.stackexchange.com/questions/259780/creating-an-index-that-is-not-used-by-a-select-query-reduces-performance-of-th/259853#259853
@techsapphire
@techsapphire 5 лет назад
This is very wrong way to present this problem. If I have to tune this query that first thing will he getting rid of lazy spool. By using cte or temp table . Creating index is not even a solution in this. But I really fan of your blog. Thank you for posting this.
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
Thanks for watching the video. Please note that the goal of the video was not to tune the query but to demonstrate that index can reduce the performance of the index. I hope you got that message, please. Once you agree to the point we can focus on alternatives to fix the queries. Additionally, the first index solves the problem as well. It is just an addition index, which is not used is creating a problem. Besides CTE or temp table and indexes there are few more tricks also there where we can get query Performance without changing the code too... In some future video, I will cover it. Thank you again for watching the video, I think we both agreed that indexes are not good so we are the same page.
@techsapphire
@techsapphire 5 лет назад
@@PinalDaveSQLAuthority Now when I see it, I agree with you. It is specially for DBA who just think index is solution to every thing. Thank you keep posting :)
@caparn100
@caparn100 5 лет назад
I spent over 10 minutes watching this video but you didn't say why the select was slower with an unused index. So this video is not really very helpful. Are you hoping we will pay you to tell us that or are you expecting us to google to find out why?
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 5 лет назад
Great question my friend. The topic was to show that Index reduces the performance of SELECT queries and not to go into the details about why as it would a very long deeper conversation which we can discuss during the consultation or during training. I hope from this video I was clear that just like Insert, Update and Delete, an Index can slow down a SELECT statement as well. Let me know if that was not clear. ... and thank you for watching this one!
@martinsmith8670
@martinsmith8670 4 года назад
Explanation here dba.stackexchange.com/questions/259780/creating-an-index-that-is-not-used-by-a-select-query-reduces-performance-of-th/259853#259853
@alajpurinikhila9225
@alajpurinikhila9225 2 года назад
find top 1-3 queries that are executed the most
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 2 года назад
I have blogged about them at stackoverflow.com
@rajib2k5
@rajib2k5 4 года назад
lol... that's a lot of forward statement my friend. :D
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
So true!
@FrancescoMantovani
@FrancescoMantovani 4 года назад
I think I have to pay that 1:1 session for my managers. If they don't listen to me at least they will listen to you :|
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 4 года назад
Thank you Francesco, it will be always a pleasure.
@srinivasannaswamy7658
@srinivasannaswamy7658 3 дня назад
why on earth anyone wants average on productid . Query is reading same table twice with a sub query in where clause . can be easily written with over clause and partition by . Best Practices of writing query not followed
@PinalDaveSQLAuthority
@PinalDaveSQLAuthority 3 дня назад
This was the example query.
Далее
SQL Server Execution Plan Operators
42:07
Просмотров 78 тыс.
I Built a SECRET Lamborghini Dealership!
33:02
Просмотров 10 млн
КОТЯТА НАУЧИЛИСЬ ГОВОРИТЬ#cat
00:13
CPU Running 100% - SQL in Sixty Seconds 185
5:28
Просмотров 20 тыс.
Watch Brent Tune Queries 2020
51:32
Просмотров 24 тыс.
Watch Brent Tune Queries - SQLSaturday Oslo
1:01:54
Просмотров 45 тыс.
SQL Indexes - Definition, Examples, and Tips
12:14
Просмотров 78 тыс.
Скучнее iPhone еще не было!
10:48
Просмотров 614 тыс.