gvwilson / sql-tutorial

The Querynomicon: An Introduction to SQL for Wary Data Scientists
https://gvwilson.github.io/sql-tutorial/
Other
418 stars 35 forks source link

feat: use "explain query plan" instead of "explain" #10

Closed SamHames closed 5 months ago

SamHames commented 5 months ago

The explain command example gives low level details of the SQLite virtual machine which probably isn't intelligible to many people.

More useful is the explain query plan version which shows which indices and what kind of processing is taking place for a given query. This is useful to identify missing indexes and avoid full table scans.

explain query plan
select
    species,
    avg(body_mass_g)
from penguins
group by species;

Output:

QUERY PLAN
|--SCAN penguins
`--USE TEMP B-TREE FOR GROUP BY
gvwilson commented 5 months ago

thanks very much!