| 351 | } |
| 352 | |
| 353 | bool NestedLoopJoin::fetchRecord(thread_db* tdbb, FB_SIZE_T n) const |
| 354 | { |
| 355 | fb_assert(m_joinType == INNER_JOIN); |
| 356 | |
| 357 | const RecordSource* const arg = m_args[n]; |
| 358 | |
| 359 | if (arg->getRecord(tdbb)) |
| 360 | return true; |
| 361 | |
| 362 | // We have exhausted this stream, so close it; if there is |
| 363 | // another candidate record from the n-1 streams to the left, |
| 364 | // then reopen the stream and start again from the beginning. |
| 365 | |
| 366 | while (true) |
| 367 | { |
| 368 | arg->close(tdbb); |
| 369 | |
| 370 | if (n == 0 || !fetchRecord(tdbb, n - 1)) |
| 371 | return false; |
| 372 | |
| 373 | arg->open(tdbb); |
| 374 | |
| 375 | if (arg->getRecord(tdbb)) |
| 376 | return true; |
| 377 | } |
| 378 | } |