final int totalSourcePar = SystemParameters.getInt(_map, "DIP_TOTAL_SRC_PAR");
final ManualBatchingCompGenFactory factory = new ManualBatchingCompGenFactory(_map,
_pq.getTan(), totalSourcePar);
final List<String> sourceNames = factory.getParAssigner().getSortedSourceNames();
final int numSources = sourceNames.size();
NameCompGen optimal = null;
// **************creating single-relation plans********************
if (numSources == 1) {
optimal = factory.create();
optimal.generateDataSource(sourceNames.get(0));
}
// **************creating 2-way joins********************
List<NameCompGen> ncgListFirst = new ArrayList<NameCompGen>();
for (int i = 0; i < numSources; i++) {
final String firstCompName = sourceNames.get(i);
final List<String> joinedWith = _pq.getJte().getJoinedWithSingleDir(firstCompName);
if (joinedWith != null)
for (final String secondCompName : joinedWith) {
final NameCompGen ncg = factory.create();
final Component first = ncg.generateDataSource(firstCompName);
final Component second = ncg.generateDataSource(secondCompName);
addEquiJoinNotSuboptimal(first, second, ncg, ncgListFirst);
}
}
if (numSources == 2)
optimal = chooseBest(ncgListFirst);
// **************creating multi-way joins********************
for (int level = 2; level < numSources; level++) {
final List<NameCompGen> ncgListSecond = new ArrayList<NameCompGen>();
for (int i = 0; i < ncgListFirst.size(); i++) {
final NameCompGen ncg = ncgListFirst.get(i);
Component firstComp = ncg.getQueryPlan().getLastComponent();
final List<String> ancestors = ParserUtil.getSourceNameList(firstComp);
final List<String> joinedWith = _pq.getJte().getJoinedWith(ancestors);
for (final String compName : joinedWith) {
NameCompGen newNcg = ncg;
if (joinedWith.size() > 1) {
// doing deepCopy only if there are multiple tables to
// be joined with
newNcg = ncg.deepCopy();
firstComp = newNcg.getQueryPlan().getLastComponent();
}
final Component secondComp = newNcg.generateDataSource(compName);
addEquiJoinNotSuboptimal(firstComp, secondComp, newNcg, ncgListSecond);
}
}
if (level == numSources - 1)