SlideShare a Scribd company logo
zen and the art of SQL optimization Karen Morton
 
 
Simplicity
“ Make everything as simple as possible but no simpler. ” Albert Einstein
 
 
“ Normally, we do not so much look at things as   overlook them.” Alan Watts
simple vs simple-minded
Oracle 9.2.0.6 SELECT to_char(   to_date(:B1,‘DD-MON-YYYY’)+1,   ‘DD-MON-YYYY’ )   FROM dual;
What about its effect?
32.9% % of total R
1,087,770 # of executions
3,263,033 # of LIOs
v_date_str :=  to_char(   to_date( :B1,‘DD-MON-YYYY’ ) + 1,   ‘ DD-MON-YYYY’ ) ;
Focus
ETCIBMVIPNASAFBI
ETC IBM VIP NASA FBI
SELECT rowid, load_no, load_status, manifest_no, manifest_date FROM cs_loads  WHERE load_no = 552888 ; VARCHAR2(15) SELECT rowid, load_no, load_status, manifest_no, manifest_date FROM cs_loads  WHERE  load_no = 552888  ; datatype mismatch causes FULL SCAN SELECT rowid, load_no, load_status, manifest_no, manifest_date FROM cs_loads  WHERE load_no =‘552888’;
SELECT rowid, load_no, load_status, manifest_no, manifest_date FROM cs_loads  WHERE load_no = :B1 ;
Keys to Optimizing SQL
Tune the question, not the query.
What output should the query provide?
What special conditions need to be handled?
“ If you don’t know where you are going, you’ll end up somewhere else.” Yogi Berra
Reduce. Reuse.
Decrease row source sizes quickly
Access objects once and reuse the result set
“ Not enough gets said about the importance of abandoning crap.”   - Ira Glass
Practice.
Never stop learning
Stay connected
Think in sets
Test Test Test (then test again)
 
“ Practice, practice, practice. Until it becomes your practice.” Unknown
Going Zen
1
SELECT invoice_id, distribution_line_number  FROM ap.ap_invoice_distributions_all ap2  WHERE ap2.project_id > 0  AND ap2.pa_addition_flag = 'T'  MINUS  SELECT invoice_id, distribution_line_number  FROM ap.ap_invoice_distributions_all ap,  pa.pa_cost_distribution_lines_all pa  WHERE ap.project_id > 0  AND ap.pa_addition_flag = 'T'  AND pa.system_reference2 IS NOT NULL  AND TO_NUMBER(pa.system_reference2) = ap.invoice_id  AND TO_NUMBER(pa.system_reference3) = ap.distribution_line_number  ORDER BY invoice_id;  Elapsed Time  LIO Blocks  PIO Blocks  Total Rows ------------  ----------  ----------  ----------   00:00:20.09  60,941  57,116  6
SELECT invoice_id, distribution_line_number FROM (SELECT invoice_id, distribution_line_number, system_reference2, system_reference3 FROM ap.ap_invoice_distributions_all ap, (SELECT TO_NUMBER(system_reference2) system_reference2, TO_NUMBER(system_reference3) system_reference3 FROM pa.pa_cost_distribution_lines_all WHERE system_reference2 IS NOT NULL) WHERE system_reference2 (+) = ap.invoice_id AND system_reference3 (+) = ap.distribution_line_number AND ap.project_id > 0 AND ap.pa_addition_flag = 'T' ) WHERE system_reference2 IS NULL AND system_reference3 IS NULL ORDER BY invoice_id; Elapsed Time  LIO Blocks  PIO Blocks  Total Rows ------------  ----------  ----------  ----------   00:00:03.09  1,824  453  6
2
SELECT t.* FROM RMS.tasks t, RMS.status s WHERE t.status_id = s.id AND (EXISTS ( SELECT null FROM RMS.tasks ta, RMS.resources r    WHERE t.id = ta.parent_task_id AND ta.project_code = :p   AND ta.task_type_code = 'A' AND ta.resource_id = r.id   AND r.reporting_id = :r )    OR (t.project_code = :p AND  t.task_type_code = 'T') ); Elapsed Time  LIO Blocks  PIO Blocks  Total Rows ------------  ----------  ----------  ----------   00:00:09.50  287,330  992  3
SELECT t.* FROM RMS.tasks t, RMS.status s WHERE t.status_id = s.id AND EXISTS    (SELECT null FROM RMS.tasks ta,RMS.resources r    WHERE t.id = ta.parent_task_id AND ta.project_code = :p  AND ta.task_type_code = 'A' AND ta.resource_id = r.id  AND r.reporting_id = :r ) UNION SELECT t.* FROM RMS.tasks t, RMS.status s WHERE t.status_id = s.id AND t.id IN  (SELECT t.parent_task_id FROM RMS.tasks t, RMS.status s    WHERE t.status_id = s.id AND EXISTS (SELECT null FROM RMS.tasks ta, RMS.resources r    WHERE t.id = ta.parent_task_id AND ta.project_code = :p    AND ta.task_type_code = 'A' AND ta.resource_id = r.id    AND r.reporting_id = :r ); Elapsed Time  LIO Blocks  PIO Blocks  Total Rows ------------  ----------  ----------  ----------   00:00:00.01  128  0  3
3
SELECT J.emplid, J.empl_rcd, J.effdt, J.effseq  FROM PS_JOB J  WHERE J.effdt = (SELECT MAX(effdt) FROM PS_JOB    WHERE emplid = J.emplid   AND empl_rcd = J.empl_rcd   AND effdt <= SYSDATE )  AND J. effseq = (SELECT MAX(effseq) FROM PS_JOB    WHERE emplid = J.emplid    AND empl_rcd = J.empl_rcd    AND effdt = J.effdt ) ; Elapsed Time  LIO Blocks  PIO Blocks  Total Rows ------------  ----------  ----------  ----------   00:00:08.04  337,908  0  30,107
SELECT J.emplid, J.empl_rcd, J.effdt, J.effseq  FROM  (SELECT J.emplid, J.empl_rcd, J.effdt, J.effseq, MAX(J.effdt)    OVER (PARTITION BY J.emplid, J.empl_rcd ) max_effdt,  LAST_VALUE(J.effseq) OVER (PARTITION BY J.emplid, J.empl_rcd ORDER BY J.efdt, J.effseq ROWS BETWEEN CURRENT ROW AND    UNBOUNDED FOLLOWING ) max_effseq   FROM PS_JOB J  WHERE J.effdt <= SYSDATE ) J  WHERE J.effdt = J.max_effdt AND J.effseq = J.max_effseq; Elapsed Time  LIO Blocks  PIO Blocks  Total Rows ------------  ----------  ----------  ----------   00:00:00.44  1,009  0  30,107
4
SELECT utrsotp_desc FROM utrsotp, ucbsvco WHERE ucbsvco_sotp_code = utrsotp_code AND ucbsvco_dispatch_date = (SELECT MAX(ucbsvco_dispatch_date) FROM ucbsvco WHERE ucbsvco_cust_code = 1320908 AND ucbsvco_prem_code = '507601' AND ucbsvco_stus_code = 'C' AND ucbsvco_dispatch_ind IS NOT NULL) AND ucbsvco_stus_code = 'C' AND ucbsvco_dispatch_ind IS NOT NULL Elapsed Time  LIO Blocks  PIO Blocks  Total Rows ------------  ----------  ----------  ----------   00:00:20.16  106,693  0  1
SELECT utrsotp_desc FROM utrsotp, (SELECT ucbsvco_sotp_code, ucbsvco_dispatch_date, MAX(ucbsvco_dispatch_date) OVER(PARTITION BY    ucbsvco_cust_code, ucbsvco_prem_code) max_dispatch_dt FROM ucbsvco WHERE ucbsvco_cust_code = 1320908 AND ucbsvco_prem_code = '507601' AND ucbsvco_stus_code = 'C' AND ucbsvco_dispatch_ind IS NOT NULL) svco WHERE svco.ucbsvco_dispatch_date = svco.max_dispatch_dt AND svco.ucbsvco_sotp_code = utrsotp_code Elapsed Time  LIO Blocks  PIO Blocks  Total Rows ------------  ----------  ----------  ----------   00:00:00.18  15  0  1
 
Simplicity is powerful…
… but it is neither simple nor easy to achieve.
It is obtained  through the careful reduction of the nonessential.
While simplicity is the goal…
… it is possible to be “too simple.”
Your job is to find the balance most appropriate to your situation.
Thank You
http://www.method-r.com http://karenmorton.blogspot.com [email_address]

More Related Content

What's hot (20)

Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
JungMinSEO5
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
Connor McDonald
 
List intersection for web search: Algorithms, Cost Models, and Optimizations
List intersection for web search: Algorithms, Cost Models, and OptimizationsList intersection for web search: Algorithms, Cost Models, and Optimizations
List intersection for web search: Algorithms, Cost Models, and Optimizations
Sunghwan Kim
 
Ramco C Question Paper 2003
Ramco  C  Question  Paper 2003Ramco  C  Question  Paper 2003
Ramco C Question Paper 2003
ncct
 
4th Semeste Electronics and Communication Engineering (Dec-2015; Jan-2016) Qu...
4th Semeste Electronics and Communication Engineering (Dec-2015; Jan-2016) Qu...4th Semeste Electronics and Communication Engineering (Dec-2015; Jan-2016) Qu...
4th Semeste Electronics and Communication Engineering (Dec-2015; Jan-2016) Qu...
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
AST: threats and opportunities
AST: threats and opportunitiesAST: threats and opportunities
AST: threats and opportunities
Alexander Lifanov
 
Fine-grained Processing of CVS Archives with APFEL
Fine-grained Processing of CVS Archives with APFELFine-grained Processing of CVS Archives with APFEL
Fine-grained Processing of CVS Archives with APFEL
Thomas Zimmermann
 
The Five Best Things To Happen To SQL
The Five Best Things To Happen To SQLThe Five Best Things To Happen To SQL
The Five Best Things To Happen To SQL
Connor McDonald
 
3rd Semeste Electronics and Communication Engineering (Dec-2015; Jan-2016) Qu...
3rd Semeste Electronics and Communication Engineering (Dec-2015; Jan-2016) Qu...3rd Semeste Electronics and Communication Engineering (Dec-2015; Jan-2016) Qu...
3rd Semeste Electronics and Communication Engineering (Dec-2015; Jan-2016) Qu...
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
mysql 高级优化之 理解索引使用
mysql 高级优化之 理解索引使用mysql 高级优化之 理解索引使用
mysql 高级优化之 理解索引使用
nigel889
 
5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment 5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment
pcnmtutorials
 
FØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
FØCAL Boston AiR - Computer Vision Tracing and Hardware SimulationFØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
FØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
FØCAL
 
5th Semester Mechanical Engineering (2013-June) Question Papers
5th Semester Mechanical Engineering (2013-June) Question Papers 5th Semester Mechanical Engineering (2013-June) Question Papers
5th Semester Mechanical Engineering (2013-June) Question Papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
Gregoire Lejeune
 
Merge sort
Merge sortMerge sort
Merge sort
Aadhrit Attire
 
4th Semester M Tech: VLSI Design and Embedded System (June-2016) Question Papers
4th Semester M Tech: VLSI Design and Embedded System (June-2016) Question Papers4th Semester M Tech: VLSI Design and Embedded System (June-2016) Question Papers
4th Semester M Tech: VLSI Design and Embedded System (June-2016) Question Papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
8th Semester (June; July-2014) Mechanical Engineering Question Papers
8th Semester (June; July-2014) Mechanical Engineering Question Papers8th Semester (June; July-2014) Mechanical Engineering Question Papers
8th Semester (June; July-2014) Mechanical Engineering Question Papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
5th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...
5th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...5th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...
5th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Machine Learning Model Bakeoff
Machine Learning Model BakeoffMachine Learning Model Bakeoff
Machine Learning Model Bakeoff
mrphilroth
 
8th Semester Mechanical Engineering (June/July-2015) Question Papers
8th Semester Mechanical Engineering  (June/July-2015) Question Papers8th Semester Mechanical Engineering  (June/July-2015) Question Papers
8th Semester Mechanical Engineering (June/July-2015) Question Papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
JungMinSEO5
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
Connor McDonald
 
List intersection for web search: Algorithms, Cost Models, and Optimizations
List intersection for web search: Algorithms, Cost Models, and OptimizationsList intersection for web search: Algorithms, Cost Models, and Optimizations
List intersection for web search: Algorithms, Cost Models, and Optimizations
Sunghwan Kim
 
Ramco C Question Paper 2003
Ramco  C  Question  Paper 2003Ramco  C  Question  Paper 2003
Ramco C Question Paper 2003
ncct
 
AST: threats and opportunities
AST: threats and opportunitiesAST: threats and opportunities
AST: threats and opportunities
Alexander Lifanov
 
Fine-grained Processing of CVS Archives with APFEL
Fine-grained Processing of CVS Archives with APFELFine-grained Processing of CVS Archives with APFEL
Fine-grained Processing of CVS Archives with APFEL
Thomas Zimmermann
 
The Five Best Things To Happen To SQL
The Five Best Things To Happen To SQLThe Five Best Things To Happen To SQL
The Five Best Things To Happen To SQL
Connor McDonald
 
mysql 高级优化之 理解索引使用
mysql 高级优化之 理解索引使用mysql 高级优化之 理解索引使用
mysql 高级优化之 理解索引使用
nigel889
 
5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment 5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment
pcnmtutorials
 
FØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
FØCAL Boston AiR - Computer Vision Tracing and Hardware SimulationFØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
FØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
FØCAL
 
Machine Learning Model Bakeoff
Machine Learning Model BakeoffMachine Learning Model Bakeoff
Machine Learning Model Bakeoff
mrphilroth
 

Viewers also liked (20)

London magento
London magentoLondon magento
London magento
Gareth Knight
 
Introduction Presentation for LinkedUp kickoff meeting
Introduction Presentation for LinkedUp kickoff meetingIntroduction Presentation for LinkedUp kickoff meeting
Introduction Presentation for LinkedUp kickoff meeting
Hendrik Drachsler
 
Do dodane vrednosti s Twitterjem in drugimi socialnimi orodji
Do dodane vrednosti s Twitterjem in drugimi socialnimi orodjiDo dodane vrednosti s Twitterjem in drugimi socialnimi orodji
Do dodane vrednosti s Twitterjem in drugimi socialnimi orodji
Danilo Tic
 
Workplace etiquettes
Workplace etiquettesWorkplace etiquettes
Workplace etiquettes
SIVA GOPAL
 
Analisis crítico del texto
Analisis crítico del textoAnalisis crítico del texto
Analisis crítico del texto
Marcela Ibaceta
 
Mwomen
MwomenMwomen
Mwomen
Amit Ambastha
 
Youth Campaigns & Social Media - Oct 2008
Youth Campaigns & Social Media -  Oct 2008Youth Campaigns & Social Media -  Oct 2008
Youth Campaigns & Social Media - Oct 2008
Charlie Hunter-Schyff
 
Product Development at the Smithsonian Libraries
Product Development at the Smithsonian LibrariesProduct Development at the Smithsonian Libraries
Product Development at the Smithsonian Libraries
eclemrush
 
LinkedUp kickoff meeting session 4
LinkedUp kickoff meeting session 4LinkedUp kickoff meeting session 4
LinkedUp kickoff meeting session 4
Hendrik Drachsler
 
Open Science
Open ScienceOpen Science
Open Science
Hendrik Drachsler
 
Data Sets as Facilitator for new Products and Services for Universities
Data Sets as Facilitator for new Products and Services for UniversitiesData Sets as Facilitator for new Products and Services for Universities
Data Sets as Facilitator for new Products and Services for Universities
Hendrik Drachsler
 
Anh Chuyen ve Chua Hai Dong Giesu
Anh Chuyen ve Chua Hai Dong GiesuAnh Chuyen ve Chua Hai Dong Giesu
Anh Chuyen ve Chua Hai Dong Giesu
Phuc Nguyen Thanh
 
Inbound Marketing Explained
Inbound Marketing ExplainedInbound Marketing Explained
Inbound Marketing Explained
Eddie Choi
 
Jisc RSC Wales ISS 260213
Jisc RSC Wales ISS 260213Jisc RSC Wales ISS 260213
Jisc RSC Wales ISS 260213
Lis Parcell
 
'Fotografia privata' su Web: microstorie del Novecento
'Fotografia privata' su Web: microstorie del Novecento'Fotografia privata' su Web: microstorie del Novecento
'Fotografia privata' su Web: microstorie del Novecento
stefanogambari
 
コミュニケーションソフトウェアを創るということ
コミュニケーションソフトウェアを創るということコミュニケーションソフトウェアを創るということ
コミュニケーションソフトウェアを創るということ
Kazuho Oku
 
Gauteng Freeways
Gauteng FreewaysGauteng Freeways
Gauteng Freeways
guest85be6a
 
The Diy Marketers Guide To A Magnetic Marketing
The Diy Marketers  Guide To A Magnetic MarketingThe Diy Marketers  Guide To A Magnetic Marketing
The Diy Marketers Guide To A Magnetic Marketing
DIYMarketers
 
Garter Snake by A.J.Delorme
Garter Snake by A.J.DelormeGarter Snake by A.J.Delorme
Garter Snake by A.J.Delorme
vebrya
 
Collecting and utilizing assessment information
Collecting and utilizing assessment informationCollecting and utilizing assessment information
Collecting and utilizing assessment information
Jennifer Orr
 
Introduction Presentation for LinkedUp kickoff meeting
Introduction Presentation for LinkedUp kickoff meetingIntroduction Presentation for LinkedUp kickoff meeting
Introduction Presentation for LinkedUp kickoff meeting
Hendrik Drachsler
 
Do dodane vrednosti s Twitterjem in drugimi socialnimi orodji
Do dodane vrednosti s Twitterjem in drugimi socialnimi orodjiDo dodane vrednosti s Twitterjem in drugimi socialnimi orodji
Do dodane vrednosti s Twitterjem in drugimi socialnimi orodji
Danilo Tic
 
Workplace etiquettes
Workplace etiquettesWorkplace etiquettes
Workplace etiquettes
SIVA GOPAL
 
Analisis crítico del texto
Analisis crítico del textoAnalisis crítico del texto
Analisis crítico del texto
Marcela Ibaceta
 
Youth Campaigns & Social Media - Oct 2008
Youth Campaigns & Social Media -  Oct 2008Youth Campaigns & Social Media -  Oct 2008
Youth Campaigns & Social Media - Oct 2008
Charlie Hunter-Schyff
 
Product Development at the Smithsonian Libraries
Product Development at the Smithsonian LibrariesProduct Development at the Smithsonian Libraries
Product Development at the Smithsonian Libraries
eclemrush
 
LinkedUp kickoff meeting session 4
LinkedUp kickoff meeting session 4LinkedUp kickoff meeting session 4
LinkedUp kickoff meeting session 4
Hendrik Drachsler
 
Data Sets as Facilitator for new Products and Services for Universities
Data Sets as Facilitator for new Products and Services for UniversitiesData Sets as Facilitator for new Products and Services for Universities
Data Sets as Facilitator for new Products and Services for Universities
Hendrik Drachsler
 
Anh Chuyen ve Chua Hai Dong Giesu
Anh Chuyen ve Chua Hai Dong GiesuAnh Chuyen ve Chua Hai Dong Giesu
Anh Chuyen ve Chua Hai Dong Giesu
Phuc Nguyen Thanh
 
Inbound Marketing Explained
Inbound Marketing ExplainedInbound Marketing Explained
Inbound Marketing Explained
Eddie Choi
 
Jisc RSC Wales ISS 260213
Jisc RSC Wales ISS 260213Jisc RSC Wales ISS 260213
Jisc RSC Wales ISS 260213
Lis Parcell
 
'Fotografia privata' su Web: microstorie del Novecento
'Fotografia privata' su Web: microstorie del Novecento'Fotografia privata' su Web: microstorie del Novecento
'Fotografia privata' su Web: microstorie del Novecento
stefanogambari
 
コミュニケーションソフトウェアを創るということ
コミュニケーションソフトウェアを創るということコミュニケーションソフトウェアを創るということ
コミュニケーションソフトウェアを創るということ
Kazuho Oku
 
Gauteng Freeways
Gauteng FreewaysGauteng Freeways
Gauteng Freeways
guest85be6a
 
The Diy Marketers Guide To A Magnetic Marketing
The Diy Marketers  Guide To A Magnetic MarketingThe Diy Marketers  Guide To A Magnetic Marketing
The Diy Marketers Guide To A Magnetic Marketing
DIYMarketers
 
Garter Snake by A.J.Delorme
Garter Snake by A.J.DelormeGarter Snake by A.J.Delorme
Garter Snake by A.J.Delorme
vebrya
 
Collecting and utilizing assessment information
Collecting and utilizing assessment informationCollecting and utilizing assessment information
Collecting and utilizing assessment information
Jennifer Orr
 
Ad

Similar to zen and the art of SQL optimization (20)

Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdfDatabase & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
InSync2011
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
Saurabh K. Gupta
 
SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013
Connor McDonald
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer Disasters
Connor McDonald
 
On Seeing Double in V$SQL_Thomas_Kytepdf
On Seeing Double in V$SQL_Thomas_KytepdfOn Seeing Double in V$SQL_Thomas_Kytepdf
On Seeing Double in V$SQL_Thomas_Kytepdf
cookie1969
 
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
 
Debugging Ruby
Debugging RubyDebugging Ruby
Debugging Ruby
Aman Gupta
 
Loopback.vhd
Loopback.vhdLoopback.vhd
Loopback.vhd
sachindb9
 
A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013
Connor McDonald
 
Debugging Ruby Systems
Debugging Ruby SystemsDebugging Ruby Systems
Debugging Ruby Systems
Engine Yard
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所
Hiroshi Sekiguchi
 
Show innodb status
Show innodb statusShow innodb status
Show innodb status
justlooks
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
Connor McDonald
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
Wim Godden
 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humans
Craig Kerstiens
 
Oracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and riversOracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and rivers
Cary Millsap
 
Formal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractFormal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction Contract
Gera Shegalov
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
Connor McDonald
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
Connor McDonald
 
12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan Directives
Franck Pachot
 
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdfDatabase & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
InSync2011
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
Saurabh K. Gupta
 
SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013
Connor McDonald
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer Disasters
Connor McDonald
 
On Seeing Double in V$SQL_Thomas_Kytepdf
On Seeing Double in V$SQL_Thomas_KytepdfOn Seeing Double in V$SQL_Thomas_Kytepdf
On Seeing Double in V$SQL_Thomas_Kytepdf
cookie1969
 
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
 
Debugging Ruby
Debugging RubyDebugging Ruby
Debugging Ruby
Aman Gupta
 
Loopback.vhd
Loopback.vhdLoopback.vhd
Loopback.vhd
sachindb9
 
A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013
Connor McDonald
 
Debugging Ruby Systems
Debugging Ruby SystemsDebugging Ruby Systems
Debugging Ruby Systems
Engine Yard
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所
Hiroshi Sekiguchi
 
Show innodb status
Show innodb statusShow innodb status
Show innodb status
justlooks
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
Connor McDonald
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
Wim Godden
 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humans
Craig Kerstiens
 
Oracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and riversOracle trace data collection errors: the story about oceans, islands, and rivers
Oracle trace data collection errors: the story about oceans, islands, and rivers
Cary Millsap
 
Formal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractFormal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction Contract
Gera Shegalov
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
Connor McDonald
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
Connor McDonald
 
12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan Directives
Franck Pachot
 
Ad

More from Karen Morton (6)

Managing SQL Performance
Managing SQL PerformanceManaging SQL Performance
Managing SQL Performance
Karen Morton
 
Managing Statistics for Optimal Query Performance
Managing Statistics for Optimal Query PerformanceManaging Statistics for Optimal Query Performance
Managing Statistics for Optimal Query Performance
Karen Morton
 
The Oracle Advisors from a Different Perspective
The Oracle Advisors from a Different PerspectiveThe Oracle Advisors from a Different Perspective
The Oracle Advisors from a Different Perspective
Karen Morton
 
Managing Statistics for Optimal Query Performance
Managing Statistics for Optimal Query PerformanceManaging Statistics for Optimal Query Performance
Managing Statistics for Optimal Query Performance
Karen Morton
 
Performance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, HowPerformance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, How
Karen Morton
 
Are you a monkey or an astronaut?
Are you a monkey or an astronaut?Are you a monkey or an astronaut?
Are you a monkey or an astronaut?
Karen Morton
 
Managing SQL Performance
Managing SQL PerformanceManaging SQL Performance
Managing SQL Performance
Karen Morton
 
Managing Statistics for Optimal Query Performance
Managing Statistics for Optimal Query PerformanceManaging Statistics for Optimal Query Performance
Managing Statistics for Optimal Query Performance
Karen Morton
 
The Oracle Advisors from a Different Perspective
The Oracle Advisors from a Different PerspectiveThe Oracle Advisors from a Different Perspective
The Oracle Advisors from a Different Perspective
Karen Morton
 
Managing Statistics for Optimal Query Performance
Managing Statistics for Optimal Query PerformanceManaging Statistics for Optimal Query Performance
Managing Statistics for Optimal Query Performance
Karen Morton
 
Performance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, HowPerformance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, How
Karen Morton
 
Are you a monkey or an astronaut?
Are you a monkey or an astronaut?Are you a monkey or an astronaut?
Are you a monkey or an astronaut?
Karen Morton
 

Recently uploaded (20)

Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
How to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptxHow to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
How to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptxHow to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 

zen and the art of SQL optimization

  • 1. zen and the art of SQL optimization Karen Morton
  • 2.  
  • 3.  
  • 5. “ Make everything as simple as possible but no simpler. ” Albert Einstein
  • 6.  
  • 7.  
  • 8. “ Normally, we do not so much look at things as overlook them.” Alan Watts
  • 10. Oracle 9.2.0.6 SELECT to_char( to_date(:B1,‘DD-MON-YYYY’)+1, ‘DD-MON-YYYY’ ) FROM dual;
  • 11. What about its effect?
  • 12. 32.9% % of total R
  • 13. 1,087,770 # of executions
  • 15. v_date_str := to_char( to_date( :B1,‘DD-MON-YYYY’ ) + 1, ‘ DD-MON-YYYY’ ) ;
  • 16. Focus
  • 18. ETC IBM VIP NASA FBI
  • 19. SELECT rowid, load_no, load_status, manifest_no, manifest_date FROM cs_loads WHERE load_no = 552888 ; VARCHAR2(15) SELECT rowid, load_no, load_status, manifest_no, manifest_date FROM cs_loads WHERE load_no = 552888 ; datatype mismatch causes FULL SCAN SELECT rowid, load_no, load_status, manifest_no, manifest_date FROM cs_loads WHERE load_no =‘552888’;
  • 20. SELECT rowid, load_no, load_status, manifest_no, manifest_date FROM cs_loads WHERE load_no = :B1 ;
  • 22. Tune the question, not the query.
  • 23. What output should the query provide?
  • 24. What special conditions need to be handled?
  • 25. “ If you don’t know where you are going, you’ll end up somewhere else.” Yogi Berra
  • 27. Decrease row source sizes quickly
  • 28. Access objects once and reuse the result set
  • 29. “ Not enough gets said about the importance of abandoning crap.” - Ira Glass
  • 34. Test Test Test (then test again)
  • 35.  
  • 36. “ Practice, practice, practice. Until it becomes your practice.” Unknown
  • 38. 1
  • 39. SELECT invoice_id, distribution_line_number FROM ap.ap_invoice_distributions_all ap2 WHERE ap2.project_id > 0 AND ap2.pa_addition_flag = 'T' MINUS SELECT invoice_id, distribution_line_number FROM ap.ap_invoice_distributions_all ap, pa.pa_cost_distribution_lines_all pa WHERE ap.project_id > 0 AND ap.pa_addition_flag = 'T' AND pa.system_reference2 IS NOT NULL AND TO_NUMBER(pa.system_reference2) = ap.invoice_id AND TO_NUMBER(pa.system_reference3) = ap.distribution_line_number ORDER BY invoice_id; Elapsed Time LIO Blocks PIO Blocks Total Rows ------------ ---------- ---------- ---------- 00:00:20.09 60,941 57,116 6
  • 40. SELECT invoice_id, distribution_line_number FROM (SELECT invoice_id, distribution_line_number, system_reference2, system_reference3 FROM ap.ap_invoice_distributions_all ap, (SELECT TO_NUMBER(system_reference2) system_reference2, TO_NUMBER(system_reference3) system_reference3 FROM pa.pa_cost_distribution_lines_all WHERE system_reference2 IS NOT NULL) WHERE system_reference2 (+) = ap.invoice_id AND system_reference3 (+) = ap.distribution_line_number AND ap.project_id > 0 AND ap.pa_addition_flag = 'T' ) WHERE system_reference2 IS NULL AND system_reference3 IS NULL ORDER BY invoice_id; Elapsed Time LIO Blocks PIO Blocks Total Rows ------------ ---------- ---------- ---------- 00:00:03.09 1,824 453 6
  • 41. 2
  • 42. SELECT t.* FROM RMS.tasks t, RMS.status s WHERE t.status_id = s.id AND (EXISTS ( SELECT null FROM RMS.tasks ta, RMS.resources r WHERE t.id = ta.parent_task_id AND ta.project_code = :p AND ta.task_type_code = 'A' AND ta.resource_id = r.id AND r.reporting_id = :r ) OR (t.project_code = :p AND t.task_type_code = 'T') ); Elapsed Time LIO Blocks PIO Blocks Total Rows ------------ ---------- ---------- ---------- 00:00:09.50 287,330 992 3
  • 43. SELECT t.* FROM RMS.tasks t, RMS.status s WHERE t.status_id = s.id AND EXISTS (SELECT null FROM RMS.tasks ta,RMS.resources r WHERE t.id = ta.parent_task_id AND ta.project_code = :p AND ta.task_type_code = 'A' AND ta.resource_id = r.id AND r.reporting_id = :r ) UNION SELECT t.* FROM RMS.tasks t, RMS.status s WHERE t.status_id = s.id AND t.id IN (SELECT t.parent_task_id FROM RMS.tasks t, RMS.status s WHERE t.status_id = s.id AND EXISTS (SELECT null FROM RMS.tasks ta, RMS.resources r WHERE t.id = ta.parent_task_id AND ta.project_code = :p AND ta.task_type_code = 'A' AND ta.resource_id = r.id AND r.reporting_id = :r ); Elapsed Time LIO Blocks PIO Blocks Total Rows ------------ ---------- ---------- ---------- 00:00:00.01 128 0 3
  • 44. 3
  • 45. SELECT J.emplid, J.empl_rcd, J.effdt, J.effseq FROM PS_JOB J WHERE J.effdt = (SELECT MAX(effdt) FROM PS_JOB WHERE emplid = J.emplid AND empl_rcd = J.empl_rcd AND effdt <= SYSDATE ) AND J. effseq = (SELECT MAX(effseq) FROM PS_JOB WHERE emplid = J.emplid AND empl_rcd = J.empl_rcd AND effdt = J.effdt ) ; Elapsed Time LIO Blocks PIO Blocks Total Rows ------------ ---------- ---------- ---------- 00:00:08.04 337,908 0 30,107
  • 46. SELECT J.emplid, J.empl_rcd, J.effdt, J.effseq FROM (SELECT J.emplid, J.empl_rcd, J.effdt, J.effseq, MAX(J.effdt) OVER (PARTITION BY J.emplid, J.empl_rcd ) max_effdt, LAST_VALUE(J.effseq) OVER (PARTITION BY J.emplid, J.empl_rcd ORDER BY J.efdt, J.effseq ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING ) max_effseq FROM PS_JOB J WHERE J.effdt <= SYSDATE ) J WHERE J.effdt = J.max_effdt AND J.effseq = J.max_effseq; Elapsed Time LIO Blocks PIO Blocks Total Rows ------------ ---------- ---------- ---------- 00:00:00.44 1,009 0 30,107
  • 47. 4
  • 48. SELECT utrsotp_desc FROM utrsotp, ucbsvco WHERE ucbsvco_sotp_code = utrsotp_code AND ucbsvco_dispatch_date = (SELECT MAX(ucbsvco_dispatch_date) FROM ucbsvco WHERE ucbsvco_cust_code = 1320908 AND ucbsvco_prem_code = '507601' AND ucbsvco_stus_code = 'C' AND ucbsvco_dispatch_ind IS NOT NULL) AND ucbsvco_stus_code = 'C' AND ucbsvco_dispatch_ind IS NOT NULL Elapsed Time LIO Blocks PIO Blocks Total Rows ------------ ---------- ---------- ---------- 00:00:20.16 106,693 0 1
  • 49. SELECT utrsotp_desc FROM utrsotp, (SELECT ucbsvco_sotp_code, ucbsvco_dispatch_date, MAX(ucbsvco_dispatch_date) OVER(PARTITION BY ucbsvco_cust_code, ucbsvco_prem_code) max_dispatch_dt FROM ucbsvco WHERE ucbsvco_cust_code = 1320908 AND ucbsvco_prem_code = '507601' AND ucbsvco_stus_code = 'C' AND ucbsvco_dispatch_ind IS NOT NULL) svco WHERE svco.ucbsvco_dispatch_date = svco.max_dispatch_dt AND svco.ucbsvco_sotp_code = utrsotp_code Elapsed Time LIO Blocks PIO Blocks Total Rows ------------ ---------- ---------- ---------- 00:00:00.18 15 0 1
  • 50.  
  • 52. … but it is neither simple nor easy to achieve.
  • 53. It is obtained through the careful reduction of the nonessential.
  • 54. While simplicity is the goal…
  • 55. … it is possible to be “too simple.”
  • 56. Your job is to find the balance most appropriate to your situation.