|
biti_rainy's words remind me of an incident we had recently. One of our DBAs is very intelligent but does not have as much knowledge of Oracle as I. We were debugging some application code, generated by Oracle Designer. Imagine the complexity. The code works fine in current production. We exported and imported into another database, where one piece of code always raises the error that a column value does not fit into any partition. We used SQL trace to find that the value is missing or null (no wonder it doesn't fit in any partition). We spent quite a bit of time to find why it's null. The value is a package variable. Here's what we find. The table has multiple triggers of the same type (before insert). One trigger assigns a value to the package variable and another trigger picks it up. That DBA asked me if triggers' firing order is fixed in some order. I said "Absolutely not! It's completely random" because I know documentation says so and Tom Kyte says too. However, the code has been working since it was written about two years ago. Then the DBA said maybe the order is indeed fixed, perhaps by trigger creation time? We checked. Indeed the trigger that uses the package variable was created later and in the new database it was created slightly earlier by the import. So I did a small test, where each trigger writes a value to an external file (because the values in a heap table have no reliable order and the timestamps for the rows are exactly the same). Surprisinglyy, they *are* written in the *reverse* order of the trigger creation time! We then dropped and recreated the trigger that uses the variable and it works fine in the new database. But since documentation says we should not rely on trigger firing order (unless it's 11g and triggers have the new follows clause defined), we modify the code to include the variable assignment code into the trigger that uses the variable, although it seems the problem was already solved by creating the trigger later.
The moral of the story is not that the more knowledge the worse, but that sometimes we need to think out of the box in troubleshooting a problem. If we had insisted on Oracle's claim and hadn't even bothered to check the trigger creation time, we wouldn't have been able to find out why the old code works and new code does not.
Yong Huang
[ 本帖最后由 Yong Huang 于 2008-6-19 20:20 编辑 ] |
|