Walden,
So if I've got this right...
Yes.
Do you have an index on customer & territory? I'd love to see the visual
explain of this query.
Yes I do. What exactly do you want to see from it? Here is an example
statement, and part of what VE says about it. Let's say I want to display
to a sales manager whose territories all begin with 40xx all of the orders
so far this year, in reverse chronological order but sorted within each
territory. Since order numbers are assigned consecutively, the latter part
just amounts to a descending sort on order number. So start with this SQL:
Select c.sman, o.ordnum, o.orddate, o.cust
From customers c, orders o
Where c.cust = o.cust and c.sman like '40%' and o.orddate >= '01/01/2009'
Order by c.sman, o.ordnum desc;
The VE shows it used the indexes I'd expect (the customers using an index by
sman and customer, and the orders an index by customer), in this case
estimating 1908 rows from the customer file (reason = row selection) and
3116 rows from the order file (reason = nested loop join) and 450 estimated
joined rows. It really ended up with 199 rows. The statement took 3.598013
seconds to process.
It appears to me the bulk of the time in this example was because it had to
create a temporary result file (CPI4325):
Cause.....: A temporary result file was created to contain the results of
the query for reason code 2. This process took 0 minutes and 3.4 seconds.
The temporary file created contains 199 records. The reason codes and their
meanings follow:
2 - The query contains ordering fields (ORDER BY) from more than one file,
or contains ordering fields from a secondary file of a join query that
cannot be reordered.
That suggests to me 3.4 of the 3.6 seconds were spent creating the temporary
file. Sometimes I'll only be dealing with a single territory and thus could
drop the c.sman from the Order by clause. Those obviously run faster, but
previously I always had very fast response time because I could index over
just the orders file. I'm just trying to keep that same response time.
As an Amazon Associate we earn from qualifying purchases.