SlideShare a Scribd company logo
1 of 47
Download to read offline
26/11/2019
1
1
a good background in ...
2
... SQL processing, aka
3
... successful application
development
4
Connor McDonald
1 2
3 4
26/11/2019
2
Copyright© 2018, Oracleand/or its affiliates. All rights reserved.
5
Copyright© 2018, Oracleand/or its affiliates. All rights reserved.
6
Getting in touch is easy...
@connor_mc_d
https://linktr.ee/connor
Copyright© 2018, Oracleand/or its affiliates. All rights reserved.
8https://asktom.oracle.com
5 6
7 8
26/11/2019
3
Copyright© 2018, Oracleand/or its affiliates. All rights reserved.https://asktom.oracle.com/officehours10
250 hours free access so far
11
assumptions
1. You roughly know databases (tables and columns)
2. You can write a SQL statement
12
SQL is like any language
9 10
11 12
26/11/2019
4
13
compile it
on the fly
14
run it
15
get | store results
16
for successful applications...
13 14
15 16
26/11/2019
5
17
compile it ... fast
18
run it ... fast
19
get | store results ... fast
20
that's it!
17 18
19 20
26/11/2019
6
21
what everyone talks about
22
compile
execute
store/fetch results
23
this session
24
compile
execute
store/fetch results
21 22
23 24
26/11/2019
7
25
before we begin ...
26
some controversy to start
27
here's the problem...
28
... it's us
25 26
27 28
26/11/2019
8
29
a small digression
30
a little bit of history on servers ...
31
(not too) long ago
29 30
31 32
26/11/2019
9
33
FSB = "front side bus"
34
any access to ... anything
35
CPU capped
33 34
35 36
26/11/2019
10
37
hypertransport
39
memory access direct from CPU
37 38
39 40
26/11/2019
11
~2007
42
"why do I care?"
43
you can't blame the server (anymore)
44
if you can't get that performance ...
41 42
43 44
26/11/2019
12
45
... it's you
47
"The sooner your company admits that you are not
Google, the sooner you can get down to some real
work"
- Ted Dziuba
48
so what's holding you back ?
45 46
47 48
26/11/2019
13
49
It all comes down to...
50
too much work or ...
51
... not being able to do work
52
PART #1
5
2
compiling SQL
49 50
51 52
26/11/2019
14
53
... how to avoid work when processing SQL
54
terminology
55
cursorsdeclare
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
all of them !
53 54
55 56
26/11/2019
15
57
3 phases
58
open
process
close
gimme some memory
do some stuff using that memory,
maybe access other memory
here's your memory back
59
memory access = controlled access
60
a quick primer on (database) memory
57 58
59 60
26/11/2019
16
61 62
metaphor
63
61 62
63 64
26/11/2019
17
67
limited resource
lots of people want it
concurrent access causes problems
it's a complex system
65 66
67 68
26/11/2019
18
69
same with memory
70
SGA
71
SGA
protected by
72
SGA
protected by
1) get latch
69 70
71 72
26/11/2019
19
73
SGA
protected by
2) access memory
74
SGA
protected by
3) release latch
75
latch contention
76
someone must wait ...
SGA
protected by
73 74
75 76
26/11/2019
20
77
active wait
78
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 ?
77 78
79 80
26/11/2019
21
81
latch contention....
82
hurts CPU...
83
hurts concurrency
YOU
81 82
83 84
26/11/2019
22
GET NOTHING
DONE
88
"Errrr.... weren't we talking SQL?"
85 86
87 88
26/11/2019
23
89
to run a SQL statement
90
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
91
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
SQL> select empnoo
2 from emp;
select empnoo
*
ERROR at line 1:
ORA-00904: invalid column name
92
PLAN
-------------------------------------
SELECT STATEMENT
TABLE ACCESS BY INDEX ROWID EMP
INDEX RANGE SCAN EMP_PK
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
89 90
91 92
26/11/2019
24
93
EMP_PK EMP
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
94
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
95
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
96
lots of preliminaries
93 94
95 96
26/11/2019
25
97
parsing
"compile"
98
lots of memory access
99
lots of latching !
100
impossible to avoid ?
97 98
99 100
26/11/2019
26
101
library cache
102
previously executed
statements
103
parse statement
already in library cache ?
reuse optimizer info
reuse row source info
select * from emp where empno = 123
syntactically, semantics OK
104
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
101 102
103 104
26/11/2019
27
105
select surname, firstname from emp where empno = 123
select * from dept where dname = 'SALES'
probability of reuse low ?
106
some queries are “nearly the same”
select surname, firstname from emp where empno = 123
select surname, firstname from emp where empno = 456
107
binding
parse this...
now run it with ? = 123
now run it with ? = 456
select surname, firstname from emp where empno = ?
108
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
105 106
107 108
26/11/2019
28
109
demo
ParseDemo
ParseDemoBind
110
"performance still looks ok"
111
let's make it real
ParseDemo2 nn
ParseDemo2Bind nn
112
much more serious
109 110
111 112
26/11/2019
29
113
building SQL by concatenation
114
you'll get hacked
115
select ename
from emp
where empno = 6543
select ename
from emp
where empno = 6543
and 1=0
union all
select table_name
from all_tables
where table_name like '%SECURITY%'
select ename
from emp
where empno = 6543
and 1=0
union all
select username
from app_security
where ...
116
it takes 5 minutes to hack you
113 114
115 116
26/11/2019
30
117
for fast, secure SQL ...
118
... always bind user input
119
"I'm an APEX developer... not an issue"
120
117 118
119 120
26/11/2019
31
121
other common culprits
item protection
create_collection_from_query
122
while we are talking binding
123
parse statement
already in library cache ?
reuse optimizer info
reuse row source info
select * from emp where empno = 123
syntactically, semantics OK
Yes!
Yes!
???
???
124
still some parsing to do
121 122
123 124
26/11/2019
32
125
Syntax
Validity
Optimization
Rowsourcing
Execution
(Fetch)
Hard
Parse
Soft
Parse
foundnot found
in lib cache
126
scott@mydb> select *
2 from EMP
3 where EMPNO = :b1
sue@mydb> select *
2 from EMP
3 where EMPNO = :b1
SQL> desc sue.emp
Name Null? Type
----------------- -------- ------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
127
(even soft) parsing =
memory access =
latching
128
can we do better ?
125 126
127 128
26/11/2019
33
129
your SQL is always shareable
library cache
select *
from emp
130
your cursor points to it
cursor
library cache
select *
from emp
131
close cursor = lose pointer
cursor
library cache
select *
from emp
132
next time we parse
soft parse
129 130
131 132
26/11/2019
34
133
what if we don't close the cursor
134
emplist(String[] args) {
if "first time I'm using this" {
else
"reset the pointer, re-execute"
}
library cache
select *
from emp
select *
from dept
select *
from emp
where ...
pstmt_all_emp =
con.prepareStatement("select * from emp");
cursor
cursor
cursor
135
don’t close the cursorhang on to the memoryremember what cursors we’ve usedreuse whenever possibledon’t exhaust memorydon’t allow invalid cursor reuse
136
sounds complicated ...
133 134
135 136
26/11/2019
35
137
a free solution exists
138
plsql
139
create procedure MY_PROC is
begin
select empno, ename, ...
into …
from emp
where empno = my_plsql_variable
...
end;
140
static SQL in stored PLSQL
automatically uses bind variables
hold’s cursors open
(even if you close)
137 138
139 140
26/11/2019
36
141
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 …
142
PART #2
get | store results
we'll come back to running SQL
143 144
start with reading data
141 142
143 144
26/11/2019
37
145
querying data
146
data is stored in blocks | pages
147
to read data, you read blocks...
148
SQL> select *
2 from EMP
3 where ...
/u01/my_data1.dat
memory
145 146
147 148
26/11/2019
38
149
but (database) memory access is complex
150
SQL> select *
2 from EMP
3 where …
SQL> update EMP
2 set …
3 where …
SQL> select *
2 from EMP
3 where …
SQL> insert into
2 EMP
3 values (…)
SQL> select *
2 from CUSTOMER
3 /
SQL> select max(EMPNO)
2 from EMP
SQL> delete
2 from DEPT
3 /
151
we have to latch !
152
• Get latch
• Search along list of blocks in memory
• Read block
• Extract row of interest
• Release latch
• Give row back to client
"fetch a row"
149 150
151 152
26/11/2019
39
153
lots of rows
154
lots of latching
155
typical program
156
rs = stmt.executeQuery("...");
while(rs.next()) {
v1 = rs.getInt(1);
v2 = rs.getString(2);
...
}
• Get latch
• Walk along list
• Get block
• Extract single row
• Release latch
• Give row back to client
• Get latch (again)
• Walk along list (again)
• Get block (again)
• Extract single row
• Release latch (again)
• Give row back to client (again)
Row #1
Row #2
• Get latch (again)
• Walk along list (again)
• Get block (again)
• Extract single row
• Release latch (again)
• Give row back to client (again)
Row #3
153 154
155 156
26/11/2019
40
157
a better strategy.... “pinning”
158
"fetch a row"
• Get latch
• Walk along list
• Get block
• Pin the block
• Release latch
• Give row 1 back to client
• Give row 2 back to client
…
• Give row n to client
• Get latch
• Walk along list
• Remove my pin on the block
• Release latch
“and .. I’ll will need
several rows from
this block”
159
how do you say
“I may want many rows” ?
160
responsibility of the client
157 158
159 160
26/11/2019
41
161
FetchDemo nn
162
focus on blocks
163
focus on roundtrips
164
all that data goes somewhere
161 162
163 164
26/11/2019
42
165
SQL> declare
cursor C is select ... (500m table)
...
9 begin
10 open c;
11 loop
12 fetch c
13 into r;
14 exit when c%notfound;
. . .
19 /
Elapsed: 00:01:11.72
166
SQL> declare
cursor C is select ... (500m table)
. . .
9 begin
10 open c;
11
12 fetch c
13 bulk collect
14 into r;
15
. . .
19 /
Elapsed: 00:00:08.93
167
SQL> select * from v$mystats
2 where name like '%pga%'
3 /
NAME VALUE
------------------------------ ----------
session pga memory 501534672
session pga memory max 501534672
168
500m of memory !
165 166
167 168
26/11/2019
43
169
law of diminishing returns
170
pin rows on a block (8k)
171
SQL> declare
. . .
9 begin
10 open c;
11 loop
12 fetch c
13 bulk collect
14 into r limit 100;
15 exit when c%notfound;
. . .
19 /
Elapsed: 00:00:08.17
NAME VALUE
------------------------------ ----------
session pga memory 625912
session pga memory max 625912
172
SQL> declare
. . .
9 begin
10 for i in c loop
12 ...
16 end loop;
17 end;
18 /
Elapsed: 00:00:08.21
169 170
171 172
26/11/2019
44
173
not just your code, but our code too
174
175 176
< 18 18,19 19.2
Classic
IR
IG
173 174
175 176
26/11/2019
45
177
PART #2(a)
storing data
178
the same rules apply
179
think blocks not rows
when appropriate
180
commit when it makes sense to
177 178
179 180
26/11/2019
46
181
demo
InsertDemo3
InsertDemo4 nn
182
summary
183
avoid parsing costs
for high frequency SQL
184
use binding and don't get hacked !
181 182
183 184
26/11/2019
47
185
using PLSQL is golden
186
and you can do it all .... for free
oracle.com/gbtour
New Free Tier
Always Free
Oracle Cloud Infrastructure
Services you can use for unlimited time
30-Day Free Trial
Free credits you can use for more services
+
Thanks for coming!
connor-mcdonald.com
https://bit.ly/techguysong
185 186
187 188

More Related Content

What's hot

Hardening Drupal setup
Hardening Drupal setupHardening Drupal setup
Hardening Drupal setupZeeland Family
 
Dbms plan - A swiss army knife for performance engineers
Dbms plan - A swiss army knife for performance engineersDbms plan - A swiss army knife for performance engineers
Dbms plan - A swiss army knife for performance engineersRiyaj Shamsudeen
 
Riyaj: why optimizer_hates_my_sql_2010
Riyaj: why optimizer_hates_my_sql_2010Riyaj: why optimizer_hates_my_sql_2010
Riyaj: why optimizer_hates_my_sql_2010Riyaj Shamsudeen
 
SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013Connor McDonald
 
pstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databasepstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databaseRiyaj Shamsudeen
 
Demystifying cost based optimization
Demystifying cost based optimizationDemystifying cost based optimization
Demystifying cost based optimizationRiyaj Shamsudeen
 
Bluespec Tutorial Helloworld
Bluespec Tutorial HelloworldBluespec Tutorial Helloworld
Bluespec Tutorial HelloworldStanley Ho
 
Devouring Security Sqli Exploitation and Prevention
Devouring Security Sqli Exploitation and PreventionDevouring Security Sqli Exploitation and Prevention
Devouring Security Sqli Exploitation and Preventiongmaran23
 
IEEE Day 2013 Oracle Database 12c: new features for developers
IEEE Day 2013 Oracle Database 12c: new features for developersIEEE Day 2013 Oracle Database 12c: new features for developers
IEEE Day 2013 Oracle Database 12c: new features for developersRamin Orujov
 
Using SQL to process hierarchies
Using SQL to process hierarchiesUsing SQL to process hierarchies
Using SQL to process hierarchiesConnor McDonald
 
Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Wim Godden
 
How To Check IE Enhanced Security Is Enabled Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShellHow To Check IE Enhanced Security Is Enabled Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShellVCP Muthukrishna
 
Most important "trick" of performance instrumentation
Most important "trick" of performance instrumentationMost important "trick" of performance instrumentation
Most important "trick" of performance instrumentationCary Millsap
 
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 riversCary Millsap
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...VCP Muthukrishna
 
Software diseases: memset
Software diseases: memsetSoftware diseases: memset
Software diseases: memsetPVS-Studio
 

What's hot (20)

Hardening Drupal setup
Hardening Drupal setupHardening Drupal setup
Hardening Drupal setup
 
Dbms plan - A swiss army knife for performance engineers
Dbms plan - A swiss army knife for performance engineersDbms plan - A swiss army knife for performance engineers
Dbms plan - A swiss army knife for performance engineers
 
Riyaj: why optimizer_hates_my_sql_2010
Riyaj: why optimizer_hates_my_sql_2010Riyaj: why optimizer_hates_my_sql_2010
Riyaj: why optimizer_hates_my_sql_2010
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 
SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013SQL Tuning 101 - Sep 2013
SQL Tuning 101 - Sep 2013
 
pstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databasepstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle database
 
Demystifying cost based optimization
Demystifying cost based optimizationDemystifying cost based optimization
Demystifying cost based optimization
 
Bluespec Tutorial Helloworld
Bluespec Tutorial HelloworldBluespec Tutorial Helloworld
Bluespec Tutorial Helloworld
 
Devouring Security Sqli Exploitation and Prevention
Devouring Security Sqli Exploitation and PreventionDevouring Security Sqli Exploitation and Prevention
Devouring Security Sqli Exploitation and Prevention
 
IEEE Day 2013 Oracle Database 12c: new features for developers
IEEE Day 2013 Oracle Database 12c: new features for developersIEEE Day 2013 Oracle Database 12c: new features for developers
IEEE Day 2013 Oracle Database 12c: new features for developers
 
Analytic SQL Sep 2013
Analytic SQL Sep 2013Analytic SQL Sep 2013
Analytic SQL Sep 2013
 
Using SQL to process hierarchies
Using SQL to process hierarchiesUsing SQL to process hierarchies
Using SQL to process hierarchies
 
Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?
 
How To Check IE Enhanced Security Is Enabled Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShellHow To Check IE Enhanced Security Is Enabled Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShell
 
Cent os 5 ssh
Cent os 5 sshCent os 5 ssh
Cent os 5 ssh
 
Most important "trick" of performance instrumentation
Most important "trick" of performance instrumentationMost important "trick" of performance instrumentation
Most important "trick" of performance instrumentation
 
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
 
Crack.ba
Crack.baCrack.ba
Crack.ba
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
 
Software diseases: memset
Software diseases: memsetSoftware diseases: memset
Software diseases: memset
 

Similar to APEX tour 2019 - successful development with autonomous

Feb14 successful development
Feb14 successful developmentFeb14 successful development
Feb14 successful developmentConnor McDonald
 
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 DevelopersConnor McDonald
 
A close encounter_with_real_world_and_odd_perf_issues
A close encounter_with_real_world_and_odd_perf_issuesA close encounter_with_real_world_and_odd_perf_issues
A close encounter_with_real_world_and_odd_perf_issuesRiyaj Shamsudeen
 
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 JediConnor McDonald
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresConnor McDonald
 
DeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestDeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestAtifkhilji
 
Oracle pl sql
Oracle pl sqlOracle pl sql
Oracle pl sqlDurga Rao
 
Tokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java DeveloperTokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java DeveloperConnor McDonald
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessionsConnor McDonald
 
12c for Developers - Feb 2014
12c for Developers - Feb 201412c for Developers - Feb 2014
12c for Developers - Feb 2014Connor McDonald
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101Connor McDonald
 
11 Things About 11gr2
11 Things About 11gr211 Things About 11gr2
11 Things About 11gr2afa reg
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentConnor McDonald
 
04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)Alexandre Moneger
 
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 PLSQLConnor McDonald
 
ILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for DevelopersILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for DevelopersConnor McDonald
 

Similar to APEX tour 2019 - successful development with autonomous (20)

Feb14 successful development
Feb14 successful developmentFeb14 successful development
Feb14 successful development
 
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
 
A close encounter_with_real_world_and_odd_perf_issues
A close encounter_with_real_world_and_odd_perf_issuesA close encounter_with_real_world_and_odd_perf_issues
A close encounter_with_real_world_and_odd_perf_issues
 
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
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
DeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestDeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latest
 
Oracle pl sql
Oracle pl sqlOracle pl sql
Oracle pl sql
 
Tokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java DeveloperTokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java Developer
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
 
12c for Developers - Feb 2014
12c for Developers - Feb 201412c for Developers - Feb 2014
12c for Developers - Feb 2014
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101
 
11 Things About 11gr2
11 Things About 11gr211 Things About 11gr2
11 Things About 11gr2
 
PLSQL
PLSQLPLSQL
PLSQL
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
 
Optimizer Statistics
Optimizer StatisticsOptimizer Statistics
Optimizer Statistics
 
Sge
SgeSge
Sge
 
Cursors
CursorsCursors
Cursors
 
04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)
 
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
 
ILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for DevelopersILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for Developers
 

More from Connor McDonald

Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesConnor McDonald
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresConnor McDonald
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne Connor McDonald
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsConnor McDonald
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistencyConnor McDonald
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsConnor McDonald
 
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 featuesConnor McDonald
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - FlashbackConnor McDonald
 
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 featuresConnor McDonald
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingConnor McDonald
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processingConnor McDonald
 
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+ optimizerConnor McDonald
 
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 tipsConnor McDonald
 
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 developersConnor McDonald
 
Kscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAsKscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAsConnor McDonald
 
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 processingConnor McDonald
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAsConnor McDonald
 
Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Connor McDonald
 

More from Connor McDonald (19)

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
 
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
 
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
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
 
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
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processing
 
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
 
Kscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAsKscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAs
 
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
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

APEX tour 2019 - successful development with autonomous

  • 1. 26/11/2019 1 1 a good background in ... 2 ... SQL processing, aka 3 ... successful application development 4 Connor McDonald 1 2 3 4
  • 2. 26/11/2019 2 Copyright© 2018, Oracleand/or its affiliates. All rights reserved. 5 Copyright© 2018, Oracleand/or its affiliates. All rights reserved. 6 Getting in touch is easy... @connor_mc_d https://linktr.ee/connor Copyright© 2018, Oracleand/or its affiliates. All rights reserved. 8https://asktom.oracle.com 5 6 7 8
  • 3. 26/11/2019 3 Copyright© 2018, Oracleand/or its affiliates. All rights reserved.https://asktom.oracle.com/officehours10 250 hours free access so far 11 assumptions 1. You roughly know databases (tables and columns) 2. You can write a SQL statement 12 SQL is like any language 9 10 11 12
  • 4. 26/11/2019 4 13 compile it on the fly 14 run it 15 get | store results 16 for successful applications... 13 14 15 16
  • 5. 26/11/2019 5 17 compile it ... fast 18 run it ... fast 19 get | store results ... fast 20 that's it! 17 18 19 20
  • 6. 26/11/2019 6 21 what everyone talks about 22 compile execute store/fetch results 23 this session 24 compile execute store/fetch results 21 22 23 24
  • 7. 26/11/2019 7 25 before we begin ... 26 some controversy to start 27 here's the problem... 28 ... it's us 25 26 27 28
  • 8. 26/11/2019 8 29 a small digression 30 a little bit of history on servers ... 31 (not too) long ago 29 30 31 32
  • 9. 26/11/2019 9 33 FSB = "front side bus" 34 any access to ... anything 35 CPU capped 33 34 35 36
  • 11. 26/11/2019 11 ~2007 42 "why do I care?" 43 you can't blame the server (anymore) 44 if you can't get that performance ... 41 42 43 44
  • 12. 26/11/2019 12 45 ... it's you 47 "The sooner your company admits that you are not Google, the sooner you can get down to some real work" - Ted Dziuba 48 so what's holding you back ? 45 46 47 48
  • 13. 26/11/2019 13 49 It all comes down to... 50 too much work or ... 51 ... not being able to do work 52 PART #1 5 2 compiling SQL 49 50 51 52
  • 14. 26/11/2019 14 53 ... how to avoid work when processing SQL 54 terminology 55 cursorsdeclare 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 all of them ! 53 54 55 56
  • 15. 26/11/2019 15 57 3 phases 58 open process close gimme some memory do some stuff using that memory, maybe access other memory here's your memory back 59 memory access = controlled access 60 a quick primer on (database) memory 57 58 59 60
  • 17. 26/11/2019 17 67 limited resource lots of people want it concurrent access causes problems it's a complex system 65 66 67 68
  • 18. 26/11/2019 18 69 same with memory 70 SGA 71 SGA protected by 72 SGA protected by 1) get latch 69 70 71 72
  • 19. 26/11/2019 19 73 SGA protected by 2) access memory 74 SGA protected by 3) release latch 75 latch contention 76 someone must wait ... SGA protected by 73 74 75 76
  • 20. 26/11/2019 20 77 active wait 78 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 ? 77 78 79 80
  • 23. 26/11/2019 23 89 to run a SQL statement 90 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 91 Syntax Validity Optimization Rowsourcing Execution (Fetch) SQL> select empnoo 2 from emp; select empnoo * ERROR at line 1: ORA-00904: invalid column name 92 PLAN ------------------------------------- SELECT STATEMENT TABLE ACCESS BY INDEX ROWID EMP INDEX RANGE SCAN EMP_PK Syntax Validity Optimization Rowsourcing Execution (Fetch) 89 90 91 92
  • 25. 26/11/2019 25 97 parsing "compile" 98 lots of memory access 99 lots of latching ! 100 impossible to avoid ? 97 98 99 100
  • 26. 26/11/2019 26 101 library cache 102 previously executed statements 103 parse statement already in library cache ? reuse optimizer info reuse row source info select * from emp where empno = 123 syntactically, semantics OK 104 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 101 102 103 104
  • 27. 26/11/2019 27 105 select surname, firstname from emp where empno = 123 select * from dept where dname = 'SALES' probability of reuse low ? 106 some queries are “nearly the same” select surname, firstname from emp where empno = 123 select surname, firstname from emp where empno = 456 107 binding parse this... now run it with ? = 123 now run it with ? = 456 select surname, firstname from emp where empno = ? 108 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 105 106 107 108
  • 28. 26/11/2019 28 109 demo ParseDemo ParseDemoBind 110 "performance still looks ok" 111 let's make it real ParseDemo2 nn ParseDemo2Bind nn 112 much more serious 109 110 111 112
  • 29. 26/11/2019 29 113 building SQL by concatenation 114 you'll get hacked 115 select ename from emp where empno = 6543 select ename from emp where empno = 6543 and 1=0 union all select table_name from all_tables where table_name like '%SECURITY%' select ename from emp where empno = 6543 and 1=0 union all select username from app_security where ... 116 it takes 5 minutes to hack you 113 114 115 116
  • 30. 26/11/2019 30 117 for fast, secure SQL ... 118 ... always bind user input 119 "I'm an APEX developer... not an issue" 120 117 118 119 120
  • 31. 26/11/2019 31 121 other common culprits item protection create_collection_from_query 122 while we are talking binding 123 parse statement already in library cache ? reuse optimizer info reuse row source info select * from emp where empno = 123 syntactically, semantics OK Yes! Yes! ??? ??? 124 still some parsing to do 121 122 123 124
  • 32. 26/11/2019 32 125 Syntax Validity Optimization Rowsourcing Execution (Fetch) Hard Parse Soft Parse foundnot found in lib cache 126 scott@mydb> select * 2 from EMP 3 where EMPNO = :b1 sue@mydb> select * 2 from EMP 3 where EMPNO = :b1 SQL> desc sue.emp Name Null? Type ----------------- -------- ------------ EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) 127 (even soft) parsing = memory access = latching 128 can we do better ? 125 126 127 128
  • 33. 26/11/2019 33 129 your SQL is always shareable library cache select * from emp 130 your cursor points to it cursor library cache select * from emp 131 close cursor = lose pointer cursor library cache select * from emp 132 next time we parse soft parse 129 130 131 132
  • 34. 26/11/2019 34 133 what if we don't close the cursor 134 emplist(String[] args) { if "first time I'm using this" { else "reset the pointer, re-execute" } library cache select * from emp select * from dept select * from emp where ... pstmt_all_emp = con.prepareStatement("select * from emp"); cursor cursor cursor 135 don’t close the cursorhang on to the memoryremember what cursors we’ve usedreuse whenever possibledon’t exhaust memorydon’t allow invalid cursor reuse 136 sounds complicated ... 133 134 135 136
  • 35. 26/11/2019 35 137 a free solution exists 138 plsql 139 create procedure MY_PROC is begin select empno, ename, ... into … from emp where empno = my_plsql_variable ... end; 140 static SQL in stored PLSQL automatically uses bind variables hold’s cursors open (even if you close) 137 138 139 140
  • 36. 26/11/2019 36 141 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 … 142 PART #2 get | store results we'll come back to running SQL 143 144 start with reading data 141 142 143 144
  • 37. 26/11/2019 37 145 querying data 146 data is stored in blocks | pages 147 to read data, you read blocks... 148 SQL> select * 2 from EMP 3 where ... /u01/my_data1.dat memory 145 146 147 148
  • 38. 26/11/2019 38 149 but (database) memory access is complex 150 SQL> select * 2 from EMP 3 where … SQL> update EMP 2 set … 3 where … SQL> select * 2 from EMP 3 where … SQL> insert into 2 EMP 3 values (…) SQL> select * 2 from CUSTOMER 3 / SQL> select max(EMPNO) 2 from EMP SQL> delete 2 from DEPT 3 / 151 we have to latch ! 152 • Get latch • Search along list of blocks in memory • Read block • Extract row of interest • Release latch • Give row back to client "fetch a row" 149 150 151 152
  • 39. 26/11/2019 39 153 lots of rows 154 lots of latching 155 typical program 156 rs = stmt.executeQuery("..."); while(rs.next()) { v1 = rs.getInt(1); v2 = rs.getString(2); ... } • Get latch • Walk along list • Get block • Extract single row • Release latch • Give row back to client • Get latch (again) • Walk along list (again) • Get block (again) • Extract single row • Release latch (again) • Give row back to client (again) Row #1 Row #2 • Get latch (again) • Walk along list (again) • Get block (again) • Extract single row • Release latch (again) • Give row back to client (again) Row #3 153 154 155 156
  • 40. 26/11/2019 40 157 a better strategy.... “pinning” 158 "fetch a row" • Get latch • Walk along list • Get block • Pin the block • Release latch • Give row 1 back to client • Give row 2 back to client … • Give row n to client • Get latch • Walk along list • Remove my pin on the block • Release latch “and .. I’ll will need several rows from this block” 159 how do you say “I may want many rows” ? 160 responsibility of the client 157 158 159 160
  • 41. 26/11/2019 41 161 FetchDemo nn 162 focus on blocks 163 focus on roundtrips 164 all that data goes somewhere 161 162 163 164
  • 42. 26/11/2019 42 165 SQL> declare cursor C is select ... (500m table) ... 9 begin 10 open c; 11 loop 12 fetch c 13 into r; 14 exit when c%notfound; . . . 19 / Elapsed: 00:01:11.72 166 SQL> declare cursor C is select ... (500m table) . . . 9 begin 10 open c; 11 12 fetch c 13 bulk collect 14 into r; 15 . . . 19 / Elapsed: 00:00:08.93 167 SQL> select * from v$mystats 2 where name like '%pga%' 3 / NAME VALUE ------------------------------ ---------- session pga memory 501534672 session pga memory max 501534672 168 500m of memory ! 165 166 167 168
  • 43. 26/11/2019 43 169 law of diminishing returns 170 pin rows on a block (8k) 171 SQL> declare . . . 9 begin 10 open c; 11 loop 12 fetch c 13 bulk collect 14 into r limit 100; 15 exit when c%notfound; . . . 19 / Elapsed: 00:00:08.17 NAME VALUE ------------------------------ ---------- session pga memory 625912 session pga memory max 625912 172 SQL> declare . . . 9 begin 10 for i in c loop 12 ... 16 end loop; 17 end; 18 / Elapsed: 00:00:08.21 169 170 171 172
  • 44. 26/11/2019 44 173 not just your code, but our code too 174 175 176 < 18 18,19 19.2 Classic IR IG 173 174 175 176
  • 45. 26/11/2019 45 177 PART #2(a) storing data 178 the same rules apply 179 think blocks not rows when appropriate 180 commit when it makes sense to 177 178 179 180
  • 46. 26/11/2019 46 181 demo InsertDemo3 InsertDemo4 nn 182 summary 183 avoid parsing costs for high frequency SQL 184 use binding and don't get hacked ! 181 182 183 184
  • 47. 26/11/2019 47 185 using PLSQL is golden 186 and you can do it all .... for free oracle.com/gbtour New Free Tier Always Free Oracle Cloud Infrastructure Services you can use for unlimited time 30-Day Free Trial Free credits you can use for more services + Thanks for coming! connor-mcdonald.com https://bit.ly/techguysong 185 186 187 188