Actually, due to some parallel developments, generateOutputSchema turns out to be not a very good place for this code.
Here's a suggestion: Create and use an alternative NestLoopIndexPlanNode constructor that accepts the two child plan nodes as arguments and includes ALL of this m_sortDirection determination.