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

Incremental view maintenance #280

Merged
merged 8 commits into from
Dec 1, 2023
Merged

Conversation

yjhjstz
Copy link
Member

@yjhjstz yjhjstz commented Nov 2, 2023

closes: #ISSUE_Number


Change logs

background:

Why are the changes needed?

Base on patch v28 from Postgres, here is design code: https://hashdata.feishu.cn/docx/RdS6dND7xotUhLxQi1UctzCVnih

The challenge lies in how to implement IVM in a distributed environment.

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?

Add extra test to regress:

  • ivm.sql
  • incremental_matview.sql

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 @cloudberrydb/dev team for review and approval when your PR is ready🥳

@CLAassistant
Copy link

CLAassistant commented Nov 2, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ yjhjstz
❌ yugo-n
You have signed the CLA already but the status is still pending? Let us recheck it.

@yjhjstz yjhjstz changed the title Incremental view maintenance [Draft]Incremental view maintenance Nov 2, 2023
@yjhjstz yjhjstz force-pushed the incremental_view_maintenance branch 2 times, most recently from 4a1c99a to 61bfb63 Compare November 2, 2023 07:14
@yjhjstz yjhjstz self-assigned this Nov 2, 2023
@yjhjstz yjhjstz force-pushed the incremental_view_maintenance branch from 7a06694 to 7c345d8 Compare November 3, 2023 03:54
@yjhjstz yjhjstz force-pushed the incremental_view_maintenance branch from 7c345d8 to c34f3e7 Compare November 3, 2023 06:51
@yjhjstz yjhjstz changed the title [Draft]Incremental view maintenance Incremental view maintenance Nov 3, 2023
@yjhjstz yjhjstz force-pushed the incremental_view_maintenance branch 4 times, most recently from c601e29 to e393fbc Compare November 8, 2023 10:30
@yjhjstz yjhjstz force-pushed the incremental_view_maintenance branch from e393fbc to 21474b1 Compare November 22, 2023 11:23
@avamingli
Copy link
Contributor

Hi, I want to see what we changed besides pg's patch, but it's hard to tell as there are separate commits of our own codes.
Could we squash them to one for easy to review? And we will do it finally when merging the pr.
And some commits should be kept as pg's, ex: [Add documentations about Incremental View Maintenance]

@yjhjstz yjhjstz force-pushed the incremental_view_maintenance branch from 21474b1 to baed6b4 Compare November 27, 2023 06:21
@yjhjstz
Copy link
Member Author

yjhjstz commented Nov 27, 2023

Hi, I want to see what we changed besides pg's patch, but it's hard to tell as there are separate commits of our own codes.
Could we squash them to one for easy to review? And we will do it finally when merging the pr.
And some commits should be kept as pg's, ex: [Add documentations about Incremental View Maintenance]

image

tried to arrange [Add documentations about Incremental View Maintenance].

@yjhjstz yjhjstz force-pushed the incremental_view_maintenance branch from baed6b4 to 70e19ab Compare November 29, 2023 04:13
Copy link
Contributor

@avamingli avamingli left a comment

Choose a reason for hiding this comment

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

LGTM.

Allow to create Incrementally Maintainable Materialized View (IMMV)
by using INCREMENTAL option in CREATE MATERIALIZED VIEW command
as follow:

     CREATE [INCREMANTAL] MATERIALIZED VIEW xxxxx AS SELECT ....;
If this boolean column is true, a relations is Incrementally Maintainable
Materialized View (IMMV). This is set when IMMV is created.
Originally, tuplestores of AFTER trigger's transition tables were
freed for each query depth. For our IVM implementation, we would like
to prolong life of the tuplestores because we have to preserve them
for a whole query assuming that some base tables might be changed
in some trigger functions.
Add tab completion and meta-command output for IVM.
In this implementation, AFTER triggers are used to collect
tuplestores containing transition table contents. When multiple tables
are changed, multiple AFTER triggers are invoked, then the final AFTER
trigger performs actual update of the matview. In addition, BEFORE
triggers are also used to handle global information for view
maintenance.

To calculate view deltas, we need both pre-state and post-state of base
tables. Post-update states are available in AFTER trigger, and pre-update
states can be calculated by removing inserted tuples and appending deleted
tuples. Insterted tuples are filtered using the snapshot taken before
table modiication, and deleted tuples are contained in the old transition
table.

Incrementally Maintainable Materialized Views (IMMV) can contain
duplicated tuples.

This patch also allows self-join, simultaneous updates of more than
one base table, and multiple updates of the same base table.
Details steps:
Step1: export snapshot, trigger data suppose is dR.
Step2: calculation delta V, dV = dR ⋈ S
Step3: apply delta V, V_new = dV U V
Step4: dispatch cleanup

Ivm feature that allows materialized views
to be updated automatically and incrementally just after a underlying
table is modified.

You can create an incremental maintainable materialized view (IMMV)
by using CREATE INCREMENTAL MATERIALIZED VIEW command.

The followings are designed to support in view definition queries:
- SELECT ... FROM ... WHERE ..., joins (inner joins, self-joins)
- some built-in aggregate functions (count, sum, avg)
- GROUP BY clause
- DISTINCT clause

Restriction:
The following are not supported in a view definition:
- Outer joins
- Aggregates other than above, window functions, HAVING
- Sub-queries, CTEs
- Set operations (UNION, INTERSECT, EXCEPT)
- DISTINCT ON, ORDER BY, LIMIT, OFFSET
@yjhjstz yjhjstz force-pushed the incremental_view_maintenance branch from 70e19ab to 572ab43 Compare November 30, 2023 09:12
Copy link
Contributor

@my-ship-it my-ship-it left a comment

Choose a reason for hiding this comment

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

LGTM

@my-ship-it my-ship-it merged commit 2bf926f into main Dec 1, 2023
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.

5 participants