diff --git a/src/jrd/RecordSourceNodes.cpp b/src/jrd/RecordSourceNodes.cpp index 3d2ba96cbc..5f75e756a3 100644 --- a/src/jrd/RecordSourceNodes.cpp +++ b/src/jrd/RecordSourceNodes.cpp @@ -2939,7 +2939,10 @@ void RseNode::pass1Source(thread_db* tdbb, CompilerScratch* csb, RseNode* rse, // where we are just trying to inner join more than 2 streams. If possible, // try to flatten the tree out before we go any further. - if (!rse->rse_jointype && !rse_jointype && !rse_sorted && !rse_projection && + const auto isLateral = (this->flags & RseNode::FLAG_LATERAL) != 0; + + if (!isLateral && !rse->rse_jointype && !rse_jointype && + !rse_sorted && !rse_projection && !rse_first && !rse_skip && !rse_plan) { NestConst* arg = rse_relations.begin();