From: | Claudio Freire <klaussfreire(at)gmail(dot)com> |
---|---|
To: | Robert Haas <robertmhaas(at)gmail(dot)com> |
Cc: | Bruce Momjian <bruce(at)momjian(dot)us>, Yuri Levinsky <yuril(at)celltick(dot)com>, PostgreSQL-Dev <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Hash partitioning. |
Date: | 2013-06-25 18:16:10 |
Message-ID: | CAGTBQpZKzY+HrsaZ4R3aYQdusCBV7j7=g_tdahvpPx9ig1=tEw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Tue, Jun 25, 2013 at 12:55 PM, Robert Haas <robertmhaas(at)gmail(dot)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).
From | Date | Subject | |
---|---|---|---|
Next Message | Alexander Korotkov | 2013-06-25 18:18:08 | Re: GIN improvements part 3: ordering in index |
Previous Message | Alvaro Herrera | 2013-06-25 18:08:24 | Re: Hash partitioning. |