A simple mnemonic to optimize your SQL queries.
Easy to remember, featuring squirrels 🐿️
Many different queries will get you to the same results.
The only difference then is the performance of each query.
SELECT
statement are executed in a specific order. After each step, the less data you have, the more performant your query is.
But in what order?
I’ve noticed that it is difficult for data engineers and data analyst to remember it, me included, so I crafted this silly mnemonic:
“Friendly Jungle Walks Generate Happy Squirrel Dances On Logs”
The next time you’re struggling with performance on an SQL query, close your eyes, and picture yourself having a nice, friendly walk in the jungle. You brought a bag of nuts to feed the local squirrels. As they have recognized you, they dance happily on a log.
Each Capital letter correspond to an evaluation step of your SELECT query:
🐿️ Friendly - FROM
🐿️ Jungle - JOINs
🐿️ Walks - WHERE
🐿️ Generate - GROUP BY
🐿️ Happy - HAVING
🐿️ Squirrel - SELECT
🐿️ Dances - DISTINCT
🐿️ On - ORDER BY
🐿️ Logs - LIMIT
This should help you get started understanding the performance issue of your SQL SELECT query.
Hope it helps :)