vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/testdata/reference_cases.json (about) 1 [ 2 { 3 "comment": "select from unqualified ambiguous reference routes to reference source", 4 "query": "select * from ambiguous_ref_with_source", 5 "v3-plan": { 6 "QueryType": "SELECT", 7 "Original": "select * from ambiguous_ref_with_source", 8 "Instructions": { 9 "OperatorType": "Route", 10 "Variant": "Reference", 11 "Keyspace": { 12 "Name": "main", 13 "Sharded": false 14 }, 15 "FieldQuery": "select * from ambiguous_ref_with_source where 1 != 1", 16 "Query": "select * from ambiguous_ref_with_source", 17 "Table": "ambiguous_ref_with_source" 18 } 19 }, 20 "gen4-plan": { 21 "QueryType": "SELECT", 22 "Original": "select * from ambiguous_ref_with_source", 23 "Instructions": { 24 "OperatorType": "Route", 25 "Variant": "Reference", 26 "Keyspace": { 27 "Name": "main", 28 "Sharded": false 29 }, 30 "FieldQuery": "select * from ambiguous_ref_with_source where 1 != 1", 31 "Query": "select * from ambiguous_ref_with_source", 32 "Table": "ambiguous_ref_with_source" 33 }, 34 "TablesUsed": [ 35 "main.ambiguous_ref_with_source" 36 ] 37 } 38 }, 39 { 40 "comment": "join with unqualified ambiguous reference table routes to optimal keyspace", 41 "query": "select user.col from user join ambiguous_ref_with_source", 42 "v3-plan": { 43 "QueryType": "SELECT", 44 "Original": "select user.col from user join ambiguous_ref_with_source", 45 "Instructions": { 46 "OperatorType": "Join", 47 "Variant": "Join", 48 "JoinColumnIndexes": "L:0", 49 "TableName": "`user`_ambiguous_ref_with_source", 50 "Inputs": [ 51 { 52 "OperatorType": "Route", 53 "Variant": "Scatter", 54 "Keyspace": { 55 "Name": "user", 56 "Sharded": true 57 }, 58 "FieldQuery": "select `user`.col from `user` where 1 != 1", 59 "Query": "select `user`.col from `user`", 60 "Table": "`user`" 61 }, 62 { 63 "OperatorType": "Route", 64 "Variant": "Reference", 65 "Keyspace": { 66 "Name": "main", 67 "Sharded": false 68 }, 69 "FieldQuery": "select 1 from ambiguous_ref_with_source where 1 != 1", 70 "Query": "select 1 from ambiguous_ref_with_source", 71 "Table": "ambiguous_ref_with_source" 72 } 73 ] 74 } 75 }, 76 "gen4-plan": { 77 "QueryType": "SELECT", 78 "Original": "select user.col from user join ambiguous_ref_with_source", 79 "Instructions": { 80 "OperatorType": "Route", 81 "Variant": "Scatter", 82 "Keyspace": { 83 "Name": "user", 84 "Sharded": true 85 }, 86 "FieldQuery": "select `user`.col from `user`, ambiguous_ref_with_source where 1 != 1", 87 "Query": "select `user`.col from `user`, ambiguous_ref_with_source", 88 "Table": "`user`, ambiguous_ref_with_source" 89 }, 90 "TablesUsed": [ 91 "user.ambiguous_ref_with_source", 92 "user.user" 93 ] 94 } 95 }, 96 { 97 "comment": "ambiguous unqualified reference table self-join routes to reference source", 98 "query": "select r1.col from ambiguous_ref_with_source r1 join ambiguous_ref_with_source", 99 "v3-plan": { 100 "QueryType": "SELECT", 101 "Original": "select r1.col from ambiguous_ref_with_source r1 join ambiguous_ref_with_source", 102 "Instructions": { 103 "OperatorType": "Route", 104 "Variant": "Reference", 105 "Keyspace": { 106 "Name": "main", 107 "Sharded": false 108 }, 109 "FieldQuery": "select r1.col from ambiguous_ref_with_source as r1 join ambiguous_ref_with_source where 1 != 1", 110 "Query": "select r1.col from ambiguous_ref_with_source as r1 join ambiguous_ref_with_source", 111 "Table": "ambiguous_ref_with_source" 112 } 113 }, 114 "gen4-plan": { 115 "QueryType": "SELECT", 116 "Original": "select r1.col from ambiguous_ref_with_source r1 join ambiguous_ref_with_source", 117 "Instructions": { 118 "OperatorType": "Route", 119 "Variant": "Reference", 120 "Keyspace": { 121 "Name": "main", 122 "Sharded": false 123 }, 124 "FieldQuery": "select r1.col from ambiguous_ref_with_source as r1, ambiguous_ref_with_source where 1 != 1", 125 "Query": "select r1.col from ambiguous_ref_with_source as r1, ambiguous_ref_with_source", 126 "Table": "ambiguous_ref_with_source" 127 }, 128 "TablesUsed": [ 129 "main.ambiguous_ref_with_source" 130 ] 131 } 132 }, 133 { 134 "comment": "ambiguous unqualified reference table can merge with other opcodes left to right.", 135 "query": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source join user", 136 "v3-plan": { 137 "QueryType": "SELECT", 138 "Original": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source join user", 139 "Instructions": { 140 "OperatorType": "Join", 141 "Variant": "Join", 142 "JoinColumnIndexes": "L:0", 143 "TableName": "ambiguous_ref_with_source_`user`", 144 "Inputs": [ 145 { 146 "OperatorType": "Route", 147 "Variant": "Reference", 148 "Keyspace": { 149 "Name": "main", 150 "Sharded": false 151 }, 152 "FieldQuery": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source where 1 != 1", 153 "Query": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source", 154 "Table": "ambiguous_ref_with_source" 155 }, 156 { 157 "OperatorType": "Route", 158 "Variant": "Scatter", 159 "Keyspace": { 160 "Name": "user", 161 "Sharded": true 162 }, 163 "FieldQuery": "select 1 from `user` where 1 != 1", 164 "Query": "select 1 from `user`", 165 "Table": "`user`" 166 } 167 ] 168 } 169 }, 170 "gen4-plan": { 171 "QueryType": "SELECT", 172 "Original": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source join user", 173 "Instructions": { 174 "OperatorType": "Route", 175 "Variant": "Scatter", 176 "Keyspace": { 177 "Name": "user", 178 "Sharded": true 179 }, 180 "FieldQuery": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source, `user` where 1 != 1", 181 "Query": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source, `user`", 182 "Table": "`user`, ambiguous_ref_with_source" 183 }, 184 "TablesUsed": [ 185 "user.ambiguous_ref_with_source", 186 "user.user" 187 ] 188 } 189 }, 190 { 191 "comment": "ambiguous unqualified reference table can merge with other opcodes left to right and vindex value is in the plan", 192 "query": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source join (select aa from user where user.id=1) user", 193 "v3-plan": { 194 "QueryType": "SELECT", 195 "Original": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source join (select aa from user where user.id=1) user", 196 "Instructions": { 197 "OperatorType": "Join", 198 "Variant": "Join", 199 "JoinColumnIndexes": "L:0", 200 "TableName": "ambiguous_ref_with_source_`user`", 201 "Inputs": [ 202 { 203 "OperatorType": "Route", 204 "Variant": "Reference", 205 "Keyspace": { 206 "Name": "main", 207 "Sharded": false 208 }, 209 "FieldQuery": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source where 1 != 1", 210 "Query": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source", 211 "Table": "ambiguous_ref_with_source" 212 }, 213 { 214 "OperatorType": "Route", 215 "Variant": "EqualUnique", 216 "Keyspace": { 217 "Name": "user", 218 "Sharded": true 219 }, 220 "FieldQuery": "select 1 from (select aa from `user` where 1 != 1) as `user` where 1 != 1", 221 "Query": "select 1 from (select aa from `user` where `user`.id = 1) as `user`", 222 "Table": "`user`", 223 "Values": [ 224 "INT64(1)" 225 ], 226 "Vindex": "user_index" 227 } 228 ] 229 } 230 }, 231 "gen4-plan": { 232 "QueryType": "SELECT", 233 "Original": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source join (select aa from user where user.id=1) user", 234 "Instructions": { 235 "OperatorType": "Route", 236 "Variant": "EqualUnique", 237 "Keyspace": { 238 "Name": "user", 239 "Sharded": true 240 }, 241 "FieldQuery": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source, (select aa from `user` where 1 != 1) as `user` where 1 != 1", 242 "Query": "select ambiguous_ref_with_source.col from ambiguous_ref_with_source, (select aa from `user` where `user`.id = 1) as `user`", 243 "Table": "`user`, ambiguous_ref_with_source", 244 "Values": [ 245 "INT64(1)" 246 ], 247 "Vindex": "user_index" 248 }, 249 "TablesUsed": [ 250 "user.ambiguous_ref_with_source", 251 "user.user" 252 ] 253 } 254 }, 255 { 256 "comment": "qualified join to reference table routes to optimal keyspace", 257 "query": "select user.col from user join main.ambiguous_ref_with_source", 258 "v3-plan": { 259 "QueryType": "SELECT", 260 "Original": "select user.col from user join main.ambiguous_ref_with_source", 261 "Instructions": { 262 "OperatorType": "Join", 263 "Variant": "Join", 264 "JoinColumnIndexes": "L:0", 265 "TableName": "`user`_ambiguous_ref_with_source", 266 "Inputs": [ 267 { 268 "OperatorType": "Route", 269 "Variant": "Scatter", 270 "Keyspace": { 271 "Name": "user", 272 "Sharded": true 273 }, 274 "FieldQuery": "select `user`.col from `user` where 1 != 1", 275 "Query": "select `user`.col from `user`", 276 "Table": "`user`" 277 }, 278 { 279 "OperatorType": "Route", 280 "Variant": "Reference", 281 "Keyspace": { 282 "Name": "main", 283 "Sharded": false 284 }, 285 "FieldQuery": "select 1 from ambiguous_ref_with_source where 1 != 1", 286 "Query": "select 1 from ambiguous_ref_with_source", 287 "Table": "ambiguous_ref_with_source" 288 } 289 ] 290 } 291 }, 292 "gen4-plan": { 293 "QueryType": "SELECT", 294 "Original": "select user.col from user join main.ambiguous_ref_with_source", 295 "Instructions": { 296 "OperatorType": "Route", 297 "Variant": "Scatter", 298 "Keyspace": { 299 "Name": "user", 300 "Sharded": true 301 }, 302 "FieldQuery": "select `user`.col from `user`, ambiguous_ref_with_source where 1 != 1", 303 "Query": "select `user`.col from `user`, ambiguous_ref_with_source", 304 "Table": "`user`, ambiguous_ref_with_source" 305 }, 306 "TablesUsed": [ 307 "user.ambiguous_ref_with_source", 308 "user.user" 309 ] 310 } 311 }, 312 { 313 "comment": "insert into ambiguous qualified reference table routes to source", 314 "query": "insert into ambiguous_ref_with_source(col) values(1)", 315 "plan": { 316 "QueryType": "INSERT", 317 "Original": "insert into ambiguous_ref_with_source(col) values(1)", 318 "Instructions": { 319 "OperatorType": "Insert", 320 "Variant": "Unsharded", 321 "Keyspace": { 322 "Name": "main", 323 "Sharded": false 324 }, 325 "TargetTabletType": "PRIMARY", 326 "MultiShardAutocommit": false, 327 "Query": "insert into ambiguous_ref_with_source(col) values (1)", 328 "TableName": "ambiguous_ref_with_source" 329 }, 330 "TablesUsed": [ 331 "main.ambiguous_ref_with_source" 332 ] 333 } 334 }, 335 { 336 "comment": "insert into qualified ambiguous reference table routes v3 to requested keyspace gen4 to source", 337 "query": "insert into user.ambiguous_ref_with_source(col) values(1)", 338 "v3-plan": { 339 "QueryType": "INSERT", 340 "Original": "insert into user.ambiguous_ref_with_source(col) values(1)", 341 "Instructions": { 342 "OperatorType": "Insert", 343 "Variant": "Sharded", 344 "Keyspace": { 345 "Name": "user", 346 "Sharded": true 347 }, 348 "TargetTabletType": "PRIMARY", 349 "MultiShardAutocommit": false, 350 "Query": "insert into ambiguous_ref_with_source(col) values (1)", 351 "TableName": "ambiguous_ref_with_source" 352 }, 353 "TablesUsed": [ 354 "user.ambiguous_ref_with_source" 355 ] 356 }, 357 "gen4-plan": { 358 "QueryType": "INSERT", 359 "Original": "insert into user.ambiguous_ref_with_source(col) values(1)", 360 "Instructions": { 361 "OperatorType": "Insert", 362 "Variant": "Unsharded", 363 "Keyspace": { 364 "Name": "main", 365 "Sharded": false 366 }, 367 "TargetTabletType": "PRIMARY", 368 "MultiShardAutocommit": false, 369 "Query": "insert into ambiguous_ref_with_source(col) values (1)", 370 "TableName": "ambiguous_ref_with_source" 371 }, 372 "TablesUsed": [ 373 "main.ambiguous_ref_with_source" 374 ] 375 } 376 }, 377 { 378 "comment": "update unqualified ambiguous reference table routes to source", 379 "query": "update ambiguous_ref_with_source set col = 1", 380 "plan": { 381 "QueryType": "UPDATE", 382 "Original": "update ambiguous_ref_with_source set col = 1", 383 "Instructions": { 384 "OperatorType": "Update", 385 "Variant": "Unsharded", 386 "Keyspace": { 387 "Name": "main", 388 "Sharded": false 389 }, 390 "TargetTabletType": "PRIMARY", 391 "MultiShardAutocommit": false, 392 "Query": "update ambiguous_ref_with_source set col = 1", 393 "Table": "ambiguous_ref_with_source" 394 }, 395 "TablesUsed": [ 396 "main.ambiguous_ref_with_source" 397 ] 398 } 399 }, 400 { 401 "comment": "update qualified ambiguous reference table v3 error no primary vindex v4 route to source", 402 "query": "update user.ambiguous_ref_with_source set col = 1", 403 "v3-plan": "VT09001: table 'ambiguous_ref_with_source' does not have a primary vindex", 404 "gen4-plan": { 405 "QueryType": "UPDATE", 406 "Original": "update user.ambiguous_ref_with_source set col = 1", 407 "Instructions": { 408 "OperatorType": "Update", 409 "Variant": "Scatter", 410 "Keyspace": { 411 "Name": "main", 412 "Sharded": false 413 }, 414 "TargetTabletType": "PRIMARY", 415 "MultiShardAutocommit": false, 416 "Query": "update ambiguous_ref_with_source set col = 1", 417 "Table": "ambiguous_ref_with_source" 418 }, 419 "TablesUsed": [ 420 "main.ambiguous_ref_with_source" 421 ] 422 } 423 }, 424 { 425 "comment": "delete from unqualified ambiguous reference table routes to source", 426 "query": "delete from ambiguous_ref_with_source where col = 1", 427 "plan": { 428 "QueryType": "DELETE", 429 "Original": "delete from ambiguous_ref_with_source where col = 1", 430 "Instructions": { 431 "OperatorType": "Delete", 432 "Variant": "Unsharded", 433 "Keyspace": { 434 "Name": "main", 435 "Sharded": false 436 }, 437 "TargetTabletType": "PRIMARY", 438 "MultiShardAutocommit": false, 439 "Query": "delete from ambiguous_ref_with_source where col = 1", 440 "Table": "ambiguous_ref_with_source" 441 }, 442 "TablesUsed": [ 443 "main.ambiguous_ref_with_source" 444 ] 445 } 446 }, 447 { 448 "comment": "delete from qualified ambiguous reference table v3 error no primary vindex v4 route to source", 449 "query": "delete from user.ambiguous_ref_with_source where col = 1", 450 "v3-plan": "VT09001: table 'ambiguous_ref_with_source' does not have a primary vindex", 451 "gen4-plan": { 452 "QueryType": "DELETE", 453 "Original": "delete from user.ambiguous_ref_with_source where col = 1", 454 "Instructions": { 455 "OperatorType": "Delete", 456 "Variant": "Scatter", 457 "Keyspace": { 458 "Name": "main", 459 "Sharded": false 460 }, 461 "TargetTabletType": "PRIMARY", 462 "MultiShardAutocommit": false, 463 "Query": "delete from ambiguous_ref_with_source where col = 1", 464 "Table": "ambiguous_ref_with_source" 465 }, 466 "TablesUsed": [ 467 "main.ambiguous_ref_with_source" 468 ] 469 } 470 }, 471 { 472 "comment": "join with unqualified unambiguous ref with source routes to requested table", 473 "query": "select user.col from user join ref_with_source", 474 "v3-plan": { 475 "QueryType": "SELECT", 476 "Original": "select user.col from user join ref_with_source", 477 "Instructions": { 478 "OperatorType": "Route", 479 "Variant": "Scatter", 480 "Keyspace": { 481 "Name": "user", 482 "Sharded": true 483 }, 484 "FieldQuery": "select `user`.col from `user` join ref_with_source where 1 != 1", 485 "Query": "select `user`.col from `user` join ref_with_source", 486 "Table": "`user`, ref_with_source" 487 } 488 }, 489 "gen4-plan": { 490 "QueryType": "SELECT", 491 "Original": "select user.col from user join ref_with_source", 492 "Instructions": { 493 "OperatorType": "Route", 494 "Variant": "Scatter", 495 "Keyspace": { 496 "Name": "user", 497 "Sharded": true 498 }, 499 "FieldQuery": "select `user`.col from `user`, ref_with_source where 1 != 1", 500 "Query": "select `user`.col from `user`, ref_with_source", 501 "Table": "`user`, ref_with_source" 502 }, 503 "TablesUsed": [ 504 "user.ref_with_source", 505 "user.user" 506 ] 507 } 508 }, 509 { 510 "comment": "join with unqualified reference optimize routes when source & reference have different names", 511 "query": "select user.col from user join ref_in_source", 512 "v3-plan": { 513 "QueryType": "SELECT", 514 "Original": "select user.col from user join ref_in_source", 515 "Instructions": { 516 "OperatorType": "Join", 517 "Variant": "Join", 518 "JoinColumnIndexes": "L:0", 519 "TableName": "`user`_ref_in_source", 520 "Inputs": [ 521 { 522 "OperatorType": "Route", 523 "Variant": "Scatter", 524 "Keyspace": { 525 "Name": "user", 526 "Sharded": true 527 }, 528 "FieldQuery": "select `user`.col from `user` where 1 != 1", 529 "Query": "select `user`.col from `user`", 530 "Table": "`user`" 531 }, 532 { 533 "OperatorType": "Route", 534 "Variant": "Reference", 535 "Keyspace": { 536 "Name": "main", 537 "Sharded": false 538 }, 539 "FieldQuery": "select 1 from ref_in_source where 1 != 1", 540 "Query": "select 1 from ref_in_source", 541 "Table": "ref_in_source" 542 } 543 ] 544 } 545 }, 546 "gen4-plan": { 547 "QueryType": "SELECT", 548 "Original": "select user.col from user join ref_in_source", 549 "Instructions": { 550 "OperatorType": "Route", 551 "Variant": "Scatter", 552 "Keyspace": { 553 "Name": "user", 554 "Sharded": true 555 }, 556 "FieldQuery": "select `user`.col from `user`, ref_with_source as ref_in_source where 1 != 1", 557 "Query": "select `user`.col from `user`, ref_with_source as ref_in_source", 558 "Table": "`user`, ref_with_source" 559 }, 560 "TablesUsed": [ 561 "user.ref_with_source", 562 "user.user" 563 ] 564 } 565 }, 566 { 567 "comment": "join with unqualified reference respects routing rules", 568 "query": "select user.col from user join rerouted_ref", 569 "v3-plan": { 570 "QueryType": "SELECT", 571 "Original": "select user.col from user join rerouted_ref", 572 "Instructions": { 573 "OperatorType": "Join", 574 "Variant": "Join", 575 "JoinColumnIndexes": "L:0", 576 "TableName": "`user`_rerouted_ref", 577 "Inputs": [ 578 { 579 "OperatorType": "Route", 580 "Variant": "Scatter", 581 "Keyspace": { 582 "Name": "user", 583 "Sharded": true 584 }, 585 "FieldQuery": "select `user`.col from `user` where 1 != 1", 586 "Query": "select `user`.col from `user`", 587 "Table": "`user`" 588 }, 589 { 590 "OperatorType": "Route", 591 "Variant": "Reference", 592 "Keyspace": { 593 "Name": "main", 594 "Sharded": false 595 }, 596 "FieldQuery": "select 1 from rerouted_ref where 1 != 1", 597 "Query": "select 1 from rerouted_ref", 598 "Table": "rerouted_ref" 599 } 600 ] 601 } 602 }, 603 "gen4-plan": { 604 "QueryType": "SELECT", 605 "Original": "select user.col from user join rerouted_ref", 606 "Instructions": { 607 "OperatorType": "Route", 608 "Variant": "Scatter", 609 "Keyspace": { 610 "Name": "user", 611 "Sharded": true 612 }, 613 "FieldQuery": "select `user`.col from `user`, ref as rerouted_ref where 1 != 1", 614 "Query": "select `user`.col from `user`, ref as rerouted_ref", 615 "Table": "`user`, ref" 616 }, 617 "TablesUsed": [ 618 "user.ref", 619 "user.user" 620 ] 621 } 622 } 623 ]