Last active
January 20, 2022 05:41
-
-
Save sdebnath/e015561811adf721dd40dd6638969c69 to your computer and use it in GitHub Desktop.
Test workload for PostgreSQL MultiXact: create new mxacts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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