Re: Removing Functionally Dependent GROUP BY Columns - Mailing list pgsql-hackers

From David Rowley
Subject Re: Removing Functionally Dependent GROUP BY Columns
Date
Msg-id CAKJS1f-21QHfQhQ7u8rd4u+N3zJP5vEhedzJUZYCWUHFXMjfJA@mail.gmail.com
Whole thread Raw
In response to Re: Removing Functionally Dependent GROUP BY Columns  (Julien Rouhaud <julien.rouhaud@dalibo.com>)
Responses Re: Removing Functionally Dependent GROUP BY Columns
List pgsql-hackers
On 24 January 2016 at 00:56, Julien Rouhaud <julien.rouhaud@dalibo.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.


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



pgsql-hackers by date:

Previous
From: Jinhua Luo
Date:
Subject: Re: insert/update performance
Next
From: Fabien COELHO
Date:
Subject: Re: pgbench stats per script & other stuff