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)
 Does the order of fields in a query effect speed?

Author  Topic 

sbt1
Yak Posting Veteran

89 Posts

Posted - 2003-12-12 : 06:42:55
I have an app which generates queries on the fly. Here's a typical one:

SELECT
TaskDates.DateValue,TaskDates.StartTime,TaskDates.EndTime,
TaskDates.Resource,TaskDates.Status,TaskDates.Confirmed,
TaskDates.Locked,TaskDates.CallFirstRequired,
TaskDates.Duration,TaskDates.OTDuration,TaskDates.Customer,
TaskDates.TaskID,TaskDates.Type,TaskDates.ID,
Tasks.TaskDescription,Tasks.JobNumber
FROM TaskDates INNER JOIN Tasks ON TaskDates.TaskID=Tasks.TaskID WHERE (TaskDates.Resource = 'Fred' and TaskDates.DateValue > 01/01/2004 and TaskDates.Type = 5)

Some queries have more tests in the WHERE clause.

Question: for optimum performance, should different type fields appear before others in the query? In other words, should an indexed integer field be placed before a non-indexed string type, etc.?

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-12-12 : 06:44:59
Select list order shouldn't matter

However, if you are using ADO to call the database, you want to put any Text or Image fields last. If you don't ADO gets confused and you get some odd results.



Damian
Go to Top of Page

sbt1
Yak Posting Veteran

89 Posts

Posted - 2003-12-12 : 07:00:15
Actually, I'm using OLE DB from a Visual C++ app.

Should I follow the same rule with OLE DB?
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-12-12 : 07:01:37
I'm not sure about that.
But I'm sure it wouldn't hurt



Damian
Go to Top of Page
   

- Advertisement -