From: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> |
---|---|
To: | Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
Cc: | Daniel Verite <daniel(at)manitou-mail(dot)org>, PostgreSQL <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless) |
Date: | 2017-01-29 21:49:18 |
Message-ID: | b0d46850-bf15-882c-a0ad-352e8631efe4@BlueTreble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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 loops=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)
From | Date | Subject | |
---|---|---|---|
Next Message | David Fetter | 2017-01-29 22:39:56 | Re: pg_ls_dir & friends still have a hard-coded superuser check |
Previous Message | David Rowley | 2017-01-29 21:34:00 | Re: Performance improvement for joins where outer side is unique |