Bug in query rewriter - hasModifyingCTE not getting set
Greg Nancarrow <gregn4422@gmail.com>
From: Greg Nancarrow <gregn4422@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2021-02-06T22:29:15Z
Lists: pgsql-hackers
Attachments
- v1-0001-Fix-bug-in-the-query-rewriter-hasModifyingCTE-not-set.patch (application/octet-stream) patch v1-0001
Hi Hackers,
I found a bug in the query rewriter. If a query that has a modifying
CTE is re-written, the hasModifyingCTE flag is not getting set in the
re-written query. This bug can result in the query being allowed to
execute in parallel-mode, which results in an error.
I originally found the problem using INSERT (which doesn't actually
affect the current Postgres code, as it doesn't support INSERT in
parallel mode) but a colleague of mine (Hou, Zhijie) managed to
reproduce it using SELECT as well (see example below), and helped to
minimize the patch size.
I've attached the patch with the suggested fix (reviewed by Amit Langote).
The following reproduces the issue (adapted from a test case in the
"with" regression tests):
drop table if exists test_data1;
create table test_data1(a int, b int) ;
insert into test_data1 select generate_series(1,1000), generate_series(1,1000);
set force_parallel_mode=on;
CREATE TEMP TABLE bug6051 AS
select i from generate_series(1,3) as i;
SELECT * FROM bug6051;
CREATE RULE bug6051_ins AS ON INSERT TO bug6051 DO INSTEAD select a as
i from test_data1;
WITH t1 AS ( DELETE FROM bug6051 RETURNING * ) INSERT INTO bug6051
SELECT * FROM t1;
produces the error:
ERROR: cannot assign XIDs during a parallel operation
Regards,
Greg Nancarrow
Fujitsu Australia
Commits
-
Fix rewriter to set hasModifyingCTE correctly on rewritten queries.
- 362e2dcc4619 15.0 landed
- cbba6ba3a062 13.5 landed
- 9de082399cfe 10.19 landed
- 882b7e728835 11.14 landed
- 595ab8a5451b 9.6.24 landed
- 1fedbcc7ab26 12.9 landed
- 03d01d746b93 14.0 landed
-
Enable parallel SELECT for "INSERT INTO ... SELECT ...".
- 05c8482f7f69 14.0 landed
-
Revert "Propagate CTE property flags when copying a CTE list into a rule."
- f94924f01e48 11.11 landed
- d6759ac6a41e 10.16 landed
- d1d297985253 14.0 landed
- ac1df003f253 13.2 landed
- a64aacf152fc 9.5.25 landed
- 6f8e393a79e4 9.6.21 landed
- 46f297113598 12.6 landed
-
Propagate CTE property flags when copying a CTE list into a rule.
- ed2908963354 14.0 landed
- ce5f27fcae61 11.11 landed
- 739375174ae8 13.2 landed
- 56ff63cac94d 10.16 landed
- 4384eccb1549 9.5.25 landed
- 2a7664a79c16 12.6 landed
- 01e3fe3275af 9.6.21 landed