* build_paths_for_OR * Given a list of restriction clauses from one arm of an OR clause, * construct all matching IndexPaths for the relation. * * Here we must scan all indexes of the relation, since a bitmap OR tree * can use multiple indexes. * * The caller actually supplies two lists of restriction clauses: some * "current" ones and some "other" ones. Both lists can be used freely
| 1200 | * 'other_clauses' is the list of additional upper-level clauses |
| 1201 | */ |
| 1202 | static List * |
| 1203 | build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel, |
| 1204 | List *clauses, List *other_clauses) |
| 1205 | { |
| 1206 | List *result = NIL; |
| 1207 | List *all_clauses = NIL; /* not computed till needed */ |
| 1208 | ListCell *lc; |
| 1209 | |
| 1210 | foreach(lc, rel->indexlist) |
| 1211 | { |
| 1212 | IndexOptInfo *index = (IndexOptInfo *) lfirst(lc); |
| 1213 | IndexClauseSet clauseset; |
| 1214 | List *indexpaths; |
| 1215 | bool useful_predicate; |
| 1216 | |
| 1217 | /* Ignore index if it doesn't support bitmap scans */ |
| 1218 | if (!index->amhasgetbitmap) |
| 1219 | continue; |
| 1220 | |
| 1221 | /* |
| 1222 | * Ignore partial indexes that do not match the query. If a partial |
| 1223 | * index is marked predOK then we know it's OK. Otherwise, we have to |
| 1224 | * test whether the added clauses are sufficient to imply the |
| 1225 | * predicate. If so, we can use the index in the current context. |
| 1226 | * |
| 1227 | * We set useful_predicate to true iff the predicate was proven using |
| 1228 | * the current set of clauses. This is needed to prevent matching a |
| 1229 | * predOK index to an arm of an OR, which would be a legal but |
| 1230 | * pointlessly inefficient plan. (A better plan will be generated by |
| 1231 | * just scanning the predOK index alone, no OR.) |
| 1232 | */ |
| 1233 | useful_predicate = false; |
| 1234 | if (index->indpred != NIL) |
| 1235 | { |
| 1236 | if (index->predOK) |
| 1237 | { |
| 1238 | /* Usable, but don't set useful_predicate */ |
| 1239 | } |
| 1240 | else |
| 1241 | { |
| 1242 | /* Form all_clauses if not done already */ |
| 1243 | if (all_clauses == NIL) |
| 1244 | all_clauses = list_concat_copy(clauses, other_clauses); |
| 1245 | |
| 1246 | if (!predicate_implied_by(index->indpred, all_clauses, false)) |
| 1247 | continue; /* can't use it at all */ |
| 1248 | |
| 1249 | if (!predicate_implied_by(index->indpred, other_clauses, false)) |
| 1250 | useful_predicate = true; |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | /* |
| 1255 | * Identify the restriction clauses that can match the index. |
| 1256 | */ |
| 1257 | MemSet(&clauseset, 0, sizeof(clauseset)); |
| 1258 | match_clauses_to_index(root, clauses, index, &clauseset); |
| 1259 |
no test coverage detected