Skip to content

Commit 6d23377

Browse files
committed
Bug#31355484: ABI compatibility complaint after WL#9384 change
Worklog # 9384 changed the value of MAX_CHAR_WIDTH from 255 to 255U. While probably harmless, we'll change it back. Patch also moves the new max blob size constant values from mysql_com.h to class Field (sql/field.h). The max size constants are also consolidated with those found in sql/create_field.h. Reviewed by: Guilhem Bichot <guilhem.bichot@oracle.com> Change-Id: I5f0031174d4143995bec2493cd57ec84f7e81b4f
1 parent 173c88a commit 6d23377

File tree

7 files changed

+29
-48
lines changed

7 files changed

+29
-48
lines changed

include/mysql_com.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -846,18 +846,8 @@ struct Vio;
846846
#define MAX_INT_WIDTH 10 /**< Max width for a LONG w.o. sign */
847847
#define MAX_BIGINT_WIDTH 20 /**< Max width for a LONGLONG */
848848
/// Max width for a CHAR column, in number of characters
849-
#define MAX_CHAR_WIDTH 255U
850-
/// Max width for a VARCHAR column, in number of bytes
851-
#define MAX_VARCHAR_WIDTH 65535U
852-
/// Max width for a tiny blob, in bytes
853-
#define MAX_TINY_BLOB_WIDTH 255U
854-
/// Max width for a short blob (aka BLOB), in bytes
855-
#define MAX_SHORT_BLOB_WIDTH 65535U
856-
/// Max width for a medium blob, in bytes
857-
#define MAX_MEDIUM_BLOB_WIDTH 16777215U
858-
/// Max width for a long blob, in bytes
859-
#define MAX_LONG_BLOB_WIDTH 4294967295U
860-
/// Default width for blob @todo - replace this with the specific types above?
849+
#define MAX_CHAR_WIDTH 255
850+
/// Default width for blob in bytes @todo - align this with sizes from field.h
861851
#define MAX_BLOB_WIDTH 16777216
862852

863853
typedef struct NET {

sql/create_field.cc

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232

3333
#include <cmath>
3434

35-
// Definition of static constexpr data members in Create_field.
36-
constexpr size_t Create_field::TINYBLOB_MAX_SIZE_IN_BYTES;
37-
constexpr size_t Create_field::BLOB_MAX_SIZE_IN_BYTES;
38-
constexpr size_t Create_field::MEDIUMBLOB_MAX_SIZE_IN_BYTES;
39-
constexpr size_t Create_field::LONGBLOB_MAX_SIZE_IN_BYTES;
40-
4135
/**
4236
Constructs a column definition from an object representing an actual
4337
column. This is a reverse-engineering procedure that creates a column
@@ -659,19 +653,19 @@ size_t Create_field::max_display_width_in_codepoints() const {
659653
return std::min(max_display_width_in_codepoints,
660654
static_cast<size_t>(MAX_FIELD_WIDTH - 1));
661655
} else if (sql_type == MYSQL_TYPE_TINY_BLOB) {
662-
return TINYBLOB_MAX_SIZE_IN_BYTES / charset->mbmaxlen;
656+
return Field::MAX_TINY_BLOB_WIDTH / charset->mbmaxlen;
663657
} else if (sql_type == MYSQL_TYPE_BLOB && !explicit_display_width()) {
664658
// For BLOB and TEXT, the user can give a display width explicitly in CREATE
665659
// TABLE (BLOB(25), TEXT(25)) where the expected behavior is that the server
666660
// will find the smallest possible BLOB/TEXT type that will fit the given
667661
// display width. If the user has given an explicit display width, return
668662
// that instead of the max BLOB size.
669-
return BLOB_MAX_SIZE_IN_BYTES / charset->mbmaxlen;
663+
return Field::MAX_SHORT_BLOB_WIDTH / charset->mbmaxlen;
670664
} else if (sql_type == MYSQL_TYPE_MEDIUM_BLOB) {
671-
return MEDIUMBLOB_MAX_SIZE_IN_BYTES / charset->mbmaxlen;
665+
return Field::MAX_MEDIUM_BLOB_WIDTH / charset->mbmaxlen;
672666
} else if (sql_type == MYSQL_TYPE_LONG_BLOB || sql_type == MYSQL_TYPE_JSON ||
673667
sql_type == MYSQL_TYPE_GEOMETRY) {
674-
return LONGBLOB_MAX_SIZE_IN_BYTES / charset->mbmaxlen;
668+
return Field::MAX_LONG_BLOB_WIDTH / charset->mbmaxlen;
675669
} else {
676670
return m_max_display_width_in_codepoints;
677671
}
@@ -691,29 +685,29 @@ size_t Create_field::max_display_width_in_bytes() const {
691685
// Numeric types, temporal types, YEAR or BIT are never multi-byte.
692686
return max_display_width_in_codepoints();
693687
} else if (sql_type == MYSQL_TYPE_TINY_BLOB) {
694-
return TINYBLOB_MAX_SIZE_IN_BYTES;
688+
return Field::MAX_TINY_BLOB_WIDTH;
695689
} else if (sql_type == MYSQL_TYPE_BLOB && !explicit_display_width()) {
696690
// For BLOB and TEXT, the user can give a display width (BLOB(25), TEXT(25))
697691
// where the expected behavior is that the server will find the smallest
698692
// possible BLOB/TEXT type that will fit the given display width. If the
699693
// user has given an explicit display width, return that instead of the
700694
// max BLOB size.
701-
return BLOB_MAX_SIZE_IN_BYTES;
695+
return Field::MAX_SHORT_BLOB_WIDTH;
702696
} else if (sql_type == MYSQL_TYPE_MEDIUM_BLOB) {
703-
return MEDIUMBLOB_MAX_SIZE_IN_BYTES;
697+
return Field::MAX_MEDIUM_BLOB_WIDTH;
704698
} else if (sql_type == MYSQL_TYPE_LONG_BLOB || sql_type == MYSQL_TYPE_JSON ||
705699
sql_type == MYSQL_TYPE_GEOMETRY) {
706-
return LONGBLOB_MAX_SIZE_IN_BYTES;
700+
return Field::MAX_LONG_BLOB_WIDTH;
707701
} else {
708702
// If the user has given a display width to the TEXT type where the display
709703
// width is 2^32-1, the below computation will exceed
710-
// LONGBLOB_MAX_SIZE_IN_BYTES if the character set is multi-byte. So we must
704+
// MAX_LONG_BLOB_WIDTH if the character set is multi-byte. So we must
711705
// ensure that we never return a value greater than
712-
// LONGBLOB_MAX_SIZE_IN_BYTES.
706+
// MAX_LONG_BLOB_WIDTH.
713707
std::int64_t display_width = max_display_width_in_codepoints() *
714708
static_cast<std::int64_t>(charset->mbmaxlen);
715709
return static_cast<size_t>(std::min(
716-
display_width, static_cast<std::int64_t>(LONGBLOB_MAX_SIZE_IN_BYTES)));
710+
display_width, static_cast<std::int64_t>(Field::MAX_LONG_BLOB_WIDTH)));
717711
}
718712
}
719713

sql/create_field.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,6 @@ class Create_field {
257257

258258
/// Whether or not the display width was given explicitly by the user.
259259
bool m_explicit_display_width{false};
260-
261-
/// The maximum number of bytes a TINYBLOB can hold.
262-
static constexpr size_t TINYBLOB_MAX_SIZE_IN_BYTES{255};
263-
264-
/// The maximum number of bytes a BLOB can hold.
265-
static constexpr size_t BLOB_MAX_SIZE_IN_BYTES{65535};
266-
267-
/// The maximum number of bytes a MEDIUMBLOB can hold.
268-
static constexpr size_t MEDIUMBLOB_MAX_SIZE_IN_BYTES{16777215};
269-
270-
/// The maximum number of bytes a LONGBLOB can hold.
271-
static constexpr size_t LONGBLOB_MAX_SIZE_IN_BYTES{4294967295};
272260
};
273261

274262
/// @returns whether or not this field is a hidden column that represents a

sql/field.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,15 @@ class Field {
864864
};
865865
enum imagetype { itRAW, itMBR };
866866

867+
// Max width for a VARCHAR column, in number of bytes
868+
static constexpr size_t MAX_VARCHAR_WIDTH{65535};
869+
870+
// Maximum sizes of the four BLOB types, in number of bytes
871+
static constexpr size_t MAX_TINY_BLOB_WIDTH{255};
872+
static constexpr size_t MAX_SHORT_BLOB_WIDTH{65535};
873+
static constexpr size_t MAX_MEDIUM_BLOB_WIDTH{16777215};
874+
static constexpr size_t MAX_LONG_BLOB_WIDTH{4294967295};
875+
867876
// Length of field. Never write to this member directly; instead, use
868877
// set_field_length().
869878
uint32 field_length;

sql/item.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,7 @@ bool Item_param::propagate_type(THD *, const Type_properties &type) {
34923492
case MYSQL_TYPE_LONG_BLOB:
34933493
case MYSQL_TYPE_BLOB:
34943494
// Parameter type is BLOB of largest possible size
3495-
set_data_type_string(MAX_LONG_BLOB_WIDTH, type.m_collation);
3495+
set_data_type_string(Field::MAX_LONG_BLOB_WIDTH, type.m_collation);
34963496
break;
34973497
case MYSQL_TYPE_DATETIME:
34983498
case MYSQL_TYPE_DATETIME2:

sql/item.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,9 +1333,9 @@ class Item : public Parse_tree_node {
13331333
inline void set_data_type_string(uint32 max_l) {
13341334
max_length = max_l * collation.collation->mbmaxlen;
13351335
decimals = DECIMAL_NOT_SPECIFIED;
1336-
if (max_length <= MAX_VARCHAR_WIDTH)
1336+
if (max_length <= Field::MAX_VARCHAR_WIDTH)
13371337
set_data_type(MYSQL_TYPE_VARCHAR);
1338-
else if (max_length <= MAX_MEDIUM_BLOB_WIDTH)
1338+
else if (max_length <= Field::MAX_MEDIUM_BLOB_WIDTH)
13391339
set_data_type(MYSQL_TYPE_MEDIUM_BLOB);
13401340
else
13411341
set_data_type(MYSQL_TYPE_LONG_BLOB);
@@ -1478,7 +1478,7 @@ class Item : public Parse_tree_node {
14781478
set_data_type(MYSQL_TYPE_JSON);
14791479
collation.set(&my_charset_utf8mb4_bin, DERIVATION_IMPLICIT);
14801480
decimals = DECIMAL_NOT_SPECIFIED;
1481-
max_length = MAX_LONG_BLOB_WIDTH;
1481+
max_length = Field::MAX_LONG_BLOB_WIDTH;
14821482
}
14831483

14841484
/**
@@ -1549,9 +1549,9 @@ class Item : public Parse_tree_node {
15491549
@param max_bytes Maximum string size, in number of bytes
15501550
*/
15511551
static enum_field_types string_field_type(uint32 max_bytes) {
1552-
if (max_bytes > MAX_MEDIUM_BLOB_WIDTH)
1552+
if (max_bytes > Field::MAX_MEDIUM_BLOB_WIDTH)
15531553
return MYSQL_TYPE_LONG_BLOB;
1554-
else if (max_bytes > MAX_VARCHAR_WIDTH)
1554+
else if (max_bytes > Field::MAX_VARCHAR_WIDTH)
15551555
return MYSQL_TYPE_MEDIUM_BLOB;
15561556
else
15571557
return MYSQL_TYPE_VARCHAR;

sql/item_geofunc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class Item_func_as_wkb : public Item_geometry_func {
349349
if (param_type_is_default(thd, 0, 1, MYSQL_TYPE_GEOMETRY)) return true;
350350
if (param_type_is_default(thd, 1, 2)) return true;
351351
if (Item_geometry_func::resolve_type(thd)) return true;
352-
set_data_type_blob(MAX_LONG_BLOB_WIDTH);
352+
set_data_type_blob(Field::MAX_LONG_BLOB_WIDTH);
353353
return false;
354354
}
355355
};

0 commit comments

Comments
 (0)