3/用户登录(二):保存用户操作日志的方法

1、表关联查询

如果关联的表示亿万级 百万级 那么影响会很大 所以要加上冗余字段

关联表
select a.user_name ,a.id,b.log_date from user_sys a,user_log b where a.id=b.user_id ORDER BY b.id desc limit 0,10;

添加冗余字段
select a.* from user_log a ORDER BY id desc limit 0,10;


加入3000W条数据测试结果:


[SQL]select a.user_name ,a.id,b.log_date from user_sys a,user_log b where a.id=b.user_id ORDER BY b.id desc limit 0,10;
受影响的行: 0
时间: 204.259s

[SQL]

select a.* from user_log a ORDER BY id desc limit 0,10;
受影响的行: 0
时间: 0.000s

保存用户操作日志的方法:

BEGIN
#Routine body goes here...
SET @gid=0;
set @user_name='';
set @_result='login success';
SELECT id,user_name into @gid,@user_name from user_sys where user_name=_user_name and user_pwd=_user_pwd limit 1;
if @gid=0 THEN #代表登录不成功
set @_result='login error';
end if;
SELECT * from (SELECT @_result as _result) a,(SELECT @gid,@user_name) b;
INSERT INTO user_log(user_id,log_type) VALUES(@gid,@_result);
END

插入3000W条数据方法:

BEGIN
#Routine body goes here...
set @num=1;
while @num<30000000 DO
INSERT into user_log(log_type,user_id) values('log success',FLOOR(RAND()*1000000));
@num++;
end WHILE;


END




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值