Snapshot reporting without blocking writes
SQL
Hard
3 views
Problem Description
You need a consistent report while inserts keep happening in parallel. Start a transaction in REPEATABLE READ and run your report query inside it.
Sample Test Case
Output:
Consistent snapshot
Constraints
Assume PostgreSQL-style interval
Official Solution
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; BEGIN; SELECT COUNT(*) AS order_count, SUM(total_amount) AS total_amount FROM Orders WHERE order_date >= (CURRENT_DATE - INTERVAL '30 days'); COMMIT;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!