Hacker News new | ask | show | jobs
by ConnorTsui20 14 days ago
We generally refer to an index that holds the data it indexes at its leaves a "clustered index". But this only means that the tuples are organized according to the ordering of the index: you still generally store the entire record (all columns/attributes) together.

For example, if I cluster on my sorted primary key, that just means that the index can jump to the tuple with the correct primary key quickly (log time), but you will still end up reading* the entire tuple in the same way I explain in the blog. And if you only store a record ID that points to the other fields instead of the entire tuple at the leaves of the index, then that wouldn't be considered a clustered index.

I will note, however, that DBMSs should be smart enough to know that an aggregation on only an indexed column does not need to fetch the rest of the columns, only the data at the leaves of the index.

3 comments

Parent was talking about covering indexes not clustered indexes. Postgresql doesn't have true clustered indexes, table is always heap and indexes are always separate.

A clustered index the table itself is an index and organized as such.

A covering index is separate from the table but contains all fields necessary for the result so the base table need not be accessed.

Ye, this is what confused me about the post as it talks about Postgres, but contradicts the postgres docs :/
Oh wow I didn't know about covering indexes, TIL!
What would be nice is a standard way of marking columns as 'to be stored in indices only' and not in the main table. Add that to SQL and an RDBMS should have a much easier time doing the right thing.