Skip to content

Instantly share code, notes, and snippets.

@sdebnath
Last active January 20, 2022 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdebnath/e015561811adf721dd40dd6638969c69 to your computer and use it in GitHub Desktop.
Save sdebnath/e015561811adf721dd40dd6638969c69 to your computer and use it in GitHub Desktop.
Test workload for PostgreSQL MultiXact: create new mxacts
CREATE OR REPLACE FUNCTION mxact_create(SCALE integer) RETURNS void AS $body$
declare
default_rows_per_scale integer := 100000;
gap integer := 3000;
range integer := 100;
create_base_id integer;
segment_id integer;
begin
-- Generate a random number to use as a segment to offset concurrent connections from hitting the same exact range of ids
select (trunc(extract(millisecond from current_timestamp) * default_rows_per_scale, 0) % (100000 * scale)) into create_base_id;
-- Generate a random number to use as a segment to offset concurrent connections from hitting the same exact range of ids
select floor(random() * 10 + 1)::integer into segment_id;
-- Execute the SQL that will generate the multixact
perform * from pgbench_accounts where aid > (create_base_id + (segment_id * gap)) and aid < ((create_base_id + (segment_id * gap)) + range) for share;
end;
$body$ LANGUAGE PLPGSQL VOLATILE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment