SQL查询优化 - 减少服务器

时间:2012-08-02 17:02:40

标签: sql performance optimization

我维护的系统似乎每隔几天放慢一点,我认为它来自某个错误的查询。

据我所知,我已将问题缩小到一两页。这是我认为导致问题的页面上的查询。

select a.s_purchase_order as order_id, a.order_type, a.nobackorder, a.order_note, a.note, a.rqst_dlvry_date, b.customer_name ,c.store_name,(c.store_name + ',' + isnull(c.address1 + ',', ' ') +  isnull(c.city + ',', ' ') +  isnull(c.state_cd+ ',', ' ')  + isnull( c.zipcode, ' ')) as store_info, d.supplier_account
from VW_CustomerOrder a, Customer b, Store c, eligible_supplier d
where a.customer = c.customer
and a.store = c.store
and a.customer = b.customer
and c.customer *= d.customer
and c.store *= d.store
and a.supplier *= d.supplier
and a.purchase_order = @order_id
and a.customer = @customer_id
and a.store=@store_id
and a.supplier = @supplier_id

那里有什么明显的东西会很慢或导致系统随着时间的推移而变慢吗?

1 个答案:

答案 0 :(得分:1)

做一些内部联接来解决这个问题,检查你的基础并查看那些表的索引和外键,这总是有助于查询和性能

select 
  a.columun_a, b.column_a from table_a a 
inner join table_b b on a.id = b.id
where 
  b.column_b = "some value"