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

Support using Row Value Constructors in OFFSET clause for paging in tables where the sort order of PK columns varies

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Implemented
    • Affects Version/s: None
    • Fix Version/s: 5.1.0, 4.16.0
    • Component/s: None
    • Labels:

      Description

      RVCs along with the LIMIT clause are useful for efficiently paging through rows (see http://phoenix.apache.org/paged.html). This works well if the pk columns are sorted ascending, we can always use the > operator to query for the next batch of row.

      However if the PK of a table is (A  DESC, B DESC) we cannot use the following query to page through the data

      SELECT * FROM TABLE WHERE (A, B) > (?, ?) ORDER BY A DESC, B DESC LIMIT 20
      

      Since the rows are sorted by A desc and then by B descending we need change the comparison order

      SELECT * FROM TABLE WHERE (A, B) < (?, ?) ORDER BY A DESC, B DESC LIMIT 20
      

      If the PK of a table contains columns with mixed sort order for eg (A  DESC, B) then we cannot use RVC to page through data.

      If we supported using RVCs in the offset clause we could use the offset to set the start row of the scan. Clients would not have to have logic to determine the comparison operator. This would also support paging through data for tables where the PK columns are sorted in mixed order.

      SELECT * FROM TABLE ORDER BY A DESC, B LIMIT 20 OFFSET (?,?)
      

      We would only allow using the offset if the rows are ordered by the sort order of the PK columns of and Index or Primary Table.

      Note that there is some care is needed in the use of OFFSET with indexes.  If the OFFSET is coercible to multiple indexes/base table it could mean very different positions based on key.  To Handle This the INDEX hint needs to be used to specify an index offset for safety.

        Attachments

        1. PHOENIX-offset.txt
          3 kB
          Lars Hofhansl
        2. PHOENIX-4845-4.x-HBase-1.3.v3.patch
          133 kB
          Daniel Wong
        3. PHOENIX-4845-4.x-HBase-1.3.v2.patch
          133 kB
          Daniel Wong
        4. PHOENIX-4845-4.x-HBase-1.3.patch
          117 kB
          Daniel Wong
        5. PHOENIX-4845.patch
          133 kB
          Daniel Wong

          Issue Links

            Activity

              People

              • Assignee:
                dbwong Daniel Wong
                Reporter:
                tdsilva Thomas D'Silva
              • Votes:
                0 Vote for this issue
                Watchers:
                8 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 - 16h 10m
                  16h 10m