August 5, 2008 at 8:58 pm
I have a table that has over 25million rows. When I do a select by mentioning a set of fields from the number of fields available on the table,I use just the 'select * from table where condition1, condition2...conditionx>0criteria but this process is getting deadlocked and also, other processes are getting timed out.It might be because there are many fields with value>0 ( critierax). What is the best possible solution in this case.I want to implement a fast running query. Is there a way to create a temp table and then do a select from it..any ideas are welcome...Thanks in Advance!!!
The_SQL_DBA
MCTS
"Quality is never an accident; it is always the result of high intention, sincere effort, intelligent direction and skillful execution; it represents the wise choice of many alternatives."
August 5, 2008 at 9:40 pm
index..
August 5, 2008 at 9:54 pm
Index... maybe a partitioned table, to boot.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 6, 2008 at 1:17 am
As appointed by previous posts... have you considered to build an index serving your query's predicate?
Here is what I wanted to say... you do not do "select *" in a production environment... never, ever. Bad, very bad mojo.
_____________________________________
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at Amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.August 6, 2008 at 4:03 am
I would also look at using an index, and not use *, however, with you mentioning deadlocking, maybe you could use:
SELECT *
FROM table_name
WITH(NOLOCK)
WHERE .....
There is a tool with SQL 2005 you could use. With the query open in SSMS, the 4th button to the right of the Execute button is 'Analyze Query in Database Engine Tuning Advisor' and it may give you an idea of the indexes (and possibly statistics) to use and the code to create them.
Regards,
Phil
August 6, 2008 at 5:00 pm
i have a scheduled job that kicks in every week.Does reindexing against this table.So I dont think Indexing should be an issue. Well I have worked on with the application developers to optimize the query and now it takes 30 seconds to run compared to 4.5 minutes before. thnx guys...:)
The_SQL_DBA
MCTS
"Quality is never an accident; it is always the result of high intention, sincere effort, intelligent direction and skillful execution; it represents the wise choice of many alternatives."
August 7, 2008 at 1:45 am
I'm glad you fixed it.
Just a side note. The fact that you rebuild your indexes in a weekly basis means nothing, how if you are rebuilding once and again indexes that do not serve your query? 😉
_____________________________________
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at Amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply