spring-pagination/sql_examples.sql
2022-11-14 18:25:25 +03:00

34 lines
687 B
SQL

EXPLAIN ANALYSE
SELECT *
FROM post
ORDER BY create_on
FETCH FIRST 50 ROWS ONLY;
EXPLAIN ANALYSE
SELECT *
FROM post
ORDER BY create_on
OFFSET 50 ROWS FETCH NEXT 50 ROWS ONLY;
EXPLAIN ANALYSE
SELECT *
FROM post
ORDER BY create_on
OFFSET 9950 ROWS FETCH NEXT 50 ROWS ONLY;
CREATE INDEX idx_post_created_on ON post (create_on DESC);
CREATE INDEX idx_post_created_on ON post (create_on DESC, id DESC);
EXPLAIN ANALYSE
SELECT *
FROM post
ORDER BY create_on DESC, id DESC
FETCH FIRST 50 ROWS ONLY;
EXPLAIN ANALYSE
SELECT *
FROM post
WHERE (create_on, id) < ('2022-10-30 00:11:43.224314', '8766d496-44c7-4e48-af29-b19178692cd9')
ORDER BY create_on DESC
FETCH FIRST 50 ROWS ONLY