Skip to content

Commit 434171d

Browse files
branch-3.1: [improve](planner) select * unique_table limit n should use one instance apache#53948 (apache#54186)
Cherry-picked from apache#53948 Co-authored-by: zhangstar333 <[email protected]>
1 parent 77def2a commit 434171d

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

be/src/pipeline/exec/scan_operator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,9 @@ Status ScanOperatorX<LocalStateType>::init(const TPlanNode& tnode, RuntimeState*
12131213
// is checked in previous branch.
12141214
if (query_options.enable_adaptive_pipeline_task_serial_read_on_limit) {
12151215
DCHECK(query_options.__isset.adaptive_pipeline_task_serial_read_on_limit);
1216-
if (!tnode.__isset.conjuncts || tnode.conjuncts.empty()) {
1216+
if (!tnode.__isset.conjuncts || tnode.conjuncts.empty() ||
1217+
(tnode.conjuncts.size() == 1 && tnode.__isset.olap_scan_node &&
1218+
tnode.olap_scan_node.keyType == TKeysType::UNIQUE_KEYS)) {
12171219
if (tnode.limit > 0 &&
12181220
tnode.limit <= query_options.adaptive_pipeline_task_serial_read_on_limit) {
12191221
_should_run_serial = true;

fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.doris.analysis.TupleDescriptor;
3939
import org.apache.doris.analysis.TupleId;
4040
import org.apache.doris.catalog.Column;
41+
import org.apache.doris.catalog.KeysType;
4142
import org.apache.doris.catalog.OlapTable;
4243
import org.apache.doris.catalog.PartitionInfo;
4344
import org.apache.doris.catalog.PrimitiveType;
@@ -765,8 +766,30 @@ public boolean shouldUseOneInstance(ConnectContext ctx) {
765766
// No connection context, typically for broker load.
766767
}
767768

768-
// For UniqueKey table, we will use multiple instance.
769-
return hasLimit() && getLimit() <= adaptivePipelineTaskSerialReadOnLimit && conjuncts.isEmpty();
769+
if (hasLimit() && getLimit() <= adaptivePipelineTaskSerialReadOnLimit) {
770+
if (conjuncts.isEmpty()) {
771+
return true;
772+
} else {
773+
if (this instanceof OlapScanNode) {
774+
OlapScanNode olapScanNode = (OlapScanNode) this;
775+
if (olapScanNode.getOlapTable() != null
776+
&& olapScanNode.getOlapTable().getKeysType() == KeysType.UNIQUE_KEYS) {
777+
// If the table is unique keys, we can check if the conjuncts only contains
778+
// delete sign
779+
if (conjuncts.size() == 1 && conjuncts.get(0) instanceof BinaryPredicate) {
780+
BinaryPredicate binaryPredicate = (BinaryPredicate) conjuncts.get(0);
781+
if (binaryPredicate.getOp() == BinaryPredicate.Operator.EQ
782+
&& binaryPredicate.getChild(0) instanceof SlotRef
783+
&& ((SlotRef) binaryPredicate.getChild(0)).getDesc().getColumn().getName()
784+
.equals(Column.DELETE_SIGN)) {
785+
return true;
786+
}
787+
}
788+
}
789+
}
790+
}
791+
}
792+
return false;
770793
}
771794

772795
// In cloud mode, meta read lock is not enough to keep a snapshot of the partition versions.

0 commit comments

Comments
 (0)