Derby
  1. Derby
  2. DERBY-5989

Stop producing byte code for non-existent qualifiers

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 10.10.1.1
    • Fix Version/s: 10.10.1.1
    • Component/s: SQL
    • Labels:
      None

      Description

      For all result set nodes that have predicate lists, Derby's compiler lays out byte code for fields to hold qualifiers, and also code to reinitialize the values in those fields on every execution. It does this even if there are no qualifiers. See PredicateList.generateQualifiers(). That method does actually check whether there are qualifiers, and it skips some of the code generation if there are none. It should be changed so that it skips all the code generation if there are no qualifiers.

      For an example, see the decompiled generated class for a natural join attached to DERBY-5947: https://issues.apache.org/jira/secure/attachment/12549514/natural-join-after-3a.txt

      That class contains three Qualifier[][] fields:

      private Qualifier[][] e1;
      private Qualifier[][] e3;
      private Qualifier[][] e4;

      Only one of them (e4) is ever set to a non-null value. Still, the reinit() method, which is called on every execution, has code for each of the fields:

      protected void reinit() throws StandardException

      { BaseActivation.reinitializeQualifiers(e1); BaseActivation.reinitializeQualifiers(e3); BaseActivation.reinitializeQualifiers(e4); }
      1. after.txt
        2 kB
        Knut Anders Hatlen
      2. before.txt
        2 kB
        Knut Anders Hatlen
      3. d5989-1a-no-whitespace.diff
        2 kB
        Knut Anders Hatlen
      4. d5989-1a.diff
        4 kB
        Knut Anders Hatlen

        Activity

        Hide
        Knut Anders Hatlen added a comment -

        Attaching a patch, d5989-1a.diff, that makes PredicateList.generateQualifier() return immediately and just lay out code for pushing null onto the stack if there are no qualifiers in the predicate list. Before, it would create a field that was always null, add code to reset the field on each execution, and push the field value (always null) onto the stack. The end result should be the same, just with less code.

        Most of the changes in the patch are whitespace changes because some conditionals could be removed, and the body of the original if statements had to be reindented. To make it easier to see exactly what was changed, I've attached d5989-1a-no-whitespace.diff which was produced by passing flags that told svn diff to ignore whitespace changes.

        I've also attached before.txt and after.txt which show the decompiled class files for "SELECT * FROM SYSIBM.SYSDUMMY1" before and after the patch. After the patch, the e1 field and the reinit() method are not in the generated class. Also, references to the e1 field have been replaced with null.

        All the regression tests ran cleanly with the patch.

        Show
        Knut Anders Hatlen added a comment - Attaching a patch, d5989-1a.diff, that makes PredicateList.generateQualifier() return immediately and just lay out code for pushing null onto the stack if there are no qualifiers in the predicate list. Before, it would create a field that was always null, add code to reset the field on each execution, and push the field value (always null) onto the stack. The end result should be the same, just with less code. Most of the changes in the patch are whitespace changes because some conditionals could be removed, and the body of the original if statements had to be reindented. To make it easier to see exactly what was changed, I've attached d5989-1a-no-whitespace.diff which was produced by passing flags that told svn diff to ignore whitespace changes. I've also attached before.txt and after.txt which show the decompiled class files for "SELECT * FROM SYSIBM.SYSDUMMY1" before and after the patch. After the patch, the e1 field and the reinit() method are not in the generated class. Also, references to the e1 field have been replaced with null. All the regression tests ran cleanly with the patch.
        Hide
        Knut Anders Hatlen added a comment -

        Committed revision 1409120.

        Show
        Knut Anders Hatlen added a comment - Committed revision 1409120.

          People

          • Assignee:
            Knut Anders Hatlen
            Reporter:
            Knut Anders Hatlen
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development