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



Fetching a single value with the right index is faster than using a
count(*), even though this information could be pulled from the statics.
According to my last tests, the fastest way to check for record existence
with SQL is:

Exec SQL Select 1 into :isFound
From MyTable
Where ....
Fetch First Row only;

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"

-----Ursprüngliche Nachricht-----
Von: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] Im Auftrag von Jerry C. Adams
Gesendet: Monday, 13.8 2012 20:16
An: 'Midrange Systems Technical Discussion'
Betreff: COUNT(*) or FETCH Faster?

No referential integrity constraints here. Usually, when I want to check
for records in a secondary file before I allow a delete of, say, a customer
master record, I just used SQL SELECT with COUNT(*) and return that to the
maintenance program.



Works okay, but now I need to check an invoice history table which has about
2,000,000 records, but I only want to check for the last twelve [12] months.




I was wondering if a SELECT into a cursor and then a FETCH FIRST 1 ROWS ONLY
might be faster.



I'm pretty sure the COUNT(*) option has to process all of the records for
the period I pass to it. I figured the SELECT into a cursor did, too, but
don't know for sure.



Thanks.



Jerry C. Adams

IBM i Programmer/Analyst

Try to look unimportant; the enemy may be low on ammo and not want to waste
a bullet on you.

--

A&K Wholesale

Murfreesboro, TN

615-867-5070



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

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.