Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Slow fully optimized SQL statement

Status
Not open for further replies.

StewartUK

Programmer
Feb 19, 2001
860
GB
I have the following SQL statement:
Code:
SELECT ContactPic ;
  FROM Donation ;
  WHERE ContactPic = Contactik AND DonDate = Dated ;
  AND WhyFk = whycode AND AlloFk = Allocode ;
INTO CURSOR CheckForDuplicateDon

There are just under 550000 records in the table. Showplan states that the query is partially optimized (it was fully optimized until I removed the index on DELETED() - there are no deleted records). However the query takes 3.8 seconds to run.

I thought the query would be almost instant (it is the 2nd time I run the same query). Can anyone advise me if they would have expected a faster execution and perhaps a way to make it faster, or if I am being overly optimistic?

Thanks,

Stewart
 
One thing that might speed it up is changing the where clause to a single comparison by concatenating all the fields and creating an index that also concatenates all the fields.

Regards,
Jim
 
Jim, Mike - thanks for your replies.

I'm certainly reluctant to add another index to this table - there are 10 already.

The SQL is only returning 1 or 2 results.

Interestingly, setting DELETED OFF made the query run a little faster. Unfortuntely I can't guarantee that there will be no deleted records.

Not using it in a grid, it's for ensuring that a user hasn't created a duplicate record.

I'll live with what I've got.

Stewart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top