8. Performant SQL
Activity 8.01: Query Planning
- Open PostgreSQL with
psqland connect to the
- Use the
EXPLAINcommand to return the query plan for selecting all available records within the
EXPLAIN SELECT * FROM customers;
- Read the output of the plan and determine the total query cost, the setup cost, the number of rows to be returned, and the width of each row.
The output is as follows:
Seq Scan on customers (cost=0.00..1535.00 rows=50000 width=140)
As such, the total query cost is
1535.00, the setup cost is
0.00, the number of rows to be returned is
50000, and the width of each row is
140. Your result may have numbers that are slightly different. But the general concept of measurements should be the same.
- Repeat the query from step 2 of this activity, this time limiting the number of returned records to
15. Review the updated query plan and compare its output against the output of the previous step...