* create_index_paths() * Generate all interesting index paths for the given relation. * Candidate paths are added to the rel's pathlist (using add_path). * * To be considered for an index scan, an index must match one or more * restriction clauses or join clauses from the query's qual condition, * or match the query's ORDER BY condition, or have a predicate that * matches the query's qu
| 243 | * as meaning "unparameterized so far as the indexquals are concerned". |
| 244 | */ |
| 245 | void |
| 246 | create_index_paths(PlannerInfo *root, RelOptInfo *rel) |
| 247 | { |
| 248 | List *indexpaths; |
| 249 | List *bitindexpaths; |
| 250 | List *bitjoinpaths; |
| 251 | List *joinorclauses; |
| 252 | IndexClauseSet rclauseset; |
| 253 | IndexClauseSet jclauseset; |
| 254 | IndexClauseSet eclauseset; |
| 255 | ListCell *lc; |
| 256 | |
| 257 | /* Skip the whole mess if no indexes */ |
| 258 | if (rel->indexlist == NIL) |
| 259 | return; |
| 260 | |
| 261 | /* Bitmap paths are collected and then dealt with at the end */ |
| 262 | bitindexpaths = bitjoinpaths = joinorclauses = NIL; |
| 263 | |
| 264 | /* Examine each index in turn */ |
| 265 | foreach(lc, rel->indexlist) |
| 266 | { |
| 267 | IndexOptInfo *index = (IndexOptInfo *) lfirst(lc); |
| 268 | |
| 269 | /* Protect limited-size array in IndexClauseSets */ |
| 270 | Assert(index->nkeycolumns <= INDEX_MAX_KEYS); |
| 271 | |
| 272 | /* |
| 273 | * Ignore partial indexes that do not match the query. |
| 274 | * (generate_bitmap_or_paths() might be able to do something with |
| 275 | * them, but that's of no concern here.) |
| 276 | */ |
| 277 | if (index->indpred != NIL && !index->predOK) |
| 278 | continue; |
| 279 | |
| 280 | /* |
| 281 | * Identify the restriction clauses that can match the index. |
| 282 | */ |
| 283 | MemSet(&rclauseset, 0, sizeof(rclauseset)); |
| 284 | match_restriction_clauses_to_index(root, index, &rclauseset); |
| 285 | |
| 286 | /* |
| 287 | * Build index paths from the restriction clauses. These will be |
| 288 | * non-parameterized paths. Plain paths go directly to add_path(), |
| 289 | * bitmap paths are added to bitindexpaths to be handled below. |
| 290 | */ |
| 291 | get_index_paths(root, rel, index, &rclauseset, |
| 292 | &bitindexpaths); |
| 293 | |
| 294 | /* |
| 295 | * Identify the join clauses that can match the index. For the moment |
| 296 | * we keep them separate from the restriction clauses. Note that this |
| 297 | * step finds only "loose" join clauses that have not been merged into |
| 298 | * EquivalenceClasses. Also, collect join OR clauses for later. |
| 299 | */ |
| 300 | MemSet(&jclauseset, 0, sizeof(jclauseset)); |
| 301 | match_join_clauses_to_index(root, rel, index, |
| 302 | &jclauseset, &joinorclauses); |
no test coverage detected