github.com/dolthub/go-mysql-server@v0.18.0/enginetest/queries/row_limit_queries.go (about) 1 // Copyright 2024 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package queries 16 17 import ( 18 "fmt" 19 20 "github.com/dolthub/go-mysql-server/sql/analyzer/analyzererrors" 21 "github.com/dolthub/go-mysql-server/sql/types" 22 ) 23 24 var longChar = make([]byte, 32700) 25 26 var RowLimitTests = []ScriptTest{ 27 { 28 Name: "row length limit", 29 Assertions: []ScriptTestAssertion{ 30 { 31 // latin1 is 1 byte per char 32 // numbers are chosen to match Dolt's |MaxTupleDataSize| 33 Query: `create table two_col (pk smallint primary key, c1 VARCHAR(32700) NOT NULL, c2 VARCHAR(32700) NOT NULL) CHARACTER SET latin1;`, 34 }, 35 { 36 Query: fmt.Sprintf("insert into two_col values (0, '%s', '%s')", longChar, longChar), 37 }, 38 { 39 Query: "create table one_col (id int primary key, c1 VARCHAR(65486) NOT NULL) CHARACTER SET latin1;", 40 }, 41 { 42 Query: fmt.Sprintf("insert into one_col values (0, '%s')", longChar), 43 }, 44 { 45 Query: ` 46 CREATE TABLE one_ref ( 47 id smallint primary key, 48 a VARCHAR(10000), 49 b VARCHAR(10000), 50 c VARCHAR(10000), 51 d VARCHAR(10000), 52 e VARCHAR(10000), 53 f VARCHAR(10000), 54 i TEXT 55 ) character set latin1;`, 56 }, 57 { 58 Query: fmt.Sprintf("insert into one_ref values (0,'%s', '%s','%s', '%s','%s', '%s','%s')", longChar[:10000], longChar[:10000], longChar[:10000], longChar[:10000], longChar[:10000], longChar[:10000], longChar[:6000]), 59 }, 60 }, 61 }, 62 { 63 Name: "row length limit errors", 64 SetUpScript: []string{ 65 "create table t (id smallint primary key, a VARCHAR(5000), b VARCHAR(5000), c VARCHAR(5000))", 66 }, 67 Assertions: []ScriptTestAssertion{ 68 { 69 Query: "alter table t add column d VARCHAR(5000)", 70 ExpectedErr: analyzererrors.ErrInvalidRowLength, 71 }, 72 { 73 Query: "alter table t modify column c VARCHAR(7000)", 74 ExpectedErr: analyzererrors.ErrInvalidRowLength, 75 }, 76 { 77 Query: fmt.Sprintf("insert into t values (1, '%s', 'a', 'a')", longChar), 78 ExpectedErr: types.ErrLengthBeyondLimit, 79 }, 80 { 81 Query: "create table t1 (c1 VARCHAR(16883) NOT NULL)", 82 ExpectedErr: analyzererrors.ErrInvalidRowLength, 83 }, 84 { 85 Query: "create table t1 (c1 VARCHAR(65536) NOT NULL) CHARACTER SET latin1;", 86 ExpectedErr: types.ErrLengthTooLarge, 87 }, 88 { 89 Query: ` 90 CREATE TABLE one_ref ( 91 id int primary key, 92 a VARCHAR(10000), 93 b VARCHAR(10000), 94 c VARCHAR(10000), 95 d VARCHAR(10000), 96 e VARCHAR(10000), 97 f VARCHAR(10000), 98 i VARCHAR(6000) 99 ) character set latin1;`, 100 ExpectedErr: analyzererrors.ErrInvalidRowLength, 101 }, 102 }, 103 }, 104 }