Chapter 5. Existence Checking

Many queries in programs execute SQL Select Count(*) statements just to see if any rows exist for particular data. Many times it doesn’t matter whether there is one row or one million rows; it just matters if any rows exist. When this is the case, using Select Count(*) is the most expensive way to check because it will count up all rows. Queries should be coded so that they ensure stopping after getting a hit on the first row (unless of course they actually need the total number of rows). There are other ways to code existence checking that are also not very efficient, and this chapter lays out some of them, with the more efficient rewrites.

Example 1

Following is a common example of an SQL statement where its purpose ...

Get DB2 SQL Tuning Tips for z/OS Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.