Does the order of filter conditions matter

willdickerson
Tera Contributor

I'm wondering if the order of the filter conditions matters when running the filter.

Simple examples on the change request table, which one would run faster on average or would it be the same?

Filter 1:

Active = true

Approval = Approved Teamlead

State !=  Closed, Cancelled, Implemented - successful, Implemented - failed

Assignment_group.Type = ITIL and Applications

Risk != 5

Filter 2:

Approval = Approved Teamlead

State !=  Closed, Cancelled, Implemented - successful, Implemented - failed

Assignment_group.Type = ITIL and Applications

Risk != 5

Active = true

 

 

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

My guess is that the app takes these conditions, converts them into a T-SQL query, queries the database, then returns the results.  In that case, they do not matter, as the database will look at all the where clauses and query once, instead of querying all active, getting the result, then moving to query the approver out of that set of active, then moving to get all the states you want out of that result set of active and approver, etc.

 

Databases optimize queries.  The thing that slows queries down is the lack of an index.

View solution in original post

1 REPLY 1

Mike Allen
Mega Sage

My guess is that the app takes these conditions, converts them into a T-SQL query, queries the database, then returns the results.  In that case, they do not matter, as the database will look at all the where clauses and query once, instead of querying all active, getting the result, then moving to query the approver out of that set of active, then moving to get all the states you want out of that result set of active and approver, etc.

 

Databases optimize queries.  The thing that slows queries down is the lack of an index.