This commit is contained in:
blue-lemon0104
2026-04-07 13:35:22 +08:00
commit 0120fa9ce3
1530 changed files with 424864 additions and 0 deletions

46
db_include/rewrite/prs2lock.h Executable file
View File

@@ -0,0 +1,46 @@
/*-------------------------------------------------------------------------
*
* prs2lock.h
* data structures for POSTGRES Rule System II (rewrite rules only)
*
* Portions Copyright (c) 1996-2021, 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 */

View File

@@ -0,0 +1,44 @@
/*-------------------------------------------------------------------------
*
* rewriteDefine.h
*
*
*
* Portions Copyright (c) 1996-2021, 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 */

View File

@@ -0,0 +1,38 @@
/*-------------------------------------------------------------------------
*
* rewriteHandler.h
* External interface to query rewriter.
*
*
* Portions Copyright (c) 1996-2021, 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 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 */

View File

@@ -0,0 +1,87 @@
/*-------------------------------------------------------------------------
*
* rewriteManip.h
* Querytree manipulation subroutines for query rewriter.
*
*
* Portions Copyright (c) 1996-2021, 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 */

View File

@@ -0,0 +1,21 @@
/*-------------------------------------------------------------------------
*
* rewriteRemove.h
*
*
*
* Portions Copyright (c) 1996-2021, 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 */

View File

@@ -0,0 +1,21 @@
/*-------------------------------------------------------------------------
*
* rewriteSearchCycle.h
* Support for rewriting SEARCH and CYCLE clauses.
*
*
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/rewrite/rewriteSearchCycle.h
*
*-------------------------------------------------------------------------
*/
#ifndef REWRITESEARCHCYCLE_H
#define REWRITESEARCHCYCLE_H
#include "nodes/parsenodes.h"
extern CommonTableExpr *rewriteSearchAndCycle(CommonTableExpr *cte);
#endif /* REWRITESEARCHCYCLE_H */

View File

@@ -0,0 +1,26 @@
/*-------------------------------------------------------------------------
*
* rewriteSupport.h
*
*
*
* Portions Copyright (c) 1996-2021, 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 */

View File

@@ -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-2021, 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 */