• Sergey Glukhov's avatar
    Bug#11756242 48137: PROCEDURE ANALYSE() LEAKS MEMORY WHEN RETURNING NULL · 53474c69
    Sergey Glukhov authored
    There are two problems with ANALYSE():
    
    1. Memory leak 
       it happens because do_select() can overwrite
       JOIN::procedure field(with zero value in our case) and
       JOIN destructor don't free the memory allocated for
       JOIN::procedure. The fix is to save original JOIN::procedure
       before do_select() call and restore it after do_select
       execution.
    
    2. Wrong result
       If ANALYSE() procedure is used for the statement with LIMIT clause
       it could retrun empty result set. It happens because of missing 
       analyse::end_of_records() call. First end_send() function call
       returns NESTED_LOOP_QUERY_LIMIT and second call of end_send() with
       end_of_records flag enabled does not happen. The fix is to return
       NESTED_LOOP_OK from end_send() if procedure is active.
    
    
    mysql-test/r/analyse.result:
      test case
    mysql-test/t/analyse.test:
      test case
    sql/sql_select.cc:
      --save original JOIN::procedure before do_select() call and
        restore it after do_select execution.
      --return NESTED_LOOP_OK from end_send() if procedure is active
    53474c69
sql_select.cc 553 KB