pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Speed-up build of MCV lists with many distinct values 2+ messages / 1 participants [nested] [flat]
* pgsql: Speed-up build of MCV lists with many distinct values @ 2019-07-05 01:06 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Tomas Vondra @ 2019-07-05 01:06 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Speed-up build of MCV lists with many distinct values When building multi-column MCV lists, we compute base frequency for each item, i.e. a product of per-column frequencies for values from the item. As a value may be in multiple groups, the code was scanning the whole array of groups while adding items to the MCV list. This works fine as long as the number of distinct groups is small, but it's easy to trigger trigger O(N^2) behavior, especially after increasing statistics target. This commit precomputes frequencies for values in all columns, so that when computing the base frequency it's enough to make a simple bsearch lookup in the array. Backpatch to 12, where multi-column MCV lists were introduced. Discussion: https://postgr.es/m/20190618205920.qtlzcu73whfpfqne@development Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/e365a581c246a8e18f38cc530013391329dcdb02 Modified Files -------------- src/backend/statistics/mcv.c | 130 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 8 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Speed-up build of MCV lists with many distinct values @ 2019-07-05 15:55 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Tomas Vondra @ 2019-07-05 15:55 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Speed-up build of MCV lists with many distinct values When building multi-column MCV lists, we compute base frequency for each item, i.e. a product of per-column frequencies for values from the item. As a value may be in multiple groups, the code was scanning the whole array of groups while adding items to the MCV list. This works fine as long as the number of distinct groups is small, but it's easy to trigger trigger O(N^2) behavior, especially after increasing statistics target. This commit precomputes frequencies for values in all columns, so that when computing the base frequency it's enough to make a simple bsearch lookup in the array. Backpatch to 12, where multi-column MCV lists were introduced. Discussion: https://postgr.es/m/20190618205920.qtlzcu73whfpfqne@development Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/57f459cf6c48e78aa321ac88418815fc65197517 Modified Files -------------- src/backend/statistics/mcv.c | 130 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 8 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2019-07-05 15:55 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-07-05 01:06 pgsql: Speed-up build of MCV lists with many distinct values Tomas Vondra <tomas.vondra@postgresql.org> 2019-07-05 15:55 pgsql: Speed-up build of MCV lists with many distinct values Tomas Vondra <tomas.vondra@postgresql.org>
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