diff options
| author | Tom Lane | 2005-03-29 00:17:27 +0000 |
|---|---|---|
| committer | Tom Lane | 2005-03-29 00:17:27 +0000 |
| commit | 70c9763d4815ac847f0f7694f43eb6a59a236868 (patch) | |
| tree | 7d8aa05f668f1ef7809ff521b6c1e12d31125fd7 /contrib | |
| parent | 119191609c507528b20d74c59be69f2129127575 (diff) | |
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 and
FUNC_MAX_ARGS have the same value. INDEX_MAX_KEYS is still embedded
in the on-disk representation (because it affects index tuple header
size), but FUNC_MAX_ARGS is not. I believe it would now be possible
to increase FUNC_MAX_ARGS at little cost, but haven't experimented yet.
There are still a lot of vestigial references to FUNC_MAX_ARGS, which
I will clean up in a separate pass. However, getting rid of it
altogether would require changing the FunctionCallInfoData struct,
and I'm not sure I want to buy into that.
Diffstat (limited to 'contrib')
| -rw-r--r-- | contrib/dblink/dblink.c | 47 | ||||
| -rw-r--r-- | contrib/dbmirror/pending.c | 16 |
2 files changed, 28 insertions, 35 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index 5de15144590..75ce4c440d7 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -74,13 +74,13 @@ static HTAB *createConnHash(void); static void createNewConnection(const char *name, remoteConn * con); static void deleteConnection(const char *name); static char **get_pkey_attnames(Oid relid, int16 *numatts); -static char *get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals); -static char *get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattvals); -static char *get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals); +static char *get_sql_insert(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals); +static char *get_sql_delete(Oid relid, int2vector *pkattnums, int16 pknumatts, char **tgt_pkattvals); +static char *get_sql_update(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals); static char *quote_literal_cstr(char *rawstr); static char *quote_ident_cstr(char *rawstr); -static int16 get_attnum_pk_pos(int16 *pkattnums, int16 pknumatts, int16 key); -static HeapTuple get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals); +static int16 get_attnum_pk_pos(int2vector *pkattnums, int16 pknumatts, int16 key); +static HeapTuple get_tuple_of_interest(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pkattvals); static Oid get_relid_from_relname(text *relname_text); static char *generate_relation_name(Oid relid); @@ -1094,7 +1094,7 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS) { Oid relid; text *relname_text; - int16 *pkattnums; + int2vector *pkattnums; int pknumatts_tmp; int16 pknumatts = 0; char **src_pkattvals; @@ -1126,7 +1126,7 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS) errmsg("relation \"%s\" does not exist", GET_STR(relname_text)))); - pkattnums = (int16 *) PG_GETARG_POINTER(1); + pkattnums = (int2vector *) PG_GETARG_POINTER(1); pknumatts_tmp = PG_GETARG_INT32(2); if (pknumatts_tmp <= SHRT_MAX) pknumatts = pknumatts_tmp; @@ -1246,7 +1246,7 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS) { Oid relid; text *relname_text; - int16 *pkattnums; + int2vector *pkattnums; int pknumatts_tmp; int16 pknumatts = 0; char **tgt_pkattvals; @@ -1273,7 +1273,7 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS) errmsg("relation \"%s\" does not exist", GET_STR(relname_text)))); - pkattnums = (int16 *) PG_GETARG_POINTER(1); + pkattnums = (int2vector *) PG_GETARG_POINTER(1); pknumatts_tmp = PG_GETARG_INT32(2); if (pknumatts_tmp <= SHRT_MAX) pknumatts = pknumatts_tmp; @@ -1363,7 +1363,7 @@ dblink_build_sql_update(PG_FUNCTION_ARGS) { Oid relid; text *relname_text; - int16 *pkattnums; + int2vector *pkattnums; int pknumatts_tmp; int16 pknumatts = 0; char **src_pkattvals; @@ -1395,7 +1395,7 @@ dblink_build_sql_update(PG_FUNCTION_ARGS) errmsg("relation \"%s\" does not exist", GET_STR(relname_text)))); - pkattnums = (int16 *) PG_GETARG_POINTER(1); + pkattnums = (int2vector *) PG_GETARG_POINTER(1); pknumatts_tmp = PG_GETARG_INT32(2); if (pknumatts_tmp <= SHRT_MAX) pknumatts = pknumatts_tmp; @@ -1552,16 +1552,13 @@ get_pkey_attnames(Oid relid, int16 *numatts) /* we're only interested if it is the primary key */ if (index->indisprimary == TRUE) { - i = 0; - while (index->indkey[i++] != 0) - (*numatts)++; - + *numatts = index->indnatts; if (*numatts > 0) { result = (char **) palloc(*numatts * sizeof(char *)); for (i = 0; i < *numatts; i++) - result[i] = SPI_fname(tupdesc, index->indkey[i]); + result[i] = SPI_fname(tupdesc, index->indkey.values[i]); } break; } @@ -1574,7 +1571,7 @@ get_pkey_attnames(Oid relid, int16 *numatts) } static char * -get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals) +get_sql_insert(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals) { Relation rel; char *relname; @@ -1664,7 +1661,7 @@ get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval } static char * -get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattvals) +get_sql_delete(Oid relid, int2vector *pkattnums, int16 pknumatts, char **tgt_pkattvals) { Relation rel; char *relname; @@ -1688,7 +1685,7 @@ get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattval appendStringInfo(str, "DELETE FROM %s WHERE ", relname); for (i = 0; i < pknumatts; i++) { - int16 pkattnum = pkattnums[i]; + int16 pkattnum = pkattnums->values[i]; if (i > 0) appendStringInfo(str, " AND "); @@ -1720,7 +1717,7 @@ get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattval } static char * -get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals) +get_sql_update(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals) { Relation rel; char *relname; @@ -1788,7 +1785,7 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval for (i = 0; i < pknumatts; i++) { - int16 pkattnum = pkattnums[i]; + int16 pkattnum = pkattnums->values[i]; if (i > 0) appendStringInfo(str, " AND "); @@ -1855,7 +1852,7 @@ quote_ident_cstr(char *rawstr) } static int16 -get_attnum_pk_pos(int16 *pkattnums, int16 pknumatts, int16 key) +get_attnum_pk_pos(int2vector *pkattnums, int16 pknumatts, int16 key) { int i; @@ -1863,14 +1860,14 @@ get_attnum_pk_pos(int16 *pkattnums, int16 pknumatts, int16 key) * Not likely a long list anyway, so just scan for the value */ for (i = 0; i < pknumatts; i++) - if (key == pkattnums[i]) + if (key == pkattnums->values[i]) return i; return -1; } static HeapTuple -get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals) +get_tuple_of_interest(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pkattvals) { Relation rel; char *relname; @@ -1907,7 +1904,7 @@ get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_p for (i = 0; i < pknumatts; i++) { - int16 pkattnum = pkattnums[i]; + int16 pkattnum = pkattnums->values[i]; if (i > 0) appendStringInfo(str, " AND "); diff --git a/contrib/dbmirror/pending.c b/contrib/dbmirror/pending.c index 48e91acd782..3ed9d2128cf 100644 --- a/contrib/dbmirror/pending.c +++ b/contrib/dbmirror/pending.c @@ -1,7 +1,7 @@ /**************************************************************************** * pending.c - * $Id: pending.c,v 1.20 2004/09/10 04:31:06 neilc Exp $ - * $PostgreSQL: pgsql/contrib/dbmirror/pending.c,v 1.20 2004/09/10 04:31:06 neilc Exp $ + * $Id: pending.c,v 1.21 2005/03/29 00:16:48 tgl Exp $ + * $PostgreSQL: pgsql/contrib/dbmirror/pending.c,v 1.21 2005/03/29 00:16:48 tgl Exp $ * * This file contains a trigger for Postgresql-7.x to record changes to tables * to a pending table for mirroring. @@ -349,8 +349,8 @@ getPrimaryKey(Oid tblOid) resDatum = SPI_getbinval(resTuple, SPI_tuptable->tupdesc, 1, &isNull); tpResultKey = (int2vector *) DatumGetPointer(resDatum); - resultKey = SPI_palloc(sizeof(int2vector)); - memcpy(resultKey, tpResultKey, sizeof(int2vector)); + resultKey = SPI_palloc(VARSIZE(tpResultKey)); + memcpy(resultKey, tpResultKey, VARSIZE(tpResultKey)); return resultKey; } @@ -438,11 +438,8 @@ packageData(HeapTuple tTupleData, TupleDesc tTupleDesc, Oid tableOid, } if (tpPKeys != NULL) - { debug_msg("dbmirror:packageData have primary keys"); - } - cpDataBlock = SPI_palloc(BUFFER_SIZE); iDataBlockSize = BUFFER_SIZE; iUsedDataBlock = 0; /* To account for the null */ @@ -462,11 +459,10 @@ packageData(HeapTuple tTupleData, TupleDesc tTupleDesc, Oid tableOid, /* Determine if this is a primary key or not. */ iIsPrimaryKey = 0; for (iPrimaryKeyIndex = 0; - (*tpPKeys)[iPrimaryKeyIndex] != 0; + iPrimaryKeyIndex < tpPKeys->dim1; iPrimaryKeyIndex++) { - if ((*tpPKeys)[iPrimaryKeyIndex] - == iColumnCounter) + if (tpPKeys->values[iPrimaryKeyIndex] == iColumnCounter) { iIsPrimaryKey = 1; break; |
