Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.doris.nereids.trees.plans.logical.LogicalLimit;
import org.apache.doris.nereids.trees.plans.logical.LogicalSink;
import org.apache.doris.nereids.trees.plans.logical.LogicalSort;
import org.apache.doris.nereids.trees.plans.logical.LogicalTableSink;
import org.apache.doris.nereids.trees.plans.visitor.CustomRewriter;
import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanRewriter;
import org.apache.doris.qe.ConnectContext;
Expand All @@ -36,6 +37,10 @@ public class AddDefaultLimit extends DefaultPlanRewriter<StatementContext> imple

@Override
public Plan rewriteRoot(Plan plan, JobContext jobContext) {
if (jobContext.getCascadesContext().getConnectContext() == null
|| !jobContext.getCascadesContext().getConnectContext().getState().isQuery()) {
return plan;
}
return plan.accept(this, jobContext.getCascadesContext().getStatementContext());
}

Expand All @@ -52,6 +57,11 @@ public Plan visit(Plan plan, StatementContext context) {
return plan;
}

@Override
public Plan visitLogicalTableSink(LogicalTableSink<? extends Plan> logicalTableSink, StatementContext context) {
return logicalTableSink;
}

// should add limit under anchor to keep optimize opportunity
@Override
public Plan visitLogicalCTEAnchor(LogicalCTEAnchor<? extends Plan, ? extends Plan> cteAnchor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ public void checkQuerySlotCount(String slotCnt) {
@VariableMgr.VarAttr(name = SQL_AUTO_IS_NULL)
public boolean sqlAutoIsNull = false;

@VariableMgr.VarAttr(name = SQL_SELECT_LIMIT, affectQueryResult = true)
@VariableMgr.VarAttr(name = SQL_SELECT_LIMIT, needForward = true, affectQueryResult = true)
private long sqlSelectLimit = Long.MAX_VALUE;

// this is used to make c3p0 library happy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !baseall_should_delete_2_lines --
1 1 1
2 2 2

-- !unique_should_delete_2_lines_and_update_1_line --
3 4 3

-- !bigtable_should_insert_2_lines --
1 1 1
2 2 2

Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,42 @@ suite('test_default_limit') {
'''
assertEquals(res.size(), 8)
}

// test dml
sql 'set default_order_by_limit = -1'
sql 'set sql_select_limit = 1'

sql """truncate table baseall"""
sql """truncate table bigtable"""
sql """drop table if exists unique_table"""
sql """create table unique_table (
k0 int,
k1 int,
k2 int
)
unique key (k0)
distributed by hash(k0) buckets 16
properties(
'replication_num'='1'
)
"""
sql """insert into baseall values(1, 1, 1), (2, 2, 2),(3, 3, 3), (4, 4, 4)"""
sql """insert into unique_table values(1, 1, 1), (2, 2, 2),(3, 3, 3)"""
sql "sync"
// should execute successful
sql "delete from baseall where k0 in (3, 4)"
sql "sync"
// should insert 2 lines
sql "insert into bigtable select * from baseall"
sql "sync"
// should update 2 lines
sql "update unique_table set k1 = 4 where k1 in (2, 3, 4)"
sql "sync"
// should delete 2 lines
sql "delete from unique_table where k0 = 1 or k0 = 2"
sql "sync"
sql 'set sql_select_limit = -1'
qt_baseall_should_delete_2_lines "select * from baseall order by k0"
qt_unique_should_delete_2_lines_and_update_1_line "select * from unique_table order by k0"
qt_bigtable_should_insert_2_lines "select * from bigtable order by k0"
}
Loading