Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
4c25a065
Commit
4c25a065
authored
Apr 30, 2002
by
Tom Lane
Browse files
Options
Browse Files
Download
Email 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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
48 deletions
+44
-48
src/backend/commands/trigger.c
src/backend/commands/trigger.c
+43
-46
src/include/commands/tablecmds.h
src/include/commands/tablecmds.h
+1
-2
No files found.
src/backend/commands/trigger.c
View file @
4c25a065
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,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/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)
...
@@ -514,8 +514,7 @@ RelationRemoveTriggers(Relation rel)
* for name conflict (within rel)
* for name conflict (within rel)
* for original trigger (if not arg)
* for original trigger (if not arg)
* modify tgname in trigger tuple
* modify tgname in trigger tuple
* insert modified trigger in trigger catalog
* update row in catalog
* delete original trigger from trigger catalog
*/
*/
void
void
renametrig
(
Oid
relid
,
renametrig
(
Oid
relid
,
...
@@ -526,8 +525,7 @@ renametrig(Oid relid,
...
@@ -526,8 +525,7 @@ renametrig(Oid relid,
Relation
tgrel
;
Relation
tgrel
;
HeapTuple
tuple
;
HeapTuple
tuple
;
SysScanDesc
tgscan
;
SysScanDesc
tgscan
;
ScanKeyData
key
;
ScanKeyData
key
[
2
];
bool
found
=
FALSE
;
Relation
idescs
[
Num_pg_trigger_indices
];
Relation
idescs
[
Num_pg_trigger_indices
];
/*
/*
...
@@ -550,70 +548,69 @@ renametrig(Oid relid,
...
@@ -550,70 +548,69 @@ renametrig(Oid relid,
/*
/*
* First pass -- look for name conflict
* First pass -- look for name conflict
*/
*/
ScanKeyEntryInitialize
(
&
key
,
0
,
ScanKeyEntryInitialize
(
&
key
[
0
]
,
0
,
Anum_pg_trigger_tgrelid
,
Anum_pg_trigger_tgrelid
,
F_OIDEQ
,
F_OIDEQ
,
ObjectIdGetDatum
(
relid
));
ObjectIdGetDatum
(
relid
));
ScanKeyEntryInitialize
(
&
key
[
1
],
0
,
Anum_pg_trigger_tgname
,
F_NAMEEQ
,
PointerGetDatum
(
newname
));
tgscan
=
systable_beginscan
(
tgrel
,
TriggerRelidNameIndex
,
true
,
tgscan
=
systable_beginscan
(
tgrel
,
TriggerRelidNameIndex
,
true
,
SnapshotNow
,
1
,
&
key
);
SnapshotNow
,
2
,
key
);
while
(
HeapTupleIsValid
(
tuple
=
systable_getnext
(
tgscan
)))
if
(
HeapTupleIsValid
(
tuple
=
systable_getnext
(
tgscan
)))
{
elog
(
ERROR
,
"renametrig: trigger %s already defined on relation %s"
,
Form_pg_trigger
pg_trigger
=
(
Form_pg_trigger
)
GETSTRUCT
(
tuple
);
newname
,
RelationGetRelationName
(
targetrel
));
if
(
namestrcmp
(
&
(
pg_trigger
->
tgname
),
newname
)
==
0
)
elog
(
ERROR
,
"renametrig: trigger %s already defined on relation %s"
,
newname
,
RelationGetRelationName
(
targetrel
));
}
systable_endscan
(
tgscan
);
systable_endscan
(
tgscan
);
/*
/*
* Second pass -- look for trigger existing with oldname and update
* Second pass -- look for trigger existing with oldname and update
*/
*/
ScanKeyEntryInitialize
(
&
key
,
0
,
ScanKeyEntryInitialize
(
&
key
[
0
]
,
0
,
Anum_pg_trigger_tgrelid
,
Anum_pg_trigger_tgrelid
,
F_OIDEQ
,
F_OIDEQ
,
ObjectIdGetDatum
(
relid
));
ObjectIdGetDatum
(
relid
));
ScanKeyEntryInitialize
(
&
key
[
1
],
0
,
Anum_pg_trigger_tgname
,
F_NAMEEQ
,
PointerGetDatum
(
oldname
));
tgscan
=
systable_beginscan
(
tgrel
,
TriggerRelidNameIndex
,
true
,
tgscan
=
systable_beginscan
(
tgrel
,
TriggerRelidNameIndex
,
true
,
SnapshotNow
,
1
,
&
key
);
SnapshotNow
,
2
,
key
);
while
(
HeapTupleIsValid
(
tuple
=
systable_getnext
(
tgscan
)))
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
)
namestrcpy
(
&
((
Form_pg_trigger
)
GETSTRUCT
(
tuple
))
->
tgname
,
newname
);
{
/*
* 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
);
/*
simple_heap_update
(
tgrel
,
&
tuple
->
t_self
,
tuple
);
* 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
);
/*
/*
* Invalidate relation's relcache entry so that other
* keep system catalog indices current
* backends (and this one too!) are sent SI message to make them
*/
* rebuild relcache entries.
CatalogOpenIndices
(
Num_pg_trigger_indices
,
Name_pg_trigger_indices
,
idescs
);
*/
CatalogIndexInsert
(
idescs
,
Num_pg_trigger_indices
,
tgrel
,
tuple
);
CacheInvalidateRelcache
(
relid
);
CatalogCloseIndices
(
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
);
systable_endscan
(
tgscan
);
heap_close
(
tgrel
,
RowExclusiveLock
);
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!
* Close rel, but keep exclusive lock!
*/
*/
...
...
src/include/commands/tablecmds.h
View file @
4c25a065
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* 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 @@
...
@@ -15,7 +15,6 @@
#define TABLECMDS_H
#define TABLECMDS_H
#include "nodes/parsenodes.h"
#include "nodes/parsenodes.h"
#include "utils/inval.h"
extern
void
AlterTableAddColumn
(
Oid
myrelid
,
bool
inherits
,
extern
void
AlterTableAddColumn
(
Oid
myrelid
,
bool
inherits
,
ColumnDef
*
colDef
);
ColumnDef
*
colDef
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment