• unknown's avatar
    * Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big · 124cb126
    unknown authored
                  tables
    Currently in INSERT ... SELECT ... LIMIT ... the compiler uses a 
    temporary table to store the results of SELECT ... LIMIT .. and then
    uses that table as a source for INSERT. The problem is that in some cases
    it actually skips the LIMIT clause in doing that and materializes the 
    whole SELECT result set regardless of the LIMIT.
    This fix is limiting the process of filling up the temp table with only 
    that much rows that will be actually used by propagating the LIMIT value.
    
    
    mysql-test/r/insert_select.result:
      * Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big
                    tables
      - a test demonstrating the code path
    mysql-test/t/insert_select.test:
      * Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big
                    tables
      - a test demonstrating the code path
    sql/sql_select.cc:
      * Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big
                    tables
      - pass through the real LIMIT number if the temp table is created for
        buffering results.
      - set the counter for all the cases when the temp table is not used for
        grouping
    124cb126
insert_select.result 9.53 KB