Recall & Review
beginner
What is an expression index in PostgreSQL?
An expression index is an index built on the result of an expression or function applied to one or more columns, not just on the raw column values.
Click to reveal answer
beginner
Why use an expression index instead of a regular index?
Expression indexes speed up queries that filter or sort based on computed values, like lowercased text or date parts, which regular indexes on raw columns cannot optimize.
Click to reveal answer
intermediate
How do you create an expression index on the lower case of a column named 'name'?
Use: CREATE INDEX idx_lower_name ON table_name (LOWER(name)); This creates an index on the lowercased values of 'name'.
Click to reveal answer
intermediate
Can expression indexes be used with WHERE clauses?
Yes, you can create partial expression indexes by adding a WHERE clause to index only rows meeting certain conditions, improving performance and saving space.
Click to reveal answer
advanced
What happens if you query without using the exact expression in the WHERE clause that matches the expression index?
PostgreSQL cannot use the expression index if the query's expression does not exactly match the index expression, so the index won't speed up that query.
Click to reveal answer
What does an expression index in PostgreSQL index?
✗ Incorrect
Expression indexes store the result of an expression or function applied to columns, not just raw column data.
Which SQL command creates an expression index on the lower case of column 'email'?
✗ Incorrect
The correct syntax applies LOWER() to the column inside the index definition.
Can expression indexes improve performance for queries filtering by a computed value?
✗ Incorrect
Expression indexes optimize queries filtering or sorting by the computed expression.
What is a partial expression index?
✗ Incorrect
Partial expression indexes index only rows that meet the WHERE condition.
If a query uses a different expression than the one in the expression index, what happens?
✗ Incorrect
The query must use the exact expression for PostgreSQL to use the expression index.
Explain what an expression index is and give a simple example of when you would use one.
Think about indexing computed values instead of raw columns.
You got /3 concepts.
Describe how partial expression indexes work and why they might be useful.
Consider indexing only some rows based on a condition.
You got /3 concepts.