Abstract

A consistent query-result cache for PostgreSQL copies the rows each registered query needs from an origin database into a cache database and keeps the copy current by applying the origin's logical replication stream one source transaction at a time. For aggregate queries it also keeps a second derived tier: a materialized result holding the query's group rows, served to clients as the answer to the original SQL. This disclosure describes maintaining the group rows in place from the same framed change stream that maintains the base-row copy. Each row change in a source transaction is classified, against the aggregate's predicate and read columns and using the pre- and post-images carried by the stream or the cached pre-image, as skipped, entering, leaving or staying; the resulting per-group deltas (count, sum, average as a sum and count pair, minimum and maximum with a per-group recompute from the cached base rows when the extremal value leaves) are applied in the same cache-database transaction as the base-row changes, so no client observes a halfapplied transaction. A change that cannot be classified marks the result dirty for rebuild. A result built from the copy at commit position S applies only deltas of transactions after S, which the stream's commit positions make decidable.

Creative Commons License

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 License.

Share

COinS