From 94355738d1b281bdc2761369078dd0cc1cfaf806 Mon Sep 17 00:00:00 2001 From: sylzd Date: Tue, 8 Dec 2020 14:57:45 +0800 Subject: [PATCH 1/7] add tcp4only for lvs --- config/config.go | 2 ++ server/server.go | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 536269a906fdb..1c740a1d095de 100644 --- a/config/config.go +++ b/config/config.go @@ -176,6 +176,8 @@ type Config struct { // where M is the element literal length and w is the number of bytes required for the maximum-length character in the character set. // See https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html for more details. EnableEnumLengthLimit bool `toml:"enable-enum-length-limit" json:"enable-enum-length-limit"` + // EnableTcp4Only enable net.Listen("tcp4",...) makes lvs with toa work, tidb can get real client ip. + EnableTcp4Only bool `toml:"enable-tcp4-only" json:"enable-tcp4-only"` } // UpdateTempStoragePath is to update the `TempStoragePath` if port/statusPort was changed diff --git a/server/server.go b/server/server.go index c3baca1e8f516..5842cd923c4b0 100644 --- a/server/server.go +++ b/server/server.go @@ -245,7 +245,11 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) { if s.cfg.Host != "" && (s.cfg.Port != 0 || runInGoTest) { addr := fmt.Sprintf("%s:%d", s.cfg.Host, s.cfg.Port) - if s.listener, err = net.Listen("tcp", addr); err == nil { + tcpProto := "tcp" + if s.cfg.EnableTcp4Only { + tcpProto = "tcp4" + } + if s.listener, err = net.Listen(tcpProto, addr); err == nil { logutil.BgLogger().Info("server is running MySQL protocol", zap.String("addr", addr)) if cfg.Socket != "" { if s.socket, err = net.Listen("unix", s.cfg.Socket); err == nil { From a19f66e49f2620820c47841bad5f76c762a91632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=AD=90=E4=B8=9C?= Date: Tue, 8 Dec 2020 15:18:16 +0800 Subject: [PATCH 2/7] fix typo --- config/config.go | 4 ++-- server/server.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 1c740a1d095de..3e69af2fde613 100644 --- a/config/config.go +++ b/config/config.go @@ -176,8 +176,8 @@ type Config struct { // where M is the element literal length and w is the number of bytes required for the maximum-length character in the character set. // See https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html for more details. EnableEnumLengthLimit bool `toml:"enable-enum-length-limit" json:"enable-enum-length-limit"` - // EnableTcp4Only enable net.Listen("tcp4",...) makes lvs with toa work, tidb can get real client ip. - EnableTcp4Only bool `toml:"enable-tcp4-only" json:"enable-tcp4-only"` + // EnableTCP4Only enable net.Listen("tcp4",...) makes lvs with toa work, tidb can get real client ip. + EnableTCP4Only bool `toml:"enable-tcp4-only" json:"enable-tcp4-only"` } // UpdateTempStoragePath is to update the `TempStoragePath` if port/statusPort was changed diff --git a/server/server.go b/server/server.go index 5842cd923c4b0..2bac944e89f03 100644 --- a/server/server.go +++ b/server/server.go @@ -246,7 +246,7 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) { if s.cfg.Host != "" && (s.cfg.Port != 0 || runInGoTest) { addr := fmt.Sprintf("%s:%d", s.cfg.Host, s.cfg.Port) tcpProto := "tcp" - if s.cfg.EnableTcp4Only { + if s.cfg.EnableTCP4Only { tcpProto = "tcp4" } if s.listener, err = net.Listen(tcpProto, addr); err == nil { From ea270514341be5df4fb03baa54c0e7a04abe9dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=AD=90=E4=B8=9C?= Date: Tue, 8 Dec 2020 17:03:26 +0800 Subject: [PATCH 3/7] fix annotaion --- config/config.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 3e69af2fde613..e9ef802a30822 100644 --- a/config/config.go +++ b/config/config.go @@ -176,8 +176,9 @@ type Config struct { // where M is the element literal length and w is the number of bytes required for the maximum-length character in the character set. // See https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html for more details. EnableEnumLengthLimit bool `toml:"enable-enum-length-limit" json:"enable-enum-length-limit"` - // EnableTCP4Only enable net.Listen("tcp4",...) makes lvs with toa work, tidb can get real client ip. - EnableTCP4Only bool `toml:"enable-tcp4-only" json:"enable-tcp4-only"` + // EnableTCP4Only enables net.Listen("tcp4",...) + // Note that: it can make lvs with toa work and thus tidb can get real client ip. + EnableTCP4Only bool `toml:"enable-tcp4-only" json:"enable-tcp4-only"`` } // UpdateTempStoragePath is to update the `TempStoragePath` if port/statusPort was changed From 7b4631b170583f6f8bbe23a4e6100afe840c6353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=AD=90=E4=B8=9C?= Date: Tue, 8 Dec 2020 17:09:25 +0800 Subject: [PATCH 4/7] fix --- config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index e9ef802a30822..a0e01f7841479 100644 --- a/config/config.go +++ b/config/config.go @@ -178,7 +178,7 @@ type Config struct { EnableEnumLengthLimit bool `toml:"enable-enum-length-limit" json:"enable-enum-length-limit"` // EnableTCP4Only enables net.Listen("tcp4",...) // Note that: it can make lvs with toa work and thus tidb can get real client ip. - EnableTCP4Only bool `toml:"enable-tcp4-only" json:"enable-tcp4-only"`` + EnableTCP4Only bool `toml:"enable-tcp4-only" json:"enable-tcp4-only"` } // UpdateTempStoragePath is to update the `TempStoragePath` if port/statusPort was changed From 7bf491e0e824569999ba9b244e6d1c227e623f5d Mon Sep 17 00:00:00 2001 From: sylzd Date: Wed, 12 May 2021 20:51:09 +0800 Subject: [PATCH 5/7] fix issue24477: nulleq with null value in year type goes wrong result --- util/ranger/points.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/ranger/points.go b/util/ranger/points.go index d98b548dcbb7a..3c3c2ae628a9a 100644 --- a/util/ranger/points.go +++ b/util/ranger/points.go @@ -250,6 +250,12 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []*point { // If the original value is adjusted, we need to change the condition. // For example, col < 2156. Since the max year is 2155, 2156 is changed to 2155. // col < 2155 is wrong. It should be col <= 2155. + + // If nulleq with null value, values.ToInt64 will return err + if value.IsNull() { + return nil + } + preValue, err1 := value.ToInt64(r.sc) if err1 != nil { return err1 From 1df3b96f4c7dbcb3929e985382000df38c706bd7 Mon Sep 17 00:00:00 2001 From: sylzd Date: Thu, 13 May 2021 15:13:22 +0800 Subject: [PATCH 6/7] fix --- util/ranger/points.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/util/ranger/points.go b/util/ranger/points.go index 3c3c2ae628a9a..9c33ccef7feb3 100644 --- a/util/ranger/points.go +++ b/util/ranger/points.go @@ -246,16 +246,11 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []*point { if col.RetType.EvalType() == types.ETString && (value.Kind() == types.KindString || value.Kind() == types.KindBinaryLiteral) { value.SetString(value.GetString(), col.RetType.Collate) } - if col.GetType().Tp == mysql.TypeYear { + // If nulleq with null value, values.ToInt64 will return err + if col.GetType().Tp == mysql.TypeYear && !value.IsNull() { // If the original value is adjusted, we need to change the condition. // For example, col < 2156. Since the max year is 2155, 2156 is changed to 2155. // col < 2155 is wrong. It should be col <= 2155. - - // If nulleq with null value, values.ToInt64 will return err - if value.IsNull() { - return nil - } - preValue, err1 := value.ToInt64(r.sc) if err1 != nil { return err1 From e2a57875e61a2f6a353233b2afe8cb044775a360 Mon Sep 17 00:00:00 2001 From: sylzd Date: Thu, 13 May 2021 15:48:34 +0800 Subject: [PATCH 7/7] add UT of 24477 --- util/ranger/ranger_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/ranger/ranger_test.go b/util/ranger/ranger_test.go index 194ba1e779dc3..575d7f196fbf9 100644 --- a/util/ranger/ranger_test.go +++ b/util/ranger/ranger_test.go @@ -1504,12 +1504,13 @@ func (s *testRangerSuite) TestIndexRangeForYear(c *C) { // test index range testKit.MustExec("DROP TABLE IF EXISTS t") testKit.MustExec("CREATE TABLE t (a year(4), key(a))") - testKit.MustExec("INSERT INTO t VALUES (1), (70), (99), (0), ('0')") + testKit.MustExec("INSERT INTO t VALUES (1), (70), (99), (0), ('0'), (NULL)") testKit.MustQuery("SELECT * FROM t WHERE a < 15698").Check(testkit.Rows("0", "1970", "1999", "2000", "2001")) testKit.MustQuery("SELECT * FROM t WHERE a <= 0").Check(testkit.Rows("0")) testKit.MustQuery("SELECT * FROM t WHERE a <= 1").Check(testkit.Rows("0", "1970", "1999", "2000", "2001")) testKit.MustQuery("SELECT * FROM t WHERE a < 2000").Check(testkit.Rows("0", "1970", "1999")) testKit.MustQuery("SELECT * FROM t WHERE a > -1").Check(testkit.Rows("0", "1970", "1999", "2000", "2001")) + testKit.MustQuery("SELECT * FROM t WHERE a <=> NULL").Check(testkit.Rows("")) tests := []struct { indexPos int