Commit graph

28019 commits

Author SHA1 Message Date
Michael Widenius
bf33056ef9 automatic merge with 5.2 2011-05-28 05:17:24 +03:00
Michael Widenius
f197991f41 Merge with 5.1-microseconds
A lot of small fixes and new test cases.

client/mysqlbinlog.cc:
  Cast removed
client/mysqltest.cc:
  Added missing DBUG_RETURN
include/my_pthread.h:
  set_timespec_time_nsec() now only takes one argument
mysql-test/t/date_formats.test:
  Remove --disable_ps_protocl as now also ps supports microseconds
mysys/my_uuid.c:
  Changed to use my_interval_timer() instead of my_getsystime()
mysys/waiting_threads.c:
  Changed to use my_hrtime()
sql/field.h:
  Added bool special_const_compare() for fields that may convert values before compare (like year)
sql/field_conv.cc:
  Added test to get optimal copying of identical temporal values.
sql/item.cc:
  Return that item_int is equal if it's positive, even if unsigned flag is different.
  Fixed Item_cache_str::save_in_field() to have identical null check as other similar functions
  Added proper NULL check to Item_cache_int::save_in_field()
sql/item_cmpfunc.cc:
  Don't call convert_constant_item() if there is nothing that is worth converting.
  Simplified test when years should be converted
sql/item_sum.cc:
  Mark cache values in Item_sum_hybrid as not constants to ensure they are not replaced by other cache values in compare_datetime()
sql/item_timefunc.cc:
  Changed sec_to_time() to take a my_decimal argument to ensure we don't loose any sub seconds.
  Added Item_temporal_func::get_time() (This simplifies some things)
sql/mysql_priv.h:
  Added Lazy_string_decimal()
sql/mysqld.cc:
  Added my_decimal constants max_seconds_for_time_type, time_second_part_factor
sql/table.cc:
  Changed expr_arena to be of type CONVENTIONAL_EXECUTION to ensure that we don't loose any items that are created by fix_fields()
sql/tztime.cc:
  TIME_to_gmt_sec() now sets *in_dst_time_gap in case of errors
  This is needed to be able to detect if timestamp is 0
storage/maria/lockman.c:
  Changed from my_getsystime() to set_timespec_time_nsec()
storage/maria/ma_loghandler.c:
  Changed from my_getsystime() to my_hrtime()
storage/maria/ma_recovery.c:
  Changed from my_getsystime() to mmicrosecond_interval_timer()
storage/maria/unittest/trnman-t.c:
  Changed from my_getsystime() to mmicrosecond_interval_timer()
storage/xtradb/handler/ha_innodb.cc:
  Added support for new time,datetime and timestamp
unittest/mysys/thr_template.c:
  my_getsystime() -> my_interval_timer()
unittest/mysys/waiting_threads-t.c:
  my_getsystime() -> my_interval_timer()
2011-05-28 05:11:32 +03:00
Vladislav Vaintroub
9ace4da571 merge 2011-05-27 19:05:35 +02:00
Igor Babaev
c9a349488b Applied Sanja's patch to fix LP bug #784297 in the tree for mwl106.
The patch imposes unconditional materialization for derived tables
used in update and multi-update statements.
Fixed a bug with a wrong order of processing derived tables/views
at the prepare stage that caused a crash for the variant of the 
query from test case for bug 52157.
2011-05-27 00:03:55 -07:00
Sergei Golubchik
34c9428871 fix for double or decimal to datetime conversion 2011-05-26 18:11:26 +02:00
Michael Widenius
73f78f7766 Fixed memory overrun in mysql_tzinfo_to_sql 2011-05-26 18:35:26 +03:00
Vladislav Vaintroub
192672d072 Fix line endings. 2011-05-26 13:42:22 +02:00
Sergey Petrunya
aa551f1b9e Post-merge fixes part#2 2011-05-26 15:01:26 +04:00
Sergey Petrunya
f0038da8f6 Post-merge fixes part #1. 2011-05-26 11:30:14 +04:00
Vladislav Vaintroub
decb9c639a Fixed sql_perror() to return appropriate error messages on Windows,
The error message is now based on GetLastError() rather than errno. 

Background: errno is C runtime specific and in many circumstances 
it is not set, e.g when using Win32 API or socket functions.
2011-05-26 02:01:47 +02:00
Vladislav Vaintroub
79afbf7646 On Windows, collect mysql error log with Windows Error Reporting.
This simplifies postmortem analysis for crashes reported via Winqual.
2011-05-26 00:37:08 +02:00
Sergey Petrunya
77b3b960b1 Merge MWL#90 with 5.3-main 2011-05-25 19:31:13 +04:00
unknown
8a314700f9 MWL#89 automatic merge with 5.3 2011-05-23 11:54:26 +03:00
unknown
742dfc92a2 MWL#89: Address review feedback (by Sergey Petrunia)
mysql-test/r/subselect4.result:
  Moved test case for LP BUG#718593 into the correct test file subselect_mat_cost_bugs.test.
mysql-test/t/subselect4.test:
  Moved test case for LP BUG#718593 into the correct test file subselect_mat_cost_bugs.test.
2011-05-23 10:56:05 +03:00
Igor Babaev
317e04ce67 Fixed 2 valgrind bugs in the tree for mwl #106.
One was due the fact that the field SELECT_LEX::insert_tables was not
initialized while the second was due to missing initialization of
JOIN_TAB::preread_init_done in subselect_hash_sj_engine::make_unique_engine. 
Removed an invalid assert.
2011-05-22 15:47:46 -07:00
Sergei Golubchik
306ed65302 unix_timestamp() and from_unixtime() supports microseconds.
unix_timestamp() and time_to_sec() are hybrid items,
  returning integer or double depending on the argument.
2011-05-22 11:58:48 +02:00
Igor Babaev
63d6dbc4ab Fixed 3 valgrind bugs.
Two of them (in the function make_join_statistics and in the function
sort_and_filter_keyuse) were due to bad merges while the third bug was
triggered by uninitialized values of the field JOIN_TAB::preread_init_done.

Fixed a compiler warning in mysql_priv.h.

Commented out some queries from the funcs_1 suite returning wrong
errors due to bugs concerning updatable views (see bugs 784297 and
784303).

Adjusted some results for the test cases with derived tables from
different suites.
2011-05-21 13:12:21 -07:00
Sergei Golubchik
dda9577d55 comments 2011-05-21 18:41:56 +02:00
Sergei Golubchik
7c459960ec db_low_byte_first is gone 2011-05-20 23:56:13 +02:00
Michael Widenius
f610296d98 Changed MariaDB error numbers to start from 1900 to not conflict with MySQL error numbers
extra/comp_err.c:
  Allow one to have multiple start-error-numbers in the same error.txt file.
  Generate 'empty' error strings for the missing error numbers in the errmsg.sys file
mysql-test/r/bigint.result:
  Update results to use new error numbers
mysql-test/r/dyncol.result:
  Update results to use new error numbers
mysql-test/r/func_math.result:
  Update results to use new error numbers
mysql-test/r/func_str.result:
  Update results to use new error numbers
mysql-test/r/plugin.result:
  Update results to use new error numbers
mysql-test/r/table_options.result:
  Update results to use new error numbers
mysql-test/r/type_newdecimal.result:
  Update results to use new error numbers
mysql-test/r/warnings.result:
  Update results to use new error numbers
mysql-test/suite/vcol/r/vcol_ins_upd_innodb.result:
  Update results to use new error numbers
mysql-test/suite/vcol/r/vcol_ins_upd_myisam.result:
  Update results to use new error numbers
mysql-test/suite/vcol/r/vcol_misc.result:
  Update results to use new error numbers
sql/derror.cc:
  Ensure we don't read a errmsg.sys with a missing required error message;  This change was needed as errmsg.sys may now contain empty error messages between the MySQL and MariaDB error messages.
  If error message file didn't exist and we have not read one in the past, don't continue.
  Give better error message if the errmsg.sys header has changed.
sql/share/errmsg.txt:
  Create new section, starting from 1900, for MariaDB error messages
2011-05-21 00:46:18 +03:00
Igor Babaev
89cf840cd9 Merge 2011-05-20 12:47:39 -07:00
Sergey Petrunya
be6d6e1b3e Fix a comment (unmatched '{' and '}' screw up jumping in advanced editors) 2011-05-20 19:52:24 +04:00
Michael Widenius
c9a0d7338c Ensure we don't read a MariaDB 5.3 errmsg.sys file or new errmsg.sys file with holes for not used error messages
sql/derror.cc:
  Ensure we don't read a MariaDB 5.3 errmsg.sys file with moved error messages or a new errmsg.sys file with holes for not used error messages
  If error message file didn't exist and we have not read one in the past, don't continue.
  Give better error message if the errmsg.sys header has changed.
2011-05-20 14:36:13 +03:00
Igor Babaev
d015b8fa0a Fixed a compiler warning. 2011-05-20 00:06:27 -07:00
Igor Babaev
aabb172f49 Fixed a compiler problem. 2011-05-19 23:13:50 -07:00
Sergey Petrunya
23cfe1261d Merge fix for BUG#784723 2011-05-20 10:13:02 +04:00
Igor Babaev
3d34cadac8 Merge 2011-05-19 20:03:33 -07:00
Igor Babaev
8e33aa9aa7 Merged the fix for bug 777745 into 5.3. 2011-05-19 20:01:43 -07:00
Igor Babaev
016a09cb7d Fixed LP bug #777745.
Fields belonging to views in general cannot be substituted for 
equal items, in particular for constants, because all references
to a view field refer to the same Item_field object while they 
could be used in different OR parts of the where condition and
belong to different equivalence classes (to different Item_equals).
That's why substitution for equal items in any context is allowed
only in place of Item_direct_view_ref objects, but not in place of
Item_fields these objects refer to.
Due to some erroneous code in the patch for bug 717577 substitution
for view fields were allowed in some context.This could lead
to wrong results returned by queries using views.

The fix prohibits substitution of view fields for equal items 
in any context.

The patch also changes slightly the compile method for the Item_func
class. Now if the analyze method returns NULL in his parameter the
compile method is not called for the arguments of the function
at all. A similar change was made for the Item_ref class.
2011-05-19 18:28:38 -07:00
Igor Babaev
2feb13cdb4 Merge 2011-05-19 17:02:47 -07:00
Vladislav Vaintroub
d7fb598c21 merge 2011-05-20 01:41:07 +02:00
Vladislav Vaintroub
f4ae8b7691 - Properly terminate options array with all-zero entry.
- Fix CRLF end of lines, use LF instead
2011-05-20 01:38:42 +02:00
Igor Babaev
98f2be0868 Fixed compiler warnings. 2011-05-19 16:04:01 -07:00
Vladislav Vaintroub
579f644360 Fix warnings 2011-05-20 00:44:21 +02:00
Igor Babaev
a19ddf0117 Fixed compiler warnings. 2011-05-19 14:53:16 -07:00
Sergey Petrunya
d1138283b9 BUG#784723: Wrong result with semijoin + nested subqueries in maria-5.3
- in advance_sj_state(), remember join->cur_dups_producing_tables in 
  pos->prefix_dups_producing_tables *before* we modify it, so that 
  restore_prev_sj_state() restores cur_dups_producing_tables in all cases.
- Updated test results in subselect_sj2[_jcl6].result (the original EXPLAIN
  was invalid there)
2011-05-20 01:05:06 +04:00
Igor Babaev
8ec03d805d Fixed crashes in the rpl suite due to a bug in Item_func_set_user_var::fix_fields.
Adjusted the result files in  the pbxt, innodb and innodb_plugin suites.

Commented out a failing test case in innodb.innodb_multi_update.test.
It should be returned back when the problem with multi-update of derived
tables (bug 784297) is resolved.
2011-05-19 12:26:09 -07:00
Sergei Golubchik
8767540a43 microseconds in log tables:
TIMESTAMP -> TIMESTAMP(6)
  TIME -> TIME(6)
in general_log and slow_log tables.

include/my_sys.h:
  use constants
2011-05-19 19:19:44 +02:00
Sergei Golubchik
f06cac336b post review changes 2
sql/event_parse_data.cc:
  don't use "not_used" variable
sql/item_timefunc.cc:
  Item_temporal_func::fix_length_and_dec()
  and other changes
sql/item_timefunc.h:
  introducing Item_timefunc::fix_length_and_dec()
sql/share/errmsg.txt:
  don't say "column X" in the error message that used not only for columns
2011-05-19 19:16:17 +02:00
Sergei Golubchik
03b33425e5 many changes to my_getsystime.c:
* my_getsystime() is only an interval timer. Its value can beused for calculating
  time intervals.
* renamed my_getsystime() to my_interval_timer(), to make the semantics
  clearer and let the compiler catch wrong usages of my_getsystime()
  (also future ones, that may come in merges).
* increased its granularity from 100ns to 1ns, old value was for UUID,
  but as UUID can no longer use it directly there is no need to downgrade
  the OS provided value
* fixed the UUID code to anchor the my_interval_timer() on the epoch, as
  required by the UUID standard. That is, this was only needed by UUID,
  and now I've moved it to UUID code from my_getsystime().
* fixed other wrong usages of my_getsystime() - e.g. in calculating
  times for pthread_cond_timedwait. It was buggy and could've caused
  long waits if OS clock would be changed.
2011-05-19 19:05:35 +02:00
Sergei Golubchik
8ddcd0cda8 post-review changes 1
include/my_time.h:
  remove duplicate defines.
  cast to ulonglong to avoid overflow
sql/field.cc:
  perform sign extension when reading packed TIME values
sql/item_cmpfunc.cc:
  when converting a string to a date for the purpose of comparing it with another date,
  we should ignore strict sql mode.
sql/item_timefunc.cc:
  better error message
sql/item_timefunc.h:
  limit decimals appropriately
sql/share/errmsg.txt:
  don't refer to an object as a "column" in error messages that are used not only for columns.
2011-05-19 19:01:46 +02:00
Michael Widenius
54a3d1869c Automatic merge 2011-05-19 19:23:06 +03:00
Michael Widenius
29b751c796 Updated comments as part of code review
.bzr-mysql/default.conf:
  5.2 -> 5.3
sql/handler.h:
  Updated comments.
2011-05-19 18:14:02 +03:00
Michael Widenius
4e968b1ec5 Fix based on suggestion by Zardosht Kasheff and Richard Prohaska) for making all clustered indexes equal in test_if_skip_sort_order()
sql/sql_select.cc:
  - Threat all clustered indexes equal in test_if_skip_sort_order().
    This is a temporary fix as the current code doesn't do proper cost analyizes for which index to use.
    I will address this later as the change required is not trivial.
  - Fixed a bug where select_limit was changed in the loop, which made different indexes see diferent values of select_limit
2011-05-19 16:37:57 +03:00
Igor Babaev
6d2da32461 Fixed LP bug #784848 that caused failures of func_str.test and
derived_view.test.
Do not register Item_ref objects of the type VIEW_REF as outer
references.
2011-05-18 22:36:33 -07:00
Michael Widenius
3631146442 Original idea from Zardosht Kasheff to add HA_CLUSTERED_INDEX
- Added a lot of code comments
- Updated get_best_ror_intersec() to prefer index scan on not clustered keys before clustered keys.
- Use HA_CLUSTERED_INDEX to define if one should use HA_MRR_INDEX_ONLY
- For test of using index or filesort to resolve ORDER BY, use HA_CLUSTERED_INDEX flag instead of primary_key_is_clustered()
- Use HA_TABLE_SCAN_ON_INDEX instead of primary_key_is_clustered() to decide if ALTER TABLE ... ORDER BY will have any effect.

sql/ha_partition.h:
  Added comment with warning for code unsafe to use with multiple storage engines at the same time
sql/handler.h:
  Added HA_CLUSTERED_INDEX.
  Documented primary_key_is_clustered()
sql/opt_range.cc:
  Added code comments
  Updated get_best_ror_intersec() to ignore clustered keys.
  Optimized away cpk_scan_used and one instance of current_thd (Simpler code)
  Use HA_CLUSTERED_INDEX to define if one should use HA_MRR_INDEX_ONLY
sql/sql_select.cc:
  Changed comment to #ifdef
  For test of using index or filesort to resolve ORDER BY, use HA_CLUSTERED_INDEX flag instead of primary_key_is_clustered()
  (Change is smaller than what it looks beause of indentation change)
sql/sql_table.cc:
  Use HA_TABLE_SCAN_ON_INDEX instead of primary_key_is_clustered() to decide if ALTER TABLE ... ORDER BY will have any effect.
storage/innobase/handler/ha_innodb.h:
  Added support for HA_CLUSTERED_INDEX
storage/innodb_plugin/handler/ha_innodb.cc:
  Added support for HA_CLUSTERED_INDEX
storage/xtradb/handler/ha_innodb.cc:
  Added support for HA_CLUSTERED_INDEX
2011-05-18 19:26:30 +03:00
unknown
1177bea2f1 Rewritten patch of percona - switching query cache on and off, removing comments.
client/mysqltest.cc:
  Column names.
mysql-test/r/grant_cache_no_prot.result:
  fix of text.
mysql-test/r/grant_cache_ps_prot.result:
  Fix of test.
mysql-test/r/query_cache.result:
  Switching on and off query cache.
mysql-test/t/query_cache.test:
  Switching on and off query cache.
mysys/charset.c:
  Fix of parser.
sql/handler.cc:
  thd added to parameters.
sql/log_event.cc:
  thd added to parameters.
sql/log_event_old.cc:
  thd added to parameters.
sql/mysql_priv.h:
  Fixed functions definitions.
sql/mysqld.cc:
  Comments stripping.
sql/set_var.cc:
  Switching on and off query cache.
sql/set_var.h:
  Switching on and off query cache.
sql/share/errmsg.txt:
  New errors.
sql/sql_cache.cc:
  Switching query cache on and off, removing comments.
sql/sql_cache.h:
  thd added to parameters.
sql/sql_class.h:
  Comments stripping.
sql/sql_db.cc:
  thd added to parameters.
sql/sql_lex.cc:
  lex fixed.
sql/sql_parse.cc:
  thd added to parameters.
2011-05-18 16:27:19 +03:00
Michael Widenius
5c70f813f3 Added HA_ERR_DISK_FULL handler error
Original code by Zardosht Kasheff

sql/handler.cc:
  Added HA_ERR_DISK_FULL and ENOSPC (for handler that uses normal errno).
  This sets 'fatal_error' to ensure that the error is logged to err file (which hopefully is on another disk...)
2011-05-18 13:36:12 +03:00
Igor Babaev
1018c90107 Fixed LP bug #784281.
When a view is merged into a select all the depended_from fields
pointing to the select of the view should have been corrected to
point to the select where the view is used. It was not done yet.
This could lead to wrong results returned by queries such as
one from the test case for bug 33389.
Correction of outer references required walking through all items
of the proccesed qurery. To avoid this the following solution was
implemented.
Each select now contains a pointer to the select it is merged into
(if there is any). Such pointers allow to get the corrected value
of depended_from on the fly. The function Item_ident::get_depended_from
was introduced for this purpose.
2011-05-17 22:22:33 -07:00
unknown
56c0e19ed0 MWL#89 Addressing Sergey's review comments - Part 1.
Address the 'trivial' part of Sergey's review of MWL#89.
2011-05-18 01:23:22 +03:00
Michael Widenius
0da2df248b Removed some alias warnings
Fixed alias bug when compiling with gcc 4.2.4 that caused subselect.test to fail

sql/item.cc:
  Removed alias warnings by changing type from char * to const char*
sql/item.h:
  Removed alias warnings by changing type from char * to const char*
sql/item_subselect.cc:
  Fixed alias bug when compiling with gcc 4.2.4 that caused subselect.test to fail
sql/sql_string.h:
  Removed alias warnings by changing type from char * to const char*
storage/heap/hp_test2.c:
  Removed SAFEMALLOC to get rid of compiler error
  Fixed test case as we can't anymore use heap_rlast() on a HASH key entry.
2011-05-18 00:47:56 +03:00
unknown
c22045aa59 MWL#89 - automatic merge with 5.3 2011-05-17 14:56:02 +03:00
Igor Babaev
704f97035f Merged the code of MWL#106 into 5.3
Resolved all conflicts, bad merges and fixed a few minor bugs in the code.
Commented out the queries from multi_update, view, subselect_sj, func_str,
derived_view, view_grant that failed either with crashes in ps-protocol or
with wrong results.
The failures are clear indications of some bugs in the code and these bugs
are to be fixed.
2011-05-16 22:39:43 -07:00
unknown
4a9c027ad8 Fix LP BUG#778413
Analysis:
The subquery is evaluated first during ref-optimization of the outer
query because the subquery is considered constant from the perspective
of the outer query. Thus an attempt is made to evaluate the MAX subquery
and use the new constant to drive an index nested loops join.
During this evaluation the inner-most subquery replaces the JOIN_TAB
with a new one that fetches the data from a temp table.
The function select_describe crashes at the lines:
        TABLE_LIST *real_table= table->pos_in_table_list; 
	item_list.push_back(new Item_string(real_table->alias,
					    strlen(real_table->alias),
					    cs));
because 'table' is a temp table, and it has no corresponding table
reference. This 'real_table' is NULL, and real_table->alias results
in a crash.

Solution:
In the spirit of MWL#89 prevent the evaluation of expensive predicates
during optimization. This patch prevents the evaluation of expensive
predicates during ref optimization.


sql/item_subselect.h:
  Remove unused class member. Not needed for the fix, but noticed now and removed.
2011-05-17 00:00:11 +03:00
Michael Widenius
8543621fa0 Merge with 5.3 main 2011-05-16 15:07:04 +03:00
Michael Widenius
f458e198c0 Merge with 5.2 2011-05-16 14:05:45 +03:00
Vladislav Vaintroub
b898022a6d Fix compile error on Unixes
my_rwlock_destroy=>rwlock_destroy
2011-05-14 18:59:06 +02:00
Vladislav Vaintroub
8a376ae237 LPBUG#782223 : Memory released by Query_cache::resize() or Query_cache::free() contains active rwlocks.
The bug was found by application verifier. 
Fixed by destroying locks prior to free(),
2011-05-14 18:37:20 +02:00
unknown
b757f73492 Fix LP BUG#777597
Analysis:
During optimization of the subquery, in the call chain:

update_ref_and_keys -> add_key_fields ->
merge_key_fields -> Item_direct_ref::is_null -> Item_cache::is_null

The call to Item_cache::is_null() returns TRUE, which is wrong.
This results in Item_null replacing the field 'f3' in the KEY_FIELD,
then this Item_null is used for index access, producing a wrong result.

The reason why Item_cache::is_null returns wrong result is that
this Item_cache object is a cache of the left operand of IN, and was
updated in Item_in_optimizer::val_int. In MWL#89 the latter method is
called during the execution phase, which is after we optimize the subquery.
Therefore during the optization phase the left operand cache of IN was
not updated.

Solution:
Update the left operand cache during optimization if it is a constant.

This bug fix also discoveres and fixes a wrong IF statement in
convert_constant_item().
2011-05-13 18:37:28 +03:00
Vladislav Vaintroub
1779c2adbf merge 2011-05-12 16:31:54 +02:00
Vladislav Vaintroub
984fa23b45 merge 2011-05-12 15:39:54 +02:00
Vladislav Vaintroub
1c95254523 Fix check_table_file_presence:
On Windows, do not attempt access() for special device names like
CON, PRN etc. access() would return 0, this does not mean that fiile
with this name exists.
2011-05-12 15:31:11 +02:00
Oleksandr Byelkin
84505e6e3a db_name can change case, so we need copy of it for case insensitive FS. 2011-05-12 14:56:08 +03:00
Michael Widenius
f09f1c7c7d Merge with dynamic column code 2011-05-12 14:30:34 +03:00
Michael Widenius
4c81cef75d Fixed bug when accessing wrong decimal value in dynamic string (Fixed lp:781233)
Store decimal 0.0 in zero bytes in dynamic strings.
mysqltest: Don't ignore error from mysql_stmt_fetch;  This could cause rows to be missing from log when running with --ps-protocol
Fixed wrong result length for CAST(... as TIME)






client/mysqltest.cc:
  Don't ignore error from mysql_stmt_fetch;  This could cause rows to be missing from log when running with --ps-protocol
libmysql/libmysql.c:
  The max length for a TIME column is 17, not 15.
mysql-test/r/dyncol.result:
  More tests
mysql-test/t/dyncol.test:
  More tests
mysys/ma_dyncol.c:
  Check content of decimal value on read and store to not get assert in decimal_bin_size().
  Store decimal 0.0 in zero bytes in dynamic strings. This also solves a problem where decimal 0 had different internal representations.
sql-common/my_time.c:
  Fixed DBUG_PRINT
sql/item_timefunc.h:
  Fixed wrong result length for CAST(... as TIME). This was the cause of failures in buildbot when doing cast(... as time);
sql/protocol.cc:
  More DBUG_PRINT
2011-05-12 02:19:28 +03:00
unknown
8840823369 Automatic merge with MWL148 2011-05-12 01:02:55 +03:00
unknown
18d08eeacc Post review fixes of MWL#148 (moving max/min optimization in optimize phase).
sql/item_subselect.cc:
  Cleanup. Comments added.
sql/item_subselect.h:
  Cleanup.
sql/mysql_priv.h:
  Comments added.
sql/opt_subselect.cc:
  The function renamed and turned to method.
  Comments added.
sql/opt_subselect.h:
  The function turned to method of JOIN.
sql/sql_select.cc:
  Comment added. The function turned to method.
sql/sql_select.h:
  The function turned to method.
2011-05-12 00:14:15 +03:00
unknown
520927a7df Bugfix: New table creation/renaming block added if old encoded table present.
mysql-test/r/create.result:
  test of renaming
mysql-test/r/upgrade.result:
  Now such behaviour prohibited to avoid problems.
mysql-test/t/create.test:
  test of renaming
mysql-test/t/upgrade.test:
  Now such behaviour prohibited to avoid problems.
sql/mysql_priv.h:
  Function to test table name presence added.
sql/sql_rename.cc:
  Rename fixed.
sql/sql_table.cc:
  Function to test table name presence added.
  Create fixed.
2011-05-11 14:09:48 +03:00
Michael Widenius
8d52c2cffe Fixed compiler warnings and test cases problems found by buildbot
mysql-test/r/dyncol.result:
  Updated test results
mysql-test/r/index_intersect.result:
  Updated results
mysql-test/r/index_intersect_innodb.result:
  Updated results
mysql-test/t/dyncol.test:
  Added replace_result for floating point results that are different on windows
  Added round() around a result to get same result on all platforms.
mysql-test/t/index_intersect.test:
  Added replace_result to fix that index_merge may put key names in different order.
mysys/ma_dyncol.c:
  Fixed compiler warnings on Solaris
sql/key.cc:
  Fixed compiler warnings on Solaris
sql/mysqld.cc:
  Fixed compiler warning on windows
support-files/compiler_warnings.supp:
  Suppressed an unintersting warning on Solaris
2011-05-11 13:59:17 +03:00
Sergey Petrunya
0a5026b057 Merge fix for BUG#779885 2011-05-11 08:52:16 +01:00
Michael Widenius
052d1bfb1a Fixed all reported bugs for dynamic columns.
Bugs fixed:
- Added automatic detection of unsigned arguments to COLUMN_CREATE()
- If string length is not know for COLUMN_GET() use MAX_DYNAMIC_COLUMN_LENGTH instead of MAX_FIELD_BLOBLENGTH
- null_value flag was not propery reset for COLUMN_LIST() and COLUMN_CREATE() which could lead to crashes later:
- lp:778905 Assertion `value->year <= 9999' failed in dynamic_column_date_store
- lp:778912 Assertion `field_pos < field_count' failed in Protocol_text::store in maria-5.3-mwl34

include/ma_dyncol.h:
  Added define for max dynamic column length.
mysql-test/r/cast.result:
  Added test of cast big unsigned int to signed (this test case was missing)
mysql-test/r/dyncol.result:
  Added tests from reported bugs
  Added testing of automatic store of signed/unsigned integers
mysql-test/t/cast.test:
  Added test of cast big unsigned int to signed (this test case was missing)
mysql-test/t/dyncol.test:
  Added tests from reported bugs
  Added testing of automatic store of signed/unsigned integers
sql/item.cc:
  Added assert to catch cases where null_value is not set properly
sql/item_strfunc.cc:
  Added automatic detection of unsigned arguments to COLUMN_CREATE()
  COLUMN_GET() returned wrong value for illegal strings which lead to assert later
  null_value flag was not propery reset for COLUMN_LIST() and COLUMN_CREATE() which could lead to crashes later.
sql/item_strfunc.h:
  If string length is not know for COLUMN_GET() use MAX_DYNAMIC_COLUMN_LENGTH
2011-05-11 02:41:02 +03:00
Sergey Petrunya
30575353b6 BUG#779885: Crash in eliminate_item_equal with materialization=on in maria-5.3
- In eliminate_item_equal(), we could end up in a situation where:
  = The multiple equality has a constant C1 (and so it is the "head item")
  = The join order was such that we've generated "sj_inner_table1=C1" equality,
    and now are looking to generate "sj_inner_table2_=..." equality. 
  When looking for what should be the other member of equality, we run

      Item *head_item= current_sjm? current_sjm_head: head;
  
  which sees current_sjm!=NULL, and takes current_sjm_head (which is NULL because 
  the constant C1 is the head for all cases).

- Fixed in a trivial way: take current_sjm_head if we don't have constant.
2011-05-10 21:59:51 +01:00
unknown
4aa1ad2b6d merge 2011-05-10 23:20:35 +03:00
Sergei Golubchik
e343a2c134 small enhancement of the create table options feature:
no unnecessary casting from void*, more type safety.
typos fixed.
2011-05-10 18:19:11 +02:00
unknown
a55b1165d2 MWL#89 - Automatic merge with 5.3 2011-05-10 18:28:05 +03:00
Michael Widenius
f34be18938 Merge with MariaDB 5.2 2011-05-10 18:17:43 +03:00
Sergey Petrunya
f34b421839 Code cleanup, added comments. 2011-05-10 11:31:02 +01:00
Sergey Petrunya
8d29fddb97 BUG#780359: Crash with get_fanout_with_deps in maria-5.3-mwl90
- Handle the case of degenerate joins. When join has impossible WHERE clause,
  a number of its members, including JOIN::map2table, are not initialized. 
  Do not try accessing them, detect degenerate joins early.
2011-05-10 11:10:21 +01:00
Sergey Petrunya
34a5646de5 MWL#90: auto-merge with 5.3-main 2011-05-09 23:00:03 +01:00
Sergey Petrunya
73ff163511 Merge 2011-05-09 22:55:44 +01:00
Sergey Petrunya
70952a554d MWL#90: Non-merged semi-joins
- Fix trivial bugs in post-GROUP-BY output cardinality calculations
- Add testcases
2011-05-09 20:11:36 +01:00
unknown
e1ceb8048c Automatic merge Mariadb 5.1->5.2. 2011-05-09 15:09:40 +02:00
unknown
e2ff288531 Fix buildbot failure in rpl_stop_slave.test.
Problem was setting DEBUG_SYNC twice in a row too fast in the test case; this
could cause the second setting to override the first before the code had time
to react to the first, causing the signal to get lost.

Fixed by waiting for the code to receive the first signal before overwriting
it in the test case.
2011-05-09 15:06:16 +02:00
Michael Widenius
8882d71f3f Make event stop code even more robust.
(Test failed if we added my_sleep(200000) in event_queue::cond_wait() just before pthread_cond_wait();  Not likely scenario but better to get that fixed too)
2011-05-09 15:14:04 +03:00
Michael Widenius
4cb68c0e89 mysqltest: Write command to be executed to the log BEFORE executing the command.
Fixed race condition in event that could cause hang when stopping event scheduler with SET GLOBAL event_scheduler=OFF 

client/mysqltest.cc:
  Write command to be executed to the log BEFORE executing the command.
  This makes it easier to debug crashes as the log will contain the fatal command.
mysql-test/r/mysqltest.result:
  Updated results (we now get more things logged)
sql/event_queue.cc:
  Fixed race condition in event that could cause hang when stopping event scheduler with SET GLOBAL event_scheduler=OFF.
  The reason was that a kill signal could be sent between last check of thd->killed and before thd->enter_cond() in which case the signal
  would be missed and we would be stuck in Event_scheduler::stop() forever.
2011-05-09 14:38:49 +03:00
Sergey Petrunya
76fd8c1c2f Change "disable semi-joins in presense of outer joins" check to actually
check for outer joins (and not for any "t1 SOME_JOIN t2 ON cond" syntax).
2011-05-09 11:20:51 +01:00
Sergey Petrunya
524e6aad73 MWL#90: Non-merged semi-joins
- Take into account that grouping or aggregates decrease join output cardinality.
  (First code, can't make use of index statistics yet)
2011-05-09 10:35:55 +01:00
Michael Widenius
03483e7bfd Merge with main 5.3 2011-05-08 14:46:32 +03:00
Michael Widenius
e843297d12 Fixed compiler warnings 2011-05-08 13:26:07 +03:00
Michael Widenius
5ab92b1f85 Adding support for Dynamic columns (WL#34):
- COLUMN_CREATE(column_nr, value, [column_nr,value]...)
- COLUMN_ADD(blob,column_nr, value, column_nr,value]...)
- COLUMN_DELETE(blob, column_nr, column_nr...)
- COLUMN_EXISTS(blob, column_nr)
- COLUMN_LIST(blob, column_nr)
- COLUMN_GET(string, column_nr AS type)

Added cast(X as DOUBLE) and cast(x as INT)
Better warning and error messages for wrong cast's
Created some sub functions to simplify and reuse code.
Added a lot of conversation functions with error/warnings for what went wrong.
Fixed some issues when casting time to datetime.
Added functions to dynamic strings and Strings to allow one to move a string buffer from dynamic strings to String (to save malloc+ copy)
Added dynamic columns library to libmysqlclient


include/Makefile.am:
  Added ma_dyncol.h
include/decimal.h:
  Added 'const' to arguments for some functions.
include/my_sys.h:
  Added dynstr_reassociate()
include/my_time.h:
  Added TIME_SUBSECOND_RANGE
  Added double_to_datetime()
  Added flag argument to str_to_time()
libmysql/CMakeLists.txt:
  Added mysys/ma_dyncol.c
libmysql/Makefile.shared:
  Added ma_dyncol
libmysql/libmysql.c:
  Added argument to str_to_time()
mysql-test/r/bigint.result:
  Better error messages
mysql-test/r/cast.result:
  Better warning and error messages
  A lot of new cast() tests
mysql-test/r/func_math.result:
  Better warning messages
mysql-test/r/func_str.result:
  Better warning messages
mysql-test/r/func_time.result:
  Better warning messages
mysql-test/r/sp-vars.result:
  Better warning messages
mysql-test/r/strict.result:
  Better warning messages
  New test result
mysql-test/r/type_newdecimal.result:
  Better warning messages
mysql-test/r/warnings.result:
  Better warning messages
mysql-test/suite/funcs_1/r/innodb_func_view.result:
  Updated results after better cast warnings
mysql-test/suite/funcs_1/r/memory_func_view.result:
  Updated results after better cast warnings
mysql-test/suite/funcs_1/r/myisam_func_view.result:
  Updated results after better cast warnings
mysql-test/suite/optimizer_unfixed_bugs/t/bug43448.test:
  Added begin...commit to speed up test.
mysql-test/suite/parts/inc/part_supported_sql_funcs_delete.inc:
  Added begin...commit to speed up test.
mysql-test/suite/parts/inc/partition_supported_sql_funcs.inc:
  Added begin...commit to speed up test.
mysql-test/suite/parts/r/part_supported_sql_func_innodb.result:
  Added begin...commit to speed up test.
mysql-test/suite/parts/r/part_supported_sql_func_myisam.result:
  Added begin...commit to speed up test.
mysql-test/suite/parts/r/rpl_partition.result:
  Added begin...commit to speed up test.
mysql-test/suite/parts/t/part_supported_sql_func_innodb.test:
  Removed duplicated --big_test
mysql-test/suite/parts/t/rpl_partition.test:
  Added begin...commit to speed up test.
mysql-test/suite/pbxt/r/cast.result:
  Updated results after better cast warnings
mysql-test/suite/pbxt/r/func_str.result:
  Updated results after better cast warnings
mysql-test/suite/pbxt/r/type_newdecimal.result:
  Updated results after better cast warnings
mysql-test/suite/rpl/r/rpl_innodb_bug28430.result:
  Added begin...commit to speed up test.
mysql-test/suite/rpl/t/rpl_innodb_bug28430.test:
  Added begin...commit to speed up test.
mysql-test/suite/vcol/r/vcol_supported_sql_funcs_innodb.result:
  More warnings
mysql-test/suite/vcol/r/vcol_supported_sql_funcs_myisam.result:
  More warnings
mysql-test/t/cast.test:
  A lot of new cast() tests
mysql-test/t/strict.test:
  Added new test
mysys/CMakeLists.txt:
  Added ma_dyncol.c
mysys/Makefile.am:
  Added ma_dyncol.c
mysys/string.c:
  Added dynstr_reassociate() to move a buffer from dynamic_strings to some other allocator
sql-common/my_time.c:
  Added 'fuzzydate' flag to str_to_time()
  Added support for microseconds to my_time_to_str() and my_datetime_to_str()
  Reset second_parts in number_to_datetime()
  Added double_to_datetime()
sql/field.cc:
  Added double_to_longlong() and truncate_double() to simplify and reuse code
sql/field.h:
  New prototypes
sql/item.cc:
  Changed Item::get_date(MYSQL_TIME *ltime,uint fuzzydate) to be aware of type of argument.
  (Needed to make it microsecond safe and get better warnings).
  Updated call to str_to_time_with_warn()
sql/item.h:
  Added struct st_dyncall_create_def used by dynamic columns
  Added virtual bool dynamic_result() to tell if type of argument may change over calls.
sql/item_cmpfunc.cc:
  Added Item_func_dyncol_exists()
sql/item_cmpfunc.h:
  Added class Item_func_dyncol_exists
sql/item_create.cc:
  Added get_length_and_scale() to simplify other functions
  Simplified and extended create_func_cast()
  Added support for cast(X as double(X,Y))
  Added functions to create dynamic column functions.
sql/item_create.h:
  Added prototypes
sql/item_func.cc:
  Extended cast functions Item_func_signed() and Item_func_unsigned() to work with dynamic types
  Added Item_double_typecast()
sql/item_func.h:
  Added class Item_double_typecast()
sql/item_strfunc.cc:
  Added functions for COLUMN_CREATE(), COLUMN_ADD(), COLUMN_GET() and COLUMN_LIST()
sql/item_strfunc.h:
  Added classes for COLUMN_CREATE(), COLUMN_ADD(), COLUMN_GET() and COLUMN_LIST()
sql/item_timefunc.cc:
  Added flag argument to str_to_time_with_warn()
  Updated Item_char_typecast() to handle result type that may change between calls (for dynamic columns)
  Added Item_time_typecast::get_date() to ensure that we cast a datetime to time properly.
sql/item_timefunc.h:
  Added get_date() to Item_time_typecast() to allow proper results for casting time to datetime
sql/lex.h:
  Added new SQL function names
sql/my_decimal.cc:
  Added 'const' to some arguments.
  Better error message in case of errors (we now print out the wrong value)
  Added my_decimal2int()
sql/my_decimal.h:
  Moved some constants to my_decimal_limits.h
  Updated prototypes.
  Made my_decimal2int() a function as it's rather long (no reason to have it inline)
  Added decimal2my_decimal() function.
sql/mysql_priv.h:
  Prototypes for new functions
sql/share/errmsg.txt:
  New error messages for wrong casts and dynamic columns
sql/sql_acl.cc:
  Fixed indentation
sql/sql_base.cc:
  Added dynamic_column_error_message()
sql/sql_string.h:
  Added reassociate() to move a buffer to be owned by String object.
sql/sql_yacc.yy:
  Added syntax for COLUMN_ functions.
sql/time.cc:
  Updated str_to_datetime_with_warn() flag argument to same type as other functions
  Added conversion flag to str_to_time_with_warn() (Similar to all datetime functions)
  Added conversion functions with warnings: double_to_datetime_with_warn() and decimal_to_datetime_with_warn()
strings/decimal.c:
  Added 'const' to arguments for some functions.
unittest/mysys/Makefile.am:
  Added test for dynamic columns code
2011-05-08 13:24:06 +03:00
Vladislav Vaintroub
ba87d4810a Fix effect of recent mismerge (it made default pid file name ".pid" instead of "hostname.pid") 2011-05-07 19:27:07 +02:00
unknown
183d6b7025 Merge MWL#180 into main MariaDB 5.3. 2011-05-07 15:48:45 +02:00
Oleksandr Byelkin
f9b3f94b5d Merge 2011-05-06 14:45:47 +03:00
unknown
9789c94349 MWL#180: Merge bugfix from 5.2 to 5.3 codebase + really fix version from which mariadb supports binlog checksums. 2011-05-05 16:35:02 +02:00
unknown
4337aa74e3 MWL#180: Fix bug where setting @@global.binlog_checksum did not actually change the value. 2011-05-05 16:32:20 +02:00
unknown
ee3b7b56e4 Fix LP BUG#772309
Analysis:
The method st_select_lex::optimize_unflattened_subqueries()
incorrectly propagated to each subquery the complete
select_options flag set for the whole query. Among other
flags in select_options, this propagated incorrectly the
STRAIGHT_JOIN flag from the upper query to the subquery.

Solution:
During EXPLAIN set only the SELECT_DESCRIBE bit in the
select_options of the subquery.
2011-05-05 15:24:28 +03:00
Igor Babaev
20c9084deb Fixed LP bug #776295.
If the value of the flag cond_false of an Item_equal object is
true then the print method must return the string '0'.
2011-05-04 18:08:44 -07:00
unknown
879f25dc64 MWL#89
Merge with main 5.3
2011-05-05 00:35:21 +03:00
Michael Widenius
4249382a65 Automatic merge 2011-05-04 22:33:18 +03:00
Michael Widenius
718ddbb2ca Automatic merge with 5.1 2011-05-04 22:25:56 +03:00
Michael Widenius
3c9ae014ca Fixed build errors on centos5-amd64-minimal, where we compile with very few character sets
Fixed compiler warnings

client/readline.cc:
  Fixed compiler warning
mysql-test/t/mysqldump.test:
  Only run test if utf8 is used
sql/log.cc:
  Fixed compiler warning
sql/mysql_priv.h:
  Fixed compiler warnings
tests/mysql_client_test.c:
  Don't abort test if ucs2 is not in use.
2011-05-04 21:28:02 +03:00
Igor Babaev
e3e2358fd2 Fixed LP bug #751350.
The third parameter in the call of make_cond_for_table() that
built the pushed condition containing only outer references
was incorrect. This condition appeared for the first time in
the patch fixing bug 729039.
2011-05-04 11:23:29 -07:00
Oleksandr Byelkin
7b797fe66d Moving max/min optimization from prepare to optimization phase. MWL#148
mysql-test/r/explain.result:
  fixed results (new item)
mysql-test/r/subselect.result:
  fixed results (new item)
mysql-test/r/subselect_no_mat.result:
  fixed results (new item)
mysql-test/r/subselect_no_opts.result:
  fixed results (new item)
mysql-test/r/subselect_no_semijoin.result:
  Fixed results (new item)
mysql-test/suite/pbxt/r/subselect.result:
  Fixed results (new item)
mysql-test/t/explain.test:
  Fixed results (correct behaviour)
sql/item_cmpfunc.cc:
  Pass through  for max/min
sql/item_subselect.cc:
  moving max/min
sql/item_subselect.h:
  moving max/min
sql/mysql_priv.h:
  new uncacheble flags added
sql/opt_subselect.cc:
  maxmin moved.
sql/opt_subselect.h:
  New function for maxmin.
sql/sql_class.h:
  debug code
sql/sql_lex.cc:
  Fixed flags.
  Limit setting fixed.
sql/sql_lex.h:
  2 new flags.
sql/sql_select.cc:
  Prepare divided on 2 function to be able recollect some info after transformation.
sql/sql_select.h:
  Prepare divided on 2 functions.
2011-05-04 18:08:58 +03:00
Vladislav Vaintroub
e4732a765e fix noisy warnings in header files 2011-05-04 14:47:27 +02:00
unknown
c7f0fd6592 Automatic merge with 5.3 2011-05-04 12:00:18 +03:00
Igor Babaev
aaf9fb0de7 Fixed LP bug #776274,
The bug was introduced by the patch that fixed bug 717577.
2011-05-03 17:11:45 -07:00
Michael Widenius
1be5462d59 Merge with MariaDB 5.1 2011-05-03 19:10:10 +03:00
unknown
284f52476c Merge MWL#180, binlog checksum backport, into MariaDB 5.3-based tree. 2011-05-03 14:44:25 +02:00
unknown
014b8e7f43 Backport MySQL WL#2540 into MariaDB.
Patch backported:

bzr diff
'-rrevid:alfranio.correia@oracle.com-20101121143257-se3vpqus73l4mum0
..revid:luis.soares@oracle.com-20101124111752-9b8260bd1qak87hr'
--old=lp:mysql-server --new=lp:mysql-server
2011-05-03 14:01:11 +02:00
unknown
5dc11616b2 MWL#89
Merge with 5.3
2011-05-02 21:59:16 +03:00
Michael Widenius
e415ba0fb2 Merge with MySQL 5.1.57/58
Moved some BSD string functions from Unireg
2011-05-02 20:58:45 +03:00
Sergey Petrunya
ea43df7685 - Release build: Fix compiler warning about unused variable
- Debug build: make DBUG_ASSERT statements really look at the first table

One can't expect cursors to work with semi-join subqueries anyway, 
though (which isn't a problem because cursors are not used anywhere)
2011-04-30 12:28:27 +02:00
Igor Babaev
80b0b300f6 Merge 2011-04-29 19:20:46 -07:00
Sergey Petrunya
3098c21b8f Merge MWL#90 into 5.3-main 2011-04-30 04:59:05 +04:00
Michael Widenius
046418ad95 Added calls to cleanup_mutexes() for embedded library. 2011-04-28 23:58:00 +03:00
Michael Widenius
2721e912ba Added ALTER ONLINE TABLE, which will give an error if the change can't be done 'instantly' (without a table copy)
mysql-test/r/alter_table_online.result:
  Test new feature
mysql-test/t/alter_table_online.test:
  Test new feature
sql/handler.cc:
  Added comment
sql/lex.h:
  Added ONLINE keyword
sql/mysql_priv.h:
  Added option to alter table to require online operation
sql/share/errmsg.txt:
  Added error message if ONLINE can't be done
sql/sql_lex.h:
  Added online option
sql/sql_parse.cc:
  Added online option to mysql_alter_table()
sql/sql_table.cc:
  Added test that gives error if table can't be done instantly when requsted to be online.
  Fixed wrong test if table includes a VARCHAR
  Fixed wrong (but unlikely) handling of error conditions in ALTER table
sql/sql_yacc.yy:
  Added ALTER ONLINE TABLE syntax
storage/maria/ha_maria.cc:
  Fixed bug where 'start_bulk_insert' used too small buffer if used with unknown number of rows
2011-04-28 19:56:10 +03:00
Michael Widenius
6da8ac5f71 Added option "AND DISABLE CHECKPOINT" to "FLUSH TABLES WITH READ LOCK"
This makes it possible to do safe multi volume snapshots as long as one snapshots the volume with the transaction logs last.


include/mysql_com.h:
  Added REFRESH_CHECKPOINT
mysql-test/r/flush.result:
  Added test of new FLUSH TABLES syntax + calls to checkpoint_status handler calls
mysql-test/t/flush.test:
  Added test of new FLUSH TABLES syntax + calls to checkpoint_status handler calls
sql/handler.cc:
  Added code to call checkpoint_state for all handlertons that supports it
sql/handler.h:
  Added new checkpoint_state() handlerton call to temporarly disable checkpoints.
sql/lex.h:
  Added CHECKPOINT keyword
sql/sql_yacc.yy:
  Added support for FLUSH TABLES WITH READ LOCK AND DISABLE CHECKPOINT
storage/maria/ha_maria.cc:
  Added handlerton call to disable checkpoints.
storage/maria/ma_checkpoint.c:
  Don't do checkpoint if checkpoints are disabled.
storage/maria/ma_static.c:
  Added maria_checkpoint_disabled
storage/maria/maria_def.h:
  Added maria_checkpoint_disabled
storage/xtradb/handler/ha_innodb.cc:
  Added handlerton call to disable checkpoints.
storage/xtradb/include/log0log.h:
  Added option to log_checkpoint() to allow one to ignore not critical checkpoints during the time checkpoints are disabled.
storage/xtradb/log/log0log.c:
  Added code to allow one to disable checkpoints during a FLUSH TABLES ... DISABLE CHECKPOINT
  This was done by adding a new argument to log_checkpoint() which tells us when the checkpoint is called by srv_master_thread (which are safe to ignore)
storage/xtradb/srv/srv0srv.c:
  Tell log_checkpoint() that checkpoints from srv_master_thread() are safe to ignore (will just delay recovery time a bit).
2011-04-28 18:02:26 +03:00
unknown
0f4236659c Fix LP BUG#718593
Analysis:
Build_equal_items_for_cond() rewrites the WHERE clause in such a way,
that it may merge the list join->cond_equal->current_level with the
list of child Items in an AND condition of the WHERE clause.

The place where this is done is:
static COND *build_equal_items_for_cond(THD *thd, COND *cond,
                                        COND_EQUAL *inherited)
{
  ...
      if (and_level)
    {
      args->concat(&eq_list);
      args->concat((List<Item> *)&cond_equal.current_level);
    }
  ...
}

As a result, later transformations on the WHERE clause may change the
structure of the list join->cond_equal->current_level without knowing this.

Specifically in this bug, Item_in_subselect::inject_in_to_exists_cond
creates a new AND of the old WHERE clause and the IN->EXISTS conditions.
It then calls fix_fields() for the new AND. Among other things, fix_fields
flattens all nested ANDs into one by merging the AND argument lists.

When there is a cond_equal for the JOIN, its list of Item_equal objects
is attached to the end of the original AND. When a lower-level AND is
merged into the top-level one, the argument list of the lower-level AND
is concatenated to the list of multiple equalities in the upper-level AND.

As a result, when substitute_for_best_equal_field processes the 
multiple equalities, it turns out that the multiple equality list contains
the Items from the lower-level AND which were concatenated to the end of
the join->cond_equal->current_level list. This results in a crash because
this list must not contain any other Items except for the previously found
Item_equal ones.

Solution:
When performing IN->EXIST predicate injection, and the where clause is an
AND, detach the list of Item_equal objects before calling fix_fields on
the injected where clause.

After fix_fields is done, reattach back the multiple equalities list to
the end of the argument list of the new AND.
2011-04-28 17:15:05 +03:00
Igor Babaev
1556a136ac Fixed LP bug #754521.
The function test_quick_select by mistake did not update the value
of table->quick_condition_rows for index intersection scans though
the specification explicitly required to do so from any table access
plan once the plan provided a better upper bound for the number of
rows selected from the table. It resulted in a bogus, usually very
big number saved as the cost of the table access. This, in its turn,
in many cases forced the optimizer to make a bad choice of the
execution plan for join queries.
2011-04-27 15:29:46 -07:00
Sergey Glukhov
a60c39a2ff Bug#11889186 60503: CRASH IN MAKE_DATE_TIME WITH DATE_FORMAT / STR_TO_DATE COMBINATION
calc_daynr() function returns negative result
if malformed date with zero year and month is used.
Attempt to calculate week day on negative value
leads to crash. The fix is return NULL for
'W', 'a', 'w' specifiers if zero year and month is used.
Additional fix for calc_daynr():
--added assertion that result can not be negative
--return 0 if zero year and month is used


mysql-test/r/func_time.result:
  test case
mysql-test/t/func_time.test:
  test case
sql-common/my_time.c:
  --added assertion that result can not be negative
  --return 0 if zero year and month is used
sql/item_timefunc.cc:
  eturn NULL for 'W', 'a', 'w' specifiers
  if zero year and month is used.
2011-04-27 11:35:57 +04:00
Igor Babaev
24edac2211 Merge 2011-04-26 21:11:06 -07:00
Igor Babaev
8d9dd21d85 Fixed LP bugs #717577, #724942.
Both these two bugs happened due to the following problem.
When a view column is referenced in the query an Item_direct_view_ref
object is created that is refers to the Item_field for the column.
All references to the same view column refer to the same Item_field.
Different references can belong to different AND/OR levels and,
as a result, can be included in different Item_equal object.
These Item_equal objects may include different constant objects.
If these constant objects are substituted for the Item_field created
for a view column we have a conflict situation when the second
substitution annuls the first substitution. This leads to
wrong result sets returned by the query. Bug #724942 demonstrates
such an erroneous behaviour.
Test case of the bug #717577 produces wrong result sets because best
equal fields of the multiple equalities built for different OR levels
of the WHERE condition differs. The subsitution for the best equal field
in the second OR branch overwrites the the substitution made for the
first branch.

To avoid such conflicts we have to substitute for the references
to the view columns rather than for the underlying field items.
To make such substitutions possible we have to include into
multiple equalities references to view columns rather than 
field items created for such columns.

This patch modifies the Item_equal class to include references
to view columns into multiple equality objects. It also performs
a clean up of the class methods and adds more comments. The methods
of the Item_direct_view_ref class that assist substitutions for
references to view columns has been also added by this patch.
2011-04-26 19:58:41 -07:00
Guilhem Bichot
c575254f9d merge from 5.1 2011-04-26 13:06:44 +02:00
Mattias Jonsson
bdaaee5d04 post fix for werror build for bug#11766249. 2011-04-26 10:21:09 +02:00
Mattias Jonsson
bd707d128a merge 2011-04-23 16:57:24 +02:00
Sergey Glukhov
a5e8d9029b Bug#11756928 48916: SERVER INCORRECTLY PROCESSING HAVING CLAUSES WITH AN ORDER BY CLAUSE
Before sorting HAVING condition is split into two parts,
first part is a table related condition and the rest of is
HAVING part. Extraction of HAVING part does not take into account
the fact that some of conditions might be non-const but
have 'used_tables' == 0 (independent subqueries)
and because of that these conditions are cut off by
make_cond_for_table() function.
The fix is to use (table_map) 0 instead of used_tables in
third argument for make_cond_for_table() function.
It allows to extract elements which belong to sorted
table and in addition elements which are independend
subqueries.


mysql-test/r/having.result:
  test case
mysql-test/t/having.test:
  test case
sql/sql_select.cc:
  The fix is to use (table_map) 0 instead of used_tables in
  third argument for make_cond_for_table() function.
  It allows to extract elements which belong to sorted
  table and in addition elements which are independend
  subqueries.
2011-04-22 11:20:55 +04:00
Igor Babaev
79439d9a74 Fixed LP bug #752353.
In some cases the field max_part_no of the SEL_ARG structure
was not initialized. That triggered a Valgrind complain.
2011-04-20 15:30:21 -07:00
Mattias Jonsson
b3d86f12eb merge 2011-04-20 18:10:15 +02:00
Mattias Jonsson
046b57450d merge 2011-04-20 18:00:50 +02:00
Mattias Jonsson
bd92ea4311 Bug#11766249 bug#59316: PARTITIONING AND INDEX_MERGE MEMORY LEAK
Update for previous patch according to reviewers comments.

Updated the constructors for ha_partitions to use the common
init_handler_variables functions

Added use of defines for size and offset to get better readability for the code that reads
and writes the .par file. Also refactored the get_from_handler_file function.
2011-04-20 17:52:33 +02:00
unknown
43acceeb47 Fix LP BUG#715069
Analysis:
The wrong result is a consquence of sorting the subquery
result and then selecting only the first row due to the
artificial LIMIT 1 introduced by the fix_fields phase.
Normally, if there is an ORDER BY in a subquery, the ORDER
is removed (Item_in_subselect::select_in_like_transformer),
however if a GROUP BY is transformed into ORDER, this happens
later, after the removal of the ORDER clause of subqueries, so
we end up with a subquery with an ORDER clause, and an artificially
added LIMIT 1.

The reason why the same works in the main 5.3 without MWL#89, is
that the 5.3 performs all subquery transformations, including
IN->EXISTS before JOIN::optimize(). The beginning of JOIN::optimize
does:
  if (having || (select_options & OPTION_FOUND_ROWS))
    select_limit= HA_POS_ERROR;
which sets the limit back to infinity, thus 5.3 sorts the whole
subquery result, and IN performs the lookup into all subquery result
rows.

Solution:
Sorting of subqueries without LIMIT is meaningless. Since LIMIT in
subqueries is not supported, the patch removes sorting by setting
  join->skip_sort_order= true
for each subquery JOIN object. This improves a number of execution
plans to not perform unnecessary sorting at all.
2011-04-20 18:36:55 +03:00
Jon Olav Hauglid
f3b024cafa BUG#12377872 ASSERTION FAILED: !_ENTERED WHEN GETHOSTBYADDR_R
FAILS ON SOLARIS

This assertion was triggered if gethostbyaddr_r cannot do a
reverse lookup on an ip address. The reason was a missing
DBUG_RETURN macro. The problem affected only debug versions of
the server.

This patch fixes the problem by replacing return with DBUG_RETURN.
No test case added.
2011-04-20 11:32:28 +02:00
Sergey Glukhov
90bbf9d615 Bug#11765923 58937: MANY VALGRIND ERRORS AFTER GROUPING BY RESULT OF DECIMAL COLUMN FUNCTION
Bug#11764671  57533: UNINITIALISED VALUES IN COPY_AND_CONVERT (SQL_STRING.CC) WITH CERTAIN CHA
When ROUND evaluates decimal result it uses Item::decimal
value as fraction value for the result. In some cases
Item::decimal is greater than real result fraction value
and uninitialised memory of result(decimal) buffer can be
used in further calculations. Issue is introduced by
Bug33143 fix. The fix is to remove erroneous assignment.


mysql-test/r/func_math.result:
  test case
mysql-test/t/func_math.test:
  test case
sql/item_func.cc:
  remove erroneous assignment
2011-04-20 11:39:20 +04:00
Sergei Golubchik
a7ff7918a0 lp:750117 Bogus warning with aggregate and datetime column
implement Item_cache_int::getdate() and Item_cache_int::save_in_field()
that handle the case of the cached packed datetime value.
2011-04-18 21:01:49 +02:00
Sergey Glukhov
bba7b9ca0c Bug#11765139 58069: LOAD DATA INFILE: VALGRIND REPORTS INVALID MEMORY READS AND WRITES WITH U
Some multibyte sequences could be considered by my_mbcharlen() functions
as multibyte character but more exact my_ismbchar() does not think so.
In such a case this multibyte sequences is pushed into 'stack' buffer which
is too small to accommodate the sequence.
The fix is to allocate stack buffer in
compliance with max character length.


mysql-test/r/loaddata.result:
  test case
mysql-test/t/loaddata.test:
  test case
sql/sql_load.cc:
  allocate stack buffer in compliance with max character length.
2011-04-15 12:51:34 +04:00
Tor Didriksen
dd3d9477b2 Bug#11765713 58705: OPTIMIZER LET ENGINE DEPEND ON UNINITIALIZED VALUES CREATED BY OPT_SUM_QU
Valgrind warnings were caused by comparing index values to an un-initialized field.


mysql-test/r/subselect.result:
  New test cases.
mysql-test/t/subselect.test:
  New test cases.
sql/opt_sum.cc:
  Add thd to opt_sum_query enabling it to test for errors.
  If we have a non-nullable index, we cannot use it to match null values,
  since set_null() will be ignored, and we might compare uninitialized data.
sql/sql_select.cc:
  Add thd to opt_sum_query, enabling it to test for errors.
sql/sql_select.h:
  Add thd to opt_sum_query, enabling it to test for errors.
2011-04-14 16:35:24 +02:00
Sergey Glukhov
3abe56f31d Bug#11756242 48137: PROCEDURE ANALYSE() LEAKS MEMORY WHEN RETURNING NULL
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
2011-04-14 12:11:57 +04:00
unknown
ce55d37929 Merge Mariadb 5.1->5.2 2011-04-12 14:26:06 +02:00
Sergey Glukhov
7fa7a0cad9 Bug#11766270 59343: YEAR(4): INCORRECT RESULT AND VALGRIND WARNINGS WITH MIN/MAX, UNION
When we create temporary result table for UNION
incorrect max_length for YEAR field is used and
it leads to incorrect field value and incorrect
result string length as YEAR field value calculation
depends on field length.
The fix is to use underlying item max_length for
Item_sum_hybrid::max_length intialization.


mysql-test/r/func_group.result:
  test case
mysql-test/t/func_group.test:
  test case
sql/field.cc:
  added assert
sql/item_sum.cc:
  init Item_sum_hybrid::max_length with 
  use underlying item max_length for
  INT result type.
2011-04-12 14:01:33 +04:00
Sergey Glukhov
33c2a5e7e3 Bug#11766212 59270: NOT IN (YEAR( ... ), ... ) PRODUCES MANY VALGRIND WARNINGS
Valgrind warning happens due to early null values check
in Item_func_in::fix_length_and_dec(before item evaluation).
As result null value items with uninitialized values are
placed into array and it leads to valgrind warnings during
value array sorting.
The fix is to check null value after item evaluation, item
is evaluated in in_array::set() method.


mysql-test/r/func_in.result:
  test case
mysql-test/t/func_in.test:
  test case
sql/item_cmpfunc.cc:
  The fix is to check null value after item evaluation.
2011-04-12 13:51:36 +04:00
Gleb Shchepa
a77bc59896 Bug #11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY
Select from a view with the underlying HAVING clause failed with a
message: "1356: View '...' references invalid table(s) or column(s)
or function(s) or definer/invoker of view lack rights to use them"

The bug is a regression of the fix for bug 11750328 - 40825 (similar
case, but the HAVING cause references an aliased field).
In the old fix for bug 40825 the Item_field::name_length value has
been used in place of the real length of Item_field::name. However,
in some cases Item_field::name_length is not in sync with the
actual name length (TODO: combine name and name_length into a
solid String field).

The Item_ref::print() method has been modified to calculate actual
name length every time.


mysql-test/r/view.result:
  Test case for bug #11829681
mysql-test/t/view.test:
  Test case for bug #11829681
sql/item.cc:
  Bug #11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY
  
  The Item_ref::print() method has been modified to calculate actual
  name length every time.
sql/item.h:
  Minor commentary.
2011-04-08 12:05:20 +04:00
unknown
64e43e1cc8 Merge various replication-related patches into MariaDB 5.3:
- MWL#116 Group commit
 - MWL#136 Enhancements for START TRANSACTION WITH CONSISTENT SNAPSHOT
 - MWL#47 Annotate_rows_log_event
 - MWL#163 innodb_release_locks_early
 - Percona patch enhancing row-based replication for tables with no primary key
2011-04-08 09:39:33 +02:00
Vladislav Vaintroub
8b427b7d55 merge 2011-04-08 02:54:01 +02:00
Vladislav Vaintroub
ad7b636d72 fix CRLF line endings to LF 2011-04-08 01:42:47 +02:00
Vladislav Vaintroub
3fdd009990 Fix SQL syntax error when running mysql --bootstrap. 2011-04-08 01:41:07 +02:00
Sergey Petrunya
acc161d363 BUG#752992: Wrong results for a subquery with 'semijoin=on'
- Let advance_sj_state() save the value of JOIN::cur_dups_producing_tables
  in POSITION::prefix_dups_producing_tables, and restore_sj_state() restore
  it.
2011-04-08 02:12:03 +04:00
unknown
86008e0ca2 Fix merge error. 2011-04-07 17:21:22 +02:00
Guilhem Bichot
dc65d9217c Fix for Bug#11765141 - "58072: LOAD DATA INFILE: LEAKS IO CACHE MEMORY WHEN ERROR OCCURS"
mysql-test/t/loaddata.test:
  test for bug; without fix, running the test with --valgrind would show the leak
  and make the test fail.
sql/sql_load.cc:
  * In READ_INFO class, 'need_end_io_cache' is true as long as init_io_cache() was called,
  so if it's true, we need to call end_io_cache(), to free memory allocated
  by init_io_cache(). No matter the value of 'error'. In the bug's scenario,
  'error' was set to true in read_sep_field() because
  '1' (read from file) isn't suitable to load into a geometric column. Because of
  'error', end_io_cache() was not called.
  Note: end_io_cache() calls my_b_flush_io_cache(), which will do nothing wrong given
  that the file is opened for reads only; see the init_io_cache() call which uses
  only those read-only types:
  (get_it_from_net) ? READ_NET : (is_fifo ? READ_FIFO : READ_CACHE).
  IF the cache were rather used to write to the file, my_b_flush_io_cache() may
  write to it, and it may be questionable to write to the file
  if 'error' is true. But here there's no problem.
  * Now that 'need_end_io_cache' is checked even if 'error' is true, it needs
  to be initialized in all cases.
  * Bonus: move some variables to the initialization list.
2011-04-07 15:09:19 +02:00
Sergey Petrunya
81c6f73ff2 MWL#90: Address review feedback part #19: More comments 2011-04-05 14:33:15 +04:00
Sergey Petrunya
151207134b MWL#90: Address review feedback part #18 2011-04-05 12:20:03 +04:00