Skip to content

Commit 208cc51

Browse files
committed
fix: logic short-circuit in OrNode
1 parent 6fbcceb commit 208cc51

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

core/src/main/java/cn/edu/tsinghua/iginx/engine/physical/memory/execute/compute/join/JoinOption.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public enum JoinOption {
2727
LEFT(true, false),
2828
RIGHT(false, true),
2929
FULL(true, true),
30-
MARK(false, true, false, true, false, true),
30+
MARK(false, true, true, true, false, true),
3131
SINGLE(false, true, true, false, false, false);
3232

3333
private final boolean toOutputProbeSideUnmatched;

core/src/main/java/cn/edu/tsinghua/iginx/engine/physical/memory/execute/compute/scalar/predicate/expression/OrNode.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,24 @@ public BaseIntVector filter(
9999
IntStream.range(0, input.getRowCount()).forEach(remainIndex::add);
100100
} else {
101101
for (int i = 0; i < selection.getValueCount(); i++) {
102+
if (selection.getField().isNullable() && selection.isNull(i)) {
103+
continue;
104+
}
102105
remainIndex.add((int) selection.getValueAsLong(i));
103106
}
104107
}
105108

106109
ResultBuilder resultBuilder = new ResultBuilder(allocator, selection);
107-
return filter(
108-
allocator, dictionaryProvider, input, selection, children, resultBuilder, remainIndex);
110+
BaseIntVector result =
111+
filter(
112+
allocator, dictionaryProvider, input, selection, children, resultBuilder, remainIndex);
113+
if (result != null) {
114+
return result;
115+
}
116+
return ValueVectors.slice(allocator, selection, "or");
109117
}
110118

119+
@Nullable
111120
private static BaseIntVector filter(
112121
BufferAllocator allocator,
113122
DictionaryProvider dictionaryProvider,
@@ -120,15 +129,15 @@ private static BaseIntVector filter(
120129
try (BaseIntVector subSelection =
121130
children.get(0).filter(allocator, dictionaryProvider, input, selection)) {
122131
if (subSelection == null) {
123-
return ValueVectors.slice(allocator, selection, "or");
132+
return null;
124133
}
125134
for (int i = 0; i < subSelection.getValueCount(); i++) {
126135
int index = (int) subSelection.getValueAsLong(i);
127136
resultBuilder.append(index);
128137
remainIndex.remove(index);
129138
}
130139
if (remainIndex.isEmpty()) {
131-
return ValueVectors.slice(allocator, selection, "or");
140+
return null;
132141
}
133142
List<PredicateExpression> remainChildren = children.subList(1, children.size());
134143
if (remainChildren.isEmpty()) {
@@ -175,6 +184,9 @@ public ResultBuilder(BufferAllocator allocator, BaseIntVector selection) {
175184
} else {
176185
invertedIndex = new IntObjectHashMap<>();
177186
for (int i = 0; i < selection.getValueCount(); i++) {
187+
if (selection.getField().isNullable() && selection.isNull(i)) {
188+
continue;
189+
}
178190
int value = (int) selection.getValueAsLong(i);
179191
invertedIndex.put(value, Integer.valueOf(i));
180192
}

optimizer/src/main/java/cn/edu/tsinghua/iginx/physical/optimizer/naive/NaivePhysicalPlanner.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -315,16 +315,17 @@ public PhysicalTask<?> construct(RowTransform operator, RequestContext context)
315315
public PhysicalTask<?> construct(Select operator, RequestContext context) {
316316
Source source = operator.getSource();
317317
PhysicalTask<?> sourceTask = fetch(operator.getSource(), context);
318-
if (sourceTask.getResultClass() == RowStream.class) {
319-
return new UnaryRowMemoryPhysicalTask(
320-
convert(sourceTask, context, RowStream.class), operator, context);
321-
}
322318

323319
StoragePhysicalTask storageTask = tryPushDownAloneWithProject(sourceTask, context, operator);
324320
if (storageTask != null) {
325321
return storageTask;
326322
}
327323

324+
if (sourceTask.getResultClass() == RowStream.class) {
325+
return new UnaryRowMemoryPhysicalTask(
326+
convert(sourceTask, context, RowStream.class), operator, context);
327+
}
328+
328329
PhysicalTask<BatchStream> batchTask = convert(sourceTask, context, BatchStream.class);
329330

330331
if (operator.getTagFilter() != null) {
@@ -371,7 +372,7 @@ private StoragePhysicalTask tryPushDownAloneWithProject(
371372
}
372373
Project project = (Project) sourceOperator;
373374

374-
if (project.getTagFilter() == null) {
375+
if (project.getTagFilter() != null) {
375376
return null;
376377
}
377378
return reConstruct(storageTask, context, false, operator);

0 commit comments

Comments
 (0)