Skip to content

Instantly share code, notes, and snippets.

@kmoppel
Created August 4, 2016 15:00
Show Gist options
  • Save kmoppel/3170590c9472baec1dbc4b361b93d1e5 to your computer and use it in GitHub Desktop.
Save kmoppel/3170590c9472baec1dbc4b361b93d1e5 to your computer and use it in GitHub Desktop.
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
BEGIN;
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);
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment