diff --git a/sql_examples.sql b/sql_examples.sql new file mode 100644 index 0000000..2a713e1 --- /dev/null +++ b/sql_examples.sql @@ -0,0 +1,34 @@ +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 \ No newline at end of file