
Chapters
- 00:00:00 – Introduction
- 00:01:05 – DOPing Points Explained
- 00:03:20 – Query Cost Analysis
- 00:05:50 – Tipping Points and DOP
- 00:07:35 – Conclusion
Full transcript
Erik Darling here with Darling Data. And I’ve got a question that I thought was interesting enough to actually answer with a brief demonstration, so I’m going to do that today. But it is about DOP and tipping points, or as I will lovingly refer to them from now on, DOPing points, because why not? Let’s just make things hard for everyone to understand. What’s wrong with that query? at the DOPing point? What’s that? You don’t want to know. It’s going to cost you $10.99 to find out. Down in the video description, there are very many helpful links for you to click on. If you’d like to hire me to fix your SQL Server performance problems, you can do that. It’s right down that way. You can also purchase my training at a discount. There’s coupons down in the doodads there. You can become a supporting member of the channel. Ask me office hours questions like I did yesterday-ish. And of course, like, subscribe, tell a friend, all that stuff. You know, the usual. If you need free SQL Server and Postgres performance monitoring, I’ve got it all under one handy umbrella. Totally free, totally open source, no weird email stuff. Just a whole bunch of perfectly written collector quiz.
queries that go and get all the stuff that you would care about as a performance tuning data professional. I recently added AGs in there, which, you know, personally, I didn’t want to do, but some people like that stuff. So here we are. And if, you know, as we transfer ourselves over to the robots, my tooling, I built it in there on purpose, has all sorts of fantastic read-of fantastic read-only MCP tools, so you can let your robot friends talk to your collected monitoring data and do all the sort of fun analysis and figuring things out for you. And then you come back and look like either a hero or an idiot, depending on what you’re using to do that analysis. So, could go either way. Choose wisely, my friends. Choose wisely. Choose wisely.
Choose wisely. And fewer than one month, I will be at Pass Summit West in Seattle, Washington, November 9th through 11th. I’ve got a pre-con there about T-SQL that doesn’t suck. You should come to that one. Because if you are out there in the world and you are using the robots to do the analysis you need you need to know what you’re talking about so the robots can’t talk past you um you know i still run into it quite a bit where uh you know i’m using my robots to do my stuff and they say something that is absolute nonsense and i’m like hey buddy bring that way back way back over here and and so you still need to know what you’re doing a little bit if you are going to remain a competent human in the loop uh with all these robots flying around doing things but it is time to continue to celebrate the month of october and uh let’s let’s do this old demo thing here so uh we’re gonna we’re gonna hope that uh the robots don’t pop anything up today i’ve asked them to i’ve asked them to take a break from anything that might pop up while i record this we’ll see how well that goes so uh i’ve created a single key column index over here uh the the because i need i want to show you something kind of interesting now uh this all has to do with query costing and at what point lookups become uh to the optimizer theoretically estimatedly more expensive than scanning something all right so if we run these two queries uh that are asking for where post type post id is less than 250 at max.1 which does limit max.1 and max.8 which remember max.1 is not min.1 this this will limit max.1 to 8 but it doesn’t guarantee max.1 will be 8 right just in case right and we did these return a lot of rows so we’re just going to work with estimated plans here when i run this these both uh let me check this up a little bit higher so uh it fills the screen and when i zoom in things don’t look dumb when we run this it for less than two post id is less than 250 they both get serial execution plans and they are both using key lookups right so we’re seeking to where post type id is less than 250 and then we are going back to the clustered index to get that user id column because that is not in our nonclustered index right and it is not the clustered primary key so it is not inherited by our non-unique nonclustered index right and then if we run these two queries for uh where post id is less than 2000 uh things change a little bit uh or rather a lot of bit at max.1 sql server still estimates that doing the lookups is cheaper than scanning the clustered index so with the single threaded query sql server is like uh i don’t know if scanning 53 million rows of the votes table is the best plan with one cpu i think i’d rather do a bunch more lookups when uh we don’t limit max.1 when we say max.1 you can go up to eight sql server is like well if i had eight of them scanning this 53 53 million row clustered index that turns out a little bit better for me right because uh that that seems like less work i don’t like we’re not looking at times or anything here i’m not saying whether the estimate the optimizer uh and its estimates are right or wrong it’s it’s it’s just showing you how it thinks and how it behaves a bit and then finally if we say where post id is less than 5000 these both do scans right sql server is like i don’t know that even at max.1 oh come on grabby thing even at max.1 that’s a lot of lookups for me uh i i think i’m just going to scan this whole thing instead so the the tipping point for these things does change depending on DOP right like DOP does have an effect on the cost models and all the other stuff there are some times where forcing a query to use max.1 retains a better plan across the board i know it’s a weird thing to say because for years everyone made fun of sharepoint and dunked on sharepoint because you had you had to have MAXDOP set to one and this was before we had the database scope configuration to uh change MAXDOP per database this was when MAXDOP was server level so if you had sharepoint on a sql server with other stuff you were like uh it’s a MAXDOP one everything sucks everywhere else well i mean sharepoint always suck but yeah whatever but there are some times where you might be in a situation where you’re like you know what i i know my data’s my data’s dictate that i never want to scan this clustered index and we’re forcing MAXDOP to one will uh be a strong enough guarantee uh for most cases this one it’s not a strong enough guarantee because uh just that less than predicate on 5 000 those are like an equality predicate we could do things differently but uh with a less than predicate like you probably don’t want to do like where where post id is less than 49 million and be like yeah you should still do a 49 million key lookup probably not a good idea but if you’re if you’re using equality predicates or you’re using very tight greater than less than with some equal twos in there maybe uh predicates and you know your data well enough where you’re like i never want to scan the clustered index no matter what sql server estimates um you know there are all sorts of ways to get sql server to do that that don’t involve creating a wider index you know you can uh have a stick a FORCESEEK hint on there uh you can use FORCESEEK with a named index uh or sometimes MAXDOP one is a good choice because for a small enough number of rows a parallel key lookup is not going to buy you right it’s just like like like what are you going to spread like you know 10 thousand rows out on eight threads that’s not a good use of eight of eight cpus why would you do that right uh small numbers of rows you don’t need lots of big numbers of rows lots of threads good small numbers of rows lots of threads not helpful right so um MAXDOP one is one interesting way one interesting hint that you can use to uh affect costing in a way that benefits you but as always test carefully all right thank you for watching i hope you enjoyed yourselves i hope you learned something and i’ll see you in tomorrow’s video uh where i actually i’m going to show you something neat with indexes so that that’ll be fun all right goodbye
Going Further
Someone still has to know enough SQL Server to keep the robots in check, and that’s what my training is for.