ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Random results from SQL UDF (something in cache?)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random results from SQL UDF (something in cache?)

    We have a situation where the same program accessing the same data provides results that differ. The problem occurs when the underlying data changes. It seems that the process fails to recognize the change in data, and reverts back to a previous results set. The hierarchy of programs is:

    a. an RPG ILE program using CGIDEV2 to display a web page

    b. calls an SQL UDF

    c. which in turn calls an ILE function called GetCutExpectedDate

    The GetCutExpectedDate is included in a results set that is generated by the SQL UDF. The SQL UDF passes off it's results to the RPG ILE pgm.

    We know the GetCutExpectedDate returns the right date because

    a. we observed this with debug

    b. we also invoke the GetCutExpectedDate function directly in the RPG ILE program (for other purposes) and it returns the correct date

    We also debugged inside the SQL UDF, and confirmed that it too is returning the right date as output. But when we debugged what was being returned to the RPG ILE, we see that the SQL UDF is not returning the same data that we saw when we debugged within the SQL UDF. The date is returned as a column to the RPG ILE, and it is also used as an "order by" in order to sort the data being returned

    We have temporarily fixed the problem by eliminating the use of the SQL UDF within the SQL that is found in the RPG ILE pgm. Instead, we replicate the process that takes place within the ILE function within the SQL statement that is inside the RPG ILE program (essentially duplicating the logic so that we now have 2 source codes to maintain if we want to make a change)

    Another interesting point is that if I copy and paste the URL for the web page from one browser to another, and sign on as the same user, I get the same bad results. But if I sign on to the second browser session as a different user, it provides refreshed/accurate data. Where si the data being cached?

    Note that the SQL UDF was originally defined as DETERMINISTIC, but we changed this to NON_DETERMINISTIC (thinking we had solved the problem). But after all, this was not the case. Or perhaps it is simply that cached somewhere is a version of the SQL UDF that does have the correction for the change to NON_DETERMINISTIC?

  • #2
    It is NOT NON_DETERMINISTICT but NOT DETERMINISTIC!
    Could this be the problem?
    NON_DETERMINISTIC is simply ignored?

    Birgitta

    Comment


    • #3
      Maybe you need to use a different isolation level.

      Comparison of isolation levels

      Comment


      • #4
        Hi

        1. The typo in deterministic was a typo in the posting to this forum, not in the UDF

        2. We use NC for isolation level, which is pretty much non-=restrictive as I understand it, so I don't think that is the problem

        It seems like the recent change we made to treat the UDF as NOT DETERMINISTIC is being ignored on a seemingly random basis

        Brad

        Comment

        Working...
        X