August 2, 2012 at 4:07 pm
Hi DBA's
can we find the count of rows that a select query is going to select before the query is executed
My query runs almost for 4 hrs. but i want to know the number of rows without running it..Pleae suggest
Thanks in advance!
August 2, 2012 at 4:19 pm
Nope.
The best you can do is grab an estimated execution plan and that'll attempt to determine it off statistics, but really... nope.
You COULD do a SELECT COUNT(*) AS cnt FROM .... and get the count before you fire up returning all the included data. I've found that'll help me nail down optimization items before as it takes the whole data-return thing out of the loop. But no, there's no 'execute me without executing' option available other then estimating the execution plan.
EDIT: I should mention expect the results of the estimated execution plan on something that big to not only be wildly inaccurate, but horribly, horribly wrong. The only time it's nearly dead on precise is when you didn't care anyway.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
August 2, 2012 at 9:17 pm
If you have a select query that is taking that long to run, something is terribly wrong. It sounds like you may need to do some database/index optimization. Review your joins and groupings and compare them to your indexes. Check to see that you are not performing an excessive number of recursive sub queries. Be sure that you don't have to perform parsing in your joins. Perhaps build a temp table to store some of that information.
I hope that helps.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply