This stackoverflow answer to a related question gives a better suggestion https://stackoverflow.com/a/6955055/3403369:
Create a separate table mapping integers to unique IDs, and join with this. You can generate that in advance, so can avoid gradually building the index.