Skip to content

Commit 9c1d12e

Browse files
author
Sreeharsha Ramanavarapu
committed
Merge branch 'mysql-5.5' into mysql-5.6
2 parents 12ada74 + 888fabd commit 9c1d12e

4 files changed

Lines changed: 47 additions & 10 deletions

File tree

mysql-test/r/update.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,3 +593,16 @@ Variable_name Value
593593
Handler_update 5
594594
ROLLBACK;
595595
DROP TABLE t1, t2;
596+
# Bug #21143080: UPDATE ON VARCHAR AND TEXT COLUMNS PRODUCE INCORRECT
597+
# RESULTS
598+
CREATE TABLE t1 (a VARCHAR(50), b TEXT, c CHAR(50)) ENGINE=INNODB;
599+
INSERT INTO t1 (a, b, c) VALUES ('start trail', '', 'even longer string');
600+
UPDATE t1 SET b = a, a = 'inject';
601+
SELECT a, b FROM t1;
602+
a b
603+
inject start trail
604+
UPDATE t1 SET b = c, c = 'inject';
605+
SELECT c, b FROM t1;
606+
c b
607+
inject even longer string
608+
DROP TABLE t1;

mysql-test/t/update.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,3 +541,16 @@ UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
541541
SHOW STATUS LIKE 'HANDLER_UPDATE';
542542
ROLLBACK;
543543
DROP TABLE t1, t2;
544+
545+
--echo # Bug #21143080: UPDATE ON VARCHAR AND TEXT COLUMNS PRODUCE INCORRECT
546+
--echo # RESULTS
547+
548+
CREATE TABLE t1 (a VARCHAR(50), b TEXT, c CHAR(50)) ENGINE=INNODB;
549+
550+
INSERT INTO t1 (a, b, c) VALUES ('start trail', '', 'even longer string');
551+
UPDATE t1 SET b = a, a = 'inject';
552+
SELECT a, b FROM t1;
553+
UPDATE t1 SET b = c, c = 'inject';
554+
SELECT c, b FROM t1;
555+
556+
DROP TABLE t1;

sql/field.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef FIELD_INCLUDED
22
#define FIELD_INCLUDED
33

4-
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -1236,6 +1236,17 @@ class Field
12361236

12371237
/* Hash value */
12381238
virtual void hash(ulong *nr, ulong *nr2);
1239+
1240+
/**
1241+
Checks whether a string field is part of write_set.
1242+
1243+
@return
1244+
FALSE - If field is not char/varchar/....
1245+
- If field is char/varchar/.. and is not part of write set.
1246+
TRUE - If field is char/varchar/.. and is part of write set.
1247+
*/
1248+
virtual bool is_updatable() const { return FALSE; }
1249+
12391250
friend int cre_myisam(char * name, register TABLE *form, uint options,
12401251
ulonglong auto_increment_value);
12411252
friend class Copy_field;
@@ -1523,6 +1534,11 @@ class Field_longstr :public Field_str
15231534

15241535
type_conversion_status store_decimal(const my_decimal *d);
15251536
uint32 max_data_length() const;
1537+
bool is_updatable() const
1538+
{
1539+
DBUG_ASSERT(table && table->write_set);
1540+
return bitmap_is_set(table->write_set, field_index);
1541+
}
15261542
};
15271543

15281544
/* base class for float and double and decimal (old one) */

sql/field_conv.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -826,15 +826,10 @@ type_conversion_status field_conv(Field *to,Field *from)
826826
{ // Be sure the value is stored
827827
Field_blob *blob=(Field_blob*) to;
828828
from->val_str(&blob->value);
829-
/*
830-
Copy value if copy_blobs is set, or source is not a string and
831-
we have a pointer to its internal string conversion buffer.
832-
*/
833-
if (to->table->copy_blobs ||
834-
(!blob->value.is_alloced() &&
835-
from->real_type() != MYSQL_TYPE_STRING &&
836-
from->real_type() != MYSQL_TYPE_VARCHAR))
829+
830+
if (!blob->value.is_alloced() && from->is_updatable())
837831
blob->value.copy();
832+
838833
return blob->store(blob->value.ptr(),blob->value.length(),from->charset());
839834
}
840835
if (from->real_type() == MYSQL_TYPE_ENUM &&

0 commit comments

Comments
 (0)