April 2018
Intermediate to advanced
508 pages
15h 22m
English
When OFFSET is added to a query, it isn't handled by its own node type. It's handled as a different form of limit. Essentially, the first few rows the underlying scan produces are thrown away. This is easy to see given a variation on the LIMIT query seen previously:
EXPLAIN ANALYZE SELECT customerid FROM customers OFFSET 10 LIMIT 10;
QUERY PLAN
----------
Limit (cost=0.34..0.68 rows=10 width=4) (actual time=0.052..0.101 rows=10 loops=1)
-> Seq Scan on customers (cost=0.00..676.00 rows=20000 width=4) (actual time=0.012..0.047 rows=20 loops=1)
Total runtime: 0.157 ms
Note how, this time, the Seq Scan node produced 20 rows of output. The first 10 were skipped by the OFFSET, then the next 10 satisfied the LIMIT node, at which point ...
Read now
Unlock full access