@@ -420,20 +420,34 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
420
420
/*
421
421
* Open all indexes of the relation, and see if there are any analyzable
422
422
* columns in the indexes. We do not analyze index columns if there was
423
- * an explicit column list in the ANALYZE command, however. If we are
424
- * doing a recursive scan, we don't want to touch the parent's indexes at
425
- * all.
423
+ * an explicit column list in the ANALYZE command, however.
424
+ *
425
+ * If we are doing a recursive scan, we don't want to touch the parent's
426
+ * indexes at all. If we're processing a partitioned table, we need to
427
+ * know if there are any indexes, but we don't want to process them.
426
428
*/
427
- if (!inh )
429
+ if (onerel -> rd_rel -> relkind == RELKIND_PARTITIONED_TABLE )
430
+ {
431
+ List * idxs = RelationGetIndexList (onerel );
432
+
433
+ Irel = NULL ;
434
+ nindexes = 0 ;
435
+ hasindex = idxs != NIL ;
436
+ list_free (idxs );
437
+ }
438
+ else if (!inh )
439
+ {
428
440
vac_open_indexes (onerel , AccessShareLock , & nindexes , & Irel );
441
+ hasindex = nindexes > 0 ;
442
+ }
429
443
else
430
444
{
431
445
Irel = NULL ;
432
446
nindexes = 0 ;
447
+ hasindex = false;
433
448
}
434
- hasindex = (nindexes > 0 );
435
449
indexdata = NULL ;
436
- if (hasindex )
450
+ if (nindexes > 0 )
437
451
{
438
452
indexdata = (AnlIndexData * ) palloc0 (nindexes * sizeof (AnlIndexData ));
439
453
for (ind = 0 ; ind < nindexes ; ind ++ )
@@ -572,7 +586,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
572
586
MemoryContextResetAndDeleteChildren (col_context );
573
587
}
574
588
575
- if (hasindex )
589
+ if (nindexes > 0 )
576
590
compute_index_stats (onerel , totalrows ,
577
591
indexdata , nindexes ,
578
592
rows , numrows ,
@@ -660,10 +674,10 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
660
674
/*
661
675
* Partitioned tables don't have storage, so we don't set any fields
662
676
* in their pg_class entries except for reltuples, which is necessary
663
- * for auto-analyze to work properly.
677
+ * for auto-analyze to work properly, and relhasindex .
664
678
*/
665
679
vac_update_relstats (onerel , -1 , totalrows ,
666
- 0 , false , InvalidTransactionId ,
680
+ 0 , hasindex , InvalidTransactionId ,
667
681
InvalidMultiXactId ,
668
682
in_outer_xact );
669
683
}
0 commit comments