Robert Haas <robertmh...@gmail.com> writes: > Well, I'm a little stumped. When I do it the way you did it, it fails > with the same error you got:
> contrib_regression=# EXPLAIN (VERBOSE, COSTS OFF) > SELECT * FROM ft1, ft2, ft4, ft5 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = ft4.c1 > AND ft1.c1 = ft5.c1 FOR UPDATE; > ERROR: outer pathkeys do not match mergeclauses > But when I add the same command to postgres_fdw.sql and run it as part > of the regression tests, it works. I tried adding it at the end with > \c beforehand so that there wouldn't be any temporary settings in > effect. I duplicated those results, and then added an ANALYZE, and then it fails: *************** *** 7548,7550 **** --- 7595,7604 ---- (4 rows) RESET enable_partition_wise_join; + \c - + analyze "S 1"."T 1"; + -- multi-way join involving multiple merge joins + EXPLAIN (VERBOSE, COSTS OFF) + SELECT * FROM ft1, ft2, ft4, ft5 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = ft4.c1 + AND ft1.c1 = ft5.c1 FOR UPDATE; + ERROR: outer pathkeys do not match mergeclauses So apparently the reason our manual tests replicated the failure is that an auto-analyze happened in between. Now that I realize that, I find that the manual query doesn't fail if executed *immediately* after the regression test run. Wait a minute, repeat, it does fail. OTOH, put the same ANALYZE before the test case where it is in the script, no change. So the contributing factors here are (1) there are a bunch of data changes to "S 1"."T 1" further down in the script than where you added the test case, and (2) you need an auto-analyze to have seen those changes before the problematic plan gets picked. It looks like Etsuro-san's proposed patch locks down the choice of plan more tightly, which is probably a reasonable answer. regards, tom lane