A look at the techniques that middle tier developers can employ to get greater value out of their applications, simply by having an understanding of how the database works and how to make it sing.
26. 26
"fine-grained to perform a single function"
"Each service is ... minimal, and complete"
https://en.wikipedia.org/wiki/Microservices
select COUNT(*)
from PEOPLE
where GENDER = 'MALE'
30. 30
"By abstracting the underlying implementation"
"describes the expected behaviour ... but can have multiple implementations"
https://en.wikipedia.org/wiki/Application_programming_interface
select NAME, STREET_NO, ZIP_CODE
from PEOPLE p,
ADDRESS a
where p.AGE > 50
and p.ADDRESS_ID = a.ADDRESS_ID;
40. SQL> with x( s, ind ) as
2 ( select sud, instr( sud, '.' )
3 from ( select replace(replace(
4 replace(replace(:board,'-'),'|'),' '),chr(10)) sud
5 from dual )
6 union all
7 select substr(s,1,ind-1)||z||substr(s,ind+1)
8 , instr(s,'.',ind+1)
9 from x
10 , ( select to_char( rownum ) z
11 from dual connect by rownum <= 9 ) z
12 where ind > 0
13 and not exists (
14 select null
15 from ( select rownum lp from dual
16 connect by rownum <= 9 )
17 where z = substr(s,trunc((ind-1)/9)*9+lp,1)
40
41. 18 or z = substr(s,mod(ind-1,9)-8+lp*9,1)
19 or z = substr(s,mod(trunc((ind-1)/3),3)*3
20 +trunc((ind-1)/27)*27+lp
21 +trunc((lp-1)/3)*6,1)
22 )
23 ),
24 result as (
25 select s
26 from x
27 where ind = 0 )
28 select
29 regexp_replace(substr(s,(idx-1)*9+1,9),
30 '(...)(...)(...)',
31 '1|2|3')||
32 case when mod(idx,3)=0 then chr(10)||rpad('-',11,'-') end soln
33 from result,
34 ( select level idx
35 from dual
36 connect by level <= 9 )
41
Ack: Anton Scheffer,
https://technology.amis.nl
71. 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 ?
71
86. • Get latch
• Search along list of blocks in memory (or "chain")
• Read block
• Extract row of interest
• Release latch
• Give row back to client
"fetch a row"
86
90. rs = stmt.executeQuery("...");
while(rs.next()) {
v1 = rs.getInt(1);
v2 = rs.getString(2);
...
}
• Get latch
• Walk along chain
• Get block
• Extract single row
• Release latch
• Give row back to client
• Get latch (again)
• Walk along chain (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 chain (again)
• Get block (again)
• Extract single row
• Release latch (again)
• Give row back to client (again)
Row #3
90
92. "fetch a row"
• Get latch
• Walk along chain
• 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 chain
• Remove my pin on the block
• Release latch
“and .. I’ll will need
several rows from
this block”
117. SQL> select name, gets
2 from v$latch
3 where name like 'library%' or name like 'shared%';
NAME GETS
------------------------------ ----------
shared pool 333907
shared pool simulator 7191
shared pool sim alloc 133
shared server configuration 6
shared server info 1
SQL> select 0 from dual;
0
----------
0
GETS
----------
333991 = 84
7196 = 5
135 = 2
6
1
162. select deptno,
nvl2(rownum,max(empno),null) empno,
nvl2(rownum,max(ename),null) ename,
sum(sal)
from emp
group by rollup(deptno,rownum)
order by deptno,empno;
DEPTNO EMPNO ENAME SUM(SAL)
---------- ---------- ---------- ----------
10 7782 CLARK 2450
10 7839 KING 5000
10 7934 MILLER 1300
10 8750
20 7369 SMITH 800
20 7566 JONES 2975
...
30 7900 JAMES 950
30 9400
29025 162
183. SQL> select
2 deptno,
3 rank(3000) within group ( order by sal ) as ranking
5 from emp
6 group by deptno;
DEPTNO RANKING
---------- ----------
10 2
20 4
30 7
40 2
189. "Find 10 or more consecutive bets in a
24 hour period,
then a large win within three days of
the last bet,
at a different location"
189
190. ACCT TSTAMP TYP AMT LOC
---------- ------------------ --- ---------- ----
54261 25/01/13 17:20:55 Bet 100 Tokyo
54261 25/01/13 17:56:58 Bet 165 Tokyo
54261 26/01/13 11:24:14 Bet 30 Tokyo
54261 26/01/13 11:47:53 Bet 45 Kyoto
54261 26/01/13 12:59:38 Bet 100 Tokyo
54261 26/01/13 13:26:04 Bet 80 Osaka
54261 26/01/13 14:41:09 Bet 50 Tokyo
54261 26/01/13 14:53:12 Bet 50 Osaka
54261 26/01/13 15:15:05 Bet 50 Yokahama
54261 26/01/13 15:51:17 Bet 50 Tokyo
54261 26/01/13 16:15:02 Bet 120 Tokyo
54261 26/01/13 16:36:51 Bet 100 Kobe
54261 26/01/13 16:55:09 Bet 100 Tokyo
54261 26/01/13 18:07:17 Win -5000 Osaka
190