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

Commit 555b929

Browse files
committed
Avoid Assert failure when processing empty statement in aborted xact.
exec_parse_message() wants to create a cached plan in all cases, including for empty input. The empty-input path does not have a test for being in an aborted transaction, making it possible that plancache.c will fail due to trying to do database lookups even though there's no real work to do. One solution would be to throw an aborted-transaction error in this path too, but it's not entirely clear whether the lack of such an error was intentional or whether some clients might be relying on non-error behavior. Instead, let's hack plancache.c so that it treats empty statements with the same logic it already had for transaction control commands, ensuring that it can soldier through even in an already-aborted transaction. Per bug #17983 from Alexander Lakhin. Back-patch to all supported branches. Discussion: https://postgr.es/m/17983-da4569fcb878672e@postgresql.org
1 parent 3d9fd1a commit 555b929

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/backend/utils/cache/plancache.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@
7878
/*
7979
* We must skip "overhead" operations that involve database access when the
8080
* cached plan's subject statement is a transaction control command.
81+
* For the convenience of postgres.c, treat empty statements as control
82+
* commands too.
8183
*/
8284
#define IsTransactionStmtPlan(plansource) \
83-
((plansource)->raw_parse_tree && \
85+
((plansource)->raw_parse_tree == NULL || \
8486
IsA((plansource)->raw_parse_tree->stmt, TransactionStmt))
8587

8688
/*

src/test/regress/expected/psql.out

+11
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,17 @@ SELECT 3 AS x, 'Hello', 4 AS y, true AS "dirty\name" \gdesc \g
268268
3 | Hello | 4 | t
269269
(1 row)
270270

271+
-- test for server bug #17983 with empty statement in aborted transaction
272+
set search_path = default;
273+
begin;
274+
bogus;
275+
ERROR: syntax error at or near "bogus"
276+
LINE 1: bogus;
277+
^
278+
;
279+
\gdesc
280+
The command has no result, or the result has no columns.
281+
rollback;
271282
-- \gexec
272283
create temporary table gexec_test(a int, b text, c date, d float);
273284
select format('create index on gexec_test(%I)', attname)

src/test/regress/sql/psql.sql

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ SELECT 1 AS x, 'Hello', 2 AS y, true AS "dirty\name"
133133
-- all on one line
134134
SELECT 3 AS x, 'Hello', 4 AS y, true AS "dirty\name" \gdesc \g
135135

136+
-- test for server bug #17983 with empty statement in aborted transaction
137+
set search_path = default;
138+
begin;
139+
bogus;
140+
;
141+
\gdesc
142+
rollback;
143+
136144
-- \gexec
137145

138146
create temporary table gexec_test(a int, b text, c date, d float);

0 commit comments

Comments
 (0)