Re: Hash partitioning.

Поиск
Список
Период
Сортировка
От Claudio Freire
Тема Re: Hash partitioning.
Дата
Msg-id CAGTBQpZKzY+HrsaZ4R3aYQdusCBV7j7=g_tdahvpPx9ig1=tEw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Hash partitioning.  (Robert Haas <robertmhaas@gmail.com>)
Ответы Re: Hash partitioning.  (Kevin Grittner <kgrittn@ymail.com>)
Список pgsql-hackers
On Tue, Jun 25, 2013 at 12:55 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> Let me back up a minute.  You told the OP that he could make hash
> partitioning by writing his own constraint and trigger functions.  I
> think that won't work.  But I'm happy to be proven wrong.  Do you have
> an example showing how to do it?
>
> Here's why I think it WON'T work:
>
> rhaas=# create table foo (a int, b text);
> CREATE TABLE
> rhaas=# create table foo0 (check ((a % 16) = 0)) inherits (foo);
> CREATE TABLE
> rhaas=# create table foo1 (check ((a % 16) = 1)) inherits (foo);
> CREATE TABLE
> rhaas=# create table foo2 (check ((a % 16) = 2)) inherits (foo);
> CREATE TABLE
> rhaas=# create table foo3 (check ((a % 16) = 3)) inherits (foo);
> CREATE TABLE
> rhaas=# explain select * from foo where a = 1;
>                          QUERY PLAN
> ------------------------------------------------------------
>  Append  (cost=0.00..101.50 rows=25 width=36)
>    ->  Seq Scan on foo  (cost=0.00..0.00 rows=1 width=36)
>          Filter: (a = 1)
>    ->  Seq Scan on foo0  (cost=0.00..25.38 rows=6 width=36)
>          Filter: (a = 1)
>    ->  Seq Scan on foo1  (cost=0.00..25.38 rows=6 width=36)
>          Filter: (a = 1)
>    ->  Seq Scan on foo2  (cost=0.00..25.38 rows=6 width=36)
>          Filter: (a = 1)
>    ->  Seq Scan on foo3  (cost=0.00..25.38 rows=6 width=36)
>          Filter: (a = 1)
> (11 rows)
>
> Notice we get a scan on every partition.  Now let's try it with no
> modulo arithmetic, just a straightforward one-partition-per-value:
>
> rhaas=# create table foo (a int, b text);
> CREATE TABLE
> rhaas=# create table foo0 (check (a = 0)) inherits (foo);
> CREATE TABLE
> rhaas=# create table foo1 (check (a = 1)) inherits (foo);
> CREATE TABLE
> rhaas=# create table foo2 (check (a = 2)) inherits (foo);
> CREATE TABLE
> rhaas=# create table foo3 (check (a = 3)) inherits (foo);
> CREATE TABLE
> rhaas=# explain select * from foo where a = 1;


Did you try "select * from foo where (a % 16) = (1::int % 16)"?

A few views I have that span multiple "partitions" (in quotes since
they're not exactly partitions, but close), I can make constraint
exclusion work if I match the expression EXACTLY, including types
(I've posted a few questions about this to pg-performance).



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: Hash partitioning.
Следующее
От: Alexander Korotkov
Дата:
Сообщение: Re: GIN improvements part 3: ordering in index