From the course: Advanced SQL for Query Tuning and Performance Optimization

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Explain and analyze

Explain and analyze

- [Voiceover] One of the first steps in optimizing queries is understanding how they're executing. Remember, sequel's declarative. So for example, here's a simple declarative statement: select star from staff. A query is a declarative statement that must be mapped into a procedural execution plan. So we want to understand what that plan looks like. From there, we can do a variety of things to our data model and to the query to try and make it more efficient. The way we learn about the execution plan in Postgres is to use the explain command and we can precede a query with the command, explain. Now, explain is used in other databases as well, including MySQL and Oracle. If you use another database, check the documentation just in case there may be another command that's used to display the execution plan, but for now we can just run this command and this will produce an execution plan or also called a query plan.…

Contents