postgresql/src/backend
David Rowley 3373c71553 Speed up finding EquivalenceClasses for a given set of rels
Previously in order to determine which ECs a relation had members in, we
had to loop over all ECs stored in PlannerInfo's eq_classes and check if
ec_relids mentioned the relation.  For the most part, this was fine, as
generally, unless queries were fairly complex, the overhead of performing
the lookup would have not been that significant.  However, when queries
contained large numbers of joins and ECs, the overhead to find the set of
classes matching a given set of relations could become a significant
portion of the overall planning effort.

Here we allow a much more efficient method to access the ECs which match a
given relation or set of relations.  A new Bitmapset field in RelOptInfo
now exists to store the indexes into PlannerInfo's eq_classes list which
each relation is mentioned in.  This allows very fast lookups to find all
ECs belonging to a single relation.  When we need to lookup ECs belonging
to a given pair of relations, we can simply bitwise-AND the Bitmapsets from
each relation and use the result to perform the lookup.

We also take the opportunity to write a new implementation of
generate_join_implied_equalities which makes use of the new indexes.
generate_join_implied_equalities_for_ecs must remain as is as it can be
given a custom list of ECs, which we can't easily determine the indexes of.

This was originally intended to fix the performance penalty of looking up
foreign keys matching a join condition which was introduced by 100340e2d.
However, we're speeding up much more than just that here.

Author: David Rowley, Tom Lane
Reviewed-by: Tom Lane, Tomas Vondra
Discussion: https://postgr.es/m/6970.1545327857@sss.pgh.pa.us
2019-07-21 17:30:58 +12:00
..
access Fix nbtree metapage cache upgrade bug. 2019-07-18 13:22:56 -07:00
bootstrap Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
catalog Avoid using lcons and list_delete_first where it's easy to do so. 2019-07-17 11:15:34 -04:00
commands Use column collation for extended statistics 2019-07-20 16:37:37 +02:00
executor Further adjust SPITupleTable to provide a public row-count field. 2019-07-18 10:37:13 -04:00
foreign Update copyright for 2019 2019-01-02 12:44:25 -05:00
jit Fix more typos and inconsistencies in the tree 2019-06-17 16:13:16 +09:00
lib Fix inconsistencies in the code 2019-07-08 13:15:09 +09:00
libpq Represent Lists as expansible arrays, not chains of cons-cells. 2019-07-15 13:41:58 -04:00
main Replace @postgresql.org with @lists.postgresql.org for mailinglists 2019-01-19 19:06:35 +01:00
nodes Speed up finding EquivalenceClasses for a given set of rels 2019-07-21 17:30:58 +12:00
optimizer Speed up finding EquivalenceClasses for a given set of rels 2019-07-21 17:30:58 +12:00
parser Avoid using lcons and list_delete_first where it's easy to do so. 2019-07-17 11:15:34 -04:00
partitioning Represent Lists as expansible arrays, not chains of cons-cells. 2019-07-15 13:41:58 -04:00
po Translation updates 2019-06-17 15:30:20 +02:00
port Update stale comments, and fix comment typos. 2019-06-08 10:12:26 -07:00
postmaster Fix inconsistencies in the code 2019-07-08 13:15:09 +09:00
regex Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
replication Redesign the API for list sorting (list_qsort becomes list_sort). 2019-07-16 11:51:44 -04:00
rewrite Avoid using lcons and list_delete_first where it's easy to do so. 2019-07-17 11:15:34 -04:00
snowball Sync our Snowball stemmer dictionaries with current upstream 2019-07-04 13:26:48 +02:00
statistics Use column collation for extended statistics 2019-07-20 16:37:37 +02:00
storage Move some md.c-specific logic from smgr.c to md.c. 2019-07-17 15:00:22 +12:00
tcop Represent Lists as expansible arrays, not chains of cons-cells. 2019-07-15 13:41:58 -04:00
tsearch Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
utils Fix error in commit e6feef57. 2019-07-18 17:04:50 -07:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Get rid of jsonpath_gram.h and jsonpath_scanner.h 2019-03-20 11:13:34 +03:00
nls.mk Translation updates 2019-05-20 16:00:53 +02:00