• unknown's avatar
    Fix for bug #11060 "Server crashes on re-execution of prepared · 78e6794b
    unknown authored
    INSERT ... SELECT with UNION" (reviewed version).
    
    Altough bug manifest itself only starting from 5.0 it is better to
    apply fix to 4.1 to keep some assumptions true and make code more
    future-proof.
    
    
    mysql-test/r/ps.result:
      Added test case for bug #11060 "Server crashes on re-execution of
      prepared INSERT ... SELECT with UNION".
    mysql-test/t/ps.test:
      Added test case for bug #11060 "Server crashes on re-execution of
      prepared INSERT ... SELECT with UNION".
    sql/sql_insert.cc:
      select_insert::prepare():
        Item::fix_fields() methods operate assuming that LEX::current_select
        points to the select to which current item belongs. Thus
        during check_insert_fields() routine execution LEX::current_select
        should point ot the first select in query since this is the
        select with which items in insert list is associated.
        But if we have INSERT SELECT UNION SELECT type of query
        LEX::current_select will point to the fake_select_lex instead
        since select_insert::prepare() is called during processing of JOIN
        which corresponds to this select_lex.
        So we have set LEX::current_select before calling check_insert_fields()
        and restore it afterwards.
    78e6794b
sql_insert.cc 54 KB