On 1/29/17 2:35 AM, Fabien COELHO wrote:
I'm wondering what pg would do on "EXISTS(SELECT 1 FROM customer)" if
there are many employees. [...]

I believe that the scan stops on the first row it finds, because the
EXITS() clause is met.

Hmmm... That is not so clear from "EXPLAIN" output:

You need to use a better test case...

explain analyze select exists(select 1 from generate_series(1,99999) gs);
                                                          QUERY PLAN
 Result  (cost=0.01..0.02 rows=1 width=1) (actual time=26.278..26.278 rows=1 
   InitPlan 1 (returns $0)
     ->  Function Scan on generate_series gs  (cost=0.00..10.00 rows=1000 
width=0) (actual time=26.271..26.271 rows=1 loops=1)
 Planning time: 6.568 ms
 Execution time: 48.917 ms
(5 rows)

In any case, +1 for not promoting count(*) <> 0; that's a really, really bad way to test for existence.
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532)

Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to