Skip to content

Commit 5aa611c

Browse files
obdevwyfanxiaoLINxiansheng
authored andcommitted
fix: use pointer comparison as fallback in sort comparator error state to prevent macOS crash
Co-authored-by: wyfanxiao <wyfanxiao@163.com> Co-authored-by: LINxiansheng <wangzelin19961202@gmail.com>
1 parent e8f2bbf commit 5aa611c

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/sql/engine/sort/ob_sort_compare_vec_op.ipp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ bool GeneralCompare<Store_Row, has_addon>::operator()(const Store_Row *l, const
2525
bool less = false;
2626
int &ret = ret_;
2727
if (OB_UNLIKELY(OB_SUCCESS != ret)) {
28+
// Use pointer comparison as a consistent fallback to maintain strict weak ordering.
29+
// Returning false for all pairs would cause introsort's right-scan loop
30+
// (while !comp(pivot, *i)) to advance past array bounds, triggering abort().
31+
less = l < r;
2832
} else if (OB_FAIL(fast_check_status())) {
2933
SQL_ENG_LOG(WARN, "fast check failed", K(ret));
34+
less = l < r;
3035
} else {
3136
if (CompareBase::ENABLE == encode_sk_state_) {
3237
ObLength l_len = 0;
@@ -260,8 +265,10 @@ bool SingleColCompare<Store_Row, is_basic_cmp, is_topn_sort>::operator()(const S
260265
bool less = false;
261266
int &ret = ret_;
262267
if (OB_UNLIKELY(OB_SUCCESS != ret)) {
268+
less = l < r;
263269
} else if (OB_FAIL(fast_check_status())) {
264270
SQL_ENG_LOG(WARN, "fast check failed", K(ret));
271+
less = l < r;
265272
} else {
266273
__builtin_prefetch(l, 0 /* read */, 2 /*high temp locality*/);
267274
__builtin_prefetch(r, 0 /* read */, 2 /*high temp locality*/);
@@ -492,8 +499,10 @@ bool FixedCompare<Store_Row, has_addon>::operator()(const Store_Row *l, const St
492499
bool less = false;
493500
int &ret = ret_;
494501
if (OB_UNLIKELY(OB_SUCCESS != ret)) {
502+
less = l < r;
495503
} else if (OB_FAIL(fast_check_status())) {
496504
SQL_ENG_LOG(WARN, "fast check failed", K(ret));
505+
less = l < r;
497506
} else {
498507
__builtin_prefetch(l, 0 /* read */, 2 /*high temp locality*/);
499508
__builtin_prefetch(r, 0 /* read */, 2 /*high temp locality*/);

src/sql/engine/sort/ob_sort_op_impl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,15 @@ bool ObSortOpImpl::Compare::operator()(
401401
bool less = false;
402402
int &ret = ret_;
403403
if (OB_UNLIKELY(OB_SUCCESS != ret)) {
404-
// already fail
404+
// Use pointer comparison to maintain strict weak ordering in error state,
405+
// preventing Apple libc++ sort consistency check from triggering abort().
406+
less = l < r;
405407
} else if (!is_inited() || OB_ISNULL(l) || OB_ISNULL(r)) {
406408
ret = !is_inited() ? OB_NOT_INIT : OB_INVALID_ARGUMENT;
407409
LOG_WARN("not init or invalid argument", K(ret), KP(l), KP(r));
408410
} else if (OB_FAIL(fast_check_status())) {
409411
LOG_WARN("fast check failed", K(ret));
412+
less = l < r;
410413
} else if (enable_encode_sortkey_) {
411414
const ObDatum l_cell = l->cells()[0];
412415
const ObDatum r_cell = r->cells()[0];

0 commit comments

Comments
 (0)