Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit abb1b3e

Browse files
committed
I checked the alter table code, and started suspecting the relation
cache. I found if I manually added a line to flush the whole relation cache, the assert error disappeared. Looking through the code, I found that the relation cache is flushed at the end of each query if the reference count is zero for the relation. However, printf's showed that the rd_relcnt(reference count) for the accessed query was not returning to zero after each query. It turns out the parser was doing a heap_ropen in parser/analyze.c to get information about the table's columns, but was not doing a heap_close. This was causing the query after the ALTER TABLE ADD to see the old table structure, and the executor's assert was reporting the problem.
1 parent bef3c89 commit abb1b3e

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/Makefile.global

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/Attic/Makefile.global,v 1.37 1996/10/11 02:38:16 scrappy Exp $
10+
# $Header: /cvsroot/pgsql/src/Attic/Makefile.global,v 1.38 1996/10/13 04:25:23 momjian Exp $
1111
#
1212
# NOTES
1313
# This is seen by any Makefiles that include mk/postgres.mk. To
@@ -214,7 +214,10 @@ X11_INCDIR = /usr/include
214214
X11_LIBDIR = /usr/lib
215215
X11_LIB = -lX11 -lsocket -lnsl
216216

217-
#
217+
# These must match include/config.h
218+
NAMEDATALEN= 32
219+
OIDNAMELEN= 36
220+
218221
# include port specific rules and variables. For instance:
219222
#
220223
# signal(2) handling - this is here because it affects some of

src/backend/parser/analyze.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.5 1996/08/06 16:37:58 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.6 1996/10/13 04:25:42 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -95,10 +95,11 @@ makeParseState() {
9595
pstate = malloc(sizeof(ParseState));
9696
pstate->p_last_resno = 1;
9797
pstate->p_target_resnos = NIL;
98+
pstate->p_current_rel = NULL;
9899
pstate->p_rtable = NIL;
99100
pstate->p_query_is_rule = 0;
100101
pstate->p_numAgg = 0;
101-
pstate->p_aggs = NULL;
102+
pstate->p_aggs = NIL;
102103

103104
return (pstate);
104105
}
@@ -126,6 +127,8 @@ parse_analyze(List *pl)
126127
pstate = makeParseState();
127128
result->qtrees[i++] = transformStmt(pstate, lfirst(pl));
128129
pl = lnext(pl);
130+
if (pstate->p_current_rel != NULL)
131+
heap_close(pstate->p_current_rel);
129132
free(pstate);
130133
}
131134

@@ -828,8 +831,8 @@ makeRangeTable(ParseState *pstate, char *relname, List *frmList)
828831
pstate->p_rtable = lappend(pstate->p_rtable, ent);
829832
}
830833
x = RangeTablePosn(pstate->p_rtable, relname);
831-
pstate->parser_current_rel = heap_openr(VarnoGetRelname(pstate,x));
832-
if (pstate->parser_current_rel == NULL)
834+
pstate->p_current_rel = heap_openr(VarnoGetRelname(pstate,x));
835+
if (pstate->p_current_rel == NULL)
833836
elog(WARN,"invalid relation name");
834837
}
835838

@@ -1036,7 +1039,7 @@ makeTargetList(ParseState *pstate, List *cols, List *exprs)
10361039
exprs = lnext(exprs);
10371040
}
10381041
} else {
1039-
Relation insertRel = pstate->parser_current_rel;
1042+
Relation insertRel = pstate->p_current_rel;
10401043
int numcol;
10411044
int i;
10421045
AttributeTupleForm *attr = insertRel->rd_att->attrs;
@@ -1155,7 +1158,7 @@ transformTargetList(ParseState *pstate,
11551158
i++;
11561159
}
11571160
sprintf(str, "=%s", val);
1158-
rd = pstate->parser_current_rel;
1161+
rd = pstate->p_current_rel;
11591162
Assert(rd != NULL);
11601163
resdomno = varattno(rd, res->name);
11611164
ndims = att_attnelems(rd, resdomno);
@@ -1334,7 +1337,7 @@ make_targetlist_expr(ParseState *pstate,
13341337
* append, replace work only on one relation,
13351338
* so multiple occurence of same resdomno is bogus
13361339
*/
1337-
rd = pstate->parser_current_rel;
1340+
rd = pstate->p_current_rel;
13381341
Assert(rd != NULL);
13391342
resdomno = varattno(rd,name);
13401343
attrisset = varisset(rd,name);

src/include/parser/parse_state.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 1994, Regents of the University of California
66
*
7-
* $Id: parse_state.h,v 1.1 1996/08/28 07:23:56 scrappy Exp $
7+
* $Id: parse_state.h,v 1.2 1996/10/13 04:26:39 momjian Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -16,7 +16,7 @@
1616
typedef struct ParseState {
1717
int p_last_resno;
1818
List *p_target_resnos;
19-
Relation parser_current_rel;
19+
Relation p_parser_current_rel;
2020
List *p_rtable;
2121
int p_query_is_rule;
2222
int p_numAgg;

0 commit comments

Comments
 (0)