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

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().

3543 {
3544  deparse_namespace *dpns;
3545  RangeTblEntry *rte;
3546 
3547  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3548 
3549  /* Build a minimal RTE for the rel */
3550  rte = makeNode(RangeTblEntry);
3551  rte->rtekind = RTE_RELATION;
3552  rte->relid = relid;
3553  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3555  rte->alias = makeAlias(aliasname, NIL);
3556  rte->eref = rte->alias;
3557  rte->lateral = false;
3558  rte->inh = false;
3559  rte->inFromCl = true;
3560 
3561  /* Build one-element rtable */
3562  dpns->rtable = list_make1(rte);
3563  dpns->subplans = NIL;
3564  dpns->ctes = NIL;
3565  dpns->appendrels = NULL;
3566  set_rtable_names(dpns, NIL, NULL);
3568 
3569  /* Return a one-deep namespace stack */
3570  return list_make1(dpns);
3571 }
#define NIL
Definition: pg_list.h:65
Alias * alias
Definition: parsenodes.h:1140
#define AccessShareLock
Definition: lockdefs.h:36
AppendRelInfo ** appendrels
Definition: ruleutils.c:163
#define list_make1(x1)
Definition: pg_list.h:206
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:387
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3708
void * palloc0(Size size)
Definition: mcxt.c:1093
#define makeNode(_type_)
Definition: nodes.h:587
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3918
RTEKind rtekind
Definition: parsenodes.h:995
Alias * eref
Definition: parsenodes.h:1141

◆ deparse_context_for_plan_tree()

List* deparse_context_for_plan_tree ( struct PlannedStmt pstmt,
List rtable_names 
)

Definition at line 3587 of file ruleutils.c.

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

Referenced by ExplainPrintPlan().

3588 {
3589  deparse_namespace *dpns;
3590 
3591  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3592 
3593  /* Initialize fields that stay the same across the whole plan tree */
3594  dpns->rtable = pstmt->rtable;
3595  dpns->rtable_names = rtable_names;
3596  dpns->subplans = pstmt->subplans;
3597  dpns->ctes = NIL;
3598  if (pstmt->appendRelations)
3599  {
3600  /* Set up the array, indexed by child relid */
3601  int ntables = list_length(dpns->rtable);
3602  ListCell *lc;
3603 
3604  dpns->appendrels = (AppendRelInfo **)
3605  palloc0((ntables + 1) * sizeof(AppendRelInfo *));
3606  foreach(lc, pstmt->appendRelations)
3607  {
3608  AppendRelInfo *appinfo = lfirst_node(AppendRelInfo, lc);
3609  Index crelid = appinfo->child_relid;
3610 
3611  Assert(crelid > 0 && crelid <= ntables);
3612  Assert(dpns->appendrels[crelid] == NULL);
3613  dpns->appendrels[crelid] = appinfo;
3614  }
3615  }
3616  else
3617  dpns->appendrels = NULL; /* don't need it */
3618 
3619  /*
3620  * Set up column name aliases. We will get rather bogus results for join
3621  * RTEs, but that doesn't matter because plan trees don't contain any join
3622  * alias Vars.
3623  */
3625 
3626  /* Return a one-deep namespace stack */
3627  return list_make1(dpns);
3628 }
#define NIL
Definition: pg_list.h:65
List * rtable_names
Definition: ruleutils.c:159
AppendRelInfo ** appendrels
Definition: ruleutils.c:163
#define list_make1(x1)
Definition: pg_list.h:206
#define lfirst_node(type, lc)
Definition: pg_list.h:172
void * palloc0(Size size)
Definition: mcxt.c:1093
unsigned int Index
Definition: c.h:549
List * subplans
Definition: plannodes.h:73
#define Assert(condition)
Definition: c.h:804
static int list_length(const List *l)
Definition: pg_list.h:149
List * rtable
Definition: plannodes.h:66
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:3918
Index child_relid
Definition: pathnodes.h:2296
List * appendRelations
Definition: plannodes.h:71

◆ deparse_expression()

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

Definition at line 3482 of file ruleutils.c.

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

3484 {
3485  return deparse_expression_pretty(expr, dpcontext, forceprefix,
3486  showimplicit, 0, 0);
3487 }
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:3509

◆ generate_collation_name()

char* generate_collation_name ( Oid  collid)

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

11836 {
11837  HeapTuple tp;
11838  Form_pg_collation colltup;
11839  char *collname;
11840  char *nspname;
11841  char *result;
11842 
11843  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
11844  if (!HeapTupleIsValid(tp))
11845  elog(ERROR, "cache lookup failed for collation %u", collid);
11846  colltup = (Form_pg_collation) GETSTRUCT(tp);
11847  collname = NameStr(colltup->collname);
11848 
11849  if (!CollationIsVisible(collid))
11850  nspname = get_namespace_name(colltup->collnamespace);
11851  else
11852  nspname = NULL;
11853 
11854  result = quote_qualified_identifier(nspname, collname);
11855 
11856  ReleaseSysCache(tp);
11857 
11858  return result;
11859 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3316
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2047
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:11407
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
#define elog(elevel,...)
Definition: elog.h:232
#define NameStr(name)
Definition: c.h:681

◆ generate_opclass_name()

char* generate_opclass_name ( Oid  opclass)

Definition at line 11193 of file ruleutils.c.

References buf, StringInfoData::data, get_opclass_name(), initStringInfo(), and InvalidOid.

Referenced by index_opclass_options().

11194 {
11196 
11197  initStringInfo(&buf);
11198  get_opclass_name(opclass, InvalidOid, &buf);
11199 
11200  return &buf.data[1]; /* get_opclass_name() prepends space */
11201 }
static char * buf
Definition: pg_test_fsync.c:68
static void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf)
Definition: ruleutils.c:11155
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
#define InvalidOid
Definition: postgres_ext.h:36

◆ get_range_partbound_string()

char* get_range_partbound_string ( List bound_datums)

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

11970 {
11971  deparse_context context;
11973  ListCell *cell;
11974  char *sep;
11975 
11976  memset(&context, 0, sizeof(deparse_context));
11977  context.buf = buf;
11978 
11979  appendStringInfoChar(buf, '(');
11980  sep = "";
11981  foreach(cell, bound_datums)
11982  {
11983  PartitionRangeDatum *datum =
11985 
11986  appendStringInfoString(buf, sep);
11987  if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
11988  appendStringInfoString(buf, "MINVALUE");
11989  else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
11990  appendStringInfoString(buf, "MAXVALUE");
11991  else
11992  {
11993  Const *val = castNode(Const, datum->value);
11994 
11995  get_const_expr(val, &context, -1);
11996  }
11997  sep = ", ";
11998  }
11999  appendStringInfoChar(buf, ')');
12000 
12001  return buf->data;
12002 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:608
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
PartitionRangeDatumKind kind
Definition: parsenodes.h:861
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
Definition: ruleutils.c:10180
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
static char * buf
Definition: pg_test_fsync.c:68
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
#define lfirst(lc)
Definition: pg_list.h:169
StringInfo buf
Definition: ruleutils.c:110
long val
Definition: informix.c:664

◆ pg_get_constraintdef_command()

char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 2099 of file ruleutils.c.

References pg_get_constraintdef_worker().

Referenced by RememberConstraintForRebuilding().

2100 {
2101  return pg_get_constraintdef_worker(constraintId, true, 0, false);
2102 }
static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:2108

◆ pg_get_indexdef_columns()

char* pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1174 of file ruleutils.c.

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

Referenced by BuildIndexValueDescription().

1175 {
1176  int prettyFlags;
1177 
1179 
1180  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1181  true, true,
1182  false, false,
1183  prettyFlags, false);
1184 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:90
#define PRETTYFLAG_SCHEMA
Definition: ruleutils.c:91
#define PRETTYFLAG_PAREN
Definition: ruleutils.c:89
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:1193

◆ pg_get_indexdef_string()

char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1164 of file ruleutils.c.

References pg_get_indexdef_worker().

Referenced by RememberIndexForRebuilding().

1165 {
1166  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1167  false, false,
1168  true, true,
1169  0, false);
1170 }
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:1193

◆ pg_get_partconstrdef_string()

char* pg_get_partconstrdef_string ( Oid  partitionId,
char *  aliasname 
)

Definition at line 2043 of file ruleutils.c.

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

Referenced by RI_PartitionRemove_Check().

2044 {
2045  Expr *constr_expr;
2046  List *context;
2047 
2048  constr_expr = get_partition_qual_relid(partitionId);
2049  context = deparse_context_for(aliasname, partitionId);
2050 
2051  return deparse_expression((Node *) constr_expr, context, true, false);
2052 }
Definition: nodes.h:539
List * deparse_context_for(const char *aliasname, Oid relid)
Definition: ruleutils.c:3542
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Definition: ruleutils.c:3482
Expr * get_partition_qual_relid(Oid relid)
Definition: partcache.c:298
Definition: pg_list.h:50

◆ pg_get_partkeydef_columns()

char* pg_get_partkeydef_columns ( Oid  relid,
bool  pretty 
)

Definition at line 1834 of file ruleutils.c.

References pg_get_partkeydef_worker(), PRETTYFLAG_INDENT, PRETTYFLAG_PAREN, and PRETTYFLAG_SCHEMA.

Referenced by ExecBuildSlotPartitionKeyDescription().

1835 {
1836  int prettyFlags;
1837 
1839 
1840  return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
1841 }
#define PRETTYFLAG_INDENT
Definition: ruleutils.c:90
#define PRETTYFLAG_SCHEMA
Definition: ruleutils.c:91
static char * pg_get_partkeydef_worker(Oid relid, int prettyFlags, bool attrsOnly, bool missing_ok)
Definition: ruleutils.c:1847
#define PRETTYFLAG_PAREN
Definition: ruleutils.c:89

◆ pg_get_statisticsobjdef_string()

char* pg_get_statisticsobjdef_string ( Oid  statextid)

Definition at line 1530 of file ruleutils.c.

References pg_get_statisticsobj_worker().

Referenced by RememberStatisticsForRebuilding().

1531 {
1532  return pg_get_statisticsobj_worker(statextid, false, false);
1533 }
static char * pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
Definition: ruleutils.c:1557

◆ select_rtable_names_for_explain()

List* select_rtable_names_for_explain ( List rtable,
Bitmapset rels_used 
)

Definition at line 3679 of file ruleutils.c.

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().

3680 {
3681  deparse_namespace dpns;
3682 
3683  memset(&dpns, 0, sizeof(dpns));
3684  dpns.rtable = rtable;
3685  dpns.subplans = NIL;
3686  dpns.ctes = NIL;
3687  dpns.appendrels = NULL;
3688  set_rtable_names(&dpns, NIL, rels_used);
3689  /* We needn't bother computing column aliases yet */
3690 
3691  return dpns.rtable_names;
3692 }
#define NIL
Definition: pg_list.h:65
List * rtable_names
Definition: ruleutils.c:159
AppendRelInfo ** appendrels
Definition: ruleutils.c:163
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3708

◆ set_deparse_context_plan()

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

Definition at line 3656 of file ruleutils.c.

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

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

3657 {
3658  deparse_namespace *dpns;
3659 
3660  /* Should always have one-entry namespace list for Plan deparsing */
3661  Assert(list_length(dpcontext) == 1);
3662  dpns = (deparse_namespace *) linitial(dpcontext);
3663 
3664  /* Set our attention on the specific plan node passed in */
3665  set_deparse_plan(dpns, plan);
3666  dpns->ancestors = ancestors;
3667 
3668  return dpcontext;
3669 }
static void set_deparse_plan(deparse_namespace *dpns, Plan *plan)
Definition: ruleutils.c:4826
#define linitial(l)
Definition: pg_list.h:174
#define Assert(condition)
Definition: c.h:804
static int list_length(const List *l)
Definition: pg_list.h:149