pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Improve performance of EXPLAIN with large range tables. 3+ messages / 1 participants [nested] [flat]
* pgsql: Improve performance of EXPLAIN with large range tables. @ 2015-01-15 18:18 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 3+ messages in thread From: Tom Lane @ 2015-01-15 18:18 UTC (permalink / raw) To: pgsql-committers Improve performance of EXPLAIN with large range tables. As of 9.3, ruleutils.c goes to some lengths to ensure that table and column aliases used in its output are unique. Of course this takes more time than was required before, which in itself isn't fatal. However, EXPLAIN was set up so that recalculation of the unique aliases was repeated for each subexpression printed in a plan. That results in O(N^2) time and memory consumption for large plan trees, which did not happen in older branches. Fortunately, the expensive work is the same across a whole plan tree, so there is no need to repeat it; we can do most of the initialization just once per query and re-use it for each subexpression. This buys back most (not all) of the performance loss since 9.2. We need an extra ExplainState field to hold the precalculated deparse context. That's no problem in HEAD, but in the back branches, expanding sizeof(ExplainState) seems risky because third-party extensions might have local variables of that struct type. So, in 9.4 and 9.3, introduce an auxiliary struct to keep sizeof(ExplainState) the same. We should refactor the APIs to avoid such local variables in future, but that's material for a separate HEAD-only commit. Per gripe from Alexey Bashtanov. Back-patch to 9.3 where the issue was introduced. Branch ------ master Details ------- http://git.postgresql.org/pg/commitdiff/a5cd70dcbc268381e13cb0b2973b5732856d186f Modified Files -------------- src/backend/commands/explain.c | 23 ++++++------ src/backend/utils/adt/ruleutils.c | 73 +++++++++++++++++++++++++------------ src/include/commands/explain.h | 1 + src/include/utils/ruleutils.h | 7 ++-- 4 files changed, 66 insertions(+), 38 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Improve performance of EXPLAIN with large range tables. @ 2015-01-15 18:18 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 3+ messages in thread From: Tom Lane @ 2015-01-15 18:18 UTC (permalink / raw) To: pgsql-committers Improve performance of EXPLAIN with large range tables. As of 9.3, ruleutils.c goes to some lengths to ensure that table and column aliases used in its output are unique. Of course this takes more time than was required before, which in itself isn't fatal. However, EXPLAIN was set up so that recalculation of the unique aliases was repeated for each subexpression printed in a plan. That results in O(N^2) time and memory consumption for large plan trees, which did not happen in older branches. Fortunately, the expensive work is the same across a whole plan tree, so there is no need to repeat it; we can do most of the initialization just once per query and re-use it for each subexpression. This buys back most (not all) of the performance loss since 9.2. We need an extra ExplainState field to hold the precalculated deparse context. That's no problem in HEAD, but in the back branches, expanding sizeof(ExplainState) seems risky because third-party extensions might have local variables of that struct type. So, in 9.4 and 9.3, introduce an auxiliary struct to keep sizeof(ExplainState) the same. We should refactor the APIs to avoid such local variables in future, but that's material for a separate HEAD-only commit. Per gripe from Alexey Bashtanov. Back-patch to 9.3 where the issue was introduced. Branch ------ REL9_4_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/d25192892d61419278fbb216e695cb070c332092 Modified Files -------------- src/backend/commands/explain.c | 29 ++++++++------- src/backend/utils/adt/ruleutils.c | 71 +++++++++++++++++++++++++------------ src/include/commands/explain.h | 9 ++++- src/include/utils/builtins.h | 5 +-- 4 files changed, 77 insertions(+), 37 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Improve performance of EXPLAIN with large range tables. @ 2015-01-15 18:18 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 3+ messages in thread From: Tom Lane @ 2015-01-15 18:18 UTC (permalink / raw) To: pgsql-committers Improve performance of EXPLAIN with large range tables. As of 9.3, ruleutils.c goes to some lengths to ensure that table and column aliases used in its output are unique. Of course this takes more time than was required before, which in itself isn't fatal. However, EXPLAIN was set up so that recalculation of the unique aliases was repeated for each subexpression printed in a plan. That results in O(N^2) time and memory consumption for large plan trees, which did not happen in older branches. Fortunately, the expensive work is the same across a whole plan tree, so there is no need to repeat it; we can do most of the initialization just once per query and re-use it for each subexpression. This buys back most (not all) of the performance loss since 9.2. We need an extra ExplainState field to hold the precalculated deparse context. That's no problem in HEAD, but in the back branches, expanding sizeof(ExplainState) seems risky because third-party extensions might have local variables of that struct type. So, in 9.4 and 9.3, introduce an auxiliary struct to keep sizeof(ExplainState) the same. We should refactor the APIs to avoid such local variables in future, but that's material for a separate HEAD-only commit. Per gripe from Alexey Bashtanov. Back-patch to 9.3 where the issue was introduced. Branch ------ REL9_3_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/939f0fb6765ef16874a4bd268efeb27cbc965e43 Modified Files -------------- src/backend/commands/explain.c | 29 ++++++++------- src/backend/utils/adt/ruleutils.c | 71 +++++++++++++++++++++++++------------ src/include/commands/explain.h | 9 ++++- src/include/utils/builtins.h | 5 +-- 4 files changed, 77 insertions(+), 37 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2015-01-15 18:18 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2015-01-15 18:18 pgsql: Improve performance of EXPLAIN with large range tables. Tom Lane <tgl@sss.pgh.pa.us> 2015-01-15 18:18 pgsql: Improve performance of EXPLAIN with large range tables. Tom Lane <tgl@sss.pgh.pa.us> 2015-01-15 18:18 pgsql: Improve performance of EXPLAIN with large range tables. Tom Lane <tgl@sss.pgh.pa.us>
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