[英]How do I multiply data in mySQL database to simulate scale?
Input: 输入:
A database consisting of 一个数据库,由
Task: 任务:
Example: 例:
Tables:
t_user (scale target)
UserId , Name
1 , John
2, Terry
t_post (dynamic)
AuthorId, PostId, TagId
1, 1 , 1
1, 2 , 2
1, 3 , 2
2, 4 , 1
t_tag (static)
TagId, Name
1, C#
2, Java
Desired output with scale factor = 2 比例因子= 2的所需输出
t_user
UserId , Name
1 , John
2, Terry
3 , John
4, Terry
t_post (dynamic)
AuthorId, PostId, TagId
1, 1 , 1
1, 2 , 2
1, 3 , 2
2, 4 , 1
1, 5 , 1
1, 6 , 2
1, 7 , 2
2, 8 , 1
t_tag (static)
TagId, Name
1, C#
2, Java
Ofcourse for such a small database this can be done in MySQL but I need a solution that will work for a database with 150+ tables (writing a scaling routine for each is not a solution) and scale factors that will bring a database form 100 to up to 10 000 users. 当然,对于这么小的数据库,这可以在MySQL中完成,但是我需要一个解决方案,该解决方案适用于具有150多个表的数据库(为每个表编写一个缩放例程不是解决方案),并且可以将数据库从100扩展到100多达10000个用户。
Does anyone know a dedicated tool or hack that can accomplish this? 有谁知道可以完成此任务的专用工具或黑客程序?
Benchmark Factory for Databases看起来可以满足您的需要,也可以尝试使用MySQL Benchmark Tool 。
I ended up with writing my own script. 我最终写了自己的剧本。 Below you will find a simplified version (many columns in tables are ommited for clarity).
在下面,您会找到一个简化的版本(为清楚起见,省略了表中的许多列)。 This worked very well.
效果很好。 I was able to scale the DB by a factor of 100 quite efficiently.
我能够非常有效地将数据库扩展到100倍。 Hope this helps
希望这可以帮助
SET autocommit = 0;
START TRANSACTION;
SET @UMAX = (SELECT MAX(UserID) AS MX FROM t_user);
SET @QSMAX = (SELECT MAX(QuestionSetID) AS MX FROM t_question_set);
SET @QGMAX = (SELECT MAX(QuestionGroupID) AS MX FROM t_question_group);
SET @QMAX = (SELECT MAX(QuestionID) AS MX FROM t_question);
SET @TMAX = (SELECT MAX(TestID) AS MX FROM t_test);
DROP TABLE IF EXISTS t_seq;
CREATE table t_seq AS
(
SELECT
1 S
);
INSERT INTO t_seq (S) VALUES (2),(3),(4),(5),(6),(7),(8),(9),(10);
INSERT INTO `t_user`
(
`UserID`,
`Login`,
`Password`,
)
SELECT
`UserID` + 1000000 + @UMAX * t_seq.S,
concat(if(Login is null, '', Login), `UserID` + 1000000 + @UMAX * t_seq.S),
`Password`,
FROM t_user,
t_seq;
INSERT INTO `t_question_set`(`QuestionSetID`)
SELECT `QuestionSetID` + 1000000 + @QSMAX * t_seq.S
FROM t_question_set,t_seq;
INSERT INTO `t_question_group`(
`QuestionGroupID`,
`QuestionSetID`
)
SELECT
`QuestionGroupID` + 1000000 + @QGMAX * t_seq.S,
`QuestionSetID` + 1000000 + @QSMAX * t_seq.S,
FROM t_question_group,t_seq;
INSERT INTO `t_question`(`QuestionID`, `QuestionGroupID`)
SELECT
`QuestionID` + 1000000 + @QMAX * t_seq.S,
`QuestionGroupID` + 1000000 + @QGMAX * t_seq.S,
FROM t_question, t_seq;
INSERT INTO `t_test`
(
`TestID`,
`QuestionSetID`,
`UserID`,
)
SELECT
`TestID` + 1000000 + @TMAX * t_seq.S,
`QuestionSetID` + 1000000 + @QSMAX * t_seq.S,
`UserID` + 1000000 + @UMAX * t_seq.S,
FROM t_test,t_seq;
INSERT INTO `t_question_answer`(
`QuestionID`,
`TestID`
)
SELECT
`QuestionID` + 1000000 + @QMAX * t_seq.S,
`TestID` + 1000000 + @TMAX * t_seq.S,
FROM t_question_answer,t_seq;
COMMIT;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.