From 4e60212ab5a956bcba89cfd465f945a9c8969f27 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 23 Sep 2010 19:34:56 -0400 Subject: [PATCH] Avoid sharing subpath list structure when flattening nested AppendRels. In some situations the original coding led to corrupting the child AppendRel's subpaths list, effectively adding other members of the parent's list to it. This was usually masked because we never made any further use of the child's list, but given the right combination of circumstances, we could do so. The visible symptom would be a relation getting scanned twice, as in bug #5673 from David Schmitt. Backpatch to 8.2, which is as far back as the risky coding appears. The example submitted by David only fails in 8.4 and later, but I'm not convinced that there aren't any even-more-obscure cases where 8.2 and 8.3 would fail. --- src/backend/optimizer/path/allpaths.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 88b09a2a8b..ba264c3c0f 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -350,7 +350,7 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, childpath = childrel->cheapest_total_path; if (IsA(childpath, AppendPath)) subpaths = list_concat(subpaths, - ((AppendPath *) childpath)->subpaths); + list_copy(((AppendPath *) childpath)->subpaths)); else subpaths = lappend(subpaths, childpath);