SlideShare ist ein Scribd-Unternehmen logo
1 von 202
a good background in ...
... successful application development
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Connor McDonald
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
4
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
5
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
6
Getting in touch is easy...
connor-mcdonald.com
https://linktr.ee/connor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
8https://asktom.oracle.com
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
https://asktom.oracle.com/officehours
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
200 hours free access so far
10
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
assumptions
1. You roughly know databases (tables and columns)
2. You can write a SQL statement
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
before we begin
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
recommended reading
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
docs.oracle.com
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
its free !
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Concepts guide
http://bit.ly/oraconcepts
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
better than lots of current people
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Application Developers guide
http://bit.ly/oradevdoc
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
better than lots of current people
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Part 1
SQL processing
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
some controversy to start...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
here's the problem...
22
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
... it's us
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
a little digression on servers
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
a little bit of history ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
(not too) long ago
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
FSB = "front side bus"
28
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
any access to ... anything
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
CPU capped
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
hypertransport
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
memory access direct from CPU
35
~2007
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"why do I care?"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
you can't blame the server
39
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
if you can't get that performance ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
... it's you
43
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
all have their place...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"The sooner your company admits that you are not
Google, the sooner you can get down to some real work"
- Ted Dziuba
47
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
so what's holding you back ?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
It all comes down to...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
too much work or ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
... not being able to do work
51
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
this part ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
... how to avoid work when processing SQL
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
terminology
54
cursors
declare
cursor C(p number) is
select * from DEPT
where DEPTNO = p;
begin
for rec in C loop
…
end loop;
end;
select *
from EMPLOYEE
where EMPNO > 1234;
delete from MY_TABLE;
drop table MY_TABLE;
begin
MY_PROCEDURE(1,2,3);
end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
all of them !
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
3 phases
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
open
process
close
gimme some memory
do some stuff using that memory,
probably access other memory
here's your memory back
58
memory access = controlled access
a quick primer on (database) memory
62
metaphor
64
limited resource
lots of people want it
concurrent access causes problems
it's a complex system
67
same with memory
SGA
SGA
protected by
SGA
protected by
1) get latch
SGA
protected by
2) access memory
SGA
protected by
3) release latch
latch contention
SGA
protected by
someone must wait ...
active wait
spinning
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
can I have the latch ?
76
latch contention....
hurts CPU...
79
hurts concurrency
YOU
GET
NOTHING
DONE
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
its importance to Oracle
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
early Oracle
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
2000 times !
(_spin_count)
87
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Zzzzzzzzzz....
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
nowadays...
yield
mutex
posting
Good reading: http://andreynikolaev.wordpress.com/
CAS
"Errrr.... weren't we talking SQL?"
to run a SQL statement
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
SQL> select *
2 frmo emp;
frmo emp
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
92
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
SQL> select empnoo
2 from emp;
select empnoo
*
ERROR at line 1:
ORA-00904: invalid column name
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
PLAN
-------------------------------------
SELECT STATEMENT
TABLE ACCESS BY INDEX ROWID EMP
INDEX RANGE SCAN EMP_PK
EMP_PK EMP
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
96
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
lots of preliminaries
parsing
99
"compile"
lots of memory access
100
lots of latching !
101
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
impossible to avoid ?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
library cache
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
previously executed statements
104
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
parse statement
already in library cache ?
reuse optimizer info
reuse row source info
select * from emp where empno = 123
syntactically, semantics OK
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
select surname, firstname from emp where empno = 123
select * from dept where deptno = 4567
select * from customer where locality = 17
select prno from property where reference = 'X123G'
select * from dept where deptno = 23
select surname, firstname from emp where empno = 123
select * from customer where locality = 256
select * from organisation where officer = 'OFF876'
select surname, firstname from emp where empno = 7632
select * from dept where deptno = 4567
select offender from crimes where crno = 247462
Two full parses avoided
library
cache
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
select surname, firstname from emp where empno = 123
select * from dept where dname = 'SALES'
probability of reuse low ?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
some queries are “nearly the same”
108
select surname, firstname from emp where empno = 123
select surname, firstname from emp where empno = 456
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
binding
parse this...
now run it with ? = 123
now run it with ? = 456
select surname, firstname from emp where empno = ?
select surname, firstname from emp where empno = ?
select * from dept where deptno = ?
select * from customer where locality = ?
select prno from property where reference = ?
select * from dept where deptno = ?
select surname, firstname from emp where empno = ?
select * from customer where locality = ?
select * from organisation where officer = ?
select surname, firstname from emp where empno = ?
select * from dept where deptno = ?
select offender from crimes where crno = ?
Five full parses avoided
library
cache
demo
ParseDemo
ParseDemoBind
"performance still looks ok"
let's make it real
ParseDemo2 nn
ParseDemo2Bind nn
much more serious
select pk from parse_demo where pk = 17
select pk from parse_demo where pk = 123
select pk from parse_demo where pk = 43
select pk from parse_demo where pk = 33
select pk from parse_demo where pk = 127
select pk from parse_demo where pk = 5432
select pk from parse_demo where pk = 12
select pk from parse_demo where pk = 876
select pk from parse_demo where pk = 76
select pk from parse_demo where pk = 19
select pk from parse_demo where pk = 213
select pk from parse_demo where pk = 543
select pk from parse_demo where pk = 4532
select pk from parse_demo where pk = 7544
select pk from parse_demo where pk = 6543
select pk from parse_demo where pk = 452
building SQL by concatenation
118
it takes 5 minutes to hack you
for fast, secure SQL ...
... always bind user input
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
while we are talking binding
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
parse statement
already in library cache ?
reuse optimizer info
reuse row source info
select * from emp where empno = 123
syntactically, semantics OK
Yes!
Yes!
???
???
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
still some parsing to do
127
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
Hard
Parse
Soft
Parse
foundnot found
in lib cache
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
scott@mydb> select *
2 from EMP
3 where EMPNO = :b1
mike@mydb> select *
2 from EMP
3 where EMPNO = :b1
SQL> desc mike.emp
Name Null? Type
----------------- -------- ------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
(even soft) parsing =
memory access =
latching
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
can we do better ?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
recall
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
open
process
close
gimme some memory
do some stuff using that memory,
probably access other memory
here's your memory back
133
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
your SQL is always shareable
library cache
select *
from emp
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
your cursor points to it
library cache
select *
from emp
cursor
135
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
close cursor = lose pointer
library cache
select *
from emp
cursor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
next time we parse
soft parse
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
impossible to avoid ?
138
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
what if we don't close the cursor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
emplist(String[] args) {
if "first time I'm using this" {
else
"reset the pointer, re-execute"
}
library cache
select *
from emp
cursor 1
select *
from dept
cursor 2
select *
from emp
where ...
cursor 3
pstmt_all_emp =
con.prepareStatement("select * from emp");
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
don’t close the cursorhang on to the memoryremember what cursors we’ve usedreuse whenever possibledon’t exhaust memorydon’t allow invalid cursor reuse
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
sounds complicated ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
a free solution exists
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
plsql
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
create procedure MY_PROC is
begin
select empno, ename, ...
into …
from emp
where empno = my_plsql_variable
...
end;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
static SQL in stored PLSQL
automatically uses bind variables
hold’s cursors open
(even if you close)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
better cursor caching
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
procedure MY_PROC is
cursor c_emp is
select * from emp;
begin
open c_emp;
fetch c_emp
into …;
close c_emp;
end;
select * from emp
procedure MY_PROC is
begin
select *
into …
from dept
where …
end;
select * from dept …
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
summary
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
avoid parsing costs
for high frequency SQL
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
binding
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
using PLSQL is gold
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
if time permits ....
Part 2
Read Consistency
154
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
156
"Readers don’t block writers"
"Writers don't block readers"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
157
Maximum concurrency…
… very few locking worries
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
158
lack of understanding
corrupt your database
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
160
some revision / fundamentals
SQL> update EMP
2 set SAL = SAL * 1.10
3 /
14 rows updated.
SQL> rollback;
Rollback complete.
how ?
161
we remember stuff
162
SQL> update EMP
2 set SAL = SAL * 1.10
3 / undo header
smith $1,0001
block 2754
jones $9002
brown $1,5003
wells $2,0004
wilson $1,0005
block 2754, row 1,
sal $1000
block 2754, row 2,
sal $900
block 2754, row 3,
sal $1500
block 2754, row 4,
sal $2000
uba 5
5
$1,100
$990
$1,650
$2,200
uba 5.1uba 5.2
163
SQL> rollback;
164
SQL> rollback;
undo header
smith $1,0001
block 2754
jones $9002
brown $1,5003
wells $2,0004
wilson $1,0005
block 2754, row 1,
sal $1000
block 2754, row 2,
sal $900
block 2754, row 3,
sal $1500
block 2754, row 4,
sal $2000
uba 5
5
$1,100
$990
$1,650
$2,200
uba 5.1uba 5.2
we can use this stuff for queries!
(Oracle version 4)
166
read consistency
167
select * from emp
where hiredate > '01/01/2004'
update emp set …
where empno = 1234;
Block 3217
"I need block 3217…
… as it was at 9:00"
9:00
9:03
9:05
session 1 session 2
...and time = scn
System Change Number
(the block “timestamp”)
Block 3217
SCN 4567192
SCN 4567234
“9am”
“9:03am”
session 1
170
so what do we do now ?
171
we apply undo
Session 1
Request
Block 3217,
SCN 4567192
Block 3217,
SCN 4567234
"ABC"
Block 3217,
SCN 4567003,
change ABC => XYZ
undo segment block(s)
No good..too new
take a copy of the block
Locate
apply undo
Block 3217,
SCN 4567234
"ABC"
Block 3217,
SCN 4567234
"ABC"
Block 3217,
SCN 4567003
"XYZ"
Block 3217,
SCN 4567003
"XYZ"
Session 2
update emp
set ename = "ABC"
where empno = 1234;
commit;
Done !
173
stress: vast simplification
results are time consistent
“I’m a developer…
I just write SQL ...
…who cares about all that?”
So many ways…
TROUBLE
example: copying data
“every hour,
populate data warehouse,
copy of OLTP data”
EMP DWEMP
readcon1/readcon2
DIY data integrity
... true story
181
Manufacturer
Product
alter table add primary key
alter table add foreign key
“ensure that every
product corresponds to
a valid manufacturer”
create or replace
trigger PROD_MAN_CHECK
before insert or update on PRODUCT
for each row
declare
l_man_id number;
begin
select man_id
into l_man_id
from manufacturer
where man_id = :new.man_id;
exception
when no_data_found then
raise_application_error(-20000,
'Manufacturer is not valid');
end;
create or replace
trigger MAN_PROD_CHECK
before delete on MANUFACTURERS
for each row
declare
l_prd_cnt number;
begin
select count(*)
into l_prd_cnt
from product
where prd_id = :old.prd_id;
if l_prd_cnt > 0 then
raise_application_error(-20001,
'Manufacturer in use by product records');
end if;
end;
testing "works"
185
SQL> insert into PRODUCT (...,MAN_ID,...)
2 values (...,100, ...);
1 row created.
SQL> insert into PRODUCT (...,MAN_ID,...)
2 values (...,101,...);
ERROR at line 1:
ORA-20000: Manufacturer is not valid
SQL> delete from MANUFACTURER
2 where man_id = 5768;
ERROR at line 1:
ORA-20001: Manufacturer in use by product records
one month later…
An unexpected error has
occurred. Manufacturer
record not found
SQL> select count(*)
2 from
3 ( select man_id from PRODUCT
4 minus
5 select man_id from MANUFACTURER )
6 /
COUNT(*)
----------
86
189
data integrity in code = no data integrity
Time
create PRD with MAN=7
Trigger fires
- does MAN=7 exist?
- "Yes"
- OK
delete MAN=7
Trigger fires
- any PRD with MAN=7
- "No" (not yet)
- OK
commit
commit
data validity seems simple…
"look up X before allowing Y"
192
referential integrity is complex
read consistency,
blocking / locking
beware the module specification
"When creating a product...
validate registration date – ensure not in the future,
validate …
validate …
validate manufacturer ID – must exist in Manufacturer table"
concurrency testing vital
195
“I’m a developer…
…who cares about all that?”
part 2
“All that stuff is a DBA issue,
I just want my code to run fast”
demo3
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
summary revisited
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
use binding for SQL
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
use SQL wherever possible
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
use PLSQL to run your SQL
Thanks for coming!
connor-mcdonald.com
https://linktr.ee/connor
APEX Connect
SQL Tuning 101
PL/SQL Performance 101

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (16)

Flashback features in Oracle - UKOUG 2017
Flashback features in Oracle - UKOUG 2017Flashback features in Oracle - UKOUG 2017
Flashback features in Oracle - UKOUG 2017
 
Perth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL TechniquesPerth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL Techniques
 
Sangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediSangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL Jedi
 
Hyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous DatabaseHyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous Database
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
Cool SQL Features
Cool SQL FeaturesCool SQL Features
Cool SQL Features
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
Agile Database Development with JSON
Agile Database Development with JSONAgile Database Development with JSON
Agile Database Development with JSON
 
SQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX DevelopersSQL and PLSQL features for APEX Developers
SQL and PLSQL features for APEX Developers
 
Eta
EtaEta
Eta
 
JPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APIJPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream API
 
Profiling Oracle with GDB
Profiling Oracle with GDBProfiling Oracle with GDB
Profiling Oracle with GDB
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's Tricks
 
Return Oriented Programming
Return Oriented ProgrammingReturn Oriented Programming
Return Oriented Programming
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
 

Ähnlich wie APEX Connect 2019 - successful application development

Ähnlich wie APEX Connect 2019 - successful application development (20)

Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerWellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
 
Melbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskMelbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without risk
 
Sangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cSangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12c
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
 
OpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 minsOpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 mins
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
 
Perth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous DatabasePerth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous Database
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c features
 
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
 
“Quantum” Performance Effects: beyond the Core
“Quantum” Performance Effects: beyond the Core“Quantum” Performance Effects: beyond the Core
“Quantum” Performance Effects: beyond the Core
 
Pl18 saving bandwidth
Pl18 saving bandwidthPl18 saving bandwidth
Pl18 saving bandwidth
 
Regular Expressions with full Unicode support
Regular Expressions with full Unicode supportRegular Expressions with full Unicode support
Regular Expressions with full Unicode support
 
Overview of Oracle Database 18c Express Edition (XE)
Overview of Oracle Database 18c Express Edition (XE)Overview of Oracle Database 18c Express Edition (XE)
Overview of Oracle Database 18c Express Edition (XE)
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processing
 
Using Machine Learning to Debug complex Oracle RAC Issues
Using Machine Learning  to Debug complex Oracle RAC IssuesUsing Machine Learning  to Debug complex Oracle RAC Issues
Using Machine Learning to Debug complex Oracle RAC Issues
 
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
Keynote (Nandini Ramani) - The Role of Java in Heterogeneous Computing & How ...
 
12 Things About 12c Release 2 for Developers
12 Things About 12c Release 2 for Developers12 Things About 12c Release 2 for Developers
12 Things About 12c Release 2 for Developers
 
ILOUG 2019 - Autonomous, what does it mean for DBAs
ILOUG 2019 - Autonomous, what does it mean for DBAsILOUG 2019 - Autonomous, what does it mean for DBAs
ILOUG 2019 - Autonomous, what does it mean for DBAs
 
Compile ahead of time. It's fine?
Compile ahead of time. It's fine?Compile ahead of time. It's fine?
Compile ahead of time. It's fine?
 

Mehr von Connor McDonald

Mehr von Connor McDonald (20)

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAs
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistency
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
 
OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developers
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

APEX Connect 2019 - successful application development

  • 3. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Connor McDonald
  • 4. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 4
  • 5. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 5
  • 6. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 6
  • 7. Getting in touch is easy... connor-mcdonald.com https://linktr.ee/connor
  • 8. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 8https://asktom.oracle.com
  • 9. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. https://asktom.oracle.com/officehours
  • 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 200 hours free access so far 10
  • 11. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. assumptions 1. You roughly know databases (tables and columns) 2. You can write a SQL statement
  • 12. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. before we begin
  • 13. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. recommended reading
  • 14. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. docs.oracle.com
  • 15. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. its free !
  • 16. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Concepts guide http://bit.ly/oraconcepts
  • 17. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. better than lots of current people
  • 18. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Application Developers guide http://bit.ly/oradevdoc
  • 19. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. better than lots of current people
  • 20. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Part 1 SQL processing
  • 21. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. some controversy to start...
  • 22. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. here's the problem... 22
  • 23. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. ... it's us
  • 24. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. a little digression on servers
  • 25. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. a little bit of history ...
  • 26. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. (not too) long ago
  • 27. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
  • 28. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. FSB = "front side bus" 28
  • 29. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. any access to ... anything
  • 30. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. CPU capped
  • 31.
  • 32.
  • 33. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. hypertransport
  • 34.
  • 35. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. memory access direct from CPU 35
  • 36.
  • 37. ~2007
  • 38. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "why do I care?"
  • 39. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. you can't blame the server 39
  • 40. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. if you can't get that performance ...
  • 41. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. ... it's you
  • 42.
  • 43. 43
  • 44.
  • 45.
  • 46. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. all have their place...
  • 47. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "The sooner your company admits that you are not Google, the sooner you can get down to some real work" - Ted Dziuba 47
  • 48. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. so what's holding you back ?
  • 49. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. It all comes down to...
  • 50. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. too much work or ...
  • 51. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. ... not being able to do work 51
  • 52. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. this part ...
  • 53. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. ... how to avoid work when processing SQL
  • 54. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. terminology 54
  • 55. cursors declare cursor C(p number) is select * from DEPT where DEPTNO = p; begin for rec in C loop … end loop; end; select * from EMPLOYEE where EMPNO > 1234; delete from MY_TABLE; drop table MY_TABLE; begin MY_PROCEDURE(1,2,3); end;
  • 56. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. all of them !
  • 57. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 3 phases
  • 58. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. open process close gimme some memory do some stuff using that memory, probably access other memory here's your memory back 58
  • 59. memory access = controlled access
  • 60. a quick primer on (database) memory
  • 61.
  • 63.
  • 64. 64 limited resource lots of people want it concurrent access causes problems it's a complex system
  • 65.
  • 66.
  • 68. SGA
  • 76. spinning can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? can I have the latch ? 76
  • 77.
  • 81. YOU
  • 82. GET
  • 84. DONE
  • 85. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. its importance to Oracle
  • 86. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. early Oracle
  • 87. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 2000 times ! (_spin_count) 87
  • 88. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Zzzzzzzzzz....
  • 89. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. nowadays... yield mutex posting Good reading: http://andreynikolaev.wordpress.com/ CAS
  • 90. "Errrr.... weren't we talking SQL?"
  • 91. to run a SQL statement
  • 92. Syntax Validity Optimization Rowsourcing Execution (Fetch) SQL> select * 2 frmo emp; frmo emp * ERROR at line 2: ORA-00923: FROM keyword not found where expected 92
  • 93. Syntax Validity Optimization Rowsourcing Execution (Fetch) SQL> select empnoo 2 from emp; select empnoo * ERROR at line 1: ORA-00904: invalid column name
  • 100. lots of memory access 100
  • 102. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. impossible to avoid ?
  • 103. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. library cache
  • 104. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. previously executed statements 104
  • 105. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. parse statement already in library cache ? reuse optimizer info reuse row source info select * from emp where empno = 123 syntactically, semantics OK
  • 106. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. select surname, firstname from emp where empno = 123 select * from dept where deptno = 4567 select * from customer where locality = 17 select prno from property where reference = 'X123G' select * from dept where deptno = 23 select surname, firstname from emp where empno = 123 select * from customer where locality = 256 select * from organisation where officer = 'OFF876' select surname, firstname from emp where empno = 7632 select * from dept where deptno = 4567 select offender from crimes where crno = 247462 Two full parses avoided library cache
  • 107. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. select surname, firstname from emp where empno = 123 select * from dept where dname = 'SALES' probability of reuse low ?
  • 108. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. some queries are “nearly the same” 108 select surname, firstname from emp where empno = 123 select surname, firstname from emp where empno = 456
  • 109. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. binding parse this... now run it with ? = 123 now run it with ? = 456 select surname, firstname from emp where empno = ?
  • 110. select surname, firstname from emp where empno = ? select * from dept where deptno = ? select * from customer where locality = ? select prno from property where reference = ? select * from dept where deptno = ? select surname, firstname from emp where empno = ? select * from customer where locality = ? select * from organisation where officer = ? select surname, firstname from emp where empno = ? select * from dept where deptno = ? select offender from crimes where crno = ? Five full parses avoided library cache
  • 113. let's make it real ParseDemo2 nn ParseDemo2Bind nn
  • 115. select pk from parse_demo where pk = 17 select pk from parse_demo where pk = 123 select pk from parse_demo where pk = 43 select pk from parse_demo where pk = 33 select pk from parse_demo where pk = 127 select pk from parse_demo where pk = 5432 select pk from parse_demo where pk = 12 select pk from parse_demo where pk = 876 select pk from parse_demo where pk = 76 select pk from parse_demo where pk = 19 select pk from parse_demo where pk = 213 select pk from parse_demo where pk = 543 select pk from parse_demo where pk = 4532 select pk from parse_demo where pk = 7544 select pk from parse_demo where pk = 6543 select pk from parse_demo where pk = 452
  • 116. building SQL by concatenation
  • 117.
  • 118. 118
  • 119.
  • 120.
  • 121. it takes 5 minutes to hack you
  • 122.
  • 123. for fast, secure SQL ...
  • 124. ... always bind user input
  • 125. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. while we are talking binding
  • 126. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. parse statement already in library cache ? reuse optimizer info reuse row source info select * from emp where empno = 123 syntactically, semantics OK Yes! Yes! ??? ???
  • 127. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. still some parsing to do 127
  • 128. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Syntax Validity Optimization Rowsourcing Execution (Fetch) Hard Parse Soft Parse foundnot found in lib cache
  • 129. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. scott@mydb> select * 2 from EMP 3 where EMPNO = :b1 mike@mydb> select * 2 from EMP 3 where EMPNO = :b1 SQL> desc mike.emp Name Null? Type ----------------- -------- ------------ EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9)
  • 130. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. (even soft) parsing = memory access = latching
  • 131. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. can we do better ?
  • 132. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. recall
  • 133. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. open process close gimme some memory do some stuff using that memory, probably access other memory here's your memory back 133
  • 134. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. your SQL is always shareable library cache select * from emp
  • 135. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. your cursor points to it library cache select * from emp cursor 135
  • 136. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. close cursor = lose pointer library cache select * from emp cursor
  • 137. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. next time we parse soft parse
  • 138. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. impossible to avoid ? 138
  • 139. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. what if we don't close the cursor
  • 140. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. emplist(String[] args) { if "first time I'm using this" { else "reset the pointer, re-execute" } library cache select * from emp cursor 1 select * from dept cursor 2 select * from emp where ... cursor 3 pstmt_all_emp = con.prepareStatement("select * from emp");
  • 141. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. don’t close the cursorhang on to the memoryremember what cursors we’ve usedreuse whenever possibledon’t exhaust memorydon’t allow invalid cursor reuse
  • 142. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. sounds complicated ...
  • 143. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. a free solution exists
  • 144. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. plsql
  • 145. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. create procedure MY_PROC is begin select empno, ename, ... into … from emp where empno = my_plsql_variable ... end;
  • 146. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. static SQL in stored PLSQL automatically uses bind variables hold’s cursors open (even if you close)
  • 147. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. better cursor caching
  • 148. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. procedure MY_PROC is cursor c_emp is select * from emp; begin open c_emp; fetch c_emp into …; close c_emp; end; select * from emp procedure MY_PROC is begin select * into … from dept where … end; select * from dept …
  • 149. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. summary
  • 150. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. avoid parsing costs for high frequency SQL
  • 151. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. binding
  • 152. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. using PLSQL is gold
  • 153. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. if time permits ....
  • 155.
  • 156. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 156 "Readers don’t block writers" "Writers don't block readers"
  • 157. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 157 Maximum concurrency… … very few locking worries
  • 158. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 158 lack of understanding
  • 160. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 160 some revision / fundamentals
  • 161. SQL> update EMP 2 set SAL = SAL * 1.10 3 / 14 rows updated. SQL> rollback; Rollback complete. how ? 161
  • 163. SQL> update EMP 2 set SAL = SAL * 1.10 3 / undo header smith $1,0001 block 2754 jones $9002 brown $1,5003 wells $2,0004 wilson $1,0005 block 2754, row 1, sal $1000 block 2754, row 2, sal $900 block 2754, row 3, sal $1500 block 2754, row 4, sal $2000 uba 5 5 $1,100 $990 $1,650 $2,200 uba 5.1uba 5.2 163
  • 165. SQL> rollback; undo header smith $1,0001 block 2754 jones $9002 brown $1,5003 wells $2,0004 wilson $1,0005 block 2754, row 1, sal $1000 block 2754, row 2, sal $900 block 2754, row 3, sal $1500 block 2754, row 4, sal $2000 uba 5 5 $1,100 $990 $1,650 $2,200 uba 5.1uba 5.2
  • 166. we can use this stuff for queries! (Oracle version 4) 166
  • 168. select * from emp where hiredate > '01/01/2004' update emp set … where empno = 1234; Block 3217 "I need block 3217… … as it was at 9:00" 9:00 9:03 9:05 session 1 session 2 ...and time = scn
  • 169. System Change Number (the block “timestamp”)
  • 170. Block 3217 SCN 4567192 SCN 4567234 “9am” “9:03am” session 1 170
  • 171. so what do we do now ? 171
  • 173. Session 1 Request Block 3217, SCN 4567192 Block 3217, SCN 4567234 "ABC" Block 3217, SCN 4567003, change ABC => XYZ undo segment block(s) No good..too new take a copy of the block Locate apply undo Block 3217, SCN 4567234 "ABC" Block 3217, SCN 4567234 "ABC" Block 3217, SCN 4567003 "XYZ" Block 3217, SCN 4567003 "XYZ" Session 2 update emp set ename = "ABC" where empno = 1234; commit; Done ! 173
  • 175. results are time consistent
  • 176. “I’m a developer… I just write SQL ... …who cares about all that?”
  • 180. “every hour, populate data warehouse, copy of OLTP data” EMP DWEMP readcon1/readcon2
  • 181. DIY data integrity ... true story 181
  • 182. Manufacturer Product alter table add primary key alter table add foreign key “ensure that every product corresponds to a valid manufacturer”
  • 183. create or replace trigger PROD_MAN_CHECK before insert or update on PRODUCT for each row declare l_man_id number; begin select man_id into l_man_id from manufacturer where man_id = :new.man_id; exception when no_data_found then raise_application_error(-20000, 'Manufacturer is not valid'); end;
  • 184. create or replace trigger MAN_PROD_CHECK before delete on MANUFACTURERS for each row declare l_prd_cnt number; begin select count(*) into l_prd_cnt from product where prd_id = :old.prd_id; if l_prd_cnt > 0 then raise_application_error(-20001, 'Manufacturer in use by product records'); end if; end;
  • 186. SQL> insert into PRODUCT (...,MAN_ID,...) 2 values (...,100, ...); 1 row created. SQL> insert into PRODUCT (...,MAN_ID,...) 2 values (...,101,...); ERROR at line 1: ORA-20000: Manufacturer is not valid SQL> delete from MANUFACTURER 2 where man_id = 5768; ERROR at line 1: ORA-20001: Manufacturer in use by product records
  • 188. An unexpected error has occurred. Manufacturer record not found
  • 189. SQL> select count(*) 2 from 3 ( select man_id from PRODUCT 4 minus 5 select man_id from MANUFACTURER ) 6 / COUNT(*) ---------- 86 189
  • 190. data integrity in code = no data integrity
  • 191. Time create PRD with MAN=7 Trigger fires - does MAN=7 exist? - "Yes" - OK delete MAN=7 Trigger fires - any PRD with MAN=7 - "No" (not yet) - OK commit commit
  • 192. data validity seems simple… "look up X before allowing Y" 192
  • 193. referential integrity is complex read consistency, blocking / locking
  • 194. beware the module specification "When creating a product... validate registration date – ensure not in the future, validate … validate … validate manufacturer ID – must exist in Manufacturer table"
  • 196. “I’m a developer… …who cares about all that?” part 2
  • 197. “All that stuff is a DBA issue, I just want my code to run fast” demo3
  • 198. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. summary revisited
  • 199. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. use binding for SQL
  • 200. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. use SQL wherever possible
  • 201. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. use PLSQL to run your SQL
  • 202. Thanks for coming! connor-mcdonald.com https://linktr.ee/connor APEX Connect SQL Tuning 101 PL/SQL Performance 101