Re: Removing Functionally Dependent GROUP BY Columns

From: Julien Rouhaud <julien(dot)rouhaud(at)dalibo(dot)com>
To: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Removing Functionally Dependent GROUP BY Columns
Date: 2016-01-23 15:31:18
Message-ID: 56A39CC6.1000101@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 23/01/2016 14:51, David Rowley wrote:
> On 24 January 2016 at 00:56, Julien Rouhaud <julien(dot)rouhaud(at)dalibo(dot)com> wrote:
>> I wonder if in remove_useless_groupby_columns(), in the foreach loop you
>> could change the
>>
>> + if (bms_subset_compare(pkattnos, relattnos) == BMS_SUBSET1)
>> + {
>>
>> by something like
>>
>>
>> + if (bms_num_members(relattnos) <= bms_num_members(pkattnos))
>> + continue;
>> +
>> + if (bms_is_subset(pkattnos, relattnos))
>> + {
>>
>>
>> which may be cheaper.
>
> Thanks for looking over this again.
>
> I actually had that part written quite a few different ways before I
> finally decided to use bms_subset_compare. I didn't benchmark, but I
> thought 1 function call was better than 2, as I had it as
> bms_is_subset(pkattnos, relattnos) && !bms_is_subset(relattnos,
> pkattnos), and again with !bms_equal() instead of the 2nd subset test.
> I figured 1 function call was better than 2, so finally settled on
> bms_subset_compare(). I'm thinking that 3 function calls likely won't
> make things better. I can't imagine it's going to cost much either
> way, so I doubt it's worth trying to check whats faster. Although the
> thing about bms_num_members() is that it's going to loop over each
> word in the bitmap no matter what, whereas a subset check can abort
> early in some cases.
>
>

FWIW, this code was simplified example. bms_num_members(relattnos) is
already called a few lines before, so it'd be 1 function call against 2
function calls (and a var assignment).

--
Julien Rouhaud
http://dalibo.com - http://dalibo.org

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-01-23 15:36:15 Re: proposal: function parse_ident
Previous Message Michael Paquier 2016-01-23 15:20:12 Re: proposal: function parse_ident