Re: Double ocurring Subplan - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Double ocurring Subplan
Date
Msg-id 5369.1305324136@sss.pgh.pa.us
Whole thread Raw
In response to Double ocurring Subplan  (Gurjeet Singh <singh.gurjeet@gmail.com>)
Responses Re: Double ocurring Subplan  (Gurjeet Singh <singh.gurjeet@gmail.com>)
List pgsql-hackers
Gurjeet Singh <singh.gurjeet@gmail.com> writes:
> I am listing the query, it's explain output and explain analyze output at
> the end.

> The EXPLAIN output shows the 'Subplan 2' node only once, whereas EXPLAIN
> ANALYZE output shows that the 'Subplan 2' is being executed twice . Is that
> true? Or is it just the plan printer getting confused? Is the confusion
> because of the 2 conditions in the WHERE clause of the correlated subquery?

The reason it looks like that is that the SubPlan is referenced in the
index condition, and there are actually two copies of that (indxqual and
indxqualorig).  They both point at the same physical subplan, but there
are two entries in the parent node's subPlan list.  In EXPLAIN you only
see one because ExecInitIndexScan skips initializing the indxquals in
EXPLAIN_ONLY mode.

In short: it's cosmetic.

We could probably suppress the duplicate printout when both references
are in the same plan node, but in bitmap scans the indxqual and
indxqualorig expressions are actually in different plan nodes (the
indexscan and heapscan respectively).  I'm not sure how we could
suppress the duplicate printout in that case, or whether it would even
make sense to do so --- after all, the subplan can in fact get called by
both nodes.
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Formatting Curmudgeons WAS: MMAP Buffers
Next
From: Cédric Villemain
Date:
Subject: Re: the big picture for index-only scans