51#include "catalog/pg_enum.h"
52#include "utils/catcache.h"
53#include "utils/fmgroids.h"
54#include "utils/syscache.h"
55#include "utils/lsyscache.h"
56#include "access/htup_details.h"
86 return DatumGetInt32(OidFunctionCall2(F_ENUM_CMP, a, b));
90explicit MinMax(Oid enum_type_oid,
bool reverse_)
93 CatCList *list = SearchSysCacheList1(ENUMTYPOIDNAME, ObjectIdGetDatum(
enum_oid));
94 if(list->n_members == 0) {
95 ReleaseCatCacheList(list);
96 throw std::runtime_error(
"MinMax: enum type has no members");
98 Oid b_oid = InvalidOid, t_oid = InvalidOid;
99 float4 b_order = 0, t_order = 0;
100 for(
int i = 0; i < list->n_members; ++i) {
101 HeapTuple tup = &list->members[i]->tuple;
102 Form_pg_enum en = (Form_pg_enum) GETSTRUCT(tup);
103#if PG_VERSION_NUM >= 120000
104 Oid label_oid = en->oid;
106 Oid label_oid = HeapTupleGetOid(tup);
108 if(i == 0 || en->enumsortorder < b_order) {
109 b_order = en->enumsortorder;
112 if(i == 0 || en->enumsortorder > t_order) {
113 t_order = en->enumsortorder;
117 ReleaseCatCacheList(list);
132 if(v.empty())
return zero();
134 for(
size_t i = 1; i < v.size(); ++i) {
142 if(v.empty())
return one();
144 for(
size_t i = 1; i < v.size(); ++i) {
158 bool x_le_S_y =
reverse ? (c <= 0) : (c >= 0);
159 return x_le_S_y ?
zero() : x;
Abstract semiring interface for provenance evaluation.
virtual value_type plus(const std::vector< value_type > &v) const override
Apply the additive operation to a list of values.
virtual value_type delta(value_type x) const override
Apply the operator.
virtual value_type monus(value_type x, value_type y) const override
Apply the monus (m-semiring difference) operation.
virtual bool absorptive() const override
Return true if this semiring is absorptive ( for all ).
virtual value_type one() const override
Return the multiplicative identity .
MinMax(Oid enum_type_oid, bool reverse_)
virtual value_type times(const std::vector< value_type > &v) const override
Apply the multiplicative operation to a list of values.
static int enum_cmp_datum(Datum a, Datum b)
virtual value_type zero() const override
Return the additive identity .
Datum parse_leaf(const char *str) const
Parse an enum text literal to a Datum.
virtual bool compatibleWithBooleanRewrite() const override
No semiring homomorphism BoolFunc(Y) →+* MinMax exists (the enum-min / enum-max structure cannot mode...
Abstract base class for (m-)semirings.