102

Supercharge your Code to get OpAmal Database Performance · Supercharge your Code to get OpAmal Database Performance Gerald Venzl Senior Principal Product Manager Oracle Database

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SuperchargeyourCodetogetOpAmalDatabasePerformanceGeraldVenzlSeniorPrincipalProductManagerOracleDatabaseDevelopment@GeraldVenzl

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SafeHarborStatementThefollowingisintendedtooutlineourgeneralproductdirecAon.ItisintendedforinformaAonpurposesonly,andmaynotbeincorporatedintoanycontract.Itisnotacommitmenttodeliveranymaterial,code,orfuncAonality,andshouldnotberelieduponinmakingpurchasingdecisions.Thedevelopment,release,andAmingofanyfeaturesorfuncAonalitydescribedforOracle’sproductsremainsatthesolediscreAonofOracle.

4

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Gerald’sSafeHarborStatement

Nothingsaidhereisaguaranteeforsolvingyourpar6cularproblem.WhilethetechniquespresentedherecanhaveahugeposiAveimpactonperformanceitisnotguaranteedthattheywillfixyourparAcularproblem.

Performanceisrela6ve.Itdependsonahugeamountofdifferentfactorsandcan’tbecompared1:1.ThenumbersinthisdeckreflectaAny2GBVirtualBoxenvironmentwithonlyonevirtualCPU,keepthatinmind.

5

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

ProgramAgenda

IntroducAon

Whatisperformance

OracleDatabasePerformanceStaAsAcs

Commits–saverofyourdata

Rowbyrow=slowbyslow

Bindvari…–WHAT?

1

2

3

4

5

6

6

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

ProgramAgenda

IntroducAon

Whatisperformance

OracleDatabasePerformanceStaAsAcs

Commits–saverofyourdata

Rowbyrow=slowbyslow

Bindvari…–WHAT?

1

2

3

4

5

7

6

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

IntroducAon

8

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

IntroducAon

9

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

IntroducAon

10

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

IntroducAon

11

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

IntroducAon

12

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

IntroducAon

13

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

IntroducAon

14

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

IntroducAon

15

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

IntroducAon

16

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

ProgramAgenda

IntroducAon

Whatisperformance

OracleDatabasePerformanceStaAsAcs

Commits–saverofyourdata

Rowbyrow=slowbyslow

Bindvari…–WHAT?

1

2

3

4

5

17

6

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Whatisperformance

Performance=?

Asimpleformula

18

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Whatisperformance

Performance=latencyxthroughput

Asimpleformula

19

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Whatisperformance

•  Latency:TheAmetoprocessaunitofwork•  Throughput:Theamountofunitsofworkthatcanbeprocessedinparallel• Aunitofworkiseitherprocessed(CPU)orhastowait(I/O)• Goalsare:– Processaunitofworkasefficientaspossible– Reducewait6measmuchaspossible– Avoidunnecessaryresourceconsump6on(CPU&I/O)

20

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Whatisperformance

Performance=latencyxthroughput

10,000workunits/s=?

Asimpleformula

21

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Whatisperformance

Performance=latencyxthroughput

10,000workunits/s=1msx10wu

Asimpleformula

22

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Whatisperformance

Performance=latencyxthroughput

10,000workunits/s=10msx100wu

Asimpleformula

23

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Whatisperformance

24

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Whatisperformance

25

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

ProgramAgenda

IntroducAon

Whatisperformance

OracleDatabasePerformanceStaAsAcs

Commits–saverofyourdata

Rowbyrow=slowbyslow

Bindvari…–WHAT?

1

2

3

4

5

26

6

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Thedatabaseasa

27

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Thedatabaseasablackbox

28

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Adatabaseiseither

29

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Adatabaseiseitherworking

30

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Adatabaseiseitherworkingoridle

31

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Theworkingstatesofthedatabase

32

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Theworkingstatesofthedatabase

33

Busy

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Theworkingstatesofthedatabase

34

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Theworkingstatesofthedatabase

35

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Theworkingstatesofthedatabase

36

Wai6ng

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Theworkingstatesofthedatabase

37

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Theworkingstatesofthedatabase

38

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Theworkingstatesofthedatabase

39

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

TheworkingstatesoftheOracleDatabase

40

=Sta6s6cs

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

TheworkingstatesoftheOracleDatabase

41

=Sta6s6cs

=WaitClasses

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

OracleDatabasestaAsAcs•  1804staAsAcsintotalinOracleDB12.2.0.1•  Query:v$sysstat,v$mystat,v$sesstat(v$statname)

•  Forexample:SELECT n.name, s.value FROM v$mystat s, v$statname n WHERE s.statistic#=n.statistic# AND value > 0 ORDER BY n.name;

42

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Oracledatabasewaitclasses•  Administra6ve:WaitsresulAngfromDBAcommandsthatcauseuserstowait(indexrebuild,etc.)

•  Applica6on:WaitsresulAngfromuserapplicaAoncode(lockwaitscausedbyrowlevellockingorexplicitlockcommands)

•  Cluster:WaitsrelatedtoOracleRealApplicaAonClustersresources(globalcacheresourcessuchas'gccrblockbusy')

•  Commit:Thiswaitclassonlycomprisesonewaitevent-waitforredologwriteconfirmaAonaneracommit(thatis,'logfilesync')

•  Concurrency:Waitsforinternaldatabaseresources(latches,cursorpins,etc.)

•  Configura6on:WaitscausedbyinadequateconfiguraAonofdatabaseorinstanceresources(undersizedlogfiles,sharedpool,etc.)

•  Idle:WaitsthatsignifythesessionisinacAve,waiAngforwork('SQL*Netmessagefromclient')

•  Network:Waitsrelatedtonetworkmessaging('SQL*Netmoredatatodblink’)

•  Other:Waitswhichshouldnottypicallyoccuronasystem(forexample,'waitforEMONtospawn')

•  Queueing:DelaysinobtainingaddiAonaldatainapipelinedenvironment.(parallelqueries,orDBMS_PIPEPL/SQLpackages)

•  Scheduler:ResourceManagerrelatedwaits('resmgr:becomeacAve’,etc.)

•  SystemI/O:WaitsforbackgroundprocessI/O(forexample,DBWRwaitfor'dbfileparallelwrite')

•  UserI/O:WaitsforuserI/O(forexample'dbfilesequenAalread')

43

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Oracledatabasewaitclasses•  Forexample:•  SELECT sid, event, p1, p2, p3 FROM v$session_wait ORDER BY sid, event;

44

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

ProgramAgenda

IntroducAon

Whatisperformance

OracleDatabasePerformanceStaAsAcs

Commits–saverofyourdata

Rowbyrow=slowbyslow

Bindvari…–WHAT?

1

2

3

4

5

45

6

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataHowdoesOraclemakesureyourdataisstoredondisk?

46

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataHowdoesOraclemakesureyourdataisstoredondisk?

47

DML(s)

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataHowdoesOraclemakesureyourdataisstoredondisk?

48

DML(s) COMMIT

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataHowdoesOraclemakesureyourdataisstoredondisk?

49

INSERTINTOpurchase(…)

VALUES(:1,:2,:3,…);

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataHowdoesOraclemakesureyourdataisstoredondisk?

50

INSERTINTOpurchase(…)

VALUES(:1,:2,:3,…);

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataHowdoesOraclemakesureyourdataisstoredondisk?

51

INSERTINTOpurchase(…)

VALUES(:1,:2,:3,…);

BufferCache

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataHowdoesOraclemakesureyourdataisstoredondisk?

52

INSERTINTOpurchase(…)

VALUES(:1,:2,:3,…);COMMIT

BufferCache

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataHowdoesOraclemakesureyourdataisstoredondisk?

53

INSERTINTOpurchase(…)

VALUES(:1,:2,:3,…);COMMIT

BufferCache

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataHowdoesOraclemakesureyourdataisstoredondisk?

54

INSERTINTOpurchase(…)

VALUES(:1,:2,:3,…);COMMIT

BufferCache REDOlogs

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataWhathappensonaCOMMIT?

55

DML(s) COMMIT

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataWhathappensonaCOMMIT?

56

GenerateSCN

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataWhathappensonaCOMMIT?

57

GenerateSCN

LGWRwritestoREDOlogs

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataWhathappensonaCOMMIT?

58

GenerateSCN

LGWRwritestoREDOlogs

Releaselocksontables

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataWhathappensonaCOMMIT?

59

GenerateSCN

LGWRwritestoREDOlogs

Releaselocksontables

Removesafe-points

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataWhathappensonaCOMMIT?

60

GenerateSCN

LGWRwritestoREDOlogs

Releaselocksontables

Removesafe-points

Performcommitcleanout

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataWhathappensonaCOMMIT?

61

GenerateSCN

LGWRwritestoREDOlogs

Releaselocksontables

Removesafe-points

Performcommitcleanout

MarkTXN

complete

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdataWhathappensonaCOMMIT?

62

GenerateSCN

LGWRwritestoREDOlogs

Releaselocksontables

Removesafe-points

Performcommitcleanout

MarkTXN

complete

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.| 63

PreparedStatementstmt=conn.prepareStatement( "INSERTINTOTEST(id,text,created_tms,last_upd_tms)VALUES (?,?,SYSDATE,SYSDATE)");

longstart=System.currentTimeMillis();

for(inti=1;i<=rows;i++){stmt.setInt(1,i);stmt.setString(2,"Thisistherowwiththevalueof"+i);stmt.executeUpdate();conn.commit();

}

longend=System.currentTimeMillis();System.out.println("Elapsedtime(ms)forcommitaftereveryrow:"+(end-start));

Commits–saverofyourdata

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.| 64

PreparedStatementstmt=conn.prepareStatement( "INSERTINTOTEST(id,text,created_tms,last_upd_tms)VALUES (?,?,SYSDATE,SYSDATE)");

longstart=System.currentTimeMillis();

for(inti=1;i<=rows;i++){stmt.setInt(1,i);stmt.setString(2,"Thisistherowwiththevalueof"+i);stmt.executeUpdate();

}conn.commit();

longend=System.currentTimeMillis();System.out.println("Elapsedtime(ms)forcommitattheend:"+(end-start));

Commits–saverofyourdata

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

0

10000

20000

30000

40000

50000

60000

Testrun1 Testrun2 Testrun3

Millisecon

ds

Commiteveryrow

Commitatend

•  ThreetestrunsinserAng10krows

•  DarkblueaxisshowselapsedAmewhencommitnganereveryrow

•  LightblueaxisshowselapsedAmewhencommitngonlyonceaneralldataisloaded

65

Commits–saverofyourdata

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Commits–saverofyourdata

• Commitwhenyourbusinesslogicrequiresyouto– Nonrestart-ableworkunitsusuallyrequirecommit•  Paymentprocessing,orderconfirmaAon,ATMwithdrawal,etc.

– Restart-ableworkunitsnormallydon’trequireacommit•  Batchloads,datatransformaAon,etc.

• Commitmeansaroundtriptothedatabase• Remember:Autocommitissettotruebydefaultinalotofdrivers

Whentocommit?

66

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

ProgramAgenda

IntroducAon

Whatisperformance

OracleDatabasePerformanceStaAsAcs

Commits–saverofyourdata

Rowbyrow=slowbyslow

Bindvari…–WHAT?

1

2

3

4

67

6

5

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Rowbyrow–Quiz• Whatwouldyouratherdoonatablewith10millionrows:

68

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Rowbyrow–Quiz• Whatwouldyouratherdoonatablewith10millionrows:PreparedStatementstmt=conn.prepareStatement(

"SELECTvalueFROMPURCHASEWHEREtms>'2016-09-01'");ResultSetrslt=stmt.executeQuery();while(rslt.next()){

val+=rslt.getInt(1);}

69

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Rowbyrow–Quiz• Whatwouldyouratherdoonatablewith10millionrows:PreparedStatementstmt=conn.prepareStatement(

"SELECTvalueFROMPURCHASEWHEREtms>'2016-09-01'");ResultSetrslt=stmt.executeQuery();while(rslt.next()){

val+=rslt.getInt(1);}PreparedStatementstmt=conn.prepareStatement(

"SELECTSUM(value)FROMPURCHASEWHEREtms>'2016-09-01'");ResultSetrslt=stmt.executeQuery();rslt.next();val=rslt.getInt(1);

70

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Rowbyrow–Quiz• Whatwouldyouratherdoonatablewith10millionrows:PreparedStatementstmt=conn.prepareStatement(

"SELECTvalueFROMPURCHASEWHEREtms>'2016-09-01'");ResultSetrslt=stmt.executeQuery();while(rslt.next()){

val+=rslt.getInt(1);}PreparedStatementstmt=conn.prepareStatement(

"SELECTSUM(value)FROMPURCHASEWHEREtms>'2016-09-01'");ResultSetrslt=stmt.executeQuery();rslt.next();val=rslt.getInt(1);

71

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Rowbyrow=Slowbyslow

• Databasesworkbestwithsetbasedprocessing• Processasmuchaspossibleonthesidewhereitmakesmostsense• GenerallyasingleSQLstatementexecuAonisfastest• Avoidunnecessaryroundtrips

72

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.| 73

PreparedStatementstmt=conn.prepareStatement( "INSERTINTOTEST(id,text,created_tms,last_upd_tms)VALUES (?,?,SYSDATE,SYSDATE)");

longstart=System.currentTimeMillis();

for(inti=1;i<=rows;i++){stmt.setInt(1,i);stmt.setString(2,"Thisistherowwiththevalueof"+i);stmt.executeUpdate();

}conn.commit();

longend=System.currentTimeMillis();System.out.println("Elapsedtime(ms)forrowbyrowinsert:"+(end-start));

Rowbyrow=Slowbyslow

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.| 74

PreparedStatementstmt=conn.prepareStatement( "INSERTINTOTEST(id,text,created_tms,last_upd_tms)VALUES (?,?,SYSDATE,SYSDATE)");

longstart=System.currentTimeMillis();

for(inti=1;i<=rows;i++){stmt.setInt(1,i);stmt.setString(2,"Thisistherowwiththevalueof"+i);stmt.addBatch();

}stmt.executeBatch();conn.commit();

longend=System.currentTimeMillis();System.out.println("Elapsedtime(ms)forsetbasedinsert:"+(end-start));

Rowbyrow=Slowbyslow

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

2701628986

26156

85 87 750

5000

10000

15000

20000

25000

30000

35000

Testrun1 Testrun2 Testrun3

Millisecon

ds

Inserteveryrow

Setbasedinsert

•  ThreetestrunsinserAng10krows

•  DarkblueaxisshowselapsedAmeofindividualinserts

•  LightblueaxisshowselapsedAmeofsetbasedinserts

75

Rowbyrow=Slowbyslow

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Rowbyrow=Slowbyslow

• UseDMLerrorlogging– Errorsdon’tabortbatch– Errorsareloggedintoseparateerrortableincludingtheinputdata

•  SQLsyntax:INSERTINTOTEST…LOGERRORS;

Whatabouterrors?

76

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

ProgramAgenda

IntroducAon

Whatisperformance

OracleDatabasePerformanceStaAsAcs

Commits–saverofyourdata

Rowbyrow=slowbyslow

Bindvari…–WHAT?

1

2

3

4

77

6

5

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Bindvari…–WHAT?

•  SQLstatementsarestrings• ButdatamanipulatedviaSQLmaybeofadifferenttypes(Number,Date,…)• Abindvariableallowsyoutobinddatatoanexplicitdatetype– Withouthavingtoconvertthedatatypefromstring– AndwithouthavingtoparsetheSQLstatementagain

Whatarebindvariables

78

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessingHowdoesOracleactuallyprocessyourSQLs?

79

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessingHowdoesOracleactuallyprocessyourSQLs?

80

Parsing

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessingHowdoesOracleactuallyprocessyourSQLs?

81

Parsing Execu6on

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessingHowdoesOracleactuallyprocessyourSQLs?

82

SodParsingHardParsing Execu6on

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–ParsingHowdoesOracleactuallyprocessyourSQLs?

83

SyntaxCheck

IstheSQLsyntaxcorrect?

I.e.didyoutypeFROMandcocorrectly?

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–ParsingHowdoesOracleactuallyprocessyourSQLs?

84

SyntaxCheck

Seman6cCheck

Doesthetablesexist;

doyouhavepermissions,…

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–ParsingHowdoesOracleactuallyprocessyourSQLs?

85

SyntaxCheck

Seman6cCheck

SharedPoolCheck

CreateSQLIDandcheck

whetherithasalreadybeenexecutedbefore

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–ParsingHowdoesOracleactuallyprocessyourSQLs?

86

SyntaxCheck

Seman6cCheck

SharedPoolCheck

AlwayshappensforanygivenqueryVeryfast!

Donebyyoursessionprocess(happensconcurrentlyforeachsession)

Sodparse

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–ParsingHowdoesOracleactuallyprocessyourSQLs?

87

SharedPoolCheck

SQLalreadyexists?

Execu6onYes

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–ParsingHowdoesOracleactuallyprocessyourSQLs?

88

SharedPoolCheck

Execu6on

SQLalreadyexists? No

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–ParsingHowdoesOracleactuallyprocessyourSQLs?

89

SharedPoolCheck

Op6miza6on

Execu6on

SQLalreadyexists?

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–ParsingHowdoesOracleactuallyprocessyourSQLs?

90

SharedPoolCheck

Op6miza6onRowsource

(execu6onplan)genera6on

Execu6on

SQLalreadyexists?

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–ParsingHowdoesOracleactuallyprocessyourSQLs?

91

SharedPoolCheck

Op6miza6onRowsource

(execu6onplan)genera6on

Execu6on

•  CPUintensive•  Checkdatadic6onary•  Checklibrarycache•  Useslatchestoserializeonthosecaches

Hardparse

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–BindvariablesHowdoesOracleactuallyprocessyourSQLs?

92

SELECTtext

FROMTEST

WHERE

id=453;

SQLID:5mwwhtqv204ba

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–BindvariablesHowdoesOracleactuallyprocessyourSQLs?

93

SELECTtext

FROMTEST

WHERE

id=453;

SQLID:5mwwhtqv204ba

SQLID:06jc0z1kcuu6b

SELECTtext

FROMTEST

WHERE

id=879;

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–BindvariablesHowdoesOracleactuallyprocessyourSQLs?

94

SQLID:cknumntjbx8u3

SELECTtext

FROMTEST

WHERE

id=?;

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–BindvariablesHowdoesOracleactuallyprocessyourSQLs?

95

SELECTtext

FROMTEST

WHERE

id=?;

SQLID:cknumntjbx8u3

SELECTtext

FROMTEST

WHERE

id=?;

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SQLprocessing–BindvariablesHowdoesOracleactuallyprocessyourSQLs?

96

SELECTsql_id,sql_text

FROMv$sql

WHEREsql_text

LIKE'%TEST%';

SQL_ID SQL_TEXT

cknumntjbx8u3 SELECTtextFROMTESTWHEREid=:1

5mwwhtqv204ba SELECTtextFROMTESTWHEREid=453

06jc0z1kcuu6b SELECTtextFROMTESTWHEREid=879

3y3unjhrpp9nm SELECTsql_id,sql_textFROMv$sqlWHEREsql_textLIKE'%TEST%'

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

0

500

1000

1500

2000

2500

3000

3500

Testrun1 Testrun2 Testrun3

Millisecon

ds

Selectusingliterals

Selectusingbindvar

•  ThreetestrunsselecAng1krows

•  DarkblueaxisshowselapsedAmeofSELECTusingliterals

•  LightblueaxisshowselapsedAmeofSELECTusingbindvariable

97

Bindvari…-WHAT?

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Usefulresources

• PerformanceTuningGuide•  SQLTuningGuide• DatabaseDevelopmentGuide•  JDBCDeveloper’sGuide• UniversalConnecAonPoolforJDBCDeveloper’sGuide

98

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

Whereisthesource?

github.com/gvenzl/Oracle-JavaOneSuperchargeCodeOp6malDBPerf

99

Copyright©2016,Oracleand/oritsaffiliates.Allrightsreserved.|

SafeHarborStatementTheprecedingisintendedtooutlineourgeneralproductdirecAon.ItisintendedforinformaAonpurposesonly,andmaynotbeincorporatedintoanycontract.Itisnotacommitmenttodeliveranymaterial,code,orfuncAonality,andshouldnotberelieduponinmakingpurchasingdecisions.Thedevelopment,release,andAmingofanyfeaturesorfuncAonalitydescribedforOracle’sproductsremainsatthesolediscreAonofOracle.

100