mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Add FILLFACTOR to CREATE INDEX.
ITAGAKI Takahiro
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.302 2006/06/29 16:07:29 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.303 2006/07/02 02:23:19 momjian Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@@ -44,20 +44,24 @@
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/tablecmds.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "commands/defrem.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "optimizer/clauses.h"
|
||||
#include "optimizer/planmain.h"
|
||||
#include "optimizer/var.h"
|
||||
#include "parser/parse_coerce.h"
|
||||
#include "parser/parse_clause.h"
|
||||
#include "parser/parse_expr.h"
|
||||
#include "parser/parse_relation.h"
|
||||
#include "rewrite/rewriteRemove.h"
|
||||
#include "storage/smgr.h"
|
||||
#include "utils/catcache.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/inval.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
@@ -66,7 +70,8 @@ static void AddNewRelationTuple(Relation pg_class_desc,
|
||||
Relation new_rel_desc,
|
||||
Oid new_rel_oid, Oid new_type_oid,
|
||||
Oid relowner,
|
||||
char relkind);
|
||||
char relkind,
|
||||
ArrayType *options);
|
||||
static Oid AddNewRelationType(const char *typeName,
|
||||
Oid typeNamespace,
|
||||
Oid new_rel_oid,
|
||||
@@ -558,7 +563,8 @@ AddNewRelationTuple(Relation pg_class_desc,
|
||||
Oid new_rel_oid,
|
||||
Oid new_type_oid,
|
||||
Oid relowner,
|
||||
char relkind)
|
||||
char relkind,
|
||||
ArrayType *options)
|
||||
{
|
||||
Form_pg_class new_rel_reltup;
|
||||
HeapTuple tup;
|
||||
@@ -596,15 +602,8 @@ AddNewRelationTuple(Relation pg_class_desc,
|
||||
|
||||
new_rel_desc->rd_att->tdtypeid = new_type_oid;
|
||||
|
||||
/* ----------------
|
||||
* now form a tuple to add to pg_class
|
||||
* XXX Natts_pg_class_fixed is a hack - see pg_class.h
|
||||
* ----------------
|
||||
*/
|
||||
tup = heap_addheader(Natts_pg_class_fixed,
|
||||
true,
|
||||
CLASS_TUPLE_SIZE,
|
||||
(void *) new_rel_reltup);
|
||||
/* now form a tuple to add to pg_class */
|
||||
tup = build_class_tuple(new_rel_reltup, options);
|
||||
|
||||
/* force tuple to have the desired OID */
|
||||
HeapTupleSetOid(tup, new_rel_oid);
|
||||
@@ -661,6 +660,8 @@ AddNewRelationType(const char *typeName,
|
||||
* heap_create_with_catalog
|
||||
*
|
||||
* creates a new cataloged relation. see comments above.
|
||||
*
|
||||
* if opaque is specified, it must be allocated in CacheMemoryContext.
|
||||
* --------------------------------
|
||||
*/
|
||||
Oid
|
||||
@@ -675,10 +676,12 @@ heap_create_with_catalog(const char *relname,
|
||||
bool oidislocal,
|
||||
int oidinhcount,
|
||||
OnCommitAction oncommit,
|
||||
bool allow_system_table_mods)
|
||||
bool allow_system_table_mods,
|
||||
ArrayType *options)
|
||||
{
|
||||
Relation pg_class_desc;
|
||||
Relation new_rel_desc;
|
||||
bytea *new_rel_options;
|
||||
Oid new_type_oid;
|
||||
|
||||
pg_class_desc = heap_open(RelationRelationId, RowExclusiveLock);
|
||||
@@ -695,6 +698,13 @@ heap_create_with_catalog(const char *relname,
|
||||
(errcode(ERRCODE_DUPLICATE_TABLE),
|
||||
errmsg("relation \"%s\" already exists", relname)));
|
||||
|
||||
/*
|
||||
* Parse options to check if option is valid.
|
||||
*/
|
||||
new_rel_options = heap_option(relkind, options);
|
||||
Assert(!new_rel_options ||
|
||||
GetMemoryChunkContext(new_rel_options) == CacheMemoryContext);
|
||||
|
||||
/*
|
||||
* Allocate an OID for the relation, unless we were told what to use.
|
||||
*
|
||||
@@ -718,6 +728,7 @@ heap_create_with_catalog(const char *relname,
|
||||
relkind,
|
||||
shared_relation,
|
||||
allow_system_table_mods);
|
||||
new_rel_desc->rd_options = new_rel_options;
|
||||
|
||||
Assert(relid == RelationGetRelid(new_rel_desc));
|
||||
|
||||
@@ -745,7 +756,8 @@ heap_create_with_catalog(const char *relname,
|
||||
relid,
|
||||
new_type_oid,
|
||||
ownerid,
|
||||
relkind);
|
||||
relkind,
|
||||
options);
|
||||
|
||||
/*
|
||||
* now add tuples to pg_attribute for the attributes in our new relation.
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.266 2006/05/10 23:18:39 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.267 2006/07/02 02:23:19 momjian Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "executor/executor.h"
|
||||
#include "miscadmin.h"
|
||||
#include "optimizer/clauses.h"
|
||||
#include "parser/parse_clause.h"
|
||||
#include "parser/parse_expr.h"
|
||||
#include "storage/procarray.h"
|
||||
#include "storage/smgr.h"
|
||||
@@ -53,7 +54,8 @@
|
||||
static TupleDesc ConstructTupleDescriptor(Relation heapRelation,
|
||||
IndexInfo *indexInfo,
|
||||
Oid *classObjectId);
|
||||
static void UpdateRelationRelation(Relation pg_class, Relation indexRelation);
|
||||
static void UpdateRelationRelation(Relation pg_class, Relation indexRelation,
|
||||
ArrayType *options);
|
||||
static void InitializeAttributeOids(Relation indexRelation,
|
||||
int numatts, Oid indexoid);
|
||||
static void AppendAttributeTuples(Relation indexRelation, int numatts);
|
||||
@@ -241,15 +243,12 @@ ConstructTupleDescriptor(Relation heapRelation,
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
UpdateRelationRelation(Relation pg_class, Relation indexRelation)
|
||||
UpdateRelationRelation(Relation pg_class, Relation indexRelation,
|
||||
ArrayType *options)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
|
||||
/* XXX Natts_pg_class_fixed is a hack - see pg_class.h */
|
||||
tuple = heap_addheader(Natts_pg_class_fixed,
|
||||
true,
|
||||
CLASS_TUPLE_SIZE,
|
||||
(void *) indexRelation->rd_rel);
|
||||
tuple = build_class_tuple(indexRelation->rd_rel, options);
|
||||
|
||||
/*
|
||||
* the new tuple must have the oid already chosen for the index. sure
|
||||
@@ -467,6 +466,7 @@ index_create(Oid heapRelationId,
|
||||
Oid accessMethodObjectId,
|
||||
Oid tableSpaceId,
|
||||
Oid *classObjectId,
|
||||
List *options,
|
||||
bool isprimary,
|
||||
bool istoast,
|
||||
bool isconstraint,
|
||||
@@ -481,6 +481,9 @@ index_create(Oid heapRelationId,
|
||||
Oid namespaceId;
|
||||
int i;
|
||||
|
||||
ArrayType *array;
|
||||
RegProcedure amoption;
|
||||
|
||||
pg_class = heap_open(RelationRelationId, RowExclusiveLock);
|
||||
|
||||
/*
|
||||
@@ -578,12 +581,41 @@ index_create(Oid heapRelationId,
|
||||
indexRelation->rd_rel->relkind = RELKIND_INDEX;
|
||||
indexRelation->rd_rel->relhasoids = false;
|
||||
|
||||
/*
|
||||
* AM specific options.
|
||||
*/
|
||||
array = OptionBuild(NULL, options);
|
||||
if (indexRelation->rd_am)
|
||||
{
|
||||
amoption = indexRelation->rd_am->amoption;
|
||||
}
|
||||
else
|
||||
{
|
||||
HeapTuple tuple;
|
||||
|
||||
/*
|
||||
* We may use the access method before initializing relation,
|
||||
* so we pick up AM from syscache directly.
|
||||
*/
|
||||
tuple = SearchSysCache(AMOID,
|
||||
ObjectIdGetDatum(accessMethodObjectId),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "cache lookup failed for access method %u",
|
||||
accessMethodObjectId);
|
||||
amoption = ((Form_pg_am) GETSTRUCT(tuple))->amoption;
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
indexRelation->rd_options = index_option(amoption, array);
|
||||
|
||||
/*
|
||||
* store index's pg_class entry
|
||||
*/
|
||||
UpdateRelationRelation(pg_class, indexRelation);
|
||||
UpdateRelationRelation(pg_class, indexRelation, array);
|
||||
|
||||
/* done with pg_class */
|
||||
if (array)
|
||||
pfree(array);
|
||||
heap_close(pg_class, RowExclusiveLock);
|
||||
|
||||
/*
|
||||
@@ -1751,3 +1783,23 @@ reindex_relation(Oid relid, bool toast_too)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse options for indexes.
|
||||
*
|
||||
* amoption Oid of option parser.
|
||||
* options Options as text[]
|
||||
*/
|
||||
bytea *index_option(RegProcedure amoption, ArrayType *options)
|
||||
{
|
||||
Datum datum;
|
||||
|
||||
Assert(RegProcedureIsValid(amoption));
|
||||
|
||||
datum = OidFunctionCall1(amoption, PointerGetDatum(options));
|
||||
|
||||
if (DatumGetPointer(datum) == NULL)
|
||||
return NULL;
|
||||
|
||||
return DatumGetByteaP(datum);
|
||||
}
|
||||
|
@@ -9,16 +9,19 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/indexing.c,v 1.111 2006/03/05 15:58:22 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/indexing.c,v 1.112 2006/07/02 02:23:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "access/genam.h"
|
||||
#include "access/heapam.h"
|
||||
#include "catalog/index.h"
|
||||
#include "catalog/indexing.h"
|
||||
#include "executor/executor.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "commands/defrem.h"
|
||||
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user