PLAIN/TEXT — ISSUE 181/456 COMPUTER SCIENCE · FOUNDATION / DATA / SAVED RESULTS · ~4 MIN READING DATE: 2027-03-31 ARCHIVE: https://plaintext.click/newsletter/ SUBJECT: Why a fast dashboard may be answering an old question Why a fast dashboard may be answering an old question ===================================================== / START HERE A shop dashboard can show yesterday’s total without adding every receipt again each time you open it. A query is an instruction asking a data store for selected or calculated information. A materialized view is the stored result of a query, kept for later reading. Reading the saved result can be quick, but it reflects the source data used when that result was last updated. / WHY NOW A dashboard’s speed and freshness are separate properties. The total can be perfectly calculated and still omit a sale that arrived after the last refresh. / THE IDEA An ordinary view stores a query definition and normally obtains its result from the underlying data when used. A materialized view stores the calculated rows as well. A query that groups millions of receipts by day can therefore pay that calculation cost during a refresh instead of on every dashboard request. The system needs a refresh policy: rebuild periodically, update incrementally where supported, or refresh on demand. PostgreSQL’s basic materialized-view refresh reruns the defining query. The saved answer remains useful only if its freshness meets the user’s purpose and its update process is working. / THE FORMAL IDEA saved_total = SUM(amount) over rows visible at refresh - SUM adds the amount values in the selected records. saved_total is the persisted result; refresh is the operation that recalculates it from source data. - The word visible matters because a refresh reads a database view of the data according to its visibility rules. It cannot include a sale that does not yet exist in that view. / RUN THE TINY EXAMPLE Change one thing. Predict what happens. At refresh time, receipts are £4, £6 and £5: saved_total = £15. A new £3 receipt arrives. A direct current sum is £18, but the saved result remains £15. Change only whether a new refresh has completed after that receipt became visible. After refresh, saved_total = 4 + 6 + 5 + 3 = £18. The missing three pounds was a timing difference, not an arithmetic error. Showing the last successful refresh time helps readers interpret the number. A schedule that merely attempted a refresh is less informative than knowing which refresh actually finished. / SO WHAT? The trade-off can suit repeated, expensive questions whose answers may be slightly old, such as a daily trend chart. It is less appropriate when accepting an order requires current stock. Start with the acceptable answer age, then choose how often to pay the calculation cost. / ONE CAVEAT Refreshing has its own processing, storage and locking costs, and different databases support different incremental and concurrent options. A saved result can also depend on a flawed source query; materializing it makes that answer faster, not more correct. Treat freshness requirements as part of the interface contract. / KEEP THIS Saving a query result moves work from every read to the update process, so its speed advantage must be paired with an explicit freshness guarantee. / SOURCE TRAIL [1] PostgreSQL — Materialized views and refresh behaviour https://www.postgresql.org/docs/18/rules-materializedviews.html NEXT: Is electricity an amount or a flow? --- HARD IDEAS. PLAIN TEXT. You are receiving this because you asked for one clear computer-science or physics idea each day. Unsubscribe: https://plaintext.click/unsubscribe View in browser: https://plaintext.click/newsletter/2027/03/2027-03-31-materialized-views.html From: Plain/Text / Brickston Consulting · 30 N Gould St Ste N, Sheridan, WY 82801 US · knowledge@plaintext.click