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

Commit70c9763

Browse files
committed
Convert oidvector and int2vector into variable-length arrays. This
change saves a great deal of space in pg_proc and its primary index,and it eliminates the former requirement that INDEX_MAX_KEYS andFUNC_MAX_ARGS have the same value. INDEX_MAX_KEYS is still embeddedin the on-disk representation (because it affects index tuple headersize), but FUNC_MAX_ARGS is not. I believe it would now be possibleto increase FUNC_MAX_ARGS at little cost, but haven't experimented yet.There are still a lot of vestigial references to FUNC_MAX_ARGS, whichI will clean up in a separate pass. However, getting rid of italtogether would require changing the FunctionCallInfoData struct,and I'm not sure I want to buy into that.
1 parent1191916 commit70c9763

File tree

61 files changed

+828
-590
lines changed

Some content is hidden

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

61 files changed

+828
-590
lines changed

‎contrib/dblink/dblink.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ static HTAB *createConnHash(void);
7474
staticvoidcreateNewConnection(constchar*name,remoteConn*con);
7575
staticvoiddeleteConnection(constchar*name);
7676
staticchar**get_pkey_attnames(Oidrelid,int16*numatts);
77-
staticchar*get_sql_insert(Oidrelid,int16*pkattnums,int16pknumatts,char**src_pkattvals,char**tgt_pkattvals);
78-
staticchar*get_sql_delete(Oidrelid,int16*pkattnums,int16pknumatts,char**tgt_pkattvals);
79-
staticchar*get_sql_update(Oidrelid,int16*pkattnums,int16pknumatts,char**src_pkattvals,char**tgt_pkattvals);
77+
staticchar*get_sql_insert(Oidrelid,int2vector*pkattnums,int16pknumatts,char**src_pkattvals,char**tgt_pkattvals);
78+
staticchar*get_sql_delete(Oidrelid,int2vector*pkattnums,int16pknumatts,char**tgt_pkattvals);
79+
staticchar*get_sql_update(Oidrelid,int2vector*pkattnums,int16pknumatts,char**src_pkattvals,char**tgt_pkattvals);
8080
staticchar*quote_literal_cstr(char*rawstr);
8181
staticchar*quote_ident_cstr(char*rawstr);
82-
staticint16get_attnum_pk_pos(int16*pkattnums,int16pknumatts,int16key);
83-
staticHeapTupleget_tuple_of_interest(Oidrelid,int16*pkattnums,int16pknumatts,char**src_pkattvals);
82+
staticint16get_attnum_pk_pos(int2vector*pkattnums,int16pknumatts,int16key);
83+
staticHeapTupleget_tuple_of_interest(Oidrelid,int2vector*pkattnums,int16pknumatts,char**src_pkattvals);
8484
staticOidget_relid_from_relname(text*relname_text);
8585
staticchar*generate_relation_name(Oidrelid);
8686

@@ -1094,7 +1094,7 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
10941094
{
10951095
Oidrelid;
10961096
text*relname_text;
1097-
int16*pkattnums;
1097+
int2vector*pkattnums;
10981098
intpknumatts_tmp;
10991099
int16pknumatts=0;
11001100
char**src_pkattvals;
@@ -1126,7 +1126,7 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
11261126
errmsg("relation \"%s\" does not exist",
11271127
GET_STR(relname_text))));
11281128

1129-
pkattnums= (int16*)PG_GETARG_POINTER(1);
1129+
pkattnums= (int2vector*)PG_GETARG_POINTER(1);
11301130
pknumatts_tmp=PG_GETARG_INT32(2);
11311131
if (pknumatts_tmp <=SHRT_MAX)
11321132
pknumatts=pknumatts_tmp;
@@ -1246,7 +1246,7 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS)
12461246
{
12471247
Oidrelid;
12481248
text*relname_text;
1249-
int16*pkattnums;
1249+
int2vector*pkattnums;
12501250
intpknumatts_tmp;
12511251
int16pknumatts=0;
12521252
char**tgt_pkattvals;
@@ -1273,7 +1273,7 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS)
12731273
errmsg("relation \"%s\" does not exist",
12741274
GET_STR(relname_text))));
12751275

1276-
pkattnums= (int16*)PG_GETARG_POINTER(1);
1276+
pkattnums= (int2vector*)PG_GETARG_POINTER(1);
12771277
pknumatts_tmp=PG_GETARG_INT32(2);
12781278
if (pknumatts_tmp <=SHRT_MAX)
12791279
pknumatts=pknumatts_tmp;
@@ -1363,7 +1363,7 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
13631363
{
13641364
Oidrelid;
13651365
text*relname_text;
1366-
int16*pkattnums;
1366+
int2vector*pkattnums;
13671367
intpknumatts_tmp;
13681368
int16pknumatts=0;
13691369
char**src_pkattvals;
@@ -1395,7 +1395,7 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
13951395
errmsg("relation \"%s\" does not exist",
13961396
GET_STR(relname_text))));
13971397

1398-
pkattnums= (int16*)PG_GETARG_POINTER(1);
1398+
pkattnums= (int2vector*)PG_GETARG_POINTER(1);
13991399
pknumatts_tmp=PG_GETARG_INT32(2);
14001400
if (pknumatts_tmp <=SHRT_MAX)
14011401
pknumatts=pknumatts_tmp;
@@ -1552,16 +1552,13 @@ get_pkey_attnames(Oid relid, int16 *numatts)
15521552
/* we're only interested if it is the primary key */
15531553
if (index->indisprimary== TRUE)
15541554
{
1555-
i=0;
1556-
while (index->indkey[i++]!=0)
1557-
(*numatts)++;
1558-
1555+
*numatts=index->indnatts;
15591556
if (*numatts>0)
15601557
{
15611558
result= (char**)palloc(*numatts*sizeof(char*));
15621559

15631560
for (i=0;i<*numatts;i++)
1564-
result[i]=SPI_fname(tupdesc,index->indkey[i]);
1561+
result[i]=SPI_fname(tupdesc,index->indkey.values[i]);
15651562
}
15661563
break;
15671564
}
@@ -1574,7 +1571,7 @@ get_pkey_attnames(Oid relid, int16 *numatts)
15741571
}
15751572

15761573
staticchar*
1577-
get_sql_insert(Oidrelid,int16*pkattnums,int16pknumatts,char**src_pkattvals,char**tgt_pkattvals)
1574+
get_sql_insert(Oidrelid,int2vector*pkattnums,int16pknumatts,char**src_pkattvals,char**tgt_pkattvals)
15781575
{
15791576
Relationrel;
15801577
char*relname;
@@ -1664,7 +1661,7 @@ get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
16641661
}
16651662

16661663
staticchar*
1667-
get_sql_delete(Oidrelid,int16*pkattnums,int16pknumatts,char**tgt_pkattvals)
1664+
get_sql_delete(Oidrelid,int2vector*pkattnums,int16pknumatts,char**tgt_pkattvals)
16681665
{
16691666
Relationrel;
16701667
char*relname;
@@ -1688,7 +1685,7 @@ get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattval
16881685
appendStringInfo(str,"DELETE FROM %s WHERE ",relname);
16891686
for (i=0;i<pknumatts;i++)
16901687
{
1691-
int16pkattnum=pkattnums[i];
1688+
int16pkattnum=pkattnums->values[i];
16921689

16931690
if (i>0)
16941691
appendStringInfo(str," AND ");
@@ -1720,7 +1717,7 @@ get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattval
17201717
}
17211718

17221719
staticchar*
1723-
get_sql_update(Oidrelid,int16*pkattnums,int16pknumatts,char**src_pkattvals,char**tgt_pkattvals)
1720+
get_sql_update(Oidrelid,int2vector*pkattnums,int16pknumatts,char**src_pkattvals,char**tgt_pkattvals)
17241721
{
17251722
Relationrel;
17261723
char*relname;
@@ -1788,7 +1785,7 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval
17881785

17891786
for (i=0;i<pknumatts;i++)
17901787
{
1791-
int16pkattnum=pkattnums[i];
1788+
int16pkattnum=pkattnums->values[i];
17921789

17931790
if (i>0)
17941791
appendStringInfo(str," AND ");
@@ -1855,22 +1852,22 @@ quote_ident_cstr(char *rawstr)
18551852
}
18561853

18571854
staticint16
1858-
get_attnum_pk_pos(int16*pkattnums,int16pknumatts,int16key)
1855+
get_attnum_pk_pos(int2vector*pkattnums,int16pknumatts,int16key)
18591856
{
18601857
inti;
18611858

18621859
/*
18631860
* Not likely a long list anyway, so just scan for the value
18641861
*/
18651862
for (i=0;i<pknumatts;i++)
1866-
if (key==pkattnums[i])
1863+
if (key==pkattnums->values[i])
18671864
returni;
18681865

18691866
return-1;
18701867
}
18711868

18721869
staticHeapTuple
1873-
get_tuple_of_interest(Oidrelid,int16*pkattnums,int16pknumatts,char**src_pkattvals)
1870+
get_tuple_of_interest(Oidrelid,int2vector*pkattnums,int16pknumatts,char**src_pkattvals)
18741871
{
18751872
Relationrel;
18761873
char*relname;
@@ -1907,7 +1904,7 @@ get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_p
19071904

19081905
for (i=0;i<pknumatts;i++)
19091906
{
1910-
int16pkattnum=pkattnums[i];
1907+
int16pkattnum=pkattnums->values[i];
19111908

19121909
if (i>0)
19131910
appendStringInfo(str," AND ");

‎contrib/dbmirror/pending.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/****************************************************************************
22
* pending.c
3-
* $Id: pending.c,v 1.20 2004/09/10 04:31:06 neilc Exp $
4-
* $PostgreSQL: pgsql/contrib/dbmirror/pending.c,v 1.20 2004/09/10 04:31:06 neilc Exp $
3+
* $Id: pending.c,v 1.21 2005/03/29 00:16:48 tgl Exp $
4+
* $PostgreSQL: pgsql/contrib/dbmirror/pending.c,v 1.21 2005/03/29 00:16:48 tgl Exp $
55
*
66
* This file contains a trigger for Postgresql-7.x to record changes to tables
77
* to a pending table for mirroring.
@@ -349,8 +349,8 @@ getPrimaryKey(Oid tblOid)
349349
resDatum=SPI_getbinval(resTuple,SPI_tuptable->tupdesc,1,&isNull);
350350

351351
tpResultKey= (int2vector*)DatumGetPointer(resDatum);
352-
resultKey=SPI_palloc(sizeof(int2vector));
353-
memcpy(resultKey,tpResultKey,sizeof(int2vector));
352+
resultKey=SPI_palloc(VARSIZE(tpResultKey));
353+
memcpy(resultKey,tpResultKey,VARSIZE(tpResultKey));
354354

355355
returnresultKey;
356356
}
@@ -438,11 +438,8 @@ packageData(HeapTuple tTupleData, TupleDesc tTupleDesc, Oid tableOid,
438438
}
439439

440440
if (tpPKeys!=NULL)
441-
{
442441
debug_msg("dbmirror:packageData have primary keys");
443442

444-
}
445-
446443
cpDataBlock=SPI_palloc(BUFFER_SIZE);
447444
iDataBlockSize=BUFFER_SIZE;
448445
iUsedDataBlock=0;/* To account for the null */
@@ -462,11 +459,10 @@ packageData(HeapTuple tTupleData, TupleDesc tTupleDesc, Oid tableOid,
462459
/* Determine if this is a primary key or not. */
463460
iIsPrimaryKey=0;
464461
for (iPrimaryKeyIndex=0;
465-
(*tpPKeys)[iPrimaryKeyIndex]!=0;
462+
iPrimaryKeyIndex<tpPKeys->dim1;
466463
iPrimaryKeyIndex++)
467464
{
468-
if ((*tpPKeys)[iPrimaryKeyIndex]
469-
==iColumnCounter)
465+
if (tpPKeys->values[iPrimaryKeyIndex]==iColumnCounter)
470466
{
471467
iIsPrimaryKey=1;
472468
break;

‎doc/src/sgml/catalogs.sgml

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.97 2005/03/27 23:52:51 tgl Exp $
3+
$PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.98 2005/03/29 00:16:49 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -2007,32 +2007,6 @@
20072007
<entry>The OID of the <structname>pg_class</> entry for the table this index is for</entry>
20082008
</row>
20092009

2010-
<row>
2011-
<entry><structfield>indkey</structfield></entry>
2012-
<entry><type>int2vector</type></entry>
2013-
<entry><literal><link linkend="catalog-pg-attribute"><structname>pg_attribute</structname></link>.attnum</literal></entry>
2014-
<entry>
2015-
This is an array of <structfield>indnatts</structfield> (up to
2016-
<symbol>INDEX_MAX_KEYS</symbol>) values that indicate which
2017-
table columns this index indexes. For example a value of
2018-
<literal>1 3</literal> would mean that the first and the third table
2019-
columns make up the index key. A zero in this array indicates that the
2020-
corresponding index attribute is an expression over the table columns,
2021-
rather than a simple column reference.
2022-
</entry>
2023-
</row>
2024-
2025-
<row>
2026-
<entry><structfield>indclass</structfield></entry>
2027-
<entry><type>oidvector</type></entry>
2028-
<entry><literal><link linkend="catalog-pg-opclass"><structname>pg_opclass</structname></link>.oid</literal></entry>
2029-
<entry>
2030-
For each column in the index key this contains the OID of
2031-
the operator class to use. See
2032-
<structname>pg_opclass</structname> for details.
2033-
</entry>
2034-
</row>
2035-
20362010
<row>
20372011
<entry><structfield>indnatts</structfield></entry>
20382012
<entry><type>int2</type></entry>
@@ -2063,6 +2037,31 @@
20632037
<entry>If true, the table was last clustered on this index.</entry>
20642038
</row>
20652039

2040+
<row>
2041+
<entry><structfield>indkey</structfield></entry>
2042+
<entry><type>int2vector</type></entry>
2043+
<entry><literal><link linkend="catalog-pg-attribute"><structname>pg_attribute</structname></link>.attnum</literal></entry>
2044+
<entry>
2045+
This is an array of <structfield>indnatts</structfield> values that
2046+
indicate which table columns this index indexes. For example a value
2047+
of <literal>1 3</literal> would mean that the first and the third table
2048+
columns make up the index key. A zero in this array indicates that the
2049+
corresponding index attribute is an expression over the table columns,
2050+
rather than a simple column reference.
2051+
</entry>
2052+
</row>
2053+
2054+
<row>
2055+
<entry><structfield>indclass</structfield></entry>
2056+
<entry><type>oidvector</type></entry>
2057+
<entry><literal><link linkend="catalog-pg-opclass"><structname>pg_opclass</structname></link>.oid</literal></entry>
2058+
<entry>
2059+
For each column in the index key this contains the OID of
2060+
the operator class to use. See
2061+
<structname>pg_opclass</structname> for details.
2062+
</entry>
2063+
</row>
2064+
20662065
<row>
20672066
<entry><structfield>indexprs</structfield></entry>
20682067
<entry><type>text</type></entry>
@@ -3637,7 +3636,7 @@
36373636
(<structfield>typlen</structfield> = -1),
36383637
but some fixed-length (<structfield>typlen</structfield> &gt; 0) types
36393638
also have nonzero <structfield>typelem</structfield>, for example
3640-
<type>name</type> and <type>oidvector</type>.
3639+
<type>name</type> and <type>point</type>.
36413640
If a fixed-length type has a <structfield>typelem</structfield> then
36423641
its internal representation must be some number of values of the
36433642
<structfield>typelem</structfield> data type with no other data.

‎doc/src/sgml/trigger.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.41 2005/01/22 22:56:36 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.42 2005/03/29 00:16:49 tgl Exp $
33
-->
44

55
<chapter id="triggers">
@@ -453,7 +453,8 @@ typedef struct Trigger
453453
bool tgdeferrable;
454454
bool tginitdeferred;
455455
int16 tgnargs;
456-
int16 tgattr[FUNC_MAX_ARGS];
456+
int16 tgnattr;
457+
int16 *tgattr;
457458
char **tgargs;
458459
} Trigger;
459460
</programlisting>

‎src/backend/access/hash/hashfunc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashfunc.c,v 1.42 2004/12/31 21:59:13 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashfunc.c,v 1.43 2005/03/29 00:16:50 tgl Exp $
1212
*
1313
* NOTES
1414
* These functions are stored in pg_amproc.For each operator class
@@ -107,17 +107,17 @@ hashfloat8(PG_FUNCTION_ARGS)
107107
Datum
108108
hashoidvector(PG_FUNCTION_ARGS)
109109
{
110-
Oid*key= (Oid*)PG_GETARG_POINTER(0);
110+
oidvector*key= (oidvector*)PG_GETARG_POINTER(0);
111111

112-
returnhash_any((unsignedchar*)key,INDEX_MAX_KEYS*sizeof(Oid));
112+
returnhash_any((unsignedchar*)key->values,key->dim1*sizeof(Oid));
113113
}
114114

115115
Datum
116116
hashint2vector(PG_FUNCTION_ARGS)
117117
{
118-
int16*key= (int16*)PG_GETARG_POINTER(0);
118+
int2vector*key= (int2vector*)PG_GETARG_POINTER(0);
119119

120-
returnhash_any((unsignedchar*)key,INDEX_MAX_KEYS*sizeof(int16));
120+
returnhash_any((unsignedchar*)key->values,key->dim1*sizeof(int2));
121121
}
122122

123123
Datum

‎src/backend/access/index/genam.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/index/genam.c,v 1.45 2005/03/27 23:52:59 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/index/genam.c,v 1.46 2005/03/29 00:16:51 tgl Exp $
1212
*
1313
* NOTES
1414
* many of the old access method routines have been turned into
@@ -219,7 +219,7 @@ systable_beginscan(Relation heapRelation,
219219
*/
220220
for (i=0;i<nkeys;i++)
221221
{
222-
Assert(key[i].sk_attno==irel->rd_index->indkey[i]);
222+
Assert(key[i].sk_attno==irel->rd_index->indkey.values[i]);
223223
key[i].sk_attno=i+1;
224224
}
225225

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp