|
24 | 24 |
|
25 | 25 | #include <limits.h>
|
26 | 26 | #include <stdio.h>
|
| 27 | +#include <stdlib.h> |
27 | 28 | #include <string.h>
|
28 | 29 |
|
29 | 30 | #include <algorithm>
|
|
68 | 69 | #include "sql/trigger_def.h"
|
69 | 70 | #include "sql_string.h"
|
70 | 71 | #include "string_with_len.h"
|
71 |
| -#include "varlen_sort.h" |
72 | 72 |
|
73 | 73 | using std::string;
|
74 | 74 |
|
@@ -1176,45 +1176,50 @@ bool partition_info::check_range_constants(THD *thd) {
|
1176 | 1176 | goto end;
|
1177 | 1177 | }
|
1178 | 1178 |
|
1179 |
| -/* |
1180 |
| - Compare two lists of column values in RANGE/LIST partitioning |
1181 |
| - SYNOPSIS |
1182 |
| - compare_column_values() |
1183 |
| - first First column list argument |
1184 |
| - second Second column list argument |
1185 |
| - RETURN VALUES |
1186 |
| - true first < second |
1187 |
| - false first >= second |
1188 |
| -*/ |
1189 |
| - |
1190 |
| -static bool partition_info_compare_column_values( |
| 1179 | +static int partition_info_compare_column_values( |
1191 | 1180 | const part_column_list_val *first, const part_column_list_val *second) {
|
1192 | 1181 | for (Field **field = first->part_info->part_field_array; *field;
|
1193 | 1182 | field++, first++, second++) {
|
1194 | 1183 | /*
|
1195 | 1184 | If both are maxvalue, they are equal (don't check the rest of the parts).
|
1196 | 1185 | Otherwise, maxvalue > *.
|
1197 |
| - */ |
1198 |
| - if (first->max_value || second->max_value) |
1199 |
| - return first->max_value < second->max_value; |
| 1186 | + */ |
| 1187 | + if (first->max_value) { |
| 1188 | + return second->max_value ? 0 : 1; |
| 1189 | + } else if (second->max_value) { |
| 1190 | + return -1; |
| 1191 | + } |
1200 | 1192 |
|
1201 | 1193 | // NULLs sort before non-NULLs.
|
1202 |
| - if (first->null_value != second->null_value) return first->null_value; |
| 1194 | + if (first->null_value != second->null_value) { |
| 1195 | + return first->null_value ? -1 : 1; |
| 1196 | + } |
1203 | 1197 |
|
1204 | 1198 | // For non-NULLs, compare the actual fields.
|
1205 | 1199 | if (!first->null_value) {
|
1206 | 1200 | int res = (*field)->cmp(first->column_value.field_image,
|
1207 | 1201 | second->column_value.field_image);
|
1208 |
| - if (res != 0) return res < 0; |
| 1202 | + if (res != 0) return res; |
1209 | 1203 | }
|
1210 | 1204 | }
|
1211 |
| - return false; |
| 1205 | + return 0; |
1212 | 1206 | }
|
1213 | 1207 |
|
| 1208 | +/* |
| 1209 | + Compare two lists of column values in RANGE/LIST partitioning |
| 1210 | + SYNOPSIS |
| 1211 | + compare_column_values() |
| 1212 | + first First column list argument |
| 1213 | + second Second column list argument |
| 1214 | + RETURN VALUES |
| 1215 | + true first < second |
| 1216 | + false first >= second |
| 1217 | +*/ |
| 1218 | + |
1214 | 1219 | bool partition_info::compare_column_values(
|
1215 | 1220 | const part_column_list_val *first_arg,
|
1216 | 1221 | const part_column_list_val *second_arg) {
|
1217 |
| - return partition_info_compare_column_values(first_arg, second_arg); |
| 1222 | + return partition_info_compare_column_values(first_arg, second_arg) < 0; |
1218 | 1223 | }
|
1219 | 1224 |
|
1220 | 1225 | /*
|
@@ -1309,14 +1314,17 @@ bool partition_info::check_list_constants(THD *thd) {
|
1309 | 1314 | }
|
1310 | 1315 | } while (++part_id < num_parts);
|
1311 | 1316 |
|
1312 |
| - varlen_sort(list_col_array, |
1313 |
| - list_col_array + num_list_values * num_column_values, |
1314 |
| - size_entries, partition_info_compare_column_values); |
| 1317 | + qsort(list_col_array, num_list_values, size_entries, |
| 1318 | + [](const void *a, const void *b) { |
| 1319 | + return partition_info_compare_column_values( |
| 1320 | + static_cast<const part_column_list_val *>(a), |
| 1321 | + static_cast<const part_column_list_val *>(b)); |
| 1322 | + }); |
1315 | 1323 |
|
1316 | 1324 | for (uint i = 1; i < num_list_values; ++i) {
|
1317 |
| - if (!partition_info_compare_column_values( |
| 1325 | + if (partition_info_compare_column_values( |
1318 | 1326 | &list_col_array[num_column_values * (i - 1)],
|
1319 |
| - &list_col_array[num_column_values * i])) { |
| 1327 | + &list_col_array[num_column_values * i]) >= 0) { |
1320 | 1328 | my_error(ER_MULTIPLE_DEF_CONST_IN_LIST_PART_ERROR, MYF(0));
|
1321 | 1329 | goto end;
|
1322 | 1330 | }
|
|
0 commit comments