Using indexes with your queries

In this section, we will go over how to see which indexes your multiple tables query is using and how to troubleshoot them. Please refer to Chapter 6, Querying a Single Table, for an introduction to the EXPLAIN syntax you will be using here.

You will begin with a query you used earlier in the chapter and will add EXPLAIN to the query to get information about which indexes your query is using. Execute the following query to get your index explanation information:

EXPLAIN SELECT p.playerid, p.birthyear, a.yearid, a.teamid, a.G_defense, b.HFROM lahmansbaseballdb.appearances AS aINNER JOIN lahmansbaseballdb.people AS pON p.playerid = a.playeridINNER JOIN lahmansbaseballdb.batting AS bON p.playerid = b.playerid ...

Get Learn SQL Database Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.