An error occurred fetching the project authors.
  1. 17 Feb, 2008 1 commit
    • unknown's avatar
      Bug #32942 now() - interval '7200' second NOT pre-calculated, causing "full table scan" · d6be1a9b
      unknown authored
      Problem is not about intervals and doesn't actually cause 'full table scan'.
      We have an optimization for DISTINCT when we have
      'DISTINCT field_from_first_join_table' we don't need to read all the
      rows from the JOIN-ed table if we found one conforming row.
      It stopped working in 5.0 as we return NESTED_LOOP_OK if we came upon
      that case in the evaluate_join_record() and that doesn't break the
      recordreading loop in sub_select().
      
      Fixed by returning NESTED_LOOP_NO_MORE_ROWS in this case.
      
      
      mysql-test/r/select.result:
        Bug #32942 now() - interval '7200' second is NOT pre-calculated, causing "full table scan".
        
        test result
      mysql-test/t/select.test:
        Bug #32942 now() - interval '7200' second is NOT pre-calculated, causing "full table scan"
        
        test case
      sql/sql_select.cc:
        Bug #32942 now() - interval '7200' second NOT pre-calculated, causing "full table scan"
        
        return NESTED_LOOP_NO_MORE_ROWS when we don't need to read rows from
        this table anymore
      d6be1a9b
  2. 27 Jan, 2008 1 commit
    • unknown's avatar
      Fixed bug #33833. · e30a0dda
      unknown authored
      Two disjuncts containing equalities of the form key=const1 and key=const2 can
      be merged into one if const1 is equal to const2. To check it the common 
      collation of the constants were used rather than the collation of the field key.
      For example when the default collation of the constants was cases insensitive
      while the collation of the field was case sensitive, then two or-ed equality 
      predicates key='b' and key='B' incorrectly were merged into one f='b'. As a 
      result ref access was used instead of range access and wrong result sets were 
      returned in many cases. 
      Fixed the problem by comparing constant in the or-ed predicate with collation of
      the key field.
      
      
      mysql-test/r/range.result:
        Added a test case for bug #33833.
      mysql-test/t/range.test:
        Added a test case for bug #33833.
      sql/item.cc:
        Fixed bug #33833.
        Added the method eq_by_collation that compares two items almost as 
        the method Item::eq, but it rather enforces a given collation for
        the comparison.
      sql/item.h:
        Fixed bug #33833.
        Added the method eq_by_collation that compares two items almost as 
        the method Item::eq, but it rather enforces a given collation for
        the comparison.
      e30a0dda
  3. 18 Jan, 2008 1 commit
    • unknown's avatar
      BUG#33794 "MySQL crashes executing specific query": · c71a6428
      unknown authored
      The problem occurred when one had a subquery that had an equality X=Y where 
      Y referred to a named select list expression from the parent select. MySQL 
      crashed when trying to use the X=Y equality for ref-based access. 
      
      Fixed by allowing non-Item_field items in the described case.
      
      
      mysql-test/r/subselect.result:
        BUG#33794 "MySQL crashes executing specific query"
        - Testcase
      mysql-test/t/subselect.test:
        BUG#33794 "MySQL crashes executing specific query"
        - Testcase
      sql/sql_select.cc:
        BUG#33794 "MySQL crashes executing specific query"
        get_store_key() assumed that if it got a reference
          t.key=Item_outer_ref(Item_direct_ref(x)) 
        then x was an Item_field object, which is not the case when one refers to a
        named select list expression out ot subquery.
      c71a6428
  4. 11 Jan, 2008 1 commit
    • unknown's avatar
      Fixed bug #33697. · d8363a40
      unknown authored
      When the function test_if_skip_sort_order prefers index backward scan 
      to ref access the corresponding access functions must be set accordingly.
      
      
      mysql-test/include/mix1.inc:
        Added a test case for bug #33697.
        Corrected one previous bad merge.
      mysql-test/r/innodb_mysql.result:
        Added a test case for bug #33697.
      mysql-test/t/disabled.def:
        Turned innodb_mysql test on.
      d8363a40
  5. 20 Dec, 2007 2 commits
    • unknown's avatar
      A pre-requisite for the fix for Bug#12713 "Error in a stored function · 0fbc29c1
      unknown authored
      called from a SELECT doesn't cause ROLLBACK of state"
      Make private all class handler methods (PSEA API) that may modify
      data. Introduce and deploy public ha_* wrappers for these methods in 
      all sql/.
      This necessary to keep track of all data modifications in sql/,
      which is in turn necessary to be able to optimize two-phase
      commit of those transactions that do not modify data.
      
      
      sql/ha_partition.cc:
        Class ha_partition is no longer a friend of class handler.
        Use the public handler interface (handler::ha_ methods) for partition
        operations.
        Remove unnecessary casts from char[] to const char *.ppзи выафвыаafa
      sql/handler.cc:
        Function ha_create_table() is no longer a friend of class handler.
        Use public handler::change_table_ptr() to access private members.
        This fixes a subtle bug (no test case in the test suite) when a
        deletion error occurs inside one partition of a partitioned engine. 
        The old code would crash in handler::print_error() in this case.
        
        Implement the newly introduced public ha_* wrappers of the private
        virtual handler methods.
      sql/handler.h:
        Introduce ha_* wrappers to all class handler methods that may
        modify data. This is necessary to be able to keep track of
        data modifying operations of class handler and optimize read-only
        transactions.
      sql/item_sum.cc:
        delete_all_rows -> ha_delete_all_rows
      sql/sql_base.cc:
        Use the new public wrappers.
      sql/sql_delete.cc:
        delete_all_rows -> ha_delete_all_rows
      sql/sql_partition.cc:
        Use the new public wrappers.
      sql/sql_select.cc:
        delete_all_rows -> ha_delete_all_rows
        delete_table -> ha_delete_table
        disabe_indexes -> ha_disable_idnexes
      sql/sql_show.cc:
        delete_all_rows -> ha_delete_all_rows
      sql/sql_table.cc:
        Use the public wrappers for class handler DDL methods.
        All methods which may change handler data are now accessed via a public
        wrapper.
      sql/sql_union.cc:
        delete_all_rows -> ha_delete_all_rows
        {enable,disable}_indexes -> ha_{enable,disable}_indexes
      sql/sql_update.cc:
        bulk_update_row -> ha_bulk_update_row
      sql/unireg.cc:
        create_handler_files -> ha_create_handler_files
      0fbc29c1
    • unknown's avatar
      Bug#32848: Data type conversion bug in union subselects in MySQL 5.0.38 · a8d1b13f
      unknown authored
      Warnings elimination
      
      
      sql/sql_select.cc:
        Bug#32848: Warnings elimination
      a8d1b13f
  6. 19 Dec, 2007 1 commit
    • unknown's avatar
      Make handler::{write,delete,update}_row private. It's critical · 226700ee
      unknown authored
      that the entire server uses their public ha_* counterparts instead,
      since only then we can ensure proper tracing of these calls that
      is necessary for Bug#12713.
      A pre-requisite for Bug#12713 "Error in a stored function called from 
      a SELECT doesn't cause ROLLBACK of statem"
      
      
      sql/ha_partition.cc:
        Use ha_write_row, ha_update_row, ha_delete_row instead of now-private
        write_row, update_row, delete_row. 
        In future ha_* calls will contain more than just a call to the binary
        log, so it's essential they are used consistently everywhere in the server.
        
        Disable the undesired effect of double binary logging of changes
        to partitioned tables with tmp_disable_binlog.
      sql/handler.h:
        Make write_row, update_row, delete_row private. It's critical
        that the entire code base uses ha_write_row, ha_update_row, ha_delete_row
        instead -- in future, ha_* counterparts will have more common
        functionality than just a call to the binary log.
      sql/sql_select.cc:
        Use ha_write_row, ha_update_row, ha_delete_row instead of
        write_row, update_row, delete_row respectively. 
        The change affects the join execution code that works with an
        intermediate internal temporary table. Do not disable binary logging,
        since it's unnecessary - temporary tables are not replicated
        by row level replication.
      sql/sql_table.cc:
        Use ha_write_row in copy_data_between_tables - the function
        that writes data from the original table to a temporary copy
        when executing ALTER TABLE. Do not disable binary logging
        since temporary tables are not replicated by row level 
        replication anyway.
      226700ee
  7. 12 Dec, 2007 1 commit
    • unknown's avatar
      Bug#12713 "Error in a stored function called from a SELECT doesn't · 2a0d2fef
      unknown authored
      cause ROLLBACK of statement", part 1. Review fixes.
      
      Do not send OK/EOF packets to the client until we reached the end of 
      the current statement.
      This is a consolidation, to keep the functionality that is shared by all 
      SQL statements in one place in the server.
      Currently this functionality includes:
      - close_thread_tables()
      - log_slow_statement().
      
      After this patch and the subsequent patch for Bug#12713, it shall also include:
      - ha_autocommit_or_rollback()
      - net_end_statement()
      - query_cache_end_of_result().
      
      In future it may also include:
      - mysql_reset_thd_for_next_command().
      
      
      include/mysql_com.h:
        Rename now unused members of NET: no_send_ok, no_send_error, report_error.
        These were server-specific variables related to the client/server
        protocol. They have been made obsolete by this patch.
        
        Previously the same members of NET were used to store the error message
        both on the client and on the server. 
        The error message was stored in net.last_error (client: mysql->net.last_error,
        server: thd->net.last_error).
        The error code was stored in net.last_errno (client: mysql->net.last_errno,
        server: thd->net.last_errno).
        The server error code and message are now stored elsewhere 
        (in the Diagnostics_area), thus NET members are no longer used by the
        server.
        Rename last_error to client_last_error, last_errno to client_last_errno
        to avoid potential bugs introduced by merges.
      include/mysql_h.ic:
        Update the ABI file to reflect a rename. 
        Renames do not break the binary compatibility.
      libmysql/libmysql.c:
        Rename last_error to client_last_error, last_errno to client_last_errno.
        This is necessary to ensure no unnoticed bugs introduced by merged
        changesets.
        
        Remove net.report_error, net.no_send_ok, net.no_send_error.
      libmysql/manager.c:
        Rename net.last_errno to net.client_last_errno.
      libmysqld/lib_sql.cc:
        Rename net.last_errno to net.client_last_errno.
        
        Update the embedded implementation of the client-server protocol to
        reflect the refactoring of protocol.cc.
      libmysqld/libmysqld.c:
        Rename net.last_errno to net.client_last_errno.
      mysql-test/r/events.result:
        Update to reflect the change in mysql_rm_db(). Now we drop stored
        routines and events for a given database name only if there
        is a directory for this database name. ha_drop_database() and
        query_cache_invalidate() are called likewise. 
        Previously we would attempt to drop routines/events even if database
        directory was not found (it worked, since routines and events are stored
        in tables). This fixes Bug 29958 "Weird message on DROP DATABASE if mysql.proc
        does not exist".
        The change was done because the previous code used to call send_ok()
        twice, which led to an assertion failure when asserts against it were
        added by this patch.
      mysql-test/r/grant.result:
        Fix the patch for Bug 16470, now FLUSH PRIVILEGES produces an error 
        if mysql.procs_priv is missing.
        This fixes the assert that send_ok() must not called after send_error()
        (the original patch for Bug 16470 was prone to this).
      mysql-test/suite/rpl/r/rpl_row_tabledefs_2myisam.result:
        Produce a more detailed error message.
      mysql-test/suite/rpl/r/rpl_row_tabledefs_3innodb.result:
        Produce a more detailed error message.
      mysql-test/t/grant.test:
        Update the test, now FLUSH PRIVILEGES returns an error if mysql.procs_priv
        is missing.
      server-tools/instance-manager/mysql_connection.cc:
        Rename net.last_errno to net.client_last_errno.
      sql/ha_ndbcluster_binlog.cc:
        Add asserts. 
        
        Use getters to access statement status information.
        
        Add a comment why run_query() is broken. Reset the diagnostics area
        in the end of run_query() to fulfill the invariant that the diagnostics_area
        is never assigned twice per statement (see the comment in the code
        when this can happen). We still do not clear thd->is_fatal_error and
        thd->is_slave_error, which may lead to bugs, I consider the whole affair
        as something to be dealt with separately.
      sql/ha_partition.cc:
        fatal_error() doesn't set an error by itself. Perhaps we should
        remove this method altogether and instead add a flag to my_error 
        to set thd->is_fatal_error property.
        
        Meanwhile, this change is a part of inspection made to the entire source
        code with the goal to ensure that fatal_error()
        is always accompanied by my_error().
      sql/item_func.cc:
        There is no net.last_error anymore. Remove the obsolete assignment.
      sql/log_event.cc:
        Use getters to access statement error status information.
      sql/log_event_old.cc:
        Use getters to access statement error status information.
      sql/mysqld.cc:
        Previously, if a continue handler for an error was found, my_message_sql() 
        would not set an error in THD. Since the current statement
        must be aborted in any case, find_handler() had a hack to assign 
        thd->net.report_error to 1.
        
        Remove this hack. Set an error in my_message_sql() even if the continue
        handler is found. The error will be cleared anyway when the handler
        is executed. This is one action among many in this patch to ensure the 
        invariant that whenever thd->is_error() is TRUE, we have a message in 
        thd->main_da.message().
      sql/net_serv.cc:
        Use a full-blown my_error() in net_serv.cc to report an error,
        instead of just setting net->last_errno. This ensures the invariant that
        whenever thd->is_error() returns TRUE, we have a message in 
        thd->main_da.message().
        
        Remove initialization of removed NET members.
      sql/opt_range.cc:
        Use my_error() instead of just raising thd->net.report_error. 
        This ensures the invariant that whenever thd->is_error() returns TRUE, 
        there is a message in thd->main_da.message().
      sql/opt_sum.cc:
        Move invocation of fatal_error() right next to the place where
        we set the error message. That makes it easier to track that whenever
        fatal_error() is called, there is a message in THD.
      sql/protocol.cc:
        Rename send_ok() and send_eof() to net_send_ok() and net_send_eof() 
        respectively. These functions write directly to the network and are not 
        for use anywhere outside the client/server protocol code. 
        
        Remove the code that was responsible for cases when either there is 
        no error code, or no error message, or both.
        Instead the calling code ensures that they are always present. Asserts
        are added to enforce the invariant.
        
        Instead of a direct access to thd->server_status and thd->total_warn_count
        use function parameters, since these from now on don't always come directly
        from THD.
        
        Introduce net_end_statement(), the single-entry-point replacement API for 
        send_ok(), send_eof() and net_send_error().
        
        Implement Protocol::end_partial_result_set to use in select_send::abort()
        when there is a continue handler.
      sql/protocol.h:
        Update declarations.
      sql/repl_failsafe.cc:
        Use getters to access statement status information in THD.
        Rename net.last_error to net.client_last_error.
      sql/rpl_record.cc:
        Set an error message in prepare_record() if there is no default
        value for the field -- later we do print this message to the client.
      sql/rpl_rli.cc:
        Use getters to access statement status information in THD.
      sql/slave.cc:
        In create_table_from_dump() (a common function that is used in 
        LOAD MASTER TABLE SQL statement and COM_LOAD_MASTER_DATA), instead of hacks
        with no_send_ok, clear the diagnostics area when mysql_rm_table() succeeded.
        
        Update has_temporary_error() to work correctly when no error is set.
        This is the case when Incident_log_event is executed: it always returns
        an error but does not set an error message.
        
        Use getters to access error status information.
      sql/sp_head.cc:
        Instead of hacks with no_send_error, work through the diagnostics area 
        interface to suppress sending of OK/ERROR packets to the client.
        
        Move query_cache_end_of_result before log_slow_statement(), similarly
        to how it's done in dispatch_command().
      sql/sp_rcontext.cc:
        Remove hacks with assignment of thd->net.report_error, they are not
        necessary any more (see the changes in mysqld.cc).
      sql/sql_acl.cc:
        Use getters to access error status information in THD.
      sql/sql_base.cc:
        Access thd->main_da.sql_errno() only if there is an error. This fixes
        a bug when auto-discovery, that was effectively disabled under pre-locking.
      sql/sql_binlog.cc:
        Remove hacks with no_send_ok/no_send_error, they are not necessary 
        anymore: the caller is responsible for network communication.
      sql/sql_cache.cc:
        Disable sending of OK/ERROR/EOF packet in the end of dispatch_command
        if the response has been served from the query cache. This raises the 
        question whether we should store EOF packet in the query cache at all,
        or generate it anew for each statement (we should generate it anew), but
        this is to be addressed separately.
      sql/sql_class.cc:
        Implement class Diagnostics_area. Please see comments in sql_class.h
        for details.
        
        Fix a subtle coding mistake in select_send::send_data: when on slave, 
        an error in Item::send() was ignored.
        The problem became visible due to asserts that the diagnostics area is
        never double assigned.
        
        Remove initialization of removed NET members.
        
        In select_send::abort() do not call select_send::send_eof(). This is
        not inheritance-safe. Even if a stored procedure continue handler is
        found, the current statement is aborted, not succeeded.
        Instead introduce a Protocol API to send the required response, 
        Protocol::end_partial_result_set().
        
        This simplifies implementation of select_send::send_eof(). No need
        to add more asserts that there is no error, there is an assert inside
        Diagnostics_area::set_ok_status() already.
        
        Leave no trace of no_send_* in the code.
      sql/sql_class.h:
        Declare class Diagnostics_area. 
        
        Remove the hack with no_send_ok from
        Substatement_state.
        
        Provide inline implementations of send_ok/send_eof.
        
        Add commetns.
      sql/sql_connect.cc:
        Remove hacks with no_send_error. 
        
        Since now an error in THD is always set if net->error, it's not necessary
        to check both net->error and thd->is_error() in the do_command loop.
        
        Use thd->main_da.message() instead of net->last_errno.
        
        Remove the hack with is_slave_error in sys_init_connect. Since now we do not
        reset the diagnostics area in net_send_error (it's reset at the beginning
        of the next statement), we can access it safely even after 
        execute_init_command.
      sql/sql_db.cc:
        Update the code to satisfy the invariant that the diagnostics area is never
        assigned twice.
        Incidentally, this fixes Bug 29958 "Weird message on DROP DATABASE if 
        mysql.proc does not exist".
      sql/sql_delete.cc:
        Change multi-delete to abort in abort(), as per select_send protocol.
        Fixes the merge error with the test for Bug 29136
      sql/sql_derived.cc:
        Use getters to access error information.
      sql/sql_insert.cc:
        Use getters to access error information.
      sql-common/client.c:
        Rename last_error to client_last_error, last_errno to client_last_errno.
      sql/sql_parse.cc:
        Remove hacks with no_send_error. Deploy net_end_statement().
        
        The story of COM_SHUTDOWN is interesting. Long story short, the server 
        would become on its death's door, and only no_send_ok/no_send_error assigned
        by send_ok()/net_send_error() would hide its babbling from the client.
        
        First of all, COM_QUIT does not require a response. So, the comment saying
        "Let's send a response to possible COM_QUIT" is not only groundless 
        (even mysqladmin shutdown/mysql_shutdown() doesn't send COM_QUIT after 
        COM_SHUTDOWN), it's plainly incorrect.
        
        Secondly, besides this additional 'OK' packet to respond to a hypothetical
        COM_QUIT, there was the following code in dispatch_command():
        
        if (thd->killed)
          thd->send_kill_message();
        if (thd->is_error()
          net_send_error(thd);
        
        This worked out really funny for the thread through which COM_SHUTDOWN
        was delivered: we would get COM_SHUTDOWN, say okay, say okay again, 
        kill everybody, get the kill signal ourselves, and then attempt to say 
        "Server shutdown in progress" to the client that is very likely long gone.
        
        This all became visible when asserts were added that the Diagnostics_area
        is not assigned twice.
        
        Move query_cache_end_of_result() to the end of dispatch_command(), since
        net_send_eof() has been moved there. This is safe, query_cache_end_of_result()
        is a no-op if there is no started query in the cache.
        
        Consistently use select_send interface to call abort() or send_eof()
        depending on the operation result.
        
        Remove thd->fatal_error() from reset_master(), it was a no-op. 
        in hacks with no_send_error woudl save us
        from complete breakage of the client/server protocol.
        
        Consistently use select_send::abort() whenever there is an error, 
        and select_send::send_eof() in case of success.
        The issue became visible due to added asserts.
      sql/sql_partition.cc:
        Always set an error in THD whenever there is a call to fatal_error().
      sql/sql_prepare.cc:
        Deploy class Diagnostics_area.
        Remove the unnecessary juggling with the protocol in 
        Select_fetch_protocol_binary::send_eof(). EOF packet format is 
        protocol-independent.
      sql/sql_select.cc:
        Call fatal_error() directly in opt_sum_query.
        Call my_error() whenever we call thd->fatal_error().
      sql/sql_servers.cc:
        Use getters to access error information in THD.
      sql/sql_show.cc:
        Use getters to access error information in THD.
        
        Add comments.
        
        Call my_error() whenever we call fatal_error().
      sql/sql_table.cc:
        Replace hacks with no_send_ok with the interface of the diagnostics area.
        
        Clear the error if ENOENT error in ha_delete_table().
      sql/sql_update.cc:
        Introduce multi_update::abort(), which is the proper way to abort a
        multi-update. This fixes the merge conflict between this patch and
        the patch for Bug 29136.
      sql/table.cc:
        Use a getter to access error information in THD.
      sql/tztime.cc:
        Use a getter to access error information in THD.
      2a0d2fef
  8. 11 Dec, 2007 1 commit
    • unknown's avatar
      Bug#32848: Data type conversion bug in union subselects in MySQL 5.0.38 · 94f75ffc
      unknown authored
      There were two problems when inferring the correct field types resulting from
      UNION queries.
      - If the type is NULL for all corresponding fields in the UNION, the resulting 
        type would be NULL, while the type is BINARY(0) if there is just a single 
        SELECT NULL.
      - If one SELECT in the UNION uses a subselect, a temporary table is created
        to represent the subselect, and the result type defaults to a STRING type,
        hiding the fact that the type was unknown(just a NULL value).
      Fixed by remembering whenever a field was created from a NULL value and pass
      type NULL to the type coercion if that is the case, and creating a string field
      as result of UNION only if the type would otherwise be NULL.
      
      
      mysql-test/r/union.result:
        Bug#32848: Test result
      mysql-test/t/union.test:
        Bug#32848: Test case
      sql/field.cc:
        Bug#32848: Initialization of new field
      sql/field.h:
        Bug#32848: New member to record when a field was created from a NULL value.
      sql/item.cc:
        Bug#32848: 
        A field created from a NULL value will submit NULL as type to the 
        type coercion procedure.
        If Item_type_holder has not inferred the correct type after processing all
        SELECTs in a UNION, a string field is created.
      sql/sql_select.cc:
        Bug#32848: Recording when a field is created from a NULL value.
      94f75ffc
  9. 08 Dec, 2007 1 commit
    • unknown's avatar
      Fixed bug #32815. · d776054e
      unknown authored
      The index (key_part_1, key_part-2) was erroneously considered as compatible
      with the required ordering in the function test_test_if_order_by_key when 
      a query with an ORDER BY clause contained a condition of the form
        key_part_1=const OR key_part_1 IS NULL 
      and the order list contained only key_part_2. This happened because the value
      of the const_key_parts field in the KEYUSE structure was not formed correctly
      for the keys that could be used for ref_or_null access. 
      This was fixed in the code of the update_ref_and_keys function.
      The problem could not manifest itself for MyISAM databases because the
      implementation of the keys_to_use_for_scanning() handler function always
      returns an empty bitmap for the MyISAM engine.
      
      
      mysql-test/r/innodb_mysql.result:
        Added a test case for bug #32815.
      mysql-test/t/innodb_mysql.test:
        Added a test case for bug #32815.
      sql/sql_select.cc:
        Fixed bug #32815.
        The index (key_part_1, key_part-2) was erroneously considered as compatible
        with the required ordering in the function test_test_if_order_by_key when 
        a query with an ORDER BY clause contained a condition of the form
          key_part_1=const OR key_part_1 IS NULL 
        and the order list contained only key_part_2. This happened because the value
        of the const_key_parts field in the KEYUSE structure was not formed correctly
        for the keys that could be used for ref_or_null access. 
        This was fixed in the code of the update_ref_and_keys function.
      d776054e
  10. 06 Dec, 2007 1 commit
  11. 23 Nov, 2007 1 commit
  12. 21 Nov, 2007 1 commit
    • unknown's avatar
      Bug #30788: Inconsistent retrieval of char/varchar · e9832cee
      unknown authored
      Index lookup does not always guarantee that we can
      simply remove the relevant conditions from the WHERE
      clause. Reasons can be e.g. conversion errors, 
      partial indexes etc. 
      The optimizer was removing these parts of the WHERE 
      condition without any further checking.
      This leads to "false positives" when using indexes.
      Fixed by checking the index reference conditions
      (using WHERE) when using indexes with sub-queries.
      
      
      mysql-test/r/subselect.result:
        Bug #30788: 
         - using where
         - test case
      mysql-test/r/subselect3.result:
        Bug #30788: using where
      mysql-test/t/subselect.test:
        Bug #30788: test case
      sql/item.h:
        Bug #30788: 
         - Declare eq() method of Item_cache descendants : this is used in
         test_if_ref()
         - preserve the field that is being cached for type comparisions
      sql/sql_select.cc:
        Bug #30788: Don't remove the WHERE when using index lookup 
        with subqueries.
      e9832cee
  13. 20 Nov, 2007 2 commits
    • unknown's avatar
      sql_select.cc: · 3a0d1f30
      unknown authored
        Additional stack check for the bug#31048.
      
      
      sql/sql_select.cc:
        Additional stack check for the bug#31048.
      3a0d1f30
    • unknown's avatar
      Bug #32268: Indexed queries give bogus MIN and MAX results · 429abc58
      unknown authored
      Loose index scan does the grouping so the temp table does 
      not need to do it, even when sorting.
      Fixed by checking if the grouping is already done before
      doing sorting and grouping in a temp table and do only 
      sorting.
      
      
      mysql-test/r/group_min_max.result:
        Bug #32268: test case
      mysql-test/t/group_min_max.test:
        Bug #32268: test case
      sql/sql_select.cc:
        Bug #32268: don't group in the temp table if already done
      429abc58
  14. 17 Nov, 2007 2 commits
    • unknown's avatar
      Bug#24907: unpredictable (display) precission, if input precission increases · e473ffaa
      unknown authored
      post-merge fixes: some things work differently in 5.1
      
      
      mysql-test/r/type_newdecimal.result:
        post-merge fix: 5.1 throws different warning here
      sql/sql_select.cc:
        post-merge fix: signature has changed in 5.1
      e473ffaa
    • unknown's avatar
      Bug#24907: unpredictable (display) precission, if input precission increases · 748446b9
      unknown authored
      Server failed in assert() when we tried to create a DECIMAL() temp field
      with a scale of more than the allowed 30. Now we limit the scale to the
      allowed maximum. A truncation warning is thrown as necessary.
      
      
      mysql-test/r/type_newdecimal.result:
        Show that out of range DECIMAL temp fields will no longer
        stop the server with an assert.
      mysql-test/t/type_newdecimal.test:
        Show that out of range DECIMAL temp fields will no longer
        stop the server with an assert.
      sql/sql_select.cc:
        When creating DECIMAL() temp field, ascertain we stay within allowed
        limits. If not, truncate and warn.
      748446b9
  15. 16 Nov, 2007 1 commit
    • unknown's avatar
      Fix for bug #32241: memory corruption due to large index map in 'Range · 1c1dd1f2
      unknown authored
      checked for each record'
      
      The problem was in incorrectly calculated length of the buffer used to
      store a hexadecimal representation of an index map in
      select_describe(). This could result in buffer overrun and stack
      corruption under some circumstances.
      
      Fixed by correcting the calculation.
      
      
      mysql-test/r/explain.result:
        Added a test case for bug #32241.
      mysql-test/t/explain.test:
        Added a test case for bug #32241.
      sql/sql_select.cc:
        Corrected the buffer length calculation. Count one hex digit as 4 bits,
        not 8.
      1c1dd1f2
  16. 15 Nov, 2007 1 commit
    • unknown's avatar
      Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE · c8450b27
      unknown authored
                  corrupts a MERGE table
      Bug 26867 - LOCK TABLES + REPAIR + merge table result in
                  memory/cpu hogging
      Bug 26377 - Deadlock with MERGE and FLUSH TABLE
      Bug 25038 - Waiting TRUNCATE
      Bug 25700 - merge base tables get corrupted by
                  optimize/analyze/repair table
      Bug 30275 - Merge tables: flush tables or unlock tables
                  causes server to crash
      Bug 19627 - temporary merge table locking
      Bug 27660 - Falcon: merge table possible
      Bug 30273 - merge tables: Can't lock file (errno: 155)
      
      The problems were:
      
      Bug 26379 - Combination of FLUSH TABLE and REPAIR TABLE
                      corrupts a MERGE table
      
        1. A thread trying to lock a MERGE table performs busy waiting while
           REPAIR TABLE or a similar table administration task is ongoing on
           one or more of its MyISAM tables.
        
        2. A thread trying to lock a MERGE table performs busy waiting until all
           threads that did REPAIR TABLE or similar table administration tasks
           on one or more of its MyISAM tables in LOCK TABLES segments do UNLOCK
           TABLES. The difference against problem #1 is that the busy waiting
           takes place *after* the administration task. It is terminated by
           UNLOCK TABLES only.
        
        3. Two FLUSH TABLES within a LOCK TABLES segment can invalidate the
           lock. This does *not* require a MERGE table. The first FLUSH TABLES
           can be replaced by any statement that requires other threads to
           reopen the table. In 5.0 and 5.1 a single FLUSH TABLES can provoke
           the problem.
      
      Bug 26867 - LOCK TABLES + REPAIR + merge table result in
                  memory/cpu hogging
      
        Trying DML on a MERGE table, which has a child locked and
        repaired by another thread, made an infinite loop in the server.
      
      Bug 26377 - Deadlock with MERGE and FLUSH TABLE
      
        Locking a MERGE table and its children in parent-child order
        and flushing the child deadlocked the server.
      
      Bug 25038 - Waiting TRUNCATE
      
        Truncating a MERGE child, while the MERGE table was in use,
        let the truncate fail instead of waiting for the table to
        become free.
      
      Bug 25700 - merge base tables get corrupted by
                  optimize/analyze/repair table
      
        Repairing a child of an open MERGE table corrupted the child.
        It was necessary to FLUSH the child first.
      
      Bug 30275 - Merge tables: flush tables or unlock tables
                  causes server to crash
      
        Flushing and optimizing locked MERGE children crashed the server.
      
      Bug 19627 - temporary merge table locking
      
        Use of a temporary MERGE table with non-temporary children
        could corrupt the children.
      
        Temporary tables are never locked. So we do now prohibit
        non-temporary chidlren of a temporary MERGE table.
      
      Bug 27660 - Falcon: merge table possible
      
        It was possible to create a MERGE table with non-MyISAM children.
      
      Bug 30273 - merge tables: Can't lock file (errno: 155)
      
        This was a Windows-only bug. Table administration statements
        sometimes failed with "Can't lock file (errno: 155)".
      
      These bugs are fixed by a new implementation of MERGE table open.
      
      When opening a MERGE table in open_tables() we do now add the
      child tables to the list of tables to be opened by open_tables()
      (the "query_list"). The children are not opened in the handler at
      this stage.
      
      After opening the parent, open_tables() opens each child from the
      now extended query_list. When the last child is opened, we remove
      the children from the query_list again and attach the children to
      the parent. This behaves similar to the old open. However it does
      not open the MyISAM tables directly, but grabs them from the already
      open children.
      
      When closing a MERGE table in close_thread_table() we detach the
      children only. Closing of the children is done implicitly because
      they are in thd->open_tables.
      
      For more detail see the comment at the top of ha_myisammrg.cc.
      
      Changed from open_ltable() to open_and_lock_tables() in all places
      that can be relevant for MERGE tables. The latter can handle tables
      added to the list on the fly. When open_ltable() was used in a loop
      over a list of tables, the list must be temporarily terminated
      after every table for open_and_lock_tables().
      table_list->required_type is set to FRMTYPE_TABLE to avoid open of
      special tables. Handling of derived tables is suppressed.
      These details are handled by the new function
      open_n_lock_single_table(), which has nearly the same signature as
      open_ltable() and can replace it in most cases.
      
      In reopen_tables() some of the tables open by a thread can be
      closed and reopened. When a MERGE child is affected, the parent
      must be closed and reopened too. Closing of the parent is forced
      before the first child is closed. Reopen happens in the order of
      thd->open_tables. MERGE parents do not attach their children
      automatically at open. This is done after all tables are reopened.
      So all children are open when attaching them.
      
      Special lock handling like mysql_lock_abort() or mysql_lock_remove()
      needs to be suppressed for MERGE children or forwarded to the parent.
      This depends on the situation. In loops over all open tables one
      suppresses child lock handling. When a single table is touched,
      forwarding is done.
      
      Behavioral changes:
      ===================
      
      This patch changes the behavior of temporary MERGE tables.
      Temporary MERGE must have temporary children.
      The old behavior was wrong. A temporary table is not locked. Hence
      even non-temporary children were not locked. See
      Bug 19627 - temporary merge table locking.
      
      You cannot change the union list of a non-temporary MERGE table
      when LOCK TABLES is in effect. The following does *not* work:
      CREATE TABLE m1 ... ENGINE=MRG_MYISAM ...;
      LOCK TABLES t1 WRITE, t2 WRITE, m1 WRITE;
      ALTER TABLE m1 ... UNION=(t1,t2) ...;
      However, you can do this with a temporary MERGE table.
      
      You cannot create a MERGE table with CREATE ... SELECT, neither
      as a temporary MERGE table, nor as a non-temporary MERGE table.
      CREATE TABLE m1 ... ENGINE=MRG_MYISAM ... SELECT ...;
      Gives error message: table is not BASE TABLE.
      
      
      include/my_base.h:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added HA_EXTRA_ATTACH_CHILDREN and HA_EXTRA_DETACH_CHILDREN.
      include/myisammrg.h:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added element 'children_attached' to MYRG_INFO.
        Added declarations for myrg_parent_open(),
        myrg_attach_children() and myrg_detach_children()
        for the new MERGE table open approach.
      mysql-test/extra/binlog_tests/blackhole.test:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Preliminarily added new error message with a comment.
      mysql-test/r/create.result:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Fixed test result.
      mysql-test/r/delayed.result:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Moved test result from here to merge.result.
      mysql-test/r/merge.result:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Fixed/added test result.
      mysql-test/r/myisam.result:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Moved test result for bug 8306 from here to merge.result.
      mysql-test/suite/binlog/r/binlog_stm_blackhole.result:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Fixed test result.
      mysql-test/t/create.test:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Fixed error number.
      mysql-test/t/delayed.test:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Moved test from here to merge.test.
      mysql-test/t/merge.test:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Fixed test for new temporary MERGE table behavior.
        Exchanged error numbers by symbolic codes.
        Added tests. Included are tests for bugs
        8306 (moved from myisam.test), 26379, 19627, 25038, 25700, 26377,
        26867, 27660, 30275, and 30273.
        Fixed changes resulting from disabled CREATE...SELECT.
        Integrated tests moved from delayed.test and myisam.test to here.
      mysql-test/t/myisam.test:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Moved test for bug 8306 from here to merge.test.
      mysys/thr_lock.c:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added code to let the owner of a high priority lock (TL_WRITE_ONLY)
        to bypass its own lock.
      sql/ha_ndbcluster_binlog.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added 'thd' argument to init_tmp_table_share().
      sql/handler.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added 'thd' argument to init_tmp_table_share().
      sql/mysql_priv.h:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Removed declaration of check_merge_table_access(). It is now static
        in sql_parse.cc.
        Added declaration for fix_merge_after_open().
        Renamed open_and_lock_tables() to open_and_lock_tables_derived()
        with additional parameter 'derived'.
        Added inline functions simple_open_n_lock_tables() and
        open_and_lock_tables(), which call open_and_lock_tables_derived()
        and add the argument for 'derived'.
        Added new function open_n_lock_single_table(), which can be used
        as an replacement for open_ltable() in most situations. Internally
        it calls simple_open_n_lock_tables() so hat it is appropriate for
        MERGE tables.
        Added 'thd' argument to init_tmp_table_share().
      sql/slave.cc:
        ug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added comment.
      sql/sql_base.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        
        Defined new functions add_merge_table_list(),
        attach_merge_children(), detach_merge_children(), and
        fix_merge_after_open() for the new MERGE table open approach.
        
        Added calls of the new functions to
        close_handle_and_leave_table_as_lock(), close_thread_tables(),
        close_thread_table(), unlink_open_table(), reopen_name_locked_table(),
        reopen_table(), drop_locked_tables(), close_temporary_table(),
        and open_tables() respectively.
        
        Prevented special lock handling of merge children (like
        mysql_lock_remove, mysql_lock_merge or mysql_lock_abort)
        at many places. Some of these calls are forwarded to the
        parent table instead.
        
        Added code to set thd->some_tables_deleted for every thread that has
        a table open that we are flushing.
        Added code for MERGE tables to unlink_open_table().
        Added MERGE children to the list of unusable tables in open_table().
        Added MERGE table handling to reopen_table().
        Added lock handling and closing of a parent before the children
        in close_data_files_and_morph_locks().
        Added code for re-attaching children in reopen_tables().
        Added MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN to the locking flags and
        error reporting after mysql_lock_tables() in reopen_tables().
        Added lock handling and closing of a parent before the children
        in close_old_data_files().
        Added lock handling and detaching in drop_locked_tables().
        Added code for removing the children list from the statement list
        to prepare for a repetition in open_tables().
        Added new function open_n_lock_single_table(), which can be used
        as an replacement for open_ltable() in most situations. Internally
        it calls simple_open_n_lock_tables() so hat it is appropriate for
        MERGE tables.
        Disabled use of open_ltable() for MERGE tables.
        Removed function simple_open_n_lock_tables(). It is now inline
        declared in mysql_priv.h.
        Renamed open_and_lock_tables() to open_and_lock_tables_derived()
        with additional parameter 'derived'. open_and_lock_tables() is now
        inline declared in mysql_priv.h.
        Added a check for end-of-list in two loops in lock_tables().
        Added 'thd' argument to init_tmp_table_share().
      sql/sql_insert.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Changed from open_ltable() to open_n_lock_single_table() in
        handle_delayed_insert().
        Reestablished LEX settings after lex initialization.
        Added 'thd' argument to init_tmp_table_share().
      sql/sql_parse.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Made check_merge_table_access() a static function.
        Disabled use of CREATE...SELECT for MERGE tables.
      sql/sql_partition.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Fixed comment typo.
      sql/sql_select.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added 'thd' argument to init_tmp_table_share().
      sql/sql_table.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Optimized use of mysql_ha_flush() in mysql_rm_table_part2().
        Disabled the use of MERGE tables with prepare_for_restore() and
        prepare_for_repair().
        Changed from open_ltable() to open_n_lock_single_table() in
        mysql_alter_table() and mysql_checksum_table().
        Disabled change of child list under LOCK TABLES.
        Initialized table_list->table in mysql_recreate_table().
      sql/sql_trigger.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added code for allowing CREATE TRIGGER under LOCK TABLE, to be able
        to test it with MERGE tables.
      sql/table.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added 'thd' argument to init_tmp_table_share().
        Setting table_map_id from query_id in init_tmp_table_share().
        Added member function TABLE::is_children_attached().
      sql/table.h:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added access method get_table_def_version() to TABLE_SHARE.
        Added elements for MERGE tables to TABLE and TABLE_LIST.
      storage/myisam/ha_myisam.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added an unrelated comment to the function comment of table2myisam().
      storage/myisam/ha_myisam.h:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added new member function MI_INFO::file_ptr().
      storage/myisammrg/ha_myisammrg.cc:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added callback functions to support parent open and children attach
        of MERGE tables.
        Changed ha_myisammrg::open() to initialize storage engine structures
        and create a list of child tables only. Child tables are not opened.
        Added ha_myisammrg::attach_children(), which does now the main part
        of MERGE open.
        Added ha_myisammrg::detach_children().
        Added calls to ::attach_children() and ::detach_children() to
        ::extra() on HA_EXTRA_ATTACH_CHILDREN and HA_EXTRA_DETACH_CHILDREN
        respectively.
        Added a check for matching TEMPORARY type for children against
        parent.
        Added a check for table def version.
        Added support for thd->open_options to attach_children().
        Changed child path name generation for temporary tables so that
        it does nothing special for temporary tables.
      storage/myisammrg/ha_myisammrg.h:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added elements to class ha_myisammrg to support the new
        open approach.
        Changed empty destructor definition to a declaration.
        Implemented in ha_myisammrg.cc.
        Added declaration for methods attach_children() and
        detach_children().
        Added definition for method table_ptr() for use with
        callback functions.
      storage/myisammrg/myrg_close.c:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Added a check to avoid closing of MyISAM tables when the
        child tables are not attached.
        Added freeing of rec_per_key_part when the child tables
        are not attached.
      storage/myisammrg/myrg_extra.c:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        Some ::extra() functions and ::reset() can be called when
        children are detached.
      storage/myisammrg/myrg_open.c:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
                    corrupts a MERGE table
        
        Kept old myrg_open() for MERGE use independent from MySQL.
        Removed an always true condition in myrg_open().
        Set children_attached for independent MERGE use in myrg_open().
        
        Added myrg_parent_open(), myrg_attach_children(), and
        myrg_detach_children() for the new MERGE table open approach.
      mysql-test/r/merge-big.result:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE corrupts a MERGE table
        New test result
      mysql-test/t/merge-big.test:
        Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE corrupts a MERGE table
        New test case
      c8450b27
  17. 13 Nov, 2007 1 commit
    • unknown's avatar
      Bug #31562: HAVING and lower case · 170ae2d2
      unknown authored
      The columns in HAVING can reference the GROUP BY and 
      SELECT columns. There can be "table" prefixes when
      referencing these columns. And these "table" prefixes
      in HAVING use the table alias if available.
      This means that table aliases are subject to the same
      storage rules as table names and are dependent on 
      lower_case_table_names in the same way as the table 
      names are.
      Fixed by :
      1. Treating table aliases as table names
      and make them lowercase when printing out the SQL
      statement for view persistence.
      2. Using case insensitive comparison for table 
      aliases when requested by lower_case_table_names
      
      
      mysql-test/r/lowercase_view.result:
        Bug #31562: test case
      mysql-test/t/lowercase_view.test:
        Bug #31562: test case
      sql/item.cc:
        Bug #31562: lower_case_table_name contious comparison
        when searching in GROUP BY
      sql/sql_base.cc:
        Bug #31562: lower_case_table_name contious comparison
        when searching in SELECT
      sql/sql_select.cc:
        Bug #31562: treat table aliases as table names
        and make them lowercase when printing
      170ae2d2
  18. 10 Nov, 2007 1 commit
    • unknown's avatar
      Bug#31700: thd->examined_row_count not incremented for 'const' type queries · a41b4763
      unknown authored
      UNIQUE (eq-ref) lookups result in table being considered as a "constant" table.
      Queries that consist of only constant tables are processed in do_select() in a
      special way that doesn't invoke evaluate_join_record(), and therefore doesn't
      increase the counters join->examined_rows and join->thd->row_count.
      
      The patch increases these counters in this special case.
      
      NOTICE:
      This behavior seems to contradict what the documentation says in Sect. 5.11.4:
      "Queries handled by the query cache are not added to the slow query log, nor
      are queries that would not benefit from the presence of an index because the
      table has zero rows or one row."
      
      No test case in 5.0 as issue shows only in slow query log, and other counters
      can give subtly different values (with regard to counting in create_sort_index(),
      synthetic rows in ROLLUP, etc.).
      
      
      sql/sql_class.h:
        add documentation for some variables
      sql/sql_select.cc:
        Don't forget const tables when counting read records!
      a41b4763
  19. 09 Nov, 2007 1 commit
    • unknown's avatar
      Fix for bug #32202: ORDER BY not working with GROUP BY · 55499d2b
      unknown authored
      The bug is a regression introduced by the fix for bug30596. The problem
      was that in cases when groups in GROUP BY correspond to only one row,
      and there is ORDER BY, the GROUP BY was removed and the ORDER BY
      rewritten to ORDER BY <group_by_columns> without checking if the
      columns in GROUP BY and ORDER BY are compatible. This led to
      incorrect ordering of the result set as it was sorted using the
      GROUP BY columns. Additionaly, the code discarded ASC/DESC modifiers
      from ORDER BY even if its columns were compatible with the GROUP BY
      ones.
      
      This patch fixes the regression by checking if ORDER BY columns form a
      prefix of the GROUP BY ones, and rewriting ORDER BY only in that case,
      preserving the ASC/DESC modifiers. That check is sufficient, since the
      GROUP BY columns contain a unique index.
      
      
      mysql-test/r/group_by.result:
        Added a test case for bug #32202.
      mysql-test/t/group_by.test:
        Added a test case for bug #32202.
      sql/sql_select.cc:
        In cases when groups in GROUP BY correspond to only one row and there
        is ORDER BY, rewrite the query to ORDER BY <group_by_columns> only if
        the columns in ORDER BY and GROUP BY are compatible, i.e. either one
        forms a prefix for another.
      55499d2b
  20. 07 Nov, 2007 2 commits
    • unknown's avatar
      Fix for bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB · 9d2b259e
      unknown authored
      and auto_increment keys
      
      Problems: 
        1. ALTER TABLE ... ORDER BY... doesn't make sence if there's a 
           user-defined clustered index in the table.
        2. using a secondary index is slower than using a clustered one 
           for a table scan.
      
      Fixes:
        1. raise a warning.
        2. use the clustered index.
      
      
      mysql-test/include/mix1.inc:
        Fix for bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB 
        and auto_increment keys
          - test case.
      mysql-test/r/innodb.result:
        Fix for bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB 
        and auto_increment keys
          - results adjusted.
      mysql-test/r/innodb_mysql.result:
        Fix for bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB 
        and auto_increment keys
          - results adjusted.
      mysql-test/r/join_outer_innodb.result:
        Fix for bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB 
        and auto_increment keys
          - results adjusted.
      sql/sql_select.cc:
        Fix for bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB 
        and auto_increment keys
          - use the clustered index for a table scan (if any) as it's faster than
            using a secondary index.
      sql/sql_table.cc:
        Fix for bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB 
        and auto_increment keys
          - ALTER TABLE ... ORDER BY doesn't make sence if there's a 
            user-defined clustered index in the table. Ignore it in such cases
            and raise a warning.
      9d2b259e
    • unknown's avatar
      Fix for bug #30666: Incorrect order when using range conditions on 2 · f6686659
      unknown authored
      tables or more
      
      The problem was that the optimizer used the join buffer in cases when
      the result set is ordered by filesort. This resulted in the ORDER BY
      clause being ignored, and the records being returned in the order
      determined by the order of matching records in the last table in join.
      
      Fixed by relaxing the condition in make_join_readinfo() to take
      filesort-ordered result sets into account, not only index-ordered ones.
      
      
      mysql-test/r/select.result:
        Added a test case for bug #30666.
      mysql-test/t/select.test:
        Added a test case for bug #30666.
      sql/sql_select.cc:
        Relaxed the condition to determine when the join buffer usage must be
        disabled. The condition is now true for cases when the result set is
        ordered by filesort, that is when 'join->order &&
        !join->skip_sort_order' is true.
      f6686659
  21. 05 Nov, 2007 1 commit
    • unknown's avatar
      Bug #31974: Wrong EXPLAIN output · 860f7db3
      unknown authored
      The fix for bug 31148 is not correct. It does not
      have a relation to the problem described in this bug.
      And removing the fix will not make the bug to re-appear.
      Fixed the bug #31974 by removing the fix for bug 31148
      and adding a test case.
      
      
      mysql-test/r/key.result:
        Bug #31974: test case
      mysql-test/t/key.test:
        Bug #31974: test case
      sql/sql_select.cc:
        Bug #31974: revert the fix for bug 31148
      860f7db3
  22. 02 Nov, 2007 1 commit
    • unknown's avatar
      Bug#31630 debug assert with explain extended select ... from i_s · dacf99b5
      unknown authored
      added 'in_rows' column value for 'describe extended' for the case 
      when 'describe' handles I_S table
      
      
      mysql-test/r/information_schema.result:
        test result
      mysql-test/t/information_schema.test:
        test case
      sql/sql_select.cc:
        added 'in_rows' column value for 'describe extended' for the case 
        when 'describe' handles I_S table
      dacf99b5
  23. 01 Nov, 2007 2 commits
    • unknown's avatar
      Bug #31794: no syntax error on SELECT id FROM t HAVING count(*)>2 · 660eb5bb
      unknown authored
      The HAVING clause is subject to the same rules as the SELECT list
      about using aggregated and non-aggregated columns.
      But this was not enforced when processing implicit grouping from
      using aggregate functions.
      Fixed by performing the same checks for HAVING as for SELECT.
      
      
      mysql-test/r/func_group.result:
        Bug #31794: test case
      mysql-test/t/func_group.test:
        Bug #31794: test case
      sql/sql_select.cc:
        Bug #31794: Check HAVING in addition to SELECT list
      660eb5bb
    • unknown's avatar
      Use thd->is_error() instead of direct access to thd->net.report_error · ecef8379
      unknown authored
      in evaluate_join_record().
      
      A minor cleanup required for the fix for Bug#12713.
      
      
      sql/sql_select.cc:
        Use thd->is_error() instead of direct access to thd->net.report_error
        in evaluate_join_record()
      ecef8379
  24. 30 Oct, 2007 1 commit
    • unknown's avatar
      Use an inline getter method (thd->is_error()) to query if there is an error · 24370012
      unknown authored
      in THD.
      In future the error may be stored elsewhere (not in net.report_error) and 
      it's important to start using an opaque getter to simplify merges.
      
      
      sql/filesort.cc:
        net.report_error -> is_error()
      sql/ha_ndbcluster_binlog.cc:
        net.report_error -> is_error()
      sql/item_func.cc:
        net.report_error -> is_error()
      sql/item_subselect.cc:
        net.report_error -> is_error()
      sql/set_var.cc:
        net.report_error -> is_error()
      sql/sp.cc:
        net.report_error -> is_error()
      sql/sp_head.cc:
        net.report_error -> is_error()
      sql/sql_base.cc:
        net.report_error -> is_error()
      sql/sql_class.cc:
        net.report_error -> is_error()
      sql/sql_class.h:
        net.report_error -> is_error()
      sql/sql_connect.cc:
        net.report_error -> is_error()
      sql/sql_delete.cc:
        net.report_error -> is_error()
      sql/sql_insert.cc:
        net.report_error -> is_error()
      sql/sql_parse.cc:
        net.report_error -> is_error()
      sql/sql_prepare.cc:
        net.report_error -> is_error()
      sql/sql_select.cc:
        net.report_error -> is_error()
      sql/sql_union.cc:
        net.report_error -> is_error()
      sql/sql_update.cc:
        net.report_error -> is_error()
      sql/sql_view.cc:
        net.report_error -> is_error()
      sql/sql_yacc.yy:
        net.report_error -> is_error()
      24370012
  25. 23 Oct, 2007 1 commit
    • unknown's avatar
      type conversions fixed to avoid warnings on Windows · e1dc86b0
      unknown authored
      myisam/mi_write.c:
        type conversion fixed
      myisam/sort.c:
        type conversion fixed
      sql/ha_federated.cc:
        type conversion fixed
      sql/ha_heap.cc:
        type conversion fixed
      sql/ha_innodb.cc:
        type conversion fixed
      sql/ha_myisam.cc:
        type conversion fixed
      sql/opt_range.cc:
        type conversion fixed
      sql/sql_map.cc:
        type conversion fixed
      sql/sql_select.cc:
        type conversion fixed
      sql/sql_update.cc:
        type conversion fixed
      e1dc86b0
  26. 20 Oct, 2007 1 commit
    • unknown's avatar
      Fix for BUG#31148: bool close_thread_table(THD*, TABLE**): · d1ddc24a
      unknown authored
      Assertion `table->key_read == 0' failed.
      
      The problem was that key_read on a table in a sub-select was not
      properly reset. That happens because the code responsible for that
      is copy&pasted all around the server. In some place, it was obviously
      forgotten to be pasted.
      
      The fix is to reset key_read properly.
      
      
      mysql-test/r/key.result:
        Update result file.
      mysql-test/t/key.test:
        A test case for BUG#31148: bool close_thread_table(THD*, TABLE**):
        Assertion `table->key_read == 0' failed.
      sql/sql_select.cc:
        Reset key_read before closing index.
      d1ddc24a
  27. 17 Oct, 2007 1 commit
    • unknown's avatar
      Fix for bug #31207: Test "join_nested" shows different strategy on IA64 · ce8bf087
      unknown authored
      CPUs / Intel's ICC compile
      
      The bug is a combination of two problems:
      
      1. IA64/ICC MySQL binaries use glibc's qsort(), not the one in mysys.
      
      2. The order relation implemented by join_tab_cmp() is not transitive,
      i.e. it is possible to choose such a, b and c that (a < b) && (b < c)
      but (c < a). This implies that result of a sort using the relation
      implemented by join_tab_cmp() depends on the order in which
      elements are compared, i.e. the result is implementation-specific. Since
      choose_plan() uses qsort() to pre-sort the
      join tables using join_tab_cmp() as a compare function, the results of
      the sorting may vary depending on qsort() implementation.
      
      It is neither possible nor important to implement a better ordering
      algorithm in join_tab_cmp(). Therefore the only way to fix it is to
      force our own qsort() to be used by renaming it to my_qsort(), so we don't depend
      on linker to decide that.
      
      This patch also "fixes" bug #20530: qsort redefinition violates the
      standard.
      
      
      include/my_sys.h:
        Renamed qsort() and qsort2() to my_qsort() and my_qsort2(). Since
        previously we relied on stdlib.h to provide a declaration for qsort(), a
        separate declaration for my_qsort() is now required.
      libmysql/Makefile.shared:
        Added mf_qsort.c to libmysql, since my_lib.c now uses my_qsort() instead of qsort().
      myisam/ft_boolean_search.c:
        Replaced qsort2() with my_qsort2().
      myisam/ft_nlq_search.c:
        Replaced qsort2() with my_qsort2().
      myisam/myisampack.c:
        Replaced qsort() with my_qsort().
      myisam/sort.c:
        Replaced qsort2() with my_qsort2().
      mysys/mf_keycache.c:
        Replaced qsort() with my_qsort().
      mysys/mf_qsort.c:
        Renamed qsort() to my_qsort() and qsort2() to my_qsort2().
      mysys/mf_sort.c:
        Replaced qsort2() with my_qsort2().
      mysys/my_lib.c:
        Replaced qsort() with my_qsort().
      mysys/queues.c:
        Replaced qsort2() with my_qsort2().
      sql/item_cmpfunc.cc:
        Replaced qsort2() with my_qsort2().
      sql/item_cmpfunc.h:
        Replaced qsort2() with my_qsort2().
      sql/opt_range.cc:
        Replaced qsort() with my_qsort().
      sql/records.cc:
        Replaced qsort() with my_qsort().
      sql/sql_acl.cc:
        Replaced qsort() with my_qsort().
      sql/sql_array.h:
        Replaced qsort() with my_qsort().
      sql/sql_help.cc:
        Replaced qsort() with my_qsort().
      sql/sql_select.cc:
        Replaced qsort() with my_qsort().
      sql/examples/ha_tina.cc:
        Replaced qsort() with my_qsort().
      sql/sql_table.cc:
        Replaced qsort() with my_qsort().
      ce8bf087
  28. 16 Oct, 2007 1 commit
  29. 09 Oct, 2007 1 commit
    • unknown's avatar
      Fix for bug #31249: Assertion `!table || (!table->write_set || · 1a5f13a1
      unknown authored
      bitmap_is_set(table->write_set, fiel
      
      Problem: creating a temporary table we allocate the group buffer if needed
      followed by table bitmaps (see create_tmp_table()). Reserving less memory for 
      the group buffer than actually needed (used) for values retrieval may lead 
      to overlapping with followed bitmaps in the memory pool that in turn leads 
      to unpredictable consequences.
      
      As we use Item->max_length sometimes to calculate group buffer size,
      it must be set to proper value. In this particular case 
      Item_datetime_typecast::max_length is too small.
      
      Another problem is that we use max_length to calculate the group buffer
      key length for items represented as DATE/TIME fields which is superfluous.
      
      Fix: set Item_datetime_typecast::max_length properly,
      accurately calculate the group buffer key length for items 
      represented as DATE/TIME fields in the buffer.
      
      
      mysql-test/r/type_datetime.result:
        Fix for bug #31249: Assertion `!table || (!table->write_set || 
        bitmap_is_set(table->write_set, fiel
          - test result.
      mysql-test/t/type_datetime.test:
        Fix for bug #31249: Assertion `!table || (!table->write_set || 
        bitmap_is_set(table->write_set, fiel
          - test case.
      sql/item_timefunc.h:
        Fix for bug #31249: Assertion `!table || (!table->write_set || 
        bitmap_is_set(table->write_set, fiel
          - set Item_datetime_typecast::max_length properly.
      sql/sql_select.cc:
        Fix for bug #31249: Assertion `!table || (!table->write_set || 
        bitmap_is_set(table->write_set, fiel
          - the group buffer key length for items represented as 
        DATE/TIME fields in the buffer should be calculated using
        the maximum pack length of such fields (== 8), using 
        max_length here is redundant.
      1a5f13a1
  30. 05 Oct, 2007 2 commits
    • unknown's avatar
      Bug #31094: Forcing index-based sort doesn't work anymore if joins are done · 10cde5e4
      unknown authored
      A rule was introduced by the 5.1 part of the fix for bug 27531 to 
      prefer filesort over indexed ORDER BY when accessing all of the rows of a 
      table (because it's faster). This new rule was not accounting for the 
      presence of a LIMIT clause.
      Fixed the condition for this rule so it will prefer filesort over 
      indexed ORDER BY only if no LIMIT.
      
      
      mysql-test/r/compress.result:
        Bug #31094: LIMIT is not considered a full index scan
      mysql-test/r/join.result:
        Bug #31094: test case
      mysql-test/r/select.result:
        Bug #31094: LIMIT is not considered a full index scan
      mysql-test/r/ssl.result:
        Bug #31094: LIMIT is not considered a full index scan
      mysql-test/r/ssl_compress.result:
        Bug #31094: LIMIT is not considered a full index scan
      mysql-test/t/join.test:
        Bug #31094: test case
      sql/sql_select.cc:
        Bug #31094: prefer filesort over indexed ORDER BY only if no LIMIT
      10cde5e4
    • unknown's avatar
      Fix for BUG#20550: Stored function: wrong RETURN type metadata · c215e78d
      unknown authored
      when used in a VIEW.
      
      The problem was that wrong function (create_tmp_from_item())
      was used to create a temporary field for Item_func_sp.
      
      The fix is to use create_tmp_from_field().
      
      
      mysql-test/r/sp.result:
        Update result file.
      mysql-test/t/sp.test:
        Add a test case for BUG#20550.
      sql/item_func.h:
        Add a getter for Item_func_sp::sp_result_field.
      sql/sql_select.cc:
        Use create_tmp_from_field() to create a temporary field
        for Item_func_sp.
      c215e78d
  31. 02 Oct, 2007 2 commits
  32. 28 Sep, 2007 2 commits
    • unknown's avatar
      Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used. · 6a8bd84a
      unknown authored
      The change_to_use_tmp_fields function leaves the orig_table member of an
      expression's tmp table field filled for the new Item_field being created.
      Later orig_table is used by the Field::make_field function to provide some
      info about original table and field name to a user. This is ok for a field
      but for an expression it should be empty.
      
      The change_to_use_tmp_fields function now resets orig_table member of
      an expression's tmp table field to prevent providing a wrong info to a user.
      The Field::make_field function now resets the table_name and the org_col_name
      variables when the orig_table is set to 0.
      
      
      sql/field.cc:
        Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used.
        The Field::make_field function now resets the table_name and the org_col_name
        variables when the orig_table is set to 0.
      sql/sql_select.cc:
        Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used.
        The change_to_use_tmp_fields function now resets orig_table member of
        an expression's tmp table field to prevent providing a wrong info to a user.
      tests/mysql_client_test.c:
        The test case for the bug#21635 is altered to test behavior on both const and
        non-const tables.
      6a8bd84a
    • unknown's avatar
      Bug#30665: Inconsistent optimization of IGNORE INDEX FOR {ORDER BY|GROUP BY} · 5a177308
      unknown authored
      The optimizer takes different execution paths during EXPLAIN than SELECT,
      this fix relates only to EXPLAIN, hence no behavior changes.
      The test of sort keys for ORDER BY was prohibited from considering keys
      that were mentioned in IGNORE KEYS FOR ORDER BY. This led to two 
      inconsistencies: One was that IGNORE INDEX FOR GROUP BY and 
      IGNORE INDEX FOR ORDER BY gave apparently different EXPLAINs; the latter 
      erroneously claimed to do filesort. The second inconsistency 
      is that the test of sort keys is called twice, finding a sort key the first
      time but not the second time, leading to the mentioned filesort.
      
      Fixed by making the test of sort keys consider all enabled 
      keys on the table. This test rejects keys that are not covering, and for 
      covering keys the hint should be ignored anyway. 
      
      
      mysql-test/r/group_by.result:
        Bug#30665: Changed test result. The plan gets more efficient here. 
        The output is included in order to show that it is still correct.
      mysql-test/r/order_by.result:
        Bug#30665: Test result
      mysql-test/t/group_by.test:
        Bug#30665: Changed test case to show correctness of changed plan
      mysql-test/t/order_by.test:
        Bug#30665: Test case
      sql/sql_select.cc:
        Bug#30665: 
        - the fix: Give test_if_skip_sort_order all keys not the subset of non-disabled keys.
        - Added comment to test_if_skip_sort_order
      5a177308