MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / setPosition

Function setPosition

src/jrd/optimizer/Optimizer.cpp:550–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

548 }
549
550 void setPosition(const SortNode* from_clause, SortNode* to_clause, const MapNode* map)
551 {
552 // Update the fields in a GROUP BY, DISTINCT, or ORDER BY clause to the same position
553 // as another clause, possibly using a mapping between the streams.
554
555 // Track the position in the from list with "to_swap", and find the corresponding
556 // field in the from list with "to_ptr", then swap the two fields. By the time
557 // we get to the end of the from list, all fields in the to list will be reordered.
558
559 auto to_swap = to_clause->expressions.begin();
560
561 // We need to process no more than the number of nodes in the "from" clause
562
563 const auto count = from_clause->expressions.getCount();
564 fb_assert(count <= to_clause->expressions.getCount());
565
566 auto from_ptr = from_clause->expressions.begin();
567 for (const auto from_end = from_ptr + count; from_ptr != from_end; ++from_ptr)
568 {
569 NestConst<ValueExprNode>* to_ptr = to_clause->expressions.begin();
570 for (const auto to_end = to_ptr + count; to_ptr != to_end; ++to_ptr)
571 {
572 if ((map && mapEqual(*to_ptr, *from_ptr, map)) ||
573 (!map && fieldEqual(*to_ptr, *from_ptr)))
574 {
575 ValueExprNode* swap = *to_swap;
576 *to_swap = *to_ptr;
577 *to_ptr = swap;
578 }
579 }
580
581 ++to_swap;
582 }
583 }
584
585} // namespace
586

Callers 2

internalGetRecordMethod · 0.85
checkSortsMethod · 0.85

Calls 4

mapEqualFunction · 0.85
fieldEqualFunction · 0.85
beginMethod · 0.45
getCountMethod · 0.45

Tested by

no test coverage detected