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

Incorrect comparator in QueryOptimizer may cause IllegalArgumentException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 4.8.0
    • None
    • None
    • None

    Description

      The problem code is in QueryOptimizer#orderPlansBestToWorst
      When we have a lot of local similar indexes, all of them comes to the array of best candidates. After that we try to sort them using our own Comparator. In the compare we check first:
      1. bound pk columns count
      2. groupBy order
      3. number of columns
      for two local indexes on different columns first 3 steps always passed (since they are equal)
      And now we execute the following checks:

                      // If all things are equal, don't choose local index as it forces scan
                      // on every region (unless there's no start/stop key)
                      if (table1.getIndexType() == IndexType.LOCAL) {
                          return plan1.getContext().getScanRanges().getRanges().isEmpty() ? -1 : 1;
                      }
                      if (table2.getIndexType() == IndexType.LOCAL) {
                          return plan2.getContext().getScanRanges().getRanges().isEmpty() ? 1 : -1;
                      }
      
      

      obvious that for similar two plans with similar scan ranges compare (plan1, plan2) and compare(plan2, plan1) will return the same result (1 if ranges are not empty, -1 otherwise). This may cause following exception from Collections.sort :

      	at java.util.TimSort.mergeLo(TimSort.java:777)
      	at java.util.TimSort.mergeAt(TimSort.java:514)Listening for transport 	at java.util.TimSort.mergeCollapse(TimSort.java:441)
      	at java.util.TimSort.sort(TimSort.java:245)
      	at java.util.Arrays.sort(Arrays.java:1512)
      	at java.util.ArrayList.sort(ArrayList.java:1454)
      	at java.util.Collections.sort(Collections.java:175)
      

      I would suggest to add a check that if both plans are local indexes, then consider them equal, otherwise execute the check. jamestaylor, ram_krish any thoughts?

      ankit@apache.org FYI

      Attachments

        1. PHOENIX-3152.patch
          4 kB
          Sergey Soldatov
        2. PHOENIX-3152.sql
          11 kB
          Sergey Soldatov

        Activity

          People

            sergey.soldatov Sergey Soldatov
            sergey.soldatov Sergey Soldatov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: