sql server 2014 - Which sql query is best performing on heavy and continues load , when fetching row with exact input match if exists, else common match -
in sp, getting employeeid,unitid,categoryid input parameter.
i need search given input parameters given category id in large table (150 million records). large table has clustered index on employeeid,unitid,categoryid.
the query should return exact match input category id or if exact input category id not found should return row category id = -1. e.g.
`select * largetable employeeid=@employeeid , unitid=@unitid , category_id in (@categoryid, -1)` will best performing query or shall write 2 query , first exact match, if match not found second query execute , return row matching categoryid -1.
which approach best?
what query check , return exact match without searching table twice, if go second approach?
i tried various ways, following gave best performance after testing in performance servers:
1) create temporary table same structure of largetable.
2) insert primary column values input parameter temp table.
3) update temp table matching values @categoryid.
4) update temp table matching values -1, temp table not updated @categoryid.
5) return data temp table.
looks spliting query 2 query gives breathing space sql server , gives best sla long , heavy load.
Comments
Post a Comment