Given the following SQL query and its EXPLAIN output, what is the estimated number of rows the query planner expects to process?
EXPLAIN SELECT * FROM employees WHERE department_id = 5;
Output:
Seq Scan on employees (cost=0.00..35.50 rows=10 width=100)
Look for the 'rows=' value in the EXPLAIN output.
The 'rows=10' means the planner estimates 10 rows will be processed.
Look at this EXPLAIN output for a join query. What type of join is being used?
Nested Loop (cost=0.00..50.00 rows=20 width=200) -> Seq Scan on table1 (cost=0.00..20.00 rows=100 width=100) -> Index Scan using idx_table2 on table2 (cost=0.00..0.30 rows=1 width=100)
The first line of the EXPLAIN output usually shows the join type.
The output starts with 'Nested Loop', indicating a Nested Loop Join is used.
Which of the following EXPLAIN queries will cause a syntax error in PostgreSQL?
Check the syntax of the SELECT statement inside EXPLAIN.
Option B is missing the '*' after SELECT, causing a syntax error.
Given this EXPLAIN output, what does the 'cost=0.00..100.00' represent?
Seq Scan on orders (cost=0.00..100.00 rows=500 width=50)
Cost values show estimated resource usage, not time or row counts.
The first number is the startup cost, the second is the total estimated cost to run the query.
What is the main difference between running EXPLAIN and EXPLAIN ANALYZE on a query in PostgreSQL?
Think about whether the query is executed or just planned.
EXPLAIN only shows the estimated plan without running the query; EXPLAIN ANALYZE runs the query and shows actual execution details.