6 Replies Latest reply: Oct 5, 2006 9:32 AM by 525995 RSS

    Precompiled query expressions

    525995
      I've got an XmlQueryExpression that I cache in java.util.Map and reuse.

      About the 4th execution of this causes a crash (ie process stops completely) with:

      "Invalid access of stack red zone b1c2afec eip=1ff22d2b"

      The query is this (ie is a call of a function defined in an xquery module):

      import module namespace mod4 = urn:mod4' at 'mod4.xquery';
      declare namespace tq = 'urn:tq';
      mod4:includesRole($serviceFqn, $aboveRole, $belowRole)

      I noticed a while back that a QueryContext must be supplied when a query is compiled, yet a different one can be supplied when it is executed.
        • 1. Re: Precompiled query expressions
          525995
          Oops, the question somehow got cut off.

          So the question is, are there any particular rules one ought to be aware of when creating and re-using precompiled query expressions? My suspicion is that something about the query expression is leading to the crash (which I can't trace into in my environment).

          Jacoby
          • 2. Re: Precompiled query expressions
            525744
            So the question is, are there any particular rules one ought to be aware of when creating and
            re-using precompiled query expressions? My suspicion is that something about the
            query expression is leading to the crash (which I can't trace into in my environment).
            Not that I am aware of. If you can, post the code here that is causing your crash.

            - Danny
            • 3. Re: Precompiled query expressions
              Gmfeinberg-Oracle
              Jacoby,

              Be careful of recursive xquery functions in your modules. They can easily
              run off the stack.

              Reusing precompiled query expressions is a good thing, and there are no known
              problems in that area.

              Regards,

              George
              • 4. Re: Precompiled query expressions
                525995
                You are exactly right. Given certain data, my recursive XQuery function went potty.

                Thanks George.
                • 5. Re: Precompiled query expressions
                  Gmfeinberg-Oracle
                  Jacoby,

                  We've got a todo item to limit recursion in xquery functions...

                  George
                  • 6. Re: Precompiled query expressions
                    525995
                    This one played out rather interesting.

                    I found my bug which led to the recursion stack overflow. But I cd reproduce it in Sleepycat XQuery only (not Saxon 8).

                    I had this in a FLOWR expression:

                    let $link := $roleData/tq:link[@above eq $aboveRole/@fqn][starts-with( $folder, @folder)]

                    which was returning tq:link nodes for which the [starts-with(...)] was patently false (and which went on to cause the recursion overflow). My own feeling is, that is incorrect behaviour (see below tho').

                    Expressing it like this:

                    let $link := $roleData/tq:link[@above eq $aboveRole/@fqn and starts-with( $folder, @folder)]

                    removed the problem.

                    This is bound to be me misunderstanding xpath, really, but comments are very welcome. I suppose I've never really twigged the difference between chained predicates and the boolean 'and' operator.

                    Incidentally - I only just discovered you can use the trace() function to help debug Sleepycat XQuery from (in my case) Oxygen XML Editor. Nice feature - if you've not discovered this, try it.