8000 Avoid listing the same ResultRelInfo in more than one EState list. · postgres/postgres@e44dd84 · GitHub
[go: up one dir, main page]

Skip to content
  • Commit e44dd84

    Browse files
    committed
    Avoid listing the same ResultRelInfo in more than one EState list.
    Doing so causes EXPLAIN ANALYZE to show trigger statistics multiple times. Commit 2f17844 seems to be to blame for this. Amit Langote, revieed by Amit Khandekar, Etsuro Fujita, and me.
    1 parent 88fdc70 commit e44dd84

    File tree

    5 files changed

    +27
    -12
    lines changed

    5 files changed

    +27
    -12
    lines changed

    src/backend/commands/explain.c

    Lines changed: 7 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -652,15 +652,18 @@ ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
    652652
    bool show_relname;
    653653
    int numrels = queryDesc->estate->es_num_result_relations;
    654654
    int numrootrels = queryDesc->estate->es_num_root_result_relations;
    655-
    List *leafrels = queryDesc->estate->es_leaf_result_relations;
    656-
    List *targrels = queryDesc->estate->es_trig_target_relations;
    655+
    List *routerels;
    656+
    List *targrels;
    657657
    int nr;
    658658
    ListCell *l;
    659659

    660+
    routerels = queryDesc->estate->es_tuple_routing_result_relations;
    661+
    targrels = queryDesc->estate->es_trig_target_relations;
    662+
    660663
    ExplainOpenGroup("Triggers", "Triggers", false, es);
    661664

    662665
    show_relname = (numrels > 1 || numrootrels > 0 ||
    663-
    leafrels != NIL || targrels != NIL);
    666+
    routerels != NIL || targrels != NIL);
    664667
    rInfo = queryDesc->estate->es_result_relations;
    665668
    for (nr = 0; nr < numrels; rInfo++, nr++)
    666669
    report_triggers(rInfo, show_relname, es);
    @@ -669,7 +672,7 @@ ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
    669672
    for (nr = 0; nr < numrootrels; rInfo++, nr++)
    670673
    report_triggers(rInfo, show_relname, es);
    671674

    672-
    foreach(l, leafrels)
    675+
    foreach(l, routerels)
    673676
    {
    674677
    rInfo = (ResultRelInfo *) lfirst(l);
    675678
    report_triggers(rInfo, show_relname, es);

    src/backend/executor/execMain.c

    Lines changed: 5 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1413,8 +1413,11 @@ ExecGetTriggerResultRel(EState *estate, Oid relid)
    14131413
    rInfo++;
    14141414
    nr--;
    14151415
    }
    1416-
    /* Third, search through the leaf result relations, if any */
    1417-
    foreach(l, estate->es_leaf_result_relations)
    1416+
    /*
    1417+
    * Third, search through the result relations that were created during
    1418+
    * tuple routing, if any.
    1419+
    */
    1420+
    foreach(l, estate->es_tuple_routing_result_relations)
    14181421
    {
    14191422
    rInfo = (ResultRelInfo *) lfirst(l);
    14201423
    if (RelationGetRelid(rInfo->ri_RelationDesc) == relid)

    src/backend/executor/execPartition.c

    Lines changed: 9 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -178,6 +178,15 @@ ExecSetupPartitionTupleRouting(ModifyTableState *mtstate,
    178178
    resultRTindex,
    179179
    rel,
    180180
    estate->es_instrument);
    181+
    182+
    /*
    183+
    * Since we've just initialized this ResultRelInfo, it's not in
    184+
    * any list attached to the estate as yet. Add it, so that it can
    185+
    * be found later.
    186+
    */
    187+
    estate->es_tuple_routing_result_relations =
    188+
    lappend(estate->es_tuple_routing_result_relations,
    189+
    leaf_part_rri);
    181190
    }
    182191

    183192
    part_tupdesc = RelationGetDescr(partrel);
    @@ -210,9 +219,6 @@ ExecSetupPartitionTupleRouting(ModifyTableState *mtstate,
    210219
    mtstate != NULL &&
    211220
    mtstate->mt_onconflict != ONCONFLICT_NONE);
    212221

    213-
    estate->es_leaf_result_relations =
    214-
    lappend(estate->es_leaf_result_relations, leaf_part_rri);
    215-
    216222
    proute->partitions[i] = leaf_part_rri;
    217223
    i++;
    218224
    }

    src/backend/executor/execUtils.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -119,7 +119,7 @@ CreateExecutorState(void)
    119119
    estate->es_root_result_relations = NULL;
    120120
    estate->es_num_root_result_relations = 0;
    121121

    122-
    estate->es_leaf_result_relations = NIL;
    122+
    estate->es_tuple_routing_result_relations = NIL;
    123123

    124124
    estate->es_trig_target_relations = NIL;
    125125
    estate->es_trig_tuple_slot = NULL;

    src/include/nodes/execnodes.h

    Lines changed: 5 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -466,8 +466,11 @@ typedef struct EState
    466466
    ResultRelInfo *es_root_result_relations; /* array of ResultRelInfos */
    467467
    int es_num_root_result_relations; /* length of the array */
    468468

    469-
    /* Info about leaf partitions of partitioned table(s) for insert queries: */
    470-
    List *es_leaf_result_relations; /* List of ResultRelInfos */
    469+
    /*
    470+
    * The following list contains ResultRelInfos created by the tuple
    471+
    * routing code for partitions that don't already have one.
    472+
    */
    473+
    List *es_tuple_routing_result_relations;
    471474

    472475
    /* Stuff used for firing triggers: */
    473476
    List *es_trig_target_relations; /* trigger-only ResultRelInfos */

    0 commit comments

    Comments
     (0)
    0