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

Ideas to speed up MIN/MAX/DISTINCT for prefixes of the PK

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Duplicate
    • None
    • None
    • None
    • None

    Description

      All of MIN, MAX, and DISTINCT always perform a full scan, even when they are on a prefix of a compound key.

      For MIN and MAX one only needs to find the first and last row (resp) and we'll have our answer. This works for the full key or a prefix of the key.
      This should work find with or without a WHERE clause, as long as we can identify the first and last row.

      For DISTINCT we could do a skip scan to the next prefix (only helps with a true prefix of a compound key).
      Say the key is (K1, K2), and say further that we're doing DISTINCT(K1). We can skip to the next value of K1 once we found a value. This should have a dramatic impact when the cardinality of K2 is high.
      With a WHERE clause that might itself be causing a SKIP SCAN, this might be quite tricky. Would need to think about it.

      Both of these statements hold equally when querying against an index.

      Anyway... Just filing this as an idea for now.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              larsh Lars Hofhansl
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: