Thursday, December 14, 2017

Understanding MySQL Queries With EXPLAIN

DZone Database Zone
Understanding MySQL Queries With EXPLAIN
Understanding MySQL Queries With EXPLAIN

You’re in your new job as a database administrator or data engineer and you just got lost trying to figure out what these insane looking queries are supposed to mean and do. Why are there five joins and why is there an ORDER BY used within a subquery before one of the joins even happens? Remember, you were hired for a reason — most likely, that reason also has to do with many convoluted queries that were created and edited over the last decade.

Explain

The EXPLAIN keyword is used throughout various SQL databases and provides information about how your SQL database executes a query. In MySQL, EXPLAIN can be used in front of a query beginning with SELECT, INSERT, DELETE, REPLACE, and UPDATE. For a simple query, it would look like the following:

No comments:

Fun With SQL: Functions in Postgres

DZone Database Zone Fun With SQL: Functions in Postgres In our previous  Fun with SQL  post on the  Citus Data  blog, we covered w...