diff --git a/doc/src/sgml/parallel.sgml b/doc/src/sgml/parallel.sgml
index cec1329e259..330c06b608f 100644
--- a/doc/src/sgml/parallel.sgml
+++ b/doc/src/sgml/parallel.sgml
@@ -144,11 +144,27 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
The query writes any data or locks any database rows. If a query
contains a data-modifying operation either at the top level or within
a CTE, no parallel plans for that query will be generated. As an
- exception, the commands CREATE TABLE ... AS, SELECT
- INTO, and CREATE MATERIALIZED VIEW which create a new
- table and populate it can use a parallel plan. Another exception is the command
- INSERT INTO ... SELECT ... which can use a parallel plan for
- the underlying SELECT part of the query.
+ exception, the following commands which create a new table and populate
+ it can use a parallel plan for the underlying SELECT
+ part of the query:
+
+
+
+ CREATE TABLE ... AS
+
+
+ SELECT INTO
+
+
+ INSERT INTO ... SELECT
+
+
+ CREATE MATERIALIZED VIEW
+
+
+ REFRESH MATERIALIZED VIEW
+
+
diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c
index c5c25ce11d5..172ec6e9828 100644
--- a/src/backend/commands/matview.c
+++ b/src/backend/commands/matview.c
@@ -402,7 +402,7 @@ refresh_matview_datafill(DestReceiver *dest, Query *query,
CHECK_FOR_INTERRUPTS();
/* Plan the query which will generate data for the refresh. */
- plan = pg_plan_query(query, queryString, 0, NULL);
+ plan = pg_plan_query(query, queryString, CURSOR_OPT_PARALLEL_OK, NULL);
/*
* Use a snapshot with an updated command ID to ensure this query sees
diff --git a/src/test/regress/expected/write_parallel.out b/src/test/regress/expected/write_parallel.out
index 77705f9a709..dc0c4ba587e 100644
--- a/src/test/regress/expected/write_parallel.out
+++ b/src/test/regress/expected/write_parallel.out
@@ -58,6 +58,9 @@ explain (costs off) create materialized view parallel_mat_view as
create materialized view parallel_mat_view as
select length(stringu1) from tenk1 group by length(stringu1);
+create unique index on parallel_mat_view(length);
+refresh materialized view parallel_mat_view;
+refresh materialized view concurrently parallel_mat_view;
drop materialized view parallel_mat_view;
prepare prep_stmt as select length(stringu1) from tenk1 group by length(stringu1);
explain (costs off) create table parallel_write as execute prep_stmt;
diff --git a/src/test/regress/sql/write_parallel.sql b/src/test/regress/sql/write_parallel.sql
index a5d63112c96..ae660dc2265 100644
--- a/src/test/regress/sql/write_parallel.sql
+++ b/src/test/regress/sql/write_parallel.sql
@@ -30,6 +30,9 @@ explain (costs off) create materialized view parallel_mat_view as
select length(stringu1) from tenk1 group by length(stringu1);
create materialized view parallel_mat_view as
select length(stringu1) from tenk1 group by length(stringu1);
+create unique index on parallel_mat_view(length);
+refresh materialized view parallel_mat_view;
+refresh materialized view concurrently parallel_mat_view;
drop materialized view parallel_mat_view;
prepare prep_stmt as select length(stringu1) from tenk1 group by length(stringu1);