| 404 | } |
| 405 | |
| 406 | bool HashJoin::internalGetRecord(thread_db* tdbb) const |
| 407 | { |
| 408 | JRD_reschedule(tdbb); |
| 409 | |
| 410 | Request* const request = tdbb->getRequest(); |
| 411 | Impure* const impure = request->getImpure<Impure>(m_impure); |
| 412 | |
| 413 | if (!(impure->irsb_flags & irsb_open)) |
| 414 | return false; |
| 415 | |
| 416 | const auto inner = m_args.front().source; |
| 417 | |
| 418 | while (true) |
| 419 | { |
| 420 | if (impure->irsb_flags & irsb_mustread) |
| 421 | { |
| 422 | // Fetch the record from the leading stream |
| 423 | |
| 424 | if (!m_leader.source->getRecord(tdbb)) |
| 425 | return false; |
| 426 | |
| 427 | if (m_boolean && !m_boolean->execute(tdbb, request)) |
| 428 | { |
| 429 | // The boolean pertaining to the left sub-stream is false |
| 430 | // so just join sub-stream to a null valued right sub-stream |
| 431 | inner->nullRecords(tdbb); |
| 432 | return true; |
| 433 | } |
| 434 | |
| 435 | // We have something to join with, so ensure the hash table is initialized |
| 436 | |
| 437 | if (!impure->irsb_hash_table && !impure->irsb_leader_buffer) |
| 438 | { |
| 439 | auto& pool = *tdbb->getDefaultPool(); |
| 440 | const auto argCount = m_args.getCount(); |
| 441 | |
| 442 | impure->irsb_hash_table = FB_NEW_POOL(pool) HashTable(pool, argCount); |
| 443 | impure->irsb_leader_buffer = FB_NEW_POOL(pool) UCHAR[m_leader.totalKeyLength]; |
| 444 | |
| 445 | UCharBuffer buffer(pool); |
| 446 | |
| 447 | for (FB_SIZE_T i = 0; i < argCount; i++) |
| 448 | { |
| 449 | // Read and cache the inner streams. While doing that, |
| 450 | // hash the join condition values and populate hash tables. |
| 451 | |
| 452 | m_args[i].buffer->open(tdbb); |
| 453 | |
| 454 | ULONG counter = 0; |
| 455 | const auto keyBuffer = buffer.getBuffer(m_args[i].totalKeyLength, false); |
| 456 | |
| 457 | while (m_args[i].buffer->getRecord(tdbb)) |
| 458 | { |
| 459 | const auto hash = computeHash(tdbb, request, m_args[i], keyBuffer); |
| 460 | impure->irsb_hash_table->put(i, hash, counter++); |
| 461 | } |
| 462 | } |
| 463 |
nothing calls this directly
no test coverage detected