Skip to content

Commit 4458a6a

Browse files
committed
Bug#36725332 BLOB_INLINE_SIZE is silently ignored for TINYBLOB
Problem: A NDB table, with a SQL TINYBLOB column configured with the BLOB_INLINE_SIZE NDB column option, would (silently) default to the hardcoded 256 byte value whichever the new size provided. Therefore, it would not only mislead the user but also not provide the configurability of BLOB inline size. Analysis: On creation of the NDB column from the NDB cluster plugin, the TINYBLOB case would never read the BLOB_INLINE_SIZE option, therefore setting the 256 default value. MySQL server already gives the 255 byte value to be the maximum for a TINYBLOB, thus no over the maximum writes would be available. However, the BLOB_INLINE_SIZE option also allows the maximum stored value to be less so that more columns can be fitted into each row (max of 30k bytes for NDB rows). Solution: Do not support BLOB_INLINE_SIZE on SQL TINYBLOB columns altogether. The reasons are many: 1) TINYBLOB is internally limited to 255 bytes on MySQL server field side (1 byte of packlength) 2) Same behavior can be achieved with VARBINARY with less hassle 3) Gets no benefit on the properties of NDB, such as having distributed parts of rows partitioned across the cluster. NDB plugin code now pushes a warning saying it is defaulting to base 256 bytes. Change-Id: Iab6a3009e5f5e407ef3bef18caf31ed6ed2810a3
1 parent 63d9403 commit 4458a6a

File tree

3 files changed

+93
-12
lines changed

3 files changed

+93
-12
lines changed

mysql-test/suite/ndb/r/ndb_blob_size.result

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,21 @@ inline_size
253253

254254
DROP TABLE test.maxlen;
255255

256+
## TINYBLOB columns ignore the BLOB_INLINE_SIZE option
257+
CREATE TABLE test.bigtiny(
258+
a int primary key,
259+
tb tinyblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=512") engine=ndb;
260+
Warnings:
261+
Warning 1296 BLOB_INLINE_SIZE not supported for BLOB column with no part table (e.g. TINYBLOB), using default value 256
262+
CREATE TABLE test.smalltiny(
263+
a int primary key,
264+
tb tinyblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=128") engine=ndb;
265+
Warnings:
266+
Warning 1296 BLOB_INLINE_SIZE not supported for BLOB column with no part table (e.g. TINYBLOB), using default value 256
267+
268+
DROP TABLE test.bigtiny;
269+
DROP TABLE test.smalltiny;
270+
256271
## ALTER definitions of extended Blob feature BLOB_INLINE_SIZE
257272
CREATE TABLE test.inline(
258273
a int primary key,
@@ -399,7 +414,7 @@ c0bb7371406f4b1c5d579dcaad1ff066a3bd09e6 c0bb7371406f4b1c5d579dcaad1ff066a3bd09e
399414
## Copy ALTER TABLE too big BLOB_INLINE_SIZE
400415
ALTER TABLE test.inline algorithm=copy,
401416
change column b b longblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=27949",
402-
change column t t longtext comment "NDB_COLUMM_BLOB_INLINE_SIZE=1000",
417+
change column t t longtext comment "NDB_COLUMM=BLOB_INLINE_SIZE=1000",
403418
change column j j json comment "NDB_COLUMN=BLOB_INLINE_SIZE=27949";
404419
ERROR HY000: Can't create destination table for copying alter table (use SHOW WARNINGS for more info).
405420
SHOW WARNINGS;
@@ -425,6 +440,30 @@ Level Code Message
425440
Warning 1478 NDB_COLUMN= : unknown modifier: randomBLOB_INLINE_SIZE=25
426441
Error 1478 Table storage engine 'ndbcluster' does not support the create option 'Syntax error in COMMENT modifier'
427442

443+
## ALTER TABLE on table for TINYBLOB
444+
ALTER TABLE test.inline change column b tb tinyblob;
445+
ERROR 22001: Data too long for column 'tb' at row 1
446+
## Length value on b (1536) is still larger than what can fit in TINYBLOB length (255)
447+
ALTER TABLE test.inline change column b b longblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=255";
448+
ALTER TABLE test.inline change column b tb tinyblob;
449+
ERROR 22001: Data too long for column 'tb' at row 1
450+
451+
## Must update data to allow to fit TINYBLOB
452+
UPDATE test.inline SET b = repeat(0x424C4F, 64) WHERE a = 1;
453+
ALTER TABLE test.inline change column b tb tinyblob;
454+
SELECT a, length(tb) FROM test.inline;
455+
a length(tb)
456+
1 192
457+
458+
CREATE TABLE test.tiny (
459+
a int primary key,
460+
tb tinyblob) engine = ndb;
461+
## Always ignored for TINYBLOB
462+
ALTER TABLE test.tiny change column tb tb tinyblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=128";
463+
Warnings:
464+
Warning 1296 BLOB_INLINE_SIZE not supported for BLOB column with no part table (e.g. TINYBLOB), using default value 256
465+
466+
DROP TABLE test.tiny;
428467
DROP TABLE test.inline;
429468

430469
## Show Backup and Restore across BLOB inline sizes

mysql-test/suite/ndb/t/ndb_blob_size.test

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ CREATE TABLE test.maxlen(
185185
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'maxlen';
186186

187187
DROP TABLE test.maxlen;
188+
189+
## TINYBLOB columns ignore the BLOB_INLINE_SIZE option
190+
CREATE TABLE test.bigtiny(
191+
a int primary key,
192+
tb tinyblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=512") engine=ndb;
193+
CREATE TABLE test.smalltiny(
194+
a int primary key,
195+
tb tinyblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=128") engine=ndb;
196+
197+
DROP TABLE test.bigtiny;
198+
DROP TABLE test.smalltiny;
188199
--echo
189200

190201
# WL#15044 Configurable BLOB inline size
@@ -291,7 +302,7 @@ SELECT sha1(b), sha1(t), sha1(j) FROM test.inline;
291302
--error ER_CANT_CREATE_TABLE
292303
ALTER TABLE test.inline algorithm=copy,
293304
change column b b longblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=27949",
294-
change column t t longtext comment "NDB_COLUMM_BLOB_INLINE_SIZE=1000",
305+
change column t t longtext comment "NDB_COLUMM=BLOB_INLINE_SIZE=1000",
295306
change column j j json comment "NDB_COLUMN=BLOB_INLINE_SIZE=27949";
296307
SHOW WARNINGS;
297308

@@ -306,6 +317,26 @@ SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'inline';
306317
ALTER TABLE test.inline change column b b longblob comment "NDB_COLUMN=randomBLOB_INLINE_SIZE=25";
307318
SHOW WARNINGS LIMIT 2;
308319

320+
## ALTER TABLE on table for TINYBLOB
321+
--error ER_DATA_TOO_LONG
322+
ALTER TABLE test.inline change column b tb tinyblob;
323+
## Length value on b (1536) is still larger than what can fit in TINYBLOB length (255)
324+
ALTER TABLE test.inline change column b b longblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=255";
325+
--error ER_DATA_TOO_LONG
326+
ALTER TABLE test.inline change column b tb tinyblob;
327+
328+
## Must update data to allow to fit TINYBLOB
329+
UPDATE test.inline SET b = repeat(0x424C4F, 64) WHERE a = 1;
330+
ALTER TABLE test.inline change column b tb tinyblob;
331+
SELECT a, length(tb) FROM test.inline;
332+
333+
CREATE TABLE test.tiny (
334+
a int primary key,
335+
tb tinyblob) engine = ndb;
336+
## Always ignored for TINYBLOB
337+
ALTER TABLE test.tiny change column tb tb tinyblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=128";
338+
339+
DROP TABLE test.tiny;
309340
DROP TABLE test.inline;
310341
--echo
311342

storage/ndb/plugin/ha_ndbcluster.cc

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8170,6 +8170,15 @@ static int create_ndb_column(THD *thd, NDBCOL &col, Field *field,
81708170
}
81718171
mod_size = size;
81728172
}
8173+
if (col.getPartSize() == 0) {
8174+
if (thd) {
8175+
get_thd_ndb(thd)->push_warning(
8176+
"BLOB_INLINE_SIZE not supported for BLOB column with no part "
8177+
"table (e.g. TINYBLOB), using default value %d",
8178+
size);
8179+
}
8180+
mod_size = size;
8181+
}
81738182
col.setInlineSize(mod_size);
81748183
} else {
81758184
col.setInlineSize(size);
@@ -8364,10 +8373,10 @@ static int create_ndb_column(THD *thd, NDBCOL &col, Field *field,
83648373
col.setType(NDBCOL::Text);
83658374
col.setCharset(cs);
83668375
}
8367-
col.setInlineSize(256);
83688376
// No parts
83698377
col.setPartSize(0);
83708378
col.setStripeSize(0);
8379+
set_blob_inline_size(thd, col, 256);
83718380
break;
83728381
// mysql_type_blob:
83738382
case MYSQL_TYPE_GEOMETRY:
@@ -8391,12 +8400,13 @@ static int create_ndb_column(THD *thd, NDBCOL &col, Field *field,
83918400
if (field_blob->max_data_length() < (1 << 8))
83928401
goto mysql_type_tiny_blob;
83938402
else if (field_blob->max_data_length() < (1 << 16)) {
8394-
set_blob_inline_size(thd, col, 256);
8395-
col.setPartSize(2000);
8396-
col.setStripeSize(0);
83978403
if (mod_maxblob->m_found) {
83988404
col.setPartSize(DEFAULT_MAX_BLOB_PART_SIZE);
8405+
} else {
8406+
col.setPartSize(2000);
83998407
}
8408+
col.setStripeSize(0);
8409+
set_blob_inline_size(thd, col, 256);
84008410
} else if (field_blob->max_data_length() < (1 << 24))
84018411
goto mysql_type_medium_blob;
84028412
else
@@ -8411,12 +8421,13 @@ static int create_ndb_column(THD *thd, NDBCOL &col, Field *field,
84118421
col.setType(NDBCOL::Text);
84128422
col.setCharset(cs);
84138423
}
8414-
set_blob_inline_size(thd, col, 256);
8415-
col.setPartSize(4000);
8416-
col.setStripeSize(0);
84178424
if (mod_maxblob->m_found) {
84188425
col.setPartSize(DEFAULT_MAX_BLOB_PART_SIZE);
8426+
} else {
8427+
col.setPartSize(4000);
84198428
}
8429+
col.setStripeSize(0);
8430+
set_blob_inline_size(thd, col, 256);
84208431
break;
84218432
mysql_type_long_blob:
84228433
case MYSQL_TYPE_LONG_BLOB:
@@ -8426,10 +8437,10 @@ static int create_ndb_column(THD *thd, NDBCOL &col, Field *field,
84268437
col.setType(NDBCOL::Text);
84278438
col.setCharset(cs);
84288439
}
8429-
set_blob_inline_size(thd, col, 256);
8440+
// The mod_maxblob modified has no effect here, already at max
84308441
col.setPartSize(DEFAULT_MAX_BLOB_PART_SIZE);
84318442
col.setStripeSize(0);
8432-
// The mod_maxblob modified has no effect here, already at max
8443+
set_blob_inline_size(thd, col, 256);
84338444
break;
84348445

84358446
// MySQL 5.7 binary-encoded JSON type
@@ -8448,9 +8459,9 @@ static int create_ndb_column(THD *thd, NDBCOL &col, Field *field,
84488459
const int NDB_JSON_PART_SIZE = 8100;
84498460

84508461
col.setType(NDBCOL::Blob);
8451-
set_blob_inline_size(thd, col, NDB_JSON_INLINE_SIZE);
84528462
col.setPartSize(NDB_JSON_PART_SIZE);
84538463
col.setStripeSize(0);
8464+
set_blob_inline_size(thd, col, NDB_JSON_INLINE_SIZE);
84548465
break;
84558466
}
84568467

0 commit comments

Comments
 (0)