From a0a63dda09c2eea2340e63c32d5e1db917354160 Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Tue, 15 Oct 2024 17:40:56 +0800 Subject: [PATCH 1/4] fix: make SET system type case-insensitive --- enginetest/queries/insert_queries.go | 4 ++-- sql/types/system_set.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/enginetest/queries/insert_queries.go b/enginetest/queries/insert_queries.go index acf36bf2d0..be37ad86c7 100644 --- a/enginetest/queries/insert_queries.go +++ b/enginetest/queries/insert_queries.go @@ -1278,10 +1278,10 @@ var InsertScripts = []ScriptTest{ }, }, { - Name: "sql_mode=NO_AUTO_VALUE_ON_ZERO", + Name: "sql_mode=NO_auto_value_ON_ZERO", SetUpScript: []string{ "set @old_sql_mode=@@sql_mode;", - "set @@sql_mode='NO_AUTO_VALUE_ON_ZERO';", + "set @@sql_mode='NO_auto_value_ON_ZERO';", "create table auto (i int auto_increment, index (i));", "create table auto_pk (i int auto_increment primary key);", }, diff --git a/sql/types/system_set.go b/sql/types/system_set.go index f6a3b24c68..c7d77d79eb 100644 --- a/sql/types/system_set.go +++ b/sql/types/system_set.go @@ -35,7 +35,7 @@ var _ sql.CollationCoercible = systemSetType{} // NewSystemSetType returns a new systemSetType. func NewSystemSetType(varName string, values ...string) sql.SystemVariableType { - return systemSetType{MustCreateSetType(values, sql.Collation_Default), varName} + return systemSetType{MustCreateSetType(values, sql.Collation_ascii_general_ci), varName} } // Compare implements Type interface. From 366abe574968a8649965e564bf662912397bd5ac Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Thu, 17 Oct 2024 10:25:11 +0800 Subject: [PATCH 2/4] Use utf8mb4_0900_ai_ci in system SET types --- sql/expression/function/coalesce_test.go | 2 +- sql/types/system_set.go | 4 ++-- sql/types/typecheck_test.go | 3 ++- sql/variables/system_variables.go | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sql/expression/function/coalesce_test.go b/sql/expression/function/coalesce_test.go index dbb9e1894d..3e0a97c7f0 100644 --- a/sql/expression/function/coalesce_test.go +++ b/sql/expression/function/coalesce_test.go @@ -213,7 +213,7 @@ func TestCoalesce(t *testing.T) { { name: "coalesce(sysSet)", input: []sql.Expression{ - expression.NewLiteral("abc", types.NewSystemSetType("str1", "abc")), + expression.NewLiteral("abc", types.NewSystemSetType("str1", sql.Collation_utf8mb4_0900_ai_ci, "abc")), }, expected: "abc", typ: types.MustCreateSetType([]string{"abc"}, sql.Collation_Default), diff --git a/sql/types/system_set.go b/sql/types/system_set.go index c7d77d79eb..a0054d3c5b 100644 --- a/sql/types/system_set.go +++ b/sql/types/system_set.go @@ -34,8 +34,8 @@ var _ sql.SystemVariableType = systemSetType{} var _ sql.CollationCoercible = systemSetType{} // NewSystemSetType returns a new systemSetType. -func NewSystemSetType(varName string, values ...string) sql.SystemVariableType { - return systemSetType{MustCreateSetType(values, sql.Collation_ascii_general_ci), varName} +func NewSystemSetType(varName string, collation sql.CollationID, values ...string) sql.SystemVariableType { + return systemSetType{MustCreateSetType(values, collation), varName} } // Compare implements Type interface. diff --git a/sql/types/typecheck_test.go b/sql/types/typecheck_test.go index 2a88cb82aa..1844d9ad65 100644 --- a/sql/types/typecheck_test.go +++ b/sql/types/typecheck_test.go @@ -17,6 +17,7 @@ package types import ( "testing" + "github.com/dolthub/go-mysql-server/sql" "github.com/stretchr/testify/assert" ) @@ -93,6 +94,6 @@ func TestSystemTypesIsSet(t *testing.T) { assert.False(t, IsSet(systemUintType{})) assert.False(t, IsSet(systemDoubleType{})) assert.False(t, IsSet(systemEnumType{})) - assert.True(t, IsSet(NewSystemSetType("", ""))) + assert.True(t, IsSet(NewSystemSetType("", sql.Collation_utf8mb4_0900_ai_ci, ""))) assert.False(t, IsSet(systemStringType{})) } diff --git a/sql/variables/system_variables.go b/sql/variables/system_variables.go index 0df108d8bb..ca55842188 100644 --- a/sql/variables/system_variables.go +++ b/sql/variables/system_variables.go @@ -1283,7 +1283,7 @@ var systemVars = map[string]sql.SystemVariable{ Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), Dynamic: true, SetVarHintApplies: false, - Type: types.NewSystemSetType("log_output", "TABLE", "FILE", "NONE"), + Type: types.NewSystemSetType("log_output", sql.Collation_utf8mb4_0900_ai_ci, "TABLE", "FILE", "NONE"), Default: "FILE", }, "log_queries_not_using_indexes": &sql.MysqlSystemVariable{ @@ -1951,7 +1951,7 @@ var systemVars = map[string]sql.SystemVariable{ Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), Dynamic: true, SetVarHintApplies: false, - Type: types.NewSystemSetType("protocol_compression_algorithms", "zlib", "zstd", "uncompressed"), + Type: types.NewSystemSetType("protocol_compression_algorithms", sql.Collation_utf8mb4_0900_ai_ci, "zlib", "zstd", "uncompressed"), Default: "zlib,zstd,uncompressed", }, "protocol_version": &sql.MysqlSystemVariable{ @@ -2430,7 +2430,7 @@ var systemVars = map[string]sql.SystemVariable{ Scope: sql.GetMysqlScope(sql.SystemVariableScope_Both), Dynamic: true, SetVarHintApplies: true, - Type: types.NewSystemSetType("sql_mode", "ALLOW_INVALID_DATES", "ANSI_QUOTES", "ERROR_FOR_DIVISION_BY_ZERO", "HIGH_NOT_PRECEDENCE", "IGNORE_SPACE", "NO_AUTO_VALUE_ON_ZERO", "NO_BACKSLASH_ESCAPES", "NO_DIR_IN_CREATE", "NO_ENGINE_SUBSTITUTION", "NO_UNSIGNED_SUBTRACTION", "NO_ZERO_DATE", "NO_ZERO_IN_DATE", "ONLY_FULL_GROUP_BY", "PAD_CHAR_TO_FULL_LENGTH", "PIPES_AS_CONCAT", "REAL_AS_FLOAT", "STRICT_ALL_TABLES", "STRICT_TRANS_TABLES", "TIME_TRUNCATE_FRACTIONAL", "TRADITIONAL", "ANSI"), + Type: types.NewSystemSetType("sql_mode", sql.Collation_utf8mb4_0900_ai_ci, "ALLOW_INVALID_DATES", "ANSI_QUOTES", "ERROR_FOR_DIVISION_BY_ZERO", "HIGH_NOT_PRECEDENCE", "IGNORE_SPACE", "NO_AUTO_VALUE_ON_ZERO", "NO_BACKSLASH_ESCAPES", "NO_DIR_IN_CREATE", "NO_ENGINE_SUBSTITUTION", "NO_UNSIGNED_SUBTRACTION", "NO_ZERO_DATE", "NO_ZERO_IN_DATE", "ONLY_FULL_GROUP_BY", "PAD_CHAR_TO_FULL_LENGTH", "PIPES_AS_CONCAT", "REAL_AS_FLOAT", "STRICT_ALL_TABLES", "STRICT_TRANS_TABLES", "TIME_TRUNCATE_FRACTIONAL", "TRADITIONAL", "ANSI"), Default: sql.DefaultSqlMode, }, "sql_notes": &sql.MysqlSystemVariable{ From 11d310637aa555e0d09f8d988ba76ec87d22dae2 Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Thu, 17 Oct 2024 11:05:05 +0800 Subject: [PATCH 3/4] Follow MySQL's implementation --- sql/expression/function/coalesce_test.go | 2 +- sql/types/typecheck_test.go | 2 +- sql/variables/system_variables.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/expression/function/coalesce_test.go b/sql/expression/function/coalesce_test.go index 3e0a97c7f0..887c975a16 100644 --- a/sql/expression/function/coalesce_test.go +++ b/sql/expression/function/coalesce_test.go @@ -213,7 +213,7 @@ func TestCoalesce(t *testing.T) { { name: "coalesce(sysSet)", input: []sql.Expression{ - expression.NewLiteral("abc", types.NewSystemSetType("str1", sql.Collation_utf8mb4_0900_ai_ci, "abc")), + expression.NewLiteral("abc", types.NewSystemSetType("str1", sql.Collation_Default, "abc")), }, expected: "abc", typ: types.MustCreateSetType([]string{"abc"}, sql.Collation_Default), diff --git a/sql/types/typecheck_test.go b/sql/types/typecheck_test.go index 1844d9ad65..ea8bdc7305 100644 --- a/sql/types/typecheck_test.go +++ b/sql/types/typecheck_test.go @@ -94,6 +94,6 @@ func TestSystemTypesIsSet(t *testing.T) { assert.False(t, IsSet(systemUintType{})) assert.False(t, IsSet(systemDoubleType{})) assert.False(t, IsSet(systemEnumType{})) - assert.True(t, IsSet(NewSystemSetType("", sql.Collation_utf8mb4_0900_ai_ci, ""))) + assert.True(t, IsSet(NewSystemSetType("", sql.Collation_Default, ""))) assert.False(t, IsSet(systemStringType{})) } diff --git a/sql/variables/system_variables.go b/sql/variables/system_variables.go index ca55842188..32d67710d5 100644 --- a/sql/variables/system_variables.go +++ b/sql/variables/system_variables.go @@ -1951,7 +1951,7 @@ var systemVars = map[string]sql.SystemVariable{ Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), Dynamic: true, SetVarHintApplies: false, - Type: types.NewSystemSetType("protocol_compression_algorithms", sql.Collation_utf8mb4_0900_ai_ci, "zlib", "zstd", "uncompressed"), + Type: types.NewSystemSetType("protocol_compression_algorithms", sql.Collation_latin1_general_ci, "zlib", "zstd", "uncompressed"), Default: "zlib,zstd,uncompressed", }, "protocol_version": &sql.MysqlSystemVariable{ From 632bf2cc831069348086bdae9caec0a3d949e592 Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Thu, 17 Oct 2024 16:33:16 +0800 Subject: [PATCH 4/4] latin1_swedish_ci is the default collation for latin1 --- sql/variables/system_variables.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/variables/system_variables.go b/sql/variables/system_variables.go index 32d67710d5..0e829ff741 100644 --- a/sql/variables/system_variables.go +++ b/sql/variables/system_variables.go @@ -1951,7 +1951,7 @@ var systemVars = map[string]sql.SystemVariable{ Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global), Dynamic: true, SetVarHintApplies: false, - Type: types.NewSystemSetType("protocol_compression_algorithms", sql.Collation_latin1_general_ci, "zlib", "zstd", "uncompressed"), + Type: types.NewSystemSetType("protocol_compression_algorithms", sql.Collation_latin1_swedish_ci, "zlib", "zstd", "uncompressed"), Default: "zlib,zstd,uncompressed", }, "protocol_version": &sql.MysqlSystemVariable{