Starting to write the index_secondary_by_primary function.