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

[RFC] Plan cache #2619

Closed
czpmango opened this issue Aug 10, 2021 · 7 comments
Closed

[RFC] Plan cache #2619

czpmango opened this issue Aug 10, 2021 · 7 comments
Labels
type/feature req Type: feature request

Comments

@czpmango
Copy link
Contributor

czpmango commented Aug 10, 2021

Summary

Cache historical execution plans to avoid replanning for the same/similar query.

Motivation

Avoid replanning to reduce the overhead of the planner and optimizer.

Usage explanation

Invisible to the user.

Design explanation

  • two-level cache
    • string cache
      Hash the query statement.
    • AST cache (match (v{age:18}) <=> match (v) where v.age=18)
      Hash the normalized AST.
  • configs
    • cache size
    • replan_interval : validity period of cached plan
    • statistics_divergence_threshold : tolerance threshold for statistical changes
  • LFU
    Cache elimination strategy.

Note: schema changes(such as index/constraint creation/removal) will flush the entire query plan cache.

Rationale and alternatives

Drawbacks

This may be a trade-off in the CBO scenario, which mean It may cause performance degradation of the execution plan.

Prior art

Unresolved questions

  • can't apply to CBO scenarios for nebula
  • ...

Future possibilities

  • supports CBO scenarios
  • ...
@Shylock-Hg
Copy link
Contributor

Do you consider the explicit usage like the prepare statement in sql, e.g. https://www.postgresql.org/docs/9.4/sql-prepare.html ?

@Shylock-Hg
Copy link
Contributor

I think you could cache the generated plan before CBO stage, and do CBO again for plan which instantiated from cache.

@CPWstatic CPWstatic transferred this issue from vesoft-inc/nebula-graph Aug 27, 2021
@CPWstatic CPWstatic added the type/feature req Type: feature request label Aug 28, 2021
@czpmango
Copy link
Contributor Author

cache the generated plan before CBO stage, and

Setting statistics_divergence_threshold to 0 has the same effect.

@czpmango
Copy link
Contributor Author

Do you consider the explicit usage like the prepare statement in sql, e.g. https://www.postgresql.org/docs/9.4/sql-prepare.html ?

Just the same thing. Implicit usage is more user-friendly, I think.

@Shylock-Hg
Copy link
Contributor

Shylock-Hg commented Aug 30, 2021

Do you consider the explicit usage like the prepare statement in sql, e.g. https://www.postgresql.org/docs/9.4/sql-prepare.html ?

Just the same thing. Implicit usage is more user-friendly, I think.

Yes, I think could provide both. The implicit mode is enable by flag, the explicit is enable by query directly.

@czpmango
Copy link
Contributor Author

czpmango commented Aug 30, 2021

Do you consider the explicit usage like the prepare statement in sql, e.g. https://www.postgresql.org/docs/9.4/sql-prepare.html ?

Just the same thing. Implicit usage is more user-friendly, I think.

Yes, I think could provide both. The implicit mode is enable by flag, the explicit is enable by query directly.

It can be considered, but will increase the complexity of the syntax.
This RFC mainly refers to the implementation of neo4j.

@czpmango
Copy link
Contributor Author

czpmango commented Jan 9, 2023

Out of date.

@czpmango czpmango closed this as completed Jan 9, 2023
yixinglu pushed a commit to yixinglu/nebula that referenced this issue Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature req Type: feature request
Projects
None yet
Development

No branches or pull requests

3 participants