Merge tag 'REL_10_5' into XL_10_STABLE
authorPavan Deolasee <[email protected]>
Tue, 25 Sep 2018 11:04:43 +0000 (16:34 +0530)
committerPavan Deolasee <[email protected]>
Tue, 25 Sep 2018 11:04:43 +0000 (16:34 +0530)
142 files changed:
1  2 
configure
configure.in
contrib/citext/expected/citext_1.out
contrib/ltree/expected/ltree.out
doc/bug.template
doc/src/sgml/acronyms.sgml
doc/src/sgml/backup.sgml
doc/src/sgml/catalogs.sgml
doc/src/sgml/config.sgml
doc/src/sgml/datatype.sgml
doc/src/sgml/ddl.sgml
doc/src/sgml/dml.sgml
doc/src/sgml/func.sgml
doc/src/sgml/high-availability.sgml
doc/src/sgml/libpq.sgml
doc/src/sgml/lobj.sgml
doc/src/sgml/ltree.sgml
doc/src/sgml/plpgsql.sgml
doc/src/sgml/ref/create_function.sgml
doc/src/sgml/ref/create_table.sgml
doc/src/sgml/ref/create_trigger.sgml
doc/src/sgml/ref/declare.sgml
doc/src/sgml/ref/fetch.sgml
doc/src/sgml/runtime.sgml
doc/src/sgml/trigger.sgml
doc/src/sgml/wal.sgml
doc/src/sgml/xfunc.sgml
src/Makefile.global.in
src/Makefile.shlib
src/backend/Makefile
src/backend/access/common/heaptuple.c
src/backend/access/heap/heapam.c
src/backend/access/heap/tuptoaster.c
src/backend/access/transam/slru.c
src/backend/access/transam/twophase.c
src/backend/access/transam/xact.c
src/backend/access/transam/xlog.c
src/backend/access/transam/xlogutils.c
src/backend/catalog/Makefile
src/backend/catalog/catalog.c
src/backend/catalog/index.c
src/backend/catalog/objectaddress.c
src/backend/commands/analyze.c
src/backend/commands/cluster.c
src/backend/commands/copy.c
src/backend/commands/event_trigger.c
src/backend/commands/indexcmds.c
src/backend/commands/matview.c
src/backend/commands/sequence.c
src/backend/commands/tablecmds.c
src/backend/commands/trigger.c
src/backend/commands/vacuum.c
src/backend/executor/execCurrent.c
src/backend/executor/execMain.c
src/backend/executor/execProcnode.c
src/backend/executor/nodeAgg.c
src/backend/executor/nodeModifyTable.c
src/backend/optimizer/path/allpaths.c
src/backend/optimizer/path/costsize.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/setrefs.c
src/backend/optimizer/plan/subselect.c
src/backend/optimizer/util/plancat.c
src/backend/optimizer/util/tlist.c
src/backend/parser/analyze.c
src/backend/parser/gram.y
src/backend/parser/parse_utilcmd.c
src/backend/postmaster/autovacuum.c
src/backend/postmaster/pgstat.c
src/backend/replication/basebackup.c
src/backend/rewrite/rewriteHandler.c
src/backend/utils/adt/ri_triggers.c
src/backend/utils/adt/ruleutils.c
src/backend/utils/adt/selfuncs.c
src/backend/utils/adt/varlena.c
src/backend/utils/cache/inval.c
src/backend/utils/cache/relcache.c
src/backend/utils/misc/guc.c
src/backend/utils/sort/tuplesort.c
src/backend/utils/time/snapmgr.c
src/bin/initdb/initdb.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dumpall.c
src/bin/pg_rewind/filemap.c
src/bin/psql/command.c
src/common/Makefile
src/include/access/hash.h
src/include/c.h
src/include/catalog/pg_proc.h
src/include/executor/tuptable.h
src/include/nodes/execnodes.h
src/include/nodes/parsenodes.h
src/include/nodes/relation.h
src/include/parser/analyze.h
src/include/pg_config.h.in
src/include/pg_config.h.win32
src/include/postmaster/autovacuum.h
src/include/storage/smgr.h
src/include/utils/builtins.h
src/include/utils/guc.h
src/interfaces/libpq/fe-auth.c
src/pl/plpgsql/src/pl_exec.c
src/test/regress/expected/aggregates.out
src/test/regress/expected/alter_table.out
src/test/regress/expected/create_table.out
src/test/regress/expected/create_table_like.out
src/test/regress/expected/foreign_data.out
src/test/regress/expected/groupingsets.out
src/test/regress/expected/inherit.out
src/test/regress/expected/insert.out
src/test/regress/expected/join.out
src/test/regress/expected/object_address.out
src/test/regress/expected/plpgsql.out
src/test/regress/expected/rowsecurity.out
src/test/regress/expected/rules.out
src/test/regress/expected/select_parallel.out
src/test/regress/expected/triggers.out
src/test/regress/expected/tsrf.out
src/test/regress/expected/updatable_views.out
src/test/regress/expected/with.out
src/test/regress/expected/xml.out
src/test/regress/expected/xml_1.out
src/test/regress/pg_regress.c
src/test/regress/sql/aggregates.sql
src/test/regress/sql/alter_table.sql
src/test/regress/sql/create_table.sql
src/test/regress/sql/create_table_like.sql
src/test/regress/sql/foreign_data.sql
src/test/regress/sql/inherit.sql
src/test/regress/sql/insert.sql
src/test/regress/sql/join.sql
src/test/regress/sql/plpgsql.sql
src/test/regress/sql/portals.sql
src/test/regress/sql/rowsecurity.sql
src/test/regress/sql/rules.sql
src/test/regress/sql/select_parallel.sql
src/test/regress/sql/triggers.sql
src/test/regress/sql/tsrf.sql
src/test/regress/sql/updatable_views.sql
src/test/regress/sql/with.sql
src/test/regress/sql/xml.sql

diff --cc configure
index d95dbce04655e6e57fc6b44c782fea1e1014db10,25fb1c7adb56c6437aa8bf60dec5c8ad05b02592..6a125c44f4d57876db9df70c79b083b01aa2bdcc
+++ b/configure
@@@ -1,8 -1,8 +1,8 @@@
  #! /bin/sh
  # Guess values for system-dependent variables and create Makefiles.
- # Generated by GNU Autoconf 2.69 for PostgreSQL 10.3 (Postgres-XL 10r1beta1).
 -# Generated by GNU Autoconf 2.69 for PostgreSQL 10.5.
++# Generated by GNU Autoconf 2.69 for PostgreSQL 10.5 (Postgres-XL 10r1beta1).
  #
 -# Report bugs to <pgsql-bugs@postgresql.org>.
 +# Report bugs to <bugs@postgres-xl.org>.
  #
  #
  # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@@ -582,10 -582,9 +582,10 @@@ MAKEFLAGS
  # Identity of this package.
  PACKAGE_NAME='PostgreSQL'
  PACKAGE_TARNAME='postgresql'
- PACKAGE_VERSION='10.3 (Postgres-XL 10r1beta1)'
 -PACKAGE_VERSION='10.5'
 -PACKAGE_STRING='PostgreSQL 10.5'
 -PACKAGE_BUGREPORT='[email protected]'
++PACKAGE_VERSION='10.5 (Postgres-XL 10r1beta1)'
 +PACKAGE_XC_VERSION='10r1beta1'
- PACKAGE_STRING='PostgreSQL 10.3 (Postgres-XL 10r1beta1)'
++PACKAGE_STRING='PostgreSQL 10.5 (Postgres-XL 10r1beta1)'
 +PACKAGE_BUGREPORT='[email protected]'
  PACKAGE_URL=''
  
  ac_unique_file="src/backend/access/common/heaptuple.c"
@@@ -1413,7 -1409,7 +1413,7 @@@ if test "$ac_init_help" = "long"; the
    # Omit some internal or obsolete options to make the list less imposing.
    # This message is too long to be a string in the A/UX 3.1 sh.
    cat <<_ACEOF
- \`configure' configures PostgreSQL 10.3 (Postgres-XL 10r1beta1) to adapt to many kinds of systems.
 -\`configure' configures PostgreSQL 10.5 to adapt to many kinds of systems.
++\`configure' configures PostgreSQL 10.5 (Postgres-XL 10r1beta1) to adapt to many kinds of systems.
  
  Usage: $0 [OPTION]... [VAR=VALUE]...
  
  
  if test -n "$ac_init_help"; then
    case $ac_init_help in
-      short | recursive ) echo "Configuration of PostgreSQL 10.3 (Postgres-XL 10r1beta1):";;
 -     short | recursive ) echo "Configuration of PostgreSQL 10.5:";;
++     short | recursive ) echo "Configuration of PostgreSQL 10.5 (Postgres-XL 10r1beta1):";;
     esac
    cat <<\_ACEOF
  
  test -n "$ac_init_help" && exit $ac_status
  if $ac_init_version; then
    cat <<\_ACEOF
- PostgreSQL configure 10.3 (Postgres-XL 10r1beta1)
 -PostgreSQL configure 10.5
++PostgreSQL configure 10.5 (Postgres-XL 10r1beta1)
  generated by GNU Autoconf 2.69
  
  Copyright (C) 2012 Free Software Foundation, Inc.
@@@ -2348,7 -2344,7 +2348,7 @@@ cat >config.log <<_ACEO
  This file contains any messages produced by compilers while
  running configure, to aid debugging if configure makes a mistake.
  
- It was created by PostgreSQL $as_me 10.3 (Postgres-XL 10r1beta1), which was
 -It was created by PostgreSQL $as_me 10.5, which was
++It was created by PostgreSQL $as_me 10.5 (Postgres-XL 10r1beta1), which was
  generated by GNU Autoconf 2.69.  Invocation command line was
  
    $ $0 $@
@@@ -17469,7 -17521,7 +17571,7 @@@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_wr
  # report actual input values of CONFIG_FILES etc. instead of their
  # values after options handling.
  ac_log="
- This file was extended by PostgreSQL $as_me 10.3 (Postgres-XL 10r1beta1), which was
 -This file was extended by PostgreSQL $as_me 10.5, which was
++This file was extended by PostgreSQL $as_me 10.5 (Postgres-XL 10r1beta1), which was
  generated by GNU Autoconf 2.69.  Invocation command line was
  
    CONFIG_FILES    = $CONFIG_FILES
@@@ -17539,7 -17591,7 +17641,7 @@@ _ACEO
  cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
  ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
  ac_cs_version="\\
- PostgreSQL config.status 10.3 (Postgres-XL 10r1beta1)
 -PostgreSQL config.status 10.5
++PostgreSQL config.status 10.5 (Postgres-XL 10r1beta1)
  configured by $0, generated by GNU Autoconf 2.69,
    with options \\"\$ac_cs_config\\"
  
diff --cc configure.in
index 4e47c23ff54727d09515385b9a59e517d3a6b9e3,527486575539ef70753ad0b4c33e314e5f98dd1a..b1e7a4b51f4a3a01c44638a2cdca50bfb4b3fb08
@@@ -17,7 -17,7 +17,7 @@@ dnl Read the Autoconf manual for detail
  dnl
  m4_pattern_forbid(^PGAC_)dnl to catch undefined macros
  
- AC_INIT([PostgreSQL], [10.3 (Postgres-XL 10r1beta1)], [[email protected]])
 -AC_INIT([PostgreSQL], [10.5], [[email protected]])
++AC_INIT([PostgreSQL], [10.5 (Postgres-XL 10r1beta1)], [[email protected]])
  
  m4_if(m4_defn([m4_PACKAGE_VERSION]), [2.69], [], [m4_fatal([Autoconf version 2.69 is required.
  Untested combinations of 'autoconf' and PostgreSQL versions are not
Simple merge
Simple merge
index 47a592a7ee60a15f4318e79ecd9dd4f8b470c6b0,b3c9f0d7eba1ffbf40f6aba11ae99cfd43483f69..bc382a4d8ff945628ccc4ceb27dde2631ea605c4
@@@ -27,7 -27,7 +27,7 @@@ System Configuration
  
    Operating System (example: Linux 2.4.18)    :
  
-   PostgreSQL version (example: PostgreSQL 10.3):  Postgres-XL 10r1beta1
 -  PostgreSQL version (example: PostgreSQL 10.5):  PostgreSQL 10.5
++  PostgreSQL version (example: PostgreSQL 10.5):  Postgres-XL 10r1beta1
  
    Compiler used (example: gcc 3.3.5)          :
  
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 666dcda39613544c83fd541e3bfbec2204dfee9b,13a10017614ccf3ea0182551a5894bbde7623357..5b4fe1cd5dac6ad06347c6fa4c53f010ae966509
mode 100755,100644..100755
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index ec2395905438452d947a191ade964733010aba15,d52a3c49d6f13add02094974d767a9e9f1edb890..846e4b36a6ac162e4bc697e266a786398c30954e
mode 100755,100644..100755
Simple merge
index ce4644d6c217890b2ae4a2a219b5e844fa266c14,864c3d75f7f8e62150bb0916fc48ccc378c0e8d0..09e56f0a393b80838272f41e131f174183aeae18
mode 100755,100644..100755
index 650736180856a7f015f4926b16cfc025b8894bd5,d8784e537f0f1d0f02da559279b464f7328ec222..edee457c9123f51a742f3905042481a26f902239
mode 100755,100644..100755
Simple merge
Simple merge
Simple merge
Simple merge
index e027262993c492de0fa22d30bbe58b3f88ec794e,d1b8e4fedeec90ec26c639aa520d7e843a758d9a..f084b2ffbea8250427f0e27d05e27d2c0109fcad
@@@ -274,19 -273,26 +274,28 @@@ UUID_EXTRA_OBJS = @UUID_EXTRA_OBJS
  LD = @LD@
  with_gnu_ld = @with_gnu_ld@
  
- # We want -L for libpgport.a and libpgcommon.a to be first in LDFLAGS.  We
- # also need LDFLAGS to be a "recursively expanded" variable, else adjustments
- # to rpathdir don't work right.  So we must NOT do LDFLAGS := something,
- # meaning this has to be done first and elsewhere we must only do LDFLAGS +=
- # something.
+ # It's critical that within LDFLAGS, all -L switches pointing to build-tree
+ # directories come before any -L switches pointing to external directories.
+ # Otherwise it's possible for, e.g., a platform-provided copy of libpq.so
+ # to get linked in place of the one we've built.  Therefore we adopt the
+ # convention that the first component of LDFLAGS is an extra variable
+ # LDFLAGS_INTERNAL, and -L and -l switches for PG's own libraries must be
+ # put into LDFLAGS_INTERNAL, so they will appear ahead of those for external
+ # libraries.
+ #
+ # We need LDFLAGS and LDFLAGS_INTERNAL to be "recursively expanded" variables,
+ # else adjustments to, e.g., rpathdir don't work right.  So we must NOT do
+ # "LDFLAGS := something" anywhere, ditto for LDFLAGS_INTERNAL.
+ # These initial assignments must be "=" type, and elsewhere we must only do
+ # "LDFLAGS += something" or "LDFLAGS_INTERNAL += something".
 +# PGXC_BEGIN
  ifdef PGXS
-   LDFLAGS = -L$(libdir)
+   LDFLAGS_INTERNAL = -L$(libdir)
  else
-   LDFLAGS = -L$(top_builddir)/src/port -L$(top_builddir)/src/common
+   LDFLAGS_INTERNAL = -L$(top_builddir)/src/port -L$(top_builddir)/src/common
  endif
- LDFLAGS += @LDFLAGS@
 +# PGXC_END
+ LDFLAGS = $(LDFLAGS_INTERNAL) @LDFLAGS@
  
  LDFLAGS_EX = @LDFLAGS_EX@
  # LDFLAGS_SL might have already been assigned by calling makefile
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 85bbe7f25f9497edb4bca25a777000294b2e262e,9004e38e6d4405f35161da3b6d55c6fb13c2220b..35d22ac082d9757e8815523bfd47cce25ca765b8
@@@ -5427,9 -4542,7 +5427,10 @@@ CommitSubTransaction(void
        AtEOSubXact_HashTables(true, s->nestingLevel);
        AtEOSubXact_PgStat(true, s->nestingLevel);
        AtSubCommit_Snapshot(s->nestingLevel);
 +#ifdef XCP
 +      AtSubCommit_WaitedXids();
 +#endif
+       AtEOSubXact_ApplyLauncher(true, s->nestingLevel);
  
        /*
         * We need to restore the upper transaction's read-only state, in case the
@@@ -5583,9 -4696,7 +5584,10 @@@ AbortSubTransaction(void
                AtEOSubXact_HashTables(false, s->nestingLevel);
                AtEOSubXact_PgStat(false, s->nestingLevel);
                AtSubAbort_Snapshot(s->nestingLevel);
 +#ifdef XCP
 +              AtSubAbort_WaitedXids();
 +#endif
+               AtEOSubXact_ApplyLauncher(false, s->nestingLevel);
        }
  
        /*
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 650b113aaafc8b7b840fdb1c4b35750d6bcda695,05e05b8fb5847dfb4a09b11521021204b34d375f..eb3dc995a2737619b6f2b2bcefc25a10637c0952
@@@ -2990,16 -2807,14 +2994,17 @@@ CopyFrom(CopyState cstate
                         * tuples inserted by an INSERT command.
                         */
                        processed++;
+               }
  
-                       if (saved_resultRelInfo)
-                       {
-                               resultRelInfo = saved_resultRelInfo;
-                               estate->es_result_relation_info = resultRelInfo;
-                       }
+               /* Restore the saved ResultRelInfo */
+               if (saved_resultRelInfo)
+               {
+                       resultRelInfo = saved_resultRelInfo;
+                       estate->es_result_relation_info = resultRelInfo;
                }
 +#ifdef PGXC
 +              }
 +#endif
        }
  
        /* Flush any remaining buffered tuples */
Simple merge
Simple merge
index 685c227c966b5f2629a790a930cfa14210456dd5,875da730c73111218f43124b720fbe7320647baf..11d0ef9e11c9a461f379829e525cd6e1c425fb7f
@@@ -638,14 -598,11 +606,13 @@@ refresh_by_match_merge(Oid matviewOid, 
        matviewname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(matviewRel)),
                                                                                         RelationGetRelationName(matviewRel));
        tempRel = heap_open(tempOid, NoLock);
 -      tempname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(tempRel)),
 +      tempschema = get_namespace_name(RelationGetNamespace(tempRel));
 +      tempname = quote_qualified_identifier(tempschema,
                                                                                  RelationGetRelationName(tempRel));
 -      diffname = make_temptable_name_n(tempname, 2);
 +      diffname = make_temptable_name_n(RelationGetRelationName(tempRel), 2);
 +      qualified_diffname = quote_qualified_identifier(tempschema, diffname);
  
        relnatts = matviewRel->rd_rel->relnatts;
-       usedForQual = (bool *) palloc0(sizeof(bool) * relnatts);
  
        /* Open SPI context. */
        if (SPI_connect() != SPI_OK_CONNECT)
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 4272370aff5703ad349bd7fb5f5147724d4cbcdf,7de4568b03e553502b13a162437abdfccf0da197..b30e9d5c118a14ae0710f6ac6ec039e363078380
@@@ -276,101 -278,8 +279,7 @@@ ExecInsert(ModifyTableState *mtstate
         * get information on the (current) result relation
         */
        resultRelInfo = estate->es_result_relation_info;
-       /* Determine the partition to heap_insert the tuple into */
-       if (mtstate->mt_partition_dispatch_info)
-       {
-               int                     leaf_part_index;
-               TupleConversionMap *map;
-               /*
-                * Away we go ... If we end up not finding a partition after all,
-                * ExecFindPartition() does not return and errors out instead.
-                * Otherwise, the returned value is to be used as an index into arrays
-                * mt_partitions[] and mt_partition_tupconv_maps[] that will get us
-                * the ResultRelInfo and TupleConversionMap for the partition,
-                * respectively.
-                */
-               leaf_part_index = ExecFindPartition(resultRelInfo,
-                                                                                       mtstate->mt_partition_dispatch_info,
-                                                                                       slot,
-                                                                                       estate);
-               Assert(leaf_part_index >= 0 &&
-                          leaf_part_index < mtstate->mt_num_partitions);
-               /*
-                * Save the old ResultRelInfo and switch to the one corresponding to
-                * the selected partition.
-                */
-               saved_resultRelInfo = resultRelInfo;
-               resultRelInfo = mtstate->mt_partitions + leaf_part_index;
-               /* We do not yet have a way to insert into a foreign partition */
-               if (resultRelInfo->ri_FdwRoutine)
-                       ereport(ERROR,
-                                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                        errmsg("cannot route inserted tuples to a foreign table")));
-               /* For ExecInsertIndexTuples() to work on the partition's indexes */
-               estate->es_result_relation_info = resultRelInfo;
-               /*
-                * If we're capturing transition tuples, we might need to convert from
-                * the partition rowtype to parent rowtype.
-                */
-               if (mtstate->mt_transition_capture != NULL)
-               {
-                       if (resultRelInfo->ri_TrigDesc &&
-                               (resultRelInfo->ri_TrigDesc->trig_insert_before_row ||
-                                resultRelInfo->ri_TrigDesc->trig_insert_instead_row))
-                       {
-                               /*
-                                * If there are any BEFORE or INSTEAD triggers on the
-                                * partition, we'll have to be ready to convert their result
-                                * back to tuplestore format.
-                                */
-                               mtstate->mt_transition_capture->tcs_original_insert_tuple = NULL;
-                               mtstate->mt_transition_capture->tcs_map =
-                                       mtstate->mt_transition_tupconv_maps[leaf_part_index];
-                       }
-                       else
-                       {
-                               /*
-                                * Otherwise, just remember the original unconverted tuple, to
-                                * avoid a needless round trip conversion.
-                                */
-                               mtstate->mt_transition_capture->tcs_original_insert_tuple = tuple;
-                               mtstate->mt_transition_capture->tcs_map = NULL;
-                       }
-               }
-               if (mtstate->mt_oc_transition_capture != NULL)
-                       mtstate->mt_oc_transition_capture->tcs_map =
-                               mtstate->mt_transition_tupconv_maps[leaf_part_index];
-               /*
-                * We might need to convert from the parent rowtype to the partition
-                * rowtype.
-                */
-               map = mtstate->mt_partition_tupconv_maps[leaf_part_index];
-               if (map)
-               {
-                       Relation        partrel = resultRelInfo->ri_RelationDesc;
-                       tuple = do_convert_tuple(tuple, map);
-                       /*
-                        * We must use the partition's tuple descriptor from this point
-                        * on, until we're finished dealing with the partition. Use the
-                        * dedicated slot for that.
-                        */
-                       slot = mtstate->mt_partition_tuple_slot;
-                       Assert(slot != NULL);
-                       ExecSetSlotDescriptor(slot, RelationGetDescr(partrel));
-                       ExecStoreTuple(tuple, slot, InvalidBuffer, true);
-               }
-       }
        resultRelationDesc = resultRelInfo->ri_RelationDesc;
 -
        /*
         * If the result relation has OIDs, force the tuple's OID to zero so that
         * heap_insert will assign a fresh OID.  Usually the OID already will be
Simple merge
Simple merge
index 199301c6ba0f4dcec1109c4006ee268e707a05c4,1946f9ef968412821ab74d28a508fca78d9eeaf4..93b275bd79ab9118a0c092a56e13f0e1ace11076
@@@ -3953,53 -3717,6 +3953,49 @@@ create_grouping_paths(PlannerInfo *root
                try_parallel_aggregation = true;
        }
  
-       else if (parse->hasTargetSRFs)
-       {
-               try_distributed_aggregation = false;
-       }
 +      /*
 +       * The distributed aggregation however works even if there are no partial
 +       * paths (when the distribution key is included in the grouping keys, we
 +       * may simply push down the whole aggregate).
 +       *
 +       * XXX We currently don't even try to push down grouping sets, although we
 +       * might do that when all grouping sets include the distribution key. But
 +       * that seems like a fairly rare case, as in most cases there will be
 +       * empty grouping set () aggregating all the data. So let's look into this
 +       * optimization later.
 +       */
 +      if (!grouped_rel->consider_parallel)
 +      {
 +              /* Not even parallel-safe. */
 +              try_distributed_aggregation = false;
 +      }
 +      else if (!parse->hasAggs && parse->groupClause == NIL)
 +      {
 +              /*
 +               * We don't know how to do parallel aggregation unless we have either
 +               * some aggregates or a grouping clause.
 +               */
 +              try_distributed_aggregation = false;
 +      }
 +      else if (parse->groupingSets)
 +      {
 +              /* We don't know how to do grouping sets in parallel. */
 +              try_distributed_aggregation = false;
 +      }
 +      else if (agg_costs->hasNonPartial || agg_costs->hasNonSerial)
 +      {
 +              /* Insufficient support for partial mode. */
 +              try_distributed_aggregation = false;
 +      }
 +      else
 +      {
 +              /* Everything looks good. */
 +              try_distributed_aggregation = true;
 +      }
 +
 +      /* Whenever parallel aggregation is allowed, distributed should be too. */
 +      Assert(!(try_parallel_aggregation && !try_distributed_aggregation));
 +
        /*
         * Before generating paths for grouped_rel, we first generate any possible
         * partial paths; that way, later code can easily consider both parallel
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index a898db50e0ed5e0efd8a2f42883551acf3b44d8b,b3367f0cd4b15c01ab0a2c1c93ff4ae38b00efae..44ab471c6220a40ad7ebb85a04bf762b808da11e
  #include "catalog/pg_constraint_fn.h"
  #include "catalog/pg_opclass.h"
  #include "catalog/pg_operator.h"
+ #include "catalog/pg_statistic_ext.h"
  #include "catalog/pg_type.h"
 +#ifdef XCP
 +#include "catalog/pgxc_node.h"
 +#endif
  #include "commands/comment.h"
  #include "commands/defrem.h"
  #include "commands/sequence.h"
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc src/include/c.h
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 42435884fed79a56c74b62b00eee03d1a752a3d7,4ee20052f22b7045091ea7dc65d5acce6f8aa04d..a9222e7d69bdb773452cd87b79be93487ac5b295
@@@ -44,8 -43,7 +44,11 @@@ extern void applyLockingClause(Query *q
                                   LockClauseStrength strength,
                                   LockWaitPolicy waitPolicy, bool pushedDown);
  
 +#ifdef XCP
 +extern void ParseAnalyze_callback(ParseState *pstate, Query *query);
 +extern post_parse_analyze_hook_type prev_ParseAnalyze_callback;
 +#endif
+ extern List *BuildOnConflictExcludedTargetlist(Relation targetrel,
+                                                                 Index exclRelIndex);
  #endif                                                        /* ANALYZE_H */
Simple merge
index c89bd357bf5bf9385408307aa264de26e2c5ce4d,cb7c139c8c5c43942e19d21cf7bd8453efda1b2f..83d08de8ecdb88ff7ae857399b418d3eaf1c9037
  #define MEMSET_LOOP_LIMIT 1024
  
  /* Define to the address where bug reports for this package should be sent. */
 -#define PACKAGE_BUGREPORT "p[email protected]"
 +#define PACKAGE_BUGREPORT "p[email protected]"
  
  /* Define to the full name of this package. */
 -#define PACKAGE_NAME "PostgreSQL"
 +#define PACKAGE_NAME "Postgres-XL"
  
  /* Define to the full name and version of this package. */
 -#define PACKAGE_STRING "PostgreSQL 10.5"
 +#define PACKAGE_STRING "Postgres-XL 10r1beta1"
  
  /* Define to the version of this package. */
- #define PACKAGE_VERSION "10.3"
+ #define PACKAGE_VERSION "10.5"
  
  /* Define to the name of a signed 128-bit integer type. */
  #undef PG_INT128_TYPE
  #define PG_INT64_TYPE long long int
  
  /* PostgreSQL version as a string */
- #define PG_VERSION "10.3"
+ #define PG_VERSION "10.5"
  
  /* PostgreSQL version as a number */
- #define PG_VERSION_NUM 100003
+ #define PG_VERSION_NUM 100005
  
  /* Define to the one symbol short name of this package. */
 -#define PACKAGE_TARNAME "postgresql"
 +#define PACKAGE_TARNAME "postgres-xl"
 +
 +/* Postgres-XC version as a string */
 +#define PGXC_VERSION "1.1devel"
 +
 +/* Postgres-XC version as a number */
 +#define PGXC_VERSION_NUM 10100
  
  /* Define to the name of the default PostgreSQL service principal in Kerberos.
     (--with-krb-srvnam=NAME) */
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 8f8f2374d1d8b32ede4a01941ec56e76de808d70,660398bdbe09742e8fb87c61c9e640087c6596b0..6fc11f42e05ca17dda05e894b14d81a93510ba4b
@@@ -780,12 -757,24 +775,26 @@@ CREATE TABLE range_parted4_3 PARTITION 
   c      | integer |           |          |         | plain   |              | 
  Partition of: range_parted4 FOR VALUES FROM (6, 8, MINVALUE) TO (9, MAXVALUE, MAXVALUE)
  Partition constraint: ((abs(a) IS NOT NULL) AND (abs(b) IS NOT NULL) AND (c IS NOT NULL) AND ((abs(a) > 6) OR ((abs(a) = 6) AND (abs(b) >= 8))) AND (abs(a) <= 9))
 +Distribute By: HASH(a)
 +Location Nodes: ALL DATANODES
  
  DROP TABLE range_parted4;
+ -- user-defined operator class in partition key
+ CREATE FUNCTION my_int4_sort(int4,int4) RETURNS int LANGUAGE sql
+   AS $$ SELECT case WHEN $1 = $2 THEN 0 WHEN $1 > $2 THEN 1 ELSE -1 END; $$;
+ CREATE OPERATOR CLASS test_int4_ops FOR TYPE int4 USING btree AS
+   OPERATOR 1 < (int4,int4), OPERATOR 2 <= (int4,int4),
+   OPERATOR 3 = (int4,int4), OPERATOR 4 >= (int4,int4),
+   OPERATOR 5 > (int4,int4), FUNCTION 1 my_int4_sort(int4,int4);
+ CREATE TABLE partkey_t (a int4) PARTITION BY RANGE (a test_int4_ops);
+ CREATE TABLE partkey_t_1 PARTITION OF partkey_t FOR VALUES FROM (0) TO (1000);
+ INSERT INTO partkey_t VALUES (100);
+ INSERT INTO partkey_t VALUES (200);
  -- cleanup
  DROP TABLE parted, list_parted, range_parted, list_parted2, range_parted2, range_parted3;
+ DROP TABLE partkey_t;
+ DROP OPERATOR CLASS test_int4_ops USING btree;
+ DROP FUNCTION my_int4_sort(int4,int4);
  -- comments on partitioned tables columns
  CREATE TABLE parted_col_comment (a int, b text) PARTITION BY LIST (a);
  COMMENT ON TABLE parted_col_comment IS 'Am partitioned table';
@@@ -816,8 -803,30 +825,32 @@@ CREATE TABLE arrlp12 PARTITION OF arrl
  --------+-----------+-----------+----------+---------+----------+--------------+-------------
   a      | integer[] |           |          |         | extended |              | 
  Partition of: arrlp FOR VALUES IN ('{1}', '{2}')
- Partition constraint: ((a IS NOT NULL) AND (((a)::anyarray OPERATOR(pg_catalog.=) '{1}'::integer[]) OR ((a)::anyarray OPERATOR(pg_catalog.=) '{2}'::integer[])))
+ Partition constraint: ((a IS NOT NULL) AND ((a = '{1}'::integer[]) OR (a = '{2}'::integer[])))
 +Distribute By: ROUND ROBIN
 +Location Nodes: ALL DATANODES
  
  DROP TABLE arrlp;
+ -- partition on boolean column
+ create table boolspart (a bool) partition by list (a);
+ create table boolspart_t partition of boolspart for values in (true);
+ create table boolspart_f partition of boolspart for values in (false);
+ \d+ boolspart
+                                  Table "public.boolspart"
+  Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
+ --------+---------+-----------+----------+---------+---------+--------------+-------------
+  a      | boolean |           |          |         | plain   |              | 
+ Partition key: LIST (a)
+ Partitions: boolspart_f FOR VALUES IN (false),
+             boolspart_t FOR VALUES IN (true)
+ drop table boolspart;
+ -- partitions mixing temporary and permanent relations
+ create table perm_parted (a int) partition by list (a);
+ create temporary table temp_parted (a int) partition by list (a);
+ create table perm_part partition of temp_parted for values in (1, 2); -- error
+ ERROR:  cannot create a permanent relation as partition of temporary relation "temp_parted"
+ create temp table temp_part partition of perm_parted for values in (1, 2); -- error
+ ERROR:  cannot create a temporary relation as partition of permanent relation "perm_parted"
+ create temp table temp_part partition of temp_parted for values in (1, 2); -- ok
+ drop table perm_parted cascade;
+ drop table temp_parted cascade;
index 697e19a29b350fcafc934f42cfea416b407dc1e7,0d8438a9abddc1ef468dcd71874872e325a10b57..555e8daaddf76343641df01837aeca6a0f5e7cd5
@@@ -250,8 -242,8 +252,10 @@@ Indexes
      "ctlt_all_expr_idx" btree ((a || b))
  Check constraints:
      "ctlt1_a_check" CHECK (length(a) > 2)
+ Statistics objects:
+     "public"."ctlt_all_a_b_stat" (ndistinct, dependencies) ON a, b FROM ctlt_all
 +Distribute By: HASH(a)
 +Location Nodes: ALL DATANODES
  
  SELECT c.relname, objsubid, description FROM pg_description, pg_index i, pg_class c WHERE classoid = 'pg_class'::regclass AND objoid = i.indexrelid AND c.oid = i.indexrelid AND i.indrelid = 'ctlt_all'::regclass ORDER BY c.relname, objsubid;
      relname     | objsubid | description 
index 1ba6f02c09d43e3620c339212ff256a321b17229,3418fefcca2ce5be03deb4747224217a7bde8a3e..2ac2698cb16807d8ec606939f54e78129afa1722
@@@ -1601,23 -1995,42 +1601,35 @@@ ALTER TABLE pt2 ADD CONSTRAINT pt2chk1 
  Partition key: LIST (c1)
  Check constraints:
      "pt2chk1" CHECK (c1 > 0)
 +Distribute By: HASH(c1)
 +Location Nodes: ALL DATANODES
  
  \d+ pt2_1
 -                                      Foreign table "public.pt2_1"
 - Column |  Type   | Collation | Nullable | Default | FDW options | Storage  | Stats target | Description 
 ---------+---------+-----------+----------+---------+-------------+----------+--------------+-------------
 - c1     | integer |           | not null |         |             | plain    |              | 
 - c2     | text    |           | not null |         |             | extended |              | 
 - c3     | date    |           | not null |         |             | plain    |              | 
 -Check constraints:
 -    "p21chk" CHECK (c2 <> ''::text)
 -Server: s0
 -FDW options: (delimiter ',', quote '"', "be quoted" 'value')
 -
  ALTER TABLE pt2 ATTACH PARTITION pt2_1 FOR VALUES IN (1);       -- ERROR
 -ERROR:  child table is missing constraint "pt2chk1"
 +ERROR:  relation "pt2_1" does not exist
  ALTER FOREIGN TABLE pt2_1 ADD CONSTRAINT pt2chk1 CHECK (c1 > 0);
 +ERROR:  relation "pt2_1" does not exist
  ALTER TABLE pt2 ATTACH PARTITION pt2_1 FOR VALUES IN (1);
 +ERROR:  relation "pt2_1" does not exist
  -- TRUNCATE doesn't work on foreign tables, either directly or recursively
  TRUNCATE pt2_1;  -- ERROR
 -ERROR:  "pt2_1" is not a table
 +ERROR:  relation "pt2_1" does not exist
  TRUNCATE pt2;  -- ERROR
 -ERROR:  "pt2_1" is not a table
  DROP FOREIGN TABLE pt2_1;
 +ERROR:  foreign table "pt2_1" does not exist
  DROP TABLE pt2;
+ -- foreign table cannot be part of partition tree made of temporary
+ -- relations.
+ CREATE TEMP TABLE temp_parted (a int) PARTITION BY LIST (a);
+ CREATE FOREIGN TABLE foreign_part PARTITION OF temp_parted
+   FOR VALUES IN (1, 2) SERVER s0;  -- ERROR
+ ERROR:  cannot create a permanent relation as partition of temporary relation "temp_parted"
+ CREATE FOREIGN TABLE foreign_part (a int) SERVER s0;
+ ALTER TABLE temp_parted ATTACH PARTITION foreign_part
+   FOR VALUES IN (1, 2);  -- ERROR
+ ERROR:  cannot attach a permanent relation as partition of temporary relation "temp_parted"
+ DROP FOREIGN TABLE foreign_part;
+ DROP TABLE temp_parted;
  -- Cleanup
  DROP SCHEMA foreign_schema CASCADE;
  DROP ROLE regress_test_role;                                -- ERROR
Simple merge
Simple merge
Simple merge
index 75cc6638890e696f99a6e3ee4b13979ac3153678,d12bf018771c85f0fac10586beffb5ed7a5aca24..d6a930d5c8cae29c577fd4b250ca72a65ff58b01
@@@ -271,7 -466,10 +271,10 @@@ SELECT (pg_identify_object(addr1.classi
   text search parser        | addr_nsp   | addr_ts_prs       | addr_nsp.addr_ts_prs                                                 | t
   text search configuration | addr_nsp   | addr_ts_conf      | addr_nsp.addr_ts_conf                                                | t
   text search template      | addr_nsp   | addr_ts_temp      | addr_nsp.addr_ts_temp                                                | t
- (37 rows)
+  subscription              |            | addr_sub          | addr_sub                                                             | t
+  publication               |            | addr_pub          | addr_pub                                                             | t
+  publication relation      |            |                   | addr_nsp.gentable in publication addr_pub                            | t
 -(46 rows)
++(40 rows)
  
  ---
  --- Cleanup resources
index b96e58b69bcacfb91909b8d833759f80ae67ff3c,0162102a19615a40e7c33007c69ae7baae5eefa4..b9a3138c05e2f09bbd6d99e99aa7583359583608
@@@ -5996,7 -5979,34 +5996,29 @@@ ALTER TABLE alter_table_under_transitio
    DROP column name;
  UPDATE alter_table_under_transition_tables
    SET id = id;
 -ERROR:  column "name" does not exist
 -LINE 1: SELECT (SELECT string_agg(id || '=' || name, ',') FROM d)
 -                                               ^
 -QUERY:  SELECT (SELECT string_agg(id || '=' || name, ',') FROM d)
 -CONTEXT:  PL/pgSQL function alter_table_under_transition_tables_upd_func() line 3 at RAISE
  --
+ -- Test multiple reference to a transition table
+ --
+ CREATE TABLE multi_test (i int);
+ INSERT INTO multi_test VALUES (1);
+ CREATE OR REPLACE FUNCTION multi_test_trig() RETURNS trigger
+ LANGUAGE plpgsql AS $$
+ BEGIN
+     RAISE NOTICE 'count = %', (SELECT COUNT(*) FROM new_test);
+     RAISE NOTICE 'count union = %',
+       (SELECT COUNT(*)
+        FROM (SELECT * FROM new_test UNION ALL SELECT * FROM new_test) ss);
+     RETURN NULL;
+ END$$;
+ CREATE TRIGGER my_trigger AFTER UPDATE ON multi_test
+   REFERENCING NEW TABLE AS new_test OLD TABLE as old_test
+   FOR EACH STATEMENT EXECUTE PROCEDURE multi_test_trig();
+ UPDATE multi_test SET i = i;
+ NOTICE:  count = 1
+ NOTICE:  count union = 2
+ DROP TABLE multi_test;
+ DROP FUNCTION multi_test_trig();
+ --
  -- Check type parsing and record fetching from partitioned tables
  --
  CREATE TABLE partitioned_table (a int, b text) PARTITION BY LIST (a);
index 700eb0ebd92362bb82b1c6ac29f8e97a64622528,99e01b9a254852cc7c0fa996448a3acf95a5b0a7..f588fd819c82c1e2941790f057f5993899a28bc3
@@@ -2838,11 -2809,12 +2838,11 @@@ Rules
      ON UPDATE TO rules_src DO  INSERT INTO rules_log (f1, f2, tag) VALUES (old.f1,old.f2,'old'::text), (new.f1,new.f2,'new'::text)
      r2 AS
      ON UPDATE TO rules_src DO  VALUES (old.f1,old.f2,'old'::text), (new.f1,new.f2,'new'::text)
 -    r3 AS
 -    ON DELETE TO rules_src DO
 - NOTIFY rules_src_deletion
 +Distribute By: HASH(f1)
 +Location Nodes: ALL DATANODES
  
  --
- -- Ensure a aliased target relation for insert is correctly deparsed.
+ -- Ensure an aliased target relation for insert is correctly deparsed.
  --
  create rule r4 as on insert to rules_src do instead insert into rules_log AS trgt SELECT NEW.* RETURNING trgt.f1, trgt.f2;
  create rule r5 as on update to rules_src do instead UPDATE rules_log AS trgt SET tag = 'updated' WHERE trgt.f1 = new.f1;
index e61a23e0b2b89e83b96fb576283ffd9246c5e34b,25be6b9ab134cde298d1cc8245ffc0069b263b53..044931c5cf3c9ad1b557b20e327226e5153ce0f2
@@@ -421,10 -421,32 +421,32 @@@ SELECT dataa, datab b, generate_series(
  (24 rows)
  
  reset enable_hashagg;
+ -- case with degenerate ORDER BY
+ explain (verbose, costs off)
+ select 'foo' as f, generate_series(1,2) as g from few order by 1;
+                   QUERY PLAN                  
+ ----------------------------------------------
+  ProjectSet
+    Output: 'foo'::text, generate_series(1, 2)
+    ->  Seq Scan on public.few
+          Output: id, dataa, datab
+ (4 rows)
+ select 'foo' as f, generate_series(1,2) as g from few order by 1;
+   f  | g 
+ -----+---
+  foo | 1
+  foo | 2
+  foo | 1
+  foo | 2
+  foo | 1
+  foo | 2
+ (6 rows)
  -- data modification
  CREATE TABLE fewmore AS SELECT generate_series(1,3) AS data;
 -INSERT INTO fewmore VALUES(generate_series(4,5));
 -SELECT * FROM fewmore;
 +INSERT INTO fewmore SELECT generate_series(4,5);
 +SELECT * FROM fewmore ORDER BY 1;
   data 
  ------
      1
Simple merge
index 197c5aba6f1ac014b3ee2a37d4ea5c5a8cbd9435,3eb638ca258f1d998edad7cbdc6d9e1493037fdc..7cd24c6701f6a7056c4b5d8e7bd1c15f0ab261b2
@@@ -1077,29 -1075,26 +1077,29 @@@ CREATE OR REPLACE VIEW public.xmltablev
      "xmltable".premier_name
     FROM ( SELECT xmldata.data
             FROM xmldata) x,
-     LATERAL XMLTABLE(('/ROWS/ROW'::text) PASSING (x.data) COLUMNS id integer PATH ('@id'::text), _id FOR ORDINALITY, country_name text PATH ('COUNTRY_NAME'::text) NOT NULL, country_id text PATH ('COUNTRY_ID'::text), region_id integer PATH ('REGION_ID'::text), size double precision PATH ('SIZE'::text), unit text PATH ('SIZE/@unit'::text), premier_name text DEFAULT ('not specified'::text) PATH ('PREMIER_NAME'::text))
+     LATERAL XMLTABLE(('/ROWS/ROW'::text) PASSING (x.data) COLUMNS id integer PATH ('@id'::text), _id FOR ORDINALITY, country_name text PATH ('COUNTRY_NAME/text()'::text) NOT NULL, country_id text PATH ('COUNTRY_ID'::text), region_id integer PATH ('REGION_ID'::text), size double precision PATH ('SIZE'::text), unit text PATH ('SIZE/@unit'::text), premier_name text DEFAULT ('not specified'::text) PATH ('PREMIER_NAME'::text))
  EXPLAIN (COSTS OFF) SELECT * FROM xmltableview1;
 -               QUERY PLAN                
 ------------------------------------------
 +                        QUERY PLAN                         
 +-----------------------------------------------------------
   Nested Loop
 -   ->  Seq Scan on xmldata
 +   ->  Remote Subquery Scan on all (datanode_1,datanode_2)
 +         ->  Seq Scan on xmldata
     ->  Table Function Scan on "xmltable"
 -(3 rows)
 +(4 rows)
  
  EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM xmltableview1;
-                                                                                                                                                                                                                         QUERY PLAN                                                                                                                                                                                                                         
- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+                                                                                                                                                                                                                             QUERY PLAN                                                                                                                                                                                                                            
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   Nested Loop
     Output: "xmltable".id, "xmltable"._id, "xmltable".country_name, "xmltable".country_id, "xmltable".region_id, "xmltable".size, "xmltable".unit, "xmltable".premier_name
 -   ->  Seq Scan on public.xmldata
 +   ->  Remote Subquery Scan on all (datanode_1,datanode_2)
           Output: xmldata.data
 +         ->  Seq Scan on public.xmldata
 +               Output: xmldata.data
     ->  Table Function Scan on "xmltable"
           Output: "xmltable".id, "xmltable"._id, "xmltable".country_name, "xmltable".country_id, "xmltable".region_id, "xmltable".size, "xmltable".unit, "xmltable".premier_name
-          Table Function Call: XMLTABLE(('/ROWS/ROW'::text) PASSING (xmldata.data) COLUMNS id integer PATH ('@id'::text), _id FOR ORDINALITY, country_name text PATH ('COUNTRY_NAME'::text) NOT NULL, country_id text PATH ('COUNTRY_ID'::text), region_id integer PATH ('REGION_ID'::text), size double precision PATH ('SIZE'::text), unit text PATH ('SIZE/@unit'::text), premier_name text DEFAULT ('not specified'::text) PATH ('PREMIER_NAME'::text))
- (9 rows)
+          Table Function Call: XMLTABLE(('/ROWS/ROW'::text) PASSING (xmldata.data) COLUMNS id integer PATH ('@id'::text), _id FOR ORDINALITY, country_name text PATH ('COUNTRY_NAME/text()'::text) NOT NULL, country_id text PATH ('COUNTRY_ID'::text), region_id integer PATH ('REGION_ID'::text), size double precision PATH ('SIZE'::text), unit text PATH ('SIZE/@unit'::text), premier_name text DEFAULT ('not specified'::text) PATH ('PREMIER_NAME'::text))
+ (7 rows)
  
  -- XMLNAMESPACES tests
  SELECT * FROM XMLTABLE(XMLNAMESPACES('http://x.y' AS zz),
index 289062ae736ca046012fb460bd6770a8320d0b0a,2053734f65f44401a8a81e5aa034c8f522a07abb..366911cdbbeacc516829754e5fe11404e62e0f18
@@@ -949,29 -947,26 +949,29 @@@ CREATE OR REPLACE VIEW public.xmltablev
      "xmltable".premier_name
     FROM ( SELECT xmldata.data
             FROM xmldata) x,
-     LATERAL XMLTABLE(('/ROWS/ROW'::text) PASSING (x.data) COLUMNS id integer PATH ('@id'::text), _id FOR ORDINALITY, country_name text PATH ('COUNTRY_NAME'::text) NOT NULL, country_id text PATH ('COUNTRY_ID'::text), region_id integer PATH ('REGION_ID'::text), size double precision PATH ('SIZE'::text), unit text PATH ('SIZE/@unit'::text), premier_name text DEFAULT ('not specified'::text) PATH ('PREMIER_NAME'::text))
+     LATERAL XMLTABLE(('/ROWS/ROW'::text) PASSING (x.data) COLUMNS id integer PATH ('@id'::text), _id FOR ORDINALITY, country_name text PATH ('COUNTRY_NAME/text()'::text) NOT NULL, country_id text PATH ('COUNTRY_ID'::text), region_id integer PATH ('REGION_ID'::text), size double precision PATH ('SIZE'::text), unit text PATH ('SIZE/@unit'::text), premier_name text DEFAULT ('not specified'::text) PATH ('PREMIER_NAME'::text))
  EXPLAIN (COSTS OFF) SELECT * FROM xmltableview1;
 -               QUERY PLAN                
 ------------------------------------------
 +                        QUERY PLAN                         
 +-----------------------------------------------------------
   Nested Loop
 -   ->  Seq Scan on xmldata
 +   ->  Remote Subquery Scan on all (datanode_1,datanode_2)
 +         ->  Seq Scan on xmldata
     ->  Table Function Scan on "xmltable"
 -(3 rows)
 +(4 rows)
  
  EXPLAIN (COSTS OFF, VERBOSE) SELECT * FROM xmltableview1;
-                                                                                                                                                                                                                         QUERY PLAN                                                                                                                                                                                                                         
- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+                                                                                                                                                                                                                             QUERY PLAN                                                                                                                                                                                                                            
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   Nested Loop
     Output: "xmltable".id, "xmltable"._id, "xmltable".country_name, "xmltable".country_id, "xmltable".region_id, "xmltable".size, "xmltable".unit, "xmltable".premier_name
 -   ->  Seq Scan on public.xmldata
 +   ->  Remote Subquery Scan on all (datanode_1,datanode_2)
           Output: xmldata.data
 +         ->  Seq Scan on public.xmldata
 +               Output: xmldata.data
     ->  Table Function Scan on "xmltable"
           Output: "xmltable".id, "xmltable"._id, "xmltable".country_name, "xmltable".country_id, "xmltable".region_id, "xmltable".size, "xmltable".unit, "xmltable".premier_name
-          Table Function Call: XMLTABLE(('/ROWS/ROW'::text) PASSING (xmldata.data) COLUMNS id integer PATH ('@id'::text), _id FOR ORDINALITY, country_name text PATH ('COUNTRY_NAME'::text) NOT NULL, country_id text PATH ('COUNTRY_ID'::text), region_id integer PATH ('REGION_ID'::text), size double precision PATH ('SIZE'::text), unit text PATH ('SIZE/@unit'::text), premier_name text DEFAULT ('not specified'::text) PATH ('PREMIER_NAME'::text))
- (9 rows)
+          Table Function Call: XMLTABLE(('/ROWS/ROW'::text) PASSING (xmldata.data) COLUMNS id integer PATH ('@id'::text), _id FOR ORDINALITY, country_name text PATH ('COUNTRY_NAME/text()'::text) NOT NULL, country_id text PATH ('COUNTRY_ID'::text), region_id integer PATH ('REGION_ID'::text), size double precision PATH ('SIZE'::text), unit text PATH ('SIZE/@unit'::text), premier_name text DEFAULT ('not specified'::text) PATH ('PREMIER_NAME'::text))
+ (7 rows)
  
  -- XMLNAMESPACES tests
  SELECT * FROM XMLTABLE(XMLNAMESPACES('http://x.y' AS zz),
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index c672991f47eb0d1b293c2061e1e4f7e5fdbfa66c,0a1e8e5666046a9cebac29563fb4a11138ebbe85..03dd0df7d65d0b8edfee423bc07df5f7a85f64c3
@@@ -88,10 -88,15 +88,15 @@@ SELECT dataa, datab b, generate_series(
  SELECT dataa, datab b, generate_series(1,2) g, count(*) FROM few GROUP BY CUBE(dataa, datab, g) ORDER BY g;
  reset enable_hashagg;
  
+ -- case with degenerate ORDER BY
+ explain (verbose, costs off)
+ select 'foo' as f, generate_series(1,2) as g from few order by 1;
+ select 'foo' as f, generate_series(1,2) as g from few order by 1;
  -- data modification
  CREATE TABLE fewmore AS SELECT generate_series(1,3) AS data;
 -INSERT INTO fewmore VALUES(generate_series(4,5));
 -SELECT * FROM fewmore;
 +INSERT INTO fewmore SELECT generate_series(4,5);
 +SELECT * FROM fewmore ORDER BY 1;
  
  -- SRFs are not allowed in UPDATE (they once were, but it was nonsense)
  UPDATE fewmore SET data = generate_series(4,9);
Simple merge
Simple merge