× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



There's no chance an index will be used for ordering when the ORDER BY
contains columns from more than one table. So, you're out of luck trying to
tune that part of the query. Make sure query is going down SQE path, just in
case SQE is smarter than CQE about ordering the final result set.

As for the indexes used... do you have an index on ORDERS table over
orddate,cust? If that does not end up being used, try cust,orddate also.

Elvis

Celebrating 11-Years of SQL Performance Excellence on IBM i, i5/OS and
OS/400
www.centerfieldtechnology.com


-----Original Message-----
Subject: Re: SQL index possible with keys from two tables?

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.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.