Skip to content

tpcc: add PL/pgSQL stored-procedure mode (--stored-procs)#205

Open
akorotkov wants to merge 2 commits into
pingcap:masterfrom
akorotkov:master
Open

tpcc: add PL/pgSQL stored-procedure mode (--stored-procs)#205
akorotkov wants to merge 2 commits into
pingcap:masterfrom
akorotkov:master

Conversation

@akorotkov
Copy link
Copy Markdown

While benchmarking PostgreSQL with TPC-C, one may note that backends might spend most of the time in the ClientRead wait event. That is, PostgreSQL protocol communication spends most of the time preventing us from reaching the core bottlenecks. This PR implements --stored-procs mode (similar to HammerDB's pg_storedprocs), in which a single transaction is appended to a single stored procedure on the PostgreSQL side. This allow us to reach higher performance level and explore PostgreSQL core/storage bottlenecks with TPC-C benchmark.

When --stored-procs is set on `go-tpc tpcc run` (postgres driver only),
each of the five TPC-C transactions is dispatched as a single server-side
CALL: tpcc_new_order / tpcc_payment / tpcc_order_status / tpcc_delivery /
tpcc_stock_level. Procedures are installed via CREATE OR REPLACE on the
first Run() invocation (sync.Once), so the same dataset can be benched
in either mode — no separate prepare step.

NEW_ORDER's 1%-rollback path (sentinel item id of -1) is handled
server-side via an in-band ROLLBACK inside the procedure: the engine
pays for the district/orders/new_order writes and then undoes them,
matching the original Go transaction's behaviour exactly. Other
procedures run their work and return; the autocommit transaction
commits implicitly.
@pingcap-cla-assistant
Copy link
Copy Markdown

pingcap-cla-assistant Bot commented May 12, 2026

CLA assistant check
All committers have signed the CLA.

…caches

The district-specific stock distribution column (s_dist_01..s_dist_10)
was selected via EXECUTE format(...), which forced PL/pgSQL to parse
and plan the SELECT from scratch on every iteration — measurable cost
on the hot NEW_ORDER path (10 stock rows per call).

Switch to a single static SELECT that picks the right column via
CASE p_d_id WHEN N THEN s_dist_NN END. PL/pgSQL caches its plan after
a few executions and pg_stat_statements collapses the 10 district
variants into one entry. Reading all 10 s_dist columns is essentially
free — the stock row is already in cache and locked FOR UPDATE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant