You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[AQUMV] Add cases of INSERT-SELECT queries using materialized views.
We already have the ability to use materialized views instead of
origin table in the SQL like:
INSERT INTO target table SELECT FROM origin table.
When valid materialized view candidates exist, the system will
automatically use them for the SELECT portion of the query,
eliminating the need to access and recompute data from the original
tables, providing significant performance benefits for queries
involving large datasets or frequent INSERT-SELECT operations by
leveraging pre-computed results from materialized views rather than
processing raw data each time.
Authored-by: Zhang Mingli <[email protected]>
Copy file name to clipboardExpand all lines: src/test/regress/expected/aqumv.out
+69Lines changed: 69 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3305,6 +3305,75 @@ select count(*) from par_1_prt_2;
3305
3305
Optimizer: Postgres query optimizer
3306
3306
(6 rows)
3307
3307
3308
+
abort;
3309
+
-- Test INSERT SELECT
3310
+
begin;
3311
+
create table t_insert(a int);
3312
+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table.
3313
+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
3314
+
create table t_select(a int);
3315
+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table.
3316
+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
3317
+
insert into t_select select i from generate_series(1, 1000) i;
3318
+
analyze t_insert;
3319
+
create materialized view mv_insert_select as
3320
+
select count(a) from t_select;
3321
+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'count' as the Apache Cloudberry data distribution key for this table.
3322
+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
3323
+
analyze mv_insert_select;
3324
+
set local enable_answer_query_using_materialized_views = off;
3325
+
explain(costs off, verbose) insert into t_insert select count(a) from t_select;
0 commit comments