From 4f65ea334995a7e48c441c748a29d9fe8bb82d78 Mon Sep 17 00:00:00 2001 From: obdev Date: Mon, 6 Feb 2023 13:56:36 +0800 Subject: [PATCH] Partition sort check earlier and more strictly --- src/sql/code_generator/ob_static_engine_cg.cpp | 10 ++++++++++ src/sql/engine/sort/ob_sort_op_impl.cpp | 9 ++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/sql/code_generator/ob_static_engine_cg.cpp b/src/sql/code_generator/ob_static_engine_cg.cpp index 7823eec379..e917dc24b3 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 287a2ace7c..4682c10a61 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)); -- GitLab