1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* vacuum.h
|
2001-05-07 02:43:27 +02:00
|
|
|
* header file for postgres vacuum cleaner and statistics analyzer
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
2003-08-04 04:40:20 +02:00
|
|
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2004-05-21 18:22:38 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.53 2004/05/21 16:22:38 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef VACUUM_H
|
|
|
|
#define VACUUM_H
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2004-05-21 18:22:38 +02:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2001-07-12 06:11:13 +02:00
|
|
|
#ifdef HAVE_GETRUSAGE
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#else
|
|
|
|
#include "rusagestub.h"
|
|
|
|
#endif
|
|
|
|
|
2004-02-13 00:41:04 +01:00
|
|
|
#include "access/htup.h"
|
|
|
|
#include "catalog/pg_attribute.h"
|
|
|
|
#include "catalog/pg_statistic.h"
|
|
|
|
#include "catalog/pg_type.h"
|
2001-05-07 02:43:27 +02:00
|
|
|
#include "nodes/parsenodes.h"
|
2004-05-21 07:08:06 +02:00
|
|
|
#include "pgtime.h"
|
2001-07-14 00:55:59 +02:00
|
|
|
#include "utils/rel.h"
|
1998-02-26 05:46:47 +01:00
|
|
|
|
1997-02-07 17:24:12 +01:00
|
|
|
|
2004-02-13 00:41:04 +01:00
|
|
|
/*----------
|
|
|
|
* ANALYZE builds one of these structs for each attribute (column) that is
|
|
|
|
* to be analyzed. The struct and subsidiary data are in anl_context,
|
|
|
|
* so they live until the end of the ANALYZE operation.
|
|
|
|
*
|
|
|
|
* The type-specific typanalyze function is passed a pointer to this struct
|
|
|
|
* and must return TRUE to continue analysis, FALSE to skip analysis of this
|
|
|
|
* column. In the TRUE case it must set the compute_stats and minrows fields,
|
|
|
|
* and can optionally set extra_data to pass additional info to compute_stats.
|
2004-02-13 07:39:49 +01:00
|
|
|
* minrows is its request for the minimum number of sample rows to be gathered
|
|
|
|
* (but note this request might not be honored, eg if there are fewer rows
|
|
|
|
* than that in the table).
|
2004-02-13 00:41:04 +01:00
|
|
|
*
|
|
|
|
* The compute_stats routine will be called after sample rows have been
|
|
|
|
* gathered. Aside from this struct, it is passed:
|
2004-02-13 07:39:49 +01:00
|
|
|
* fetchfunc: a function for accessing the column values from the
|
|
|
|
* sample rows
|
|
|
|
* samplerows: the number of sample tuples
|
2004-02-13 00:41:04 +01:00
|
|
|
* totalrows: estimated total number of rows in relation
|
2004-02-13 07:39:49 +01:00
|
|
|
* The fetchfunc may be called with rownum running from 0 to samplerows-1.
|
|
|
|
* It returns a Datum and an isNull flag.
|
2004-02-13 00:41:04 +01:00
|
|
|
*
|
|
|
|
* compute_stats should set stats_valid TRUE if it is able to compute
|
|
|
|
* any useful statistics. If it does, the remainder of the struct holds
|
|
|
|
* the information to be stored in a pg_statistic row for the column. Be
|
|
|
|
* careful to allocate any pointed-to data in anl_context, which will NOT
|
|
|
|
* be CurrentMemoryContext when compute_stats is called.
|
|
|
|
*----------
|
|
|
|
*/
|
2004-02-13 07:39:49 +01:00
|
|
|
typedef struct VacAttrStats *VacAttrStatsP;
|
|
|
|
|
|
|
|
typedef Datum (*AnalyzeAttrFetchFunc) (VacAttrStatsP stats, int rownum,
|
|
|
|
bool *isNull);
|
|
|
|
|
2004-02-13 00:41:04 +01:00
|
|
|
typedef struct VacAttrStats
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* These fields are set up by the main ANALYZE code before invoking
|
|
|
|
* the type-specific typanalyze function.
|
|
|
|
*/
|
|
|
|
Form_pg_attribute attr; /* copy of pg_attribute row for column */
|
|
|
|
Form_pg_type attrtype; /* copy of pg_type row for column */
|
|
|
|
MemoryContext anl_context; /* where to save long-lived data */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These fields must be filled in by the typanalyze routine,
|
|
|
|
* unless it returns FALSE.
|
|
|
|
*/
|
2004-02-13 07:39:49 +01:00
|
|
|
void (*compute_stats) (VacAttrStatsP stats,
|
|
|
|
AnalyzeAttrFetchFunc fetchfunc,
|
|
|
|
int samplerows,
|
|
|
|
double totalrows);
|
2004-02-13 00:41:04 +01:00
|
|
|
int minrows; /* Minimum # of rows wanted for stats */
|
|
|
|
void *extra_data; /* for extra type-specific data */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These fields are to be filled in by the compute_stats routine.
|
|
|
|
* (They are initialized to zero when the struct is created.)
|
|
|
|
*/
|
|
|
|
bool stats_valid;
|
|
|
|
float4 stanullfrac; /* fraction of entries that are NULL */
|
|
|
|
int4 stawidth; /* average width of column values */
|
|
|
|
float4 stadistinct; /* # distinct values */
|
|
|
|
int2 stakind[STATISTIC_NUM_SLOTS];
|
|
|
|
Oid staop[STATISTIC_NUM_SLOTS];
|
|
|
|
int numnumbers[STATISTIC_NUM_SLOTS];
|
|
|
|
float4 *stanumbers[STATISTIC_NUM_SLOTS];
|
|
|
|
int numvalues[STATISTIC_NUM_SLOTS];
|
|
|
|
Datum *stavalues[STATISTIC_NUM_SLOTS];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These fields are private to the main ANALYZE code and should not
|
|
|
|
* be looked at by type-specific functions.
|
|
|
|
*/
|
|
|
|
int tupattnum; /* attribute number within tuples */
|
2004-02-15 22:01:39 +01:00
|
|
|
HeapTuple *rows; /* access info for std fetch function */
|
2004-02-13 07:39:49 +01:00
|
|
|
TupleDesc tupDesc;
|
2004-02-15 22:01:39 +01:00
|
|
|
Datum *exprvals; /* access info for index fetch function */
|
|
|
|
bool *exprnulls;
|
|
|
|
int rowstride;
|
2004-02-13 00:41:04 +01:00
|
|
|
} VacAttrStats;
|
|
|
|
|
|
|
|
|
2001-07-12 06:11:13 +02:00
|
|
|
/* State structure for vac_init_rusage/vac_show_rusage */
|
|
|
|
typedef struct VacRUsage
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
struct timeval tv;
|
|
|
|
struct rusage ru;
|
2001-07-12 06:11:13 +02:00
|
|
|
} VacRUsage;
|
|
|
|
|
2002-07-31 19:19:54 +02:00
|
|
|
/* Default statistics target (GUC parameter) */
|
|
|
|
extern int default_statistics_target;
|
|
|
|
|
2001-07-12 06:11:13 +02:00
|
|
|
|
2001-05-07 02:43:27 +02:00
|
|
|
/* in commands/vacuum.c */
|
|
|
|
extern void vacuum(VacuumStmt *vacstmt);
|
2001-07-14 00:55:59 +02:00
|
|
|
extern void vac_open_indexes(Relation relation, int *nindexes,
|
2001-10-25 07:50:21 +02:00
|
|
|
Relation **Irel);
|
2001-07-14 00:55:59 +02:00
|
|
|
extern void vac_close_indexes(int nindexes, Relation *Irel);
|
2001-06-28 01:31:40 +02:00
|
|
|
extern void vac_update_relstats(Oid relid,
|
2001-10-25 07:50:21 +02:00
|
|
|
BlockNumber num_pages,
|
|
|
|
double num_tuples,
|
|
|
|
bool hasindex);
|
2001-08-26 18:56:03 +02:00
|
|
|
extern void vacuum_set_xid_limits(VacuumStmt *vacstmt, bool sharedRel,
|
2001-10-25 07:50:21 +02:00
|
|
|
TransactionId *oldestXmin,
|
|
|
|
TransactionId *freezeLimit);
|
2001-07-18 02:46:25 +02:00
|
|
|
extern bool vac_is_partial_index(Relation indrel);
|
2001-07-12 06:11:13 +02:00
|
|
|
extern void vac_init_rusage(VacRUsage *ru0);
|
|
|
|
extern const char *vac_show_rusage(VacRUsage *ru0);
|
2004-02-10 04:42:45 +01:00
|
|
|
extern void vacuum_delay_point(void);
|
2001-07-12 06:11:13 +02:00
|
|
|
|
2001-07-14 00:55:59 +02:00
|
|
|
/* in commands/vacuumlazy.c */
|
|
|
|
extern void lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt);
|
|
|
|
|
2001-05-07 02:43:27 +02:00
|
|
|
/* in commands/analyze.c */
|
|
|
|
extern void analyze_rel(Oid relid, VacuumStmt *vacstmt);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* VACUUM_H */
|