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

3259 {
3260  deparse_namespace *dpns;
3261  RangeTblEntry *rte;
3262 
3263  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3264 
3265  /* Build a minimal RTE for the rel */
3266  rte = makeNode(RangeTblEntry);
3267  rte->rtekind = RTE_RELATION;
3268  rte->relid = relid;
3269  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3271  rte->alias = makeAlias(aliasname, NIL);
3272  rte->eref = rte->alias;
3273  rte->lateral = false;
3274  rte->inh = false;
3275  rte->inFromCl = true;
3276 
3277  /* Build one-element rtable */
3278  dpns->rtable = list_make1(rte);
3279  dpns->ctes = NIL;
3280  set_rtable_names(dpns, NIL, NULL);
3282 
3283  /* Return a one-deep namespace stack */
3284  return list_make1(dpns);
3285 }
#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:3403
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:3616
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 3301 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().

3302 {
3303  deparse_namespace *dpns;
3304 
3305  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3306 
3307  /* Initialize fields that stay the same across the whole plan tree */
3308  dpns->rtable = rtable;
3309  dpns->rtable_names = rtable_names;
3310  dpns->ctes = NIL;
3311 
3312  /*
3313  * Set up column name aliases. We will get rather bogus results for join
3314  * RTEs, but that doesn't matter because plan trees don't contain any join
3315  * alias Vars.
3316  */
3318 
3319  /* Return a one-deep namespace stack */
3320  return list_make1(dpns);
3321 }
#define NIL
Definition: pg_list.h:65
List * rtable_names
Definition: ruleutils.c:154
#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:3616

◆ deparse_expression()

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

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

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

◆ generate_collation_name()

char* generate_collation_name ( Oid  collid)

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

11145 {
11146  HeapTuple tp;
11147  Form_pg_collation colltup;
11148  char *collname;
11149  char *nspname;
11150  char *result;
11151 
11152  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
11153  if (!HeapTupleIsValid(tp))
11154  elog(ERROR, "cache lookup failed for collation %u", collid);
11155  colltup = (Form_pg_collation) GETSTRUCT(tp);
11156  collname = NameStr(colltup->collname);
11157 
11158  if (!CollationIsVisible(collid))
11159  nspname = get_namespace_name(colltup->collnamespace);
11160  else
11161  nspname = NULL;
11162 
11163  result = quote_qualified_identifier(nspname, collname);
11164 
11165  ReleaseSysCache(tp);
11166 
11167  return result;
11168 }
#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:10712
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1124
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
#define elog(elevel,...)
Definition: elog.h:226
#define NameStr(name)
Definition: c.h:609

◆ get_range_partbound_string()

char* get_range_partbound_string ( List bound_datums)

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

11270 {
11271  deparse_context context;
11273  ListCell *cell;
11274  char *sep;
11275 
11276  memset(&context, 0, sizeof(deparse_context));
11277  context.buf = buf;
11278 
11279  appendStringInfoString(buf, "(");
11280  sep = "";
11281  foreach(cell, bound_datums)
11282  {
11283  PartitionRangeDatum *datum =
11285 
11286  appendStringInfoString(buf, sep);
11287  if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
11288  appendStringInfoString(buf, "MINVALUE");
11289  else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
11290  appendStringInfoString(buf, "MAXVALUE");
11291  else
11292  {
11293  Const *val = castNode(Const, datum->value);
11294 
11295  get_const_expr(val, &context, -1);
11296  }
11297  sep = ", ";
11298  }
11299  appendStringInfoChar(buf, ')');
11300 
11301  return buf->data;
11302 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
StringInfo makeStringInfo(void)
Definition: stringinfo.c:28
PartitionRangeDatumKind kind
Definition: parsenodes.h:845
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
Definition: ruleutils.c:9506
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:163
static char * buf
Definition: pg_test_fsync.c:68
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:175
#define lfirst(lc)
Definition: pg_list.h:190
StringInfo buf
Definition: ruleutils.c:112
long val
Definition: informix.c:684

◆ pg_get_constraintdef_command()

char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 1902 of file ruleutils.c.

References pg_get_constraintdef_worker().

Referenced by RememberConstraintForRebuilding().

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

◆ pg_get_indexdef_columns()

char* pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1155 of file ruleutils.c.

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

Referenced by BuildIndexValueDescription().

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

◆ pg_get_indexdef_string()

char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1145 of file ruleutils.c.

References pg_get_indexdef_worker().

Referenced by RememberIndexForRebuilding().

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

◆ pg_get_partconstrdef_string()

char* pg_get_partconstrdef_string ( Oid  partitionId,
char *  aliasname 
)

Definition at line 1846 of file ruleutils.c.

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

Referenced by RI_PartitionRemove_Check().

1847 {
1848  Expr *constr_expr;
1849  List *context;
1850 
1851  constr_expr = get_partition_qual_relid(partitionId);
1852  context = deparse_context_for(aliasname, partitionId);
1853 
1854  return deparse_expression((Node *) constr_expr, context, true, false);
1855 }
Definition: nodes.h:525
List * deparse_context_for(const char *aliasname, Oid relid)
Definition: ruleutils.c:3258
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Definition: ruleutils.c:3199
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 1637 of file ruleutils.c.

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

Referenced by ExecBuildSlotPartitionKeyDescription().

1638 {
1639  int prettyFlags;
1640 
1642 
1643  return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
1644 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:92
#define PRETTYFLAG_SCHEMA
Definition: ruleutils.c:93
static char * pg_get_partkeydef_worker(Oid relid, int prettyFlags, bool attrsOnly, bool missing_ok)
Definition: ruleutils.c:1650
#define PRETTYFLAG_PAREN
Definition: ruleutils.c:91

◆ select_rtable_names_for_explain()

List* select_rtable_names_for_explain ( List rtable,
Bitmapset rels_used 
)

Definition at line 3376 of file ruleutils.c.

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

Referenced by ExplainPrintPlan().

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

◆ set_deparse_context_planstate()

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

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

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