Retrieving Alias Name

2019-02-26 Thread Walter Cai
Hi,

I'm currently using a (very rough) scheme to retrieve relation names from a
PlannerInfo, and a RelOptInfo struct:

PlannerInfo *root
RelOptInfo *inner_rel

//...

RangeTblEntry *rte;
int x = -1;
while ((x = bms_next_member(inner_rel->relids, x)) >= 0)
{
rte = root->simple_rte_array[x];
if (rte->rtekind == RTE_RELATION)
{
char *rel_name = get_rel_name(rte->relid);
// do stuff...
}
}

However, I now realize it would be better to access aliases as they appear
in the SQL query. For instance, if the query contains "... FROM rel_name AS
rel_alias ..." I would like to retrieve `rel_alias` instead of `rel_name`.

Is it possible to derive the alias in a similar way?

For context: this code is being inserted into
src/backend/optimizer/path/costsize.c and specifically in the
calc_joinrel_size_estimate method.

Thanks in advance,
Walter


Re:

2018-01-09 Thread Walter Cai
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 <t...@sss.pgh.pa.us> wrote:

> Walter Cai <wzca...@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
>


[no subject]

2018-01-09 Thread Walter Cai
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


Programmatically accessing selection predicates

2018-01-03 Thread Walter Cai
Hi,

In order to run some cardinality estimation 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


Accessing base table relational names via RelOptInfo

2017-12-06 Thread Walter Cai
Hi,

I hope this is the appropriate list to send this to.

*Context:*

I (grad student) am trying to insert my own cardinality estimates into the
optimizer

*What I need to do to get there:*

I want to be able to programmatically access the relation names inside from
inside the calc_joinrel_size_estimate method (in costsize.c) using the
RelOptInfo
*outer_rel, RelOptInfo *inner_rel arguments. I'm pretty sure I need to use
the Relids relids variables in the RelOptInfo struct but I'm not sure where
to go from there.

Any help would be much appreciated

Best, Walter