|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.90 2008/01/01 19:45:50 momjian Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.91 2008/01/11 04:02:18 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -838,33 +838,27 @@ has_join_restriction(PlannerInfo *root, RelOptInfo *rel)
|
838 | 838 | * Detect whether the specified relation can legally be joined
|
839 | 839 | * to any other rels using join clauses.
|
840 | 840 | *
|
841 |
| - * We consider only joins to single other relations. This is sufficient |
842 |
| - * to get a "true" result in most real queries, and an occasional erroneous |
843 |
| - * "false" will only cost a bit more planning time. The reason for this |
844 |
| - * limitation is that considering joins to other joins would require proving |
845 |
| - * that the other join rel can legally be formed, which seems like too much |
846 |
| - * trouble for something that's only a heuristic to save planning time. |
| 841 | + * We consider only joins to single other relations in the current |
| 842 | + * initial_rels list. This is sufficient to get a "true" result in most real |
| 843 | + * queries, and an occasional erroneous "false" will only cost a bit more |
| 844 | + * planning time. The reason for this limitation is that considering joins to |
| 845 | + * other joins would require proving that the other join rel can legally be |
| 846 | + * formed, which seems like too much trouble for something that's only a |
| 847 | + * heuristic to save planning time. (Note: we must look at initial_rels |
| 848 | + * and not all of the query, since when we are planning a sub-joinlist we |
| 849 | + * may be forced to make clauseless joins within initial_rels even though |
| 850 | + * there are join clauses linking to other parts of the query.) |
847 | 851 | */
|
848 | 852 | static bool
|
849 | 853 | has_legal_joinclause(PlannerInfo *root, RelOptInfo *rel)
|
850 | 854 | {
|
851 |
| - Index rti; |
| 855 | + ListCell *lc; |
852 | 856 |
|
853 |
| - for (rti = 1; rti < root->simple_rel_array_size; rti++) |
| 857 | + foreach(lc, root->initial_rels) |
854 | 858 | {
|
855 |
| - RelOptInfo *rel2 = root->simple_rel_array[rti]; |
| 859 | + RelOptInfo *rel2 = (RelOptInfo *) lfirst(lc); |
856 | 860 |
|
857 |
| - /* there may be empty slots corresponding to non-baserel RTEs */ |
858 |
| - if (rel2 == NULL) |
859 |
| - continue; |
860 |
| - |
861 |
| - Assert(rel2->relid == rti); /* sanity check on array */ |
862 |
| - |
863 |
| - /* ignore RTEs that are "other rels" */ |
864 |
| - if (rel2->reloptkind != RELOPT_BASEREL) |
865 |
| - continue; |
866 |
| - |
867 |
| - /* ignore RTEs that are already in "rel" */ |
| 861 | + /* ignore rels that are already in "rel" */ |
868 | 862 | if (bms_overlap(rel->relids, rel2->relids))
|
869 | 863 | continue;
|
870 | 864 |
|
|
0 commit comments