About the Authors |
|
xi | |
About the Technical Reviewer |
|
xiii | |
Acknowledgments |
|
xv | |
Introduction |
|
xvii | |
|
|
1 | (12) |
|
What Do We Mean by Optimization? |
|
|
1 | (1) |
|
Why It Is Difficult: Imperative and Declarative |
|
|
2 | (3) |
|
|
5 | (2) |
|
|
7 | (1) |
|
|
8 | (1) |
|
Database Design and Performance |
|
|
8 | (2) |
|
Application Development and Performance |
|
|
10 | (1) |
|
Other Stages of the Lifecycle |
|
|
10 | (1) |
|
|
11 | (1) |
|
|
12 | (1) |
|
Chapter 2 Theory: Yes, We Need It! |
|
|
13 | (10) |
|
Query Processing Overview |
|
|
13 | (1) |
|
|
13 | (1) |
|
Optimization and Execution |
|
|
14 | (1) |
|
Relational, Logical, and Physical Operations |
|
|
15 | (1) |
|
|
15 | (4) |
|
|
19 | (1) |
|
Queries as Expressions: Thinking in Sets |
|
|
20 | (1) |
|
Operations and Algorithms |
|
|
20 | (1) |
|
|
21 | (2) |
|
Chapter 3 Even More Theory: Algorithms |
|
|
23 | (20) |
|
|
23 | (1) |
|
|
24 | (1) |
|
|
25 | (1) |
|
|
26 | (1) |
|
|
27 | (1) |
|
|
28 | (1) |
|
Comparing Data Access Algorithms |
|
|
28 | (3) |
|
|
31 | (1) |
|
|
31 | (2) |
|
|
33 | (2) |
|
Why Are B-Trees Used So Often? |
|
|
35 | (1) |
|
|
35 | (1) |
|
|
36 | (1) |
|
|
37 | (1) |
|
|
37 | (2) |
|
|
39 | (2) |
|
|
41 | (1) |
|
|
42 | (1) |
|
|
42 | (1) |
|
Chapter 4 Understanding Execution Plans |
|
|
43 | (14) |
|
Putting Everything Together: How an Optimizer Builds an Execution Plan |
|
|
43 | (1) |
|
|
44 | (5) |
|
Understanding Execution Plans |
|
|
49 | (1) |
|
What Is Going On During Optimization? |
|
|
49 | (1) |
|
Why Are There So Many Execution Plans to Choose From? |
|
|
50 | (1) |
|
How Are Execution Costs Calculated? |
|
|
51 | (3) |
|
How Can the Optimizer Be Led Astray? |
|
|
54 | (1) |
|
|
55 | (2) |
|
Chapter 5 Short Queries and Indexes |
|
|
57 | (44) |
|
Which Queries Are Considered Short? |
|
|
57 | (2) |
|
Choosing Selection Criteria |
|
|
59 | (1) |
|
|
60 | (1) |
|
Unique Indexes and Constraints |
|
|
61 | (4) |
|
Indexes and Non-equal Conditions |
|
|
65 | (1) |
|
Indexes and Column Transformations |
|
|
65 | (5) |
|
Indexes and the like Operator |
|
|
70 | (2) |
|
|
72 | (1) |
|
|
73 | (1) |
|
How Do Compound Indexes Work? |
|
|
74 | (2) |
|
|
76 | (1) |
|
Using Indexes for Data Retrieval |
|
|
76 | (1) |
|
|
77 | (2) |
|
Excessive Selection Criteria |
|
|
79 | (4) |
|
|
83 | (2) |
|
|
85 | (3) |
|
When Are Indexes Not Used |
|
|
88 | (1) |
|
|
89 | (1) |
|
Why Does PostgreSQL Ignore My Index? |
|
|
89 | (3) |
|
Let PostgreSQL Do Its Job! |
|
|
92 | (5) |
|
How to Build the Right Index(es)? |
|
|
97 | (1) |
|
|
97 | (1) |
|
Which Indexes Are Needed? |
|
|
98 | (1) |
|
Which Indexes Are Not Needed? |
|
|
98 | (1) |
|
Indexes and Short Query Scalability |
|
|
99 | (1) |
|
|
100 | (1) |
|
Chapter 6 Long Queries and Full Scans |
|
|
101 | (38) |
|
Which Queries Are Considered Long? |
|
|
101 | (2) |
|
Long Queries and Full Scans |
|
|
103 | (1) |
|
Long Queries and Hash Joins |
|
|
104 | (1) |
|
Long Queries and the Order of Joins |
|
|
105 | (1) |
|
|
105 | (2) |
|
Semi-joins and Join Order |
|
|
107 | (2) |
|
|
109 | (3) |
|
|
112 | (1) |
|
Semi- and Anti-joins Using the JOIN Operator |
|
|
113 | (3) |
|
When Is It Necessary to Specify Join Order? |
|
|
116 | (2) |
|
Grouping: Filter First, Group Last |
|
|
118 | (7) |
|
Grouping: Group First, Select Last |
|
|
125 | (3) |
|
|
128 | (4) |
|
|
132 | (6) |
|
|
138 | (1) |
|
Chapter 7 Long Queries: Additional Techniques |
|
|
139 | (28) |
|
|
139 | (1) |
|
Temporary Tables and CTEs |
|
|
140 | (1) |
|
|
140 | (2) |
|
Common Table Expressions (CTEs) |
|
|
142 | (5) |
|
Views: To Use or Not to Use |
|
|
147 | (7) |
|
|
154 | (1) |
|
|
154 | (1) |
|
Creating and Using Materialized Views |
|
|
154 | (2) |
|
Refreshing Materialized Views |
|
|
156 | (1) |
|
Create a Materialized View or Not? |
|
|
156 | (2) |
|
Do Materialized Views Need to Be Optimized? |
|
|
158 | (1) |
|
|
159 | (1) |
|
|
160 | (5) |
|
|
165 | (1) |
|
|
166 | (1) |
|
Chapter 8 Optimizing Data Modification |
|
|
167 | (10) |
|
|
167 | (1) |
|
Two Ways to Optimize Data Modification |
|
|
167 | (1) |
|
|
168 | (1) |
|
|
168 | (1) |
|
The Impact of Concurrency Control |
|
|
169 | (3) |
|
Data Modification and Indexes |
|
|
172 | (1) |
|
Mass Updates and Frequent Updates |
|
|
173 | (1) |
|
Referential Integrity and Triggers |
|
|
174 | (1) |
|
|
175 | (2) |
|
|
177 | (20) |
|
|
177 | (4) |
|
Why Use a Relational Model? |
|
|
181 | (1) |
|
|
182 | (1) |
|
Entity-Attribute-Value Model |
|
|
182 | (1) |
|
|
183 | (1) |
|
|
184 | (1) |
|
Combining the Best of Different Worlds |
|
|
185 | (1) |
|
Flexibility vs. Efficiency and Correctness |
|
|
185 | (2) |
|
|
187 | (2) |
|
Use and Misuse of Surrogate Keys |
|
|
189 | (6) |
|
|
195 | (2) |
|
Chapter 10 Application Development and Performance |
|
|
197 | (14) |
|
|
197 | (1) |
|
|
198 | (1) |
|
|
199 | (1) |
|
|
200 | (1) |
|
The Road Paved with Good Intentions |
|
|
200 | (1) |
|
Application Development Patterns |
|
|
201 | (2) |
|
|
203 | (2) |
|
|
205 | (1) |
|
Welcome to the World of ORM |
|
|
205 | (2) |
|
In Search of a Better Solution |
|
|
207 | (3) |
|
|
210 | (1) |
|
|
211 | (34) |
|
|
211 | (1) |
|
|
212 | (1) |
|
|
212 | (1) |
|
Introducing Procedural Language |
|
|
213 | (1) |
|
|
214 | (1) |
|
Function Parameters and Function Output: Void Functions |
|
|
215 | (1) |
|
|
216 | (2) |
|
|
218 | (2) |
|
Function Execution Internals |
|
|
220 | (3) |
|
Functions and Performance |
|
|
223 | (1) |
|
How Using Functions Can Worsen Performance |
|
|
224 | (2) |
|
Any Chance Functions Can Improve Performance? |
|
|
226 | (1) |
|
Functions and User-Defined Types |
|
|
226 | (1) |
|
|
226 | (1) |
|
Functions Returning Composite Types |
|
|
227 | (4) |
|
Using Composite Types with Nested Structure |
|
|
231 | (4) |
|
Functions and Type Dependencies |
|
|
235 | (1) |
|
Data Manipulation with Functions |
|
|
236 | (2) |
|
|
238 | (1) |
|
What About Business Logic? |
|
|
239 | (1) |
|
Functions in OLAP Systems |
|
|
240 | (1) |
|
|
240 | (1) |
|
No Explicit Dependency on Tables and Views |
|
|
241 | (1) |
|
Ability to Execute Dynamic SQL |
|
|
241 | (1) |
|
|
241 | (1) |
|
Functions with No Results |
|
|
241 | (1) |
|
Functions and Stored Procedures |
|
|
242 | (1) |
|
|
242 | (1) |
|
|
243 | (1) |
|
|
244 | (1) |
|
|
245 | (24) |
|
|
245 | (1) |
|
Why It Works Better in Postgres |
|
|
245 | (1) |
|
What About SQL Injection? |
|
|
246 | (1) |
|
How to Use Dynamic SQL in OLTP Systems |
|
|
246 | (6) |
|
How to Use Dynamic SQL in OLAP Systems |
|
|
252 | (4) |
|
Using Dynamic SQL for Flexibility |
|
|
256 | (7) |
|
Using Dynamic SQL to Aid the Optimizer |
|
|
263 | (3) |
|
|
266 | (1) |
|
|
267 | (2) |
|
Chapter 13 Avoiding the Pitfalls of Object-Relational Mapping |
|
|
269 | (24) |
|
Why Application Developers Like NORM |
|
|
269 | (1) |
|
|
270 | (2) |
|
|
272 | (6) |
|
|
278 | (5) |
|
|
283 | (3) |
|
|
286 | (1) |
|
|
287 | (1) |
|
|
288 | (2) |
|
|
290 | (1) |
|
|
291 | (1) |
|
|
291 | (1) |
|
Working Together with Application Developers |
|
|
292 | (1) |
|
|
292 | (1) |
|
Chapter 14 More Complex Filtering and Search |
|
|
293 | (10) |
|
|
293 | (2) |
|
Multidimensional and Spatial Search |
|
|
295 | (1) |
|
Generalized Index Types in PostgreSQL |
|
|
295 | (1) |
|
|
296 | (1) |
|
Indexes for Full Text Search |
|
|
296 | (1) |
|
Indexing Very Large Tables |
|
|
297 | (1) |
|
|
298 | (4) |
|
|
302 | (1) |
|
Chapter 15 Ultimate Optimization Algorithm |
|
|
303 | (6) |
|
|
303 | (1) |
|
|
304 | (1) |
|
|
304 | (1) |
|
|
304 | (2) |
|
|
306 | (1) |
|
Step 4 Incremental Updates |
|
|
306 | (1) |
|
Step 5 Non-incremental Long Query |
|
|
306 | (1) |
|
|
307 | (1) |
|
|
308 | (1) |
|
|
309 | (2) |
Index |
|
311 | |