@Test
public void testJoinCostFormulasPlain() {
// hash join costs
Costs hashBothSmall = new Costs();
Costs hashBothLarge = new Costs();
Costs hashSmallBuild = new Costs();
Costs hashLargeBuild = new Costs();
costEstimator.addHybridHashCosts(SMALL_ESTIMATES, BIG_ESTIMATES, hashSmallBuild, 1);
costEstimator.addHybridHashCosts(BIG_ESTIMATES, SMALL_ESTIMATES, hashLargeBuild, 1);
costEstimator.addHybridHashCosts(SMALL_ESTIMATES, SMALL_ESTIMATES, hashBothSmall, 1);
costEstimator.addHybridHashCosts(BIG_ESTIMATES, BIG_ESTIMATES, hashBothLarge, 1);
assertTrue(hashBothSmall.compareTo(hashSmallBuild) < 0);
assertTrue(hashSmallBuild.compareTo(hashLargeBuild) < 0);
assertTrue(hashLargeBuild.compareTo(hashBothLarge) < 0);
// merge join costs
Costs mergeBothSmall = new Costs();
Costs mergeBothLarge = new Costs();
Costs mergeSmallFirst = new Costs();
Costs mergeSmallSecond = new Costs();
costEstimator.addLocalSortCost(SMALL_ESTIMATES, mergeSmallFirst);
costEstimator.addLocalSortCost(BIG_ESTIMATES, mergeSmallFirst);
costEstimator.addLocalMergeCost(SMALL_ESTIMATES, BIG_ESTIMATES, mergeSmallFirst, 1);
costEstimator.addLocalSortCost(BIG_ESTIMATES, mergeSmallSecond);
costEstimator.addLocalSortCost(SMALL_ESTIMATES, mergeSmallSecond);
costEstimator.addLocalMergeCost(BIG_ESTIMATES, SMALL_ESTIMATES, mergeSmallSecond, 1);
costEstimator.addLocalSortCost(SMALL_ESTIMATES, mergeBothSmall);
costEstimator.addLocalSortCost(SMALL_ESTIMATES, mergeBothSmall);
costEstimator.addLocalMergeCost(SMALL_ESTIMATES, SMALL_ESTIMATES, mergeBothSmall, 1);
costEstimator.addLocalSortCost(BIG_ESTIMATES, mergeBothLarge);
costEstimator.addLocalSortCost(BIG_ESTIMATES, mergeBothLarge);
costEstimator.addLocalMergeCost(BIG_ESTIMATES, BIG_ESTIMATES, mergeBothLarge, 1);
assertTrue(mergeBothSmall.compareTo(mergeSmallFirst) < 0);
assertTrue(mergeBothSmall.compareTo(mergeSmallSecond) < 0);
assertTrue(mergeSmallFirst.compareTo(mergeSmallSecond) == 0);
assertTrue(mergeSmallFirst.compareTo(mergeBothLarge) < 0);
assertTrue(mergeSmallSecond.compareTo(mergeBothLarge) < 0);
// compare merge join and hash join costs
assertTrue(hashBothSmall.compareTo(mergeBothSmall) < 0);
assertTrue(hashBothLarge.compareTo(mergeBothLarge) < 0);