PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

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

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

3045 {
3046  deparse_namespace *dpns;
3047  RangeTblEntry *rte;
3048 
3049  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3050 
3051  /* Build a minimal RTE for the rel */
3052  rte = makeNode(RangeTblEntry);
3053  rte->rtekind = RTE_RELATION;
3054  rte->relid = relid;
3055  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3056  rte->alias = makeAlias(aliasname, NIL);
3057  rte->eref = rte->alias;
3058  rte->lateral = false;
3059  rte->inh = false;
3060  rte->inFromCl = true;
3061 
3062  /* Build one-element rtable */
3063  dpns->rtable = list_make1(rte);
3064  dpns->ctes = NIL;
3065  set_rtable_names(dpns, NIL, NULL);
3067 
3068  /* Return a one-deep namespace stack */
3069  return list_make1(dpns);
3070 }
#define NIL
Definition: pg_list.h:69
Alias * alias
Definition: parsenodes.h:1048
#define list_make1(x1)
Definition: pg_list.h:139
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:384
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3188
void * palloc0(Size size)
Definition: mcxt.c:877
#define makeNode(_type_)
Definition: nodes.h:557
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3401
RTEKind rtekind
Definition: parsenodes.h:945
Alias * eref
Definition: parsenodes.h:1049
#define RELKIND_RELATION
Definition: pg_class.h:160
List* deparse_context_for_plan_rtable ( List rtable,
List rtable_names 
)

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

3087 {
3088  deparse_namespace *dpns;
3089 
3090  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3091 
3092  /* Initialize fields that stay the same across the whole plan tree */
3093  dpns->rtable = rtable;
3094  dpns->rtable_names = rtable_names;
3095  dpns->ctes = NIL;
3096 
3097  /*
3098  * Set up column name aliases. We will get rather bogus results for join
3099  * RTEs, but that doesn't matter because plan trees don't contain any join
3100  * alias Vars.
3101  */
3103 
3104  /* Return a one-deep namespace stack */
3105  return list_make1(dpns);
3106 }
#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:877
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3401
char* deparse_expression ( Node expr,
List dpcontext,
bool  forceprefix,
bool  showimplicit 
)

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

2987 {
2988  return deparse_expression_pretty(expr, dpcontext, forceprefix,
2989  showimplicit, 0, 0);
2990 }
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:3012
char* generate_collation_name ( Oid  collid)

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

10799 {
10800  HeapTuple tp;
10801  Form_pg_collation colltup;
10802  char *collname;
10803  char *nspname;
10804  char *result;
10805 
10806  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
10807  if (!HeapTupleIsValid(tp))
10808  elog(ERROR, "cache lookup failed for collation %u", collid);
10809  colltup = (Form_pg_collation) GETSTRUCT(tp);
10810  collname = NameStr(colltup->collname);
10811 
10812  if (!CollationIsVisible(collid))
10813  nspname = get_namespace_name(colltup->collnamespace);
10814  else
10815  nspname = NULL;
10816 
10817  result = quote_qualified_identifier(nspname, collname);
10818 
10819  ReleaseSysCache(tp);
10820 
10821  return result;
10822 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:159
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2008
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10476
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:52
#define NameStr(name)
Definition: c.h:493
#define elog
Definition: elog.h:219
char* get_range_partbound_string ( List bound_datums)

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

10924 {
10925  deparse_context context;
10927  ListCell *cell;
10928  char *sep;
10929 
10930  memset(&context, 0, sizeof(deparse_context));
10931  context.buf = buf;
10932 
10933  appendStringInfoString(buf, "(");
10934  sep = "";
10935  foreach(cell, bound_datums)
10936  {
10937  PartitionRangeDatum *datum =
10939 
10940  appendStringInfoString(buf, sep);
10941  if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
10942  appendStringInfoString(buf, "MINVALUE");
10943  else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
10944  appendStringInfoString(buf, "MAXVALUE");
10945  else
10946  {
10947  Const *val = castNode(Const, datum->value);
10948 
10949  get_const_expr(val, &context, -1);
10950  }
10951  sep = ", ";
10952  }
10953  appendStringInfoChar(buf, ')');
10954 
10955  return buf->data;
10956 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
StringInfo makeStringInfo(void)
Definition: stringinfo.c:28
PartitionRangeDatumKind kind
Definition: parsenodes.h:828
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
Definition: ruleutils.c:9257
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
char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 1813 of file ruleutils.c.

References pg_get_constraintdef_worker().

Referenced by ATExecAlterColumnType().

1814 {
1815  return pg_get_constraintdef_worker(constraintId, true, 0, false);
1816 }
static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:1822
char* pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1130 of file ruleutils.c.

References pg_get_indexdef_worker(), PRETTYFLAG_INDENT, and PRETTYFLAG_PAREN.

Referenced by BuildIndexValueDescription().

1131 {
1132  int prettyFlags;
1133 
1134  prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT;
1135  return pg_get_indexdef_worker(indexrelid, 0, NULL, true, false,
1136  prettyFlags, false);
1137 }
#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:1146
char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1123 of file ruleutils.c.

References pg_get_indexdef_worker().

Referenced by ATExecAlterColumnType().

1124 {
1125  return pg_get_indexdef_worker(indexrelid, 0, NULL, false, true, 0, false);
1126 }
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:1146
char* pg_get_partkeydef_columns ( Oid  relid,
bool  pretty 
)

Definition at line 1571 of file ruleutils.c.

References pg_get_partkeydef_worker(), PRETTYFLAG_INDENT, and PRETTYFLAG_PAREN.

Referenced by ExecBuildSlotPartitionKeyDescription().

1572 {
1573  int prettyFlags;
1574 
1575  prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT;
1576  return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
1577 }
#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:1583
#define PRETTYFLAG_PAREN
Definition: ruleutils.c:89
List* select_rtable_names_for_explain ( List rtable,
Bitmapset rels_used 
)

Definition at line 3161 of file ruleutils.c.

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

Referenced by ExplainPrintPlan().

3162 {
3163  deparse_namespace dpns;
3164 
3165  memset(&dpns, 0, sizeof(dpns));
3166  dpns.rtable = rtable;
3167  dpns.ctes = NIL;
3168  set_rtable_names(&dpns, NIL, rels_used);
3169  /* We needn't bother computing column aliases yet */
3170 
3171  return dpns.rtable_names;
3172 }
#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:3188
List* set_deparse_context_planstate ( List dpcontext,
Node planstate,
List ancestors 
)

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

3139 {
3140  deparse_namespace *dpns;
3141 
3142  /* Should always have one-entry namespace list for Plan deparsing */
3143  Assert(list_length(dpcontext) == 1);
3144  dpns = (deparse_namespace *) linitial(dpcontext);
3145 
3146  /* Set our attention on the specific plan node passed in */
3147  set_deparse_planstate(dpns, (PlanState *) planstate);
3148  dpns->ancestors = ancestors;
3149 
3150  return dpcontext;
3151 }
static void set_deparse_planstate(deparse_namespace *dpns, PlanState *ps)
Definition: ruleutils.c:4425
#define linitial(l)
Definition: pg_list.h:111
#define Assert(condition)
Definition: c.h:664
static int list_length(const List *l)
Definition: pg_list.h:89