Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 

 

 

Oracle Global Temporary Tables


Oracle Database Tips by Donald Burleson

Question:  What are global temporary table and how do they differ fro regular Oracle tables?  Also, please show when to use global temporary tables.

Answer:  Oracle introduced Global Temporary Tables (GTT) starting in Oracle8i for removing complex subqueries and allowing us to materialize the intermediate data that we need to solve a complex problem with SQL.
Global temporary tables are an alternative to using the WITH clause to materialize intermediate query results.

To speed-up global temporary table operations, see my notes on temp_undo_enabled.

Please read these important notes on SQL tuning with global temporary tables:

12c note:  Starting in 12c, Oracle will allow you to invoke session-level dbms_stats to gather statistics specific to your own global temporary table.  Prior to 12c, statistics were shared from a master copy of the CBO statistics.

In addition to data dictionary queries, global temporary tables can dramatically improve the performance of certain SQL self-join queries that summarize data values.

The Elapsed-Time Section of the Date Range Report is a very sophisticated DBA report, and one that can run for many hours without the use of global temporary tables because of Oracle's use of the CARTESIAN access method.

However, with the use of global temporary tables, the table and index counts can be summarized and saved in the temp tables for fast analysis. We also use the same technique to sum the number of bytes in all tables and indexes into temporary tables, and then quickly interrogate the summary tables for total sizes of our database.


You can use the global temporary tables (GTT) syntax to improve the speed of queries that perform complex summarization activities.

We can also use the following query to display all Oracle global temporary tables:

select table_name from all_tables where temporary = 'Y';

Upon close examination, we see that we create global temporary tables to hold the total counts, and we also create two temporary tables to hold the sum of bytes for each table and index. Once the sums are pre-calculated, it becomes fast and easy for Oracle SQL to compute the total bytes for the whole database.

The Oracle database codified this approach starting and Oracle8i with their global temporary tables construct.  Here is an example of using global temporary tables.  Note that the SQL data from the global temporary tables are preserved and passed (as if it was a "real" table) to a subsequent SQL query:

drop table store_sales;
drop table store_cnt;
drop table store_qty;

create global temporary table store_qty
on commit preserve rows
as select sum(quantity) all_sales from sales;

create global temporary table store_cnt
on commit preserve rows
as select count(*) nbr_stores from store;

create global temporary table store_sales
on commit preserve rows
as select store_name, sum(quantity) store_sales
from store natural join sales group by store_name;

select
   store_name,
   store_sales,
   all_sales / nbr_stores avg_sales

from
   store_qty,
   store_cnt,
   store_sales

where
   store_sales > (all_sales / nbr_stores);


 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.


 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.