Skip to content

Instantly share code, notes, and snippets.

Created August 4, 2016 15:00
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
ALTER TABLE pgbench_accounts
ADD created_on timestamptz,
DROP CONSTRAINT pgbench_accounts_pkey;
CREATE UNIQUE INDEX ON pgbench_accounts(aid, created_on DESC);
\set nbranches :scale
\set ntellers 10 * :scale
\set naccounts 100000 * :scale
\setrandom aid 1 :naccounts
\setrandom bid 1 :nbranches
\setrandom tid 1 :ntellers
\setrandom delta -5000 5000
INSERT INTO pgbench_accounts (aid, abalance, created_on) SELECT :aid, abalance + :delta, now() FROM pgbench_accounts WHERE aid = :aid ORDER BY created_on DESC LIMIT 1;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
--INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment