Anda di halaman 1dari 50

V6R1: SQL Grouping Functions Multidimensional Results at the click of a Query DB2 for IBM i

Tom McKinley (mac2@us.ibm.com) IBM Systems and Technology Group Lab Services

2010 IBM Corporation

IBM Power Systems

Whats in a name?
Industry refers to Grouping Sets and Super Groups (Rollup and Cube) collectively as Grouping Sets

Grouping Sets and Super Groups are sometimes referred to as Analytical SQL Grouping Functions

For clarity, this presentation will use the term Grouping Functions when collectively describing Grouping Sets, Rollups, and Cubes

2010 IBM Corporation

IBM Power Systems

SQL Group By: Specifies that an SQL Select statement returns rows grouped by one or more columns
EXAMPLE: For each quarter in 2006, show me the

total number of widgets that were sold?


SELECT Qtr, SUM(Units) FROM Orders WHERE Year = 2006 and Part = Widget GROUP BY Qtr

2010 IBM Corporation

IBM Power Systems

Hash Table Grouping


Part Units Year Qtr
Input: Join or Group By value Output: Hash value The same input value will always result in the same hash value

Widget Cog Widget Widget Flange Dome Widget Widget Flange

7 19 83 1 14 3 30 680 110

2006 2006 2006 2007 2005 2005 2006 2005 2007

4 2 4 3 3 4 4 1 4

Qtr, Units

Only relevant information is stored and the data is in no particular order

Aggregate on units for each group of quarters

Selection can be performed using any method available, including parallel enabled methods

Qtr1

Qtr2

Qtr3

Qtr4

Collect all common input values into a common bucket (by hash value)
4 2010 IBM Corporation

IBM Power Systems

Radix Index Grouping


Part Year Qtr

Cog Dome Flange Flange Widget Widget Widget Widget Widget

2006 2005 2005 2007 2005 2006 2006 2006 2007

2 4 3 4 1 4 4 4 3
Use RRNs to access the table rows to gather the units information

Aggregate on units for each group of quarters

Part

Units

Year

Qtr

Widget Cog Widget Widget

7 19 83 1 14 3 30 680 110

2006 2006 2006 2007 2005 2005 2006 2005 2007

4 2 4 3 3 4 4 1 4

RRNs

Flange Dome Widget Widget Flange

Given an index on Part, Year, Qtr, Apply local selection, and gather RRNs for each group of Quarters

2010 IBM Corporation

IBM Power Systems

Grouping Functions Roadmap

Grouping Sets and Super Groups Defined Grouping Functions Syntax and Examples Grouping Functions Performance Considerations and Examples

2010 IBM Corporation

IBM Power Systems

Grouping Sets and Super Groups Defined

2010 IBM Corporation

IBM Power Systems

Grouping Sets and Super Groups (ROLLUP and CUBE)


Many BI applications involve hierarchical, multi-dimensional aggregate view of the data. Current group by support permits grouping/aggregation data along one dimension
SELECT COUNTRY, REGION, STORE, PRODUCT, SUM(SALES), COUNT(*) FROM TRANS GROUP BY COUNTRY, REGION, STORE, PRODUCT

Users naturally view this data in multiple ways


e.g. Roll result up to aggregate on the country and region (group by country, region) and then to the overall total (no group by clause, whole table aggregation).

User may also want a different perspective


e.g. group by region, product.

Currently, all these different viewings require different succinct queries.

2010 IBM Corporation

IBM Power Systems

Grouping Sets and Super Groups


Grouping Sets and Super Groups allow a user to group and aggregate data in multiple ways in one query.
4 new keywords enable new Grouping Functions support
GROUPING SETS ROLLUP CUBE GROUPING Aggregate Function

Syntax dictates whether multiple sets in a query act in an additive or multiplicative fashion

2010 IBM Corporation

IBM Power Systems

Grouping Functions Syntax and Examples

10

2010 IBM Corporation

IBM Power Systems

Grouping Sets Example


Total sales grouped by (country, region) and by (country, store) SELECT COUNTRY, REGION, STORE, SUM(SALES) FROM TRANS GROUP BY GROUPING SETS ((COUNTRY, REGION), (COUNTRY, STORE)) Logical Equivalent SQL UNION syntax: SELECT * FROM (SELECT COUNTRY, REGION, NULL, SUM(SALES) FROM TRANS GROUP BY COUNTRY, REGION, NULL UNION ALL SELECT COUNTRY, NULL, STORE, SUM(SALES) FROM TRANS GROUP BY COUNTRY, NULL, STORE)
11 2010 IBM Corporation

IBM Power Systems

Grouping Sets Example


SELECT COUNTRY, REGION, NULL, SUM(SALES) FROM TRANS GROUP BY COUNTRY, REGION, NULL

SELECT COUNTRY, REGION, STORE, SUM(SALES) FROM TRANS GROUP BY GROUPING SETS ((COUNTRY, REGION), (COUNTRY, STORE))

Country Canada U.S.A. U.S.A. U.S.A. U.S.A. Canada U.S.A. U.S.A.

Region NW NE NW SE SW -

Store Bobs Barbs Caining Menes Mills Pensk Shell Targe Toms Wally

Sum(Sales) 100,000 450,000


Store 940,000 is NULL even if Store is Not Null 550,000 Capable!

1,310,000 100,000 350,000 770,000 400,000 500,000 300,000 200,000 140,000 440,000 150,000
2010 IBM Corporation

SELECT COUNTRY, NULL, STORE, SUM(SALES) FROM TRANS GROUP BY COUNTRY, NULL, STORE

U.S.A. U.S.A. U.S.A. U.S.A. U.S.A. U.S.A. U.S.A.

12

IBM Power Systems

Rollup Example
The ROLLUP operation generates a result set showing aggregates for a hierarchy of values in the selected columns

SELECT COUNTRY, REGION, SUM(SALES) FROM TRANS GROUP BY ROLLUP (COUNTRY, REGION) Logical equivalent SQL UNION syntax:
SELECT * FROM (SELECT COUNTRY, REGION, SUM(SALES) FROM TRANS GROUP BY COUNTRY, REGION UNION ALL SELECT COUNTRY, NULL, SUM(SALES) FROM TRANS GROUP BY COUNTRY, NULL UNION ALL SELECT NULL, NULL, SUM(SALES) FROM TRANS)
13 2010 IBM Corporation

IBM Power Systems

Rollup Example
SELECT NULL, NULL, SUM(SALES) FROM TRANS SELECT COUNTRY, NULL, SUM(SALES) FROM TRANS GROUP BY COUNTRY, NULL Country Canada U.S.A. Canada U.S.A. SELECT COUNTRY, REGION, SUM(SALES) FROM TRANS GROUP BY COUNTRY, REGION U.S.A. U.S.A. U.S.A.

SELECT COUNTRY, REGION, SUM(SALES) FROM TRANS GROUP BY ROLLUP (COUNTRY, REGION)

Region NW NE NW SE SW

Sum(Sales) 3,350,000 100,000 3,250,000 100,000 450,000 940,000 550,000 1,310,000

Question: Is this data ordered?


14 2010 IBM Corporation

IBM Power Systems

Ordered Rollup Example


The ROLLUP operation generates a result set showing aggregates for a hierarchy of values in the selected columns

SELECT COUNTRY, REGION, SUM(SALES) FROM TRANS GROUP BY ROLLUP (COUNTRY, REGION) ORDER BY 1 ASC, 2 ASC

15

2010 IBM Corporation

IBM Power Systems

Ordered Rollup Example

SELECT COUNTRY, REGION, SUM(SALES) FROM TRANS GROUP BY ROLLUP (COUNTRY, REGION) ORDER BY 1 ASC, 2 ASC

Country Canada Canada U.S.A. U.S.A. U.S.A. U.S.A.

Region NW NE NW SE SW

Sum(Sales) 100,000 100,000 450,000 940,000 550,000 1,310,000

U.S.A. -

3,250,000 3,350,000

16

2010 IBM Corporation

IBM Power Systems

Ordered Rollup Example

SELECT COUNTRY, REGION, SUM(SALES) FROM TRANS GROUP BY ROLLUP (COUNTRY, REGION) ORDER BY 1 ASC, 2 ASC

Country Canada Canada U.S.A. U.S.A. U.S.A. U.S.A. U.S.A. -

Region NW NE NW SE SW -

Sum(Sales) 100,000 100,000 3,250,000 450,000 940,000 550,000 1,310,000 3,350,000

17

2010 IBM Corporation

IBM Power Systems

Cube Example
The CUBE operation is a shorthand way to specify grouping over every possible dimension out of a given set of grouping columns

SELECT COUNTRY, REGION, SUM(SALES) from TRANS GROUP BY CUBE (COUNTRY, REGION)
Is equivalent to the following Grouping Sets syntax:

SELECT COUNTRY, REGION, SUM(SALES) FROM TRANS GROUP BY GROUPING SETS ((COUNTRY, REGION), (COUNTRY), (REGION), ())
18 2010 IBM Corporation

IBM Power Systems

Cube Example
SELECT COUNTRY, REGION, SUM(SALES) from TRANS GROUP BY CUBE (COUNTRY, REGION) Logical equivalent SQL UNION syntax:
SELECT * FROM (SELECT COUNTRY, REGION, SUM(SALES) FROM TRANS GROUP BY COUNTRY, REGION UNION ALL SELECT COUNTRY, NULL, SUM(SALES) FROM TRANS GROUP BY COUNTRY, NULL UNION ALL SELECT NULL, REGION, SUM(SALES) FROM TRANS GROUP BY NULL, REGION UNION ALL SELECT NULL, NULL, SUM(SALES) FROM TRANS)
19 2010 IBM Corporation

IBM Power Systems

Cube Example
Country
SELECT NULL, REGION, SUM(SALES) FROM TRANS GROUP BY NULL, REGION SELECT COUNTRY, NULL, SUM(SALES) FROM TRANS GROUP BY COUNTRY, NULL SELECT COUNTRY, REGION, SUM(SALES) FROM TRANS GROUP BY COUNTRY, REGION
Canada U.S.A. Canada U.S.A. U.S.A. U.S.A. U.S.A.

SELECT COUNTRY, REGION, SUM(SALES) from TRANS GROUP BY CUBE (COUNTRY, REGION)

Region
NE NW SE SW NW NE NW SE SW

Sum(Sales)
450000 1040000 550000 1310000 3350000 100000 3250000 100000 450000 940000 550000 1310000

SELECT NULL, NULL, SUM(SALES) FROM TRANS

20

2010 IBM Corporation

IBM Power Systems

GROUPING Aggregate function


GROUPING Aggregate function helps to differentiate between a grouping function over columns containing NULL values and a group where a column is set to NULL because it is not represented. Aggregate function produces a 0 if column is part of the grouping function Aggregate function produces a 1 if column is set to NULL because it is not represented Example:
SELECT A, B, GROUPING(B), SUM(D) FROM T1 GROUP BY ROLLUP (A, B)
ROLLUP(AB) = (A,B), (A,-), (-,-)

GROUPING(B) returns a value of 0 for group 1: (A,B) GROUPING(B) returns a value of 1 for groups 2 and 3: (A,-),(-.-) Helps to differentiate between group 1 result set where B is NULL and result sets of groups 2 & 3

21

2010 IBM Corporation

IBM Power Systems

Multiplicative vs. Additive


CUBE and ROLLUP can appear as part of a GROUP BY or GROUPING SETS list When CUBE and ROLLUP expressions are combined in one set, they operate like multipliers, forming additional set entries according to the definition of CUBE, ROLLUP When the CUBE or ROLLUP are separate sets, they operate in an additive fashion The use of parenthesis and the GROUPING SETS vs. GROUP BY clause will dictate how CUBE and ROLLUP expressions interact with each other

22

2010 IBM Corporation

IBM Power Systems

Multiplicative vs. Additive Examples


EXAMPLE 1: GROUP BY GROUPING SETS ((A, B, C, D), (A, B, C), (A, B))
Additive grouping sets. GROUPING SETS without ROLLUP or CUBE are always additive. The parenthesis in BLUE are required

EXAMPLE 2: GROUP BY GROUPING SETS (CUBE(A,B), ROLLUP(C,D), E)

GROUPING SETS clause used in both. One set of parenthesis around all sets specifies an additive association. Parenthesizing each set individually also specifies an additive association GROUPING SETS clause with single parenthesis is Additive CUBE(A,B) expands to GROUPING SETS ((A,B), (A), (B), ()) ROLLUP(C,D) expands to GROUPING SETS ((C,D), (C), ()) GROUP BY occurs in an additive fashion to form: GROUPING SETS ((A, B), (A), (B), (), (C, D), (C), (), (E))

23

2010 IBM Corporation

IBM Power Systems

Multiplicative vs. Additive Examples


EXAMPLE 3: GROUP BY A, B, ROLLUP(C,D) Or GROUP BY GROUPING SETS ((A, B, ROLLUP(C,D)))
Parenthesis in BLUE specifies that those elements are multiplicative in nature if a ROLLUP or CUBE exists. GROUPING SETS clause with double parenthesis is multiplicative GROUP BY clause with ROLLUP or CUBE is multiplicative ROLLUP(C,D) expands to GROUPING SETS ((C,D), (C), ()) GROUP BY occurs in a multiplicative fashion to form: GROUP BY GROUPING SETS ((a, b, c, d), (a, b, c), (a, b))

24

2010 IBM Corporation

IBM Power Systems

Multiplicative vs. Additive Examples


EXAMPLE 4: GROUP BY CUBE(A, B), ROLLUP(C, D), E OR GROUP BY GROUPING SETS ((CUBE(A,B), ROLLUP(C,D), E))
Parenthesis in BLUE specifies that those elements are multiplicative in nature if a ROLLUP or CUBE exists CUBE(A,B) expands to GROUPING SETS ((A,B), (A), (B), ()) ROLLUP(C,D) expands to GROUPING SETS ((C,D), (C), ()) GROUP BY occurs in a multiplicative fashion to form: GROUPING SETS ((A, B C, D, E), (A, B, C, E), (A, B, E), (A, C, D, E), (A, C, E), (A, E), (B, C, D, E), (B, C, E), (B, E), (C, D, E), (C, E), (E))

25

2010 IBM Corporation

IBM Power Systems

Grouping Functions Performance Tuning

26

2010 IBM Corporation

IBM Power Systems

Performance Tuning Opportunities


Sound Indexing & Statistics Strategy (ibm.com/servers/enable/site/education/ibo/record.html?indxng)

Sorted Aggregate Hash Table Creates

Create Radix Indexes for common Grouping Set and ROLLUP sets Run Visual Explain to view query rewrites Use Index Advised to find holes in indexing strategy and temporary index creates Could be replaced by a permanent index if index encapsulates predicate selection, grouping and aggregation columns. Index Advised can help with this Parallelism can greatly improve populate time of the hash table Could be replaced by a permanent index if index encapsulates predicate selection, grouping and aggregation columns. Index Advised can help with this Can imply that the environment is memory constrained Grouping function queries are generally more memory intensive as they often union multiple trees that create and interrogate temporary objects Use feedback tools to determine the Optimizers fair share of memory

Temporary Index Creates

Memory Constaints

27

2010 IBM Corporation

IBM Power Systems

Strategic Indexed Advised Mechanisms


Visual Explain
System wide index advice (V5R4)
Data is placed into a DB2 table (QSYS2/SYSIXADV) Autonomic with no overhead
Visual Explain Indexes Advised SQE Plan Cache SQE Plan Cache Snapshots Detailed DB Monitor Data SQL request Summarized DB Monitor Data Debug Job Log Messages

SQE Plan Cache (V5R4)

No direct index advice Index advice via Snapshot data or Visual Explain

SQE Plan Cache Snapshot (V5R4)

Enhanced SQE index advised 3020 rows to show multiple indexes for same table Temporary index created

Detailed Database Monitor (V5R4)

Enhanced SQE index advised 3020 rows to show multiple indexes for same table Temporary index created

Query Optimization
Print SQL Information Messages

28

2010 IBM Corporation

IBM Power Systems

Grouping Set Index Advised Example


SELECT REGION, COUNTRY, COUNT(TERRITORY) FROM CUST_DIM WHERE CONTINENT = 'AMERICA' GROUP BY GROUPING SETS ((REGION),(COUNTRY))

29

2010 IBM Corporation

IBM Power Systems

Grouping Set Index Advised Example

30

2010 IBM Corporation

IBM Power Systems

Grouping Set Index Advised Example

31

2010 IBM Corporation

IBM Power Systems

Grouping Set Index Advised Example


SELECT REGION, COUNTRY, COUNT(TERRITORY) FROM CUST_DIM GROUP BY GROUPING SETS ((REGION),(COUNTRY))

32

2010 IBM Corporation

IBM Power Systems

Grouping Set Index Advised Example

33

2010 IBM Corporation

IBM Power Systems

Grouping Set Index Advised Example

34

2010 IBM Corporation

IBM Power Systems

Feedback Mechanism Changes for Grouping Sets


CHANGED Visual Explain

Detailed Database Monitor Data SQL trace


Indexes Advised System wide

New icons: Multiple Aggregations, Temporary Distinct Hash Table


Grouping rows (3028 rows) will get cut for each ROLLUP and Grouping Set leg See V6R1 info Center doc for 3028 record changes Index Advised strategy unchanged Indexes will be advised during normal optimization path

UNCHANGED SQE Plan Cache SQE Plan Cache Snapshots Summarized Database Monitor Data Debug Job Log Messages PRTSQLINF Messages

35

2010 IBM Corporation

IBM Power Systems

DB2 Family & MQTs Stage 2 V5R4


MQT Example: CREATE TABLE Example_MQT AS (SELECT Geography, Region, Year, Month, SUM(Revenue) AS Total_Revenue, SUM(Quantity) AS Total_Quantity, COUNT(*) AS Rows_per_Group FROM Example_Table GROUP BY Geography,Region,Year,Month) DATA INITIALLY IMMEDIATE REFRESH DEFERRED ENABLE QUERY OPTIMIZATION MAINTAINED BY USER Optimizer could use the MQT instead of fully executing the following query: SELECT Geography, Year, SUM(Revenue) AS Total_Revenue, SUM(Quantity) AS Total_Quantity, FROM Example_Table WHERE Year IN (2004, 2005) GROUP BY Geography, Year; white paper: ibm.com/servers/enable/site/education/abstracts/438a_abs.html User responsible for keeping MQT data current and activating optimizer MQT awareness with QAQQINI options

36

2010 IBM Corporation

IBM Power Systems

MQTs and Grouping Sets


MQT matching strategy will look for an exact match of the grouping sets in the query to grouping sets in an MQT. Example: SELECT A, B, C, SUM(D) FROM T1 GROUP BY MQT1: MQT2:
GROUPING SETS ((A), (B, C)) CREATE TABLE MQT1 AS SELECT A, SUM(D) as SUM_MQT1 FROM T1 GROUP BY A CREATE TABLE MQT2 AS SELECT B, C, SUM(D) as SUM_MQT2 FROM T1 GROUP BY B, C

The MQTs can be used as follows: SELECT A, NULL, NULL, SUM_MQT1 FROM MQT1 UNION ALL SELECT NULL, B, C, SUM_MQT2 FROM MQT2 MQTs which provide a subset of the grouping sets asked for in the query can be unioned with a query that implements the remaining grouping sets

37

2010 IBM Corporation

IBM Power Systems

MQTs and ROLLUP


If the query contains a ROLLUP, an MQT that does simple grouping or ROLLUP over the ROLLUP columns is useful Example: SELECT A, B, C, SUM(D) FROM T1 GROUP BY ROLLUP (A, B, C) MQT:
SELECT A, B, C, SUM(D) as SUM_MQT FROM T1 GROUP BY A, B, C

The MQT can be used as follows: SELECT A, B, C, SUM(SUM_MQT) FROM MQT GROUP BY ROLLUP(A, B, C) SUM(D) becomes a SUM(SUM) when the MQT is substituted. Other aggregate expressions can be done with similar compensations.
COUNT aggregate expression becomes SUM of the MQT COUNT MAX/MIN becomes MAX/MIN of the MQT MAX/MIN.

38

2010 IBM Corporation

IBM Power Systems

MQTs with GROUPING aggregate function


Example:
SELECT A, B, C, SUM(D) FROM T1 GROUP BY ROLLUP (A, B, C)

MQT: SELECT A, B, C, E, GROUPING(E) as GE, SUM(D) as SUM_MQT FROM T1 GROUP BY ROLLUP(A, B, C, E) The MQT can be used as follows: SELECT A, B, C, SUM_MQT FROM MQT WHERE GE = 1 Rows where GROUPING(E) = 1 are results for ROLLUP(A, B, C)
Optimizer must be able to differentiate between result set for GS(A,B,C,E) where E contains NULLs and GS(A,B,C,-), GS(A,B,-,-), GS(A,-,-,-) and GS(-,-,-,-) MQT would not be usable without GROUPING(E) in the MQT definition

39

2010 IBM Corporation

IBM Power Systems

MQTs and Grouping Sets


MQTs with GROUPING SET, ROLLUP and CUBE syntax can be used to handle grouping queries Example:
SELECT SUM(D) FROM T1 GROUP BY GROUPING SETS((A), (B), (C)) SELECT SUM(D) FROM T1 GROUP BY GROUPING SETS((A), (B)) SELECT SUM(D) FROM T1 GROUP BY GROUPING SETS((A), (C)) SELECT SUM(D) FROM T1 GROUP BY GROUPING SETS((B), (C)) SELECT SUM(D) FROM T1 GROUP BY (A) SELECT SUM(D) FROM T1 GROUP BY (B) SELECT SUM(D) FROM T1 GROUP BY (C)

Can be satisfied with MQT: SELECT A, B, C, SUM(D), GROUPING(A), GROUPING(B), GROUPING(C) as SUM_MQT FROM T1 GROUP BY GROUPING SETS((A), (B), (C)) MQTs specifying CUBE and ROLLUP tend to carry large volumes of data. Used when disk space is plentiful and:
Contain commonly used grouping permutations Very commonly run CUBE and ROLLUP queries

40

2010 IBM Corporation

IBM Power Systems

Summary

New Grouping Functions Allow for multiple Grouping operations in 1 query, usually using 1 pass through the data
GROUP BY GROUPING SETS((C1,C2,C3), (C1,C2,C3,C4),(C1,C2) GROUP BY ROLLUP (C1,C2,C3) GROUP BY CUBE(C1,C2)

Be careful not to Ask for more than you need. Use Visual explain to understand and tune query before you run it.
Index advise is Key

Consider MQTs
Solve these kinds of queries Provide great performance for expanded use of this grouping technology

41

2010 IBM Corporation

IBM Power Systems

V6R1 Index Enhancements

42

2010 IBM Corporation

IBM Power Systems

V6R1 Creation of Index with Derived values


Creation of indexes with derived values via SQL
CREATE INDEX STAR100G.ODERPRIORITYUPPER ON STAR100G.ITEM_FACT (UPPER(ORDERPRIORITY ) AS ASC); UORDERPRIORITY

CREATE ENCODED VECTOR INDEX STAR100G.YEARQTR ON STAR100G.ITEM_FACT (YEAR(ORDERDATE) AS ORDYEAR ASC, QUARTER(ORDERDATE) AS ORDQTR ASC); CREATE INDEX STAR100G.TOTALEXTENDEDPRICE ON STAR100G.ITEM_FACT (QUANTITY * EXTENDEDPRICE AS ASC); TOTEXTPRICE

* BEWARE, THERE ARE SOME RESTRICTIONS ON WHAT QUERY OPTIMIZER CAN USE

43

2010 IBM Corporation

IBM Power Systems

V6R1 Enhanced Native access to the SQL Index

Specify format name And table columns to be added to that format.

CREATE INDEX STAR100G.SHIPMODE ON STAR100G.ITEM_FACT (SHIPMODE ASC, ZIPCODE ASC ) RCDFMT SHPMODEZIP ADD CUSTNAME, SHIPADDR;

CREATE INDEX STAR100G.SHIPMDMON ON STAR100G.ITEM_FACT (SHIPMODE ASC, MONTH(SHIPDATE AS SHIPMON for COLUMN SHIPMON ASC) RCDFMT SHPMODEMON ADD CUSTNAME, SHIPADDR, COMMITDATE;

44

2010 IBM Corporation

IBM Power Systems

Create sparse indexes from SQL

Support of WHERE clause on SQL create index


CREATE INDEX STAR100G.FASTDELIVER ON STAR100G.ITEM_FACT (SHIPMODE ASC) WHERE SHIPMODE = 'NEXTDAYAIR' OR SHIPMODE = 'COURIER'; CREATE INDEX STAR100G.FASTDELIVR ON STAR100G.ITEM_FACT (SHIPMODE AS SHIPMODE FOR COLUMN SHIPMODE ASC) WHERE SHIPMODE = 'NEXTDAYAIR' OR SHIPMODE = 'COURIER' RCDFMT FASTDLVR ADD ORDERKEY, SHIPDATE, COMMITDATE, RECEIPTDATE, SHIPPRIORITY;

Limitations

NOT USED BY THE QUERY OPTIMIZER (BOTH SQE AND CQE)

45

2010 IBM Corporation

IBM Power Systems

When should I use Derived IX support?

Could replace some logical files with SQL indexes for use by Native programs.
Modernize those objects Big logical pagesize

Derived indexes may be useful for


Case insensitive searches Data extracted from a column (i.e. SUBSTR, YEAR, MONTH.. Results of operations ( COL1+COL2 , QTY * COST) Might be useful to allow Index only access in more cases Reduce table scans Index Used more often for local selection

46

2010 IBM Corporation

IBM Power Systems

When Should I use WHERE Clause support

In general its not a good idea to build indexes with the WHERE clause
Not yet useable by the Optimizer May be too specific, Only useable by small number of statements DO NOT Replace general purpose index with multiple Sparse indexes CREATE INDEX ORDERYEAR on ORDERS (YEAR ASC)

NOT the following CREATE INDEX ODERYEAR1 on ORDERS(YEAR ASC) WHERE YEAR=2006 CREATE INDEX ODERYEAR2 on ORDERS(YEAR ASC) WHERE YEAR=2007 CREATE INDEX ODERYEAR3 on ORDERS(YEAR ASC) WHERE YEAR=2008

47

2010 IBM Corporation

IBM Power Systems

Are you experiencing performance problems? Are you using SQL? Are you getting the most out of DB2 for i? IBM DB2 for i Center of Excellence
Database modernization DB2 Web Query Database architecture and design DB2 SQL performance analysis and tuning Data warehousing and Business Intelligence DB2 for i education and training
Contact: Mike Cain Rochester, MN USA
48 2010 IBM Corporation

Need help?

mcain@us.ibm.com

IBM Systems and Technology Group

Thank You

IBM Power Systems

Trademarks and Disclaimers


Adobe, Acrobat, PostScript and all Adobe-based trademarks are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States, other countries, or both. Intel, Intel logo, Intel Inside, Intel Inside logo, Intel Centrino, Intel Centrino logo, Celeron, Intel Xeon, Intel SpeedStep, Itanium, and Pentium are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both. IT Infrastructure Library is a registered trademark of the Central Computer and Telecommunications Agency which is now part of the Office of Government Commerce. ITIL is a registered trademark, and a registered community trademark of the Office of Government Commerce, and is registered in the U.S. Patent and Trademark Office. UNIX is a registered trademark of The Open Group in the United States and other countries. Cell Broadband Engine and Cell/B.E. are trademarks of Sony Computer Entertainment, Inc., in the United States, other countries, or both and are used under license therefrom. Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others. Information is provided "AS IS" without warranty of any kind. The customer examples described are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual environmental costs and performance characteristics may vary by customer. Information concerning non-IBM products was obtained from a supplier of these products, published announcement material, or other publicly available sources and does not constitute an endorsement of such products by IBM. Sources for non-IBM list prices and performance numbers are taken from publicly available information, including vendor announcements and vendor worldwide homepages. IBM has not tested these products and cannot confirm the accuracy of performance, capability, or any other claims related to non-IBM products. Questions on the capability of non-IBM products should be addressed to the supplier of those products. All statements regarding IBM future direction and intent are subject to change or withdrawal without notice, and represent goals and objectives only. Some information addresses anticipated future capabilities. Such information is not intended as a definitive statement of a commitment to specific levels of performance, function or delivery schedules with respect to any future products. Such commitments are only made in IBM product announcements. The information is presented here to communicate IBM's current investment and development activities as a good faith effort to help with our customers' future planning. Performance is based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual throughput or performance that any user will experience will vary depending upon considerations such as the amount of multiprogramming in the user's job stream, the I/O configuration, the storage configuration, and the workload processed. Therefore, no assurance can be given that an individual user will achieve throughput or performance improvements equivalent to the ratios stated here. Prices are suggested U.S. list prices and are subject to change without notice. Contact your IBM representative or Business Partner for the most current pricing in your geography.
50 2010 IBM Corporation

Anda mungkin juga menyukai