_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

Materialized Views — předpočítané pohledy

19. 06. 2025 1 min read intermediate

Architecture Intermediate

Materialized Views — předpočítané pohledy

Materialized ViewsPerformanceCQRS 3 min read

Materialized views pro výkon čtení. PostgreSQL a event-driven aktualizace.

PostgreSQL

CREATE MATERIALIZED VIEW order_summary AS
SELECT c.id, c.name, COUNT(o.id) as orders, SUM(o.total) as total
FROM customers c LEFT JOIN orders o ON c.id = o.customer_id
GROUP BY c.id, c.name;

CREATE UNIQUE INDEX idx_os_cust ON order_summary(id);
REFRESH MATERIALIZED VIEW CONCURRENTLY order_summary;

Event-Driven

eventBus.on('OrderCreated', async (e) => {
    await db.query(\`
        INSERT INTO order_summary (customer_id, orders, total)
        VALUES ($1, 1, $2)
        ON CONFLICT (customer_id) DO UPDATE SET
            orders = order_summary.orders + 1,
            total = order_summary.total + $2
    \`, [e.customerId, e.total]);
});

Summary

Materialized views = zásadní optimalizace čtení. Zvažte freshness vs performance trade-off.

Need Help with Implementation?

Our team has experience designing and implementing modern architectures. We’re happy to help.

Free Consultation

Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.