Java Performance Tuning
Java(TM) - see bottom of page
Our valued sponsors who help make this site possible
FREE Java Performance Troubleshooting Tool from AppDynamics. Download now!
New Relic: The first free APM tool with production profiler. Download now!
ManageEngine: End-to-End Java Performance Management. Download Product Now!
Question of the month: Primary Key Efficiency
|
JProfiler
|
|
Get rid of your performance problems and memory leaks!
|
|
JENNIFER for APM
|
|
Monitor All Transactions in "Per-One-Second" Real-time. Download Now!
|
|
See Your Message Here
|
|
You could have your tool advertised here, to be seen by thousands of potential customers
|
|
AppDynamics
|
|
FREE Java Performance Troubleshooting Tool from AppDynamics. Download now!
|
|
New Relic
|
|
New Relic: The first free APM tool with production profiler. Download now!
|
|
ManageEngine
|
|
ManageEngine: End-to-End Java Performance Management. Download Product Now!
|
|
JProfiler
|
|
Get rid of your performance problems and memory leaks!
|
|
JENNIFER for APM
|
|
Monitor All Transactions in "Per-One-Second" Real-time. Download Now!
|
|
|
Back to newsletter 040 contents
Why is a long primary key bad for performance?
There are always lots of new things to find out about Java performance, even for
the performance experts. I recently had the pleasure of sitting through Carol
McDonald's Sun tech day presentation on J2EE performance. Even despite
having a power cut causing a longish delay in the middle, this was easily the
best presentation of the two day event.
One point she made was that long primary keys were bad for performance. I can
easily believe this but it was new to me, so later I asked Carol for clarification
on why this should be. Back she came with a detailed listing of the performance
effects of primary keys, and I'm delighted to share these details with you. The
following tips and references are all courtesy of Carol.
From "Bitter EJB"
"a longer key will require more computation to hash or compare than a shorter primary key" chapter 7 page 234.
Good primary keys are essential to good database design. They let you query and modify each table row individually
without changing other rows in the same table. When you evaluate candidates for a table's primary key, follow these rules:
- The primary key should consist of one column whenever possible.
- The name should mean the same 5 years from now as it does today.
- The data value should be non-null and remain constant over time.
- The data type should be either an integer or a short, fixed-width character.
- If you're using a character data type, the primary key should exclude differential
capitalization, spaces, and special characters, which might be difficult to remember.
Keep the "width" of your indexes as narrow as possible. This reduces the size of the index and reduces the number of disk I/O reads
required to read the index, boosting performance.
If possible, try to create indexes on columns that have integer values instead of characters. Integer values have less overhead than character values.
Don't use FLOAT or REAL data types for primary keys, as they add unnecessary overhead and can hurt performance.
Indexes on narrow columns are preferable to indexes on wide columns. The narrower the index, the more entries SQL Server can fit
on a data page, which in turn reduces the amount of I/O required to access the data.
Reduce the size of the keys, thus decreasing read I/O during the join process, and increasing overall performance.
My thanks to Carol for answering my question this month.
The JavaPerformanceTuning.com team
Back to newsletter 040 contents
Last Updated: 2012-02-02
Copyright © 2000-2012 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries. JavaPerformanceTuning.com is not connected to Sun Microsystems, Inc. and is not sponsored by Sun Microsystems, Inc.
URL: http://www.JavaPerformanceTuning.com/news/qotm040.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us