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_rtable (List *rtable, List *rtable_names)
 
Listset_deparse_context_planstate (List *dpcontext, Node *planstate, List *ancestors)
 
Listselect_rtable_names_for_explain (List *rtable, Bitmapset *rels_used)
 
char * generate_collation_name (Oid collid)
 
char * get_range_partbound_string (List *bound_datums)
 

Function Documentation

◆ deparse_context_for()

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

Definition at line 3256 of file ruleutils.c.

References AccessShareLock, RangeTblEntry::alias, 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(), and set_simple_column_names().

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(), transformPartitionBound(), and transformPartitionRangeBounds().

3257 {
3258  deparse_namespace *dpns;
3259  RangeTblEntry *rte;
3260 
3261  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3262 
3263  /* Build a minimal RTE for the rel */
3264  rte = makeNode(RangeTblEntry);
3265  rte->rtekind = RTE_RELATION;
3266  rte->relid = relid;
3267  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3269  rte->alias = makeAlias(aliasname, NIL);
3270  rte->eref = rte->alias;
3271  rte->lateral = false;
3272  rte->inh = false;
3273  rte->inFromCl = true;
3274 
3275  /* Build one-element rtable */
3276  dpns->rtable = list_make1(rte);
3277  dpns->ctes = NIL;
3278  set_rtable_names(dpns, NIL, NULL);
3280 
3281  /* Return a one-deep namespace stack */
3282  return list_make1(dpns);
3283 }
#define NIL
Definition: pg_list.h:65
Alias * alias
Definition: parsenodes.h:1091
#define AccessShareLock
Definition: lockdefs.h:36
#define list_make1(x1)
Definition: pg_list.h:227
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:385
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3401
void * palloc0(Size size)
Definition: mcxt.c:980
#define makeNode(_type_)
Definition: nodes.h:573
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3614
RTEKind rtekind
Definition: parsenodes.h:974
Alias * eref
Definition: parsenodes.h:1092

◆ deparse_context_for_plan_rtable()

List* deparse_context_for_plan_rtable ( List rtable,
List rtable_names 
)

Definition at line 3299 of file ruleutils.c.

References deparse_namespace::ctes, list_make1, NIL, palloc0(), deparse_namespace::rtable, deparse_namespace::rtable_names, and set_simple_column_names().

Referenced by ExplainPrintPlan().

3300 {
3301  deparse_namespace *dpns;
3302 
3303  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3304 
3305  /* Initialize fields that stay the same across the whole plan tree */
3306  dpns->rtable = rtable;
3307  dpns->rtable_names = rtable_names;
3308  dpns->ctes = NIL;
3309 
3310  /*
3311  * Set up column name aliases. We will get rather bogus results for join
3312  * RTEs, but that doesn't matter because plan trees don't contain any join
3313  * alias Vars.
3314  */
3316 
3317  /* Return a one-deep namespace stack */
3318  return list_make1(dpns);
3319 }
#define NIL
Definition: pg_list.h:65
List * rtable_names
Definition: ruleutils.c:153
#define list_make1(x1)
Definition: pg_list.h:227
void * palloc0(Size size)
Definition: mcxt.c:980
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3614

◆ deparse_expression()

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

Definition at line 3197 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_plan_tlist(), show_sort_group_keys(), show_tablesample(), transformPartitionBound(), and transformPartitionRangeBounds().

3199 {
3200  return deparse_expression_pretty(expr, dpcontext, forceprefix,
3201  showimplicit, 0, 0);
3202 }
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:3224

◆ generate_collation_name()

char* generate_collation_name ( Oid  collid)

Definition at line 11156 of file ruleutils.c.

References CollationIsVisible(), COLLOID, elog, ERROR, get_namespace_name(), 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().

11157 {
11158  HeapTuple tp;
11159  Form_pg_collation colltup;
11160  char *collname;
11161  char *nspname;
11162  char *result;
11163 
11164  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
11165  if (!HeapTupleIsValid(tp))
11166  elog(ERROR, "cache lookup failed for collation %u", collid);
11167  colltup = (Form_pg_collation) GETSTRUCT(tp);
11168  collname = NameStr(colltup->collname);
11169 
11170  if (!CollationIsVisible(collid))
11171  nspname = get_namespace_name(colltup->collnamespace);
11172  else
11173  nspname = NULL;
11174 
11175  result = quote_qualified_identifier(nspname, collname);
11176 
11177  ReleaseSysCache(tp);
11178 
11179  return result;
11180 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3094
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2040
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10724
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
#define elog(elevel,...)
Definition: elog.h:228
#define NameStr(name)
Definition: c.h:616

◆ get_range_partbound_string()

char* get_range_partbound_string ( List bound_datums)

Definition at line 11281 of file ruleutils.c.

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

Referenced by check_new_partition_bound(), and get_rule_expr().

11282 {
11283  deparse_context context;
11285  ListCell *cell;
11286  char *sep;
11287 
11288  memset(&context, 0, sizeof(deparse_context));
11289  context.buf = buf;
11290 
11291  appendStringInfoString(buf, "(");
11292  sep = "";
11293  foreach(cell, bound_datums)
11294  {
11295  PartitionRangeDatum *datum =
11297 
11298  appendStringInfoString(buf, sep);
11299  if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
11300  appendStringInfoString(buf, "MINVALUE");
11301  else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
11302  appendStringInfoString(buf, "MAXVALUE");
11303  else
11304  {
11305  Const *val = castNode(Const, datum->value);
11306 
11307  get_const_expr(val, &context, -1);
11308  }
11309  sep = ", ";
11310  }
11311  appendStringInfoChar(buf, ')');
11312 
11313  return buf->data;
11314 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
PartitionRangeDatumKind kind
Definition: parsenodes.h:845
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
Definition: ruleutils.c:9518
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
static char * buf
Definition: pg_test_fsync.c:67
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
#define lfirst(lc)
Definition: pg_list.h:190
StringInfo buf
Definition: ruleutils.c:111
long val
Definition: informix.c:664

◆ pg_get_constraintdef_command()

char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 1900 of file ruleutils.c.

References pg_get_constraintdef_worker().

Referenced by RememberConstraintForRebuilding().

1901 {
1902  return pg_get_constraintdef_worker(constraintId, true, 0, false);
1903 }
static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:1909

◆ pg_get_indexdef_columns()

char* pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1153 of file ruleutils.c.

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

Referenced by BuildIndexValueDescription().

1154 {
1155  int prettyFlags;
1156 
1158 
1159  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1160  true, true,
1161  false, false,
1162  prettyFlags, false);
1163 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:91
#define PRETTYFLAG_SCHEMA
Definition: ruleutils.c:92
#define PRETTYFLAG_PAREN
Definition: ruleutils.c:90
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:1172

◆ pg_get_indexdef_string()

char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1143 of file ruleutils.c.

References pg_get_indexdef_worker().

Referenced by RememberIndexForRebuilding().

1144 {
1145  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1146  false, false,
1147  true, true,
1148  0, false);
1149 }
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:1172

◆ pg_get_partconstrdef_string()

char* pg_get_partconstrdef_string ( Oid  partitionId,
char *  aliasname 
)

Definition at line 1844 of file ruleutils.c.

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

Referenced by RI_PartitionRemove_Check().

1845 {
1846  Expr *constr_expr;
1847  List *context;
1848 
1849  constr_expr = get_partition_qual_relid(partitionId);
1850  context = deparse_context_for(aliasname, partitionId);
1851 
1852  return deparse_expression((Node *) constr_expr, context, true, false);
1853 }
Definition: nodes.h:525
List * deparse_context_for(const char *aliasname, Oid relid)
Definition: ruleutils.c:3256
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Definition: ruleutils.c:3197
Expr * get_partition_qual_relid(Oid relid)
Definition: partcache.c:278
Definition: pg_list.h:50

◆ pg_get_partkeydef_columns()

char* pg_get_partkeydef_columns ( Oid  relid,
bool  pretty 
)

Definition at line 1635 of file ruleutils.c.

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

Referenced by ExecBuildSlotPartitionKeyDescription().

1636 {
1637  int prettyFlags;
1638 
1640 
1641  return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
1642 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:91
#define PRETTYFLAG_SCHEMA
Definition: ruleutils.c:92
static char * pg_get_partkeydef_worker(Oid relid, int prettyFlags, bool attrsOnly, bool missing_ok)
Definition: ruleutils.c:1648
#define PRETTYFLAG_PAREN
Definition: ruleutils.c:90

◆ select_rtable_names_for_explain()

List* select_rtable_names_for_explain ( List rtable,
Bitmapset rels_used 
)

Definition at line 3374 of file ruleutils.c.

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

Referenced by ExplainPrintPlan().

3375 {
3376  deparse_namespace dpns;
3377 
3378  memset(&dpns, 0, sizeof(dpns));
3379  dpns.rtable = rtable;
3380  dpns.ctes = NIL;
3381  set_rtable_names(&dpns, NIL, rels_used);
3382  /* We needn't bother computing column aliases yet */
3383 
3384  return dpns.rtable_names;
3385 }
#define NIL
Definition: pg_list.h:65
List * rtable_names
Definition: ruleutils.c:153
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3401

◆ set_deparse_context_planstate()

List* set_deparse_context_planstate ( List dpcontext,
Node planstate,
List ancestors 
)

Definition at line 3350 of file ruleutils.c.

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

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

3352 {
3353  deparse_namespace *dpns;
3354 
3355  /* Should always have one-entry namespace list for Plan deparsing */
3356  Assert(list_length(dpcontext) == 1);
3357  dpns = (deparse_namespace *) linitial(dpcontext);
3358 
3359  /* Set our attention on the specific plan node passed in */
3360  set_deparse_planstate(dpns, (PlanState *) planstate);
3361  dpns->ancestors = ancestors;
3362 
3363  return dpcontext;
3364 }
static void set_deparse_planstate(deparse_namespace *dpns, PlanState *ps)
Definition: ruleutils.c:4638
#define linitial(l)
Definition: pg_list.h:195
#define Assert(condition)
Definition: c.h:739
static int list_length(const List *l)
Definition: pg_list.h:169