Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-6663

SQL: optimize primary key equality lookup

    Details

    • Type: Task
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.4
    • Component/s: sql
    • Labels:

      Description

      H2 perform every index search through BaseIndex.find method. It contains both first and last rows. If condition looks like attr = ?, then both bounds are the same. When this call is propagated to our BPlusTree, then two index lookups occur:

      • Lower bound: BPlusTree#findInsertionPoint
      • Upper bound: BPlusTree.ForwardCursor#findUpperBound

      This is done for a reason because we do not know in advance how many elements are in between the bounds, so one lookup + scan is not an option in general case. But in case of PK lookup with equality condition, when we know in advance that only one row will be returned, this leads to additional unnecessary comparisons.

      Suggested fix:
      1) Make sure that all rows in GridH2PlainRowFactory has correct equals implementation.
      2) Inside H2TreeIndex#find: if this is PK index (see constructor args) and lower.equals(upper), then use BPlusTree.findOne instead of BPlusTree.find.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kirill.shirokov Kirill Shirokov
                Reporter:
                vozerov Vladimir Ozerov
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: