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 3615 of file ruleutils.c.

3616 {
3617  deparse_namespace *dpns;
3618  RangeTblEntry *rte;
3619 
3620  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3621 
3622  /* Build a minimal RTE for the rel */
3623  rte = makeNode(RangeTblEntry);
3624  rte->rtekind = RTE_RELATION;
3625  rte->relid = relid;
3626  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3628  rte->alias = makeAlias(aliasname, NIL);
3629  rte->eref = rte->alias;
3630  rte->lateral = false;
3631  rte->inh = false;
3632  rte->inFromCl = true;
3633 
3634  /* Build one-element rtable */
3635  dpns->rtable = list_make1(rte);
3636  dpns->subplans = NIL;
3637  dpns->ctes = NIL;
3638  dpns->appendrels = NULL;
3639  set_rtable_names(dpns, NIL, NULL);
3641 
3642  /* Return a one-deep namespace stack */
3643  return list_make1(dpns);
3644 }
#define AccessShareLock
Definition: lockdefs.h:36
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:387
void * palloc0(Size size)
Definition: mcxt.c:1093
#define makeNode(_type_)
Definition: nodes.h:587
@ RTE_RELATION
Definition: parsenodes.h:990
#define NIL
Definition: pg_list.h:65
#define list_make1(x1)
Definition: pg_list.h:206
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3991
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3781
Alias * eref
Definition: parsenodes.h:1153
Alias * alias
Definition: parsenodes.h:1152
RTEKind rtekind
Definition: parsenodes.h:1007
AppendRelInfo ** appendrels
Definition: ruleutils.c:163

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().

◆ deparse_context_for_plan_tree()

List* deparse_context_for_plan_tree ( struct PlannedStmt pstmt,
List rtable_names 
)

Definition at line 3660 of file ruleutils.c.

3661 {
3662  deparse_namespace *dpns;
3663 
3664  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3665 
3666  /* Initialize fields that stay the same across the whole plan tree */
3667  dpns->rtable = pstmt->rtable;
3668  dpns->rtable_names = rtable_names;
3669  dpns->subplans = pstmt->subplans;
3670  dpns->ctes = NIL;
3671  if (pstmt->appendRelations)
3672  {
3673  /* Set up the array, indexed by child relid */
3674  int ntables = list_length(dpns->rtable);
3675  ListCell *lc;
3676 
3677  dpns->appendrels = (AppendRelInfo **)
3678  palloc0((ntables + 1) * sizeof(AppendRelInfo *));
3679  foreach(lc, pstmt->appendRelations)
3680  {
3681  AppendRelInfo *appinfo = lfirst_node(AppendRelInfo, lc);
3682  Index crelid = appinfo->child_relid;
3683 
3684  Assert(crelid > 0 && crelid <= ntables);
3685  Assert(dpns->appendrels[crelid] == NULL);
3686  dpns->appendrels[crelid] = appinfo;
3687  }
3688  }
3689  else
3690  dpns->appendrels = NULL; /* don't need it */
3691 
3692  /*
3693  * Set up column name aliases. We will get rather bogus results for join
3694  * RTEs, but that doesn't matter because plan trees don't contain any join
3695  * alias Vars.
3696  */
3698 
3699  /* Return a one-deep namespace stack */
3700  return list_make1(dpns);
3701 }
unsigned int Index
Definition: c.h:549
Assert(fmt[strlen(fmt) - 1] !='\n')
#define lfirst_node(type, lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:149
Index child_relid
Definition: pathnodes.h:2311
List * appendRelations
Definition: plannodes.h:71
List * subplans
Definition: plannodes.h:73
List * rtable
Definition: plannodes.h:66
List * rtable_names
Definition: ruleutils.c:159

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

Referenced by ExplainPrintPlan().

◆ deparse_expression()

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

Definition at line 3555 of file ruleutils.c.

3557 {
3558  return deparse_expression_pretty(expr, dpcontext, forceprefix,
3559  showimplicit, 0, 0);
3560 }
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:3582

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().

◆ generate_collation_name()

char* generate_collation_name ( Oid  collid)

Definition at line 11952 of file ruleutils.c.

11953 {
11954  HeapTuple tp;
11955  Form_pg_collation colltup;
11956  char *collname;
11957  char *nspname;
11958  char *result;
11959 
11960  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
11961  if (!HeapTupleIsValid(tp))
11962  elog(ERROR, "cache lookup failed for collation %u", collid);
11963  colltup = (Form_pg_collation) GETSTRUCT(tp);
11964  collname = NameStr(colltup->collname);
11965 
11966  if (!CollationIsVisible(collid))
11967  nspname = get_namespace_name_or_temp(colltup->collnamespace);
11968  else
11969  nspname = NULL;
11970 
11971  result = quote_qualified_identifier(nspname, collname);
11972 
11973  ReleaseSysCache(tp);
11974 
11975  return result;
11976 }
#define NameStr(name)
Definition: c.h:681
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3340
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2093
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:56
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:11524
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1198
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1150
@ COLLOID
Definition: syscache.h:50

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().

◆ generate_opclass_name()

char* generate_opclass_name ( Oid  opclass)

Definition at line 11310 of file ruleutils.c.

11311 {
11313 
11314  initStringInfo(&buf);
11315  get_opclass_name(opclass, InvalidOid, &buf);
11316 
11317  return &buf.data[1]; /* get_opclass_name() prepends space */
11318 }
static char * buf
Definition: pg_test_fsync.c:70
#define InvalidOid
Definition: postgres_ext.h:36
static void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf)
Definition: ruleutils.c:11272
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

References buf, get_opclass_name(), initStringInfo(), and InvalidOid.

Referenced by index_opclass_options().

◆ get_range_partbound_string()

char* get_range_partbound_string ( List bound_datums)

Definition at line 12086 of file ruleutils.c.

12087 {
12088  deparse_context context;
12090  ListCell *cell;
12091  char *sep;
12092 
12093  memset(&context, 0, sizeof(deparse_context));
12094  context.buf = buf;
12095 
12096  appendStringInfoChar(buf, '(');
12097  sep = "";
12098  foreach(cell, bound_datums)
12099  {
12100  PartitionRangeDatum *datum =
12102 
12104  if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
12105  appendStringInfoString(buf, "MINVALUE");
12106  else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
12107  appendStringInfoString(buf, "MAXVALUE");
12108  else
12109  {
12110  Const *val = castNode(Const, datum->value);
12111 
12112  get_const_expr(val, &context, -1);
12113  }
12114  sep = ", ";
12115  }
12116  appendStringInfoChar(buf, ')');
12117 
12118  return buf->data;
12119 }
long val
Definition: informix.c:664
#define castNode(_type_, nodeptr)
Definition: nodes.h:608
@ PARTITION_RANGE_DATUM_MAXVALUE
Definition: parsenodes.h:866
@ PARTITION_RANGE_DATUM_MINVALUE
Definition: parsenodes.h:864
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
Definition: ruleutils.c:10297
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
PartitionRangeDatumKind kind
Definition: parsenodes.h:873
StringInfo buf
Definition: ruleutils.c:110

References appendStringInfoChar(), appendStringInfoString(), deparse_context::buf, buf, castNode, 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().

◆ pg_get_constraintdef_command()

char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 2103 of file ruleutils.c.

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

References pg_get_constraintdef_worker().

Referenced by RememberConstraintForRebuilding().

◆ pg_get_indexdef_columns()

char* pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1178 of file ruleutils.c.

1179 {
1180  int prettyFlags;
1181 
1183 
1184  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1185  true, true,
1186  false, false,
1187  prettyFlags, false);
1188 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:90
#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:1197
#define PRETTYFLAG_SCHEMA
Definition: ruleutils.c:91

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

Referenced by BuildIndexValueDescription().

◆ pg_get_indexdef_string()

char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1168 of file ruleutils.c.

1169 {
1170  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1171  false, false,
1172  true, true,
1173  0, false);
1174 }

References pg_get_indexdef_worker().

Referenced by RememberIndexForRebuilding().

◆ pg_get_partconstrdef_string()

char* pg_get_partconstrdef_string ( Oid  partitionId,
char *  aliasname 
)

Definition at line 2047 of file ruleutils.c.

2048 {
2049  Expr *constr_expr;
2050  List *context;
2051 
2052  constr_expr = get_partition_qual_relid(partitionId);
2053  context = deparse_context_for(aliasname, partitionId);
2054 
2055  return deparse_expression((Node *) constr_expr, context, true, false);
2056 }
Expr * get_partition_qual_relid(Oid relid)
Definition: partcache.c:298
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Definition: ruleutils.c:3555
List * deparse_context_for(const char *aliasname, Oid relid)
Definition: ruleutils.c:3615
Definition: pg_list.h:51
Definition: nodes.h:540

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

Referenced by RI_PartitionRemove_Check().

◆ pg_get_partkeydef_columns()

char* pg_get_partkeydef_columns ( Oid  relid,
bool  pretty 
)

Definition at line 1838 of file ruleutils.c.

1839 {
1840  int prettyFlags;
1841 
1843 
1844  return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
1845 }
static char * pg_get_partkeydef_worker(Oid relid, int prettyFlags, bool attrsOnly, bool missing_ok)
Definition: ruleutils.c:1851

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

Referenced by ExecBuildSlotPartitionKeyDescription().

◆ pg_get_statisticsobjdef_string()

char* pg_get_statisticsobjdef_string ( Oid  statextid)

Definition at line 1534 of file ruleutils.c.

1535 {
1536  return pg_get_statisticsobj_worker(statextid, false, false);
1537 }
static char * pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
Definition: ruleutils.c:1561

References pg_get_statisticsobj_worker().

Referenced by RememberStatisticsForRebuilding().

◆ select_rtable_names_for_explain()

List* select_rtable_names_for_explain ( List rtable,
Bitmapset rels_used 
)

Definition at line 3752 of file ruleutils.c.

3753 {
3754  deparse_namespace dpns;
3755 
3756  memset(&dpns, 0, sizeof(dpns));
3757  dpns.rtable = rtable;
3758  dpns.subplans = NIL;
3759  dpns.ctes = NIL;
3760  dpns.appendrels = NULL;
3761  set_rtable_names(&dpns, NIL, rels_used);
3762  /* We needn't bother computing column aliases yet */
3763 
3764  return dpns.rtable_names;
3765 }

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().

◆ set_deparse_context_plan()

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

Definition at line 3729 of file ruleutils.c.

3730 {
3731  deparse_namespace *dpns;
3732 
3733  /* Should always have one-entry namespace list for Plan deparsing */
3734  Assert(list_length(dpcontext) == 1);
3735  dpns = (deparse_namespace *) linitial(dpcontext);
3736 
3737  /* Set our attention on the specific plan node passed in */
3738  dpns->ancestors = ancestors;
3739  set_deparse_plan(dpns, plan);
3740 
3741  return dpcontext;
3742 }
#define linitial(l)
Definition: pg_list.h:174
static void set_deparse_plan(deparse_namespace *dpns, Plan *plan)
Definition: ruleutils.c:4899

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().