what are the changes in mysql 8 result rowset case?

老子叫甜甜 提交于 2019-12-01 02:00:44

MySQL 8.0 did change the implementation of some views in the INFORMATION_SCHEMA:

https://mysqlserverteam.com/mysql-8-0-improvements-to-information_schema/ says:

Now that the metadata of all database tables is stored in transactional data dictionary tables, it enables us to design an INFORMATION_SCHEMA table as a database VIEW over the data dictionary tables. This eliminates costs such as the creation of temporary tables for each INFORMATION_SCHEMA query during execution on-the-fly, and also scanning file-system directories to find FRM files. It is also now possible to utilize the full power of the MySQL optimizer to prepare better query execution plans using indexes on data dictionary tables.

So it's being done for good reasons, but I understand that it has upset some of your queries when you fetch results in associative arrays based on column name.

You can see the definition of the view declares the column name explicitly in uppercase:

mysql 8.0.14> SHOW CREATE VIEW CHARACTER_SETS\G
*************************** 1. row ***************************
                View: CHARACTER_SETS
         Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`mysql.infoschema`@`localhost` SQL SECURITY DEFINER VIEW `CHARACTER_SETS` AS 
  select 
    `cs`.`name` AS `CHARACTER_SET_NAME`,
    `col`.`name` AS `DEFAULT_COLLATE_NAME`,
    `cs`.`comment` AS `DESCRIPTION`,
    `cs`.`mb_max_length` AS `MAXLEN` -- delimited column explicitly uppercase
  from (`mysql`.`character_sets` `cs` 
  join `mysql`.`collations` `col` on((`cs`.`default_collation_id` = `col`.`id`)))

character_set_client: utf8
collation_connection: utf8_general_ci

You can work around the change in a couple of ways:

You can declare your own column aliases in the case you want when you query a view:

mysql 8.0.14> SELECT MAXLEN AS `maxlen` 
  FROM `information_schema`.`CHARACTER_SETS` LIMIT 2;
+--------+
| maxlen |
+--------+
|      2 |
|      1 |
+--------+

You could start a habit of querying columns in uppercase prior to 8.0. Here's a test showing results in my 5.7 sandbox:

mysql 5.7.24> SELECT MAXLEN 
  FROM `information_schema`.`CHARACTER_SETS` LIMIT 2;
+--------+
| MAXLEN |
+--------+
|      2 |
|      1 |
+--------+

Or you could fetch results into a non-associative array, and reference columns by column number, instead of by name.

There is no change in case sensitivity. If you check mysql documentation on identifier case sensitivity, both v5.7 and v8.0 say that field names are case insensitive:

Column, index, stored routine, event, and resource group names are not case-sensitive on any platform, nor are column aliases.

To me this seems more like a display difference.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!