pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix a bug in how we generate partition constraints.
8+ messages / 5 participants
[nested] [flat]

Commits from this thread:
  2017-01-19 cc144155f7  Avoid some code duplication in map_partition_varattnos().
* pgsql: Fix a bug in how we generate partition constraints.
@ 2017-01-13 19:07 Robert Haas <rhaas@postgresql.org>
  2017-01-13 19:18 ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Robert Haas @ 2017-01-13 19:07 UTC (permalink / raw)
  To: pgsql-committers

Fix a bug in how we generate partition constraints.

Move the code for doing parent attnos to child attnos mapping for Vars
in partition constraint expressions to a separate function
map_partition_varattnos() and call it from the appropriate places.
Doing it in get_qual_from_partbound(), as is now, would produce wrong
result in certain multi-level partitioning cases, because it only
considers the current pair of parent-child relations.  In certain
multi-level partitioning cases, attnums for the same key attribute(s)
might differ between various levels causing the same attribute to be
numbered differently in different instances of the Var corresponding
to a given attribute.

With this commit, in generate_partition_qual(), we first generate the
the whole partition constraint (considering all levels of partitioning)
and then do the mapping, so that Vars in the final expression are
numbered according the leaf relation (to which it is supposed to apply).

Amit Langote, reviewed by me.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/0563a3a8b59150bf3cc8b2b7077f684e0eaf8aff

Modified Files
--------------
src/backend/catalog/partition.c           | 99 +++++++++++++++----------------
src/backend/commands/tablecmds.c          |  7 ++-
src/include/catalog/partition.h           |  1 +
src/test/regress/expected/alter_table.out | 30 ++++++++++
src/test/regress/sql/alter_table.sql      | 25 ++++++++
5 files changed, 110 insertions(+), 52 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints.
  2017-01-13 19:07 pgsql: Fix a bug in how we generate partition constraints. Robert Haas <rhaas@postgresql.org>
@ 2017-01-13 19:18 ` Alvaro Herrera <alvherre@2ndquadrant.com>
  2017-01-13 19:31   ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Alvaro Herrera @ 2017-01-13 19:18 UTC (permalink / raw)
  To: Robert Haas <rhaas@postgresql.org>; +Cc: pgsql-hackers@postgresql.org; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>

Robert Haas wrote:
> Fix a bug in how we generate partition constraints.
> 
> Move the code for doing parent attnos to child attnos mapping for Vars
> in partition constraint expressions to a separate function
> map_partition_varattnos() and call it from the appropriate places.

Hmm, we were discussing this stuff a few days ago, see
https://www.postgresql.org/message-id/20170109182800.qrkae62kmur3gfeg@alvherre.pgsql
and commit 3957b58b8885441c8d03bc1cfc00e47cf8cd7975.  Part of this code
duplicates that ...

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints.
  2017-01-13 19:07 pgsql: Fix a bug in how we generate partition constraints. Robert Haas <rhaas@postgresql.org>
  2017-01-13 19:18 ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2017-01-13 19:31   ` Robert Haas <robertmhaas@gmail.com>
  2017-01-13 19:35     ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Robert Haas @ 2017-01-13 19:31 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>

On Fri, Jan 13, 2017 at 2:18 PM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:
> Robert Haas wrote:
>> Fix a bug in how we generate partition constraints.
>>
>> Move the code for doing parent attnos to child attnos mapping for Vars
>> in partition constraint expressions to a separate function
>> map_partition_varattnos() and call it from the appropriate places.
>
> Hmm, we were discussing this stuff a few days ago, see
> https://www.postgresql.org/message-id/20170109182800.qrkae62kmur3gfeg@alvherre.pgsql
> and commit 3957b58b8885441c8d03bc1cfc00e47cf8cd7975.  Part of this code
> duplicates that ...

Is that bad?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints.
  2017-01-13 19:07 pgsql: Fix a bug in how we generate partition constraints. Robert Haas <rhaas@postgresql.org>
  2017-01-13 19:18 ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
  2017-01-13 19:31   ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
@ 2017-01-13 19:35     ` Robert Haas <robertmhaas@gmail.com>
  2017-01-13 20:09       ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Robert Haas @ 2017-01-13 19:35 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>

On Fri, Jan 13, 2017 at 2:31 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> On Fri, Jan 13, 2017 at 2:18 PM, Alvaro Herrera
> <alvherre@2ndquadrant.com> wrote:
>> Robert Haas wrote:
>>> Fix a bug in how we generate partition constraints.
>>>
>>> Move the code for doing parent attnos to child attnos mapping for Vars
>>> in partition constraint expressions to a separate function
>>> map_partition_varattnos() and call it from the appropriate places.
>>
>> Hmm, we were discussing this stuff a few days ago, see
>> https://www.postgresql.org/message-id/20170109182800.qrkae62kmur3gfeg@alvherre.pgsql
>> and commit 3957b58b8885441c8d03bc1cfc00e47cf8cd7975.  Part of this code
>> duplicates that ...
>
> Is that bad?

If you are expressing a concern about who wrote this code, I took
Amit's word for it that he did.  His patch file says:

Reported by: n/a
Patch by: Amit Langote
Reports: n/a

If that ain't right, that's bad.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints.
  2017-01-13 19:07 pgsql: Fix a bug in how we generate partition constraints. Robert Haas <rhaas@postgresql.org>
  2017-01-13 19:18 ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
  2017-01-13 19:31   ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  2017-01-13 19:35     ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
@ 2017-01-13 20:09       ` Alvaro Herrera <alvherre@2ndquadrant.com>
  2017-01-13 21:10         ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Alvaro Herrera @ 2017-01-13 20:09 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>

Robert Haas wrote:
> On Fri, Jan 13, 2017 at 2:31 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> > On Fri, Jan 13, 2017 at 2:18 PM, Alvaro Herrera
> > <alvherre@2ndquadrant.com> wrote:

> >> Hmm, we were discussing this stuff a few days ago, see
> >> https://www.postgresql.org/message-id/20170109182800.qrkae62kmur3gfeg@alvherre.pgsql
> >> and commit 3957b58b8885441c8d03bc1cfc00e47cf8cd7975.  Part of this code
> >> duplicates that ...
> >
> > Is that bad?
> 
> If you are expressing a concern about who wrote this code, I took
> Amit's word for it that he did.

I'm just saying that the problem at hand is already solved for a related
feature, so ISTM this new code should use the recently added routine
rather than doing the same thing in a different way.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints.
  2017-01-13 19:07 pgsql: Fix a bug in how we generate partition constraints. Robert Haas <rhaas@postgresql.org>
  2017-01-13 19:18 ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
  2017-01-13 19:31   ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  2017-01-13 19:35     ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  2017-01-13 20:09       ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2017-01-13 21:10         ` Robert Haas <robertmhaas@gmail.com>
  2017-01-14 04:36           ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Amit Langote <amitlangote09@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Robert Haas @ 2017-01-13 21:10 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>

On Fri, Jan 13, 2017 at 3:09 PM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:
> Robert Haas wrote:
>> On Fri, Jan 13, 2017 at 2:31 PM, Robert Haas <robertmhaas@gmail.com> wrote:
>> > On Fri, Jan 13, 2017 at 2:18 PM, Alvaro Herrera
>> > <alvherre@2ndquadrant.com> wrote:
>
>> >> Hmm, we were discussing this stuff a few days ago, see
>> >> https://www.postgresql.org/message-id/20170109182800.qrkae62kmur3gfeg@alvherre.pgsql
>> >> and commit 3957b58b8885441c8d03bc1cfc00e47cf8cd7975.  Part of this code
>> >> duplicates that ...
>> >
>> > Is that bad?
>>
>> If you are expressing a concern about who wrote this code, I took
>> Amit's word for it that he did.
>
> I'm just saying that the problem at hand is already solved for a related
> feature, so ISTM this new code should use the recently added routine
> rather than doing the same thing in a different way.

Oh, I see.  Amit, thoughts?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints.
  2017-01-13 19:07 pgsql: Fix a bug in how we generate partition constraints. Robert Haas <rhaas@postgresql.org>
  2017-01-13 19:18 ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
  2017-01-13 19:31   ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  2017-01-13 19:35     ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  2017-01-13 20:09       ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
  2017-01-13 21:10         ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
@ 2017-01-14 04:36           ` Amit Langote <amitlangote09@gmail.com>
  2017-01-16 06:04             ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
  0 siblings, 1 reply; 8+ messages in thread

From: Amit Langote @ 2017-01-14 04:36 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>

On Sat, Jan 14, 2017 at 6:10 AM, Robert Haas <robertmhaas@gmail.com> wrote:
> On Fri, Jan 13, 2017 at 3:09 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
>>
>> I'm just saying that the problem at hand is already solved for a related
>> feature, so ISTM this new code should use the recently added routine
>> rather than doing the same thing in a different way.
>
> Oh, I see.  Amit, thoughts?

Hm, perhaps.  The code in map_partition_varattnos() that creates the
map could be replaced by a call to the new
convert_tuples_by_name_map().  In fact, it could even have used the
old version of it (convert_tuples_by_name()).  I guess I just aped
what other callers of map_variable_attnos() were doing, which is to
generate the map themselves (not that they ought to be changed to use
convert_tuples_by_name_map).

I will send a patch at my earliest convenience. Thanks to Alvaro for
pointing that out.

Thanks,
Amit


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints.
  2017-01-13 19:07 pgsql: Fix a bug in how we generate partition constraints. Robert Haas <rhaas@postgresql.org>
  2017-01-13 19:18 ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
  2017-01-13 19:31   ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  2017-01-13 19:35     ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  2017-01-13 20:09       ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Alvaro Herrera <alvherre@2ndquadrant.com>
  2017-01-13 21:10         ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Robert Haas <robertmhaas@gmail.com>
  2017-01-14 04:36           ` Re: [COMMITTERS] pgsql: Fix a bug in how we generate partition constraints. Amit Langote <amitlangote09@gmail.com>
@ 2017-01-16 06:04             ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
  0 siblings, 0 replies; 8+ messages in thread

From: Amit Langote @ 2017-01-16 06:04 UTC (permalink / raw)
  To: Amit Langote <amitlangote09@gmail.com>; Robert Haas <robertmhaas@gmail.com>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On 2017/01/14 13:36, Amit Langote wrote:
> On Sat, Jan 14, 2017 at 6:10 AM, Robert Haas <robertmhaas@gmail.com> wrote:
>> On Fri, Jan 13, 2017 at 3:09 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
>>>
>>> I'm just saying that the problem at hand is already solved for a related
>>> feature, so ISTM this new code should use the recently added routine
>>> rather than doing the same thing in a different way.
>>
>> Oh, I see.  Amit, thoughts?
> 
> Hm, perhaps.  The code in map_partition_varattnos() that creates the
> map could be replaced by a call to the new
> convert_tuples_by_name_map().  In fact, it could even have used the
> old version of it (convert_tuples_by_name()).  I guess I just aped
> what other callers of map_variable_attnos() were doing, which is to
> generate the map themselves (not that they ought to be changed to use
> convert_tuples_by_name_map).
> 
> I will send a patch at my earliest convenience. Thanks to Alvaro for
> pointing that out.

And here is the patch.

Thanks,
Amit

Attachments:

  0001-Avoid-code-duplication-in-map_partition_varattnos.patch (text/x-diff, 0B) download

^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2017-01-16 06:04 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-01-13 19:07 pgsql: Fix a bug in how we generate partition constraints. Robert Haas <rhaas@postgresql.org>
2017-01-13 19:18 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2017-01-13 19:31   ` Robert Haas <robertmhaas@gmail.com>
2017-01-13 19:35     ` Robert Haas <robertmhaas@gmail.com>
2017-01-13 20:09       ` Alvaro Herrera <alvherre@2ndquadrant.com>
2017-01-13 21:10         ` Robert Haas <robertmhaas@gmail.com>
2017-01-14 04:36           ` Amit Langote <amitlangote09@gmail.com>
2017-01-16 06:04             ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox