| 283 | // |
| 284 | |
| 285 | bool InnerJoin::findJoinOrder() |
| 286 | { |
| 287 | bestStreams.clear(); |
| 288 | bestCount = 0; |
| 289 | remainingStreams = 0; |
| 290 | |
| 291 | #ifdef OPT_DEBUG |
| 292 | // Debug |
| 293 | printStartOrder(); |
| 294 | #endif |
| 295 | |
| 296 | for (const auto innerStream : innerStreams) |
| 297 | { |
| 298 | if (!innerStream->used) |
| 299 | { |
| 300 | remainingStreams++; |
| 301 | |
| 302 | if (innerStream->isIndependent()) |
| 303 | { |
| 304 | if (!bestCount || innerStream->baseCost < bestCost) |
| 305 | { |
| 306 | bestStreams.resize(1); |
| 307 | bestStreams.front().number = innerStream->number; |
| 308 | bestCount = 1; |
| 309 | bestCost = innerStream->baseCost; |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | if (bestCount == 0) |
| 316 | { |
| 317 | IndexedRelationships indexedRelationships; |
| 318 | |
| 319 | for (const auto innerStream : innerStreams) |
| 320 | { |
| 321 | if (!innerStream->used) |
| 322 | { |
| 323 | indexedRelationships.clear(); |
| 324 | findBestOrder(0, innerStream, indexedRelationships, 0.0, 1.0); |
| 325 | |
| 326 | if (plan) // if an explicit PLAN was specified we should be ready |
| 327 | break; |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | // Mark streams as used |
| 333 | for (const auto& stream : bestStreams) |
| 334 | { |
| 335 | auto streamInfo = getStreamInfo(stream.number); |
| 336 | streamInfo->used = true; |
| 337 | } |
| 338 | |
| 339 | #ifdef OPT_DEBUG |
| 340 | // Debug |
| 341 | printBestOrder(); |
| 342 | #endif |
no test coverage detected