public Pair<Boolean, GroupExpression> insertGroupExpression(GroupExpression groupExpression, Group targetGroup) {
        if (groupExpressions.get(groupExpression) != null) {
            GroupExpression existedGroupExpression = groupExpressions.get(groupExpression);
            Group existedGroup = existedGroupExpression.getGroup();

            if (needMerge(targetGroup, existedGroup)) {
                mergeGroup(existedGroup, targetGroup);
            }

            return new Pair<>(false, existedGroupExpression);
        }

        if (targetGroup == null) {
            targetGroup = newGroup();
            groups.add(targetGroup);
        }

        groupExpressions.put(groupExpression, groupExpression);

        targetGroup.addExpression(groupExpression);

        return new Pair<>(true, groupExpression);
    }
@Test
    public void testInsertGroupExpression(@Mocked OlapTable olapTable1,
                                          @Mocked OlapTable olapTable2) {
        new Expectations() {
            {
                olapTable1.getId();
                result = 0;
                minTimes = 0;

                olapTable2.getId();
                result = 1;
                minTimes = 0;
            }
        };

        OptExpression expr = OptExpression.create(new LogicalProjectOperator(Maps.newHashMap()),
                OptExpression.create(new LogicalJoinOperator(),
                        OptExpression.create(new LogicalOlapScanOperator(olapTable1)),
                        OptExpression.create(new LogicalOlapScanOperator(olapTable2))));

        Memo memo = new Memo();
        memo.init(expr);

        Operator projectOperator = LogicalLimitOperator.init(1, 1);
        GroupExpression newGroupExpression = new GroupExpression(projectOperator, Lists.newArrayList());

        memo.insertGroupExpression(newGroupExpression, memo.getGroups().get(3));

        assertEquals(memo.getGroups().size(), 4);
        assertEquals(memo.getGroupExpressions().size(), 5);
        assertEquals(memo.getGroups().get(3).getLogicalExpressions().size(), 2);
        assertEquals(memo.getGroups().get(3).getPhysicalExpressions().size(), 0);
    }