This set of questions relates to the results of the EXPLAIN query on simple queries.
The quiz is available as a google form https://forms.gle/5fdjpUSr8YaqA9KNA
in the query
select * from trees;
The EXPLAIN diagram uses a sequential scan
What is a sequential scan ?
epita@airdb=> explain select * from passenger;
QUERY PLAN
----------------------------------------------------------------------
Seq Scan on passenger (cost=0.00..334838.55 rows=16311855 width=47)
(1 row)
so we have
and
epita@airdb=> explain select * from passenger where age > 68;
QUERY PLAN
---------------------------------------------------------------------------------
Seq Scan on passenger (cost=0.00..375618.19 rows=3613778 width=47)
Filter: (age > 18)
(5 rows)
so we have
In the second query the cost has gone up although less rows are returned.
Why ?
The passenger table has a id primary key
Explain the difference between Index Scan and Index Heap scan in the 2 examples
explain select * from passenger where passenger_id = 8888;
QUERY PLAN
---------------------------------------------------------------------------------
Index Scan using passenger_pkey on passenger (cost=0.43..8.45 rows=1 width=47)
Index Cond: (passenger_id = 8888)
(2 rows)
and
explain select * from passenger where passenger_id < 8888;
QUERY PLAN
----------------------------------------------------------------------------------
Bitmap Heap Scan on passenger (cost=184.03..31558.41 rows=9754 width=47)
Recheck Cond: (passenger_id < 8888)
-> Bitmap Index Scan on passenger_pkey (cost=0.00..181.59 rows=9754 width=0)
Index Cond: (passenger_id < 8888)
Which if the following statement is true
In the following query plan
explain select * from passenger order by random() limit 50;
QUERY PLAN
----------------------------------------------------------------------------------
Limit (cost=917486.28..917486.41 rows=50 width=55)
-> Sort (cost=917486.28..958265.92 rows=16311855 width=55)
Sort Key: (random())
-> Seq Scan on passenger (cost=0.00..375618.19 rows=16311855 width=55)
JIT:
Functions: 3
Options: Inlining true, Optimization true, Expressions true, Deforming true
(7 rows)
what is the order of operations ?