× 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.



Dean,

I only have a few observations, which may or may not be of use to you...

1. Indexes need only exist for them to benefit SQL in its execution plan. There is no reason to ever refer to an index in a select statement.
2. When performing LEFT OUTER JOIN, you must be careful when you use right-file fields in your WHERE clause. On left outer join, the left-table data is returned, with all right table fields initialized to null. In the Where clause, testing for b.STATE = 'OH', you remove all of the rows where b.STATE is null. It is sometimes necessary to use IS NULL in your where clause, so that you correctly handle the filtering of rows from your result set... WHERE (b.STATE is NULL or b.STATE = 'OH')
3. Using LIKE to perform wildcard tests is notorious for performance related issues. It typically forces the SQL optimizer to perform table scan, a tedious process even for a modern system.

-Eric DeLong


-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Dean Eshleman
Sent: Tuesday, February 28, 2012 3:38 PM
To: 'midrange-l@xxxxxxxxxxxx'
Subject: Optimizing SQL question

Hi,

I have the following SQL statement that will be executed in an RPG program and I'm trying to speed it up.

select a.FLD1, a.FLD2, a.FLD3, a.FLD4, a.FIRSTNME, a.MIDDLENME, a.LASTNME , a.HISTC , b.ADDRL1, b.CITY, b.STATE from FILE1 a left outer join FILE2 b on a.FLD1 = b.FLD1 where a.HISTC in ( 'C' , 'D' , 'F' ) and ( (b.STATE = 'OH' and upper(b.CITY) = 'DOVER' and upper(b.ADDRL1) like '110%' and ( upper(a.LASTNME) like 'MITC%' or upper(a.FIRSTNME) like 'JO%' ) ) or ( upper(a.LASTNME) = 'MITCHELL' and upper(a.FIRSTNME) like 'J%' and a.FLD2 = 1994 and a.FLD3 = 9 and a.FLD4 = 23 ) ) order by a.LASTNME, a.FIRSTNME, a.MIDDLENME

There are about 1.2 million records in FILE1 and 548,000 in FILE2. I have used Visual Explain to see if it recommended any indexes, and ended up creating one over FILE1 by the HIST field. There are existing logicals keyed by the join fields. All of the comparison values for the various fields will change based on what the user enters. The only one that won't change is the values for the HIST field. The query takes about 1 to 2 minutes to execute when running it from the SQL scripts window in System I Navigator. It is being used in an interactive application, so I would like to make it as fast as possible.

I created a join logical between FILE1 and FILE2 and keyed it by LASTNME, FIRSTNME and MIDDLENME since that is the order by clause. I also selected on the HIST values. Then, I ran the statement specifying the logical, but that didn't seem to help much. Would the UPPER function have much of an impact? Is there a way to avoid using that? Maybe there isn't much that can be done, but I thought I would throw it out here and see if anyone has a suggestion. TIA

Dean Eshleman
Software Development Architect

Everence Financial
1110 North Main Street
PO Box 483
Goshen, IN 46527
Phone: (574) 533-9515 x3528
www.everence.com<http://www.everence.com>





________________________________
Confidentiality Notice: This information is intended only for the individual or entity named. If you are not the intended recipient, do not use or disclose this information. If you received this e-mail in error, please delete or otherwise destroy it and contact us at (800) 348-7468 so we can take steps to avoid such transmission errors in the future. Thank you.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.