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

OrExpression should can also push non-leading pk columns to scan

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 4.13.0
    • 4.14.0
    • None
    • None

    Description

      Given following table:

          CREATE TABLE test_table (
           PK1 INTEGER NOT NULL,
           PK2 INTEGER NOT NULL,
           PK3 INTEGER NOT NULL,
           DATA INTEGER, 
           CONSTRAINT TEST_PK PRIMARY KEY (PK1,PK2,PK3))
      

      and a sql:

        select * from test_table t where (t.pk1 >=2 and t.pk1<5) and ((t.pk2 >= 4 and t.pk2 <6) or (t.pk2 >= 8 and t.pk2 <9))
      

      Obviously, it is a typical case for the sql to use SkipScanFilter,however, the sql actually does not use Skip Scan, it use Range Scan and just push the leading pk column expression (t.pk1 >=2 and t.pk1<5) to scan,the explain sql is :
       

         CLIENT PARALLEL 1-WAY RANGE SCAN OVER TEST_TABLE [2] - [5]
             SERVER FILTER BY ((PK2 >= 4 AND PK2 < 6) OR (PK2 >= 8 AND PK2 < 9))
      

       I think the problem is affected by the WhereOptimizer.KeyExpressionVisitor.orKeySlots method, in the following line 763, because the pk2 column is not the leading pk column,so this method return null, causing the expression
      ((t.pk2 >= 4 and t.pk2 <6) or (t.pk2 >= 8 and t.pk2 <9)) is not pushed to scan:

      757    boolean hasFirstSlot = true;
      758    boolean prevIsNull = false;
      759    // TODO: Do the same optimization that we do for IN if the childSlots specify a fully qualified row key
      760   for (KeySlot slot : childSlot) {
      761      if (hasFirstSlot) {
      762           // if the first slot is null, return null immediately
      763           if (slot == null) {
      764                return null;
      765            }
      766           // mark that we've handled the first slot
      767           hasFirstSlot = false;
      768      }
      

      For above WhereOptimizer.KeyExpressionVisitor.orKeySlots method, it seems that it is not necessary to make sure the PK Column in OrExpression is leading PK Column,just guarantee there is only one PK Column in OrExpression is enough.

       

      Attachments

        1. PHOENIX-4602_v2.patch
          20 kB
          chenglei

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: