3 replies
by aikimark
ROGER,
Select statement performance tweaking/coding depends on several factors.
1. What database is this (MSAccess, SQLServer, Oracle, DB2, etc.)?
2. What are the 5 tables joined on?
2a. number of columns in the join
2b. data type(s) of the joined column(s)
2c. defined indexes on the tables
2d. method of join (INNER JOIN, WHERE clause, function invocation or expression used)
3. What order are the tables joined?
3a. smaller tables are more limiting that larger tables on intermediate (internal) result sets
3b. does your database pay attention to this order?
4. Does your database have a tracing/explain facility that you can use?
_________________________________
Things to try:
It seems that you might be able to add seemingly redundant selection criteria to your Where clause and improve your performance. For example, if you are joining two tables with similar data, both containing a limiting column, you may get better performance by specifying the limiting criteria on both tables, rather than allowing the join of one limited table to reduce the result set.
You might pre-join some (all) of these tables in a query/view, stored procedure, or user-defined function.
Related to the prior sentence...Is this dynamic SQL or static? Static SQL performs much better than dynamic SQL, since the database engine has less to do and might make better decisions.
by alongjordan
When joining tables, you are looking at cartesian products for size. With several joins, especially when not based on key or indexed values this can produce long calculations. Unioning smaller select statements with fewer joins and conditions can make each more efficient.
This process is also true with splitting complex multiple joins into multiple sequential select statements if a union is not appropriate (the results of the first select required for the subsequent.) The key in both is to make the first select statement the most restrictive, that is the join with the fewest expected results.
This discussion is closed to new replies.
Trending Software posts
Sort by Trending