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_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 2854 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_partkeydef_worker(), StoreAttrDefault(), StoreRelCheck(), and transformPartitionBound().

2855 {
2856  deparse_namespace *dpns;
2857  RangeTblEntry *rte;
2858 
2859  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
2860 
2861  /* Build a minimal RTE for the rel */
2862  rte = makeNode(RangeTblEntry);
2863  rte->rtekind = RTE_RELATION;
2864  rte->relid = relid;
2865  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
2866  rte->alias = makeAlias(aliasname, NIL);
2867  rte->eref = rte->alias;
2868  rte->lateral = false;
2869  rte->inh = false;
2870  rte->inFromCl = true;
2871 
2872  /* Build one-element rtable */
2873  dpns->rtable = list_make1(rte);
2874  dpns->ctes = NIL;
2875  set_rtable_names(dpns, NIL, NULL);
2877 
2878  /* Return a one-deep namespace stack */
2879  return list_make1(dpns);
2880 }
#define NIL
Definition: pg_list.h:69
Alias * alias
Definition: parsenodes.h:960
#define list_make1(x1)
Definition: pg_list.h:133
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:2998
void * palloc0(Size size)
Definition: mcxt.c:920
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3211
RTEKind rtekind
Definition: parsenodes.h:882
Alias * eref
Definition: parsenodes.h:961
#define RELKIND_RELATION
Definition: pg_class.h:160
List* deparse_context_for_plan_rtable ( List rtable,
List rtable_names 
)

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

2897 {
2898  deparse_namespace *dpns;
2899 
2900  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
2901 
2902  /* Initialize fields that stay the same across the whole plan tree */
2903  dpns->rtable = rtable;
2904  dpns->rtable_names = rtable_names;
2905  dpns->ctes = NIL;
2906 
2907  /*
2908  * Set up column name aliases. We will get rather bogus results for join
2909  * RTEs, but that doesn't matter because plan trees don't contain any join
2910  * alias Vars.
2911  */
2913 
2914  /* Return a one-deep namespace stack */
2915  return list_make1(dpns);
2916 }
#define NIL
Definition: pg_list.h:69
List * rtable_names
Definition: ruleutils.c:148
#define list_make1(x1)
Definition: pg_list.h:133
void * palloc0(Size size)
Definition: mcxt.c:920
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3211
char* deparse_expression ( Node expr,
List dpcontext,
bool  forceprefix,
bool  showimplicit 
)

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

2797 {
2798  return deparse_expression_pretty(expr, dpcontext, forceprefix,
2799  showimplicit, 0, 0);
2800 }
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:2822
char* generate_collation_name ( Oid  collid)

Definition at line 10376 of file ruleutils.c.

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

10377 {
10378  HeapTuple tp;
10379  Form_pg_collation colltup;
10380  char *collname;
10381  char *nspname;
10382  char *result;
10383 
10384  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
10385  if (!HeapTupleIsValid(tp))
10386  elog(ERROR, "cache lookup failed for collation %u", collid);
10387  colltup = (Form_pg_collation) GETSTRUCT(tp);
10388  collname = NameStr(colltup->collname);
10389 
10390  if (!CollationIsVisible(collid))
10391  nspname = get_namespace_name(colltup->collnamespace);
10392  else
10393  nspname = NULL;
10394 
10395  result = quote_qualified_identifier(nspname, collname);
10396 
10397  ReleaseSysCache(tp);
10398 
10399  return result;
10400 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3006
bool CollationIsVisible(Oid collid)
Definition: namespace.c:1965
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10054
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:47
#define NameStr(name)
Definition: c.h:495
#define elog
Definition: elog.h:219
char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 1624 of file ruleutils.c.

References pg_get_constraintdef_worker().

Referenced by ATExecAlterColumnType().

1625 {
1626  return pg_get_constraintdef_worker(constraintId, true, 0, false);
1627 }
static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:1633
char* pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1121 of file ruleutils.c.

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

Referenced by BuildIndexValueDescription().

1122 {
1123  int prettyFlags;
1124 
1125  prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : PRETTYFLAG_INDENT;
1126  return pg_get_indexdef_worker(indexrelid, 0, NULL, true, false,
1127  prettyFlags, false);
1128 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:88
#define NULL
Definition: c.h:226
#define PRETTYFLAG_PAREN
Definition: ruleutils.c:87
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:1137
char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1114 of file ruleutils.c.

References NULL, and pg_get_indexdef_worker().

Referenced by ATExecAlterColumnType().

1115 {
1116  return pg_get_indexdef_worker(indexrelid, 0, NULL, false, true, 0, false);
1117 }
#define NULL
Definition: c.h:226
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:1137
List* select_rtable_names_for_explain ( List rtable,
Bitmapset rels_used 
)

Definition at line 2971 of file ruleutils.c.

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

Referenced by ExplainPrintPlan().

2972 {
2973  deparse_namespace dpns;
2974 
2975  memset(&dpns, 0, sizeof(dpns));
2976  dpns.rtable = rtable;
2977  dpns.ctes = NIL;
2978  set_rtable_names(&dpns, NIL, rels_used);
2979  /* We needn't bother computing column aliases yet */
2980 
2981  return dpns.rtable_names;
2982 }
#define NIL
Definition: pg_list.h:69
List * rtable_names
Definition: ruleutils.c:148
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:2998
List* set_deparse_context_planstate ( List dpcontext,
Node planstate,
List ancestors 
)

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

2949 {
2950  deparse_namespace *dpns;
2951 
2952  /* Should always have one-entry namespace list for Plan deparsing */
2953  Assert(list_length(dpcontext) == 1);
2954  dpns = (deparse_namespace *) linitial(dpcontext);
2955 
2956  /* Set our attention on the specific plan node passed in */
2957  set_deparse_planstate(dpns, (PlanState *) planstate);
2958  dpns->ancestors = ancestors;
2959 
2960  return dpcontext;
2961 }
static void set_deparse_planstate(deparse_namespace *dpns, PlanState *ps)
Definition: ruleutils.c:4230
#define linitial(l)
Definition: pg_list.h:110
#define Assert(condition)
Definition: c.h:671
static int list_length(const List *l)
Definition: pg_list.h:89