* Compute requested extended stats, using the rows sampled for the plain * (single-column) stats. * * This fetches a list of stats types from pg_statistic_ext, computes the * requested stats, and serializes them back into the catalog. */
| 112 | * requested stats, and serializes them back into the catalog. |
| 113 | */ |
| 114 | void |
| 115 | BuildRelationExtStatistics(Relation onerel, double totalrows, |
| 116 | int numrows, HeapTuple *rows, |
| 117 | int natts, VacAttrStats **vacattrstats) |
| 118 | { |
| 119 | Relation pg_stext; |
| 120 | ListCell *lc; |
| 121 | List *statslist; |
| 122 | MemoryContext cxt; |
| 123 | MemoryContext oldcxt; |
| 124 | int64 ext_cnt; |
| 125 | |
| 126 | /* Do nothing if there are no columns to analyze. */ |
| 127 | if (Gp_role == GP_ROLE_EXECUTE || !natts) |
| 128 | return; |
| 129 | |
| 130 | /* the list of stats has to be allocated outside the memory context */ |
| 131 | pg_stext = table_open(StatisticExtRelationId, RowExclusiveLock); |
| 132 | statslist = fetch_statentries_for_relation(pg_stext, RelationGetRelid(onerel)); |
| 133 | |
| 134 | /* memory context for building each statistics object */ |
| 135 | cxt = AllocSetContextCreate(CurrentMemoryContext, |
| 136 | "BuildRelationExtStatistics", |
| 137 | ALLOCSET_DEFAULT_SIZES); |
| 138 | oldcxt = MemoryContextSwitchTo(cxt); |
| 139 | |
| 140 | /* report this phase */ |
| 141 | if (statslist != NIL) |
| 142 | { |
| 143 | const int index[] = { |
| 144 | PROGRESS_ANALYZE_PHASE, |
| 145 | PROGRESS_ANALYZE_EXT_STATS_TOTAL |
| 146 | }; |
| 147 | const int64 val[] = { |
| 148 | PROGRESS_ANALYZE_PHASE_COMPUTE_EXT_STATS, |
| 149 | list_length(statslist) |
| 150 | }; |
| 151 | |
| 152 | pgstat_progress_update_multi_param(2, index, val); |
| 153 | } |
| 154 | |
| 155 | ext_cnt = 0; |
| 156 | foreach(lc, statslist) |
| 157 | { |
| 158 | StatExtEntry *stat = (StatExtEntry *) lfirst(lc); |
| 159 | MVNDistinct *ndistinct = NULL; |
| 160 | MVDependencies *dependencies = NULL; |
| 161 | MCVList *mcv = NULL; |
| 162 | Datum exprstats = (Datum) 0; |
| 163 | VacAttrStats **stats; |
| 164 | ListCell *lc2; |
| 165 | int stattarget; |
| 166 | StatsBuildData *data; |
| 167 | |
| 168 | /* |
| 169 | * Check if we can build these stats based on the column analyzed. If |
| 170 | * not, report this fact (except in autovacuum) and move on. |
| 171 | */ |
no test coverage detected