diff --git a/src/sql/optimizer/ob_del_upd_log_plan.cpp b/src/sql/optimizer/ob_del_upd_log_plan.cpp index 4f1921b13a..b50bc54f49 100644 --- a/src/sql/optimizer/ob_del_upd_log_plan.cpp +++ b/src/sql/optimizer/ob_del_upd_log_plan.cpp @@ -323,7 +323,8 @@ int ObDelUpdLogPlan::calculate_insert_table_location_and_sharding(ObTablePartiti &dml_table_infos.at(0)->part_ids_, insert_sharding, insert_table_part))) { - if (ret == OB_NO_PARTITION_FOR_GIVEN_VALUE && trigger_exist) { + if (ret == OB_NO_PARTITION_FOR_GIVEN_VALUE && + (trigger_exist || (del_upd_stmt->is_insert_stmt() && static_cast(del_upd_stmt)->value_from_select()))) { ret = OB_SUCCESS; } else { LOG_WARN("failed to calculate table location and sharding", K(ret)); diff --git a/src/sql/optimizer/ob_insert_log_plan.cpp b/src/sql/optimizer/ob_insert_log_plan.cpp index 2d0059b551..bd2fccbf75 100644 --- a/src/sql/optimizer/ob_insert_log_plan.cpp +++ b/src/sql/optimizer/ob_insert_log_plan.cpp @@ -659,6 +659,8 @@ int ObInsertLogPlan::check_insert_location_need_multi_partition_dml(ObLogicalOpe ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(insert_table_part), K(insert_sharding), K(insert_stmt), K(ret)); + } else if (0 == insert_table_part->get_phy_tbl_location_info().get_partition_cnt()) { + is_multi_part_dml = true; } else if (OB_FAIL(check_basic_sharding_for_insert_stmt(*insert_sharding, top, is_basic))) { diff --git a/src/sql/optimizer/ob_log_plan.cpp b/src/sql/optimizer/ob_log_plan.cpp index f6b2e4ad84..c5b647bf0d 100644 --- a/src/sql/optimizer/ob_log_plan.cpp +++ b/src/sql/optimizer/ob_log_plan.cpp @@ -11978,6 +11978,9 @@ int ObLogPlan::build_location_related_tablet_ids() if (OB_ISNULL(table_part_info)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("invalid partition info", K(ret)); + } else if (0 == table_part_info->get_phy_tbl_location_info().get_partition_cnt()) { + // partition count is 0 means no matching partition for data table, no need to calculate + // related tablet ids for it. } else if (!table_part_info->get_table_location().use_das() && OB_FAIL(ObPhyLocationGetter::build_related_tablet_info( table_part_info->get_table_location(), *optimizer_context_.get_exec_ctx(), map))) { diff --git a/src/sql/optimizer/ob_logical_operator.cpp b/src/sql/optimizer/ob_logical_operator.cpp index 170e32b5ae..2f6d65880a 100644 --- a/src/sql/optimizer/ob_logical_operator.cpp +++ b/src/sql/optimizer/ob_logical_operator.cpp @@ -3630,6 +3630,8 @@ int ObLogicalOperator::explain_print_partitions(ObTablePartitionInfo &table_part || OB_ISNULL(stmt = get_plan()->get_stmt())) { ret = OB_INVALID_ARGUMENT; LOG_WARN("NULL pointer error", K(get_plan()), K(opt_ctx), K(schema_guard), K(ret)); + } else if (partitions.count() == 0) { + // do nothing } else if (OB_FAIL(schema_guard->get_table_schema(ref_table_id, table_schema))) { LOG_WARN("fail to get index schema", K(ret), K(ref_table_id), K(table_id)); } diff --git a/tools/deploy/mysql_test/test_suite/optimizer/r/mysql/equal_set_mysql.result b/tools/deploy/mysql_test/test_suite/optimizer/r/mysql/equal_set_mysql.result index 62506eb1b1..54b5e6ffd8 100644 --- a/tools/deploy/mysql_test/test_suite/optimizer/r/mysql/equal_set_mysql.result +++ b/tools/deploy/mysql_test/test_suite/optimizer/r/mysql/equal_set_mysql.result @@ -6123,7 +6123,7 @@ Outputs & filters: 2 - output([t1.a], [t1.b], [t1.c], [t1.d]), filter(nil), rowset=256 partition wise, force partition granule 3 - output([t1.a], [t1.b], [t1.c], [t1.d]), filter(nil), rowset=256 - conds(nil), nl_params_([VIEW2.VIEW1.a(:2)], [VIEW2.VIEW1.b(:3)]), use_batch=false + conds(nil), nl_params_([VIEW2.VIEW1.a(:0)], [VIEW2.VIEW1.b(:1)]), use_batch=false 4 - output([VIEW2.VIEW1.a], [VIEW2.VIEW1.b]), filter(nil), rowset=256 access([VIEW2.VIEW1.a], [VIEW2.VIEW1.b]) 5 - output([t2.a], [t2.b]), filter(nil), rowset=256 @@ -6136,7 +6136,7 @@ Outputs & filters: access([t1.a], [t1.b], [t1.c], [t1.d]), partitions(p0sp[0-4], p1sp[0-4], p2sp[0-4], p3sp[0-4], p4sp[0-4]) is_index_back=false, is_global_index=false, range_key([t1.a], [t1.b], [t1.c]), range(MIN ; MAX), - range_cond([t1.a = :2], [t1.b = :3]) + range_cond([t1.a = :0], [t1.b = :1]) explain select * from t1 where (t1.a, t1.b) in (select t2.a, t2.b from t2) and (t1.a, t1.b) in (select t3.a, t3.b from t3); Query Plan ================================================================= @@ -6161,9 +6161,9 @@ Outputs & filters: 2 - output([t1.a], [t1.b], [t1.c], [t1.d]), filter(nil), rowset=256 partition wise, force partition granule 3 - output([t1.a], [t1.b], [t1.c], [t1.d]), filter(nil), rowset=256 - conds(nil), nl_params_([t1.a(:4)], [t1.b(:5)]), use_batch=false + conds(nil), nl_params_([t1.a(:2)], [t1.b(:3)]), use_batch=false 4 - output([t1.a], [t1.b], [t1.c], [t1.d]), filter(nil), rowset=256 - conds(nil), nl_params_([VIEW3.VIEW1.a(:2)], [VIEW3.VIEW1.b(:3)]), use_batch=false + conds(nil), nl_params_([VIEW3.VIEW1.a(:0)], [VIEW3.VIEW1.b(:1)]), use_batch=false 5 - output([VIEW3.VIEW1.a], [VIEW3.VIEW1.b]), filter(nil), rowset=256 access([VIEW3.VIEW1.a], [VIEW3.VIEW1.b]) 6 - output([t2.a], [t2.b]), filter(nil), rowset=256 @@ -6176,12 +6176,12 @@ Outputs & filters: access([t1.a], [t1.b], [t1.c], [t1.d]), partitions(p0sp[0-4], p1sp[0-4], p2sp[0-4], p3sp[0-4], p4sp[0-4]) is_index_back=false, is_global_index=false, range_key([t1.a], [t1.b], [t1.c]), range(MIN ; MAX), - range_cond([t1.a = :2], [t1.b = :3]) + range_cond([t1.a = :0], [t1.b = :1]) 9 - output(nil), filter(nil), rowset=256 access(nil), partitions(p0sp[0-4], p1sp[0-4], p2sp[0-4], p3sp[0-4], p4sp[0-4]) is_index_back=false, is_global_index=false, range_key([t3.a], [t3.b], [t3.c]), range(MIN ; MAX), - range_cond([:4 = t3.a], [:5 = t3.b]) + range_cond([:2 = t3.a], [:3 = t3.b]) explain select * from t1 where (t1.a, t1.b) in (select t2.a, t2.b from t2 where (t2.a, t2.b) in (select t3.a, t3.b from t3)); Query Plan =================================================================== @@ -6207,7 +6207,7 @@ Outputs & filters: 2 - output([t1.a], [t1.b], [t1.c], [t1.d]), filter(nil), rowset=256 partition wise, force partition granule 3 - output([t1.a], [t1.b], [t1.c], [t1.d]), filter(nil), rowset=256 - conds(nil), nl_params_([t1.a(:4)], [t1.b(:5)]), use_batch=false + conds(nil), nl_params_([t1.a(:2)], [t1.b(:3)]), use_batch=false 4 - output([t1.a], [t1.b], [t1.c], [t1.d]), filter(nil), rowset=256 access([t1.a], [t1.b], [t1.c], [t1.d]), partitions(p0sp[0-4], p1sp[0-4], p2sp[0-4], p3sp[0-4], p4sp[0-4]) is_index_back=false, is_global_index=false, @@ -6215,7 +6215,7 @@ Outputs & filters: 5 - output(nil), filter(nil), rowset=256 access(nil) 6 - output([t2.a], [t2.b]), filter(nil), rowset=256 - conds(nil), nl_params_([VIEW3.VIEW1.a(:8)], [VIEW3.VIEW1.b(:9)]), use_batch=false + conds(nil), nl_params_([VIEW3.VIEW1.a(:4)], [VIEW3.VIEW1.b(:5)]), use_batch=false 7 - output([VIEW3.VIEW1.a], [VIEW3.VIEW1.b]), filter(nil), rowset=256 access([VIEW3.VIEW1.a], [VIEW3.VIEW1.b]) 8 - output([t3.a], [t3.b]), filter(nil), rowset=256 @@ -6228,7 +6228,7 @@ Outputs & filters: access([t2.a], [t2.b]), partitions(p0sp[0-4], p1sp[0-4], p2sp[0-4], p3sp[0-4], p4sp[0-4]) is_index_back=false, is_global_index=false, range_key([t2.a], [t2.b], [t2.c]), range(MIN ; MAX), - range_cond([:4 = t2.a], [:5 = t2.b], [t2.a = :8], [t2.b = :9]) + range_cond([:2 = t2.a], [:3 = t2.b], [t2.a = :4], [t2.b = :5]) drop table if exists t1, t2, t3; create table t1(a int, b int) partition by hash(a+1) partitions 5; create table t2(a int, b int) partition by hash(a+1) partitions 5;