Query optimization is hard! But it is much simpler when visualized!  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏
SQL For Devs

Understanding the EXPLAIN Command To Optimize Slow Queries

Happy New Year everyone! I want to dedicate this newsletter to a passion topic of mine: I've now been helping teams optimize their slow database queries for years because apps shouldn't be slow - and slow response times result in a bad user experience. And why are those queries slow? It is not because those teams are bad at what they are doing: Understanding which part of a query is slow is just too hard!

Visual EXPLAIN for MySQL

I had private tooling for all those years to simplify the EXPLAIN output you get when optimizing a query. But this helped only me and not the thousands of developers constantly struggling to optimize a query. You could say this is a solved problem today as you can ask an AI to help you. But the reality is different: AI will spit out something for simple queries, which may actually be correct sometimes but the recommendations are worthless as soon as queries get more complex when multiple tables are involved with joins, subqueries etc.

Last year, I dedicated a lot of work to making my custom tooling easier to understand for anyone so that deep database experience is unnecessary. The result is a free graphical service for MySQL to visualize query plans that I now want to share with you: mysqlexplain.com

There is also an API you can use to submit slow queries easily. I've used it to build a TablePlus plugin , a PHP package and Laravel integration . I would also love to offer a VS Code and DataGrip plugin, but I've not yet figured out how to do it.

Example of a Visualized EXPLAIN Plan

Alternatives

This project is dedicated to MySQL because it lacked such a tool and I understand why: It was a ton of work handling all the edge cases the EXPLAIN output can have, which you only know when working with it for years. In the past, the MySQL Workbench could show graphical EXPLAINs, but it was never updated for MySQL 8 (released more than 6 years ago!). Analyzing a query that used “new” features crashed the tool or displayed incorrect results by omitting critical information it didn't understand.

Most databases have fantastic tooling to visualize and optimize slow queries. If you use PostgreSQL, I used and personally recommend these tools:

Go ahead and check out my tool or the ones I recommended. I am happy to receive any feedback! Do you have any suggestions for improvements?

Indexing Beyond the Basics

Learn Everything About Creating Database Indexes You don't have to know all the complicated database internals to make a slow query fast. This book teaches simple rules for creating good indexes - enriched with dozens of illustrations to make all concepts more easy to understand. You have no excuse anymore for your slow queries!

SQL For Devs SPONSOR

Curated Database Content

Other people also write great educational content. So I hand-pick some new articles for this issue you may like. Have fun learning even more.

Databases in 2024: A Year in Review The yearly write-up of database researcher Andy Pavlo is always a must-read! You don't follow databases closely? Now you can get a summary of everything important that happened last year.
cs‌.‌cmu‌.‌edu
Is Oracle Finally Killing MySQL? Peter Zaitsev, the founder of the most-known MySQL consulting company Percona questions Oracle's handling of MySQL. He's right that there's not much interesting work happening on the open-source version of MySQL.
percona‌.‌com
Challenges of Postgres Containers Nowadays, everything is run in containers as it simplifies deployment. But PostgreSQL has some pitfalls you should know before. However, the criticism about collations also applies when upgrading the operating system.
ardentperf‌.‌com
Evaluating Vector Indexes in MariaDB and Pgvector MariaDB added vector storage support last year and benchmarks by the trusted Mark Callaghan show its consistently faster than PostgreSQL. But pgvectorscale is also much faster than pgvector. The fastest one changes all the time...
smalldatum‌.‌blogspot‌.‌com
Postgres Support With Bun 1.2 The bun JavaScript runtime bundled PostgreSQL support directly into their runtime, showing significant performance improvements. Native is still faster! MySQL seems to be planned next.
bun‌.‌sh
MySQL Cloud Services Cost Comparison: Who Provides the Best Value? Oracle compared MySQL cloud providers and found itself to be the cheapest. Sure, it isn't very objective. But is there anything to dispute when comparing public pricing of CPU cores and available memory?
oracle‌.‌com
This message was sent to phps6dnxqhkm8i24@kill-the-newsletter.com.
If you don't want to receive these emails in the future, you can unsubscribe .