Index Basics — Series 3

Preview — 3 of 10 questions

What name does PostgreSQL give an index if you don't specify one, e.g. CREATE INDEX ON users (email);?

AIt errors — an index name is always required
Bemail_index
CA generated name following the pattern <table>_<column>_idx — here, users_email_idx
DA random UUID-based name

Which statement creates a single index covering both last_name and first_name, in that order?

ACREATE INDEX ON people (last_name, first_name);
BCREATE INDEX ON people (last_name), (first_name);
CCREATE INDEX ON people (last_name) AND (first_name);
DCREATE INDEX ON people (last_name); CREATE INDEX ON people (first_name); — two separate statements automatically combine into one composite index

A table has an index on created_at. Does SELECT * FROM events; (no ORDER BY) come back sorted by created_at?

ANot reliably — without an explicit ORDER BY, PostgreSQL is free to return rows in whatever order is convenient for the plan it picks, which may or may not happen to follow an index's order; relying on incidental ordering from a query without ORDER BY is not guaranteed to stay consistent
BYes, always — having any index on a column guarantees results come back in that column's order
COnly if the index was created with the ORDERED option
DOnly if the table has fewer than 1000 rows

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.