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.

Macros

#define RULE_INDEXDEF_PRETTY   0x01
 
#define RULE_INDEXDEF_KEYS_ONLY   0x02 /* ignore included attributes */
 

Functions

char * pg_get_indexdef_string (Oid indexrelid)
 
char * pg_get_indexdef_columns (Oid indexrelid, bool pretty)
 
char * pg_get_indexdef_columns_extended (Oid indexrelid, bits16 flags)
 
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)
 
char * get_list_partvalue_string (Const *val)
 

Macro Definition Documentation

◆ RULE_INDEXDEF_KEYS_ONLY

#define RULE_INDEXDEF_KEYS_ONLY   0x02 /* ignore included attributes */

Definition at line 25 of file ruleutils.h.

◆ RULE_INDEXDEF_PRETTY

#define RULE_INDEXDEF_PRETTY   0x01

Definition at line 24 of file ruleutils.h.

Function Documentation

◆ deparse_context_for()

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

Definition at line 3685 of file ruleutils.c.

3686 {
3687  deparse_namespace *dpns;
3688  RangeTblEntry *rte;
3689 
3690  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3691 
3692  /* Build a minimal RTE for the rel */
3693  rte = makeNode(RangeTblEntry);
3694  rte->rtekind = RTE_RELATION;
3695  rte->relid = relid;
3696  rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3697  rte->rellockmode = AccessShareLock;
3698  rte->alias = makeAlias(aliasname, NIL);
3699  rte->eref = rte->alias;
3700  rte->lateral = false;
3701  rte->inh = false;
3702  rte->inFromCl = true;
3703 
3704  /* Build one-element rtable */
3705  dpns->rtable = list_make1(rte);
3706  dpns->subplans = NIL;
3707  dpns->ctes = NIL;
3708  dpns->appendrels = NULL;
3709  set_rtable_names(dpns, NIL, NULL);
3711 
3712  /* Return a one-deep namespace stack */
3713  return list_make1(dpns);
3714 }
#define AccessShareLock
Definition: lockdefs.h:36
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:389
void * palloc0(Size size)
Definition: mcxt.c:1346
#define makeNode(_type_)
Definition: nodes.h:155
@ RTE_RELATION
Definition: parsenodes.h:1028
#define NIL
Definition: pg_list.h:68
#define list_make1(x1)
Definition: pg_list.h:212
static void set_simple_column_names(deparse_namespace *dpns)
Definition: ruleutils.c:4061
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3851
RTEKind rtekind
Definition: parsenodes.h:1057
AppendRelInfo ** appendrels
Definition: ruleutils.c:168

References AccessShareLock, deparse_namespace::appendrels, deparse_namespace::ctes, RangeTblEntry::inh, list_make1, makeAlias(), makeNode, NIL, palloc0(), RangeTblEntry::relid, 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 3730 of file ruleutils.c.

3731 {
3732  deparse_namespace *dpns;
3733 
3734  dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3735 
3736  /* Initialize fields that stay the same across the whole plan tree */
3737  dpns->rtable = pstmt->rtable;
3738  dpns->rtable_names = rtable_names;
3739  dpns->subplans = pstmt->subplans;
3740  dpns->ctes = NIL;
3741  if (pstmt->appendRelations)
3742  {
3743  /* Set up the array, indexed by child relid */
3744  int ntables = list_length(dpns->rtable);
3745  ListCell *lc;
3746 
3747  dpns->appendrels = (AppendRelInfo **)
3748  palloc0((ntables + 1) * sizeof(AppendRelInfo *));
3749  foreach(lc, pstmt->appendRelations)
3750  {
3751  AppendRelInfo *appinfo = lfirst_node(AppendRelInfo, lc);
3752  Index crelid = appinfo->child_relid;
3753 
3754  Assert(crelid > 0 && crelid <= ntables);
3755  Assert(dpns->appendrels[crelid] == NULL);
3756  dpns->appendrels[crelid] = appinfo;
3757  }
3758  }
3759  else
3760  dpns->appendrels = NULL; /* don't need it */
3761 
3762  /*
3763  * Set up column name aliases. We will get rather bogus results for join
3764  * RTEs, but that doesn't matter because plan trees don't contain any join
3765  * alias Vars.
3766  */
3768 
3769  /* Return a one-deep namespace stack */
3770  return list_make1(dpns);
3771 }
#define Assert(condition)
Definition: c.h:858
unsigned int Index
Definition: c.h:614
#define lfirst_node(type, lc)
Definition: pg_list.h:176
static int list_length(const List *l)
Definition: pg_list.h:152
Index child_relid
Definition: pathnodes.h:2958
List * appendRelations
Definition: plannodes.h:80
List * subplans
Definition: plannodes.h:82
List * rtable
Definition: plannodes.h:72
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 3625 of file ruleutils.c.

3627 {
3628  return deparse_expression_pretty(expr, dpcontext, forceprefix,
3629  showimplicit, 0, 0);
3630 }
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:3652

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

13136 {
13137  HeapTuple tp;
13138  Form_pg_collation colltup;
13139  char *collname;
13140  char *nspname;
13141  char *result;
13142 
13143  tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
13144  if (!HeapTupleIsValid(tp))
13145  elog(ERROR, "cache lookup failed for collation %u", collid);
13146  colltup = (Form_pg_collation) GETSTRUCT(tp);
13147  collname = NameStr(colltup->collname);
13148 
13149  if (!CollationIsVisible(collid))
13150  nspname = get_namespace_name_or_temp(colltup->collnamespace);
13151  else
13152  nspname = NULL;
13153 
13154  result = quote_qualified_identifier(nspname, collname);
13155 
13156  ReleaseSysCache(tp);
13157 
13158  return result;
13159 }
#define NameStr(name)
Definition: c.h:746
Oid collid
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3390
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2392
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:58
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:12707
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:266
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:218

References CollationIsVisible(), collid, 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 12493 of file ruleutils.c.

12494 {
12496 
12497  initStringInfo(&buf);
12498  get_opclass_name(opclass, InvalidOid, &buf);
12499 
12500  return &buf.data[1]; /* get_opclass_name() prepends space */
12501 }
static char * buf
Definition: pg_test_fsync.c:73
#define InvalidOid
Definition: postgres_ext.h:36
static void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf)
Definition: ruleutils.c:12455
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

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

Referenced by index_opclass_options().

◆ get_list_partvalue_string()

char* get_list_partvalue_string ( Const val)

Definition at line 13308 of file ruleutils.c.

13309 {
13312 
13313  memset(&context, 0, sizeof(deparse_context));
13314  context.buf = buf;
13315 
13316  get_const_expr(val, &context, -1);
13317 
13318  return buf->data;
13319 }
long val
Definition: informix.c:670
tree context
Definition: radixtree.h:1829
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
Definition: ruleutils.c:11060
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41

References buf, context, get_const_expr(), makeStringInfo(), and val.

Referenced by check_parent_values_in_new_partitions().

◆ get_range_partbound_string()

char* get_range_partbound_string ( List bound_datums)

Definition at line 13268 of file ruleutils.c.

13269 {
13272  ListCell *cell;
13273  char *sep;
13274 
13275  memset(&context, 0, sizeof(deparse_context));
13276  context.buf = buf;
13277 
13278  appendStringInfoChar(buf, '(');
13279  sep = "";
13280  foreach(cell, bound_datums)
13281  {
13282  PartitionRangeDatum *datum =
13284 
13286  if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
13287  appendStringInfoString(buf, "MINVALUE");
13288  else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
13289  appendStringInfoString(buf, "MAXVALUE");
13290  else
13291  {
13292  Const *val = castNode(Const, datum->value);
13293 
13294  get_const_expr(val, &context, -1);
13295  }
13296  sep = ", ";
13297  }
13298  appendStringInfoChar(buf, ')');
13299 
13300  return buf->data;
13301 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
@ PARTITION_RANGE_DATUM_MAXVALUE
Definition: parsenodes.h:926
@ PARTITION_RANGE_DATUM_MINVALUE
Definition: parsenodes.h:924
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:182
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:194
PartitionRangeDatumKind kind
Definition: parsenodes.h:933

References appendStringInfoChar(), appendStringInfoString(), buf, castNode, context, 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(), check_partition_bounds_for_split_range(), and get_rule_expr().

◆ pg_get_constraintdef_command()

char* pg_get_constraintdef_command ( Oid  constraintId)

Definition at line 2168 of file ruleutils.c.

2169 {
2170  return pg_get_constraintdef_worker(constraintId, true, 0, false);
2171 }
static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:2177

References pg_get_constraintdef_worker().

Referenced by RememberConstraintForRebuilding().

◆ pg_get_indexdef_columns()

char* pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1219 of file ruleutils.c.

1220 {
1221  int prettyFlags;
1222 
1223  prettyFlags = GET_PRETTY_FLAGS(pretty);
1224 
1225  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1226  true, true,
1227  false, false,
1228  prettyFlags, false);
1229 }
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:1254
#define GET_PRETTY_FLAGS(pretty)
Definition: ruleutils.c:94

References GET_PRETTY_FLAGS, and pg_get_indexdef_worker().

Referenced by BuildIndexValueDescription().

◆ pg_get_indexdef_columns_extended()

char* pg_get_indexdef_columns_extended ( Oid  indexrelid,
bits16  flags 
)

Definition at line 1233 of file ruleutils.c.

1234 {
1235  bool pretty = ((flags & RULE_INDEXDEF_PRETTY) != 0);
1236  bool keys_only = ((flags & RULE_INDEXDEF_KEYS_ONLY) != 0);
1237  int prettyFlags;
1238 
1239  prettyFlags = GET_PRETTY_FLAGS(pretty);
1240 
1241  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1242  true, keys_only,
1243  false, false,
1244  prettyFlags, false);
1245 }
#define RULE_INDEXDEF_PRETTY
Definition: ruleutils.h:24
#define RULE_INDEXDEF_KEYS_ONLY
Definition: ruleutils.h:25

References GET_PRETTY_FLAGS, pg_get_indexdef_worker(), RULE_INDEXDEF_KEYS_ONLY, and RULE_INDEXDEF_PRETTY.

Referenced by gist_page_items().

◆ pg_get_indexdef_string()

char* pg_get_indexdef_string ( Oid  indexrelid)

Definition at line 1209 of file ruleutils.c.

1210 {
1211  return pg_get_indexdef_worker(indexrelid, 0, NULL,
1212  false, false,
1213  true, true,
1214  0, false);
1215 }

References pg_get_indexdef_worker().

Referenced by RememberIndexForRebuilding().

◆ pg_get_partconstrdef_string()

char* pg_get_partconstrdef_string ( Oid  partitionId,
char *  aliasname 
)

Definition at line 2112 of file ruleutils.c.

2113 {
2114  Expr *constr_expr;
2115  List *context;
2116 
2117  constr_expr = get_partition_qual_relid(partitionId);
2118  context = deparse_context_for(aliasname, partitionId);
2119 
2120  return deparse_expression((Node *) constr_expr, context, true, false);
2121 }
Expr * get_partition_qual_relid(Oid relid)
Definition: partcache.c:299
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Definition: ruleutils.c:3625
List * deparse_context_for(const char *aliasname, Oid relid)
Definition: ruleutils.c:3685
Definition: pg_list.h:54
Definition: nodes.h:129

References context, 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 1908 of file ruleutils.c.

1909 {
1910  int prettyFlags;
1911 
1912  prettyFlags = GET_PRETTY_FLAGS(pretty);
1913 
1914  return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
1915 }
static char * pg_get_partkeydef_worker(Oid relid, int prettyFlags, bool attrsOnly, bool missing_ok)
Definition: ruleutils.c:1921

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

1573 {
1575  int prettyFlags;
1576 
1577  prettyFlags = GET_PRETTY_FLAGS(pretty);
1578 
1579  initStringInfo(&buf);
1580 
1581  get_query_def(query, &buf, NIL, NULL, true,
1582  prettyFlags, WRAP_COLUMN_DEFAULT, 0);
1583 
1584  return buf.data;
1585 }
static void get_query_def(Query *query, StringInfo buf, List *parentnamespace, TupleDesc resultDesc, bool colNamesVisible, int prettyFlags, int wrapColumn, int startIndent)
Definition: ruleutils.c:5457
#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 1611 of file ruleutils.c.

1612 {
1613  return pg_get_statisticsobj_worker(statextid, false, false);
1614 }
static char * pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
Definition: ruleutils.c:1638

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

3823 {
3824  deparse_namespace dpns;
3825 
3826  memset(&dpns, 0, sizeof(dpns));
3827  dpns.rtable = rtable;
3828  dpns.subplans = NIL;
3829  dpns.ctes = NIL;
3830  dpns.appendrels = NULL;
3831  set_rtable_names(&dpns, NIL, rels_used);
3832  /* We needn't bother computing column aliases yet */
3833 
3834  return dpns.rtable_names;
3835 }

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

3800 {
3801  deparse_namespace *dpns;
3802 
3803  /* Should always have one-entry namespace list for Plan deparsing */
3804  Assert(list_length(dpcontext) == 1);
3805  dpns = (deparse_namespace *) linitial(dpcontext);
3806 
3807  /* Set our attention on the specific plan node passed in */
3808  dpns->ancestors = ancestors;
3809  set_deparse_plan(dpns, plan);
3810 
3811  return dpcontext;
3812 }
#define linitial(l)
Definition: pg_list.h:178
#define plan(x)
Definition: pg_regress.c:162
static void set_deparse_plan(deparse_namespace *dpns, Plan *plan)
Definition: ruleutils.c:4988

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

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