Accessing base table relational names via RelOptInfo

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing base table relational names via RelOptInfo

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
Reply | Threaded
Open this post in threaded view
|

Re: Accessing base table relational names via RelOptInfo

David Rowley-3
On 7 December 2017 at 09:26, Walter Cai <[hidden email]> wrote:
> 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.

If you loop through the RelOptInfo->relids with bms_next_member() and
lookup the RangeTblEntry from root->simple_rte_array[] you can get the
"relid", which is the Oid of the relation. You can then call
get_rel_name() on that Oid. You'll also need to ensure the relid
actually belongs to a relation, for this check that the
RangeTblEntry->rtekind is RTE_RELATION. You might also want to think
about schema names since two relations can share the same name in
different schemas.

--
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Previous Thread Next Thread