Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit277807b

Browse files
committed
Add FILLFACTOR to CREATE INDEX.
ITAGAKI Takahiro
1 parent5d5c141 commit277807b

File tree

65 files changed

+1457
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1457
-308
lines changed

‎doc/src/sgml/ref/alter_index.sgml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_index.sgml,v 1.8 2006/02/12 19:11:00 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_index.sgml,v 1.9 2006/07/02 02:23:17 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -22,6 +22,8 @@ PostgreSQL documentation
2222
<synopsis>
2323
ALTER INDEX <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
2424
ALTER INDEX <replaceable class="PARAMETER">name</replaceable> SET TABLESPACE <replaceable class="PARAMETER">tablespace_name</replaceable>
25+
ALTER INDEX <replaceable class="PARAMETER">name</replaceable> SET (FILLFACTOR = <replaceable class="PARAMETER">fillfactor</replaceable>)
26+
ALTER INDEX <replaceable class="PARAMETER">name</replaceable> RESET (FILLFACTOR)
2527
</synopsis>
2628
</refsynopsisdiv>
2729

@@ -56,6 +58,26 @@ ALTER INDEX <replaceable class="PARAMETER">name</replaceable> SET TABLESPACE <re
5658
</listitem>
5759
</varlistentry>
5860

61+
<varlistentry>
62+
<term><literal>SET (FILLFACTOR)</literal></term>
63+
<listitem>
64+
<para>
65+
This form changes the index's fillfactor to the specified percentage.
66+
Index structure is not modified immediately; use <literal>REINDEX</literal>
67+
to ensure reflection of the change.
68+
</para>
69+
</listitem>
70+
</varlistentry>
71+
72+
<varlistentry>
73+
<term><literal>RESET (FILLFACTOR)</literal></term>
74+
<listitem>
75+
<para>
76+
This form changes the index's fillfactor to the default value.
77+
</para>
78+
</listitem>
79+
</varlistentry>
80+
5981
</variablelist>
6082
</para>
6183

‎doc/src/sgml/ref/alter_table.sgml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.85 2006/07/0201:58:36 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.86 2006/07/0202:23:17 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -46,6 +46,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
4646
CLUSTER ON <replaceable class="PARAMETER">index_name</replaceable>
4747
SET WITHOUT CLUSTER
4848
SET WITHOUT OIDS
49+
SET (FILLFACTOR = <replaceable class="PARAMETER">fillfactor</replaceable>)
50+
RESET (FILLFACTOR)
4951
INHERIT <replaceable class="PARAMETER">parent_table</replaceable>
5052
NO INHERIT <replaceable class="PARAMETER">parent_table</replaceable>
5153
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
@@ -321,6 +323,26 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
321323
</listitem>
322324
</varlistentry>
323325

326+
<varlistentry>
327+
<term><literal>SET (FILLFACTOR)</literal></term>
328+
<listitem>
329+
<para>
330+
This form changes the table's fillfactor to the specified percentage.
331+
Table structure is not modified immediately; use <literal>CLUSTER</literal>
332+
to ensure reflection of the change.
333+
</para>
334+
</listitem>
335+
</varlistentry>
336+
337+
<varlistentry>
338+
<term><literal>RESET</literal></term>
339+
<listitem>
340+
<para>
341+
This form changes the table's fillfactor to the default value.
342+
</para>
343+
</listitem>
344+
</varlistentry>
345+
324346
<varlistentry>
325347
<term><literal>RENAME</literal></term>
326348
<listitem>

‎doc/src/sgml/ref/create_index.sgml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_index.sgml,v 1.52 2005/11/07 17:36:44 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_index.sgml,v 1.53 2006/07/02 02:23:17 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -22,6 +22,7 @@ PostgreSQL documentation
2222
<synopsis>
2323
CREATE [ UNIQUE ] INDEX <replaceable class="parameter">name</replaceable> ON <replaceable class="parameter">table</replaceable> [ USING <replaceable class="parameter">method</replaceable> ]
2424
( { <replaceable class="parameter">column</replaceable> | ( <replaceable class="parameter">expression</replaceable> ) } [ <replaceable class="parameter">opclass</replaceable> ] [, ...] )
25+
[ WITH (FILLFACTOR = <replaceable>fillfactor</replaceable>) ]
2526
[ TABLESPACE <replaceable class="parameter">tablespace</replaceable> ]
2627
[ WHERE <replaceable class="parameter">predicate</replaceable> ]
2728
</synopsis>
@@ -171,6 +172,15 @@ CREATE [ UNIQUE ] INDEX <replaceable class="parameter">name</replaceable> ON <re
171172
</listitem>
172173
</varlistentry>
173174

175+
<varlistentry>
176+
<term><replaceable class="parameter">fillfactor</replaceable></term>
177+
<listitem>
178+
<para>
179+
The index's fillfactor in percentage.
180+
</para>
181+
</listitem>
182+
</varlistentry>
183+
174184
<varlistentry>
175185
<term><replaceable class="parameter">tablespace</replaceable></term>
176186
<listitem>

‎doc/src/sgml/ref/create_table.sgml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.102 2006/06/28 22:01:52 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.103 2006/07/02 02:23:17 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -28,6 +28,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
2828
] )
2929
[ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
3030
[ WITH OIDS | WITHOUT OIDS ]
31+
[ WITH (FILLFACTOR = <replaceable>fillfactor</replaceable>) ]
3132
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
3233
[ TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]
3334

@@ -303,6 +304,15 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
303304
</listitem>
304305
</varlistentry>
305306

307+
<varlistentry>
308+
<term><literal>WITH (FILLFACTOR = <replaceable>fillfactor</replaceable>)</literal></term>
309+
<listitem>
310+
<para>
311+
This optional clause specifies the table's fillfactor in percentage.
312+
</para>
313+
</listitem>
314+
</varlistentry>
315+
306316
<varlistentry>
307317
<term><literal>CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable></literal></term>
308318
<listitem>

‎doc/src/sgml/ref/create_table_as.sgml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.32 2006/02/19 00:04:26 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.33 2006/07/02 02:23:18 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -23,6 +23,7 @@ PostgreSQL documentation
2323
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name</replaceable>
2424
[ (<replaceable>column_name</replaceable> [, ...] ) ]
2525
[ WITH OIDS | WITHOUT OIDS ]
26+
[ WITH (FILLFACTOR = <replaceable>fillfactor</replaceable>) ]
2627
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
2728
[ TABLESPACE <replaceable class="PARAMETER">tablespace</replaceable> ]
2829
AS <replaceable>query</replaceable>
@@ -116,6 +117,15 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name
116117
</listitem>
117118
</varlistentry>
118119

120+
<varlistentry>
121+
<term><literal>WITH (FILLFACTOR = <replaceable>fillfactor</replaceable>)</literal></term>
122+
<listitem>
123+
<para>
124+
This optional clause specifies the table's fillfactor in percentage.
125+
</para>
126+
</listitem>
127+
</varlistentry>
128+
119129
<varlistentry>
120130
<term><literal>ON COMMIT</literal></term>
121131
<listitem>

‎src/backend/access/common/heaptuple.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.107 2006/06/27 02:51:39 tgl Exp $
19+
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.108 2006/07/02 02:23:18 momjian Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -1738,3 +1738,54 @@ heap_addheader(int natts,/* max domain index */
17381738

17391739
returntuple;
17401740
}
1741+
1742+
/*
1743+
* build_class_tuple
1744+
*
1745+
*XXX Natts_pg_class_fixed is a hack - see pg_class.h
1746+
*/
1747+
HeapTuple
1748+
build_class_tuple(Form_pg_classpgclass,ArrayType*options)
1749+
{
1750+
HeapTupletuple;
1751+
HeapTupleHeadertd;
1752+
Form_pg_classdata;/* contents of tuple */
1753+
Sizelen;
1754+
Sizesize;
1755+
inthoff;
1756+
1757+
/* size of pg_class tuple with options */
1758+
if (options)
1759+
size= offsetof(FormData_pg_class,reloptions)+VARATT_SIZE(options);
1760+
else
1761+
size=CLASS_TUPLE_SIZE;
1762+
1763+
/* header needs no null bitmap */
1764+
hoff= offsetof(HeapTupleHeaderData,t_bits);
1765+
hoff+=sizeof(Oid);
1766+
hoff=MAXALIGN(hoff);
1767+
len=hoff+size;
1768+
1769+
tuple= (HeapTuple)palloc0(HEAPTUPLESIZE+len);
1770+
tuple->t_data=td= (HeapTupleHeader) ((char*)tuple+HEAPTUPLESIZE);
1771+
1772+
tuple->t_len=len;
1773+
ItemPointerSetInvalid(&(tuple->t_self));
1774+
tuple->t_tableOid=InvalidOid;
1775+
1776+
/* we don't bother to fill the Datum fields */
1777+
1778+
td->t_natts=Natts_pg_class_fixed;
1779+
td->t_hoff=hoff;
1780+
td->t_infomask=HEAP_HASOID;
1781+
1782+
data= (Form_pg_class) ((char*)td+hoff);
1783+
memcpy(data,pgclass,CLASS_TUPLE_SIZE);
1784+
if (options)
1785+
{
1786+
td->t_natts++;
1787+
memcpy(data->reloptions,options,VARATT_SIZE(options));
1788+
}
1789+
1790+
returntuple;
1791+
}

‎src/backend/access/gin/ginutil.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gin/ginutil.c,v 1.1 2006/05/0211:28:54 teodor Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gin/ginutil.c,v 1.2 2006/07/0202:23:18 momjian Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

@@ -201,3 +201,17 @@ GinPageGetCopyPage( Page page ) {
201201

202202
returntmppage;
203203
}
204+
205+
Datum
206+
ginoption(PG_FUNCTION_ARGS)
207+
{
208+
ArrayType*options= (ArrayType*)PG_GETARG_POINTER(0);
209+
210+
if (options!=NULL)
211+
ereport(ERROR,
212+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
213+
errmsg("GIN does not support parameters at all")));
214+
215+
/* Do not use PG_RETURN_NULL. */
216+
PG_RETURN_BYTEA_P(NULL);
217+
}

‎src/backend/access/gist/gist.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.139 2006/06/28 12:00:14 teodor Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.140 2006/07/02 02:23:18 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -44,6 +44,7 @@ static void gistbuildCallback(Relation index,
4444
void*state);
4545
staticvoidgistdoinsert(Relationr,
4646
IndexTupleitup,
47+
Sizefreespace,
4748
GISTSTATE*GISTstate);
4849
staticvoidgistfindleaf(GISTInsertState*state,
4950
GISTSTATE*giststate);
@@ -197,7 +198,8 @@ gistbuildCallback(Relation index,
197198
* you're inserting single tups, but not when you're initializing the
198199
* whole index at once.
199200
*/
200-
gistdoinsert(index,itup,&buildstate->giststate);
201+
gistdoinsert(index,itup,IndexGetPageFreeSpace(index),
202+
&buildstate->giststate);
201203

202204
buildstate->indtuples+=1;
203205
MemoryContextSwitchTo(oldCtx);
@@ -236,7 +238,7 @@ gistinsert(PG_FUNCTION_ARGS)
236238
values,isnull, true/* size is currently bogus */);
237239
itup->t_tid=*ht_ctid;
238240

239-
gistdoinsert(r,itup,&giststate);
241+
gistdoinsert(r,itup,0,&giststate);
240242

241243
/* cleanup */
242244
freeGISTstate(&giststate);
@@ -253,7 +255,7 @@ gistinsert(PG_FUNCTION_ARGS)
253255
* so it does not bother releasing palloc'd allocations.
254256
*/
255257
staticvoid
256-
gistdoinsert(Relationr,IndexTupleitup,GISTSTATE*giststate)
258+
gistdoinsert(Relationr,IndexTupleitup,Sizefreespace,GISTSTATE*giststate)
257259
{
258260
GISTInsertStatestate;
259261

@@ -263,6 +265,7 @@ gistdoinsert(Relation r, IndexTuple itup, GISTSTATE *giststate)
263265
state.itup[0]= (IndexTuple)palloc(IndexTupleSize(itup));
264266
memcpy(state.itup[0],itup,IndexTupleSize(itup));
265267
state.ituplen=1;
268+
state.freespace=freespace;
266269
state.r=r;
267270
state.key=itup->t_tid;
268271
state.needInsertComplete= true;
@@ -294,7 +297,11 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
294297
*/
295298

296299

297-
if (gistnospace(state->stack->page,state->itup,state->ituplen, (is_leaf) ?InvalidOffsetNumber :state->stack->childoffnum))
300+
/*
301+
* XXX: If we want to change fillfactors between node and leaf,
302+
* fillfactor = (is_leaf ? state->leaf_fillfactor : state->node_fillfactor)
303+
*/
304+
if (gistnospace(state->stack->page,state->itup,state->ituplen, (is_leaf) ?InvalidOffsetNumber :state->stack->childoffnum,state->freespace))
298305
{
299306
/* no space for insertion */
300307
IndexTuple*itvec;

‎src/backend/access/gist/gistutil.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
*$PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.16 2006/06/28 12:00:14 teodor Exp $
11+
*$PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.17 2006/07/02 02:23:18 momjian Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include"postgres.h"
@@ -58,9 +58,9 @@ gistfillbuffer(Relation r, Page page, IndexTuple *itup,
5858
* Check space for itup vector on page
5959
*/
6060
bool
61-
gistnospace(Pagepage,IndexTuple*itvec,intlen,OffsetNumbertodelete)
61+
gistnospace(Pagepage,IndexTuple*itvec,intlen,OffsetNumbertodelete,Sizefreespace)
6262
{
63-
unsignedintsize=0,deleted=0;
63+
unsignedintsize=freespace,deleted=0;
6464
inti;
6565

6666
for (i=0;i<len;i++)
@@ -82,6 +82,7 @@ gistfitpage(IndexTuple *itvec, int len) {
8282
for(i=0;i<len;i++)
8383
size+=IndexTupleSize(itvec[i])+sizeof(ItemIdData);
8484

85+
/* TODO: Consider fillfactor */
8586
return (size <=GiSTPageSize);
8687
}
8788

@@ -634,3 +635,16 @@ gistNewBuffer(Relation r)
634635

635636
returnbuffer;
636637
}
638+
639+
Datum
640+
gistoption(PG_FUNCTION_ARGS)
641+
{
642+
#defineGIST_DEFAULT_FILLFACTOR90
643+
#defineGIST_MIN_FILLFACTOR50
644+
645+
ArrayType*options= (ArrayType*)PG_GETARG_POINTER(0);
646+
647+
/* Use index common routine. */
648+
PG_RETURN_BYTEA_P(genam_option(options,
649+
GIST_MIN_FILLFACTOR,GIST_DEFAULT_FILLFACTOR));
650+
}

‎src/backend/access/gist/gistvacuum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.22 2006/05/19 11:10:25 teodor Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.23 2006/07/02 02:23:18 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -376,7 +376,7 @@ gistVacuumUpdate(GistVacuum *gv, BlockNumber blkno, bool needunion)
376376
if (curlenaddon)
377377
{
378378
/* insert updated tuples */
379-
if (gistnospace(tempPage,addon,curlenaddon,InvalidOffsetNumber)) {
379+
if (gistnospace(tempPage,addon,curlenaddon,InvalidOffsetNumber,0)) {
380380
/* there is no space on page to insert tuples */
381381
res=vacuumSplitPage(gv,tempPage,buffer,addon,curlenaddon);
382382
tempPage=NULL;/* vacuumSplitPage() free tempPage */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp