Form_pg_attribute att = TupleDescAttr(tupDesc, attno - 1);
- cstate->domain_with_constraint[i] = DomainHasConstraints(att->atttypid);
+ cstate->domain_with_constraint[i] = DomainHasConstraints(att->atttypid, NULL);
}
}
defval = (Expr *) build_column_default(rel, attribute->attnum);
/* Build CoerceToDomain(NULL) expression if needed */
- has_domain_constraints = DomainHasConstraints(attribute->atttypid);
+ has_domain_constraints = DomainHasConstraints(attribute->atttypid, NULL);
if (!defval && has_domain_constraints)
{
Oid baseTypeId;
{
CoerceToDomain *d = (CoerceToDomain *) expr;
- if (DomainHasConstraints(d->resulttype))
+ if (DomainHasConstraints(d->resulttype, NULL))
return true;
expr = (Node *) d->arg;
}
scratch.d.jsonexpr_coercion.exists_cast_to_int = exists_coerce &&
getBaseType(returning->typid) == INT4OID;
scratch.d.jsonexpr_coercion.exists_check_domain = exists_coerce &&
- DomainHasConstraints(returning->typid);
+ DomainHasConstraints(returning->typid, NULL);
ExprEvalPushStep(state, &scratch);
}
arg = eval_const_expressions_mutator((Node *) cdomain->arg,
context);
if (context->estimate ||
- !DomainHasConstraints(cdomain->resulttype))
+ !DomainHasConstraints(cdomain->resulttype, NULL))
{
/* Record dependency, if this isn't estimation mode */
if (context->root && !context->estimate)
if (jsexpr->returning->typid != TEXTOID)
{
if (get_typtype(jsexpr->returning->typid) == TYPTYPE_DOMAIN &&
- DomainHasConstraints(jsexpr->returning->typid))
+ DomainHasConstraints(jsexpr->returning->typid, NULL))
jsexpr->use_json_coercion = true;
else
jsexpr->use_io_coercion = true;
/*
* DomainHasConstraints --- utility routine to check if a domain has constraints
*
+ * Returns true if the domain has any constraints at all. If has_volatile
+ * is not NULL, also checks whether any CHECK constraint contains a volatile
+ * expression and sets *has_volatile accordingly.
+ *
* This is defined to return false, not fail, if type is not a domain.
*/
bool
-DomainHasConstraints(Oid type_id)
+DomainHasConstraints(Oid type_id, bool *has_volatile)
{
TypeCacheEntry *typentry;
*/
typentry = lookup_type_cache(type_id, TYPECACHE_DOMAIN_CONSTR_INFO);
- return (typentry->domainData != NULL);
+ if (typentry->domainData == NULL)
+ return false;
+
+ if (has_volatile)
+ {
+ *has_volatile = false;
+
+ foreach_node(DomainConstraintState, constrstate,
+ typentry->domainData->constraints)
+ {
+ if (constrstate->constrainttype == DOM_CONSTRAINT_CHECK &&
+ contain_volatile_functions((Node *) constrstate->check_expr))
+ {
+ *has_volatile = true;
+ break;
+ }
+ }
+ }
+
+ return true;
}
extern void UpdateDomainConstraintRef(DomainConstraintRef *ref);
-extern bool DomainHasConstraints(Oid type_id);
+extern bool DomainHasConstraints(Oid type_id, bool *has_volatile);
extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod);