Bird
0
0

Given a materialized view mv_orders with an index on order_date, what will be the output of this query?

medium📝 query result Q13 of 15
PostgreSQL - Views and Materialized Views
Given a materialized view mv_orders with an index on order_date, what will be the output of this query?

SELECT order_date FROM mv_orders WHERE order_date = '2023-01-01';

Assuming the materialized view is refreshed and contains data for that date.
AReturns all rows with order_date '2023-01-01' quickly using the index
BReturns an error because indexes cannot be used on materialized views
CReturns no rows because materialized views do not store data
DReturns all rows but ignores the index, causing slow performance
Step-by-Step Solution
Solution:
  1. Step 1: Understand index usage on materialized views

    Indexes on materialized views speed up queries by quickly locating matching rows.
  2. Step 2: Analyze the query behavior

    The query filters by order_date, which is indexed, so it returns matching rows efficiently.
  3. Final Answer:

    Returns all rows with order_date '2023-01-01' quickly using the index -> Option A
  4. Quick Check:

    Indexed query = fast matching rows [OK]
Quick Trick: Indexed columns speed up matching queries on materialized views [OK]
Common Mistakes:
  • Thinking indexes don't work on materialized views
  • Assuming materialized views are empty without refresh
  • Believing query ignores indexes always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes