▲ | Sesse__ 4 days ago | |||||||||||||||||||||||||
I'll take a [citation needed] on that one. | ||||||||||||||||||||||||||
▲ | jitl 4 days ago | parent | next [-] | |||||||||||||||||||||||||
https://www.postgresql.org/docs/current/indexes-index-only-s... This is why Postgres b-tree indexes offer CREATE INDEX (indexCol1, indexCol2, ...) INCLUDE (includeCol1, includeCol2, ...). With INCLUDE, the index will directly store the listed additional columns, so if your query does `SELECT includeCol1 WHERE indexCol1 = X AND indexCol2 > Y`, you avoid needing to look up the entire row in the heap, because includeCol1 is stored in the index already. This is called a "covering index" because the index itself covers all the data necessary to answer the query, and you get an "index only scan" in your query plan. The downside to creating covering indexes is that it's more work for Postgres to go update all the INCLUDE values in all your covering indexes at write time, so you are trading write speed for increased read speed. I think it's quite typical to see this in SQL databases. SQLite behaves the same way for indexes; the exception is that if you create a WITHOUT ROWID table, then the table itself is sorted by primary key instead of by ROWID, so you get at most 1 index that maps directly to the row value. (sqlite docs: https://sqlite.org/withoutrowid.html) | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | akorotkov 4 days ago | parent | prev [-] | |||||||||||||||||||||||||
Yep, regular PostgreSQL indexes point to a heap location (block number + offset). And it is the same for primary and secondary indexes. |