simple.sql 939 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. -- \setrandom aid 1 :naccounts
  2. \set aid random(1, 100000)
  3. -- \setrandom bid 1 :nbranches
  4. \set bid random(1, 100000)
  5. -- \setrandom tid 1 :ntellers
  6. \set tid random(1, 100000)
  7. -- \setrandom delta -5000 5000
  8. \set delta random(-5000,5000)
  9. \set shard random(0, 2)
  10. SET SHARD TO :shard;
  11. SET SERVER ROLE TO 'auto';
  12. BEGIN;
  13. UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
  14. SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
  15. UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
  16. UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
  17. INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
  18. END;
  19. SET SHARDING KEY TO :aid;
  20. -- Read load balancing
  21. SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
  22. SET SERVER ROLE TO 'replica';
  23. -- Read load balancing
  24. SELECT abalance FROM pgbench_accounts WHERE aid = :aid;