full throttle: oracle sql tuning & the ressource

42

Upload: others

Post on 06-Apr-2022

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Full Throttle: Oracle SQL Tuning & the Ressource
Page 2: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 2/42

Full Throttle: Oracle SQL Tuning & the Ressource Consumption Approach

Martin Klier

Performing Databases GmbHMitterteich / Germany

Volle Kanne: Oracle SQL Tuning mit dem Ressourcenansatz

Page 3: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 3/42

The Self-DrivingDatabase

or„What We Can Learn

From Speedy (SPD-13)“

Page 4: Full Throttle: Oracle SQL Tuning & the Ressource

© Chesley Bonestell “The Surface of Mercury”

Day: +427°C (800 F)Night: -173°C (-279 F)

Planet Mercury

1 day on Mercury= ½ year on Earth

Page 5: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 5/42

1) A robot may not injure a human being or, through inaction, allow a human being to come to harm.

2) A robot must obey the orders given it by human beingsexcept where such orders would conflict with the First Law.

3) A robot must protect its own existenceas long as such protection does not conflict with the First or Second Laws.

Isaac Asimov, „Runaround“, 1942

Page 6: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 6/42

Page 7: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 7/42

Basics

Page 8: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 8/42

TEMP

Oracle Architecture (simplified)

Listener:1521

PMON

SGA

ServerServer

Buffer Cache

Shared Pool

Log Buffer

ARCnSMON

LGWR

DBWn

PGAs

CKPT

Server

Online

Redo

Logs

ArchivedRedoLogs

Tablespace Undo Tbs.

Blocks

Page 9: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 9/42

Reading

TEMP

Listener:1521

SGA

PGAs

Server

Tablespace

Blocks

Sort,Hash,Merge

Shared Pool

select ... ;

Buffer Cache

„Buffer“

Page 10: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 10/42

ParsingSQL

SyntaxSemantic

Optimizer

Execution

Library Cache

#?LC

Check !

Cursor

# Plan

# = 'select * from emp where id=:a'

= „Hard Parse“

Page 11: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 11/42

Cursor SharingSQL

SyntaxSemantic

Execution

Library Cache

Cursor

#?#

LCCheck

Plan

= „Soft Parse“

# = 'select * from emp where id=:a'

Page 12: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 12/42

Session Cached CursorsSQL

SyntaxSemantic

Execution

Library Cache

Cursor

#?

#

LCCheck

Plan

Server

###

PGA

= „Very Soft Parse“?

# = 'select * from emp where id=:a'

Session CachedCursors

Page 13: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 13/42

Statistics FeedbackSQL

SyntaxSemantic

Execution

Library Cache

Cursor

#

LCCheck

Plan

Statistics-(ex. Cardinality-)Feedback

BINDAWARE

# = 'select * from emp where id=:a'

Page 14: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 14/42

Child Cursor PlansSQL

SyntaxSemantic

Execution

Library Cache

Cursor

#

LCCheck

PlanBINDAWARE Parent

Cursor

#

Optimizer

#?

!

= „Hard Parse“

C 1K

C 1B

C 1M

# = 'select * from emp where id=:a'

Page 15: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 15/42

Adaptive Cursor SharingSQL

SyntaxSemantic

Execution

Library Cache

LCCheck

BINDAWARE

+ SENSITIVEParent

Cursor

#

Optimizer

#?

= „Harder Soft Parse“

C 1K

BindPeek

Selectivity

C 1B

C 1M

# = 'select * from emp where id=:a'

Page 16: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 16/42

Adaptive Cursor Sharing

Example

Page 17: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 17/42

Live-case Adaptive CursorReal-life example, Mar 30, 2016, Germany

select *from COLLIwhere status <> :3

and moddat < :2and clientid = :1

;

In our three cases called with status <> 3 and moddat < sysdate

2 110

68445

11

5581

Client ID

count(*)

Page 18: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 18/42

Index usage for ACS

XIF133COLLI = Blevel 2 886 LeafBl 43k ClusteringF

XAK1COLLI = Blevel 2 478 LeafBl 124k ClusteringF

Page 19: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 19/42

ACS Cursor 3

Real # = 68445

Customer ID 2

Page 20: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 20/42

ACS Cursor 0

Real # = 5581

XIF133COLLI = 886 LeafBl 43k ClusteringF

Customer ID 10

Page 21: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 21/42

ACS Cursor 8

Real # = 11

XAK1COLLI = 478 LeafBl 124k ClusteringF

Customer ID 1

Page 22: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 22/42

RessourceConsumption

Makes you vulnerable

Page 23: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 23/42

Short: AWR Reports

Page 24: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 24/42

Reading a Report

We observed 60min of clock timeWe had 12 cores for 60min = 720min plus x of timeDB used only 51.89 min (nearly 100% of 1 core)

Can this be overload? Check for single-threaded problem.

Page 25: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 25/42

Reading a Report

IO

CPU

CPU

Page 26: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 26/42

Reading a Report

Buffer Gets cause (CPU) load

=> Big ones first!

Page 27: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 27/42

Execution Plan

Example -1-

Page 28: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 28/42

My #1 Tool

SELECT * FROM table(

DBMS_XPLAN.DISPLAY_CURSOR('&&SQL_ID',null,'COST,IOSTATS,LAST,ADVANCED,ADAPTIVE')

);

Page 29: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 29/42

Execution Plan Overview

Inliners

select(select …) as

from a,b,cwhere….

Main Join„Staircase“

613K Buffer Gets

Page 30: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 30/42

Execution Plan Overview

InlinerFilter + Count +Hash Unique610K BG

Overall Heat613K Buffer Gets

Main Join„Staircase“~1k BG

Inliners 400 BG =>„Small Game“

Real-life example, Nov 5, 2017, Switzerland

Page 31: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 31/42

Execution Plan Detail

Filter = Intermediate Result :(

Not all reducing predicates in an index

Major Problem: - JOIN grows big, because- PACKINGUNIT does not work as a reduction here (not part of JOIN)- Both have to be filtered afterwards (big heat)

Page 32: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 32/42

Analyzing the ViewThis was used as an Inline Select (=dynamic field) of a MASSIVE join

LU ist the largest table in the database.Using IN() and DISTINCT makes it impossible to estimate thecardinality here or to Query-rewrite it to a JOIN!

Tables are de-facto referenced by Foreign Keys pointing toPrimary Keys. JOIN is an option! :)

Page 33: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 33/42

Improving the ViewIn many cases, the Cost-based Optimizer works best, if problems can be solved by

USING JOIN OPERATIONS!

So why not just thinking + working the same way?

Removed DISTINCT, since it's useless: Join Condition (FK on PK) + ROWNUM=1 does the same here

Just joining ...

Added 2-column index + Extended Statistics on TU

Page 34: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 34/42

Execution Plan Improved

What helped:- Straight join approach allows accurate Cardinality Estimates, based on- Multi-Column (=Extended) Statistics- Most results can be read from Multi-Column Indexes

1.700 Buffer Gets

Page 35: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 35/42

Still time forExecution Plan

Example -2-???

Page 36: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 36/42

Example 2

„Dynamic Data Model“ - joining into large table several times (to generate columns), part of MV refresh

Runtime 20min

See BadPlan.txt

Countermeasure: Multi-Column Indexes(to avoid table access)

See BetterPlan.txt

Real-life example, October 25, 2017, Germany

Page 37: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 37/42

Example 2

„Dynamic Data Model“ - joining a large table several times (to generate columns), part of MV refresh

Runtime <5min, way better, but still looking for improvement

Created MV logs on tables + Fast Refresh on demandcreate materialized view MYMV refresh fast on commit

Hint: Use DBMS_MVIEW.EXPLAIN_MVIEW

Runtime improved to 2sec

Real-life example, October 25, 2017, Germany

Page 38: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 38/42

Speaker

● Martin Klier● Solution Architect and

Database Expert

● My focus– Performance Optimization– High Availability– Architecture DBMS

● Linux since 1997● Oracle Database since 2003

Page 39: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 39/42

Speaker

● Meet & Greet

● Contact: [email protected]

● Weblog: http://www.usn-it.de (English)

RegionalgruppenFachkonferenzen

Las Vegas, April 2018Tel Aviv, January 2018

Frankfurt, December 2018

Page 40: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 40/42

Performing Databases

● Experts for Database Technology

– Concept– Planning & Sizing– Licensing– Implementation and Troubleshooting

● Get in touch

– Performing Databases GmbHWiesauer Straße 2795666 Mitterteich, GERMANY

– Web: http://www.performing-databases.com– Twitter: @PerformingDB

Page 41: Full Throttle: Oracle SQL Tuning & the Ressource

@MartinKlierDBA Full Throttle: SQL Tuning & Ressource Consumption Appr. 42/42

Q & A

Download my Presentations and Whitepapershttp://www.performing-databases.com