I've got an application that generates data for reports that look like:
age < 30 | age >=30 | asian | hispanic
-----------------------------------------------------------------
clients in prog A | | |
-----------------------------------------------------------------
clients in prog B | | |
-----------------------------------------------------------------
number clients | | |
-----------------------------------------------------------------
number children | | |
The queries are sometimes very very long, and I'd like to optimize them.
I don't have permissions on the server to run the query analyzer (and I read that it's often better not to use it's suggestions). The longest sprocs take ~35 seconds to execute.
Reading around, the things to avoid for high query optimization are :
- Select *
- exists
- distinct
- cursors
- having
I have a few questions about the task at hand:
- how much of a difference am I looking at by changing Select * into Select colA, colB ... ? Is it really worth the trouble?
- how can I optimize if exists( ... )? Is if( Select Count(query ) > 0 ) a good optimization?
- If I am really going to return all of the columns in a table, is it okay to use Select * ?
I don't want to post these queries because they are so long and terrible, but what other suggestions might you be able to offer? I'm trying to use re-usable functions and temporary tables wherever possible to ease the strain both on my brain and on the server.