PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 */
 

Typedefs

typedef struct Plan Plan
 
typedef struct PlannedStmt PlannedStmt
 

Functions

charpg_get_indexdef_string (Oid indexrelid)
 
charpg_get_indexdef_columns (Oid indexrelid, bool pretty)
 
charpg_get_indexdef_columns_extended (Oid indexrelid, uint16 flags)
 
charpg_get_querydef (Query *query, bool pretty)
 
charpg_get_partkeydef_columns (Oid relid, bool pretty)
 
charpg_get_partconstrdef_string (Oid partitionId, char *aliasname)
 
charpg_get_constraintdef_command (Oid constraintId)
 
chardeparse_expression (Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
 
Listdeparse_context_for (const char *aliasname, Oid relid)
 
Listdeparse_context_for_plan_tree (PlannedStmt *pstmt, List *rtable_names)
 
Listset_deparse_context_plan (List *dpcontext, Plan *plan, List *ancestors)
 
Listselect_rtable_names_for_explain (List *rtable, Bitmapset *rels_used)
 
charget_window_frame_options_for_explain (int frameOptions, Node *startOffset, Node *endOffset, List *dpcontext, bool forceprefix)
 
chargenerate_collation_name (Oid collid)
 
chargenerate_opclass_name (Oid opclass)
 
charget_range_partbound_string (List *bound_datums)
 
void get_reloptions (StringInfo buf, Datum reloptions)
 
charpg_get_statisticsobjdef_string (Oid statextid)
 

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.

Typedef Documentation

◆ Plan

typedef struct Plan Plan

Definition at line 20 of file ruleutils.h.

◆ PlannedStmt

Definition at line 21 of file ruleutils.h.

Function Documentation

◆ deparse_context_for()

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

Definition at line 4070 of file ruleutils.c.

4071{
4074
4076
4077 /* Build a minimal RTE for the rel */
4079 rte->rtekind = RTE_RELATION;
4080 rte->relid = relid;
4081 rte->relkind = RELKIND_RELATION; /* no need for exactness here */
4082 rte->rellockmode = AccessShareLock;
4083 rte->alias = makeAlias(aliasname, NIL);
4084 rte->eref = rte->alias;
4085 rte->lateral = false;
4086 rte->inh = false;
4087 rte->inFromCl = true;
4088
4089 /* Build one-element rtable */
4090 dpns->rtable = list_make1(rte);
4091 dpns->subplans = NIL;
4092 dpns->ctes = NIL;
4093 dpns->appendrels = NULL;
4096
4097 /* Return a one-deep namespace stack */
4098 return list_make1(dpns);
4099}
#define palloc0_object(type)
Definition fe_memutils.h:75
#define AccessShareLock
Definition lockdefs.h:36
Alias * makeAlias(const char *aliasname, List *colnames)
Definition makefuncs.c:438
#define makeNode(_type_)
Definition nodes.h:161
@ RTE_RELATION
#define NIL
Definition pg_list.h:68
#define list_make1(x1)
Definition pg_list.h:244
static int fb(int x)
static void set_simple_column_names(deparse_namespace *dpns)
Definition ruleutils.c:4460
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition ruleutils.c:4246

References AccessShareLock, fb(), list_make1, makeAlias(), makeNode, NIL, palloc0_object, RTE_RELATION, set_rtable_names(), and set_simple_column_names().

Referenced by check_element_properties(), make_propgraphdef_properties(), 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 ( PlannedStmt pstmt,
List rtable_names 
)
extern

Definition at line 4115 of file ruleutils.c.

4116{
4118
4120
4121 /* Initialize fields that stay the same across the whole plan tree */
4122 dpns->rtable = pstmt->rtable;
4123 dpns->rtable_names = rtable_names;
4124 dpns->subplans = pstmt->subplans;
4125 dpns->ctes = NIL;
4126 if (pstmt->appendRelations)
4127 {
4128 /* Set up the array, indexed by child relid */
4129 int ntables = list_length(dpns->rtable);
4130 ListCell *lc;
4131
4132 dpns->appendrels = (AppendRelInfo **)
4133 palloc0((ntables + 1) * sizeof(AppendRelInfo *));
4134 foreach(lc, pstmt->appendRelations)
4135 {
4137 Index crelid = appinfo->child_relid;
4138
4139 Assert(crelid > 0 && crelid <= ntables);
4140 Assert(dpns->appendrels[crelid] == NULL);
4141 dpns->appendrels[crelid] = appinfo;
4142 }
4143 }
4144 else
4145 dpns->appendrels = NULL; /* don't need it */
4146
4147 /*
4148 * Set up column name aliases, ignoring any join RTEs; they don't matter
4149 * because plan trees don't contain any join alias Vars.
4150 */
4152
4153 /* Return a one-deep namespace stack */
4154 return list_make1(dpns);
4155}
#define Assert(condition)
Definition c.h:943
unsigned int Index
Definition c.h:698
void * palloc0(Size size)
Definition mcxt.c:1417
#define lfirst_node(type, lc)
Definition pg_list.h:176
static int list_length(const List *l)
Definition pg_list.h:152
List * appendRelations
Definition plannodes.h:124
List * subplans
Definition plannodes.h:129
List * rtable
Definition plannodes.h:107

References PlannedStmt::appendRelations, Assert, fb(), lfirst_node, list_length(), list_make1, NIL, palloc0(), palloc0_object, PlannedStmt::rtable, set_simple_column_names(), and PlannedStmt::subplans.

Referenced by ExplainPrintPlan().

◆ deparse_expression()

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

◆ generate_collation_name()

char * generate_collation_name ( Oid  collid)
extern

Definition at line 14199 of file ruleutils.c.

14200{
14201 HeapTuple tp;
14203 char *collname;
14204 char *nspname;
14205 char *result;
14206
14208 if (!HeapTupleIsValid(tp))
14209 elog(ERROR, "cache lookup failed for collation %u", collid);
14211 collname = NameStr(colltup->collname);
14212
14214 nspname = get_namespace_name_or_temp(colltup->collnamespace);
14215 else
14216 nspname = NULL;
14217
14218 result = quote_qualified_identifier(nspname, collname);
14219
14220 ReleaseSysCache(tp);
14221
14222 return result;
14223}
#define NameStr(name)
Definition c.h:835
uint32 result
Oid collid
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
char * get_namespace_name_or_temp(Oid nspid)
Definition lsyscache.c:3612
bool CollationIsVisible(Oid collid)
Definition namespace.c:2476
END_CATALOG_STRUCT typedef FormData_pg_collation * Form_pg_collation
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
char * quote_qualified_identifier(const char *qualifier, const char *ident)
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221

References CollationIsVisible(), collid, elog, ERROR, fb(), Form_pg_collation, get_namespace_name_or_temp(), GETSTRUCT(), HeapTupleIsValid, NameStr, 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().

◆ generate_opclass_name()

char * generate_opclass_name ( Oid  opclass)
extern

Definition at line 13553 of file ruleutils.c.

13554{
13556
13558 get_opclass_name(opclass, InvalidOid, &buf);
13559
13560 return &buf.data[1]; /* get_opclass_name() prepends space */
13561}
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define InvalidOid
static void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf)
void initStringInfo(StringInfo str)
Definition stringinfo.c:97

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)
extern

Definition at line 14332 of file ruleutils.c.

14333{
14334 deparse_context context;
14336 ListCell *cell;
14337 char *sep;
14338
14340 memset(&context, 0, sizeof(deparse_context));
14341 context.buf = &buf;
14342
14344 sep = "";
14345 foreach(cell, bound_datums)
14346 {
14347 PartitionRangeDatum *datum =
14349
14352 appendStringInfoString(&buf, "MINVALUE");
14353 else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
14354 appendStringInfoString(&buf, "MAXVALUE");
14355 else
14356 {
14357 Const *val = castNode(Const, datum->value);
14358
14359 get_const_expr(val, &context, -1);
14360 }
14361 sep = ", ";
14362 }
14364
14365 return buf.data;
14366}
long val
Definition informix.c:689
#define castNode(_type_, nodeptr)
Definition nodes.h:182
@ PARTITION_RANGE_DATUM_MAXVALUE
Definition parsenodes.h:971
@ PARTITION_RANGE_DATUM_MINVALUE
Definition parsenodes.h:969
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242
PartitionRangeDatumKind kind
Definition parsenodes.h:978
StringInfo buf
Definition ruleutils.c:119

References appendStringInfoChar(), appendStringInfoString(), deparse_context::buf, buf, castNode, fb(), get_const_expr(), initStringInfo(), PartitionRangeDatum::kind, lfirst_node, 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().

◆ get_reloptions()

void get_reloptions ( StringInfo  buf,
Datum  reloptions 
)
extern

Definition at line 14244 of file ruleutils.c.

14245{
14246 Datum *options;
14247 int noptions;
14248 int i;
14249
14251 &options, NULL, &noptions);
14252
14253 for (i = 0; i < noptions; i++)
14254 {
14256 char *name;
14257 char *separator;
14258 char *value;
14259
14260 /*
14261 * Each array element should have the form name=value. If the "=" is
14262 * missing for some reason, treat it like an empty value.
14263 */
14264 name = option;
14265 separator = strchr(option, '=');
14266 if (separator)
14267 {
14268 *separator = '\0';
14269 value = separator + 1;
14270 }
14271 else
14272 value = "";
14273
14274 if (i > 0)
14277
14278 /*
14279 * In general we need to quote the value; but to avoid unnecessary
14280 * clutter, do not quote if it is an identifier that would not need
14281 * quoting. (We could also allow numbers, but that is a bit trickier
14282 * than it looks --- for example, are leading zeroes significant? We
14283 * don't want to assume very much here about what custom reloptions
14284 * might mean.)
14285 */
14288 else
14290
14291 pfree(option);
14292 }
14293}
#define DatumGetArrayTypeP(X)
Definition array.h:261
void deconstruct_array_builtin(const ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
#define TextDatumGetCString(d)
Definition builtins.h:99
static struct @177 value
int i
Definition isn.c:77
void pfree(void *pointer)
Definition mcxt.c:1616
static size_t noptions
uint64_t Datum
Definition postgres.h:70
static void simple_quote_literal(StringInfo buf, const char *val)
const char * quote_identifier(const char *ident)
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
const char * name

References appendStringInfo(), appendStringInfoString(), buf, DatumGetArrayTypeP, deconstruct_array_builtin(), fb(), i, name, noptions, pfree(), quote_identifier(), simple_quote_literal(), TextDatumGetCString, and value.

Referenced by flatten_reloptions(), pg_get_indexdef_worker(), and pg_get_tablespace_ddl_internal().

◆ get_window_frame_options_for_explain()

char * get_window_frame_options_for_explain ( int  frameOptions,
Node startOffset,
Node endOffset,
List dpcontext,
bool  forceprefix 
)
extern

Definition at line 7275 of file ruleutils.c.

7278{
7280 deparse_context context;
7281
7283 context.buf = &buf;
7284 context.namespaces = dpcontext;
7285 context.resultDesc = NULL;
7286 context.targetList = NIL;
7287 context.windowClause = NIL;
7288 context.varprefix = forceprefix;
7289 context.prettyFlags = 0;
7291 context.indentLevel = 0;
7292 context.colNamesVisible = true;
7293 context.inGroupBy = false;
7294 context.varInOrderBy = false;
7295 context.appendparents = NULL;
7296
7297 get_window_frame_options(frameOptions, startOffset, endOffset, &context);
7298
7299 return buf.data;
7300}
static void get_window_frame_options(int frameOptions, Node *startOffset, Node *endOffset, deparse_context *context)
Definition ruleutils.c:7206
#define WRAP_COLUMN_DEFAULT
Definition ruleutils.c:103
TupleDesc resultDesc
Definition ruleutils.c:121
List * targetList
Definition ruleutils.c:122
List * namespaces
Definition ruleutils.c:120
List * windowClause
Definition ruleutils.c:123
Bitmapset * appendparents
Definition ruleutils.c:131

References deparse_context::appendparents, deparse_context::buf, buf, deparse_context::colNamesVisible, fb(), get_window_frame_options(), deparse_context::indentLevel, deparse_context::inGroupBy, initStringInfo(), deparse_context::namespaces, NIL, deparse_context::prettyFlags, deparse_context::resultDesc, deparse_context::targetList, deparse_context::varInOrderBy, deparse_context::varprefix, deparse_context::windowClause, WRAP_COLUMN_DEFAULT, and deparse_context::wrapColumn.

Referenced by show_window_def().

◆ pg_get_constraintdef_command()

char * pg_get_constraintdef_command ( Oid  constraintId)
extern

Definition at line 2542 of file ruleutils.c.

2543{
2544 return pg_get_constraintdef_worker(constraintId, true, 0, false);
2545}
static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags, bool missing_ok)
Definition ruleutils.c:2551

References fb(), and pg_get_constraintdef_worker().

Referenced by RememberConstraintForRebuilding().

◆ pg_get_indexdef_columns()

char * pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)
extern

Definition at line 1246 of file ruleutils.c.

1247{
1248 int prettyFlags;
1249
1250 prettyFlags = GET_PRETTY_FLAGS(pretty);
1251
1252 return pg_get_indexdef_worker(indexrelid, 0, NULL,
1253 true, true,
1254 false, false,
1255 prettyFlags, false);
1256}
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:1281
#define GET_PRETTY_FLAGS(pretty)
Definition ruleutils.c:98

References fb(), GET_PRETTY_FLAGS, and pg_get_indexdef_worker().

Referenced by BuildIndexValueDescription().

◆ pg_get_indexdef_columns_extended()

char * pg_get_indexdef_columns_extended ( Oid  indexrelid,
uint16  flags 
)
extern

Definition at line 1260 of file ruleutils.c.

1261{
1262 bool pretty = ((flags & RULE_INDEXDEF_PRETTY) != 0);
1263 bool keys_only = ((flags & RULE_INDEXDEF_KEYS_ONLY) != 0);
1264 int prettyFlags;
1265
1266 prettyFlags = GET_PRETTY_FLAGS(pretty);
1267
1268 return pg_get_indexdef_worker(indexrelid, 0, NULL,
1269 true, keys_only,
1270 false, false,
1271 prettyFlags, false);
1272}
#define RULE_INDEXDEF_PRETTY
Definition ruleutils.h:24
#define RULE_INDEXDEF_KEYS_ONLY
Definition ruleutils.h:25

References fb(), 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)
extern

Definition at line 1236 of file ruleutils.c.

1237{
1238 return pg_get_indexdef_worker(indexrelid, 0, NULL,
1239 false, false,
1240 true, true,
1241 0, false);
1242}

References fb(), and pg_get_indexdef_worker().

Referenced by RememberIndexForRebuilding().

◆ pg_get_partconstrdef_string()

char * pg_get_partconstrdef_string ( Oid  partitionId,
char aliasname 
)
extern

Definition at line 2486 of file ruleutils.c.

2487{
2489 List *context;
2490
2492 context = deparse_context_for(aliasname, partitionId);
2493
2494 return deparse_expression((Node *) constr_expr, context, true, false);
2495}
Expr * get_partition_qual_relid(Oid relid)
Definition partcache.c:299
List * deparse_context_for(const char *aliasname, Oid relid)
Definition ruleutils.c:4070
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Definition ruleutils.c:4007
Definition pg_list.h:54
Definition nodes.h:135

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

Referenced by RI_PartitionRemove_Check().

◆ pg_get_partkeydef_columns()

char * pg_get_partkeydef_columns ( Oid  relid,
bool  pretty 
)
extern

Definition at line 2282 of file ruleutils.c.

2283{
2284 int prettyFlags;
2285
2286 prettyFlags = GET_PRETTY_FLAGS(pretty);
2287
2288 return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
2289}
static char * pg_get_partkeydef_worker(Oid relid, int prettyFlags, bool attrsOnly, bool missing_ok)
Definition ruleutils.c:2295

References fb(), GET_PRETTY_FLAGS, and pg_get_partkeydef_worker().

Referenced by ExecBuildSlotPartitionKeyDescription().

◆ pg_get_querydef()

char * pg_get_querydef ( Query query,
bool  pretty 
)
extern

Definition at line 1599 of file ruleutils.c.

1600{
1602 int prettyFlags;
1603
1604 prettyFlags = GET_PRETTY_FLAGS(pretty);
1605
1607
1608 get_query_def(query, &buf, NIL, NULL, true,
1609 prettyFlags, WRAP_COLUMN_DEFAULT, 0);
1610
1611 return buf.data;
1612}
static void get_query_def(Query *query, StringInfo buf, List *parentnamespace, TupleDesc resultDesc, bool colNamesVisible, int prettyFlags, int wrapColumn, int startIndent)
Definition ruleutils.c:5986

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

◆ pg_get_statisticsobjdef_string()

char * pg_get_statisticsobjdef_string ( Oid  statextid)
extern

Definition at line 1985 of file ruleutils.c.

1986{
1987 return pg_get_statisticsobj_worker(statextid, false, false);
1988}
static char * pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
Definition ruleutils.c:2012

References fb(), and pg_get_statisticsobj_worker().

Referenced by RememberStatisticsForRebuilding().

◆ select_rtable_names_for_explain()

List * select_rtable_names_for_explain ( List rtable,
Bitmapset rels_used 
)
extern

Definition at line 4217 of file ruleutils.c.

4218{
4220
4221 memset(&dpns, 0, sizeof(dpns));
4222 dpns.rtable = rtable;
4223 dpns.subplans = NIL;
4224 dpns.ctes = NIL;
4225 dpns.appendrels = NULL;
4227 /* We needn't bother computing column aliases yet */
4228
4229 return dpns.rtable_names;
4230}

References fb(), NIL, and set_rtable_names().

Referenced by ExplainPrintPlan().

◆ set_deparse_context_plan()

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

Definition at line 4187 of file ruleutils.c.

4188{
4190
4191 /* Should always have one-entry namespace list for Plan deparsing */
4194
4195 /* Set our attention on the specific plan node passed in */
4196 dpns->ancestors = ancestors;
4198
4199 /* For ModifyTable, set aliases for OLD and NEW in RETURNING */
4200 if (IsA(plan, ModifyTable))
4201 {
4202 dpns->ret_old_alias = ((ModifyTable *) plan)->returningOldAlias;
4203 dpns->ret_new_alias = ((ModifyTable *) plan)->returningNewAlias;
4204 }
4205
4206 return dpcontext;
4207}
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define linitial(l)
Definition pg_list.h:178
#define plan(x)
Definition pg_regress.c:164
static void set_deparse_plan(deparse_namespace *dpns, Plan *plan)
Definition ruleutils.c:5514

References Assert, fb(), IsA, 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(), show_tablesample(), show_window_def(), and show_window_keys().