Q1. I have a Global Temp (GT) (ON commit Preserve Rows).
I do lots of processsing (mostly inserts, some updates)
After processing and committing, I trucate a Permanent Table (P) and want to copy GT ->P, say a million rows.
What is the quickest way of achieving that
- Drop P, CTAS P as select from GT
- Some other ?
Q2. Curiosity - there does not seem a compelling reason why TEMP tables should not persist across sessions. In which case I would not need to do the above operation (i.e GT -P). That is, I want to exploit the minimal redo generation aspect of GT but want more persistance. Is that a reasonable demand from Oracle?
thanks
Tom
q1) insert /*+ APPEND */ into P select * from GT;
see
</code>
http://docs.oracle.com/cd/B10501_01/server.920/a96524/c21dlins.htm#11358 <code>
for detalis on that -- it is known as a direct path insert
q2) No, we give you the tools to do minimal redo generation on a permanent table via non-logged bulk operations.
You do understand that even a GTT will generate GOBS of redo when you use UPDATE and DELETE on it (generates MINIMAL with INSERT).
So, against a permanent table you can do many of the things you are asking with bulk operations (CTAS -- doesn't have to be logged, INSERT /*+ APPEND */ -- does not have to be logged, truncate -- no log)
But just remember that with GTTs and permanent tables -- UPDATES and DELETES -- whole lotta logging going on ...
ops$tkyte@ORA920.US.ORACLE.COM> create global temporary table t1
2 on commit preserve rows
3 as
4 select * from all_objects
5 where 1=0;
Table created.
ops$tkyte@ORA920.US.ORACLE.COM>
ops$tkyte@ORA920.US.ORACLE.COM> create table t2
2 as
3 select * from all_objects
4 where 1=0;
Table created.
ops$tkyte@ORA920.US.ORACLE.COM>
ops$tkyte@ORA920.US.ORACLE.COM> set autotrace on statistics
ops$tkyte@ORA920.US.ORACLE.COM>
ops$tkyte@ORA920.US.ORACLE.COM> insert into t1 select * from all_objects;
29303 rows created.
Statistics
----------------------------------------------------------
97 recursive calls
31377 db block gets
138393 consistent gets
0 physical reads
3767208 redo size
789 bytes sent via SQL*Net to client
809 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
29303 rows processed
ops$tkyte@ORA920.US.ORACLE.COM> insert /*+ APPEND */ into t2 select * from all_o bjects;
29303 rows created.
Statistics
----------------------------------------------------------
387 recursive calls
483 db block gets
138450 consistent gets
0 physical reads
3390208 redo size
773 bytes sent via SQL*Net to client
823 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
29303 rows processed
ops$tkyte@ORA920.US.ORACLE.COM> commit;
Commit complete.
ops$tkyte@ORA920.US.ORACLE.COM>
ops$tkyte@ORA920.US.ORACLE.COM> update t1 set object_id = object_id+1;
29303 rows updated.
Statistics
----------------------------------------------------------
0 recursive calls
30079 db block gets
799 consistent gets
0 physical reads
4472720 redo size
789 bytes sent via SQL*Net to client
806 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
29303 rows processed
ops$tkyte@ORA920.US.ORACLE.COM> update t2 set object_id = object_id+1;
29303 rows updated.
Statistics
----------------------------------------------------------
0 recursive calls
29986 db block gets
407 consistent gets
400 physical reads
7171100 redo size
789 bytes sent via SQL*Net to client
806 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
29303 rows processed
ops$tkyte@ORA920.US.ORACLE.COM> commit;
Commit complete.
ops$tkyte@ORA920.US.ORACLE.COM>
ops$tkyte@ORA920.US.ORACLE.COM> delete from t1;
29303 rows deleted.
Statistics
----------------------------------------------------------
128 recursive calls
31547 db block gets
863 consistent gets
0 physical reads
8449052 redo size
790 bytes sent via SQL*Net to client
783 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
29303 rows processed
ops$tkyte@ORA920.US.ORACLE.COM> delete from t2;
29303 rows deleted.
Statistics
----------------------------------------------------------
56 recursive calls
32713 db block gets
810 consistent gets
221 physical reads
10464456 redo size
790 bytes sent via SQL*Net to client
783 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
29303 rows processed
ops$tkyte@ORA920.US.ORACLE.COM> commit;
Commit complete.
ops$tkyte@ORA920.US.ORACLE.COM>
ops$tkyte@ORA920.US.ORACLE.COM> set autotrace off
so no, I would say "not a reasonable 'demand'" as we already supply it for the most part with non-logged operations