Maybe.
...
improve performance. And you need the inner query to use a good index,
shanky wrote:
>
> Is there a way to just count like 200 rows...instead of doing count on 8
> million records....count is taking 2-3 minutes....
>
> "Gert-Jan Strik" wrote:
>
> > For this query, the only usuable index would be an index on
> > products(product7).
> >
> > Some general remarks: it is a bit odd that you do "LIKE COALESCE" four
> > times, "= COALESCE" one time and the equivalent of "= COALESCE" one
> > time. By the way: changing "prod = COALESCE(@prod,prod)" to "prod =
> > @prod OR @prod IS NULL" will not make a difference.
> >
> > What can make a difference is if you rewrite the "LIKE
> > COALESCE(@prod,prod)" to "LIKE COALESCE(@prod,'%')", but only for
> > product that you mention first in the index. So I suggest that you do
> > that for the column where it is most likely that you have filled the
> > local variable for.
> >
> > So you are now always using a value in @product7. Let's assume that the
> > next local variable that is likely to be filled is @product6. In that
> > case, you could create an index on products(product7,product6), and
> > rewrite the last two lines of your query to
> >
> > AND product6 LIKE COALESCE(@product6, '%')
> > AND product7 = @product7
> >
> > If the stored procedure is recompiled each time it is called (WITH
> > RECOMPILE) that you could do this for all combination of product7 +
> > another productcolumn.
> >
> > In the end, it will probably still give you just average performance. If
> > you want better performance, read articles like this:
> >
http://www.sommarskog.se/dynamic_sql.html > >
> > HTH,
> > Gert-Jan
> >
> >
> > shanky wrote:
> > >
> > > I have one performance problem....
> > >
> > > I am using follwing query to get some data back from sql server 2000...
> > >
> > > select @Rec_Cnt = count(Customer_Id)
> > > FROM products with (nolock)
> > > WHERE product1 like COALESCE(@product1, product1) and
> > > product2 like COALESCE(@product2, product2) and
> > > product3 Like COALESCE(@product3, product3) and
> > > product4 Like COALESCE(@product4, product4) and
> > > product5 = COALESCE(@product5, product5) and
> > > ((product6 = @product6 ) or (@product6 Is Null)) And
> > > product7 = @product7
> > >
> > > I am using count and bunch of like statements...There is no problem in
> > > query...I have around 8 millions rows....it is taking around 2 minutes to run
> > > above query...
> > > what is the best way to improve above query...or there is some other way to
> > > write above code...need to improve the performance. I have index defined on
> > > customerid, product1, product2, product3 and product4.
> > >
> > > Thanks