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

References RangeTblEntry::alias, deparse_namespace::ctes, RangeTblEntry::eref, RangeTblEntry::inFromCl, RangeTblEntry::inh, RangeTblEntry::lateral, list_make1, makeAlias(), makeNode, NIL, palloc0(), RangeTblEntry::relid, RangeTblEntry::relkind, RELKIND_RELATION, 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_partition_constraintdef(), pg_get_partkeydef_worker(), StoreAttrDefault(), StoreRelCheck(), and transformPartitionBound().

3068 {
3069  deparse_namespace *dpns;
3070  RangeTblEntry *rte;
3071 
3072  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3073 
3074  /* Build a minimal RTE for the rel */
3075  rte = makeNode(RangeTblEntry);
3076  rte->rtekind = RTE_RELATION;
3077  rte->relid = relid;
3078  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3079  rte->alias = makeAlias(aliasname, NIL);
3080  rte->eref = rte->alias;
3081  rte->lateral = false;
3082  rte->inh = false;
3083  rte->inFromCl = true;
3084 
3085  /* Build one-element rtable */
3086  dpns->rtable = list_make1(rte);
3087  dpns->ctes = NIL;
3088  set_rtable_names(dpns, NIL, NULL);
3090 
3091  /* Return a one-deep namespace stack */
3092  return list_make1(dpns);
3093 }
#define NIL
Definition: pg_list.h:69
Alias * alias
Definition: parsenodes.h:1054
#define list_make1(x1)
Definition: pg_list.h:139
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:386
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3211
void * palloc0(Size size)
Definition: mcxt.c:864
#define makeNode(_type_)
Definition: nodes.h:560
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3424
RTEKind rtekind
Definition: parsenodes.h:951
Alias * eref
Definition: parsenodes.h:1055
#define RELKIND_RELATION
Definition: pg_class.h:160

◆ deparse_context_for_plan_rtable()

List* deparse_context_for_plan_rtable ( List rtable,
List rtable_names 
)

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

3110 {
3111  deparse_namespace *dpns;
3112 
3113  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3114 
3115  /* Initialize fields that stay the same across the whole plan tree */
3116  dpns->rtable = rtable;
3117  dpns->rtable_names = rtable_names;
3118  dpns->ctes = NIL;
3119 
3120  /*
3121  * Set up column name aliases. We will get rather bogus results for join
3122  * RTEs, but that doesn't matter because plan trees don't contain any join
3123  * alias Vars.
3124  */
3126 
3127  /* Return a one-deep namespace stack */
3128  return list_make1(dpns);
3129 }
#define NIL
Definition: pg_list.h:69
List * rtable_names
Definition: ruleutils.c:150
#define list_make1(x1)
Definition: pg_list.h:139
void * palloc0(Size size)
Definition: mcxt.c:864
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3424

◆ deparse_expression()

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

Definition at line 3008 of file ruleutils.c.

References deparse_expression_pretty().

Referenced by AlterDomainDefault(), DefineDomain(), domainAddConstraint(), pg_get_function_arg_default(), print_function_arguments(), show_expression(), show_grouping_set_keys(), show_plan_tlist(), show_sort_group_keys(), show_tablesample(), StoreAttrDefault(), StoreRelCheck(), and transformPartitionBound().

3010 {
3011  return deparse_expression_pretty(expr, dpcontext, forceprefix,
3012  showimplicit, 0, 0);
3013 }
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:3035

◆ generate_collation_name()

char* generate_collation_name ( Oid  collid)

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

10857 {
10858  HeapTuple tp;
10859  Form_pg_collation colltup;
10860  char *collname;
10861  char *nspname;
10862  char *result;
10863 
10864  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
10865  if (!HeapTupleIsValid(tp))
10866  elog(ERROR, "cache lookup failed for collation %u", collid);
10867  colltup = (Form_pg_collation) GETSTRUCT(tp);
10868  collname = NameStr(colltup->collname);
10869 
10870  if (!CollationIsVisible(collid))
10871  nspname = get_namespace_name(colltup->collnamespace);
10872  else
10873  nspname = NULL;
10874 
10875  result = quote_qualified_identifier(nspname, collname);
10876 
10877  ReleaseSysCache(tp);
10878 
10879  return result;
10880 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3066
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2008
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10498
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:52
#define NameStr(name)
Definition: c.h:557
#define elog
Definition: elog.h:219

◆ get_range_partbound_string()

char* get_range_partbound_string ( List bound_datums)

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

10982 {
10983  deparse_context context;
10985  ListCell *cell;
10986  char *sep;
10987 
10988  memset(&context, 0, sizeof(deparse_context));
10989  context.buf = buf;
10990 
10991  appendStringInfoString(buf, "(");
10992  sep = "";
10993  foreach(cell, bound_datums)
10994  {
10995  PartitionRangeDatum *datum =
10997 
10998  appendStringInfoString(buf, sep);
10999  if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
11000  appendStringInfoString(buf, "MINVALUE");
11001  else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
11002  appendStringInfoString(buf, "MAXVALUE");
11003  else
11004  {
11005  Const *val = castNode(Const, datum->value);
11006 
11007  get_const_expr(val, &context, -1);
11008  }
11009  sep = ", ";
11010  }
11011  appendStringInfoChar(buf, ')');
11012 
11013  return buf->data;
11014 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:581
StringInfo makeStringInfo(void)
Definition: stringinfo.c:28
PartitionRangeDatumKind kind
Definition: parsenodes.h:834
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
Definition: ruleutils.c:9279
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
static char * buf
Definition: pg_test_fsync.c:67
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:169
#define lfirst(lc)
Definition: pg_list.h:106
StringInfo buf
Definition: ruleutils.c:108
long val
Definition: informix.c:689

◆ pg_get_constraintdef_command()

char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 1818 of file ruleutils.c.

References pg_get_constraintdef_worker().

Referenced by ATExecAlterColumnType().

1819 {
1820  return pg_get_constraintdef_worker(constraintId, true, 0, false);
1821 }
static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:1827

◆ pg_get_indexdef_columns()

char* pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1131 of file ruleutils.c.

References pg_get_indexdef_worker(), PRETTYFLAG_INDENT, and PRETTYFLAG_PAREN.

Referenced by BuildIndexValueDescription().

1132 {
1133  int prettyFlags;
1134 
1135  prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT;
1136  return pg_get_indexdef_worker(indexrelid, 0, NULL, true, false,
1137  prettyFlags, false);
1138 }
#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 showTblSpc, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:1147

◆ pg_get_indexdef_string()

char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1124 of file ruleutils.c.

References pg_get_indexdef_worker().

Referenced by ATExecAlterColumnType().

1125 {
1126  return pg_get_indexdef_worker(indexrelid, 0, NULL, false, true, 0, false);
1127 }
static char * pg_get_indexdef_worker(Oid indexrelid, int colno, const Oid *excludeOps, bool attrsOnly, bool showTblSpc, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:1147

◆ pg_get_partkeydef_columns()

char* pg_get_partkeydef_columns ( Oid  relid,
bool  pretty 
)

Definition at line 1572 of file ruleutils.c.

References pg_get_partkeydef_worker(), PRETTYFLAG_INDENT, and PRETTYFLAG_PAREN.

Referenced by ExecBuildSlotPartitionKeyDescription().

1573 {
1574  int prettyFlags;
1575 
1576  prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT;
1577  return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
1578 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:90
static char * pg_get_partkeydef_worker(Oid relid, int prettyFlags, bool attrsOnly, bool missing_ok)
Definition: ruleutils.c:1584
#define PRETTYFLAG_PAREN
Definition: ruleutils.c:89

◆ select_rtable_names_for_explain()

List* select_rtable_names_for_explain ( List rtable,
Bitmapset rels_used 
)

Definition at line 3184 of file ruleutils.c.

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

Referenced by ExplainPrintPlan().

3185 {
3186  deparse_namespace dpns;
3187 
3188  memset(&dpns, 0, sizeof(dpns));
3189  dpns.rtable = rtable;
3190  dpns.ctes = NIL;
3191  set_rtable_names(&dpns, NIL, rels_used);
3192  /* We needn't bother computing column aliases yet */
3193 
3194  return dpns.rtable_names;
3195 }
#define NIL
Definition: pg_list.h:69
List * rtable_names
Definition: ruleutils.c:150
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3211

◆ set_deparse_context_planstate()

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

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

3162 {
3163  deparse_namespace *dpns;
3164 
3165  /* Should always have one-entry namespace list for Plan deparsing */
3166  Assert(list_length(dpcontext) == 1);
3167  dpns = (deparse_namespace *) linitial(dpcontext);
3168 
3169  /* Set our attention on the specific plan node passed in */
3170  set_deparse_planstate(dpns, (PlanState *) planstate);
3171  dpns->ancestors = ancestors;
3172 
3173  return dpcontext;
3174 }
static void set_deparse_planstate(deparse_namespace *dpns, PlanState *ps)
Definition: ruleutils.c:4448
#define linitial(l)
Definition: pg_list.h:111
#define Assert(condition)
Definition: c.h:680
static int list_length(const List *l)
Definition: pg_list.h:89