• unknown's avatar
    Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving. · a97fd193
    unknown authored
     Several problems fixed: 
      1. There was a "catch-all" context initialization in setup_tables()
        that was causing the table that we insert into to be visible in the 
        SELECT part of an INSERT .. SELECT .. statement with no tables in
        its FROM clause. This was making sure all the under-initialized
        contexts in various parts of the code are not left uninitialized.
        Fixed by removing the "catch-all" statement and initializing the 
        context in the parser.
      2. Incomplete name resolution context when resolving the right-hand
        values in the ON DUPLICATE KEY UPDATE ... part of an INSERT ... SELECT ...
        caused columns from NATURAL JOIN/JOIN USING table references in the
        FROM clause of the select to be unavailable.
        Fixed by establishing a proper name resolution context.
      3. When setting up the special name resolution context for problem 2
        there was no check for cases where an aggregate function without a
        GROUP BY effectively takes the column from the SELECT part of an 
        INSERT ... SELECT unavailable for ON DUPLICATE KEY UPDATE.
        Fixed by checking for that condition when setting up the name 
        resolution context.
    
    
    mysql-test/r/insert_update.result:
      Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
       - test case
    mysql-test/t/insert_update.test:
      Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
       - test case
    sql/item.h:
      Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
       - save_next_local is not referenced any more outside class methods
    sql/sql_base.cc:
      Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
       - removed a "catch-all" code to cater for correct context initialization
    sql/sql_help.cc:
      Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
       - fixed the name resolution context initialization
    sql/sql_insert.cc:
      Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
       - Fixed the context of resolving the values in INSERT SELECT ON UPDATE
    sql/sql_prepare.cc:
      Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
       - Correct context for name resolution of prepared INSERT .. SELECT
    sql/sql_union.cc:
      Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
       - fixed the name resolution context initialization
    sql/sql_yacc.yy:
      Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
       - Set the context here instead of setup_tables()
    a97fd193
sql_yacc.yy 248 KB