Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AQUMV] Extend AQUMV to support materialized views on partitioned tables. #965

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

avamingli
Copy link
Contributor

This commit introduces support for partitioned tables in the AQUMV (Answer Query Using Materialized Views) feature. Users can now create materialized views based on partitioned tables, which may include multiple levels of child partitions. When a query is executed on the root partition table, AQUMV will automatically rewrite the query to utilize the materialized view, thereby improving query performance by avoiding direct access to the partitioned tables.

Example:
We have a partition table par with children tables of multiple level.

select * from pg_partition_tree('par');
        relid        | parentrelid | isleaf | level
---------------------+-------------+--------+-------
 par                 |             | f      |     0
 par_1_prt_1         | par         | f      |     1
 par_1_prt_2         | par         | f      |     1
 par_1_prt_1_2_prt_1 | par_1_prt_1 | t      |     2
 par_1_prt_1_2_prt_2 | par_1_prt_1 | t      |     2
 par_1_prt_2_2_prt_1 | par_1_prt_2 | t      |     2
 par_1_prt_2_2_prt_2 | par_1_prt_2 | t      |     2

create materialized view mv_par as select count(*) as column_1 from par;

When execute:

  select count(*) from par;

AQUMV will rewrite the SQL to:

  select column_1 from mv_par;

Answer the results from materialized view mv_par instead of querying on par and its partitions.

explain(costs off, verbose) select count(*) from par;
                          QUERY PLAN
---------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   Output: column_1
   ->  Seq Scan on public.mv_par
         Output: column_1
 Settings: enable_answer_query_using_materialized_views = 'on'
 Optimizer: Postgres query optimizer
(6 rows)

This enhancement significantly boosts query performance in OLAP environments where partitioned tables are extensively used, allowing users to fully leverage the benefits of materialized views.

Authored-by: Zhang Mingli [email protected]

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


…les.

This commit introduces support for partitioned tables in the AQUMV
(Answer Query Using Materialized Views) feature. Users can now create
materialized views based on partitioned tables, which may include
multiple levels of child partitions. When a query is executed on the
root partition table, AQUMV will automatically rewrite the query to
utilize the materialized view, thereby improving query performance by
avoiding direct access to the partitioned tables.

Example:
We have a partition table par with children tables of multiple level.

select * from pg_partition_tree('par');
        relid        | parentrelid | isleaf | level
---------------------+-------------+--------+-------
 par                 |             | f      |     0
 par_1_prt_1         | par         | f      |     1
 par_1_prt_2         | par         | f      |     1
 par_1_prt_1_2_prt_1 | par_1_prt_1 | t      |     2
 par_1_prt_1_2_prt_2 | par_1_prt_1 | t      |     2
 par_1_prt_2_2_prt_1 | par_1_prt_2 | t      |     2
 par_1_prt_2_2_prt_2 | par_1_prt_2 | t      |     2

create materialized view mv_par as select count(*) as column_1 from par;

When execute:
  select count(*) from par;

AQUMV will rewrite the SQL to:
  select column_1 from mv_par;

Answer the results from materialized view mv_par instead of querying on
par and its partitions.

explain(costs off, verbose) select count(*) from par;
                          QUERY PLAN
---------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   Output: column_1
   ->  Seq Scan on public.mv_par
         Output: column_1
 Settings: enable_answer_query_using_materialized_views = 'on'
 Optimizer: Postgres query optimizer
(6 rows)

This enhancement significantly boosts query performance in OLAP
environments where partitioned tables are extensively used, allowing
users to fully leverage the benefits of materialized views.

Authored-by: Zhang Mingli [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant