Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit030962d

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
Bugfix in ALTER TABLE CREATE TOAST TABLE
Automatically create toast table at CREATE TABLE if new tablehas toastable attributes.Jan
1 parentf2dfd56 commit030962d

File tree

3 files changed

+62
-39
lines changed

3 files changed

+62
-39
lines changed

‎src/backend/commands/command.c

Lines changed: 48 additions & 35 deletions
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.83 2000/07/04 06:11:27 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.84 2000/07/05 12:45:25 wieck Exp $
1212
*
1313
* NOTES
1414
* The PerformAddAttribute() code, like most of the relation
@@ -1177,38 +1177,57 @@ AlterTableDropConstraint(const char *relationName,
11771177
* ALTER TABLE CREATE TOAST TABLE
11781178
*/
11791179
void
1180-
AlterTableCreateToastTable(constchar*relationName)
1180+
AlterTableCreateToastTable(constchar*relationName,boolsilent)
11811181
{
11821182
Relationrel;
11831183
Oidmyrelid;
11841184
HeapTuplereltup;
1185+
HeapTupleDataclasstuple;
11851186
TupleDesctupdesc;
11861187
Form_pg_attribute*att;
11871188
Relationclass_rel;
1189+
Bufferbuffer;
11881190
Relationridescs[Num_pg_class_indices];
11891191
Oidtoast_relid;
11901192
Oidtoast_idxid;
11911193
boolhas_toastable_attrs= false;
11921194
inti;
1193-
chartoast_relname[NAMEDATALEN];
1194-
chartoast_idxname[NAMEDATALEN];
1195+
chartoast_relname[NAMEDATALEN+1];
1196+
chartoast_idxname[NAMEDATALEN+1];
11951197
Relationtoast_rel;
11961198
AttrNumberattNums[1];
11971199
OidclassObjectId[1];
11981200

11991201
/*
12001202
* permissions checking. XXX exactly what is appropriate here?
12011203
*/
1202-
/*
1203-
if (!allowSystemTableMods && IsSystemRelationName(relationName))
1204-
elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
1205-
relationName);
1206-
*/
12071204
#ifndefNO_SECURITY
12081205
if (!pg_ownercheck(UserName,relationName,RELNAME))
12091206
elog(ERROR,"ALTER TABLE: permission denied");
12101207
#endif
12111208

1209+
/*
1210+
* lock the pg_class tuple for update
1211+
*/
1212+
reltup=SearchSysCacheTuple(RELNAME,PointerGetDatum(relationName),
1213+
0,0,0);
1214+
1215+
if (!HeapTupleIsValid(reltup))
1216+
elog(ERROR,"ALTER TABLE: relation \"%s\" not found",
1217+
relationName);
1218+
class_rel=heap_openr(RelationRelationName,RowExclusiveLock);
1219+
classtuple.t_self=reltup->t_self;
1220+
switch (heap_mark4update(class_rel,&classtuple,&buffer))
1221+
{
1222+
caseHeapTupleSelfUpdated:
1223+
caseHeapTupleMayBeUpdated:
1224+
break;
1225+
default:
1226+
elog(ERROR,"couldn't lock pg_class tuple");
1227+
}
1228+
reltup=heap_copytuple(&classtuple);
1229+
ReleaseBuffer(buffer);
1230+
12121231
/*
12131232
* Grab an exclusive lock on the target table, which we will NOT
12141233
* release until end of transaction.
@@ -1231,22 +1250,24 @@ AlterTableCreateToastTable(const char *relationName)
12311250
}
12321251

12331252
if (!has_toastable_attrs)
1253+
{
1254+
if (silent)
1255+
{
1256+
heap_close(rel,NoLock);
1257+
heap_close(class_rel,NoLock);
1258+
return;
1259+
}
1260+
12341261
elog(ERROR,"ALTER TABLE: relation \"%s\" has no toastable attributes",
12351262
relationName);
1263+
}
12361264

1237-
/*
1238-
* Get the pg_class tuple for the relation
1239-
*/
1240-
reltup=SearchSysCacheTuple(RELNAME,
1241-
PointerGetDatum(relationName),
1242-
0,0,0);
1243-
1244-
if (!HeapTupleIsValid(reltup))
1245-
elog(ERROR,"ALTER TABLE: relation \"%s\" not found",
1246-
relationName);
12471265

12481266
/*
1249-
* XXX is the following check sufficient?
1267+
* XXX is the following check sufficient? At least it would
1268+
* allow to create TOAST tables for views. But why not - someone
1269+
* can insert into a view, so it shouldn't be impossible to hide
1270+
* huge data there :-)
12501271
*/
12511272
if (((Form_pg_class)GETSTRUCT(reltup))->relkind!=RELKIND_RELATION)
12521273
{
@@ -1281,6 +1302,8 @@ AlterTableCreateToastTable(const char *relationName)
12811302

12821303
/* XXX use RELKIND_TOASTVALUE here? */
12831304
/* XXX what if owning relation is temp? need we mark toasttable too? */
1305+
/* !!! No need to worry about temp. It'll go away when it's master */
1306+
/* table is deleted. Jan */
12841307
heap_create_with_catalog(toast_relname,tupdesc,RELKIND_RELATION,
12851308
false, true);
12861309

@@ -1307,33 +1330,23 @@ AlterTableCreateToastTable(const char *relationName)
13071330
toast_idxid=RelationGetRelid(toast_rel);
13081331
index_close(toast_rel);
13091332

1310-
/*
1311-
* Get the pg_class tuple for the relation
1312-
*/
1313-
class_rel=heap_openr(RelationRelationName,RowExclusiveLock);
1314-
1315-
reltup=SearchSysCacheTupleCopy(RELNAME,
1316-
PointerGetDatum(relationName),
1317-
0,0,0);
1318-
if (!HeapTupleIsValid(reltup))
1319-
elog(ERROR,"ALTER TABLE: relation \"%s\" not found",
1320-
relationName);
1321-
13221333
/*
13231334
* Store the toast table- and index-Oid's in the relation tuple
13241335
*/
13251336
((Form_pg_class)GETSTRUCT(reltup))->reltoastrelid=toast_relid;
13261337
((Form_pg_class)GETSTRUCT(reltup))->reltoastidxid=toast_idxid;
13271338
heap_update(class_rel,&reltup->t_self,reltup,NULL);
13281339

1329-
/* keep catalog indices current */
1340+
/*
1341+
* Keep catalog indices current
1342+
*/
13301343
CatalogOpenIndices(Num_pg_class_indices,Name_pg_class_indices,ridescs);
1331-
CatalogIndexInsert(ridescs,Num_pg_class_indices,rel,reltup);
1344+
CatalogIndexInsert(ridescs,Num_pg_class_indices,class_rel,reltup);
13321345
CatalogCloseIndices(Num_pg_class_indices,ridescs);
13331346

13341347
heap_freetuple(reltup);
13351348

1336-
heap_close(class_rel,RowExclusiveLock);
1349+
heap_close(class_rel,NoLock);
13371350
heap_close(rel,NoLock);
13381351
}
13391352

‎src/backend/tcop/utility.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.90 2000/07/03 23:09:46 wieck Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.91 2000/07/05 12:45:26 wieck Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -159,6 +159,15 @@ ProcessUtility(Node *parsetree,
159159
CHECK_IF_ABORTED();
160160

161161
DefineRelation((CreateStmt*)parsetree,RELKIND_RELATION);
162+
163+
/*
164+
* Let AlterTableCreateToastTable decide if this
165+
* one needs a secondary relation too.
166+
*
167+
*/
168+
CommandCounterIncrement();
169+
AlterTableCreateToastTable(((CreateStmt*)parsetree)->relname,
170+
true);
162171
break;
163172

164173
caseT_DropStmt:
@@ -361,7 +370,7 @@ ProcessUtility(Node *parsetree,
361370
AlterTableDropConstraint(stmt->relname,stmt->inh,stmt->name,stmt->behavior);
362371
break;
363372
case'E':/* CREATE TOAST TABLE */
364-
AlterTableCreateToastTable(stmt->relname);
373+
AlterTableCreateToastTable(stmt->relname, false);
365374
break;
366375
default:/* oops */
367376
elog(ERROR,"T_AlterTableStmt: unknown subtype");

‎src/include/commands/command.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: command.h,v 1.20 2000/07/03 23:10:10 wieck Exp $
10+
* $Id: command.h,v 1.21 2000/07/05 12:45:31 wieck Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -58,7 +58,8 @@ extern void AlterTableDropConstraint(const char *relationName,
5858
boolinh,constchar*constrName,
5959
intbehavior);
6060

61-
externvoidAlterTableCreateToastTable(constchar*relationName);
61+
externvoidAlterTableCreateToastTable(constchar*relationName,
62+
boolsilent);
6263

6364
/*
6465
* LOCK

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp