About the Author |
|
xxiii | |
About the Technical Reviewer |
|
xxv | |
Acknowledgments |
|
xxvii | |
Introduction |
|
xxix | |
Part I Learn How to Learn |
|
1 | (104) |
|
Chapter 1 Understand Relational Databases |
|
|
3 | (26) |
|
History of Relational Databases |
|
|
3 | (3) |
|
Relational Model and Why It Matters |
|
|
6 | (3) |
|
|
6 | (1) |
|
|
7 | (1) |
|
|
7 | (1) |
|
|
8 | (1) |
|
Problems Implementing a Relational Model |
|
|
8 | (1) |
|
Relational Model and Why It Doesn't Matter |
|
|
9 | (3) |
|
The NULL Problem Isn't a Problem |
|
|
9 | (2) |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
12 | (1) |
|
|
12 | (5) |
|
|
12 | (1) |
|
|
13 | (3) |
|
Is SQL a Programming Language? |
|
|
16 | (1) |
|
|
17 | (2) |
|
Alternative Database Models |
|
|
17 | (1) |
|
Different Oracle Databases (OLTP vs. DW) |
|
|
18 | (1) |
|
|
19 | (9) |
|
|
20 | (2) |
|
|
22 | (6) |
|
|
28 | (1) |
|
Chapter 2 Create an Efficient Database Development Process |
|
|
29 | (22) |
|
Shared Database vs. Private Database |
|
|
29 | (1) |
|
Create an Infinite Number of Databases |
|
|
30 | (6) |
|
Advantages of Private Databases |
|
|
31 | (3) |
|
How to Implement Private Databases |
|
|
34 | (2) |
|
Rapidly Drop and Recreate Schemas |
|
|
36 | (6) |
|
|
36 | (1) |
|
|
37 | (1) |
|
SQL*Plus Installation Scripts |
|
|
38 | (2) |
|
|
40 | (2) |
|
Control and Integrate Schemas with Version-Controlled Text Files |
|
|
42 | (4) |
|
|
42 | (1) |
|
Load Objects from the Repository and File System |
|
|
43 | (1) |
|
Create and Save Changes Manually |
|
|
44 | (2) |
|
|
46 | (4) |
|
Power Imbalance Between Developers and Administrators |
|
|
47 | (1) |
|
|
48 | (1) |
|
|
49 | (1) |
|
|
49 | (1) |
|
|
50 | (1) |
|
Chapter 3 Increase Confidence and Knowledge with Testing |
|
|
51 | (26) |
|
Build Confidence with Automated Tests |
|
|
51 | (8) |
|
|
51 | (1) |
|
Gain Confidence, Avoid Biases |
|
|
52 | (1) |
|
|
53 | (1) |
|
|
53 | (2) |
|
|
55 | (1) |
|
|
56 | (1) |
|
How to Build Automated Tests |
|
|
56 | (3) |
|
Build Knowledge with Minimal, Complete, and Verifiable Examples |
|
|
59 | (8) |
|
Why Spend So Much Time Building Reproducible Test Cases? |
|
|
59 | (1) |
|
|
60 | (1) |
|
|
61 | (1) |
|
|
62 | (2) |
|
|
64 | (1) |
|
|
65 | (1) |
|
Oracle Performance Testing |
|
|
65 | (2) |
|
|
67 | (8) |
|
|
67 | (2) |
|
Dynamic Performance Views |
|
|
69 | (3) |
|
Relational Tools for Inspecting Databases |
|
|
72 | (2) |
|
Non-relational Tools for Inspecting Databases |
|
|
74 | (1) |
|
|
75 | (2) |
|
Chapter 4 Find Reliable Sources |
|
|
77 | (10) |
|
|
78 | (6) |
|
|
78 | (1) |
|
The Problems with Static Websites |
|
|
79 | (1) |
|
|
79 | (3) |
|
The Manual Is Not Perfect |
|
|
82 | (1) |
|
|
83 | (1) |
|
|
84 | (1) |
|
|
85 | (2) |
|
Chapter 5 Master the Entire Stack |
|
|
87 | (18) |
|
|
87 | (2) |
|
|
89 | (1) |
|
Operating Systems and Supporting Programs |
|
|
89 | (4) |
|
|
90 | (1) |
|
|
90 | (1) |
|
|
91 | (1) |
|
Reporting Tools and Excel |
|
|
92 | (1) |
|
|
93 | (1) |
|
|
94 | (2) |
|
When We Should Use SQL*Plus |
|
|
94 | (1) |
|
When We Should Not Use SQL*Plus |
|
|
95 | (1) |
|
Integrated Development Environment |
|
|
96 | (3) |
|
|
97 | (1) |
|
When Not to Use an IDE Feature |
|
|
98 | (1) |
|
|
98 | (1) |
|
Worksheets, Notebooks, Snippets, Scripts, and Gists |
|
|
99 | (4) |
|
|
99 | (1) |
|
|
100 | (3) |
|
|
103 | (2) |
Part II Write Powerful SQL with Sets and Advanced Features |
|
105 | (186) |
|
Chapter 6 Build Sets with Inline Views and ANSI Join Syntax |
|
|
107 | (20) |
|
Spaghetti Code from Nonstandard Syntax |
|
|
107 | (5) |
|
|
108 | (1) |
|
|
109 | (1) |
|
Accidental Cross Joins in Old Syntax |
|
|
110 | (1) |
|
Nonstandard but Still Useful |
|
|
111 | (1) |
|
|
112 | (3) |
|
The Importance of Limiting Context |
|
|
112 | (1) |
|
Avoid Correlated Subqueries |
|
|
113 | (1) |
|
Avoid Common Table Expressions |
|
|
114 | (1) |
|
Sets, Chunking, and Functional Programming to the Rescue |
|
|
115 | (4) |
|
|
115 | (1) |
|
|
116 | (2) |
|
|
118 | (1) |
|
|
119 | (3) |
|
|
119 | (1) |
|
Inline Views Make Code Bigger but Simpler |
|
|
120 | (1) |
|
Simple Inline Views for a Large Example |
|
|
121 | (1) |
|
|
122 | (1) |
|
|
123 | (3) |
|
|
126 | (1) |
|
Chapter 7 Query the Database with Advanced SELECT Features |
|
|
127 | (64) |
|
Operators, Functions, Expressions, and Conditions |
|
|
128 | (3) |
|
|
128 | (1) |
|
How to Know When We're Missing Something |
|
|
128 | (1) |
|
|
129 | (1) |
|
|
130 | (1) |
|
|
131 | (2) |
|
|
133 | (7) |
|
|
134 | (2) |
|
Lateral, Cross Apply, and Outer Apply |
|
|
136 | (1) |
|
|
136 | (1) |
|
|
136 | (2) |
|
|
138 | (1) |
|
Natural Joins and USING Considered Harmful |
|
|
139 | (1) |
|
|
140 | (2) |
|
|
140 | (2) |
|
Sorting Performance, Resources, and Implicit Sorting |
|
|
142 | (1) |
|
|
142 | (4) |
|
|
143 | (1) |
|
|
144 | (1) |
|
Set Operator Complications |
|
|
145 | (1) |
|
|
146 | (4) |
|
|
146 | (2) |
|
|
148 | (1) |
|
Advanced Aggregate Functions |
|
|
149 | (1) |
|
|
150 | (4) |
|
|
150 | (1) |
|
Analytic Function Examples |
|
|
151 | (3) |
|
|
154 | (5) |
|
Regular Expression Syntax |
|
|
154 | (1) |
|
Regular Expression Examples |
|
|
155 | (3) |
|
Regular Expression Limitations |
|
|
158 | (1) |
|
|
159 | (3) |
|
|
159 | (1) |
|
|
160 | (1) |
|
Analytic Function Row Limiting |
|
|
161 | (1) |
|
|
162 | (6) |
|
|
163 | (1) |
|
|
164 | (1) |
|
|
165 | (3) |
|
|
168 | (2) |
|
|
168 | (1) |
|
|
169 | (1) |
|
Partition Extension Clause |
|
|
169 | (1) |
|
|
170 | (4) |
|
|
170 | (2) |
|
PL/SQL Common Table Expressions |
|
|
172 | (1) |
|
|
173 | (1) |
|
|
174 | (3) |
|
|
174 | (2) |
|
Recursive Common Table Expressions |
|
|
176 | (1) |
|
|
177 | (5) |
|
|
177 | (2) |
|
DBMS_XMLGEN and Creating XML |
|
|
179 | (1) |
|
|
180 | (1) |
|
XML Programming Languages |
|
|
181 | (1) |
|
|
182 | (3) |
|
Build and Store JSON in the Database |
|
|
182 | (2) |
|
|
184 | (1) |
|
National Language Support |
|
|
185 | (5) |
|
|
186 | (1) |
|
|
187 | (1) |
|
NLS Comparing and Sorting |
|
|
188 | (1) |
|
|
189 | (1) |
|
|
190 | (1) |
|
Chapter 8 Modify Data with Advanced DML |
|
|
191 | (28) |
|
|
192 | (1) |
|
|
193 | (1) |
|
|
194 | (2) |
|
|
196 | (2) |
|
|
198 | (1) |
|
|
199 | (2) |
|
|
201 | (2) |
|
|
203 | (1) |
|
|
204 | (3) |
|
COMMIT, ROLLBACK, and SAVEPOINT |
|
|
207 | (2) |
|
|
209 | (2) |
|
|
211 | (1) |
|
|
212 | (2) |
|
|
214 | (3) |
|
|
217 | (2) |
|
Chapter 9 Improve the Database with Advanced Oracle Schema Objects |
|
|
219 | (46) |
|
|
219 | (2) |
|
|
221 | (10) |
|
|
221 | (4) |
|
|
225 | (4) |
|
|
229 | (1) |
|
Column Types and Properties |
|
|
229 | (2) |
|
|
231 | (6) |
|
Constraint Performance Impact |
|
|
232 | (1) |
|
|
232 | (1) |
|
|
233 | (1) |
|
NOVALIDATE and Parallel Constraints |
|
|
234 | (2) |
|
|
236 | (1) |
|
|
237 | (6) |
|
|
237 | (2) |
|
|
239 | (3) |
|
|
242 | (1) |
|
|
243 | (5) |
|
|
243 | (3) |
|
|
246 | (2) |
|
|
248 | (2) |
|
|
248 | (1) |
|
|
249 | (1) |
|
|
250 | (2) |
|
|
252 | (2) |
|
|
254 | (1) |
|
|
254 | (3) |
|
Materialized Views for Multi-table Constraints |
|
|
255 | (2) |
|
|
257 | (2) |
|
|
259 | (1) |
|
|
260 | (1) |
|
|
260 | (1) |
|
|
261 | (2) |
|
|
263 | (2) |
|
Chapter 10 Optimize the Database with Oracle Architecture |
|
|
265 | (26) |
|
|
265 | (3) |
|
|
266 | (1) |
|
|
266 | (2) |
|
Undo and Multiversion Read Consistency |
|
|
268 | (4) |
|
|
268 | (2) |
|
Undo for Multiversion Consistency |
|
|
270 | (2) |
|
|
272 | (10) |
|
|
273 | (1) |
|
|
274 | (1) |
|
Blocks and Row-Level Locking |
|
|
275 | (2) |
|
|
277 | (1) |
|
|
277 | (1) |
|
|
278 | (1) |
|
|
279 | (1) |
|
Automatic Storage Management |
|
|
280 | (1) |
|
|
281 | (1) |
|
|
282 | (1) |
|
|
283 | (2) |
|
|
285 | (2) |
|
|
287 | (2) |
|
|
289 | (2) |
Part III Write Elegant SQL with Patterns and Styles |
|
291 | (88) |
|
Chapter 11 Stop Coding and Start Writing |
|
|
293 | (16) |
|
The Hypocrisy of Examples |
|
|
294 | (1) |
|
|
295 | (3) |
|
|
295 | (1) |
|
|
296 | (1) |
|
|
297 | (1) |
|
|
298 | (3) |
|
|
298 | (1) |
|
|
299 | (1) |
|
|
300 | (1) |
|
|
301 | (1) |
|
|
302 | (5) |
|
|
303 | (1) |
|
Avoid Pokemon Exception Handling |
|
|
303 | (2) |
|
Use Bad Names and Weird Values |
|
|
305 | (1) |
|
|
306 | (1) |
|
The Path to Writing Good SQL |
|
|
307 | (1) |
|
|
308 | (1) |
|
Chapter 12 Write Large SQL Statements |
|
|
309 | (18) |
|
Imperative Programming Size Limits Do Not Apply |
|
|
309 | (1) |
|
One Large SQL Statement vs. Multiple Small SQL Statements |
|
|
310 | (2) |
|
Performance Risks of Large SQL Statements |
|
|
312 | (4) |
|
Large SQL Parsing Problems |
|
|
312 | (1) |
|
Large SQL Increases Optimizer Risks |
|
|
313 | (2) |
|
Large SQL Resource Consumption Problems |
|
|
315 | (1) |
|
Performance Benefits of Large SQL Statements |
|
|
316 | (5) |
|
Large SQL Improves Clarity |
|
|
316 | (1) |
|
Large SQL Increases Optimizer Opportunities |
|
|
316 | (2) |
|
Large SQL Reduces Input/Output |
|
|
318 | (1) |
|
Large SQL Reduces Context Switches |
|
|
318 | (1) |
|
Large SQL Improves Parallelism |
|
|
319 | (2) |
|
Reading and Debugging Large SQL Statements |
|
|
321 | (4) |
|
|
321 | (1) |
|
|
322 | (3) |
|
|
325 | (2) |
|
Chapter 13 Write Beautiful SQL Statements |
|
|
327 | (12) |
|
How to Measure Code Complexity |
|
|
328 | (1) |
|
Avoid Unnecessary Aliases |
|
|
329 | (1) |
|
|
330 | (2) |
|
Object and Variable Names |
|
|
331 | (1) |
|
Referencing Tables and Columns |
|
|
331 | (1) |
|
|
332 | (1) |
|
Use Tabs for Left Alignment |
|
|
333 | (3) |
|
|
336 | (1) |
|
|
337 | (1) |
|
|
338 | (1) |
|
Chapter 14 Use SQL More Often with Basic Dynamic SQL |
|
|
339 | (16) |
|
|
339 | (5) |
|
|
340 | (1) |
|
|
341 | (1) |
|
|
342 | (1) |
|
|
343 | (1) |
|
When Not to Use Dynamic SQL |
|
|
343 | (1) |
|
|
344 | (1) |
|
Bind Variables for Performance and Security |
|
|
345 | (2) |
|
How to Simplify String Concatenation |
|
|
347 | (4) |
|
|
347 | (1) |
|
Alternative Quoting Mechanism |
|
|
348 | (2) |
|
|
350 | (1) |
|
Code Generation, Not Generic Code |
|
|
351 | (2) |
|
|
353 | (2) |
|
Chapter 15 Avoid Anti-Patterns |
|
|
355 | (24) |
|
Avoid Second System Syndrome and Rewriting from Scratch |
|
|
355 | (2) |
|
Avoid Stringly Typed Entity-Attribute-Value Model |
|
|
357 | (4) |
|
|
357 | (1) |
|
|
358 | (1) |
|
Subtle Conversion Bugs in Oracle SQL |
|
|
359 | (2) |
|
|
361 | (1) |
|
Avoid Object-Relational Tables |
|
|
362 | (2) |
|
Avoid Java in the Database |
|
|
364 | (1) |
|
Java Is Not Always Available |
|
|
364 | (1) |
|
Java Does Not Fit Perfectly |
|
|
364 | (1) |
|
SQL and PL/SQL Are Almost Always Better Choices |
|
|
365 | (1) |
|
|
365 | (3) |
|
Avoid String-to-Date Conversion |
|
|
366 | (1) |
|
Use DATE, TIMESTAMP, and INTERVAL Literals |
|
|
367 | (1) |
|
|
368 | (2) |
|
|
370 | (2) |
|
Avoid Automating Everything |
|
|
372 | (1) |
|
|
373 | (1) |
|
Avoid Undocumented Features |
|
|
373 | (1) |
|
Avoid Deprecated Features |
|
|
374 | (1) |
|
Avoid Simplistic Explanations for Generic Errors |
|
|
374 | (3) |
|
|
375 | (1) |
|
|
375 | (1) |
|
|
376 | (1) |
|
Avoid Unnecessarily Small Parameters |
|
|
377 | (1) |
|
Anti-Patterns Discussed in Other Chapters |
|
|
378 | (1) |
|
|
378 | (1) |
Part IV: Improve SQL Performance |
|
379 | (126) |
|
Chapter 16 Understand SQL Performance with Algorithm Analysis |
|
|
381 | (30) |
|
Algorithm Analysis Introduction |
|
|
382 | (4) |
|
O(1/N) — Batching to Reduce Overhead |
|
|
386 | (2) |
|
O(1) — Hashing, Other Operations |
|
|
388 | (4) |
|
|
388 | (2) |
|
|
390 | (1) |
|
|
391 | (1) |
|
|
392 | (1) |
|
|
392 | (1) |
|
|
393 | (2) |
|
1/((1-P)+P/N) — Amdahl's Law |
|
|
395 | (2) |
|
O(N) — Full Table Scans, Other Operations |
|
|
397 | (1) |
|
O(N*LOG(N)) — Full Table Scan vs. Index, Sorting, Joining, Global vs. Local Index, Gathering Statistics |
|
|
398 | (9) |
|
Full Table Scan vs. Index |
|
|
399 | (1) |
|
|
400 | (1) |
|
|
401 | (3) |
|
|
404 | (1) |
|
Gathering Optimizer Statistics |
|
|
404 | (3) |
|
O(N^2) — Cross Joins, Nested Loops, Other Operations |
|
|
407 | (2) |
|
|
409 | (1) |
|
O(infinity) —The Optimizer |
|
|
409 | (1) |
|
|
410 | (1) |
|
Chapter 17 Understand SQL Tuning Theories |
|
|
411 | (38) |
|
Managing User Expectations |
|
|
411 | (1) |
|
Performance Tuning State of Mind |
|
|
412 | (4) |
|
Performance Tuning Is Not Debugging |
|
|
413 | (1) |
|
Motivated Troubleshooting |
|
|
413 | (1) |
|
|
414 | (2) |
|
|
416 | (1) |
|
Declarative Programming (Why Execution Plans Are Important) |
|
|
416 | (2) |
|
|
416 | (1) |
|
|
417 | (1) |
|
Operations (What Execution Plan Decisions Are Available) |
|
|
418 | (14) |
|
|
419 | (1) |
|
Execution Plans and Recursive SQL |
|
|
419 | (1) |
|
|
420 | (1) |
|
|
421 | (1) |
|
|
421 | (2) |
|
|
423 | (1) |
|
|
424 | (1) |
|
|
425 | (1) |
|
|
425 | (1) |
|
|
426 | (1) |
|
|
426 | (3) |
|
|
429 | (1) |
|
|
430 | (1) |
|
|
431 | (1) |
|
Cardinality and Optimizer Statistics (Building Execution Plans I) |
|
|
432 | (8) |
|
|
433 | (2) |
|
|
435 | (1) |
|
|
436 | (1) |
|
|
436 | (2) |
|
Optimizer Statistics Example |
|
|
438 | (2) |
|
Transformations and Dynamic Optimizations (Building Execution Plans II) |
|
|
440 | (7) |
|
|
440 | (2) |
|
Adaptive Cursor Sharing and Adaptive Statistics |
|
|
442 | (2) |
|
|
444 | (3) |
|
|
447 | (1) |
|
|
448 | (1) |
|
Chapter 18 Improve SQL Performance |
|
|
449 | (56) |
|
Application Tuning - Logging and Profiling |
|
|
449 | (5) |
|
|
450 | (1) |
|
Profiling - DBMS_PROFILER |
|
|
451 | (2) |
|
|
453 | (1) |
|
Application Tuning Through Batching |
|
|
454 | (5) |
|
Installation and Patch Scripts |
|
|
455 | (2) |
|
|
457 | (1) |
|
|
458 | (1) |
|
|
459 | (11) |
|
Measure Database Performance |
|
|
460 | (3) |
|
Automatic Workload Repository (AWR) |
|
|
463 | (2) |
|
Active Session History (ASH) |
|
|
465 | (1) |
|
Automatic Database Diagnostic Monitor (ADDM) |
|
|
466 | (2) |
|
|
468 | (1) |
|
|
469 | (1) |
|
SQL Tuning - Find Slow SQL |
|
|
470 | (3) |
|
|
470 | (1) |
|
|
470 | (1) |
|
Find Currently Running Slow SQL |
|
|
471 | (2) |
|
Find Historically Slow SQL |
|
|
473 | (1) |
|
SQL Tuning - Find Execution Plans |
|
|
473 | (7) |
|
Graphical Execution Plans Considered Harmful |
|
|
473 | (2) |
|
|
475 | (2) |
|
|
477 | (1) |
|
DBMS_XPLAN FORMAT Parameter |
|
|
478 | (1) |
|
|
479 | (1) |
|
Other Ways to Get Execution Plans |
|
|
480 | (1) |
|
SQL Tuning - Find Actual Times and Cardinalities for Operations |
|
|
480 | (13) |
|
|
481 | (4) |
|
Real-Time SQL Monitor Reports (Text) |
|
|
485 | (3) |
|
Real-Time SQL Monitor Reports (Active) |
|
|
488 | (1) |
|
|
489 | (2) |
|
What to Look for in Execution Plans |
|
|
491 | (2) |
|
SQL Tuning - Changing Execution Plans |
|
|
493 | (6) |
|
|
493 | (2) |
|
|
495 | (2) |
|
|
497 | (2) |
|
SQL Tuning - Gathering Optimizer Statistics |
|
|
499 | (4) |
|
|
499 | (2) |
|
|
501 | (1) |
|
|
501 | (2) |
|
|
503 | (2) |
Part V Solve Anything with Oracle SQL |
|
505 | (74) |
|
Chapter 19 Solve Challenging Problems with Arcane SQL Features |
|
|
507 | (16) |
|
Oracle vs. the Unix Philosophy |
|
|
507 | (1) |
|
|
508 | (4) |
|
|
512 | (1) |
|
|
513 | (2) |
|
|
515 | (2) |
|
|
517 | (2) |
|
|
519 | (2) |
|
Advanced Analytics (Data Mining) |
|
|
519 | (1) |
|
|
519 | (1) |
|
|
519 | (1) |
|
|
520 | (1) |
|
|
520 | (1) |
|
|
521 | (1) |
|
|
521 | (1) |
|
|
521 | (2) |
|
Chapter 20 Use SQL More Often with Advanced Dynamic SQL |
|
|
523 | (14) |
|
|
523 | (5) |
|
|
524 | (1) |
|
|
525 | (1) |
|
|
526 | (2) |
|
|
528 | (1) |
|
|
529 | (2) |
|
PL/SQL Common Table Expressions |
|
|
531 | (1) |
|
|
532 | (1) |
|
Polymorphic Table Functions |
|
|
533 | (1) |
|
|
534 | (1) |
|
|
535 | (2) |
|
Chapter 21 Level Up Your Skills with PL/SQL |
|
|
537 | (42) |
|
Is PL/SQL Worth Mastering? |
|
|
537 | (1) |
|
The Focus Is Still on SQL |
|
|
538 | (1) |
|
Create a PL/SQL Playground |
|
|
538 | (1) |
|
PL/SQL Integration Features |
|
|
539 | (36) |
|
|
540 | (1) |
|
|
540 | (3) |
|
Transactions I - COMMIT, ROLLBACK, and SAVEPOINT |
|
|
543 | (2) |
|
Transactions II - Implicit Cursor Attributes |
|
|
545 | (1) |
|
Transactions III - Row-Level Locking |
|
|
546 | (1) |
|
Transactions IV - Isolation and Consistency |
|
|
547 | (2) |
|
|
549 | (2) |
|
|
551 | (3) |
|
|
554 | (2) |
|
|
556 | (3) |
|
|
559 | (2) |
|
|
561 | (2) |
|
|
563 | (1) |
|
Parallel Pipelined Functions |
|
|
564 | (1) |
|
Autonomous Transactions for DML and DDL |
|
|
565 | (1) |
|
Autonomous Transactions for Logging |
|
|
566 | (2) |
|
Definer's Rights vs. Invoker's Rights |
|
|
568 | (1) |
|
|
569 | (5) |
|
|
574 | (1) |
|
|
575 | (1) |
|
Start Teaching and Creating |
|
|
575 | (4) |
|
|
576 | (1) |
|
Create Open Source Projects |
|
|
576 | (3) |
Part VI: Appendices |
|
579 | (6) |
|
Appendix A: SQL Style Guide Cheat Sheet |
|
|
581 | (2) |
|
Appendix B: Computer Science Topics |
|
|
583 | (2) |
Index |
|
585 | |