Re: JOIN performance

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dean Gibson (DB Administrator)" <postgresql3(at)ultimeth(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: JOIN performance
Date: 2004-09-21 00:54:30
Message-ID: 23901.1095728070@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Dean Gibson (DB Administrator)" <postgresql3(at)ultimeth(dot)com> writes:
> Question: why do the last two column definitions in the second VIEW change
> the scan on _LicHD from indexed to sequential ??

It's the CASE that's getting you. The poor plan is basically because
the sub-view isn't getting "flattened" into the upper query, and so it's
not possible to choose a plan for it that's dependent on the upper query
context. And the reason it's not getting flattened is that subselects
that are on the nullable side of an outer join can't be flattened unless
they have nullable targetlists --- otherwise the results might not go to
NULL when they are supposed to. A CASE construct is always going to be
treated as non-nullable.

Fixing this properly is a research project, and I haven't thought of any
quick-and-dirty hacks that aren't too ugly to consider :-(

In the meantime, you could easily replace that CASE construct with a
min() function that's declared strict. I think date_smaller would
do nicely, assuming the columns are actually of type date.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Snodgrass 2004-09-21 01:36:45 Problem with functions
Previous Message Dean Gibson (DB Administrator) 2004-09-21 00:10:58 Re: JOIN performance