Order of items in the where clause

Last Post 07 Sep 2007 09:59 AM by timcronin. 1 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
timcronin
New Member
New Member

--
07 Sep 2007 07:03 AM
I had a report of a sp from a developer running slow, I fixed a join which help, but I have a ? about the order of the where clause. I know this might be like arguing religion, but should we consider sql smart enough to use the obvious first. In the where below the first eliminator wold be the inmateid, but the developer has it after a complicated if and or

where (cr.cb_routine = 1 or cr.cb_urgent = 1 or cr.cb_emergency_room = 1
or cr.cb_on_site_clinic = 1 or cr.cb_retro_request = 1 or cr.cb_initial = 1
or cr.cb_followup = 1 or cr.cb_in_person = 1 or cr.cb_telemed = 1
or cr.df_within is not null or cr.df_provider is not null
or cr.df_proc_test_spec is not null or cr.df_provider_area is not null)
and p.privacy_level = 10
and p.other_id_number = @inmateID
and isdate(cr.df_from_date)=1
timcronin
New Member
New Member

--
07 Sep 2007 09:59 AM
Yes welcome to DBA hell, the date fields are char 8 and can sometimes get garbage data
You are not authorized to post a reply.

Acceptable Use Policy