[Feat](nereids)when dealing insert into stmt with empty table source, fe returns directly (#35333)
* [Feat](nereids) when dealing insert into stmt with empty table source, fe returns directly (#34418) When a LogicalOlapScan has no partitions, transform it to a LogicalEmptyRelation. When dealing insert into stmt with empty table source, fe returns directly. * [Fix](nereids) fix when insert into select empty table --------- Co-authored-by: feiniaofeiafei <moailing@selectdb.com>
This commit is contained in:
@ -20,7 +20,11 @@ package org.apache.doris.nereids.rules.rewrite;
|
||||
import org.apache.doris.catalog.OlapTable;
|
||||
import org.apache.doris.nereids.rules.Rule;
|
||||
import org.apache.doris.nereids.rules.RuleType;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalEmptyRelation;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Used to prune empty partition.
|
||||
@ -32,7 +36,12 @@ public class PruneEmptyPartition extends OneRewriteRuleFactory {
|
||||
return logicalOlapScan().thenApply(ctx -> {
|
||||
LogicalOlapScan scan = ctx.root;
|
||||
OlapTable table = scan.getTable();
|
||||
return scan.withSelectedPartitionIds(table.selectNonEmptyPartitionIds(scan.getSelectedPartitionIds()));
|
||||
List<Long> ids = table.selectNonEmptyPartitionIds(scan.getSelectedPartitionIds());
|
||||
if (ids.isEmpty()) {
|
||||
return new LogicalEmptyRelation(ConnectContext.get().getStatementContext().getNextRelationId(),
|
||||
scan.getOutput());
|
||||
}
|
||||
return scan.withSelectedPartitionIds(ids);
|
||||
}).toRule(RuleType.PRUNE_EMPTY_PARTITION);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class CreateMTMVInfo {
|
||||
public static final Logger LOG = LogManager.getLogger(CreateMTMVInfo.class);
|
||||
public static final String MTMV_PLANER_DISABLE_RULES = "OLAP_SCAN_PARTITION_PRUNE";
|
||||
public static final String MTMV_PLANER_DISABLE_RULES = "OLAP_SCAN_PARTITION_PRUNE,PRUNE_EMPTY_PARTITION";
|
||||
private final boolean ifNotExists;
|
||||
private final TableNameInfo mvName;
|
||||
private List<String> keys;
|
||||
|
||||
@ -58,18 +58,20 @@ public abstract class AbstractInsertExecutor {
|
||||
|
||||
protected String errMsg = "";
|
||||
protected Optional<InsertCommandContext> insertCtx;
|
||||
protected final boolean emptyInsert;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public AbstractInsertExecutor(ConnectContext ctx, TableIf table, String labelName, NereidsPlanner planner,
|
||||
Optional<InsertCommandContext> insertCtx) {
|
||||
Optional<InsertCommandContext> insertCtx, boolean emptyInsert) {
|
||||
this.ctx = ctx;
|
||||
this.coordinator = new Coordinator(ctx, null, planner, ctx.getStatsErrorEstimator());
|
||||
this.labelName = labelName;
|
||||
this.table = table;
|
||||
this.database = table.getDatabase();
|
||||
this.insertCtx = insertCtx;
|
||||
this.emptyInsert = emptyInsert;
|
||||
}
|
||||
|
||||
public Coordinator getCoordinator() {
|
||||
@ -189,4 +191,8 @@ public abstract class AbstractInsertExecutor {
|
||||
}
|
||||
afterExec(executor);
|
||||
}
|
||||
|
||||
public boolean isEmptyInsert() {
|
||||
return emptyInsert;
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,8 +59,9 @@ public abstract class BaseExternalTableInsertExecutor extends AbstractInsertExec
|
||||
*/
|
||||
public BaseExternalTableInsertExecutor(ConnectContext ctx, ExternalTable table,
|
||||
String labelName, NereidsPlanner planner,
|
||||
Optional<InsertCommandContext> insertCtx) {
|
||||
super(ctx, table, labelName, planner, insertCtx);
|
||||
Optional<InsertCommandContext> insertCtx,
|
||||
boolean emptyInsert) {
|
||||
super(ctx, table, labelName, planner, insertCtx, emptyInsert);
|
||||
catalogName = table.getCatalog().getName();
|
||||
transactionManager = table.getCatalog().getTransactionManager();
|
||||
|
||||
|
||||
@ -43,8 +43,8 @@ public class HiveInsertExecutor extends BaseExternalTableInsertExecutor {
|
||||
*/
|
||||
public HiveInsertExecutor(ConnectContext ctx, HMSExternalTable table,
|
||||
String labelName, NereidsPlanner planner,
|
||||
Optional<InsertCommandContext> insertCtx) {
|
||||
super(ctx, table, labelName, planner, insertCtx);
|
||||
Optional<InsertCommandContext> insertCtx, boolean emptyInsert) {
|
||||
super(ctx, table, labelName, planner, insertCtx, emptyInsert);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -40,8 +40,9 @@ public class IcebergInsertExecutor extends BaseExternalTableInsertExecutor {
|
||||
*/
|
||||
public IcebergInsertExecutor(ConnectContext ctx, IcebergExternalTable table,
|
||||
String labelName, NereidsPlanner planner,
|
||||
Optional<InsertCommandContext> insertCtx) {
|
||||
super(ctx, table, labelName, planner, insertCtx);
|
||||
Optional<InsertCommandContext> insertCtx,
|
||||
boolean emptyInsert) {
|
||||
super(ctx, table, labelName, planner, insertCtx, emptyInsert);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -37,6 +37,7 @@ import org.apache.doris.nereids.trees.plans.PlanType;
|
||||
import org.apache.doris.nereids.trees.plans.commands.Command;
|
||||
import org.apache.doris.nereids.trees.plans.commands.ForwardWithSync;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
|
||||
import org.apache.doris.nereids.trees.plans.physical.PhysicalEmptyRelation;
|
||||
import org.apache.doris.nereids.trees.plans.physical.PhysicalHiveTableSink;
|
||||
import org.apache.doris.nereids.trees.plans.physical.PhysicalIcebergTableSink;
|
||||
import org.apache.doris.nereids.trees.plans.physical.PhysicalOlapTableSink;
|
||||
@ -165,9 +166,11 @@ public class InsertIntoTableCommand extends Command implements ForwardWithSync,
|
||||
// return;
|
||||
throw new AnalysisException("group commit is not supported in Nereids now");
|
||||
}
|
||||
boolean emptyInsert = childIsEmptyRelation(physicalSink);
|
||||
OlapTable olapTable = (OlapTable) targetTableIf;
|
||||
// the insertCtx contains some variables to adjust SinkNode
|
||||
insertExecutor = new OlapInsertExecutor(ctx, olapTable, label, planner, insertCtx);
|
||||
insertExecutor = new OlapInsertExecutor(ctx, olapTable, label, planner, insertCtx, emptyInsert);
|
||||
|
||||
boolean isEnableMemtableOnSinkNode =
|
||||
olapTable.getTableProperty().getUseSchemaLightChange()
|
||||
? insertExecutor.getCoordinator().getQueryOptions().isEnableMemtableOnSinkNode()
|
||||
@ -175,14 +178,16 @@ public class InsertIntoTableCommand extends Command implements ForwardWithSync,
|
||||
insertExecutor.getCoordinator().getQueryOptions()
|
||||
.setEnableMemtableOnSinkNode(isEnableMemtableOnSinkNode);
|
||||
} else if (physicalSink instanceof PhysicalHiveTableSink) {
|
||||
boolean emptyInsert = childIsEmptyRelation(physicalSink);
|
||||
HMSExternalTable hiveExternalTable = (HMSExternalTable) targetTableIf;
|
||||
insertExecutor = new HiveInsertExecutor(ctx, hiveExternalTable, label, planner,
|
||||
Optional.of(insertCtx.orElse((new HiveInsertCommandContext()))));
|
||||
Optional.of(insertCtx.orElse((new HiveInsertCommandContext()))), emptyInsert);
|
||||
// set hive query options
|
||||
} else if (physicalSink instanceof PhysicalIcebergTableSink) {
|
||||
boolean emptyInsert = childIsEmptyRelation(physicalSink);
|
||||
IcebergExternalTable icebergExternalTable = (IcebergExternalTable) targetTableIf;
|
||||
insertExecutor = new IcebergInsertExecutor(ctx, icebergExternalTable, label, planner,
|
||||
Optional.of(insertCtx.orElse((new BaseExternalTableInsertCommandContext()))));
|
||||
Optional.of(insertCtx.orElse((new BaseExternalTableInsertCommandContext()))), emptyInsert);
|
||||
} else {
|
||||
// TODO: support other table types
|
||||
throw new AnalysisException("insert into command only support [olap, hive, iceberg] table");
|
||||
@ -203,6 +208,10 @@ public class InsertIntoTableCommand extends Command implements ForwardWithSync,
|
||||
|
||||
private void runInternal(ConnectContext ctx, StmtExecutor executor) throws Exception {
|
||||
AbstractInsertExecutor insertExecutor = initPlan(ctx, executor);
|
||||
// if the insert stmt data source is empty, directly return, no need to be executed.
|
||||
if (insertExecutor.isEmptyInsert()) {
|
||||
return;
|
||||
}
|
||||
insertExecutor.executeSingleInsert(executor, jobId);
|
||||
}
|
||||
|
||||
@ -219,4 +228,12 @@ public class InsertIntoTableCommand extends Command implements ForwardWithSync,
|
||||
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
|
||||
return visitor.visitInsertIntoTableCommand(this, context);
|
||||
}
|
||||
|
||||
private boolean childIsEmptyRelation(PhysicalSink sink) {
|
||||
if (sink.children() != null && sink.children().size() == 1
|
||||
&& sink.child(0) instanceof PhysicalEmptyRelation) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,8 +76,8 @@ public class OlapInsertExecutor extends AbstractInsertExecutor {
|
||||
* constructor
|
||||
*/
|
||||
public OlapInsertExecutor(ConnectContext ctx, Table table,
|
||||
String labelName, NereidsPlanner planner, Optional<InsertCommandContext> insertCtx) {
|
||||
super(ctx, table, labelName, planner, insertCtx);
|
||||
String labelName, NereidsPlanner planner, Optional<InsertCommandContext> insertCtx, boolean emptyInsert) {
|
||||
super(ctx, table, labelName, planner, insertCtx, emptyInsert);
|
||||
}
|
||||
|
||||
public long getTxnId() {
|
||||
|
||||
@ -525,7 +525,7 @@ public class SelectStmtTest {
|
||||
|
||||
@Test
|
||||
public void testDeleteSign() throws Exception {
|
||||
String sql1 = "SELECT /*+ SET_VAR(enable_nereids_planner=true, ENABLE_FALLBACK_TO_ORIGINAL_PLANNER=false) */ * FROM db1.table1 LEFT ANTI JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;";
|
||||
String sql1 = "SELECT /*+ SET_VAR(enable_nereids_planner=true, ENABLE_FALLBACK_TO_ORIGINAL_PLANNER=false, DISABLE_NEREIDS_RULES=PRUNE_EMPTY_PARTITION) */ * FROM db1.table1 LEFT ANTI JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;";
|
||||
String explain = dorisAssert.query(sql1).explainQuery();
|
||||
Assert.assertTrue(explain
|
||||
.contains("__DORIS_DELETE_SIGN__ = 0"));
|
||||
|
||||
@ -45,6 +45,7 @@ public class CreateViewTest {
|
||||
UtFrameUtils.createDorisCluster(runningDir);
|
||||
// create connect context
|
||||
connectContext = UtFrameUtils.createDefaultCtx();
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
// create database
|
||||
String createDbStmtStr = "create database test;";
|
||||
CreateDbStmt createDbStmt = (CreateDbStmt) UtFrameUtils.parseAndAnalyzeStmt(createDbStmtStr, connectContext);
|
||||
|
||||
@ -44,6 +44,7 @@ class DistributeHintTest extends TestWithFeService implements MemoPatternMatchSu
|
||||
protected void runBeforeAll() throws Exception {
|
||||
createDatabase("test");
|
||||
useDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
|
||||
createTable("CREATE TABLE `t1` (\n"
|
||||
+ " `a` int(11) NULL,\n"
|
||||
|
||||
@ -43,6 +43,7 @@ import java.util.List;
|
||||
class CompareOuterJoinTest extends SqlTestBase {
|
||||
@Test
|
||||
void testStarGraphWithInnerJoin() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
// t2
|
||||
// |
|
||||
//t3-- t1 -- t4
|
||||
@ -72,6 +73,7 @@ class CompareOuterJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testRandomQuery() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
Plan p1 = new HyperGraphBuilder(Sets.newHashSet(JoinType.INNER_JOIN))
|
||||
.randomBuildPlanWith(3, 3);
|
||||
p1 = PlanChecker.from(connectContext, p1)
|
||||
@ -91,7 +93,7 @@ class CompareOuterJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testInnerJoinWithFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 inner join T2 on T1.id = T2.id where T1.id = 0",
|
||||
connectContext
|
||||
@ -118,7 +120,7 @@ class CompareOuterJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testInnerJoinWithFilter2() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 inner join T2 on T1.id = T2.id where T1.id = 0",
|
||||
connectContext
|
||||
@ -144,12 +146,11 @@ class CompareOuterJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testLeftOuterJoinWithLeftFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from ( select * from T1 where T1.id = 0) T1 left outer join T2 on T1.id = T2.id",
|
||||
connectContext
|
||||
);
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
Plan p1 = PlanChecker.from(c1)
|
||||
.analyze()
|
||||
.rewrite()
|
||||
@ -172,12 +173,11 @@ class CompareOuterJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testLeftOuterJoinWithRightFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 left outer join ( select * from T2 where T2.id = 0) T2 on T1.id = T2.id",
|
||||
connectContext
|
||||
);
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
Plan p1 = PlanChecker.from(c1)
|
||||
.analyze()
|
||||
.rewrite()
|
||||
|
||||
@ -41,7 +41,7 @@ import java.util.stream.Collectors;
|
||||
class InferJoinTest extends SqlTestBase {
|
||||
@Test
|
||||
void testInnerInferLeft() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 inner join T2 on T1.id = T2.id where T1.id = 0",
|
||||
connectContext
|
||||
@ -70,7 +70,7 @@ class InferJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testInnerInferLeftWithFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 inner join T2 on T1.id = T2.id where T1.id = 0",
|
||||
connectContext
|
||||
@ -103,7 +103,7 @@ class InferJoinTest extends SqlTestBase {
|
||||
@Disabled
|
||||
@Test
|
||||
void testInnerInferLeftWithJoinCond() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 inner join "
|
||||
+ "(select T2.id from T2 inner join T3 on T2.id = T3.id) T2 "
|
||||
@ -137,12 +137,11 @@ class InferJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testLeftOuterJoinWithRightFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 left outer join ( select * from T2 where T2.id = 0) T2 on T1.id = T2.id",
|
||||
connectContext
|
||||
);
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
Plan p1 = PlanChecker.from(c1)
|
||||
.analyze()
|
||||
.rewrite()
|
||||
|
||||
@ -38,6 +38,7 @@ import java.util.BitSet;
|
||||
class InferPredicateTest extends SqlTestBase {
|
||||
@Test
|
||||
void testPullUpQueryFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 left join T2 on T1.id = T2.id where T1.id = 1",
|
||||
connectContext
|
||||
|
||||
@ -38,6 +38,7 @@ import java.util.BitSet;
|
||||
class PullupExpressionTest extends SqlTestBase {
|
||||
@Test
|
||||
void testPullUpQueryFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 join T2 on T1.id = T2.id where T1.id = 1",
|
||||
connectContext
|
||||
@ -64,6 +65,7 @@ class PullupExpressionTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testPullUpQueryJoinCondition() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 join T2 on T1.id = T2.id and T1.score = T2.score",
|
||||
connectContext
|
||||
@ -90,6 +92,7 @@ class PullupExpressionTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testPullUpViewFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 join T2 on T1.id = T2.id",
|
||||
connectContext
|
||||
@ -117,6 +120,7 @@ class PullupExpressionTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testPullUpViewJoinCondition() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 join T2 on T1.id = T2.id ",
|
||||
connectContext
|
||||
|
||||
@ -24,6 +24,7 @@ import org.apache.doris.nereids.rules.exploration.mv.StructInfo;
|
||||
import org.apache.doris.nereids.sqltest.SqlTestBase;
|
||||
import org.apache.doris.nereids.util.PlanChecker;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
import org.apache.doris.qe.SessionVariable;
|
||||
|
||||
import mockit.Mock;
|
||||
import mockit.MockUp;
|
||||
@ -37,6 +38,14 @@ import java.util.stream.Collectors;
|
||||
class StructInfoMapTest extends SqlTestBase {
|
||||
@Test
|
||||
void testTableMap() throws Exception {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
BitSet disableNereidsRules = connectContext.getSessionVariable().getDisableNereidsRules();
|
||||
new MockUp<SessionVariable>() {
|
||||
@Mock
|
||||
public BitSet getDisableNereidsRules() {
|
||||
return disableNereidsRules;
|
||||
}
|
||||
};
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select T1.id from T1 inner join T2 "
|
||||
+ "on T1.id = T2.id "
|
||||
@ -60,6 +69,7 @@ class StructInfoMapTest extends SqlTestBase {
|
||||
};
|
||||
connectContext.getSessionVariable().enableMaterializedViewRewrite = true;
|
||||
connectContext.getSessionVariable().enableMaterializedViewNestRewrite = true;
|
||||
|
||||
createMvByNereids("create materialized view mv1 BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL\n"
|
||||
+ " DISTRIBUTED BY RANDOM BUCKETS 1\n"
|
||||
+ " PROPERTIES ('replication_num' = '1') \n"
|
||||
@ -85,6 +95,14 @@ class StructInfoMapTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testLazyRefresh() throws Exception {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
BitSet disableNereidsRules = connectContext.getSessionVariable().getDisableNereidsRules();
|
||||
new MockUp<SessionVariable>() {
|
||||
@Mock
|
||||
public BitSet getDisableNereidsRules() {
|
||||
return disableNereidsRules;
|
||||
}
|
||||
};
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select T1.id from T1 inner join T2 "
|
||||
+ "on T1.id = T2.id "
|
||||
@ -135,6 +153,14 @@ class StructInfoMapTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testTableChild() throws Exception {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
BitSet disableNereidsRules = connectContext.getSessionVariable().getDisableNereidsRules();
|
||||
new MockUp<SessionVariable>() {
|
||||
@Mock
|
||||
public BitSet getDisableNereidsRules() {
|
||||
return disableNereidsRules;
|
||||
}
|
||||
};
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select T1.id from T1 inner join T2 "
|
||||
+ "on T1.id = T2.id "
|
||||
|
||||
@ -51,6 +51,7 @@ class EqualSetTest extends TestWithFeService {
|
||||
+ "distributed by hash(id) buckets 10\n"
|
||||
+ "properties('replication_num' = '1');");
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -53,6 +53,7 @@ class FunctionalDependenciesTest extends TestWithFeService {
|
||||
+ "distributed by hash(id) buckets 10\n"
|
||||
+ "properties('replication_num' = '1');");
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -49,6 +49,7 @@ class UniformTest extends TestWithFeService {
|
||||
+ "distributed by hash(id) buckets 10\n"
|
||||
+ "properties('replication_num' = '1');");
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -49,6 +49,7 @@ class UniqueTest extends TestWithFeService {
|
||||
+ "distributed by hash(id) buckets 10\n"
|
||||
+ "properties('replication_num' = '1');");
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -94,6 +94,7 @@ public class AnalyzeWhereSubqueryTest extends TestWithFeService implements MemoP
|
||||
protected void runBeforeAll() throws Exception {
|
||||
createDatabase("test");
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
|
||||
createTables(
|
||||
"create table test.t6\n"
|
||||
|
||||
@ -35,6 +35,7 @@ public class BindFunctionTest extends TestWithFeService implements MemoPatternMa
|
||||
protected void runBeforeAll() throws Exception {
|
||||
createDatabase("test");
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
createTables(
|
||||
"CREATE TABLE t1 (col1 date, col2 int) DISTRIBUTED BY HASH(col2)\n" + "BUCKETS 1\n" + "PROPERTIES(\n"
|
||||
+ " \"replication_num\"=\"1\"\n" + ");",
|
||||
|
||||
@ -54,6 +54,7 @@ class BindRelationTest extends TestWithFeService implements GeneratedPlanPattern
|
||||
+ ")ENGINE=OLAP\n"
|
||||
+ "DISTRIBUTED BY HASH(`a`) BUCKETS 3\n"
|
||||
+ "PROPERTIES (\"replication_num\"= \"1\");");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test;
|
||||
class BuildStructInfoTest extends SqlTestBase {
|
||||
@Test
|
||||
void testSimpleSQL() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "select * from T1, T2, T3, T4 "
|
||||
+ "where "
|
||||
+ "T1.id = T2.id and "
|
||||
@ -47,6 +48,7 @@ class BuildStructInfoTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testStructInfoNode() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "select * from T1 inner join "
|
||||
+ "(select sum(id) as id from T2 where id = 1) T2 "
|
||||
+ "on T1.id = T2.id";
|
||||
@ -67,6 +69,7 @@ class BuildStructInfoTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "select * from T1 left outer join "
|
||||
+ " (select id from T2 where id = 1) T2 "
|
||||
+ "on T1.id = T2.id ";
|
||||
|
||||
@ -35,7 +35,7 @@ import java.util.BitSet;
|
||||
class EliminateJoinTest extends SqlTestBase {
|
||||
@Test
|
||||
void testLOJWithGroupBy() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1",
|
||||
connectContext
|
||||
@ -75,7 +75,7 @@ class EliminateJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testLOJWithUK() throws Exception {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1",
|
||||
connectContext
|
||||
@ -105,7 +105,7 @@ class EliminateJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testLOJWithPKFK() throws Exception {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1",
|
||||
connectContext
|
||||
@ -149,7 +149,7 @@ class EliminateJoinTest extends SqlTestBase {
|
||||
@Disabled
|
||||
@Test
|
||||
void testLOJWithPKFKAndUK1() throws Exception {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1",
|
||||
connectContext
|
||||
@ -182,7 +182,7 @@ class EliminateJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testLOJWithPKFKAndUK2() throws Exception {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1",
|
||||
connectContext
|
||||
|
||||
@ -37,6 +37,7 @@ import java.util.Objects;
|
||||
class HyperGraphAggTest extends SqlTestBase {
|
||||
@Test
|
||||
void testJoinWithAgg() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c2 = createCascadesContext(
|
||||
"select * from T1 inner join"
|
||||
+ "("
|
||||
|
||||
@ -35,7 +35,7 @@ import java.util.BitSet;
|
||||
class HyperGraphComparatorTest extends SqlTestBase {
|
||||
@Test
|
||||
void testInnerJoinAndLOJ() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 inner join T2 "
|
||||
+ "on T1.id = T2.id "
|
||||
@ -66,7 +66,7 @@ class HyperGraphComparatorTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testIJAndLojAssoc() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 inner join T3 "
|
||||
+ "on T1.id = T3.id "
|
||||
@ -97,7 +97,7 @@ class HyperGraphComparatorTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testIJAndLojAssocWithFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 inner join T3 "
|
||||
+ "on T1.id = T3.id "
|
||||
@ -130,7 +130,7 @@ class HyperGraphComparatorTest extends SqlTestBase {
|
||||
@Disabled
|
||||
@Test
|
||||
void testIJAndLojAssocWithJoinCond() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES,PRUNE_EMPTY_PARTITION");
|
||||
CascadesContext c1 = createCascadesContext(
|
||||
"select * from T1 inner join T3 "
|
||||
+ "on T1.id = T3.id "
|
||||
|
||||
@ -201,7 +201,7 @@ public class MaterializedViewUtilsTest extends TestWithFeService {
|
||||
+ " );\n"
|
||||
+ "\n");
|
||||
// Should not make scan to empty relation when the table used by materialized view has no data
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("OLAP_SCAN_PARTITION_PRUNE");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("OLAP_SCAN_PARTITION_PRUNE,PRUNE_EMPTY_PARTITION");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -33,6 +33,7 @@ class SimplifyComparisonPredicateSqlTest extends TestWithFeService implements Me
|
||||
protected void runBeforeAll() throws Exception {
|
||||
createDatabase("test");
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
createTables(
|
||||
"CREATE TABLE IF NOT EXISTS `log_items_test` (\n"
|
||||
+ " a DATETIME(0) NOT NULL,\n"
|
||||
|
||||
@ -37,6 +37,7 @@ class CountLiteralRewriteTest extends TestWithFeService implements MemoPatternMa
|
||||
+ "age int, sex int)\n" + "distributed by hash(id) buckets 10\n"
|
||||
+ "properties('replication_num' = '1');");
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -54,6 +54,7 @@ class EliminateJoinByFkTest extends TestWithFeService implements MemoPatternMatc
|
||||
+ "references pri(id1)");
|
||||
addConstraint("Alter table foreign_null add constraint f_not_null foreign key (id3)\n"
|
||||
+ "references pri(id1)");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -28,6 +28,7 @@ class EliminateJoinByUniqueTest extends TestWithFeService implements MemoPattern
|
||||
protected void runBeforeAll() throws Exception {
|
||||
createDatabase("test");
|
||||
connectContext.setDatabase("default_cluster:test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
createTables(
|
||||
"CREATE TABLE IF NOT EXISTS t1 (\n"
|
||||
+ " id1 int not null,\n"
|
||||
|
||||
@ -74,6 +74,7 @@ class InferPredicatesTest extends TestWithFeService implements MemoPatternMatchS
|
||||
+ "properties('replication_num' = '1');");
|
||||
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -39,6 +39,7 @@ class PushDownLimitDistinctThroughJoinTest extends TestWithFeService implements
|
||||
createDatabase("test");
|
||||
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
|
||||
createTable("CREATE TABLE `t1` (\n"
|
||||
+ " `k1` int(11) NULL,\n"
|
||||
|
||||
@ -72,6 +72,7 @@ class PushDownLimitTest extends TestWithFeService implements MemoPatternMatchSup
|
||||
createDatabase("test");
|
||||
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
|
||||
createTable("CREATE TABLE `t1` (\n"
|
||||
+ " `k1` int(11) NULL,\n"
|
||||
@ -267,6 +268,7 @@ class PushDownLimitTest extends TestWithFeService implements MemoPatternMatchSup
|
||||
void testLimitPushWindow() {
|
||||
ConnectContext context = MemoTestUtils.createConnectContext();
|
||||
context.getSessionVariable().setEnablePartitionTopN(true);
|
||||
context.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
NamedExpression grade = scanScore.getOutput().get(2).toSlot();
|
||||
|
||||
List<Expression> partitionKeyList = ImmutableList.of();
|
||||
@ -309,6 +311,7 @@ class PushDownLimitTest extends TestWithFeService implements MemoPatternMatchSup
|
||||
void testTopNPushWindow() {
|
||||
ConnectContext context = MemoTestUtils.createConnectContext();
|
||||
context.getSessionVariable().setEnablePartitionTopN(true);
|
||||
context.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
NamedExpression grade = scanScore.getOutput().get(2).toSlot();
|
||||
|
||||
List<Expression> partitionKeyList = ImmutableList.of();
|
||||
|
||||
@ -45,6 +45,7 @@ class PushDownTopNThroughJoinTest extends TestWithFeService implements MemoPatte
|
||||
createDatabase("test");
|
||||
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
|
||||
createTable("CREATE TABLE `t1` (\n"
|
||||
+ " `k1` int(11) NOT NULL,\n"
|
||||
|
||||
@ -27,6 +27,7 @@ import org.apache.doris.nereids.util.MemoPatternMatchSupported;
|
||||
import org.apache.doris.nereids.util.MemoTestUtils;
|
||||
import org.apache.doris.nereids.util.PlanChecker;
|
||||
import org.apache.doris.nereids.util.PlanConstructor;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -92,8 +93,9 @@ class ReorderJoinTest implements MemoPatternMatchSupported {
|
||||
.join(scan2, JoinType.LEFT_SEMI_JOIN, Pair.of(0, 0))
|
||||
.filter(new EqualTo(scan3.getOutput().get(0), scan1.getOutput().get(0)))
|
||||
.build();
|
||||
|
||||
PlanChecker.from(MemoTestUtils.createConnectContext(), plan2)
|
||||
ConnectContext connectContext = MemoTestUtils.createConnectContext();
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
PlanChecker.from(connectContext, plan2)
|
||||
.rewrite()
|
||||
.matchesFromRoot(
|
||||
logicalJoin(
|
||||
@ -121,7 +123,9 @@ class ReorderJoinTest implements MemoPatternMatchSupported {
|
||||
)
|
||||
.filter(new EqualTo(scan3.getOutput().get(0), scan1.getOutput().get(0)))
|
||||
.build();
|
||||
PlanChecker.from(MemoTestUtils.createConnectContext(), plan2)
|
||||
ConnectContext connectContext = MemoTestUtils.createConnectContext();
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
PlanChecker.from(connectContext, plan2)
|
||||
.applyBottomUp(new SemiJoinCommute())
|
||||
.rewrite()
|
||||
.matchesFromRoot(
|
||||
@ -167,7 +171,9 @@ class ReorderJoinTest implements MemoPatternMatchSupported {
|
||||
);
|
||||
|
||||
for (LogicalPlan plan : plans) {
|
||||
PlanChecker.from(MemoTestUtils.createConnectContext(), plan)
|
||||
ConnectContext connectContext = MemoTestUtils.createConnectContext();
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
PlanChecker.from(connectContext, plan)
|
||||
.applyBottomUp(new ReorderJoin())
|
||||
.matchesFromRoot(
|
||||
logicalJoin(
|
||||
@ -180,7 +186,9 @@ class ReorderJoinTest implements MemoPatternMatchSupported {
|
||||
|
||||
public void check(List<LogicalPlan> plans) {
|
||||
for (LogicalPlan plan : plans) {
|
||||
PlanChecker.from(MemoTestUtils.createConnectContext(), plan)
|
||||
ConnectContext connectContext = MemoTestUtils.createConnectContext();
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
PlanChecker.from(connectContext, plan)
|
||||
.rewrite()
|
||||
.printlnTree()
|
||||
.matchesFromRoot(
|
||||
@ -214,8 +222,9 @@ class ReorderJoinTest implements MemoPatternMatchSupported {
|
||||
.joinEmptyOn(rightJoin, JoinType.CROSS_JOIN)
|
||||
.filter(new EqualTo(scan1.getOutput().get(0), scan3.getOutput().get(0)))
|
||||
.build();
|
||||
|
||||
PlanChecker.from(MemoTestUtils.createConnectContext(), plan)
|
||||
ConnectContext connectContext = MemoTestUtils.createConnectContext();
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
PlanChecker.from(connectContext, plan)
|
||||
.applyBottomUp(new ReorderJoin())
|
||||
.matchesFromRoot(
|
||||
logicalJoin(
|
||||
|
||||
@ -36,6 +36,7 @@ import org.junit.jupiter.api.Test;
|
||||
class CascadesJoinReorderTest extends SqlTestBase {
|
||||
@Test
|
||||
void testStartThreeJoin() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
// Three join
|
||||
// (n-1)! * 2^(n-1) = 8
|
||||
String sql = "SELECT * FROM T1 "
|
||||
@ -56,6 +57,7 @@ class CascadesJoinReorderTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testStarFourJoinZigzag() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
// Four join
|
||||
// (n-1)! * 2^(n-1) = 48
|
||||
String sql = "SELECT * FROM T1 "
|
||||
@ -81,6 +83,7 @@ class CascadesJoinReorderTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testStarFourJoinBushy() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
// Four join
|
||||
// (n-1)! * 2^(n-1) = 48
|
||||
String sql = "SELECT * FROM T1 "
|
||||
@ -106,6 +109,7 @@ class CascadesJoinReorderTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testChainFourJoinBushy() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
// Four join
|
||||
// 2^(n-1) * C(n-1) = 40
|
||||
String sql = "SELECT * FROM T1 "
|
||||
@ -131,6 +135,7 @@ class CascadesJoinReorderTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testChainFiveJoinBushy() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
// Five join
|
||||
// 2^(n-1) * C(n-1) = 224
|
||||
String sql = "SELECT * FROM T1 "
|
||||
|
||||
@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class InferTest extends SqlTestBase {
|
||||
@Test
|
||||
void testInferNotNullAndInferPredicates() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
// Test InferNotNull, EliminateOuter, InferPredicate together
|
||||
String sql = "select * from T1 left outer join T2 on T1.id = T2.id where T2.id = 4";
|
||||
PlanChecker.from(connectContext)
|
||||
@ -39,6 +40,7 @@ public class InferTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testInferNotNullFromFilterAndEliminateOuter2() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql
|
||||
= "select * from T1 right outer join T2 on T1.id = T2.id where T1.id = 4 OR (T1.id > 4 AND T2.score IS NULL)";
|
||||
PlanChecker.from(connectContext)
|
||||
@ -58,6 +60,7 @@ public class InferTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testInferNotNullFromFilterAndEliminateOuter3() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql
|
||||
= "select * from T1 full outer join T2 on T1.id = T2.id where T1.id = 4 OR (T1.id > 4 AND T2.score IS NULL)";
|
||||
PlanChecker.from(connectContext)
|
||||
@ -77,6 +80,7 @@ public class InferTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testInferNotNullFromJoinAndEliminateOuter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
// Is Not Null will infer from semi join, so right outer join can be eliminated.
|
||||
String sql
|
||||
= "select * from (select T1.id from T1 right outer join T2 on T1.id = T2.id) T1 left semi join T3 on T1.id = T3.id";
|
||||
@ -93,6 +97,7 @@ public class InferTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void aggEliminateOuterJoin() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "select count(T2.score) from T1 left Join T2 on T1.id = T2.id";
|
||||
|
||||
PlanChecker.from(connectContext)
|
||||
|
||||
@ -111,6 +111,7 @@ public class JoinOrderJobTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
protected void testCountJoin() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "select count(*) \n"
|
||||
+ "from \n"
|
||||
+ "T1, \n"
|
||||
|
||||
@ -31,6 +31,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class JoinTest extends SqlTestBase {
|
||||
@Test
|
||||
void testJoinUsing() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "SELECT * FROM T1 JOIN T2 using (id)";
|
||||
PlanChecker.from(connectContext)
|
||||
.analyze(sql)
|
||||
@ -42,6 +43,7 @@ public class JoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testColocatedJoin() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "select * from T2 join T2 b on T2.id = b.id and T2.id = b.id;";
|
||||
PhysicalPlan plan = PlanChecker.from(connectContext)
|
||||
.analyze(sql)
|
||||
@ -65,6 +67,7 @@ public class JoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testDedupConjuncts() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "select * from T1 join T2 on T1.id = T2.id and T1.id = T2.id;";
|
||||
PlanChecker.from(connectContext)
|
||||
.analyze(sql)
|
||||
@ -84,6 +87,7 @@ public class JoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testBucketJoinWithAgg() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "select * from "
|
||||
+ "(select distinct id as cnt from T2) T1 inner join"
|
||||
+ "(select distinct id as cnt from T2) T2 "
|
||||
|
||||
@ -29,6 +29,7 @@ import java.util.List;
|
||||
public class MultiJoinTest extends SqlTestBase {
|
||||
@Test
|
||||
void testMultiJoinEliminateCross() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
List<String> sqls = ImmutableList.<String>builder()
|
||||
.add("SELECT * FROM T2 LEFT JOIN T3 ON T2.id = T3.id, T1 WHERE T1.id = T2.id")
|
||||
.add("SELECT * FROM T2 LEFT JOIN T3 ON T2.id = T3.id, T1 WHERE T1.id = T2.id AND T1.score > 0")
|
||||
@ -52,6 +53,7 @@ public class MultiJoinTest extends SqlTestBase {
|
||||
@Test
|
||||
@Disabled
|
||||
void testEliminateBelowOuter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
// FIXME: MultiJoin And EliminateOuter
|
||||
String sql = "SELECT * FROM T1, T2 LEFT JOIN T3 ON T2.id = T3.id WHERE T1.id = T2.id";
|
||||
PlanChecker.from(connectContext)
|
||||
@ -62,6 +64,7 @@ public class MultiJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testPushdownAndEliminateOuter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "SELECT * FROM T1 LEFT JOIN T2 ON T1.id = T2.id WHERE T2.score > 0";
|
||||
PlanChecker.from(connectContext)
|
||||
.analyze(sql)
|
||||
@ -86,6 +89,7 @@ public class MultiJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testMultiJoinExistCross() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
List<String> sqls = ImmutableList.<String>builder()
|
||||
.add("SELECT * FROM T2 LEFT SEMI JOIN T3 ON T2.id = T3.id, T1 WHERE T1.id > T2.id")
|
||||
.build();
|
||||
@ -107,6 +111,7 @@ public class MultiJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void testOuterJoin() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "SELECT * FROM T1 LEFT OUTER JOIN T2 ON T1.id = T2.id, T3 WHERE T2.score > 0";
|
||||
PlanChecker.from(connectContext)
|
||||
.analyze(sql)
|
||||
@ -124,6 +129,7 @@ public class MultiJoinTest extends SqlTestBase {
|
||||
@Test
|
||||
@Disabled
|
||||
void testNoFilter() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "Select * FROM T1 INNER JOIN T2 On true";
|
||||
PlanChecker.from(connectContext)
|
||||
.analyze(sql)
|
||||
@ -135,6 +141,7 @@ public class MultiJoinTest extends SqlTestBase {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "select T1.score, T2.score from T1 inner join T2 on T1.id = T2.id where T1.score - 2 > T2.score";
|
||||
PlanChecker.from(connectContext)
|
||||
.analyze(sql)
|
||||
|
||||
@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class SortTest extends SqlTestBase {
|
||||
@Test
|
||||
public void testTwoPhaseSort() {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
String sql = "select * from\n"
|
||||
+ "(select score from T1 order by id) as t order by score\n";
|
||||
PhysicalPlan plan = PlanChecker.from(connectContext)
|
||||
|
||||
@ -33,6 +33,7 @@ public class DeleteFromUsingCommandTest extends TestWithFeService implements Pla
|
||||
protected void runBeforeAll() throws Exception {
|
||||
createDatabase("test");
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
createTable("create table t1 (\n"
|
||||
+ " k1 int,\n"
|
||||
+ " k2 int,\n"
|
||||
|
||||
@ -30,13 +30,17 @@ import org.apache.doris.nereids.trees.plans.visitor.NondeterministicFunctionColl
|
||||
import org.apache.doris.nereids.trees.plans.visitor.TableCollector;
|
||||
import org.apache.doris.nereids.trees.plans.visitor.TableCollector.TableCollectorContext;
|
||||
import org.apache.doris.nereids.util.PlanChecker;
|
||||
import org.apache.doris.qe.SessionVariable;
|
||||
import org.apache.doris.utframe.TestWithFeService;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import mockit.Mock;
|
||||
import mockit.MockUp;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -51,6 +55,7 @@ public class PlanVisitorTest extends TestWithFeService {
|
||||
protected void runBeforeAll() throws Exception {
|
||||
createDatabase("visitor_test");
|
||||
useDatabase("visitor_test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
|
||||
createTable("CREATE TABLE `table1` (\n"
|
||||
+ " `c1` varchar(20) NULL,\n"
|
||||
@ -166,6 +171,14 @@ public class PlanVisitorTest extends TestWithFeService {
|
||||
|
||||
@Test
|
||||
public void test3() throws Exception {
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
BitSet disableNereidsRules = connectContext.getSessionVariable().getDisableNereidsRules();
|
||||
new MockUp<SessionVariable>() {
|
||||
@Mock
|
||||
public BitSet getDisableNereidsRules() {
|
||||
return disableNereidsRules;
|
||||
}
|
||||
};
|
||||
PlanChecker.from(connectContext)
|
||||
.checkPlannerResult("SELECT mv1.*, uuid() FROM mv1 "
|
||||
+ "INNER JOIN view1 on mv1.c1 = view1.c2 "
|
||||
|
||||
@ -32,6 +32,7 @@ public class UpdateCommandTest extends TestWithFeService implements PlanPatternM
|
||||
public void runBeforeAll() throws Exception {
|
||||
createDatabase("test");
|
||||
connectContext.setDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
createTable("create table t1 (\n"
|
||||
+ " k1 int,\n"
|
||||
+ " k2 int,\n"
|
||||
|
||||
@ -92,6 +92,7 @@ public class ExpressionUtilsTest extends TestWithFeService {
|
||||
+ "PROPERTIES (\n"
|
||||
+ " \"replication_num\" = \"1\"\n"
|
||||
+ ")");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -31,6 +31,7 @@ public class StatisticDeriveTest extends TestWithFeService {
|
||||
Config.enable_odbc_mysql_broker_table = true;
|
||||
// create database
|
||||
createDatabase("test");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
|
||||
createTable(
|
||||
"CREATE TABLE test.join1 (\n"
|
||||
|
||||
@ -26,6 +26,7 @@ public class TpchTest extends TestWithFeService {
|
||||
@Override
|
||||
protected void runBeforeAll() throws Exception {
|
||||
createDatabase("db1");
|
||||
connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION");
|
||||
|
||||
// Create tables.
|
||||
String lineitem = "CREATE TABLE db1.lineitem (\n"
|
||||
|
||||
@ -128,6 +128,7 @@ public class OlapQueryCacheTest {
|
||||
Config.cache_enable_partition_mode = true;
|
||||
context.getSessionVariable().setEnableSqlCache(true);
|
||||
context.getSessionVariable().setEnablePartitionCache(true);
|
||||
|
||||
Config.cache_last_version_interval_second = 7200;
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
@ -510,6 +511,7 @@ public class OlapQueryCacheTest {
|
||||
LogicalPlan plan = new NereidsParser().parseSingle(sql);
|
||||
OriginStatement originStatement = new OriginStatement(sql, 0);
|
||||
StatementContext statementContext = new StatementContext(ctx, originStatement);
|
||||
ctx.setStatementContext(statementContext);
|
||||
NereidsPlanner nereidsPlanner = new NereidsPlanner(statementContext);
|
||||
LogicalPlanAdapter adapter = new LogicalPlanAdapter(plan, statementContext);
|
||||
nereidsPlanner.plan(adapter);
|
||||
|
||||
Reference in New Issue
Block a user