August 22, 2007 at 2:09 pm
I have a client table with 150,000 records
for presenting clients on a form (top 25) i use a procedure
"select top 25 * from Clienttable
where ClientName>=@name
order by ClientName"
with big over 50,000 records the actoin takes to mutch time
has any body an idea how to manage it faster?
thanks
August 22, 2007 at 2:45 pm
Do you have a clustered index on clientname?
N 56°04'39.16"
E 12°55'05.25"
August 22, 2007 at 3:10 pm
how can i have a clustered index on clientname when clientname can't be uniqe?
August 22, 2007 at 3:37 pm
Clustered index has nothing to do with uniqueness.
I suggest you read about indexes in Books Online, just to refresh your knowledge a little.
N 56°04'39.16"
E 12°55'05.25"
August 22, 2007 at 11:39 pm
This smacks of a "paging" problem... is that what you're trying to do?
--Jeff Moden
Change is inevitable... Change for the better is not.
August 24, 2007 at 9:42 pm
select * will mess you up everytime - by selecting * you're forcing SQL to go back to the base row in the table regardles of indexes including including covering indexes.
Take a look at your query, determine exactly which fields need to be present in your select/joins/where clause and adjust accordingly - the build a covering index to contain all the data required to satisfy the query as written.
Joe
August 25, 2007 at 1:59 pm
thank's a lot, you were very helpfull
is there a way to know the location (row number)
of a certain record in a clustered table?
August 27, 2007 at 12:03 am
The concept of row number is a meaningless one. In a table with a clustered index, the clustering key is the only 'identifier' of row location
Try a nonclustered index on Clientname. 25 out of 150000 should be selective enough for the optimiser to do a non-clustered index scan with bookmark lookups.
Oh, and get rid of that *.
If you can limit down the required firlds to 2 or 3, add them to the NC index on client name
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 29, 2007 at 2:38 am
The clustering key refers to the columns that make up the clustered index. Nothing fancier than that.
So, if your clustered index is on the field ClientID, your sample queries would be
select clientname from tbl where ClientID = @x
select ClientID from tbl where clientname = @y
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 29, 2007 at 8:16 am
If you're paging, then you can do
select top 25 clientname from tbl order by clientname
for the first page. You can add a WHERE clause ot limit things as needed. Then for the next page, you need to pass in the last clientname
select top 25 clientname from tbl where Clientname > @x
order by clientname
and so on, passing in the first or last clientname, depending on which way you're going in the paging. You can also look up ROW_NUMBER in SQL Server 2005 if you move there and some other options become available.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply