Why Performance Tuners Need To Use The Right Type Of Join In SQL Server

  Рет қаралды 1,572

Erik Darling (Erik Darling Data)

Erik Darling (Erik Darling Data)

Күн бұрын

Пікірлер: 20
@hannahvernon
@hannahvernon 7 ай бұрын
I really love seeing a LEFT JOIN with the referenced table appearing in a WHERE clause. I mean, that essentially *is* an INNER JOIN.
@ErikDarlingData
@ErikDarlingData 7 ай бұрын
Unless it’s where something is null, and then it’s just a 💩
@mkeyx82
@mkeyx82 Ай бұрын
I've had some good fortune working with queries that used extra (but necessary) left joins (where it seemed like adding 6th or 7th left join made things exponentially worse; incredibly, it seems the same thing happens when drinking beer, everything is fine after the first 3 or 4) and replacing them with outer apply. Which again can introduce problems of its own, but the pay off seems higher when there's a subselect that is being left joined. Didn't know about the merge join predicament. I'll keep an eye out for that little s.o.b. Thanks.
@ErikDarlingData
@ErikDarlingData Ай бұрын
Yep, it’s a pesky thing for sure.
@brainsniffer
@brainsniffer 7 ай бұрын
Erik recommends every query needs a right join? Sounds good to me!
@ErikDarlingData
@ErikDarlingData 7 ай бұрын
😂😂😂
@zammea
@zammea 7 ай бұрын
Hi, mind me asking but way back I saw a code structured like that select columns from tableA left outer join tableB on a.id = b.ref_id where b.ref_id is null I was wondering is this a wrong way of writhing a.id not in (select b.ref_id from tableB)?
@ErikDarlingData
@ErikDarlingData 7 ай бұрын
Check out this post to learn more about that: erikdarling.com/the-how-to-write-sql-server-queries-correctly-cheat-sheet-exists-and-not-exists/
@zammea
@zammea 7 ай бұрын
@@ErikDarlingData Thank you.
@caparn100
@caparn100 7 ай бұрын
Merge joins are excellent if joining two tables on a clustered index when they have the right columns for the join.
@ErikDarlingData
@ErikDarlingData 7 ай бұрын
Sort of like in this query plan where they’re not awesome? 😉
@mrfuzztone
@mrfuzztone 5 ай бұрын
The INNER JOIN was faster because of the Bitmap filter used by the hash join. You did remind me of why an INNER JOIN can be faster than a LEFT JOIN when appropriate. Good real world example. Of course an INNER JOIN might perform identical to a LEFT JOIN. Depends.
@ErikDarlingData
@ErikDarlingData 5 ай бұрын
Yes, many things do seem to depend.
@seancarroll6843
@seancarroll6843 7 ай бұрын
Never knew about the parallel merge join pitfall... did MS just think that having a plan going parallel and risking the thread deadlock is "always" better than defaulting to a serial query because it wants to use a merge join? FYI if everyone thinks you're "darlene data" maybe you're off the hook with beer gut magazine.
@ErikDarlingData
@ErikDarlingData 7 ай бұрын
well, it's all about costing, and the optimizer doesn't consider the *chance* of a parallel deadlock when choosing plans. if i had anything to say about it, once parallel plan exploration started, merge join costs would increase significantly. though i think they view it as more of a challenge to fix parallel deadlocks to avoid merge joins. i've added a link to the video with more details about exchange spills for reference.
@seancarroll6843
@seancarroll6843 7 ай бұрын
@@ErikDarlingData Thanks! I appreciate the additional info!
@seannalexander
@seannalexander 6 ай бұрын
OPTION (OPTIMIZE FOR UNKNOWN) HELLO I AM SEE(A)N
@ErikDarlingData
@ErikDarlingData 6 ай бұрын
I can see into the UNKNOWN
@FlaggedStar
@FlaggedStar 7 ай бұрын
I think you've just accidentally explained why I can never get table variables to merge join. If you can't go parallel, then you probably won't merge join.
@ErikDarlingData
@ErikDarlingData 7 ай бұрын
No, that’s completely wrong thinking. You don’t need a parallel plan to get a merge join, and there’s no restriction on parallel select plans from table variables. More likely is you don’t have a supporting index for the Merge join, and that the low cardinality estimates from them make nested loops seem cheaper.
Choosing Between Triggers And Foreign Keys In SQL Server
13:29
Erik Darling (Erik Darling Data)
Рет қаралды 576
How To Use A Numbers Table To Replace WHILE Loops In SQL Server Functions
9:44
Erik Darling (Erik Darling Data)
Рет қаралды 1 М.
Это было очень близко...
00:10
Аришнев
Рет қаралды 7 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 11 МЛН
My MEAN sister annoys me! 😡 Use this gadget #hack
00:24
JOON
Рет қаралды 2,4 МЛН
Performance Pains With NOT IN And NULLable Columns In SQL Server
12:36
Erik Darling (Erik Darling Data)
Рет қаралды 842
Advanced String Searching In SQL Server
14:31
Erik Darling (Erik Darling Data)
Рет қаралды 1,1 М.
Fundamentals of Vacuum in PostgreSQL: Module 1
12:06
Smart Postgres
Рет қаралды 1,1 М.
An Advanced SQL Server Query Profiling Technique
11:01
Erik Darling (Erik Darling Data)
Рет қаралды 2 М.
Everything You Know About Isolation Levels Is Wrong Promo
8:38
Erik Darling (Erik Darling Data)
Рет қаралды 733
Why You Should Always Use Unicode For Dynamic SQL
10:19
Erik Darling (Erik Darling Data)
Рет қаралды 733
A Video For My Friend Brent About Automatic Tuning
10:35
Erik Darling (Erik Darling Data)
Рет қаралды 1 М.
A Little About Paging Queries And Batch Mode In SQL Server
19:45
Erik Darling (Erik Darling Data)
Рет қаралды 1 М.
Tricky Scalar UDF Rewrites In SQL Server
9:35
Erik Darling (Erik Darling Data)
Рет қаралды 467
When Profiling SQL Server Stored Procedures Gets Tricky
10:36
Erik Darling (Erik Darling Data)
Рет қаралды 350
Это было очень близко...
00:10
Аришнев
Рет қаралды 7 МЛН