Thread:

From
Walter Cai
Date:
Hi,

I (a graduate student) am currently trying to modify a postgres instance slightly to incorporate my modified cardinality estimates. In order to run these experiments I'm hoping to access the raw values for selections predicates from within the calc_joinrel_size_estimate method (in costsize.c). For example, if the restriction

WHERE name_attr = "example_str"

appears in the query, I'd like to get the "name_attr" and "example_str" values. If possible, I would very much appreciate the help.

Best, Walter

Re:

From
Gavin Flower
Date:
On 10/01/18 07:52, Walter Cai wrote:
> Hi,
>
> I (a graduate student) am currently trying to modify a postgres 
> instance slightly to incorporate my modified cardinality estimates. In 
> order to run these experiments I'm hoping to access the raw values for 
> selections predicates from within the calc_joinrel_size_estimate 
> method (in costsize.c). For example, if the restriction
>
> WHERE name_attr = "example_str"
>
> appears in the query, I'd like to get the "name_attr" and 
> "example_str" values. If possible, I would very much appreciate the help.
>
> Best, Walter

Very good idea to include a subject!

Blank subjects look like spam,...


Cheers,
Gavin



Re:

From
Tom Lane
Date:
Walter Cai <wzcai92@gmail.com> writes:
> I (a graduate student) am currently trying to modify a postgres instance
> slightly to incorporate my modified cardinality estimates. In order to run
> these experiments I'm hoping to access the raw values for selections
> predicates from within the calc_joinrel_size_estimate method (in costsize.c).
> For example, if the restriction

> WHERE name_attr = "example_str"

> appears in the query, I'd like to get the "name_attr" and "example_str"
> values. If possible, I would very much appreciate the help.

It's pretty unclear what you mean by "raw values".  What you're actually
going to be dealing with in that part of the code is a List of
RestrictInfo nodes, one for each relevant WHERE clause.  The one
representing this particular clause would contain an OpExpr node
representing the "=" operator, and the two inputs of the operator
would be a Var node representing the name_attr column and a Const
representing the 'example_str' literal.  You could pull the value
of the literal out of the Const node easily enough, but I don't
understand what you're looking for with respect to the Var.

            regards, tom lane


Re:

From
Walter Cai
Date:
Sorry about not including a title at first, I completely forgot!

And thanks for the help, Tom. With respect to the Var: I'm really just hoping to access the column name

Best, Walter

On Tue, Jan 9, 2018 at 11:14 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Walter Cai <wzcai92@gmail.com> writes:
> I (a graduate student) am currently trying to modify a postgres instance
> slightly to incorporate my modified cardinality estimates. In order to run
> these experiments I'm hoping to access the raw values for selections
> predicates from within the calc_joinrel_size_estimate method (in costsize.c).
> For example, if the restriction

> WHERE name_attr = "example_str"

> appears in the query, I'd like to get the "name_attr" and "example_str"
> values. If possible, I would very much appreciate the help.

It's pretty unclear what you mean by "raw values".  What you're actually
going to be dealing with in that part of the code is a List of
RestrictInfo nodes, one for each relevant WHERE clause.  The one
representing this particular clause would contain an OpExpr node
representing the "=" operator, and the two inputs of the operator
would be a Var node representing the name_attr column and a Const
representing the 'example_str' literal.  You could pull the value
of the literal out of the Const node easily enough, but I don't
understand what you're looking for with respect to the Var.

                        regards, tom lane

From
Tom Lane
Date:
Walter Cai <wzcai92@gmail.com> writes:
> Sorry about not including a title at first, I completely forgot!
> And thanks for the help, Tom. With respect to the Var: I'm really just
> hoping to access the column name

Well, you could look that up from the catalogs, or maybe better pull
it out of the alias list for the Var's corresponding RTE, but I wonder
why C code would take any interest in the column name?  Just about
everything is more usefully dealt with in terms of column numbers
(varattno) --- certainly, anything you might want to look up in
pg_statistic or suchlike places is going to be indexed by number not name.

            regards, tom lane