aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks/bank/bank.aup
blob: acc7938b0425672db30cccb186474b92ad8738d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# A bank as pgbench's TPC-B-like transaction: accounts, tellers and branches,
# each a list kept in key order, and a history of every transfer. A transfer
# moves a teller's delta into an account, the teller and its branch, and
# records it, all in one event: one transaction over four tables.
record Account {
  aid = 0
  bid = 0
  balance = 0
  filler: text
}
record Teller {
  tid = 0
  bid = 0
  balance = 0
}
record Branch {
  bid = 0
  balance = 0
}
record Transfer {
  tid = 0
  bid = 0
  aid = 0
  delta = 0
  at = 0
}

state accounts: list of Account by aid
state tellers: list of Teller by tid
state branches: list of Branch by bid
state history: list of Transfer

input branch = message {
  bid: u32
}
input teller = message {
  tid: u32
  bid: u32
}
input account = message {
  aid: u32
  bid: u32
}
input transfer = message {
  aid: u32
  tid: u32
  bid: u32
  delta: number
}

on branch { branches.add(Branch { bid: branch.bid }) }
on teller { tellers.add(Teller { tid: teller.tid, bid: teller.bid }) }
on account { accounts.add(Account { aid: account.aid, bid: account.bid, filler: "" }) }

on transfer {
  accounts[transfer.aid].balance = accounts[transfer.aid].balance + transfer.delta
  tellers[transfer.tid].balance = tellers[transfer.tid].balance + transfer.delta
  branches[transfer.bid].balance = branches[transfer.bid].balance + transfer.delta
  history.append(Transfer { tid: transfer.tid, bid: transfer.bid, aid: transfer.aid, delta: transfer.delta, at: now })
}

view accounts_count = accounts.count
view history_count = history.count
view total = sum(b.balance for b in branches)