@@ -246,6 +246,17 @@ typedef struct ComputeXidHorizonsResult
246
246
247
247
} ComputeXidHorizonsResult ;
248
248
249
+ /*
250
+ * Return value for GlobalVisHorizonKindForRel().
251
+ */
252
+ typedef enum GlobalVisHorizonKind
253
+ {
254
+ VISHORIZON_SHARED ,
255
+ VISHORIZON_CATALOG ,
256
+ VISHORIZON_DATA ,
257
+ VISHORIZON_TEMP
258
+ } GlobalVisHorizonKind ;
259
+
249
260
250
261
static ProcArrayStruct * procArray ;
251
262
@@ -1952,6 +1963,33 @@ ComputeXidHorizons(ComputeXidHorizonsResult *h)
1952
1963
GlobalVisUpdateApply (h );
1953
1964
}
1954
1965
1966
+ /*
1967
+ * Determine what kind of visibility horizon needs to be used for a
1968
+ * relation. If rel is NULL, the most conservative horizon is used.
1969
+ */
1970
+ static inline GlobalVisHorizonKind
1971
+ GlobalVisHorizonKindForRel (Relation rel )
1972
+ {
1973
+ /*
1974
+ * Other relkkinds currently don't contain xids, nor always the necessary
1975
+ * logical decoding markers.
1976
+ */
1977
+ Assert (!rel ||
1978
+ rel -> rd_rel -> relkind == RELKIND_RELATION ||
1979
+ rel -> rd_rel -> relkind == RELKIND_MATVIEW ||
1980
+ rel -> rd_rel -> relkind == RELKIND_TOASTVALUE );
1981
+
1982
+ if (rel == NULL || rel -> rd_rel -> relisshared || RecoveryInProgress ())
1983
+ return VISHORIZON_SHARED ;
1984
+ else if (IsCatalogRelation (rel ) ||
1985
+ RelationIsAccessibleInLogicalDecoding (rel ))
1986
+ return VISHORIZON_CATALOG ;
1987
+ else if (!RELATION_IS_LOCAL (rel ))
1988
+ return VISHORIZON_DATA ;
1989
+ else
1990
+ return VISHORIZON_TEMP ;
1991
+ }
1992
+
1955
1993
/*
1956
1994
* Return the oldest XID for which deleted tuples must be preserved in the
1957
1995
* passed table.
@@ -1970,16 +2008,20 @@ GetOldestNonRemovableTransactionId(Relation rel)
1970
2008
1971
2009
ComputeXidHorizons (& horizons );
1972
2010
1973
- /* select horizon appropriate for relation */
1974
- if (rel == NULL || rel -> rd_rel -> relisshared || RecoveryInProgress ())
1975
- return horizons .shared_oldest_nonremovable ;
1976
- else if (IsCatalogRelation (rel ) ||
1977
- RelationIsAccessibleInLogicalDecoding (rel ))
1978
- return horizons .catalog_oldest_nonremovable ;
1979
- else if (RELATION_IS_LOCAL (rel ))
1980
- return horizons .temp_oldest_nonremovable ;
1981
- else
1982
- return horizons .data_oldest_nonremovable ;
2011
+ switch (GlobalVisHorizonKindForRel (rel ))
2012
+ {
2013
+ case VISHORIZON_SHARED :
2014
+ return horizons .shared_oldest_nonremovable ;
2015
+ case VISHORIZON_CATALOG :
2016
+ return horizons .catalog_oldest_nonremovable ;
2017
+ case VISHORIZON_DATA :
2018
+ return horizons .data_oldest_nonremovable ;
2019
+ case VISHORIZON_TEMP :
2020
+ return horizons .temp_oldest_nonremovable ;
2021
+ }
2022
+
2023
+ /* just to prevent compiler warnings */
2024
+ return InvalidTransactionId ;
1983
2025
}
1984
2026
1985
2027
/*
@@ -3986,38 +4028,27 @@ DisplayXidCache(void)
3986
4028
GlobalVisState *
3987
4029
GlobalVisTestFor (Relation rel )
3988
4030
{
3989
- bool need_shared ;
3990
- bool need_catalog ;
3991
- GlobalVisState * state ;
4031
+ GlobalVisState * state = NULL ;
3992
4032
3993
4033
/* XXX: we should assert that a snapshot is pushed or registered */
3994
4034
Assert (RecentXmin );
3995
4035
3996
- if (!rel )
3997
- need_shared = need_catalog = true;
3998
- else
4036
+ switch (GlobalVisHorizonKindForRel (rel ))
3999
4037
{
4000
- /*
4001
- * Other kinds currently don't contain xids, nor always the necessary
4002
- * logical decoding markers.
4003
- */
4004
- Assert (rel -> rd_rel -> relkind == RELKIND_RELATION ||
4005
- rel -> rd_rel -> relkind == RELKIND_MATVIEW ||
4006
- rel -> rd_rel -> relkind == RELKIND_TOASTVALUE );
4007
-
4008
- need_shared = rel -> rd_rel -> relisshared || RecoveryInProgress ();
4009
- need_catalog = IsCatalogRelation (rel ) || RelationIsAccessibleInLogicalDecoding (rel );
4038
+ case VISHORIZON_SHARED :
4039
+ state = & GlobalVisSharedRels ;
4040
+ break ;
4041
+ case VISHORIZON_CATALOG :
4042
+ state = & GlobalVisCatalogRels ;
4043
+ break ;
4044
+ case VISHORIZON_DATA :
4045
+ state = & GlobalVisDataRels ;
4046
+ break ;
4047
+ case VISHORIZON_TEMP :
4048
+ state = & GlobalVisTempRels ;
4049
+ break ;
4010
4050
}
4011
4051
4012
- if (need_shared )
4013
- state = & GlobalVisSharedRels ;
4014
- else if (need_catalog )
4015
- state = & GlobalVisCatalogRels ;
4016
- else if (RELATION_IS_LOCAL (rel ))
4017
- state = & GlobalVisTempRels ;
4018
- else
4019
- state = & GlobalVisDataRels ;
4020
-
4021
4052
Assert (FullTransactionIdIsValid (state -> definitely_needed ) &&
4022
4053
FullTransactionIdIsValid (state -> maybe_needed ));
4023
4054
0 commit comments