Skip to content

Commit 1ccf5b9

Browse files
committed
Use more adequate name for variable, optimize code
1 parent ae574fd commit 1ccf5b9

File tree

4 files changed

+16
-66
lines changed

4 files changed

+16
-66
lines changed

src/hooks.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
6666
innerrel, jointype, extra);
6767

6868
/* Hooks can be disabled */
69-
if (!hooks_enabled)
69+
if (!pathman_hooks_enabled)
7070
return;
7171

7272
/* Check that both pg_pathman & RuntimeAppend nodes are enabled */
@@ -209,7 +209,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
209209
set_rel_pathlist_hook_next(root, rel, rti, rte);
210210

211211
/* Hooks can be disabled */
212-
if (!hooks_enabled)
212+
if (!pathman_hooks_enabled)
213213
return;
214214

215215
/* Make sure that pg_pathman is ready */
@@ -492,19 +492,7 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
492492

493493
PG_TRY();
494494
{
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-
return result;
505-
}
506-
507-
if (pathman_ready)
495+
if (pathman_ready && pathman_hooks_enabled)
508496
{
509497
/* Increment relation tags refcount */
510498
incr_refcount_relation_tags();
@@ -519,6 +507,9 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
519507
else
520508
result = standard_planner(parse, cursorOptions, boundParams);
521509

510+
if (!pathman_hooks_enabled)
511+
return result;
512+
522513
if (pathman_ready)
523514
{
524515
/* Give rowmark-related attributes correct names */
@@ -564,7 +555,7 @@ pathman_post_parse_analysis_hook(ParseState *pstate, Query *query)
564555
post_parse_analyze_hook_next(pstate, query);
565556

566557
/* Hooks can be disabled */
567-
if (!hooks_enabled)
558+
if (!pathman_hooks_enabled)
568559
return;
569560

570561
/* We shouldn't do anything on BEGIN or SET ISOLATION LEVEL stmts */
@@ -642,7 +633,7 @@ pathman_relcache_hook(Datum arg, Oid relid)
642633
return;
643634

644635
/* Hooks can be disabled */
645-
if (!hooks_enabled)
636+
if (!pathman_hooks_enabled)
646637
return;
647638

648639
/* We shouldn't even consider special OIDs */

src/include/pathman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extern Oid pathman_config_relid;
8686
extern Oid pathman_config_params_relid;
8787

8888
/* Hooks enable state */
89-
extern bool hooks_enabled;
89+
extern bool pathman_hooks_enabled;
9090

9191
/*
9292
* Just to clarify our intentions (return the corresponding relid).

src/partition_creation.c

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,51 +1708,10 @@ parse_expression(Oid relid, const char *expr, char **query_string_out)
17081708
return (Node *)(lfirst(list_head(parsetree_list)));
17091709
}
17101710

1711-
/* By given relation id and expression returns node */
17121711
/*
1713-
Node *
1714-
get_raw_expression(Oid relid, const char *expr)
1715-
{
1716-
List *querytree_list;
1717-
List *target_list;
1718-
char *query_string;
1719-
Node *parsetree,
1720-
*result;
1721-
Query *query;
1722-
TargetEntry *target_entry;
1723-
PlannedStmt *plan;
1724-
MemoryContext oldcontext;
1725-
struct expr_mutator_context context;
1726-
1727-
parsetree = parse_expression(relid, expr, &query_string),
1728-
target_list = ((SelectStmt *)parsetree)->targetList;
1729-
1730-
result = (Node *)(((ResTarget *)(lfirst(list_head(target_list))))->val);
1731-
return result; */
1732-
1733-
/*
1734-
hooks_enabled = false;
1735-
1736-
querytree_list = pg_analyze_and_rewrite(parsetree, query_string, NULL, 0);
1737-
query = (Query *)lfirst(list_head(querytree_list));
1738-
plan = pg_plan_query(query, 0, NULL);
1739-
target_entry = lfirst(list_head(plan->planTree->targetlist));
1740-
1741-
hooks_enabled = true;
1742-
1743-
result = (Node *)target_entry->expr;
1744-
1745-
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
1746-
1747-
context.relid = relid;
1748-
context.rtable = plan->rtable;
1749-
1750-
result = expression_mutator(result, (void *) &context);
1751-
MemoryContextSwitchTo(oldcontext);
1752-
return result;
1753-
}*/
1754-
1755-
/* Determines type of expression for a relation */
1712+
* Parses expression related to 'relid', and returns its type,
1713+
* raw expression tree, and if specified returns its plan
1714+
*/
17561715
PartExpressionInfo *
17571716
get_part_expression_info(Oid relid, const char *expr_string,
17581717
bool check_hash_func, bool make_plan)
@@ -1780,7 +1739,7 @@ get_part_expression_info(Oid relid, const char *expr_string,
17801739
expr_info->expr_datum = (Datum) 0;
17811740

17821741
/* We don't need pathman activity initialization for this relation yet */
1783-
hooks_enabled = false;
1742+
pathman_hooks_enabled = false;
17841743

17851744
/* This will fail with elog in case of wrong expression
17861745
* with more or less understable text */
@@ -1819,7 +1778,7 @@ get_part_expression_info(Oid relid, const char *expr_string,
18191778

18201779
end:
18211780
/* Enable pathman hooks */
1822-
hooks_enabled = true;
1781+
pathman_hooks_enabled = true;
18231782

18241783
return expr_info;
18251784
}

src/pg_pathman.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ PG_MODULE_MAGIC;
4242
Oid pathman_config_relid = InvalidOid,
4343
pathman_config_params_relid = InvalidOid;
4444

45-
/* Used to temporary disable hooks */
46-
bool hooks_enabled = true;
45+
/* Used to disable hooks temporarily */
46+
bool pathman_hooks_enabled = true;
4747

4848

4949
/* pg module functions */

0 commit comments

Comments
 (0)