惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - 最坏是单飞

[转载]启用IIS的Gzip压缩功能 javascript判断IFRAME是否加载完成 - 最坏是单飞 - 博客园 Cookie注入是怎样产生的 国外网站设计与浏览习惯 从一个错误提示引出SQL中in和or的问题。 CSS中 link与@import的区别 firefox3.0上安装google toolbar的问题 ASP.NET中常用的26个优化性能方法 INSERT 失败,因为下列 SET 选项的设置不正确: 'ARITHABORT' 背英语单词的捷径 提高sql server性能的几种方法 Windows下配置Apache支持PHP windows Server mysql的root密码忘记修复方法 select时尽可能少使用as对性能很有好处 sb.5252.ws恶意注入解决方法 asp调用存储过程返回值为空解决方案 - 最坏是单飞 - 博客园 如何在SQL Sever中建立索引? 解决ASP.NET中Type.GetType方法总返回空的问题 - 最坏是单飞 - 博客园 验证视图状态 MAC 失败
判断记录是否存在 exists 和 top 1 要比 count 快
最坏是单飞 · 2008-09-28 · via 博客园 - 最坏是单飞

之前在程序中验证记录是否存在,总是用select count(0) from table1的到记录数,然后在比对

今天做的页面中需要验证此类信息3此,所以就像有没有性能更好的办法

 思考count的工作原理后感觉是读取所有数据后进行统计的

而使用top 1 会不会只是取得第一个纪录后就跳出查询呢?

正好手头上又朋友上次做实验制作的一个300万记录的表,我就用来做了下实验

首先是

select count(0) from table1

执行时间 两次分别是 3秒,1秒

select top 1 0 from table1

两次执行时间都为0秒

exists( select  0 from table1)

两次都为0秒

当使用数据库中的某个字段来做验证时(特别是字符串型)的更明显

以上只是本人做的一个小小实验,如果哪里不合理大家多多指证,写的不好大家别丢石子就行了