Commit a4bcf99f authored by Alexey Kopytov's avatar Alexey Kopytov

Backport of the fix for bug #33969: Updating a text field via a

left join 

When creating a temporary TEXT/BLOB field from an Item in
Item::make_string_field(), the field's type was unconditionally
set to the one corresponding to the maximum length (i.e.
LONGTEXT/ LONGBLOB). This resulted in problems when exactly the
same TEXT/BLOB is type required in cases like CREATE ... SELECT
or creating internal temporary tables for joins. 

Fixed by calling a different constructor for Field_blob so that
an appropriate type is used depending on the Item's max_length
value.
parent 8c1dfab3
...@@ -974,3 +974,21 @@ ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967 ...@@ -974,3 +974,21 @@ ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967
explain select convert(1, binary(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); explain select convert(1, binary(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295) ERROR 42000: Display width out of range for column 'cast as char' (max = 4294967295)
End of 5.0 tests End of 5.0 tests
CREATE TABLE t1(id INT NOT NULL);
CREATE TABLE t2(id INT NOT NULL, c TEXT NOT NULL);
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (1, '');
UPDATE t2 SET c = REPEAT('1', 70000);
Warnings:
Warning 1265 Data truncated for column 'c' at row 1
SELECT LENGTH(c) FROM t2;
LENGTH(c)
65535
UPDATE t1 LEFT JOIN t2 USING(id) SET t2.c = REPEAT('1', 70000) WHERE t1.id = 1;
Warnings:
Warning 1265 Data truncated for column 'c' at row 1
SELECT LENGTH(c) FROM t2;
LENGTH(c)
65535
DROP TABLE t1, t2;
End of 5.1 tests
...@@ -276,8 +276,8 @@ t1 int(1) NULL NO 0 # ...@@ -276,8 +276,8 @@ t1 int(1) NULL NO 0 #
t2 varchar(1) latin1_swedish_ci NO # t2 varchar(1) latin1_swedish_ci NO #
t3 varchar(256) latin1_swedish_ci NO # t3 varchar(256) latin1_swedish_ci NO #
t4 varbinary(256) NULL NO # t4 varbinary(256) NULL NO #
t5 longtext latin1_swedish_ci NO NULL # t5 text latin1_swedish_ci NO NULL #
t6 longblob NULL NO NULL # t6 blob NULL NO NULL #
t7 char(0) latin1_swedish_ci NO # t7 char(0) latin1_swedish_ci NO #
t8 binary(0) NULL NO # t8 binary(0) NULL NO #
select t1,t2,length(t3),length(t4),length(t5),length(t6),t7,t8 from t2; select t1,t2,length(t3),length(t4),length(t5),length(t6),t7,t8 from t2;
......
...@@ -612,3 +612,23 @@ explain select convert(1, binary(4294967296)); ...@@ -612,3 +612,23 @@ explain select convert(1, binary(4294967296));
explain select convert(1, binary(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); explain select convert(1, binary(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
--echo End of 5.0 tests --echo End of 5.0 tests
#
# Bug #33969: Updating a text field via a left join
#
CREATE TABLE t1(id INT NOT NULL);
CREATE TABLE t2(id INT NOT NULL, c TEXT NOT NULL);
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (1, '');
UPDATE t2 SET c = REPEAT('1', 70000);
SELECT LENGTH(c) FROM t2;
UPDATE t1 LEFT JOIN t2 USING(id) SET t2.c = REPEAT('1', 70000) WHERE t1.id = 1;
SELECT LENGTH(c) FROM t2;
DROP TABLE t1, t2;
--echo End of 5.1 tests
...@@ -5025,7 +5025,7 @@ Field *Item::make_string_field(TABLE *table) ...@@ -5025,7 +5025,7 @@ Field *Item::make_string_field(TABLE *table)
DBUG_ASSERT(collation.collation); DBUG_ASSERT(collation.collation);
if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB) if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
field= new Field_blob(max_length, maybe_null, name, field= new Field_blob(max_length, maybe_null, name,
collation.collation); collation.collation, TRUE);
/* Item_type_holder holds the exact type, do not change it */ /* Item_type_holder holds the exact type, do not change it */
else if (max_length > 0 && else if (max_length > 0 &&
(type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING)) (type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment