From 4a3d453d0d2785a8269857e186feec6c7f4f07dd Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Fri, 4 Nov 2022 19:03:02 +0300 Subject: [PATCH] sql_examples.sql --- sql_examples.sql | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 sql_examples.sql 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