I'm just throwing something out there... might not make a difference. But
let's try it. My wheels are spinning... :-)

Get a distinct count of each column in your where clause. Then order your
where clause so the field with the lowest distinct count first followed by
the second lowest and so on.


Another question, do any of these fields have a parent table? If you do,
I'm thinking that you can do this range/like selection on the smaller table
and use the IN clause with subselect from the parent table. i.e.

where field in (select field from parent_table where parent_value like
'SOME STRING%')
and field2 in (select field2 from another_parent where parent_value between
-999 and 999)

etc.

throwing something else out there to try... maybe... I say this because I
truly don't know, use your best judgement. If you don't have parent tables
on those fields... what happens if you create your own in qtemp. It will
obviously depend on how fast each of these create.

create table qtemp/table_field1 (
field1 char(10)
);

insert into qtemp/table_field1
select distinct field1
from table
where field1 between :field1_low and :field1_high;

repeat for the other columns. Again it depends on the speed of these.
If it's not fast then it's not worth it.

Using the qtemp tables.

select *
from invmstp
where (field1,field2,field3,field4,field5) in
(select field1, field2, field3, field4, field5
from qtemp/table_field1
, qtemp/table_field2
, qtemp/table_field3
, qtemp/table_field4
, qtemp/table_field5)

Remember to put the smallest distinct count columns first in the where
clause.


On Thu, Oct 24, 2013 at 1:52 PM, Michael Ryan <michaelrtr@xxxxxxxxx> wrote:

I will Steve, but I think I'll examine the code closer. I'm getting very
fast results in interactive SQL, and slow results in my service program
procedure/stored procedure/result set program. I'm going to look at some
work management issues too. Thanks!


On Thu, Oct 24, 2013 at 1:49 PM, Needles,Stephen J <
SNEEDLES@xxxxxxxxxxxxxxxx> wrote:

Ryan,

Can you post the SQL?

Steve Needles


-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:
midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Michael Ryan
Sent: Thursday, October 24, 2013 11:59 AM
To: Midrange Systems Technical Discussion; RPG programming on the IBM i /
System i
Subject: SQL - Slow Like or Between

Note: Cross posted because it's SQL in RPG, but I think it's just an SQL
issue.

A continuation of an email that I sent a couple of days ago, and got some
good feedback. I'm returning a result set to RPG or PHP via a stored
procedure.

On further analysis, I need to provide a starting point for record
access.
I was using static SQL and a Between clause for each of 10 fields between
*LOVAL and *HIVAL. Takes too long to run...like 60 seconds over an 800K
record file.

I created individual indexes (EVI's) over each of the 10 possible
columns.

Tried static SQL with a technique like this: Where :xxvnda1 in (' ',
IMVNDA) And.... Still too slow.

Tried dynamic SQL by creating the statement using equal, like this:
SQLStmt = SQLStmt + cBlank + 'IMVNDA =' + cBlank + cQuote + xxvnda1 +
cQuote; Much faster when looking for an equal, but doesn't return records
that don't match exactly.

Tried dynamic SQL using Like, and it's as slow as the initial static
technique.

I'm going to try dynamic SQL using a Between clause, but not as far as
*LOVAL and *HIVAL, and only including the columns I want to search in the
Where clause. I'm not anticipating good results though.

Question (finally): What's the best technique for an SQL-based search
where I return a result set from a search of multiple fields?

Thanks for any ideas.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/midrange-l.

________________________________
This communication, including attachments, is confidential, may be
subject
to legal privileges, and is intended for the sole use of the addressee.
Any
use, duplication, disclosure or dissemination of this communication,
other
than by the addressee, is prohibited. If you have received this
communication in error, please notify the sender immediately and delete
or
destroy this communication and all copies.

TRVDiscDefault::1201
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



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.