Let be a finite, ordered alphabet, and consider a string x = x1x2 . . . xn n . A secondary index for x answers alphabet range queries of the form: Given a range [al, ar] , return the set I[al;ar] = {i | xi [al; ar]}. Secondary indexes are heavily used in relational databases and scientific data analysis. It is well-known that the obvious solution, storing a dictionary for the set i{xi} with a position set associated with each character, does not always give optimal query time. In this paper we give the first theoretically optimal data structure for the secondary indexing problem. In the I/O model, the amount of data read when answering a query is within a constant factor of the minimum space needed to represent the set I[al;ar], assuming that the size of internal memory is (|| lg n) blocks, for some constant > 0. The space usage of the data structure is O(n lg ||) bits in the worst case, and we further show how to bound the size of the data structure in terms of the 0th order ...