January 26, 2007 at 9:11 pm
Hi all ,
I have problem and need somebody help me.
I have a select statement which exec about 4 seconds but when i put "distinct" into this select statement then exec it , it run between 55' and 1'20''
So , What happen which my select ?
Somebody know something about this , please tell me . Thanks
January 26, 2007 at 10:31 pm
DISTINCT is simplest option of GROUP BY.
It makes SQL Server rescan returning resultset and group the data.
It involves creating hash table in tempbd for holding temporary data.
Your query must return big recordset, so it takes time to work it out.
_____________
Code for TallyGenerator
January 30, 2007 at 9:32 pm
its may be because ur table and record count may be big ,
try to index ur table with the column which u use for distint clause
January 30, 2007 at 9:48 pm
My result record just return 507 record, i think it maybe small , so i don't know exactly why this result took so long to run when have distinct in it ???
Regard.
January 31, 2007 at 1:31 am
As posted by Sergiy, Your DISTINCT clause would implement a GROUP BY implicitly and does a scan of the results, so in the query analyzer if you look at the Execution Play you would see that there would an additional SORT scan when you include the DISTINCT clause to your query.
Prasad Bhogadi
www.inforaise.com
January 31, 2007 at 2:51 am
Thanks for your answer.
I watched the Excution Plan and saw what you said, but what i mentioned is why have difference between 5'' and 55'' when you just add "distinct" on result of 507 records.
Regards.
January 31, 2007 at 3:07 am
Can you please post your table structure and the query. Your question makes sense as it should not really take so much time.
Prasad Bhogadi
www.inforaise.com
January 31, 2007 at 6:21 am
And, do a ...
SELECT COUNT(*)
FROM yourtablename
... to find out how many rows it's really looking at...
--Jeff Moden
Change is inevitable... Change for the better is not.
January 31, 2007 at 8:59 pm
sol,
how many records WITHOUT distinct (see Jeff's query) and how "heavy" is each of those records?
I mean what is aggregate size of all columns in your recordset?
_____________
Code for TallyGenerator
February 2, 2007 at 2:25 am
It's exactly 507 records , the same when have "distinct". Because this, I have confused. ???
About my SQL statement , i will post it in here in the short time , please be patient.
Thanks and Regards.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply