Bug #119393 Wrong db_name asing for acquire_uncached_table()
Submitted: 14 Nov 7:54
Reporter: mengchu shi (OCA) Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: table, table cache

[14 Nov 7:54] mengchu shi
Description:
Parameter `name` of acquire_uncached_table is like "test/t1". The parameter `db_name` for acquire_uncached_table is "test/t1" rather than expected "test".

How to repeat:
Check the codes.

Suggested fix:
```
diff --git a/storage/innobase/dict/dict0dd.cc b/storage/innobase/dict/dict0dd.cc
index 6818515db66..8c2261a783b 100644
--- a/storage/innobase/dict/dict0dd.cc
+++ b/storage/innobase/dict/dict0dd.cc
@@ -338,24 +338,25 @@ int acquire_uncached_table(THD *thd, dd::cache::Dictionary_client *client,
                            TABLE_SHARE *ts, TABLE *td) {
   int error = 0;
   dd::Schema *schema;
-  const char *table_cache_key;
-  size_t table_cache_key_len;
+  const char *db_name_ptr;
+  char db_name[NAME_LEN + 1];
 
   if (name != nullptr) {
     schema = nullptr;
-    table_cache_key = name;
-    table_cache_key_len = dict_get_db_name_len(name);
+    size_t db_name_len = dict_get_db_name_len(name);
+    strncpy(db_name, name, db_name_len);
+    db_name[db_name_len] = '\0';
+    db_name_ptr = db_name;
   } else {
     error =
         client->acquire_uncached<dd::Schema>(dd_table->schema_id(), &schema);
     if (error != 0) {
       return (error);
     }
-    table_cache_key = schema->name().c_str();
-    table_cache_key_len = schema->name().size();
+    db_name_ptr = schema->name().c_str();
   }
 
-  init_tmp_table_share(thd, ts, table_cache_key, table_cache_key_len,
+  init_tmp_table_share(thd, ts, db_name_ptr, 0,
                        dd_table->name().c_str(), "" /* file name */, nullptr);
 
   error = open_table_def_suppress_invalid_meta_data(thd, ts, dd_table->table());
```
[14 Nov 8:07] mengchu shi
Wrong db_name asing for acquire_uncached_table()

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: diff.txt (text/plain), 1.36 KiB.