Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4c08a0f

Browse files
jianhe-funCommitfest Bot
authored and
Commitfest Bot
committed
add function DomainHaveVolatileConstraints
the signature is: extern bool DomainHaveVolatileConstraints(Oid type_id, bool *have_volatile); Returns true if the Domain has any constraints. If you want check this domain have any volatile check constraints, make sure have_volatile is not NULL. discussion: https://postgr.es/m/CACJufxE_+iZBR1i49k_AHigppPwLTJi6km8NOsC7FWvKdEmmXg@mail.gmail.com
1 parent d143a11 commit 4c08a0f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/backend/utils/cache/typcache.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,46 @@ DomainHasConstraints(Oid type_id)
15001500
}
15011501

15021502

1503+
/*
1504+
* Check whether a domain has any constraints, and determine if any of those
1505+
* constraints contain volatile expressions.
1506+
*
1507+
* To detect volatile expressions within domain check constraints, ensure that
1508+
* have_volatile is not NULL. If have_volatile is NULL, the behavior is
1509+
* equivalent to that of DomainHasConstraints.
1510+
*/
1511+
bool
1512+
DomainHaveVolatileConstraints(Oid type_id, bool *have_volatile)
1513+
{
1514+
TypeCacheEntry *typentry;
1515+
1516+
/*
1517+
* Note: a side effect is to cause the typcache's domain data to become
1518+
* valid. This is fine since we'll likely need it soon if there is any.
1519+
*/
1520+
typentry = lookup_type_cache(type_id, TYPECACHE_DOMAIN_CONSTR_INFO);
1521+
1522+
if (typentry->domainData != NULL)
1523+
{
1524+
ListCell *lc;
1525+
1526+
foreach(lc, typentry->domainData->constraints)
1527+
{
1528+
DomainConstraintState *r = (DomainConstraintState *) lfirst(lc);
1529+
1530+
if (r->constrainttype == DOM_CONSTRAINT_CHECK &&
1531+
contain_volatile_functions((Node *) r->check_expr))
1532+
{
1533+
if (have_volatile)
1534+
*have_volatile = true;
1535+
break;
1536+
}
1537+
}
1538+
return true;
1539+
}
1540+
return false;
1541+
}
1542+
15031543
/*
15041544
* array_element_has_equality and friends are helper routines to check
15051545
* whether we should believe that array_eq and related functions will work

src/include/utils/typcache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ extern void InitDomainConstraintRef(Oid type_id, DomainConstraintRef *ref,
184184
extern void UpdateDomainConstraintRef(DomainConstraintRef *ref);
185185

186186
extern bool DomainHasConstraints(Oid type_id);
187+
extern bool DomainHaveVolatileConstraints(Oid type_id, bool *have_volatile);
187188

188189
extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod);
189190

0 commit comments

Comments
 (0)