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)
 

Function Documentation

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

Definition at line 3036 of file ruleutils.c.

References RangeTblEntry::alias, deparse_namespace::ctes, RangeTblEntry::eref, RangeTblEntry::inFromCl, RangeTblEntry::inh, RangeTblEntry::lateral, list_make1, makeAlias(), makeNode, NIL, NULL, 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().

3037 {
3038  deparse_namespace *dpns;
3039  RangeTblEntry *rte;
3040 
3041  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3042 
3043  /* Build a minimal RTE for the rel */
3044  rte = makeNode(RangeTblEntry);
3045  rte->rtekind = RTE_RELATION;
3046  rte->relid = relid;
3047  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3048  rte->alias = makeAlias(aliasname, NIL);
3049  rte->eref = rte->alias;
3050  rte->lateral = false;
3051  rte->inh = false;
3052  rte->inFromCl = true;
3053 
3054  /* Build one-element rtable */
3055  dpns->rtable = list_make1(rte);
3056  dpns->ctes = NIL;
3057  set_rtable_names(dpns, NIL, NULL);
3059 
3060  /* Return a one-deep namespace stack */
3061  return list_make1(dpns);
3062 }
#define NIL
Definition: pg_list.h:69
Alias * alias
Definition: parsenodes.h:1015
#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:3180
void * palloc0(Size size)
Definition: mcxt.c:878
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3393
RTEKind rtekind
Definition: parsenodes.h:929
Alias * eref
Definition: parsenodes.h:1016
#define RELKIND_RELATION
Definition: pg_class.h:160
List* deparse_context_for_plan_rtable ( List rtable,
List rtable_names 
)

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

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

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

2979 {
2980  return deparse_expression_pretty(expr, dpcontext, forceprefix,
2981  showimplicit, 0, 0);
2982 }
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:3004
char* generate_collation_name ( Oid  collid)

Definition at line 10692 of file ruleutils.c.

References CollationIsVisible(), COLLOID, elog, ERROR, get_namespace_name(), GETSTRUCT, HeapTupleIsValid, NameStr, NULL, ObjectIdGetDatum, quote_qualified_identifier(), ReleaseSysCache(), result, 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().

10693 {
10694  HeapTuple tp;
10695  Form_pg_collation colltup;
10696  char *collname;
10697  char *nspname;
10698  char *result;
10699 
10700  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
10701  if (!HeapTupleIsValid(tp))
10702  elog(ERROR, "cache lookup failed for collation %u", collid);
10703  colltup = (Form_pg_collation) GETSTRUCT(tp);
10704  collname = NameStr(colltup->collname);
10705 
10706  if (!CollationIsVisible(collid))
10707  nspname = get_namespace_name(colltup->collnamespace);
10708  else
10709  nspname = NULL;
10710 
10711  result = quote_qualified_identifier(nspname, collname);
10712 
10713  ReleaseSysCache(tp);
10714 
10715  return result;
10716 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
return result
Definition: formatting.c:1632
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#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:1966
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10370
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:52
#define NameStr(name)
Definition: c.h:499
#define elog
Definition: elog.h:219
char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 1806 of file ruleutils.c.

References pg_get_constraintdef_worker().

Referenced by ATExecAlterColumnType().

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

Definition at line 1127 of file ruleutils.c.

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

Referenced by BuildIndexValueDescription().

1128 {
1129  int prettyFlags;
1130 
1131  prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT;
1132  return pg_get_indexdef_worker(indexrelid, 0, NULL, true, false,
1133  prettyFlags, false);
1134 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:90
#define NULL
Definition: c.h:229
#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:1143
char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1120 of file ruleutils.c.

References NULL, and pg_get_indexdef_worker().

Referenced by ATExecAlterColumnType().

1121 {
1122  return pg_get_indexdef_worker(indexrelid, 0, NULL, false, true, 0, false);
1123 }
#define NULL
Definition: c.h:229
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:1143
char* pg_get_partkeydef_columns ( Oid  relid,
bool  pretty 
)

Definition at line 1569 of file ruleutils.c.

References pg_get_partkeydef_worker(), PRETTYFLAG_INDENT, and PRETTYFLAG_PAREN.

Referenced by ExecBuildSlotPartitionKeyDescription().

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

Definition at line 3153 of file ruleutils.c.

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

Referenced by ExplainPrintPlan().

3154 {
3155  deparse_namespace dpns;
3156 
3157  memset(&dpns, 0, sizeof(dpns));
3158  dpns.rtable = rtable;
3159  dpns.ctes = NIL;
3160  set_rtable_names(&dpns, NIL, rels_used);
3161  /* We needn't bother computing column aliases yet */
3162 
3163  return dpns.rtable_names;
3164 }
#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:3180
List* set_deparse_context_planstate ( List dpcontext,
Node planstate,
List ancestors 
)

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

3131 {
3132  deparse_namespace *dpns;
3133 
3134  /* Should always have one-entry namespace list for Plan deparsing */
3135  Assert(list_length(dpcontext) == 1);
3136  dpns = (deparse_namespace *) linitial(dpcontext);
3137 
3138  /* Set our attention on the specific plan node passed in */
3139  set_deparse_planstate(dpns, (PlanState *) planstate);
3140  dpns->ancestors = ancestors;
3141 
3142  return dpcontext;
3143 }
static void set_deparse_planstate(deparse_namespace *dpns, PlanState *ps)
Definition: ruleutils.c:4415
#define linitial(l)
Definition: pg_list.h:111
#define Assert(condition)
Definition: c.h:675
static int list_length(const List *l)
Definition: pg_list.h:89