SQL查询效率,100w数据
2021/6/3 19:27:59
本文主要是介绍SQL查询效率,100w数据,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
SQL优化—SQL查询效率,100w数据,查询只要1秒
https://www.cnblogs.com/ShaYeBlog/p/3227244.html
其他 测试
-- 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 ( select top 900020 userid from t_userinfo order by userid asc ) a order by a.userid desc ) a inner join t_userinfo b on a.userid = b.userid order by a.userid asc -- 耗时 1 秒,太快了吧,不可以思议 -- step 5 where 查询 select top 20 userid,nick,classid,writetime from t_userinfo where 1=1 and classid = 1 and userid not in ( select top 90000 userid from t_userinfo where classid = 1 order by userid asc ) -- 耗时 2 秒 -- step 6 where 查询 select a.userid,b.nick,b.classid,b.writetime from ( select top 20 a.userid from ( select top 90000 userid from t_userinfo where classid = 1 order by userid asc ) a order by a.userid desc ) a inner join t_userinfo b on a.userid = b.userid order by a.userid asc -- 查询分析器显示不到 1 秒. --查询数据个数 select count(*) from t_userinfo --999999 --测试 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 )
-- 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 ( select top 900020 userid from t_userinfo order by userid asc ) a order by a.userid desc ) a inner join t_userinfo b on a.userid = b.userid order by a.userid asc -- 耗时 1 秒,太快了吧,不可以思议 -- step 5 where 查询 select top 20 userid,nick,classid,writetime from t_userinfo where 1=1 and classid = 1 and userid not in ( select top 90000 userid from t_userinfo where classid = 1 order by userid asc ) -- 耗时 2 秒 -- step 6 where 查询 select a.userid,b.nick,b.classid,b.writetime from ( select top 20 a.userid from ( select top 90000 userid from t_userinfo where classid = 1 order by userid asc ) a order by a.userid desc ) a inner join t_userinfo b on a.userid = b.userid order by a.userid asc -- 查询分析器显示不到 1 秒. --查询数据个数 select count(*) from t_userinfo --999999 --测试 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 )
这篇关于SQL查询效率,100w数据的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)