Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 64bf72c

Browse files
committedJan 3, 2019
Add DB_METADATA to INFORMATION_SCHEMA.SCHEMATA
Summary: Add DB_METADATA to INFORMATION_SCHEMA.SCHEMATA for each database for easy query by OLM Test Plan: 1. Test manually by inspecting SCHEMATA Result: https://phabricator.intern.facebook.com/P60466869 2. Update test case (TODO) Reviewers: herman, lcai Reviewed By: herman Subscribers: butterflybot, webscalesql-eng@fb.com Differential Revision: https://phabricator.intern.facebook.com/D13510326 Tasks: T37428915 Tags: bootcamp Signature: 13510326:1546451545:62ec37297de59dde87229dfa922570fa510c45e3
1 parent 2134da9 commit 64bf72c

11 files changed

+473
-15
lines changed
 

‎mysql-test/r/db_metadata.result

+328
Large diffs are not rendered by default.

‎mysql-test/r/information_schema-big.result

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ USER_STATISTICS USER_NAME
6666
VIEWS TABLE_SCHEMA
6767
AUTHINFO ID
6868
SLAVE_DB_LOAD DB
69+
SCHEMATA_EXT SCHEMA_NAME
6970
SELECT t.table_name, c1.column_name
7071
FROM information_schema.tables t
7172
INNER JOIN
@@ -129,3 +130,4 @@ USER_STATISTICS USER_NAME
129130
VIEWS TABLE_SCHEMA
130131
AUTHINFO ID
131132
SLAVE_DB_LOAD DB
133+
SCHEMATA_EXT SCHEMA_NAME

‎mysql-test/r/information_schema.result

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ USER_STATISTICS
9898
VIEWS
9999
AUTHINFO
100100
SLAVE_DB_LOAD
101+
SCHEMATA_EXT
101102
columns_priv
102103
db
103104
event
@@ -939,7 +940,7 @@ table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest')
939940
AND table_name not like 'ndb%' AND table_name not like 'innodb_%' AND table_name not like 'rocksdb_%'
940941
GROUP BY TABLE_SCHEMA;
941942
table_schema count(*)
942-
information_schema 45
943+
information_schema 46
943944
mysql 27
944945
create table t1 (i int, j int);
945946
create trigger trg1 before insert on t1 for each row
@@ -1407,6 +1408,7 @@ QUERY_PERF_COUNTER information_schema.QUERY_PERF_COUNTER 1
14071408
REFERENTIAL_CONSTRAINTS information_schema.REFERENTIAL_CONSTRAINTS 1
14081409
ROUTINES information_schema.ROUTINES 1
14091410
SCHEMATA information_schema.SCHEMATA 1
1411+
SCHEMATA_EXT information_schema.SCHEMATA_EXT 1
14101412
SCHEMA_PRIVILEGES information_schema.SCHEMA_PRIVILEGES 1
14111413
SESSION_STATUS information_schema.SESSION_STATUS 1
14121414
SESSION_VARIABLES information_schema.SESSION_VARIABLES 1

‎mysql-test/r/information_schema_db.result

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ USER_STATISTICS
5050
VIEWS
5151
AUTHINFO
5252
SLAVE_DB_LOAD
53+
SCHEMATA_EXT
5354
show tables from INFORMATION_SCHEMA like 'T%';
5455
Tables_in_information_schema (T%)
5556
TRANSACTION_LIST

‎mysql-test/r/mysqlshow.result

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ DROP TABLE t1, t2;
146146
| ROCKSDB_TRX |
147147
| ROUTINES |
148148
| SCHEMATA |
149+
| SCHEMATA_EXT |
149150
| SCHEMA_PRIVILEGES |
150151
| SESSION_STATUS |
151152
| SESSION_VARIABLES |
@@ -234,6 +235,7 @@ DROP TABLE t1, t2;
234235
| ROCKSDB_TRX |
235236
| ROUTINES |
236237
| SCHEMATA |
238+
| SCHEMATA_EXT |
237239
| SCHEMA_PRIVILEGES |
238240
| SESSION_STATUS |
239241
| SESSION_VARIABLES |

‎mysql-test/suite/funcs_1/r/is_columns_is.result

+6
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ def information_schema SCHEMATA DEFAULT_CHARACTER_SET_NAME 3 NO varchar 32 96 N
287287
def information_schema SCHEMATA DEFAULT_COLLATION_NAME 4 NO varchar 32 96 NULL NULL NULL utf8 utf8_general_ci varchar(32) select
288288
def information_schema SCHEMATA SCHEMA_NAME 2 NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select
289289
def information_schema SCHEMATA SQL_PATH 5 NULL YES varchar 512 1536 NULL NULL NULL utf8 utf8_general_ci varchar(512) select
290+
def information_schema SCHEMATA_EXT CATALOG_NAME 1 NO varchar 512 1536 NULL NULL NULL utf8 utf8_general_ci varchar(512) select
291+
def information_schema SCHEMATA_EXT DB_METADATA 3 NO varchar 1024 3072 NULL NULL NULL utf8 utf8_general_ci varchar(1024) select
292+
def information_schema SCHEMATA_EXT SCHEMA_NAME 2 NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select
290293
def information_schema SCHEMA_PRIVILEGES GRANTEE 1 NO varchar 81 243 NULL NULL NULL utf8 utf8_general_ci varchar(81) select
291294
def information_schema SCHEMA_PRIVILEGES IS_GRANTABLE 5 NO varchar 3 9 NULL NULL NULL utf8 utf8_general_ci varchar(3) select
292295
def information_schema SCHEMA_PRIVILEGES PRIVILEGE_TYPE 4 NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select
@@ -918,6 +921,9 @@ NULL information_schema ROUTINES LAST_ALTERED datetime NULL NULL NULL NULL datet
918921
3.0000 information_schema SCHEMATA DEFAULT_CHARACTER_SET_NAME varchar 32 96 utf8 utf8_general_ci varchar(32)
919922
3.0000 information_schema SCHEMATA DEFAULT_COLLATION_NAME varchar 32 96 utf8 utf8_general_ci varchar(32)
920923
3.0000 information_schema SCHEMATA SQL_PATH varchar 512 1536 utf8 utf8_general_ci varchar(512)
924+
3.0000 information_schema SCHEMATA_EXT CATALOG_NAME varchar 512 1536 utf8 utf8_general_ci varchar(512)
925+
3.0000 information_schema SCHEMATA_EXT SCHEMA_NAME varchar 64 192 utf8 utf8_general_ci varchar(64)
926+
3.0000 information_schema SCHEMATA_EXT DB_METADATA varchar 1024 3072 utf8 utf8_general_ci varchar(1024)
921927
3.0000 information_schema SCHEMA_PRIVILEGES GRANTEE varchar 81 243 utf8 utf8_general_ci varchar(81)
922928
3.0000 information_schema SCHEMA_PRIVILEGES TABLE_CATALOG varchar 512 1536 utf8 utf8_general_ci varchar(512)
923929
3.0000 information_schema SCHEMA_PRIVILEGES TABLE_SCHEMA varchar 64 192 utf8 utf8_general_ci varchar(64)

‎mysql-test/suite/funcs_1/r/is_tables_is.result

+46
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,29 @@ user_comment
636636
Separator -----------------------------------------------------
637637
TABLE_CATALOG def
638638
TABLE_SCHEMA information_schema
639+
TABLE_NAME SCHEMATA_EXT
640+
TABLE_TYPE SYSTEM VIEW
641+
ENGINE MEMORY
642+
VERSION 10
643+
ROW_FORMAT Fixed
644+
TABLE_ROWS #TBLR#
645+
AVG_ROW_LENGTH #ARL#
646+
DATA_LENGTH #DL#
647+
MAX_DATA_LENGTH #MDL#
648+
INDEX_LENGTH #IL#
649+
DATA_FREE #DF#
650+
AUTO_INCREMENT NULL
651+
CREATE_TIME #CRT#
652+
UPDATE_TIME #UT#
653+
CHECK_TIME #CT#
654+
TABLE_COLLATION utf8_general_ci
655+
CHECKSUM NULL
656+
CREATE_OPTIONS #CO#
657+
TABLE_COMMENT #TC#
658+
user_comment
659+
Separator -----------------------------------------------------
660+
TABLE_CATALOG def
661+
TABLE_SCHEMA information_schema
639662
TABLE_NAME SCHEMA_PRIVILEGES
640663
TABLE_TYPE SYSTEM VIEW
641664
ENGINE MEMORY
@@ -1665,6 +1688,29 @@ user_comment
16651688
Separator -----------------------------------------------------
16661689
TABLE_CATALOG def
16671690
TABLE_SCHEMA information_schema
1691+
TABLE_NAME SCHEMATA_EXT
1692+
TABLE_TYPE SYSTEM VIEW
1693+
ENGINE MEMORY
1694+
VERSION 10
1695+
ROW_FORMAT Fixed
1696+
TABLE_ROWS #TBLR#
1697+
AVG_ROW_LENGTH #ARL#
1698+
DATA_LENGTH #DL#
1699+
MAX_DATA_LENGTH #MDL#
1700+
INDEX_LENGTH #IL#
1701+
DATA_FREE #DF#
1702+
AUTO_INCREMENT NULL
1703+
CREATE_TIME #CRT#
1704+
UPDATE_TIME #UT#
1705+
CHECK_TIME #CT#
1706+
TABLE_COLLATION utf8_general_ci
1707+
CHECKSUM NULL
1708+
CREATE_OPTIONS #CO#
1709+
TABLE_COMMENT #TC#
1710+
user_comment
1711+
Separator -----------------------------------------------------
1712+
TABLE_CATALOG def
1713+
TABLE_SCHEMA information_schema
16681714
TABLE_NAME SCHEMA_PRIVILEGES
16691715
TABLE_TYPE SYSTEM VIEW
16701716
ENGINE MEMORY

‎mysql-test/t/db_metadata.test

+21
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,49 @@ show create database test4;
4242
create database test5 db_metadata = "{\"shard\":\"test5_shard\"}";
4343
show create database test5;
4444
--exec cat $MYSQLD_DATADIR/test5/db.opt
45+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
4546

4647
# verify show create is valid
4748
--let $db_create=query_get_value(show create database test5, 'Create Database', 1)
4849
drop database test5;
4950
eval $db_create;
5051
show create database test5;
5152
--exec cat $MYSQLD_DATADIR/test5/db.opt
53+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
5254

5355
# create database with character set and db metadata
5456
create database test6 character set utf8 db_metadata = "{\"shard\":\"test6_shard\"}";
5557
show create database test6;
5658
--exec cat $MYSQLD_DATADIR/test6/db.opt
59+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
5760

5861
# create database with read only and db metadata
5962
create database test7 read_only = true db_metadata = "{\"shard\":\"test7_shard\"}";
6063
show create database test7;
6164
--exec cat $MYSQLD_DATADIR/test7/db.opt
65+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
6266

6367
# create database with character set and read only
6468
create database test8 character set utf8 read_only = true;
6569
show create database test8;
6670
--exec cat $MYSQLD_DATADIR/test8/db.opt
71+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
6772

6873
# create database with character set, read only and db metadata
6974
create database test9 character set utf8 read_only = true db_metadata = "{\"shard\":\"test9_shard\"}";
7075
show create database test9;
7176
--exec cat $MYSQLD_DATADIR/test9/db.opt
77+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
7278

7379
# create database with invalid JSON string for db_metadata
7480
--error ER_DB_METADATA_INVALID_JSON
7581
create database test10 db_metadata = "invalid_json";
82+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
7683

7784
# create database with single quotation
7885
--error ER_DB_METADATA_INVALID_JSON
7986
create database test11 db_metadata = "{\'shard\':\'test11_shard\'}";
87+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
8088

8189
# create database with double quote around metadata with single and double quotes in value
8290
create database test12 db_metadata = "{\"sha'rd\":\"test12\\\"_shard\"}";
@@ -107,6 +115,7 @@ show create database test3;
107115
alter database test3 db_metadata = "{\"shard\":\"test3_shard_altered\"}";
108116
show create database test3;
109117
--exec cat $MYSQLD_DATADIR/test3/db.opt
118+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
110119

111120
# alter database read only
112121
alter database test4 read_only = true;
@@ -117,6 +126,7 @@ show create database test4;
117126
alter database test4 db_metadata = "{\"shard\":\"test4_shard_altered\"}";
118127
show create database test4;
119128
--exec cat $MYSQLD_DATADIR/test4/db.opt
129+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
120130

121131
# alter database read only
122132
alter database test4 read_only = false;
@@ -127,6 +137,7 @@ show create database test4;
127137
alter database test5 db_metadata = "{\"shard\":\"test5_shard_altered\"}";
128138
show create database test5;
129139
--exec cat $MYSQLD_DATADIR/test5/db.opt
140+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
130141

131142
# alter database character set but keep db metadata intact
132143
alter database test5 character set ascii;
@@ -147,11 +158,13 @@ show create database test5;
147158
alter database test5 db_metadata "";
148159
show create database test5;
149160
--exec cat $MYSQLD_DATADIR/test5/db.opt
161+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
150162

151163
# alter database set db metadata to max length string
152164
alter database test5 db_metadata "{\"shard\":\"Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Fin\"}";
153165
show create database test5;
154166
--exec cat $MYSQLD_DATADIR/test5/db.opt
167+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
155168

156169
# verify show create is valid
157170
--let $db_create=query_get_value(show create database test5, 'Create Database', 1)
@@ -163,36 +176,43 @@ show create database test5;
163176
# alter database exceed db metadata max length
164177
--error ER_DB_METADATA_TOO_LONG
165178
alter database test5 db_metadata "{\"shard\":\"Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Really long shard name. Fin\"}";
179+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
166180

167181
# alter database character set and db metadata
168182
alter database test6 character set ascii db_metadata = "{\"shard\":\"test6_shard_altered\"}";
169183
show create database test6;
170184
--exec cat $MYSQLD_DATADIR/test6/db.opt
185+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
171186

172187
# alter database read only and db metadata
173188
alter database test7 read_only = true db_metadata = "{\"shard\":\"test7_shard_altered\"}";
174189
show create database test7;
175190
--exec cat $MYSQLD_DATADIR/test7/db.opt
191+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
176192

177193
# alter database character set and read only
178194
alter database test8 character set ascii read_only = true;
179195
show create database test8;
180196
--exec cat $MYSQLD_DATADIR/test8/db.opt
197+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
181198

182199
# alter database character set, read only and db metadata
183200
alter database test9 character set ascii read_only = true db_metadata = "{\"shard\":\"test9_shard_altered\"}";
184201
show create database test9;
185202
--exec cat $MYSQLD_DATADIR/test9/db.opt
203+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
186204

187205
# ensure information_schema and mysql tables are intact
188206
show create database information_schema;
189207
show create database mysql;
190208
--error ER_DBACCESS_DENIED_ERROR
191209
alter database information_schema db_metadata "{\"shard\":\"is_shard\"}";
210+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
192211

193212
# alter database with invalid JSON string for db_metadata
194213
--error ER_DB_METADATA_INVALID_JSON
195214
alter database test9 db_metadata = "invalid_json";
215+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
196216

197217
# create database without any options
198218
create database test10;
@@ -208,6 +228,7 @@ show create database test10;
208228
alter database test10 db_metadata = "{\"shard\":\"test10_shard_altered\"}";
209229
show create database test10;
210230
--exec cat $MYSQLD_DATADIR/test10/db.opt
231+
select catalog_name, schema_name, db_metadata from information_schema.schemata_ext;
211232

212233
# alter database read only
213234
alter database test10 read_only = false;

‎sql/handler.h

+15-4
Original file line numberDiff line numberDiff line change
@@ -1131,15 +1131,14 @@ enum enum_db_read_only { DB_READ_ONLY_NO = 0,
11311131
DB_READ_ONLY_SUPER = 2,
11321132
DB_READ_ONLY_NULL = 255 };
11331133

1134-
typedef struct st_ha_create_information
1134+
struct st_ha_create_information_base
11351135
{
11361136
const CHARSET_INFO *table_charset, *default_table_charset;
11371137
bool alter_default_table_charset; /* This is to differentiate whether the
11381138
null value for default_table_charset
11391139
means it is explicitly set to default or
11401140
it is not specified in alter */
11411141
enum enum_db_read_only db_read_only;
1142-
String db_metadata;
11431142
bool alter_db_metadata; /* This is to differentiate whether the null value
11441143
for db_metadata means it is explicitly set to
11451144
default or it is not specified in alter */
@@ -1157,7 +1156,6 @@ typedef struct st_ha_create_information
11571156
uint stats_sample_pages; /* number of pages to sample during
11581157
stats estimation, if used, otherwise 0. */
11591158
enum_stats_auto_recalc stats_auto_recalc;
1160-
SQL_I_List<TABLE_LIST> merge_list;
11611159
handlerton *db_type;
11621160
/**
11631161
Row type of the table definition.
@@ -1177,9 +1175,22 @@ typedef struct st_ha_create_information
11771175
enum ha_storage_media storage_media; /* DEFAULT, DISK or MEMORY */
11781176
bool rbr_column_names; /* If true, column names for this table are logged
11791177
in Table_map_log_events */
1178+
};
1179+
1180+
typedef struct st_ha_create_information : public st_ha_create_information_base
1181+
{
1182+
String db_metadata;
1183+
SQL_I_List<TABLE_LIST> merge_list;
11801184

11811185
/* initialize db_read_only parameter */
1182-
st_ha_create_information() : db_read_only(DB_READ_ONLY_NO) {}
1186+
st_ha_create_information()
1187+
{
1188+
// memset the base struct with POD fields
1189+
memset(
1190+
(st_ha_create_information_base *)this,
1191+
0,
1192+
sizeof(st_ha_create_information_base));
1193+
}
11831194
} HA_CREATE_INFO;
11841195

11851196
/**

‎sql/sql_db.cc

-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create,
667667
bool error=1;
668668
uint nbytes;
669669

670-
memset(create, 0, sizeof(*create));
671670
create->default_table_charset= thd->variables.collation_server;
672671

673672
/* Check if options for this database are already in the hash */

0 commit comments

Comments
 (0)
Please sign in to comment.