Skip to content

Instantly share code, notes, and snippets.

@georgewfraser
Created August 20, 2022 00:54
Show Gist options
  • Save georgewfraser/1401b8382bec3b2202ccfe4d12cfbfa8 to your computer and use it in GitHub Desktop.
Save georgewfraser/1401b8382bec3b2202ccfe4d12cfbfa8 to your computer and use it in GitHub Desktop.
-- psql -d postgres -f 1.Generate.sql
drop table if exists source;
create table source as
select
x,
cast(random() as varchar) as a,
cast(random() as varchar) as b,
cast(random() as varchar) as c,
cast(random() as varchar) as d,
cast(random() as varchar) as e,
cast(random() as varchar) as f,
cast(random() as varchar) as g,
cast(random() as varchar) as h,
cast(random() as varchar) as i,
cast(random() as varchar) as j
from generate_series(1, 5000000, 1) as x;
select count(*) from source;
-- time psql -d postgres -f 2.Paging.sql > output.txt
begin;
set transaction isolation level read committed;
declare page_cursor cursor for select * from source;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
fetch 100000 from page_cursor;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment