| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * queryenvironment.h |
| 4 | * Access to functions to mutate the query environment and retrieve the |
| 5 | * actual data related to entries (if any). |
| 6 | * |
| 7 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 8 | * Portions Copyright (c) 1994, Regents of the University of California |
| 9 | * |
| 10 | * src/include/utils/queryenvironment.h |
| 11 | * |
| 12 | *------------------------------------------------------------------------- |
| 13 | */ |
| 14 | #ifndef QUERYENVIRONMENT_H |
| 15 | #define QUERYENVIRONMENT_H |
| 16 | |
| 17 | #include "access/tupdesc.h" |
| 18 | |
| 19 | |
| 20 | typedef enum EphemeralNameRelationType |
| 21 | { |
| 22 | ENR_NAMED_TUPLESTORE /* named tuplestore relation; e.g., deltas */ |
| 23 | } EphemeralNameRelationType; |
| 24 | |
| 25 | /* |
| 26 | * Some ephemeral named relations must match some relation (e.g., trigger |
| 27 | * transition tables), so to properly handle cached plans and DDL, we should |
| 28 | * carry the OID of that relation. In other cases an ENR might be independent |
| 29 | * of any relation which is stored in the system catalogs, so we need to be |
| 30 | * able to directly store the TupleDesc. We never need both. |
| 31 | */ |
| 32 | typedef struct EphemeralNamedRelationMetadataData |
| 33 | { |
| 34 | char *name; /* name used to identify the relation */ |
| 35 | |
| 36 | /* only one of the next two fields should be used */ |
| 37 | Oid reliddesc; /* oid of relation to get tupdesc */ |
| 38 | TupleDesc tupdesc; /* description of result rows */ |
| 39 | |
| 40 | EphemeralNameRelationType enrtype; /* to identify type of relation */ |
| 41 | double enrtuples; /* estimated number of tuples */ |
| 42 | } EphemeralNamedRelationMetadataData; |
| 43 | |
| 44 | typedef EphemeralNamedRelationMetadataData *EphemeralNamedRelationMetadata; |
| 45 | |
| 46 | /* |
| 47 | * Ephemeral Named Relation data; used for parsing named relations not in the |
| 48 | * catalog, like transition tables in AFTER triggers. |
| 49 | */ |
| 50 | typedef struct EphemeralNamedRelationData |
| 51 | { |
| 52 | EphemeralNamedRelationMetadataData md; |
| 53 | void *reldata; /* structure for execution-time access to data */ |
| 54 | } EphemeralNamedRelationData; |
| 55 | |
| 56 | typedef EphemeralNamedRelationData *EphemeralNamedRelation; |
| 57 | |
| 58 | /* |
| 59 | * This is an opaque structure outside of queryenvironment.c itself. The |
| 60 | * intention is to be able to change the implementation or add new context |
| 61 | * features without needing to change existing code for use of existing |
| 62 | * features. |
| 63 | */ |
| 64 | typedef struct QueryEnvironment QueryEnvironment; |
| 65 | |
| 66 | |
| 67 | extern QueryEnvironment *create_queryEnv(void); |
| 68 | extern EphemeralNamedRelationMetadata get_visible_ENR_metadata(QueryEnvironment *queryEnv, const char *refname); |
| 69 | extern void register_ENR(QueryEnvironment *queryEnv, EphemeralNamedRelation enr); |
| 70 | extern void unregister_ENR(QueryEnvironment *queryEnv, const char *name); |
| 71 | extern EphemeralNamedRelation get_ENR(QueryEnvironment *queryEnv, const char *name); |
| 72 | extern TupleDesc ENRMetadataGetTupDesc(EphemeralNamedRelationMetadata enrmd); |
| 73 | |
| 74 | #endif /* QUERYENVIRONMENT_H */ |
| 75 | |