Re: Allowing join removals for more join types

From: Dilip kumar <dilip(dot)kumar(at)huawei(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Allowing join removals for more join types
Date: 2014-05-23 08:28:56
Message-ID: 4205E661176A124FAF891E0A6BA91352663126FA@szxeml509-mbs.china.huawei.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 23 May 2014 12:43 David Rowley Wrote,

>I'm hitting a bit of a roadblock on point 1. Here's a snipped from my latest attempt:

> if (bms_membership(innerrel->relids) == BMS_SINGLETON)
> {
> int subqueryrelid = bms_singleton_member(innerrel->relids);
> RelOptInfo *subqueryrel = find_base_rel(innerrel->subroot, subqueryrelid);
>
> if (relation_has_unique_index_for(root, subqueryrel, clause_list, NIL, NIL))
> return true;
> }

>But it seems that innerrel->subroot is still NULL at this stage of planning and from what I can tell does not exist anywhere else yet and is not generated until make_one_rel() is called from query_planner()

>Am I missing something major here,or does this sound about right?

It’s true that, till this point of time we haven’t prepared the base relation list for the subquery, and that will be done from make_one_rel while generating the SUBQURY path list.

I can think of one solution but I think it will be messy…

We get the base relation info directly from subquery
Like currently in your patch (shown in below snippet) we are getting the distinct and groupby clause from sub Query, similarly we can get base relation info from (Query->jointree)

if (innerrel->rtekind == RTE_SUBQUERY)
{
Query *query = root->simple_rte_array[innerrelid]->subquery;

if (sortclause_is_unique_on_restrictinfo(query, clause_list, query->groupClause) ||
sortclause_is_unique_on_restrictinfo(query, clause_list, query->distinctClause))
return true;
}

Regards,
Dilip

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Shigeru Hanada 2014-05-23 09:29:55 fix worker_spi to run as non-dynamic background worker
Previous Message Matteo Beccati 2014-05-23 08:05:49 Re: uuid-ossp (Re: [pgsql-packagers] Postgresapp 9.4 beta build ready)