---------------------------------------------------------------- * ExecOpenIndices * * Find the indices associated with a result relation, open them, * and save information about them in the result ResultRelInfo. * * At entry, caller has already opened and locked * resultRelInfo->ri_RelationDesc. * ---------------------------------------------------------------- */
| 148 | * ---------------------------------------------------------------- |
| 149 | */ |
| 150 | void |
| 151 | ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative) |
| 152 | { |
| 153 | Relation resultRelation = resultRelInfo->ri_RelationDesc; |
| 154 | List *indexoidlist; |
| 155 | ListCell *l; |
| 156 | int len, |
| 157 | i; |
| 158 | RelationPtr relationDescs; |
| 159 | IndexInfo **indexInfoArray; |
| 160 | |
| 161 | resultRelInfo->ri_NumIndices = 0; |
| 162 | |
| 163 | /* fast path if no indexes */ |
| 164 | if (!RelationGetForm(resultRelation)->relhasindex) |
| 165 | return; |
| 166 | |
| 167 | /* |
| 168 | * Get cached list of index OIDs |
| 169 | */ |
| 170 | indexoidlist = RelationGetIndexList(resultRelation); |
| 171 | len = list_length(indexoidlist); |
| 172 | if (len == 0) |
| 173 | return; |
| 174 | |
| 175 | /* |
| 176 | * allocate space for result arrays |
| 177 | */ |
| 178 | relationDescs = (RelationPtr) palloc(len * sizeof(Relation)); |
| 179 | indexInfoArray = (IndexInfo **) palloc(len * sizeof(IndexInfo *)); |
| 180 | |
| 181 | resultRelInfo->ri_NumIndices = len; |
| 182 | resultRelInfo->ri_IndexRelationDescs = relationDescs; |
| 183 | resultRelInfo->ri_IndexRelationInfo = indexInfoArray; |
| 184 | |
| 185 | /* |
| 186 | * For each index, open the index relation and save pg_index info. We |
| 187 | * acquire RowExclusiveLock, signifying we will update the index. |
| 188 | * |
| 189 | * Note: we do this even if the index is not indisready; it's not worth |
| 190 | * the trouble to optimize for the case where it isn't. |
| 191 | */ |
| 192 | i = 0; |
| 193 | foreach(l, indexoidlist) |
| 194 | { |
| 195 | Oid indexOid = lfirst_oid(l); |
| 196 | Relation indexDesc; |
| 197 | IndexInfo *ii; |
| 198 | |
| 199 | indexDesc = index_open(indexOid, RowExclusiveLock); |
| 200 | |
| 201 | /* extract index key information from the index's pg_index info */ |
| 202 | ii = BuildIndexInfo(indexDesc); |
| 203 | |
| 204 | /* |
| 205 | * If the indexes are to be used for speculative insertion, add extra |
| 206 | * information required by unique index entries. |
| 207 | */ |
no test coverage detected