Commit graph

395 commits

Author SHA1 Message Date
Sergei Golubchik
8b1f145c82 cleanup
Item_func_format::print() was redundant
and other changes
2017-09-18 10:12:23 +02:00
Sergei Golubchik
cb1e76e4de Merge branch '10.1' into 10.2 2017-08-17 11:38:34 +02:00
Sergei Golubchik
8e8d42ddf0 Merge branch '10.0' into 10.1 2017-08-08 10:18:43 +02:00
Sergei Golubchik
2fcd8c1252 MDEV-13173 An RLIKE that previously worked on 10.0 now returns "Got error 'pcre_exec: recursion limit of 100 exceeded' from regexp"
1. use Regexp_processor_pcre::set_recursion_limit() to set the
   recursion limit depending on the current available stack size
2. make pcre stack frame to be estimated no less than 500 bytes.
   sometimes pcre estimates it too low, even though the manual
   says 500+16 bytes (it was estimated only 188 for me, actual
   frame size was 512).
3. do it for embedded too
2017-07-20 20:13:28 +02:00
Sergei Golubchik
f6633bf058 Merge branch '10.1' into 10.2 2017-07-05 19:08:55 +02:00
Vicențiu Ciorbaru
2e335a471c Merge remote-tracking branch '10.0' into 10.1 2017-06-21 16:19:43 +03:00
Alexander Barkov
3a37afec29 MDEV-10306 Wrong results with combination of CONCAT, SUBSTR and CONVERT in subquery
The bug happens because of a combination of unfortunate circumstances:

1. Arguments args[0] and args[2] of Item_func_concat point recursively
(through Item_direct_view_ref's) to the same Item_func_conv_charset.
Both args[0]->args[0]->ref[0] and args[2]->args[0]->ref[0] refer to
this Item_func_conv_charset.

2. When Item_func_concat::args[0]->val_str() is called,
Item_func_conv_charset::val_str() writes its result to
Item_func_conc_charset::tmp_value.

3. Then, for optimization purposes (to avoid copying),
Item_func_substr::val_str() initializes Item_func_substr::tmp_value
to point to the buffer fragment owned by Item_func_conv_charset::tmp_value
Item_func_substr::tmp_value is returned as a result of
Item_func_concat::args[0]->val_str().

4. Due to optimization to avoid memory reallocs,
Item_func_concat::val_str() remembers the result of args[0]->val_str()
in "res" and further uses "res" to collect the return value.

5. When Item_func_concat::args[2]->val_str() is called,
Item_func_conv_charset::tmp_value gets overwritten (see #1),
which effectively overwrites args[0]'s Item_func_substr::tmp_value (see #3),
which effectively overwrites "res" (see #4).

This patch does the following:

a. Changes Item_func_conv_charset::val_str(String *str) to use
   tmp_value and str the other way around. After this change tmp_value
   is used to store a temporary result, while str is used to return the value.
   The fixes the second problem (without SUBSTR):
     SELECT CONCAT(t2,'-',t2) c2
       FROM (SELECT CONVERT(t USING latin1) t2 FROM t1) sub;
   As Item_func_concat::val_str() supplies two different buffers when calling
   args[0]->val_str() and args[2]->val_str(), in the new reduction the result
   created during args[0]->val_str() does not get overwritten by
   args[2]->val_str().

b. Fixing the same problem in val_str() for similar classes

   Item_func_to_base64
   Item_func_from_base64
   Item_func_weight_string
   Item_func_hex
   Item_func_unhex
   Item_func_quote
   Item_func_compress
   Item_func_uncompress
   Item_func_des_encrypt
   Item_func_des_decrypt
   Item_func_conv_charset
   Item_func_reverse
   Item_func_soundex
   Item_func_aes_encrypt
   Item_func_aes_decrypt
   Item_func_buffer

c. Fixing Item_func::val_str_from_val_str_ascii() the same way.
   Now Item_str_ascii_func::ascii_buff is used for temporary value,
   while the parameter passed to val_str() is used to return the result.
   This fixes the same problem when conversion (from ASCII to e.g. UCS2)
   takes place. See the ctype_ucs.test for example queries that returned
   wrong results before the fix.

d. Some Item_func descendand classes had temporary String buffers
   (tmp_value and tmp_str), but did not really use them.
   Removing these temporary buffers from:

   Item_func_decode_histogram
   Item_func_format
   Item_func_binlog_gtid_pos
   Item_func_spatial_collection:

e. Removing Item_func_buffer::tmp_value, because it's not used any more.

f. Renaming Item_func_[un]compress::buffer to "tmp_value",
   for consistency with other classes.

Note, this patch does not fix the following classes
(although they have a similar problem):

   Item_str_conv
   Item_func_make_set
   Item_char_typecast

They have a complex implementations and simple swapping between "tmp_value"
and "str" won't work. These classes will be fixed separately.
2017-06-19 12:45:32 +04:00
Vicențiu Ciorbaru
f0ad93403f MDEV-12666: CURRENT_ROLE() and DATABASE() does not work in a view
The problem lies in how CURRENT_ROLE is defined. The
Item_func_current_role inherits from Item_func_sysconst, which defines
a safe_charset_converter to be a const_charset_converter.

During view creation, if there is no role previously set, the current_role()
function returns NULL.

This is captured on item instantiation and the
const_charset_converter call subsequently returns an Item_null.
In turn, the function is replaced with Item_null and the view is
then created with an Item_null instead of Item_func_current_role.

Without this patch, the first SHOW CREATE VIEW from the testcase would
have a where clause of WHERE role_name = NULL, while the second SHOW
CREATE VIEW would show a correctly created view.

The same applies for the DATABASE function, as it can change as well.

There is an additional problem with CURRENT_ROLE() when used in a
prepared statement. During prepared statement creation we used to set
the string_value of the function to the current role as well as the
null_value flag. During execution, if CURRENT_ROLE was not null, the
null_value flag was never set to not-null during fix_fields.

Item_func_current_user however can never be NULL so it did not show this
problem in a view before. At the same time, the CURRENT_USER() can not
be changed between prepared statement execution and creation so the
implementation where the value is stored during fix_fields is
sufficient.

Note also that DATABASE() function behaves differently during prepared
statements. See bug 25843 for details or commit
7e0ad09edf
2017-06-15 19:20:35 +03:00
Sergei Golubchik
4a5d25c338 Merge branch '10.1' into 10.2 2016-12-29 13:23:18 +01:00
Sergei Golubchik
180065ebb0 Item::print(): remove redundant parentheses
by introducing new Item::precedence() method and using it
to decide whether parentheses are required
2016-12-12 20:44:41 +01:00
Sergei Golubchik
0980627fca bugfix: Item_func_weight_string::print() 2016-12-12 20:27:22 +01:00
Alexander Barkov
9f837c6e1a MDEV-10864 Wrong result for WHERE .. (f2=COMPRESS('test') OR f2=COMPRESS('TEST')) 2016-09-22 10:03:12 +04:00
Alexander Barkov
7e4eb990ad MDEV-10425 Assertion `collation.derivation == DERIVATION_IMPLICIT' failed in Item_func_conv_charset::fix_length_and_dec()
MDEV-10850 Wrong result for WHERE .. (f2=TO_BASE64('test') OR f2=TO_BASE64('TEST'))

Problem N1: MDEV-10425
Item_func_{md5|sha|sha2}::fix_length_and_dec() changed args[0]->collation
to force binary comparison in args[0]->eq().
It was done to treat e.g. MD5('a') and MD5('A') as different values.
It is wrong for a Item_func_xxx to modify its arguments.
Item_func_conv_charset did not expect that and crashed on assert.

Problem N2: MDEV-10850
Item_func_to_base64, Item_func_password, Item_func_hex are also case sensitive
hash functions, but they did not compare their arguments as binary.

Solution:
- Removing the code changing args[0]->collation
- Introducing Item_str_ascii_checksum_func as a common parent
  for Item_func_{md5|sha|sha2|password|hex|to_base64}
  and overriding its eq() method to compare arguments binary.
2016-09-22 07:00:10 +04:00
Igor Babaev
3fb4f9bb93 Merge branch '10.2-mdev9197-cons' of github.com:shagalla/server
into branch 10.2-mdev9197.
2016-08-31 16:16:54 -07:00
Sergei Golubchik
73a220aac3 session-state dependent functions in DEFAULT/CHECK/vcols
* revert part of the db7edfe that moved calculations from
  fix_fields to val_str for Item_func_sysconst and descendants
* mark session state dependent functions in check_vcol_func_processor()
* re-run fix_fields for all such functions for every statement
* fix CURRENT_USER/CURRENT_ROLE not to use Name_resolution_context
  (that is allocated on the stack in unpack_vcol_info_from_frm())

Note that NOW(), CURDATE(), etc use lazy initialization and do *not*
force fix_fields to be re-run. The rule is:
* lazy initialization is *not* allowed, if it changes metadata (so,
   e.g. DAYNAME() cannot use it)
* lazy initialization is *preferrable* if it has side effects (e.g.
  NOW() sets thd->time_zone_used=1, so it's better to do it when
  the value of NOW is actually needed, not when NOW is simply prepared)
2016-08-27 16:59:12 +02:00
Galina Shalygina
eb2c147475 The consolidated patch for mdev-9197. 2016-08-23 00:39:12 +03:00
Sergei Golubchik
0a056c9b53 better ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED 2016-06-30 11:43:02 +02:00
Sergei Golubchik
ed77ee1aab cleanup: change Item::walk() to take void* not uchar*
and remove all related casts to uchar*
also remove a couple of unused methods
2016-06-30 11:43:02 +02:00
Michael Widenius
fb67cde237 Use default character set for expressions
- Force usage of () around complex DEFAULT expressions
- Give error if DEFAULT expression contains invalid characters
- Don't use const_charset_conversion for stored Item_func_sysconf expressions
  as the result is not constaint over different executions
- Fixed Item_func_user() to not store calculated value in str_value
2016-06-30 11:43:02 +02:00
Alexander Barkov
6c626117e7 More test for MDEV-10134 Add full support for DEFAULT
Miscelaneous functions:
BENCHMARK(), SLEEP(), ROW_COUNT(), FOUND_ROWS(),
GET_LOCK(), RELEASE_LOCK(), IS_USED_LOCK(), IS_FREE_LOCK(),
MASTER_POS_WAIT(), MASTER_GTID_WAIT(), BINLOG_GTID_POS(),
ST_GIS_DEBUG(), DECODE_HISTOGRAM(),
2016-06-30 11:43:02 +02:00
Michael Widenius
2fe8dd0f90 various cleanups 2016-06-30 11:43:02 +02:00
Michael Widenius
db7edfed17 MDEV-7563 Support CHECK constraint as in (or close to) SQL Standard
MDEV-10134 Add full support for DEFAULT

- Added support for using tables with MySQL 5.7 virtual fields,
  including MySQL 5.7 syntax
- Better error messages also for old cases
- CREATE ... SELECT now also updates timestamp columns
- Blob can now have default values
- Added new system variable "check_constraint_checks", to turn of
  CHECK constraint checking if needed.
- Removed some engine independent tests in suite vcol to only test myisam
- Moved some tests from 'include' to 't'. Should some day be done for all tests.
- FRM version increased to 11 if one uses virtual fields or constraints
- Changed to use a bitmap to check if a field has got a value, instead of
  setting HAS_EXPLICIT_VALUE bit in field flags
- Expressions can now be up to 65K in total
- Ensure we are not refering to uninitialized fields when handling virtual fields or defaults
- Changed check_vcol_func_processor() to return a bitmap of used types
- Had to change some functions that calculated cached value in fix_fields to do
  this in val() or getdate() instead.
- store_now_in_TIME() now takes a THD argument
- fill_record() now updates default values
- Add a lookahead for NOT NULL, to be able to handle DEFAULT 1+1 NOT NULL
- Automatically generate a name for constraints that doesn't have a name
- Added support for ALTER TABLE DROP CONSTRAINT
- Ensure that partition functions register virtual fields used. This fixes
  some bugs when using virtual fields in a partitioning function
2016-06-30 11:43:02 +02:00
Alexander Barkov
afbd28aeff Preparing the CAST(..AS [UN]SIGNED) related code to fix a number
of bugs easier (MDEV-8919, MDEV-10304, MDEV-10305, MDEV-10307)

- Adding Item::push_note_converted_to_negative_complement() and
  Item::push_note_converted_to_positive_complement()
- Adding virtual methods Item::val_int_signed_typecast() and
  Item::val_int_unsigned_typecast()
- Moving COLUMN_GET() related code from
  Item_func_signed::val_int() and Item_func_unsigned::val_int() to
  Item_dyncol_get::val_int_signed_typecast() and
  Item_dyncol_get::val_int_unsigned_typecast()
- Moving Item_func_signed::val_int_from_str() to Item::val_int_from_str()
  and changing it to get the value from "this" instead of args[0].

The patch does not change behaviour. It's only to simplify fixing of the
mentioned bugs. It will also simplify switching the CAST related code to
use the type handler infrastructure easier (soon).
2016-06-29 18:25:51 +04:00
Monty
b2f8d7b410 Merge branch '10.1' into 10.2
Conflicts:
	VERSION
	cmake/plugin.cmake
	config.h.cmake
	configure.cmake
	plugin/server_audit/server_audit.c
	sql/sql_yacc.yy
2016-02-06 18:14:54 +02:00
Alexander Barkov
77c75a46cf A clean-up patch for Item_func_conv_charset (needed for MDEV-9181)
Removing the "conv_charset" member and using collation.collation
instead, as they duplicated each other.
2016-01-26 17:52:24 +04:00
Alexander Barkov
607ef786fc MDEV-9215 Detect cmp_type() and result_type() from field_type()
(A dependency task for MDEV-4912 Add a plugin to field types)
2015-12-01 13:13:23 +04:00
Sergey Vojtovich
54689e1d5c MDEV-8715 - Obsolete sql_alloc() in favor of THD::alloc() and thd_alloc()
The following left in semi-improved state to keep patch size reasonable:
- Field operator new: left thd_alloc(current_thd)
- Sql_alloc operator new: left thd_alloc(thd_get_current_thd())
- Item_args constructors: left thd_alloc(thd)
- Item_func_interval::fix_length_and_dec(): no THD arg, have to call current_thd
- Item_func_dyncol_exists::val_int(): same
- Item_dyncol_get::val_str(): same
- Item_dyncol_get::val_int(): same
- Item_dyncol_get::val_real(): same
- Item_dyncol_get::val_decimal(): same
- Item_singlerow_subselect::fix_length_and_dec(): same
2015-11-26 11:34:17 +04:00
Sergey Vojtovich
0746a07708 MDEV-8718 - Obsolete sql_strmake() in favor of THD::strmake() and thd_strmake() 2015-11-26 11:34:16 +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
Sergei Golubchik
66b9a9409c New encryption API. Piece-wise encryption.
Instead of encrypt(src, dst, key, iv) that encrypts all
data in one go, now we have encrypt_init(key,iv),
encrypt_update(src,dst), and encrypt_finish(dst).

This also causes collateral changes in the internal my_crypt.cc
encryption functions and in the encryption service.

There are wrappers to provide the old all-at-once encryption
functionality. But binlog events are often written piecewise,
they'll need the new api.
2015-09-04 10:33:50 +02:00
Alexander Barkov
aa1002a35c MDEV-8723 Wrong result for SELECT..WHERE COLLATION(a)='binary' AND a='a' 2015-09-02 08:20:49 +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
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
Sergei Golubchik
5091a4ba75 Merge tag 'mariadb-10.0.19' into 10.1 2015-06-01 15:51:25 +02:00
Sergei Golubchik
49c853fb94 Merge branch '5.5' into 10.0 2015-05-04 22:00:24 +02:00
Alexander Barkov
59d847bd26 MDEV-7814 Assertion `args[0]->fixed' fails in Item_func_conv_charset::Item_func_conv_charset
Removing a wrong assertion.
2015-04-15 12:08:37 +04:00
Sergei Golubchik
bb1b61b312 encryption plugin controls the encryption
* no --encryption-algorithm option anymore
* encrypt/decrypt methods in the encryption plugin
* ecnrypt/decrypt methods in the encryption_km service
* file_km plugin has --file-key-management-encryption-algorithm
* debug_km always uses aes_cbc
* example_km changes between aes_cbc and aes_ecb for different key versions
2015-04-09 18:42:43 +02:00
Sergei Golubchik
b937574293 remove old my_aes_encrypt/decrypt
and simplify Item_func_aes_encrypt/decrypt
2015-04-08 10:58:46 +02:00
Oleksandr Byelkin
3502d74121 MDEV-7015: SET STATEMENT old_passwords has no effect
Decision about algorihtm moved on prepare phase.
Made possible to add mpore password algorithms.
2014-12-02 10:59:44 +01:00
Alexander Barkov
58eb51d1cf MDEV-6044 MySQL BUG#12735829 - SPACE() FUNCTION WARNING REFERS TO REPEAT() IN ER_WARN_ALLOWED_PACKET_OVERFLOWED
Merged from 5.6
2014-09-04 08:50:06 +04:00
Alexander Barkov
1427e1db99 MDEV-6661 PI() does not work well in UCS2/UTF16/UTF32 context
MDEV-6666 Malformed result for CONCAT(utf8_column, binary_string)

Item_static_string_func::safe_charset_converter() and 
Item_hex_string::safe_charset_converter() did not
handle character sets with mbminlen>1 properly, as well as
did not handle conversion from binary to multi-byte well.

Introducing Item::const_charset_converter(), to reuse it in a number
of Item_*::safe_charset_converter().
2014-09-01 20:57:32 +04:00
Alexander Barkov
c57c5be12a MDEV-5745 analyze MySQL fix for bug#12368495 2014-07-28 12:47:14 +04:00
Sergei Golubchik
6fb17a0601 5.5.39 merge 2014-08-07 18:06:56 +02:00
Alexander Barkov
1449d1d54f Moving implementation of INET_ATON() INET_NTOA() into
separate files item_inetfunc.h and item_inetfunc.cc.
2014-05-30 15:24:25 +04:00
Sergei Golubchik
10740939eb 5.5 merge 2014-03-26 22:25:38 +01:00
Sergei Golubchik
21a17536c6 5.3 merge 2014-03-25 11:09:12 +01:00
Alexander Barkov
63d0918807 MDEV-5783 Assertion `0' failed in make_sortkey(SORTPARAM*, uchar*, uchar*) on ORDER BY HEX( UNCOMPRESSED_LENGTH( pk ) ) 2014-03-23 16:02:56 +04:00
unknown
70c08df4dc MDEV-5840: group_concat( column_json(dynamic_column )) return empty result
Fixed max_length of dynamic columns json/create/add functions.
2014-03-13 10:38:41 +02:00
Sergei Golubchik
0b3d74e403 WEIGHT_STRING fix: correct Item_func_weight_string::eq() method 2014-02-03 15:27:03 +01:00
Sergei Golubchik
72c20282db 10.0-base merge 2014-02-03 15:22:39 +01:00