2011/11/15

[轉載] Index Scan vs Seek in SQL Server


FAQ : Index Scan Vs Seek in SQL Server

There are five logical/physical operators in SQL Server related to Index scan ,Index Seek and Table scan. 


(a) Table Scan

(b) Clustered Index Scan

(c) Clustered Index Seek

(d) Index Scan (Non- Clustered index Seek)

(e) Index Seek (Non- Clustered index Seek)


Table Scan 

Table Scan retrieves all rows from the table (if you have no WHERE Conditions). Basically, before returning the rows, it traverse through all data pages related to the table. If you have where condition, though it travel through all the pages only those rows are returned which satisfy the conditions. When you do not have Clustered index on the table it does a table scan. In other words, both Clustered Index Scan (clustered index is nothing but the data itself) and Table Scan are same because in both method system traverse through all the data pages. Generally, you should avoid table scan.


Clustered Index Scan

Clustered Index Scan is nothing but horizontally traversing though the clustered index data pages. Clustered Index Scan return all the rows from the clustered index (Clustered index is nothing but Data). If you have where condition , only the satisfying rows are returned, but system traverse through all the data pages of the clustered index. Both Table scan and Clustered Index Scan are generally considered to be bad. But at times like if the table is small contains only few rows table or clustered index scan may be good also


Clustered Index Seek

Clustered Index Seek traverse vertically right down to the Data page where the requested data is stored. Basically any seek is vertically traversing though the B-Tree structure (as we all know the index is stored in B-tree structure in sql server). System does a Seek when it find a useful index and generally its done for highly selective query.


Index Scan or Non-Clustered Index Scan

As already said, Scan is horizontal traversing of B-Tree data pages. But in this case it horizontally traverse though the Non-Clustered index available. Its not same as Clustered index scan or Table Scan. In SQL Server , while reading execution plan you can find only Index Scan not Non-Clustered Index Scan. But you must read Index Scan as Non-Clustered Index Scan.


Index Seek or Non-Clustered Index Seek

As already mentioned Seek is Vertical traversing of B-Tree to the data page. But in Index seek it vertical traversing of Non-Clustered Index. Generally, its considered as the best option for high selective query.


2011/11/09

BB 第廿週 結構檢查

免去了千六元在私家醫生的檢查下, 在政府醫院的檢查始終因為人數眾多, 素質自然下降. 尤其因內地產婦人數驚人, 害得許多有經驗的醫生也捱不了沉重的工作量下大量流失. 取而代之便是沒有或淺經驗的年輕醫生及助產士值班, 而且也是因為醫護人員不斷減少下, 排症輪候的時間也長了.

原先預約了十時診症作超聲波的結構性檢查, 但等多了差不多半小時才開始. 入到超音波室, 當值年輕的女醫生劈頭一句, 現在不要問問題, 隨後會另有醫生解釋給你聽, 我們唯有忍著, 短短的五分鐘中, 醫生不斷看但只不斷喃喃自語, 我們根本聽不到她說甚麽, 看她將那掃瞄器推上推下, 看似尋找甚麽, 但有沒甚發現, 因為太太關心較早前驗到的肌瘤會否影響產道, 最後還是開口問了. 那醫生極不願意下再作檢查, 推了幾推掃瞄器, 又說找不到肌瘤, 瞎猜胎盤大了可能拉開了而看不見, 總是說不影響...云云, 見著她的技術, 我們也不再追問了.

再見醫生時, 又是年輕的女醫生 , 像依書直說地交代檢查正常, 迴避太太那肌瘤問題, 但太太苦纏下得到三十七周時可再做一次超音波檢查會否影響順產....最後, 等下一次預約的日期後便打道回府.

---------------------------------------------------------------------

過了數月後, 據聞現在公立醫院因人手不足而取消了結構性檢查, 除非一些高齡產婦或曾流產的產婦外, 有需要的要自費出外找私家醫生做.

2011/11/08

「Pancake 仔」的由來



BB出世了四個多月後, 終於重拾寫Blog的動力, 因為想兒子將來可以看到老爸的文章, 令他對他的成長有多一份回憶.

星期日到教會時, 其中一位母親向我追問「Pancake仔」為何不是叫「Hotcake仔」. 我其實也沒有大關係, 反正這就是他了. 但對於其他人問到, 我還是樂意解說一下.

事緣因為當我知道太太懷了BB後, 到了差不多二十多週, 開始做一些所謂胎教時, 也不知怎樣稱呼「他」. 其後, 他母親的飲食也些改變了, 開始對某大美資快餐店的熱香餅狂熱起來, 幾乎每天早上也嚷著要吃, 但從前的她對此是沒有興趣的, 甚至有時因為過了早餐時間買不到而會向我生氣, 及後甚至買了材料自己整pancake. 所以推斷好像是肚裡的他想吃. 想起那不如用這個「Pancake仔」來稱呼他吧, 反正聽起了也挺可愛吧! 後來他對這個暱稱也喜愛, 當呼叫這個名時, 在媽媽肚裡的他也會有回應的.

但隨著他出世後, 起了名字後, 我也少了這樣稱呼他.

The Pillars of The Earth 玩後感


取名同名小說改編的, 我雖然沒有看過, 但吸引我買的原因主要因為版圖的畫風華麗, 而且有很多meeples 再配合原作故事的大教堂. 據說外形是取材於法國的聖母院.


上週第一次PoE玩board 版 + expansion(6人版) , 先前玩了幾次大概熟悉遊戲流程, 玩bsw版本己經覺得此game混合stone age及caylus的元素, 另加入了抽master builder 機制的隨機性. 但此機制劣勝於好. start player 作用主要只是在選工人上有優勢, 但對抽master builder沒有太大作用, 最多有只是重抽一次. 尤其是在遊戲後段, 重要的工匠咭極度罕有, 所擁有的金錢已足夠有餘, 雖然付出多一元, 但先抽出來的builder先行動的優勢下絕對可以彌補多花一元的代價, 而後抽出來的已沒有太多選擇, 所以少付錢未能平衡那個隨機性, 導致未能有策略的安排工作.

但到昨晚自己帶了5人版, 還是有很多細節規則不熟悉. 開始時由我作start player介紹遊戲, 基本流程是沒有問題, 但到了某些card 與該回合的event 出現時便有些矛盾. 例如privilege card中的Archbishop Thomas, 用作可以免去下週event帶來的影響. 但同一回合的event卻是取消下回合privilege card的效果. 這些細節之前玩時沒有遇到. 而且今次每人有大灑金錢去買工匠咭, 而且沒有省錢或送錢的privilege card, 加上幾乎每個event 也是負面影響. 幾次抽master builder 也排到最後, 辛苦經營下只能以石頭為主去取分.



以下是一些規則容易玩錯或遺留的: 



1.      當錢不夠付的時候, 以每1分換作2, 若欠單數的金額則round down處理, 即是若欠3元的話只需扣1
2.      當選擇2號的建築師當選取資源時, 是取市場(12)的資源, 而不是取資源的supply
3.      黑色工人只在當其中一張privilege card生效後才歸入該玩家手視為自己的工人而直至遊戲結束
4.      黑色的建築師當被抽出使用時, 是免費使用的, 而且黑色的成本計不需減一.若直至擁有該玩家的建築師被抽出時, 才計算當時的成本, 同時黑色的建築師需要抽離遊戲. 若外starting player也可以決定重抽而將黑色建築師放回入袋.
5.      放置privilege card的位置, 玩前需要分開持續生效的一堆(A), 一次性及即時生效是另一堆(B). A堆放在4, B堆放在9c.
6.      9d的海岸市場, 只賣不能買, 但沒有限制數量
7.      若沒有Woodcutter, 是不能木材
8.      若沒有Stonecutter, 是不能石頭
9.      若沒有Mortar Mixer, Mason是不能獲取分數, 並非另一張Mortar Mixer. 但另有一張privilege card Sally 可以跳過此限制
10.  有其中一個event (Shiring lures away master builders for its own Cathedral!)是即時從start player開始, 移走一個已放置的建築師. 另一event (A newtown wall must be built to protect the Cathedral!)則是下一回合只有兩個建築師, 若有5-6人玩時, 則只放一個建築師入袋, 另一個則準備放在後置的builder strip, 視乎抽出的建築師所放置的先後次序再決定這個建築師的次序