skipped 26 lines 27 27 "github.com/dolthub/dolt/go/libraries/doltcore/sqle" 28 28 "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" 29 29 "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" 30 + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables" 30 31 ) 31 32 32 33 var ViewsWithAsOfScriptTest = queries.ScriptTest{ skipped 681 lines 714 715 Expected: []sql.Row{ 715 716 {"view", "view1", "SELECT v1 FROM viewtest", int64(1)}, 716 717 {"view", "view2", "SELECT v2 FROM viewtest", int64(2)}, 717 - }, 718 - }, 719 - }, 720 - }, 721 - { 722 - Name: "unique key violation prevents insert", 723 - SetUpScript: []string{ 724 - "CREATE TABLE auniquetable (pk int primary key, uk int unique key, i int);", 725 - "INSERT INTO auniquetable VALUES(0,0,0);", 726 - "INSERT INTO auniquetable (pk,uk) VALUES(1,0) on duplicate key update i = 99;", 727 - }, 728 - Assertions: []queries.ScriptTestAssertion{ 729 - { 730 - Query: "SELECT pk, uk, i from auniquetable", 731 - Expected: []sql.Row{ 732 - {0, 0, 99}, 733 718 }, 734 719 }, 735 720 }, skipped 725 lines 1461 1446 Query: "select c1 from dolt_history_t;", 1462 1447 Expected: []sql.Row{ 1463 1448 {uint64(1)}, 1449 + }, 1450 + }, 1451 + }, 1452 + }, 1453 + { 1454 + Name: "dolt_history table index lookup", 1455 + SetUpScript: []string{ 1456 + "create table yx (y int, x int primary key);", 1457 + "call dolt_add('.');", 1458 + "call dolt_commit('-m', 'creating table');", 1459 + "insert into yx values (0, 1);", 1460 + "call dolt_commit('-am', 'add data');", 1461 + "insert into yx values (2, 3);", 1462 + "call dolt_commit('-am', 'add data');", 1463 + "insert into yx values (4, 5);", 1464 + "call dolt_commit('-am', 'add data');", 1465 + }, 1466 + Assertions: []queries.ScriptTestAssertion{ 1467 + { 1468 + Query: "select count(x) from dolt_history_yx where x = 1;", 1469 + Expected: []sql.Row{ 1470 + {3}, 1464 1471 }, 1465 1472 }, 1466 1473 }, skipped 3198 lines 4665 4672 {nil, nil, nil, 3, "three", "four", "removed"}, 4666 4673 }, 4667 4674 }, 4675 + { 4676 + Query: ` 4677 + SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type 4678 + from dolt_diff(@Commit1, @Commit2, 't') 4679 + inner join t on to_pk = t.pk;`, 4680 + Expected: []sql.Row{{1, "one", "two", nil, nil, nil, "added"}}, 4681 + }, 4668 4682 }, 4669 4683 }, 4670 4684 { skipped 685 lines 5356 5370 Query: "SELECT count(*) from dolt_log('main^');", 5357 5371 Expected: []sql.Row{{3}}, 5358 5372 }, 5373 + { 5374 + Query: "SELECT count(*) from dolt_log('main') join dolt_diff(@Commit1, @Commit2, 't') where commit_hash = to_commit;", 5375 + Expected: []sql.Row{{2}}, 5376 + }, 5359 5377 }, 5360 5378 }, 5361 5379 { skipped 455 lines 5817 5835 Query: "SELECT * from dolt_diff_summary(@Commit1, @Commit5, 't');", 5818 5836 ExpectedErr: sql.ErrTableNotFound, 5819 5837 }, 5838 + { 5839 + Query: ` 5840 + SELECT * 5841 + from dolt_diff_summary(@Commit3, @Commit4, 't') 5842 + inner join t as of @Commit3 on rows_unmodified = t.pk;`, 5843 + Expected: []sql.Row{}, 5844 + }, 5820 5845 }, 5821 5846 }, 5822 5847 { skipped 472 lines 6295 6320 }, 6296 6321 }, 6297 6322 }, 6323 + { 6324 + Name: "pk set change should throw an error for 3 argument dolt_diff_summary", 6325 + SetUpScript: []string{ 6326 + "CREATE table t (pk int primary key);", 6327 + "INSERT INTO t values (1);", 6328 + "CALL DOLT_COMMIT('-Am', 'table with row');", 6329 + "ALTER TABLE t ADD col1 int not null default 0;", 6330 + "ALTER TABLE t drop primary key;", 6331 + "ALTER TABLE t add primary key (pk, col1);", 6332 + "CALL DOLT_COMMIT('-am', 'add secondary column with primary key');", 6333 + }, 6334 + Assertions: []queries.ScriptTestAssertion{ 6335 + { 6336 + Query: "SELECT * from dolt_diff_summary('HEAD~', 'HEAD', 't');", 6337 + ExpectedErrStr: "failed to compute diff summary for table t: primary key set changed", 6338 + }, 6339 + }, 6340 + }, 6341 + { 6342 + Name: "pk set change should report warning for 2 argument dolt_diff_summary", 6343 + SetUpScript: []string{ 6344 + "CREATE table t (pk int primary key);", 6345 + "INSERT INTO t values (1);", 6346 + "CREATE table t2 (pk int primary key);", 6347 + "INSERT INTO t2 values (2);", 6348 + "CALL DOLT_COMMIT('-Am', 'multiple tables');", 6349 + "ALTER TABLE t ADD col1 int not null default 0;", 6350 + "ALTER TABLE t drop primary key;", 6351 + "ALTER TABLE t add primary key (pk, col1);", 6352 + "INSERT INTO t2 values (3), (4), (5);", 6353 + "CALL DOLT_COMMIT('-am', 'add secondary column with primary key to t');", 6354 + }, 6355 + Assertions: []queries.ScriptTestAssertion{ 6356 + { 6357 + Query: "SELECT * from dolt_diff_summary('HEAD~', 'HEAD')", 6358 + Expected: []sql.Row{ 6359 + {"t", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 6360 + {"t2", 1, 3, 0, 0, 3, 0, 0, 1, 4, 1, 4}, 6361 + }, 6362 + ExpectedWarning: dtables.PrimaryKeyChangeWarningCode, 6363 + ExpectedWarningsCount: 1, 6364 + }, 6365 + }, 6366 + }, 6298 6367 } 6299 6368 6300 6369 var LargeJsonObjectScriptTests = []queries.ScriptTest{ skipped 1825 lines 8126 8195 8127 8196 var DoltIndexPrefixScripts = []queries.ScriptTest{ 8128 8197 { 8129 - Name: "varchar primary key prefix", 8130 - SetUpScript: []string{ 8131 - "create table t (v varchar(100))", 8132 - }, 8133 - Assertions: []queries.ScriptTestAssertion{ 8134 - { 8135 - Query: "alter table t add primary key (v(10))", 8136 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8137 - }, 8138 - { 8139 - Query: "create table v_tbl (v varchar(100), primary key (v(10)))", 8140 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8141 - }, 8142 - }, 8143 - }, 8144 - { 8145 - Name: "varchar keyed secondary index prefix", 8146 - SetUpScript: []string{ 8147 - "create table t (i int primary key, v varchar(10))", 8148 - }, 8149 - Assertions: []queries.ScriptTestAssertion{ 8150 - { 8151 - Query: "alter table t add unique index (v(1))", 8152 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8153 - }, 8154 - { 8155 - Query: "show create table t", 8156 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `v` varchar(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `v` (`v`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8157 - }, 8158 - { 8159 - Query: "insert into t values (0, 'aa'), (1, 'ab')", 8160 - ExpectedErr: sql.ErrUniqueKeyViolation, 8161 - }, 8162 - { 8163 - Query: "insert into t values (0, 'aa'), (1, 'bb'), (2, 'cc')", 8164 - Expected: []sql.Row{{sql.NewOkResult(3)}}, 8165 - }, 8166 - { 8167 - Query: "select * from t where v = 'a'", 8168 - Expected: []sql.Row{}, 8169 - }, 8170 - { 8171 - Query: "select * from t where v = 'aa'", 8172 - Expected: []sql.Row{ 8173 - {0, "aa"}, 8174 - }, 8175 - }, 8176 - { 8177 - Query: "create table v_tbl (i int primary key, v varchar(100), index (v(10)))", 8178 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8179 - }, 8180 - { 8181 - Query: "show create table v_tbl", 8182 - Expected: []sql.Row{{"v_tbl", "CREATE TABLE `v_tbl` (\n `i` int NOT NULL,\n `v` varchar(100),\n PRIMARY KEY (`i`),\n KEY `v` (`v`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8183 - }, 8184 - }, 8185 - }, 8186 - { 8187 - Name: "varchar keyless secondary index prefix", 8198 + Name: "inline secondary indexes with collation", 8188 8199 SetUpScript: []string{ 8189 - "create table t (v varchar(10))", 8200 + "create table t (i int primary key, v1 varchar(10), v2 varchar(10), unique index (v1(3),v2(5))) collate utf8mb4_0900_ai_ci", 8190 8201 }, 8191 8202 Assertions: []queries.ScriptTestAssertion{ 8192 8203 { 8193 - Query: "alter table t add unique index (v(1))", 8194 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8195 - }, 8196 - { 8197 8204 Query: "show create table t", 8198 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `v ` varchar(10),\n UNIQUE KEY `v ` (`v `(1 ))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin "}}, 8199 - }, 8200 - { 8201 - Query: "insert into t values ('aa'), ('ab')", 8202 - ExpectedErr: sql.ErrUniqueKeyViolation, 8203 - }, 8204 - { 8205 - Query: "create table v_tbl (v varchar(100), index (v(10)))", 8206 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8207 - }, 8208 - { 8209 - Query: "show create table v_tbl", 8210 - Expected: []sql.Row{{"v_tbl", "CREATE TABLE `v_tbl` (\n `v` varchar(100),\n KEY `v` (`v`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8211 - }, 8212 - }, 8213 - }, 8214 - { 8215 - Name: "char primary key prefix", 8216 - SetUpScript: []string{ 8217 - "create table t (c char(100))", 8218 - }, 8219 - Assertions: []queries.ScriptTestAssertion{ 8220 - { 8221 - Query: "alter table t add primary key (c(10))", 8222 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8223 - }, 8224 - { 8225 - Query: "create table c_tbl (c char(100), primary key (c(10)))", 8226 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8227 - }, 8228 - }, 8229 - }, 8230 - { 8231 - Name: "char keyed secondary index prefix", 8232 - SetUpScript: []string{ 8233 - "create table t (i int primary key, c char(10))", 8234 - }, 8235 - Assertions: []queries.ScriptTestAssertion{ 8236 - { 8237 - Query: "alter table t add unique index (c(1))", 8238 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8205 + Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i ` int NOT NULL , \ n ` v1 ` varchar(10) COLLATE utf8mb4_0900_ai_ci , \ n ` v2 ` varchar ( 10 ) COLLATE utf8mb4_0900_ai_ci , \ n PRIMARY KEY ( ` i ` ) ,\n UNIQUE KEY `v1v2 ` (`v1 `(3 ) , ` v2 ` ( 5 ))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci "}}, 8239 8206 }, 8240 8207 { 8241 - Query: "show create table t", 8242 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `c` char(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `c` (`c`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8208 + Query: "insert into t values (0, 'a', 'a'), (1, 'ab','ab'), (2, 'abc', 'abc'), (3, 'abcde', 'abcde')", 8209 + Expected: []sql.Row{{sql.NewOkResult(4)}}, 8243 8210 }, 8244 8211 { 8245 - Query: "insert into t values (0 , 'aa ') , ( 1 , 'ab ')", 8212 + Query: "insert into t values (99 , 'ABC ', 'ABCDE ')", 8246 8213 ExpectedErr: sql.ErrUniqueKeyViolation, 8247 8214 }, 8248 8215 { 8249 - Query: "create table c_tbl (i int primary key, c varchar(100), index (c(10)))", 8250 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8251 - }, 8252 - { 8253 - Query: "show create table c_tbl", 8254 - Expected: []sql.Row{{"c_tbl", "CREATE TABLE `c_tbl` (\n `i` int NOT NULL,\n `c` varchar(100),\n PRIMARY KEY (`i`),\n KEY `c` (`c`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8255 - }, 8256 - }, 8257 - }, 8258 - { 8259 - Name: "char keyless secondary index prefix", 8260 - SetUpScript: []string{ 8261 - "create table t (c char(10))", 8262 - }, 8263 - Assertions: []queries.ScriptTestAssertion{ 8264 - { 8265 - Query: "alter table t add unique index (c(1))", 8266 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8216 + Query: "insert into t values (99, 'ABC', 'ABCDE')", 8217 + ExpectedErrStr: "duplicate unique key given: [ABC,ABCDE]", 8267 8218 }, 8268 8219 { 8269 - Query: "show create table t", 8270 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `c` char(10),\n UNIQUE KEY `c` (`c`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8271 - }, 8272 - { 8273 - Query: "insert into t values ('aa'), ('ab')", 8220 + Query: "insert into t values (99, 'ABC123', 'ABCDE123')", 8274 8221 ExpectedErr: sql.ErrUniqueKeyViolation, 8275 8222 }, 8276 8223 { 8277 - Query: "create table c_tbl (c char(100), index (c(10)))", 8278 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8224 + Query: "insert into t values (99, 'ABC123', 'ABCDE123')", 8225 + ExpectedErrStr: "duplicate unique key given: [ABC,ABCDE]", 8279 8226 }, 8280 8227 { 8281 - Query: "show create table c_tbl", 8282 - Expected: []sql.Row{{"c_tbl", "CREATE TABLE `c_tbl` (\n `c` char(100),\n KEY `c` (`c`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8228 + Query: "select * from t where v1 = 'A'", 8229 + Expected: []sql.Row{ 8230 + {0, "a", "a"}, 8231 + }, 8283 8232 }, 8284 - }, 8285 - }, 8286 - { 8287 - Name: "varbinary primary key prefix", 8288 - SetUpScript: []string{ 8289 - "create table t (v varbinary(100))", 8290 - }, 8291 - Assertions: []queries.ScriptTestAssertion{ 8292 8233 { 8293 - Query: "alter table t add primary key (v(10))", 8294 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8295 - }, 8296 - { 8297 - Query: "create table v_tbl (v varbinary(100), primary key (v(10)))", 8298 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8299 - }, 8300 - }, 8301 - }, 8302 - { 8303 - Name: "varbinary keyed secondary index prefix", 8304 - SetUpScript: []string{ 8305 - "create table t (i int primary key, v varbinary(10))", 8306 - }, 8307 - Assertions: []queries.ScriptTestAssertion{ 8308 - { 8309 - Query: "alter table t add unique index (v(1))", 8310 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8311 - }, 8312 - { 8313 - Query: "show create table t", 8314 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `v` varbinary(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `v` (`v`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8315 - }, 8316 - { 8317 - Query: "insert into t values (0, 'aa'), (1, 'ab')", 8318 - ExpectedErr: sql.ErrUniqueKeyViolation, 8234 + Query: "explain select * from t where v1 = 'A'", 8235 + Expected: []sql.Row{ 8236 + {"Filter(t.v1 = 'A')"}, 8237 + {" ââ IndexedTableAccess(t)"}, 8238 + {" ââ index: [t.v1,t.v2]"}, 8239 + {" ââ filters: [{[A, A], [NULL, â)}]"}, 8240 + {" ââ columns: [i v1 v2]"}, 8241 + },8319 8242 }, 8320 8243 { 8321 - Query: "create table v_tbl (i int primary key, v varbinary(100), index (v(10)))", 8322 - Expected: []sql.Row{{ sql . NewOkResult ( 0 ) } } , 8244 + Query: "select * from t where v1 = 'ABC'", 8245 + Expected: []sql.Row{ 8246 + {2, "abc", "abc"}, 8247 + }, 8323 8248 }, 8324 8249 { 8325 - Query: "show create table v_tbl", 8326 - Expected: []sql.Row{{"v_tbl", "CREATE TABLE `v_tbl` (\n `i` int NOT NULL,\n `v` varbinary(100),\n PRIMARY KEY (`i`),\n KEY `v` (`v`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8250 + Query: "explain select * from t where v1 = 'ABC'", 8251 + Expected: []sql.Row{ 8252 + {"Filter(t.v1 = 'ABC')"}, 8253 + {" ââ IndexedTableAccess(t)"}, 8254 + {" ââ index: [t.v1,t.v2]"}, 8255 + {" ââ filters: [{[ABC, ABC], [NULL, â)}]"}, 8256 + {" ââ columns: [i v1 v2]"}, 8257 + }, 8327 8258 }, 8328 - }, 8329 - }, 8330 - { 8331 - Name: "varbinary keyless secondary index prefix", 8332 - SetUpScript: []string{ 8333 - "create table t (v varbinary(10))", 8334 - }, 8335 - Assertions: []queries.ScriptTestAssertion{ 8336 8259 { 8337 - Query: "alter table t add unique index (v(1))", 8338 - Expected: []sql.Row{{ sql . NewOkResult ( 0 ) } }, 8260 + Query: "select * from t where v1 = 'ABCD'", 8261 + Expected: []sql.Row{}, 8339 8262 }, 8340 8263 { 8341 - Query: "show create table t", 8342 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `v` varbinary(10),\n UNIQUE KEY `v` (`v`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8264 + Query: "explain select * from t where v1 = 'ABCD'", 8265 + Expected: []sql.Row{ 8266 + {"Filter(t.v1 = 'ABCD')"}, 8267 + {" ââ IndexedTableAccess(t)"}, 8268 + {" ââ index: [t.v1,t.v2]"}, 8269 + {" ââ filters: [{[ABCD, ABCD], [NULL, â)}]"}, 8270 + {" ââ columns: [i v1 v2]"}, 8271 + }, 8343 8272 }, 8344 8273 { 8345 - Query: "insert into t values ('aa'), ('ab')", 8346 - ExpectedErr: sql.ErrUniqueKeyViolation, 8274 + Query: "select * from t where v1 > 'A' and v1 < 'ABCDE'", 8275 + Expected: []sql.Row{ 8276 + {1, "ab", "ab"}, 8277 + {2, "abc", "abc"}, 8278 + }, 8347 8279 }, 8348 8280 { 8349 - Query: "create table v_tbl (v varbinary(100), index (v(10)))", 8350 - Expected: []sql.Row{{ sql . NewOkResult ( 0 ) } } , 8281 + Query: "explain select * from t where v1 > 'A' and v1 < 'ABCDE'", 8282 + Expected: []sql.Row{ 8283 + {"Filter((t.v1 > 'A') AND (t.v1 < 'ABCDE'))"}, 8284 + {" ââ IndexedTableAccess(t)"}, 8285 + {" ââ index: [t.v1,t.v2]"}, 8286 + {" ââ filters: [{(A, ABCDE), [NULL, â)}]"}, 8287 + {" ââ columns: [i v1 v2]"}, 8288 + }, 8351 8289 }, 8352 8290 { 8353 - Query: "show create table v_tbl", 8354 - Expected: []sql.Row{{"v_tbl", "CREATE TABLE `v_tbl` (\n `v` varbinary(100),\n KEY `v` (`v`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8291 + Query: "select * from t where v1 > 'A' and v2 < 'ABCDE'", 8292 + Expected: []sql.Row{ 8293 + {1, "ab", "ab"}, 8294 + {2, "abc", "abc"}, 8295 + }, 8355 8296 }, 8356 - }, 8357 - }, 8358 - { 8359 - Name: "binary primary key prefix", 8360 - SetUpScript: []string{ 8361 - "create table t (b binary(100))", 8362 - }, 8363 - Assertions: []queries.ScriptTestAssertion{ 8364 8297 { 8365 - Query: "alter table t add primary key (b(10))", 8366 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8298 + Query: "explain select * from t where v1 > 'A' and v2 < 'ABCDE'", 8299 + Expected: []sql.Row{ 8300 + {"Filter((t.v1 > 'A') AND (t.v2 < 'ABCDE'))"}, 8301 + {" ââ IndexedTableAccess(t)"}, 8302 + {" ââ index: [t.v1,t.v2]"}, 8303 + {" ââ filters: [{(A, â), (NULL, ABCDE)}]"}, 8304 + {" ââ columns: [i v1 v2]"}, 8305 + }, 8367 8306 }, 8368 8307 { 8369 - Query: "create table b_tbl (b binary(100), primary key (b(10)))", 8370 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8308 + Query: "update t set v1 = concat(v1, 'Z') where v1 >= 'A'", 8309 + Expected: []sql.Row{ 8310 + {sql.OkResult{RowsAffected: 4, InsertID: 0, Info: plan.UpdateInfo{Matched: 4, Updated: 4}}}, 8311 + }, 8371 8312 }, 8372 - }, 8373 - }, 8374 - { 8375 - Name: "binary keyed secondary index prefix", 8376 - SetUpScript: []string{ 8377 - "create table t (i int primary key, b binary(10))", 8378 - }, 8379 - Assertions: []queries.ScriptTestAssertion{ 8380 8313 { 8381 - Query: "alter table t add unique index (b(1))", 8382 - Expected: []sql.Row{{ sql . NewOkResult ( 0 ) } } , 8314 + Query: "explain update t set v1 = concat(v1, 'Z') where v1 >= 'A'", 8315 + Expected: []sql.Row{ 8316 + {"Update"}, 8317 + {" ââ UpdateSource(SET t.v1 = concat(t.v1, 'Z'))"}, 8318 + {" ââ Filter(t.v1 >= 'A')"}, 8319 + {" ââ IndexedTableAccess(t)"}, 8320 + {" ââ index: [t.v1,t.v2]"}, 8321 + {" ââ filters: [{[A, â), [NULL, â)}]"}, 8322 + }, 8383 8323 }, 8384 8324 { 8385 - Query: "show create table t", 8386 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `b` binary(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `b` (`b`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8325 + Query: "select * from t", 8326 + Expected: []sql.Row{ 8327 + {0, "aZ", "a"}, 8328 + {1, "abZ", "ab"}, 8329 + {2, "abcZ", "abc"}, 8330 + {3, "abcdeZ", "abcde"}, 8331 + }, 8387 8332 }, 8388 8333 { 8389 - Query: "insert into t values (0, 'aa'), (1, 'ab')", 8390 - ExpectedErr: sql.ErrUniqueKeyViolation, 8334 + Query: "delete from t where v1 >= 'A'", 8335 + Expected: []sql.Row{ 8336 + {sql.OkResult{RowsAffected: 4}}, 8337 + }, 8391 8338 }, 8392 8339 { 8393 - Query: "create table b_tbl (i int primary key, b binary(100), index (b(10)))", 8394 - Expected: []sql.Row{{ sql . NewOkResult ( 0 ) } } , 8340 + Query: "explain delete from t where v1 >= 'A'", 8341 + Expected: []sql.Row{ 8342 + {"Delete"}, 8343 + {" ââ Filter(t.v1 >= 'A')"}, 8344 + {" ââ IndexedTableAccess(t)"}, 8345 + {" ââ index: [t.v1,t.v2]"}, 8346 + {" ââ filters: [{[A, â), [NULL, â)}]"}, 8347 + }, 8395 8348 }, 8396 8349 { 8397 - Query: "show create table b_tbl", 8398 - Expected: []sql.Row{{"b_tbl", "CREATE TABLE `b_tbl` (\n `i` int NOT NULL,\n `b` binary(100),\n PRIMARY KEY (`i`),\n KEY `b` (`b`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8350 + Query: "select * from t", 8351 + Expected: []sql.Row{}, 8399 8352 }, 8400 8353 }, 8401 8354 }, 8355 + // TODO: these should eventually go in GMS, but it doesn't currently support index rewrite on column modify 8402 8356 { 8403 - Name: "binary keyless secondary index prefix", 8357 + Name: "drop prefix lengths when modifying column to non string type", 8404 8358 SetUpScript: []string{ 8405 - "create table t (b binary (10))", 8359 + "create table t (j varchar ( 100 ) , index ( j (10) ))", 8406 8360 }, 8407 8361 Assertions: []queries.ScriptTestAssertion{ 8408 8362 { 8409 - Query: "alter table t add unique index ( b ( 1 ) ) ", 8410 - Expected: []sql.Row{{sql.NewOkResult ( 0 ) }}, 8363 + Query: "alter table t modify column j int ", 8364 + Expected: []sql.Row{{sql.OkResult { } }}, 8411 8365 }, 8412 8366 { 8413 8367 Query: "show create table t", 8414 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `b ` binary ( 10 ) ,\n UNIQUE KEY `b ` (`b `( 1 ) )\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8415 - }, 8416 - { 8417 - Query: "insert into t values ('aa'), ('ab')", 8418 - ExpectedErr: sql.ErrUniqueKeyViolation, 8419 - }, 8420 - { 8421 - Query: "create table b_tbl (b binary(100), index (b(10)))", 8422 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8423 - }, 8424 - { 8425 - Query: "show create table b_tbl", 8426 - Expected: []sql.Row{{"b_tbl", "CREATE TABLE `b_tbl` (\n `b` binary(100),\n KEY `b` (`b`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8427 - }, 8428 - }, 8429 - }, 8430 - { 8431 - Name: "blob primary key prefix", 8432 - SetUpScript: []string{ 8433 - "create table t (b blob)", 8434 - }, 8435 - Assertions: []queries.ScriptTestAssertion{ 8436 - { 8437 - Query: "alter table t add primary key (b(10))", 8438 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8439 - }, 8440 - { 8441 - Query: "create table b_tbl (b blob, primary key (b(10)))", 8442 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8368 + Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `j ` int ,\n KEY `j ` (`j `)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8443 8369 }, 8444 8370 }, 8445 8371 }, 8446 8372 { 8447 - Name: "blob keyed secondary index prefix", 8373 + Name: "drop prefix length when modifying columns to invalid string type", 8448 8374 SetUpScript: []string{ 8449 - "create table t (i int primary key, b blob)", 8375 + "create table t (j varchar(100), index (j(10)))", 8450 8376 }, 8451 8377 Assertions: []queries.ScriptTestAssertion{ 8452 8378 { 8453 - Query: "alter table t add unique index ( b (1 ) )", 8454 - Expected: []sql.Row{{sql.NewOkResult ( 0 ) }}, 8379 + Query: "alter table t modify column j varchar (2 )", 8380 + Expected: []sql.Row{{sql.OkResult { } }}, 8455 8381 }, 8456 8382 { 8457 8383 Query: "show create table t", 8458 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i ` int NOT NULL , \ n ` b ` blob , \ n PRIMARY KEY (` i ` ),\n UNIQUE KEY `b ` (`b `( 1 ) )\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8459 - }, 8460 - { 8461 - Query: "insert into t values (0, 'aa'), (1, 'ab')", 8462 - ExpectedErr: sql.ErrUniqueKeyViolation, 8463 - }, 8464 - { 8465 - Query: "create table b_tbl (i int primary key, b blob, index (b(10)))", 8466 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8467 - }, 8468 - { 8469 - Query: "show create table b_tbl", 8470 - Expected: []sql.Row{{"b_tbl", "CREATE TABLE `b_tbl` (\n `i` int NOT NULL,\n `b` blob,\n PRIMARY KEY (`i`),\n KEY `b` (`b`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8384 + Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `j ` varchar (2 ),\n KEY `j ` (`j `)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8471 8385 }, 8472 8386 }, 8473 8387 }, 8474 8388 { 8475 - Name: "blob keyless secondary index prefix", 8389 + Name: "preserve prefix length when modifying column to valid string type", 8476 8390 SetUpScript: []string{ 8477 - "create table t (b blob )", 8391 + "create table t (j varchar ( 100 ) , index ( j ( 10 ) ) )", 8478 8392 }, 8479 8393 Assertions: []queries.ScriptTestAssertion{ 8480 8394 { 8481 - Query: "alter table t add unique index ( b (1 ) )", 8482 - Expected: []sql.Row{{sql.NewOkResult ( 0 ) }}, 8395 + Query: "alter table t modify column j varchar (200 )", 8396 + Expected: []sql.Row{{sql.OkResult { } }}, 8483 8397 }, 8484 8398 { 8485 8399 Query: "show create table t", 8486 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `b ` blob ,\n UNIQUE KEY `b ` (`b `(1 ))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8487 - }, 8488 - { 8489 - Query: "insert into t values ('aa'), ('ab')", 8490 - ExpectedErr: sql.ErrUniqueKeyViolation, 8491 - }, 8492 - { 8493 - Query: "create table b_tbl (b blob, index (b(10)))", 8494 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8495 - }, 8496 - { 8497 - Query: "show create table b_tbl", 8498 - Expected: []sql.Row{{"b_tbl", "CREATE TABLE `b_tbl` (\n `b` blob,\n KEY `b` (`b`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8400 + Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `j ` varchar ( 200 ) ,\n KEY `j ` (`j `(10 ))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8499 8401 }, 8500 8402 }, 8501 8403 }, 8502 8404 { 8503 - Name: "text primary key prefix", 8504 - SetUpScript: []string{ 8505 - "create table t (t text)", 8506 - }, 8507 - Assertions: []queries.ScriptTestAssertion{ 8508 - { 8509 - Query: "alter table t add primary key (t(10))", 8510 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8511 - }, 8512 - { 8513 - Query: "create table b_tbl (t text, primary key (t(10)))", 8514 - ExpectedErr: sql.ErrUnsupportedIndexPrefix, 8515 - }, 8516 - }, 8517 - }, 8518 - { 8519 - Name: "text keyed secondary index prefix", 8405 + Name: "preserve prefix lengths when there are other unchanged prefix lengths", 8520 8406 SetUpScript: []string{ 8521 - "create table t (i int primary key, t text)", 8407 + "create table t (i varchar(100), j varchar(100), index (i(10), j(10)))", 8522 8408 }, 8523 8409 Assertions: []queries.ScriptTestAssertion{ 8524 8410 { 8525 - Query: "alter table t add unique index ( t ( 1 ) ) ", 8526 - Expected: []sql.Row{{sql.NewOkResult ( 0 ) }}, 8411 + Query: "alter table t modify column j int ", 8412 + Expected: []sql.Row{{sql.OkResult { } }}, 8527 8413 }, 8528 8414 { 8529 8415 Query: "show create table t", 8530 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL ,\n `t ` text ,\n PRIMARY KEY (`i`),\ n UNIQUE KEY `t ` ( ` t ` ( 1 ) )\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8531 - }, 8532 - { 8533 - Query: "insert into t values (0, 'aa'), (1, 'ab')", 8534 - ExpectedErr: sql.ErrUniqueKeyViolation, 8535 - }, 8536 - { 8537 - Query: "create table t_tbl (i int primary key, t text, index (t(10)))", 8538 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8539 - }, 8540 - { 8541 - Query: "show create table t_tbl", 8542 - Expected: []sql.Row{{"t_tbl", "CREATE TABLE `t_tbl` (\n `i` int NOT NULL,\n `t` text,\n PRIMARY KEY (`i`),\n KEY `t` (`t`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8416 + Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` varchar ( 100 ) ,\n `j ` int ,\n KEY ` ij ` (`i`( 10 ),`j `)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8543 8417 }, 8544 8418 }, 8545 8419 }, 8546 8420 { 8547 - Name: "text keyless secondary index prefix", 8421 + Name: "prefix length too long", 8548 8422 SetUpScript: []string{ 8549 - "create table t (t text )", 8423 + "create table t (i blob , index ( i ( 3072 ) ) )", 8550 8424 }, 8551 8425 Assertions: []queries.ScriptTestAssertion{ 8552 8426 { 8553 - Query: "alter table t add unique index ( t ( 1 ) ) ", 8554 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8555 - }, 8556 - { 8557 - Query: "show create table t", 8558 - Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `t` text,\n UNIQUE KEY `t` (`t`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8559 - }, 8560 - { 8561 - Query: "insert into t values ('aa'), ('ab')", 8562 - ExpectedErr: sql.ErrUniqueKeyViolation, 8563 - }, 8564 - { 8565 - Query: "create table t_tbl (t text, index (t(10)))", 8566 - Expected: []sql.Row{{sql.NewOkResult(0)}}, 8567 - }, 8568 - { 8569 - Query: "show create table t_tbl", 8570 - Expected: []sql.Row{{"t_tbl", "CREATE TABLE `t_tbl` (\n `t` text,\n KEY `t` (`t`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 8427 + Query: "alter table t modify column i text ", 8428 + ExpectedErr: sql.ErrKeyTooLong, 8571 8429 }, 8572 8430 }, 8573 8431 }, skipped 2 lines