Skip to content

Commit 8777724

Browse files
author
Alexander Barkov
committed
MDEV-8912 Wrong metadata or type for @c:=string_or_blob_field
1 parent 8afe96f commit 8777724

File tree

11 files changed

+439
-113
lines changed

11 files changed

+439
-113
lines changed

mysql-test/r/func_hybrid_type.result

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,5 +3231,170 @@ NULL
32313231
DROP TABLE t2;
32323232
DROP TABLE t1;
32333233
#
3234+
# MDEV-8912 Wrong metadata or type for @c:=string_or_blob_field
3235+
#
3236+
CREATE TABLE t1 (c1 TINYBLOB, c2 BLOB, c3 MEDIUMBLOB, c4 LONGBLOB);
3237+
CREATE TABLE t2 AS
3238+
SELECT
3239+
@c1:=c1 AS c1,
3240+
@c2:=c2 AS c2,
3241+
@c3:=c3 AS c3,
3242+
@c4:=c4 AS c4
3243+
FROM t1;
3244+
SHOW CREATE TABLE t2;
3245+
Table Create Table
3246+
t2 CREATE TABLE `t2` (
3247+
`c1` varbinary(255) DEFAULT NULL,
3248+
`c2` blob,
3249+
`c3` mediumblob,
3250+
`c4` longblob
3251+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3252+
SELECT
3253+
@c1:=c1 AS c1,
3254+
@c2:=c2 AS c2,
3255+
@c3:=c3 AS c3,
3256+
@c4:=c4 AS c4
3257+
FROM t1;
3258+
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
3259+
def c1 253 255 0 Y 128 31 63
3260+
def c2 252 65535 0 Y 128 31 63
3261+
def c3 250 16777215 0 Y 128 31 63
3262+
def c4 251 4294967295 0 Y 128 31 63
3263+
c1 c2 c3 c4
3264+
DROP TABLE t2;
3265+
DROP TABLE t1;
3266+
CREATE TABLE t1 (c1 CHAR(1), c2 CHAR(255)) CHARACTER SET latin1;
3267+
CREATE TABLE t2 AS
3268+
SELECT
3269+
@c1:=c1 AS c1,
3270+
@c2:=c2 AS c2
3271+
FROM t1;
3272+
SHOW CREATE TABLE t2;
3273+
Table Create Table
3274+
t2 CREATE TABLE `t2` (
3275+
`c1` varchar(1) DEFAULT NULL,
3276+
`c2` varchar(255) DEFAULT NULL
3277+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3278+
SELECT
3279+
@c1:=c1 AS c1,
3280+
@c2:=c2 AS c2
3281+
FROM t1;
3282+
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
3283+
def c1 253 1 0 Y 0 31 8
3284+
def c2 253 255 0 Y 0 31 8
3285+
c1 c2
3286+
DROP TABLE t2;
3287+
DROP TABLE t1;
3288+
CREATE TABLE t1 (c1 CHAR(1), c2 CHAR(255)) CHARACTER SET utf8;
3289+
CREATE TABLE t2 AS
3290+
SELECT
3291+
@c1:=c1 AS c1,
3292+
@c2:=c2 AS c2
3293+
FROM t1;
3294+
SHOW CREATE TABLE t2;
3295+
Table Create Table
3296+
t2 CREATE TABLE `t2` (
3297+
`c1` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
3298+
`c2` varchar(255) CHARACTER SET utf8 DEFAULT NULL
3299+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3300+
SELECT
3301+
@c1:=c1 AS c1,
3302+
@c2:=c2 AS c2
3303+
FROM t1;
3304+
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
3305+
def c1 253 1 0 Y 0 31 8
3306+
def c2 253 255 0 Y 0 31 8
3307+
c1 c2
3308+
DROP TABLE t2;
3309+
DROP TABLE t1;
3310+
CREATE TABLE t1 (c1 VARCHAR(1), c2 VARCHAR(255), c3 VARCHAR(20000)) CHARACTER SET latin1;
3311+
CREATE TABLE t2 AS
3312+
SELECT
3313+
@c:=c1 AS c1,
3314+
@c:=c2 AS c2,
3315+
@c:=c3 AS c3
3316+
FROM t1;
3317+
SHOW CREATE TABLE t2;
3318+
Table Create Table
3319+
t2 CREATE TABLE `t2` (
3320+
`c1` varchar(1) DEFAULT NULL,
3321+
`c2` varchar(255) DEFAULT NULL,
3322+
`c3` text
3323+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3324+
SELECT
3325+
@c:=c1 AS c1,
3326+
@c:=c2 AS c2,
3327+
@c:=c3 AS c3
3328+
FROM t1;
3329+
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
3330+
def c1 253 1 0 Y 0 31 8
3331+
def c2 253 255 0 Y 0 31 8
3332+
def c3 252 20000 0 Y 0 31 8
3333+
c1 c2 c3
3334+
DROP TABLE t2;
3335+
DROP TABLE t1;
3336+
CREATE TABLE t1 (c1 VARCHAR(1), c2 VARCHAR(255), c3 VARCHAR(20000)) CHARACTER SET utf8;
3337+
CREATE TABLE t2 AS
3338+
SELECT
3339+
@c:=c1 AS c1,
3340+
@c:=c2 AS c2,
3341+
@c:=c3 AS c3
3342+
FROM t1;
3343+
SHOW CREATE TABLE t2;
3344+
Table Create Table
3345+
t2 CREATE TABLE `t2` (
3346+
`c1` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
3347+
`c2` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
3348+
`c3` text CHARACTER SET utf8
3349+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3350+
SELECT
3351+
@c:=c1 AS c1,
3352+
@c:=c2 AS c2,
3353+
@c:=c3 AS c3
3354+
FROM t1;
3355+
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
3356+
def c1 253 1 0 Y 0 31 8
3357+
def c2 253 255 0 Y 0 31 8
3358+
def c3 252 60000 0 Y 0 31 8
3359+
c1 c2 c3
3360+
DROP TABLE t2;
3361+
DROP TABLE t1;
3362+
CREATE TABLE t1 (c1 ENUM('a')) CHARACTER SET latin1;
3363+
CREATE TABLE t2 AS
3364+
SELECT
3365+
@c:=c1 AS c1
3366+
FROM t1;
3367+
SHOW CREATE TABLE t2;
3368+
Table Create Table
3369+
t2 CREATE TABLE `t2` (
3370+
`c1` varchar(1) DEFAULT NULL
3371+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3372+
SELECT
3373+
@c:=c1 AS c1
3374+
FROM t1;
3375+
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
3376+
def c1 253 1 0 Y 0 0 8
3377+
c1
3378+
DROP TABLE t2;
3379+
DROP TABLE t1;
3380+
CREATE TABLE t1 (c1 ENUM('a')) CHARACTER SET utf8;
3381+
CREATE TABLE t2 AS
3382+
SELECT
3383+
@c:=c1 AS c1
3384+
FROM t1;
3385+
SHOW CREATE TABLE t2;
3386+
Table Create Table
3387+
t2 CREATE TABLE `t2` (
3388+
`c1` varchar(1) CHARACTER SET utf8 DEFAULT NULL
3389+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3390+
SELECT
3391+
@c:=c1 AS c1
3392+
FROM t1;
3393+
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
3394+
def c1 253 1 0 Y 0 0 8
3395+
c1
3396+
DROP TABLE t2;
3397+
DROP TABLE t1;
3398+
#
32343399
# End of 10.1 tests
32353400
#

mysql-test/t/func_hybrid_type.test

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,140 @@ DROP TABLE t2;
299299
DROP TABLE t1;
300300

301301

302+
--echo #
303+
--echo # MDEV-8912 Wrong metadata or type for @c:=string_or_blob_field
304+
--echo #
305+
CREATE TABLE t1 (c1 TINYBLOB, c2 BLOB, c3 MEDIUMBLOB, c4 LONGBLOB);
306+
CREATE TABLE t2 AS
307+
SELECT
308+
@c1:=c1 AS c1,
309+
@c2:=c2 AS c2,
310+
@c3:=c3 AS c3,
311+
@c4:=c4 AS c4
312+
FROM t1;
313+
SHOW CREATE TABLE t2;
314+
--disable_ps_protocol
315+
--enable_metadata
316+
SELECT
317+
@c1:=c1 AS c1,
318+
@c2:=c2 AS c2,
319+
@c3:=c3 AS c3,
320+
@c4:=c4 AS c4
321+
FROM t1;
322+
--disable_metadata
323+
--enable_ps_protocol
324+
DROP TABLE t2;
325+
DROP TABLE t1;
326+
327+
CREATE TABLE t1 (c1 CHAR(1), c2 CHAR(255)) CHARACTER SET latin1;
328+
CREATE TABLE t2 AS
329+
SELECT
330+
@c1:=c1 AS c1,
331+
@c2:=c2 AS c2
332+
FROM t1;
333+
SHOW CREATE TABLE t2;
334+
--disable_ps_protocol
335+
--enable_metadata
336+
SELECT
337+
@c1:=c1 AS c1,
338+
@c2:=c2 AS c2
339+
FROM t1;
340+
--disable_metadata
341+
--enable_ps_protocol
342+
DROP TABLE t2;
343+
DROP TABLE t1;
344+
345+
CREATE TABLE t1 (c1 CHAR(1), c2 CHAR(255)) CHARACTER SET utf8;
346+
CREATE TABLE t2 AS
347+
SELECT
348+
@c1:=c1 AS c1,
349+
@c2:=c2 AS c2
350+
FROM t1;
351+
SHOW CREATE TABLE t2;
352+
--disable_ps_protocol
353+
--enable_metadata
354+
SELECT
355+
@c1:=c1 AS c1,
356+
@c2:=c2 AS c2
357+
FROM t1;
358+
--disable_metadata
359+
--enable_ps_protocol
360+
DROP TABLE t2;
361+
DROP TABLE t1;
362+
363+
CREATE TABLE t1 (c1 VARCHAR(1), c2 VARCHAR(255), c3 VARCHAR(20000)) CHARACTER SET latin1;
364+
CREATE TABLE t2 AS
365+
SELECT
366+
@c:=c1 AS c1,
367+
@c:=c2 AS c2,
368+
@c:=c3 AS c3
369+
FROM t1;
370+
SHOW CREATE TABLE t2;
371+
--disable_ps_protocol
372+
--enable_metadata
373+
SELECT
374+
@c:=c1 AS c1,
375+
@c:=c2 AS c2,
376+
@c:=c3 AS c3
377+
FROM t1;
378+
--disable_metadata
379+
--enable_ps_protocol
380+
DROP TABLE t2;
381+
DROP TABLE t1;
382+
383+
CREATE TABLE t1 (c1 VARCHAR(1), c2 VARCHAR(255), c3 VARCHAR(20000)) CHARACTER SET utf8;
384+
CREATE TABLE t2 AS
385+
SELECT
386+
@c:=c1 AS c1,
387+
@c:=c2 AS c2,
388+
@c:=c3 AS c3
389+
FROM t1;
390+
SHOW CREATE TABLE t2;
391+
--disable_ps_protocol
392+
--enable_metadata
393+
SELECT
394+
@c:=c1 AS c1,
395+
@c:=c2 AS c2,
396+
@c:=c3 AS c3
397+
FROM t1;
398+
--disable_metadata
399+
--enable_ps_protocol
400+
DROP TABLE t2;
401+
DROP TABLE t1;
402+
403+
CREATE TABLE t1 (c1 ENUM('a')) CHARACTER SET latin1;
404+
CREATE TABLE t2 AS
405+
SELECT
406+
@c:=c1 AS c1
407+
FROM t1;
408+
SHOW CREATE TABLE t2;
409+
--disable_ps_protocol
410+
--enable_metadata
411+
SELECT
412+
@c:=c1 AS c1
413+
FROM t1;
414+
--disable_metadata
415+
--enable_ps_protocol
416+
DROP TABLE t2;
417+
DROP TABLE t1;
418+
419+
CREATE TABLE t1 (c1 ENUM('a')) CHARACTER SET utf8;
420+
CREATE TABLE t2 AS
421+
SELECT
422+
@c:=c1 AS c1
423+
FROM t1;
424+
SHOW CREATE TABLE t2;
425+
--disable_ps_protocol
426+
--enable_metadata
427+
SELECT
428+
@c:=c1 AS c1
429+
FROM t1;
430+
--disable_metadata
431+
--enable_ps_protocol
432+
DROP TABLE t2;
433+
DROP TABLE t1;
434+
435+
302436
--echo #
303437
--echo # End of 10.1 tests
304438
--echo #

sql/item.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5565,7 +5565,9 @@ Field *Item::make_string_field(TABLE *table)
55655565
\# Created field
55665566
*/
55675567

5568-
Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length)
5568+
Field *Item::tmp_table_field_from_field_type(TABLE *table,
5569+
bool fixed_length,
5570+
bool set_blob_packlength)
55695571
{
55705572
/*
55715573
The field functions defines a field to be not null if null_ptr is not 0
@@ -5663,12 +5665,9 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length)
56635665
case MYSQL_TYPE_MEDIUM_BLOB:
56645666
case MYSQL_TYPE_LONG_BLOB:
56655667
case MYSQL_TYPE_BLOB:
5666-
if (this->type() == Item::TYPE_HOLDER)
5667-
field= new (mem_root)
5668-
Field_blob(max_length, maybe_null, name, collation.collation, 1);
5669-
else
5670-
field= new (mem_root)
5671-
Field_blob(max_length, maybe_null, name, collation.collation);
5668+
field= new (mem_root)
5669+
Field_blob(max_length, maybe_null, name,
5670+
collation.collation, set_blob_packlength);
56725671
break; // Blob handled outside of case
56735672
#ifdef HAVE_SPATIAL
56745673
case MYSQL_TYPE_GEOMETRY:
@@ -9551,7 +9550,7 @@ Field *Item_type_holder::make_field_by_type(TABLE *table)
95519550
default:
95529551
break;
95539552
}
9554-
return tmp_table_field_from_field_type(table, 0);
9553+
return tmp_table_field_from_field_type(table, false, true);
95559554
}
95569555

95579556

sql/item.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,8 @@ class Item: public Value_source,
10231023
virtual Field *get_tmp_table_field() { return 0; }
10241024
/* This is also used to create fields in CREATE ... SELECT: */
10251025
virtual Field *tmp_table_field(TABLE *t_arg) { return 0; }
1026+
virtual Field *create_field_for_create_select(THD *thd, TABLE *table);
1027+
virtual Field *create_field_for_schema(THD *thd, TABLE *table);
10261028
virtual const char *full_name() const { return name ? name : "???"; }
10271029
const char *field_name_or_null()
10281030
{ return real_item()->type() == Item::FIELD_ITEM ? name : NULL; }
@@ -1626,7 +1628,9 @@ class Item: public Value_source,
16261628
// used in row subselects to get value of elements
16271629
virtual void bring_value() {}
16281630

1629-
Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length);
1631+
Field *tmp_table_field_from_field_type(TABLE *table,
1632+
bool fixed_length,
1633+
bool set_blob_packlength);
16301634
virtual Item_field *field_for_view_update() { return 0; }
16311635

16321636
virtual Item *neg_transformer(THD *thd) { return NULL; }
@@ -3190,6 +3194,8 @@ class Item_blob :public Item_partition_func_safe_string
31903194
{ max_length= length; }
31913195
enum Type type() const { return TYPE_HOLDER; }
31923196
enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
3197+
Field *create_field_for_schema(THD *thd, TABLE *table)
3198+
{ return tmp_table_field_from_field_type(table, false, true); }
31933199
};
31943200

31953201

@@ -3384,7 +3390,7 @@ class Item_temporal_literal :public Item_basic_constant
33843390
my_decimal *val_decimal(my_decimal *decimal_value)
33853391
{ return val_decimal_from_date(decimal_value); }
33863392
Field *tmp_table_field(TABLE *table)
3387-
{ return tmp_table_field_from_field_type(table, 0); }
3393+
{ return tmp_table_field_from_field_type(table, false, false); }
33883394
int save_in_field(Field *field, bool no_conversions)
33893395
{ return save_date_in_field(field); }
33903396
};

sql/item_cmpfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ uint Item_func_case_abbreviation2::decimal_precision2(Item **args) const
22662266

22672267
Field *Item_func_ifnull::tmp_table_field(TABLE *table)
22682268
{
2269-
return tmp_table_field_from_field_type(table, 0);
2269+
return tmp_table_field_from_field_type(table, false, false);
22702270
}
22712271

22722272
double

0 commit comments

Comments
 (0)