mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
Removed obsolete DROP_COLUMN_HACK stuff.
This commit is contained in:
parent
b4bedfa956
commit
c26a44db08
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.171 2002/04/01 22:36:09 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.172 2002/04/02 08:51:50 inoue Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* The PerformAddAttribute() code, like most of the relation
|
* The PerformAddAttribute() code, like most of the relation
|
||||||
@ -1115,140 +1115,6 @@ AlterTableAlterColumnFlags(Oid myrelid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DROP_COLUMN_HACK__
|
|
||||||
/*
|
|
||||||
* ALTER TABLE DROP COLUMN trial implementation
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* find a specified attribute in a node entry
|
|
||||||
*/
|
|
||||||
static bool
|
|
||||||
find_attribute_walker(Node *node, int *attnump)
|
|
||||||
{
|
|
||||||
if (node == NULL)
|
|
||||||
return false;
|
|
||||||
if (IsA(node, Var))
|
|
||||||
{
|
|
||||||
Var *var = (Var *) node;
|
|
||||||
|
|
||||||
if (var->varlevelsup == 0 && var->varno == 1 &&
|
|
||||||
var->varattno == *attnump)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return expression_tree_walker(node, find_attribute_walker,
|
|
||||||
(void *) attnump);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
find_attribute_in_node(Node *node, int attnum)
|
|
||||||
{
|
|
||||||
return find_attribute_walker(node, &attnum);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remove/check references for the column
|
|
||||||
*/
|
|
||||||
static bool
|
|
||||||
RemoveColumnReferences(Oid reloid, int attnum, bool checkonly, HeapTuple reltup)
|
|
||||||
{
|
|
||||||
Relation indexRelation,
|
|
||||||
rcrel;
|
|
||||||
ScanKeyData entry;
|
|
||||||
HeapScanDesc scan;
|
|
||||||
void *sysscan;
|
|
||||||
HeapTuple htup,
|
|
||||||
indexTuple;
|
|
||||||
Form_pg_index index;
|
|
||||||
Form_pg_class pgcform = (Form_pg_class) NULL;
|
|
||||||
int i;
|
|
||||||
bool checkok = true;
|
|
||||||
|
|
||||||
|
|
||||||
if (!checkonly)
|
|
||||||
pgcform = (Form_pg_class) GETSTRUCT(reltup);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remove/check constraints here
|
|
||||||
*/
|
|
||||||
ScanKeyEntryInitialize(&entry, (bits16) 0x0,
|
|
||||||
Anum_pg_relcheck_rcrelid,
|
|
||||||
(RegProcedure) F_OIDEQ,
|
|
||||||
ObjectIdGetDatum(reloid));
|
|
||||||
|
|
||||||
rcrel = heap_openr(RelCheckRelationName, RowExclusiveLock);
|
|
||||||
sysscan = systable_beginscan(rcrel, RelCheckIndex, true,
|
|
||||||
SnapshotNow,
|
|
||||||
1, &entry);
|
|
||||||
|
|
||||||
while (HeapTupleIsValid(htup = systable_getnext(sysscan)))
|
|
||||||
{
|
|
||||||
Form_pg_relcheck relcheck;
|
|
||||||
char *ccbin;
|
|
||||||
Node *node;
|
|
||||||
|
|
||||||
relcheck = (Form_pg_relcheck) GETSTRUCT(htup);
|
|
||||||
ccbin = DatumGetCString(DirectFunctionCall1(textout,
|
|
||||||
PointerGetDatum(&relcheck->rcbin)));
|
|
||||||
node = stringToNode(ccbin);
|
|
||||||
pfree(ccbin);
|
|
||||||
if (find_attribute_in_node(node, attnum))
|
|
||||||
{
|
|
||||||
if (checkonly)
|
|
||||||
{
|
|
||||||
checkok = false;
|
|
||||||
elog(ERROR, "target column is used in a constraint");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
simple_heap_delete(rcrel, &htup->t_self);
|
|
||||||
pgcform->relchecks--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
systable_endscan(sysscan);
|
|
||||||
heap_close(rcrel, NoLock);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* What to do with triggers/rules/views/procedues ?
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remove/check indexes
|
|
||||||
*/
|
|
||||||
indexRelation = heap_openr(IndexRelationName, RowExclusiveLock);
|
|
||||||
ScanKeyEntryInitialize(&entry, 0, Anum_pg_index_indrelid, F_OIDEQ,
|
|
||||||
ObjectIdGetDatum(reloid));
|
|
||||||
scan = heap_beginscan(indexRelation, false, SnapshotNow, 1, &entry);
|
|
||||||
while (HeapTupleIsValid(indexTuple = heap_getnext(scan, 0)))
|
|
||||||
{
|
|
||||||
index = (Form_pg_index) GETSTRUCT(indexTuple);
|
|
||||||
for (i = 0; i < INDEX_MAX_KEYS; i++)
|
|
||||||
{
|
|
||||||
if (index->indkey[i] == InvalidAttrNumber)
|
|
||||||
break;
|
|
||||||
else if (index->indkey[i] == attnum)
|
|
||||||
{
|
|
||||||
if (checkonly)
|
|
||||||
{
|
|
||||||
checkok = false;
|
|
||||||
elog(ERROR, "target column is used in an index");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
index_drop(index->indexrelid);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
heap_endscan(scan);
|
|
||||||
heap_close(indexRelation, NoLock);
|
|
||||||
|
|
||||||
return checkok;
|
|
||||||
}
|
|
||||||
#endif /* _DROP_COLUMN_HACK__ */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ALTER TABLE DROP COLUMN
|
* ALTER TABLE DROP COLUMN
|
||||||
@ -1258,171 +1124,7 @@ AlterTableDropColumn(Oid myrelid,
|
|||||||
bool inh, const char *colName,
|
bool inh, const char *colName,
|
||||||
int behavior)
|
int behavior)
|
||||||
{
|
{
|
||||||
#ifdef _DROP_COLUMN_HACK__
|
|
||||||
Relation rel,
|
|
||||||
attrdesc;
|
|
||||||
HeapTuple reltup;
|
|
||||||
HeapTupleData classtuple;
|
|
||||||
Buffer buffer;
|
|
||||||
Form_pg_attribute attribute;
|
|
||||||
HeapTuple tup;
|
|
||||||
Relation idescs[Num_pg_attr_indices];
|
|
||||||
int attnum;
|
|
||||||
bool hasindex;
|
|
||||||
char dropColname[32];
|
|
||||||
|
|
||||||
if (inh)
|
|
||||||
elog(ERROR, "ALTER TABLE / DROP COLUMN with inherit option is not supported yet");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Grab an exclusive lock on the target table, which we will NOT
|
|
||||||
* release until end of transaction.
|
|
||||||
*/
|
|
||||||
rel = heap_open(myrelid, AccessExclusiveLock);
|
|
||||||
|
|
||||||
if (rel->rd_rel->relkind != RELKIND_RELATION)
|
|
||||||
elog(ERROR, "ALTER TABLE: relation \"%s\" is not a table",
|
|
||||||
RelationGetRelationName(rel));
|
|
||||||
|
|
||||||
if (!allowSystemTableMods
|
|
||||||
&& IsSystemRelationName(RelationGetRelationName(rel)))
|
|
||||||
elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
|
|
||||||
RelationGetRelationName(rel));
|
|
||||||
|
|
||||||
/*
|
|
||||||
* permissions checking. this would normally be done in utility.c,
|
|
||||||
* but this particular routine is recursive.
|
|
||||||
*
|
|
||||||
* normally, only the owner of a class can change its schema.
|
|
||||||
*/
|
|
||||||
if (!pg_class_ownercheck(myrelid, GetUserId()))
|
|
||||||
elog(ERROR, "ALTER TABLE: \"%s\": permission denied",
|
|
||||||
RelationGetRelationName(rel));
|
|
||||||
|
|
||||||
heap_close(rel, NoLock); /* close rel but keep lock! */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* What to do when rel has inheritors ?
|
|
||||||
*/
|
|
||||||
if (length(find_all_inheritors(myrelid)) > 1)
|
|
||||||
elog(ERROR, "ALTER TABLE: cannot drop a column on table that is inherited from");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* lock the pg_class tuple for update
|
|
||||||
*/
|
|
||||||
rel = heap_openr(RelationRelationName, RowExclusiveLock);
|
|
||||||
reltup = SearchSysCache(RELOID,
|
|
||||||
ObjectIdGetDatum(myrelid),
|
|
||||||
0, 0, 0);
|
|
||||||
if (!HeapTupleIsValid(reltup))
|
|
||||||
{
|
|
||||||
Relation myrel;
|
|
||||||
char *myrelname;
|
|
||||||
|
|
||||||
myrel = heap_open(myrelid, AccessExclusiveLock);
|
|
||||||
myrelname = pstrdup(RelationGetRelationName(myrel));
|
|
||||||
heap_close(myrel, AccessExclusiveLock);
|
|
||||||
|
|
||||||
elog(ERROR, "ALTER TABLE: relation \"%s\" not found",
|
|
||||||
myrelname);
|
|
||||||
}
|
|
||||||
classtuple.t_self = reltup->t_self;
|
|
||||||
ReleaseSysCache(reltup);
|
|
||||||
|
|
||||||
switch (heap_mark4update(rel, &classtuple, &buffer))
|
|
||||||
{
|
|
||||||
case HeapTupleSelfUpdated:
|
|
||||||
case HeapTupleMayBeUpdated:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
elog(ERROR, "couldn't lock pg_class tuple");
|
|
||||||
}
|
|
||||||
reltup = heap_copytuple(&classtuple);
|
|
||||||
ReleaseBuffer(buffer);
|
|
||||||
|
|
||||||
attrdesc = heap_openr(AttributeRelationName, RowExclusiveLock);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the target pg_attribute tuple and make a modifiable copy
|
|
||||||
*/
|
|
||||||
tup = SearchSysCacheCopy(ATTNAME,
|
|
||||||
ObjectIdGetDatum(myrelid),
|
|
||||||
PointerGetDatum(colName),
|
|
||||||
0, 0);
|
|
||||||
if (!HeapTupleIsValid(tup))
|
|
||||||
{
|
|
||||||
Relation myrel;
|
|
||||||
char *myrelname;
|
|
||||||
|
|
||||||
myrel = heap_open(myrelid, AccessExclusiveLock);
|
|
||||||
myrelname = pstrdup(RelationGetRelationName(myrel));
|
|
||||||
heap_close(myrel, AccessExclusiveLock);
|
|
||||||
|
|
||||||
elog(ERROR, "ALTER TABLE: column name \"%s\" doesn't exist in table \"%s\"",
|
|
||||||
colName, myrelname);
|
|
||||||
}
|
|
||||||
|
|
||||||
attribute = (Form_pg_attribute) GETSTRUCT(tup);
|
|
||||||
attnum = attribute->attnum;
|
|
||||||
if (attnum <= 0)
|
|
||||||
elog(ERROR, "ALTER TABLE: column name \"%s\" was already dropped",
|
|
||||||
colName);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check constraints/indices etc here
|
|
||||||
*/
|
|
||||||
if (behavior != CASCADE)
|
|
||||||
{
|
|
||||||
if (!RemoveColumnReferences(myrelid, attnum, true, NULL))
|
|
||||||
elog(ERROR, "the column is referenced");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* change the target pg_attribute tuple
|
|
||||||
*/
|
|
||||||
sprintf(dropColname, "*already Dropped*%d", attnum);
|
|
||||||
namestrcpy(&(attribute->attname), dropColname);
|
|
||||||
ATTRIBUTE_DROP_COLUMN(attribute);
|
|
||||||
|
|
||||||
simple_heap_update(attrdesc, &tup->t_self, tup);
|
|
||||||
hasindex = (!IsIgnoringSystemIndexes() && RelationGetForm(attrdesc)->relhasindex);
|
|
||||||
if (hasindex)
|
|
||||||
{
|
|
||||||
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
|
|
||||||
CatalogIndexInsert(idescs, Num_pg_attr_indices,
|
|
||||||
attrdesc, tup);
|
|
||||||
CatalogCloseIndices(Num_pg_attr_indices, idescs);
|
|
||||||
}
|
|
||||||
heap_close(attrdesc, NoLock);
|
|
||||||
heap_freetuple(tup);
|
|
||||||
|
|
||||||
/* delete comment for this attribute only */
|
|
||||||
CreateComments(RelationGetRelid(rel), RelOid_pg_class,
|
|
||||||
(int32) attnum, NULL);
|
|
||||||
|
|
||||||
/* delete attrdef */
|
|
||||||
drop_default(myrelid, attnum);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remove objects which reference this column
|
|
||||||
*/
|
|
||||||
if (behavior == CASCADE)
|
|
||||||
{
|
|
||||||
Relation ridescs[Num_pg_class_indices];
|
|
||||||
|
|
||||||
RemoveColumnReferences(myrelid, attnum, false, reltup);
|
|
||||||
/* update pg_class tuple */
|
|
||||||
simple_heap_update(rel, &reltup->t_self, reltup);
|
|
||||||
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
|
|
||||||
CatalogIndexInsert(ridescs, Num_pg_class_indices, rel, reltup);
|
|
||||||
CatalogCloseIndices(Num_pg_class_indices, ridescs);
|
|
||||||
}
|
|
||||||
|
|
||||||
heap_freetuple(reltup);
|
|
||||||
heap_close(rel, NoLock);
|
|
||||||
#else
|
|
||||||
elog(ERROR, "ALTER TABLE / DROP COLUMN is not implemented");
|
elog(ERROR, "ALTER TABLE / DROP COLUMN is not implemented");
|
||||||
#endif /* _DROP_COLUMN_HACK__ */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.50 2002/03/20 19:44:15 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.51 2002/04/02 08:51:51 inoue Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -198,11 +198,6 @@ expand_targetlist(List *tlist, int command_type,
|
|||||||
new_expr = build_column_default(rel, attrno);
|
new_expr = build_column_default(rel, attrno);
|
||||||
break;
|
break;
|
||||||
case CMD_UPDATE:
|
case CMD_UPDATE:
|
||||||
#ifdef _DROP_COLUMN_HACK__
|
|
||||||
if (COLUMN_IS_DROPPED(att_tup))
|
|
||||||
new_expr = (Node *) makeNullConst(atttype);
|
|
||||||
else
|
|
||||||
#endif /* _DROP_COLUMN_HACK__ */
|
|
||||||
new_expr = (Node *) makeVar(result_relation,
|
new_expr = (Node *) makeVar(result_relation,
|
||||||
attrno,
|
attrno,
|
||||||
atttype,
|
atttype,
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.66 2002/03/26 19:15:59 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.67 2002/04/02 08:51:51 inoue Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -855,11 +855,6 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte,
|
|||||||
{
|
{
|
||||||
Form_pg_attribute attr = rel->rd_att->attrs[varattno];
|
Form_pg_attribute attr = rel->rd_att->attrs[varattno];
|
||||||
|
|
||||||
#ifdef _DROP_COLUMN_HACK__
|
|
||||||
if (COLUMN_IS_DROPPED(attr))
|
|
||||||
continue;
|
|
||||||
#endif /* _DROP_COLUMN_HACK__ */
|
|
||||||
|
|
||||||
if (colnames)
|
if (colnames)
|
||||||
{
|
{
|
||||||
char *label;
|
char *label;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.80 2002/03/29 19:06:12 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.81 2002/04/02 08:51:52 inoue Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -373,10 +373,6 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
|
|||||||
{
|
{
|
||||||
ResTarget *col = makeNode(ResTarget);
|
ResTarget *col = makeNode(ResTarget);
|
||||||
|
|
||||||
#ifdef _DROP_COLUMN_HACK__
|
|
||||||
if (COLUMN_IS_DROPPED(attr[i]))
|
|
||||||
continue;
|
|
||||||
#endif /* _DROP_COLUMN_HACK__ */
|
|
||||||
col->name = pstrdup(NameStr(attr[i]->attname));
|
col->name = pstrdup(NameStr(attr[i]->attname));
|
||||||
col->indirection = NIL;
|
col->indirection = NIL;
|
||||||
col->val = NULL;
|
col->val = NULL;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: pg_attribute.h,v 1.87 2002/03/29 19:06:18 tgl Exp $
|
* $Id: pg_attribute.h,v 1.88 2002/04/02 08:51:49 inoue Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* the genbki.sh script reads this file and generates .bki
|
* the genbki.sh script reads this file and generates .bki
|
||||||
@ -182,20 +182,6 @@ typedef FormData_pg_attribute *Form_pg_attribute;
|
|||||||
#define Anum_pg_attribute_atthasdef 15
|
#define Anum_pg_attribute_atthasdef 15
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DROP_COLUMN_HACK__
|
|
||||||
/*
|
|
||||||
* CONSTANT and MACROS for DROP COLUMN implementation
|
|
||||||
*/
|
|
||||||
#define DROP_COLUMN_OFFSET -20
|
|
||||||
#define COLUMN_IS_DROPPED(attribute) ((attribute)->attnum <= DROP_COLUMN_OFFSET)
|
|
||||||
#define DROPPED_COLUMN_INDEX(attidx) (DROP_COLUMN_OFFSET - attidx)
|
|
||||||
#define ATTRIBUTE_DROP_COLUMN(attribute) \
|
|
||||||
Assert((attribute)->attnum > 0); \
|
|
||||||
(attribute)->attnum = DROPPED_COLUMN_INDEX((attribute)->attnum); \
|
|
||||||
(attribute)->atttypid = (Oid) -1; \
|
|
||||||
(attribute)->attnotnull = false; \
|
|
||||||
(attribute)->atthasdef = false;
|
|
||||||
#endif /* _DROP_COLUMN_HACK__ */
|
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* SCHEMA_ macros for declaring hardcoded tuple descriptors.
|
* SCHEMA_ macros for declaring hardcoded tuple descriptors.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user