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



On Mon, Jan 19, 2009 at 8:03 AM, Nathan Andelin <nandelin@xxxxxxxxx> wrote:
From: David FOXWELL
select '1' from sysibm.sysdummy1
where exists (select * from mytable where field1 = 'A'
and field2='000002')

Even though sysibm.sysdummy1 contains only 1 record, performance will be dependent on the number of rows and COLUMNS generated by the inner select statement. The constant "1" returned from the first select statement will be compared against each.


You are mistaken. The EXISTS predicate, doesn't look at all rows.
After it finds the first one that matches it returns true.

select '1' from mytable where field1 = 'A'
and field2='000002' fetch first row only;

You've reduced it to just one select statement that generates only one column. Good for you.


Not really, EXISTS is designed to provide the answer to the question,
"does one or more rows exists that match a certain criteria". By
using it, the SQE knows what you want to do. With the second
statement, SQE doesn't know.

On my system, using the second form with a file containing about 35
million records of which 286 million match the criteria, there is a
noticeable difference in speed; using EXISTS is faster. With the
second statement I notice the following debug message:
CPI4325 - Temporary result file built for query.
Cause . . . . . : A temporary result file was created to contain the results
of the query for reason code 8. This process took 0 minutes and 1.0
seconds. The temporary file created contains 0 records. The reason codes and
their meanings follow:
13 - The query involves a static cursor or the SQL FETCH FIRST clause.

HTH,
Charles

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.