Skip to content
  • Steinar H. Gunderson's avatar
    fd9c161a
    Bug #31303537: RUN NTH_ELEMENT BEFORE SORTING BUFFERS WHEN LIMIT IS ACTIVE · fd9c161a
    Steinar H. Gunderson authored
    When filesort sorts a buffer and LIMIT is active, it first sorts all rows and
    then discards the ones that don't fit into LIMIT. This sorts a lot of rows that
    we know we're going to throw away anyway. Instead, find the right element using
    nth_element first (if LIMIT is sufficiently smaller than the buffer size -- the
    factor 2 has been chosen without much measurement), and then sort only the rows
    we know we actually need. This speeds up the sorting phase of a simple string
    sorting benchmark (as measured with EXPLAIN ANALYZE) by ~15%.
    
    Change-Id: Id267c8e9ed264c32f7e338ff028efbe52fe9d428
    fd9c161a
    Bug #31303537: RUN NTH_ELEMENT BEFORE SORTING BUFFERS WHEN LIMIT IS ACTIVE
    Steinar H. Gunderson authored
    When filesort sorts a buffer and LIMIT is active, it first sorts all rows and
    then discards the ones that don't fit into LIMIT. This sorts a lot of rows that
    we know we're going to throw away anyway. Instead, find the right element using
    nth_element first (if LIMIT is sufficiently smaller than the buffer size -- the
    factor 2 has been chosen without much measurement), and then sort only the rows
    we know we actually need. This speeds up the sorting phase of a simple string
    sorting benchmark (as measured with EXPLAIN ANALYZE) by ~15%.
    
    Change-Id: Id267c8e9ed264c32f7e338ff028efbe52fe9d428
Loading