Automating Partitions in PostgreSQL - Query on syntax
Automating Partitions in PostgreSQL - Query on syntax
Hi ,
We are working on a patch to automate partitioning in PostgreSQL.
For Range partitions, we have proposed the syntax which is as follows –
CREATE TABLE emp (
emp_id int not null primary key,
designation text not null,
location varchar(50) not null,
jdate date not null,
ctc float not null
)
PARTITION BY RANGE (emp_id)
(
emp_500 (START 1 END 500),
emp_1500 (START 500 END 1500),
emp_4000 (START 1520 END 4000)
);
As observed in this syntax, user needs to specify explicitly, the min and max values of a range for a given partition.
With this design, partition ranges are inherently allowed to be fragmented and non-contiguous. As ‘gaps’ are allowed
in the ranges, we’re also supporting an ‘overflow’ partition, so that any row, which does not satisfy constraints of any
existing partitions, does not stall a big UPDATE operation and such rows are preserved.(in overflow table)
However, Oracle uses user-friendly syntax but makes it compulsion that partition ranges *have* to be contiguous.
PARTITION BY RANGE (emp_id)
(
Partition emp_500 values less than (500),
Partition emp_1500 values less than (1500),
Partition emp_4000 values less than (4000),
Partition emp_max values less than (maxvalue)
);
As it does not allow fragmented ranges, it automatically removes the need for an ‘overflow’ partition.
The syntax proposed by us is more flexible and would handle both the cases of ranges with gaps or ranges without gaps.
I want to seek general opinion from the community on preferences between user-friendly ‘Oracle’ syntax, and a more generic syntax that allows ‘gaps’ in partition ranges?
Regards,
--
Kedar
Re: Automating Partitions in PostgreSQL - Query on syntax
On Tue, Apr 21, 2009 at 12:50 PM, Kedar Potdar wrote: > I want to seek general opinion from the community on preferences between > user-friendly ‘Oracle’ syntax, and a more generic syntax that allows ‘gaps’ > in partition ranges? What happens to records in the overflow table when you add a new partition whose range covers their values? -- greg
Re: Automating Partitions in PostgreSQL - Query on syntax
Thanks for your response.
Currently, such records are left in the overflow partition and its responsibility
of user to insert them into partitioned-table which will then re-direct those to
appropriate partitions.
Regards,
--
Kedar.
On Tue, Apr 21, 2009 at 12:50 PM, Kedar Potdar <kedar.potdar@gmail.com> wrote:What happens to records in the overflow table when you add a new
> I want to seek general opinion from the community on preferences between
> user-friendly ‘Oracle’ syntax, and a more generic syntax that allows ‘gaps’
> in partition ranges?
partition whose range covers their values?
--
greg
Re: Automating Partitions in PostgreSQL - Query on syntax
Em Ter, 2009-04-21 às 17:20 +0530, Kedar Potdar escreveu: > Hi , > > We are working on a patch to automate partitioning in PostgreSQL. Nice. ":) > For Range partitions, we have proposed the syntax which is as > follows > > (...) > PARTITION BY RANGE (emp_id) > ( > emp_500 (START 1 END 500), > emp_1500 (START 500 END 1500), > emp_4000 (START 1520 END 4000) > ); What if I need more columns to set the partitions? []s -- Dickson S. Guedes mail/xmpp: guedes@guedesoft.net - skype: guediz http://guedesoft.net - http://planeta.postgresql.org.br
Re: Automating Partitions in PostgreSQL - Query on syntax
Em Ter, 2009-04-21 às 17:20 +0530, Kedar Potdar escreveu:> Hi ,Nice. ":)
>
> We are working on a patch to automate partitioning in PostgreSQL.> (...)
> For Range partitions, we have proposed the syntax which is as
> follows
>> PARTITION BY RANGE (emp_id)What if I need more columns to set the partitions?
> (
> emp_500 (START 1 END 500),
> emp_1500 (START 500 END 1500),
> emp_4000 (START 1520 END 4000)
> );
CREATE TABLE emp (
emp_id int not null primary key,
designation text not null,
location varchar(50) not null,
jdate date not null,
ctc float not null
)
PARTITION BY RANGE (jdate, emp_id)
(
emp_500 (START '01-01-1980',1 END '01-01-1990',500),
emp_1500(START '01-01-1990',500 END '01-01-2000',1500+10),
emp_4000 (START '1 Jan 2000',1500+20 END 'Jan 1, 2010', 4000-50)
);
You can have multiple columns as partition key attributes and values for these attributes should appear in the order specified.
[]s
--
Dickson S. Guedes
mail/xmpp: guedes@guedesoft.net - skype: guediz
http://guedesoft.net - http://planeta.postgresql.org.br
Re: Automating Partitions in PostgreSQL - Query on syntax
Vacuum, I guess you forgot to reply-to-all. ":) Em Ter, 2009-04-21 às 16:05 +0200, vacuum@quantentunnel.de escreveu: > why not partitions by "conditions"? > > you can do that in similar way how "case when then " works .. > > CREATE PARTITIONS ON
Re: Automating Partitions in PostgreSQL - Query on syntax
2009/4/21 Kedar Potdar : > > > 2009/4/21 Dickson S. Guedes >> >> Em Ter, 2009-04-21 às 17:20 +0530, Kedar Potdar escreveu: >> > Hi , >> > >> > We are working on a patch to automate partitioning in PostgreSQL. >> >> Nice. ":) >> >> > For Range partitions, we have proposed the syntax which is as >> > follows >> > >> > (...) >> > PARTITION BY RANGE (emp_id) >> > ( >> > emp_500 (START 1 END 500), >> > emp_1500 (START 500 END 1500), >> > emp_4000 (START 1520 END 4000) >> > ); >> >> What if I need more columns to set the partitions? > > > You can do so by using command like this, > > CREATE TABLE emp ( > emp_id int not null primary key, > designation text not null, > location varchar(50) not null, > jdate date not null, > ctc float not null > > ) > PARTITION BY RANGE (jdate, emp_id) > ( > emp_500 (START '01-01-1980',1 END '01-01-1990',500), > emp_1500(START '01-01-1990',500 END '01-01-2000',1500+10), > emp_4000 (START '1 Jan 2000',1500+20 END 'Jan 1, 2010', 4000-50) > ); > > You can have multiple columns as partition key attributes and values for > these attributes should appear in the order specified. -1, this is really ugly Pavel > >> >> >> >> []s >> -- >> Dickson S. Guedes >> mail/xmpp: guedes@guedesoft.net - skype: guediz >> http://guedesoft.net - http://planeta.postgresql.org.br > >
Re: Automating Partitions in PostgreSQL - Query on syntax
-1, this is really ugly>> > (...)
>> > PARTITION BY RANGE (emp_id)
>> > (
>> > emp_500 (START 1 END 500),
>> > emp_1500 (START 500 END 1500),
>> > emp_4000 (START 1520 END 4000)
>> > );
>>
>> What if I need more columns to set the partitions?
>
>
> You can do so by using command like this,
>
> CREATE TABLE emp (
> emp_id int not null primary key,
> designation text not null,
> location varchar(50) not null,
> jdate date not null,
> ctc float not null
>
> )
> PARTITION BY RANGE (jdate, emp_id)
> (
> emp_500 (START '01-01-1980',1 END '01-01-1990',500),
> emp_1500(START '01-01-1990',500 END '01-01-2000',1500+10),
> emp_4000 (START '1 Jan 2000',1500+20 END 'Jan 1, 2010', 4000-50)
> );
>
> You can have multiple columns as partition key attributes and values for
> these attributes should appear in the order specified.
Yeah, but what is the syntax for multiple column ranges in Orcl - is it similarly ugly?
As to Kedar's original question about gap-based ranges or Orcl style no-gap ranges, I don't think while partitioning such fine-grained gap-based ranges is such a stringent requirement.
Also specification of the maxvalue range in Orcl's case nicely maps to the overflow partition that is being mentioned upthread.
So whichever way we go maybe we can also consider accomodating the maxval for different datatypes if possible within the syntax itself.
Regards,
Nikhils
Pavel
>
>>
>>
>>
>> []s
>> --
>> Dickson S. Guedes
>> mail/xmpp: guedes@guedesoft.net - skype: guediz
>> http://guedesoft.net - http://planeta.postgresql.org.br
>
>--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
--
http://www.enterprisedb.com
Re: Automating Partitions in PostgreSQL - Query on syntax
oh sorry .. but what I miss in this discussion - where we can define tablespace? CREATE PARTITIONS ON
Re: Automating Partitions in PostgreSQL - Query on syntax
On Tue, Apr 21, 2009 at 4:13 PM, wrote: > oh sorry .. > > but what I miss in this discussion - where we can define tablespace? > > CREATE PARTITIONS ON
Re: Automating Partitions in PostgreSQL - Query on syntax
On Tue, Apr 21, 2009 at 11:13 AM, wrote: > oh sorry .. > > but what I miss in this discussion - where we can define tablespace? > > CREATE PARTITIONS ON
Re: Automating Partitions in PostgreSQL - Query on syntax
On Tue, Apr 21, 2009 at 9:38 AM, Kedar Potdar wrote: > Currently, such records are left in the overflow partition and its > responsibility > of user to insert them into partitioned-table which will then re-direct > those to > appropriate partitions. This doesn't sound like a very good idea, because the planner cannot then rely on the overflow table not containing tuples that ought to be within some other partition. The big win that is associated with table partitioning is using constraint exclusion to avoid unnecessary partitions scans. ...Robert
Re: Automating Partitions in PostgreSQL - Query on syntax
the idea is, that this statement does not create a new kind of db-object. this "CREATE PARTITIONS" statement should be a meta-statement -> "meta" like the serial type. with create paritions you can create all defined tables (maybe by inheritin from
Re: Automating Partitions in PostgreSQL - Query on syntax
On Tue, 2009-04-21 at 11:43 -0400, Robert Haas wrote: > This doesn't sound like a very good idea, because the planner cannot > then rely on the overflow table not containing tuples that ought to be > within some other partition. > > The big win that is associated with table partitioning is using > constraint exclusion to avoid unnecessary partitions scans. Well it could always check 2 partitions: the overflow and the one selected by the constraint exclusion. If the overflow is kept empty by properly setting up the partitions so that all insertions always go to one of the active partitions, that would be cheap enough too while still providing a way to catch unexpected data. Then when a new partition is defined, there's no need to shuffle around data immediately, but there could be a maintenance command to clean up the overflow... not to mention that you could define a trigger to create the new partition once you get something in the overflow (how cool would that be if it would work ?). Cheers, Csaba.
Re: Automating Partitions in PostgreSQL - Query on syntax
-------- Original-Nachricht -------- > Datum: Tue, 21 Apr 2009 17:50:02 +0200 > Von: Csaba Nagy > An: Robert Haas > CC: Kedar Potdar , Greg Stark , pgsql-hackers@postgresql.org > Betreff: Re: [HACKERS] Automating Partitions in PostgreSQL - Query on syntax > > The big win that is associated with table partitioning is using > > constraint exclusion to avoid unnecessary partitions scans. there is no reason for not using the 'CASE condition' for constraint exclusion. -- Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate + Telefonanschluss für nur 17,95 Euro/mtl.!* http://dslspecial.gmx.de/freedsl-surfflat/?ac=OM.AD.PD003K11308T4569a
Re: Automating Partitions in PostgreSQL - Query on syntax
-------- Original-Nachricht -------- > Datum: Tue, 21 Apr 2009 16:37:15 +0100 > Von: Greg Stark > An: vacuum@quantentunnel.de > CC: "Dickson S. Guedes" , pgsql-hackers@postgresql.org > Betreff: Re: [HACKERS] Automating Partitions in PostgreSQL - Query on syntax > On Tue, Apr 21, 2009 at 4:13 PM, wrote: > > oh sorry .. > > > > but what I miss in this discussion - where we can define tablespace? > > > > CREATE PARTITIONS ON
Re: Automating Partitions in PostgreSQL - Query on syntax
> SWITCH > CASE TABLE
Re: Automating Partitions in PostgreSQL - Query on syntax
On Tue, Apr 21, 2009 at 11:50 AM, Csaba Nagy wrote: > On Tue, 2009-04-21 at 11:43 -0400, Robert Haas wrote: >> This doesn't sound like a very good idea, because the planner cannot >> then rely on the overflow table not containing tuples that ought to be >> within some other partition. >> >> The big win that is associated with table partitioning is using >> constraint exclusion to avoid unnecessary partitions scans. > > Well it could always check 2 partitions: the overflow and the one > selected by the constraint exclusion. If the overflow is kept empty by > properly setting up the partitions so that all insertions always go to > one of the active partitions, that would be cheap enough too while still > providing a way to catch unexpected data. Then when a new partition is > defined, there's no need to shuffle around data immediately, but there > could be a maintenance command to clean up the overflow... not to > mention that you could define a trigger to create the new partition once > you get something in the overflow (how cool would that be if it would > work ?). Sure, you could do it that way. But it will cause problems for people who want to have a million rows in each of 100 partitions, and another million rows in the overflow partition. Now all operations that can be done on a single partition must scan 2 million rows instead of 1 million, just on the off chance that someone executed a DDL command and didn't clean up after themselves. ...Robert
Re: Automating Partitions in PostgreSQL - Query on syntax
On Tue, Apr 21, 2009 at 12:35 PM, steven king wrote: > why a partition-key cannot be a complex expression? > > like this: > > SWITCH > CASE TABLE
Re: Automating Partitions in PostgreSQL - Query on syntax
>> > The big win that is associated with table partitioning is using >> > constraint exclusion to avoid unnecessary partitions scans. > > there is no reason for not using the 'CASE condition' for constraint exclusion. There is if you can't rely on the rows to be in the right partition. Allowing DDL commands to change the partitioning layout without moving the rows is going cause a lot of problems for you, I think. I'm also not sure how skillful the constraint exclusion logic is at proving theorems when CASE statements are involved. It might be good to test that before going too far with this approach. ...Robert
Re: Automating Partitions in PostgreSQL - Query on syntax
On Tue, Apr 21, 2009 at 12:17 PM, steven king wrote: > the idea is, that this statement does not create a new kind of db-object. this "CREATE PARTITIONS" statement should be a meta-statement -> "meta" like the serial type. That was my assumption as well. > with create paritions you can create all defined tables (maybe by inheritin from
Re: Automating Partitions in PostgreSQL - Query on syntax
More importantly it makes it a lot harder for the planner to do clever things. Currently having to append two tables means losing the ordering of the records and having to resort. Even if that's fixed it makes it harder to get reasonable estimates for size and distinctness. Ideally partitioned tables would be completely eliminated from plans at plan time whenever possible so that the runtime plan is the same as you would have gotten without partitioning. Where that's not possible we should aim to get as close as possible. -- Greg On 21 Apr 2009, at 18:22, Robert Haas wrote: > On Tue, Apr 21, 2009 at 11:50 AM, Csaba Nagy > wrote: >> On Tue, 2009-04-21 at 11:43 -0400, Robert Haas wrote: >>> This doesn't sound like a very good idea, because the planner cannot >>> then rely on the overflow table not containing tuples that ought >>> to be >>> within some other partition. >>> >>> The big win that is associated with table partitioning is using >>> constraint exclusion to avoid unnecessary partitions scans. >> >> Well it could always check 2 partitions: the overflow and the one >> selected by the constraint exclusion. If the overflow is kept empty >> by >> properly setting up the partitions so that all insertions always go >> to >> one of the active partitions, that would be cheap enough too while >> still >> providing a way to catch unexpected data. Then when a new partition >> is >> defined, there's no need to shuffle around data immediately, but >> there >> could be a maintenance command to clean up the overflow... not to >> mention that you could define a trigger to create the new partition >> once >> you get something in the overflow (how cool would that be if it would >> work ?). > > Sure, you could do it that way. But it will cause problems for people > who want to have a million rows in each of 100 partitions, and another > million rows in the overflow partition. Now all operations that can > be done on a single partition must scan 2 million rows instead of 1 > million, just on the off chance that someone executed a DDL command > and didn't clean up after themselves. > > ...Robert
Re: Automating Partitions in PostgreSQL - Query on syntax
-------- Original-Nachricht -------- > Datum: Tue, 21 Apr 2009 13:36:19 -0400 > Von: Robert Haas > An: steven king > CC: Greg Stark , pgsql-hackers@postgresql.org, listas@guedesoft.net > Betreff: Re: [HACKERS] Automating Partitions in PostgreSQL - Query on syntax > > SWITCH > > CASE TABLE
Re: Automating Partitions in PostgreSQL - Query on syntax
Em Ter, 2009-04-21 às 19:33 +0530, Kedar Potdar escreveu: (...) > You can have multiple columns as partition key attributes and values > for these attributes should appear in the order specified. How would be the behavior if the partition keys are foreing key with ON UPDATE CASCADE? I'm thinking in the scenario that this is allowed we can do a update that don't satisfies the actual partition rule but another in other partition, so the data will be moved? This make senses? []s Dickson S. Guedes mail/xmpp: guedes@guedesoft.net - skype: guediz http://guedesoft.net - http://planeta.postgresql.org.br
Re: Automating Partitions in PostgreSQL - Query on syntax
Robert Haas writes: > I'm also not sure how skillful the constraint exclusion logic is at > proving theorems when CASE statements are involved. It's not at all, and unlikely to become so. However, I think worrying about that might be focusing on the wrong thing. If this patch expects us to still use theorem proving to handle partition exclusion, it's going at things in the wrong way from the get-go. The partitioning rules should be simple enough that they can easily be applied at runtime to determine which partition to look in. Which leads me to the same conclusion: anything as complicated as CASE is the wrong design. But perhaps for slightly different reasons. regards, tom lane
Re: Automating Partitions in PostgreSQL - Query on syntax
On Tue, Apr 21, 2009 at 2:29 PM, steven king wrote: >> Rather than SWITCH CASE ... you probably would >> want to reuse the existing PostgreSQL syntax of CASE WHEN >> ... > > I think - at first we've to ask for the problem we have to solve. > > The syntax it isnt. If we get confused with CASE of CASE THEN ELSE - we can use other keywords .. forinstance SWITCH ON USE ... that should not the problem. > > You talking about 1000s of partitions - I cant see that this is the major use-case of table partitioning .. Who wants thousands of partitions? It's come up in previous discussions on pgsql-hackers. Besides, even if you have only 100 partitions, a binary search requires only 8 comparisons whereas a linear search through a list requires 100. I'd be hesistant to say that doesn't matter without testing it; I suspect it WILL matter. > We simply need a tool to create partitions for common use-cases. Maybe we should provide two or more types of partitioning strategies. > > 1. key-range partitioning > 2. constraint exclusion partitioning > 3.? auto-partitioning (for performance issues only) Yep, probably. I don't think a "tool to create partitions for common use-cases" is very interesting. To really make partitioning work in a simple, reliable, and efficient fashion, you're going to need to do a lot more than that. Of course if you just want to make a simple tool, that's fine too, but in that case I'd recommend designing it as an add-on rather than something that modifies the core syntax of PostgreSQL, because I doubt you're going to have much luck getting a patch of that type accepted. ...Robert
Re: Automating Partitions in PostgreSQL - Query on syntax
Does sql standard defines it ? and another question, what about updating existing partitions, with no need to drop/recreate ?
Re: Automating Partitions in PostgreSQL - Query on syntax
-------- Original-Nachricht -------- > Datum: Tue, 21 Apr 2009 14:53:54 -0400 > Von: Robert Haas > An: steven king > CC: listas@guedesoft.net, pgsql-hackers@postgresql.org, stark@enterprisedb.com > Betreff: Re: [HACKERS] Automating Partitions in PostgreSQL - Query on syntax > Of course if you just want to make a simple tool, look your (?) idea for range-partitioning ... that solution is (in principle) very close to "my" constraints. the difference is, that I added the possability to evaluate "logical ranges" (-> values) before deciding the partition to be used. not more ... -- Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01
Re: Automating Partitions in PostgreSQL - Query on syntax
> Which leads me to the same conclusion: anything as complicated as CASE > is the wrong design. But perhaps for slightly different reasons. What I like about the sql CASE is, that it is expression based, and thus allows full flexibility in partitioning and is highly self documenting. Do we need to invent special syntax, or could we use common syntax and detect specific use cases and handle them specially ? e.g. "when a >= const1 and a < const2 ...; when a >= const2 and a < const3" - check a btree opclass exists for datatype of a- prove the partitions don't overlap- prove the btree order of the partitions- ... Andreas
Re: Automating Partitions in PostgreSQL - Query on syntax
Zeugswetter Andreas OSB sIT writes: >> Which leads me to the same conclusion: anything as complicated as CASE >> is the wrong design. But perhaps for slightly different reasons. > What I like about the sql CASE is, that it is expression based, and thus > allows full flexibility in partitioning and is highly self documenting. > Do we need to invent special syntax, or could we use common syntax and > detect specific use cases and handle them specially ? The problem with that approach is you still need to have an implementation for the non-specific cases. What I want is to design the syntax so that *only* the optimized special cases are possible. We should not waste time either on implementing the general case or on constantly re-deducing which special case applies. That's the Achilles heel of what we have now (ie, constraint exclusion via theorem proving) --- it's a beautifully general approach, but it's so general that it's hard to make any but the simplest cases work efficiently, and the runtime cost of proving *each time* that a special case applies is horrid. The KISS principle applies with a vengeance here. I think we should make the partitioning stuff handle only the simplest cases but do those well. Anybody who wants something more complex can still try to tackle it via the existing facilities. regards, tom lane
Re: Automating Partitions in PostgreSQL - Query on syntax
On Tue, 2009-04-21 at 14:51 -0400, Tom Lane wrote: > The partitioning > rules should be simple enough that they can easily be applied at > runtime to determine which partition to look in. +1 -- Simon Riggs www.2ndQuadrant.comPostgreSQL Training, Services and Support
Re: Automating Partitions in PostgreSQL - Query on syntax
On Wed, Apr 22, 2009 at 11:34 AM, Tom Lane wrote: > The KISS principle applies with a vengeance here. I think we should > make the partitioning stuff handle only the simplest cases but do those > well. Anybody who wants something more complex can still try to tackle > it via the existing facilities. +1. ...Robert