From 2c01f57edb30c273f8b36e92062c61a630669909 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Sat, 17 Jan 2026 21:01:32 +0200 Subject: [PATCH 01/28] Allow VARCHAR without length to default to a length of 65,535 Signed-off-by: Osama Nabih --- sql/sql_type.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index a41cdee95c7c7..0c5fc7d1b6ccb 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2862,8 +2862,14 @@ Type_handler_varchar::Column_definition_set_attributes( } break; case COLUMN_DEFINITION_ROUTINE_LOCAL: - case COLUMN_DEFINITION_TABLE_FIELD: break; + case COLUMN_DEFINITION_TABLE_FIELD: + /* + Support SQL Standard T081: "Optional string types maximum length" + Allows users to specify VARCHAR fields without a length + */ + def->length= UINT_MAX16; + return false; } thd->parse_error(); return true; From f3acea30f9589f51ba5164e19259022cc3213554 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Sat, 17 Jan 2026 22:57:33 +0200 Subject: [PATCH 02/28] Change default VARCHAR size to 16383 Signed-off-by: Osama Nabih --- sql/sql_type.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 0c5fc7d1b6ccb..baecece3ef985 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2868,7 +2868,7 @@ Type_handler_varchar::Column_definition_set_attributes( Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length */ - def->length= UINT_MAX16; + def->length= 16383; return false; } thd->parse_error(); From f7889f7e6bcb269679012dad7e30b5524cfff854 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Tue, 20 Jan 2026 11:46:05 +0200 Subject: [PATCH 03/28] Define MAX_VARCHAR_ESTIMATED_SIZE with value 16383 Signed-off-by: Osama Nabih --- sql/sql_const.h | 8 ++++++++ sql/sql_type.cc | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sql/sql_const.h b/sql/sql_const.h index 389c70e2668b4..df6b6ef5b8cd0 100644 --- a/sql/sql_const.h +++ b/sql/sql_const.h @@ -67,6 +67,14 @@ in non-strict mode. */ #define MAX_FIELD_VARCHARLENGTH (65535-2-1) + +/* + Estimated max size for VARCHAR for all collations (mbmaxlen = 4) + = MAX_FIELD_VARCHARLENGTH / mbmaxlen + NOTE: Support for "gb18030" will have mbmaxlen=5 - See MDEV-7495 + For such charsets, a value of 16383 will cause an error +*/ +#define MAX_VARCHAR_ESTIMATED_SIZE 16383 #define MAX_FIELD_BLOBLENGTH UINT_MAX32 /* cf field_blob::get_length() */ #define CONVERT_IF_BIGGER_TO_BLOB 512 /* Threshold *in characters* */ diff --git a/sql/sql_type.cc b/sql/sql_type.cc index baecece3ef985..228bc158817e9 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2868,7 +2868,7 @@ Type_handler_varchar::Column_definition_set_attributes( Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length */ - def->length= 16383; + def->length= MAX_VARCHAR_ESTIMATED_SIZE; return false; } thd->parse_error(); From d41ca1e4a47829364f48faa5956608e332d0e8c7 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Tue, 20 Jan 2026 15:49:44 +0200 Subject: [PATCH 04/28] Revert "Define MAX_VARCHAR_ESTIMATED_SIZE with value 16383" This reverts commit 85217ec2774aeefaf077db2d81a56777bea91ada. --- sql/sql_const.h | 8 -------- sql/sql_type.cc | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/sql/sql_const.h b/sql/sql_const.h index df6b6ef5b8cd0..389c70e2668b4 100644 --- a/sql/sql_const.h +++ b/sql/sql_const.h @@ -67,14 +67,6 @@ in non-strict mode. */ #define MAX_FIELD_VARCHARLENGTH (65535-2-1) - -/* - Estimated max size for VARCHAR for all collations (mbmaxlen = 4) - = MAX_FIELD_VARCHARLENGTH / mbmaxlen - NOTE: Support for "gb18030" will have mbmaxlen=5 - See MDEV-7495 - For such charsets, a value of 16383 will cause an error -*/ -#define MAX_VARCHAR_ESTIMATED_SIZE 16383 #define MAX_FIELD_BLOBLENGTH UINT_MAX32 /* cf field_blob::get_length() */ #define CONVERT_IF_BIGGER_TO_BLOB 512 /* Threshold *in characters* */ diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 228bc158817e9..baecece3ef985 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2868,7 +2868,7 @@ Type_handler_varchar::Column_definition_set_attributes( Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length */ - def->length= MAX_VARCHAR_ESTIMATED_SIZE; + def->length= 16383; return false; } thd->parse_error(); From 893d343f0272d61569fe6b8c7fa64ccc57856d11 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Tue, 20 Jan 2026 15:49:56 +0200 Subject: [PATCH 05/28] Calculate default VARCHAR max len based on Column charset, fallback to DB charset Signed-off-by: Osama Nabih --- sql/sql_type.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index baecece3ef985..1612b90c1f32f 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2868,7 +2868,9 @@ Type_handler_varchar::Column_definition_set_attributes( Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length */ - def->length= 16383; + def->length = def->charset->mbmaxlen ? + MAX_FIELD_VARCHARLENGTH / def->charset->mbmaxlen : + MAX_FIELD_VARCHARLENGTH / thd->db_charset->mbmaxlen; return false; } thd->parse_error(); From 9ba9be459fc01c68484581fc7fa8a8ec674f89c7 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Tue, 20 Jan 2026 23:38:20 +0200 Subject: [PATCH 06/28] Add nullptr check for def->charset Signed-off-by: Osama Nabih --- sql/sql_type.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 1612b90c1f32f..dc57a2f934eee 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2868,7 +2868,7 @@ Type_handler_varchar::Column_definition_set_attributes( Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length */ - def->length = def->charset->mbmaxlen ? + def->length = def->charset && def->charset->mbmaxlen ? MAX_FIELD_VARCHARLENGTH / def->charset->mbmaxlen : MAX_FIELD_VARCHARLENGTH / thd->db_charset->mbmaxlen; return false; From 0379e9e032e49e10e676c9826c71e1196cad1593 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Tue, 20 Jan 2026 23:54:40 +0200 Subject: [PATCH 07/28] Add initial test for CREATE TABLE statement with VARCHAR column without length Signed-off-by: Osama Nabih --- mysql-test/main/varchar_no_length.cnf | 2 ++ mysql-test/main/varchar_no_length.result | 25 ++++++++++++++++++++++++ mysql-test/main/varchar_no_length.test | 25 ++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 mysql-test/main/varchar_no_length.cnf create mode 100644 mysql-test/main/varchar_no_length.result create mode 100644 mysql-test/main/varchar_no_length.test diff --git a/mysql-test/main/varchar_no_length.cnf b/mysql-test/main/varchar_no_length.cnf new file mode 100644 index 0000000000000..129cff26ea246 --- /dev/null +++ b/mysql-test/main/varchar_no_length.cnf @@ -0,0 +1,2 @@ +# Use default conf to set collation and charset +!include include/default_my.cnf diff --git a/mysql-test/main/varchar_no_length.result b/mysql-test/main/varchar_no_length.result new file mode 100644 index 0000000000000..4a54ab34743db --- /dev/null +++ b/mysql-test/main/varchar_no_length.result @@ -0,0 +1,25 @@ +# +# SQL Standard T081: VARCHAR without explicit length specification +# +# +# Basic test: CREATE TABLE with VARCHAR without length +# +CREATE TABLE t1 (a VARCHAR); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(16383) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DESC t1; +Field Type Null Key Default Extra +a varchar(16383) YES NULL +# Verify we can insert and retrieve data +INSERT INTO t1 VALUES ('test string'); +INSERT INTO t1 VALUES (''); +INSERT INTO t1 VALUES (NULL); +SELECT * FROM t1; +a +test string + +NULL +DROP TABLE t1; diff --git a/mysql-test/main/varchar_no_length.test b/mysql-test/main/varchar_no_length.test new file mode 100644 index 0000000000000..b948a7f85e50a --- /dev/null +++ b/mysql-test/main/varchar_no_length.test @@ -0,0 +1,25 @@ +# +# Test for SQL Standard T081: "Optional string types maximum length" +# This tests the feature that allows VARCHAR columns to be created without +# specifying a length, defaulting to the maximum VARCHAR length (65535) +# + +--echo # +--echo # SQL Standard T081: VARCHAR without explicit length specification +--echo # + +--echo # +--echo # Basic test: CREATE TABLE with VARCHAR without length +--echo # + +CREATE TABLE t1 (a VARCHAR); +SHOW CREATE TABLE t1; +DESC t1; + +--echo # Verify we can insert and retrieve data +INSERT INTO t1 VALUES ('test string'); +INSERT INTO t1 VALUES (''); +INSERT INTO t1 VALUES (NULL); +SELECT * FROM t1; + +DROP TABLE t1; From a34ec7aac8f027baa3959778816d8f7fd65dd61e Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 21 Jan 2026 00:18:04 +0200 Subject: [PATCH 08/28] Add test case for different column charsets Signed-off-by: Osama Nabih --- mysql-test/main/varchar_no_length.result | 17 +++++++++++++++++ mysql-test/main/varchar_no_length.test | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/mysql-test/main/varchar_no_length.result b/mysql-test/main/varchar_no_length.result index 4a54ab34743db..e0da57ebda3a1 100644 --- a/mysql-test/main/varchar_no_length.result +++ b/mysql-test/main/varchar_no_length.result @@ -23,3 +23,20 @@ test string NULL DROP TABLE t1; +# +# Test VARCHAR without length with various character sets +# +CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(16383) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR CHARSET latin1); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; diff --git a/mysql-test/main/varchar_no_length.test b/mysql-test/main/varchar_no_length.test index b948a7f85e50a..aba11c6732491 100644 --- a/mysql-test/main/varchar_no_length.test +++ b/mysql-test/main/varchar_no_length.test @@ -23,3 +23,15 @@ INSERT INTO t1 VALUES (NULL); SELECT * FROM t1; DROP TABLE t1; + +--echo # +--echo # Test VARCHAR without length with various character sets +--echo # + +CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR CHARSET latin1); +SHOW CREATE TABLE t1; +DROP TABLE t1; \ No newline at end of file From 7a305d41ac53fbf856aaf23bdbe0657e565d17ae Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Sun, 25 Jan 2026 21:07:54 +0200 Subject: [PATCH 09/28] MDEV-31414 Implement optional lengths for string types Add test for CREATE TABLE .... CHARSET scenario Signed-off-by: Osama Nabih --- mysql-test/main/varchar_no_length.result | 7 +++++++ mysql-test/main/varchar_no_length.test | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/varchar_no_length.result b/mysql-test/main/varchar_no_length.result index e0da57ebda3a1..1e320282538b9 100644 --- a/mysql-test/main/varchar_no_length.result +++ b/mysql-test/main/varchar_no_length.result @@ -40,3 +40,10 @@ t1 CREATE TABLE `t1` ( `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR) CHARSET latin1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(65532) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; diff --git a/mysql-test/main/varchar_no_length.test b/mysql-test/main/varchar_no_length.test index aba11c6732491..31cbba6ab2df1 100644 --- a/mysql-test/main/varchar_no_length.test +++ b/mysql-test/main/varchar_no_length.test @@ -9,7 +9,7 @@ --echo # --echo # ---echo # Basic test: CREATE TABLE with VARCHAR without length +--echo # Basic test: CREATE TABLE with VARCHAR without length or charset --echo # CREATE TABLE t1 (a VARCHAR); @@ -25,7 +25,7 @@ SELECT * FROM t1; DROP TABLE t1; --echo # ---echo # Test VARCHAR without length with various character sets +--echo # Test VARCHAR without length with various column charsets --echo # CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); @@ -34,4 +34,12 @@ DROP TABLE t1; CREATE TABLE t1 (a VARCHAR CHARSET latin1); SHOW CREATE TABLE t1; -DROP TABLE t1; \ No newline at end of file +DROP TABLE t1; + +--echo # +--echo # Basic test: CREATE TABLE with charset +--echo # + +CREATE TABLE t1 (a VARCHAR) CHARSET latin1; +SHOW CREATE TABLE t1; +DROP TABLE t1; From 018dbda3771ef0d15129f706cced955002a32e25 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Thu, 29 Jan 2026 18:39:39 +0200 Subject: [PATCH 10/28] MDEV-31414 Implement optional lengths for string types Add test cases for different charset scenarios Signed-off-by: Osama Nabih --- mysql-test/main/varchar_no_length.result | 66 +++++++++++++++++++----- mysql-test/main/varchar_no_length.test | 56 ++++++++++++++++---- 2 files changed, 99 insertions(+), 23 deletions(-) diff --git a/mysql-test/main/varchar_no_length.result b/mysql-test/main/varchar_no_length.result index 1e320282538b9..938f0074dcba8 100644 --- a/mysql-test/main/varchar_no_length.result +++ b/mysql-test/main/varchar_no_length.result @@ -2,7 +2,7 @@ # SQL Standard T081: VARCHAR without explicit length specification # # -# Basic test: CREATE TABLE with VARCHAR without length +# Basic test: CREATE TABLE with VARCHAR without length or charset (scenario 1a) # CREATE TABLE t1 (a VARCHAR); SHOW CREATE TABLE t1; @@ -10,21 +10,21 @@ Table Create Table t1 CREATE TABLE `t1` ( `a` varchar(16383) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci -DESC t1; -Field Type Null Key Default Extra -a varchar(16383) YES NULL -# Verify we can insert and retrieve data -INSERT INTO t1 VALUES ('test string'); -INSERT INTO t1 VALUES (''); -INSERT INTO t1 VALUES (NULL); -SELECT * FROM t1; -a -test string +DROP TABLE t1; -NULL +# +# Basic test: CREATE TABLE with charset (scenario 1b) +# +CREATE TABLE t1 (a VARCHAR CHARSET latin1); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; + # -# Test VARCHAR without length with various character sets +# Test VARCHAR without length with specific column charsets or collations (scenario 2a) # CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); SHOW CREATE TABLE t1; @@ -33,6 +33,15 @@ t1 CREATE TABLE `t1` ( `a` varchar(16383) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR COLLATE utf8mb4_general_ci); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(16383) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + CREATE TABLE t1 (a VARCHAR CHARSET latin1); SHOW CREATE TABLE t1; Table Create Table @@ -40,6 +49,37 @@ t1 CREATE TABLE `t1` ( `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR COLLATE latin1_general_ci); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +# +# Test VARCHAR without length with specific column charsets and collations (scenario 2b) +# +CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4 COLLATE utf8mb4_general_ci); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(16383) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR CHARSET latin1 COLLATE latin1_general_ci); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +# +# Basic test: CREATE TABLE with charset (Scenario 3) +# CREATE TABLE t1 (a VARCHAR) CHARSET latin1; SHOW CREATE TABLE t1; Table Create Table diff --git a/mysql-test/main/varchar_no_length.test b/mysql-test/main/varchar_no_length.test index 31cbba6ab2df1..4b90e65a9173c 100644 --- a/mysql-test/main/varchar_no_length.test +++ b/mysql-test/main/varchar_no_length.test @@ -1,45 +1,81 @@ # +# MDEV-31414 # Test for SQL Standard T081: "Optional string types maximum length" # This tests the feature that allows VARCHAR columns to be created without # specifying a length, defaulting to the maximum VARCHAR length (65535) # +# We have 3 scenarios for resolving charset and collation +# 1. Empty +# 2. Precisely Typed +# 3. Contextually typed +# +# Check the comment section in "lex_charset.cc" at +# CHARSET_INFO *Lex_exact_charset_extended_collation_attrs_st:: +# resolved_to_character_set --echo # --echo # SQL Standard T081: VARCHAR without explicit length specification --echo # --echo # ---echo # Basic test: CREATE TABLE with VARCHAR without length or charset +--echo # Basic test: CREATE TABLE with VARCHAR without length or charset (scenario 1a) --echo # CREATE TABLE t1 (a VARCHAR); SHOW CREATE TABLE t1; -DESC t1; +DROP TABLE t1; ---echo # Verify we can insert and retrieve data -INSERT INTO t1 VALUES ('test string'); -INSERT INTO t1 VALUES (''); -INSERT INTO t1 VALUES (NULL); -SELECT * FROM t1; +--echo +--echo # +--echo # Basic test: CREATE TABLE with charset (scenario 1b) +--echo # +CREATE TABLE t1 (a VARCHAR CHARSET latin1); +SHOW CREATE TABLE t1; DROP TABLE t1; +--echo --echo # ---echo # Test VARCHAR without length with various column charsets +--echo # Test VARCHAR without length with specific column charsets or collations (scenario 2a) --echo # CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); SHOW CREATE TABLE t1; DROP TABLE t1; +--echo +CREATE TABLE t1 (a VARCHAR COLLATE utf8mb4_general_ci); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo CREATE TABLE t1 (a VARCHAR CHARSET latin1); SHOW CREATE TABLE t1; DROP TABLE t1; +--echo +CREATE TABLE t1 (a VARCHAR COLLATE latin1_general_ci); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo --echo # ---echo # Basic test: CREATE TABLE with charset +--echo # Test VARCHAR without length with specific column charsets and collations (scenario 2b) --echo # -CREATE TABLE t1 (a VARCHAR) CHARSET latin1; +CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4 COLLATE utf8mb4_general_ci); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo +CREATE TABLE t1 (a VARCHAR CHARSET latin1 COLLATE latin1_general_ci); SHOW CREATE TABLE t1; DROP TABLE t1; + +--echo +--echo # +--echo # Basic test: CREATE TABLE with charset (Scenario 3) +--echo # +CREATE TABLE t1 (a VARCHAR) CHARSET latin1; +SHOW CREATE TABLE t1; +DROP TABLE t1; \ No newline at end of file From fa3c28f9d655cb8a11dd741fa64f4b7526d1d228 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Thu, 29 Jan 2026 18:37:14 +0200 Subject: [PATCH 11/28] MDEV-31414 Implement optional lengths for string types Remove setting default length during parsing. Instead, set VARCHAR length during charset resolution Handles VARCHAR field charset being derived from table charset Signed-off-by: Osama Nabih --- sql/field.cc | 16 +++++++++++++--- sql/field.h | 4 +++- sql/sql_table.cc | 8 +++++++- sql/sql_type.cc | 4 +--- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/sql/field.cc b/sql/field.cc index 590253ac49bdd..fec4a3614fb6d 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -10764,9 +10764,16 @@ void Column_definition_attributes::set_length_and_dec(const Lex_length_and_dec_st &type) { - if (type.has_explicit_length()) + if (type.has_explicit_length()) + { length= type.length_overflowed() ? (ulonglong) UINT_MAX32 + 1 : (ulonglong) type.length(); + has_explicit_length= true; + } + else { + length= 0; + has_explicit_length= false; + } if (type.has_explicit_dec()) decimals= type.dec(); @@ -11128,7 +11135,8 @@ Column_definition_attributes::Column_definition_attributes(const Field *field) charset(field->charset()), // May be NULL ptr pack_flag(0), decimals(field->decimals()), - unireg_check(field->unireg_check) + unireg_check(field->unireg_check), + has_explicit_length(true) {} @@ -11139,7 +11147,8 @@ Column_definition_attributes:: charset(attr.collation.collation), pack_flag(attr.unsigned_flag ? 0 : FIELDFLAG_DECIMAL), decimals(attr.decimals), - unireg_check(Field::NONE) + unireg_check(Field::NONE), + has_explicit_length(true) {} @@ -11255,6 +11264,7 @@ Column_definition::redefine_stage1_common(const Column_definition *dup_field, comment= dup_field->comment; option_list= dup_field->option_list; versioning= dup_field->versioning; + has_explicit_length= dup_field->has_explicit_length; } diff --git a/sql/field.h b/sql/field.h index 2797cad5da427..cff532f65448a 100644 --- a/sql/field.h +++ b/sql/field.h @@ -5339,12 +5339,14 @@ class Column_definition_attributes: public Type_extra_attributes uint32 pack_flag; decimal_digits_t decimals; Field::utype unireg_check; + bool has_explicit_length; Column_definition_attributes() :length(0), charset(&my_charset_bin), pack_flag(0), decimals(0), - unireg_check(Field::NONE) + unireg_check(Field::NONE), + has_explicit_length(false) { } Column_definition_attributes(const Field *field); Column_definition_attributes(const Type_all_attributes &attr); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 5cc74785ef734..230959ba36ead 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2581,6 +2581,12 @@ bool Column_definition::prepare_stage1_typelib(THD *thd, bool Column_definition::prepare_stage1_string(THD *thd, MEM_ROOT *mem_root) { + if (real_field_type() == MYSQL_TYPE_VARCHAR && !this->has_explicit_length) + { + char_length= (MAX_FIELD_VARCHARLENGTH) / (charset->mbmaxlen); + length= char_length; + } + if (real_field_type() == FIELD_TYPE_STRING && length*charset->mbmaxlen > 1024) { @@ -3220,7 +3226,7 @@ static bool mysql_prepare_create_table_stage1(THD *thd, COLUMN_DEFINITION_TABLE_FIELD, &dattr)) DBUG_RETURN(true); - + DBUG_ASSERT(sql_field->charset); if (check_column_name(sql_field->field_name)) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index dc57a2f934eee..42abee0e5371d 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2867,10 +2867,8 @@ Type_handler_varchar::Column_definition_set_attributes( /* Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length + In this case, has_explicit_length is false. */ - def->length = def->charset && def->charset->mbmaxlen ? - MAX_FIELD_VARCHARLENGTH / def->charset->mbmaxlen : - MAX_FIELD_VARCHARLENGTH / thd->db_charset->mbmaxlen; return false; } thd->parse_error(); From 86dcf32f785795b798eff7844ef76ea4f99714a5 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Fri, 30 Jan 2026 23:10:13 +0200 Subject: [PATCH 12/28] MDEV-31414 Implement optional lengths for string types Set has_explicit_length to true for Field constructor Set has_explicit_length default to true for constructor Signed-off-by: Osama Nabih --- sql/field.cc | 1 + sql/field.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/field.cc b/sql/field.cc index fec4a3614fb6d..ce6b08f55ff54 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -11172,6 +11172,7 @@ Column_definition::Column_definition(THD *thd, Field *old_field, invisible= old_field->invisible; interval_list.empty(); // prepare_interval_field() needs this char_length= (uint) length; + has_explicit_length= true; if (orig_field) { diff --git a/sql/field.h b/sql/field.h index cff532f65448a..992e2d73c90f7 100644 --- a/sql/field.h +++ b/sql/field.h @@ -5346,7 +5346,7 @@ class Column_definition_attributes: public Type_extra_attributes pack_flag(0), decimals(0), unireg_check(Field::NONE), - has_explicit_length(false) + has_explicit_length(true) { } Column_definition_attributes(const Field *field); Column_definition_attributes(const Type_all_attributes &attr); From 19e2c5c15df1a964061660af5614b1a09d2d94ad Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Fri, 30 Jan 2026 23:12:38 +0200 Subject: [PATCH 13/28] MDEV-31414 Implement optional lengths for string types Add test for ALTER TABLE MODIFY COLUMN Signed-off-by: Osama Nabih --- mysql-test/main/varchar_no_length.result | 12 ++++++++++++ mysql-test/main/varchar_no_length.test | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/varchar_no_length.result b/mysql-test/main/varchar_no_length.result index 938f0074dcba8..d569872c3fc92 100644 --- a/mysql-test/main/varchar_no_length.result +++ b/mysql-test/main/varchar_no_length.result @@ -87,3 +87,15 @@ t1 CREATE TABLE `t1` ( `a` varchar(65532) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci DROP TABLE t1; + +# +# Test ALTER TABLE MODIFY COLUMN with VARCHAR without length +# +CREATE TABLE t1 (id VARCHAR(1)); +ALTER TABLE t1 MODIFY id VARCHAR; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` varchar(16383) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; diff --git a/mysql-test/main/varchar_no_length.test b/mysql-test/main/varchar_no_length.test index 4b90e65a9173c..4b2d0804b2b94 100644 --- a/mysql-test/main/varchar_no_length.test +++ b/mysql-test/main/varchar_no_length.test @@ -78,4 +78,13 @@ DROP TABLE t1; --echo # CREATE TABLE t1 (a VARCHAR) CHARSET latin1; SHOW CREATE TABLE t1; -DROP TABLE t1; \ No newline at end of file +DROP TABLE t1; + +--echo +--echo # +--echo # Test ALTER TABLE MODIFY COLUMN with VARCHAR without length +--echo # +CREATE TABLE t1 (id VARCHAR(1)); +ALTER TABLE t1 MODIFY id VARCHAR; +SHOW CREATE TABLE t1; +DROP TABLE t1; From e0bb5e051f65f44c3a3664f9d2acad141c4a5a24 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:27 +0200 Subject: [PATCH 14/28] Revert "MDEV-31414 Implement optional lengths for string types" This reverts commit 19e2c5c15df1a964061660af5614b1a09d2d94ad. --- mysql-test/main/varchar_no_length.result | 12 ------------ mysql-test/main/varchar_no_length.test | 11 +---------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/mysql-test/main/varchar_no_length.result b/mysql-test/main/varchar_no_length.result index d569872c3fc92..938f0074dcba8 100644 --- a/mysql-test/main/varchar_no_length.result +++ b/mysql-test/main/varchar_no_length.result @@ -87,15 +87,3 @@ t1 CREATE TABLE `t1` ( `a` varchar(65532) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci DROP TABLE t1; - -# -# Test ALTER TABLE MODIFY COLUMN with VARCHAR without length -# -CREATE TABLE t1 (id VARCHAR(1)); -ALTER TABLE t1 MODIFY id VARCHAR; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `id` varchar(16383) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci -DROP TABLE t1; diff --git a/mysql-test/main/varchar_no_length.test b/mysql-test/main/varchar_no_length.test index 4b2d0804b2b94..4b90e65a9173c 100644 --- a/mysql-test/main/varchar_no_length.test +++ b/mysql-test/main/varchar_no_length.test @@ -78,13 +78,4 @@ DROP TABLE t1; --echo # CREATE TABLE t1 (a VARCHAR) CHARSET latin1; SHOW CREATE TABLE t1; -DROP TABLE t1; - ---echo ---echo # ---echo # Test ALTER TABLE MODIFY COLUMN with VARCHAR without length ---echo # -CREATE TABLE t1 (id VARCHAR(1)); -ALTER TABLE t1 MODIFY id VARCHAR; -SHOW CREATE TABLE t1; -DROP TABLE t1; +DROP TABLE t1; \ No newline at end of file From 4f80aae38df106a9d3df5878a17d5039664c67d6 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:29 +0200 Subject: [PATCH 15/28] Revert "MDEV-31414 Implement optional lengths for string types" This reverts commit 86dcf32f785795b798eff7844ef76ea4f99714a5. --- sql/field.cc | 1 - sql/field.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/field.cc b/sql/field.cc index ce6b08f55ff54..fec4a3614fb6d 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -11172,7 +11172,6 @@ Column_definition::Column_definition(THD *thd, Field *old_field, invisible= old_field->invisible; interval_list.empty(); // prepare_interval_field() needs this char_length= (uint) length; - has_explicit_length= true; if (orig_field) { diff --git a/sql/field.h b/sql/field.h index 992e2d73c90f7..cff532f65448a 100644 --- a/sql/field.h +++ b/sql/field.h @@ -5346,7 +5346,7 @@ class Column_definition_attributes: public Type_extra_attributes pack_flag(0), decimals(0), unireg_check(Field::NONE), - has_explicit_length(true) + has_explicit_length(false) { } Column_definition_attributes(const Field *field); Column_definition_attributes(const Type_all_attributes &attr); From 8fb2804dc4432377799314547562ab858a6a0884 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:30 +0200 Subject: [PATCH 16/28] Revert "MDEV-31414 Implement optional lengths for string types" This reverts commit fa3c28f9d655cb8a11dd741fa64f4b7526d1d228. --- sql/field.cc | 16 +++------------- sql/field.h | 4 +--- sql/sql_table.cc | 8 +------- sql/sql_type.cc | 4 +++- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/sql/field.cc b/sql/field.cc index fec4a3614fb6d..590253ac49bdd 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -10764,16 +10764,9 @@ void Column_definition_attributes::set_length_and_dec(const Lex_length_and_dec_st &type) { - if (type.has_explicit_length()) - { + if (type.has_explicit_length()) length= type.length_overflowed() ? (ulonglong) UINT_MAX32 + 1 : (ulonglong) type.length(); - has_explicit_length= true; - } - else { - length= 0; - has_explicit_length= false; - } if (type.has_explicit_dec()) decimals= type.dec(); @@ -11135,8 +11128,7 @@ Column_definition_attributes::Column_definition_attributes(const Field *field) charset(field->charset()), // May be NULL ptr pack_flag(0), decimals(field->decimals()), - unireg_check(field->unireg_check), - has_explicit_length(true) + unireg_check(field->unireg_check) {} @@ -11147,8 +11139,7 @@ Column_definition_attributes:: charset(attr.collation.collation), pack_flag(attr.unsigned_flag ? 0 : FIELDFLAG_DECIMAL), decimals(attr.decimals), - unireg_check(Field::NONE), - has_explicit_length(true) + unireg_check(Field::NONE) {} @@ -11264,7 +11255,6 @@ Column_definition::redefine_stage1_common(const Column_definition *dup_field, comment= dup_field->comment; option_list= dup_field->option_list; versioning= dup_field->versioning; - has_explicit_length= dup_field->has_explicit_length; } diff --git a/sql/field.h b/sql/field.h index cff532f65448a..2797cad5da427 100644 --- a/sql/field.h +++ b/sql/field.h @@ -5339,14 +5339,12 @@ class Column_definition_attributes: public Type_extra_attributes uint32 pack_flag; decimal_digits_t decimals; Field::utype unireg_check; - bool has_explicit_length; Column_definition_attributes() :length(0), charset(&my_charset_bin), pack_flag(0), decimals(0), - unireg_check(Field::NONE), - has_explicit_length(false) + unireg_check(Field::NONE) { } Column_definition_attributes(const Field *field); Column_definition_attributes(const Type_all_attributes &attr); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 230959ba36ead..5cc74785ef734 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2581,12 +2581,6 @@ bool Column_definition::prepare_stage1_typelib(THD *thd, bool Column_definition::prepare_stage1_string(THD *thd, MEM_ROOT *mem_root) { - if (real_field_type() == MYSQL_TYPE_VARCHAR && !this->has_explicit_length) - { - char_length= (MAX_FIELD_VARCHARLENGTH) / (charset->mbmaxlen); - length= char_length; - } - if (real_field_type() == FIELD_TYPE_STRING && length*charset->mbmaxlen > 1024) { @@ -3226,7 +3220,7 @@ static bool mysql_prepare_create_table_stage1(THD *thd, COLUMN_DEFINITION_TABLE_FIELD, &dattr)) DBUG_RETURN(true); - + DBUG_ASSERT(sql_field->charset); if (check_column_name(sql_field->field_name)) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 42abee0e5371d..dc57a2f934eee 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2867,8 +2867,10 @@ Type_handler_varchar::Column_definition_set_attributes( /* Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length - In this case, has_explicit_length is false. */ + def->length = def->charset && def->charset->mbmaxlen ? + MAX_FIELD_VARCHARLENGTH / def->charset->mbmaxlen : + MAX_FIELD_VARCHARLENGTH / thd->db_charset->mbmaxlen; return false; } thd->parse_error(); From 8a77dc929929fbcb0a854aea9d0b2272da23e7a9 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:31 +0200 Subject: [PATCH 17/28] Revert "MDEV-31414 Implement optional lengths for string types" This reverts commit 018dbda3771ef0d15129f706cced955002a32e25. --- mysql-test/main/varchar_no_length.result | 66 +++++------------------- mysql-test/main/varchar_no_length.test | 56 ++++---------------- 2 files changed, 23 insertions(+), 99 deletions(-) diff --git a/mysql-test/main/varchar_no_length.result b/mysql-test/main/varchar_no_length.result index 938f0074dcba8..1e320282538b9 100644 --- a/mysql-test/main/varchar_no_length.result +++ b/mysql-test/main/varchar_no_length.result @@ -2,7 +2,7 @@ # SQL Standard T081: VARCHAR without explicit length specification # # -# Basic test: CREATE TABLE with VARCHAR without length or charset (scenario 1a) +# Basic test: CREATE TABLE with VARCHAR without length # CREATE TABLE t1 (a VARCHAR); SHOW CREATE TABLE t1; @@ -10,21 +10,21 @@ Table Create Table t1 CREATE TABLE `t1` ( `a` varchar(16383) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci -DROP TABLE t1; +DESC t1; +Field Type Null Key Default Extra +a varchar(16383) YES NULL +# Verify we can insert and retrieve data +INSERT INTO t1 VALUES ('test string'); +INSERT INTO t1 VALUES (''); +INSERT INTO t1 VALUES (NULL); +SELECT * FROM t1; +a +test string -# -# Basic test: CREATE TABLE with charset (scenario 1b) -# -CREATE TABLE t1 (a VARCHAR CHARSET latin1); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +NULL DROP TABLE t1; - # -# Test VARCHAR without length with specific column charsets or collations (scenario 2a) +# Test VARCHAR without length with various character sets # CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); SHOW CREATE TABLE t1; @@ -33,15 +33,6 @@ t1 CREATE TABLE `t1` ( `a` varchar(16383) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; - -CREATE TABLE t1 (a VARCHAR COLLATE utf8mb4_general_ci); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` varchar(16383) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci -DROP TABLE t1; - CREATE TABLE t1 (a VARCHAR CHARSET latin1); SHOW CREATE TABLE t1; Table Create Table @@ -49,37 +40,6 @@ t1 CREATE TABLE `t1` ( `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; - -CREATE TABLE t1 (a VARCHAR COLLATE latin1_general_ci); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci -DROP TABLE t1; - -# -# Test VARCHAR without length with specific column charsets and collations (scenario 2b) -# -CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4 COLLATE utf8mb4_general_ci); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` varchar(16383) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci -DROP TABLE t1; - -CREATE TABLE t1 (a VARCHAR CHARSET latin1 COLLATE latin1_general_ci); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci -DROP TABLE t1; - -# -# Basic test: CREATE TABLE with charset (Scenario 3) -# CREATE TABLE t1 (a VARCHAR) CHARSET latin1; SHOW CREATE TABLE t1; Table Create Table diff --git a/mysql-test/main/varchar_no_length.test b/mysql-test/main/varchar_no_length.test index 4b90e65a9173c..31cbba6ab2df1 100644 --- a/mysql-test/main/varchar_no_length.test +++ b/mysql-test/main/varchar_no_length.test @@ -1,81 +1,45 @@ # -# MDEV-31414 # Test for SQL Standard T081: "Optional string types maximum length" # This tests the feature that allows VARCHAR columns to be created without # specifying a length, defaulting to the maximum VARCHAR length (65535) # -# We have 3 scenarios for resolving charset and collation -# 1. Empty -# 2. Precisely Typed -# 3. Contextually typed -# -# Check the comment section in "lex_charset.cc" at -# CHARSET_INFO *Lex_exact_charset_extended_collation_attrs_st:: -# resolved_to_character_set --echo # --echo # SQL Standard T081: VARCHAR without explicit length specification --echo # --echo # ---echo # Basic test: CREATE TABLE with VARCHAR without length or charset (scenario 1a) +--echo # Basic test: CREATE TABLE with VARCHAR without length or charset --echo # CREATE TABLE t1 (a VARCHAR); SHOW CREATE TABLE t1; -DROP TABLE t1; +DESC t1; ---echo ---echo # ---echo # Basic test: CREATE TABLE with charset (scenario 1b) ---echo # +--echo # Verify we can insert and retrieve data +INSERT INTO t1 VALUES ('test string'); +INSERT INTO t1 VALUES (''); +INSERT INTO t1 VALUES (NULL); +SELECT * FROM t1; -CREATE TABLE t1 (a VARCHAR CHARSET latin1); -SHOW CREATE TABLE t1; DROP TABLE t1; ---echo --echo # ---echo # Test VARCHAR without length with specific column charsets or collations (scenario 2a) +--echo # Test VARCHAR without length with various column charsets --echo # CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); SHOW CREATE TABLE t1; DROP TABLE t1; ---echo -CREATE TABLE t1 (a VARCHAR COLLATE utf8mb4_general_ci); -SHOW CREATE TABLE t1; -DROP TABLE t1; - ---echo CREATE TABLE t1 (a VARCHAR CHARSET latin1); SHOW CREATE TABLE t1; DROP TABLE t1; ---echo -CREATE TABLE t1 (a VARCHAR COLLATE latin1_general_ci); -SHOW CREATE TABLE t1; -DROP TABLE t1; - ---echo --echo # ---echo # Test VARCHAR without length with specific column charsets and collations (scenario 2b) +--echo # Basic test: CREATE TABLE with charset --echo # -CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4 COLLATE utf8mb4_general_ci); -SHOW CREATE TABLE t1; -DROP TABLE t1; - ---echo -CREATE TABLE t1 (a VARCHAR CHARSET latin1 COLLATE latin1_general_ci); -SHOW CREATE TABLE t1; -DROP TABLE t1; - ---echo ---echo # ---echo # Basic test: CREATE TABLE with charset (Scenario 3) ---echo # CREATE TABLE t1 (a VARCHAR) CHARSET latin1; SHOW CREATE TABLE t1; -DROP TABLE t1; \ No newline at end of file +DROP TABLE t1; From 20ee4fc39d09f802b8b6aa94b510e6a4cdef5cf7 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:32 +0200 Subject: [PATCH 18/28] Revert "MDEV-31414 Implement optional lengths for string types" This reverts commit 7a305d41ac53fbf856aaf23bdbe0657e565d17ae. --- mysql-test/main/varchar_no_length.result | 7 ------- mysql-test/main/varchar_no_length.test | 14 +++----------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/mysql-test/main/varchar_no_length.result b/mysql-test/main/varchar_no_length.result index 1e320282538b9..e0da57ebda3a1 100644 --- a/mysql-test/main/varchar_no_length.result +++ b/mysql-test/main/varchar_no_length.result @@ -40,10 +40,3 @@ t1 CREATE TABLE `t1` ( `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR) CHARSET latin1; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` varchar(65532) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci -DROP TABLE t1; diff --git a/mysql-test/main/varchar_no_length.test b/mysql-test/main/varchar_no_length.test index 31cbba6ab2df1..aba11c6732491 100644 --- a/mysql-test/main/varchar_no_length.test +++ b/mysql-test/main/varchar_no_length.test @@ -9,7 +9,7 @@ --echo # --echo # ---echo # Basic test: CREATE TABLE with VARCHAR without length or charset +--echo # Basic test: CREATE TABLE with VARCHAR without length --echo # CREATE TABLE t1 (a VARCHAR); @@ -25,7 +25,7 @@ SELECT * FROM t1; DROP TABLE t1; --echo # ---echo # Test VARCHAR without length with various column charsets +--echo # Test VARCHAR without length with various character sets --echo # CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); @@ -34,12 +34,4 @@ DROP TABLE t1; CREATE TABLE t1 (a VARCHAR CHARSET latin1); SHOW CREATE TABLE t1; -DROP TABLE t1; - ---echo # ---echo # Basic test: CREATE TABLE with charset ---echo # - -CREATE TABLE t1 (a VARCHAR) CHARSET latin1; -SHOW CREATE TABLE t1; -DROP TABLE t1; +DROP TABLE t1; \ No newline at end of file From e07557cacd75e915aee7eb56290a5cfc5023dfd6 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:33 +0200 Subject: [PATCH 19/28] Revert "Add test case for different column charsets" This reverts commit a34ec7aac8f027baa3959778816d8f7fd65dd61e. --- mysql-test/main/varchar_no_length.result | 17 ----------------- mysql-test/main/varchar_no_length.test | 12 ------------ 2 files changed, 29 deletions(-) diff --git a/mysql-test/main/varchar_no_length.result b/mysql-test/main/varchar_no_length.result index e0da57ebda3a1..4a54ab34743db 100644 --- a/mysql-test/main/varchar_no_length.result +++ b/mysql-test/main/varchar_no_length.result @@ -23,20 +23,3 @@ test string NULL DROP TABLE t1; -# -# Test VARCHAR without length with various character sets -# -CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` varchar(16383) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci -DROP TABLE t1; -CREATE TABLE t1 (a VARCHAR CHARSET latin1); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` varchar(65532) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci -DROP TABLE t1; diff --git a/mysql-test/main/varchar_no_length.test b/mysql-test/main/varchar_no_length.test index aba11c6732491..b948a7f85e50a 100644 --- a/mysql-test/main/varchar_no_length.test +++ b/mysql-test/main/varchar_no_length.test @@ -23,15 +23,3 @@ INSERT INTO t1 VALUES (NULL); SELECT * FROM t1; DROP TABLE t1; - ---echo # ---echo # Test VARCHAR without length with various character sets ---echo # - -CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); -SHOW CREATE TABLE t1; -DROP TABLE t1; - -CREATE TABLE t1 (a VARCHAR CHARSET latin1); -SHOW CREATE TABLE t1; -DROP TABLE t1; \ No newline at end of file From 6a6e18cbd1d15f64d6cd237ad6a3a60e070fa312 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:34 +0200 Subject: [PATCH 20/28] Revert "Add initial test for CREATE TABLE statement with VARCHAR column without length" This reverts commit 0379e9e032e49e10e676c9826c71e1196cad1593. --- mysql-test/main/varchar_no_length.cnf | 2 -- mysql-test/main/varchar_no_length.result | 25 ------------------------ mysql-test/main/varchar_no_length.test | 25 ------------------------ 3 files changed, 52 deletions(-) delete mode 100644 mysql-test/main/varchar_no_length.cnf delete mode 100644 mysql-test/main/varchar_no_length.result delete mode 100644 mysql-test/main/varchar_no_length.test diff --git a/mysql-test/main/varchar_no_length.cnf b/mysql-test/main/varchar_no_length.cnf deleted file mode 100644 index 129cff26ea246..0000000000000 --- a/mysql-test/main/varchar_no_length.cnf +++ /dev/null @@ -1,2 +0,0 @@ -# Use default conf to set collation and charset -!include include/default_my.cnf diff --git a/mysql-test/main/varchar_no_length.result b/mysql-test/main/varchar_no_length.result deleted file mode 100644 index 4a54ab34743db..0000000000000 --- a/mysql-test/main/varchar_no_length.result +++ /dev/null @@ -1,25 +0,0 @@ -# -# SQL Standard T081: VARCHAR without explicit length specification -# -# -# Basic test: CREATE TABLE with VARCHAR without length -# -CREATE TABLE t1 (a VARCHAR); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` varchar(16383) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci -DESC t1; -Field Type Null Key Default Extra -a varchar(16383) YES NULL -# Verify we can insert and retrieve data -INSERT INTO t1 VALUES ('test string'); -INSERT INTO t1 VALUES (''); -INSERT INTO t1 VALUES (NULL); -SELECT * FROM t1; -a -test string - -NULL -DROP TABLE t1; diff --git a/mysql-test/main/varchar_no_length.test b/mysql-test/main/varchar_no_length.test deleted file mode 100644 index b948a7f85e50a..0000000000000 --- a/mysql-test/main/varchar_no_length.test +++ /dev/null @@ -1,25 +0,0 @@ -# -# Test for SQL Standard T081: "Optional string types maximum length" -# This tests the feature that allows VARCHAR columns to be created without -# specifying a length, defaulting to the maximum VARCHAR length (65535) -# - ---echo # ---echo # SQL Standard T081: VARCHAR without explicit length specification ---echo # - ---echo # ---echo # Basic test: CREATE TABLE with VARCHAR without length ---echo # - -CREATE TABLE t1 (a VARCHAR); -SHOW CREATE TABLE t1; -DESC t1; - ---echo # Verify we can insert and retrieve data -INSERT INTO t1 VALUES ('test string'); -INSERT INTO t1 VALUES (''); -INSERT INTO t1 VALUES (NULL); -SELECT * FROM t1; - -DROP TABLE t1; From c65ecad67d893cd050683c11a0f3e4b84240f5b8 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:35 +0200 Subject: [PATCH 21/28] Revert "Add nullptr check for def->charset" This reverts commit 9ba9be459fc01c68484581fc7fa8a8ec674f89c7. --- sql/sql_type.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index dc57a2f934eee..1612b90c1f32f 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2868,7 +2868,7 @@ Type_handler_varchar::Column_definition_set_attributes( Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length */ - def->length = def->charset && def->charset->mbmaxlen ? + def->length = def->charset->mbmaxlen ? MAX_FIELD_VARCHARLENGTH / def->charset->mbmaxlen : MAX_FIELD_VARCHARLENGTH / thd->db_charset->mbmaxlen; return false; From ef920c3733159ca1f2a54200c9c06526ab22f5ac Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:37 +0200 Subject: [PATCH 22/28] Revert "Calculate default VARCHAR max len based on Column charset, fallback to DB charset" This reverts commit 893d343f0272d61569fe6b8c7fa64ccc57856d11. --- sql/sql_type.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 1612b90c1f32f..baecece3ef985 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2868,9 +2868,7 @@ Type_handler_varchar::Column_definition_set_attributes( Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length */ - def->length = def->charset->mbmaxlen ? - MAX_FIELD_VARCHARLENGTH / def->charset->mbmaxlen : - MAX_FIELD_VARCHARLENGTH / thd->db_charset->mbmaxlen; + def->length= 16383; return false; } thd->parse_error(); From 08db88ae208f1b65ba51350bdcb683526bfc5931 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:38 +0200 Subject: [PATCH 23/28] Reapply "Define MAX_VARCHAR_ESTIMATED_SIZE with value 16383" This reverts commit d41ca1e4a47829364f48faa5956608e332d0e8c7. --- sql/sql_const.h | 8 ++++++++ sql/sql_type.cc | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sql/sql_const.h b/sql/sql_const.h index 389c70e2668b4..df6b6ef5b8cd0 100644 --- a/sql/sql_const.h +++ b/sql/sql_const.h @@ -67,6 +67,14 @@ in non-strict mode. */ #define MAX_FIELD_VARCHARLENGTH (65535-2-1) + +/* + Estimated max size for VARCHAR for all collations (mbmaxlen = 4) + = MAX_FIELD_VARCHARLENGTH / mbmaxlen + NOTE: Support for "gb18030" will have mbmaxlen=5 - See MDEV-7495 + For such charsets, a value of 16383 will cause an error +*/ +#define MAX_VARCHAR_ESTIMATED_SIZE 16383 #define MAX_FIELD_BLOBLENGTH UINT_MAX32 /* cf field_blob::get_length() */ #define CONVERT_IF_BIGGER_TO_BLOB 512 /* Threshold *in characters* */ diff --git a/sql/sql_type.cc b/sql/sql_type.cc index baecece3ef985..228bc158817e9 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2868,7 +2868,7 @@ Type_handler_varchar::Column_definition_set_attributes( Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length */ - def->length= 16383; + def->length= MAX_VARCHAR_ESTIMATED_SIZE; return false; } thd->parse_error(); From 8c900f94c62ef4f3bb61605ed5e19f1d54a2e027 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:39 +0200 Subject: [PATCH 24/28] Revert "Define MAX_VARCHAR_ESTIMATED_SIZE with value 16383" This reverts commit f7889f7e6bcb269679012dad7e30b5524cfff854. --- sql/sql_const.h | 8 -------- sql/sql_type.cc | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/sql/sql_const.h b/sql/sql_const.h index df6b6ef5b8cd0..389c70e2668b4 100644 --- a/sql/sql_const.h +++ b/sql/sql_const.h @@ -67,14 +67,6 @@ in non-strict mode. */ #define MAX_FIELD_VARCHARLENGTH (65535-2-1) - -/* - Estimated max size for VARCHAR for all collations (mbmaxlen = 4) - = MAX_FIELD_VARCHARLENGTH / mbmaxlen - NOTE: Support for "gb18030" will have mbmaxlen=5 - See MDEV-7495 - For such charsets, a value of 16383 will cause an error -*/ -#define MAX_VARCHAR_ESTIMATED_SIZE 16383 #define MAX_FIELD_BLOBLENGTH UINT_MAX32 /* cf field_blob::get_length() */ #define CONVERT_IF_BIGGER_TO_BLOB 512 /* Threshold *in characters* */ diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 228bc158817e9..baecece3ef985 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2868,7 +2868,7 @@ Type_handler_varchar::Column_definition_set_attributes( Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length */ - def->length= MAX_VARCHAR_ESTIMATED_SIZE; + def->length= 16383; return false; } thd->parse_error(); From 2cf1b55c81b9a0cdc259c03b4088a46a6633f839 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:39 +0200 Subject: [PATCH 25/28] Revert "Change default VARCHAR size to 16383" This reverts commit f3acea30f9589f51ba5164e19259022cc3213554. --- sql/sql_type.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index baecece3ef985..0c5fc7d1b6ccb 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2868,7 +2868,7 @@ Type_handler_varchar::Column_definition_set_attributes( Support SQL Standard T081: "Optional string types maximum length" Allows users to specify VARCHAR fields without a length */ - def->length= 16383; + def->length= UINT_MAX16; return false; } thd->parse_error(); From 410abed141aa0a5d2bc8edc7c494840c5f036063 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:58:41 +0200 Subject: [PATCH 26/28] Revert "Allow VARCHAR without length to default to a length of 65,535" This reverts commit 2c01f57edb30c273f8b36e92062c61a630669909. --- sql/sql_type.cc | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 0c5fc7d1b6ccb..a41cdee95c7c7 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2862,14 +2862,8 @@ Type_handler_varchar::Column_definition_set_attributes( } break; case COLUMN_DEFINITION_ROUTINE_LOCAL: - break; case COLUMN_DEFINITION_TABLE_FIELD: - /* - Support SQL Standard T081: "Optional string types maximum length" - Allows users to specify VARCHAR fields without a length - */ - def->length= UINT_MAX16; - return false; + break; } thd->parse_error(); return true; From 03b43df863b909dce5034fb813a127c9429f7f92 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 21:50:10 +0200 Subject: [PATCH 27/28] Add test suite for treating varchar as text Signed-off-by: Osama Nabih --- mysql-test/main/varchar_no_length_text.result | 102 ++++++++++++++++++ mysql-test/main/varchar_no_length_text.test | 90 ++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 mysql-test/main/varchar_no_length_text.result create mode 100644 mysql-test/main/varchar_no_length_text.test diff --git a/mysql-test/main/varchar_no_length_text.result b/mysql-test/main/varchar_no_length_text.result new file mode 100644 index 0000000000000..8474d6fbae639 --- /dev/null +++ b/mysql-test/main/varchar_no_length_text.result @@ -0,0 +1,102 @@ +# +# SQL Standard T081: VARCHAR without explicit length specification +# +# +# Basic test: CREATE TABLE with VARCHAR without length or charset (scenario 1a) +# +CREATE TABLE t1 (a VARCHAR); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +# +# Basic test: CREATE TABLE with charset (scenario 1b) +# +CREATE TABLE t1 (a VARCHAR CHARSET latin1); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +# +# Test VARCHAR without length with specific column charsets or collations (scenario 2a) +# +CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR COLLATE utf8mb4_general_ci); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR CHARSET latin1); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR COLLATE latin1_general_ci); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +# +# Test VARCHAR without length with specific column charsets and collations (scenario 2b) +# +CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4 COLLATE utf8mb4_general_ci); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR CHARSET latin1 COLLATE latin1_general_ci); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; + +# +# Basic test: CREATE TABLE with charset (Scenario 3) +# +CREATE TABLE t1 (a VARCHAR) CHARSET latin1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; + +# +# Test ALTER TABLE MODIFY COLUMN with VARCHAR without length +# +CREATE TABLE t1 (id INTEGER, a VARCHAR(255)); +ALTER TABLE t1 MODIFY a VARCHAR; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) DEFAULT NULL, + `a` text DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE t1; diff --git a/mysql-test/main/varchar_no_length_text.test b/mysql-test/main/varchar_no_length_text.test new file mode 100644 index 0000000000000..1aa3275dd026a --- /dev/null +++ b/mysql-test/main/varchar_no_length_text.test @@ -0,0 +1,90 @@ +# +# MDEV-31414 +# Test for SQL Standard T081: "Optional string types maximum length" +# This tests the feature that allows VARCHAR columns to be created without +# specifying a length, defaulting to the maximum VARCHAR length (65535) +# +# We have 3 scenarios for resolving charset and collation +# 1. Empty +# 2. Precisely Typed +# 3. Contextually typed +# +# Check the comment section in "lex_charset.cc" at +# CHARSET_INFO *Lex_exact_charset_extended_collation_attrs_st:: +# resolved_to_character_set + +--echo # +--echo # SQL Standard T081: VARCHAR without explicit length specification +--echo # + +--echo # +--echo # Basic test: CREATE TABLE with VARCHAR without length or charset (scenario 1a) +--echo # + +CREATE TABLE t1 (a VARCHAR); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo +--echo # +--echo # Basic test: CREATE TABLE with charset (scenario 1b) +--echo # + +CREATE TABLE t1 (a VARCHAR CHARSET latin1); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo +--echo # +--echo # Test VARCHAR without length with specific column charsets or collations (scenario 2a) +--echo # + +CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo +CREATE TABLE t1 (a VARCHAR COLLATE utf8mb4_general_ci); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo +CREATE TABLE t1 (a VARCHAR CHARSET latin1); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo +CREATE TABLE t1 (a VARCHAR COLLATE latin1_general_ci); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo +--echo # +--echo # Test VARCHAR without length with specific column charsets and collations (scenario 2b) +--echo # + +CREATE TABLE t1 (a VARCHAR CHARSET utf8mb4 COLLATE utf8mb4_general_ci); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo +CREATE TABLE t1 (a VARCHAR CHARSET latin1 COLLATE latin1_general_ci); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo +--echo # +--echo # Basic test: CREATE TABLE with charset (Scenario 3) +--echo # +CREATE TABLE t1 (a VARCHAR) CHARSET latin1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo +--echo # +--echo # Test ALTER TABLE MODIFY COLUMN with VARCHAR without length +--echo # +CREATE TABLE t1 (id INTEGER, a VARCHAR(255)); +ALTER TABLE t1 MODIFY a VARCHAR; +SHOW CREATE TABLE t1; +DROP TABLE t1; From 39f2addb8edb950233eb5ae52bcb1fe4a68f7cd1 Mon Sep 17 00:00:00 2001 From: Osama Nabih Date: Wed, 4 Feb 2026 22:04:51 +0200 Subject: [PATCH 28/28] Treat VARCHAR without length as TEXT Signed-off-by: Osama Nabih --- sql/sql_type.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index a41cdee95c7c7..202f8223edae6 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2862,8 +2862,15 @@ Type_handler_varchar::Column_definition_set_attributes( } break; case COLUMN_DEFINITION_ROUTINE_LOCAL: - case COLUMN_DEFINITION_TABLE_FIELD: break; + case COLUMN_DEFINITION_TABLE_FIELD: + /* + Support SQL Standard T081: "Optional string types maximum length" + Allows users to specify VARCHAR fields without a length + In this case, has_explicit_length is false. + */ + def->set_handler(&type_handler_blob); + return false; } thd->parse_error(); return true;