Re: Performance of subselects - Mailing list pgsql-general

From Tom Lane
Subject Re: Performance of subselects
Date
Msg-id 28910.1236355327@sss.pgh.pa.us
Whole thread Raw
In response to Performance of subselects  (Christian Schröder <cs@deriva.de>)
Responses Re: Performance of subselects  (Christian Schröder <cs@deriva.de>)
List pgsql-general
=?ISO-8859-1?Q?Christian_Schr=F6der?= <cs@deriva.de> writes:
> if I want to find all records from a table that don't have a matching
> record in another table there are at least two ways to do it: Using a
> left outer join or using a subselect. I always thought that the planner
> would create identical plans for both approaches, but actually they are
> quite different which leads to a bad performance in one case.

No, they're not the same; NOT IN has different semantics for nulls.

> Another interesting thing: If table "a" contains only 400,000 rows
> (instead of 500,000) the query planner decides to use a hashed subplan
> and performance is fine again:

You're probably at the threshold where it doesn't think the hashtable
would fit in work_mem.

            regards, tom lane

pgsql-general by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: Installing a module for PostgreSQL
Next
From: Tom Lane
Date:
Subject: Re: After Upgrade from 8.2.6 to 8.3.6: function to_timestamp does not exist