Robert Haas <robertmhaas@gmail.com> writes:
> Right -- the idea I was talking about was to create a Plan tree
> without using the main planner. So it wouldn't bother costing an index
> scan on each index, and a sequential scan, on the target table - it
> would just make an index scan plan, or maybe an index path that it
> would then convert to an index plan. Or something like that.
Consing up a Path tree and then letting create_plan() make it into
an executable plan might not be a terrible idea. There's a whole
boatload of finicky details that you could avoid that way, like
everything in setrefs.c.
But it's not entirely clear to me that we know the best plan for a
statement-level RI action with sufficient certainty to go that way.
Is it really the case that the plan would not vary based on how
many tuples there are to check, for example? If we *do* know
exactly what should happen, I'd tend to lean towards Andres'
idea that we shouldn't be using the executor at all, but just
hard-wiring stuff at the level of "do these table scans".
Also, it's definitely not the case that create_plan() has an API
that's so clean that you would be able to use it without major
hassles. You'd still have to generate a pile of lookalike planner
data structures, and make sure that expression subtrees have been
fed through eval_const_expressions(), etc etc.
On the whole I still think that generating a Query tree and then
letting the planner do its thing might be the best approach.
regards, tom lane