2014年3月31日 星期一

[T-SQL] WITH (NOLOCK): 提升查詢效率和避免LOCK發生



加了WITH (NOLOCK)即告訴SQL Server,我們的這段SELECT指令
無需去考慮目前table的transaction lock狀態,因此效能上會有明顯的提升,
而且資料庫系統的Lock現象會有明顯的減少(包含Dead Lock)。

有一點要特別注意,因為WITH (NOLOCK)不考慮目前table的transaction lock,
因此當有某些資料正處於多個phase交易(例如跨多個table的transaction交易-->如提款系統),
WITH (NOLOCK)會讓目前處理交易process的資料被乎略…

講白話一點,也就是說當使用NoLock時,它允許閱讀那些已經修改但是還沒有交易完成的資料。
因此如果有需要考量transaction交易資料的即時完整性時,使用WITH (NOLOCK)就要好好考慮一下。

如果不需考量transaction,WITH (NOLOCK)或許是個好用的參考




2014年3月26日 星期三

UrlEncode & UrlDecode in ASP.NET

From : http://www.dotblogs.com.tw/alonstar/archive/2010/01/04/12778.aspx


前陣子還看到蠻常有人在問這二個問題的,結果發現自己習慣用的和別人不太一樣:我比較常用Server.UrlEncode,不過有些人習慣的是HttpUtility.UrlEncode;這二個差別可以從程式碼看得出來…
HttpServerUtility的預設編碼模式是從Response截取,而HttpUtility則是預設UTF8,我們通常都用UTF8編碼,所以沒什麼差;如果不是利用UTF8編碼的時候,使用上就要小心一點。
01//Server.UrlEncode
02public sealed class HttpServerUtility
03{
04 
05    public string UrlEncode(string s)
06    {
07        Encoding e = (this._context != null) ? this._context.Response.ContentEncoding : Encoding.UTF8;
08        return HttpUtility.UrlEncode(s, e);
09    }
10 
11    public string UrlDecode(string s)
12    {
13        Encoding e = (this._context != null) ? this._context.Request.ContentEncoding : Encoding.UTF8;
14        return HttpUtility.UrlDecode(s, e);
15    }
16 
17}
18 
19//HttpUtility.UrlEncode
20public sealed class HttpUtility
21{
22    public static string UrlEncode(string str)
23    {
24        if (str == null)
25        {
26            return null;
27        }
28        return UrlEncode(str, Encoding.UTF8);
29    }
30     
31    public static string UrlDecode(string str)
32    {
33        if (str == null)
34        {
35            return null;
36        }
37        return UrlDecode(str, Encoding.UTF8);
38    }
39  
40}
 

MangoHost Copyright © 2009 Cookiez is Designed by Ipietoon for Free Blogger Template