Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
4c25a065
Commit
4c25a065
authored
23 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Code review for ALTER TRIGGER RENAME patch: make better use of index,
don't scribble on tuple returned by table scan.
parent
857661ba
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/backend/commands/trigger.c
+43
-46
43 additions, 46 deletions
src/backend/commands/trigger.c
src/include/commands/tablecmds.h
+1
-2
1 addition, 2 deletions
src/include/commands/tablecmds.h
with
44 additions
and
48 deletions
src/backend/commands/trigger.c
+
43
−
46
View file @
4c25a065
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.11
6
2002/04/
27 03:45:02
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.11
7
2002/04/
30 01:24:57
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -514,8 +514,7 @@ RelationRemoveTriggers(Relation rel)
* for name conflict (within rel)
* for original trigger (if not arg)
* modify tgname in trigger tuple
* insert modified trigger in trigger catalog
* delete original trigger from trigger catalog
* update row in catalog
*/
void
renametrig
(
Oid
relid
,
...
...
@@ -526,8 +525,7 @@ renametrig(Oid relid,
Relation
tgrel
;
HeapTuple
tuple
;
SysScanDesc
tgscan
;
ScanKeyData
key
;
bool
found
=
FALSE
;
ScanKeyData
key
[
2
];
Relation
idescs
[
Num_pg_trigger_indices
];
/*
...
...
@@ -550,70 +548,69 @@ renametrig(Oid relid,
/*
* First pass -- look for name conflict
*/
ScanKeyEntryInitialize
(
&
key
,
0
,
ScanKeyEntryInitialize
(
&
key
[
0
]
,
0
,
Anum_pg_trigger_tgrelid
,
F_OIDEQ
,
ObjectIdGetDatum
(
relid
));
ScanKeyEntryInitialize
(
&
key
[
1
],
0
,
Anum_pg_trigger_tgname
,
F_NAMEEQ
,
PointerGetDatum
(
newname
));
tgscan
=
systable_beginscan
(
tgrel
,
TriggerRelidNameIndex
,
true
,
SnapshotNow
,
1
,
&
key
);
while
(
HeapTupleIsValid
(
tuple
=
systable_getnext
(
tgscan
)))
{
Form_pg_trigger
pg_trigger
=
(
Form_pg_trigger
)
GETSTRUCT
(
tuple
);
if
(
namestrcmp
(
&
(
pg_trigger
->
tgname
),
newname
)
==
0
)
elog
(
ERROR
,
"renametrig: trigger %s already defined on relation %s"
,
newname
,
RelationGetRelationName
(
targetrel
));
}
SnapshotNow
,
2
,
key
);
if
(
HeapTupleIsValid
(
tuple
=
systable_getnext
(
tgscan
)))
elog
(
ERROR
,
"renametrig: trigger %s already defined on relation %s"
,
newname
,
RelationGetRelationName
(
targetrel
));
systable_endscan
(
tgscan
);
/*
* Second pass -- look for trigger existing with oldname and update
*/
ScanKeyEntryInitialize
(
&
key
,
0
,
ScanKeyEntryInitialize
(
&
key
[
0
]
,
0
,
Anum_pg_trigger_tgrelid
,
F_OIDEQ
,
ObjectIdGetDatum
(
relid
));
ScanKeyEntryInitialize
(
&
key
[
1
],
0
,
Anum_pg_trigger_tgname
,
F_NAMEEQ
,
PointerGetDatum
(
oldname
));
tgscan
=
systable_beginscan
(
tgrel
,
TriggerRelidNameIndex
,
true
,
SnapshotNow
,
1
,
&
key
);
while
(
HeapTupleIsValid
(
tuple
=
systable_getnext
(
tgscan
)))
SnapshotNow
,
2
,
key
);
if
(
HeapTupleIsValid
(
tuple
=
systable_getnext
(
tgscan
)))
{
Form_pg_trigger
pg_trigger
=
(
Form_pg_trigger
)
GETSTRUCT
(
tuple
);
/*
* Update pg_trigger tuple with new tgname.
*/
tuple
=
heap_copytuple
(
tuple
);
/* need a modifiable copy */
if
(
namestrcmp
(
&
(
pg_trigger
->
tgname
),
oldname
)
==
0
)
{
/*
* Update pg_trigger tuple with new tgname.
* (Scribbling on tuple is OK because it's a copy...)
*/
namestrcpy
(
&
(
pg_trigger
->
tgname
),
newname
);
simple_heap_update
(
tgrel
,
&
tuple
->
t_self
,
tuple
);
namestrcpy
(
&
((
Form_pg_trigger
)
GETSTRUCT
(
tuple
))
->
tgname
,
newname
);
/*
* keep system catalog indices current
*/
CatalogOpenIndices
(
Num_pg_trigger_indices
,
Name_pg_trigger_indices
,
idescs
);
CatalogIndexInsert
(
idescs
,
Num_pg_trigger_indices
,
tgrel
,
tuple
);
CatalogCloseIndices
(
Num_pg_trigger_indices
,
idescs
);
simple_heap_update
(
tgrel
,
&
tuple
->
t_self
,
tuple
);
/*
*
Invalidate relation's relcache entry so that other
*
backends (and this one too!) are sent SI message to make them
* rebuild relcache entries.
*/
Ca
cheInvalidateRelcache
(
relid
);
/*
*
keep system catalog indices current
*
/
CatalogOpenIndices
(
Num_pg_trigger_indices
,
Name_pg_trigger_indices
,
idescs
);
CatalogIndexInsert
(
idescs
,
Num_pg_trigger_indices
,
tgrel
,
tuple
);
Ca
talogCloseIndices
(
Num_pg_trigger_indices
,
idescs
);
found
=
TRUE
;
break
;
}
/*
* Invalidate relation's relcache entry so that other backends (and
* this one too!) are sent SI message to make them rebuild relcache
* entries. (Ideally this should happen automatically...)
*/
CacheInvalidateRelcache
(
relid
);
}
else
{
elog
(
ERROR
,
"renametrig: trigger %s not defined on relation %s"
,
oldname
,
RelationGetRelationName
(
targetrel
));
}
systable_endscan
(
tgscan
);
heap_close
(
tgrel
,
RowExclusiveLock
);
if
(
!
found
)
elog
(
ERROR
,
"renametrig: trigger %s not defined on relation %s"
,
oldname
,
RelationGetRelationName
(
targetrel
));
/*
* Close rel, but keep exclusive lock!
*/
...
...
This diff is collapsed.
Click to expand it.
src/include/commands/tablecmds.h
+
1
−
2
View file @
4c25a065
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: tablecmds.h,v 1.
3
2002/04/
26 19:29:47
tgl Exp $
* $Id: tablecmds.h,v 1.
4
2002/04/
30 01:24:52
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -15,7 +15,6 @@
#define TABLECMDS_H
#include
"nodes/parsenodes.h"
#include
"utils/inval.h"
extern
void
AlterTableAddColumn
(
Oid
myrelid
,
bool
inherits
,
ColumnDef
*
colDef
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment