CREATE TEMPORARY TABLESPACE ts_tmp
TEMPFILE 'E:\temp01.dbf' SIZE 10000M
REUSE AUTOEXTEND ON EXTENT MANAGEMENT LOCAL;
This creates a temporary tablespace (an area on disk where the intermediate sort results will be stored). An index is a sorted set of data, and sorting needs lots of space.
"Temporary" here means that the data that is stored is temporary by nature, not that the tablespace itself is temporary. Think of it like of /tmp directory in Unix or %TEMP% folded in Windows : the directory / folder itself is permanent, but the data stored within it are temporary.
REUSE means do not fail if the file already exists (usually used when the filename points to a raw device, like unformatted disk partition, to avoid OS file management overhead). Instead, it will just open the file for writing and fill it with the new data. If not for this clause, the command would fail if the file with the given name existed.
AUTOEXTEND ON means "grow the file if required". If you set it to off and 10Gb will be not enough for the sorting operation, the tablespace will not automatically grow, and the operation will fail.
EXTENT MANAGEMENT LOCAL means that the tablespace layout is stored in the tablespace itself (not in the system tables). Not sure about 11g, but in previous versions of Oracle this option was not available for temporary tablespaces.
ALTER USER me TEMPORARY TABLESPACE ts_tmp;
This makes the user me to use the newly created temp tablespace as a temporary storage medium
CREATE UNIQUE INDEX big_table_idx ON big_table ( record_id );
This just creates the index.
DROP TABLESPACE ts_tmp;
This drops the temporary tablespace.
Before running the script, figure out the current default tablespace:
SELECT temporary_tablespace
FROM dba_users
WHERE username = 'ME'
Most probably, it will return TEMP.
Before dropping ts_tmp, revert the default temp tablespace for the user:
ALTER USER me TEMPORARY TABLESPACE temp; -- or whatever the previous query returned.