我是一名学生,正在尝试为一个项目测试不同数据库的性能。 我试图做的是生成 0-99999(通过多次自加入 0-9 数字表)并测量时序。我对我的结果感到惊讶,想知道是否有人可以帮助解释它们(它们如下所示)。
这是我的测试程序:
BEGIN
DECLARE vduration DECIMAL(8,4) DEFAULT 0;
DECLARE vid INT DEFAULT 0;
DECLARE vcount INT DEFAULT 0;
DECLARE vprofilingid INT DEFAULT 0;
DECLARE a INT DEFAULT 0 ;
simple_loop: LOOP
SET a = a+1;
FLUSH QUERY CACHE;
SET profiling=1;
SELECT n1.n + n2.n*10 + n3.n*100 + n4.n*1000 + n5.n*10000
FROM
baseline.num n1
, baseline.num n2
, baseline.num n3
, baseline.num n4
, baseline.num n5
LIMIT 100000;
SET profiling=0;
SELECT COUNT(*) INTO vcount FROM baseline.result;
IF vcount=0 THEN
SET vid=1;
ELSE
SELECT MAX(Rid)+1 INTO vid FROM baseline.result;
END IF;
SELECT MAX(DISTINCT(query_id)) INTO vprofilingid
FROM information_schema.profiling;
SELECT SUM(duration) INTO vduration
FROM information_schema.profiling WHERE query_id=vprofilingid;
INSERT INTO baseline.result VALUES (vid, vduration);
IF a=5 THEN
LEAVE simple_loop;
END IF;
END LOOP simple_loop;
END
结果:
RID DURATION
8 0.0406
9 1.8610
10 1.8401
11 1.8558
12 1.8638
运行 SHOW PROFILES 显示:
8 0.04059275 select n1.n+n2.n*10+n3.n*100+n4.n*1000+n5.n*10000 from baseline.num n1, baseline.num n2,baseline.num n3,baseline.num n4,baseline.num n5 Limit 100000
9 1.86098975 select n1.n+n2.n*10+n3.n*100+n4.n*1000+n5.n*10000 from baseline.num n1, baseline.num n2,baseline.num n3,baseline.num n4,baseline.num n5 Limit 100000
10 1.84006350 select n1.n+n2.n*10+n3.n*100+n4.n*1000+n5.n*10000 from baseline.num n1, baseline.num n2,baseline.num n3,baseline.num n4,baseline.num n5 Limit 100000
11 1.85582025 select n1.n+n2.n*10+n3.n*100+n4.n*1000+n5.n*10000 from baseline.num n1, baseline.num n2,baseline.num n3,baseline.num n4,baseline.num n5 Limit 100000
12 1.86381750 select n1.n+n2.n*10+n3.n*100+n4.n*1000+n5.n*10000 from baseline.num n1, baseline.num n2,baseline.num n3,baseline.num n4,baseline.num n5 Limit 100000
为什么第一次更快?这与我的假设相反。
我注意到 SENDINT DATA 有区别,
SELECT * FROM information_schema.profiling
WHERE query_id > 7 and state = 'Sending data';
显示:
8 10 Sending data 0.040310
9 10 Sending data 1.860891
10 10 Sending data 1.839958
11 10 Sending data 1.855719
12 10 Sending data 1.863717
另外,如果我将循环设置为只运行一次,则所有结果都在 0.04 秒左右。我在这里做错了什么吗?我真的很困惑。
最佳答案
这是 MySQL 拥有的所有线程状态的链接。
http://dev.mysql.com/doc/refman/5.5/en/general-thread-states.html
注意关于发送数据的部分:
Sending data
The thread is reading and processing rows for a SELECT statement, and sending data to the client. Because operations occurring during this this state tend to perform large amounts of disk access (reads), it is often the longest-running state over the lifetime of a given query.
因为发送数据包括磁盘读取时间,所以值可能会有很大差异,具体取决于数据是否在 HDD 缓存、RAM 缓存、MySQL 缓存等中。
您的第一个查询不会从磁盘读取任何数据,因此读取数据+发送数据这一步要快得多。
关于MYSQL "Sending data"每次显示不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5517464/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我有一个这样的哈希数组:[{:foo=>2,:date=>Sat,01Sep2014},{:foo2=>2,:date=>Sat,02Sep2014},{:foo3=>3,:date=>Sat,01Sep2014},{:foo4=>4,:date=>Sat,03Sep2014},{:foo5=>5,:date=>Sat,02Sep2014}]如果:date相同,我想合并哈希值。我对上面数组的期望是:[{:foo=>2,:foo3=>3,:date=>Sat,01Sep2014},{:foo2=>2,:foo5=>5:date=>Sat,02Sep2014},{:foo4=>4,:dat
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我有一个包含多个键的散列和一个字符串,该字符串不包含散列中的任何键或包含一个键。h={"k1"=>"v1","k2"=>"v2","k3"=>"v3"}s="thisisanexamplestringthatmightoccurwithakeysomewhereinthestringk1(withspecialcharacterslike(^&*$#@!^&&*))"检查s是否包含h中的任何键的最佳方法是什么,如果包含,则返回它包含的键的值?例如,对于上面的h和s的例子,输出应该是v1。编辑:只有字符串是用户定义的。哈希将始终相同。 最佳答案