From 285257f7c8c3d9e00811c7713323586ad36a832d Mon Sep 17 00:00:00 2001
From: Sergei Golubchik <serg@mysql.com>
Date: Mon, 12 Oct 2009 20:15:10 +0200
Subject: [PATCH] bug#33731 - INSTALL/UNINSTALL PLUGIN: Inconsistent handling
 of identifier case

indexed column in mysql.plugin table should use case-insensitive collation
for index lookups to work

(backport from 6.0)

sql/sql_plugin.cc:
  generate the key correctly using key_copy.
  field->store() stores the value in record format, not key format.
---
 scripts/mysql_system_tables.sql     | 2 +-
 scripts/mysql_system_tables_fix.sql | 5 +++++
 sql/sql_plugin.cc                   | 9 +++++----
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/scripts/mysql_system_tables.sql b/scripts/mysql_system_tables.sql
index 67e1851791..3dd4b7a7a8 100644
--- a/scripts/mysql_system_tables.sql
+++ b/scripts/mysql_system_tables.sql
@@ -22,7 +22,7 @@ set @had_user_table= @@warning_count != 0;
 CREATE TABLE IF NOT EXISTS func (  name char(64) binary DEFAULT '' NOT NULL, ret tinyint(1) DEFAULT '0' NOT NULL, dl char(128) DEFAULT '' NOT NULL, type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin   comment='User defined functions';
 
 
-CREATE TABLE IF NOT EXISTS plugin ( name char(64) binary DEFAULT '' NOT NULL, dl char(128) DEFAULT '' NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='MySQL plugins';
+CREATE TABLE IF NOT EXISTS plugin ( name varchar(64) DEFAULT '' NOT NULL, dl varchar(128) DEFAULT '' NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci comment='MySQL plugins';
 
 
 CREATE TABLE IF NOT EXISTS servers ( Server_name char(64) NOT NULL DEFAULT '', Host char(64) NOT NULL DEFAULT '', Db char(64) NOT NULL DEFAULT '', Username char(64) NOT NULL DEFAULT '', Password char(64) NOT NULL DEFAULT '', Port INT(4) NOT NULL DEFAULT '0', Socket char(64) NOT NULL DEFAULT '', Wrapper char(64) NOT NULL DEFAULT '', Owner char(64) NOT NULL DEFAULT '', PRIMARY KEY (Server_name)) CHARACTER SET utf8 comment='MySQL Foreign Servers table';
diff --git a/scripts/mysql_system_tables_fix.sql b/scripts/mysql_system_tables_fix.sql
index a6497f57f0..71d18de889 100644
--- a/scripts/mysql_system_tables_fix.sql
+++ b/scripts/mysql_system_tables_fix.sql
@@ -229,6 +229,11 @@ SET GLOBAL slow_query_log = 'OFF';
 ALTER TABLE slow_log MODIFY COLUMN server_id INTEGER UNSIGNED NOT NULL;
 SET GLOBAL slow_query_log = @old_log_state;
 
+ALTER TABLE plugin
+  MODIFY name varchar(64) COLLATE utf8_general_ci NOT NULL DEFAULT '',
+  MODIFY dl varchar(128) COLLATE utf8_general_ci NOT NULL DEFAULT '',
+  CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
+
 #
 # Detect whether we had Create_view_priv
 #
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 025c8a8248..4e0b4b4d07 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -1764,12 +1764,13 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
   reap_plugins();
   pthread_mutex_unlock(&LOCK_plugin);
 
+  uchar user_key[MAX_KEY_LENGTH];
   table->use_all_columns();
   table->field[0]->store(name->str, name->length, system_charset_info);
-  if (! table->file->index_read_idx_map(table->record[0], 0,
-                                        (uchar *)table->field[0]->ptr,
-                                        HA_WHOLE_KEY,
-                                        HA_READ_KEY_EXACT))
+  key_copy(user_key, table->record[0], table->key_info,
+           table->key_info->key_length);
+  if (! table->file->index_read_idx_map(table->record[0], 0, user_key,
+                                        HA_WHOLE_KEY, HA_READ_KEY_EXACT))
   {
     int error;
     /*
-- 
2.30.9