Re: Ideas of "printing out" the alternative paths

Lists: pgsql-hackers
From: Zhan Li <zhanli89(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Ideas of "printing out" the alternative paths
Date: 2013-11-14 16:35:10
Message-ID: CANp-BfaRAAH2f9a55WqSanH4TrBeErFP_G3KaRwC-jLU-KX38A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

When searching all the possible paths of executing a query, the optimizer
finds and saves the cheapest paths for the top level rel. I'd like to check
out all the paths the optimizer has ever considered, which I believe, are
stored in the pathlist of the top level rel. But I do not have an idea of
how to "print out" these paths to see them visually. Does anyone have an
idea how I can achieve this?

Thanks,
Zhan


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Zhan Li <zhanli89(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Ideas of "printing out" the alternative paths
Date: 2013-11-14 17:01:52
Message-ID: 15988.1384448512@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Zhan Li <zhanli89(at)gmail(dot)com> writes:
> When searching all the possible paths of executing a query, the optimizer
> finds and saves the cheapest paths for the top level rel. I'd like to check
> out all the paths the optimizer has ever considered, which I believe, are
> stored in the pathlist of the top level rel.

No, most of them have been thrown away long before that. See add_path.
Also realize that in a large join problem, a lot of potential plans never
get explicitly considered, because the input paths get pruned before we
get to considering the join rel at all. (If this were not so, planning
would take too long.)

People have experimented with having add_path print something about each
path that's fed to it, but the output tends to be voluminous and not all
that useful.

regards, tom lane


From: Zhan Li <zhanli89(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Ideas of "printing out" the alternative paths
Date: 2013-11-14 17:13:19
Message-ID: CANp-Bfa=L-JrR1oZLZkjbW61Pj8OoPN_SfU8DgbNAwzZOpFCFg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thank you for your reply Tom. Then a) what are exactly stored in the
pathlist of top level rel? Paths worth considering? b) I have been
struggling to come up with a way to print the Path struct. If I can print a
path the way like "A hash join (B nested loop join C)", that would be
great. You mentioned people have printed "something" about each path, can
you please give me a hint of what's that and how to achieve that?

On Thu, Nov 14, 2013 at 12:01 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Zhan Li <zhanli89(at)gmail(dot)com> writes:
> > When searching all the possible paths of executing a query, the optimizer
> > finds and saves the cheapest paths for the top level rel. I'd like to
> check
> > out all the paths the optimizer has ever considered, which I believe, are
> > stored in the pathlist of the top level rel.
>
> No, most of them have been thrown away long before that. See add_path.
> Also realize that in a large join problem, a lot of potential plans never
> get explicitly considered, because the input paths get pruned before we
> get to considering the join rel at all. (If this were not so, planning
> would take too long.)
>
> People have experimented with having add_path print something about each
> path that's fed to it, but the output tends to be voluminous and not all
> that useful.
>
> regards, tom lane
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Zhan Li <zhanli89(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Ideas of "printing out" the alternative paths
Date: 2013-11-14 19:27:15
Message-ID: 19982.1384457235@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Zhan Li <zhanli89(at)gmail(dot)com> writes:
> Thank you for your reply Tom. Then a) what are exactly stored in the
> pathlist of top level rel? Paths worth considering? b) I have been
> struggling to come up with a way to print the Path struct. If I can print a
> path the way like "A hash join (B nested loop join C)", that would be
> great. You mentioned people have printed "something" about each path, can
> you please give me a hint of what's that and how to achieve that?

I don't think anyone's tried anything much smarter than
src/backend/nodes/outfuncs.c, or there's some more limited stuff at the
bottom of src/backend/optimizer/path/allpaths.c. Reassembling into
something more human-readable than that would probably take some work.

regards, tom lane