11.pgsql批量插入测试数据测试

本文详细测试了PostgreSQL中四种不同的批量插入数据效率,包括直接调用存储过程、关闭自动提交调用存储过程、直接使用插入语句以及关闭自动提交使用插入语句。测试结果显示关闭自动提交对性能提升不明显。此外,还对比了通过导出导入数据文件使用COPY复制和直接使用SQL语句复制表的效率,COPY操作对性能提升有帮助。总结指出,插入数据推荐使用直接插入并关闭自动提交,复制表数据推荐使用COPY命令。
摘要由CSDN通过智能技术生成

1.测试准备

-- 1.创建测试表t_user
create table if not exists t_user(
	id serial primary key,
	user_name varchar(255),
	pass_word varchar(255),
	create_time date,
	dr char(1)
)

-- 2.注释
comment on column t_user.id is '测试表';
comment on column t_user.user_name is '账号';
comment on column t_user.pass_word is '密码';
comment on column t_user.create_time is '创建日期';
comment on column t_user.dr is 'delete remark';

2.测试4种不同的批量插入测试数据效率

创建存储过程

-- 创建存储过程插入数据
create or replace function batch_insert_proc(num int) returns void as 
$$
begin
	while num > 0 loop
		insert into t_user(user_name,pass_word,create_time,dr) values('username'||round(random()*num),'password'||round(random()*num),now(),0);
		num = num -1;
	end loop;
exception
	when others then
	raise exception'(%)',SQLERRM;
end;
$$ language plpgsql;

2.1直接调用存储过程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值