20
20
#define PG_RETURN_UINT8 (x ) return UInt8GetDatum(x)
21
21
#define PG_RETURN_UINT16 (x ) return UInt16GetDatum(x)
22
22
23
- #if defined(__GNUC__ ) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95 ))
24
- # define likely (x ) __builtin_expect((x),1)
25
- # define unlikely (x ) __builtin_expect((x),0)
26
- #else
27
- # define likely (x ) (x)
28
- # define unlikely (x ) (x)
23
+ #if !defined(likely ) && !defined(unlikely )
24
+ # if defined(__GNUC__ ) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95 ))
25
+ # define likely (x ) __builtin_expect((x),1)
26
+ # define unlikely (x ) __builtin_expect((x),0)
27
+ # else
28
+ # define likely (x ) (x)
29
+ # define unlikely (x ) (x)
30
+ # endif
29
31
#endif
30
32
31
33
#ifdef PG_MODULE_MAGIC
32
34
PG_MODULE_MAGIC ;
33
35
#endif
34
36
37
+
35
38
/*
36
39
* ==================
37
40
* UINT1 DECLARATIONS
@@ -214,6 +217,7 @@ PG_FUNCTION_INFO_V1(uint1le);
214
217
PG_FUNCTION_INFO_V1 (uint1gt );
215
218
PG_FUNCTION_INFO_V1 (uint1ge );
216
219
PG_FUNCTION_INFO_V1 (uint1int4eq );
220
+ PG_FUNCTION_INFO_V1 (int4uint1eq );
217
221
218
222
/**
219
223
* This function implements the "equal" (=) operator for the uint1 datatype.
@@ -743,6 +747,7 @@ PG_FUNCTION_INFO_V1(uint2le);
743
747
PG_FUNCTION_INFO_V1 (uint2gt );
744
748
PG_FUNCTION_INFO_V1 (uint2ge );
745
749
PG_FUNCTION_INFO_V1 (uint2int4eq );
750
+ PG_FUNCTION_INFO_V1 (int4uint2eq );
746
751
747
752
/**
748
753
* This function implements the "equal" (=) operator for the uint2 datatype.
@@ -2029,8 +2034,12 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
2029
2034
double (* convert_stats )(Datum ))
2030
2035
{
2031
2036
double hist_selec ;
2037
+ #if PG_VERSION_NUM < 100000
2032
2038
Datum * values ;
2033
2039
int nvalues ;
2040
+ #else
2041
+ AttStatsSlot sslot ;
2042
+ #endif
2034
2043
2035
2044
hist_selec = 0.0 ;
2036
2045
@@ -2045,13 +2054,29 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
2045
2054
* the reverse way if isgt is TRUE.
2046
2055
*/
2047
2056
if (HeapTupleIsValid (vardata -> statsTuple ) &&
2057
+ #if PG_VERSION_NUM < 90000
2058
+ get_attstatsslot (vardata -> statsTuple , vardata -> atttype ,
2059
+ vardata -> atttypmod , STATISTIC_KIND_HISTOGRAM ,
2060
+ InvalidOid ,
2061
+ & values , & nvalues , NULL , NULL )
2062
+ #elif PG_VERSION_NUM < 100000
2048
2063
get_attstatsslot (vardata -> statsTuple , vardata -> atttype ,
2049
2064
vardata -> atttypmod , STATISTIC_KIND_HISTOGRAM ,
2050
2065
InvalidOid ,
2051
2066
NULL , /* Added for postgresql 9 compatibality */
2052
- & values , & nvalues , NULL , NULL ))
2067
+ & values , & nvalues , NULL , NULL )
2068
+ #else
2069
+ get_attstatsslot (& sslot ,
2070
+ vardata -> statsTuple , vardata -> atttype ,
2071
+ vardata -> atttypmod , STATISTIC_KIND_HISTOGRAM )
2072
+ #endif
2073
+ )
2053
2074
{
2054
- if (nvalues > 1 ) {
2075
+ if (
2076
+ #if PG_VERSION_NUM >= 100000
2077
+ sslot .
2078
+ #endif
2079
+ nvalues > 1 ) {
2055
2080
/*
2056
2081
* Use binary search to find proper location, ie, the first slot
2057
2082
* at which the comparison fails. (If the given operator isn't
@@ -2061,13 +2086,21 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
2061
2086
*/
2062
2087
double histfrac ;
2063
2088
int lobound = 0 ; /* first possible slot to search */
2064
- int hibound = nvalues ; /* last+1 slot to search */
2089
+ int hibound =
2090
+ #if PG_VERSION_NUM >= 100000
2091
+ sslot .
2092
+ #endif
2093
+ nvalues ; /* last+1 slot to search */
2065
2094
2066
2095
while (lobound < hibound ) {
2067
2096
int probe = (lobound + hibound ) / 2 ;
2068
2097
bool ltcmp ;
2069
2098
2070
- ltcmp = DatumGetBool (FunctionCall2 (opproc , values [probe ], constval ));
2099
+ ltcmp = DatumGetBool (FunctionCall2 (opproc ,
2100
+ #if PG_VERSION_NUM >= 100000
2101
+ sslot .
2102
+ #endif
2103
+ values [probe ], constval ));
2071
2104
if (isgt )
2072
2105
ltcmp = !ltcmp ;
2073
2106
@@ -2077,7 +2110,11 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
2077
2110
hibound = probe ;
2078
2111
}
2079
2112
2080
- if (lobound >= nvalues ) {
2113
+ if (lobound >=
2114
+ #if PG_VERSION_NUM >= 100000
2115
+ sslot .
2116
+ #endif
2117
+ nvalues ) {
2081
2118
/* Constant is above upper histogram boundary. */
2082
2119
histfrac = 1.0 ;
2083
2120
}
@@ -2096,8 +2133,16 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
2096
2133
*/
2097
2134
2098
2135
val = (* convert_value )(constval );
2099
- low = (* convert_stats )(values [i - 1 ]);
2100
- high = (* convert_stats )(values [i ]);
2136
+ low = (* convert_stats )(
2137
+ #if PG_VERSION_NUM >= 100000
2138
+ sslot .
2139
+ #endif
2140
+ values [i - 1 ]);
2141
+ high = (* convert_stats )(
2142
+ #if PG_VERSION_NUM >= 100000
2143
+ sslot .
2144
+ #endif
2145
+ values [i ]);
2101
2146
2102
2147
if (high <= low )
2103
2148
binfrac = 0.5 ; /* cope if bin boundaries appear identical */
@@ -2124,7 +2169,11 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
2124
2169
* binfrac partial bin below the constant.
2125
2170
*/
2126
2171
histfrac = (double ) (i - 1 ) + binfrac ;
2127
- histfrac /= (double ) (nvalues - 1 );
2172
+ histfrac /= (double ) (
2173
+ #if PG_VERSION_NUM >= 100000
2174
+ sslot .
2175
+ #endif
2176
+ nvalues - 1 );
2128
2177
}
2129
2178
2130
2179
/*
@@ -2145,7 +2194,11 @@ uint_histogram_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
2145
2194
else if (hist_selec > 0.9999 )
2146
2195
hist_selec = 0.9999 ;
2147
2196
}
2197
+ #if PG_VERSION_NUM < 100000
2148
2198
free_attstatsslot (vardata -> atttype , values , nvalues , NULL , 0 );
2199
+ #else
2200
+ free_attstatsslot (& sslot );
2201
+ #endif
2149
2202
}
2150
2203
return hist_selec ;
2151
2204
}
0 commit comments