To estimate the amount of temporary space needed for an entire index build, perform the following steps:
sizeof_sort_item = keysize + 4
sizeof_sort_item =
keysize + 8
temp_bytes = 2 * (rows * sizeof_sort_item)
This formula uses the factor 2 because everything is stored twice when intermediate sort runs use temporary space. Intermediate sort runs occur when not enough memory exists to perform the entire sort in memory.
The value for rows is the total number of rows that you expect to be in the table.