tpcc: add PL/pgSQL stored-procedure mode (--stored-procs)#205
Open
akorotkov wants to merge 2 commits into
Open
tpcc: add PL/pgSQL stored-procedure mode (--stored-procs)#205akorotkov wants to merge 2 commits into
akorotkov wants to merge 2 commits into
Conversation
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.
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.