Question
Why should a URL shortener maintain an index or primary key on the short_code column?
A
To make redirect lookup fast and enforce uniqueness
B
To automatically compress long URLs
C
To remove the need for cache invalidation
D
To select the HTTP status code
Explanation
It enables fast lookup of the original URL during redirects and enforces uniqueness if used as a primary key.
Redirect requests are served by looking up the short_code. Without an index, the database may need to scan many rows, which becomes slow at large scale. An index or primary key on short_code enables efficient lookup and can also enforce uniqueness, which is critical because each short code must map to exactly one long URL.