SlideShare a Scribd company logo
1 of 66
Download to read offline
www.sagecomputing.com.au
penny@sagecomputing.com.au
Transformations – how
Oracle rewrites your
statements
Penny Cookson
SAGE Computing Services
SAGE Computing Services
Customised Oracle Training Workshops and Consulting
Agenda
How to identify transformations
Join Factorisation
Join Elimination
Other Transformations
Effect on Parse Time
Queries in the Select
Identifying Transformations –
Tracing the Optimizer’s decisions
Oracle 10g:
ALTER SYSTEM FLUSH SHARED_POOL;
ALTER SESSION
SET TRACEFILE_IDENTIFIER = ‘events_10053_1’;
ALTER SESSION
SET EVENTS ‘10053 trace name context forever’;
Identifying Transformations –
Tracing the Optimizer’s decisions
Oracle 10g:
Parse the statement:-
SELECT * FROM organisations WHERE postcode = 6000
View the trace file
ALTER SESSION
SET EVENTS ‘10053 trace name context off’
Identifying Transformations –
Tracing the Optimizer’s decisions
Oracle 11g:
ALTER SYSTEM FLUSH SHARED_POOL;
ALTER SESSION
SET TRACEFILE_IDENTIFIER = ‘events_10053_2’;
ALTER SESSION
SET EVENTS
‘trace[rdbms.SQL_Optimizer.*][sql:40038fgx69y23]’;
Identifying Transformations –
Tracing the Optimizer’s decisions
Oracle 11g:
Execute the statement:-
SELECT * FROM organisations WHERE postcode = 6000;
View the trace file
ALTER SESSION
SET EVENTS ‘trace[rdbms.SQL_Optimizer.*] off’;
Identifying Transformations –
Tracing the Optimizer’s decisions
More examples:
ALTER SESSION
SET EVENTS
‘trace[rdbms.SQL_Transform.*][sql:40038fgx69y23]’;
Trace file smaller
Transformations, session optimizer settings and bug fixes only
Identifying Transformations –
Tracing the Optimizer’s decisions
Oracle 11g using DBMS_SQL_DIAG:
Automatically hard parse the statement
BEGIN
dbms_sqldiag.dump_trace (p_sql_id => '40038fgx69y23'
,p_child_number => 0
,p_component => 'Compiler'
,p_file_id => 'events_10053_4');
END;
/
View the trace file dbmsdiag.sql
Identifying Transformations –
Tracing the Optimizer’s decisions
Oracle 11g using DBMS_SQL_DIAG: Is bind aware
DECLARE
v2 number;
cursor c1 (p_code in resources.code%type) is
SELECT /*+BIND_AWARE */ COUNT(l.quantity) FROM train1.bookings_large l WHERE
resource_code = p_code;
BEGIN
open c1 ('PC2');
fetch c1 into v2;
close c1;
open c1 ('BRLG');
fetch c1 into v2;
close c1;
END;
/
Identifying Transformations –
Tracing the Optimizer’s decisions
Oracle 11g using DBMS_SQL_DIAG: Is bind aware
BEGIN
dbms_sqldiag.dump_trace (p_sql_id => '463fjw7fvwmq6'
,p_child_number => 0
,p_component => 'Compiler'
,p_file_id => 'events_10053_11');
END;
/
BEGIN
dbms_sqldiag.dump_trace (p_sql_id => '463fjw7fvwmq6'
,p_child_number => 1
,p_component => 'Compiler'
,p_file_id => 'events_10053_12');
END;
/
View the 11 trace file View the 12 trace file
Join Factorization
TABLE_A
TABLE_A
TABLE_B
TABLE_B
TABLE_C
TABLE_D
UNION ALL
Join Factorization
TABLE_A
TABLE_B
TABLE_B
TABLE_C
TABLE_D
UNION ALL
Join Factorization
alter session set optimizer_features_enable = '11.1.0.7'
SELECT e.description, b.booking_no, b.cost
FROM events_large e, bookings_large b, internal_organisations oi
WHERE e.event_no = b.event_no
AND e.org_id = oi.org_id
AND oi.state = 'WA'
UNION ALL
SELECT e.description, b.booking_no, b.cost
FROM events_large e, bookings_large b, external_organisations oe
WHERE e.event_no = b.event_no
AND e.org_id = oe.org_id
AND oe.state = 'WA'
Version 11.1
Join Factorization
alter session set optimizer_features_enable = '11.2.0.3'
SELECT e.description, b.booking_no, b.cost
FROM events_large e, bookings_large b, internal_organisations oi
WHERE e.event_no = b.event_no
AND e.org_id = oi.org_id
AND oi.state = 'WA'
UNION ALL
SELECT e.description, b.booking_no, b.cost
FROM events_large e, bookings_large b, external_organisations oe
WHERE e.event_no = b.event_no
AND e.org_id = oe.org_id
AND oe.state = 'WA'
Join Factorization
Manual Join Factorization
alter session set optimizer_features_enable = '11.1.0.7'
SELECT evt.description, b.booking_no, b.cost
FROM bookings_large b,
(SELECT e.description, e.event_no
FROM events_large e, internal_organisations oi
WHERE e.org_id = oi.org_id
AND oi.state = 'WA'
UNION ALL
SELECT e.description, e.event_no
FROM events_large e, external_organisations oe
WHERE e.org_id = oe.org_id
AND oe.state = 'WA') evt
WHERE evt.event_no = b.event_no
Manual Join Factorization
How to Avoid Stuffing It Up
UNION (RATHER THAN UNION ALL)
DISTINCT
OUTER JOINS
Join Factorization – This is OK
TABLE_A
TABLE_A
TABLE_B
TABLE_B
TABLE_C
TABLE_D
UNION ALL
(+)
(+)
Join Factorization – This is not OK
TABLE_A
TABLE_A
TABLE_B
TABLE_B
TABLE_C
TABLE_D
UNION ALL
(+)
(+)
(+)
(+)
Join Elimination
Oracle will get rid of joined tables if:
We give it indexes it can use instead
The PK and/or FK relationships imply a table is not required
Its done this for a long time
SELECT b.booking_no, b.resource_code
FROM bookings_large b, events_large e
WHERE b.event_no = e.event_no
AND e.contact_name like 'JOSIE%'
Why constraints are a good idea
SELECT e.description
FROM events e, organisations o
WHERE e.org_id = o.org_id
Constraints matter – they tell the optimiser stuff
Without a foreign key constraint
SELECT e.description
FROM events e, organisations o
WHERE e.org_id = o.org_id
ALTER TABLE events DISABLE
CONSTRAINT org_fk
Without a foreign key constraint
Use RELY for Warehouses
SELECT e.description
FROM events e, organisations o
WHERE e.org_id = o.org_id
ALTER TABLE events MODIFY
CONSTRAINT org_fk RELY;
Join Elimination - this is also OK
SELECT e.description, o.org_id
FROM events e, organisations o
WHERE e.org_id = o.org_id
This won’t do join elimination
SELECT e.description
FROM event_state e, org_state o
WHERE e.org_id = o.org_id
AND e.state = o.state
Multi column primary keys don’t do
Join Elimination
SELECT e.description
FROM event_state e, org_state o
WHERE e.org_id = o.org_id
AND e.state = o.state
SELECT *
FROM user_cons_columns
WHERE constraint_name = 'EVTST_ORG_FK'
Multi column primary keys don’t do
Join Elimination
SELECT e.description
FROM event_state e, org_state o
WHERE e.org_id = o.org_id
SELECT *
FROM user_cons_columns
WHERE constraint_name = 'EVTST_ORG_FK'
Use artificial
sequence
numbers for
Primary Keys
Join Elimination
So who would write that rubbish?
Useful with views where lots of columns are included but not
all selected from the view
Means views with a whole load of unnecessary stuff are not
so bad now
And we have View Merging transformations
CREATE VIEW pretty_stuff_for_users
AS
SELECT o.org_id, o.name,
e.event_no, e.description event_description,
e.start_date, r.description resource_description,
b.booking_no, b.cost, b.quantity, b.resource_code
FROM organisations o, events e, bookings b, resources r
WHERE o.org_id = e.org_id
AND e.event_no = b.event_no
AND b.resource_code = r.code
SELECT booking_no, cost, quantity,
resource_code, resource_description
FROM pretty_stuff_for_users
SELECT e.description
FROM events e, organisations o
WHERE e.org_id = o.org_id
ALTER TABLE events modify (org_id not null)
SELECT booking_no, cost, quantity,
resource_code, resource_description
FROM pretty_stuff_for_users
Join Factorization
Join Factorization
If a column is not
null define it as
NOT NULL
10G – JOIN before the GROUP BY
11G – GROUP BY before the JOIN
10G – NOT IN (PROMISE_NO NULLABLE)
10G – KILLED AFTER 1 hr
11G – Rewrite as Null Aware Anti join
10G – Full Outer Join – default behaviour
From version 10.2.0.3
SELECT /*+ NATIVE_FULL_OUTER_JOIN */
count(e.comments) nume,
count (b.comments) numb
FROM events_large e
FULL OUTER JOIN bookings_large b
ON (e.event_no = b.event_no)
10G – Full Outer Join – hint
11G Native Full Outer Join
SELECT b.booking_no, b.cost, b.quantity,
(SELECT description FROM resources r
WHERE r.code = b.resource_code)
FROM bookings_large b)
SELECT b.booking_no, b.cost, b.quantity,
r.description
FROM bookings_large b, resources r
WHERE b.resource_code = r.code
This is fine and will actually be
more efficient than this
(but may have a different result)
Queries in the SELECT
SELECT b.booking_no, b.cost, b.quantity,
(SELECT description FROM resources r
WHERE r.code = b.resource_code),
(SELECT type_code FROM resources r
WHERE r.code = b.resource_code),
(SELECT daily_rate FROM resources r
WHERE r.code = b.resource_code)
FROM bookings_large b)
This is really stupid and will access the
RESOURCES table multiple times
Queries in the SELECT
SELECT b.booking_no, b.cost, b.quantity,
booking_utl.get_stat1 (
(SELECT description FROM resources r
WHERE r.code = b.resource_code),
(SELECT type_code FROM resources r
WHERE r.code = b.resource_code),
(SELECT daily_rate FROM resources r
WHERE r.code = b.resource_code)),
booking_utl.get_stat2 (
(SELECT description FROM resources r
WHERE r.code = b.resource_code),
(SELECT type_code FROM resources r
WHERE r.code = b.resource_code),
(SELECT daily_rate FROM resources r
WHERE r.code = b.resource_code)),
FROM bookings_large b)
From a real example!!!
Much More Query Transformation
SELECT e.event_no, e.start_date, sum(cost) totcost
FROM events_large e, bookings_large b
WHERE e.event_no = b.event_no
GROUP BY e.event_no, e.start_date
Oracle 10g – Run a whole load of random statements – all of
which require parsing
Oracle 11g – Run a whole load of random statements – all of
which require parsing
So Tuning the Shared
Pool becomes more
important,
but overall the 11g
CBO is pretty smart
Conclusion
Proper relational database design techniques are important
Views are OK
11g will do stuff 10g can’t – get rid of the hints
Developer are encouraged to do stupid stuff
Proper use of the shared pool is important
SAGE Computing Services
Customised Oracle Training Workshops and Consulting
Questions?
www.sagecomputing.com.au
penny@sagecomputing.com.au

More Related Content

What's hot

comboboxentry - glade - ruby - guide
comboboxentry - glade - ruby - guidecomboboxentry - glade - ruby - guide
comboboxentry - glade - ruby - guideArulalan T
 
Drupal csu-open atriumname
Drupal csu-open atriumnameDrupal csu-open atriumname
Drupal csu-open atriumnameEmanuele Quinto
 
Inventory aging report using oracle discoverer desktop
Inventory aging report using oracle discoverer desktopInventory aging report using oracle discoverer desktop
Inventory aging report using oracle discoverer desktopAhmed Elshayeb
 
Miniproject on Employee Management using Perl/Database.
Miniproject on Employee Management using Perl/Database.Miniproject on Employee Management using Perl/Database.
Miniproject on Employee Management using Perl/Database.Sanchit Raut
 
Database performance 101
Database performance 101Database performance 101
Database performance 101Leon Fayer
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using CodeceptionJeroen van Dijk
 
Tim Kunze\'s SQL Server and VB.NET portfolio
Tim Kunze\'s SQL Server and VB.NET portfolioTim Kunze\'s SQL Server and VB.NET portfolio
Tim Kunze\'s SQL Server and VB.NET portfolioTim Kunze
 
Smart Join Algorithms for Fighting Skew at Scale
Smart Join Algorithms for Fighting Skew at ScaleSmart Join Algorithms for Fighting Skew at Scale
Smart Join Algorithms for Fighting Skew at ScaleDatabricks
 
Oracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationOracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationScott Wesley
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answersNawaz Sk
 
Christopher Latham Portfolio
Christopher Latham PortfolioChristopher Latham Portfolio
Christopher Latham Portfoliolathamcl
 
11. CodeIgniter vederea unei singure inregistrari
11. CodeIgniter vederea unei singure inregistrari11. CodeIgniter vederea unei singure inregistrari
11. CodeIgniter vederea unei singure inregistrariRazvan Raducanu, PhD
 
Developing applications for performance
Developing applications for performanceDeveloping applications for performance
Developing applications for performanceLeon Fayer
 
Managing category structures in relational databases
Managing category structures in relational databasesManaging category structures in relational databases
Managing category structures in relational databasesAntoine Osanz
 
How to create payslip through self service
How to create payslip through self serviceHow to create payslip through self service
How to create payslip through self serviceFeras Ahmad
 

What's hot (20)

comboboxentry - glade - ruby - guide
comboboxentry - glade - ruby - guidecomboboxentry - glade - ruby - guide
comboboxentry - glade - ruby - guide
 
Drupal csu-open atriumname
Drupal csu-open atriumnameDrupal csu-open atriumname
Drupal csu-open atriumname
 
Laravel
LaravelLaravel
Laravel
 
Presentation1
Presentation1Presentation1
Presentation1
 
Inventory aging report using oracle discoverer desktop
Inventory aging report using oracle discoverer desktopInventory aging report using oracle discoverer desktop
Inventory aging report using oracle discoverer desktop
 
Miniproject on Employee Management using Perl/Database.
Miniproject on Employee Management using Perl/Database.Miniproject on Employee Management using Perl/Database.
Miniproject on Employee Management using Perl/Database.
 
Database performance 101
Database performance 101Database performance 101
Database performance 101
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using Codeception
 
Tim Kunze\'s SQL Server and VB.NET portfolio
Tim Kunze\'s SQL Server and VB.NET portfolioTim Kunze\'s SQL Server and VB.NET portfolio
Tim Kunze\'s SQL Server and VB.NET portfolio
 
Smart Join Algorithms for Fighting Skew at Scale
Smart Join Algorithms for Fighting Skew at ScaleSmart Join Algorithms for Fighting Skew at Scale
Smart Join Algorithms for Fighting Skew at Scale
 
Array operators
Array operatorsArray operators
Array operators
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
 
Oracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationOracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional Compilation
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answers
 
Christopher Latham Portfolio
Christopher Latham PortfolioChristopher Latham Portfolio
Christopher Latham Portfolio
 
11. CodeIgniter vederea unei singure inregistrari
11. CodeIgniter vederea unei singure inregistrari11. CodeIgniter vederea unei singure inregistrari
11. CodeIgniter vederea unei singure inregistrari
 
Developing applications for performance
Developing applications for performanceDeveloping applications for performance
Developing applications for performance
 
Assignment#07
Assignment#07Assignment#07
Assignment#07
 
Managing category structures in relational databases
Managing category structures in relational databasesManaging category structures in relational databases
Managing category structures in relational databases
 
How to create payslip through self service
How to create payslip through self serviceHow to create payslip through self service
How to create payslip through self service
 

Viewers also liked

Annenberg Digital Lounge, Spring 2016 Report
Annenberg Digital Lounge, Spring 2016 ReportAnnenberg Digital Lounge, Spring 2016 Report
Annenberg Digital Lounge, Spring 2016 ReportCourtney Miller
 
склад та функціонування комп’ютера. Вероніка Бумбу
склад та функціонування комп’ютера. Вероніка Бумбусклад та функціонування комп’ютера. Вероніка Бумбу
склад та функціонування комп’ютера. Вероніка БумбуЖеня Аврам
 
Company Profile FuGenX
Company Profile FuGenXCompany Profile FuGenX
Company Profile FuGenXAshton J
 
Prison psychologist performance appraisal
Prison psychologist performance appraisalPrison psychologist performance appraisal
Prison psychologist performance appraisalsammywood963
 
Bluemix Girl's Night by Keshia - Building a custom HR application
Bluemix Girl's Night by Keshia - Building a custom HR applicationBluemix Girl's Night by Keshia - Building a custom HR application
Bluemix Girl's Night by Keshia - Building a custom HR applicationcraftworkz
 
Internet usage ການນຳໃຊ້ອິນເຕີເນັດ
Internet usage ການນຳໃຊ້ອິນເຕີເນັດInternet usage ການນຳໃຊ້ອິນເຕີເນັດ
Internet usage ການນຳໃຊ້ອິນເຕີເນັດviengkhone
 
list of papers for mrshariati in detail 03302016
list of papers for mrshariati in detail  03302016list of papers for mrshariati in detail  03302016
list of papers for mrshariati in detail 03302016Mohammad reza Shariati
 
2014 sabbathschool lesson_4_4th_quarter
2014 sabbathschool lesson_4_4th_quarter2014 sabbathschool lesson_4_4th_quarter
2014 sabbathschool lesson_4_4th_quarterwisebuli
 
Bệnh Viện Xương Khớp
Bệnh Viện Xương KhớpBệnh Viện Xương Khớp
Bệnh Viện Xương Khớpyasmine699
 
Cdl truck driver performance appraisal
Cdl truck driver performance appraisalCdl truck driver performance appraisal
Cdl truck driver performance appraisalonkyometro
 
English england-terminado
English england-terminadoEnglish england-terminado
English england-terminado1072709860
 

Viewers also liked (15)

Annenberg Digital Lounge, Spring 2016 Report
Annenberg Digital Lounge, Spring 2016 ReportAnnenberg Digital Lounge, Spring 2016 Report
Annenberg Digital Lounge, Spring 2016 Report
 
склад та функціонування комп’ютера. Вероніка Бумбу
склад та функціонування комп’ютера. Вероніка Бумбусклад та функціонування комп’ютера. Вероніка Бумбу
склад та функціонування комп’ютера. Вероніка Бумбу
 
Global media Journal
Global media JournalGlobal media Journal
Global media Journal
 
Company Profile FuGenX
Company Profile FuGenXCompany Profile FuGenX
Company Profile FuGenX
 
Prison psychologist performance appraisal
Prison psychologist performance appraisalPrison psychologist performance appraisal
Prison psychologist performance appraisal
 
Bluemix Girl's Night by Keshia - Building a custom HR application
Bluemix Girl's Night by Keshia - Building a custom HR applicationBluemix Girl's Night by Keshia - Building a custom HR application
Bluemix Girl's Night by Keshia - Building a custom HR application
 
Presentation1
Presentation1Presentation1
Presentation1
 
2
22
2
 
Internet usage ການນຳໃຊ້ອິນເຕີເນັດ
Internet usage ການນຳໃຊ້ອິນເຕີເນັດInternet usage ການນຳໃຊ້ອິນເຕີເນັດ
Internet usage ການນຳໃຊ້ອິນເຕີເນັດ
 
list of papers for mrshariati in detail 03302016
list of papers for mrshariati in detail  03302016list of papers for mrshariati in detail  03302016
list of papers for mrshariati in detail 03302016
 
IPT/WORKSHOP WITH MNC CERTIFICATION - 9382207007
IPT/WORKSHOP WITH MNC CERTIFICATION - 9382207007IPT/WORKSHOP WITH MNC CERTIFICATION - 9382207007
IPT/WORKSHOP WITH MNC CERTIFICATION - 9382207007
 
2014 sabbathschool lesson_4_4th_quarter
2014 sabbathschool lesson_4_4th_quarter2014 sabbathschool lesson_4_4th_quarter
2014 sabbathschool lesson_4_4th_quarter
 
Bệnh Viện Xương Khớp
Bệnh Viện Xương KhớpBệnh Viện Xương Khớp
Bệnh Viện Xương Khớp
 
Cdl truck driver performance appraisal
Cdl truck driver performance appraisalCdl truck driver performance appraisal
Cdl truck driver performance appraisal
 
English england-terminado
English england-terminadoEnglish england-terminado
English england-terminado
 

Similar to Transformations - how Oracle rewrites your statements

Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...Coupa Software
 
Constraint Optimization
Constraint OptimizationConstraint Optimization
Constraint OptimizationOren Nakdimon
 
Sql basics
Sql basicsSql basics
Sql basicsKumar
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersKacper Gunia
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needKacper Gunia
 
Database Development Replication Security Maintenance Report
Database Development Replication Security Maintenance ReportDatabase Development Replication Security Maintenance Report
Database Development Replication Security Maintenance Reportnyin27
 
Les 11 Fb Queries
Les 11 Fb QueriesLes 11 Fb Queries
Les 11 Fb Queriesvivaankumar
 
Them’s the Rules: Using a Rules Engine to Wrangle Complexity
Them’s the Rules: Using a Rules Engine to Wrangle ComplexityThem’s the Rules: Using a Rules Engine to Wrangle Complexity
Them’s the Rules: Using a Rules Engine to Wrangle ComplexityTechWell
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails Mohit Jain
 
Managing Oracle Streams Using Enterprise Manager Grid Control
Managing Oracle Streams Using Enterprise Manager Grid ControlManaging Oracle Streams Using Enterprise Manager Grid Control
Managing Oracle Streams Using Enterprise Manager Grid Controlscottb411
 
Wait Events 10g
Wait Events 10gWait Events 10g
Wait Events 10gsagai
 
Vpd Virtual Private Database By Saurabh
Vpd   Virtual Private Database By SaurabhVpd   Virtual Private Database By Saurabh
Vpd Virtual Private Database By Saurabhguestd83b546
 
Common Coding and Design mistakes (that really mess up performance)
Common Coding and Design mistakes (that really mess up performance)Common Coding and Design mistakes (that really mess up performance)
Common Coding and Design mistakes (that really mess up performance)Sage Computing Services
 
dokumen.tips_spring-boot-actuator.pdf
dokumen.tips_spring-boot-actuator.pdfdokumen.tips_spring-boot-actuator.pdf
dokumen.tips_spring-boot-actuator.pdfAppster1
 

Similar to Transformations - how Oracle rewrites your statements (20)

Meet the CBO in Version 11g
Meet the CBO in Version 11gMeet the CBO in Version 11g
Meet the CBO in Version 11g
 
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
 
Event Sourcing with php
Event Sourcing with phpEvent Sourcing with php
Event Sourcing with php
 
Constraint Optimization
Constraint OptimizationConstraint Optimization
Constraint Optimization
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Sql basics
Sql basicsSql basics
Sql basics
 
Sql General
Sql General Sql General
Sql General
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 
Database Development Replication Security Maintenance Report
Database Development Replication Security Maintenance ReportDatabase Development Replication Security Maintenance Report
Database Development Replication Security Maintenance Report
 
Les 11 Fb Queries
Les 11 Fb QueriesLes 11 Fb Queries
Les 11 Fb Queries
 
Them’s the Rules: Using a Rules Engine to Wrangle Complexity
Them’s the Rules: Using a Rules Engine to Wrangle ComplexityThem’s the Rules: Using a Rules Engine to Wrangle Complexity
Them’s the Rules: Using a Rules Engine to Wrangle Complexity
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
 
Opm mac subledger
Opm mac subledgerOpm mac subledger
Opm mac subledger
 
Managing Oracle Streams Using Enterprise Manager Grid Control
Managing Oracle Streams Using Enterprise Manager Grid ControlManaging Oracle Streams Using Enterprise Manager Grid Control
Managing Oracle Streams Using Enterprise Manager Grid Control
 
Wait Events 10g
Wait Events 10gWait Events 10g
Wait Events 10g
 
R12 MOAC AND PAYABLES
R12 MOAC AND PAYABLESR12 MOAC AND PAYABLES
R12 MOAC AND PAYABLES
 
Vpd Virtual Private Database By Saurabh
Vpd   Virtual Private Database By SaurabhVpd   Virtual Private Database By Saurabh
Vpd Virtual Private Database By Saurabh
 
Common Coding and Design mistakes (that really mess up performance)
Common Coding and Design mistakes (that really mess up performance)Common Coding and Design mistakes (that really mess up performance)
Common Coding and Design mistakes (that really mess up performance)
 
dokumen.tips_spring-boot-actuator.pdf
dokumen.tips_spring-boot-actuator.pdfdokumen.tips_spring-boot-actuator.pdf
dokumen.tips_spring-boot-actuator.pdf
 

More from Sage Computing Services

Bind Peeking - The Endless Tuning Nightmare
Bind Peeking - The Endless Tuning NightmareBind Peeking - The Endless Tuning Nightmare
Bind Peeking - The Endless Tuning NightmareSage Computing Services
 
Back to basics: Simple database web services without the need for SOA
Back to basics: Simple database web services without the need for SOABack to basics: Simple database web services without the need for SOA
Back to basics: Simple database web services without the need for SOASage Computing Services
 
Whose fault is it? - a review of application tuning problems
Whose fault is it? - a review of application tuning problemsWhose fault is it? - a review of application tuning problems
Whose fault is it? - a review of application tuning problemsSage Computing Services
 
New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...Sage Computing Services
 
How Can I tune it When I Can't Change the Code?
How Can I tune it When I Can't Change the Code?How Can I tune it When I Can't Change the Code?
How Can I tune it When I Can't Change the Code?Sage Computing Services
 
Take a load off! Load testing your Oracle APEX or JDeveloper web applications
Take a load off! Load testing your Oracle APEX or JDeveloper web applicationsTake a load off! Load testing your Oracle APEX or JDeveloper web applications
Take a load off! Load testing your Oracle APEX or JDeveloper web applicationsSage Computing Services
 
Application Express - A web development environment for the masses - and for ...
Application Express - A web development environment for the masses - and for ...Application Express - A web development environment for the masses - and for ...
Application Express - A web development environment for the masses - and for ...Sage Computing Services
 
Oracle Discoverer is dead - Where to next for BI?
Oracle Discoverer is dead - Where to next for BI?Oracle Discoverer is dead - Where to next for BI?
Oracle Discoverer is dead - Where to next for BI?Sage Computing Services
 

More from Sage Computing Services (15)

Oracle XML DB - What's in it for me?
Oracle XML DB - What's in it for me?Oracle XML DB - What's in it for me?
Oracle XML DB - What's in it for me?
 
Aspects of 10 Tuning
Aspects of 10 TuningAspects of 10 Tuning
Aspects of 10 Tuning
 
Bind Peeking - The Endless Tuning Nightmare
Bind Peeking - The Endless Tuning NightmareBind Peeking - The Endless Tuning Nightmare
Bind Peeking - The Endless Tuning Nightmare
 
Back to basics: Simple database web services without the need for SOA
Back to basics: Simple database web services without the need for SOABack to basics: Simple database web services without the need for SOA
Back to basics: Simple database web services without the need for SOA
 
Results cache
Results cacheResults cache
Results cache
 
Vpd
VpdVpd
Vpd
 
Whose fault is it? - a review of application tuning problems
Whose fault is it? - a review of application tuning problemsWhose fault is it? - a review of application tuning problems
Whose fault is it? - a review of application tuning problems
 
New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...
 
Lost without a trace
Lost without a traceLost without a trace
Lost without a trace
 
How Can I tune it When I Can't Change the Code?
How Can I tune it When I Can't Change the Code?How Can I tune it When I Can't Change the Code?
How Can I tune it When I Can't Change the Code?
 
Take a load off! Load testing your Oracle APEX or JDeveloper web applications
Take a load off! Load testing your Oracle APEX or JDeveloper web applicationsTake a load off! Load testing your Oracle APEX or JDeveloper web applications
Take a load off! Load testing your Oracle APEX or JDeveloper web applications
 
The Cost Based Optimiser in 11gR2
The Cost Based Optimiser in 11gR2The Cost Based Optimiser in 11gR2
The Cost Based Optimiser in 11gR2
 
Application Express - A web development environment for the masses - and for ...
Application Express - A web development environment for the masses - and for ...Application Express - A web development environment for the masses - and for ...
Application Express - A web development environment for the masses - and for ...
 
OHarmony - How the Optimiser works
OHarmony - How the Optimiser worksOHarmony - How the Optimiser works
OHarmony - How the Optimiser works
 
Oracle Discoverer is dead - Where to next for BI?
Oracle Discoverer is dead - Where to next for BI?Oracle Discoverer is dead - Where to next for BI?
Oracle Discoverer is dead - Where to next for BI?
 

Recently uploaded

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

Transformations - how Oracle rewrites your statements

  • 1. www.sagecomputing.com.au penny@sagecomputing.com.au Transformations – how Oracle rewrites your statements Penny Cookson SAGE Computing Services SAGE Computing Services Customised Oracle Training Workshops and Consulting
  • 2. Agenda How to identify transformations Join Factorisation Join Elimination Other Transformations Effect on Parse Time Queries in the Select
  • 3. Identifying Transformations – Tracing the Optimizer’s decisions Oracle 10g: ALTER SYSTEM FLUSH SHARED_POOL; ALTER SESSION SET TRACEFILE_IDENTIFIER = ‘events_10053_1’; ALTER SESSION SET EVENTS ‘10053 trace name context forever’;
  • 4. Identifying Transformations – Tracing the Optimizer’s decisions Oracle 10g: Parse the statement:- SELECT * FROM organisations WHERE postcode = 6000 View the trace file ALTER SESSION SET EVENTS ‘10053 trace name context off’
  • 5. Identifying Transformations – Tracing the Optimizer’s decisions Oracle 11g: ALTER SYSTEM FLUSH SHARED_POOL; ALTER SESSION SET TRACEFILE_IDENTIFIER = ‘events_10053_2’; ALTER SESSION SET EVENTS ‘trace[rdbms.SQL_Optimizer.*][sql:40038fgx69y23]’;
  • 6. Identifying Transformations – Tracing the Optimizer’s decisions Oracle 11g: Execute the statement:- SELECT * FROM organisations WHERE postcode = 6000; View the trace file ALTER SESSION SET EVENTS ‘trace[rdbms.SQL_Optimizer.*] off’;
  • 7. Identifying Transformations – Tracing the Optimizer’s decisions More examples: ALTER SESSION SET EVENTS ‘trace[rdbms.SQL_Transform.*][sql:40038fgx69y23]’; Trace file smaller Transformations, session optimizer settings and bug fixes only
  • 8. Identifying Transformations – Tracing the Optimizer’s decisions Oracle 11g using DBMS_SQL_DIAG: Automatically hard parse the statement BEGIN dbms_sqldiag.dump_trace (p_sql_id => '40038fgx69y23' ,p_child_number => 0 ,p_component => 'Compiler' ,p_file_id => 'events_10053_4'); END; / View the trace file dbmsdiag.sql
  • 9. Identifying Transformations – Tracing the Optimizer’s decisions Oracle 11g using DBMS_SQL_DIAG: Is bind aware DECLARE v2 number; cursor c1 (p_code in resources.code%type) is SELECT /*+BIND_AWARE */ COUNT(l.quantity) FROM train1.bookings_large l WHERE resource_code = p_code; BEGIN open c1 ('PC2'); fetch c1 into v2; close c1; open c1 ('BRLG'); fetch c1 into v2; close c1; END; /
  • 10. Identifying Transformations – Tracing the Optimizer’s decisions Oracle 11g using DBMS_SQL_DIAG: Is bind aware BEGIN dbms_sqldiag.dump_trace (p_sql_id => '463fjw7fvwmq6' ,p_child_number => 0 ,p_component => 'Compiler' ,p_file_id => 'events_10053_11'); END; / BEGIN dbms_sqldiag.dump_trace (p_sql_id => '463fjw7fvwmq6' ,p_child_number => 1 ,p_component => 'Compiler' ,p_file_id => 'events_10053_12'); END; / View the 11 trace file View the 12 trace file
  • 13. Join Factorization alter session set optimizer_features_enable = '11.1.0.7' SELECT e.description, b.booking_no, b.cost FROM events_large e, bookings_large b, internal_organisations oi WHERE e.event_no = b.event_no AND e.org_id = oi.org_id AND oi.state = 'WA' UNION ALL SELECT e.description, b.booking_no, b.cost FROM events_large e, bookings_large b, external_organisations oe WHERE e.event_no = b.event_no AND e.org_id = oe.org_id AND oe.state = 'WA'
  • 15. Join Factorization alter session set optimizer_features_enable = '11.2.0.3' SELECT e.description, b.booking_no, b.cost FROM events_large e, bookings_large b, internal_organisations oi WHERE e.event_no = b.event_no AND e.org_id = oi.org_id AND oi.state = 'WA' UNION ALL SELECT e.description, b.booking_no, b.cost FROM events_large e, bookings_large b, external_organisations oe WHERE e.event_no = b.event_no AND e.org_id = oe.org_id AND oe.state = 'WA'
  • 17.
  • 18. Manual Join Factorization alter session set optimizer_features_enable = '11.1.0.7' SELECT evt.description, b.booking_no, b.cost FROM bookings_large b, (SELECT e.description, e.event_no FROM events_large e, internal_organisations oi WHERE e.org_id = oi.org_id AND oi.state = 'WA' UNION ALL SELECT e.description, e.event_no FROM events_large e, external_organisations oe WHERE e.org_id = oe.org_id AND oe.state = 'WA') evt WHERE evt.event_no = b.event_no
  • 20. How to Avoid Stuffing It Up UNION (RATHER THAN UNION ALL) DISTINCT OUTER JOINS
  • 21. Join Factorization – This is OK TABLE_A TABLE_A TABLE_B TABLE_B TABLE_C TABLE_D UNION ALL (+) (+)
  • 22. Join Factorization – This is not OK TABLE_A TABLE_A TABLE_B TABLE_B TABLE_C TABLE_D UNION ALL (+) (+) (+) (+)
  • 23. Join Elimination Oracle will get rid of joined tables if: We give it indexes it can use instead The PK and/or FK relationships imply a table is not required
  • 24. Its done this for a long time SELECT b.booking_no, b.resource_code FROM bookings_large b, events_large e WHERE b.event_no = e.event_no AND e.contact_name like 'JOSIE%'
  • 25. Why constraints are a good idea SELECT e.description FROM events e, organisations o WHERE e.org_id = o.org_id Constraints matter – they tell the optimiser stuff
  • 26. Without a foreign key constraint SELECT e.description FROM events e, organisations o WHERE e.org_id = o.org_id ALTER TABLE events DISABLE CONSTRAINT org_fk
  • 27. Without a foreign key constraint
  • 28. Use RELY for Warehouses SELECT e.description FROM events e, organisations o WHERE e.org_id = o.org_id ALTER TABLE events MODIFY CONSTRAINT org_fk RELY;
  • 29. Join Elimination - this is also OK SELECT e.description, o.org_id FROM events e, organisations o WHERE e.org_id = o.org_id
  • 30. This won’t do join elimination SELECT e.description FROM event_state e, org_state o WHERE e.org_id = o.org_id AND e.state = o.state
  • 31. Multi column primary keys don’t do Join Elimination SELECT e.description FROM event_state e, org_state o WHERE e.org_id = o.org_id AND e.state = o.state SELECT * FROM user_cons_columns WHERE constraint_name = 'EVTST_ORG_FK'
  • 32. Multi column primary keys don’t do Join Elimination SELECT e.description FROM event_state e, org_state o WHERE e.org_id = o.org_id SELECT * FROM user_cons_columns WHERE constraint_name = 'EVTST_ORG_FK' Use artificial sequence numbers for Primary Keys
  • 33. Join Elimination So who would write that rubbish? Useful with views where lots of columns are included but not all selected from the view Means views with a whole load of unnecessary stuff are not so bad now And we have View Merging transformations
  • 34. CREATE VIEW pretty_stuff_for_users AS SELECT o.org_id, o.name, e.event_no, e.description event_description, e.start_date, r.description resource_description, b.booking_no, b.cost, b.quantity, b.resource_code FROM organisations o, events e, bookings b, resources r WHERE o.org_id = e.org_id AND e.event_no = b.event_no AND b.resource_code = r.code
  • 35.
  • 36. SELECT booking_no, cost, quantity, resource_code, resource_description FROM pretty_stuff_for_users
  • 37. SELECT e.description FROM events e, organisations o WHERE e.org_id = o.org_id
  • 38. ALTER TABLE events modify (org_id not null) SELECT booking_no, cost, quantity, resource_code, resource_description FROM pretty_stuff_for_users
  • 41.
  • 42. If a column is not null define it as NOT NULL
  • 43. 10G – JOIN before the GROUP BY
  • 44.
  • 45. 11G – GROUP BY before the JOIN
  • 46.
  • 47.
  • 48.
  • 49.
  • 50. 10G – NOT IN (PROMISE_NO NULLABLE)
  • 51. 10G – KILLED AFTER 1 hr
  • 52. 11G – Rewrite as Null Aware Anti join
  • 53.
  • 54. 10G – Full Outer Join – default behaviour
  • 55.
  • 56. From version 10.2.0.3 SELECT /*+ NATIVE_FULL_OUTER_JOIN */ count(e.comments) nume, count (b.comments) numb FROM events_large e FULL OUTER JOIN bookings_large b ON (e.event_no = b.event_no) 10G – Full Outer Join – hint
  • 57. 11G Native Full Outer Join
  • 58.
  • 59. SELECT b.booking_no, b.cost, b.quantity, (SELECT description FROM resources r WHERE r.code = b.resource_code) FROM bookings_large b) SELECT b.booking_no, b.cost, b.quantity, r.description FROM bookings_large b, resources r WHERE b.resource_code = r.code This is fine and will actually be more efficient than this (but may have a different result) Queries in the SELECT
  • 60. SELECT b.booking_no, b.cost, b.quantity, (SELECT description FROM resources r WHERE r.code = b.resource_code), (SELECT type_code FROM resources r WHERE r.code = b.resource_code), (SELECT daily_rate FROM resources r WHERE r.code = b.resource_code) FROM bookings_large b) This is really stupid and will access the RESOURCES table multiple times Queries in the SELECT
  • 61. SELECT b.booking_no, b.cost, b.quantity, booking_utl.get_stat1 ( (SELECT description FROM resources r WHERE r.code = b.resource_code), (SELECT type_code FROM resources r WHERE r.code = b.resource_code), (SELECT daily_rate FROM resources r WHERE r.code = b.resource_code)), booking_utl.get_stat2 ( (SELECT description FROM resources r WHERE r.code = b.resource_code), (SELECT type_code FROM resources r WHERE r.code = b.resource_code), (SELECT daily_rate FROM resources r WHERE r.code = b.resource_code)), FROM bookings_large b) From a real example!!!
  • 62. Much More Query Transformation SELECT e.event_no, e.start_date, sum(cost) totcost FROM events_large e, bookings_large b WHERE e.event_no = b.event_no GROUP BY e.event_no, e.start_date
  • 63. Oracle 10g – Run a whole load of random statements – all of which require parsing
  • 64. Oracle 11g – Run a whole load of random statements – all of which require parsing So Tuning the Shared Pool becomes more important, but overall the 11g CBO is pretty smart
  • 65. Conclusion Proper relational database design techniques are important Views are OK 11g will do stuff 10g can’t – get rid of the hints Developer are encouraged to do stupid stuff Proper use of the shared pool is important
  • 66. SAGE Computing Services Customised Oracle Training Workshops and Consulting Questions? www.sagecomputing.com.au penny@sagecomputing.com.au