private static List < JoinNode > generateInnerJoinOrdersForTree ( JoinNode subTree ) { // Get a list of the leaf nodes(tables) to permute them List < JoinNode > tableNodes = subTree . generateLeafNodesJoinOrder ( ) ; List < List < JoinNode > > joinOrders = PermutationGenerator . generatePurmutations ( tableNodes ) ; List < JoinNode > newTrees = new ArrayList <> ( ) ; for ( List < JoinNode > joinOrder : joinOrders ) { newTrees . add ( JoinNode . reconstructJoinTreeFromTableNodes ( joinOrder , JoinType . INNER ) ) ; } //Collect all the join/where conditions to reassign them later AbstractExpression combinedWhereExpr = subTree . getAllFilters ( ) ; List < JoinNode > treePermutations = new ArrayList <> ( ) ; for ( JoinNode newTree : newTrees ) { if ( combinedWhereExpr != null ) { newTree . setWhereExpression ( combinedWhereExpr . clone ( ) ) ; } // The new tree root node id must match the original one to be able to reconnect the // subtrees newTree . setId ( subTree . getId ( ) ) ; treePermutations . add ( newTree ) ; } return treePermutations ; }
Helper method to generate join orders for a join tree containing only INNER joins that can be obtained by the permutation of the original tables .