vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/testdata/ddl_cases.json (about) 1 [ 2 { 3 "comment": "simple create table", 4 "query": "create table t1(id bigint, primary key(id))", 5 "plan": { 6 "QueryType": "DDL", 7 "Original": "create table t1(id bigint, primary key(id))", 8 "Instructions": { 9 "OperatorType": "DDL", 10 "Keyspace": { 11 "Name": "main", 12 "Sharded": false 13 }, 14 "Query": "create table t1 (\n\tid bigint,\n\tprimary key (id)\n)" 15 }, 16 "TablesUsed": [ 17 "main.t1" 18 ] 19 } 20 }, 21 { 22 "comment": "simple create table with keyspace", 23 "query": "create table user.t1(id bigint, primary key(id))", 24 "plan": { 25 "QueryType": "DDL", 26 "Original": "create table user.t1(id bigint, primary key(id))", 27 "Instructions": { 28 "OperatorType": "DDL", 29 "Keyspace": { 30 "Name": "user", 31 "Sharded": true 32 }, 33 "Query": "create table t1 (\n\tid bigint,\n\tprimary key (id)\n)" 34 }, 35 "TablesUsed": [ 36 "user.t1" 37 ] 38 } 39 }, 40 { 41 "comment": "DDL", 42 "query": "create table a(id int)", 43 "plan": { 44 "QueryType": "DDL", 45 "Original": "create table a(id int)", 46 "Instructions": { 47 "OperatorType": "DDL", 48 "Keyspace": { 49 "Name": "main", 50 "Sharded": false 51 }, 52 "Query": "create table a (\n\tid int\n)" 53 }, 54 "TablesUsed": [ 55 "main.a" 56 ] 57 } 58 }, 59 { 60 "comment": "simple create table with table qualifier that does not exists", 61 "query": "create table a.b(id int)", 62 "plan": "VT05003: unknown database 'a' in vschema" 63 }, 64 { 65 "comment": "Alter table", 66 "query": "alter table a ADD id int", 67 "plan": { 68 "QueryType": "DDL", 69 "Original": "alter table a ADD id int", 70 "Instructions": { 71 "OperatorType": "DDL", 72 "Keyspace": { 73 "Name": "main", 74 "Sharded": false 75 }, 76 "Query": "alter table a add column id int" 77 }, 78 "TablesUsed": [ 79 "main.a" 80 ] 81 } 82 }, 83 { 84 "comment": "Alter table with qualifier", 85 "query": "alter table user.user ADD id int", 86 "plan": { 87 "QueryType": "DDL", 88 "Original": "alter table user.user ADD id int", 89 "Instructions": { 90 "OperatorType": "DDL", 91 "Keyspace": { 92 "Name": "user", 93 "Sharded": true 94 }, 95 "Query": "alter table `user` add column id int" 96 }, 97 "TablesUsed": [ 98 "user.user" 99 ] 100 } 101 }, 102 { 103 "comment": "Alter table with qualifier and table not in vschema", 104 "query": "alter table user.a ADD id int", 105 "plan": { 106 "QueryType": "DDL", 107 "Original": "alter table user.a ADD id int", 108 "Instructions": { 109 "OperatorType": "DDL", 110 "Keyspace": { 111 "Name": "user", 112 "Sharded": true 113 }, 114 "Query": "alter table a add column id int" 115 }, 116 "TablesUsed": [ 117 "user.a" 118 ] 119 } 120 }, 121 { 122 "comment": "Alter table with unknown qualifier", 123 "query": "alter table a.b ADD id int", 124 "plan": "VT05003: unknown database 'a' in vschema" 125 }, 126 { 127 "comment": "create db foo", 128 "query": "create database foo", 129 "plan": { 130 "QueryType": "DDL", 131 "Original": "create database foo", 132 "Instructions": { 133 "OperatorType": "CREATEDB", 134 "Keyspace": { 135 "Name": "foo", 136 "Sharded": false 137 } 138 } 139 } 140 }, 141 { 142 "comment": "create db main", 143 "query": "create database main", 144 "plan": "VT06001: cannot create database 'main'; database exists" 145 }, 146 { 147 "comment": "create db if not exists main", 148 "query": "create database if not exists main", 149 "plan": { 150 "QueryType": "DDL", 151 "Original": "create database if not exists main", 152 "Instructions": { 153 "OperatorType": "Rows" 154 } 155 } 156 }, 157 { 158 "comment": "alter db foo", 159 "query": "alter database foo collate utf8", 160 "plan": "VT05002: cannot alter database 'foo'; unknown database" 161 }, 162 { 163 "comment": "alter db main", 164 "query": "alter database main collate utf8", 165 "plan": "VT12001: unsupported: ALTER DATABASE" 166 }, 167 { 168 "comment": "drop db foo", 169 "query": "drop database foo", 170 "plan": "VT05001: cannot drop database 'foo'; database does not exists" 171 }, 172 { 173 "comment": "drop db main", 174 "query": "drop database main", 175 "plan": { 176 "QueryType": "DDL", 177 "Original": "drop database main", 178 "Instructions": { 179 "OperatorType": "DROPDB", 180 "Keyspace": { 181 "Name": "main", 182 "Sharded": false 183 } 184 } 185 } 186 }, 187 { 188 "comment": "drop db if exists main", 189 "query": "drop database if exists main", 190 "plan": { 191 "QueryType": "DDL", 192 "Original": "drop database if exists main", 193 "Instructions": { 194 "OperatorType": "DROPDB", 195 "Keyspace": { 196 "Name": "main", 197 "Sharded": false 198 } 199 } 200 } 201 }, 202 { 203 "comment": "drop db if exists foo", 204 "query": "drop schema if exists foo", 205 "plan": { 206 "QueryType": "DDL", 207 "Original": "drop schema if exists foo", 208 "Instructions": { 209 "OperatorType": "Rows" 210 } 211 } 212 }, 213 { 214 "comment": "DDL with qualifier", 215 "query": "create index a on user.user(id)", 216 "plan": { 217 "QueryType": "DDL", 218 "Original": "create index a on user.user(id)", 219 "Instructions": { 220 "OperatorType": "DDL", 221 "Keyspace": { 222 "Name": "user", 223 "Sharded": true 224 }, 225 "Query": "alter table `user` add index a (id)" 226 }, 227 "TablesUsed": [ 228 "user.user" 229 ] 230 } 231 }, 232 { 233 "comment": "DDL with qualifier for a table not in vschema of an unsharded keyspace", 234 "query": "create index a on main.unknown(id)", 235 "plan": { 236 "QueryType": "DDL", 237 "Original": "create index a on main.unknown(id)", 238 "Instructions": { 239 "OperatorType": "DDL", 240 "Keyspace": { 241 "Name": "main", 242 "Sharded": false 243 }, 244 "Query": "alter table unknown add index a (id)" 245 }, 246 "TablesUsed": [ 247 "main.unknown" 248 ] 249 } 250 }, 251 { 252 "comment": "create view with subquery in unsharded keyspace", 253 "query": "create view view_a as select * from (select col1, col2 from unsharded where id = 1 union select col1, col2 from unsharded where id = 3) a", 254 "v3-plan": { 255 "QueryType": "DDL", 256 "Original": "create view view_a as select * from (select col1, col2 from unsharded where id = 1 union select col1, col2 from unsharded where id = 3) a", 257 "Instructions": { 258 "OperatorType": "DDL", 259 "Keyspace": { 260 "Name": "main", 261 "Sharded": false 262 }, 263 "Query": "create view view_a as select * from (select col1, col2 from unsharded where id = 1 union select col1, col2 from unsharded where id = 3) as a" 264 }, 265 "TablesUsed": [ 266 "main.view_a" 267 ] 268 }, 269 "gen4-plan": { 270 "QueryType": "DDL", 271 "Original": "create view view_a as select * from (select col1, col2 from unsharded where id = 1 union select col1, col2 from unsharded where id = 3) a", 272 "Instructions": { 273 "OperatorType": "DDL", 274 "Keyspace": { 275 "Name": "main", 276 "Sharded": false 277 }, 278 "Query": "create view view_a as select a.col1, a.col2 from (select col1, col2 from unsharded where id = 1 union select col1, col2 from unsharded where id = 3) as a" 279 }, 280 "TablesUsed": [ 281 "main.view_a" 282 ] 283 } 284 }, 285 { 286 "comment": "create view with subquery in unsharded keyspace with IN clause", 287 "query": "create view view_a as select id, name from unsharded where id in (select id from unsharded where id = 1 union select id from unsharded where id = 3)", 288 "plan": { 289 "QueryType": "DDL", 290 "Original": "create view view_a as select id, name from unsharded where id in (select id from unsharded where id = 1 union select id from unsharded where id = 3)", 291 "Instructions": { 292 "OperatorType": "DDL", 293 "Keyspace": { 294 "Name": "main", 295 "Sharded": false 296 }, 297 "Query": "create view view_a as select id, `name` from unsharded where id in (select id from unsharded where id = 1 union select id from unsharded where id = 3)" 298 }, 299 "TablesUsed": [ 300 "main.view_a" 301 ] 302 } 303 }, 304 { 305 "comment": "create view with subquery in unsharded keyspace with UNION clause", 306 "query": "create view view_a as (select id from unsharded) union (select id from unsharded_auto) order by id limit 5", 307 "plan": { 308 "QueryType": "DDL", 309 "Original": "create view view_a as (select id from unsharded) union (select id from unsharded_auto) order by id limit 5", 310 "Instructions": { 311 "OperatorType": "DDL", 312 "Keyspace": { 313 "Name": "main", 314 "Sharded": false 315 }, 316 "Query": "create view view_a as select id from unsharded union select id from unsharded_auto order by id asc limit 5" 317 }, 318 "TablesUsed": [ 319 "main.view_a" 320 ] 321 } 322 }, 323 { 324 "comment": "create view with subquery in unsharded keyspace with multiple UNION clauses", 325 "query": "create view view_a as select id from unsharded union select id from unsharded_auto union select id from unsharded_auto where id in (132)", 326 "plan": { 327 "QueryType": "DDL", 328 "Original": "create view view_a as select id from unsharded union select id from unsharded_auto union select id from unsharded_auto where id in (132)", 329 "Instructions": { 330 "OperatorType": "DDL", 331 "Keyspace": { 332 "Name": "main", 333 "Sharded": false 334 }, 335 "Query": "create view view_a as select id from unsharded union select id from unsharded_auto union select id from unsharded_auto where id in (132)" 336 }, 337 "TablesUsed": [ 338 "main.view_a" 339 ] 340 } 341 }, 342 { 343 "comment": "create view with subquery in unsharded keyspace with UNION clauses in subqueries", 344 "query": "create view view_a as (select id from unsharded union select id from unsharded_auto) union (select id from unsharded_auto union select name from unsharded)", 345 "plan": { 346 "QueryType": "DDL", 347 "Original": "create view view_a as (select id from unsharded union select id from unsharded_auto) union (select id from unsharded_auto union select name from unsharded)", 348 "Instructions": { 349 "OperatorType": "DDL", 350 "Keyspace": { 351 "Name": "main", 352 "Sharded": false 353 }, 354 "Query": "create view view_a as select id from unsharded union select id from unsharded_auto union select id from unsharded_auto union select `name` from unsharded" 355 }, 356 "TablesUsed": [ 357 "main.view_a" 358 ] 359 } 360 }, 361 { 362 "comment": "Alter View", 363 "query": "alter view user.user_extra as select * from user.user", 364 "plan": { 365 "QueryType": "DDL", 366 "Original": "alter view user.user_extra as select * from user.user", 367 "Instructions": { 368 "OperatorType": "DDL", 369 "Keyspace": { 370 "Name": "user", 371 "Sharded": true 372 }, 373 "Query": "alter view user_extra as select * from `user`" 374 }, 375 "TablesUsed": [ 376 "user.user_extra" 377 ] 378 } 379 }, 380 { 381 "comment": "Create View with authoritative column", 382 "query": "create view user.tmp_view as select * from user.authoritative", 383 "v3-plan": { 384 "QueryType": "DDL", 385 "Original": "create view user.tmp_view as select * from user.authoritative", 386 "Instructions": { 387 "OperatorType": "DDL", 388 "Keyspace": { 389 "Name": "user", 390 "Sharded": true 391 }, 392 "Query": "create view tmp_view as select * from authoritative" 393 }, 394 "TablesUsed": [ 395 "user.tmp_view" 396 ] 397 }, 398 "gen4-plan": { 399 "QueryType": "DDL", 400 "Original": "create view user.tmp_view as select * from user.authoritative", 401 "Instructions": { 402 "OperatorType": "DDL", 403 "Keyspace": { 404 "Name": "user", 405 "Sharded": true 406 }, 407 "Query": "create view tmp_view as select user_id, col1, col2 from authoritative" 408 }, 409 "TablesUsed": [ 410 "user.tmp_view" 411 ] 412 } 413 }, 414 { 415 "comment": "drop table without qualifier", 416 "query": "drop table unsharded_a", 417 "plan": { 418 "QueryType": "DDL", 419 "Original": "drop table unsharded_a", 420 "Instructions": { 421 "OperatorType": "DDL", 422 "Keyspace": { 423 "Name": "main", 424 "Sharded": false 425 }, 426 "Query": "drop table unsharded_a" 427 }, 428 "TablesUsed": [ 429 "main.unsharded_a" 430 ] 431 } 432 }, 433 { 434 "comment": "Drop view", 435 "query": "drop view main.a", 436 "plan": { 437 "QueryType": "DDL", 438 "Original": "drop view main.a", 439 "Instructions": { 440 "OperatorType": "DDL", 441 "Keyspace": { 442 "Name": "main", 443 "Sharded": false 444 }, 445 "Query": "drop view a" 446 }, 447 "TablesUsed": [ 448 "main.a" 449 ] 450 } 451 }, 452 { 453 "comment": "Truncate table with qualifier", 454 "query": "truncate user.user_extra", 455 "plan": { 456 "QueryType": "DDL", 457 "Original": "truncate user.user_extra", 458 "Instructions": { 459 "OperatorType": "DDL", 460 "Keyspace": { 461 "Name": "user", 462 "Sharded": true 463 }, 464 "Query": "truncate table user_extra" 465 }, 466 "TablesUsed": [ 467 "user.user_extra" 468 ] 469 } 470 }, 471 { 472 "comment": "Rename table", 473 "query": "rename table a to main.b", 474 "plan": { 475 "QueryType": "DDL", 476 "Original": "rename table a to main.b", 477 "Instructions": { 478 "OperatorType": "DDL", 479 "Keyspace": { 480 "Name": "main", 481 "Sharded": false 482 }, 483 "Query": "rename table a to b" 484 }, 485 "TablesUsed": [ 486 "main.a", 487 "main.b" 488 ] 489 } 490 }, 491 { 492 "comment": "CREATE temp TABLE", 493 "query": "create temporary table a(id int)", 494 "plan": { 495 "QueryType": "DDL", 496 "Original": "create temporary table a(id int)", 497 "Instructions": { 498 "OperatorType": "DDL", 499 "Keyspace": { 500 "Name": "main", 501 "Sharded": false 502 }, 503 "Query": "create temporary table a (\n\tid int\n)", 504 "TempTable": true 505 }, 506 "TablesUsed": [ 507 "main.a" 508 ] 509 } 510 }, 511 { 512 "comment": "DROP temp TABLE", 513 "query": "drop temporary table a", 514 "plan": { 515 "QueryType": "DDL", 516 "Original": "drop temporary table a", 517 "Instructions": { 518 "OperatorType": "DDL", 519 "Keyspace": { 520 "Name": "main", 521 "Sharded": false 522 }, 523 "Query": "drop temporary table a", 524 "TempTable": true 525 }, 526 "TablesUsed": [ 527 "main.a" 528 ] 529 } 530 }, 531 { 532 "comment": "create table with function as a default value", 533 "query": "create table function_default (x varchar(25) DEFAULT (TRIM(' check ')))", 534 "plan": { 535 "QueryType": "DDL", 536 "Original": "create table function_default (x varchar(25) DEFAULT (TRIM(' check ')))", 537 "Instructions": { 538 "OperatorType": "DDL", 539 "Keyspace": { 540 "Name": "main", 541 "Sharded": false 542 }, 543 "Query": "create table function_default (\n\tx varchar(25) default (trim(' check '))\n)" 544 }, 545 "TablesUsed": [ 546 "main.function_default" 547 ] 548 } 549 } 550 ]