• MySQL Build Team's avatar
    Backport into build-201102032246-5.1.52sp1 · 89b9934c
    MySQL Build Team authored
    > ------------------------------------------------------------
    > revno: 3520
    > revision-id: sergey.glukhov@oracle.com-20101214093303-wmo9mqcb8rz0wv9f
    > parent: tor.didriksen@oracle.com-20101213161301-81lprlbune7r98dl
    > committer: Sergey Glukhov <sergey.glukhov@oracle.com>
    > branch nick: mysql-5.1-bugteam
    > timestamp: Tue 2010-12-14 12:33:03 +0300
    > message:
    >   Fixed following problems:
    >   --Bug#52157 various crashes and assertions with multi-table update, stored function
    >   --Bug#54475 improper error handling causes cascading crashing failures in innodb/ndb
    >   --Bug#57703 create view cause Assertion failed: 0, file .\item_subselect.cc, line 846
    >   --Bug#57352 valgrind warnings when creating view
    >   --Recently discovered problem when a nested materialized derived table is used
    >     before being populated and it leads to incorrect result
    >   
    >   We have several modes when we should disable subquery evaluation.
    >   The reasons for disabling are different. It could be
    >   uselessness of the evaluation as in case of 'CREATE VIEW'
    >   or 'PREPARE stmt', or we should disable subquery evaluation
    >   if tables are not locked yet as it happens in bug#54475, or
    >   too early evaluation of subqueries can lead to wrong result
    >   as it happened in Bug#19077.
    >   Main problem is that if subquery items are treated as const
    >   they are evaluated in ::fix_fields(), ::fix_length_and_dec()
    >   of the parental items as a lot of these methods have
    >   Item::val_...() calls inside.
    >   We have to make subqueries non-const to prevent unnecessary
    >   subquery evaluation. At the moment we have different methods
    >   for this. Here is a list of these modes:
    >   
    >   1. PREPARE stmt;
    >   We use UNCACHEABLE_PREPARE flag.
    >   It is set during parsing in sql_parse.cc, mysql_new_select() for
    >   each SELECT_LEX object and cleared at the end of PREPARE in
    >   sql_prepare.cc, init_stmt_after_parse(). If this flag is set
    >   subquery becomes non-const and evaluation does not happen.
    >   
    >   2. CREATE|ALTER VIEW, SHOW CREATE VIEW, I_S tables which
    >      process FRM files
    >   We use LEX::view_prepare_mode field. We set it before
    >   view preparation and check this flag in
    >   ::fix_fields(), ::fix_length_and_dec().
    >   Some bugs are fixed using this approach,
    >   some are not(Bug#57352, Bug#57703). The problem here is
    >   that we have a lot of ::fix_fields(), ::fix_length_and_dec()
    >   where we use Item::val_...() calls for const items.
    >   
    >   3. Derived tables with subquery = wrong result(Bug19077)
    >   The reason of this bug is too early subquery evaluation.
    >   It was fixed by adding Item::with_subselect field
    >   The check of this field in appropriate places prevents
    >   const item evaluation if the item have subquery.
    >   The fix for Bug19077 fixes only the problem with
    >   convert_constant_item() function and does not cover
    >   other places(::fix_fields(), ::fix_length_and_dec() again)
    >   where subqueries could be evaluated.
    >   
    >   Example:
    >   CREATE TABLE t1 (i INT, j BIGINT);
    >   INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2);
    >   SELECT * FROM (SELECT MIN(i) FROM t1
    >   WHERE j = SUBSTRING('12', (SELECT * FROM (SELECT MIN(j) FROM t1) t2))) t3;
    >   DROP TABLE t1;
    >   
    >   4. Derived tables with subquery where subquery
    >      is evaluated before table locking(Bug#54475, Bug#52157)
    >   
    >   Suggested solution is following:
    >   
    >   -Introduce new field LEX::context_analysis_only with the following
    >    possible flags:
    >    #define CONTEXT_ANALYSIS_ONLY_PREPARE 1
    >    #define CONTEXT_ANALYSIS_ONLY_VIEW    2
    >    #define CONTEXT_ANALYSIS_ONLY_DERIVED 4
    >   -Set/clean these flags when we perform
    >    context analysis operation
    >   -Item_subselect::const_item() returns
    >    result depending on LEX::context_analysis_only.
    >    If context_analysis_only is set then we return
    >    FALSE that means that subquery is non-const.
    >    As all subquery types are wrapped by Item_subselect
    >    it allow as to make subquery non-const when
    >    it's necessary.
    89b9934c
item_cmpfunc.cc 144 KB