Chapter 9Cache Complex Queries Using Materialized Views

When we need to query data stored in several tables, there is a trade-off. Either we keep our code simple by using Active Record—which makes several queries to the database—or we make our code more complex by using a single, efficient query specific to our needs. Performance is an issue in both cases because we’re pulling back a lot of data. Postgres solves this dilemma with its materialized views feature, which provides clean code, accesses data with a single query, and exhibits high performance.

In this chapter, we’ll continue to build on our running example where we display a customer’s details. To do this, we need to fetch data from five different tables. We’ll see how the idiomatic ...

Get Rails, Angular, Postgres, and Bootstrap now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.