Whisht Wind


« 十二月 2009
星期日星期一星期二星期三星期四星期五星期六
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
今天

Subscribe

Add to My YahooSubscribe in RojoSubscribe in NewsGator OnlineThis blog's XML feed
Subscribe with BloglinesAdd to Google

Search this blog

Blog Roll

Downloads

Other Links

Popular Tags

addons android archive autoloading autopager china chinese cisco dhcp dict earthquake firefox flock fonts foxbeans hgweb j2me java javame jstardict jstardictm language mercurial milax moon mozilla mtu nb-xul netbeans openoffice opensolaris pack palette recommended solaris stardict tar.gz tar.gz2 vpn vpnclient windows wine xul zip 嫦娥 郑萍如 面板

Weblog menu

Feeds

Recent Entries

Today's referrers

今日点击: 2108

Locations of visitors to this page

20070424 星期二 2007年04月24日

a strang derby optimize

There is table MyTable, it has a primary key generatedId defined as:generatedId integer not null generated always as identity
Here are two sql queries:
1. select min(generatedId),max(generatedId),max(generatedId) - min(generatedId) from MyTable

2. select minId,maxId, maxId - minId from
            (select min(generatedId) minId from MyTable)  minT ,
             (select max(generatedId) maxId from MyTable) maxT

They will return the same result, but could you guess which one has the better performance?

It's the second one. When the table has 1296607 row, the times for the first sql is 43.8s.
But second sql will finished in 8s.
I try select min(generatedId),max(generatedId) from MyTable then. It needs nearly 43s too.  And then  select  count(*) from MyTable finished in less then 40s.

So what does this mean?
I guess derby optimize select min(generatedId) minId from MyTable and select max(generatedId) minId from MyTable but not optimize sql queries like select min(generatedId),max(generatedId) from MyTable.




Technorati Tags: ,

( 2007年04月24日, 04:02:01 下午 CST ) [Listen] Permalink 评论 [1]

Share and enjoy:  Bookmark it with Blinklist Submit to Bloglines Bookmark it with Blogmarks Track with co.mments Bookmark it with Del.icio.us Submit it to Digg Submit it to Fark Bookmark it with Furl Bookmark it with Ma.gnolia Bookmark it with Maple Bookmark it at NewsVine Bookmark it at reddit.com Bookmark it at Simpy.com Bookmark it with Spurl Submit it to slashdot Track with TailRank See who links to it via Technorati Bookmark it with wists

评论:

I'm amazed it's taking that long in the first place. If the table is indexed then MIN() and MAX() should run in constant time.

发表于 空っぽ 在 2008年02月08日, 06:45 上午 CST #

发表一条评论:
  • HTML语法: 禁用