The 12.0.1 Help on Plan caching says "The plan cache is a per-connection cache of the data structures used to execute an access plan." However, observed behavior would indicate that "per-connection" may not apply when the separate connections are different invocations of the same web service... that a Very Bad Plan cached for a Query From Hell inside a web service stored procedure can persist (for a while, long enough to confuse(1) the observer :) across multiple invocations of the web service. I suspect the details are complex and hard to explain for us Deltas (ok, Gammas :) but any attempt to do so would be welcome! Footnote (1): An example of "confuse the observer" is "How come the new clustered index makes my plan look a million times faster in the ISQL Plan Viewer, but my web service is still running slow? ...no, wait, NOW it's faster, after running it fifty times!" In a comment on his answer to a related question Mark Culp wrote this: "We have discussed (and have experimented with) cross connection plan caching but it is hard to get it right so this feature has not (yet) made it into the released product." |
If I remember correctly in SA 12 we introduced connection pooling for web service requests. This means that the database connection is put back into a pool when the web service request completes. If a new web service request arrives for the database within a short period of time (30 seconds I think) then the database connection will be pulled out of the pool and used to handle the request. This pooling technique saves the time to create and tear down the database connection ... but the new web service request must still go through the same parsing, mapping, and authentication process. Now here's the rub: to ensure that there is no leakage of information from one request to the next, when a connection goes into the pool the connection is "cleaned" by closing all cursors, dropping all temp tables and connection variables, and a few other things (that I can't remember right now). Net result is that the plan cache is I say "normal" web requests because if you are using HTTP sessions then everything that I have said above does not apply. When you use HTTP sessions the database connection used to handle the web request is maintained completely intact between web requests - the connection is associated with the HTTP session and will only be used to handle requests associated with the session and therefore there is no concern about information leakage between requests (since that is exactly why you would use sessions - to keep information on the connection between requests) and therefore the no cleaning is performed. So how do you solve the "I have a bad cached plan; how do I get rid of it?"? You have two methods:
The first solution is likely easiest to do on a running system. HTH
Obviously you happen to work on the next few releases, so what us users call a new version is rather old in the developer's view:)
(06 Oct '11, 02:41)
Volker Barth
Replies hidden
As an answer to the question http://sqlanywhere-forum.sap.com/questions/782/connection-pooling-and-connection-parameters it is said, that the complete connection string must match for a pooled connection to be reused. This means that also the AppInfo parameter is considered which can already be different if the calling thread is not the same. Which can not be quaranteed if called from inside a webservice.
(06 Oct '11, 05:36)
Martin
Replies hidden
@Mark: Sadly, in this case, the HTTP SessionID option is not being used, so the observed behaviour (a Very Bad Plan being used) must have some other explanation... and (sigh) a more difficult solution because the engine must be picking the Very Bad Plan all on its own. This is confirmed by setting max_plans_cached = 0 having no effect, and neither does OPTION ( FORCE OPTIMIZATION ). Alas, although procedure profiling points directly to the Query From Hell, Database Tracing seems to ignore it most of the time; i.e., the Query From Hell will be executed a dozen times but only show up once in the tracing database... or not at all. So I'm on my own using dbisql and copy and paste to get the Graphical Plan... but at least procedure profiling found the query for me, for that I am grateful. This ... stuff ... takes ... so ... long ... to ... do :)
(06 Oct '11, 06:42)
Breck Carter
Replies hidden
Ah yes, it was too long ago!
(06 Oct '11, 09:04)
Mark Culp
The question that you refer to is talking about connection pooling when connecting via a client using traditional TCP/IP connection (i.e. dblib, odbc, ado.net, etc). This question is asking about web services connections which is done via HTTP or HTTPS. The pools used in each are different and have different behaviour.
(06 Oct '11, 09:07)
Mark Culp
Yes, I did not remember the full story... I will revise my answer.
(06 Oct '11, 09:08)
Mark Culp
|
I added the "insistent-question" tag for that matter - though apparently not that successful...and references to Alpha Pluses don't seem to help, either(: