forked from timescale/timescaledb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constraint.c
58 lines (51 loc) · 1.34 KB
/
constraint.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* This file and its contents are licensed under the Apache License 2.0.
* Please see the included NOTICE for copyright information and
* LICENSE-APACHE for a copy of the license.
*/
#include <postgres.h>
#include <access/genam.h>
#include <access/table.h>
#include <catalog/indexing.h>
#include <catalog/pg_constraint.h>
#include <utils/fmgroids.h>
#include "constraint.h"
/*
* Process constraints that belong to a given relation.
*
* Returns the number of constraints processed.
*/
int
ts_constraint_process(Oid relid, constraint_func process_func, void *ctx)
{
ScanKeyData skey;
Relation rel;
SysScanDesc scan;
HeapTuple htup;
bool should_continue = true;
int count = 0;
ScanKeyInit(&skey, Anum_pg_constraint_conrelid, BTEqualStrategyNumber, F_OIDEQ, relid);
rel = table_open(ConstraintRelationId, AccessShareLock);
scan = systable_beginscan(rel, ConstraintRelidTypidNameIndexId, true, NULL, 1, &skey);
while (HeapTupleIsValid(htup = systable_getnext(scan)) && should_continue)
{
switch (process_func(htup, ctx))
{
case CONSTR_PROCESSED:
count++;
break;
case CONSTR_PROCESSED_DONE:
count++;
should_continue = false;
break;
case CONSTR_IGNORED:
break;
case CONSTR_IGNORED_DONE:
should_continue = false;
break;
}
}
systable_endscan(scan);
table_close(rel, AccessShareLock);
return count;
}