From 45ab00f097be0f77d7087182244218f036c3f113 Mon Sep 17 00:00:00 2001 From: Jacob Mathew Date: Mon, 23 Jul 2018 14:14:23 -0700 Subject: [PATCH 1/2] MDEV-15786: ERROR 1062 (23000) at line 365: Duplicate entry 'spider' for key 'PRIMARY' The problem occurs on Ubuntu where a Spider package is installed on the system separately from the MariaDB package. MariaDB and Spider upgrades leave the Spider plugin improperly installed. Spider is present in the mysql.plugin table but is not present in information_schema. The problem has been corrected in Spider's installation script. Logic has been added to check for Spider entries in both information_schema and mysql.plugin. If Spider is present in mysql.plugin but is not present in information_schema, then Spider is first removed from mysql.plugin. The subsequent plugin install of Spider will insert entries in both mysql.plugin and information_schema. Author: Jacob Mathew. Reviewer: Kentoku Shiba. Cherry-Picked: Commit 0897d81 on branch bb-10.3-MDEV-15786 --- storage/spider/scripts/install_spider.sql | 24 ++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/storage/spider/scripts/install_spider.sql b/storage/spider/scripts/install_spider.sql index dbafe95bdbf..9c9eaacdf60 100644 --- a/storage/spider/scripts/install_spider.sql +++ b/storage/spider/scripts/install_spider.sql @@ -297,9 +297,18 @@ delimiter // create procedure mysql.spider_plugin_installer() begin set @win_plugin := IF(@@version_compile_os like 'Win%', 1, 0); + set @have_spider_i_s_plugin := 0; + select @have_spider_i_s_plugin := 1 from INFORMATION_SCHEMA.plugins where PLUGIN_NAME = 'SPIDER'; set @have_spider_plugin := 0; - select @have_spider_plugin := 1 from INFORMATION_SCHEMA.plugins where PLUGIN_NAME = 'SPIDER'; - if @have_spider_plugin = 0 then + select @have_spider_plugin := 1 from mysql.plugin where name = 'spider'; + if @have_spider_i_s_plugin = 0 then + if @have_spider_plugin = 1 then + -- spider plugin is present in mysql.plugin but not in + -- information_schema.plugins. Remove spider plugin entry + -- in mysql.plugin first. + delete from mysql.plugin where name = 'spider'; + end if; + -- Install spider plugin if @win_plugin = 0 then install plugin spider soname 'ha_spider.so'; else @@ -308,7 +317,16 @@ begin end if; set @have_spider_i_s_alloc_mem_plugin := 0; select @have_spider_i_s_alloc_mem_plugin := 1 from INFORMATION_SCHEMA.plugins where PLUGIN_NAME = 'SPIDER_ALLOC_MEM'; - if @have_spider_i_s_alloc_mem_plugin = 0 then + set @have_spider_alloc_mem_plugin := 0; + select @have_spider_alloc_mem_plugin := 1 from mysql.plugin where name = 'spider_alloc_mem'; + if @have_spider_i_s_alloc_mem_plugin = 0 then + if @have_spider_alloc_mem_plugin = 1 then + -- spider_alloc_mem plugin is present in mysql.plugin but not in + -- information_schema.plugins. Remove spider_alloc_mem plugin entry + -- in mysql.plugin first. + delete from mysql.plugin where name = 'spider_alloc_mem'; + end if; + -- Install spider_alloc_mem plugin if @win_plugin = 0 then install plugin spider_alloc_mem soname 'ha_spider.so'; else From a8227a154306a818685ab291f1715c3971d03099 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 24 Jul 2018 18:15:15 +0400 Subject: [PATCH 2/2] MDEV-16814 CREATE TABLE SELECT JSON_QUOTE(multibyte_charset_expr) makes a field of a wrong length --- mysql-test/r/func_json.result | 15 ++++++++++++++- mysql-test/t/func_json.test | 9 +++++++++ sql/item_jsonfunc.cc | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index 564442a2880..39bd46b7dea 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -297,7 +297,7 @@ json_quote('foo') show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `json_quote('foo')` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL + `json_quote('foo')` varchar(38) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select json_merge('string'); @@ -747,3 +747,16 @@ INSERT INTO t1 VALUES ('foo'),('bar'); SELECT * FROM t1 WHERE c IN (JSON_EXTRACT('{"a":"b"}', '$.*')); c DROP TABLE t1; +# +# MDEV-16814 CREATE TABLE SELECT JSON_QUOTE(multibyte_charset_expr) makes a field of a wrong length +# +CREATE TABLE t1 AS SELECT +JSON_QUOTE(_latin1'foo') AS c1, +JSON_QUOTE(_utf8'foo') AS c2; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(38) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, + `c2` varchar(38) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index 1b91061b9a3..37b18763e91 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -413,3 +413,12 @@ INSERT INTO t1 VALUES ('foo'),('bar'); SELECT * FROM t1 WHERE c IN (JSON_EXTRACT('{"a":"b"}', '$.*')); DROP TABLE t1; +--echo # +--echo # MDEV-16814 CREATE TABLE SELECT JSON_QUOTE(multibyte_charset_expr) makes a field of a wrong length +--echo # + +CREATE TABLE t1 AS SELECT + JSON_QUOTE(_latin1'foo') AS c1, + JSON_QUOTE(_utf8'foo') AS c2; +SHOW CREATE TABLE t1; +DROP TABLE t1; diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 8103aa906ff..ac0d7e9e6b0 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -575,7 +575,7 @@ bool Item_func_json_quote::fix_length_and_dec() Odd but realistic worst case is when all characters of the argument turn into '\uXXXX\uXXXX', which is 12. */ - max_length= args[0]->max_length * 12 + 2; + fix_char_length_ulonglong((ulonglong) args[0]->max_char_length() * 12 + 2); return FALSE; }