![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
OID lookup, constants cache, and utility functions for ProvSQL. More...
#include "postgres.h"#include "access/htup_details.h"#include "miscadmin.h"#include "catalog/namespace.h"#include "catalog/pg_type.h"#include "catalog/pg_enum.h"#include "catalog/pg_namespace.h"#include "catalog/pg_operator.h"#include "fmgr.h"#include "nodes/value.h"#include "parser/parse_func.h"#include "utils/syscache.h"#include "utils/lsyscache.h"#include "provsql_utils.h"
Go to the source code of this file.
Macros | |
| #define | CheckOid(o) |
| #define | GET_GATE_TYPE_OID(x) |
Functions | |
| static Oid | binary_oper_exact (List *opname, Oid arg1, Oid arg2) |
| Look up an exactly matching binary operator OID. | |
| Oid | find_equality_operator (Oid ltypeId, Oid rtypeId) |
| Find the equality operator OID for two given types. | |
| static Oid | get_func_oid (char *s) |
Return the OID of a globally qualified function named s. | |
| static Oid | get_provsql_func_oid (char *s) |
Return the OID of a provsql-schema function named s. | |
| static void | OperatorGet (const char *operatorName, Oid operatorNamespace, Oid leftObjectId, Oid rightObjectId, Oid *operatorObjectId, Oid *functionObjectId) |
| Retrieve operator and function OIDs for a named operator. | |
| static Oid | get_enum_oid (Oid enumtypoid, const char *label) |
| Return the OID of a specific enum label within an enum type. | |
| static constants_t | initialize_constants (bool failure_if_not_possible) |
Query the system catalogs to populate a fresh constants_t. | |
| constants_t | get_constants (bool failure_if_not_possible) |
| Retrieve the cached OID constants for the current database. | |
| Datum | reset_constants_cache (PG_FUNCTION_ARGS) |
| SQL function to invalidate the OID constants cache. | |
Variables | |
| const char * | gate_type_name [] |
| Names of gate types. | |
| database_constants_t * | constants_cache |
| Per-database OID constants cache (sorted by database OID) | |
| unsigned | constants_cache_len =0 |
Number of valid entries in constants_cache. | |
OID lookup, constants cache, and utility functions for ProvSQL.
Implements the functions declared in provsql_utils.h:
get_constants(): retrieves and caches per-database OIDs for all ProvSQL types, functions, and operators.find_equality_operator(): looks up the = operator OID for a given pair of types.The constants cache is a sorted, dynamically-grown array of database_constants_t records (one per PostgreSQL database OID) stored in process-local memory and searched with binary search. The reset_constants_cache() SQL function forces a cache invalidation for the current database, which is needed after ALTER EXTENSION.
Several helper functions (get_func_oid, get_provsql_func_oid, OperatorGet, get_enum_oid, binary_oper_exact) are adapted from PostgreSQL source code that is not exported as a public API.
Definition in file provsql_utils.c.
| #define CheckOid | ( | o | ) |
| #define GET_GATE_TYPE_OID | ( | x | ) |
|
static |
Look up an exactly matching binary operator OID.
Copied and adapted from parse_oper.c (PostgreSQL internals, not exported). Returns InvalidOid if no exact match exists.
| opname | Qualified operator name (a List of String nodes). |
| arg1 | OID of the left operand type. |
| arg2 | OID of the right operand type. |
InvalidOid. Definition at line 69 of file provsql_utils.c.

| Oid find_equality_operator | ( | Oid | ltypeId, |
| Oid | rtypeId | ||
| ) |
Find the equality operator OID for two given types.
Searches pg_operator for the = operator that accepts ltypeId on the left and rtypeId on the right.
| ltypeId | OID of the left operand type. |
| rtypeId | OID of the right operand type. |
InvalidOid if none is found. Definition at line 109 of file provsql_utils.c.


| constants_t get_constants | ( | bool | failure_if_not_possible | ) |
Retrieve the cached OID constants for the current database.
On first call (or after a cache miss) this function looks up the OIDs of all ProvSQL-specific types, functions, and operators in the system catalogs and stores them in a per-database cache. Subsequent calls return the cached values without touching the catalogs.
| failure_if_not_possible | If true, call provsql_error when the ProvSQL schema cannot be found (e.g. the extension is not installed in the current database). If false, return a constants_t with ok==false instead of aborting. |
constants_t whose ok field is true on success. Definition at line 425 of file provsql_utils.c.


|
static |
Return the OID of a specific enum label within an enum type.
| enumtypoid | OID of the enum type (e.g. provenance_gate). |
| label | C-string label of the enum value to look up. |
pg_enum row. Definition at line 253 of file provsql_utils.c.
|
static |
Return the OID of a globally qualified function named s.
Looks up the function in the default search path. Returns 0 if no matching function is found.
| s | Function name (unqualified). |
Definition at line 149 of file provsql_utils.c.

|
static |
Return the OID of a provsql-schema function named s.
Looks up the function in the provsql schema. Returns 0 if not found.
| s | Function name (without schema prefix). |
Definition at line 175 of file provsql_utils.c.

|
static |
Query the system catalogs to populate a fresh constants_t.
Performs all OID lookups required by ProvSQL in a single pass through the system caches. The CheckOid() macro aborts (or returns early, depending on failure_if_not_possible) if any OID resolves to InvalidOid.
| failure_if_not_possible | If true, raise a provsql_error when any OID cannot be resolved. If false, return a constants_t with ok==false instead. |
constants_t on success, or ok==false on failure when failure_if_not_possible is false. Abort or return early if OID field o of constants is invalid.
Look up the OID of provenance_gate enum value x and store it in constants.
Definition at line 288 of file provsql_utils.c.


|
static |
Retrieve operator and function OIDs for a named operator.
Copied and adapted from pg_operator.c (PostgreSQL internals, not exported). Looks up the operator by name, namespace, and operand types in the system cache.
| operatorName | Operator symbol string (e.g. "<>"). |
| operatorNamespace | OID of the schema containing the operator. |
| leftObjectId | OID of the left operand type. |
| rightObjectId | OID of the right operand type. |
| operatorObjectId | Output: OID of the operator, or 0 if not found. |
| functionObjectId | Output: OID of the underlying function, or 0. |
Definition at line 207 of file provsql_utils.c.

| Datum reset_constants_cache | ( | PG_FUNCTION_ARGS | ) |
SQL function to invalidate the OID constants cache.
Forces a fresh OID lookup for the current database on the next call to get_constants(). Must be called after ALTER EXTENSION provsql UPDATE to ensure cached OIDs are refreshed.
Definition at line 466 of file provsql_utils.c.

| database_constants_t* constants_cache |
Per-database OID constants cache (sorted by database OID)
Definition at line 422 of file provsql_utils.c.
| unsigned constants_cache_len =0 |
Number of valid entries in constants_cache.
Definition at line 423 of file provsql_utils.c.
| const char* gate_type_name[] |
Names of gate types.
Definition at line 38 of file provsql_utils.c.