Are SQL joins bad for performance?

preview_player
Показать описание

Have you heard that SQL joins are bad and can slow down your queries? I've heard this too.

In this video, I'll demonstrate a query that joins three tables together along with the execution plan.
I'll also demonstrate the same query except all of the data is from one table, and the execution plan.

We'll then add some indexes and see what the execution plan looks like.

⏱ TIMESTAMPS:
00:00 - Our test
01:18 - Query 1
03:27 - Query 2
04:28 - Indexes
06:00 - Check both queries

LINKS:
Рекомендации по теме
Комментарии
Автор

for the last two day's i was watching your content,
i genuinely appreciate the time and the effort that you put into this vidoes, your content is amazing and it's well explained,
Thank you so much for sharing such a content.

alifawzi
Автор

I've always had this question: Does the number of joins affect performance or not? This video answered all my questions.

dav.R
Автор

Thank very much for this constructive demo.
I have question: when you indexed the columns, it reduced the total cost. But not the total execution time. Why you prefer reducing the total cost over the execution time which is crucial to for an applications in production ?

Sdirimohamedsalah
Автор

In this case, why wouldn't I add indexes everywhere if it allows for more performance?

pable
Автор

In your case separated tables win againts the single table with no indexes, in my case separated tables make more cost since each table has about 40 columns, but the single table on provide the columns that needed for the user, lets said 40x4 is 160 columns but in single table we approximitely only combine 20 columns each. I will try to implement this indexes with my company databases, as we seems need this indexes to be implemented. Working on old databases that been laying around for decades with MyISAM engine with millions of rows and try to make the performance faster as it getting slower every single month. Thanks for the video its really helpful. I will also considering to ask management to migrate to other database engine or even other DBMS like PostgreSQL, using Cache is kinda eating too much memory considering our company budget that run all the apps in one server.

NotMeEitherOfficial
Автор

Very insightful thanks a lot ❤ what does noc stand for?

CanRau
Автор

Hi, can you offer us the DDL scripts that you used to set up your example database? Then we can recreate it directly. That would be great. Thanks and regards \sdohn

ftet
Автор

Are all these concepts applicable on cloud services? Wouldnt there be a difference?

ublue
Автор

Very well done, sir. I do get asked about the effort made to normalize a database. The insight offered by your very clear explanation will go a long way in helping to answer those queries.

Your videos and website are a great resource for the database developer community.

sdmagic
Автор

Hi,

Thank you for the great insight.

What is the software you use to run the queries and the explain feature?

milenfrom
Автор

Do you think joins can have impact on scalability? Thanks

tanzimibthesam
Автор

This is completely wrong.
0) Operating in "less than a second" units for 100-200k tables is like saying this car was not expensive, it's was less than a million dollars. You need to show execution times millis from the query plan (EXPLAIN ANALYZE).
1) You execution time seemed to be 5 times faster for the denormalized query.
2) Joining will ALWAYS be slower than one tabel if you join big tables (sorry but in 2023 few hundred k rows is nothing, even on a local machine).
3) You didn't explain how actually JOIN works behind the scenes but I get it because it would ruin the whole video.

luco-games