diff --git a/src/sql/code_generator/ob_static_engine_cg.cpp b/src/sql/code_generator/ob_static_engine_cg.cpp index 7823eec379826753ec73bcffbd1fd35e52c436c5..e917dc24b321c4d1ab9d3e4448f632bf0d725460 100644 --- a/src/sql/code_generator/ob_static_engine_cg.cpp +++ b/src/sql/code_generator/ob_static_engine_cg.cpp @@ -1762,6 +1762,16 @@ int ObStaticEngineCG::generate_spec(ObLogSort &op, ObSortSpec &spec, const bool spec.part_cnt_ = op.get_part_cnt(); LOG_TRACE("trace order by", K(spec.all_exprs_.count()), K(spec.all_exprs_)); } + if (OB_SUCC(ret)) { + if (spec.sort_collations_.count() != spec.sort_cmp_funs_.count() + || (spec.part_cnt_ > 0 && spec.part_cnt_ >= spec.sort_collations_.count())) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("part cnt or sort size not meet the expection", K(ret), + K(OB_NOT_NULL(op.get_topn_expr())), K(OB_NOT_NULL(op.get_topk_limit_expr())), + K(spec.enable_encode_sortkey_opt_), K(spec.prefix_pos_), K(spec.is_local_merge_sort_), + K(spec.part_cnt_), K(spec.sort_collations_.count()), K(spec.sort_cmp_funs_.count())); + } + } } } return ret; diff --git a/src/sql/engine/sort/ob_sort_op_impl.cpp b/src/sql/engine/sort/ob_sort_op_impl.cpp index 287a2ace7c9e2f21a05e98754185cb2762e32e6a..4682c10a6119820bf917454530959ff03ae78696 100644 --- a/src/sql/engine/sort/ob_sort_op_impl.cpp +++ b/src/sql/engine/sort/ob_sort_op_impl.cpp @@ -596,12 +596,11 @@ int ObSortOpImpl::init( } else if (OB_INVALID_ID == tenant_id) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument", K(ret), K(tenant_id)); - } else if (OB_ISNULL(sort_collations) || OB_ISNULL(sort_cmp_funs) || OB_ISNULL(eval_ctx) - || sort_collations->count() != sort_cmp_funs->count() || OB_ISNULL(exec_ctx) - || part_cnt > sort_collations->count()) { + } else if (OB_ISNULL(sort_collations) || OB_ISNULL(sort_cmp_funs) + || OB_ISNULL(eval_ctx) || OB_ISNULL(exec_ctx)) { ret = OB_INVALID_ARGUMENT; - LOG_WARN("invalid argument: argument is null", K(ret), K(tenant_id), - K(sort_collations), K(sort_cmp_funs), K(eval_ctx), K(part_cnt)); + LOG_WARN("invalid argument: argument is null", K(ret), + K(tenant_id), K(sort_collations), K(sort_cmp_funs), K(eval_ctx)); } else if (OB_FAIL(comp_.init(sort_collations, sort_cmp_funs, exec_ctx, enable_encode_sortkey))) { LOG_WARN("failed to init compare functions", K(ret));