Commit graph

1886 commits

Author SHA1 Message Date
Alexander Barkov
3cc6e5b7f2 MDEV-8852 Implicit or explicit CAST from MAX(string) to INT,DOUBLE,DECIMAL does not produce warnings 2015-09-28 12:51:02 +04:00
Alexander Barkov
30711c6650 MDEV-8806 Numeric CAST produce different warnings for strings literals vs functions 2015-09-25 21:33:50 +04:00
Alexander Barkov
212698b152 MDEV-8253 EXPLAIN SELECT prints unexpected characters
Item_string::clone_item() creates a new Item_string that
points exactly to the same buffer that the original one does.
Later, Item_string::print() uses c_ptr() for the original Item_string,
which reallocs the original buffer, and the clone remain with
the old freed buffer.
Refactoring the code not to use c_ptr() in Item_string::print().
2015-09-23 13:04:28 +04:00
Alexander Barkov
22cc8f990b Changing a number of functions to aggregate argument character sets
and collations from the global name space into private and protected
methods in Item_func_or_sum.
2015-09-21 19:04:32 +04:00
Alexander Barkov
2dc32c02ab Removing "DTCollation user_var_entry::collation", using a CHARSET_INFO
pointer instread, as the "derivation" and "repertoire" parts of
DTCollation were not really used by user_var_entry.
2015-09-21 15:52:50 +04:00
Alexander Barkov
b75c003372 MDEV-8816 Equal field propagation is not applied for WHERE varbinary_column>=_utf8'a' COLLATE utf8_general_ci AND varbinary_column='A';
1. Removing the legacy code that disabled equal field propagation in cases
   when comparison is done as VARBINARY. This is now correctly handled by
   the new propagation code in Item_xxx::propagate_equal_fields() and
   Field_str::can_be_substituted_to_equal_item (the bug fix).
2. Also, removing legacy (pre-MySQL-4.1) Arg_comparator methods
   compare_binary_string() and compare_e_binary_string(), as VARBINARY
   comparison is correcty handled in compare_string() and compare_e_string() by
   the corresponding VARBINARY collation handler implemented in my_charset_bin.
   (not really a part of the bug fix)
2015-09-18 23:03:35 +04:00
Alexander Barkov
79140b0383 MDEV-8793 Wrong result set for SELECT ...
WHERE COALESCE(time_column)=TIME('00:00:00')
            AND COALESCE(time_column)=DATE('2015-09-11')
MDEV-8814 Wrong result for WHERE datetime_column > TIME('00:00:00')
2015-09-18 13:30:44 +04:00
Alexander Barkov
d9b25ae3db MDEV-8466 CAST works differently for DECIMAL/INT vs DOUBLE for empty strings
MDEV-8468 CAST and INSERT work differently for DECIMAL/INT vs DOUBLE for a string with trailing spaces
2015-09-17 11:05:07 +04:00
Alexander Barkov
6cc2e7ea5d MDEV-8795 Equal expression propagation does not work for temporal literals 2015-09-13 23:32:10 +04:00
Alexander Barkov
4aebba3aeb MDEV-8740 Wrong result for SELECT..WHERE year_field=10 AND NULLIF(year_field,2011.1)='2011'
MDEV-8754 Wrong result for SELECT..WHERE year_field=2020 AND NULLIF(year_field,2010)='2020'
Problems:
1. Item_func_nullif stored a copy of args[0] in a private member m_args0_copy,
   which was invisible for the inherited Item_func menthods, like
   update_used_tables(). As a result, after equal field propagation
   things like Item_func_nullif::const_item() could return wrong result
   and a non-constant NULLIF() was erroneously treated as a constant
   at optimize_cond() time.
   Solution: removing m_args0_copy and storing the return value item
   in args[2] instead.
2. Equal field propagation did not work well for Item_fun_nullif.
   Solution: using ANY_SUBST for args[0] and args[1], as they are in
   comparison, and IDENTITY_SUBST for args[2], as it's not in comparison.
2015-09-10 17:13:35 +04:00
Alexander Barkov
4278d6d402 MDEV-8786 Wrong result for SELECT FORMAT=JSON * FROM t1 WHERE a=_latin1 0xDF 2015-09-10 14:04:52 +04:00
Alexander Barkov
3fcd84c289 MDEV-8741 Equal field propagation leaves some remainders after simplifying WH ERE zerofill_column=2010 AND zerofill_column>=2010 2015-09-09 08:11:43 +04:00
Alexander Barkov
de269f2f1f MDEV-8766 Wrong result for SELECT..WHERE LENGTH(time_column)=8 AND time_column=TIMESTAMP'2001-01-01 10:20:31' 2015-09-08 16:02:29 +04:00
Alexander Barkov
42574427e6 MDEV-8699 Wrong result for SELECT..WHERE HEX(date_column)!='323030312D30312D3031' AND date_column='2001-01-01x' 2015-09-07 17:43:53 +04:00
Alexander Barkov
0736cddbd4 Field_num::get_equal_const_item() appeared to be in a wrong file (item.cc).
Moving to field.cc.
2015-09-07 06:45:51 +04:00
Alexander Barkov
1a36caf0e9 MDEV-8729 Wrong result for SELECT..WHERE HEX(enum_column)='61' AND enum_column='a ' 2015-09-06 18:49:17 +04:00
Alexander Barkov
e0df116056 A clean-up after the patch for MDEV-8747 and MDEV-8749:
removing IMPOSSIBLE_RESULT from Item_result, as it's not
needed any more. The fact that an Item is not in a comparison
context is now always designated by IDENTITY_SUBST in Subst_constraint.
Previously IMPOSSIBLE_RESULT and IDENTITY_SUBST co-existed but
actually meant the same thing.
2015-09-06 13:25:47 +04:00
Alexander Barkov
c108019a48 MDEV-8747 Wrong result for SELECT..WHERE derived_table_column='a' AND derived_table_column<>_latin1'A' COLLATE latin1_bin
MDEV-8749 Wrong result for SELECT..WHERE derived_table_enum_column='number' AND derived_table_enum_column OP number
2015-09-06 01:30:46 +04:00
Sergei Golubchik
530a6e7481 Merge branch '10.0' into 10.1
referenced_by_foreign_key2(), needed for InnoDB to compile,
was taken from 10.0-galera
2015-09-03 12:58:41 +02:00
Alexander Barkov
68810129a0 MDEV-8695 Wrong result for SELECT..WHERE varchar_column='a' AND CRC32(varchar_column)=3904355907 2015-09-01 22:48:17 +04:00
Monty
56aa19989f MDEV-6152: Remove calls to current_thd while creating Item
Part 5: Removing calls to current_thd in net_read calls, creating fields,
        query_cache, acl and some other places where thd was available
2015-09-01 18:42:02 +03:00
Alexander Barkov
8ea9b8c0b1 MDEV-8722 The patch for MDEV-8688 disabled equal field propagation for temporal column and BETWEEN and IN
Item::cmp_context was inconsistently used in combination with cmp_type()
and result_type() in different places of the code. Fixed to use cmp_type()
in all places where cmp_context is involved, to avoid unexpected results
for temporal data types (which have result_type()==STRING_RESULT and
cmp_type==TIME_RESULT).
2015-09-01 19:24:58 +04:00
Alexander Barkov
a3c24ee739 MDEV-8707 Wrong result for
SELECT..WHERE varchar_column=DATE'2001-01-01' AND varchar_column='2001-01-01'
2015-08-31 18:18:10 +04:00
Monty
3bca8db4f9 MDEV-6152: Remove calls to current_thd while creating Item
- Part 4: Removing calls to sql_alloc() and sql_calloc()

Other things:
- Added current_thd in some places to make it clear that it's called (easier to remove later)
- Move memory allocation from Item_func_case::fix_length_and_dec() to Item_func_case::fix_fields()
- Added mem_root to some new calls
- Fixed some wrong UNINIT_VAR() calls
- Fixed a bug in generate_partition_syntax() in case of errors
- Added mem_root to argument to new thread_info
- Simplified my_parse_error() call in sql_yacc.yy
2015-08-27 22:29:11 +03:00
Monty
3cb578c001 MDEV-6152: Remove calls to current_thd while creating Item
- Part 3: Adding mem_root to push_back() and push_front()

Other things:
- Added THD as an argument to some partition functions.
- Added memory overflow checking for XML tag's in read_xml()
2015-08-27 22:21:08 +03:00
Alexander Barkov
1b6b44b6b5 MDEV-8661 Wrong result for SELECT..WHERE a='a' AND a='a' COLLATE latin1_bin
MDEV-8679 Equal field propagation is not used for VARCHAR when it safely could
2015-08-26 22:32:01 +04:00
Monty
1bae0d9e56 Stage 2 of MDEV-6152:
- Added mem_root to all calls to new Item
- Added private method operator new(size_t size) to Item to ensure that
  we always use a mem_root when creating an item.

This saves use once call to current_thd per Item creation
2015-08-21 10:40:51 +04:00
Sergey Vojtovich
31e365efae MDEV-8010 - Avoid sql_alloc() in Items (Patch #1)
Added mandatory thd parameter to Item (and all derivative classes) constructor.
Added thd parameter to all routines that may create items.
Also removed "current_thd" from Item::Item. This reduced number of
pthread_getspecific() calls from 290 to 177 per OLTP RO transaction.
2015-08-21 10:40:39 +04:00
Jan Lindström
9a5787db51 Merge commit '96badb16afcf' into 10.0
Conflicts:
	client/mysql_upgrade.c
	mysql-test/r/func_misc.result
	mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result
	mysql-test/suite/innodb/r/innodb-fk.result
	mysql-test/t/subselect_sj_mat.test
	sql/item.cc
	sql/item_func.cc
	sql/log.cc
	sql/log_event.cc
	sql/rpl_utility.cc
	sql/slave.cc
	sql/sql_class.cc
	sql/sql_class.h
	sql/sql_select.cc
	storage/innobase/dict/dict0crea.c
	storage/innobase/dict/dict0dict.c
	storage/innobase/handler/ha_innodb.cc
	storage/xtradb/dict/dict0crea.c
	storage/xtradb/dict/dict0dict.c
	storage/xtradb/handler/ha_innodb.cc
	vio/viosslfactories.c
2015-08-03 23:09:43 +03:00
Sergei Golubchik
4d5772c578 MDEV-7810 Wrong result on execution of a query as a PS (both 1st and further executions)
Alternative fix that doesn't cause view.test crash in --ps:
Remember when Item_ref was fixed right in the constructor
and did not have a full Item_ref::fix_fields() call. Later
in PS/SP, after Item_ref::cleanup, we use this knowledge
to avoid doing full fix_fields() for items that were never
supposed to be fix_field'ed.

Simplify the test case.
2015-07-31 17:17:33 +02:00
Monty
9bb8b74e99 Merge branch '10.1' of github.com:MariaDB/server into 10.1
Conflicts:
	sql/item_subselect.cc

Fixed also typo in comment
2015-07-09 14:47:32 +03:00
Monty
7332af49e4 - Renaming variables so that they don't shadow others (After this patch one can compile with -Wshadow and get much fewer warnings)
- Changed ER(ER_...) to ER_THD(thd, ER_...) when thd was known or if there was many calls to current_thd in the same function.
- Changed ER(ER_..) to ER_THD_OR_DEFAULT(current_thd, ER...) in some places where current_thd is not necessary defined.
- Removing calls to current_thd when we have access to thd

Part of this is optimization (not calling current_thd when not needed),
but part is bug fixing for error condition when current_thd is not defined
(For example on startup and end of mysqld)

Notable renames done as otherwise a lot of functions would have to be changed:
- In JOIN structure renamed:
   examined_rows -> join_examined_rows
   record_count -> join_record_count
- In Field, renamed new_field() to make_new_field()

Other things:
- Added DBUG_ASSERT(thd == tmp_thd) in Item_singlerow_subselect() just to be safe.
- Removed old 'tab' prefix in JOIN_TAB::save_explain_data() and use members directly
- Added 'thd' as argument to a few functions to avoid calling current_thd.
2015-07-06 20:24:14 +03:00
Monty
86377d078e Fixes done while working on MDEV-4119:
Fixed several optimizer issues relatied to GROUP BY:

a) Refering to a SELECT column in HAVING sometimes calculated it twice, which caused problems with non determinstic functions

b) Removing duplicate fields and constants from GROUP BY was done too late for "using index for group by" optimization to work

c) EXPLAIN SELECT ... GROUP BY did wrongly show 'Using filesort' in some cases involving "Using index for group-by"


a) was fixed by:
- Changed last argument to Item::split_sum_func2() from bool to int to allow more flags
- Added flag argument to Item::split_sum_func() to allow on to specify if the item was in the SELECT part
- Mark all split_sum_func() calls from SELECT with SPLIT_SUM_SELECT
- Changed split_sum_func2() to do nothing if called with an argument that is not a sum function and doesn't include sum functions, if we are not an argument to SELECT.

This ensures that in a case like
select a*sum(b) as f1 from t1 where a=1 group by c having f1 <= 10;

That 'a' in the SELECT part is stored as a reference in the temporary table togeher with sum(b) while the 'a' in having isn't (not needed as 'a' is already a reference to a column in the result)

b) was fixed by:
- Added an extra remove_const() pass for GROUP BY arguments before make_join_statistics() in case of one table SELECT.

This allowes get_best_group_min_max() to optimize things better.

c) was fixed by:
- Added test for group by optimization in JOIN::exec_inner for
  select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX

item.cc:
- Simplifed Item::split_sum_func2()
  - Split test to make them faster and easier to read
  - Changed last argument to Item::split_sum_func2() from bool to int to allow more flags
  - Added flag argument to Item::split_sum_func() to allow on to specify if the item was in the SELECT part
  - Changed split_sum_func2() to do nothing if called with an argument that is not a sum function and doesn't include sum functions, if we are not an argument to SELECT.

opt_range.cc:
- Simplified get_best_group_min_max() by calcuating first how many group_by elements.
- Use join->group instead of join->group_list to test if group by, as join->group_list may be NULL if everything was optimized away.

sql_select.cc:
- Added an extra remove_const() pass for GROUP BY arguments before make_join_statistics() in case of one table SELECT.
- Use group instead of group_list to test if group by, as group_list may be NULL if everything was optimized away.
- Moved printing of "Error in remove_const" to remove_const() instead of having it in caller.
- Simplified some if tests by re-ordering code.
- update_depend_map_for_order() and remove_const() fixed to handle the case where make_join_statistics() has not yet been called (join->join_tab is 0 in this case)
2015-07-05 12:39:46 +03:00
Sergei Petrunia
9d2aa2b309 MDEV-7811: EXPLAIN/ANALYZE FORMAT=JSON should show subquery cache
Fixes over the original patch:
- Fix variable/class/other names
- Fix the JSON output to be in line with the output of other JSON
  constructs we produce
2015-07-01 20:03:29 +03:00
Oleksandr Byelkin
c6aee27b73 MDEV-7811: EXPLAIN/ANALYZE FORMAT=JSON should show subquery cache 2015-06-30 23:07:14 +03:00
Sergei Golubchik
658992699b Merge tag 'mariadb-10.0.20' into 10.1 2015-06-27 20:35:26 +02:00
Alexander Barkov
115904c2c8 MDEV-7824 [Bug #68041] Zero date can be inserted in strict no-zero mode through a default value 2015-06-26 10:16:51 +04:00
Monty
67c56ab1e4 Simple cleanups
- Removing use of calls to current_thd
- More DBUG_PRINT
- Code style changes
- Made some local functions static
Ensure that calls to print_keyuse are locked with mutex to get all lines in same debug packet
2015-06-25 23:34:54 +03:00
Monty
2e941fe9fc Fixed crashing bug when using ONLY_FULL_GROUP_BY in a stored procedure/trigger that is repeatedly executed.
This is MDEV-7601, including it's sub tasks MDEV-7594, MDEV-7555, MDEV-7590, MDEV-7581, MDEV-7589

The problem was that select_lex->non_agg_fields was not properly reset for re-execution and this caused an overwrite of a random memory position.
The fix was move non_agg_fields from select_lext to JOIN, which is properly reset.
2015-06-25 23:18:48 +03:00
Sergey Vojtovich
360176f397 MDEV-7943 - pthread_getspecific() takes 0.76% in OLTP RO
Pass THD to Item_field (and all derivatives) constructors.
This reduces number of pthread_getspecific() calls from 322 to 292.
2015-06-19 15:06:34 +04:00
Sergei Petrunia
e2a59eba5d Make dbug_print_item() print conditions in siccint form 2015-06-18 14:52:17 +03:00
Sergei Golubchik
810cf362ea Merge branch '5.5' into 10.0 2015-06-11 20:20:35 +02:00
Sergei Golubchik
b96c196f1c Item_cache::safe_charset_converter() fixes
* take into account that example may be NULL
* use example->safe_charset_converter(), copy-paste from
  Item::safe_charset_converter() (example might have its own
  implementation)
* handle the case when the charset doesn't need conversion
  (and return this).
2015-06-11 16:48:10 +02:00
Alexander Barkov
a765cca69f MDEV-8067 correct fix for MySQL Bug # 19699237: UNINITIALIZED VARIABLE IN ITEM_FIELD::STR_RESULT 2015-06-08 20:50:40 +04:00
Alexey Botchkov
b37b52a3a2 MDEV-4922 Stored Procedure - Geometry parameter not working.
Fhe GEOMETRY field should be handled just as the BLOB field. So that was fiexed in field_conv.
  One additional bug was found and fixed meanwhile - thet the geometry field subtypes
  should also be merged for UNION command.
2015-06-08 13:47:07 +05:00
Sergei Golubchik
5091a4ba75 Merge tag 'mariadb-10.0.19' into 10.1 2015-06-01 15:51:25 +02:00
Sergey Vojtovich
4d1ccc4289 MDEV-7951 - sql_alloc() takes 0.25% in OLTP RO
sql_alloc() has additional costs compared to direct mem_root allocation:
- function call: it is defined in a separate translation unit and can't be
  inlined
- it needs to call pthread_getspecific() to get THD::mem_root

It is called dozens of times implicitely at least by:
- List<>::push_back()
- List<>::push_front()
- new (for Sql_alloc derived classes)
- sql_memdup()

Replaced lots of implicit sql_alloc() calls with direct mem_root allocation,
passing through THD pointer whenever it is needed.

Number of sql_alloc() calls reduced 345 -> 41 per OLTP RO transaction.
pthread_getspecific() overhead dropped 0.76 -> 0.59
sql_alloc() overhed dropped 0.25 -> 0.06
2015-05-13 10:43:14 +04:00
Sergei Golubchik
49c853fb94 Merge branch '5.5' into 10.0 2015-05-04 22:00:24 +02:00
Alexander Barkov
462bca365a MDEV-7950 Item_func::type() takes 0.26% in OLTP RO
Step 2c:

After discussion with Igor, it appeared that Item_field and Item_ref
could not appear in this context in the old function build_equal_item_for_cond:

  else if (cond->type() == Item::FUNC_ITEM ||
           cond->real_item()->type() == Item::FIELD_ITEM)

The part of the condition checking for Item_field::FIELD_ITEM was a dead code.
- Moving implementation of Item_ident_or_func_or_sum::build_equal_items()
to Item_func::build_equal_items()
- Restoring deriving of Item_ident and Item_sum_or_func from Item_result_field.
  Removing Item_ident_or_func_or_sum.
2015-05-04 18:12:31 +04:00
Alexander Barkov
c8141f5314 MDEV-7950 Item_func::type() takes 0.26% in OLTP RO
Step#2:

1. Removes the function build_equal_items_for_cond() and
   introduces a new method Item::build_equal_items() instead,
   with specific implementations in the following Items:

   Item  (the default implementation)
   Item_ident_or_func_or_sum
   Item_cond
   Item_cond_and

2. Adds a new abstract class Item_ident_or_func_or_sum,
   a common parent for Item_ident and Item_func_or_sum,
   as they have exactly the same build_equal_items().

3. Renames Item_cond_and::cond_equal to Item_cond_and::m_cond_equal,
   to avoid confusion between the member and local variables named
   "cond_equal".
2015-04-28 14:06:07 +04:00