Skip to content

Commit c60ad0a

Browse files
committed
Merge branch 'bnlj-only' into left-outer
2 parents d579c94 + 0efa5ad commit c60ad0a

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

src/enclave/Enclave/BroadcastNestedLoopJoin.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
#include "common.h"
77

88
/** C++ implementation of a broadcast nested loop join.
9-
* Which row is broadcast and which row is not is handled in Scala.
9+
* Assumes outer_rows is streamed and inner_rows is broadcast.
1010
* DOES NOT rely on rows to be tagged primary or secondary, and that
11-
* assumption will break the implementation. In other words,
12-
* outer is always left and inner is always right.
11+
* assumption will break the implementation.
1312
*/
1413
void broadcast_nested_loop_join(
1514
uint8_t *join_expr, size_t join_expr_length,

src/enclave/Enclave/ExpressionEvaluation.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,10 +1756,9 @@ class FlatbuffersJoinExprEvaluator {
17561756
}
17571757
}
17581758

1759-
/**
1760-
* Return true if the given row is from the primary table, indicated by its first field, which
1761-
* must be an IntegerField.
1762-
* Rows MUST have been tagged in Scala.
1759+
/** Return true if the given row is from the primary table, indicated by its first field, which
1760+
* must be an IntegerField.
1761+
* Rows MUST have been tagged in Scala.
17631762
*/
17641763
bool is_primary(const tuix::Row *row) {
17651764
return static_cast<const tuix::IntegerField *>(
@@ -1774,12 +1773,14 @@ class FlatbuffersJoinExprEvaluator {
17741773
return is_primary(row1) ? row1 : row2;
17751774
}
17761775

1777-
/** Return true if the two rows are from the same join group. */
1776+
/** Return true if the two rows satisfy the join condition. */
17781777
bool eval_condition(const tuix::Row *row1, const tuix::Row *row2) {
17791778
builder.Clear();
17801779
bool row1_equals_row2;
17811780

1782-
/* Check equality for equi joins */
1781+
/** Check equality for equi joins. If it is a non-equi join,
1782+
* the key evaluators will be empty, so the code never enters the for loop.
1783+
*/
17831784
auto &row1_evaluators = is_primary(row1) ? left_key_evaluators : right_key_evaluators;
17841785
auto &row2_evaluators = is_primary(row2) ? left_key_evaluators : right_key_evaluators;
17851786
for (uint32_t i = 0; i < row1_evaluators.size(); i++) {

src/flatbuffers/operators.fbs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ table JoinExpr {
5858
// pairs of rows where each expression from the left is equal to the matching expression from the right.
5959
left_keys:[Expr];
6060
right_keys:[Expr];
61-
// In the case of non-equi joins, we pass in a condition
62-
// as an expression and evaluate that on each pair of rows.
61+
// In the case of non-equi joins, we pass in a condition as an expression and evaluate that on each pair of rows.
6362
// TODO: have equi joins use this condition rather than an additional filter operation.
6463
condition:Expr;
6564
}

src/main/scala/edu/berkeley/cs/rise/opaque/execution/SGXEnclave.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SGXEnclave extends java.io.Serializable {
4343
eid: Long, joinExpr: Array[Byte], input: Array[Byte]): Array[Byte]
4444

4545
@native def BroadcastNestedLoopJoin(
46-
eid: Long, joinExpr: Array[Byte], innerBlock: Array[Byte], outerBlock: Array[Byte]): Array[Byte]
46+
eid: Long, joinExpr: Array[Byte], outerBlock: Array[Byte], innerBlock: Array[Byte]): Array[Byte]
4747

4848
@native def NonObliviousAggregate(
4949
eid: Long, aggOp: Array[Byte], inputRows: Array[Byte], isPartial: Boolean): (Array[Byte])

src/main/scala/edu/berkeley/cs/rise/opaque/execution/operators.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ case class EncryptedBroadcastNestedLoopJoinExec(
350350
val rightRDD = right.asInstanceOf[OpaqueOperatorExec].executeBlocked()
351351

352352
joinType match {
353-
case LeftAnti | LeftOuter => {
353+
case LeftExistence(_) | LeftOuter => {
354354
join(leftRDD, rightRDD, joinExprSer)
355355
}
356356
case _ =>
@@ -361,7 +361,8 @@ case class EncryptedBroadcastNestedLoopJoinExec(
361361
def join(leftRDD: RDD[Block], rightRDD: RDD[Block],
362362
joinExprSer: Array[Byte]): RDD[Block] = {
363363
// We pick which side to broadcast/stream according to buildSide.
364-
// NOTE: outer_rows and inner_rows in C++ ALWAYS correspond to left and right side.
364+
// BuildRight means the right relation <=> the broadcast relation.
365+
// NOTE: outer_rows and inner_rows in C++ correspond to stream and broadcast side respectively.
365366
var (streamRDD, broadcastRDD) = buildSide match {
366367
case BuildRight =>
367368
(leftRDD, rightRDD)

src/main/scala/edu/berkeley/cs/rise/opaque/strategies.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ object OpaqueOperators extends Strategy {
114114

115115
// Used to match non-equi joins
116116
case Join(left, right, joinType, condition, hint) if isEncrypted(left) && isEncrypted(right) =>
117-
// Pick which side to broadcast: if left join, broadcast right. If right join, broadcast left.
118-
// Otherwise, pick the smallest side to broadcast.
117+
// How to pick broadcast side: if left join, broadcast right. If right join, broadcast left.
118+
// This is the simplest and most performant method, but may be worth revisting if one side is
119+
// significantly smaller than the other. Otherwise, pick the smallest side to broadcast.
120+
// NOTE: the current implementation of BNLJ only works under the assumption that
121+
// left join <==> broadcast right AND right join <==> broadcast left.
119122
val desiredBuildSide = if (joinType.isInstanceOf[InnerLike] || joinType == FullOuter)
120123
getSmallerSide(left, right) else
121124
getBroadcastSideBNLJ(joinType)

0 commit comments

Comments
 (0)