- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitd69d45a
Speedup child EquivalenceMember lookup in planner
When planning queries to partitioned tables, we clone allEquivalenceMembers belonging to the partitioned table into em_is_childEquivalenceMembers for each non-pruned partition. For partitioned tableswith large numbers of partitions, this meant the ec_members list couldbecome large and code searching that list would become slow. Effectively,the more partitions which were present, the more searches needed to beperformed for operations such as find_ec_member_matching_expr() duringcreate_plan() and the more partitions present, the longer these searcheswould take, i.e., a quadratic slowdown.To fix this, here we adjust how we store EquivalenceMembers forem_is_child members. Instead of storing these directly in ec_members,these are now stored in a new array of Lists in the EquivalenceClass,which is indexed by the relid. When we want to find EquivalenceMembersbelonging to a certain child relation, we can narrow the search to thearray element for that relation.To make EquivalenceMember lookup easier and to reduce the amount of codechange, this commit provides a pair of functions to allow iteration overthe EquivalenceMembers of an EC which also handles finding the childmembers, if required. Callers that never need to look at child memberscan remain using the foreach loop over ec_members, which will now oftenbe faster due to only parent-level members being stored there.The actual performance increases here are highly dependent on the numberof partitions and the query being planned. Performance increases can bevisible with as few as 8 partitions, but the speedup is marginal forsuch low numbers of partitions. The speedups become much more visiblewith a few dozen to hundreds of partitions. With some tested queriesusing 56 partitions, the planner was around 3x faster than before. Foruse cases with thousands of partitions, these are likely to becomesignificantly faster. Some testing has shown planner speedups of 60x ormore with 8192 partitions.Author: Yuya Watari <watari.yuya@gmail.com>Co-authored-by: David Rowley <dgrowleyml@gmail.com>Reviewed-by: David Rowley <dgrowleyml@gmail.com>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Reviewed-by: Andrey Lepikhov <a.lepikhov@postgrespro.ru>Reviewed-by: Alena Rybakina <lena.ribackina@yandex.ru>Reviewed-by: Dmitry Dolgov <9erthalion6@gmail.com>Reviewed-by: Amit Langote <amitlangote09@gmail.com>Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>Tested-by: Thom Brown <thom@linux.com>Tested-by: newtglobal postgresql_contributors <postgresql_contributors@newtglobalcorp.com>Discussion:https://postgr.es/m/CAJ2pMkZNCgoUKSE%2B_5LthD%2BKbXKvq6h2hQN8Esxpxd%2Bcxmgomg%40mail.gmail.com1 parent105b2cb commitd69d45a
File tree
9 files changed
+446
-120
lines changed- contrib/postgres_fdw
- src
- backend
- nodes
- optimizer
- path
- plan
- include
- nodes
- optimizer
- tools/pgindent
9 files changed
+446
-120
lines changedLines changed: 10 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
7847 | 7847 |
| |
7848 | 7848 |
| |
7849 | 7849 |
| |
7850 |
| - | |
7851 |
| - | |
7852 | 7850 |
| |
| 7851 | + | |
| 7852 | + | |
7853 | 7853 |
| |
7854 |
| - | |
| 7854 | + | |
| 7855 | + | |
7855 | 7856 |
| |
7856 |
| - | |
7857 |
| - | |
7858 | 7857 |
| |
7859 | 7858 |
| |
7860 | 7859 |
| |
| |||
7908 | 7907 |
| |
7909 | 7908 |
| |
7910 | 7909 |
| |
7911 |
| - | |
| 7910 | + | |
| 7911 | + | |
| 7912 | + | |
| 7913 | + | |
7912 | 7914 |
| |
7913 | 7915 |
| |
7914 | 7916 |
| |
| |||
7918 | 7920 |
| |
7919 | 7921 |
| |
7920 | 7922 |
| |
7921 |
| - | |
7922 |
| - | |
7923 |
| - | |
| 7923 | + | |
| 7924 | + | |
7924 | 7925 |
| |
7925 | 7926 |
| |
7926 | 7927 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
465 | 465 |
| |
466 | 466 |
| |
467 | 467 |
| |
| 468 | + | |
468 | 469 |
| |
| 470 | + | |
469 | 471 |
| |
470 | 472 |
| |
471 | 473 |
| |
|
0 commit comments
Comments
(0)