cmu-db / optd

CMU-DB's Cascades optimizer framework
https://cmu-db.github.io/optd/
MIT License
349 stars 19 forks source link

Fix: Heuristic wrapper fix #150

Closed AveryQi115 closed 5 months ago

AveryQi115 commented 5 months ago

The flow of the optimization is:

OptimizeGroup(root) --> exploreGroup(children)(can only apply logical->logical) --> after exploration, there are physical exprs in the root --> optimizeInput --> optimizeGroup(children)(can apply logical to physical)

While marking the rules as deadend, we cannot mark the impl rules as fired as we might need them to start the optimizeGroup task of the children node after merging of groups even if we know the expr can never be the winner.

AveryQi115 commented 5 months ago

After some debugging, I found merge group is ok as long as the two corresponding groups are still having optimizeGroup task after the merge. However, optimizeGroup for children nodes are called by optimizeInput, so the ancestors of the children node cannot be pruned. There might be some problems for merge group in the future if we introduce pruning. @skyzh

If the above example is too abstract, you can try Select a from (select a from (select a from t)) with MergeProjection rules registered as heuristics to see the flow of tasks.

AveryQi115 commented 5 months ago

LGTM - I know you're waiting for Chi though

It's ok. Let's merge it first.