Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword or section
Like this
5Activity
P. 1
SQL Pivot and Prune Queries - Keeping an Eye on Performance

SQL Pivot and Prune Queries - Keeping an Eye on Performance

Ratings: (0)|Views: 772 |Likes:
Published by Brendan Furey
It is a very common requirement in SQL to join two record sets where there is a one to many relationship between the two sets, but where the cardinality of the result set is the same as that of the set on the 'one' side. The obvious case is for standard grouping and aggregation querying, such as simply counting the number of records in the 'many' set for each record in the 'one' set. There are also some slightly less obvious cases where there may be various SQL techniques available, with varying performance and complexity characteristics. This article looks at two such cases: the first where one wishes to join multiple subtypes of a given entity – this is generally referred to as ‘pivoting’ from rows to columns; and the second where one wishes to join just one record from the 'many' set, but does not have a pure join condition to identify the record and so must use an ordering condition instead – I will call this ‘pruning’.

This work attempts to find the best SQL techniques for such queries in Oracle 11g, mainly in terms of performance. It does this by running a variety of queries within the context of an outbound interface against a deliberately simple data model across a two-dimensional range of data sizes. A simple generic PL/SQL package has been written to perform the testing efficiently, and it uses a previously described (REF-4) object type for timing. Visio diagrams are provided for query structures, based on a similar approach previously described (REF-3), and Microsoft Excel graphs are used to display comparative performances. The results reveal some interesting features of the behaviour of the Cost Based Optimiser in Oracle 11g.

I have applied the same domain-based approach to performance analysis in a subsequent article, ‘Forming Range-Based Break Groups with Advanced SQL'.
It is a very common requirement in SQL to join two record sets where there is a one to many relationship between the two sets, but where the cardinality of the result set is the same as that of the set on the 'one' side. The obvious case is for standard grouping and aggregation querying, such as simply counting the number of records in the 'many' set for each record in the 'one' set. There are also some slightly less obvious cases where there may be various SQL techniques available, with varying performance and complexity characteristics. This article looks at two such cases: the first where one wishes to join multiple subtypes of a given entity – this is generally referred to as ‘pivoting’ from rows to columns; and the second where one wishes to join just one record from the 'many' set, but does not have a pure join condition to identify the record and so must use an ordering condition instead – I will call this ‘pruning’.

This work attempts to find the best SQL techniques for such queries in Oracle 11g, mainly in terms of performance. It does this by running a variety of queries within the context of an outbound interface against a deliberately simple data model across a two-dimensional range of data sizes. A simple generic PL/SQL package has been written to perform the testing efficiently, and it uses a previously described (REF-4) object type for timing. Visio diagrams are provided for query structures, based on a similar approach previously described (REF-3), and Microsoft Excel graphs are used to display comparative performances. The results reveal some interesting features of the behaviour of the Cost Based Optimiser in Oracle 11g.

I have applied the same domain-based approach to performance analysis in a subsequent article, ‘Forming Range-Based Break Groups with Advanced SQL'.

More info:

Published by: Brendan Furey on May 02, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

09/26/2012

pdf

text

original

 
SQL P
IVOT
 
 AND
P
RUNE
Q
UERIES
- K
EEPING
 
 AN
E
YE
 
ON
P
ERFORMANCE
 Author:Brendan FureyCreation Date:2 May 2011Version:1.3Last Updated:25 September 2012
110516346.doc.Page 1 of 52
 
Table of Contents
110516346.docPage 2 of 52
 
Change Record
 
DateAuthorVersionChange Reference
02-May-2011BPF1.0Initial03-May-2011BPF1.1Typos and references20-Jun-2011BPF1.2More typos and reference to new article25-Sep-2011BPF1.3References now hyperlinks, and minor tidying
110516346.docPage 3 of 52

Activity (5)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
TEJASKO liked this
TEJASKO liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->