Thursday, March 8, 2012

aggregate query reporting different results

forgive the absense of DDL and data to reproduce this problem, but it
is 8 tables and hundreds of thousands of rows of data. instead, let me
just post the query and the symptom and we'll see how far that can get
me.
select r.description, sum(t.amount), count(*)
from salesregion as r
join metroarea as w on r.salesregionid = w.salesregionid
join saleitems as a on a.website = w.id
join transactions as t on t.adid = a.adid
join orders as o on t.orderid = o.orderid
join products as p on t.productid = p.productid
where o.orderpaid = 1
and datepart(mm, o.datecreated) = 2
and datepart(year, o.datecreated) = 2006
and p.type in (1, 3)
group by r.description
order by r.description asc
when this query is run in our production support environment, which has
almost no load, it produces completely predictable results every time.
however, when this same query is run in our production environment,
which has identical data, but a much higher load, the aggregate
functions fluctuate very slightly (one to three rows).
i have read on this issue and found two possible remedies:
1) "option (maxdop 1)" (a response i've seen in many threads on this
ng) - i applied this, it had no effect at all on the stability of the
results
2) apply sql service pack 4 (known parallelism bug described at
http://support.microsoft.com/kb/814509) - my question here is: does
load affect parallelism? because production and production support
environments both have service pack 3 applied, but it's happening in
one and not the other. i will apply the service pack if necessary, but
i want to make sure that the parallelism bug is known to occur only
under high load.
thanks in advance for any help,
jasonoh, an additional note:
when i further narrow the search results to just calculate the
aggregates for a single salesregion, like so:
select r.description, sum(t.amount), count(*)
from salesregion as r
join metroarea as w on r.salesregionid = w.salesregionid
join saleitems as a on a.website = w.id
join transactions as t on t.adid = a.adid
join orders as o on t.orderid = o.orderid
join products as p on t.productid = p.productid
where o.orderpaid = 1
and datepart(mm, o.datecreated) = 2
and datepart(year, o.datecreated) = 2006
and p.type in (1, 3)
AND r.description = 'Arizona' -- NEW LINE
group by r.description
order by r.description asc
then it becomes deterministic again!

No comments:

Post a Comment