| 1220 | // |
| 1221 | |
| 1222 | void Optimizer::compileRelation(StreamType stream) |
| 1223 | { |
| 1224 | // We have found a base relation; record its stream number in the streams array |
| 1225 | // as a candidate for merging into a river |
| 1226 | |
| 1227 | compileStreams.add(stream); |
| 1228 | |
| 1229 | // If we have any booleans or sort fields, we may be able to |
| 1230 | // use an index to optimize them; retrieve the current format of |
| 1231 | // all indices at this time so we can determine if it's possible |
| 1232 | |
| 1233 | const bool needIndices = conjuncts.hasData() || (rse->rse_sorted || rse->rse_aggregate); |
| 1234 | |
| 1235 | const auto tail = &csb->csb_rpt[stream]; |
| 1236 | |
| 1237 | const auto relation = tail->csb_relation; |
| 1238 | fb_assert(relation); |
| 1239 | |
| 1240 | tail->csb_idx = nullptr; |
| 1241 | |
| 1242 | if (needIndices && !relation->rel_file && !relation->isVirtual()) |
| 1243 | { |
| 1244 | const auto relPages = relation->getPages(tdbb); |
| 1245 | IndexDescList idxList; |
| 1246 | BTR_all(tdbb, relation, idxList, relPages); |
| 1247 | |
| 1248 | if (idxList.hasData()) |
| 1249 | tail->csb_idx = FB_NEW_POOL(getPool()) IndexDescList(getPool(), idxList); |
| 1250 | |
| 1251 | if (tail->csb_plan) |
| 1252 | markIndices(tail, relation->rel_id); |
| 1253 | } |
| 1254 | |
| 1255 | const auto format = CMP_format(tdbb, csb, stream); |
| 1256 | tail->csb_cardinality = getCardinality(tdbb, relation, format); |
| 1257 | } |
| 1258 | |
| 1259 | |
| 1260 | // |
no test coverage detected