Re: PG11 Hash partitioning and null values in the partition key

From: amul sul <sulamul(at)gmail(dot)com>
To: daniel(dot)westermann(at)dbi-services(dot)com
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: PG11 Hash partitioning and null values in the partition key
Date: 2018-07-13 14:56:48
Message-ID: CAAJ_b94Y+ajsqGs0tFw9hnX8h-u2mfZdZy5LcbG05_2DCJOXig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jul 13, 2018, 7:35 PM Daniel Westermann <
daniel(dot)westermann(at)dbi-services(dot)com> wrote:

> Hi,
>
> given this setup:
>
> create table part2 ( a int, list varchar(10) ) partition by hash (a);
> create table part2_1 partition of part2 FOR VALUES WITH (MODULUS 3,
> REMAINDER 0);
> create table part2_2 partition of part2 FOR VALUES WITH (MODULUS 3,
> REMAINDER 1);
> create table part2_3 partition of part2 FOR VALUES WITH (MODULUS 3,
> REMAINDER 2);
>
> insert into part2 (a,list) values (1,'aaa');
> insert into part2 (a,list) values (2,'bbb');
> insert into part2 (a,list) values (3,'ccc');
>
> ... it is possible to insert rows like this which will always go to the
> first partition:
>
> insert into part2 (a,list) values (null,'ddd');
> insert into part2 (a,list) values (null,'eee');
> select * from part2_1;
> a | list
> ---+------
> 2 | bbb
> | ddd
> | eee
> (3 rows)
>
> I suppose this is intended but I could not find anything in the
> documentation about that. Can someone please clarify the logic behind that?
>

The calculated hash value for the null value will be zero, therefore, it
will fall to the partition having remainder zero.

​Regards,
Amul​

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sean McIntyre 2018-07-13 15:14:36 ERROR: found multixact from before relminmxid
Previous Message Łukasz Jarych 2018-07-13 14:39:08 Re: Read only to schema