Re: [HACKERS] Optimizer cleanup to avoid redundant work on joins

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Optimizer cleanup to avoid redundant work on joins
Date: 2000-02-06 20:57:18
Message-ID: 933.949870638@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> I will set aside the code I already rewrote for this purpose, and come
> back to it after we start 7.1.

Wait a minute ... stop the presses ...

I just realized that the bug I was complaining of is *already there
in current sources*, and has been for a while (certainly since 6.5).
Look at prune.c's code that merges together RelOptInfos after-the-
fact:

if (same(rel->relids, unmerged_rel->relids))
{
/*
* These rels are for the same set of base relations,
* so get the best of their pathlists. We assume it's
* ok to reassign a path to the other RelOptInfo without
* doing more than changing its parent pointer (cf. pathnode.c).
*/
rel->pathlist = add_pathlist(rel,
rel->pathlist,
unmerged_rel->pathlist);
}

This is wrong, wrong, wrong, because the paths coming from different
RelOptInfos (different pairs of sub-relations) may need different sets
of qual clauses applied as restriction clauses. There's no way to
represent that in the single RelOptInfo that will be left over. The
worst case is that the generated plan is missing a needed restriction
clause (the other possibility is that the clause is evaluated
redundantly, which is much less painful).

I am not sure why we haven't heard bug reports about this. It seems
like it wouldn't be hard at all to provoke the failure (I'm going to
try to make a test case right now). Assuming I can do that, I think
we have no choice but to move join restrictlists into JoinPath nodes.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2000-02-06 21:59:45 Re: [HACKERS] Optimizer cleanup to avoid redundant work on joins
Previous Message Tom Lane 2000-02-06 20:26:57 Re: [HACKERS] Optimizer cleanup to avoid redundant work on joins