Skip to content

Commit 130e8fc

Browse files
committed
Bug#36724336 BLOB_INLINE_SIZE=0 is ignored
When BLOB_INLINE_SIZE=0 is used as a NDB_COLUMN option for column's COMMENT, the option is ignored and the default inline size for the BLOB type is used. The main issue is that the function that reads the conversion was also ignoring a successful conversion to 0 ( <= 0 ). Changed to use strtol for better conversion functionality and made sanity check just use "< 0". Change-Id: Ieb652f720c626443c66a7ff1303c1e7f4fe283f1
1 parent 3bd325a commit 130e8fc

File tree

3 files changed

+103
-20
lines changed

3 files changed

+103
-20
lines changed

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

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@ inline_size part_size
2323

2424
DROP TABLE test.defs;
2525

26+
## Create table with inline values of 0
27+
CREATE TABLE test.zeroinline(
28+
a int primary key,
29+
b blob comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
30+
bm mediumblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
31+
bl longblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
32+
t text comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
33+
tm mediumtext comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
34+
tl longtext comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
35+
j json comment "NDB_COLUMN=BLOB_INLINE_SIZE=0") engine=ndb;
36+
37+
## Verify inline and partition sizes of test.zeroinline
38+
SELECT inline_size, part_size FROM ndbinfo.blobs WHERE table_name = 'zeroinline';
39+
inline_size part_size
40+
0 2000
41+
0 4000
42+
0 13948
43+
0 2000
44+
0 4000
45+
0 13948
46+
0 8100
47+
48+
DROP TABLE test.zeroinline;
49+
2650
## Create table with less than default inline values
2751
CREATE TABLE test.shortinline(
2852
a int primary key,
@@ -178,11 +202,6 @@ a sha1(b) sha1(bm) sha1(bl) sha1(t) sha1(tm) sha1(tl) sha1(j)
178202
DROP TABLE test.withmaxparts;
179203

180204
## Create tables with bad values
181-
CREATE TABLE test.zerolen(
182-
a int primary key,
183-
b blob comment "NDB_COLUMN=BLOB_INLINE_SIZE=0") engine=ndb;
184-
Warnings:
185-
Warning 1296 Failed to parse BLOB_INLINE_SIZE=0, using default value 256
186205
CREATE TABLE test.neglen(
187206
a int primary key,
188207
b blob comment "NDB_COLUMN=BLOB_INLINE_SIZE=-20") engine=ndb;
@@ -194,18 +213,14 @@ CREATE TABLE test.badchar(
194213
Warnings:
195214
Warning 1296 Failed to parse BLOB_INLINE_SIZE=ten, using default value 256
196215

197-
## Verify inline of test.zerolen and test.neglen
198-
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'zerolen';
199-
inline_size
200-
256
216+
## Verify inline_size
201217
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'neglen';
202218
inline_size
203219
256
204220
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'badchar';
205221
inline_size
206222
256
207223

208-
DROP TABLE test.zerolen;
209224
DROP TABLE test.neglen;
210225
DROP TABLE test.badchar;
211226

@@ -321,6 +336,15 @@ SHOW WARNINGS;
321336
Level Code Message
322337
Error 1846 ALGORITHM=INPLACE is not supported. Reason: NDB_COLUMN= comment changed. Try ALGORITHM=COPY.
323338

339+
## Insert some data and verify that read data remains the same
340+
INSERT INTO test.inline (a, b, t, j) VALUES (1,
341+
repeat(0x424C4F, 512),
342+
repeat(0x424C4F, 512),
343+
"{\"a\": \"42\"}");
344+
SELECT sha1(b), sha1(t), sha1(j) FROM test.inline;
345+
sha1(b) sha1(t) sha1(j)
346+
c0bb7371406f4b1c5d579dcaad1ff066a3bd09e6 c0bb7371406f4b1c5d579dcaad1ff066a3bd09e6 8bef4ce42aa0c9268e300438f01d118b75e3b423
347+
324348
## Copy ALTER TABLE change column BLOB_INLINE_SIZE changes inline_blob_size
325349
ALTER TABLE test.inline algorithm=copy,
326350
change column b b longblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=1000",
@@ -333,6 +357,10 @@ inline_size
333357
1000
334358
1000
335359
10000
360+
## Verify data
361+
SELECT sha1(b), sha1(t), sha1(j) FROM test.inline;
362+
sha1(b) sha1(t) sha1(j)
363+
c0bb7371406f4b1c5d579dcaad1ff066a3bd09e6 c0bb7371406f4b1c5d579dcaad1ff066a3bd09e6 8bef4ce42aa0c9268e300438f01d118b75e3b423
336364

337365
## Copy ALTER TABLE change back BLOB_INLINE_SIZE to less
338366
ALTER TABLE test.inline algorithm=copy,
@@ -346,6 +374,27 @@ inline_size
346374
10
347375
10
348376
25
377+
## Verify data
378+
SELECT sha1(b), sha1(t), sha1(j) FROM test.inline;
379+
sha1(b) sha1(t) sha1(j)
380+
c0bb7371406f4b1c5d579dcaad1ff066a3bd09e6 c0bb7371406f4b1c5d579dcaad1ff066a3bd09e6 8bef4ce42aa0c9268e300438f01d118b75e3b423
381+
382+
## Copy ALTER TABLE change to zero inline size
383+
ALTER TABLE test.inline algorithm=copy,
384+
change column b b longblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
385+
change column t t longtext comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
386+
change column j j json comment "NDB_COLUMN=BLOB_INLINE_SIZE=0";
387+
388+
## Verify updated test.inline with zero inline size
389+
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'inline';
390+
inline_size
391+
0
392+
0
393+
0
394+
## Verify data
395+
SELECT sha1(b), sha1(t), sha1(j) FROM test.inline;
396+
sha1(b) sha1(t) sha1(j)
397+
c0bb7371406f4b1c5d579dcaad1ff066a3bd09e6 c0bb7371406f4b1c5d579dcaad1ff066a3bd09e6 8bef4ce42aa0c9268e300438f01d118b75e3b423
349398

350399
## Copy ALTER TABLE too big BLOB_INLINE_SIZE
351400
ALTER TABLE test.inline algorithm=copy,
@@ -365,8 +414,8 @@ ALTER TABLE test.inline change column b b longblob comment "randomNDB_COLUMN=BLO
365414
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'inline';
366415
inline_size
367416
15
368-
10
369-
25
417+
0
418+
0
370419

371420
## ALTER TABLE random characters on COMMENT after NDB_COLUMN
372421
ALTER TABLE test.inline change column b b longblob comment "NDB_COLUMN=randomBLOB_INLINE_SIZE=25";

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

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ SELECT inline_size, part_size FROM ndbinfo.blobs WHERE table_name = 'defs';
1919

2020
DROP TABLE test.defs;
2121

22+
## Create table with inline values of 0
23+
CREATE TABLE test.zeroinline(
24+
a int primary key,
25+
b blob comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
26+
bm mediumblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
27+
bl longblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
28+
t text comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
29+
tm mediumtext comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
30+
tl longtext comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
31+
j json comment "NDB_COLUMN=BLOB_INLINE_SIZE=0") engine=ndb;
32+
33+
## Verify inline and partition sizes of test.zeroinline
34+
SELECT inline_size, part_size FROM ndbinfo.blobs WHERE table_name = 'zeroinline';
35+
36+
DROP TABLE test.zeroinline;
37+
2238
## Create table with less than default inline values
2339
CREATE TABLE test.shortinline(
2440
a int primary key,
@@ -135,22 +151,17 @@ DROP TABLE test.withmaxparts;
135151

136152
## Create tables with bad values
137153

138-
CREATE TABLE test.zerolen(
139-
a int primary key,
140-
b blob comment "NDB_COLUMN=BLOB_INLINE_SIZE=0") engine=ndb;
141154
CREATE TABLE test.neglen(
142155
a int primary key,
143156
b blob comment "NDB_COLUMN=BLOB_INLINE_SIZE=-20") engine=ndb;
144157
CREATE TABLE test.badchar(
145158
a int primary key,
146159
b blob comment "NDB_COLUMN=BLOB_INLINE_SIZE=ten") engine=ndb;
147160

148-
## Verify inline of test.zerolen and test.neglen
149-
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'zerolen';
161+
## Verify inline_size
150162
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'neglen';
151163
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'badchar';
152164

153-
DROP TABLE test.zerolen;
154165
DROP TABLE test.neglen;
155166
DROP TABLE test.badchar;
156167

@@ -236,6 +247,13 @@ ALTER TABLE test.inline ALGORITHM=inplace,
236247
change column b b longblob comment "NDB_COLUMNrandom= BLOB_INLINE_SIZE=1000";
237248
SHOW WARNINGS;
238249

250+
## Insert some data and verify that read data remains the same
251+
INSERT INTO test.inline (a, b, t, j) VALUES (1,
252+
repeat(0x424C4F, 512),
253+
repeat(0x424C4F, 512),
254+
"{\"a\": \"42\"}");
255+
SELECT sha1(b), sha1(t), sha1(j) FROM test.inline;
256+
239257
## Copy ALTER TABLE change column BLOB_INLINE_SIZE changes inline_blob_size
240258
ALTER TABLE test.inline algorithm=copy,
241259
change column b b longblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=1000",
@@ -244,6 +262,8 @@ ALTER TABLE test.inline algorithm=copy,
244262

245263
## Verify updated test.inline
246264
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'inline';
265+
## Verify data
266+
SELECT sha1(b), sha1(t), sha1(j) FROM test.inline;
247267

248268
## Copy ALTER TABLE change back BLOB_INLINE_SIZE to less
249269
ALTER TABLE test.inline algorithm=copy,
@@ -253,6 +273,19 @@ ALTER TABLE test.inline algorithm=copy,
253273

254274
## Verify updated test.inline with reduced BLOB_INLINE_SIZE
255275
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'inline';
276+
## Verify data
277+
SELECT sha1(b), sha1(t), sha1(j) FROM test.inline;
278+
279+
## Copy ALTER TABLE change to zero inline size
280+
ALTER TABLE test.inline algorithm=copy,
281+
change column b b longblob comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
282+
change column t t longtext comment "NDB_COLUMN=BLOB_INLINE_SIZE=0",
283+
change column j j json comment "NDB_COLUMN=BLOB_INLINE_SIZE=0";
284+
285+
## Verify updated test.inline with zero inline size
286+
SELECT inline_size FROM ndbinfo.blobs WHERE table_name = 'inline';
287+
## Verify data
288+
SELECT sha1(b), sha1(t), sha1(j) FROM test.inline;
256289

257290
## Copy ALTER TABLE too big BLOB_INLINE_SIZE
258291
--error ER_CANT_CREATE_TABLE

storage/ndb/plugin/ha_ndbcluster.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8149,11 +8149,12 @@ static int create_ndb_column(THD *thd, NDBCOL &col, Field *field,
81498149
const NDB_Modifier *mod = column_modifiers.get("BLOB_INLINE_SIZE");
81508150

81518151
if (mod->m_found) {
8152-
int mod_size = atoi(mod->m_val_str.str);
8152+
char *end = nullptr;
8153+
long mod_size = strtol(mod->m_val_str.str, &end, 10);
81538154

81548155
if (mod_size > INT_MAX) mod_size = INT_MAX;
81558156

8156-
if (mod_size <= 0) {
8157+
if (*end != 0 || mod_size < 0) {
81578158
if (thd) {
81588159
get_thd_ndb(thd)->push_warning(
81598160
"Failed to parse BLOB_INLINE_SIZE=%s, "

0 commit comments

Comments
 (0)