Things you didn't know about indexes

38 points by bugsmith


hongminhee

Used PostgreSQL for years and somehow never bumped into INCLUDE. This was the first explanation that made it click: columns in the index proper affect ordering and have to be maintained on writes; INCLUDE columns are just there to cover the query.

snej

FYI almost all of this is applicable to SQLite too, except

markerz

Databases also keep metadata on how many times an index was used. It is a reasonable maintenance task to go through any index that is older than a few months and delete the ones that are never used. Indices are not free, but it’s often better to make a bunch and then delete the unused ones later than to make an index on a really big table.

eatonphil

I always wanted a way for postgres to warn you if it is not going to be able to do a covering index for a table. I don't know if it's possible or what it would take.