Hi Liya, This approach may work. However, as Julian mentioned earlier, the main question is why do you need these plans? If you collect the plans in the way you described, you may get several best plans which are only marginally different from each other, which are of little use.
For example, there is one real scenario where several plans might be needed - join planning. Several Calcite-based engines perform join planning as a separate phase because otherwise planning might take too much time. And this phase produces only one RelNode. What we would like to have here instead, is a set of best plans for different join orders, e.g. "A join B" and "B join A". But in the proposed algorithm, you may easily get two flavors of "A join B", which is not what we need. So perhaps what we need instead, is the ability to switch off certain RelNode-s or even RelSubset-s from the plan during the best-exp calculation? Regards, Vladimir. чт, 19 мар. 2020 г. в 05:03, Fan Liya <[email protected]>: > IMO, there is no easy way, and the algorithm should depends on definition > of 'alternative plans'. > > In general, the algorithm can proceed like this: > 1. we use the volcano algoirthm to find the best plan > 2. we make the self cost of some node to be infinite, and then apply the > volcano algorithm again to find the second best plan > 3. we repeat the above steps, until we find the k best plans. > > Best, > Liya Fan > > On Thu, Mar 19, 2020 at 3:20 AM Julian Hyde <[email protected]> wrote: > > > There’s no easy way. You could modify ‘buildCheapestPlan()’ to build all > > plans below a cost limit. (You’d have to carefully choose a cost limit > only > > a little above the optimal cost, otherwise you’ll get huge numbers of > > plans.) > > > > I fear that you’ll get plans that are different in only trivial or minor > > respects (e.g. ordering of items in a Project) whereas you probably want > > plans with significant differences (e.g. different join orders). > > > > Julian > > > > > On Mar 18, 2020, at 12:01 PM, Rui Souto <[email protected]> wrote: > > > > > > Hi there! > > > > > > Just recently started to learn about Apache Calcite. What's the best > way > > to > > > get a list of the k-cheapest alternative plans generated by the > optimizer > > > for a given query? (being k an arbitrary number) > > > > >
