Skip to content
New issue

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

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

Already on GitHub? # to your account

[Answer Query Using Materialized Views] Support ORDER BY in origin query #358

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

avamingli
Copy link
Contributor

ORDER BY clause could refer result column, result number, table column or expression has table columns.
All that could be processed by aqumv_process_targetlist()
if ORDER BY clause could be computed from materialized views.

begin;
create table aqumv_t5(c1 int, c2 int, c3 int) distributed by (c1);
insert into aqumv_t5 select i, i+1, i+2 from generate_series(1, 100) i;
insert into aqumv_t5 values (91, NULL, 95);
analyze aqumv_t5;
create incremental materialized view aqumv_mvt5_0 as
  select c1 as mc1, c2 as mc2, c3 as mc3
  from aqumv_t5 where c1 > 90;

set local enable_answer_query_using_materialized_views = on;
explain(costs off, verbose)
select c1, c3 from aqumv_t5 where c1 > 90 order by c2 - c1 - 1 asc;
                                    QUERY PLAN                                    
----------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   Output: mc1, mc3, (((mc2 - mc1) - 1))
   Merge Key: (((mc2 - mc1) - 1))
   ->  Sort
         Output: mc1, mc3, (((mc2 - mc1) - 1))
         Sort Key: (((aqumv_mvt5_0.mc2 - aqumv_mvt5_0.mc1) - 1))
         ->  Seq Scan on public.aqumv_mvt5_0
               Output: mc1, mc3, ((mc2 - mc1) - 1)
 Settings: enable_answer_query_using_materialized_views = 'on', optimizer = 'off'
 Optimizer: Postgres query optimizer
(10 rows)

See more examples in test cases.

Authored-by: Zhang Mingli avamingli@gmail.com

fix #ISSUE_Number


Change logs

Describe your change clearly, including what problem is being solved or what feature is being added.

If it has some breaking backward or forward compatibility, please clary.

Why are the changes needed?

Describe why the changes are necessary.

Does this PR introduce any user-facing change?

If yes, please clarify the previous behavior and the change this PR proposes.

How was this patch tested?

Please detail how the changes were tested, including manual tests and any relevant unit or integration tests.

Contributor's Checklist

Here are some reminders and checklists before/when submitting your pull request, please check them:

  • Make sure your Pull Request has a clear title and commit message. You can take git-commit template as a reference.
  • Sign the Contributor License Agreement as prompted for your first-time contribution(One-time setup).
  • Learn the coding contribution guide, including our code conventions, workflow and more.
  • List your communication in the GitHub Issues or Discussions (if has or needed).
  • Document changes.
  • Add tests for the change
  • Pass make installcheck
  • Pass make -C src/test installcheck-cbdb-parallel
  • Feel free to request cloudberrydb/dev team for review and approval when your PR is ready🥳

ORDER BY clause could refer result column, result number,
table column or expression has table columns.
All that could be processed by aqumv_process_targetlist()
if ORDER BY clause could be computed from materialized views.

Authored-by: Zhang Mingli avamingli@gmail.com
@avamingli avamingli self-assigned this Jan 8, 2024
@avamingli avamingli changed the title [AQUMV] Support ORDER BY in origin query. [Answer Query Using Materialized Views] Support ORDER BY in origin query. Jan 8, 2024
@avamingli avamingli changed the title [Answer Query Using Materialized Views] Support ORDER BY in origin query. [Answer Query Using Materialized Views] Support ORDER BY in origin query Jan 8, 2024
Copy link
Member

@yjhjstz yjhjstz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@avamingli
Copy link
Contributor Author

Pushed, thanks for review.

@avamingli avamingli merged commit d70f664 into apache:main Jan 10, 2024
8 checks passed
@avamingli avamingli deleted the order_by_aqumv branch January 10, 2024 03:40
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants