PostgreSQL Source Code  git master
appendinfo.h File Reference
#include "nodes/pathnodes.h"
#include "utils/relcache.h"
Include dependency graph for appendinfo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

AppendRelInfomake_append_rel_info (Relation parentrel, Relation childrel, Index parentRTindex, Index childRTindex)
 
Nodeadjust_appendrel_attrs (PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
 
Nodeadjust_appendrel_attrs_multilevel (PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids)
 
Relids adjust_child_relids (Relids relids, int nappinfos, AppendRelInfo **appinfos)
 
Relids adjust_child_relids_multilevel (PlannerInfo *root, Relids relids, Relids child_relids, Relids top_parent_relids)
 
AppendRelInfo ** find_appinfos_by_relids (PlannerInfo *root, Relids relids, int *nappinfos)
 

Function Documentation

◆ adjust_appendrel_attrs()

Node* adjust_appendrel_attrs ( PlannerInfo root,
Node node,
int  nappinfos,
AppendRelInfo **  appinfos 
)

Definition at line 180 of file appendinfo.c.

References adjust_appendrel_attrs_mutator(), adjust_inherited_tlist(), adjust_appendrel_attrs_context::appinfos, Assert, AppendRelInfo::child_relid, CMD_UPDATE, Query::commandType, IsA, adjust_appendrel_attrs_context::nappinfos, AppendRelInfo::parent_relid, QTW_IGNORE_RC_SUBQUERIES, query_tree_mutator(), Query::resultRelation, adjust_appendrel_attrs_context::root, and Query::targetList.

Referenced by add_child_rel_equivalences(), adjust_appendrel_attrs_multilevel(), apply_child_basequals(), apply_scanjoin_target_to_paths(), build_child_join_rel(), build_child_join_reltarget(), build_child_join_sjinfo(), create_partitionwise_grouping_paths(), inheritance_planner(), make_partitionedrel_pruneinfo(), set_append_rel_size(), and try_partitionwise_join().

182 {
183  Node *result;
185 
186  context.root = root;
187  context.nappinfos = nappinfos;
188  context.appinfos = appinfos;
189 
190  /* If there's nothing to adjust, don't call this function. */
191  Assert(nappinfos >= 1 && appinfos != NULL);
192 
193  /*
194  * Must be prepared to start with a Query or a bare expression tree.
195  */
196  if (node && IsA(node, Query))
197  {
198  Query *newnode;
199  int cnt;
200 
201  newnode = query_tree_mutator((Query *) node,
203  (void *) &context,
205  for (cnt = 0; cnt < nappinfos; cnt++)
206  {
207  AppendRelInfo *appinfo = appinfos[cnt];
208 
209  if (newnode->resultRelation == appinfo->parent_relid)
210  {
211  newnode->resultRelation = appinfo->child_relid;
212  /* Fix tlist resnos too, if it's inherited UPDATE */
213  if (newnode->commandType == CMD_UPDATE)
214  newnode->targetList =
216  appinfo);
217  break;
218  }
219  }
220 
221  result = (Node *) newnode;
222  }
223  else
224  result = adjust_appendrel_attrs_mutator(node, &context);
225 
226  return result;
227 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
static List * adjust_inherited_tlist(List *tlist, AppendRelInfo *context)
Definition: appendinfo.c:621
int resultRelation
Definition: parsenodes.h:122
Definition: nodes.h:525
List * targetList
Definition: parsenodes.h:140
#define QTW_IGNORE_RC_SUBQUERIES
Definition: nodeFuncs.h:22
static Node * adjust_appendrel_attrs_mutator(Node *node, adjust_appendrel_attrs_context *context)
Definition: appendinfo.c:230
CmdType commandType
Definition: parsenodes.h:112
#define Assert(condition)
Definition: c.h:732
AppendRelInfo ** appinfos
Definition: appendinfo.c:31
Index child_relid
Definition: pathnodes.h:2192
Index parent_relid
Definition: pathnodes.h:2191
Query * query_tree_mutator(Query *query, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3187

◆ adjust_appendrel_attrs_multilevel()

Node* adjust_appendrel_attrs_multilevel ( PlannerInfo root,
Node node,
Relids  child_relids,
Relids  top_parent_relids 
)

Definition at line 483 of file appendinfo.c.

References adjust_appendrel_attrs(), adjust_appendrel_attrs_multilevel(), Assert, bms_add_member(), bms_equal(), bms_num_members(), find_appinfos_by_relids(), AppendRelInfo::parent_relid, and pfree().

Referenced by add_child_rel_equivalences(), adjust_appendrel_attrs_multilevel(), generate_join_implied_equalities_broken(), and make_partitionedrel_pruneinfo().

486 {
487  AppendRelInfo **appinfos;
488  Bitmapset *parent_relids = NULL;
489  int nappinfos;
490  int cnt;
491 
492  Assert(bms_num_members(child_relids) == bms_num_members(top_parent_relids));
493 
494  appinfos = find_appinfos_by_relids(root, child_relids, &nappinfos);
495 
496  /* Construct relids set for the immediate parent of given child. */
497  for (cnt = 0; cnt < nappinfos; cnt++)
498  {
499  AppendRelInfo *appinfo = appinfos[cnt];
500 
501  parent_relids = bms_add_member(parent_relids, appinfo->parent_relid);
502  }
503 
504  /* Recurse if immediate parent is not the top parent. */
505  if (!bms_equal(parent_relids, top_parent_relids))
506  node = adjust_appendrel_attrs_multilevel(root, node, parent_relids,
507  top_parent_relids);
508 
509  /* Now translate for this child */
510  node = adjust_appendrel_attrs(root, node, nappinfos, appinfos);
511 
512  pfree(appinfos);
513 
514  return node;
515 }
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids)
Definition: appendinfo.c:483
void pfree(void *pointer)
Definition: mcxt.c:1056
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:646
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: appendinfo.c:709
#define Assert(condition)
Definition: c.h:732
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736
Index parent_relid
Definition: pathnodes.h:2191
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:94
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Definition: appendinfo.c:180

◆ adjust_child_relids()

Relids adjust_child_relids ( Relids  relids,
int  nappinfos,
AppendRelInfo **  appinfos 
)

Definition at line 522 of file appendinfo.c.

References bms_add_member(), bms_copy(), bms_del_member(), bms_is_member(), AppendRelInfo::child_relid, and AppendRelInfo::parent_relid.

Referenced by adjust_appendrel_attrs_mutator(), adjust_child_relids_multilevel(), and build_child_join_sjinfo().

523 {
524  Bitmapset *result = NULL;
525  int cnt;
526 
527  for (cnt = 0; cnt < nappinfos; cnt++)
528  {
529  AppendRelInfo *appinfo = appinfos[cnt];
530 
531  /* Remove parent, add child */
532  if (bms_is_member(appinfo->parent_relid, relids))
533  {
534  /* Make a copy if we are changing the set. */
535  if (!result)
536  result = bms_copy(relids);
537 
538  result = bms_del_member(result, appinfo->parent_relid);
539  result = bms_add_member(result, appinfo->child_relid);
540  }
541  }
542 
543  /* If we made any changes, return the modified copy. */
544  if (result)
545  return result;
546 
547  /* Otherwise, return the original set without modification. */
548  return relids;
549 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736
Index child_relid
Definition: pathnodes.h:2192
Index parent_relid
Definition: pathnodes.h:2191
Bitmapset * bms_del_member(Bitmapset *a, int x)
Definition: bitmapset.c:773
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427

◆ adjust_child_relids_multilevel()

Relids adjust_child_relids_multilevel ( PlannerInfo root,
Relids  relids,
Relids  child_relids,
Relids  top_parent_relids 
)

Definition at line 557 of file appendinfo.c.

References adjust_child_relids(), adjust_child_relids_multilevel(), bms_add_member(), bms_equal(), bms_free(), bms_overlap(), find_appinfos_by_relids(), AppendRelInfo::parent_relid, and pfree().

Referenced by adjust_child_relids_multilevel(), and reparameterize_path_by_child().

559 {
560  AppendRelInfo **appinfos;
561  int nappinfos;
562  Relids parent_relids = NULL;
563  Relids result;
564  Relids tmp_result = NULL;
565  int cnt;
566 
567  /*
568  * If the given relids set doesn't contain any of the top parent relids,
569  * it will remain unchanged.
570  */
571  if (!bms_overlap(relids, top_parent_relids))
572  return relids;
573 
574  appinfos = find_appinfos_by_relids(root, child_relids, &nappinfos);
575 
576  /* Construct relids set for the immediate parent of the given child. */
577  for (cnt = 0; cnt < nappinfos; cnt++)
578  {
579  AppendRelInfo *appinfo = appinfos[cnt];
580 
581  parent_relids = bms_add_member(parent_relids, appinfo->parent_relid);
582  }
583 
584  /* Recurse if immediate parent is not the top parent. */
585  if (!bms_equal(parent_relids, top_parent_relids))
586  {
587  tmp_result = adjust_child_relids_multilevel(root, relids,
588  parent_relids,
589  top_parent_relids);
590  relids = tmp_result;
591  }
592 
593  result = adjust_child_relids(relids, nappinfos, appinfos);
594 
595  /* Free memory consumed by any intermediate result. */
596  if (tmp_result)
597  bms_free(tmp_result);
598  bms_free(parent_relids);
599  pfree(appinfos);
600 
601  return result;
602 }
Relids adjust_child_relids_multilevel(PlannerInfo *root, Relids relids, Relids child_relids, Relids top_parent_relids)
Definition: appendinfo.c:557
void pfree(void *pointer)
Definition: mcxt.c:1056
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: appendinfo.c:709
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494
Relids adjust_child_relids(Relids relids, int nappinfos, AppendRelInfo **appinfos)
Definition: appendinfo.c:522
Index parent_relid
Definition: pathnodes.h:2191
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:94

◆ find_appinfos_by_relids()

AppendRelInfo** find_appinfos_by_relids ( PlannerInfo root,
Relids  relids,
int *  nappinfos 
)

Definition at line 709 of file appendinfo.c.

References PlannerInfo::append_rel_array, bms_next_member(), bms_num_members(), elog, ERROR, i, and palloc().

Referenced by adjust_appendrel_attrs_multilevel(), adjust_child_relids_multilevel(), apply_scanjoin_target_to_paths(), build_child_join_rel(), build_child_join_sjinfo(), create_partitionwise_grouping_paths(), make_partitionedrel_pruneinfo(), and try_partitionwise_join().

710 {
711  AppendRelInfo **appinfos;
712  int cnt = 0;
713  int i;
714 
715  *nappinfos = bms_num_members(relids);
716  appinfos = (AppendRelInfo **) palloc(sizeof(AppendRelInfo *) * *nappinfos);
717 
718  i = -1;
719  while ((i = bms_next_member(relids, i)) >= 0)
720  {
721  AppendRelInfo *appinfo = root->append_rel_array[i];
722 
723  if (!appinfo)
724  elog(ERROR, "child rel %d not found in append_rel_array", i);
725 
726  appinfos[cnt++] = appinfo;
727  }
728  return appinfos;
729 }
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1043
#define ERROR
Definition: elog.h:43
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:646
struct AppendRelInfo ** append_rel_array
Definition: pathnodes.h:217
void * palloc(Size size)
Definition: mcxt.c:949
#define elog(elevel,...)
Definition: elog.h:226
int i

◆ make_append_rel_info()

AppendRelInfo* make_append_rel_info ( Relation  parentrel,
Relation  childrel,
Index  parentRTindex,
Index  childRTindex 
)

Definition at line 49 of file appendinfo.c.

References AppendRelInfo::child_relid, AppendRelInfo::child_reltype, make_inh_translation_list(), makeNode, AppendRelInfo::parent_relid, AppendRelInfo::parent_reloid, AppendRelInfo::parent_reltype, RelationData::rd_rel, RelationGetRelid, and AppendRelInfo::translated_vars.

Referenced by expand_single_inheritance_child().

51 {
53 
54  appinfo->parent_relid = parentRTindex;
55  appinfo->child_relid = childRTindex;
56  appinfo->parent_reltype = parentrel->rd_rel->reltype;
57  appinfo->child_reltype = childrel->rd_rel->reltype;
58  make_inh_translation_list(parentrel, childrel, childRTindex,
59  &appinfo->translated_vars);
60  appinfo->parent_reloid = RelationGetRelid(parentrel);
61 
62  return appinfo;
63 }
Form_pg_class rd_rel
Definition: rel.h:83
List * translated_vars
Definition: pathnodes.h:2219
Oid parent_reltype
Definition: pathnodes.h:2200
static void make_inh_translation_list(Relation oldrelation, Relation newrelation, Index newvarno, List **translated_vars)
Definition: appendinfo.c:73
#define makeNode(_type_)
Definition: nodes.h:573
Index child_relid
Definition: pathnodes.h:2192
Index parent_relid
Definition: pathnodes.h:2191
#define RelationGetRelid(relation)
Definition: rel.h:419