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 <jh...@apache.org> 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 <ruipso...@gmail.com> 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)
>
>

Reply via email to