如何在mysql v8中生成固定数量的行以进行性能测试?

bvjxkvbb  于 2021-06-23  发布在  Mysql
关注(0)|答案(2)|浏览(609)

我尝试在mysql v8中创建性能测试。为此,我需要生成固定数量的行,以便将它们插入到表中。
在postgresql中,我会执行以下操作:

insert into film(title)
select random_string(30)
from   generate_series(1, 100000);

在这里, random_string(int) 是一个自定义函数。在mysql中,我可以使用https://stackoverflow.com/a/47884557/9740433,我想这就足够了。
如何在mysql v8中生成10万行?

gab6jxml

gab6jxml1#

根据草莓的评论,回答我自己的问题:

WITH RECURSIVE cte (n) AS
(
  SELECT 1
  UNION ALL
  SELECT n + 1 FROM cte WHERE n < 5
)
SELECT * FROM cte;

您可能需要更改递归深度: SET SESSION cte_max_recursion_depth = 1000000; .

j8ag8udp

j8ag8udp2#

你可以用老式的 cross join 方法:

with d as (
      select 0 as d union all select 1 union all select 2 union all select 3 union all
             select 4 union all select 5 union all select 6 union all
             select 7 union all select 8 union all select 9
     ),
     n as (
      select (1 + d1 + d2 * 10 + d3 * 100 + d4 * 1000 + d5 * 10000) as n
      from d d1 cross join
           d d2 cross join
           d d3 cross join
           d d4 cross join
           d d5
     )
select *
from n;

这将是有趣的测试的性能 cross join 针对递归cte。

相关问题