Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#1071 XQueryCompiler and StaticQueryContext are not reusable

v9.2
closed
Michael Kay
6
2012-10-08
2010-05-28
Michael Kay
No

Whether compilation of a query is initiated using the s9api XQueryCompiler, or the lower-level StaticQueryContext object, it is not safe to reuse the XQueryCompiler or StaticQueryContext to compile more than one query - except possibly in the special case where the queries compiled the first time it is used are never executed after it has been reused.

I've been desk-checking the code in this area, and looking at the tests in the test suite, and I think that pending further investigation, it's probably best to recommend creating a new XQueryCompiler for each query that is compiled. The documentation states that this isn't necessary, and indeed that you can change the settings on the XQueryCompiler between one compilation and the next, and there is a lot of code whose only purpose is to make this possible, but I'm not 100% convinced that it's safe.

Applies to 9.2 and all known earlier releases.

(In particular - and this is largely for my reference - the XQueryCompiler owns a StaticQueryContext, and the StaticQueryContext owns an Executable, and the Executable is updated with information specific to an individual query, such as the required parameters and the list of available collations. I can't see how the default collation would become null, but the code does look wrong.)

A fix will be produced later; in the meantime, please avoid reusing the XQueryCompiler or StaticQueryContext.

Discussion

  • Michael Kay
    Michael Kay
    2010-05-28

    Raising the priority a notch just so it stands out as not having a fix available yet.

     
  • Michael Kay
    Michael Kay
    2010-06-02

    A patch for this has now been produced and is about to be committed to Subversion. It's a rather more extensive change than most patches, and is not without risk, though it has also been more thoroughly tested than most patches. The effect is that each query compiled using an XQueryCompiler (or StaticQueryContext) now has its own Executable, rather than sharing the same Executable with other queries that were compiled using the same compiler. This caused some problems with the new facility for separately compiled XQuery library modules, where the design relied on the Executable being shared. However, it has been reworked so each unit of compilation results in one Executable, and this appears to work OK. (However, separate compilation is a new feature in 9.2, so there are not a large number of tests.)

     
  • Michael Kay
    Michael Kay
    2010-08-09

    Fixed in 9.2.1.2