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 194 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_join_rel_equivalences(), 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().

196 {
197  Node *result;
199 
200  context.root = root;
201  context.nappinfos = nappinfos;
202  context.appinfos = appinfos;
203 
204  /* If there's nothing to adjust, don't call this function. */
205  Assert(nappinfos >= 1 && appinfos != NULL);
206 
207  /*
208  * Must be prepared to start with a Query or a bare expression tree.
209  */
210  if (node && IsA(node, Query))
211  {
212  Query *newnode;
213  int cnt;
214 
215  newnode = query_tree_mutator((Query *) node,
217  (void *) &context,
219  for (cnt = 0; cnt < nappinfos; cnt++)
220  {
221  AppendRelInfo *appinfo = appinfos[cnt];
222 
223  if (newnode->resultRelation == appinfo->parent_relid)
224  {
225  newnode->resultRelation = appinfo->child_relid;
226  /* Fix tlist resnos too, if it's inherited UPDATE */
227  if (newnode->commandType == CMD_UPDATE)
228  newnode->targetList =
230  appinfo);
231  break;
232  }
233  }
234 
235  result = (Node *) newnode;
236  }
237  else
238  result = adjust_appendrel_attrs_mutator(node, &context);
239 
240  return result;
241 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
static List * adjust_inherited_tlist(List *tlist, AppendRelInfo *context)
Definition: appendinfo.c:640
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:244
CmdType commandType
Definition: parsenodes.h:112
#define Assert(condition)
Definition: c.h:739
AppendRelInfo ** appinfos
Definition: appendinfo.c:31
Index child_relid
Definition: pathnodes.h:2190
Index parent_relid
Definition: pathnodes.h:2189
Query * query_tree_mutator(Query *query, Node *(*mutator)(), void *context, int flags)
Definition: nodeFuncs.c:3202

◆ adjust_appendrel_attrs_multilevel()

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

Definition at line 502 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_join_rel_equivalences(), add_child_rel_equivalences(), adjust_appendrel_attrs_multilevel(), generate_join_implied_equalities_broken(), and make_partitionedrel_pruneinfo().

505 {
506  AppendRelInfo **appinfos;
507  Bitmapset *parent_relids = NULL;
508  int nappinfos;
509  int cnt;
510 
511  Assert(bms_num_members(child_relids) == bms_num_members(top_parent_relids));
512 
513  appinfos = find_appinfos_by_relids(root, child_relids, &nappinfos);
514 
515  /* Construct relids set for the immediate parent of given child. */
516  for (cnt = 0; cnt < nappinfos; cnt++)
517  {
518  AppendRelInfo *appinfo = appinfos[cnt];
519 
520  parent_relids = bms_add_member(parent_relids, appinfo->parent_relid);
521  }
522 
523  /* Recurse if immediate parent is not the top parent. */
524  if (!bms_equal(parent_relids, top_parent_relids))
525  node = adjust_appendrel_attrs_multilevel(root, node, parent_relids,
526  top_parent_relids);
527 
528  /* Now translate for this child */
529  node = adjust_appendrel_attrs(root, node, nappinfos, appinfos);
530 
531  pfree(appinfos);
532 
533  return node;
534 }
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids)
Definition: appendinfo.c:502
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:728
#define Assert(condition)
Definition: c.h:739
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736
Index parent_relid
Definition: pathnodes.h:2189
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:194

◆ adjust_child_relids()

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

Definition at line 541 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().

542 {
543  Bitmapset *result = NULL;
544  int cnt;
545 
546  for (cnt = 0; cnt < nappinfos; cnt++)
547  {
548  AppendRelInfo *appinfo = appinfos[cnt];
549 
550  /* Remove parent, add child */
551  if (bms_is_member(appinfo->parent_relid, relids))
552  {
553  /* Make a copy if we are changing the set. */
554  if (!result)
555  result = bms_copy(relids);
556 
557  result = bms_del_member(result, appinfo->parent_relid);
558  result = bms_add_member(result, appinfo->child_relid);
559  }
560  }
561 
562  /* If we made any changes, return the modified copy. */
563  if (result)
564  return result;
565 
566  /* Otherwise, return the original set without modification. */
567  return relids;
568 }
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:2190
Index parent_relid
Definition: pathnodes.h:2189
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 576 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 add_child_join_rel_equivalences(), adjust_child_relids_multilevel(), and reparameterize_path_by_child().

578 {
579  AppendRelInfo **appinfos;
580  int nappinfos;
581  Relids parent_relids = NULL;
582  Relids result;
583  Relids tmp_result = NULL;
584  int cnt;
585 
586  /*
587  * If the given relids set doesn't contain any of the top parent relids,
588  * it will remain unchanged.
589  */
590  if (!bms_overlap(relids, top_parent_relids))
591  return relids;
592 
593  appinfos = find_appinfos_by_relids(root, child_relids, &nappinfos);
594 
595  /* Construct relids set for the immediate parent of the given child. */
596  for (cnt = 0; cnt < nappinfos; cnt++)
597  {
598  AppendRelInfo *appinfo = appinfos[cnt];
599 
600  parent_relids = bms_add_member(parent_relids, appinfo->parent_relid);
601  }
602 
603  /* Recurse if immediate parent is not the top parent. */
604  if (!bms_equal(parent_relids, top_parent_relids))
605  {
606  tmp_result = adjust_child_relids_multilevel(root, relids,
607  parent_relids,
608  top_parent_relids);
609  relids = tmp_result;
610  }
611 
612  result = adjust_child_relids(relids, nappinfos, appinfos);
613 
614  /* Free memory consumed by any intermediate result. */
615  if (tmp_result)
616  bms_free(tmp_result);
617  bms_free(parent_relids);
618  pfree(appinfos);
619 
620  return result;
621 }
Relids adjust_child_relids_multilevel(PlannerInfo *root, Relids relids, Relids child_relids, Relids top_parent_relids)
Definition: appendinfo.c:576
void pfree(void *pointer)
Definition: mcxt.c:1056
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: appendinfo.c:728
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:541
Index parent_relid
Definition: pathnodes.h:2189
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 728 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().

729 {
730  AppendRelInfo **appinfos;
731  int cnt = 0;
732  int i;
733 
734  *nappinfos = bms_num_members(relids);
735  appinfos = (AppendRelInfo **) palloc(sizeof(AppendRelInfo *) * *nappinfos);
736 
737  i = -1;
738  while ((i = bms_next_member(relids, i)) >= 0)
739  {
740  AppendRelInfo *appinfo = root->append_rel_array[i];
741 
742  if (!appinfo)
743  elog(ERROR, "child rel %d not found in append_rel_array", i);
744 
745  appinfos[cnt++] = appinfo;
746  }
747  return appinfos;
748 }
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:219
void * palloc(Size size)
Definition: mcxt.c:949
#define elog(elevel,...)
Definition: elog.h:228
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, and RelationGetRelid.

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, appinfo);
59  appinfo->parent_reloid = RelationGetRelid(parentrel);
60 
61  return appinfo;
62 }
static void make_inh_translation_list(Relation oldrelation, Relation newrelation, Index newvarno, AppendRelInfo *appinfo)
Definition: appendinfo.c:78
Form_pg_class rd_rel
Definition: rel.h:84
Oid parent_reltype
Definition: pathnodes.h:2198
#define makeNode(_type_)
Definition: nodes.h:573
Index child_relid
Definition: pathnodes.h:2190
Index parent_relid
Definition: pathnodes.h:2189
#define RelationGetRelid(relation)
Definition: rel.h:428