You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.9 KiB

5 months ago
--
create table test_enf_demo
(
id bigint not null comment '主键'
primary key,
enf_text varchar(255) null comment '文本',
enf_content longtext null comment '长文本',
tenant_id varchar(20) default '000000' null comment '租户编号',
dept_id bigint null comment '部门id',
user_id bigint null comment '用户id',
order_num int default 0 null comment '排序号',
test_key varchar(255) null comment 'key键',
value varchar(255) null comment '',
version int default 0 null comment '版本',
create_dept varchar(100) null comment '创建部门',
create_time datetime null comment '创建时间',
create_by bigint null comment '创建人',
update_time datetime null comment '更新时间',
update_by bigint null comment '更新人',
del_flag int default 0 null comment '删除标志'
)
comment 'enf测试单表';
-- 为 test_enf_demo 表生成 10000 条测试数据
-- 使用存储过程批量插入
DROP PROCEDURE IF EXISTS generate_test_enf_demo_data;
DELIMITER $$
CREATE PROCEDURE generate_test_enf_demo_data()
BEGIN
DECLARE i INT DEFAULT 1;
DECLARE batch_size INT DEFAULT 500;
DECLARE current_batch INT DEFAULT 0;
-- 关闭自动提交,提升插入性能
SET autocommit = 0;
WHILE i <= 10000 DO
INSERT INTO test_enf_demo (
id, enf_text, enf_content, tenant_id, dept_id, user_id,
order_num, test_key, value, version,
create_dept, create_time, create_by, update_time, update_by, del_flag
) VALUES (
i,
CONCAT('文本_', i),
CONCAT('这是第', i, '条测试长文本内容,用于测试数据填充。'),
'000000',
100 + FLOOR(RAND() * 50),
1000 + FLOOR(RAND() * 500),
i,
CONCAT('KEY_', LPAD(i, 5, '0')),
CONCAT('VAL_', LPAD(i, 5, '0')),
0,
CONCAT('部门_', FLOOR(RAND() * 20)),
DATE_ADD('2024-01-01', INTERVAL FLOOR(RAND() * 730) DAY),
1,
NOW(),
1,
0
);
-- 每 500 条提交一次
SET current_batch = current_batch + 1;
IF current_batch >= batch_size THEN
COMMIT;
SET current_batch = 0;
END IF;
SET i = i + 1;
END WHILE;
-- 提交剩余数据
COMMIT;
SET autocommit = 1;
END$$
DELIMITER ;
-- 执行存储过程
CALL generate_test_enf_demo_data();
-- 清理存储过程
DROP PROCEDURE IF EXISTS generate_test_enf_demo_data;
-- 验证数据量
SELECT COUNT(*) AS total_count FROM test_enf_demo;