Unix Technical Forum

table partioning performance

This is a discussion on table partioning performance within the Pgsql Performance forums, part of the PostgreSQL category; --> Hi there, we've partioned a table (using 8.2) by day due to the 50TB of data (500k row size, ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 09:02 AM
Colin Taylor
 
Posts: n/a
Default table partioning performance

Hi there, we've partioned a table (using 8.2) by day due to the 50TB of
data (500k row size, 100G rows) we expect to store it in a year.
Our performance on inserts and selects against the master table is
disappointing, 10x slower (with ony 1 partition constraint) than we get by
going to the partioned table directly. Browsing the list I get the
impression this just a case of too many partitions? would be better off
doing partitions of partitions ?

Any other advice or pointers to more information with dealing with these
sorts of scales appreciated.

thanks
Colin.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 09:02 AM
Luke Lonergan
 
Posts: n/a
Default Re: table partioning performance

Colin,


On 1/6/07 8:37 PM, "Colin Taylor" <colin.taylor@gmail.com> wrote:

> Hi there, we've partioned a table (using 8.2) by day due to the 50TB of data
> (500k row size, 100G rows) we expect to store it in a year.
> Our performance on inserts and selects against the master table is
> disappointing, 10x slower (with ony 1 partition constraint) than we get by
> going to the partioned table directly. Browsing the list I get the impression
> this just a case of too many partitions? would be better off doing partitions
> of partitions ?


Can you post an "explain analyze" of your query here so we can see what's
going on?

- Luke



---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 09:02 AM
Steven Flatt
 
Posts: n/a
Default Re: table partioning performance

On 1/6/07, Colin Taylor <colin.taylor@gmail.com> wrote:

> Hi there, we've partioned a table (using 8.2) by day due to the 50TB of
> data (500k row size, 100G rows) we expect to store it in a year.
> Our performance on inserts and selects against the master table is
> disappointing, 10x slower (with ony 1 partition constraint) than we get by
> going to the partioned table directly.



Are you implementing table partitioning as described at:
http://developer.postgresql.org/pgdo...titioning.html ?

If yes, and if I understand your partitioning "by day" correctly, then you
have one base/master table with 366 partitions (inherited/child tables). Do
each of these partitions have check constraints and does your master table
use rules to redirect inserts to the appropriate partition? I guess I don't
understand your "only 1 partition constraint" comment.

We use partitioned tables extensively and we have observed linear
performance degradation on inserts as the number of rules on the master
table grows (i.e. number of rules = number of partitions). We had to come
up with a solution that didn't have a rule per partition on the master
table. Just wondering if you are observing the same thing.

Selects shouldn't be affected in the same way, theoretically, if you have
constraint_exclusion enabled.

Steve

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 09:02 AM
Merlin Moncure
 
Posts: n/a
Default Re: table partioning performance

On 1/7/07, Colin Taylor <colin.taylor@gmail.com> wrote:
> Hi there, we've partioned a table (using 8.2) by day due to the 50TB of
> data (500k row size, 100G rows) we expect to store it in a year.
> Our performance on inserts and selects against the master table is
> disappointing, 10x slower (with ony 1 partition constraint) than we get by
> going to the partioned table directly. Browsing the list I get the
> impression this just a case of too many partitions? would be better off
> doing partitions of partitions ?
>
> Any other advice or pointers to more information with dealing with these
> sorts of scales appreciated.


as others have stated, something is not set up correctly. table
partitioning with constraint exclusion should be considerably faster
for situations were the planner can optimize for it (select queries
are case dependent, but inserts are not).

also, I would like to speak for everybody else here and ask for as
much detail as possible about the hardware and software challenges you
are solving :-) in particular, I am curious how you arrived at 500k
row size.

merlin

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-19-2008, 09:02 AM
Simon Riggs
 
Posts: n/a
Default Re: table partioning performance

On Mon, 2007-01-08 at 15:02 -0500, Steven Flatt wrote:
> On 1/6/07, Colin Taylor <colin.taylor@gmail.com> wrote:
> Hi there, we've partioned a table (using 8.2) by day due to
> the 50TB of data (500k row size, 100G rows) we expect to store
> it in a year.
> Our performance on inserts and selects against the master
> table is disappointing, 10x slower (with ony 1 partition
> constraint) than we get by going to the partioned table
> directly.
>
> Are you implementing table partitioning as described at:
> http://developer.postgresql.org/pgdo...titioning.html ?
>
> If yes, and if I understand your partitioning "by day" correctly, then
> you have one base/master table with 366 partitions (inherited/child
> tables). Do each of these partitions have check constraints and does
> your master table use rules to redirect inserts to the appropriate
> partition? I guess I don't understand your "only 1 partition
> constraint" comment.
>
> We use partitioned tables extensively and we have observed linear
> performance degradation on inserts as the number of rules on the
> master table grows (i.e. number of rules = number of partitions). We
> had to come up with a solution that didn't have a rule per partition
> on the master table. Just wondering if you are observing the same
> thing.


If you are doing date range partitioning it should be fairly simple to
load data into the latest table directly. That was the way I originally
intended for it to be used. The rules approach isn't something I'd
recommend as a bulk loading option and its a lot more complex anyway.

> Selects shouldn't be affected in the same way, theoretically, if you
> have constraint_exclusion enabled.


Selects can incur parsing overhead if there are a large number of
partitions. That will be proportional to the number of partitions, at
present.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com



---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-19-2008, 09:03 AM
Jim C. Nasby
 
Posts: n/a
Default Re: table partioning performance

On Mon, Jan 08, 2007 at 03:02:24PM -0500, Steven Flatt wrote:
> We use partitioned tables extensively and we have observed linear
> performance degradation on inserts as the number of rules on the master
> table grows (i.e. number of rules = number of partitions). We had to come
> up with a solution that didn't have a rule per partition on the master
> table. Just wondering if you are observing the same thing.


Except for the simplest partitioning cases, you'll be much better off
using a trigger on the parent table to direct inserts/updates/deletes to
the children. As a bonus, using a trigger makes it a lot more realistic
to deal with an update moving data between partitions.
--
Jim Nasby jim@nasby.net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-19-2008, 09:04 AM
Steven Flatt
 
Posts: n/a
Default Re: table partioning performance

On 1/9/07, Simon Riggs <simon@2ndquadrant.com> wrote:
>
> If you are doing date range partitioning it should be fairly simple to
> load data into the latest table directly. That was the way I originally
> intended for it to be used. The rules approach isn't something I'd
> recommend as a bulk loading option and its a lot more complex anyway.
>

The problem we have with blindly loading all data into the latest table is
that some data (< 5%, possibly even much less) is actually delivered "late"
and belongs in earlier partitions. So we still needed the ability to send
data to an arbitrary partition.

Steve

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-19-2008, 09:04 AM
Steven Flatt
 
Posts: n/a
Default Re: table partioning performance

On 1/10/07, Jim C. Nasby <jim@nasby.net> wrote:
>
> Except for the simplest partitioning cases, you'll be much better off
> using a trigger on the parent table to direct inserts/updates/deletes to
> the children. As a bonus, using a trigger makes it a lot more realistic
> to deal with an update moving data between partitions.



In our application, data is never moved between partitions.

The problem I found with triggers is the non-robustness of the PLpgSQL
record data type. For example, in an "on insert" trigger, I can't determine
the fields of the NEW record unless I hard code the column names into the
trigger. This makes it hard to write a generic trigger, which I can use for
all our partitioned tables. It would have been somewhat of a pain to write
a separate trigger for each of our partitioned tables.

For that and other reasons, we moved some of the insert logic up to the
application level in our product.

Steve

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-19-2008, 09:04 AM
Jim C. Nasby
 
Posts: n/a
Default Re: table partioning performance

On Wed, Jan 10, 2007 at 04:39:06PM -0500, Steven Flatt wrote:
> On 1/10/07, Jim C. Nasby <jim@nasby.net> wrote:
> >
> >Except for the simplest partitioning cases, you'll be much better off
> >using a trigger on the parent table to direct inserts/updates/deletes to
> >the children. As a bonus, using a trigger makes it a lot more realistic
> >to deal with an update moving data between partitions.

>
>
> In our application, data is never moved between partitions.
>
> The problem I found with triggers is the non-robustness of the PLpgSQL
> record data type. For example, in an "on insert" trigger, I can't determine
> the fields of the NEW record unless I hard code the column names into the
> trigger. This makes it hard to write a generic trigger, which I can use for
> all our partitioned tables. It would have been somewhat of a pain to write
> a separate trigger for each of our partitioned tables.
>
> For that and other reasons, we moved some of the insert logic up to the
> application level in our product.


Yeah, I think the key there would be to produce a function that wrote
the function for you.
--
Jim Nasby jim@nasby.net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-19-2008, 09:04 AM
Simon Riggs
 
Posts: n/a
Default Re: table partioning performance

On Wed, 2007-01-10 at 16:00 -0500, Steven Flatt wrote:
> On 1/9/07, Simon Riggs <simon@2ndquadrant.com> wrote:
> If you are doing date range partitioning it should be fairly
> simple to
> load data into the latest table directly. That was the way I
> originally
> intended for it to be used. The rules approach isn't something
> I'd
> recommend as a bulk loading option and its a lot more complex
> anyway.
> The problem we have with blindly loading all data into the latest
> table is that some data (< 5%, possibly even much less) is actually
> delivered "late" and belongs in earlier partitions. So we still
> needed the ability to send data to an arbitrary partition.


Yes, understand the problem.

COPY is always going to be faster than INSERTs anyhow and COPY doesn't
allow views, nor utilise rules. You can set up a client-side program to
pre-qualify the data and feed it to multiple simultaneous COPY commands,
as the best current way to handle this.

--
Next section aimed at pgsql-hackers, relates directly to above:


My longer term solution looks like this:

1. load all data into newly created partition (optimised in a newly
submitted patch for 8.3), then add the table as a new partition

2. use a newly created, permanent "errortable" into which rows that
don't match constraints or have other formatting problems would be put.
Following the COPY you would then run an INSERT SELECT to load the
remaining rows from the errortable into their appropriate tables. The
INSERT statement could target the parent table, so that rules to
distribute the rows would be applied appropriately. When all of those
have happened, drop the errortable. This would allow the database to
apply its constraints accurately without aborting the load when a
constraint error occurs.

In the use case you outline this would provide a fast path for 95% of
the data load, plus a straightforward mechanism for the remaining 5%.

We discussed this on hackers earlier, though we had difficulty with
handling unique constraint errors, so the idea was shelved. The
errortable part of the concept was sound however.
http://archives.postgresql.org/pgsql...1/msg01100.php
James William Pye had a similar proposal
http://archives.postgresql.org/pgsql...2/msg00120.php

The current TODO says
"Allow COPY to report error lines and continue
This requires the use of a savepoint before each COPY line is processed,
with ROLLBACK on COPY failure."

If we agreed that the TODO actually has two parts to it, each of which
is separately implementable:
1. load errors to a table (all errors apart from uniqueness violation)
2. do something sensible with unique violation ERRORs

IMHO part (1) can be implemented without Savepoints, which testing has
shown (see James' results) would not be an acceptable solution for bulk
data loading. So (1) can be implemented fairly easily, whereas (2)
remains an issue that we have no acceptable solution for, as yet.

Can we agree to splitting the TODO into two parts? That way we stand a
chance of getting at least some functionality in this important area.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:34 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com