Created
February 2, 2020 02:43
-
-
Save akorotkov/fce8ec80e3b0bf113b68a82fe41294a3 to your computer and use it in GitHub Desktop.
Fastpath lock collision generator
This file contains 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 int4_to_bytea(int8) RETURNS bytea AS | |
$BODY$ | |
SELECT set_byte(' '::bytea, 0, ($1 % 256)::int4) || | |
set_byte(' '::bytea, 0, (($1 / 256) % 256)::int4) || | |
set_byte(' '::bytea, 0, (($1 / 65536) % 256)::int4) || | |
set_byte(' '::bytea, 0, (($1 / 16777216) % 256)::int4); | |
$BODY$ | |
LANGUAGE sql; | |
CREATE OR REPLACE FUNCTION int2_to_bytea(int4) RETURNS bytea AS | |
$BODY$ | |
SELECT set_byte(' '::bytea, 0, $1 % 256) || | |
set_byte(' '::bytea, 0, ($1 / 256) % 256); | |
$BODY$ | |
LANGUAGE sql; | |
CREATE OR REPLACE FUNCTION hashbytea(bytea) RETURNS int8 AS $$hashvarlena$$ LANGUAGE internal; | |
CREATE OR REPLACE FUNCTION rellocktaghash(regclass) RETURNS int4 AS | |
$BODY$ | |
SELECT (hashbytea( | |
int4_to_bytea((SELECT oid FROM pg_database WHERE datname = current_database())::int8) || | |
int4_to_bytea($1::int8) || | |
int4_to_bytea(0) || | |
int2_to_bytea(0) || | |
int2_to_bytea(256)) % 1024)::int4; | |
$BODY$ | |
LANGUAGE sql; | |
CREATE OR REPLACE FUNCTION make_collision() RETURNS void AS | |
$BODY$ | |
BEGIN | |
LOOP | |
CREATE TABLE collision (i int4); | |
IF rellocktaghash('collision'::regclass) = rellocktaghash('pgbench_accounts'::regclass) THEN | |
EXIT; | |
END IF; | |
DROP TABLE collision; | |
END LOOP; | |
END | |
$BODY$ | |
LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment