Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 querying

Author  Topic 

delpi767
Starting Member

11 Posts

Posted - 2009-02-06 : 23:21:28
I have a table with 4,500,000 dummy records.
Each record contains fields entitled
LastName
FirstName
MaidenName

Obviously not all rows have a value for maidenname.

When I say select * from members where lastname = 'ODOM'
Query analyzer returns 74 rows in 1 second

When I say When I say select * from members where maidenname = 'ODOM'
Query analyzer takes over two minutes to return 34 rows.

Can someone explain this to me and offer a solution?

Thanks,

Mac

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-07 : 00:36:26
It sounds like you didn't add an index to maidenname column. Add one and then check performance again.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

delpi767
Starting Member

11 Posts

Posted - 2009-02-07 : 08:24:35
Actually there are no indexes except on the primary key which is an identity column. Both fields are char (26). However, I'll give the index a try.

Mac

Regards,

-dmd-
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-07 : 08:53:28
add a non clustered index on maidenname and check. Also its better to add the index only if you're sure that frequency of searching the table for maidenname value is high
Go to Top of Page

delpi767
Starting Member

11 Posts

Posted - 2009-02-07 : 11:50:38
I've now added an index for maiden

However, last name still returns its rows almost instantly (not indexed) while maiden still take 10-20 seconds.

Any thoughts?

Thanks,

Mac
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-07 : 11:54:59
what does execution plan suggests in both cases?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-07 : 13:54:59
Run them together in the same batch and post the execution plan.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-07 : 13:55:19
Also, what is the selectivity of both columns?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -