MDEV-8630 Datetime value dropped in "INSERT ... SELECT ... ON DUPLICATE KEY"

Item_func_coalesce::fix_length_and_dec() calls
Item_func::count_string_result_length()) which called agg_arg_charsets()
with wrong flags, so the collation derivation of the COALESCE result was
not properly set to DERIVATION_COERCIBLE. It erroneously stayed
DERIVATION_NUMERIC. So GREATEST() misinterpreted the argument as
a number rather that a string and did not calculate its own length properly.
This commit is contained in:
Alexander Barkov 2015-12-03 20:43:54 +04:00
commit d87bc55b05
3 changed files with 44 additions and 1 deletions

View file

@ -1631,6 +1631,22 @@ INSERT INTO t2 VALUES ('aaa');
SELECT (SELECT CONCAT(a),1 FROM t1) <=> (SELECT CONCAT(a),1 FROM t2);
DROP TABLE t1, t2;
--echo #
--echo # MDEV-8630 Datetime value dropped in "INSERT ... SELECT ... ON DUPLICATE KEY"
--echo #
SET NAMES utf8;
CREATE TABLE t1 (id2 int, ts timestamp);
INSERT INTO t1 VALUES (1,'2012-06-11 15:17:34'),(2,'2012-06-11 15:18:24');
CREATE TABLE t2 AS SELECT
COALESCE(ts, 0) AS c0,
GREATEST(COALESCE(ts, 0), COALESCE(ts, 0)) AS c1,
GREATEST(CASE WHEN 1 THEN ts ELSE 0 END, CASE WHEN 1 THEN ts ELSE 0 END) AS c2,
GREATEST(IFNULL(ts,0), IFNULL(ts,0)) AS c3,
GREATEST(IF(1,ts,0), IF(1,ts,0)) AS c4
FROM t1;
SHOW CREATE TABLE t2;
SELECT * FROM t2;
DROP TABLE t2, t1;
--echo #
--echo # End of 5.5 tests