MCPcopy Create free account
hub / github.com/apache/cloudberry / GenerateJoinNodes

Function GenerateJoinNodes

src/backend/gpopt/utils/COptTasks.cpp:508–575  ·  view source on GitHub ↗

--------------------------------------------------------------------------- @function: GenerateJoinNodes @doc: Converts OuterInnerRels into a JoinNode structure ---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

506// Converts OuterInnerRels into a JoinNode structure
507//---------------------------------------------------------------------------
508CJoinHint::JoinNode *
509GenerateJoinNodes(CMemoryPool *mp, OuterInnerRels *outer_inner,
510 gpos::set<std::string> &aliases)
511{
512 if (nullptr == outer_inner)
513 {
514 return nullptr;
515 }
516
517 CJoinHint::JoinNode *pair = nullptr;
518
519 if (outer_inner->relation != nullptr)
520 {
521 // Base case: processing outer_inner leaf node
522 char *str_buffer =
523 GPOS_NEW_ARRAY(mp, char, strlen(outer_inner->relation) + 1);
524 memcpy(str_buffer, outer_inner->relation,
525 strlen(outer_inner->relation));
526 str_buffer[strlen(outer_inner->relation)] = '\0';
527
528 if (aliases.count(std::string(str_buffer)) > 0)
529 {
530 // invalid leading hint if alias is specified more than once
531 return nullptr;
532 }
533 aliases.insert(std::string(str_buffer));
534
535 CWStringConst *alias = GPOS_NEW(mp)
536 CWStringConst(mp, str_buffer /*outer_inner->relation*/);
537
538 GPOS_DELETE_ARRAY(str_buffer);
539
540 pair = GPOS_NEW(mp) CJoinHint::JoinNode(alias);
541 }
542 else if (2 == list_length(outer_inner->outer_inner_pair))
543 {
544 // Recursive case: processing outer_inner branch node
545 CJoinHint::JoinNode *left_joinnode = GenerateJoinNodes(
546 mp,
547 (OuterInnerRels *) lfirst(list_head(outer_inner->outer_inner_pair)),
548 aliases);
549
550 CJoinHint::JoinNode *right_joinnode = GenerateJoinNodes(
551 mp,
552 (OuterInnerRels *) lfirst(
553 list_second_cell(outer_inner->outer_inner_pair)),
554 aliases);
555
556 if (nullptr == left_joinnode || nullptr == right_joinnode)
557 {
558 // bad input - outer_inner may be malformed
559 CRefCount::SafeRelease(left_joinnode);
560 CRefCount::SafeRelease(right_joinnode);
561 return nullptr;
562 }
563
564 pair = GPOS_NEW(mp) CJoinHint::JoinNode(left_joinnode, right_joinnode,
565 /*is_directed*/ true);

Callers 1

GetPlanHintsMethod · 0.85

Calls 7

GPOS_DELETE_ARRAYFunction · 0.85
JoinNodeClass · 0.85
list_lengthFunction · 0.85
list_headFunction · 0.85
list_second_cellFunction · 0.85
countMethod · 0.80
CWStringConstClass · 0.50

Tested by

no test coverage detected