DEV Community

Cover image for Advanced SQL: Mastering Query Optimization and Complex Joins

Advanced SQL: Mastering Query Optimization and Complex Joins

bilel salem on May 30, 2024

Hello everyone, السلام عليكم و رحمة الله و بركاته SQL (Structured Query Language) is an essential tool for managing and manipulating relational d...
Collapse
 
andatki profile image
Andrew Atkinson • Edited

Hi Bilel. Nice post! I’ve recently written a PostgreSQL book that covers advanced SQL, query planning, index design, and uses a Ruby on Rails app for examples and exercises.

After reading through your examples, I’ve realized we didn’t cover recursive CTEs (non recursive CTEs are covered) or lateral joins. I’ll save your post and link to as you introduce those topics nicely.

You did a great job of boiling down all of these topics into short descriptions with examples.

As you mentioned in Postgres we’ve got native materialized views that can be refreshed concurrently and indexed. In the extension ecosystem, there are even extensions to incrementally update materialized views.

Thanks for writing the post!

Collapse
 
bilelsalemdev profile image
bilel salem

You are welcome, Thank you .

Collapse
 
alvfig profile image
Alvaro Figueiredo

Great article, I just learned a bunch of new techniques! I only missed a mention to the use case of ANALYZE statement to update the statistics about the dataset, allowing optimization of WHERE clauses.

Collapse
 
ali-cherif profile image
MOHAMMEDI

Very interresting informations

Collapse
 
alexandrefuente profile image
alexandrefuente

Awesome article. 👏🏽

Collapse
 
martinbaun profile image
Martin Baun

Very well done. I've got some videos on YouTube on the same topic as well, and I agree with a lot of this!

Collapse
 
craiginscotland profile image
craig mcinne • Edited

Did you state a product anywhere or are you picking pure ANSI standard SQL ?
Looks like SQL Server to me.

Collapse
 
bilelsalemdev profile image
bilel salem • Edited

standard SQL, i put some notes for mysql about materialized views

Collapse
 
ihebsebai profile image
iheb-sebai

Extremely helpful

Collapse
 
firas_latrach profile image
Firas Latrach

Good job 👏

Collapse
 
solixzsys profile image
solixzsys

Thanks very much.
But are this sql construct portable across all major relational databases because you only took notes of MySQL?

Collapse
 
bilelsalemdev profile image
bilel salem

i took note for mysql because it doesn't support directly materialized views but postgres for example supports materialized views . It's more general than specific db .

Collapse
 
tun_nguynmnh_97f60a5f profile image
Tuân Nguyễn Mạnh

Nice article!

Collapse
 
oussema_benhassena_4ed78 profile image
Oussema Ben hassena

Very helpful 💯​

Collapse
 
yassinekhouaja profile image
yassineKhouaja

well done 💯​

Collapse
 
manikanda_saravanan_5b7fe profile image
manikanda saravanan

Great👍

Collapse
 
ultimate_solutions_3a629a profile image
Ultimate Solutions

Great