* standard_join_search * Find possible joinpaths for a query by successively finding ways * to join component relations into join relations. * * 'levels_needed' is the number of iterations needed, ie, the number of * independent jointree items in the query. This is > 1. * * 'initial_rels' is a list of RelOptInfo nodes for each independent * jointree item. These are the components t
| 3814 | * original states of those data structures. See geqo_eval() for an example. |
| 3815 | */ |
| 3816 | RelOptInfo * |
| 3817 | standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels) |
| 3818 | { |
| 3819 | int lev; |
| 3820 | RelOptInfo *rel; |
| 3821 | RelOptInfo *rel_grouped; |
| 3822 | |
| 3823 | /* |
| 3824 | * This function cannot be invoked recursively within any one planning |
| 3825 | * problem, so join_rel_level[] can't be in use already. |
| 3826 | */ |
| 3827 | Assert(root->join_rel_level == NULL); |
| 3828 | |
| 3829 | /* |
| 3830 | * We employ a simple "dynamic programming" algorithm: we first find all |
| 3831 | * ways to build joins of two jointree items, then all ways to build joins |
| 3832 | * of three items (from two-item joins and single items), then four-item |
| 3833 | * joins, and so on until we have considered all ways to join all the |
| 3834 | * items into one rel. |
| 3835 | * |
| 3836 | * root->join_rel_level[j] is a list of all the j-item rels. Initially we |
| 3837 | * set root->join_rel_level[1] to represent all the single-jointree-item |
| 3838 | * relations. |
| 3839 | */ |
| 3840 | root->join_rel_level = (List **) palloc0((levels_needed + 1) * sizeof(List *)); |
| 3841 | |
| 3842 | root->join_rel_level[1] = initial_rels; |
| 3843 | |
| 3844 | for (lev = 2; lev <= levels_needed; lev++) |
| 3845 | { |
| 3846 | ListCell *lc; |
| 3847 | |
| 3848 | /* |
| 3849 | * Determine all possible pairs of relations to be joined at this |
| 3850 | * level, and build paths for making each one from every available |
| 3851 | * pair of lower-level relations. |
| 3852 | */ |
| 3853 | join_search_one_level(root, lev); |
| 3854 | |
| 3855 | /* |
| 3856 | * Run generate_partitionwise_join_paths() and |
| 3857 | * generate_useful_gather_paths() for each just-processed joinrel. We |
| 3858 | * could not do this earlier because both regular and partial paths |
| 3859 | * can get added to a particular joinrel at multiple times within |
| 3860 | * join_search_one_level. |
| 3861 | * |
| 3862 | * After that, we're done creating paths for the joinrel, so run |
| 3863 | * set_cheapest(). |
| 3864 | */ |
| 3865 | foreach(lc, root->join_rel_level[lev]) |
| 3866 | { |
| 3867 | rel = (RelOptInfo *) lfirst(lc); |
| 3868 | |
| 3869 | /* Create paths for partitionwise joins. */ |
| 3870 | generate_partitionwise_join_paths(root, rel); |
| 3871 | |
| 3872 | /* |
| 3873 | * Except for the topmost scan/join rel, consider gathering |
no test coverage detected