Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to create table with some TiDB table info #4596

Closed
JaySon-Huang opened this issue Apr 6, 2022 · 5 comments · Fixed by #4630
Closed

Fail to create table with some TiDB table info #4596

JaySon-Huang opened this issue Apr 6, 2022 · 5 comments · Fixed by #4630

Comments

@JaySon-Huang
Copy link
Contributor

JaySon-Huang commented Apr 6, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

A simplified case from https://asktug.com/t/topic/662946

> set sql_mode='';
> CREATE TABLE test ( id int(16) NOT NULL AUTO_INCREMENT, PRIMARY KEY (id));
> alter table test add column b longblob not null default '';

-- p.s. Note that `set sql_mode=""` is required or the SQL will get blocked like
> CREATE TABLE test ( id int(16) NOT NULL AUTO_INCREMENT, PRIMARY KEY (id));
> alter table test add column b longblob not null default '';
ERROR 1101 (42000): BLOB/TEXT/JSON column 'b' can't have a default value

Those SQLs will create a table with JSON info as below. Note that the column type of "b" is not null long blob, but its "default"/"origin_default" field is "" and "type.FLen" is -1.

{
	"cols": [{
		"comment": "",
		"default": null,
		"default_bit": null,
		"id": 1,
		"name": {
			"L": "id",
			"O": "id"
		},
		"offset": 0,
		"origin_default": null,
		"state": 5,
		"type": {
			"Charset": "binary",
			"Collate": "binary",
			"Decimal": 0,
			"Elems": null,
			"Flag": 515,
			"Flen": 16,
			"Tp": 3
		}
	}, {
		"comment": "",
		"default": "",
		"default_bit": null,
		"id": 15,
		"name": {
			"L": "b",
			"O": "b"
		},
		"offset": 12,
		"origin_default": "",
		"state": 5,
		"type": {
			"Charset": "binary",
			"Collate": "binary",
			"Decimal": 0,
			"Elems": null,
			"Flag": 4225,
			"Flen": -1,
			"Tp": 251
		}
	}],
	"comment": "",
	"id": 330,
	"index_info": [],
	"is_common_handle": false,
	"name": {
		"L": "test",
		"O": "test"
	},
	"partition": null,
	"pk_is_handle": true,
	"schema_version": 465,
	"state": 5,
	"update_timestamp":999 
}

However, if we run CREATE TABLE test ( id int(16) NOT NULL AUTO_INCREMENT, b longblob not null, PRIMARY KEY (id)); in TiDB, we can only get a JSON as below, which "default"/"origin_default" is null instead of "". And this won't make any error.

2. What did you expect to see? (Required)

Table create successfully

3. What did you see instead (Required)

TiFlash crashes with basic_string::_M_replace_aux

4. What is your TiFlash version? (Required)

v5.2.1

@JaySon-Huang JaySon-Huang added the type/bug The issue is confirmed as a bug. label Apr 6, 2022
@JaySon-Huang
Copy link
Contributor Author

JaySon-Huang commented Apr 6, 2022

When run into defaultValueToField with that table info json. The column "b" with "default" field is "" and "type.FLen" is -1, and line 161 will run into v.append(-1, , '\0') which cause error.

The unit test case: https://github.com/JaySon-Huang/tiflash/tree/add_4596_test

case TypeString:
{
auto v = value.convert<String>();
if (hasBinaryFlag())
{
// For binary column, we have to pad trailing zeros according to the specified type length.
// User may define default value `0x1234` for a `BINARY(4)` column, TiDB stores it in a string "\u12\u34" (sized 2).
// But it actually means `0x12340000`.
v.append(flen - v.length(), '\0');
}
return v;
}

@JaySon-Huang

This comment was marked as duplicate.

@JaySon-Huang

This comment was marked as outdated.

@JaySon-Huang
Copy link
Contributor Author

/assign @Lloyd-Pottiger

@JaySon-Huang
Copy link
Contributor Author

JaySon-Huang commented Apr 21, 2022

similar issue for parsing invalid default value: #3157

ti-chi-bot added a commit that referenced this issue Apr 25, 2022
ti-chi-bot added a commit that referenced this issue Jun 16, 2022
ti-chi-bot added a commit that referenced this issue Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants