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

conditional materialized view refresh and create-replace for the view #87

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kraftaa
Copy link

@kraftaa kraftaa commented May 3, 2024

for issue: #88
hi I've started testing quary in the production and hitting dependencies errors: If I follow the logic of DROP/CREATE view I can't do it without CASCADE deleting all dependencies. The same with materialized views.

I suggest that for the view and materialized view there would be no DROP command and then changed creation commands:

  • view : CREATE OR REPLACE VIEW ...
  • materialized view: checking if the view exists first and based on that either REFRESH MATERIALIZED VIEW .. or CREATE MATERIALIZED VIEW ... In case of REFRESH there is no issue with dependent views.

thank you

@kraftaa kraftaa changed the title conditional materialized view refresh and create-replace for the view conditional materialized view refresh and create-replace for the view fix #88 May 3, 2024
@kraftaa kraftaa changed the title conditional materialized view refresh and create-replace for the view fix #88 Fix #88 conditional materialized view refresh and create-replace for the view May 3, 2024
@kraftaa kraftaa changed the title Fix #88 conditional materialized view refresh and create-replace for the view conditional materialized view refresh and create-replace for the view May 3, 2024
@benfdking
Copy link
Collaborator

benfdking commented May 5, 2024

The fundamental problem with this approach is that if you change the model between the runs, the behavior is vastly different from what you would expect, e.g., changing the model as expected.

We do have a system for this, though, which I think we can rely on our "cached views" system. It's mainly defined in this file: https://github.com/quarylabs/quary/blob/main/rust/core/src/automatic_branching.rs.

We currently use it for our development flow; suppose you have models A, B, and C that depend on each other as follows, and you are pushing them to production in a materialized way.

A --> B --> C

It essentially measures the diff between your local setup and what's in production and tries to use as much "production" as possible to rely on materialized models as much as possible. So if your local models change C to C', you can still rely on production A and B because those are identical.

At its core, it's a "diffing system" that I think we can use here as well, to both speed up builds by

  • running refresh if the model is materialized but the definition is the same
  • skipping create/replace steps for views that are identical.

I hope some of the above makes sense.

@kraftaa
Copy link
Author

kraftaa commented May 6, 2024

Ben, thank you, yes it makes total sense.

@benfdking
Copy link
Collaborator

#141 The beginning!

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.

None yet

2 participants