OLTP and OLAP
Overview
Online transaction processing (OLTP) handles operational changes such as placing one order. Online analytical processing (OLAP) answers questions across many records, such as daily paid revenue. A warehouse integrates historical data for analysis; operational and analytical workloads can share an engine but have different access patterns.
First example
SELECT id,cents,status FROM de_order WHERE id=2;Observed SQLite result (rows in JSON):
[ [ 2, 2000, "paid" ]]How it works
An operational system emphasizes transaction integrity and point access; analytical queries scan, group and combine many records. A columnar layout can reduce reading unused columns; this is a storage choice, not a requirement for OLAP. Data lakes hold diverse files, lakehouses add table-management capabilities over lake storage, and data marts serve a subject area. Snapshot facts represent a state at a time; transaction facts represent events. The fixture uses integer cents and paid-order grain. Do not count cancelled orders as revenue.
Practical example
SELECT day,COUNT(*),SUM(cents) FROM de_order WHERE status='paid' GROUP BY day ORDER BY day;Observed SQLite result (rows in JSON):
[ [ 5, 1, 1000 ], [ 12, 2, 5000 ]]Practice and mistakes
Practice: retrieve order 2, then aggregate paid orders by day. Hint: filter status before grouping. Expected day 12 revenue is 5000 cents. Mistake: assuming every OLAP workload needs a separate database or that analytic SQL is always faster.
PostgreSQL 17 example — NOT RUN
SELECT day,SUM(cents) FROM (VALUES(5,1000),(12,2000),(12,3000)) AS f(day,cents) GROUP BY day ORDER BY day;Expected result, not executed: "Rows (5,1000),(12,5000)."