1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

Rewrite of planner statistics-gathering code. ANALYZE is now available as

a separate statement (though it can still be invoked as part of VACUUM, too).
pg_statistic redesigned to be more flexible about what statistics are
stored.  ANALYZE now collects a list of several of the most common values,
not just one, plus a histogram (not just the min and max values).  Random
sampling is used to make the process reasonably fast even on very large
tables.  The number of values and histogram bins collected is now
user-settable via an ALTER TABLE command.

There is more still to do; the new stats are not being used everywhere
they could be in the planner.  But the remaining changes for this project
should be localized, and the behavior is already better than before.

A not-very-related change is that sorting now makes use of btree comparison
routines if it can find one, rather than invoking '<' twice.
This commit is contained in:
Tom Lane
2001-05-07 00:43:27 +00:00
parent 9583aea9d0
commit f905d65ee3
66 changed files with 4131 additions and 2063 deletions

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: command.h,v 1.26 2001/03/22 04:00:41 momjian Exp $
* $Id: command.h,v 1.27 2001/05/07 00:43:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -43,9 +43,13 @@ extern void PortalCleanup(Portal portal);
extern void AlterTableAddColumn(const char *relationName,
bool inh, ColumnDef *colDef);
extern void AlterTableAlterColumn(const char *relationName,
bool inh, const char *colName,
Node *newDefault);
extern void AlterTableAlterColumnDefault(const char *relationName,
bool inh, const char *colName,
Node *newDefault);
extern void AlterTableAlterColumnStatistics(const char *relationName,
bool inh, const char *colName,
Node *statsTarget);
extern void AlterTableDropColumn(const char *relationName,
bool inh, const char *colName,

View File

@@ -1,129 +1,27 @@
/*-------------------------------------------------------------------------
*
* vacuum.h
* header file for postgres vacuum cleaner
* header file for postgres vacuum cleaner and statistics analyzer
*
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: vacuum.h,v 1.34 2001/03/22 04:00:43 momjian Exp $
* $Id: vacuum.h,v 1.35 2001/05/07 00:43:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef VACUUM_H
#define VACUUM_H
#include "catalog/pg_attribute.h"
#include "catalog/pg_index.h"
#include "fmgr.h"
#include "nodes/pg_list.h"
#include "storage/itemptr.h"
#include "nodes/parsenodes.h"
typedef struct VAttListData
{
int val_dummy;
struct VAttListData *val_next;
} VAttListData;
typedef VAttListData *VAttList;
typedef struct VacPageData
{
BlockNumber blkno; /* BlockNumber of this Page */
Size free; /* FreeSpace on this Page */
uint16 offsets_used; /* Number of OffNums used by vacuum */
uint16 offsets_free; /* Number of OffNums free or to be free */
OffsetNumber offsets[1]; /* Array of its OffNums */
} VacPageData;
typedef VacPageData *VacPage;
typedef struct VacPageListData
{
int empty_end_pages;/* Number of "empty" end-pages */
int num_pages; /* Number of pages in pagedesc */
int num_allocated_pages; /* Number of allocated pages in
* pagedesc */
VacPage *pagedesc; /* Descriptions of pages */
} VacPageListData;
typedef VacPageListData *VacPageList;
typedef struct
{
Form_pg_attribute attr;
Datum best,
guess1,
guess2,
max,
min;
int best_len,
guess1_len,
guess2_len,
max_len,
min_len;
long best_cnt,
guess1_cnt,
guess1_hits,
guess2_hits,
null_cnt,
nonnull_cnt,
max_cnt,
min_cnt;
FmgrInfo f_cmpeq,
f_cmplt,
f_cmpgt;
Oid op_cmplt;
regproc outfunc;
Oid typelem;
bool initialized;
} VacAttrStats;
typedef struct VRelListData
{
Oid vrl_relid;
struct VRelListData *vrl_next;
} VRelListData;
typedef VRelListData *VRelList;
typedef struct VTupleLinkData
{
ItemPointerData new_tid;
ItemPointerData this_tid;
} VTupleLinkData;
typedef VTupleLinkData *VTupleLink;
typedef struct VTupleMoveData
{
ItemPointerData tid; /* tuple ID */
VacPage vacpage; /* where to move */
bool cleanVpd; /* clean vacpage before using */
} VTupleMoveData;
typedef VTupleMoveData *VTupleMove;
typedef struct VRelStats
{
Oid relid;
int num_tuples;
int num_pages;
Size min_tlen;
Size max_tlen;
bool hasindex;
int num_vtlinks;
VTupleLink vtlinks;
} VRelStats;
extern bool VacuumRunning;
extern void vc_abort(void);
extern void vacuum(char *vacrel, bool verbose, bool analyze, List *anal_cols);
extern void analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL);
#define ATTNVALS_SCALE 1000000000 /* XXX so it can act as a float4 */
/* in commands/vacuum.c */
extern void vacuum(VacuumStmt *vacstmt);
extern void vac_update_relstats(Oid relid, long num_pages, double num_tuples,
bool hasindex);
/* in commands/analyze.c */
extern void analyze_rel(Oid relid, VacuumStmt *vacstmt);
#endif /* VACUUM_H */