Complete the code to select all columns from the table using an index scan.
SELECT * FROM users WHERE [1] = 'active';
The status column is used in the WHERE clause to filter rows. If an index exists on status, PostgreSQL can use an index scan to quickly find rows where status is 'active'.
Complete the code to create an index that supports index-only scans on the 'status' column.
CREATE INDEX idx_users_[1] ON users([2]);
Creating an index on the status column allows PostgreSQL to perform index-only scans when queries filter by status.
Fix the error in the query to enable an index-only scan by selecting only indexed columns.
SELECT [1] FROM users WHERE status = 'active';
Index-only scans work when the query selects only columns present in the index. Selecting id (assuming it is indexed) allows the scan to avoid accessing the table.
Fill both blanks to create a covering index that supports index-only scans for queries filtering by 'status' and selecting 'email'.
CREATE INDEX idx_users_[1] ON users(status, [2]);
A multi-column index on status and email allows index-only scans for queries filtering by status and selecting email.
Fill all three blanks to write a query that uses an index-only scan by selecting only indexed columns and filtering by 'status'.
SELECT [1], [2] FROM users WHERE [3] = 'active';
Selecting id and email columns and filtering by status (all indexed) enables an index-only scan, avoiding table access.