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

Commitd67442c

Browse files
committed
Mop-up some infelicities in new relation lookup handling.
1 parentea13a3f commitd67442c

File tree

7 files changed

+70
-97
lines changed

7 files changed

+70
-97
lines changed

‎src/backend/access/index/genam.c

Lines changed: 2 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/access/index/genam.c,v 1.31 2002/02/19 20:11:10 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.32 2002/03/29 22:10:32 tgl Exp $
1212
*
1313
* NOTES
1414
* many of the old access method routines have been turned into
@@ -308,6 +308,7 @@ systable_beginscan(Relation rel,
308308
Relationirel;
309309
unsignedi;
310310

311+
/* We assume it's a system index, so index_openr is OK */
311312
sysscan->irel=irel=index_openr(indexRelname);
312313
/*
313314
* Change attribute numbers to be index column numbers.

‎src/backend/commands/cluster.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.74 2002/03/2919:06:03 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.75 2002/03/2922:10:33 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -33,6 +33,7 @@
3333
#include"commands/rename.h"
3434
#include"miscadmin.h"
3535
#include"utils/builtins.h"
36+
#include"utils/lsyscache.h"
3637
#include"utils/syscache.h"
3738
#include"utils/temprel.h"
3839

@@ -65,40 +66,35 @@ cluster(RangeVar *oldrelation, char *oldindexname)
6566
boolistemp;
6667
charNewHeapName[NAMEDATALEN];
6768
charNewIndexName[NAMEDATALEN];
68-
RangeVar*saveoldrelation;
69-
RangeVar*saveoldindex;
7069
RangeVar*NewHeap;
7170
RangeVar*NewIndex;
7271

73-
/*
74-
* FIXME SCHEMAS: The old code had the comment:
75-
* "Copy the arguments into local storage, just to be safe."
76-
* By using copyObject we are not using local storage.
77-
* Was that really necessary?
78-
*/
79-
saveoldrelation=copyObject(oldrelation);
80-
saveoldindex=copyObject(oldrelation);
81-
saveoldindex->relname=pstrdup(oldindexname);
82-
8372
/*
8473
* We grab exclusive access to the target rel and index for the
8574
* duration of the transaction.
8675
*/
87-
OldHeap=heap_openrv(saveoldrelation,AccessExclusiveLock);
76+
OldHeap=heap_openrv(oldrelation,AccessExclusiveLock);
8877
OIDOldHeap=RelationGetRelid(OldHeap);
8978

90-
OldIndex=index_openrv(saveoldindex);
91-
LockRelation(OldIndex,AccessExclusiveLock);
92-
OIDOldIndex=RelationGetRelid(OldIndex);
79+
istemp=is_temp_rel_name(oldrelation->relname);
9380

94-
istemp=is_temp_rel_name(saveoldrelation->relname);
81+
/*
82+
* The index is expected to be in the same namespace as the relation.
83+
*/
84+
OIDOldIndex=get_relname_relid(oldindexname,
85+
RelationGetNamespace(OldHeap));
86+
if (!OidIsValid(OIDOldIndex))
87+
elog(ERROR,"CLUSTER: cannot find index \"%s\" for table \"%s\"",
88+
oldindexname,oldrelation->relname);
89+
OldIndex=index_open(OIDOldIndex);
90+
LockRelation(OldIndex,AccessExclusiveLock);
9591

9692
/*
9793
* Check that index is in fact an index on the given relation
9894
*/
9995
if (OldIndex->rd_index->indrelid!=OIDOldHeap)
10096
elog(ERROR,"CLUSTER: \"%s\" is not an index for table \"%s\"",
101-
saveoldindex->relname,saveoldrelation->relname);
97+
oldindexname,oldrelation->relname);
10298

10399
/* Drop relcache refcnts, but do NOT give up the locks */
104100
heap_close(OldHeap,NoLock);
@@ -133,17 +129,19 @@ cluster(RangeVar *oldrelation, char *oldindexname)
133129

134130
CommandCounterIncrement();
135131

136-
NewHeap=copyObject(saveoldrelation);
132+
/* XXX ugly, and possibly wrong in the presence of schemas... */
133+
/* would be better to pass OIDs to renamerel. */
134+
NewHeap=copyObject(oldrelation);
137135
NewHeap->relname=NewHeapName;
138-
NewIndex=copyObject(saveoldindex);
136+
NewIndex=copyObject(oldrelation);
139137
NewIndex->relname=NewIndexName;
140138

141-
renamerel(NewHeap,saveoldrelation->relname);
139+
renamerel(NewHeap,oldrelation->relname);
142140

143141
/* This one might be unnecessary, but let's be safe. */
144142
CommandCounterIncrement();
145143

146-
renamerel(NewIndex,saveoldindex->relname);
144+
renamerel(NewIndex,oldindexname);
147145
}
148146

149147
staticOid

‎src/backend/commands/creatinh.c

Lines changed: 5 additions & 6 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/creatinh.c,v 1.93 2002/03/2919:06:05 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.94 2002/03/2922:10:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -260,13 +260,12 @@ RemoveRelation(const RangeVar *relation)
260260
void
261261
TruncateRelation(constRangeVar*relation)
262262
{
263-
Oidrelid;
264263
Relationrel;
265-
266-
relid=RangeVarGetRelid(relation, false);
264+
Oidrelid;
267265

268266
/* Grab exclusive lock in preparation for truncate */
269-
rel=heap_open(relid,AccessExclusiveLock);
267+
rel=heap_openrv(relation,AccessExclusiveLock);
268+
relid=RelationGetRelid(rel);
270269

271270
if (rel->rd_rel->relkind==RELKIND_SEQUENCE)
272271
elog(ERROR,"TRUNCATE cannot be used on sequences. '%s' is a sequence",
@@ -280,7 +279,7 @@ TruncateRelation(const RangeVar *relation)
280279
elog(ERROR,"TRUNCATE cannot be used on system tables. '%s' is a system table",
281280
RelationGetRelationName(rel));
282281

283-
if (!pg_class_ownercheck(RelationGetRelid(rel),GetUserId()))
282+
if (!pg_class_ownercheck(relid,GetUserId()))
284283
elog(ERROR,"you do not own relation \"%s\"",
285284
RelationGetRelationName(rel));
286285

‎src/backend/commands/trigger.c

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.108 2002/03/26 19:15:45 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.109 2002/03/29 22:10:33 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -18,6 +18,7 @@
1818
#include"catalog/catalog.h"
1919
#include"catalog/catname.h"
2020
#include"catalog/indexing.h"
21+
#include"catalog/namespace.h"
2122
#include"catalog/pg_language.h"
2223
#include"catalog/pg_proc.h"
2324
#include"catalog/pg_trigger.h"
@@ -29,6 +30,7 @@
2930
#include"utils/builtins.h"
3031
#include"utils/fmgroids.h"
3132
#include"utils/inval.h"
33+
#include"utils/lsyscache.h"
3234
#include"utils/syscache.h"
3335

3436

@@ -96,20 +98,10 @@ CreateTrigger(CreateTrigStmt *stmt)
9698
stmt->trigname=constrtrigname;
9799
sprintf(constrtrigname,"RI_ConstraintTrigger_%u",newoid());
98100

99-
if (stmt->constrrel==NULL)
100-
constrrelid=InvalidOid;
101+
if (stmt->constrrel!=NULL)
102+
constrrelid=RangeVarGetRelid(stmt->constrrel, false);
101103
else
102-
{
103-
/*
104-
* NoLock is probably sufficient here, since we're only
105-
* interested in getting the relation's OID...
106-
*/
107-
Relationconrel;
108-
109-
conrel=heap_openrv(stmt->constrrel,NoLock);
110-
constrrelid=conrel->rd_id;
111-
heap_close(conrel,NoLock);
112-
}
104+
constrrelid=InvalidOid;
113105
}
114106

115107
TRIGGER_CLEAR_TYPE(tgtype);
@@ -310,8 +302,11 @@ CreateTrigger(CreateTrigStmt *stmt)
310302
heap_close(rel,NoLock);
311303
}
312304

305+
/*
306+
* DropTrigger - drop an individual trigger by name
307+
*/
313308
void
314-
DropTrigger(DropTrigStmt*stmt)
309+
DropTrigger(Oidrelid,constchar*trigname)
315310
{
316311
Relationrel;
317312
Relationtgrel;
@@ -320,21 +315,21 @@ DropTrigger(DropTrigStmt *stmt)
320315
Relationpgrel;
321316
HeapTupletuple;
322317
Relationridescs[Num_pg_class_indices];
318+
intremaining=0;
323319
intfound=0;
324-
inttgfound=0;
325320

326-
rel=heap_openrv(stmt->relation,AccessExclusiveLock);
321+
rel=heap_open(relid,AccessExclusiveLock);
327322

328323
if (rel->rd_rel->relkind!=RELKIND_RELATION)
329324
elog(ERROR,"DropTrigger: relation \"%s\" is not a table",
330-
stmt->relation->relname);
325+
RelationGetRelationName(rel));
331326

332-
if (!allowSystemTableMods&&IsSystemRelationName(stmt->relation->relname))
327+
if (!allowSystemTableMods&&IsSystemRelationName(RelationGetRelationName(rel)))
333328
elog(ERROR,"DropTrigger: can't drop trigger for system relation %s",
334-
stmt->relation->relname);
329+
RelationGetRelationName(rel));
335330

336-
if (!pg_class_ownercheck(RelationGetRelid(rel),GetUserId()))
337-
elog(ERROR,"%s: %s",stmt->relation->relname,
331+
if (!pg_class_ownercheck(relid,GetUserId()))
332+
elog(ERROR,"%s: %s",RelationGetRelationName(rel),
338333
aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
339334

340335
/*
@@ -346,33 +341,33 @@ DropTrigger(DropTrigStmt *stmt)
346341
tgrel=heap_openr(TriggerRelationName,RowExclusiveLock);
347342
ScanKeyEntryInitialize(&key,0,Anum_pg_trigger_tgrelid,
348343
F_OIDEQ,
349-
ObjectIdGetDatum(RelationGetRelid(rel)));
344+
ObjectIdGetDatum(relid));
350345
tgscan=systable_beginscan(tgrel,TriggerRelidIndex, true,
351346
SnapshotNow,1,&key);
352347
while (HeapTupleIsValid(tuple=systable_getnext(tgscan)))
353348
{
354349
Form_pg_triggerpg_trigger= (Form_pg_trigger)GETSTRUCT(tuple);
355350

356-
if (namestrcmp(&(pg_trigger->tgname),stmt->trigname)==0)
351+
if (namestrcmp(&(pg_trigger->tgname),trigname)==0)
357352
{
358353
/* Delete any comments associated with this trigger */
359354
DeleteComments(tuple->t_data->t_oid,RelationGetRelid(tgrel));
360355

361356
simple_heap_delete(tgrel,&tuple->t_self);
362-
tgfound++;
357+
found++;
363358
}
364359
else
365-
found++;
360+
remaining++;
366361
}
367362
systable_endscan(tgscan);
368363
heap_close(tgrel,RowExclusiveLock);
369364

370-
if (tgfound==0)
365+
if (found==0)
371366
elog(ERROR,"DropTrigger: there is no trigger %s on relation %s",
372-
stmt->trigname,stmt->relation->relname);
373-
if (tgfound>1)
367+
trigname,RelationGetRelationName(rel));
368+
if (found>1)/* shouldn't happen */
374369
elog(NOTICE,"DropTrigger: found (and deleted) %d triggers %s on relation %s",
375-
tgfound,stmt->trigname,stmt->relation->relname);
370+
found,trigname,RelationGetRelationName(rel));
376371

377372
/*
378373
* Update relation's pg_class entry. Crucial side-effect: other
@@ -381,26 +376,20 @@ DropTrigger(DropTrigStmt *stmt)
381376
*/
382377
pgrel=heap_openr(RelationRelationName,RowExclusiveLock);
383378
tuple=SearchSysCacheCopy(RELOID,
384-
ObjectIdGetDatum(RelationGetRelid(rel)),
379+
ObjectIdGetDatum(relid),
385380
0,0,0);
386381
if (!HeapTupleIsValid(tuple))
387382
elog(ERROR,"DropTrigger: relation %s not found in pg_class",
388-
stmt->relation->relname);
383+
RelationGetRelationName(rel));
389384

390-
((Form_pg_class)GETSTRUCT(tuple))->reltriggers=found;
385+
((Form_pg_class)GETSTRUCT(tuple))->reltriggers=remaining;
391386
simple_heap_update(pgrel,&tuple->t_self,tuple);
392387
CatalogOpenIndices(Num_pg_class_indices,Name_pg_class_indices,ridescs);
393388
CatalogIndexInsert(ridescs,Num_pg_class_indices,pgrel,tuple);
394389
CatalogCloseIndices(Num_pg_class_indices,ridescs);
395390
heap_freetuple(tuple);
396391
heap_close(pgrel,RowExclusiveLock);
397392

398-
/*
399-
* We used to try to update the rel's relcache entry here, but that's
400-
* fairly pointless since it will happen as a byproduct of the
401-
* upcoming CommandCounterIncrement...
402-
*/
403-
404393
/* Keep lock on target rel until end of xact */
405394
heap_close(rel,NoLock);
406395
}
@@ -479,25 +468,12 @@ RelationRemoveTriggers(Relation rel)
479468

480469
while (HeapTupleIsValid(tup=systable_getnext(tgscan)))
481470
{
482-
Form_pg_triggerpg_trigger;
483-
Relationrefrel;
484-
DropTrigStmt*stmt=makeNode(DropTrigStmt);
485-
486-
pg_trigger= (Form_pg_trigger)GETSTRUCT(tup);
487-
488-
stmt->trigname=pstrdup(NameStr(pg_trigger->tgname));
489-
490-
/* May as well grab AccessExclusiveLock, since DropTrigger will. */
491-
refrel=heap_open(pg_trigger->tgrelid,AccessExclusiveLock);
492-
stmt->relation=makeNode(RangeVar);
493-
/* XXX bogus: what about schema? */
494-
stmt->relation->relname=pstrdup(RelationGetRelationName(refrel));
495-
heap_close(refrel,NoLock);
471+
Form_pg_triggerpg_trigger= (Form_pg_trigger)GETSTRUCT(tup);
496472

497473
elog(NOTICE,"DROP TABLE implicitly drops referential integrity trigger from table \"%s\"",
498-
stmt->relation->relname);
474+
get_temp_rel_by_physicalname(get_rel_name(pg_trigger->tgrelid)));
499475

500-
DropTrigger(stmt);
476+
DropTrigger(pg_trigger->tgrelid,NameStr(pg_trigger->tgname));
501477

502478
/*
503479
* Need to do a command counter increment here to show up new

‎src/backend/parser/parse_func.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.121 2002/03/2919:06:11 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.122 2002/03/2922:10:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1227,12 +1227,7 @@ find_inheritors(Oid relid, Oid **supervec)
12271227
foreach(elt,visited)
12281228
{
12291229
/* return the type id, rather than the relation id */
1230-
Relationrd;
1231-
1232-
relid=lfirsti(elt);
1233-
rd=heap_open(relid,NoLock);
1234-
*relidvec++=rd->rd_rel->reltype;
1235-
heap_close(rd,NoLock);
1230+
*relidvec++=get_rel_type_id((Oid)lfirsti(elt));
12361231
}
12371232
}
12381233
else

‎src/backend/tcop/utility.c

Lines changed: 7 additions & 3 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.141 2002/03/2919:06:13 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.142 2002/03/2922:10:33 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -385,7 +385,6 @@ ProcessUtility(Node *parsetree,
385385
{
386386
RenameStmt*stmt= (RenameStmt*)parsetree;
387387

388-
relname=stmt->relation->relname;
389388
CheckOwnership(stmt->relation, true);
390389

391390
/* ----------------
@@ -723,7 +722,12 @@ ProcessUtility(Node *parsetree,
723722
break;
724723

725724
caseT_DropTrigStmt:
726-
DropTrigger((DropTrigStmt*)parsetree);
725+
{
726+
DropTrigStmt*stmt= (DropTrigStmt*)parsetree;
727+
728+
DropTrigger(RangeVarGetRelid(stmt->relation, false),
729+
stmt->trigname);
730+
}
727731
break;
728732

729733
caseT_CreatePLangStmt:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp