@@ -94,20 +94,21 @@ static char *ChooseIndexName(const char *tabname, Oid namespaceId,
94
94
bool primary , bool isconstraint );
95
95
static char * ChooseIndexNameAddition (const List * colnames );
96
96
static List * ChooseIndexColumnNames (const List * indexElems );
97
- static void ReindexIndex (const RangeVar * indexRelation , const ReindexParams * params ,
97
+ static void ReindexIndex (const ReindexStmt * stmt , const ReindexParams * params ,
98
98
bool isTopLevel );
99
99
static void RangeVarCallbackForReindexIndex (const RangeVar * relation ,
100
100
Oid relId , Oid oldRelId , void * arg );
101
- static Oid ReindexTable (const RangeVar * relation , const ReindexParams * params ,
101
+ static Oid ReindexTable (const ReindexStmt * stmt , const ReindexParams * params ,
102
102
bool isTopLevel );
103
- static void ReindexMultipleTables (const char * objectName ,
104
- ReindexObjectType objectKind , const ReindexParams * params );
103
+ static void ReindexMultipleTables (const ReindexStmt * stmt ,
104
+ const ReindexParams * params );
105
105
static void reindex_error_callback (void * arg );
106
- static void ReindexPartitions (Oid relid , const ReindexParams * params ,
107
- bool isTopLevel );
108
- static void ReindexMultipleInternal (const List * relids ,
106
+ static void ReindexPartitions (const ReindexStmt * stmt , Oid relid ,
107
+ const ReindexParams * params , bool isTopLevel );
108
+ static void ReindexMultipleInternal (const ReindexStmt * stmt , const List * relids ,
109
109
const ReindexParams * params );
110
- static bool ReindexRelationConcurrently (Oid relationOid ,
110
+ static bool ReindexRelationConcurrently (const ReindexStmt * stmt ,
111
+ Oid relationOid ,
111
112
const ReindexParams * params );
112
113
static void update_relispartition (Oid relationId , bool newval );
113
114
static inline void set_indexsafe_procflags (void );
@@ -2735,10 +2736,10 @@ ExecReindex(ParseState *pstate, const ReindexStmt *stmt, bool isTopLevel)
2735
2736
switch (stmt -> kind )
2736
2737
{
2737
2738
case REINDEX_OBJECT_INDEX :
2738
- ReindexIndex (stmt -> relation , & params , isTopLevel );
2739
+ ReindexIndex (stmt , & params , isTopLevel );
2739
2740
break ;
2740
2741
case REINDEX_OBJECT_TABLE :
2741
- ReindexTable (stmt -> relation , & params , isTopLevel );
2742
+ ReindexTable (stmt , & params , isTopLevel );
2742
2743
break ;
2743
2744
case REINDEX_OBJECT_SCHEMA :
2744
2745
case REINDEX_OBJECT_SYSTEM :
@@ -2754,7 +2755,7 @@ ExecReindex(ParseState *pstate, const ReindexStmt *stmt, bool isTopLevel)
2754
2755
(stmt -> kind == REINDEX_OBJECT_SCHEMA ) ? "REINDEX SCHEMA" :
2755
2756
(stmt -> kind == REINDEX_OBJECT_SYSTEM ) ? "REINDEX SYSTEM" :
2756
2757
"REINDEX DATABASE" );
2757
- ReindexMultipleTables (stmt -> name , stmt -> kind , & params );
2758
+ ReindexMultipleTables (stmt , & params );
2758
2759
break ;
2759
2760
default :
2760
2761
elog (ERROR , "unrecognized object type: %d" ,
@@ -2768,8 +2769,9 @@ ExecReindex(ParseState *pstate, const ReindexStmt *stmt, bool isTopLevel)
2768
2769
* Recreate a specific index.
2769
2770
*/
2770
2771
static void
2771
- ReindexIndex (const RangeVar * indexRelation , const ReindexParams * params , bool isTopLevel )
2772
+ ReindexIndex (const ReindexStmt * stmt , const ReindexParams * params , bool isTopLevel )
2772
2773
{
2774
+ const RangeVar * indexRelation = stmt -> relation ;
2773
2775
struct ReindexIndexCallbackState state ;
2774
2776
Oid indOid ;
2775
2777
char persistence ;
@@ -2802,16 +2804,16 @@ ReindexIndex(const RangeVar *indexRelation, const ReindexParams *params, bool is
2802
2804
relkind = get_rel_relkind (indOid );
2803
2805
2804
2806
if (relkind == RELKIND_PARTITIONED_INDEX )
2805
- ReindexPartitions (indOid , params , isTopLevel );
2807
+ ReindexPartitions (stmt , indOid , params , isTopLevel );
2806
2808
else if ((params -> options & REINDEXOPT_CONCURRENTLY ) != 0 &&
2807
2809
persistence != RELPERSISTENCE_TEMP )
2808
- ReindexRelationConcurrently (indOid , params );
2810
+ ReindexRelationConcurrently (stmt , indOid , params );
2809
2811
else
2810
2812
{
2811
2813
ReindexParams newparams = * params ;
2812
2814
2813
2815
newparams .options |= REINDEXOPT_REPORT_PROGRESS ;
2814
- reindex_index (indOid , false, persistence , & newparams );
2816
+ reindex_index (stmt , indOid , false, persistence , & newparams );
2815
2817
}
2816
2818
}
2817
2819
@@ -2891,10 +2893,11 @@ RangeVarCallbackForReindexIndex(const RangeVar *relation,
2891
2893
* Recreate all indexes of a table (and of its toast table, if any)
2892
2894
*/
2893
2895
static Oid
2894
- ReindexTable (const RangeVar * relation , const ReindexParams * params , bool isTopLevel )
2896
+ ReindexTable (const ReindexStmt * stmt , const ReindexParams * params , bool isTopLevel )
2895
2897
{
2896
2898
Oid heapOid ;
2897
2899
bool result ;
2900
+ const RangeVar * relation = stmt -> relation ;
2898
2901
2899
2902
/*
2900
2903
* The lock level used here should match reindex_relation().
@@ -2911,11 +2914,11 @@ ReindexTable(const RangeVar *relation, const ReindexParams *params, bool isTopLe
2911
2914
RangeVarCallbackOwnsTable , NULL );
2912
2915
2913
2916
if (get_rel_relkind (heapOid ) == RELKIND_PARTITIONED_TABLE )
2914
- ReindexPartitions (heapOid , params , isTopLevel );
2917
+ ReindexPartitions (stmt , heapOid , params , isTopLevel );
2915
2918
else if ((params -> options & REINDEXOPT_CONCURRENTLY ) != 0 &&
2916
2919
get_rel_persistence (heapOid ) != RELPERSISTENCE_TEMP )
2917
2920
{
2918
- result = ReindexRelationConcurrently (heapOid , params );
2921
+ result = ReindexRelationConcurrently (stmt , heapOid , params );
2919
2922
2920
2923
if (!result )
2921
2924
ereport (NOTICE ,
@@ -2927,7 +2930,7 @@ ReindexTable(const RangeVar *relation, const ReindexParams *params, bool isTopLe
2927
2930
ReindexParams newparams = * params ;
2928
2931
2929
2932
newparams .options |= REINDEXOPT_REPORT_PROGRESS ;
2930
- result = reindex_relation (heapOid ,
2933
+ result = reindex_relation (stmt , heapOid ,
2931
2934
REINDEX_REL_PROCESS_TOAST |
2932
2935
REINDEX_REL_CHECK_CONSTRAINTS ,
2933
2936
& newparams );
@@ -2949,9 +2952,9 @@ ReindexTable(const RangeVar *relation, const ReindexParams *params, bool isTopLe
2949
2952
* That means this must not be called within a user transaction block!
2950
2953
*/
2951
2954
static void
2952
- ReindexMultipleTables (const char * objectName , ReindexObjectType objectKind ,
2953
- const ReindexParams * params )
2955
+ ReindexMultipleTables (const ReindexStmt * stmt , const ReindexParams * params )
2954
2956
{
2957
+
2955
2958
Oid objectOid ;
2956
2959
Relation relationRelation ;
2957
2960
TableScanDesc scan ;
@@ -2963,6 +2966,8 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
2963
2966
int num_keys ;
2964
2967
bool concurrent_warning = false;
2965
2968
bool tablespace_warning = false;
2969
+ const char * objectName = stmt -> name ;
2970
+ const ReindexObjectType objectKind = stmt -> kind ;
2966
2971
2967
2972
Assert (objectKind == REINDEX_OBJECT_SCHEMA ||
2968
2973
objectKind == REINDEX_OBJECT_SYSTEM ||
@@ -3158,7 +3163,7 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
3158
3163
* Process each relation listed in a separate transaction. Note that this
3159
3164
* commits and then starts a new transaction immediately.
3160
3165
*/
3161
- ReindexMultipleInternal (relids , params );
3166
+ ReindexMultipleInternal (stmt , relids , params );
3162
3167
3163
3168
MemoryContextDelete (private_context );
3164
3169
}
@@ -3188,7 +3193,7 @@ reindex_error_callback(void *arg)
3188
3193
* by the caller.
3189
3194
*/
3190
3195
static void
3191
- ReindexPartitions (Oid relid , const ReindexParams * params , bool isTopLevel )
3196
+ ReindexPartitions (const ReindexStmt * stmt , Oid relid , const ReindexParams * params , bool isTopLevel )
3192
3197
{
3193
3198
List * partitions = NIL ;
3194
3199
char relkind = get_rel_relkind (relid );
@@ -3264,7 +3269,7 @@ ReindexPartitions(Oid relid, const ReindexParams *params, bool isTopLevel)
3264
3269
* Process each partition listed in a separate transaction. Note that
3265
3270
* this commits and then starts a new transaction immediately.
3266
3271
*/
3267
- ReindexMultipleInternal (partitions , params );
3272
+ ReindexMultipleInternal (stmt , partitions , params );
3268
3273
3269
3274
/*
3270
3275
* Clean up working storage --- note we must do this after
@@ -3282,7 +3287,7 @@ ReindexPartitions(Oid relid, const ReindexParams *params, bool isTopLevel)
3282
3287
* and starts a new transaction when finished.
3283
3288
*/
3284
3289
static void
3285
- ReindexMultipleInternal (const List * relids , const ReindexParams * params )
3290
+ ReindexMultipleInternal (const ReindexStmt * stmt , const List * relids , const ReindexParams * params )
3286
3291
{
3287
3292
ListCell * l ;
3288
3293
@@ -3341,7 +3346,7 @@ ReindexMultipleInternal(const List *relids, const ReindexParams *params)
3341
3346
ReindexParams newparams = * params ;
3342
3347
3343
3348
newparams .options |= REINDEXOPT_MISSING_OK ;
3344
- (void ) ReindexRelationConcurrently (relid , & newparams );
3349
+ (void ) ReindexRelationConcurrently (stmt , relid , & newparams );
3345
3350
/* ReindexRelationConcurrently() does the verbose output */
3346
3351
}
3347
3352
else if (relkind == RELKIND_INDEX )
@@ -3350,7 +3355,7 @@ ReindexMultipleInternal(const List *relids, const ReindexParams *params)
3350
3355
3351
3356
newparams .options |=
3352
3357
REINDEXOPT_REPORT_PROGRESS | REINDEXOPT_MISSING_OK ;
3353
- reindex_index (relid , false, relpersistence , & newparams );
3358
+ reindex_index (stmt , relid , false, relpersistence , & newparams );
3354
3359
PopActiveSnapshot ();
3355
3360
/* reindex_index() does the verbose output */
3356
3361
}
@@ -3361,7 +3366,7 @@ ReindexMultipleInternal(const List *relids, const ReindexParams *params)
3361
3366
3362
3367
newparams .options |=
3363
3368
REINDEXOPT_REPORT_PROGRESS | REINDEXOPT_MISSING_OK ;
3364
- result = reindex_relation (relid ,
3369
+ result = reindex_relation (stmt , relid ,
3365
3370
REINDEX_REL_PROCESS_TOAST |
3366
3371
REINDEX_REL_CHECK_CONSTRAINTS ,
3367
3372
& newparams );
@@ -3406,7 +3411,7 @@ ReindexMultipleInternal(const List *relids, const ReindexParams *params)
3406
3411
* anyway, and a non-concurrent reindex is more efficient.
3407
3412
*/
3408
3413
static bool
3409
- ReindexRelationConcurrently (Oid relationOid , const ReindexParams * params )
3414
+ ReindexRelationConcurrently (const ReindexStmt * stmt , Oid relationOid , const ReindexParams * params )
3410
3415
{
3411
3416
typedef struct ReindexIndexInfo
3412
3417
{
@@ -3843,6 +3848,20 @@ ReindexRelationConcurrently(Oid relationOid, const ReindexParams *params)
3843
3848
SetUserIdAndSecContext (save_userid , save_sec_context );
3844
3849
3845
3850
table_close (heapRel , NoLock );
3851
+
3852
+ /*
3853
+ * If a statement is available, telling that this comes from a REINDEX
3854
+ * command, collect the new index for event triggers.
3855
+ */
3856
+ if (stmt )
3857
+ {
3858
+ ObjectAddress address ;
3859
+
3860
+ ObjectAddressSet (address , RelationRelationId , newIndexId );
3861
+ EventTriggerCollectSimpleCommand (address ,
3862
+ InvalidObjectAddress ,
3863
+ (Node * ) stmt );
3864
+ }
3846
3865
}
3847
3866
3848
3867
/*
0 commit comments