sql - Slow Query - uses views -
backend on cloud using sql server express 2008 r2 frontend on access 2013
i had query had add subquery to restrict results. query took 1 second run before, takes 70+. think problem may using views in query not indexed. i'm pretty new , don't use access/sql much, apologies if missing obvious here.
this query code:
select distinct vusearch.paid ,vusearch.pdid ,concataddress(nz([building_name]), nz([building_no]), nz([street]), nz([indest]), nz([district]), nz([town]), nz([postcode])) address ,vusearch.deal_date ,vusearch.lease_end ,vusearch.break_date ,vusearch.review_date ,vusearch.propertytype ,vusearch.acting_for ,vusearch.landlord_seller ,vusearch.tenant_purchaser ,iif(isnull([vusearch.gia]), [vusearch.nia], [vusearch.gia]) mainarea ,vudesc.comments_incentives ,tlddealsearch.include ,vusearch.incomplete ( vusearch right join tlddealsearch on vusearch.pdid = tlddealsearch.pdid ) left join vudesc on tlddealsearch.pdid = vudesc.pdid ( ( (vusearch.pdid) in ( ( select max(v2.pdid) vusearch v2 group v2.paid ) ) ) , ((vusearch.incomplete) = false) );
i added indexes tlddealsearch table pdid , include fields (i think i've done right). when looked @ views on backend not add indexes views no schema bound.
is there can or should looking @ speed up? i'm quite worried right there 300 records on database - 70+ seconds?
i have checked on 'analyze performance' tool not sure next.
edit: fast responses guys.
nz - access nulltozero function believe, or replaced it. http://www.techonthenet.com/access/functions/advanced/nz.php
concataddress - function use put elements of address in readable format inclusion in report.
public function concataddress(strbuildingname string, strbuildingno string, strstreet string, _ strindestate string, strdistrict string, strtown string, strpostcode string) string on error goto errroutine dim strsql string if len(strbuildingname) > 0 strsql = strbuildingname end if if len(strbuildingno) > 0 if len(strsql) > 0 strsql = strsql & " " & strbuildingno else strsql = strbuildingno end if end if if len(strstreet) > 0 if len(strsql) > 0 strsql = strsql & " " & strstreet & "," else strsql = strstreet end if end if if len(strindestate) > 0 if len(strsql) > 0 strsql = strsql & " " & strindestate & "," else strsql = strindestate end if end if if len(strdistrict) > 0 if len(strsql) > 0 strsql = strsql & " " & strdistrict & "," else strsql = strdistrict end if end if if len(strtown) > 0 if len(strsql) > 0 strsql = strsql & " " & strtown else strsql = strtown end if end if if len(strpostcode) > 0 if len(strsql) > 0 strsql = strsql & " " & strpostcode else strsql = strpostcode end if end if if len(strsql) > 0 concataddress = strsql else concataddress = "" end if errexit: exit function errroutine: concataddress = empty select case err case 94 'msgbox "postcode not found." resume errexit case else msgbox "the following error has occurred " & err & " " & err.description resume errexit end select end function
'#'#'#'#'#'#'
edit
i asked post execution plan query, not available in access. got hack working think close execution plan (couldn't work access 2013 though).
[for info] add key , string registry - hkey_local_machine\software\wow6432node\microsoft\jet\4.0\engines
add key 'debug' , add string 'jetshowplan' - set value on record (results should in documents or in location of database)
- inputs query - odbc table 'vusearch' odbc table 'vusearch' table 'tlddealsearch' odbc table 'vudesc' - end inputs query - 01) sort table 'vudesc' 02) outer join table 'tlddealsearch' result of '01)' using temporary index join expression "tlddealsearch.pdid=vudesc.pdid" 1614631268) remote sql 03) sort result of '02)' 04) inner join result of '02)' result of '03)' using temporary index join expression "tlddealsearch.pdid=vusearch.pdid" store result in temporary table
seems alot of sorting going on must slow down some. hope looking for.
edit
access jetshowplan not give detail transferred tldsearchdata table backend , ran query there. removed concatadderss (as uses access function) , iif formula determine area use. resultant execution plans below.
actual: https://drive.google.com/file/d/0b5o8fyhuyq0zodzcwhnias1kz1k/view?usp=sharing estimated: https://drive.google.com/file/d/0b5o8fyhuyq0zu0lnruhvaxvkc1k/view?usp=sharing
query took 19 seconds run directly sql (from cloud server)
Comments
Post a Comment