Is it safe to put an index on an Oracle Temporary Table?

前端 未结 6 2311
闹比i
闹比i 2021-02-19 22:41

I have read that one should not analyze a temp table, as it screws up the table statistics for others. What about an index? If I put an index on the table for the duration of

6条回答
  •  迷失自我
    2021-02-19 23:23

    Does an index effect my process, and all other processes using the table? or Does it effect my process alone?

    I'm assuming we are talking of GLOBAL TEMPORARY tables.

    Think of a temporary table as of multiple tables that are created and dropped by each process on the fly from a template stored in the system dictionary.

    In Oracle, DML of a temporary table affects all processes, while data contained in the table will affect only one process that uses them.

    Data in a temporary table is visible only inside the session scope. It uses TEMPORARY TABLESPACE to store both data and possible indexes.

    DML for a temporary table (i. e. its layout, including column names and indexes) is visible to everybody with sufficient privileges.

    This means that existence of the index will affect your process as well as other processes using the table in sense that any process that modifies data in the temporary table will also have to modify the index.

    Data contained in the table (and in the index too), on the contrary, will affect only the process that created them, and will not even be visible to other processes.

    IF you want one process to use the index and another one not to use it, do the following:

    • Create two temporary tables with same column layout
    • Index on one of them
    • Use indexed or non-indexed table depending on the process

提交回复
热议问题