aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/command.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-03-05 05:33:31 +0000
committerBruce Momjian <bruce@momjian.us>2002-03-05 05:33:31 +0000
commit03194432de712f7afb4ddc2ade2bc44f0536dae1 (patch)
tree8a864adc9b1d924fe8f6a919b51d34cef4a4ef01 /src/backend/commands/command.c
parent276fc7ce829404627075ebf8ed5ee3039923eb2b (diff)
downloadpostgresql-03194432de712f7afb4ddc2ade2bc44f0536dae1.tar.gz
postgresql-03194432de712f7afb4ddc2ade2bc44f0536dae1.zip
I attach a version of my toast-slicing patch, against current CVS
(current as of a few hours ago.) This patch: 1. Adds PG_GETARG_xxx_P_SLICE() macros and associated support routines. 2. Adds routines in src/backend/access/tuptoaster.c for fetching only necessary chunks of a toasted value. (Modelled on latest changes to assume chunks are returned in order). 3. Amends text_substr and bytea_substr to use new methods. It now handles multibyte cases -and should still lead to a performance improvement in the multibyte case where the substring is near the beginning of the string. 4. Added new command: ALTER TABLE tabname ALTER COLUMN colname SET STORAGE {PLAIN | EXTERNAL | EXTENDED | MAIN} to parser and documented in alter-table.sgml. (NB I used ColId as the item type for the storage mode string, rather than a new production - I hope this makes sense!). All this does is sets attstorage for the specified column. 4. AlterTableAlterColumnStatistics is now AlterTableAlterColumnFlags and handles both statistics and storage (it uses the subtype code to distinguish). The previous version of my patch also re-arranged other code in backend/commands/command.c but I have dropped that from this patch.(I plan to return to it separately). 5. Documented new macros (and also the PG_GETARG_xxx_P_COPY macros) in xfunc.sgml. ref/alter_table.sgml also contains documentation for ALTER COLUMN SET STORAGE. John Gray
Diffstat (limited to 'src/backend/commands/command.c')
-rw-r--r--src/backend/commands/command.c95
1 files changed, 75 insertions, 20 deletions
diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c
index eefbe269f30..e49c8ca3212 100644
--- a/src/backend/commands/command.c
+++ b/src/backend/commands/command.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.157 2002/03/02 21:39:22 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.158 2002/03/05 05:33:08 momjian Exp $
*
* NOTES
* The PerformAddAttribute() code, like most of the relation
@@ -714,20 +714,27 @@ drop_default(Oid relid, int16 attnum)
/*
- * ALTER TABLE ALTER COLUMN SET STATISTICS
+ * ALTER TABLE ALTER COLUMN SET STATISTICS / STORAGE
*/
void
-AlterTableAlterColumnStatistics(const char *relationName,
+AlterTableAlterColumnFlags(const char *relationName,
bool inh, const char *colName,
- Node *statsTarget)
+ Node *flagValue, const char *flagType)
{
Relation rel;
Oid myrelid;
- int newtarget;
+ int newtarget = 1;
+ char newstorage = 'x';
+ char *storagemode;
Relation attrelation;
HeapTuple tuple;
- /* we allow this on system tables */
+ /* we allow statistics case for system tables */
+
+ if (*flagType =='M' && !allowSystemTableMods && IsSystemRelationName(relationName))
+ elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
+ relationName);
+
#ifndef NO_SECURITY
if (!pg_ownercheck(GetUserId(), relationName, RELNAME))
elog(ERROR, "ALTER TABLE: permission denied");
@@ -742,6 +749,50 @@ AlterTableAlterColumnStatistics(const char *relationName,
myrelid = RelationGetRelid(rel);
heap_close(rel, NoLock); /* close rel, but keep lock! */
+
+ /*
+ * Check the supplied parameters before anything else
+ */
+ if (*flagType == 'S') /*
+ * STATISTICS
+ */
+ {
+ Assert(IsA(flagValue, Integer));
+ newtarget = intVal(flagValue);
+
+ /*
+ * Limit target to sane range (should we raise an error instead?)
+ */
+ if (newtarget < 0)
+ newtarget = 0;
+ else if (newtarget > 1000)
+ newtarget = 1000;
+ }
+ else if (*flagType == 'M') /*
+ * STORAGE
+ */
+ {
+ Assert(IsA(flagValue, Value));
+
+ storagemode = strVal(flagValue);
+ if (strcasecmp(storagemode, "plain") == 0)
+ newstorage = 'p';
+ else if (strcasecmp(storagemode, "external") == 0)
+ newstorage = 'e';
+ else if (strcasecmp(storagemode, "extended") == 0)
+ newstorage = 'x';
+ else if (strcasecmp(storagemode, "main") == 0)
+ newstorage = 'm';
+ else
+ elog(ERROR, "ALTER TABLE: \"%s\" storage not recognized",
+ storagemode);
+ }
+ else
+ {
+ elog(ERROR, "ALTER TABLE: Invalid column flag: %c",
+ (int) *flagType);
+ }
+
/*
* Propagate to children if desired
*/
@@ -765,23 +816,14 @@ AlterTableAlterColumnStatistics(const char *relationName,
if (childrelid == myrelid)
continue;
rel = heap_open(childrelid, AccessExclusiveLock);
- AlterTableAlterColumnStatistics(RelationGetRelationName(rel),
- false, colName, statsTarget);
+ AlterTableAlterColumnFlags(RelationGetRelationName(rel),
+ false, colName, flagValue, flagType);
heap_close(rel, AccessExclusiveLock);
}
}
/* -= now do the thing on this relation =- */
- Assert(IsA(statsTarget, Integer));
- newtarget = intVal(statsTarget);
-
- /* Limit target to sane range (should we raise an error instead?) */
- if (newtarget < 0)
- newtarget = 0;
- else if (newtarget > 1000)
- newtarget = 1000;
-
attrelation = heap_openr(AttributeRelationName, RowExclusiveLock);
tuple = SearchSysCacheCopy(ATTNAME,
@@ -795,9 +837,22 @@ AlterTableAlterColumnStatistics(const char *relationName,
if (((Form_pg_attribute) GETSTRUCT(tuple))->attnum < 0)
elog(ERROR, "ALTER TABLE: cannot change system attribute \"%s\"",
colName);
-
- ((Form_pg_attribute) GETSTRUCT(tuple))->attstattarget = newtarget;
-
+ /*
+ * Now change the appropriate field
+ */
+ if (*flagType == 'S')
+ ((Form_pg_attribute) GETSTRUCT(tuple))->attstattarget = newtarget;
+ else
+ {
+ if ((newstorage == 'p') ||
+ (((Form_pg_attribute) GETSTRUCT(tuple))->attlen == -1))
+ ((Form_pg_attribute) GETSTRUCT(tuple))->attstorage = newstorage;
+ else
+ {
+ elog(ERROR,
+ "ALTER TABLE: Fixed-length columns can only have storage \"plain\"");
+ }
+ }
simple_heap_update(attrelation, &tuple->t_self, tuple);
/* keep system catalog indices current */