簡體   English   中英

速度問題在SQLCE數據庫中提取數千行

[英]Speed issues fetching Thousands of rows in a SQLCE database

首先快速免責聲明:關於數據庫,我是一個完全菜鳥。 我知道如何構成一個SQL查詢,並且...好吧,差不多了-我認為這樣就足夠了。 性能優化將在稍后發布。

“后來”到了。 我需要你的幫助。

我正在對新聞文章進行NLP處理。 文章取自Internet並存儲在數據庫中。 用戶給了我一個輸入時期來進行分析,我提出了這個時期內的所有文章,對其進行了分析並顯示了一些圖表作為回報。 我目前對此還比較幼稚-我不限制返回的文章數量。 每天大約250篇文章* 6個月是45,000條記錄,數量相當可觀。

我的讀取性能中等。 我正在使用C#+ SQLCE(最簡單的數據庫開始,沒有設置成本)。 我嘗試索引數據庫無濟於事。 我懷疑問題來自於

  • 在一個查詢中要查詢這么多數據。
  • 使用SQLCE

我完全瘋狂地嘗試一次調用就獲取數千條記錄嗎? SQLCE是一個愚蠢的選擇嗎? 我基本上需要有關此的實用建議。 另外,如果您可以為我提供解決我的問題的替代方案,那就更好了。

您的幫助對我很有價值-預先感謝!

編輯 -以下是我用來獲取文章的命令:

using (SqlCeCommand com1 = new SqlCeCommand(mySqlRequestString, myConnectionString))
        {
            SqlCeResultSet res = com1.ExecuteResultSet(ResultSetOptions.Scrollable);
            if (res.HasRows)
            {
                //Use the get ordinal method so we don’t have to worry about remembering what order our SQL put the field names in.
                int ordGuid = res.GetOrdinal("Id"); int ordUrl = res.GetOrdinal("Url"); int ordPublicationDate = res.GetOrdinal("PublicationDate"); 
                int ordTitle = res.GetOrdinal("Title"); int ordContent = res.GetOrdinal("Content"); int ordSource = res.GetOrdinal("Source");
                int ordAuthor = res.GetOrdinal("Author"); int ordComputedKeywords = res.GetOrdinal("ComputedKeywords"); int ordComputedKeywordsDate = res.GetOrdinal("ComputedKeywordsDate"); 

                //Get all the Articles
                List<Article> articles = new List<Article>();
                if (res.ReadFirst())
                {
                    // Read the first record and get its data
                    res.ReadFirst();
                    Constants.Sources src = (Constants.Sources)Enum.Parse(typeof(Constants.Sources), res.GetString(ordSource));
                    string[] computedKeywords = res.IsDBNull(ordComputedKeywords)?new string[]{}: res.GetString(ordComputedKeywords).Split(',').ToArray();
                    DateTime computedKeywordsDate = res.IsDBNull(ordComputedKeywordsDate) ? new DateTime() : res.GetDateTime(ordComputedKeywordsDate);
                    articles.Add(new Article(res.GetGuid(ordGuid), new Uri(res.GetString(ordUrl)), res.GetDateTime(ordPublicationDate), res.GetString(ordTitle), res.GetString(ordContent), src, res.GetString(ordAuthor), computedKeywords, computedKeywordsDate));
                }
                // Read the remaining records
                while (res.Read())
                {
                    Constants.Sources src = (Constants.Sources)Enum.Parse(typeof(Constants.Sources), res.GetString(ordSource));
                    string[] computedKeywords = res.IsDBNull(ordComputedKeywords) ? new string[] { } : res.GetString(ordComputedKeywords).Split(',').ToArray();
                     DateTime computedKeywordsDate = res.IsDBNull(ordComputedKeywordsDate) ? new DateTime() : res.GetDateTime(ordComputedKeywordsDate);
                    articles.Add(new Article(res.GetGuid(ordGuid), new Uri(res.GetString(ordUrl)), res.GetDateTime(ordPublicationDate), res.GetString(ordTitle), res.GetString(ordContent), src, res.GetString(ordAuthor), computedKeywords, computedKeywordsDate));
                }
                return articles.ToArray();
            }
        }
  1. 您一次只能獲取一頁結果。
  2. SqlCE非常適合測試或使用率極低的應用程序,但是您應該真正考慮使用SQL Express或功能全面的SQL Server。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM