English 中文(简体)
Query slow on first run but fast on subsequent calls - Subsonic 2.0
原标题:
  • 时间:2009-11-13 12:25:36
  •  标签:
  • subsonic

We ve come across an issue when we open our application and run a Subsonic Select the select takes a while to return data. Any subsequent calls to the same select run very quickly. The equivilent T-SQL also runs very quickly. It s as though SubSonic is caching something on the first connection and reusing this on subsequent connections. The queries run fast until we close the application and then open a new one, again the first run takes a while but all subsequent calls are fast.

Any ideas on this? Do we need to upgrade to a newer version?

I couldn t find any mention of this anywhere.

The app is a windows app although we have a similar issue with a web app. The query is a simple select with an inner join:

Dim status As New subsonicdal.Status("statusCode", "active")
Dim clientPreferencesDataSet As DataSet = New SubSonic.Select(subsonicdal.ClientPreference.ClientIdColumn, subsonicdal.ClientPreferenceType.AssetOrUnitColumn, subsonicdal.ClientPreferenceUsage.UsageTypeColumn) _
                                                                .From(subsonicdal.ClientPreference.Schema) _
                                                                .InnerJoin(subsonicdal.ClientPreferenceType.Schema) _
                                                                .InnerJoin(subsonicdal.ClientPreferenceUsage.Schema) _
                                                                .Where(subsonicdal.ClientPreference.ClientIdColumn).IsEqualTo(clientId) _
                                                                .And(subsonicdal.ClientPreference.StatusidColumn).IsEqualTo(status.Statusid).ExecuteDataSet()

Basically if I put a breakpoint on Dim clientPreferencesDataSet As DataSet line, execute the line it takes around 6 seconds. If I break on the line again it is immediate (under a second).

The ClientPreferences has foreign Integer keys to ClientPreferenceUsage & ClientPreferenceType there are around 70 records in ClientPreferences, 8 in ClientPreferenceUsage and 12 in ClientPreferenceType. Its a very simple structure. If I run the SQL that Subsonic generates in Mgt Studio it is immediate. I have tried InnerJoining the Status table, using strings for the fields returned but there is no difference.

问题回答

Two things come to mind:

  • Possibly the database connection is made at first use (lazy)
  • Or if it is a prepared query, after the first run, the execution plan is cached and subsequent calls will be faster

SubSonic doesn t cache anything - it just tries to execute whatever query you throw it. Is this a web app? If so (which you probably know) the load time is very slow at first.

The more detail you can offer the better - such as a test that pinpoints the load issue as well as your DB structure (if you can).





相关问题
Debugging SQL in ASP.NET

private void BuildGridView2() { GridView1.DataSource = new Select() .From("NewsReleases") .Where("RelMonth").IsEqualTo(this.ddlAward.SelectedValue) .And("RelYear").IsEqualTo(this....

SubSonic Error with MySql CONVERT()

I has encountered conversion from integer to string with MySql+SubSonic3 (it generates wrong SQL query). After I found root of the problem in SubSonic sources and fixed it, everything works fine, but ...

SubSonic OpenExpression/CloseExpression

Hey All! I m trying to construct a query that is something like this: Where column = "value" AND column2 = "value" AND (column3 = "value" OR column4 = "value") I have this code: return new Select() ...

Grouping with SubSonic 3

I have the following table "GroupPriority": Id Group Priority 1 1 0 2 2 0 3 3 0 4 2 1 5 1 1 6 2 2 7 ...

Subsonic Linq guid problem

The construtor Void .ctor(System.Guid, Int32) is not supported. this error occured with the following statements: var Test = from r in db.UserRoles join p in db.UserPermissions on new { r....

热门标签