Fix missing outfuncs.c support for IncrementalSortPath.
authorTom Lane <[email protected]>
Mon, 30 Nov 2020 21:32:56 +0000 (16:32 -0500)
committerTom Lane <[email protected]>
Mon, 30 Nov 2020 21:33:09 +0000 (16:33 -0500)
For debugging purposes, Path nodes are supposed to have outfuncs
support, but this was overlooked in the original incremental sort patch.

While at it, clean up a couple other minor oversights, as well as
bizarre choice of return type for create_incremental_sort_path().
(All the existing callers just cast it to "Path *" immediately, so
they don't care, but some future caller might care.)

outfuncs.c fix by Zhijie Hou, the rest by me

Discussion: https://postgr.es/m/324c4d81d8134117972a5b1f6cdf9560@G08CNEXMBPEKD05.g08.fujitsu.local

src/backend/nodes/outfuncs.c
src/backend/optimizer/README
src/backend/optimizer/util/pathnode.c
src/include/nodes/pathnodes.h
src/include/optimizer/pathnode.h

index bd5694d88e03fdab6666dee487884ca5e11ed344..b90c10e79fb58747670150a26b29553949522215 100644 (file)
@@ -1954,14 +1954,30 @@ _outProjectSetPath(StringInfo str, const ProjectSetPath *node)
    WRITE_NODE_FIELD(subpath);
 }
 
+static void
+_outSortPathInfo(StringInfo str, const SortPath *node)
+{
+   _outPathInfo(str, (const Path *) node);
+
+   WRITE_NODE_FIELD(subpath);
+}
+
 static void
 _outSortPath(StringInfo str, const SortPath *node)
 {
    WRITE_NODE_TYPE("SORTPATH");
 
-   _outPathInfo(str, (const Path *) node);
+   _outSortPathInfo(str, node);
+}
 
-   WRITE_NODE_FIELD(subpath);
+static void
+_outIncrementalSortPath(StringInfo str, const IncrementalSortPath *node)
+{
+   WRITE_NODE_TYPE("INCREMENTALSORTPATH");
+
+   _outSortPathInfo(str, (const SortPath *) node);
+
+   WRITE_INT_FIELD(nPresortedCols);
 }
 
 static void
@@ -4055,6 +4071,9 @@ outNode(StringInfo str, const void *obj)
            case T_SortPath:
                _outSortPath(str, obj);
                break;
+           case T_IncrementalSortPath:
+               _outIncrementalSortPath(str, obj);
+               break;
            case T_GroupPath:
                _outGroupPath(str, obj);
                break;
index d174b8cb73a8a94529b71196db177d7a5fb2f047..efb52858c88b1d90d8229458612d5ee9ee3419e4 100644 (file)
@@ -387,6 +387,7 @@ RelOptInfo      - a relation or joined relations
   ProjectionPath - a Result plan node with child (used for projection)
   ProjectSetPath - a ProjectSet plan node applied to some sub-path
   SortPath      - a Sort plan node applied to some sub-path
+  IncrementalSortPath - an IncrementalSort plan node applied to some sub-path
   GroupPath     - a Group plan node applied to some sub-path
   UpperUniquePath - a Unique plan node applied to some sub-path
   AggPath       - an Agg plan node applied to some sub-path
index 5281a2f9983ffcd7c6706a1f3778c1f41bdd034b..51478957fb353fb18a4b19955a4e9766b4ae9258 100644 (file)
@@ -2798,7 +2798,7 @@ create_set_projection_path(PlannerInfo *root,
  * 'limit_tuples' is the estimated bound on the number of output tuples,
  *     or -1 if no LIMIT or couldn't estimate
  */
-SortPath *
+IncrementalSortPath *
 create_incremental_sort_path(PlannerInfo *root,
                             RelOptInfo *rel,
                             Path *subpath,
@@ -2834,7 +2834,7 @@ create_incremental_sort_path(PlannerInfo *root,
 
    sort->nPresortedCols = presorted_keys;
 
-   return pathnode;
+   return sort;
 }
 
 /*
index 5a10c1855d66c059e488c6dd7e3849b4390e7abe..b4059895de50abb9ad6db18b413272403cb5794d 100644 (file)
@@ -1655,7 +1655,10 @@ typedef struct SortPath
 } SortPath;
 
 /*
- * IncrementalSortPath
+ * IncrementalSortPath represents an incremental sort step
+ *
+ * This is like a regular sort, except some leading key columns are assumed
+ * to be ordered already.
  */
 typedef struct IncrementalSortPath
 {
index 715a24ad29a716f8112a3196e1dcb7faf5a22e9d..3bd7072ae8c60485a89affe14f4d9a46cd3192ee 100644 (file)
@@ -184,17 +184,17 @@ extern ProjectSetPath *create_set_projection_path(PlannerInfo *root,
                                                  RelOptInfo *rel,
                                                  Path *subpath,
                                                  PathTarget *target);
-extern SortPath *create_incremental_sort_path(PlannerInfo *root,
-                                             RelOptInfo *rel,
-                                             Path *subpath,
-                                             List *pathkeys,
-                                             int presorted_keys,
-                                             double limit_tuples);
 extern SortPath *create_sort_path(PlannerInfo *root,
                                  RelOptInfo *rel,
                                  Path *subpath,
                                  List *pathkeys,
                                  double limit_tuples);
+extern IncrementalSortPath *create_incremental_sort_path(PlannerInfo *root,
+                                                        RelOptInfo *rel,
+                                                        Path *subpath,
+                                                        List *pathkeys,
+                                                        int presorted_keys,
+                                                        double limit_tuples);
 extern GroupPath *create_group_path(PlannerInfo *root,
                                    RelOptInfo *rel,
                                    Path *subpath,