Small improvements to OPTIMIZER_DEBUG code.
authorTom Lane
Sat, 30 Apr 2016 18:08:00 +0000 (14:08 -0400)
committerTom Lane
Sat, 30 Apr 2016 18:08:00 +0000 (14:08 -0400)
Now that Paths have their own rows field, print that rather than
the parent relation's rowcount.

Show the relid sets associated with Paths using table names rather
than numbers; since this code is able to print simple Var references
using table names, it seems a bit silly that print_relids can't.

Print the cheapest_parameterized_paths list for a RelOptInfo, and
include information about a parameterized path's required_outer rels.

Noted while trying to use this feature to debug Alexander Kirkouski's
recent bug report.

src/backend/optimizer/path/allpaths.c

index 5246260e12a5f3e5bfef510e3892671f72f80edc..873a76477484d4b41eaf7b2778b13c306fd71405 100644 (file)
@@ -2829,7 +2829,7 @@ remove_unused_subquery_outputs(Query *subquery, RelOptInfo *rel)
 #ifdef OPTIMIZER_DEBUG
 
 static void
-print_relids(Relids relids)
+print_relids(PlannerInfo *root, Relids relids)
 {
    int         x;
    bool        first = true;
@@ -2839,7 +2839,11 @@ print_relids(Relids relids)
    {
        if (!first)
            printf(" ");
-       printf("%d", x);
+       if (x < root->simple_rel_array_size &&
+           root->simple_rte_array[x])
+           printf("%s", root->simple_rte_array[x]->eref->aliasname);
+       else
+           printf("%d", x);
        first = false;
    }
 }
@@ -3013,10 +3017,17 @@ print_path(PlannerInfo *root, Path *path, int indent)
    if (path->parent)
    {
        printf("(");
-       print_relids(path->parent->relids);
-       printf(") rows=%.0f", path->parent->rows);
+       print_relids(root, path->parent->relids);
+       printf(")");
+   }
+   if (path->param_info)
+   {
+       printf(" required_outer (");
+       print_relids(root, path->param_info->ppi_req_outer);
+       printf(")");
    }
-   printf(" cost=%.2f..%.2f\n", path->startup_cost, path->total_cost);
+   printf(" rows=%.0f cost=%.2f..%.2f\n",
+          path->rows, path->startup_cost, path->total_cost);
 
    if (path->pathkeys)
    {
@@ -3062,7 +3073,7 @@ debug_print_rel(PlannerInfo *root, RelOptInfo *rel)
    ListCell   *l;
 
    printf("RELOPTINFO (");
-   print_relids(rel->relids);
+   print_relids(root, rel->relids);
    printf("): rows=%.0f width=%d\n", rel->rows, rel->reltarget->width);
 
    if (rel->baserestrictinfo)
@@ -3082,6 +3093,12 @@ debug_print_rel(PlannerInfo *root, RelOptInfo *rel)
    printf("\tpath list:\n");
    foreach(l, rel->pathlist)
        print_path(root, lfirst(l), 1);
+   if (rel->cheapest_parameterized_paths)
+   {
+       printf("\n\tcheapest parameterized paths:\n");
+       foreach(l, rel->cheapest_parameterized_paths)
+           print_path(root, lfirst(l), 1);
+   }
    if (rel->cheapest_startup_path)
    {
        printf("\n\tcheapest startup path:\n");