8000 Avoid Assert failure when processing empty statement in aborted xact. · postgres/postgres@a8be235 · GitHub
[go: up one dir, main page]

Skip to content

Commit a8be235

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 erro 8000 r 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 6973868 commit a8be235

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/backend/utils/cache/plancache.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@
7474
/*
7575
* We must skip "overhead" operations that involve database access when the
7676
* cached plan's subject statement is a transaction control command.
77+
* For the convenience of postgres.c, treat empty statements as control
78+
* commands too.
7779
*/
7880
#define IsTransactionStmtPlan(plansource) \
79-
((plansource)->raw_parse_tree && \
81+
((plansource)->raw_parse_tree == NULL || \
8082
IsA((plansource)->raw_parse_tree->stmt, TransactionStmt))
8183

8284
/*

src/test/regress/expected/psql.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ SELECT 3 AS x, 'Hello', 4 AS y, true AS "dirty\name" \gdesc \g
215215
3 | Hello | 4 | t
216216
(1 row)
217217

218+
-- test for server bug #17983 with empty statement in aborted transaction
219+
set search_path = default;
220+
begin;
221+
bogus;
222+
ERROR: syntax error at or near "bogus"
223+
LINE 1: bogus;
224+
^
225+
;
226+
\gdesc
227+
The command has no result, or the result has no columns.
228+
rollback;
218229
-- \gexec
219230
create temporary table gexec_test(a int, b text, c date, d float);
220231
select format('create index on gexec_test(%I)', attname)

src/test/regress/sql/psql.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ SELECT 1 AS x, 'Hello', 2 AS y, true AS "dirty\name"
112112
-- all on one line
113113
SELECT 3 AS x, 'Hello', 4 AS y, true AS "dirty\name" \gdesc \g
114114

115+
-- test for server bug #17983 with empty statement in aborted transaction
116+
set search_path = default;
117+
begin;
118+
bogus;
119+
;
120+
\gdesc
121+
rollback;
122+
115123
-- \gexec
116124

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

0 commit comments

Comments
 (0)
0