phisiart / peloton

Always keep master branch synced with cmudb/master!
http://pelotondb.org
Apache License 2.0
1 stars 1 forks source link

The lifecycle of a planner::AbstractPlan #5

Open phisiart opened 7 years ago

phisiart commented 7 years ago

We are the LLVM team. This issue is blocking us from integrating plan caching into the system (our caching system already passes standalone tests).

Cache system

Our cache is a singleton object which boils down to a:

std::map<std::unique_ptr<planner::AbstractPlan>, // physical plan
         std::unique_ptr<codegen::Query>>        // compiled query

(We've implemented a plan comparator.)

The use of std::unique_ptr's is reasonable - the cache owns the cached plan and compiled query. We could also use std::shared_ptr here. The key is that a plan in the cache should not be freed.

When the user wants to access a plan in the cache, we would provide a const planner::AbstractPlan * (ownership borrowing - the cache still owns the plan).

When a new planner::AbstractPlan comes, we check whether a structurally equivalent plan is already in the cache. If there isn't, then we store the plan in the cache.

Now we have to carefully manage the lifecycle of a plan. There are basically 2 ways we come up with:

We believe that the first and second methods are better.

There are also technical issues with regards to the second approach: currently the Copy() method for a lot of kinds of plans are incorrectly implemented.

Ownership Problem

We have currently adopted the first approach (moving to the second is also easy), and the cache is passing standalone test cases. However, the current peloton system is blocking us from integrating the cache. Here is why.

Conclusion

Therefore, the current peloton manages the lifecycle of physical plans in a way that prevents us from integrating the cache.

We have come up with several possible approaches.