Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-4820

Optimize OrderBy for ClientAggregatePlan

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.14.0
    • 4.15.0, 5.1.0
    • None
    • None

    Description

      Given a table

        create table test ( 
             pk1 varchar not null , 
             pk2 varchar not null, 
             pk3 varchar not null,
              v1 varchar, 
              v2 varchar, 
              CONSTRAINT TEST_PK PRIMARY KEY ( 
                    pk1,
                    pk2,
                    pk3 ))
      

      for following sql :

           select a.ak3 
           from (select substr(pk1,1,1) ak1,substr(pk2,1,1) ak2,substr(pk3,1,1) ak3,substr(v1,1,1) av1,substr(v2,1,1) av2 from test order by pk2,pk3 limit 10) a  group by a.ak3,a.av1 order by a.ak3,a.av1
      

      Intuitively, the above OrderBy statement order by a.ak3,a.av1 should be compiled out because it match the group by statement, but in fact it is not.
      The problem is caused by the QueryCompiler.compileSingleQuery and QueryCompiler.compileSingleFlatQuery,for QueryCompiler.compileSingleQuery method,because the inner query has order by, so in line 520, local variable isInRowKeyOrder is false:

      519        context.setCurrentTable(tableRef);
      520        boolean isInRowKeyOrder = innerPlan.getGroupBy() == GroupBy.EMPTY_GROUP_BY && innerPlan.getOrderBy() == OrderBy.EMPTY_ORDER_BY;
      

      In QueryCompiler.compileSingleFlatQuery,when OrderByCompiler.compile method is invoked, the last parameter isInRowKeyOrder is false:

      562        OrderBy orderBy = OrderByCompiler.compile(context, select, groupBy, limit, offset, projector,
      563                groupBy == GroupBy.EMPTY_GROUP_BY ? innerPlanTupleProjector : null, isInRowKeyOrder);
      

      So in following line 156 for OrderByCompiler.compile,even though the tracker.isOrderPreserving is true, the OrderBy statement could not be compiled out.

      156       if (isInRowKeyOrder && tracker.isOrderPreserving()) {
      

      In my opinion, with GroupBy, in following line 563 for QueryCompiler.compileSingleFlatQuery method, when we call
      OrderByCompiler.compile method, we no need to conside the isInRowKeyOrder, just like the previous parameter tupleProjector does.

       562        OrderBy orderBy = OrderByCompiler.compile(context, select, groupBy, limit, offset, projector,
       563                groupBy == GroupBy.EMPTY_GROUP_BY ? innerPlanTupleProjector : null, isInRowKeyOrder);
      

      Attachments

        1. PHOENIX-4820_v4-4.x-HBase-1.3.patch
          63 kB
          chenglei
        2. PHOENIX-4820_v5-4.x-HBase-1.3.patch
          63 kB
          chenglei
        3. PHOENIX-4820.diff
          11 kB
          Thomas D'Silva
        4. PHOENIX-4820-4.x-HBase-1.3.patch
          51 kB
          chenglei

        Issue Links

          Activity

            People

              comnetwork chenglei
              comnetwork chenglei
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h