pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14263: Query planner is slow to plan UPDATE on a table with many partitions
4+ messages / 4 participants
[nested] [flat]
* BUG #14263: Query planner is slow to plan UPDATE on a table with many partitions
@ 2016-07-22 06:20 shirshegsm@gmail.com
0 siblings, 1 reply; 4+ messages in thread
From: shirshegsm@gmail.com @ 2016-07-22 06:20 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14263
Logged by: Linas Valiukas
Email address: shirshegsm@gmail.com
PostgreSQL version: 9.3.13
Operating system: Ubuntu 12.04.5 LTS
Description:
Hi there,
We have a partitioned table, "bitly_clicks_total", with 600 partitions, up
to 1m rows in each sub-table. Property constraint_exclusion is
'partition'.
SELECTs on said table work as expected, but UPDATEs spend a lot of time on
query planner phase, even though executing the plan afterwards is very fast,
i.e. see https://paste.fedoraproject.org/393750/16797914/.
Here's a way to replicate the issue on an empty table with 600 partitions
too, so it doesn't depend on the number of rows in the partitioned table:
https://paste.fedoraproject.org/393751/91680241/
After some discussion on #postgresql @ Freenode (abridged version:
https://paste.fedoraproject.org/393752/16805914/), it seems that the query
planner has O(n^2) complexity for the number of partitions in a partitioned
table. Thus, I've been advised to split the table into less partitions, but
I found it unexpected that a sheer number of tables could slow down UPDATEs
like that, so I think that this behaviour could be at very least documented
accordingly.
Regards,
Linas
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #14263: Query planner is slow to plan UPDATE on a table with many partitions
@ 2016-07-22 13:39 Andrew Gierth <andrew@tao11.riddles.org.uk>
parent: shirshegsm@gmail.com
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Gierth @ 2016-07-22 13:39 UTC (permalink / raw)
To: shirshegsm@gmail.com; +Cc: pgsql-bugs
>>>>> "shirshegsm" == shirshegsm <shirshegsm@gmail.com> writes:
shirshegsm> After some discussion on #postgresql @ Freenode (abridged
shirshegsm> version: https://paste.fedoraproject.org/393752/16805914/),
shirshegsm> it seems that the query planner has O(n^2) complexity for
shirshegsm> the number of partitions in a partitioned table.
To sum up my part of that discussion: the repeated calls to
adjust_appendrel_attrs cause an O(N^2) number of calls to palloc, as
query_tree_mutator calls range_table_mutator which does two pallocs per
RTE (one for the RTE and one for the listcell).
Also none of those get freed, as far as I can tell, so the memory usage
is O(N^2) too.
--
Andrew (irc:RhodiumToad)
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
* BUG #14263: Query planner is slow to plan UPDATE on a table with many partitions
@ 2017-01-18 09:58 Joel Sanger <joelsanger@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Joel Sanger @ 2017-01-18 09:58 UTC (permalink / raw)
To: pgsql-bugs
Hi all,
Just to keep this bug current, I am also experiencing the same issue. I'm
using PostgreSQL 9.6.1 on Debian 8.6.
As an example, i have a table with a *very* large number of partitions. A
simple select clause has a planning time of 600ms where as the same clause
as an update results in a 8300ms planning time.
Unfortunately the partitioning scheme we have is ideal for our regular
workflow, so using less partitions isn't practical.
If there's any update, plans to fix (or not) that would be appreciated.
Thanks,
Joel
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #14263: Query planner is slow to plan UPDATE on a table with many partitions
@ 2017-01-18 14:08 Stephen Frost <sfrost@snowman.net>
parent: Joel Sanger <joelsanger@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Frost @ 2017-01-18 14:08 UTC (permalink / raw)
To: Joel Sanger <joelsanger@gmail.com>; +Cc: pgsql-bugs
Greetings Joel,
* Joel Sanger (joelsanger@gmail.com) wrote:
> Just to keep this bug current, I am also experiencing the same issue. I'm
> using PostgreSQL 9.6.1 on Debian 8.6.
>
> As an example, i have a table with a *very* large number of partitions. A
> simple select clause has a planning time of 600ms where as the same clause
> as an update results in a 8300ms planning time.
>
> Unfortunately the partitioning scheme we have is ideal for our regular
> workflow, so using less partitions isn't practical.
>
> If there's any update, plans to fix (or not) that would be appreciated.
The short answer is "it's being actively worked on." The slightly
longer answer is that the next version of PG (PG10) is going to have
declarative partitioning, such that you can actually say something like
"ALTER TABLE ... ATTACH PARTITION FOR VALUES FROM x TO y".
That is just the start and we don't (yet) have code committed to improve
planning time when using declarative partitioning, but it's being worked
on and it might make it in time for PG10, or it might not.
If you're really curious and interested in all of this, the right place
to discuss it is on the pgsql-hackers list. If you don't want to follow
all of that traffic then I would suggest you watch
https://planet.postgresql.org as there will surely be blog posts about
all of this as patches are committed to improve things in this area.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2017-01-18 14:08 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-07-22 06:20 BUG #14263: Query planner is slow to plan UPDATE on a table with many partitions shirshegsm@gmail.com
2016-07-22 13:39 ` Andrew Gierth <andrew@tao11.riddles.org.uk>
2017-01-18 09:58 BUG #14263: Query planner is slow to plan UPDATE on a table with many partitions Joel Sanger <joelsanger@gmail.com>
2017-01-18 14:08 ` Stephen Frost <sfrost@snowman.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox