September 14, 2013 at 3:36 pm
I am having a performnace problem is a sql server 2008 sql. The stored procedure does a full table scan when one of the @state or @zip paramteres are used. The dba says he will not put an index on the state and zip columns since this is the only sql that uses state and zip cocde. The sql look like the following:
select cs.person_id,cs.cust_id,cs.customer_name,cs.address1, cs.address2, cs.city,
cs.state,cs.zip,z.product_id,z.product_name,z.product_description
from customer_table cs
left join view1 v1 on v1.cust_id = cs.cust_id
left join
(select product_id,product_name,product_description from product_table p on p.iventory_id = v.iventory_id
where @prod_quantity <= p.supply_on_hand) z on z.person_id = c.person_id
where @zip = Cs.zip or @state=cs.state
Thus cany ou tell me what I can do to make this sql run faster?
September 15, 2013 at 10:45 am
Looks like your query won't compile since you join on non-existing v-table inside the LEFT JOIN?
Can you create an INDEXED VIEW inside the procedure that indexes the zip /state-columns?
That might help, otherwise hard to make query much faster without indexes...
September 15, 2013 at 2:15 pm
Please post table definition, index definitions and execution plan as per http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 15, 2013 at 9:46 pm
How do you create an indexed view?
September 16, 2013 at 12:17 am
A view with clustered index is indexed view.
There are lot of limitations/conditions apply on creating the index view.see BOL for detail
Pramod
SQL Server DBA | MCSE SQL Server 2012/2014
in.linkedin.com/in/pramodsingla/
http://pramodsingla.wordpress.com/
September 16, 2013 at 4:51 am
wendy elizabeth (9/15/2013)
How do you create an indexed view?
Something like:
IF OBJECT_ID('INDEXED_CUSTOMER', N'V') IS NOT NULL
DROP VIEW INDEXED_CUSTOMER;
GO
CREATE VIEW dbo.INDEXED_CUSTOMER
WITH SCHEMABINDING
AS
SELECTcust_id, cust_no, zipcode, city, province -- etc
FROMdbo.customer
GO
CREATE UNIQUE CLUSTERED INDEX pk_i_customer ON INDEXED_CUSTOMER (cust_id)
GO
CREATE UNIQUE INDEX s1_i_customer ON INDEXED_CUSTOMER (zipcode, cust_id) INCLUDE (city, province)
CREATE UNIQUE INDEX s2_i_customer ON INDEXED_CUSTOMER (province, cust_id) INCLUDE (city, zipcode)
GO
September 16, 2013 at 5:27 am
wendy elizabeth (9/14/2013)
Thus cany ou tell me what I can do to make this sql run faster?
what made you to think that this query is behaving bad ?
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
September 16, 2013 at 6:43 am
wendy elizabeth (9/15/2013)
How do you create an indexed view?
Why are you thinking about creating an indexed view?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply