|
10 | 10 | * Portions Copyright (c) 1994, Regents of the University of California
|
11 | 11 | *
|
12 | 12 | * IDENTIFICATION
|
13 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/path/equivclass.c,v 1.20 2009/09/12 00:04:58 tgl Exp $ |
| 13 | + * $PostgreSQL: pgsql/src/backend/optimizer/path/equivclass.c,v 1.21 2009/09/29 01:20:34 tgl Exp $ |
14 | 14 | *
|
15 | 15 | *-------------------------------------------------------------------------
|
16 | 16 | */
|
@@ -114,6 +114,19 @@ process_equivalence(PlannerInfo *root, RestrictInfo *restrictinfo,
|
114 | 114 | item1_relids = restrictinfo->left_relids;
|
115 | 115 | item2_relids = restrictinfo->right_relids;
|
116 | 116 |
|
| 117 | + /* |
| 118 | + * Reject clauses of the form X=X. These are not as redundant as they |
| 119 | + * might seem at first glance: assuming the operator is strict, this is |
| 120 | + * really an expensive way to write X IS NOT NULL. So we must not risk |
| 121 | + * just losing the clause, which would be possible if there is already |
| 122 | + * a single-element EquivalenceClass containing X. The case is not |
| 123 | + * common enough to be worth contorting the EC machinery for, so just |
| 124 | + * reject the clause and let it be processed as a normal restriction |
| 125 | + * clause. |
| 126 | + */ |
| 127 | + if (equal(item1, item2)) |
| 128 | + return false; /* X=X is not a useful equivalence */ |
| 129 | + |
117 | 130 | /*
|
118 | 131 | * If below outer join, check for strictness, else reject.
|
119 | 132 | */
|
@@ -152,13 +165,10 @@ process_equivalence(PlannerInfo *root, RestrictInfo *restrictinfo,
|
152 | 165 | *
|
153 | 166 | * 4. We find neither. Make a new, two-entry EC.
|
154 | 167 | *
|
155 |
| - * Note: since all ECs are built through this process, it's impossible |
156 |
| - * that we'd match an item in more than one existing EC. It is possible |
157 |
| - * to match more than once within an EC, if someone fed us something silly |
158 |
| - * like "WHERE X=X". (However, we can't simply discard such clauses, |
159 |
| - * since they should fail when X is null; so we will build a 2-member EC |
160 |
| - * to ensure the correct restriction clause gets generated. Hence there |
161 |
| - * is no shortcut here for item1 and item2 equal.) |
| 168 | + * Note: since all ECs are built through this process or the similar |
| 169 | + * search in get_eclass_for_sort_expr(), it's impossible that we'd match |
| 170 | + * an item in more than one existing nonvolatile EC. So it's okay to stop |
| 171 | + * at the first match. |
162 | 172 | */
|
163 | 173 | ec1 = ec2 = NULL;
|
164 | 174 | em1 = em2 = NULL;
|
|
0 commit comments