sql translaon framework - andy colvin's oracle...
TRANSCRIPT
![Page 1: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/1.jpg)
SQLTransla+onFramework
![Page 2: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/2.jpg)
2
whoami–
NeverWorkedforOracleWorkedwithOracleDBSince1982(V2)WorkforEnkitec
-NowapartofAccentureIusuallywearaballcapHaven’twornaneck+einafewdecadesDecidedlongagothatittakestoolongtogethaircuts
Email:[email protected]:kerryosborne.oracle-guy.comTwiSer:@KerryOracleGuy
![Page 3: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/3.jpg)
WhatisSQLTransla/onFramework?
Featureof12crelease1ProvidescapabilitytotransparentlytranslateSQLCameoutofSQLDeveloperDesignedtotranslatenon-OraclesyntaxBut–providesabilitytocreateyourowntransla+onsJ
![Page 4: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/4.jpg)
WhyAmIinterested?
BecauseSh*tHappens!Performanceissuesoccur-badplans-badSQLIt’so]endifficultor+meconsumingtomakeapplica+onchangesThereareseveralmechanismstochangeplans(hintbased)
BaselinesSQLProfilesSQLPatchesOutlines
![Page 5: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/5.jpg)
Digression:HintBasedMechanisms
ApplysetofhintsbehindthescenesTheydonot“lock”plans
-althoughtheycanappeartohavethataffect
![Page 6: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/6.jpg)
Digression:BaselinesvsSQLProfiles
SQLProfilesDesignedtoapplysta+s+calfixes(fudgefactors)ViaSQLTuningAdvisorUsesopt_es+matehintHowever,theycanbecreatedmanuallywithanyhints
Baselines
DesignedtopreventperformanceregressionAllowformul+pleplansEvolu+onmechanism Knowplan_hash_value
Butsome+mestheSQLhastochange
![Page 7: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/7.jpg)
Wherehintswon’twork
select sum(distinct X) from T1, T2 where T1.start_date < sysdate-7and T2.dept = ‘XYZ’
Blah Blah
MERGE JOIN CARTESIAN
Blah Blah
![Page 8: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/8.jpg)
SQLTransla/onFrameworkCoolness!
12.1Migra+onGuide:Inaddi+ontotransla+ngnon-OracleSQLstatements,theSQLTransla+onFrameworkcanalsobeusedtosubs+tuteanOracleSQLstatementwithanotherOraclestatementtoaddressaseman+coraperformanceissue.Inthisway,youcanaddressanapplica+onissuewithoutpatchingtheclientapplica+on.
![Page 9: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/9.jpg)
BasicMechanics
1. GetAccesstodbms_sql_translator2. CreateTransla+onProfile(create_profile)3. CreateSQLmappings(register_sql_transla+ons)4. TellasessiontousetheProfile5. Setthe10601event
SeeBlogEntry:hSp://kerryosborne.oracle-guy.com/2013/07/sql-transla+on-framework/
![Page 10: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/10.jpg)
Tracing
execDBMS_SQL_TRANSLATOR.SET_ATTRIBUTE(’FOO’,'TRACE_TRANSLATION','TRUE');...SQLTransla+onProfile"SYS"."FOO":originalSQLtext"select/*kso6*/sum(pk_col)fromkso.skew”SQLTransla+onProfile"SYS"."FOO":translatedSQLtext"select/*kso6*/sum(pk_col),count(pk_col)fromkso.skew"
![Page 11: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/11.jpg)
ViewingTransla/onsDBA_SQL_TRANSLATIONS
SYS@gluent> @translations
OWNER PROFILE_NA SQL_TEXT TRANSLATED_TEXT---------- ---------- ------------------------------ ------------------------------SYS FOO select /* kso6 */ sum(pk_col) select /* kso6 */ sum(pk_col), from kso.skew count(pk_col) from kso.skew
SYS FOO select max(col1) from kso.skew select distinct col4 from kso.skew
SYS FOO select /*+ noparallel */ select /*+ noparallel */ a.col2, sum(a.col1) from a.col2, sum(a.col1) from kso.skew3 a, kso.skew b group kso.skew3 a, kso.skew b where by a.col2 a.pk_col = b.pk_col group by a.col2
SYS FOO select 5 from dual delete from dual
![Page 12: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/12.jpg)
ViewingTransla/onsV$MAPPED_SQL
SYS@gluent1> @mapped_sqlEnter value for sql_text: Enter value for mapped_sql_text:
SQL_ID SQL_TEXT MAPPED_SQL_ID MAPPED_SQL_TEXT------------- ------------------------------ ------------- ------------------------------d2vqx2b16ups7 select 22 from dual 355cqk9my0sna select 33 from dual
9fusd37prv595 select 2 from dual d2vqx2b16ups7 select 22 from dual
Note:V$SESSION:SQL_TRANSLATION_PROFILE_ID
![Page 13: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/13.jpg)
Digression:MaterializedViewRewrite
ThereisanAPItotheMaterializedViewRewritemechanismAvailablesince10g?Directaccessprovidedbydbms_advanced_rewriteMorerestric+ons
![Page 14: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/14.jpg)
DBMS_ADVANCED_REWRITErestric/ons
SYS@gluent> @create_rewriteEnter value for rewrite_name: KSO7Enter value for from_statement: select max(col1) from kso.skewEnter value for to_statement: select distinct col4 from kso.skew
BEGIN sys.dbms_advanced_rewrite.declare_rewrite_equivalence ( name => 'KSO7', source_stmt => 'select max(col1) from kso.skew', destination_stmt => 'select distinct col4 from kso.skew', validate => FALSE, rewrite_mode => 'GENERAL' ); END;
*ERROR at line 1:ORA-30389: the source statement is not compatible with the destination statementORA-01790: expression must have same datatype as corresponding expressionORA-06512: at "SYS.DBMS_ADVANCED_REWRITE", line 29ORA-06512: at "SYS.DBMS_ADVANCED_REWRITE", line 185ORA-06512: at line 1
![Page 15: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/15.jpg)
DBMS_ADVANCED_REWRITErestric/ons
SYS@gluent>!oerrora3038930389,00000,"thesourcestatementisnotcompa+blewiththedes+na+onstatement"//*Cause:TheSELECTclauseofthesourcestatementisnotcompa+blewith//theSELECTclauseofthedes+na+onstatement//*Ac+on:VerifybothSELECTclausesarecompa+blewitheachothersuchas//numbersofSELECTlistitemsarethesameandthedatatypefor//eachSELECTlistitemiscompa+ble
![Page 16: SQL Translaon Framework - Andy Colvin's Oracle Blogkerryosborne.oracle-guy.com/papers/SQL_Translation... · 2016-11-22 · SQL Transla/on Framework Coolness! 12.1 Migraon Guide: In](https://reader030.vdocuments.site/reader030/viewer/2022040818/5e64e10c2c8af7036b2c191a/html5/thumbnails/16.jpg)
Demo
IfwehaveinternetaccessJ