Skip to content

Commit 93e1f5d

Browse files
Jan WieckJan Wieck
authored andcommitted
Automatically create toast tables on ALTER TABLE ... ADD COLUMN
and SELECT ... INTO ... too. Jan
1 parent 030962d commit 93e1f5d

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/backend/commands/command.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.84 2000/07/05 12:45:25 wieck Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.85 2000/07/05 13:22:23 wieck Exp $
1212
*
1313
* NOTES
1414
* The PerformAddAttribute() code, like most of the relation
@@ -471,6 +471,13 @@ AlterTableAddColumn(const char *relationName,
471471
heap_freetuple(reltup);
472472

473473
heap_close(rel, NoLock);
474+
475+
/*
476+
* Automatically create the secondary relation for TOAST
477+
* if it formerly had no such but now has toastable attributes.
478+
*/
479+
CommandCounterIncrement();
480+
AlterTableCreateToastTable(relationName, true);
474481
}
475482

476483

@@ -1255,6 +1262,7 @@ AlterTableCreateToastTable(const char *relationName, bool silent)
12551262
{
12561263
heap_close(rel, NoLock);
12571264
heap_close(class_rel, NoLock);
1265+
heap_freetuple(reltup);
12581266
return;
12591267
}
12601268

@@ -1276,8 +1284,18 @@ AlterTableCreateToastTable(const char *relationName, bool silent)
12761284
}
12771285

12781286
if (((Form_pg_class) GETSTRUCT(reltup))->reltoastrelid != InvalidOid)
1287+
{
1288+
if (silent)
1289+
{
1290+
heap_close(rel, NoLock);
1291+
heap_close(class_rel, NoLock);
1292+
heap_freetuple(reltup);
1293+
return;
1294+
}
1295+
12791296
elog(ERROR, "ALTER TABLE: relation \"%s\" already has a toast table",
12801297
relationName);
1298+
}
12811299

12821300
/*
12831301
* Create the toast table and its index
@@ -1348,6 +1366,8 @@ AlterTableCreateToastTable(const char *relationName, bool silent)
13481366

13491367
heap_close(class_rel, NoLock);
13501368
heap_close(rel, NoLock);
1369+
1370+
CommandCounterIncrement();
13511371
}
13521372

13531373

src/backend/executor/execMain.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
*
2828
*
2929
* IDENTIFICATION
30-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.119 2000/07/04 06:11:33 tgl Exp $
30+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.120 2000/07/05 13:22:25 wieck Exp $
3131
*
3232
*-------------------------------------------------------------------------
3333
*/
3434
#include "postgres.h"
3535

3636
#include "access/heapam.h"
3737
#include "catalog/heap.h"
38+
#include "commands/command.h"
3839
#include "commands/trigger.h"
3940
#include "executor/execdebug.h"
4041
#include "executor/execdefs.h"
@@ -892,6 +893,11 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
892893
*/
893894
CommandCounterIncrement();
894895

896+
/*
897+
* Eventually create a TOAST table for the into relation
898+
*/
899+
AlterTableCreateToastTable(intoName, true);
900+
895901
intoRelationDesc = heap_open(intoRelationId,
896902
AccessExclusiveLock);
897903
}

0 commit comments

Comments
 (0)