MDEV-40486 Length check for vector fields in CREATE TABLE ... SELECT - #5443
MDEV-40486 Length check for vector fields in CREATE TABLE ... SELECT#5443mariadb-YuchenPei wants to merge 1 commit into
Conversation
|
|
|
claude: Code Review: MDEV-40486 — Length check for vector fields in
|
3b1915b to
4e97c43
Compare
|
claude: Code Review: MDEV-40486 (revised) — Length check for vector fields in
|
|
re claude comment
This is actually covered, for example, in this testcase: Before the change from max_length to max_char_length() this would fail with ER_TOO_BIG_FIELDLENGTH, because the max_length of VARCHAR(16383) is 65532 which results in 131064 max length for the vector, exceeding its limit. After the change it uses max_char_length() which is, well, 16383 and is correct.
I am not sure how this is possible, so I asked claude to come up with a testcase and it came up with a wrong one. After more back and forth it conceded this point is invalid. The second round review is done after that, but somehow clauded decided to make the same comment again |
sanja-byelkin
left a comment
There was a problem hiding this comment.
Main problem is spoiled SHOW CREATE VIEW (or I just do not understand how it should be shown)
CREATE TABLE t1 (a CHAR(1));
CREATE TABLE t2 AS SELECT VEC_FROMTEXT(a) AS f FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`f` vector(0) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
INSERT INTO t2 VALUES (VEC_FROMTEXT('[1]'));
ERROR 22007: Incorrect vector value: '\x00\x00\x80?' for column `test`.`t2`.`f` at row 1
CREATE TABLE t3 (f VECTOR(0));
ERROR 42000: Incorrect column specifier for column 'f'
DROP TABLE t1, t2;
i.e. it shows impossible CREATE TABLE
here is a test case (of course it is incorrect just changed to pass):
CREATE TABLE t1 (a CHAR(1));
CREATE TABLE t2 AS SELECT VEC_FROMTEXT(a) AS f FROM t1;
SHOW CREATE TABLE t2; # `f` vector(0)
--error ER_TRUNCATED_WRONG_VALUE
INSERT INTO t2 VALUES (VEC_FROMTEXT('[1]')); # rejected, count(*) = 0
--error ER_WRONG_FIELD_SPEC
CREATE TABLE t3 (f VECTOR(0));
DROP TABLE t1, t2;
Add SHOW CREATE TABLE to the test and fix it please. Also there are some quietsions
4e97c43 to
89b5f31
Compare
Discussed with @vuvova and understand that zero-dimension vectors should not be allowed in table fields, even though |
|
claude: Code Review: MDEV-40486 (iteration 3) — Length check for vector fieldsCommit: OverviewThird revision. The length validation is relocated from the CREATE-only field-creation hook into
Plus expanded tests (empty vector, zero-length, Main concern — the scope change is an incompatible behavior changeBecause the check now fires in
This may be an intentional, defensible policy (a Secondary risks
Code quality / message
Test coverage
VerdictThe mechanics (underflow guard, |
This is following @abarkov 's review comments. Updated commit message to explain this change. |
eff1b90 to
4ead7cb
Compare
a5a7946 to
7efd7dc
Compare
|
Amended the commit addressing more review comments by @abarkov |
The changes of MDEV-39558 2b65294 added length check assertion in Field_varstring constructors, and length check in type inference for SELECT set operations, to emit errors before reaching the assertions. That change caused an error to turn into an assertion failure in a separate path, when the length limit violation is not detected before tripping the assertion. So in this patch we fix it by adding an earlier length check in that path. The reason that we place this check inside Item_func_vec_fromtext::fix_length_and_dec rather than say `create_field_for_create_select is for consistency: If create table t1 as select vec_fromtext(concat('[',group_concat(1),']')) as c1 from seq_1_to_64; fails due to length limit violation, then so should create table t1 (v vector(64) not null); insert into t1 select vec_fromtext(concat('[',group_concat(1),']')) from seq_1_to_64; Also use max_char_length() instead of max_length. This is a more accurate length of characters. And add handling of empty string edge case. Added testcases accordingly. The change that uses max_char_length() causes side effects where creating a table using a VEC_FROMTEXT(CHAR(1)) would result in a 0-dimensional vector field. This is accurate but 0-dim vector table fields should not be allowed. So we add a check for that too, as well as an exception of (?) prepared statement placeholders. Also fixed the underflow in (args[0]->max_length - 1) * 2 when the arg's max length is 0. Previously this underflow would cause create table t1 select vec_fromtext(NULL) to fail with ER_TOO_BIG_FIELDLENGTH. Now the zero length check would cause it to fail with a different error (ER_WRONG_ARGUMENTS).
7efd7dc to
645884a
Compare
abarkov
left a comment
There was a problem hiding this comment.
The patch is OK to push. Thanks.
The changes of MDEV-39558 2b65294 added length check assertion in Field_varstring constructors, and length check in type inference for SELECT set operations, to emit errors before reaching the assertions.
That change caused an error to turn into an assertion failure in a separate path, when the length limit violation is not detected before tripping the assertion. So in this patch we fix it by adding an earlier length check in that path.