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

Go to the source code of this file.

Functions

char * pg_get_indexdef_string (Oid indexrelid)
 
char * pg_get_indexdef_columns (Oid indexrelid, bool pretty)
 
char * pg_get_partkeydef_columns (Oid relid, bool pretty)
 
char * pg_get_partconstrdef_string (Oid partitionId, char *aliasname)
 
char * pg_get_constraintdef_command (Oid constraintId)
 
char * deparse_expression (Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
 
Listdeparse_context_for (const char *aliasname, Oid relid)
 
Listdeparse_context_for_plan_tree (struct PlannedStmt *pstmt, List *rtable_names)
 
Listset_deparse_context_plan (List *dpcontext, struct Plan *plan, List *ancestors)
 
Listselect_rtable_names_for_explain (List *rtable, Bitmapset *rels_used)
 
char * generate_collation_name (Oid collid)
 
char * generate_opclass_name (Oid opclass)
 
char * get_range_partbound_string (List *bound_datums)
 
char * pg_get_statisticsobjdef_string (Oid statextid)
 

Function Documentation

◆ deparse_context_for()

List* deparse_context_for ( const char *  aliasname,
Oid  relid 
)

Definition at line 3561 of file ruleutils.c.

References AccessShareLock, RangeTblEntry::alias, deparse_namespace::appendrels, deparse_namespace::ctes, RangeTblEntry::eref, RangeTblEntry::inFromCl, RangeTblEntry::inh, RangeTblEntry::lateral, list_make1, makeAlias(), makeNode, NIL, palloc0(), RangeTblEntry::relid, RangeTblEntry::relkind, RangeTblEntry::rellockmode, deparse_namespace::rtable, RTE_RELATION, RangeTblEntry::rtekind, set_rtable_names(), set_simple_column_names(), and deparse_namespace::subplans.

Referenced by pg_get_constraintdef_worker(), pg_get_expr_worker(), pg_get_indexdef_worker(), pg_get_partconstrdef_string(), pg_get_partition_constraintdef(), pg_get_partkeydef_worker(), pg_get_statisticsobj_worker(), pg_get_statisticsobjdef_expressions(), transformPartitionBound(), and transformPartitionRangeBounds().

3562 {
3563  deparse_namespace *dpns;
3564  RangeTblEntry *rte;
3565 
3566  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3567 
3568  /* Build a minimal RTE for the rel */
3569  rte = makeNode(RangeTblEntry);
3570  rte->rtekind = RTE_RELATION;
3571  rte->relid = relid;
3572  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3574  rte->alias = makeAlias(aliasname, NIL);
3575  rte->eref = rte->alias;
3576  rte->lateral = false;
3577  rte->inh = false;
3578  rte->inFromCl = true;
3579 
3580  /* Build one-element rtable */
3581  dpns->rtable = list_make1(rte);
3582  dpns->subplans = NIL;
3583  dpns->ctes = NIL;
3584  dpns->appendrels = NULL;
3585  set_rtable_names(dpns, NIL, NULL);
3587 
3588  /* Return a one-deep namespace stack */
3589  return list_make1(dpns);
3590 }
#define NIL
Definition: pg_list.h:65
Alias * alias
Definition: parsenodes.h:1152
#define AccessShareLock
Definition: lockdefs.h:36
AppendRelInfo ** appendrels
Definition: ruleutils.c:163
#define list_make1(x1)
Definition: pg_list.h:206
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:387
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3727
void * palloc0(Size size)
Definition: mcxt.c:1093
#define makeNode(_type_)
Definition: nodes.h:584
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3937
RTEKind rtekind
Definition: parsenodes.h:1007
Alias * eref
Definition: parsenodes.h:1153

◆ deparse_context_for_plan_tree()

List* deparse_context_for_plan_tree ( struct PlannedStmt pstmt,
List rtable_names 
)

Definition at line 3606 of file ruleutils.c.

References PlannedStmt::appendRelations, deparse_namespace::appendrels, Assert, AppendRelInfo::child_relid, deparse_namespace::ctes, lfirst_node, list_length(), list_make1, NIL, palloc0(), PlannedStmt::rtable, deparse_namespace::rtable, deparse_namespace::rtable_names, set_simple_column_names(), PlannedStmt::subplans, and deparse_namespace::subplans.

Referenced by ExplainPrintPlan().

3607 {
3608  deparse_namespace *dpns;
3609 
3610  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3611 
3612  /* Initialize fields that stay the same across the whole plan tree */
3613  dpns->rtable = pstmt->rtable;
3614  dpns->rtable_names = rtable_names;
3615  dpns->subplans = pstmt->subplans;
3616  dpns->ctes = NIL;
3617  if (pstmt->appendRelations)
3618  {
3619  /* Set up the array, indexed by child relid */
3620  int ntables = list_length(dpns->rtable);
3621  ListCell *lc;
3622 
3623  dpns->appendrels = (AppendRelInfo **)
3624  palloc0((ntables + 1) * sizeof(AppendRelInfo *));
3625  foreach(lc, pstmt->appendRelations)
3626  {
3627  AppendRelInfo *appinfo = lfirst_node(AppendRelInfo, lc);
3628  Index crelid = appinfo->child_relid;
3629 
3630  Assert(crelid > 0 && crelid <= ntables);
3631  Assert(dpns->appendrels[crelid] == NULL);
3632  dpns->appendrels[crelid] = appinfo;
3633  }
3634  }
3635  else
3636  dpns->appendrels = NULL; /* don't need it */
3637 
3638  /*
3639  * Set up column name aliases. We will get rather bogus results for join
3640  * RTEs, but that doesn't matter because plan trees don't contain any join
3641  * alias Vars.
3642  */
3644 
3645  /* Return a one-deep namespace stack */
3646  return list_make1(dpns);
3647 }
#define NIL
Definition: pg_list.h:65
List * rtable_names
Definition: ruleutils.c:159
AppendRelInfo ** appendrels
Definition: ruleutils.c:163
#define list_make1(x1)
Definition: pg_list.h:206
#define lfirst_node(type, lc)
Definition: pg_list.h:172
void * palloc0(Size size)
Definition: mcxt.c:1093
unsigned int Index
Definition: c.h:549
List * subplans
Definition: plannodes.h:73
#define Assert(condition)
Definition: c.h:804
static int list_length(const List *l)
Definition: pg_list.h:149
List * rtable
Definition: plannodes.h:66
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3937
Index child_relid
Definition: pathnodes.h:2307
List * appendRelations
Definition: plannodes.h:71

◆ deparse_expression()

char* deparse_expression ( Node expr,
List dpcontext,
bool  forceprefix,
bool  showimplicit 
)

Definition at line 3501 of file ruleutils.c.

References deparse_expression_pretty().

Referenced by AlterDomainDefault(), DefineDomain(), pg_get_function_arg_default(), pg_get_partconstrdef_string(), print_function_arguments(), show_expression(), show_grouping_set_keys(), show_memoize_info(), show_plan_tlist(), show_sort_group_keys(), show_tablesample(), transformPartitionBound(), and transformPartitionRangeBounds().

3503 {
3504  return deparse_expression_pretty(expr, dpcontext, forceprefix,
3505  showimplicit, 0, 0);
3506 }
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:3528

◆ generate_collation_name()

char* generate_collation_name ( Oid  collid)

Definition at line 11886 of file ruleutils.c.

References CollationIsVisible(), COLLOID, elog, ERROR, get_namespace_name_or_temp(), GETSTRUCT, HeapTupleIsValid, NameStr, ObjectIdGetDatum, quote_qualified_identifier(), ReleaseSysCache(), and SearchSysCache1().

Referenced by get_const_collation(), get_from_clause_coldeflist(), get_rule_expr(), pg_collation_for(), pg_get_indexdef_worker(), and pg_get_partkeydef_worker().

11887 {
11888  HeapTuple tp;
11889  Form_pg_collation colltup;
11890  char *collname;
11891  char *nspname;
11892  char *result;
11893 
11894  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
11895  if (!HeapTupleIsValid(tp))
11896  elog(ERROR, "cache lookup failed for collation %u", collid);
11897  colltup = (Form_pg_collation) GETSTRUCT(tp);
11898  collname = NameStr(colltup->collname);
11899 
11900  if (!CollationIsVisible(collid))
11901  nspname = get_namespace_name_or_temp(colltup->collnamespace);
11902  else
11903  nspname = NULL;
11904 
11905  result = quote_qualified_identifier(nspname, collname);
11906 
11907  ReleaseSysCache(tp);
11908 
11909  return result;
11910 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2093
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:11458
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:56
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3340
#define elog(elevel,...)
Definition: elog.h:232
#define NameStr(name)
Definition: c.h:681

◆ generate_opclass_name()

char* generate_opclass_name ( Oid  opclass)

Definition at line 11244 of file ruleutils.c.

References buf, StringInfoData::data, get_opclass_name(), initStringInfo(), and InvalidOid.

Referenced by index_opclass_options().

11245 {
11247 
11248  initStringInfo(&buf);
11249  get_opclass_name(opclass, InvalidOid, &buf);
11250 
11251  return &buf.data[1]; /* get_opclass_name() prepends space */
11252 }
static char * buf
Definition: pg_test_fsync.c:68
static void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf)
Definition: ruleutils.c:11206
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
#define InvalidOid
Definition: postgres_ext.h:36

◆ get_range_partbound_string()

char* get_range_partbound_string ( List bound_datums)

Definition at line 12020 of file ruleutils.c.

References appendStringInfoChar(), appendStringInfoString(), buf, deparse_context::buf, castNode, StringInfoData::data, get_const_expr(), PartitionRangeDatum::kind, lfirst_node, makeStringInfo(), PARTITION_RANGE_DATUM_MAXVALUE, PARTITION_RANGE_DATUM_MINVALUE, val, and PartitionRangeDatum::value.

Referenced by check_new_partition_bound(), and get_rule_expr().

12021 {
12022  deparse_context context;
12024  ListCell *cell;
12025  char *sep;
12026 
12027  memset(&context, 0, sizeof(deparse_context));
12028  context.buf = buf;
12029 
12030  appendStringInfoChar(buf, '(');
12031  sep = "";
12032  foreach(cell, bound_datums)
12033  {
12034  PartitionRangeDatum *datum =
12036 
12037  appendStringInfoString(buf, sep);
12038  if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
12039  appendStringInfoString(buf, "MINVALUE");
12040  else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
12041  appendStringInfoString(buf, "MAXVALUE");
12042  else
12043  {
12044  Const *val = castNode(Const, datum->value);
12045 
12046  get_const_expr(val, &context, -1);
12047  }
12048  sep = ", ";
12049  }
12050  appendStringInfoChar(buf, ')');
12051 
12052  return buf->data;
12053 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:605
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
PartitionRangeDatumKind kind
Definition: parsenodes.h:873
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
Definition: ruleutils.c:10231
#define lfirst_node(type, lc)
Definition: pg_list.h:172
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
static char * buf
Definition: pg_test_fsync.c:68
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
StringInfo buf
Definition: ruleutils.c:110
long val
Definition: informix.c:664

◆ pg_get_constraintdef_command()

char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 2101 of file ruleutils.c.

References pg_get_constraintdef_worker().

Referenced by RememberConstraintForRebuilding().

2102 {
2103  return pg_get_constraintdef_worker(constraintId, true, 0, false);
2104 }
static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:2110

◆ pg_get_indexdef_columns()

char* pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1176 of file ruleutils.c.

References pg_get_indexdef_worker(), PRETTYFLAG_INDENT, PRETTYFLAG_PAREN, and PRETTYFLAG_SCHEMA.

Referenced by BuildIndexValueDescription().

1177 {
1178  int prettyFlags;
1179 
1181 
1182  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1183  true, true,
1184  false, false,
1185  prettyFlags, false);
1186 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:90
#define PRETTYFLAG_SCHEMA
Definition: ruleutils.c:91
#define PRETTYFLAG_PAREN
Definition: ruleutils.c:89
static char * pg_get_indexdef_worker(Oid indexrelid, int colno, const Oid *excludeOps, bool attrsOnly, bool keysOnly, bool showTblSpc, bool inherits, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:1195

◆ pg_get_indexdef_string()

char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1166 of file ruleutils.c.

References pg_get_indexdef_worker().

Referenced by RememberIndexForRebuilding().

1167 {
1168  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1169  false, false,
1170  true, true,
1171  0, false);
1172 }
static char * pg_get_indexdef_worker(Oid indexrelid, int colno, const Oid *excludeOps, bool attrsOnly, bool keysOnly, bool showTblSpc, bool inherits, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:1195

◆ pg_get_partconstrdef_string()

char* pg_get_partconstrdef_string ( Oid  partitionId,
char *  aliasname 
)

Definition at line 2045 of file ruleutils.c.

References deparse_context_for(), deparse_expression(), and get_partition_qual_relid().

Referenced by RI_PartitionRemove_Check().

2046 {
2047  Expr *constr_expr;
2048  List *context;
2049 
2050  constr_expr = get_partition_qual_relid(partitionId);
2051  context = deparse_context_for(aliasname, partitionId);
2052 
2053  return deparse_expression((Node *) constr_expr, context, true, false);
2054 }
Definition: nodes.h:536
List * deparse_context_for(const char *aliasname, Oid relid)
Definition: ruleutils.c:3561
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Definition: ruleutils.c:3501
Expr * get_partition_qual_relid(Oid relid)
Definition: partcache.c:298
Definition: pg_list.h:50

◆ pg_get_partkeydef_columns()

char* pg_get_partkeydef_columns ( Oid  relid,
bool  pretty 
)

Definition at line 1836 of file ruleutils.c.

References pg_get_partkeydef_worker(), PRETTYFLAG_INDENT, PRETTYFLAG_PAREN, and PRETTYFLAG_SCHEMA.

Referenced by ExecBuildSlotPartitionKeyDescription().

1837 {
1838  int prettyFlags;
1839 
1841 
1842  return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
1843 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:90
#define PRETTYFLAG_SCHEMA
Definition: ruleutils.c:91
static char * pg_get_partkeydef_worker(Oid relid, int prettyFlags, bool attrsOnly, bool missing_ok)
Definition: ruleutils.c:1849
#define PRETTYFLAG_PAREN
Definition: ruleutils.c:89

◆ pg_get_statisticsobjdef_string()

char* pg_get_statisticsobjdef_string ( Oid  statextid)

Definition at line 1532 of file ruleutils.c.

References pg_get_statisticsobj_worker().

Referenced by RememberStatisticsForRebuilding().

1533 {
1534  return pg_get_statisticsobj_worker(statextid, false, false);
1535 }
static char * pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
Definition: ruleutils.c:1559

◆ select_rtable_names_for_explain()

List* select_rtable_names_for_explain ( List rtable,
Bitmapset rels_used 
)

Definition at line 3698 of file ruleutils.c.

References deparse_namespace::appendrels, deparse_namespace::ctes, NIL, deparse_namespace::rtable, deparse_namespace::rtable_names, set_rtable_names(), and deparse_namespace::subplans.

Referenced by ExplainPrintPlan().

3699 {
3700  deparse_namespace dpns;
3701 
3702  memset(&dpns, 0, sizeof(dpns));
3703  dpns.rtable = rtable;
3704  dpns.subplans = NIL;
3705  dpns.ctes = NIL;
3706  dpns.appendrels = NULL;
3707  set_rtable_names(&dpns, NIL, rels_used);
3708  /* We needn't bother computing column aliases yet */
3709 
3710  return dpns.rtable_names;
3711 }
#define NIL
Definition: pg_list.h:65
List * rtable_names
Definition: ruleutils.c:159
AppendRelInfo ** appendrels
Definition: ruleutils.c:163
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3727

◆ set_deparse_context_plan()

List* set_deparse_context_plan ( List dpcontext,
struct Plan plan,
List ancestors 
)

Definition at line 3675 of file ruleutils.c.

References deparse_namespace::ancestors, Assert, linitial, list_length(), and set_deparse_plan().

Referenced by show_expression(), show_grouping_sets(), show_memoize_info(), show_plan_tlist(), show_sort_group_keys(), and show_tablesample().

3676 {
3677  deparse_namespace *dpns;
3678 
3679  /* Should always have one-entry namespace list for Plan deparsing */
3680  Assert(list_length(dpcontext) == 1);
3681  dpns = (deparse_namespace *) linitial(dpcontext);
3682 
3683  /* Set our attention on the specific plan node passed in */
3684  set_deparse_plan(dpns, plan);
3685  dpns->ancestors = ancestors;
3686 
3687  return dpcontext;
3688 }
static void set_deparse_plan(deparse_namespace *dpns, Plan *plan)
Definition: ruleutils.c:4845
#define linitial(l)
Definition: pg_list.h:174
#define Assert(condition)
Definition: c.h:804
static int list_length(const List *l)
Definition: pg_list.h:149