Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-649 Useful indexes not used in UNION ALL
  3. DERBY-805

Push join predicates into union and other set operations. DERBY-649 implemented scalar (single table) predicate pushdown. Adding join predicate push down could improve performance significantly.

    XMLWordPrintableJSON

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 10.1.2.1, 10.2.1.6
    • Fix Version/s: 10.1.3.1, 10.2.1.6
    • Component/s: SQL
    • Labels:
      None
    • Environment:
      generic

      Description

      Fix for DERBY-649 implemented scalar (single table) predicate push down into UNIONs. While this improves performance for one set of queries, ability to push join-predicates further improves Derby performance by enabling use of indices where possible.

      For example,

      create view V1 as select i, j from T1 union all select i,j from T2;
      create view V2 as select a,b from T3 union all select a,b from T4;
      insert into T1 values (1,1), (2,2), (3,3), (4,4), (5,5);

      For a query like

      select * from V1, V2 where V1.j = V2.b and V1.i =1;

      If the join order choosen is V1,V2, V1 can use index on V1.i (if present) following fix for DERBY-649. But if there is a index on V2.b also, Derby currently can't use that index. By pushing join predicate, Derby would be able to use the index and improve performance. Some of the queries I have seen (not the one shown here...) could improve from 70-120 seconds to about one second.

      Note there is a good comment by Jeff Lichtman about join-predicate push down. I am copying parts of it here for completeness of this report: (Modified)

      If predicate push down is done during optimization, it would be possible to push joins into the union as long as it's in the right place in the join order.

      For example:

      create view v as select * from t1 union all select * from t2;

      select * from v, t3 where v.c1 = t3.c2;

      In this select, if t3 is the outer table then the qualification could be pushed into the union and optimized there, but if t3 is the inner table the qualification can't be pushed into the union.

      If the pushing is done at preprocess time (i.e. before optimization) it is impossible to know whether a join qualification like this can be safely pushed.

      There's a comment in UnionNode.optimizeIt() saying:

      /* RESOLVE - don't try to push predicated through for now */

      This is where I'd expect to see something for pushing predicates into the union during optimization.

      BTW, the business of pushing and pulling predicates during optimization can be hard to understand and debug, so maybe it's best to only handle the simple cases and do it during preprocessing.

        Attachments

        1. test_805.htm
          23 kB
          Manjula Kutty
        2. predPushdown_testFix.patch
          3 kB
          A B
        3. phase2_javadocFix.patch
          0.6 kB
          A B
        4. DERBY-805.html
          106 kB
          A B
        5. DERBY-805_v5.html
          161 kB
          A B
        6. DERBY-805_v4.html
          160 kB
          A B
        7. DERBY-805_v3.html
          133 kB
          A B
        8. DERBY-805_v2.html
          121 kB
          A B
        9. d805_phase4_v2.patch
          194 kB
          A B
        10. d805_phase4_v1.stat
          1.0 kB
          A B
        11. d805_phase4_v1.patch
          194 kB
          A B
        12. d805_phase3_v1.stat
          1 kB
          A B
        13. d805_phase3_v1.patch
          410 kB
          A B
        14. d805_phase2_v1.stat
          0.3 kB
          A B
        15. d805_phase2_v1.patch
          28 kB
          A B
        16. d805_phase1_v3.stat
          0.6 kB
          A B
        17. d805_phase1_v3.patch
          21 kB
          A B
        18. d805_phase1_v2.stat
          0.5 kB
          A B
        19. d805_phase1_v2.patch
          11 kB
          A B
        20. d805_phase1_v1.stat
          0.2 kB
          A B
        21. d805_phase1_v1.patch
          11 kB
          A B
        22. d805_followup_v1.patch
          21 kB
          A B
        23. d805_1007_1073_portTo10_1.stat
          3 kB
          A B
        24. d805_1007_1073_portTo10_1.patch
          558 kB
          A B

          Issue Links

            Activity

              People

              • Assignee:
                army A B
                Reporter:
                bandaram Satheesh E. Bandaram
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: