Re: Use unique index for longer pathkeys.

From: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>
To: amit(dot)kapila16(at)gmail(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Use unique index for longer pathkeys.
Date: 2014-08-08 03:40:42
Message-ID: 20140808.124042.236254271.horiguchi.kyotaro@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

> > Although, yes, you're right, irrespective of the "common
> > something", and even if the dropped index was i_t1_pkey_2, which
> > is on t1(a, b), the result tuples are sorted as expected only by
> > the pathkey (t.a = t1.a, t1.b). It is because both t and t1 are
> > still unique so the joined tuples are also unique, and the unique
> > key of the result tuples is the merged pkey (t.a, t1.a, t1.b),
> > which can be transformed to (t.a, t1.b) using the equiality
> > between t.a and t1.a. And considering the inner relation (t1) is
> > already sorted by (a, b), the sort itself could be elimited from
> > the plan.
>
> I think if we could eliminate t1.c,t1.d considering indexes on
> individual relations (may be by using technique I have mentioned
> upthread or some other way), then the current code itself will
> eliminate the ORDER BY clause. I have tried that by using a query
> without having t1.c,t1.d in ORDER BY clause
>
> explain (costs off, analyze off) select * from t,t1 where t.a=t1.a order by
> t1.a,t1.b;
> QUERY PLAN
> ------------------------------------------
> Merge Join
> Merge Cond: (t1.a = t.a)
> -> Index Scan using i_t1_pkey_2 on t1
> -> Index Scan using i_t_pkey on t
> (4 rows)

Ya, the elimination seems to me so fascinate:)

> Okay, I think you want to handle the elimination of ORDER BY clauses
> at a much broader level which might handle most of simple cases as
> well. However I think eliminating clauses as mentioned above is itself
> a good optimization for many cases and more so if that can be done in
> a much simpler way.

Yes, if can be done in "much" simpler way.. I guess that it
could be looking from opposite side, that is, equivalence
classes, anyway, I'll try it.

regards,

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2014-08-08 03:56:08 Re: Specifying the unit in storage parameter
Previous Message Fujii Masao 2014-08-08 03:32:40 Specifying the unit in storage parameter