PostgreSQL Source Code git master
Macros | Typedefs | Functions
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

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 (PlannedStmt *pstmt, List *rtable_names)
 
Listset_deparse_context_plan (List *dpcontext, Plan *plan, List *ancestors)
 
 
char *  get_window_frame_options_for_explain (int frameOptions, Node *startOffset, Node *endOffset, List *dpcontext, bool forceprefix)
 
 
char *  generate_opclass_name (Oid opclass)
 
char *  get_range_partbound_string (List *bound_datums)
 
char *  pg_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

typedef struct PlannedStmt PlannedStmt

Definition at line 21 of file ruleutils.h.

Function Documentation

deparse_context_for()

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

Definition at line 3707 of file ruleutils.c.

3708{
3709 deparse_namespace *dpns;
3710 RangeTblEntry *rte;
3711
3712 dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3713
3714 /* Build a minimal RTE for the rel */
3715 rte = makeNode(RangeTblEntry);
3716 rte->rtekind = RTE_RELATION;
3717 rte->relid = relid;
3718 rte->relkind = RELKIND_RELATION; /* no need for exactness here */
3719 rte->rellockmode = AccessShareLock;
3720 rte->alias = makeAlias(aliasname, NIL);
3721 rte->eref = rte->alias;
3722 rte->lateral = false;
3723 rte->inh = false;
3724 rte->inFromCl = true;
3725
3726 /* Build one-element rtable */
3727 dpns->rtable = list_make1(rte);
3728 dpns->subplans = NIL;
3729 dpns->ctes = NIL;
3730 dpns->appendrels = NULL;
3731 set_rtable_names(dpns, NIL, NULL);
3733
3734 /* Return a one-deep namespace stack */
3735 return list_make1(dpns);
3736}
#define AccessShareLock
Definition: lockdefs.h:36
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:438
void * palloc0(Size size)
Definition: mcxt.c:1395
#define makeNode(_type_)
Definition: nodes.h:161
@ RTE_RELATION
Definition: parsenodes.h:1043
#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:4097
static void set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, Bitmapset *rels_used)
Definition: ruleutils.c:3883
RTEKind rtekind
Definition: parsenodes.h:1078
List * rtable
Definition: ruleutils.c:164
List * subplans
Definition: ruleutils.c:167
AppendRelInfo ** appendrels
Definition: ruleutils.c:169

References AccessShareLock, deparse_namespace::appendrels, deparse_namespace::ctes, RangeTblEntry::inh, list_make1, makeAlias(), makeNode, NIL, palloc0(), 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 ( PlannedStmtpstmt,
Listrtable_names 
)

Definition at line 3752 of file ruleutils.c.

3753{
3754 deparse_namespace *dpns;
3755
3756 dpns = (deparse_namespace *) palloc0(sizeof(deparse_namespace));
3757
3758 /* Initialize fields that stay the same across the whole plan tree */
3759 dpns->rtable = pstmt->rtable;
3760 dpns->rtable_names = rtable_names;
3761 dpns->subplans = pstmt->subplans;
3762 dpns->ctes = NIL;
3763 if (pstmt->appendRelations)
3764 {
3765 /* Set up the array, indexed by child relid */
3766 int ntables = list_length(dpns->rtable);
3767 ListCell *lc;
3768
3769 dpns->appendrels = (AppendRelInfo **)
3770 palloc0((ntables + 1) * sizeof(AppendRelInfo *));
3771 foreach(lc, pstmt->appendRelations)
3772 {
3773 AppendRelInfo *appinfo = lfirst_node(AppendRelInfo, lc);
3774 Index crelid = appinfo->child_relid;
3775
3776 Assert(crelid > 0 && crelid <= ntables);
3777 Assert(dpns->appendrels[crelid] == NULL);
3778 dpns->appendrels[crelid] = appinfo;
3779 }
3780 }
3781 else
3782 dpns->appendrels = NULL; /* don't need it */
3783
3784 /*
3785 * Set up column name aliases, ignoring any join RTEs; they don't matter
3786 * because plan trees don't contain any join alias Vars.
3787 */
3789
3790 /* Return a one-deep namespace stack */
3791 return list_make1(dpns);
3792}
unsigned int Index
Definition: c.h:619
Assert(PointerIsAligned(start, uint64))
#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:3122
List * appendRelations
Definition: plannodes.h:127
List * subplans
Definition: plannodes.h:132
List * rtable
Definition: plannodes.h:109
List * rtable_names
Definition: ruleutils.c:165
Definition: pg_list.h:46

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 ( Nodeexpr,
Listdpcontext,
bool  forceprefix,
bool  showimplicit 
)

Definition at line 3644 of file ruleutils.c.

3646{
3647 return deparse_expression_pretty(expr, dpcontext, forceprefix,
3648 showimplicit, 0, 0);
3649}
static char * deparse_expression_pretty(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit, int prettyFlags, int startIndent)
Definition: ruleutils.c:3671

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

generate_collation_name()

char * generate_collation_name ( Oid  collid )

Definition at line 13574 of file ruleutils.c.

13575{
13576 HeapTuple tp;
13577 Form_pg_collation colltup;
13578 char *collname;
13579 char *nspname;
13580 char *result;
13581
13582 tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid));
13583 if (!HeapTupleIsValid(tp))
13584 elog(ERROR, "cache lookup failed for collation %u", collid);
13585 colltup = (Form_pg_collation) GETSTRUCT(tp);
13586 collname = NameStr(colltup->collname);
13587
13589 nspname = get_namespace_name_or_temp(colltup->collnamespace);
13590 else
13591 nspname = NULL;
13592
13593 result = quote_qualified_identifier(nspname, collname);
13594
13595 ReleaseSysCache(tp);
13596
13597 return result;
13598}
#define NameStr(name)
Definition: c.h:751
Oid collid
Definition: collationcmds.c:700
#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)
Definition: htup_details.h:728
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3557
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2474
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:58
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:13142
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:220

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

12929{
12931
12933 get_opclass_name(opclass, InvalidOid, &buf);
12934
12935 return &buf.data[1]; /* get_opclass_name() prepends space */
12936}
static char * buf
Definition: pg_test_fsync.c:72
#define InvalidOid
Definition: postgres_ext.h:37
static void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf)
Definition: ruleutils.c:12890
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 ( Listbound_datums )

Definition at line 13707 of file ruleutils.c.

13708{
13709 deparse_context context;
13711 ListCell *cell;
13712 char *sep;
13713
13714 memset(&context, 0, sizeof(deparse_context));
13715 context.buf = buf;
13716
13718 sep = "";
13719 foreach(cell, bound_datums)
13720 {
13721 PartitionRangeDatum *datum =
13723
13726 appendStringInfoString(buf, "MINVALUE");
13727 else if (datum->kind == PARTITION_RANGE_DATUM_MAXVALUE)
13728 appendStringInfoString(buf, "MAXVALUE");
13729 else
13730 {
13731 Const *val = castNode(Const, datum->value);
13732
13733 get_const_expr(val, &context, -1);
13734 }
13735 sep = ", ";
13736 }
13738
13739 return buf->data;
13740}
long val
Definition: informix.c:689
#define castNode(_type_, nodeptr)
Definition: nodes.h:182
@ PARTITION_RANGE_DATUM_MAXVALUE
Definition: parsenodes.h:954
@ PARTITION_RANGE_DATUM_MINVALUE
Definition: parsenodes.h:952
static void get_const_expr(Const *constval, deparse_context *context, int showtype)
Definition: ruleutils.c:11494
StringInfo makeStringInfo(void)
Definition: stringinfo.c:72
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242
Definition: primnodes.h:324
PartitionRangeDatumKind kind
Definition: parsenodes.h:961
StringInfo buf
Definition: ruleutils.c:114

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

get_window_frame_options_for_explain()

char * get_window_frame_options_for_explain ( int  frameOptions,
NodestartOffset,
NodeendOffset,
Listdpcontext,
bool  forceprefix 
)

Definition at line 6908 of file ruleutils.c.

6911{
6913 deparse_context context;
6914
6916 context.buf = &buf;
6917 context.namespaces = dpcontext;
6918 context.resultDesc = NULL;
6919 context.targetList = NIL;
6920 context.windowClause = NIL;
6921 context.varprefix = forceprefix;
6922 context.prettyFlags = 0;
6924 context.indentLevel = 0;
6925 context.colNamesVisible = true;
6926 context.inGroupBy = false;
6927 context.varInOrderBy = false;
6928 context.appendparents = NULL;
6929
6930 get_window_frame_options(frameOptions, startOffset, endOffset, &context);
6931
6932 return buf.data;
6933}
static void get_window_frame_options(int frameOptions, Node *startOffset, Node *endOffset, deparse_context *context)
Definition: ruleutils.c:6839
#define WRAP_COLUMN_DEFAULT
Definition: ruleutils.c:98
int indentLevel
Definition: ruleutils.c:121
TupleDesc resultDesc
Definition: ruleutils.c:116
int wrapColumn
Definition: ruleutils.c:120
List * targetList
Definition: ruleutils.c:117
bool inGroupBy
Definition: ruleutils.c:124
bool colNamesVisible
Definition: ruleutils.c:123
List * namespaces
Definition: ruleutils.c:115
bool varprefix
Definition: ruleutils.c:122
bool varInOrderBy
Definition: ruleutils.c:125
List * windowClause
Definition: ruleutils.c:118
Bitmapset * appendparents
Definition: ruleutils.c:126
int prettyFlags
Definition: ruleutils.c:119

References deparse_context::appendparents, deparse_context::buf, buf, deparse_context::colNamesVisible, 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 )

Definition at line 2183 of file ruleutils.c.

2184{
2185 return pg_get_constraintdef_worker(constraintId, true, 0, false);
2186}
static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags, bool missing_ok)
Definition: ruleutils.c:2192

References pg_get_constraintdef_worker().

Referenced by RememberConstraintForRebuilding().

pg_get_indexdef_columns()

char * pg_get_indexdef_columns ( Oid  indexrelid,
bool  pretty 
)

Definition at line 1235 of file ruleutils.c.

1236{
1237 int prettyFlags;
1238
1239 prettyFlags = GET_PRETTY_FLAGS(pretty);
1240
1241 return pg_get_indexdef_worker(indexrelid, 0, NULL,
1242 true, true,
1243 false, false,
1244 prettyFlags, false);
1245}
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:1270
#define GET_PRETTY_FLAGS(pretty)
Definition: ruleutils.c:93

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

1250{
1251 bool pretty = ((flags & RULE_INDEXDEF_PRETTY) != 0);
1252 bool keys_only = ((flags & RULE_INDEXDEF_KEYS_ONLY) != 0);
1253 int prettyFlags;
1254
1255 prettyFlags = GET_PRETTY_FLAGS(pretty);
1256
1257 return pg_get_indexdef_worker(indexrelid, 0, NULL,
1258 true, keys_only,
1259 false, false,
1260 prettyFlags, false);
1261}
#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 1225 of file ruleutils.c.

1226{
1227 return pg_get_indexdef_worker(indexrelid, 0, NULL,
1228 false, false,
1229 true, true,
1230 0, false);
1231}

References pg_get_indexdef_worker().

Referenced by RememberIndexForRebuilding().

pg_get_partconstrdef_string()

char * pg_get_partconstrdef_string ( Oid  partitionId,
char *  aliasname 
)

Definition at line 2127 of file ruleutils.c.

2128{
2129 Expr *constr_expr;
2130 List *context;
2131
2132 constr_expr = get_partition_qual_relid(partitionId);
2133 context = deparse_context_for(aliasname, partitionId);
2134
2135 return deparse_expression((Node *) constr_expr, context, true, false);
2136}
Expr * get_partition_qual_relid(Oid relid)
Definition: partcache.c:299
List * deparse_context_for(const char *aliasname, Oid relid)
Definition: ruleutils.c:3707
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Definition: ruleutils.c:3644
Definition: primnodes.h:189
Definition: pg_list.h:54
Definition: nodes.h:135

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

1924{
1925 int prettyFlags;
1926
1927 prettyFlags = GET_PRETTY_FLAGS(pretty);
1928
1929 return pg_get_partkeydef_worker(relid, prettyFlags, true, false);
1930}
static char * pg_get_partkeydef_worker(Oid relid, int prettyFlags, bool attrsOnly, bool missing_ok)
Definition: ruleutils.c:1936

References GET_PRETTY_FLAGS, and pg_get_partkeydef_worker().

Referenced by ExecBuildSlotPartitionKeyDescription().

pg_get_querydef()

char * pg_get_querydef ( Queryquery,
bool  pretty 
)

Definition at line 1588 of file ruleutils.c.

1589{
1591 int prettyFlags;
1592
1593 prettyFlags = GET_PRETTY_FLAGS(pretty);
1594
1596
1597 get_query_def(query, &buf, NIL, NULL, true,
1598 prettyFlags, WRAP_COLUMN_DEFAULT, 0);
1599
1600 return buf.data;
1601}
static void get_query_def(Query *query, StringInfo buf, List *parentnamespace, TupleDesc resultDesc, bool colNamesVisible, int prettyFlags, int wrapColumn, int startIndent)
Definition: ruleutils.c:5623

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

1627{
1628 return pg_get_statisticsobj_worker(statextid, false, false);
1629}
static char * pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
Definition: ruleutils.c:1653

References pg_get_statisticsobj_worker().

Referenced by RememberStatisticsForRebuilding().

select_rtable_names_for_explain()

List * select_rtable_names_for_explain ( Listrtable,
Bitmapsetrels_used 
)

Definition at line 3854 of file ruleutils.c.

3855{
3856 deparse_namespace dpns;
3857
3858 memset(&dpns, 0, sizeof(dpns));
3859 dpns.rtable = rtable;
3860 dpns.subplans = NIL;
3861 dpns.ctes = NIL;
3862 dpns.appendrels = NULL;
3863 set_rtable_names(&dpns, NIL, rels_used);
3864 /* We needn't bother computing column aliases yet */
3865
3866 return dpns.rtable_names;
3867}

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 ( Listdpcontext,
Planplan,
Listancestors 
)

Definition at line 3824 of file ruleutils.c.

3825{
3826 deparse_namespace *dpns;
3827
3828 /* Should always have one-entry namespace list for Plan deparsing */
3829 Assert(list_length(dpcontext) == 1);
3830 dpns = (deparse_namespace *) linitial(dpcontext);
3831
3832 /* Set our attention on the specific plan node passed in */
3833 dpns->ancestors = ancestors;
3834 set_deparse_plan(dpns, plan);
3835
3836 /* For ModifyTable, set aliases for OLD and NEW in RETURNING */
3837 if (IsA(plan, ModifyTable))
3838 {
3839 dpns->ret_old_alias = ((ModifyTable *) plan)->returningOldAlias;
3840 dpns->ret_new_alias = ((ModifyTable *) plan)->returningNewAlias;
3841 }
3842
3843 return dpcontext;
3844}
#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:5151
char * ret_old_alias
Definition: ruleutils.c:170
char * ret_new_alias
Definition: ruleutils.c:171
List * ancestors
Definition: ruleutils.c:177

References deparse_namespace::ancestors, Assert(), IsA, linitial, list_length(), plan, deparse_namespace::ret_new_alias, deparse_namespace::ret_old_alias, 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().

AltStyle によって変換されたページ (->オリジナル) /