Skip to content

Commit 48b38a0

Browse files
committed
Fix #8628: Incorrect join order for JOIN LATERAL with UNION referencing the outer stream(s) via its select list
1 parent 8e38f19 commit 48b38a0

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/jrd/RecordSourceNodes.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,31 +2457,48 @@ RecordSource* UnionSourceNode::compile(thread_db* tdbb, Optimizer* opt, bool /*i
24572457
// Identify all of the streams for which a dbkey may need to be carried through a sort.
24582458
void UnionSourceNode::computeDbKeyStreams(StreamList& streamList) const
24592459
{
2460-
const NestConst<RseNode>* ptr = clauses.begin();
2461-
2462-
for (const NestConst<RseNode>* const end = clauses.end(); ptr != end; ++ptr)
2463-
(*ptr)->computeDbKeyStreams(streamList);
2460+
for (const auto& clause : clauses)
2461+
clause->computeDbKeyStreams(streamList);
24642462
}
24652463

24662464
bool UnionSourceNode::computable(CompilerScratch* csb, StreamType stream,
24672465
bool allowOnlyCurrentStream, ValueExprNode* /*value*/)
24682466
{
2469-
NestConst<RseNode>* ptr = clauses.begin();
2470-
2471-
for (NestConst<RseNode>* const end = clauses.end(); ptr != end; ++ptr)
2467+
for (auto& clause : clauses)
24722468
{
2473-
if (!(*ptr)->computable(csb, stream, allowOnlyCurrentStream, NULL))
2469+
if (!clause->computable(csb, stream, allowOnlyCurrentStream, NULL))
24742470
return false;
24752471
}
24762472

2473+
for (auto& map : maps)
2474+
{
2475+
for (auto& source : map->sourceList)
2476+
{
2477+
if (!source->computable(csb, stream, allowOnlyCurrentStream, NULL))
2478+
return false;
2479+
}
2480+
2481+
// dimitr: no need to process also map->targetList,
2482+
// as its nodes are purely local to the union stream
2483+
}
2484+
24772485
return true;
24782486
}
24792487

24802488
void UnionSourceNode::findDependentFromStreams(const CompilerScratch* csb,
24812489
StreamType currentStream, SortedStreamList* streamList)
24822490
{
2483-
for (auto clause : clauses)
2491+
for (auto& clause : clauses)
24842492
clause->findDependentFromStreams(csb, currentStream, streamList);
2493+
2494+
for (auto& map : maps)
2495+
{
2496+
for (auto& source : map->sourceList)
2497+
source->findDependentFromStreams(csb, currentStream, streamList);
2498+
2499+
// dimitr: no need to process also map->targetList,
2500+
// as its nodes are purely local to the union stream
2501+
}
24852502
}
24862503

24872504

0 commit comments

Comments
 (0)