PostgreSQL Source Code git master
Loading...
Searching...
No Matches
extended_stats_funcs.c File Reference
#include "postgres.h"
#include "access/heapam.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/pg_database.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_statistic_ext_data.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "statistics/stat_utils.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
Include dependency graph for extended_stats_funcs.c:

Go to the source code of this file.

Enumerations

enum  extended_stats_argnum {
  RELSCHEMA_ARG = 0 , RELNAME_ARG , STATSCHEMA_ARG , STATNAME_ARG ,
  INHERITED_ARG , NUM_EXTENDED_STATS_ARGS
}
 

Functions

static HeapTuple get_pg_statistic_ext (Relation pg_stext, Oid nspoid, const char *stxname)
 
static bool delete_pg_statistic_ext_data (Oid stxoid, bool inherited)
 
Datum pg_clear_extended_stats (PG_FUNCTION_ARGS)
 

Variables

static struct StatsArgInfo extarginfo []
 

Enumeration Type Documentation

◆ extended_stats_argnum

Enumerator
RELSCHEMA_ARG 
RELNAME_ARG 
STATSCHEMA_ARG 
STATNAME_ARG 
INHERITED_ARG 
NUM_EXTENDED_STATS_ARGS 

Definition at line 38 of file extended_stats_funcs.c.

Function Documentation

◆ delete_pg_statistic_ext_data()

static bool delete_pg_statistic_ext_data ( Oid  stxoid,
bool  inherited 
)
static

Definition at line 117 of file extended_stats_funcs.c.

118{
121 bool result = false;
122
123 /* Is there already a pg_statistic tuple for this attribute? */
127
129 {
130 CatalogTupleDelete(sed, &oldtup->t_self);
132 result = true;
133 }
134
136
138
139 return result;
140}
#define HeapTupleIsValid(tuple)
Definition htup.h:78
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
Definition indexing.c:365
#define RowExclusiveLock
Definition lockdefs.h:38
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
static int fb(int x)
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition syscache.c:230
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40
void CommandCounterIncrement(void)
Definition xact.c:1101

References BoolGetDatum(), CatalogTupleDelete(), CommandCounterIncrement(), fb(), HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), RowExclusiveLock, SearchSysCache2(), table_close(), and table_open().

Referenced by pg_clear_extended_stats().

◆ get_pg_statistic_ext()

static HeapTuple get_pg_statistic_ext ( Relation  pg_stext,
Oid  nspoid,
const char stxname 
)
static

Definition at line 70 of file extended_stats_funcs.c.

71{
73 SysScanDesc scan;
76
77 ScanKeyInit(&key[0],
82 ScanKeyInit(&key[1],
85 F_OIDEQ,
87
88 /*
89 * Try to find matching pg_statistic_ext row.
90 */
93 true,
94 NULL,
95 2,
96 key);
97
98 /* Lookup is based on a unique index, so we get either 0 or 1 tuple. */
99 tup = systable_getnext(scan);
100
103
104 systable_endscan(scan);
105
106 if (!OidIsValid(stxoid))
107 return NULL;
108
110}
#define OidIsValid(objectId)
Definition c.h:798
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:603
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:514
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:388
static void * GETSTRUCT(const HeapTupleData *tuple)
FormData_pg_statistic_ext * Form_pg_statistic_ext
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
#define InvalidOid
unsigned int Oid
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition scankey.c:76
#define BTEqualStrategyNumber
Definition stratnum.h:31
#define SearchSysCacheCopy1(cacheId, key1)
Definition syscache.h:91

References BTEqualStrategyNumber, CStringGetDatum(), fb(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, ObjectIdGetDatum(), OidIsValid, ScanKeyInit(), SearchSysCacheCopy1, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by pg_clear_extended_stats().

◆ pg_clear_extended_stats()

Datum pg_clear_extended_stats ( PG_FUNCTION_ARGS  )

Definition at line 146 of file extended_stats_funcs.c.

147{
148 char *relnspname;
149 char *relname;
150 char *nspname;
151 Oid nspoid;
152 Oid relid;
153 char *stxname;
154 bool inherited;
159
160 /* relation arguments */
165
166 /* extended statistics arguments */
173
174 if (RecoveryInProgress())
175 {
178 errmsg("recovery is in progress"),
179 errhint("Statistics cannot be modified during recovery."));
181 }
182
183 /*
184 * First open the relation where we expect to find the statistics. This
185 * is similar to relation and attribute statistics, so as ACL checks are
186 * done before any locks are taken, even before any attempts related to
187 * the extended stats object.
188 */
192
193 /* Now check if the namespace of the stats object exists. */
194 nspoid = get_namespace_oid(nspname, true);
195 if (nspoid == InvalidOid)
196 {
199 errmsg("could not find schema \"%s\"", nspname));
201 }
202
205
206 if (!HeapTupleIsValid(tup))
207 {
211 errmsg("could not find extended statistics object \"%s\".\"%s\"",
212 nspname, stxname));
214 }
215
217
218 /*
219 * This should be consistent, based on the lock taken on the table when we
220 * started.
221 */
222 if (stxform->stxrelid != relid)
223 {
227 errmsg("could not clear extended statistics object \"%s\".\"%s\": incorrect relation \"%s\".\"%s\" specified",
231 }
232
235
237
239}
#define TextDatumGetCString(d)
Definition builtins.h:98
int errhint(const char *fmt,...)
Definition elog.c:1330
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define WARNING
Definition elog.h:36
#define ereport(elevel,...)
Definition elog.h:150
static bool delete_pg_statistic_ext_data(Oid stxoid, bool inherited)
static struct StatsArgInfo extarginfo[]
static HeapTuple get_pg_statistic_ext(Relation pg_stext, Oid nspoid, const char *stxname)
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1435
#define ShareUpdateExclusiveLock
Definition lockdefs.h:39
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3516
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition makefuncs.c:473
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition namespace.c:3605
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition namespace.c:440
NameData relname
Definition pg_class.h:38
void RangeVarCallbackForStats(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
Definition stat_utils.c:142
void stats_check_required_arg(FunctionCallInfo fcinfo, struct StatsArgInfo *arginfo, int argnum)
Definition stat_utils.c:51
bool RecoveryInProgress(void)
Definition xlog.c:6461

References delete_pg_statistic_ext_data(), ereport, errcode(), errhint(), errmsg(), extarginfo, fb(), get_namespace_name(), get_namespace_oid(), get_pg_statistic_ext(), GETSTRUCT(), heap_freetuple(), HeapTupleIsValid, INHERITED_ARG, InvalidOid, makeRangeVar(), PG_GETARG_BOOL, PG_GETARG_DATUM, PG_RETURN_VOID, RangeVarCallbackForStats(), RangeVarGetRelidExtended(), RecoveryInProgress(), relname, RELNAME_ARG, RELSCHEMA_ARG, RowExclusiveLock, ShareUpdateExclusiveLock, STATNAME_ARG, stats_check_required_arg(), STATSCHEMA_ARG, table_close(), table_open(), TextDatumGetCString, and WARNING.

Variable Documentation

◆ extarginfo

struct StatsArgInfo extarginfo[]
static
Initial value:
=
{
[RELSCHEMA_ARG] = {"schemaname", TEXTOID},
[RELNAME_ARG] = {"relname", TEXTOID},
[STATSCHEMA_ARG] = {"statistics_schemaname", TEXTOID},
[STATNAME_ARG] = {"statistics_name", TEXTOID},
[INHERITED_ARG] = {"inherited", BOOLOID},
}

Definition at line 52 of file extended_stats_funcs.c.

53{
54 [RELSCHEMA_ARG] = {"schemaname", TEXTOID},
55 [RELNAME_ARG] = {"relname", TEXTOID},
56 [STATSCHEMA_ARG] = {"statistics_schemaname", TEXTOID},
57 [STATNAME_ARG] = {"statistics_name", TEXTOID},
58 [INHERITED_ARG] = {"inherited", BOOLOID},
60};

Referenced by pg_clear_extended_stats().