Re: Query never completes with low work_mem (at least not within one hour)

From: Daniel Westermann <daniel(dot)westermann(at)dbi-services(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Query never completes with low work_mem (at least not within one hour)
Date: 2017-04-05 06:57:17
Message-ID: 1897407172.249960.1491375437054.JavaMail.zimbra@dbi-services.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>> I have set work_mem to a very low value intentionally for demonstration
>> purposes:
>>
>> postgres=# show work_mem;
>> work_mem
>> ----------
>> 16MB
>> (1 row)
>>
>> postgres=# show shared_buffers ;
>> shared_buffers
>> ----------------
>> 128MB
>> (1 row)
>>
>>
>> When I run the following query ( I know that "not in" is not a good choice
>> here ):
>>
>> postgres=# select count(user_id) from users where user_id not in ( select id
>> from ids);

>"NOT IN" where the predate is a table column can lead to very poor
>query plans especially where the haystack is not provably known (at
>plan time) to contain only not null values. By reducing work_mem, the
>server has decided has to repeatedly search the table to search for
>the presence of null values. Try converting the query to NOT EXISTS.

Thank you, Merlin. As said I know that "not in" is not a good choice in this case but I still do not get what is going here. Why does the server repeatedly search for NULL values when I decrease work_mem and why not when increasing work_mem?

Regards
Daniel

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2017-04-05 07:05:09 Re: Query never completes with low work_mem (at least not within one hour)
Previous Message Tom DalPozzo 2017-04-05 06:52:56 Re: keeping WAL after dropping replication slots