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, bits16 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)
 
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 4068 of file ruleutils.c.

4069{
4072
4074
4075 /* Build a minimal RTE for the rel */
4077 rte->rtekind = RTE_RELATION;
4078 rte->relid = relid;
4079 rte->relkind = RELKIND_RELATION; /* no need for exactness here */
4080 rte->rellockmode = AccessShareLock;
4081 rte->alias = makeAlias(aliasname, NIL);
4082 rte->eref = rte->alias;
4083 rte->lateral = false;
4084 rte->inh = false;
4085 rte->inFromCl = true;
4086
4087 /* Build one-element rtable */
4088 dpns->rtable = list_make1(rte);
4089 dpns->subplans = NIL;
4090 dpns->ctes = NIL;
4091 dpns->appendrels = NULL;
4094
4095 /* Return a one-deep namespace stack */
4096 return list_make1(dpns);
4097}
#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:212
static int fb(int x)
static void set_simple_column_names(deparse_namespace *dpns)
Definition ruleutils.c:4458
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition ruleutils.c:4244

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

4114{
4116
4118
4119 /* Initialize fields that stay the same across the whole plan tree */
4120 dpns->rtable = pstmt->rtable;
4121 dpns->rtable_names = rtable_names;
4122 dpns->subplans = pstmt->subplans;
4123 dpns->ctes = NIL;
4124 if (pstmt->appendRelations)
4125 {
4126 /* Set up the array, indexed by child relid */
4127 int ntables = list_length(dpns->rtable);
4128 ListCell *lc;
4129
4130 dpns->appendrels = (AppendRelInfo **)
4131 palloc0((ntables + 1) * sizeof(AppendRelInfo *));
4132 foreach(lc, pstmt->appendRelations)
4133 {
4135 Index crelid = appinfo->child_relid;
4136
4137 Assert(crelid > 0 && crelid <= ntables);
4138 Assert(dpns->appendrels[crelid] == NULL);
4139 dpns->appendrels[crelid] = appinfo;
4140 }
4141 }
4142 else
4143 dpns->appendrels = NULL; /* don't need it */
4144
4145 /*
4146 * Set up column name aliases, ignoring any join RTEs; they don't matter
4147 * because plan trees don't contain any join alias Vars.
4148 */
4150
4151 /* Return a one-deep namespace stack */
4152 return list_make1(dpns);
4153}
#define Assert(condition)
Definition c.h:945
unsigned int Index
Definition c.h:700
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:125
List * subplans
Definition plannodes.h:130
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 14158 of file ruleutils.c.

14159{
14160 HeapTuple tp;
14162 char *collname;
14163 char *nspname;
14164 char *result;
14165
14167 if (!HeapTupleIsValid(tp))
14168 elog(ERROR, "cache lookup failed for collation %u", collid);
14170 collname = NameStr(colltup->collname);
14171
14173 nspname = get_namespace_name_or_temp(colltup->collnamespace);
14174 else
14175 nspname = NULL;
14176
14177 result = quote_qualified_identifier(nspname, collname);
14178
14179 ReleaseSysCache(tp);
14180
14181 return result;
14182}
#define NameStr(name)
Definition c.h:837
Oid collid
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#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:264
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220

References CollationIsVisible(), collid, elog, ERROR, fb(), Form_pg_collation, 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)
extern

Definition at line 13512 of file ruleutils.c.

13513{
13515
13517 get_opclass_name(opclass, InvalidOid, &buf);
13518
13519 return &buf.data[1]; /* get_opclass_name() prepends space */
13520}
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 14291 of file ruleutils.c.

14292{
14293 deparse_context context;
14295 ListCell *cell;
14296 char *sep;
14297
14299 memset(&context, 0, sizeof(deparse_context));
14300 context.buf = &buf;
14301
14303 sep = "";
14304 foreach(cell, bound_datums)
14305 {
14306 PartitionRangeDatum *datum =
14308
14311 appendStringInfoString(&buf, "MINVALUE");
14312 else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
14313 appendStringInfoString(&buf, "MAXVALUE");
14314 else
14315 {
14316 Const *val = castNode(Const, datum->value);
14317
14318 get_const_expr(val, &context, -1);
14319 }
14320 sep = ", ";
14321 }
14323
14324 return buf.data;
14325}
long val
Definition informix.c:689
#define castNode(_type_, nodeptr)
Definition nodes.h:182
@ PARTITION_RANGE_DATUM_MAXVALUE
Definition parsenodes.h:968
@ PARTITION_RANGE_DATUM_MINVALUE
Definition parsenodes.h:966
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:975
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_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 7273 of file ruleutils.c.

7276{
7278 deparse_context context;
7279
7281 context.buf = &buf;
7282 context.namespaces = dpcontext;
7283 context.resultDesc = NULL;
7284 context.targetList = NIL;
7285 context.windowClause = NIL;
7286 context.varprefix = forceprefix;
7287 context.prettyFlags = 0;
7289 context.indentLevel = 0;
7290 context.colNamesVisible = true;
7291 context.inGroupBy = false;
7292 context.varInOrderBy = false;
7293 context.appendparents = NULL;
7294
7295 get_window_frame_options(frameOptions, startOffset, endOffset, &context);
7296
7297 return buf.data;
7298}
static void get_window_frame_options(int frameOptions, Node *startOffset, Node *endOffset, deparse_context *context)
Definition ruleutils.c:7204
#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 2540 of file ruleutils.c.

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

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

1245{
1246 int prettyFlags;
1247
1248 prettyFlags = GET_PRETTY_FLAGS(pretty);
1249
1250 return pg_get_indexdef_worker(indexrelid, 0, NULL,
1251 true, true,
1252 false, false,
1253 prettyFlags, false);
1254}
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:1279
#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,
bits16  flags 
)
extern

Definition at line 1258 of file ruleutils.c.

1259{
1260 bool pretty = ((flags & RULE_INDEXDEF_PRETTY) != 0);
1261 bool keys_only = ((flags & RULE_INDEXDEF_KEYS_ONLY) != 0);
1262 int prettyFlags;
1263
1264 prettyFlags = GET_PRETTY_FLAGS(pretty);
1265
1266 return pg_get_indexdef_worker(indexrelid, 0, NULL,
1267 true, keys_only,
1268 false, false,
1269 prettyFlags, false);
1270}
#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 1234 of file ruleutils.c.

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

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

2485{
2487 List *context;
2488
2490 context = deparse_context_for(aliasname, partitionId);
2491
2492 return deparse_expression((Node *) constr_expr, context, true, false);
2493}
Expr * get_partition_qual_relid(Oid relid)
Definition partcache.c:299
List * deparse_context_for(const char *aliasname, Oid relid)
Definition ruleutils.c:4068
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Definition ruleutils.c:4005
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 2280 of file ruleutils.c.

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

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

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

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

1984{
1985 return pg_get_statisticsobj_worker(statextid, false, false);
1986}
static char * pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
Definition ruleutils.c:2010

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

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

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

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

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