Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Reduce fragment plan size #29719

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Enhancement] Reduce fragment plan size
Signed-off-by: Seaven <seaven_7@qq.com>
  • Loading branch information
Seaven committed Aug 22, 2023
commit 9ffc63233c040194148982ef17f793155f394666
11 changes: 8 additions & 3 deletions be/src/runtime/descriptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ SlotDescriptor::SlotDescriptor(SlotId id, std::string name, TypeDescriptor type)
_slot_idx(0),
_slot_size(_type.get_slot_size()),
_is_materialized(false),
_is_output_column(false) {}
_is_output_column(false),
_is_nullable(true) {}

SlotDescriptor::SlotDescriptor(const TSlotDescriptor& tdesc)
: _id(tdesc.id),
Expand All @@ -79,7 +80,8 @@ SlotDescriptor::SlotDescriptor(const TSlotDescriptor& tdesc)
_slot_idx(tdesc.slotIdx),
_slot_size(_type.get_slot_size()),
_is_materialized(tdesc.isMaterialized),
_is_output_column(tdesc.__isset.isOutputColumn ? tdesc.isOutputColumn : true) {}
_is_output_column(tdesc.__isset.isOutputColumn ? tdesc.isOutputColumn : true),
_is_nullable(tdesc.__isset.isNullable ? tdesc.isNullable : true) {}

SlotDescriptor::SlotDescriptor(const PSlotDescriptor& pdesc)
: _id(pdesc.id()),
Expand All @@ -90,7 +92,10 @@ SlotDescriptor::SlotDescriptor(const PSlotDescriptor& pdesc)
_slot_idx(pdesc.slot_idx()),
_slot_size(_type.get_slot_size()),
_is_materialized(pdesc.is_materialized()),
_is_output_column(true) {}
_is_output_column(true),
// keep same as is_nullable()
_is_nullable(_null_indicator_offset.bit_mask != 0) {
}

void SlotDescriptor::to_protobuf(PSlotDescriptor* pslot) const {
pslot->set_id(_id);
Expand Down
3 changes: 3 additions & 0 deletions be/src/runtime/descriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class SlotDescriptor {
const bool _is_materialized;
const bool _is_output_column;

// @todo: replace _null_indicator_offset when remove _null_indicator_offset
const bool _is_nullable;

SlotDescriptor(const TSlotDescriptor& tdesc);
SlotDescriptor(const PSlotDescriptor& pdesc);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,28 +245,26 @@ public TSlotDescriptor toThrift() {
nullIndicatorBit = -1;
}
Preconditions.checkState(isMaterialized, "isMaterialized must be true");

TSlotDescriptor tSlotDescriptor;
if (originType != null) {
TSlotDescriptor tSlotDescriptor = new TSlotDescriptor(id.asInt(), parent.getId().asInt(), originType.toThrift(), -1,
-1, -1,
nullIndicatorBit, ((column != null) ? column.getName() : ""),
-1, true);
tSlotDescriptor.setIsOutputColumn(isOutputColumn);
return tSlotDescriptor;
tSlotDescriptor = new TSlotDescriptor(id.asInt(), originType.toThrift());
} else {
/**
* Refer to {@link Expr#treeToThrift}
*/
if (type.isNull()) {
type = ScalarType.BOOLEAN;
}
TSlotDescriptor tSlotDescriptor = new TSlotDescriptor(id.asInt(), parent.getId().asInt(), type.toThrift(), -1,
-1, -1,
nullIndicatorBit, ((column != null) ? column.getName() : ""),
-1, true);
tSlotDescriptor.setIsOutputColumn(isOutputColumn);
return tSlotDescriptor;
tSlotDescriptor = new TSlotDescriptor(id.asInt(), type.toThrift());
}

tSlotDescriptor.setColumnPos(-1);
tSlotDescriptor.setByteOffset(-1);
tSlotDescriptor.setNullIndicatorByte(-1);
tSlotDescriptor.setNullIndicatorBit(nullIndicatorBit);
tSlotDescriptor.setColName(((column != null) ? column.getName() : ""));
tSlotDescriptor.setSlotIdx(-1);
tSlotDescriptor.setIsMaterialized(true);
tSlotDescriptor.setIsOutputColumn(isOutputColumn);
tSlotDescriptor.setIsNullable(isNullable);
return tSlotDescriptor;
}

public String debugString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ public String getAlias() {
}

public TTupleDescriptor toThrift() {
TTupleDescriptor ttupleDesc = new TTupleDescriptor(id.asInt(), -1, -1);
TTupleDescriptor ttupleDesc = new TTupleDescriptor();
ttupleDesc.setId(id.asInt());
ttupleDesc.setByteSize(-1);
ttupleDesc.setNumNullBytes(-1);
ttupleDesc.setNumNullSlots(-1);
if (table != null && table.getId() >= 0) {
ttupleDesc.setTableId((int) table.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -63,20 +62,6 @@ public boolean isConstant() {
return true;
}

public static boolean isTrue(@Nullable ScalarOperator op) {
if (op == null) {
return false;
}
return op.isTrue();
}

public static boolean isFalse(@Nullable ScalarOperator op) {
if (op == null) {
return false;
}
return op.isFalse();
}

public boolean isTrue() {
return this.equals(ConstantOperator.TRUE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.starrocks.sql.optimizer.operator.scalar.ColumnRefOperator;
import com.starrocks.sql.optimizer.operator.scalar.ScalarOperator;
import com.starrocks.sql.optimizer.rewrite.ReplaceColumnRefRewriter;
import com.starrocks.sql.optimizer.rewrite.ScalarOperatorRewriter;
import com.starrocks.sql.optimizer.rule.RuleType;

import java.util.List;
Expand All @@ -42,10 +43,16 @@ public List<OptExpression> transform(OptExpression input, OptimizerContext conte
LogicalProjectOperator firstProject = (LogicalProjectOperator) input.getOp();
LogicalProjectOperator secondProject = (LogicalProjectOperator) input.getInputs().get(0).getOp();

ScalarOperatorRewriter scalarRewriter = new ScalarOperatorRewriter();
ReplaceColumnRefRewriter rewriter = new ReplaceColumnRefRewriter(secondProject.getColumnRefMap());
Map<ColumnRefOperator, ScalarOperator> resultMap = Maps.newHashMap();
for (Map.Entry<ColumnRefOperator, ScalarOperator> entry : firstProject.getColumnRefMap().entrySet()) {
resultMap.put(entry.getKey(), rewriter.rewrite(entry.getValue()));
ScalarOperator result = rewriter.rewrite(entry.getValue());
if (result.isConstant()) {
// better to rewrite all expression, but it's unnecessary
result = scalarRewriter.rewrite(result, ScalarOperatorRewriter.DEFAULT_REWRITE_RULES);
}
resultMap.put(entry.getKey(), result);
}

// ASSERT_TRUE must be executed in the runtime, so it should be kept anyway.
Expand Down
10 changes: 10 additions & 0 deletions fe/fe-core/src/test/java/com/starrocks/sql/plan/SetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,4 +592,14 @@ public void testUnionNull() throws Exception {
"WHERE NULL";
getThriftPlan(sql);
}

@Test
public void testCast() throws Exception {
String sql = "select * from t0 union all select 1, 1, 1 from t1";
String plan = getFragmentPlan(sql);
assertContains(plan, " 4:Project\n" +
" | <slot 10> : 1\n" +
" | <slot 11> : 1\n" +
" | <slot 12> : 1");
}
}
27 changes: 14 additions & 13 deletions gensrc/thrift/Descriptors.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,25 @@ include "Exprs.thrift"

struct TSlotDescriptor {
1: required Types.TSlotId id
2: required Types.TTupleId parent
2: optional Types.TTupleId parent
3: required Types.TTypeDesc slotType
4: required i32 columnPos // in originating table
5: required i32 byteOffset // into tuple
6: required i32 nullIndicatorByte
7: required i32 nullIndicatorBit
8: required string colName;
9: required i32 slotIdx
10: required bool isMaterialized
11: optional bool isOutputColumn
4: optional i32 columnPos // Deprecated
5: optional i32 byteOffset // Deprecated
6: optional i32 nullIndicatorByte // Deprecated
7: optional i32 nullIndicatorBit // Deprecated
8: optional string colName;
9: optional i32 slotIdx // Deprecated
10: optional bool isMaterialized // Deprecated
11: optional bool isOutputColumn // Deprecated
12: optional bool isNullable // replace nullIndicatorBit & nullIndicatorByte
}

struct TTupleDescriptor {
1: required Types.TTupleId id
2: required i32 byteSize
3: required i32 numNullBytes
1: optional Types.TTupleId id
2: optional i32 byteSize // Deprecated
3: optional i32 numNullBytes // Deprecated
4: optional Types.TTableId tableId
5: optional i32 numNullSlots
5: optional i32 numNullSlots // Deprecated
}

enum THdfsFileFormat {
Expand Down