}
log.debug("{} SQL2 JOIN executed second branch, took {} ms.",
genString(printIndentation), System.currentTimeMillis()
- bTime);
return new SimpleQueryResult(merger.getColumnNames(),
merger.getSelectorNames(), new RowIteratorAdapter(allRows));
}
Set<Row> leftRows = buildLeftRowsJoin(csInfo, leftCo, printIndentation
+ printIndentStep);
if (log.isDebugEnabled()) {
timeJoinLeftSide = System.currentTimeMillis() - timeJoinLeftSide;
log.debug(genString(printIndentation) + "SQL2 JOIN LEFT SIDE took "
+ timeJoinLeftSide + " ms. fetched " + leftRows.size()
+ " rows.");
}
// The join constraint information is split into:
// - rightConstraints selects just the 'ON' constraints
// - csInfo has the 'WHERE' constraints
//
// So, in the case of an OUTER JOIN we'll run 2 queries, one with
// 'ON'
// and one with 'ON' + 'WHERE' conditions
// this way, at merge time in case of an outer join we can tell if
// it's a 'null' row, or a bad row -> one that must not be returned.
// This way at the end we'll have:
// - rightRowsSet containing the 'ON' dataset
// - excludingOuterJoinRowsSet: the 'ON' + 'WHERE' condition
// dataset, or
// NULL if there is no 'WHERE' condition
long timeJoinRightSide = System.currentTimeMillis();
List<Constraint> rightConstraints = merger
.getRightJoinConstraints(leftRows);
Comparator<Row> rightCo = new RowPathComparator(
merger.getRightSelectors());
Set<Row> rightRows = buildRightRowsJoin(csInfo, rightConstraints,
isOuterJoin, rightCo, printIndentation + printIndentStep);
// this has to be initialized as null
Set<Row> excludingOuterJoinRowsSet = null;
if (isOuterJoin && csInfo.getRightConstraint() != null) {
excludingOuterJoinRowsSet = buildRightRowsJoin(csInfo,
rightConstraints, false, rightCo, printIndentation
+ printIndentStep);
}
if (log.isDebugEnabled()) {
timeJoinRightSide = System.currentTimeMillis() - timeJoinRightSide;
log.debug(genString(printIndentation)
+ "SQL2 JOIN RIGHT SIDE took " + timeJoinRightSide
+ " ms. fetched " + rightRows.size() + " rows.");
}
// merge left with right datasets
return merger.merge(new RowIteratorAdapter(leftRows),
new RowIteratorAdapter(rightRows), excludingOuterJoinRowsSet,
rightCo);
}