7 million is less than 10 ms for 10 random data records?

Source: Internet
Author: User

Although it is a bit confusing, but in actual development, it is true that such requirements will be met, but the requirements are not very strict. In that case, it is a good choice to use this method.

Haha the following content is reprinted from CSDB Forum

BlogArticle
Http://blog.csdn.net/jinjazz/archive/2009/04/16/4084142.aspx

SQL code
 
SetNocountOn
 
-- 75151448 rows of data
 
Select Count(*)FromSyscolumns A, syscolumns B, syscolumns C
 
Set Statistics Time On
 
 
 
 Select Top10 *From(
SelectA. NameAsName,Left(B. Name, 10)AsName1, checksum (newid ())AsHash
 
FromSyscolumns A, syscolumns B, syscolumns C) T
 
 WhereHash % 100 = 0
 
 
 
Set Statistics Time Off
 
SetNocountOff

SQL Server execution time:

CPU time = 16 ms, occupied time = 4 ms.

So BT? However, if you look at it carefully, it is a pseudo-random, and most of the data in the future will not be displayed for a lifetime. However, this is an idea. In the where hash % 100 = 0 clause, 100 is a key factor.

to be truly random, at least hash % 700000 is required. It takes 20 seconds for the same machine, but I think it is quite good. If it is hash % 70000, It is 2 seconds. It can be seen that this is basically a linear relationship. This idea should be more practical than order by newid. I gave up the top 10 of order by newid () after 2 minutes and a half of execution.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.