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

Commitf0f18c7

Browse files
committed
Repair bug that allowed RevalidateCachedPlan to attempt to rebuild a cached
plan before the effects of DDL executed in an immediately prior SPI operationhad been absorbed. Per report from Chris Wood.This patch has an unpleasant side effect of causing the number ofCommandCounterIncrement()s done by a typical plpgsql function toapproximately double. Amelioration of the consequences of thatwill be undertaken in a separate patch.
1 parent7c43106 commitf0f18c7

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

‎src/backend/executor/spi.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.184 2007/11/15 21:14:35 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.185 2007/11/30 18:38:34 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1374,14 +1374,6 @@ _SPI_prepare_plan(const char *src, SPIPlanPtr plan)
13741374
intnargs=plan->nargs;
13751375
intcursor_options=plan->cursor_options;
13761376

1377-
/*
1378-
* Increment CommandCounter to see changes made by now. We must do this
1379-
* to be sure of seeing any schema changes made by a just-preceding SPI
1380-
* command. (But we don't bother advancing the snapshot, since the
1381-
* planner generally operates under SnapshotNow rules anyway.)
1382-
*/
1383-
CommandCounterIncrement();
1384-
13851377
/*
13861378
* Setup error traceback support for ereport()
13871379
*/
@@ -1662,6 +1654,14 @@ _SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls,
16621654
if (cplan)
16631655
ReleaseCachedPlan(cplan, true);
16641656
cplan=NULL;
1657+
1658+
/*
1659+
* If not read-only mode, advance the command counter after the
1660+
* last command. This ensures that its effects are visible, in
1661+
* case it was DDL that would affect the next CachedPlanSource.
1662+
*/
1663+
if (!read_only)
1664+
CommandCounterIncrement();
16651665
}
16661666

16671667
fail:

‎src/test/regress/expected/plancache.out

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ drop schema s1 cascade;
202202
NOTICE: drop cascades to table s1.abc
203203
drop schema s2 cascade;
204204
NOTICE: drop cascades to table abc
205+
reset search_path;
205206
-- Check that invalidation deals with regclass constants
206207
create temp sequence seq;
207208
prepare p2 as select nextval('seq');
@@ -219,3 +220,42 @@ execute p2;
219220
1
220221
(1 row)
221222

223+
-- Check DDL via SPI, immediately followed by SPI plan re-use
224+
-- (bug in original coding)
225+
create function cachebug() returns void as $$
226+
declare r int;
227+
begin
228+
drop table if exists temptable cascade;
229+
create temp table temptable as select * from generate_series(1,3) as f1;
230+
create temp view vv as select * from temptable;
231+
for r in select * from vv loop
232+
raise notice '%', r;
233+
end loop;
234+
end$$ language plpgsql;
235+
select cachebug();
236+
NOTICE: table "temptable" does not exist, skipping
237+
CONTEXT: SQL statement "drop table if exists temptable cascade"
238+
PL/pgSQL function "cachebug" line 3 at SQL statement
239+
NOTICE: 1
240+
NOTICE: 2
241+
NOTICE: 3
242+
cachebug
243+
----------
244+
245+
(1 row)
246+
247+
select cachebug();
248+
NOTICE: drop cascades to rule _RETURN on view vv
249+
CONTEXT: SQL statement "drop table if exists temptable cascade"
250+
PL/pgSQL function "cachebug" line 3 at SQL statement
251+
NOTICE: drop cascades to view vv
252+
CONTEXT: SQL statement "drop table if exists temptable cascade"
253+
PL/pgSQL function "cachebug" line 3 at SQL statement
254+
NOTICE: 1
255+
NOTICE: 2
256+
NOTICE: 3
257+
cachebug
258+
----------
259+
260+
(1 row)
261+

‎src/test/regress/sql/plancache.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ execute p1;
124124
dropschema s1 cascade;
125125
dropschema s2 cascade;
126126

127+
reset search_path;
128+
127129
-- Check that invalidation deals with regclass constants
128130

129131
create temp sequence seq;
@@ -137,3 +139,20 @@ drop sequence seq;
137139
create temp sequence seq;
138140

139141
execute p2;
142+
143+
-- Check DDL via SPI, immediately followed by SPI plan re-use
144+
-- (bug in original coding)
145+
146+
createfunctioncachebug() returns voidas $$
147+
declare rint;
148+
begin
149+
droptable if exists temptable cascade;
150+
create temp table temptableasselect*from generate_series(1,3)as f1;
151+
create temp view vvasselect*from temptable;
152+
for rinselect*from vv loop
153+
raise notice'%', r;
154+
end loop;
155+
end$$ language plpgsql;
156+
157+
select cachebug();
158+
select cachebug();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp