educative.io

Educative

Indexing (PhotoID,CreationTime)

I am still learning about indexing; however, I think the concept of indexing works as the following: DB is indexed on some non-PK column. That set of data is then copied into a separate data structure and sorted via the natural ordering of that data type. That sorted data can then be searched which is mapped to PK’s of the desired record, correct? If this is the case, why would one want to include an index on the PK aka PhotoID?

e.g.
CreationTime1 -> PKa
CreationTime2 -> PKb
.
.
.
CreationTimeN -> PKn

Our indexing provides the mapping to our PhotoID; therefore, we don’t need to index PhotoID. Maybe the docs are just stating that this mapping is the result of indexing on CreationTime?

Hi @Joseph_Fernandez
The indexing will be created in such a way that it has the timestamp part in the index itself. So if we need to fetch a set of photos which were created say after a timetamp T in the past, we can easily query based on the index itself, and that itself will be fast because index already has timestamp values