Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Fixed
-
10.1(EOL)
-
None
Description
UNIV_LIKELY()/UNIV_UNLIKELY() hints are supposed to improve branch prediction. They're defined in InnoDB as following:
/* Tell the compiler that 'expr' probably evaluates to 'constant'. */
|
# define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant)
|
/* Tell the compiler that cond is likely to hold */
|
#define UNIV_LIKELY(cond) UNIV_EXPECT(cond, TRUE)
|
/* Tell the compiler that cond is unlikely to hold */
|
#define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, FALSE)
|
In other words they're expected to work only if cond evaluates to TRUE or FALSE,
see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html.
However there're a few conditions that may evaluate to different values, e.g.:
page/page0zip.cc: if (UNIV_LIKELY(c_stream->avail_in)) {
|
page/page0zip.cc: if (UNIV_LIKELY(c_stream->avail_in)) {
|
dict/dict0mem.cc: if (UNIV_LIKELY(i) && UNIV_UNLIKELY(!table->col_names)) {
|
Either fix condition or fix UNIV_LIKELY() to evaluate condition to bool (see likely() in my_global.h).
Note: we'll gain little to nothing in terms of performance out of this. But at least we'll have correct use of these compiler hints.