Amir Michail writes:
> Hi,
>
> Given some condition, how do you efficiently check whether there is at
> least one row that satisfies that condition?
>
> count(*) is slow.
To check whether there are any rows in the table T where X < 4, you
could do something like this:
VALUES 1 INTERSECT SELECT 1 FROM T WHERE X < 4
(returns one row if there's a match, zero rows otherwise)
This should stop immediately when it finds a matching row. If there are
no matching rows, the entire table will be scanned unless you have an
index on the column X.
--
Knut Anders