Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/backend/catalog/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
InvokePreAddConstraintsHook_type InvokePreAddConstraintsHook = NULL;
transform_check_constraint_expr_hook_type transform_check_constraint_expr_hook = NULL;
drop_relation_refcnt_hook_type drop_relation_refcnt_hook = NULL;
persisted_col_hook_type persisted_col_hook = NULL;

/* Potentially set by pg_upgrade_support functions */
Oid binary_upgrade_next_heap_pg_class_oid = InvalidOid;
Expand Down Expand Up @@ -3498,12 +3499,16 @@ cookDefault(ParseState *pstate,
/* Disallow refs to other generated columns */
check_nested_generated(pstate, expr);

/* Disallow mutable functions */
if (contain_mutable_functions_after_planning((Expr *) expr))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("generation expression is not immutable")));

/* hook to handle stable func in computed columns */
if (!persisted_col_hook ||
persisted_col_hook(expr) != NULL)
{
/* Disallow mutable functions */
if (contain_mutable_functions_after_planning((Expr *) expr))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("generation expression is not immutable")));
}
/* Check security of expressions for virtual generated column */
if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
check_virtual_generated_security(pstate, expr);
Expand Down
9 changes: 9 additions & 0 deletions src/backend/optimizer/plan/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ bool enable_distinct_reordering = true;

/* Hook for plugins to get control in planner() */
planner_hook_type planner_hook = NULL;
/* Hook for persisted computed column re-evaluation in subquery_planner */
persisted_col_rewrite_hook_type persisted_col_rewrite_hook = NULL;
/* Hook for plugins to transform qual nodes in planner */
planner_node_transformer_hook_type planner_node_transformer_hook = NULL;
/* Hook for plugins to get control when grouping_planner() plans upper rels */
Expand Down Expand Up @@ -788,6 +790,13 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
*/
pull_up_subqueries(root);

/*
* Hook for persisted computed column re-evaluation when session GUCs
* differ from defaults.
*/
if (persisted_col_rewrite_hook)
parse = root->parse = persisted_col_rewrite_hook(root->parse);

/*
* If this is a simple UNION ALL query, flatten it into an appendrel. We
* do this now because it requires applying pull_up_subqueries to the leaf
Expand Down
3 changes: 3 additions & 0 deletions src/include/catalog/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,7 @@ extern PGDLLEXPORT transform_check_constraint_expr_hook_type transform_check_con
typedef void (*drop_relation_refcnt_hook_type) (Relation rel);
extern PGDLLEXPORT drop_relation_refcnt_hook_type drop_relation_refcnt_hook;

typedef Node* (*persisted_col_hook_type)(Node *expr);
extern PGDLLEXPORT persisted_col_hook_type persisted_col_hook;

#endif /* HEAP_H */
4 changes: 4 additions & 0 deletions src/include/optimizer/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ typedef PlannedStmt *(*planner_hook_type) (Query *parse,
ParamListInfo boundParams);
extern PGDLLEXPORT planner_hook_type planner_hook;

/* Hook for persisted computed column re-evaluation in subquery_planner */
typedef Query* (*persisted_col_rewrite_hook_type)(Query *parse);
extern PGDLLEXPORT persisted_col_rewrite_hook_type persisted_col_rewrite_hook;

/* Hook for plugins to transform qual nodes in planner */
typedef Node* (*planner_node_transformer_hook_type) (PlannerInfo *root,
Node *expr,
Expand Down
Loading