数据量300w要求分包100wsql

数据量300w要求分包100wsql,第1张

内存: 4 G

os: windows 2003

数据库: ms sql server 2008

目的: 查询性能测试,比较两种查询的性能

SQL查询效率 step by step

-- setp 1.

-- 建表

create table t_userinfo

(

userid int identity(1,1) primary key nonclustered,

nick varchar(50) not null default '',

classid int not null default 0,

writetime datetime not null default getdate()

)

go

-- 建索引

create clustered index ix_userinfo_classid on t_userinfo(classid)

go

-- step 2.

declare @i int

declare @k int

declare @nick varchar(10)

set @i = 1

while @i<1000000

begin

set @k = @i % 10

set @nick = convert(varchar,@i)

insert into t_userinfo(nick,classid,writetime) values(@nick,@k,getdate())

set @i = @i + 1

end

-- 耗时 08:27 ,需要耐心等待

-- step 3.

select top 20 userid,nick,classid,writetime from t_userinfo

where userid not in

(

select top 900000 userid from t_userinfo order by userid asc

)

-- 耗时 8 秒 ,够长的

-- step 4.

select a.userid,b.nick,b.classid,b.writetime from

(

select top 20 a.userid from

(

你说的慢一半,是在你插入了50万数据的时候,估计是查询慢了吧。因为按你说的还没到删除的时候呢。查询慢要看看你的查询的语句的执行计划,是否使用了合适的索引。如果索引错了,那么慢是正常的。可以用hint指定索引,从而保证执行计划稳定。

对于你这样的周期性维护的大表,可以做31个分区,每天一个,一个月内循环使用。不需要保留的数据可以以天为单位truncate掉一个或多个分区的数据,索引采用分区索引,truncate分区不影响索引的使用。

有一种猜测,是你的索引建的不对。

你的查询语句的查询条件是什么?是单列查询吗?如果pwd指password,至少我觉得不会有按password单列查询的语句吧。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9932623.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存