-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mysql-5.6][PR] FB8-120: Added db_metadata options to create database…
… command Summary: JIRA ticket: https://jira.percona.com/browse/FB8-120 Reference commit: 2f08e3a Reference commit: a21e84f Reference commit: 5983ba3181a Reference commit: 414870abeee Added new option db_metadata to the create database `CREATE DATABASE [IF NOT EXISTS] db_name DB_METADATA [=] metadata` The new option is stored in the db.opt file along with other database options like charset and read_only. The options accepts any string value. If not specified, it writes empty string as the default value in the db.opt file. To retrieve the option value for a particular database, the show command can be used as follows: `SHOW CREATE DATABASE db_name` Example Usage: create database test2 charset utf8 read_only = true db_metadata '{\'shard_name\':\'myshard_for_test2\'}'; show create database test2; Output: +----------+--------------------------------------------------------------------------------------------------------------------------+ | Database | Create Database | +----------+--------------------------------------------------------------------------------------------------------------------------+ | test2 | CREATE DATABASE `test2` /*!40100 DEFAULT CHARACTER SET utf8 READ_ONLY DB_METADATA {'shard_name':'myshard_for_test2'} */ | +----------+--------------------------------------------------------------------------------------------------------------------------+ Pull Request resolved: #972 GitHub Author: Zsolt Parragi <[email protected]> Test Plan: Imported from GitHub, without a `Test Plan:` line. Reviewers: mung, yzha Reviewed By: yzha Subscribers: butterflybot, vinaybhat, [email protected] Differential Revision: https://phabricator.intern.facebook.com/D14883632 Signature: 14883632:1557511964:520d100e270adc11fba035a56ecebc4eac332052
- Loading branch information
1 parent
5a455f2
commit 3af0fc8
Showing
16 changed files
with
418 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
create database test2; | ||
show create database test2; | ||
Database Create Database | ||
test2 CREATE DATABASE `test2` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ | ||
create database test3 character set utf8; | ||
Warnings: | ||
Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. | ||
show create database test3; | ||
Database Create Database | ||
test3 CREATE DATABASE `test3` /*!40100 DEFAULT CHARACTER SET utf8 */ | ||
create database test4 read_only = true; | ||
show create database test4; | ||
Database Create Database | ||
test4 CREATE DATABASE `test4` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ | ||
create database test5 db_metadata = "{\"shard\":\"test5_shard\"}"; | ||
show create database test5; | ||
Database Create Database | ||
test5 CREATE DATABASE `test5` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"shard":"test5_shard"}' */ | ||
drop database test5; | ||
CREATE DATABASE `test5` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"shard":"test5_shard"}' */; | ||
show create database test5; | ||
Database Create Database | ||
test5 CREATE DATABASE `test5` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"shard":"test5_shard"}' */ | ||
create database test6 character set utf8 db_metadata = "{\"shard\":\"test6_shard\"}"; | ||
Warnings: | ||
Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. | ||
show create database test6; | ||
Database Create Database | ||
test6 CREATE DATABASE `test6` /*!40100 DEFAULT CHARACTER SET utf8 DB_METADATA '{"shard":"test6_shard"}' */ | ||
create database test7 read_only = true db_metadata = "{\"shard\":\"test7_shard\"}"; | ||
show create database test7; | ||
Database Create Database | ||
test7 CREATE DATABASE `test7` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"shard":"test7_shard"}' */ | ||
create database test8 character set utf8 read_only = true; | ||
Warnings: | ||
Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. | ||
show create database test8; | ||
Database Create Database | ||
test8 CREATE DATABASE `test8` /*!40100 DEFAULT CHARACTER SET utf8 */ | ||
create database test9 character set utf8 read_only = true db_metadata = "{\"shard\":\"test9_shard\"}"; | ||
Warnings: | ||
Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. | ||
show create database test9; | ||
Database Create Database | ||
test9 CREATE DATABASE `test9` /*!40100 DEFAULT CHARACTER SET utf8 DB_METADATA '{"shard":"test9_shard"}' */ | ||
alter database test3 character set ascii; | ||
show create database test3; | ||
Database Create Database | ||
test3 CREATE DATABASE `test3` /*!40100 DEFAULT CHARACTER SET ascii */ | ||
alter database test4 read_only = true; | ||
show create database test4; | ||
Database Create Database | ||
test4 CREATE DATABASE `test4` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci READ_ONLY */ | ||
alter database test5 db_metadata = "{\"shard\":\"test5_shard_altered\"}"; | ||
show create database test5; | ||
Database Create Database | ||
test5 CREATE DATABASE `test5` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"shard":"test5_shard_altered"}' */ | ||
alter database test5 character set ascii; | ||
show create database test5; | ||
Database Create Database | ||
test5 CREATE DATABASE `test5` /*!40100 DEFAULT CHARACTER SET ascii DB_METADATA '{"shard":"test5_shard_altered"}' */ | ||
alter database test5 read_only = true; | ||
show create database test5; | ||
Database Create Database | ||
test5 CREATE DATABASE `test5` /*!40100 DEFAULT CHARACTER SET ascii READ_ONLY DB_METADATA '{"shard":"test5_shard_altered"}' */ | ||
alter database test5 character set utf8 read_only = false; | ||
Warnings: | ||
Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. | ||
show create database test5; | ||
Database Create Database | ||
test5 CREATE DATABASE `test5` /*!40100 DEFAULT CHARACTER SET utf8 DB_METADATA '{"shard":"test5_shard_altered"}' */ | ||
alter database test5 db_metadata ""; | ||
show create database test5; | ||
Database Create Database | ||
test5 CREATE DATABASE `test5` /*!40100 DEFAULT CHARACTER SET utf8 */ | ||
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\"}"; | ||
show create database test5; | ||
Database Create Database | ||
test5 CREATE DATABASE `test5` /*!40100 DEFAULT CHARACTER SET utf8 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"}' */ | ||
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\"}";; | ||
ERROR HY000: Metadata for the database is too long. Max length is 1024 bytes | ||
alter database test6 character set ascii db_metadata = "{\"shard\":\"test6_shard_altered\"}"; | ||
show create database test6; | ||
Database Create Database | ||
test6 CREATE DATABASE `test6` /*!40100 DEFAULT CHARACTER SET ascii DB_METADATA '{"shard":"test6_shard_altered"}' */ | ||
alter database test7 read_only = true db_metadata = "{\"shard\":\"test7_shard_altered\"}"; | ||
show create database test7; | ||
Database Create Database | ||
test7 CREATE DATABASE `test7` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci READ_ONLY DB_METADATA '{"shard":"test7_shard_altered"}' */ | ||
alter database test8 character set ascii read_only = true; | ||
show create database test8; | ||
Database Create Database | ||
test8 CREATE DATABASE `test8` /*!40100 DEFAULT CHARACTER SET ascii READ_ONLY */ | ||
alter database test9 character set ascii read_only = true db_metadata = "{\"shard\":\"test9_shard_altered\"}"; | ||
show create database test9; | ||
Database Create Database | ||
test9 CREATE DATABASE `test9` /*!40100 DEFAULT CHARACTER SET ascii READ_ONLY DB_METADATA '{"shard":"test9_shard_altered"}' */ | ||
show create database information_schema; | ||
Database Create Database | ||
information_schema CREATE DATABASE `information_schema` /*!40100 DEFAULT CHARACTER SET utf8 */ | ||
show create database mysql; | ||
Database Create Database | ||
mysql CREATE DATABASE `mysql` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ | ||
alter database information_schema db_metadata "{\"shard\":\"is_shard\"}"; | ||
ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema' | ||
alter database test9 db_metadata = "invalid_json"; | ||
ERROR HY000: Invalid JSON for DB_METADATA attribute: invalid_json. | ||
show create database test9; | ||
Database Create Database | ||
test9 CREATE DATABASE `test9` /*!40100 DEFAULT CHARACTER SET ascii READ_ONLY DB_METADATA '{"shard":"test9_shard_altered"}' */ | ||
create database test10; | ||
show create database test10; | ||
Database Create Database | ||
test10 CREATE DATABASE `test10` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ | ||
alter database test10 read_only = true; | ||
show create database test10; | ||
Database Create Database | ||
test10 CREATE DATABASE `test10` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci READ_ONLY */ | ||
alter database test10 db_metadata = "{\"shard\":\"test10_shard_altered\"}"; | ||
show create database test10; | ||
Database Create Database | ||
test10 CREATE DATABASE `test10` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci READ_ONLY DB_METADATA '{"shard":"test10_shard_altered"}' */ | ||
alter database test10 read_only = false; | ||
show create database test10; | ||
Database Create Database | ||
test10 CREATE DATABASE `test10` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"shard":"test10_shard_altered"}' */ | ||
create database test11 db_metadata = "{\'shard\':\'test11_shard\'}"; | ||
ERROR HY000: Invalid JSON for DB_METADATA attribute: {'shard':'test11_shard'}. | ||
create database test12 db_metadata = "{\"sha'rd\":\"test12\\\"_shard\"}"; | ||
show create database test12; | ||
Database Create Database | ||
test12 CREATE DATABASE `test12` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"sha''rd":"test12\\"_shard"}' */ | ||
drop database test12; | ||
CREATE DATABASE `test12` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"sha''rd":"test12\\"_shard"}' */; | ||
show create database test12; | ||
Database Create Database | ||
test12 CREATE DATABASE `test12` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"sha''rd":"test12\\"_shard"}' */ | ||
create database test13 db_metadata = '{"sha\'\\"rd":"test13\'_sh\\"ard"}'; | ||
show create database test13; | ||
Database Create Database | ||
test13 CREATE DATABASE `test13` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"sha''\\"rd":"test13''_sh\\"ard"}' */ | ||
drop database test13; | ||
CREATE DATABASE `test13` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"sha''\\"rd":"test13''_sh\\"ard"}' */; | ||
show create database test13; | ||
Database Create Database | ||
test13 CREATE DATABASE `test13` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DB_METADATA '{"sha''\\"rd":"test13''_sh\\"ard"}' */ | ||
drop database test2; | ||
drop database test3; | ||
drop database test4; | ||
drop database test5; | ||
drop database test6; | ||
drop database test7; | ||
drop database test8; | ||
drop database test9; | ||
drop database test10; | ||
drop database test12; | ||
drop database test13; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ DAY_HOUR 1 | |
DAY_MICROSECOND 1 | ||
DAY_MINUTE 1 | ||
DAY_SECOND 1 | ||
DB_METADATA 1 | ||
DEALLOCATE 0 | ||
DEC 1 | ||
DECIMAL 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# Test per-database database-metadata attribute | ||
|
||
let $MYSQLD_DATADIR= `select @@datadir`; | ||
|
||
# create database without any options | ||
create database test2; | ||
show create database test2; | ||
|
||
# create database with character set | ||
create database test3 character set utf8; | ||
show create database test3; | ||
|
||
# create database with read only | ||
create database test4 read_only = true; | ||
show create database test4; | ||
|
||
# create database with db metadata | ||
create database test5 db_metadata = "{\"shard\":\"test5_shard\"}"; | ||
show create database test5; | ||
|
||
# verify show create is valid | ||
--let $db_create=query_get_value(show create database test5, 'Create Database', 1) | ||
drop database test5; | ||
eval $db_create; | ||
show create database test5; | ||
|
||
# create database with character set and db metadata | ||
create database test6 character set utf8 db_metadata = "{\"shard\":\"test6_shard\"}"; | ||
show create database test6; | ||
|
||
# create database with read only and db metadata | ||
create database test7 read_only = true db_metadata = "{\"shard\":\"test7_shard\"}"; | ||
show create database test7; | ||
|
||
# create database with character set and read only | ||
create database test8 character set utf8 read_only = true; | ||
show create database test8; | ||
|
||
# create database with character set, read only and db metadata | ||
create database test9 character set utf8 read_only = true db_metadata = "{\"shard\":\"test9_shard\"}"; | ||
show create database test9; | ||
|
||
# alter database tests | ||
|
||
# alter database character set | ||
alter database test3 character set ascii; | ||
show create database test3; | ||
|
||
# alter database read only | ||
alter database test4 read_only = true; | ||
show create database test4; | ||
|
||
# alter database db metadata | ||
alter database test5 db_metadata = "{\"shard\":\"test5_shard_altered\"}"; | ||
show create database test5; | ||
|
||
# alter database character set but keep db metadata intact | ||
alter database test5 character set ascii; | ||
show create database test5; | ||
|
||
# alter database read only but keep db metadata intact | ||
alter database test5 read_only = true; | ||
show create database test5; | ||
|
||
# alter database character set and read only but keep db metadata intact | ||
alter database test5 character set utf8 read_only = false; | ||
show create database test5; | ||
|
||
# alter database reset db metadata | ||
alter database test5 db_metadata ""; | ||
show create database test5; | ||
|
||
# alter database set db metadata to max length string | ||
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\"}"; | ||
show create database test5; | ||
|
||
# alter database exceed db metadata max length | ||
--error ER_DB_METADATA_TOO_LONG | ||
--eval 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\\\"}\"; | ||
|
||
# alter database character set and db metadata | ||
alter database test6 character set ascii db_metadata = "{\"shard\":\"test6_shard_altered\"}"; | ||
show create database test6; | ||
|
||
# alter database read only and db metadata | ||
alter database test7 read_only = true db_metadata = "{\"shard\":\"test7_shard_altered\"}"; | ||
show create database test7; | ||
|
||
# alter database character set and read only | ||
alter database test8 character set ascii read_only = true; | ||
show create database test8; | ||
|
||
# alter database character set, read only and db metadata | ||
alter database test9 character set ascii read_only = true db_metadata = "{\"shard\":\"test9_shard_altered\"}"; | ||
show create database test9; | ||
|
||
# ensure information_schema and mysql tables are intact | ||
show create database information_schema; | ||
show create database mysql; | ||
|
||
--error ER_DBACCESS_DENIED_ERROR | ||
alter database information_schema db_metadata "{\"shard\":\"is_shard\"}"; | ||
|
||
# alter database with invalid JSON string for db_metadata | ||
--error ER_DB_METADATA_INVALID_JSON | ||
alter database test9 db_metadata = "invalid_json"; | ||
show create database test9; | ||
|
||
|
||
|
||
# create database without any options | ||
create database test10; | ||
show create database test10; | ||
|
||
# alter database read only | ||
alter database test10 read_only = true; | ||
show create database test10; | ||
|
||
# alter database db metadata | ||
alter database test10 db_metadata = "{\"shard\":\"test10_shard_altered\"}"; | ||
show create database test10; | ||
|
||
# alter database read only | ||
alter database test10 read_only = false; | ||
show create database test10; | ||
|
||
# create database with single quotation | ||
--error ER_DB_METADATA_INVALID_JSON | ||
create database test11 db_metadata = "{\'shard\':\'test11_shard\'}"; | ||
|
||
# create database with double quote around metadata with single and double quotes in value | ||
create database test12 db_metadata = "{\"sha'rd\":\"test12\\\"_shard\"}"; | ||
show create database test12; | ||
--let $db_create=query_get_value(show create database test12, 'Create Database', 1) | ||
drop database test12; | ||
eval $db_create; | ||
show create database test12; | ||
|
||
# create database with single quote around metadata with single and double quotes in value | ||
create database test13 db_metadata = '{"sha\'\\"rd":"test13\'_sh\\"ard"}'; | ||
show create database test13; | ||
--let $db_create=query_get_value(show create database test13, 'Create Database', 1) | ||
drop database test13; | ||
eval $db_create; | ||
show create database test13; | ||
|
||
|
||
# cleanup | ||
drop database test2; | ||
drop database test3; | ||
drop database test4; | ||
drop database test5; | ||
drop database test6; | ||
drop database test7; | ||
drop database test8; | ||
drop database test9; | ||
drop database test10; | ||
drop database test12; | ||
drop database test13; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.