diff options
Diffstat (limited to '')
-rw-r--r-- | src/include/rewrite/prs2lock.h | 46 | ||||
-rw-r--r-- | src/include/rewrite/rewriteDefine.h | 44 | ||||
-rw-r--r-- | src/include/rewrite/rewriteHandler.h | 40 | ||||
-rw-r--r-- | src/include/rewrite/rewriteManip.h | 87 | ||||
-rw-r--r-- | src/include/rewrite/rewriteRemove.h | 21 | ||||
-rw-r--r-- | src/include/rewrite/rewriteSupport.h | 26 | ||||
-rw-r--r-- | src/include/rewrite/rowsecurity.h | 49 |
7 files changed, 313 insertions, 0 deletions
diff --git a/src/include/rewrite/prs2lock.h b/src/include/rewrite/prs2lock.h new file mode 100644 index 0000000..84ee6a5 --- /dev/null +++ b/src/include/rewrite/prs2lock.h @@ -0,0 +1,46 @@ +/*------------------------------------------------------------------------- + * + * prs2lock.h + * data structures for POSTGRES Rule System II (rewrite rules only) + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/prs2lock.h + * + *------------------------------------------------------------------------- + */ +#ifndef PRS2LOCK_H +#define PRS2LOCK_H + +#include "access/attnum.h" +#include "nodes/pg_list.h" + +/* + * RewriteRule - + * holds an info for a rewrite rule + * + */ +typedef struct RewriteRule +{ + Oid ruleId; + CmdType event; + Node *qual; + List *actions; + char enabled; + bool isInstead; +} RewriteRule; + +/* + * RuleLock - + * all rules that apply to a particular relation. Even though we only + * have the rewrite rule system left and these are not really "locks", + * the name is kept for historical reasons. + */ +typedef struct RuleLock +{ + int numLocks; + RewriteRule **rules; +} RuleLock; + +#endif /* PRS2LOCK_H */ diff --git a/src/include/rewrite/rewriteDefine.h b/src/include/rewrite/rewriteDefine.h new file mode 100644 index 0000000..c25733a --- /dev/null +++ b/src/include/rewrite/rewriteDefine.h @@ -0,0 +1,44 @@ +/*------------------------------------------------------------------------- + * + * rewriteDefine.h + * + * + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteDefine.h + * + *------------------------------------------------------------------------- + */ +#ifndef REWRITEDEFINE_H +#define REWRITEDEFINE_H + +#include "catalog/objectaddress.h" +#include "nodes/parsenodes.h" +#include "utils/relcache.h" + +#define RULE_FIRES_ON_ORIGIN 'O' +#define RULE_FIRES_ALWAYS 'A' +#define RULE_FIRES_ON_REPLICA 'R' +#define RULE_DISABLED 'D' + +extern ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString); + +extern ObjectAddress DefineQueryRewrite(const char *rulename, + Oid event_relid, + Node *event_qual, + CmdType event_type, + bool is_instead, + bool replace, + List *action); + +extern ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName, + const char *newName); + +extern void setRuleCheckAsUser(Node *node, Oid userid); + +extern void EnableDisableRule(Relation rel, const char *rulename, + char fires_when); + +#endif /* REWRITEDEFINE_H */ diff --git a/src/include/rewrite/rewriteHandler.h b/src/include/rewrite/rewriteHandler.h new file mode 100644 index 0000000..a18211f --- /dev/null +++ b/src/include/rewrite/rewriteHandler.h @@ -0,0 +1,40 @@ +/*------------------------------------------------------------------------- + * + * rewriteHandler.h + * External interface to query rewriter. + * + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteHandler.h + * + *------------------------------------------------------------------------- + */ +#ifndef REWRITEHANDLER_H +#define REWRITEHANDLER_H + +#include "nodes/parsenodes.h" +#include "utils/relcache.h" + +extern List *QueryRewrite(Query *parsetree); +extern void AcquireRewriteLocks(Query *parsetree, + bool forExecute, + bool forUpdatePushedDown); + +extern Node *build_column_default(Relation rel, int attrno); +extern void rewriteTargetListUD(Query *parsetree, RangeTblEntry *target_rte, + Relation target_relation); + +extern void fill_extraUpdatedCols(RangeTblEntry *target_rte, + Relation target_relation); + +extern Query *get_view_query(Relation view); +extern const char *view_query_is_auto_updatable(Query *viewquery, + bool check_cols); +extern int relation_is_updatable(Oid reloid, + List *outer_reloids, + bool include_triggers, + Bitmapset *include_cols); + +#endif /* REWRITEHANDLER_H */ diff --git a/src/include/rewrite/rewriteManip.h b/src/include/rewrite/rewriteManip.h new file mode 100644 index 0000000..5ece816 --- /dev/null +++ b/src/include/rewrite/rewriteManip.h @@ -0,0 +1,87 @@ +/*------------------------------------------------------------------------- + * + * rewriteManip.h + * Querytree manipulation subroutines for query rewriter. + * + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteManip.h + * + *------------------------------------------------------------------------- + */ +#ifndef REWRITEMANIP_H +#define REWRITEMANIP_H + +#include "nodes/parsenodes.h" + +struct AttrMap; /* avoid including attmap.h here */ + + +typedef struct replace_rte_variables_context replace_rte_variables_context; + +typedef Node *(*replace_rte_variables_callback) (Var *var, + replace_rte_variables_context *context); + +struct replace_rte_variables_context +{ + replace_rte_variables_callback callback; /* callback function */ + void *callback_arg; /* context data for callback function */ + int target_varno; /* RTE index to search for */ + int sublevels_up; /* (current) nesting depth */ + bool inserted_sublink; /* have we inserted a SubLink? */ +}; + +typedef enum ReplaceVarsNoMatchOption +{ + REPLACEVARS_REPORT_ERROR, /* throw error if no match */ + REPLACEVARS_CHANGE_VARNO, /* change the Var's varno, nothing else */ + REPLACEVARS_SUBSTITUTE_NULL /* replace with a NULL Const */ +} ReplaceVarsNoMatchOption; + + +extern void OffsetVarNodes(Node *node, int offset, int sublevels_up); +extern void ChangeVarNodes(Node *node, int old_varno, int new_varno, + int sublevels_up); +extern void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, + int min_sublevels_up); +extern void IncrementVarSublevelsUp_rtable(List *rtable, + int delta_sublevels_up, int min_sublevels_up); + +extern bool rangeTableEntry_used(Node *node, int rt_index, + int sublevels_up); + +extern Query *getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr); + +extern void AddQual(Query *parsetree, Node *qual); +extern void AddInvertedQual(Query *parsetree, Node *qual); + +extern bool contain_aggs_of_level(Node *node, int levelsup); +extern int locate_agg_of_level(Node *node, int levelsup); +extern bool contain_windowfuncs(Node *node); +extern int locate_windowfunc(Node *node); +extern bool checkExprHasSubLink(Node *node); + +extern Node *replace_rte_variables(Node *node, + int target_varno, int sublevels_up, + replace_rte_variables_callback callback, + void *callback_arg, + bool *outer_hasSubLinks); +extern Node *replace_rte_variables_mutator(Node *node, + replace_rte_variables_context *context); + +extern Node *map_variable_attnos(Node *node, + int target_varno, int sublevels_up, + const struct AttrMap *attno_map, + Oid to_rowtype, bool *found_whole_row); + +extern Node *ReplaceVarsFromTargetList(Node *node, + int target_varno, int sublevels_up, + RangeTblEntry *target_rte, + List *targetlist, + ReplaceVarsNoMatchOption nomatch_option, + int nomatch_varno, + bool *outer_hasSubLinks); + +#endif /* REWRITEMANIP_H */ diff --git a/src/include/rewrite/rewriteRemove.h b/src/include/rewrite/rewriteRemove.h new file mode 100644 index 0000000..f07896c --- /dev/null +++ b/src/include/rewrite/rewriteRemove.h @@ -0,0 +1,21 @@ +/*------------------------------------------------------------------------- + * + * rewriteRemove.h + * + * + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteRemove.h + * + *------------------------------------------------------------------------- + */ +#ifndef REWRITEREMOVE_H +#define REWRITEREMOVE_H + +#include "nodes/parsenodes.h" + +extern void RemoveRewriteRuleById(Oid ruleOid); + +#endif /* REWRITEREMOVE_H */ diff --git a/src/include/rewrite/rewriteSupport.h b/src/include/rewrite/rewriteSupport.h new file mode 100644 index 0000000..f58f356 --- /dev/null +++ b/src/include/rewrite/rewriteSupport.h @@ -0,0 +1,26 @@ +/*------------------------------------------------------------------------- + * + * rewriteSupport.h + * + * + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteSupport.h + * + *------------------------------------------------------------------------- + */ +#ifndef REWRITESUPPORT_H +#define REWRITESUPPORT_H + +/* The ON SELECT rule of a view is always named this: */ +#define ViewSelectRuleName "_RETURN" + +extern bool IsDefinedRewriteRule(Oid owningRel, const char *ruleName); + +extern void SetRelationRuleStatus(Oid relationId, bool relHasRules); + +extern Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok); + +#endif /* REWRITESUPPORT_H */ diff --git a/src/include/rewrite/rowsecurity.h b/src/include/rewrite/rowsecurity.h new file mode 100644 index 0000000..2e0bac5 --- /dev/null +++ b/src/include/rewrite/rowsecurity.h @@ -0,0 +1,49 @@ +/* ------------------------------------------------------------------------- + * + * rowsecurity.h + * + * prototypes for rewrite/rowsecurity.c and the structures for managing + * the row security policies for relations in relcache. + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * ------------------------------------------------------------------------- + */ +#ifndef ROWSECURITY_H +#define ROWSECURITY_H + +#include "nodes/parsenodes.h" +#include "utils/array.h" +#include "utils/relcache.h" + +typedef struct RowSecurityPolicy +{ + char *policy_name; /* Name of the policy */ + char polcmd; /* Type of command policy is for */ + ArrayType *roles; /* Array of roles policy is for */ + bool permissive; /* restrictive or permissive policy */ + Expr *qual; /* Expression to filter rows */ + Expr *with_check_qual; /* Expression to limit rows allowed */ + bool hassublinks; /* If either expression has sublinks */ +} RowSecurityPolicy; + +typedef struct RowSecurityDesc +{ + MemoryContext rscxt; /* row security memory context */ + List *policies; /* list of row security policies */ +} RowSecurityDesc; + +typedef List *(*row_security_policy_hook_type) (CmdType cmdtype, + Relation relation); + +extern PGDLLIMPORT row_security_policy_hook_type row_security_policy_hook_permissive; + +extern PGDLLIMPORT row_security_policy_hook_type row_security_policy_hook_restrictive; + +extern void get_row_security_policies(Query *root, + RangeTblEntry *rte, int rt_index, + List **securityQuals, List **withCheckOptions, + bool *hasRowSecurity, bool *hasSubLinks); + +#endif /* ROWSECURITY_H */ |