Skip to content

Commit 2b16fcd

Browse files
committed
code cleanup
1 parent 691c6e1 commit 2b16fcd

File tree

2 files changed

+44
-54
lines changed

2 files changed

+44
-54
lines changed

src/utils.c

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626

2727
static bool clause_contains_params_walker(Node *node, void *context);
28-
static void change_varnos_in_restrinct_info(RestrictInfo *rinfo, change_varno_context *context);
28+
static void change_varnos_in_restrinct_info(RestrictInfo *rinfo,
29+
change_varno_context *context);
2930
static bool change_varno_walker(Node *node, change_varno_context *context);
3031
static List *get_tableoids_list(List *tlist);
3132
static void lock_rows_visitor(Plan *plan, void *context);
@@ -440,6 +441,43 @@ change_varno_walker(Node *node, change_varno_context *context)
440441
return expression_tree_walker(node, change_varno_walker, (void *) context);
441442
}
442443

444+
static void
445+
change_varnos_in_restrinct_info(RestrictInfo *rinfo, change_varno_context *context)
446+
{
447+
ListCell *lc;
448+
449+
change_varno_walker((Node *) rinfo->clause, context);
450+
if (rinfo->left_em)
451+
change_varno_walker((Node *) rinfo->left_em->em_expr, context);
452+
453+
if (rinfo->right_em)
454+
change_varno_walker((Node *) rinfo->right_em->em_expr, context);
455+
456+
if (rinfo->orclause)
457+
foreach(lc, ((BoolExpr *) rinfo->orclause)->args)
458+
{
459+
Node *node = (Node *) lfirst(lc);
460+
change_varno_walker(node, context);
461+
}
462+
463+
/* TODO: find some elegant way to do this */
464+
if (bms_is_member(context->old_varno, rinfo->clause_relids))
465+
{
466+
rinfo->clause_relids = bms_del_member(rinfo->clause_relids, context->old_varno);
467+
rinfo->clause_relids = bms_add_member(rinfo->clause_relids, context->new_varno);
468+
}
469+
if (bms_is_member(context->old_varno, rinfo->left_relids))
470+
{
471+
rinfo->left_relids = bms_del_member(rinfo->left_relids, context->old_varno);
472+
rinfo->left_relids = bms_add_member(rinfo->left_relids, context->new_varno);
473+
}
474+
if (bms_is_member(context->old_varno, rinfo->right_relids))
475+
{
476+
rinfo->right_relids = bms_del_member(rinfo->right_relids, context->old_varno);
477+
rinfo->right_relids = bms_add_member(rinfo->right_relids, context->new_varno);
478+
}
479+
}
480+
443481
Oid
444482
str_to_oid(const char *cstr)
445483
{
@@ -477,10 +515,6 @@ plan_tree_walker(Plan *plan,
477515
plan_tree_walker((Plan *) lfirst(l), visitor, context);
478516
break;
479517

480-
/*
481-
* Add proxy PartitionFilter nodes
482-
* to subplans of ModifyTable node
483-
*/
484518
case T_ModifyTable:
485519
foreach (l, ((ModifyTable *) plan)->plans)
486520
plan_tree_walker((Plan *) lfirst(l), visitor, context);
@@ -510,47 +544,10 @@ plan_tree_walker(Plan *plan,
510544
plan_tree_walker(plan->lefttree, visitor, context);
511545
plan_tree_walker(plan->righttree, visitor, context);
512546

547+
/* Apply visitor to the current node */
513548
visitor(plan, context);
514549
}
515550

516-
517-
static void
518-
change_varnos_in_restrinct_info(RestrictInfo *rinfo, change_varno_context *context)
519-
{
520-
ListCell *lc;
521-
522-
change_varno_walker((Node *) rinfo->clause, context);
523-
if (rinfo->left_em)
524-
change_varno_walker((Node *) rinfo->left_em->em_expr, context);
525-
526-
if (rinfo->right_em)
527-
change_varno_walker((Node *) rinfo->right_em->em_expr, context);
528-
529-
if (rinfo->orclause)
530-
foreach(lc, ((BoolExpr *) rinfo->orclause)->args)
531-
{
532-
Node *node = (Node *) lfirst(lc);
533-
change_varno_walker(node, context);
534-
}
535-
536-
/* TODO: find some elegant way to do this */
537-
if (bms_is_member(context->old_varno, rinfo->clause_relids))
538-
{
539-
rinfo->clause_relids = bms_del_member(rinfo->clause_relids, context->old_varno);
540-
rinfo->clause_relids = bms_add_member(rinfo->clause_relids, context->new_varno);
541-
}
542-
if (bms_is_member(context->old_varno, rinfo->left_relids))
543-
{
544-
rinfo->left_relids = bms_del_member(rinfo->left_relids, context->old_varno);
545-
rinfo->left_relids = bms_add_member(rinfo->left_relids, context->new_varno);
546-
}
547-
if (bms_is_member(context->old_varno, rinfo->right_relids))
548-
{
549-
rinfo->right_relids = bms_del_member(rinfo->right_relids, context->old_varno);
550-
rinfo->right_relids = bms_add_member(rinfo->right_relids, context->new_varno);
551-
}
552-
}
553-
554551
/*
555552
* Add missing 'TABLEOID_STR%u' junk attributes for inherited partitions
556553
*

src/utils.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,8 @@
1919

2020
typedef struct
2121
{
22-
RelOptInfo *child;
23-
RelOptInfo *parent;
24-
int sublevels_up;
25-
} ReplaceVarsContext;
26-
27-
typedef struct
28-
{
29-
Oid old_varno;
30-
Oid new_varno;
22+
Oid old_varno;
23+
Oid new_varno;
3124
} change_varno_context;
3225

3326

@@ -53,10 +46,10 @@ List * list_reverse(List *l);
5346

5447
void change_varnos(Node *node, Oid old_varno, Oid new_varno);
5548

56-
Oid str_to_oid(const char * cstr);
49+
Oid str_to_oid(const char *cstr);
5750

5851
void plan_tree_walker(Plan *plan,
59-
void (*visitor)(Plan *, void *),
52+
void (*visitor) (Plan *plan, void *context),
6053
void *context);
6154

6255
void rowmark_add_tableoids(Query *parse);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy