Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 © 2005 Julian Dyke Reducing Redo Julian Dyke Independent Consultant Web Version juliandyke.com.

Similar presentations


Presentation on theme: "1 © 2005 Julian Dyke Reducing Redo Julian Dyke Independent Consultant Web Version juliandyke.com."— Presentation transcript:

1 1 © 2005 Julian Dyke Reducing Redo Julian Dyke Independent Consultant Web Version juliandyke.com

2 © 2005 Julian Dyke juliandyke.com 2 Agenda  Introduction  Tests  Indexes  Number of columns processed  SELECT FOR UPDATE  Number of rows processed  COMMIT  Batch size  Global temporary tables  External tables  Conclusion

3 © 2005 Julian Dyke juliandyke.com 3 Redo Records Redo Block Header 16 bytes Redo Block 512 or 1024 bytes Redo Block Body 496 bytes Redo Record 1 Redo Record 2 Wastage Redo Record 3 Wastage Header Body Header Spare Header Body Spare STOP

4 © 2005 Julian Dyke juliandyke.com 4 Change Vectors Redo Record Header Body Header Body Header Body Header Body Change Vectors Change Vector 3 Change Vector 1 Change Vector 2 STOP

5 © 2005 Julian Dyke juliandyke.com 5 Header Change Vector Header Body STOP

6 © 2005 Julian Dyke juliandyke.com 6 Example  Examples in this presentation taken from Formula 1 database  Contains full details of all races from 1961 to 2004  Updated annually in November (end of season)  Currently  20 cars per race  19 races per season  `Approximately 360 new rows per season juliandyke.net

7 © 2005 Julian Dyke juliandyke.com 7 Schema CLASSIFICATION SEASON GRANDPRIX RACETEAMDRIVER COUNTRYCIRCUIT ENGINE CAR

8 © 2005 Julian Dyke juliandyke.com 8 Cars  Each season has up to 18 races (19 in 2005)  Each race has up to 39 entrants (13 races in 1989)  Each car has  driver, team and engine  laps completed (may be zero)  optional notes  Results are classified as follows CClassified DNFDid not finish DNSDid not start DNQDid not qualify DISDisqualified

9 © 2005 Julian Dyke juliandyke.com 9 Points  Points basically awarded to driver and team as follows 1 st 2 nd 3 rd 4 th 5 th 6 th 7 th 8 th Pre 1991964321 1991-20021064321 2003 onwards108654321  But... not always straightforward  Half points awarded for incomplete races  Split races (two half point races aggregated)  Driver and / or team disqualifications e.g. Tyrrell in 1984  Up to 1980 only best scores counted for each half of season e.g.  Best 5 results from first 7 races and best 5 results from last 7 races  1982-1990 only best 11 results counted for drivers  1961-1978 only first car to finish counted for each team

10 © 2005 Julian Dyke juliandyke.com 10 Input file - car.csv  Comma separated file  16181 rows  Fields are:  season_key  race_key  position  driver_key  team_key  engine_key  laps_completed  classification_key  notes (optional) 200417 ZBAUMINFOR41DNFSpin 20041718DCOUMCLMER38DNFAccident 20041719RBARFER 38DNFAccident 20041720MWEBJAGFOR20DNFOverheated 2004181JMONWILBMW71C 2004182KRAIMCLMER71C 2004183RBARFER 71C 2004184FALOREN 71C 2004185RSCHWILBMW71C 2004186TSATBARHON71C 2004187MSCHFER 71C 2004188FMASSAUFER71C 2004189GFISSAUFER71C 20041810JVILREN 70C 20041811DCOUMCLMER70C 20041812JTRUTOY 70C 20041813RZONTOY 70C 20041814CKLIJAGFOR69C 20041815TGLOJORFOR69C 20041816ZBAUMINFOR67C 20041817GBRUMINFOR67C 200418 MWEBJAGFOR23DNFAccident 20041819NHEIJORFOR15DNFClutch 20041820JBUTBARHON3DNFEngine

11 © 2005 Julian Dyke juliandyke.com 11 Input file - points.csv  Comma separated file  16181 rows  Fields are:  season_key  race_key  position  driver_points  team_point 200417 00 2004171800 2004171900 2004172000 200418110 200418288 200418366 200418455 200418544 200418633 200418722 200418811 200418900 2004181000 2004181100 2004181200 2004181300 2004181400 2004181500 2004181600 2004181700 200418 00 2004181900 2004182000

12 © 2005 Julian Dyke juliandyke.com 12 CAR table  CAR table and index definitions CREATE TABLE car ( season_keyNUMBERNOT NULL, race_keyNUMBERNOT NULL, positionNUMBERNOT NULL, driver_keyVARCHAR2(4)NOT NULL, team_keyVARCHAR2(3)NOT NULL, engine_keyVARCHAR2(3)NOT NULL, laps_completedNUMBERNOT NULL, classification_keyVARCHAR2(4)NOT NULL, notesVARCHAR2(100), driver_pointsNUMBERNOT NULL DEFAULT 0, team_pointsNUMBERNOT NULLDEFAULT 0 ); ALTER TABLE car ADD CONSTRAINT car_pk PRIMARY KEY (season_key,race_key,position); CREATE INDEX car_driver ON car (season_key,driver_key,driver_points);

13 © 2005 Julian Dyke juliandyke.com 13 CAR  CAR table relational integrity definitions ALTER TABLE car ADD CONSTRAINT car_race FOREIGN KEY (season_key,race_key) REFERENCES race (season_key,race_key); ALTER TABLE car ADD CONSTRAINT car_driver FOREIGN KEY (driver_key) REFERENCES driver (driver_key); ALTER TABLE car ADD CONSTRAINT car_team FOREIGN KEY (team_key) REFERENCES team (team_key); ALTER TABLE car ADD CONSTRAINT car_engine FOREIGN KEY (engine_key) REFERENCES engine (engine_key); ALTER TABLE car ADD CONSTRAINT car_classification FOREIGN KEY (classification_key) REFERENCES classification (classification_key);

14 © 2005 Julian Dyke juliandyke.com 14 For each line in car.csv { read :season_key, :race_key, :position, :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes; INSERT INTO car (season_key, race_key, position, driver_key, team_key, engine_key, laps_completed, classification_key, notes) VALUES (:season_key,:race_key,:position, :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes) COMMIT; } Baseline - Insert

15 © 2005 Julian Dyke juliandyke.com 15 Baseline - Insert Redo Generation for each Insert Statement Header 5.2 Start Transaction 5.1 (11.1) Undo Undo insert row in CAR tableINSERT 11.2 Redo Insert row in CAR table INSERT UndoUndo insert row into CAR_PK index5.1 (10.22) INSERT Redo10.2Insert row into CAR_PK indexINSERT 5.1 (10.22)UndoUndo insert row into CAR_DRIVER index INSERT Redo 10.2 Insert row into CAR_DRIVER indexINSERT Commit 5.4 End Transaction COMMIT Oracle 9.2 and below

16 © 2005 Julian Dyke juliandyke.com 16 Insert Statement Redo Generation for each Insert Statement Header 5.2 Start Transaction 5.1 (11.1) Undo Undo insert row in CAR tableINSERT 11.2 Redo Insert row in CAR table INSERT UndoUndo insert row into CAR_PK index5.1 (10.22) INSERT Redo10.2Insert row into CAR_PK indexINSERT 5.1 (10.22)UndoUndo insert row into CAR_DRIVER index INSERT Redo 10.2 Insert row into CAR_DRIVER indexINSERT Commit 5.4 End Transaction COMMIT Oracle 10.1 and above

17 © 2005 Julian Dyke juliandyke.com 17 Baseline - Update For each line in points.csv { read :season_key, :race_key, :position, :driver_points, :team_points; SELECT driver_key, team_key, engine_key, laps_completed, classification_key, notes INTO :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes FROM car WHERE season_key = :season_key AND race_key = :race_key AND position = :position FOR UPDATE; UPDATE car SET driver_key = :driver_key, team_key = :team_key,engine_key = :engine_key, laps_completed = :laps_completed,classification_key = :classification_key, notes = :notes, driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position; COMMIT; }

18 © 2005 Julian Dyke juliandyke.com 18 Baseline - Update Redo Generation for each Update Statement Header 5.2 Start Transaction 5.1 (11.1) Undo Undo update row in CAR tableUPDATE 11.5 Redo Update row in CAR table UPDATE UndoUndo delete row from CAR_DRIVER index5.1 (10.22) UPDATE Redo10.4Delete row from CAR_DRIVER indexUPDATE 5.1 (10.22)UndoUndo insert row into CAR_DRIVER index UPDATE Redo 10.2 Insert row into CAR_DRIVER indexUPDATE 5.1 (11.1) Undo Undo lock row in CAR tableSELECT FOR UPDATE 11.4 Redo Lock row in CAR tableSELECT FOR UPDATE Commit 5.4 End Transaction COMMIT Oracle 9.2 and below

19 © 2005 Julian Dyke juliandyke.com 19 Baseline - Update Redo Generation Header 5.2 Start Transaction 5.1 (11.1) Undo Undo update row in CAR tableUPDATE 11.5 Redo Update row in CAR table UPDATE UndoUndo delete row from CAR_DRIVER index5.1 (10.22) UPDATE Redo10.4Delete row from CAR_DRIVER indexUPDATE 5.1 (10.22)UndoUndo insert row into CAR_DRIVER index UPDATE Redo 10.2 Insert row into CAR_DRIVER indexUPDATE 5.1 (11.1) Undo Undo lock row in CAR tableSELECT FOR UPDATE 11.4 Redo Lock row in CAR tableSELECT FOR UPDATE Commit 5.4 End Transaction COMMIT Oracle 10.1 and aboveRedo Generation for each Update Statement

20 © 2005 Julian Dyke juliandyke.com 20 Baseline - Results  Redo Generation in Bytes OperationINSERT (car.csv) UPDATE (points.csv) Total Baseline204488521440967634858528  Note  Amount of redo generated by both INSERT and UPDATE can be variable due to  Undo segment management  Recursive DDL statements e.g. extent allocation  Block cleanouts

21 © 2005 Julian Dyke juliandyke.com 21 Test 1  Check for unused indexes  CAR_PK indexes columns  SEASON_KEY  RACE_KEY  POSITION  supports primary key therefore mandatory  CAR_DRIVER indexes columns  SEASON_KEY  DRIVER_KEY  DRIVER_POINTS  no longer required by current version of application DROP INDEX car_driver;

22 © 2005 Julian Dyke juliandyke.com 22 Test 1 - Insert Redo Generation for each Insert Statement Header 5.2 Start Transaction 11.2 Redo Insert row in CAR table INSERT Redo10.2Insert row into CAR_PK indexINSERT 5.1 (10.22)UndoUndo insert row into CAR_DRIVER index INSERT Redo 10.2 Insert row into CAR_DRIVER indexINSERT 5.1 (11.1) Undo Undo insert row in CAR tableINSERT UndoUndo insert row into CAR_PK index5.1 (10.22) INSERT Commit 5.4 End Transaction COMMIT STOP

23 © 2005 Julian Dyke juliandyke.com 23 Test 1 - Update Redo Generation Header 5.2 Start Transaction 5.1 (11.1) Undo Undo update row in CAR tableUPDATE 11.5 Redo Update row in CAR table UPDATE UndoUndo delete row from CAR_DRIVER index5.1 (10.22) UPDATE Redo10.4Delete row from CAR_DRIVER indexUPDATE 5.1 (10.22)UndoUndo insert row into CAR_DRIVER index UPDATE Redo 10.2 Insert row into CAR_DRIVER indexUPDATE 5.1 (11.1) Undo Undo lock row in CAR tableSELECT FOR UPDATE 11.4 Redo Lock row in CAR tableSELECT FOR UPDATE Commit 5.4 End Transaction COMMIT Redo Generation for each Update Statement STOP

24 © 2005 Julian Dyke juliandyke.com 24 Test 1 - Results  Redo Generation in Bytes OperationINSERT (car.csv) UPDATE (points.csv) Total Baseline204488521440967634858528 Test 1146877561246740027155156  Conclusion  Eliminating redundant index reduced  insert redo generation by 5761096 bytes  update redo generation by 1942276 bytes

25 © 2005 Julian Dyke juliandyke.com 25 Test 2  In UPDATE statements  For tables undo and redo is generated for all columns in SET clause  For indexes undo and redo are only generated for index keys that have changed  Statements often update all columns to reduce parsing e.g.: UPDATE car SET driver_key = :driver_key, team_key = :team_key, engine_key = :engine_key, laps_completed = :laps_completed, classification_key = :classification_key, notes = :notes, driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position;

26 © 2005 Julian Dyke juliandyke.com 26 Test 2 - Update Redo Generation Header 5.2 Start Transaction 5.1 (11.1) Undo Undo update row in CAR table UPDATE 11.5 Redo Update row in CAR table UPDATE 5.1 (11.1) Undo Undo lock row in CAR tableSELECT FOR UPDATE 11.4 Redo Lock row in CAR tableSELECT FOR UPDATE Commit 5.4 End Transaction COMMIT Redo Generation for each Update Statement Slot = 23 Col 3 = JMON Col 4 = WIL Col 5 = BMW Col 6 = 71 Col 7 = C Col 8 = Col 9 = 10 Col 10= 10 Slot = 23 Col 3 = JMON Col 4 = WIL Col 5 = BMW Col 6 = 71 Col 7 = C Col 8 = Col 9 = 0 Col 10= 0 11.5 Redo 5.1 (11.1) Undo Slot = 23 Col 3 = JMON Col 4 = WIL Col 5 = BMW Col 6 = 71 Col 7 = C Col 8 = Col 9 = 10 Col 10= 10 Slot = 23 Col 3 = JMON Col 4 = WIL Col 5 = BMW Col 6 = 71 Col 7 = C Col 8 = Col 9 = 0 Col 10= 0 STOP

27 © 2005 Julian Dyke juliandyke.com 27 Test 2  Only update columns which can have new values  DRIVER_POINTS  TEAM_POINTS For each line in points.csv { read :season_key, :race_key, :position, :driver_points, :team_points; SELECT... FOR UPDATE; UPDATE car SET driver_key = :driver_key, team_key = :team_key, engine_key = :engine_key, laps_completed = :laps_completed, classification_key = :classification_key, notes = :notes, driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position; COMMIT; } For each line in points.csv { read :season_key, :race_key, :position, :driver_points, :team_points; SELECT... FOR UPDATE; UPDATE car SET driver_key = :driver_key, team_key = :team_key, engine_key = :engine_key, laps_completed = :laps_completed, classification_key = :classification_key, notes = :notes, driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position; COMMIT; }

28 © 2005 Julian Dyke juliandyke.com 28 Test 2 - Results  Redo Generation in Bytes OperationINSERT (car.csv) UPDATE (points.csv) Total Baseline204488521440967634858528 Test1146877561246740027155156 Test2145600521158476026144812  Conclusion  Eliminating unnecessary columns from update statements reduced update redo generation by 882640 bytes  Would be significantly more if unchanged columns included long fields e.g. CHAR, or VARCHAR2

29 © 2005 Julian Dyke juliandyke.com 29 Test 3  Eliminate unnecessary SELECT FOR UPDATE statements For each line in points.csv { read :season_key, :race_key, :position, :driver_points, :team_points; SELECT driver_key, team_key, engine_key, laps_completed, classification_key, notes INTO :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes FROM car WHERE season_key = :season_key AND race_key = :race_key AND position = :position FOR UPDATE; UPDATE car SET driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position; COMMIT; } For each line in points.csv { read :season_key, :race_key, :position, :driver_points, :team_points; SELECT driver_key, team_key, engine_key, laps_completed, classification_key, notes INTO :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes FROM car WHERE season_key = :season_key AND race_key = :race_key AND position = :position FOR UPDATE; UPDATE car SET driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position; COMMIT; }

30 © 2005 Julian Dyke juliandyke.com 30 Test 3 - Update Redo Generation Header 5.2 Start Transaction 5.1 (11.1) Undo Undo lock row in CAR tableSELECT FOR UPDATE 11.4 Redo Lock row in CAR tableSELECT FOR UPDATE Redo Generation for each Update Statement 11.5 Redo Update row in CAR table UPDATE 5.1 (11.1) Undo Undo update row in CAR tableUPDATE Commit 5.4 End Transaction COMMIT STOP

31 © 2005 Julian Dyke juliandyke.com 31 Test 3 - Results  Redo Generation in Bytes OperationINSERT (car.csv) UPDATE (points.csv) Total Baseline204488521440967634858528 Test 1146877561246740027155156 Test 2145600521158476026144812 Test 314554428847548423029912  Conclusion  Eliminating SELECT FOR UPDATE statement reduced update redo generation by 3109276 bytes

32 © 2005 Julian Dyke juliandyke.com 32 Test 4  Rows are inserted with default values of 0 for driver_points and team_points  Points only scored by  first eight cars - 2003 onwards  first six cars - pre 2003  Only update rows with non-zero rows for driver_points and/or team_points Team Driver PointsNo Points Points351430 No Points32412313 DriverTeam 32435143012313 STOP

33 © 2005 Julian Dyke juliandyke.com 33 Header 5.2 11.5 Redo 5.1 (11.1) Undo Commit 5.4 Test 4 - Update Redo GenerationRedo Generation for each Update Statement Header 5.2 11.5 Redo 5.1 (11.1) Undo Commit 5.4 UPDATE car SET driver_points = 1 team_points = 1 WHERE... col9 = 0 col10 = 0 col9 = 1 col10 = 1 UPDATE car SET driver_points = 0 team_points = 0 WHERE... col9 = 0 col10 = 0 UPDATE car SET driver_points = 0 team_points = 0 WHERE... col9 = 0 col10 = 0 UPDATE car SET driver_points = 9 team_points = 9 WHERE... col9 = 0 col10 = 0 col9 = 9 col10 = 9 Header 5.2 11.5 Redo 5.1 (11.1) Undo Commit 5.4 Header 5.2 11.5 Redo 5.1 (11.1) Undo Commit 5.4 Header 5.2 11.5 Redo 5.1 (11.1) Undo Commit 5.4 UPDATE car SET driver_points = 9 team_points = 9 WHERE... col9 = 0 col10 = 0 col9 = 9 col10 = 9 STOP

34 © 2005 Julian Dyke juliandyke.com 34 Test 4  Only update rows with non-zero rows for driver_points and/or team_points For each line in points.csv { read :season_key, :race_key, :position, :driver_points, :team_points; UPDATE car SET driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position; COMMIT; } For each line in points.csv { read :season_key, :race_key, :position, :driver_points, :team_points; IF driver_points != 0 OR team_points != 0 THEN { UPDATE car SET driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position; COMMIT; } }

35 © 2005 Julian Dyke juliandyke.com 35 Test 4 - Results  Redo Generation in Bytes OperationINSERT (car.csv) UPDATE (points.csv) Total Baseline204488521440967634858528 Test 1146877561246740027155156 Test 2145600521158476026144812 Test 314554428847548423029912 Test 414683408207031616753724  Conclusions  Eliminating unnecessary update statements reduced update redo generation by 6405168 bytes

36 © 2005 Julian Dyke juliandyke.com 36 For each line in car.csv { read :season_key, :race_key, :position, :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes; INSERT INTO car (season_key, race_key, position, driver_key, team_key, engine_key, laps_completed, classification_key, notes) VALUES (:season_key,:race_key,:position, :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes) COMMIT; } For each line in car.csv { read :season_key, :race_key, :position, :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes; INSERT INTO car (season_key, race_key, position, driver_key, team_key, engine_key, laps_completed, classification_key, notes) VALUES (:season_key,:race_key,:position, :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes) COMMIT; } COMMIT; Test 5  Eliminate unnecessary COMMIT statements

37 © 2005 Julian Dyke juliandyke.com 37 For each line in points.csv { read :season_key, :race_key, :position, :driver_points, :team_points; IF driver_points != 0 OR team_points != 0 THEN { UPDATE car SET driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position; COMMIT; } } For each line in points.csv { read :season_key, :race_key, :position, :driver_points, :team_points; IF driver_points != 0 OR team_points != 0 THEN { UPDATE car SET driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position; COMMIT; } } COMMIT; Test 5  Eliminate unnecessary COMMIT statements (continued)

38 © 2005 Julian Dyke juliandyke.com 38 Test 5 - Insert Redo GenerationRedo Generation for each Insert Statement Header 5.2 Start Transaction 11.2 Redo Insert row in CAR table INSERT Redo10.2Insert row into CAR_PK indexINSERT 5.1 (11.1) Undo Undo insert row in CAR tableINSERT UndoUndo insert row into CAR_PK index5.1 (10.22) INSERT Commit 5.4 End Transaction COMMIT Header 5.2 Start Transaction Undo Undo insert row into CAR_PK index 5.1 (10.22) INSERT 11.2 Redo Insert row in CAR table INSERT Redo10.2Insert row into CAR_PK indexINSERT 5.1 (11.1) Undo Undo insert row in CAR table INSERT Commit 5.4 End Transaction COMMIT STOP

39 © 2005 Julian Dyke juliandyke.com 39 Test 5 - Results  Redo Generation in Bytes OperationINSERT (car.csv) UPDATE (points.csv) Total Baseline204488521440967634858528 Test 1146877561246740027155156 Test 2145600521158476026144812 Test 314554428847548423029912 Test 414683408207031616753724 Test 59516512102808410544596  Conclusion  Eliminating COMMIT statements reduced  insert redo generation by 5166896 bytes  update redo generation by 1042232 bytes

40 © 2005 Julian Dyke juliandyke.com 40 Test 6  Default batch size is 1  Test INSERT and UPDATE with different batch sizes Batch SizeINSERT RedoUPDATE RedoTotal Redo 19517096102808410545180 2565413610280846682220 4392709210284404955532 8301194410280844040028 16258854010286363617176 32237588410281723404056 64225493610280403282976 128219587610280843223960 256217940410284403207844 512216381610280843191900 1024216308410280843191168 2048216001210280843188096

41 © 2005 Julian Dyke juliandyke.com 41 Test 6 - Results

42 © 2005 Julian Dyke juliandyke.com 42 Test 6 - Results  Redo Generation in Bytes OperationINSERT (car.csv) UPDATE (points.csv) Total Baseline204488521440967634858528 Test 1146877561246740027155156 Test 2145600521158476026144812 Test 314554428847548423029912 Test 414683408207031616753724 Test 59516512102808410544596 Test 6219587610280843223960  Conclusion  Batch Size of 128  reduced insert redo generation by 7320636 bytes  update redo generation unaffected

43 © 2005 Julian Dyke juliandyke.com 43 Test 7  Create global temporary table CREATE GLOBAL TEMPORARY TABLE temporary_car ( season_keyVARCHAR2(4), race_keyVARCHAR2(2), positionNUMBER, driver_keyVARCHAR2(4), team_keyVARCHAR2(3), engine_keyVARCHAR2(3), laps_completedNUMBER, classification_keyVARCHAR2(4), notesVARCHAR2(100), driver_pointsNUMBER, team_pointsNUMBER ) ON COMMIT PRESERVE ROWS;

44 © 2005 Julian Dyke juliandyke.com 44 Test 7  Insert rows into global temporary table For each line in car.csv { read :season_key, :race_key, :position, :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes; INSERT INTO temporary_car (season_key, race_key, position, driver_key, team_key, engine_key, laps_completed, classification_key, notes) VALUES (:season_key,:race_key,:position, :driver_key, :team_key, :engine_key, :laps_completed, :classification_key, :notes) COMMIT; }  Generated 64140 bytes of redo

45 © 2005 Julian Dyke juliandyke.com 45 Test 7  Update points in global temporary table For each line in points.csv { read :season_key, :race_key, :position, :driver_points, :team_points; IF driver_points != 0 OR team_points != 0 THEN { UPDATE temporary car SET driver_points = :driver_points, team_points = :team_points WHERE season_key = :season_key AND race_key = :race_key AND position = :position; } } COMMIT;  Generated 652884 bytes of redo

46 © 2005 Julian Dyke juliandyke.com 46 Test 7  Copy rows from global temporary table to permanent table INSERT INTO car ( season_key, race_key, position, driver_key, team_key, engine_key, laps_completed, classification_key, notes, driver_points, team_points ) SELECT season_key, race_key, position, driver_key, team_key, engine_key, laps_completed, classification_key, notes, driver_points, team_points FROM temporary_car;  Generated 2166724 bytes of redo  APPEND hint had no effect

47 © 2005 Julian Dyke juliandyke.com 47 Test 7 - Results  Redo Generation in Bytes  Conclusion  Global Temporary Table reduced total redo generation by 340212 bytes OperationDescriptionTotal BaselineUpdate all rows34858528 Test 1Update affected rows27155156 Test 2Update affected columns26144812 Test 3Drop index23029912 Test 4SELECT FOR UPDATE16753724 Test 5COMMIT10544596 Test 6Increase Batch Size3223960 Test 7Global Temporary Table2883748

48 © 2005 Julian Dyke juliandyke.com 48 Test 8  Create external tables CREATE OR REPLACE DIRECTORY external_dir AS '/u01/app/oracle/gp'; CREATE TABLE external_points ( season_keyVARCHAR2(4), race_keyVARCHAR2(2), positionNUMBER, driver_pointsNUMBER, team_pointsNUMBER ) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY external_dir ACCESS PARAMETERS ( RECORDS DELIMITED BY NEWLINE FIELDS TERMINATED BY ',' ) LOCATION ('points.csv') );

49 © 2005 Julian Dyke juliandyke.com 49 Test 8 CREATE TABLE external_car ( season_keyVARCHAR2(4), race_keyVARCHAR2(2), positionNUMBER, driver_keyVARCHAR2(4), team_keyVARCHAR2(3), engine_keyVARCHAR2(3), laps_completedNUMBER, classification_keyVARCHAR2(4), notesVARCHAR2(100) ) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY external_dir ACCESS PARAMETERS ( RECORDS DELIMITED BY NEWLINE FIELDS TERMINATED BY ',' MISSING FIELD VALUES ARE NULL ) LOCATION ('car.csv') );

50 © 2005 Julian Dyke juliandyke.com 50 Test 8  Insert directly into permanent table joining contents of both external tables INSERT INTO car ( season_key, race_key, position, driver_key, team_key, engine_key, laps_completed, classification_key, notes, driver_points, team_points ) SELECT c.season_key, c.race_key, c.position, c.driver_key, c.team_key, c.engine_key, c.laps_completed, c.classification_key, c.notes, p.driver_points, p.team_points FROM external_car c, external_points p WHERE c.season_key = p.season_key AND c.race_key = p.race_key AND c.position = p.position";  Generated 2166724 bytes of redo

51 © 2005 Julian Dyke juliandyke.com 51 Test 8 - Results  Redo Generation in Bytes  Conclusion  External Tables reduced total redo generation by 717024 bytes OperationDescriptionTotal BaselineUpdate all rows34858528 Test 1Update affected rows27155156 Test 2Update affected columns26144812 Test 3Drop index23029912 Test 4SELECT FOR UPDATE16753724 Test 5COMMIT10544596 Test 6Increase Batch Size3223960 Test 7Global Temporary Table2883748 Test 8External Table2166724

52 © 2005 Julian Dyke juliandyke.com 52 Conclusion  We have seen that the following techniques can be used to reduce the amount of redo generated:  Eliminating redundant indexes  Reducing the number of columns updated  Eliminating redundant SELECT FOR UPDATE statements  Reducing the number of rows processed  Eliminating COMMIT statements  Increasing the batch size  Using Global Temporary Tables  Using External Tables

53 © 2005 Julian Dyke juliandyke.com 53 Thank you for your interest For more information and to provide feedback please contact me My e-mail address is: info@juliandyke.com My website address is: www.juliandyke.com


Download ppt "1 © 2005 Julian Dyke Reducing Redo Julian Dyke Independent Consultant Web Version juliandyke.com."

Similar presentations


Ads by Google