Skip to content

Commit 09a152f

Browse files
committed
Improve HashSemiJoinOperator
Consult Block#mayHaveNull() outside of the main processing loop to potentially skip per-row isNull checks for HashSemiJoins. Also unwraps LazyBlocks on the probeJoin block when isNull checks do occur to avoid an extra indirection inside the loop.
1 parent 404a887 commit 09a152f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

presto-main/src/main/java/com/facebook/presto/operator/HashSemiJoinOperator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package com.facebook.presto.operator;
1515

1616
import com.facebook.presto.common.Page;
17+
import com.facebook.presto.common.block.Block;
1718
import com.facebook.presto.common.block.BlockBuilder;
1819
import com.facebook.presto.common.type.Type;
1920
import com.facebook.presto.operator.SetBuilderOperator.SetSupplier;
@@ -136,18 +137,21 @@ public void addInput(Page page)
136137
{
137138
requireNonNull(page, "page is null");
138139
checkState(!finishing, "Operator is finishing");
140+
// use an effectively-final local variable instead of the non-final instance field inside of the loop
141+
ChannelSet channelSet = this.channelSet;
139142
checkState(channelSet != null, "Set has not been built yet");
140143
checkState(outputPage == null, "Operator still has pending output");
141144

142145
// create the block builder for the new boolean column
143146
// we know the exact size required for the block
144147
BlockBuilder blockBuilder = BOOLEAN.createFixedSizeBlockBuilder(page.getPositionCount());
145148

146-
Page probeJoinPage = page.extractChannel(probeJoinChannel);
149+
Page probeJoinPage = page.getLoadedPage(probeJoinChannel);
150+
Block probeJoinNulls = probeJoinPage.getBlock(0).mayHaveNull() ? probeJoinPage.getBlock(0) : null;
147151

148152
// update hashing strategy to use probe cursor
149153
for (int position = 0; position < page.getPositionCount(); position++) {
150-
if (probeJoinPage.getBlock(0).isNull(position)) {
154+
if (probeJoinNulls != null && probeJoinNulls.isNull(position)) {
151155
if (channelSet.isEmpty()) {
152156
BOOLEAN.writeBoolean(blockBuilder, false);
153157
}

0 commit comments

Comments
 (0)