diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/commands/analyze.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 426c1e67109..0c9591415e4 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -420,20 +420,34 @@ do_analyze_rel(Relation onerel, VacuumParams *params, /* * Open all indexes of the relation, and see if there are any analyzable * columns in the indexes. We do not analyze index columns if there was - * an explicit column list in the ANALYZE command, however. If we are - * doing a recursive scan, we don't want to touch the parent's indexes at - * all. + * an explicit column list in the ANALYZE command, however. + * + * If we are doing a recursive scan, we don't want to touch the parent's + * indexes at all. If we're processing a partitioned table, we need to + * know if there are any indexes, but we don't want to process them. */ - if (!inh) + if (onerel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) + { + List *idxs = RelationGetIndexList(onerel); + + Irel = NULL; + nindexes = 0; + hasindex = idxs != NIL; + list_free(idxs); + } + else if (!inh) + { vac_open_indexes(onerel, AccessShareLock, &nindexes, &Irel); + hasindex = nindexes > 0; + } else { Irel = NULL; nindexes = 0; + hasindex = false; } - hasindex = (nindexes > 0); indexdata = NULL; - if (hasindex) + if (nindexes > 0) { indexdata = (AnlIndexData *) palloc0(nindexes * sizeof(AnlIndexData)); for (ind = 0; ind < nindexes; ind++) @@ -572,7 +586,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params, MemoryContextResetAndDeleteChildren(col_context); } - if (hasindex) + if (nindexes > 0) compute_index_stats(onerel, totalrows, indexdata, nindexes, rows, numrows, @@ -660,10 +674,10 @@ do_analyze_rel(Relation onerel, VacuumParams *params, /* * Partitioned tables don't have storage, so we don't set any fields * in their pg_class entries except for reltuples, which is necessary - * for auto-analyze to work properly. + * for auto-analyze to work properly, and relhasindex. */ vac_update_relstats(onerel, -1, totalrows, - 0, false, InvalidTransactionId, + 0, hasindex, InvalidTransactionId, InvalidMultiXactId, in_outer_xact); } |