where 1=2

From: Johan Eriksson <valpis_at_gmail.com>
Date: Mon, 29 Jun 2015 13:33:29 +0200
Message-ID: <CABz5TyDFba8wa3E8tJQgW0RaFMOFN_8CUXw+z2uiUK4Psb=GpA_at_mail.gmail.com>


To use this when creating an empty table (create table t1 as select * from t2 where 1=2) I have done many times, but now I am looking at a query like this:

select *
from t1
where 1!=1
or c1 = '1';

Back in the days (oracle 7) I know we used this form to try to force a full table scan and I haven't seen it on many years.

The query uses primary key index when executed on but on it does a full table scan (c1 is unique primary key).

Even when I used this myself many years ago I didn't know why it worked, it mostly just did. What happens when the optimizer encounter this? Why could this sometimes force a full table scan?


Received on Mon Jun 29 2015 - 13:33:29 CEST

Original text of this message