Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita36a14c

Browse files
committed
Disable hooks while expression is parsing
1 parentbf826d2 commita36a14c

File tree

5 files changed

+46
-12
lines changed

5 files changed

+46
-12
lines changed

‎src/hooks.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ pathman_join_pathlist_hook(PlannerInfo *root,
6565
set_join_pathlist_next(root,joinrel,outerrel,
6666
innerrel,jointype,extra);
6767

68+
/* Hooks can be disabled */
69+
if (!hooks_enabled)
70+
return;
71+
6872
/* Check that both pg_pathman & RuntimeAppend nodes are enabled */
6973
if (!IsPathmanReady()|| !pg_pathman_enable_runtimeappend)
7074
return;
@@ -204,6 +208,10 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
204208
if (set_rel_pathlist_hook_next!=NULL)
205209
set_rel_pathlist_hook_next(root,rel,rti,rte);
206210

211+
/* Hooks can be disabled */
212+
if (!hooks_enabled)
213+
return;
214+
207215
/* Make sure that pg_pathman is ready */
208216
if (!IsPathmanReady())
209217
return;
@@ -484,6 +492,18 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
484492

485493
PG_TRY();
486494
{
495+
/* Hooks can be disabled */
496+
if (!hooks_enabled)
497+
{
498+
/* Invoke original hook if needed */
499+
if (planner_hook_next)
500+
result=planner_hook_next(parse,cursorOptions,boundParams);
501+
else
502+
result=standard_planner(parse,cursorOptions,boundParams);
503+
504+
returnresult;
505+
}
506+
487507
if (pathman_ready)
488508
{
489509
/* Increment relation tags refcount */
@@ -543,6 +563,10 @@ pathman_post_parse_analysis_hook(ParseState *pstate, Query *query)
543563
if (post_parse_analyze_hook_next)
544564
post_parse_analyze_hook_next(pstate,query);
545565

566+
/* Hooks can be disabled */
567+
if (!hooks_enabled)
568+
return;
569+
546570
/* We shouldn't do anything on BEGIN or SET ISOLATION LEVEL stmts */
547571
if (query->commandType==CMD_UTILITY&&
548572
(xact_is_transaction_stmt(query->utilityStmt)||
@@ -617,6 +641,10 @@ pathman_relcache_hook(Datum arg, Oid relid)
617641
if (!IsPathmanReady())
618642
return;
619643

644+
/* Hooks can be disabled */
645+
if (!hooks_enabled)
646+
return;
647+
620648
/* We shouldn't even consider special OIDs */
621649
if (relid<FirstNormalObjectId)
622650
return;

‎src/include/pathman.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
externOidpathman_config_relid;
8585
externOidpathman_config_params_relid;
8686

87+
/* Hooks enable state */
88+
externboolhooks_enabled;
89+
8790
/*
8891
* Just to clarify our intentions (return the corresponding relid).
8992
*/

‎src/init.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ validate_hash_constraint(const Expr *expr,
11351135

11361136
if (list_length(get_hash_expr->args)==2)
11371137
{
1138-
Node*first=linitial(get_hash_expr->args);/* arg #1: TYPE_HASH_PROC(VALUE) */
1138+
Node*first=linitial(get_hash_expr->args);/* arg #1: TYPE_HASH_PROC(EXPRESSION) */
11391139
Node*second=lsecond(get_hash_expr->args);/* arg #2: PARTITIONS_COUNT */
11401140
Const*cur_partition_hash;/* hash value for this partition */
11411141

@@ -1146,9 +1146,7 @@ validate_hash_constraint(const Expr *expr,
11461146

11471147
/* Check that function is indeed TYPE_HASH_PROC */
11481148
if (type_hash_proc_expr->funcid!=prel->hash_proc)
1149-
{
11501149
return false;
1151-
}
11521150

11531151
/* Check that PARTITIONS_COUNT is equal to total amount of partitions */
11541152
if (DatumGetUInt32(((Const*)second)->constvalue)!=PrelChildrenCount(prel))

‎src/partition_creation.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include"commands/tablecmds.h"
3030
#include"commands/tablespace.h"
3131
#include"miscadmin.h"
32+
#include"nodes/plannodes.h"
3233
#include"parser/parser.h"
3334
#include"parser/parse_func.h"
3435
#include"parser/parse_relation.h"
@@ -2053,7 +2054,7 @@ static bool location_cleaning_walker(Node *node, void *context)
20532054
returnraw_expression_tree_walker(node,location_cleaning_walker,context);
20542055
}
20552056

2056-
/* By given relation id and expression returnsquerynode */
2057+
/* By given relation id and expression returns node */
20572058
Node*
20582059
get_expression_node(Oidrelid,constchar*expr,boolanalyze)
20592060
{
@@ -2064,7 +2065,7 @@ get_expression_node(Oid relid, const char *expr, bool analyze)
20642065
*raw_node;
20652066
Query*query;
20662067
TargetEntry*target_entry;
2067-
post_parse_analyze_hook_typeorig_hook=NULL;
2068+
PlannedStmt*plan;
20682069

20692070
target_list= ((SelectStmt*)parsetree)->targetList;
20702071

@@ -2074,16 +2075,17 @@ get_expression_node(Oid relid, const char *expr, bool analyze)
20742075
returnraw_node;
20752076
}
20762077

2077-
//turn off parse hooks
2078-
orig_hook=post_parse_analyze_hook;
2079-
post_parse_analyze_hook=NULL;
2078+
/* We don't need pathman hooks on next stages */
2079+
hooks_enabled= false;
20802080

20812081
querytree_list=pg_analyze_and_rewrite(parsetree,query_string,NULL,0);
20822082
query= (Query*)lfirst(list_head(querytree_list));
2083-
target_entry= (TargetEntry*)lfirst(list_head(query->targetList));
2084-
//plan = pg_plan_query(query, 0, NULL);
2083+
plan=pg_plan_query(query,0,NULL);
20852084

2086-
post_parse_analyze_hook=orig_hook;
2085+
target_entry=lfirst(list_head(plan->planTree->targetlist));
2086+
2087+
/* Hooks can work now */
2088+
hooks_enabled= true;
20872089

20882090
return (Node*)target_entry->expr;
20892091
}

‎src/pg_pathman.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ PG_MODULE_MAGIC;
4242
Oidpathman_config_relid=InvalidOid,
4343
pathman_config_params_relid=InvalidOid;
4444

45+
/* Used to temporary disable hooks */
46+
boolhooks_enabled= true;
47+
4548

4649
/* pg module functions */
4750
void_PG_init(void);
@@ -141,7 +144,7 @@ _PG_init(void)
141144
/* Apply initial state */
142145
restore_pathman_init_state(&temp_init_state);
143146

144-
/*Initialize 'next' hook pointers */
147+
/*Set basic hooks */
145148
set_rel_pathlist_hook_next=set_rel_pathlist_hook;
146149
set_rel_pathlist_hook=pathman_rel_pathlist_hook;
147150
set_join_pathlist_next=set_join_pathlist_hook;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp