Presentation is loading. Please wait.

Presentation is loading. Please wait.

Query Rewrite Starburst Model (IBM). DB2 Query Optimizer (Starburst) Parsing and Semantic Checking Query Rewrite Plan Optimization Query Evaluation System.

Similar presentations


Presentation on theme: "Query Rewrite Starburst Model (IBM). DB2 Query Optimizer (Starburst) Parsing and Semantic Checking Query Rewrite Plan Optimization Query Evaluation System."— Presentation transcript:

1 Query Rewrite Starburst Model (IBM)

2 DB2 Query Optimizer (Starburst) Parsing and Semantic Checking Query Rewrite Plan Optimization Query Evaluation System Query Graph Model Executable Plan Data Flow Control Flow Compile Time Run Time

3 Goal of Query Rewrite Make queries as declarative as possible : Poorly expressed queries could force the optimizer into choosing suboptimal plans Perform natural heuristics For example, “predicate pushdown”

4 Components of Rewrite Engine Rewrite rules (more later) Rule engine –control strategies sequential (rules are processed sequentially) priority (higher priority rules are given a chance first) statistical (next rule is chosen randomly based on a user defined probability distribution –budget to avoid spending too much time on rewrites, the processing stops at a consistent state of QGM when the budget is exhausted Search facility –browses through QGM providing the context for the rules to work on

5 Problem How do we choose between competing incompatible transformations? Optimal solution: apply cost analysis and pick the transformation leading to a cheaper plan Practical solution (why?): generate multiple alternatives and send them to plan optimization phase (problems?)

6 Rewrite Rules: SELECT Merge CREATE VIEW itpv AS (SELECT DISTINCT itp.itemn, pur.vendn FROM itp, pur WHERE itp.ponum = pur.ponum AND pur.odate > ’85’) SELECT DISTINCT itm.itmn, pur.vendn FROM itm, itp, pur WHERE itp.ponum = pur.ponum AND itm.itemn = itpv.itemn AND pur.odate > ’85’ AND itm.itemn > ’01’ AND itm.itemn < ’20’ SELECT itm.itmn, itpv.vendn FROM itm, itpv WHERE itm.itemn = itpv.itemn AND itm.itemn > ’01’ AND itm.itemn < ’20’ Speedup: 200 times

7 Rewrite Rules: Existential Subquery Merge SELECT * FROM itp WHERE itm.itemn IN (SELECT itl.itmn FROM itl WHERE itl.wkcen = ‘WK468’ AND itl.locan = ‘L’ ) SELECT DISTINCT itp.* FROM itp, itl WHERE itp.itmn = itl.itemn AND itl.wkcen = ‘WK468’ AND itl.locan = ‘L’ Speedup: 15 times

8 Rewrite Rules: Intersect to Exists SELECT itemn FROM wor WHERE empno = ‘EMPN1279’ INTERSECT SELECT itmn FROM itl WHERE entry_time = ‘9773’ AND wkctr = ‘WK195’ ) Speedup: 8 times SELECT DISTINCT itemn FROM wor, itl WHERE empno = ‘EMPN1279’ entry_time = ‘9773’ AND wkctr = ‘WK195’ ) AND itl.itmn = wor.itemn

9 The Count Bug parts(PNUM,QOH) supply(PNUM,QUAN,SHIPDATE) Query: Find the part numbers of those parts whose quantities on hand equal the number of shipments of those parts before 1-1-80. select PNUM from parts where QOH = ( select count(SHIPDATE) from supply where supply.PNUM = parts.PNUM and SHIPDATE < 1-1-80)

10 The Count Bug (cont.) select PNUM from parts where QOH = ( select count(SHIPDATE) from supply where supply.PNUM = parts.PNUM and SHIPDATE < 1-1-80) temp (SUPPNUM,CT) = ( select PNUM, count(SHIPDATE) from supply where SHIPDATE < 1-1-80) group by PNUM) select PNUM from parts, temp where parts.QOH = temp.CT and temp.PNUM = parts.PNUM

11 The Count Bug (cont.) PNUMQOH 36 101 80 PNUMQUANSHIPDATE 347-3-79 3210-1-78 1016-8-78 1028-10-81 855-7-83 select PNUM from parts where QOH = ( select count(SHIPDATE) from supply where supply.PNUM = parts.PNUM and SHIPDATE < 1-1-80) SupplyParts PNUM 10 8 Result

12 The Count Bug (cont.) PNUMQOH 36 101 80 PNUMQUANSHIPDATE 347-3-79 3210-1-78 1016-8-78 1028-10-81 855-7-83 SupplyParts Temp temp (SUPPNUM,CT) = ( select PNUM, count(SHIPDATE) from supply where SHIPDATE < 1-1-80) group by PNUM) SuppnumCT 32 101

13 The Count Bug (cont.) PNUMQOH 36 101 80 Parts Temp SUPPNUMCT 32 101 select PNUM from parts, temp where parts.QOH = temp.CT and temp.PNUM = parts.PNUM Result PNUM 10

14 The Count Bug – solution with outer joins X A B Y B C E RSR=+S XY Anull BB C E

15 The Count Bug – solution with outer joins temp (SUPPNUM,CT) = ( select parts.PNUM, count(SHIPDATE) from parts, supply where SHIPDATE < 1-1-80 and parts.PNUM =+ supply.PNUM group by parts.PNUM) Parts.PNUMParts.QOHSupply.PNUMSupply.QUONSupply.SHIPDATE 36347-3-79 363210-1-78 101 16-8-78 80null parts.PNUM =+ supply.PNUM (for SHIPDATE < 1-1-80)


Download ppt "Query Rewrite Starburst Model (IBM). DB2 Query Optimizer (Starburst) Parsing and Semantic Checking Query Rewrite Plan Optimization Query Evaluation System."

Similar presentations


Ads by Google