8000 Invalidate temp entries for aborted transactions. · postgrespro/postgres_cluster@fb7548f · GitHub
[go: up one dir, main page]

Skip to content

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

Appearance settings

Commit fb7548f

Browse files
committed
Invalidate temp entries for aborted transactions.
1 parent b4a607c commit fb7548f

File tree

4 files changed

+76
-22
lines changed

4 files changed

+76
-22
lines changed

src/backend/access/transam/xact.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.48 1999/09/04 18:42:15 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.49 1999/09/04 19:55:48 momjian Exp $
1111
*
1212
* NOTES
1313
* Transaction aborts can now occur two ways:
@@ -151,6 +151,7 @@
151151
#include "commands/vacuum.h"
152152
#include "libpq/be-fsstubs.h"
153153
#include "storage/proc.h"
154+
#include "utils/temprel.h"
154155
#include "utils/inval.h"
155156
#include "utils/port 8000 al.h"
156157
#include "utils/relcache.h"
@@ -1022,6 +1023,7 @@ AbortTransaction()
10221023
RecordTransactionAbort();
10231024
RelationPurgeLocalRelation(false);
10241025
DestroyNoNameRels();
1026+
invalidate_temp_relations();
10251027
AtEOXact_nbtree();
10261028
AtAbort_Cache();
10271029
AtAbort_Locks();

src/backend/catalog/indexing.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.42 1999/07/20 17:14:06 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.43 1999/09/04 19:55:49 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -449,13 +449,14 @@ ClassNameIndexScan(Relation heapRelation, char *relName)
449449
Relation idesc;
450450
ScanKeyData skey[1];
451451
HeapTuple tuple;
452-
452+
char *hold_rel;
453+
453454
/*
454455
* we have to do this before looking in system tables because temp
455456
* table namespace takes precedence
456457
*/
457-
if ((tuple = get_temp_rel_by_name(relName)) != NULL)
458-
return heap_copytuple(tuple);
458+
if ((hold_rel = get_temp_rel_by_name(relName)) != NULL)
459+
relName = hold_rel;
459460

460461
ScanKeyEntryInitialize(&skey[0],
461462
(bits16) 0x0,

src/backend/utils/cache/temprel.c

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.10 1999/07/17 20:18:02 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.11 1999/09/04 19:55:50 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -18,13 +18,13 @@
1818
* When a temp table is created, a linked list of temp table tuples is
1919
* stored here. When a relname cache lookup is done, references to user-named
2020
* temp tables are converted to the internal temp table names.
21-
*
2221
*/
2322

2423
#include <sys/types.h>
2524

2625
#include "postgres.h"
2726
#include "access/heapam.h"
27+
#include "access/xact.h"
2828
#include "catalog/heap.h"
2929
#include "catalog/index.h"
3030
#include "utils/temprel.h"
@@ -41,7 +41,10 @@ static List *temp_rels = NIL;
4141
typedef struct TempTable
4242
{
4343
char *user_relname;
44-
HeapTuple pg_class_tuple;
44+
char *relname;
45+
Oid relid;
46+
char relkind;
47+
TransactionId xid;
4548
} TempTable;
4649

4750

@@ -55,11 +58,15 @@ create_temp_relation(char *relname, HeapTuple pg_class_tuple)
5558

5659
temp_rel = palloc(sizeof(TempTable));
5760
temp_rel->user_relname = palloc(NAMEDATALEN);
61+
temp_rel->relname = palloc(NAMEDATALEN);
5862

5963
/* save user-supplied name */
6064
strcpy(temp_rel->user_relname, relname);
61-
62-
temp_rel->pg_class_tuple = heap_copytuple(pg_class_tuple);
65+
StrNCpy(temp_rel->relname, ((Form_pg_class)
66+
GETSTRUCT(pg_class_tuple))->relname.data, NAMEDATALEN);
67+
temp_rel->relid = pg_class_tuple->t_data->t_oid;
68+
temp_rel->relkind = ((Form_pg_class) GETSTRUCT(pg_class_tuple))->relkind;
69+
temp_rel->xid = GetCurrentTransactionId();
6370

6471
temp_rels = lcons(temp_rel, temp_rels);
6572

@@ -79,22 +86,19 @@ remove_all_temp_relations(void)
7986
while (l != NIL)
8087
{
8188
TempTable *temp_rel = lfirst(l);
82-
Form_pg_class classtuple;
83-
84-
classtuple = (Form_pg_class) GETSTRUCT(temp_rel->pg_class_tuple);
8589

8690
next = lnext(l); /* do this first, l is deallocated */
8791

88-
if (classtuple->relkind != RELKIND_INDEX)
92+
if (temp_rel->relkind != RELKIND_INDEX)
8993
{
90-
char relname[NAMEDATALEN];
94+
char relname[NAMEDATALEN];
9195

9296
/* safe from deallocation */
9397
strcpy(relname, temp_rel->user_relname);
9498
heap_destroy_with_catalog(relname);
9599
}
96100
else
97-
index_destroy(temp_rel->pg_class_tuple->t_data->t_oid);
101+
index_destroy(temp_rel->relid);
98102

99103
l = next;
100104
}
@@ -118,10 +122,56 @@ remove_temp_relation(Oid relid)
118122
{
119123
TempTable *temp_rel = lfirst(l);
120124

121-
if (temp_rel->pg_class_tuple->t_data->t_oid == relid)
125+
if (temp_rel->relid == relid)
126+
{
127+
pfree(temp_rel->user_relname);
128+
pfree(temp_rel->relname);
129+
pfree(temp_rel);
130+
/* remove from linked list */
131+
if (prev != NIL)
132+
{
133+
lnext(prev) = lnext(l);
134+
pfree(l);
135+
l = lnext(prev);
136+
}
137+
else
138+
{
139+
temp_rels = lnext(l);
140+
pfree(l);
141+
l = temp_rels;
142+
}
143+
}
144+
else
145+
{
146+
prev = l;
147+
l = lnext(l);
148+
}
149+
150+
}
151+
152+
MemoryContextSwitchTo(oldcxt);
153+
}
154+
155+
/* remove entries from aborted transactions */
156+
void
157+
invalidate_temp_relations(void)
158+
{
159+
MemoryContext oldcxt;
160+
List *l,
161+
*prev;
162+
163+
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
164+
165+
prev = NIL;
166+
l = temp_rels;
167+
while (l != NIL)
168+
{
169+
TempTable *temp_rel = lfirst(l);
170+
171+
if (temp_rel->xid == GetCurrentTransactionId())
122172
{
123173
pfree(temp_rel->user_relname);
124-
pfree(temp_rel->pg_class_tuple);
174+
pfree(temp_rel->relname);
125175
pfree(temp_rel);
126176
/* remove from linked list */
127177
if (prev != NIL)
@@ -148,7 +198,7 @@ remove_temp_relation(Oid relid)
148198
MemoryContextSwitchTo(oldcxt);
149199
}
150200

151-
HeapTuple
201+
char *
152202
get_temp_rel_by_name(char *user_relname)
153203
{
154204
List *l;
@@ -158,7 +208,7 @@ get_temp_rel_by_name(char *user_relname)
158208
TempTable *temp_rel = lfirst(l);
159209

160210
if (strcmp(temp_rel->user_relname, user_relname) == 0)
161-
return temp_rel->pg_class_tuple;
211+
return temp_rel->relname;
162212
}
163213
return NULL;
164214
}

src/include/utils/temprel.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: temprel.h,v 1.4 1999/07/15 15:21:43 momjian Exp $
9+
* $Id: temprel.h,v 1.5 1999/09/04 19:55:50 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -17,7 +17,8 @@
1717

1818
void create_temp_relation(char *relname, HeapTuple pg_class_tuple);
1919
void remove_all_temp_relations(void);
20+
void invalidate_temp_relations(void);
2021
void remove_temp_relation(Oid relid);
21-
HeapTuple get_temp_rel_by_name(char *user_relname);
22+
char *get_temp_rel_by_name(char *user_relname);
2223

2324
#endif /* TEMPREL_H */

0 commit comments

Comments
 (0)
0