|
14 | 14 |
|
15 | 15 | #include "postgres.h" |
16 | 16 | #include <commands/explain.h> |
| 17 | +#include <distributed/pg_dist_partition.h> |
17 | 18 | #include "planner/predicate_management.h" |
18 | 19 | #include "multirelation/multirelation_utils.h" |
19 | 20 | #include "planner/distributed_mobilitydb_planner.h" |
@@ -68,20 +69,75 @@ static void ExplainMainPredicate(PredicateType predicateType, PredicateInfo * pr |
68 | 69 | * touched by the query along with its tiling method, local index, and tile |
69 | 70 | * count; repeated references to the same table (self-joins) are skipped |
70 | 71 | * after the first. |
| 72 | + * |
| 73 | + * The header counts distinguish genuinely-distributed (tiled) spatiotemporal |
| 74 | + * tables from replicated reference tables -- tablesList->length/diffCount |
| 75 | + * count every range-table entry or distinct relid regardless of kind, so a |
| 76 | + * query joining one tiled table against several reference tables (e.g. a |
| 77 | + * self-join on trips_16t plus 4 reference-table references) used to print |
| 78 | + * as "Distributed Tables:6" / "different tables: 4", reading as if several |
| 79 | + * genuinely-sharded tables were involved instead of one. |
71 | 80 | */ |
72 | 81 | static void ExplainDistributedTables(STMultirelations *tablesList, ExplainState *es, int indent_group) |
73 | 82 | { |
| 83 | + List *seenDistributedRelids = NIL; |
| 84 | + List *seenReferenceRelids = NIL; |
| 85 | + int distributedOccurrences = 0; |
| 86 | + int referenceOccurrences = 0; |
| 87 | + ListCell *countCell = NULL; |
| 88 | + foreach(countCell, tablesList->tables) |
| 89 | + { |
| 90 | + Rte *rteNode = (Rte *) lfirst(countCell); |
| 91 | + if (rteNode->RteType == STRte) |
| 92 | + { |
| 93 | + STMultirelation *st = (STMultirelation *) rteNode->rte; |
| 94 | + distributedOccurrences++; |
| 95 | + if (!list_member_oid(seenDistributedRelids, st->catalogTableInfo.table_oid)) |
| 96 | + seenDistributedRelids = lappend_oid(seenDistributedRelids, st->catalogTableInfo.table_oid); |
| 97 | + } |
| 98 | + else if (rteNode->RteType == CitusRte) |
| 99 | + { |
| 100 | + CitusRteNode *citusRte = (CitusRteNode *) rteNode->rte; |
| 101 | + /* Reference tables report Citus' "none" partition method |
| 102 | + * ('n', DISTRIBUTE_BY_NONE) -- the same value plain Citus |
| 103 | + * local tables report, but a CitusRteNode only ever exists for |
| 104 | + * a hash/range-distributed table or a reference table (see |
| 105 | + * analyzeDistributedSpatiotemporalTables), so "not hash, not |
| 106 | + * range" reliably means "reference table" here. */ |
| 107 | + if (citusRte->partitionMethod != DISTRIBUTE_BY_HASH && |
| 108 | + citusRte->partitionMethod != DISTRIBUTE_BY_RANGE) |
| 109 | + { |
| 110 | + Oid relid = ((RangeTblEntry *) lfirst(citusRte->rangeTableCell))->relid; |
| 111 | + referenceOccurrences++; |
| 112 | + if (!list_member_oid(seenReferenceRelids, relid)) |
| 113 | + seenReferenceRelids = lappend_oid(seenReferenceRelids, relid); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + int distinctDistributedCount = list_length(seenDistributedRelids); |
| 119 | + |
74 | 120 | appendStringInfoSpaces(es->str, es->indent * indent_group); |
75 | | - appendStringInfo(es->str, "-> Distributed Tables:%d\n", tablesList->length); |
| 121 | + appendStringInfo(es->str, "-> Distributed Tables:%d\n", distinctDistributedCount); |
76 | 122 | es->indent += indent_group; |
77 | 123 | ExplainOpenGroup("TablesInfo", "Distributed Tables Info", true, es); |
78 | 124 | appendStringInfoSpaces(es->str, es->indent * indent_group); |
79 | | - appendStringInfo(es->str, "Number of similar tables: %d\n", tablesList->simCount); |
| 125 | + /* "Similar"/"different" here are scoped to genuinely-distributed (tiled) |
| 126 | + * tables only -- self-joins (e.g. trips_16t as both t1 and t2) count as |
| 127 | + * "similar", and distinct distributed tables (e.g. two different tiled |
| 128 | + * tables joined together) count as "different". Reference tables are |
| 129 | + * reported separately below, never folded into either count. */ |
| 130 | + appendStringInfo(es->str, "Number of similar tables: %d\n", |
| 131 | + distributedOccurrences - distinctDistributedCount); |
| 132 | + appendStringInfoSpaces(es->str, es->indent * indent_group); |
| 133 | + appendStringInfo(es->str, "Number of different tables: %d\n", distinctDistributedCount); |
80 | 134 | appendStringInfoSpaces(es->str, es->indent * indent_group); |
81 | | - if (tablesList->diffCount > 1) |
82 | | - appendStringInfo(es->str, "Number of different tables: %d\n", tablesList->diffCount); |
| 135 | + if (referenceOccurrences > 0) |
| 136 | + appendStringInfo(es->str, "Replicated (reference) tables: %d (%d reference%s)\n", |
| 137 | + list_length(seenReferenceRelids), referenceOccurrences, |
| 138 | + referenceOccurrences == 1 ? "" : "s"); |
83 | 139 | else |
84 | | - appendStringInfo(es->str, "Number of different tables: %d\n", 0); |
| 140 | + appendStringInfo(es->str, "Replicated (reference) tables: 0\n"); |
85 | 141 | appendStringInfoSpaces(es->str, es->indent * indent_group); |
86 | 142 | ListCell *rangeTableCell = NULL; |
87 | 143 | char * check = NULL; |
|
0 commit comments