Remove coordinator quals, evaluated at Remote Subquery
authorTomas Vondra <tomas@2ndquadrant.com>
Tue, 17 Oct 2017 18:12:49 +0000 (20:12 +0200)
committerTomas Vondra <tomas@2ndquadrant.com>
Thu, 19 Oct 2017 11:48:05 +0000 (13:48 +0200)
commit2d29155679eb98e46f8a47b6dff89231445fb9d6
treedf8b4b64b9be0da7a04c6654221ec10a072ec5a1
parent1078b079d5476e3447bd5268b317eacb4c455f5d
Remove coordinator quals, evaluated at Remote Subquery

While rewriting UPDATE/DELETE commands in rewriteTargetListUD, we've
been pulling all Vars from quals, and adding them to target lists. As
multiple Vars may reference the same column, this sometimes produced
plans with duplicate targetlist entries like this one:

  Update on public.t111
    -> Index Scan using t1_a_idx on public.t1
       Output: 100, t1.b, t1.c, t1.a, t1.a, t1.a, t1.a, t1.a, t1.a,
               t1.a, t1.a, t1.ctid
    -> ...

Getting rid of the duplicate entries would be simple - before adding
entry for eachh Vars, check that a matching entry does not exist yet.
The question however is if we actually need any of this.

The comment in rewriteTargetListUD() claims we need to add the Vars
because of "coordinator quals" - which is not really defined anywhere,
but it probably means quals evaluated at the Remote Subquery node.
But we push all quals to the remote node, so there should not be any
cases where a qual would have to be evaluated locally (or where that
would be preferable).

So just remove all the relevant code from rewriteHandler.c, which
means we produce this plan instead:

  Update on public.t111
    -> Index Scan using t1_a_idx on public.t1
       Output: 100, t1.b, t1.c, t1.ctid
    -> ...

This affects a number of plans in regression tests, but the changes
seem fine - we simply remove unnecessary target list entries.

I've also added an assert to EXPLAIN enforcing the "no quals" rule
for Remote Subquery nodes.

Discussion: <95e80368-1549-a921-c5e2-7e0ad9485bd3@2ndquadrant.com>
src/backend/commands/explain.c
src/backend/rewrite/rewriteHandler.c
src/test/regress/expected/domain.out
src/test/regress/expected/xc_FQS.out
src/test/regress/expected/xc_FQS_join.out
src/test/regress/expected/xc_alter_table.out
src/test/regress/expected/xc_remote.out
src/test/regress/expected/xl_plan_pushdown.out