Q
Problem solve Get help with specific problems with your technologies, process and projects.

What difference does a 1 = 1 predicate make?

What difference does a 1 = 1 predicate make? For example, consider the following SQL queries:
SELECT LASTNAME, FIRSTNAME, ADDR1 FROM EMP

SELECT LASTNAME, FIRSTNAME, ADDR1 FROM EMP WHERE 1 = 1
Is there any difference in the treatment of the optimizer for the above two queries?
There should be no discernible difference between the two SQL statements you specify. In fact, I would guess that the second one would be ever so slightly less efficient than the first one because of the additional predicate that is involved.

I've never seen an approach like this before. Perhaps you are confusing this with the approach of appending OR...

0 = 1 to a predicate to force DB2's hand when selecting an index at bind time. For example, consider this statement:

SELECT a,b,c
FROM    table1
WHERE d between 'A' and 'F'
AND      e > 1500;
If there were two indexes, one on column d and one on column e, you could add OR 0 = 1 to one of the predicates to get DB2 to choose the index for the other. For example:
SELECT a,b,c
FROM    table1
WHERE d between 'A' and 'F'
AND      (e > 1500 OR 0 = 1);
This would eliminate the index on e, and DB2 would choose the index on d. But this will not help in your situation because there are no other predicates.
This was last published in January 2005

Dig Deeper on IBM DB2 management

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchAWS

SearchContentManagement

SearchOracle

SearchSAP

SearchSQLServer

Close