From 70f02c71b54075bbaab0c3cb52208fe6da3156dd Mon Sep 17 00:00:00 2001 From: David Gow Date: Tue, 15 May 2018 15:54:50 -0700 Subject: [PATCH] Make sort_keys comparator irreflexive (bug #90878) Comparators passed to std::sort need to obey a strict weak ordering, and sort_keys() does not. In particular, it is not irreflexive: sort_keys(x,x) can be true, implying x < x. This occurs when x is a primary key (i.e. x.name == primary_key_name). In this patch, we do not exit early if both inputs are primary keys, fixing this. See: https://bugs.mysql.com/bug.php?id=90878 --- sql/sql_table.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index d4561db6d15..d369bf9c11d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3364,8 +3364,10 @@ struct sort_keys { return b.flags & HA_NULL_PART_KEY; // Sort PRIMARY KEY before other UNIQUE NOT NULL. - if (a.name == primary_key_name) return true; - if (b.name == primary_key_name) return false; + if (a.name != b.name) { + if (a.name == primary_key_name) return true; + if (b.name == primary_key_name) return false; + } // Sort keys don't containing partial segments before others. if ((a.flags ^ b.flags) & HA_KEY_HAS_PART_KEY_SEG) -- 2.17.0.441.gb46fe60e1d-goog