1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Enable parallelism in REFRESH MATERIALIZED VIEW.

Pass CURSOR_OPT_PARALLEL_OK to pg_plan_query() so that parallel plans
are considered when running the underlying SELECT query.  This wasn't
done in commit e9baa5e9, which did this for CREATE MATERIALIZED VIEW,
because it wasn't yet known to be safe.

Since REFRESH always inserts into a freshly created table before later
merging or swapping the data into place with separate operations, we can
enable such plans here too.

Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Hou, Zhijie <houzj.fnst@cn.fujitsu.com>
Reviewed-by: Luc Vlaming <luc@swarm64.com>
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/CALj2ACXg-4hNKJC6nFnepRHYT4t5jJVstYvri%2BtKQHy7ydcr8A%40mail.gmail.com
This commit is contained in:
Thomas Munro
2021-03-17 13:43:08 +13:00
parent fbe4cb3bd4
commit 9e7ccd9ef6
4 changed files with 28 additions and 6 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);