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_querydef (Query *query, 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_tree (struct PlannedStmt *pstmt, List *rtable_names)
 
Listset_deparse_context_plan (List *dpcontext, struct Plan *plan, List *ancestors)
 
Listselect_rtable_names_for_explain (List *rtable, Bitmapset *rels_used)
 
char * generate_collation_name (Oid collid)
 
char * generate_opclass_name (Oid opclass)
 
char * get_range_partbound_string (List *bound_datums)
 
char * pg_get_statisticsobjdef_string (Oid statextid)
 

Function Documentation

◆ deparse_context_for()

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

Definition at line 3667 of file ruleutils.c.

3668 {
3669  deparse_namespace *dpns;
3670  RangeTblEntry *rte;
3671 
3672  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3673 
3674  /* Build a minimal RTE for the rel */
3675  rte = makeNode(RangeTblEntry);
3676  rte->rtekind = RTE_RELATION;
3677  rte->relid = relid;
3678  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3680  rte->alias = makeAlias(aliasname, NIL);
3681  rte->eref = rte->alias;
3682  rte->lateral = false;
3683  rte->inh = false;
3684  rte->inFromCl = true;
3685 
3686  /* Build one-element rtable */
3687  dpns->rtable = list_make1(rte);
3688  dpns->subplans = NIL;
3689  dpns->ctes = NIL;
3690  dpns->appendrels = NULL;
3691  set_rtable_names(dpns, NIL, NULL);
3693 
3694  /* Return a one-deep namespace stack */
3695  return list_make1(dpns);
3696 }
#define AccessShareLock
Definition: lockdefs.h:36
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:388
void * palloc0(Size size)
Definition: mcxt.c:1099
#define makeNode(_type_)
Definition: nodes.h:622
@ RTE_RELATION
Definition: parsenodes.h:999
#define NIL
Definition: pg_list.h:66
#define list_make1(x1)
Definition: pg_list.h:210
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:4043
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3833
Alias * eref
Definition: parsenodes.h:1162
Alias * alias
Definition: parsenodes.h:1161
RTEKind rtekind
Definition: parsenodes.h:1016
AppendRelInfo ** appendrels
Definition: ruleutils.c:168

References AccessShareLock, RangeTblEntry::alias, deparse_namespace::appendrels, 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(), set_simple_column_names(), and deparse_namespace::subplans.

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(), pg_get_statisticsobj_worker(), pg_get_statisticsobjdef_expressions(), transformPartitionBound(), and transformPartitionRangeBounds().

◆ deparse_context_for_plan_tree()

List* deparse_context_for_plan_tree ( struct PlannedStmt pstmt,
List rtable_names 
)

Definition at line 3712 of file ruleutils.c.

3713 {
3714  deparse_namespace *dpns;
3715 
3716  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3717 
3718  /* Initialize fields that stay the same across the whole plan tree */
3719  dpns->rtable = pstmt->rtable;
3720  dpns->rtable_names = rtable_names;
3721  dpns->subplans = pstmt->subplans;
3722  dpns->ctes = NIL;
3723  if (pstmt->appendRelations)
3724  {
3725  /* Set up the array, indexed by child relid */
3726  int ntables = list_length(dpns->rtable);
3727  ListCell *lc;
3728 
3729  dpns->appendrels = (AppendRelInfo **)
3730  palloc0((ntables + 1) * sizeof(AppendRelInfo *));
3731  foreach(lc, pstmt->appendRelations)
3732  {
3733  AppendRelInfo *appinfo = lfirst_node(AppendRelInfo, lc);
3734  Index crelid = appinfo->child_relid;
3735 
3736  Assert(crelid > 0 && crelid <= ntables);
3737  Assert(dpns->appendrels[crelid] == NULL);
3738  dpns->appendrels[crelid] = appinfo;
3739  }
3740  }
3741  else
3742  dpns->appendrels = NULL; /* don't need it */
3743 
3744  /*
3745  * Set up column name aliases. We will get rather bogus results for join
3746  * RTEs, but that doesn't matter because plan trees don't contain any join
3747  * alias Vars.
3748  */
3750 
3751  /* Return a one-deep namespace stack */
3752  return list_make1(dpns);
3753 }
unsigned int Index
Definition: c.h:560
Assert(fmt[strlen(fmt) - 1] !='\n')
#define lfirst_node(type, lc)
Definition: pg_list.h:174
static int list_length(const List *l)
Definition: pg_list.h:150
Index child_relid
Definition: pathnodes.h:2539
List * appendRelations
Definition: plannodes.h:72
List * subplans
Definition: plannodes.h:74
List * rtable
Definition: plannodes.h:67
List * rtable_names
Definition: ruleutils.c:164

References PlannedStmt::appendRelations, deparse_namespace::appendrels, Assert(), AppendRelInfo::child_relid, deparse_namespace::ctes, lfirst_node, list_length(), list_make1, NIL, palloc0(), deparse_namespace::rtable, PlannedStmt::rtable, deparse_namespace::rtable_names, set_simple_column_names(), deparse_namespace::subplans, and PlannedStmt::subplans.

Referenced by ExplainPrintPlan().

◆ deparse_expression()

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

Definition at line 3607 of file ruleutils.c.

3609 {
3610  return deparse_expression_pretty(expr, dpcontext, forceprefix,
3611  showimplicit, 0, 0);
3612 }
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:3634

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_memoize_info(), show_plan_tlist(), show_sort_group_keys(), show_tablesample(), transformPartitionBound(), and transformPartitionRangeBounds().

◆ generate_collation_name()

char* generate_collation_name ( Oid  collid)

Definition at line 12701 of file ruleutils.c.

12702 {
12703  HeapTuple tp;
12704  Form_pg_collation colltup;
12705  char *collname;
12706  char *nspname;
12707  char *result;
12708 
12709  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
12710  if (!HeapTupleIsValid(tp))
12711  elog(ERROR, "cache lookup failed for collation %u", collid);
12712  colltup = (Form_pg_collation) GETSTRUCT(tp);
12713  collname = NameStr(colltup->collname);
12714 
12715  if (!CollationIsVisible(collid))
12716  nspname = get_namespace_name_or_temp(colltup->collnamespace);
12717  else
12718  nspname = NULL;
12719 
12720  result = quote_qualified_identifier(nspname, collname);
12721 
12722  ReleaseSysCache(tp);
12723 
12724  return result;
12725 }
#define NameStr(name)
Definition: c.h:692
#define ERROR
Definition: elog.h:33
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3350
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2094
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:57
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:12273
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1221
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1173
@ COLLOID
Definition: syscache.h:50

References CollationIsVisible(), COLLOID, elog(), ERROR, get_namespace_name_or_temp(), 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().

◆ generate_opclass_name()

char* generate_opclass_name ( Oid  opclass)

Definition at line 12059 of file ruleutils.c.

12060 {
12062 
12063  initStringInfo(&buf);
12064  get_opclass_name(opclass, InvalidOid, &buf);
12065 
12066  return &buf.data[1]; /* get_opclass_name() prepends space */
12067 }
static char * buf
Definition: pg_test_fsync.c:67
#define InvalidOid
Definition: postgres_ext.h:36
static void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf)
Definition: ruleutils.c:12021
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

References buf, get_opclass_name(), initStringInfo(), and InvalidOid.

Referenced by index_opclass_options().

◆ get_range_partbound_string()

char* get_range_partbound_string ( List bound_datums)

Definition at line 12834 of file ruleutils.c.

12835 {
12836  deparse_context context;
12838  ListCell *cell;
12839  char *sep;
12840 
12841  memset(&context, 0, sizeof(deparse_context));
12842  context.buf = buf;
12843 
12844  appendStringInfoChar(buf, '(');
12845  sep = "";
12846  foreach(cell, bound_datums)
12847  {
12848  PartitionRangeDatum *datum =
12850 
12852  if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
12853  appendStringInfoString(buf, "MINVALUE");
12854  else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
12855  appendStringInfoString(buf, "MAXVALUE");
12856  else
12857  {
12858  Const *val = castNode(Const, datum->value);
12859 
12860  get_const_expr(val, &context, -1);
12861  }
12862  sep = ", ";
12863  }
12864  appendStringInfoChar(buf, ')');
12865 
12866  return buf->data;
12867 }
long val
Definition: informix.c:664
#define castNode(_type_, nodeptr)
Definition: nodes.h:643
@ PARTITION_RANGE_DATUM_MAXVALUE
Definition: parsenodes.h:875
@ PARTITION_RANGE_DATUM_MINVALUE
Definition: parsenodes.h:873
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
Definition: ruleutils.c:10781
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
PartitionRangeDatumKind kind
Definition: parsenodes.h:882
StringInfo buf
Definition: ruleutils.c:115

References appendStringInfoChar(), appendStringInfoString(), deparse_context::buf, buf, castNode, get_const_expr(), PartitionRangeDatum::kind, lfirst_node, makeStringInfo(), PARTITION_RANGE_DATUM_MAXVALUE, PARTITION_RANGE_DATUM_MINVALUE, val, and PartitionRangeDatum::value.

Referenced by check_new_partition_bound(), and get_rule_expr().

◆ pg_get_constraintdef_command()

char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 2149 of file ruleutils.c.

2150 {
2151  return pg_get_constraintdef_worker(constraintId, true, 0, false);
2152 }
static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:2158

References pg_get_constraintdef_worker().

Referenced by RememberConstraintForRebuilding().

◆ pg_get_indexdef_columns()

char* pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1196 of file ruleutils.c.

1197 {
1198  int prettyFlags;
1199 
1200  prettyFlags = GET_PRETTY_FLAGS(pretty);
1201 
1202  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1203  true, true,
1204  false, false,
1205  prettyFlags, false);
1206 }
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:1215
#define GET_PRETTY_FLAGS(pretty)
Definition: ruleutils.c:94

References GET_PRETTY_FLAGS, and pg_get_indexdef_worker().

Referenced by BuildIndexValueDescription().

◆ pg_get_indexdef_string()

char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1186 of file ruleutils.c.

1187 {
1188  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1189  false, false,
1190  true, true,
1191  0, false);
1192 }

References pg_get_indexdef_worker().

Referenced by RememberIndexForRebuilding().

◆ pg_get_partconstrdef_string()

char* pg_get_partconstrdef_string ( Oid  partitionId,
char *  aliasname 
)

Definition at line 2093 of file ruleutils.c.

2094 {
2095  Expr *constr_expr;
2096  List *context;
2097 
2098  constr_expr = get_partition_qual_relid(partitionId);
2099  context = deparse_context_for(aliasname, partitionId);
2100 
2101  return deparse_expression((Node *) constr_expr, context, true, false);
2102 }
Expr * get_partition_qual_relid(Oid relid)
Definition: partcache.c:298
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Definition: ruleutils.c:3607
List * deparse_context_for(const char *aliasname, Oid relid)
Definition: ruleutils.c:3667
Definition: pg_list.h:52
Definition: nodes.h:575

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

Referenced by RI_PartitionRemove_Check().

◆ pg_get_partkeydef_columns()

char* pg_get_partkeydef_columns ( Oid  relid,
bool  pretty 
)

Definition at line 1884 of file ruleutils.c.

1885 {
1886  int prettyFlags;
1887 
1888  prettyFlags = GET_PRETTY_FLAGS(pretty);
1889 
1890  return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
1891 }
static char * pg_get_partkeydef_worker(Oid relid, int prettyFlags, bool attrsOnly, bool missing_ok)
Definition: ruleutils.c:1897

References GET_PRETTY_FLAGS, and pg_get_partkeydef_worker().

Referenced by ExecBuildSlotPartitionKeyDescription().

◆ pg_get_querydef()

char* pg_get_querydef ( Query query,
bool  pretty 
)

Definition at line 1541 of file ruleutils.c.

1542 {
1544  int prettyFlags;
1545 
1546  prettyFlags = GET_PRETTY_FLAGS(pretty);
1547 
1548  initStringInfo(&buf);
1549 
1550  get_query_def(query, &buf, NIL, NULL, true,
1551  prettyFlags, WRAP_COLUMN_DEFAULT, 0);
1552 
1553  return buf.data;
1554 }
static void get_query_def(Query *query, StringInfo buf, List *parentnamespace, TupleDesc resultDesc, bool colNamesVisible, int prettyFlags, int wrapColumn, int startIndent)
Definition: ruleutils.c:5417
#define WRAP_COLUMN_DEFAULT
Definition: ruleutils.c:99

References buf, GET_PRETTY_FLAGS, get_query_def(), initStringInfo(), NIL, and WRAP_COLUMN_DEFAULT.

◆ pg_get_statisticsobjdef_string()

char* pg_get_statisticsobjdef_string ( Oid  statextid)

Definition at line 1580 of file ruleutils.c.

1581 {
1582  return pg_get_statisticsobj_worker(statextid, false, false);
1583 }
static char * pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
Definition: ruleutils.c:1607

References pg_get_statisticsobj_worker().

Referenced by RememberStatisticsForRebuilding().

◆ select_rtable_names_for_explain()

List* select_rtable_names_for_explain ( List rtable,
Bitmapset rels_used 
)

Definition at line 3804 of file ruleutils.c.

3805 {
3806  deparse_namespace dpns;
3807 
3808  memset(&dpns, 0, sizeof(dpns));
3809  dpns.rtable = rtable;
3810  dpns.subplans = NIL;
3811  dpns.ctes = NIL;
3812  dpns.appendrels = NULL;
3813  set_rtable_names(&dpns, NIL, rels_used);
3814  /* We needn't bother computing column aliases yet */
3815 
3816  return dpns.rtable_names;
3817 }

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

Referenced by ExplainPrintPlan().

◆ set_deparse_context_plan()

List* set_deparse_context_plan ( List dpcontext,
struct Plan plan,
List ancestors 
)

Definition at line 3781 of file ruleutils.c.

3782 {
3783  deparse_namespace *dpns;
3784 
3785  /* Should always have one-entry namespace list for Plan deparsing */
3786  Assert(list_length(dpcontext) == 1);
3787  dpns = (deparse_namespace *) linitial(dpcontext);
3788 
3789  /* Set our attention on the specific plan node passed in */
3790  dpns->ancestors = ancestors;
3791  set_deparse_plan(dpns, plan);
3792 
3793  return dpcontext;
3794 }
#define linitial(l)
Definition: pg_list.h:176
static void set_deparse_plan(deparse_namespace *dpns, Plan *plan)
Definition: ruleutils.c:4951

References deparse_namespace::ancestors, Assert(), linitial, list_length(), and set_deparse_plan().

Referenced by show_expression(), show_grouping_sets(), show_memoize_info(), show_plan_tlist(), show_sort_group_keys(), and show_tablesample().