Commit fd9ff86b authored by Hiroshi Inoue's avatar Hiroshi Inoue

Trial implementation of ALTER DROP COLUMN.

They are #ifdef'd.
Add -D_DROP_COLUMN_HACK__ compile option
to evaluate it.
parent 6513946c
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.101 2000/02/13 18:59:50 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.102 2000/03/09 05:00:23 inoue Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -394,6 +394,9 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_p ...@@ -394,6 +394,9 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_p
int32 attr_count, int32 attr_count,
i; i;
#ifdef _DROP_COLUMN_HACK__
bool *valid;
#endif /* _DROP_COLUMN_HACK__ */
Form_pg_attribute *attr; Form_pg_attribute *attr;
FmgrInfo *out_functions; FmgrInfo *out_functions;
Oid out_func_oid; Oid out_func_oid;
...@@ -425,8 +428,20 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_p ...@@ -425,8 +428,20 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_p
out_functions = (FmgrInfo *) palloc(attr_count * sizeof(FmgrInfo)); out_functions = (FmgrInfo *) palloc(attr_count * sizeof(FmgrInfo));
elements = (Oid *) palloc(attr_count * sizeof(Oid)); elements = (Oid *) palloc(attr_count * sizeof(Oid));
typmod = (int32 *) palloc(attr_count * sizeof(int32)); typmod = (int32 *) palloc(attr_count * sizeof(int32));
#ifdef _DROP_COLUMN_HACK__
valid = (bool *) palloc(attr_count * sizeof(bool));
#endif /* _DROP_COLUMN_HACK__ */
for (i = 0; i < attr_count; i++) for (i = 0; i < attr_count; i++)
{ {
#ifdef _DROP_COLUMN_HACK__
if (COLUMN_IS_DROPPED(attr[i]))
{
valid[i] = false;
continue;
}
else
valid[i] = true;
#endif /* _DROP_COLUMN_HACK__ */
out_func_oid = (Oid) GetOutputFunction(attr[i]->atttypid); out_func_oid = (Oid) GetOutputFunction(attr[i]->atttypid);
fmgr_info(out_func_oid, &out_functions[i]); fmgr_info(out_func_oid, &out_functions[i]);
elements[i] = GetTypeElement(attr[i]->atttypid); elements[i] = GetTypeElement(attr[i]->atttypid);
...@@ -466,6 +481,14 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_p ...@@ -466,6 +481,14 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_p
value = heap_getattr(tuple, i + 1, tupDesc, &isnull); value = heap_getattr(tuple, i + 1, tupDesc, &isnull);
if (!binary) if (!binary)
{ {
#ifdef _DROP_COLUMN_HACK__
if (!valid[i])
{
if (i == attr_count - 1)
CopySendChar('\n', fp);
continue;
}
#endif /* _DROP_COLUMN_HACK__ */
if (!isnull) if (!isnull)
{ {
string = (char *) (*fmgr_faddr(&out_functions[i])) string = (char *) (*fmgr_faddr(&out_functions[i]))
...@@ -692,6 +715,10 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null ...@@ -692,6 +715,10 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
typmod = (int32 *) palloc(attr_count * sizeof(int32)); typmod = (int32 *) palloc(attr_count * sizeof(int32));
for (i = 0; i < attr_count; i++) for (i = 0; i < attr_count; i++)
{ {
#ifdef _DROP_COLUMN_HACK__
if (COLUMN_IS_DROPPED(attr[i]))
continue;
#endif /* _DROP_COLUMN_HACK__ */
in_func_oid = (Oid) GetInputFunction(attr[i]->atttypid); in_func_oid = (Oid) GetInputFunction(attr[i]->atttypid);
fmgr_info(in_func_oid, &in_functions[i]); fmgr_info(in_func_oid, &in_functions[i]);
elements[i] = GetTypeElement(attr[i]->atttypid); elements[i] = GetTypeElement(attr[i]->atttypid);
...@@ -718,6 +745,13 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null ...@@ -718,6 +745,13 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
{ {
nulls[i] = ' '; nulls[i] = ' ';
index_nulls[i] = ' '; index_nulls[i] = ' ';
#ifdef _DROP_COLUMN_HACK__
if (COLUMN_IS_DROPPED(attr[i]))
{
byval[i] = 'n';
continue;
}
#endif /* _DROP_COLUMN_HACK__ */
byval[i] = (bool) IsTypeByVal(attr[i]->atttypid); byval[i] = (bool) IsTypeByVal(attr[i]->atttypid);
} }
...@@ -750,6 +784,14 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null ...@@ -750,6 +784,14 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
} }
for (i = 0; i < attr_count && !done; i++) for (i = 0; i < attr_count && !done; i++)
{ {
#ifdef _DROP_COLUMN_HACK__
if (COLUMN_IS_DROPPED(attr[i]))
{
values[i] = PointerGetDatum(NULL);
nulls[i] = 'n';
continue;
}
#endif /* _DROP_COLUMN_HACK__ */
string = CopyReadAttribute(fp, &isnull, delim, &newline, null_print); string = CopyReadAttribute(fp, &isnull, delim, &newline, null_print);
if (isnull) if (isnull)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.142 2000/03/08 23:41:00 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.143 2000/03/09 05:00:23 inoue Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2240,6 +2240,10 @@ vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple tuple) ...@@ -2240,6 +2240,10 @@ vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple tuple)
VacAttrStats *stats = &vacattrstats[i]; VacAttrStats *stats = &vacattrstats[i];
bool value_hit = true; bool value_hit = true;
#ifdef _DROP_COLUMN_HACK__
if (COLUMN_IS_DROPPED(stats->attr))
continue;
#endif /* _DROP_COLUMN_HACK__ */
value = heap_getattr(tuple, value = heap_getattr(tuple,
stats->attr->attnum, tupDesc, &isnull); stats->attr->attnum, tupDesc, &isnull);
......
...@@ -15,7 +15,7 @@ ...@@ -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.34 2000/01/26 05:56:39 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.35 2000/03/09 05:00:24 inoue Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -189,10 +189,20 @@ expand_targetlist(List *tlist, int command_type, ...@@ -189,10 +189,20 @@ expand_targetlist(List *tlist, int command_type,
{ {
case CMD_INSERT: case CMD_INSERT:
{ {
#ifdef _DROP_COLUMN_HACK__
Datum typedefault;
#else
Datum typedefault = get_typdefault(atttype); Datum typedefault = get_typdefault(atttype);
#endif /* _DROP_COLUMN_HACK__ */
int typlen; int typlen;
Const *temp_const; Const *temp_const;
#ifdef _DROP_COLUMN_HACK__
if (COLUMN_IS_DROPPED(att_tup))
typedefault = PointerGetDatum(NULL);
else
typedefault = get_typdefault(atttype);
#endif /* _DROP_COLUMN_HACK__ */
if (typedefault == PointerGetDatum(NULL)) if (typedefault == PointerGetDatum(NULL))
typlen = 0; typlen = 0;
else else
...@@ -230,8 +240,25 @@ expand_targetlist(List *tlist, int command_type, ...@@ -230,8 +240,25 @@ expand_targetlist(List *tlist, int command_type,
{ {
Var *temp_var; Var *temp_var;
#ifdef _DROP_COLUMN_HACK__
Node *temp_node = (Node *) NULL;
if (COLUMN_IS_DROPPED(att_tup))
{
temp_node = (Node *)makeConst(atttype, 0,
PointerGetDatum(NULL),
true,
false,
false, /* not a set */
false);
}
else
#endif /* _DROP_COLUMN_HACK__ */
temp_var = makeVar(result_relation, attrno, atttype, temp_var = makeVar(result_relation, attrno, atttype,
atttypmod, 0); atttypmod, 0);
#ifdef _DROP_COLUMN_HACK__
if (!temp_node)
temp_node = (Node *) temp_var;
#endif /* _DROP_COLUMN_HACK__ */
new_tle = makeTargetEntry(makeResdom(attrno, new_tle = makeTargetEntry(makeResdom(attrno,
atttype, atttype,
...@@ -240,7 +267,11 @@ expand_targetlist(List *tlist, int command_type, ...@@ -240,7 +267,11 @@ expand_targetlist(List *tlist, int command_type,
0, 0,
(Oid) 0, (Oid) 0,
false), false),
#ifdef _DROP_COLUMN_HACK__
temp_node);
#else
(Node *) temp_var); (Node *) temp_var);
#endif /* _DROP_COLUMN_HACK__ */
break; break;
} }
default: default:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.35 2000/02/15 03:37:47 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.36 2000/03/09 05:00:24 inoue Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -359,6 +359,10 @@ expandTable(ParseState *pstate, char *refname, bool getaliases) ...@@ -359,6 +359,10 @@ expandTable(ParseState *pstate, char *refname, bool getaliases)
{ {
char *attrname; char *attrname;
#ifdef _DROP_COLUMN_HACK__
if (COLUMN_IS_DROPPED(rel->rd_att->attrs[varattno]))
continue;
#endif /* _DROP_COLUMN_HACK__ */
attrname = pstrdup(NameStr(rel->rd_att->attrs[varattno]->attname)); attrname = pstrdup(NameStr(rel->rd_att->attrs[varattno]->attname));
attr->attrs = lappend(attr->attrs, makeString(attrname)); attr->attrs = lappend(attr->attrs, makeString(attrname));
} }
...@@ -404,6 +408,10 @@ expandAll(ParseState *pstate, char *relname, Attr *ref, int *this_resno) ...@@ -404,6 +408,10 @@ expandAll(ParseState *pstate, char *relname, Attr *ref, int *this_resno)
Var *varnode; Var *varnode;
TargetEntry *te = makeNode(TargetEntry); TargetEntry *te = makeNode(TargetEntry);
#ifdef _DROP_COLUMN_HACK__
if (COLUMN_IS_DROPPED(rel->rd_att->attrs[varattno]))
continue;
#endif /* _DROP_COLUMN_HACK__ */
attrname = pstrdup(NameStr(rel->rd_att->attrs[varattno]->attname)); attrname = pstrdup(NameStr(rel->rd_att->attrs[varattno]->attname));
/* varattno is zero-based, so check that length() is always greater */ /* varattno is zero-based, so check that length() is always greater */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.55 2000/02/15 03:37:47 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.56 2000/03/09 05:00:24 inoue Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -355,6 +355,12 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos) ...@@ -355,6 +355,12 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
{ {
Ident *id = makeNode(Ident); Ident *id = makeNode(Ident);
#ifdef _DROP_COLUMN_HACK__
if (COLUMN_IS_DROPPED(attr[i]))
{
continue;
}
#endif /* _DROP_COLUMN_HACK__ */
id->name = palloc(NAMEDATALEN); id->name = palloc(NAMEDATALEN);
StrNCpy(id->name, NameStr(attr[i]->attname), NAMEDATALEN); StrNCpy(id->name, NameStr(attr[i]->attname), NAMEDATALEN);
id->indirection = NIL; id->indirection = NIL;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.91 2000/02/27 12:02:32 wieck Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.92 2000/03/09 05:00:25 inoue Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -568,6 +568,9 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo, ...@@ -568,6 +568,9 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
AttrDefault *attrdef = NULL; AttrDefault *attrdef = NULL;
int ndef = 0; int ndef = 0;
int i; int i;
#ifdef _DROP_COLUMN_HACK__
bool columnDropped;
#endif /* _DROP_COLUMN_HACK__ */
constr->has_not_null = false; constr->has_not_null = false;
...@@ -575,12 +578,25 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo, ...@@ -575,12 +578,25 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
for (i = 1; i <= relation->rd_rel->relnatts; i++) for (i = 1; i <= relation->rd_rel->relnatts; i++)
{ {
#ifdef _DROP_COLUMN_HACK__
columnDropped = false;
#endif /* _DROP_COLUMN_HACK__ */
atttup = (HeapTuple) AttributeRelidNumIndexScan(attrel, atttup = (HeapTuple) AttributeRelidNumIndexScan(attrel,
RelationGetRelid(relation), i); RelationGetRelid(relation), i);
if (!HeapTupleIsValid(atttup)) if (!HeapTupleIsValid(atttup))
#ifdef _DROP_COLUMN_HACK__
{
atttup = (HeapTuple) AttributeRelidNumIndexScan(attrel,
RelationGetRelid(relation), DROPPED_COLUMN_INDEX(i));
if (!HeapTupleIsValid(atttup))
#endif /* _DROP_COLUMN_HACK__ */
elog(ERROR, "cannot find attribute %d of relation %s", i, elog(ERROR, "cannot find attribute %d of relation %s", i,
RelationGetRelationName(relation)); RelationGetRelationName(relation));
#ifdef _DROP_COLUMN_HACK__
columnDropped = true;
}
#endif /* _DROP_COLUMN_HACK__ */
attp = (Form_pg_attribute) GETSTRUCT(atttup); attp = (Form_pg_attribute) GETSTRUCT(atttup);
relation->rd_att->attrs[i - 1] = relation->rd_att->attrs[i - 1] =
...@@ -590,6 +606,10 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo, ...@@ -590,6 +606,10 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
(char *) attp, (char *) attp,
ATTRIBUTE_TUPLE_SIZE); ATTRIBUTE_TUPLE_SIZE);
#ifdef _DROP_COLUMN_HACK__
if (columnDropped)
continue;
#endif /* _DROP_COLUMN_HACK__ */
/* Update if this attribute have a constraint */ /* Update if this attribute have a constraint */
if (attp->attnotnull) if (attp->attnotnull)
constr->has_not_null = true; constr->has_not_null = true;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* 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.53 2000/01/26 05:57:57 momjian Exp $ * $Id: pg_attribute.h,v 1.54 2000/03/09 05:00:26 inoue Exp $
* *
* NOTES * NOTES
* the genbki.sh script reads this file and generates .bki * the genbki.sh script reads this file and generates .bki
...@@ -178,6 +178,20 @@ typedef FormData_pg_attribute *Form_pg_attribute; ...@@ -178,6 +178,20 @@ 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.
* these are used in utils/cache/relcache.c * these are used in utils/cache/relcache.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment