Post on 09-Aug-2015
EclipseWorldOctober 28-30, 2008
Classic Database Development Mi t kMistakes
And Five ways to Overcome them7
And Five ways to Overcome them
Scott WalzEmbarcadero Technologies
2
Agendag
• Classic DB Development MistakesClassic DB Development Mistakes
Steps to overcome them• Steps to overcome them
• Questions
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
3
Marketplacep• Data is growing at mind bending speed• The number and diversity of applications is striving to keepThe number and diversity of applications is striving to keep
up with market demand, which is further driving data growth • More and more people are needed to manage the data and
t th li ticreate the applications• Nearly 16 million application developers today, growing at
nearly 2 million annually*• Time to market, quality, and predictability of software systems
continues to plague the software industry• Customers need tools that address development of the entire• Customers need tools that address development of the entire
system
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
4
Classic Mistakes
• Rows returned = SuccessRows returned = Success• My query is FAST!!
M d l t!• My query does a lot!
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
5
Classic Mistakes
• Rows returned = successRows returned = success– Sample the results
Validate the query by breaking it down– Validate the query by breaking it down– Does the row count pass the test?
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
6
Classic Mistakes
• My query is fast!My query is fast!– What is your test data size?
Have you explained it?– Have you explained it?• more later
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
7
Classic Mistakes
• My query does a lotMy query does a lot– Is the query too complex
Trying to get back too much data– Trying to get back too much data– Would it serve you better to break it into
smaller queriessmaller queries
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
8
Overcoming the mistakesg
• Explain Plan usageExplain Plan usage• Index usage
ANSI 92 SQL• ANSI-92 SQL• Reuse, reuse, reuse• Query rewrites• Database StructureDatabase Structure• Develop a set of best practices
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
9
Words of Wisdom“Several factors determine how well a query performs, some with
t i fl th th Wh t d t h itgreater influence than others. When you tune a data warehouse, it makes sense to address the factors of greatest influence before those with lesser influence. Often, the factors with greatest influence determine performance When you follow this approach you maximizedetermine performance. When you follow this approach, you maximize the payoff (better query performance) and minimize the effort.Simply put, this approach takes advantage of the 80/20 rule (law of diminishing returns) which says that eighty percent of the benefits comediminishing returns) which says that eighty percent of the benefits come from twenty percent of the effort. If you know what falls into the twenty percent, take advantage of this knowledge and save yourself a lot of effort ”1effort.
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
1IBM Software Information Center www.ibm.com
10
Explain Plan Usagep g• Your window into the database• The last thing executed before moving the
SQL statement off of your desk.
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
11
Explan Plan Usagep gLooking for Index Usage
Determine the Cost
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
12
Index Usageg
• Dramatic performance improvementsDramatic performance improvements• Remember, too many may not be good.
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
13
Index usageg
Cost = 0
Cost = 3
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
14
Syntax Issuesy• Null Operators
S b t f ti• Substr functions
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
15
Syntax Issuesy• Functions suppress index usage
I tibl d t t i d• Incompatible datatypes suppress index usage
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
16
Syntax Issuesy• Massaging the query
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
17
Using ANSI-92 Syntaxg y
• Easier to readEasier to read• More companies are standardizing on it
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
18
Non ANSI-92
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
19
ANSI-92 SQL
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
20
Reuse, Reuse, Reuse, ,
• Take advantage ofTake advantage of– Stored Procedures
Triggers– Triggers– Packages
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
21
Query Rewritesy
• There is more than one way to write theThere is more than one way to write the query
Change the order of the where clause– Change the order of the where clause– Use sub-selects in the place of sub-queries
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
22
Database Structure
• Could a View be a better optionCould a View be a better option– If the same tables are queried often w/
changing fields being returnedchanging fields being returned– A complex query can be optimized once and
a view created based on the query.a view created based on the query.– Oftentimes is not a developer option.
• Can be suggested, but normally a DBA activity.Ca be sugges ed, bu o a y a ac y
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0
23
Best Practices
Classic Database Development Mistakes | © 2008 by Scott Walz – Embarcadero Technologies; made available under the EPL v1.0