vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/testdata/from_cases.json (about) 1 [ 2 { 3 "comment": "Single table sharded scatter", 4 "query": "select col from user", 5 "v3-plan": { 6 "QueryType": "SELECT", 7 "Original": "select col from user", 8 "Instructions": { 9 "OperatorType": "Route", 10 "Variant": "Scatter", 11 "Keyspace": { 12 "Name": "user", 13 "Sharded": true 14 }, 15 "FieldQuery": "select col from `user` where 1 != 1", 16 "Query": "select col from `user`", 17 "Table": "`user`" 18 } 19 }, 20 "gen4-plan": { 21 "QueryType": "SELECT", 22 "Original": "select col from user", 23 "Instructions": { 24 "OperatorType": "Route", 25 "Variant": "Scatter", 26 "Keyspace": { 27 "Name": "user", 28 "Sharded": true 29 }, 30 "FieldQuery": "select col from `user` where 1 != 1", 31 "Query": "select col from `user`", 32 "Table": "`user`" 33 }, 34 "TablesUsed": [ 35 "user.user" 36 ] 37 } 38 }, 39 { 40 "comment": "Single table unsharded", 41 "query": "select col from unsharded", 42 "v3-plan": { 43 "QueryType": "SELECT", 44 "Original": "select col from unsharded", 45 "Instructions": { 46 "OperatorType": "Route", 47 "Variant": "Unsharded", 48 "Keyspace": { 49 "Name": "main", 50 "Sharded": false 51 }, 52 "FieldQuery": "select col from unsharded where 1 != 1", 53 "Query": "select col from unsharded", 54 "Table": "unsharded" 55 } 56 }, 57 "gen4-plan": { 58 "QueryType": "SELECT", 59 "Original": "select col from unsharded", 60 "Instructions": { 61 "OperatorType": "Route", 62 "Variant": "Unsharded", 63 "Keyspace": { 64 "Name": "main", 65 "Sharded": false 66 }, 67 "FieldQuery": "select col from unsharded where 1 != 1", 68 "Query": "select col from unsharded", 69 "Table": "unsharded" 70 }, 71 "TablesUsed": [ 72 "main.unsharded" 73 ] 74 } 75 }, 76 { 77 "comment": "Select from sequence", 78 "query": "select next 2 values from seq", 79 "v3-plan": { 80 "QueryType": "SELECT", 81 "Original": "select next 2 values from seq", 82 "Instructions": { 83 "OperatorType": "Route", 84 "Variant": "Next", 85 "Keyspace": { 86 "Name": "main", 87 "Sharded": false 88 }, 89 "FieldQuery": "select next 2 values from seq where 1 != 1", 90 "Query": "select next 2 values from seq", 91 "Table": "seq" 92 } 93 }, 94 "gen4-plan": { 95 "QueryType": "SELECT", 96 "Original": "select next 2 values from seq", 97 "Instructions": { 98 "OperatorType": "Route", 99 "Variant": "Next", 100 "Keyspace": { 101 "Name": "main", 102 "Sharded": false 103 }, 104 "FieldQuery": "select next 2 values from seq where 1 != 1", 105 "Query": "select next 2 values from seq", 106 "Table": "seq" 107 }, 108 "TablesUsed": [ 109 "main.seq" 110 ] 111 } 112 }, 113 { 114 "comment": "select next from non-sequence table", 115 "query": "select next value from user", 116 "v3-plan": "VT03018: NEXT used on a non-sequence table", 117 "gen4-plan": "NEXT used on a non-sequence table" 118 }, 119 { 120 "comment": "select next in derived table", 121 "query": "select 1 from (select next value from seq) t", 122 "v3-plan": { 123 "QueryType": "SELECT", 124 "Original": "select 1 from (select next value from seq) t", 125 "Instructions": { 126 "OperatorType": "Route", 127 "Variant": "Next", 128 "Keyspace": { 129 "Name": "main", 130 "Sharded": false 131 }, 132 "FieldQuery": "select 1 from (select next 1 values from seq where 1 != 1) as t where 1 != 1", 133 "Query": "select 1 from (select next 1 values from seq) as t", 134 "Table": "seq" 135 } 136 }, 137 "gen4-plan": "Incorrect usage/placement of 'NEXT'" 138 }, 139 { 140 "comment": "select next in derived table", 141 "query": "select * from (select next value from seq) t", 142 "v3-plan": { 143 "QueryType": "SELECT", 144 "Original": "select * from (select next value from seq) t", 145 "Instructions": { 146 "OperatorType": "Route", 147 "Variant": "Next", 148 "Keyspace": { 149 "Name": "main", 150 "Sharded": false 151 }, 152 "FieldQuery": "select * from (select next 1 values from seq where 1 != 1) as t where 1 != 1", 153 "Query": "select * from (select next 1 values from seq) as t", 154 "Table": "seq" 155 } 156 }, 157 "gen4-plan": "Incorrect usage/placement of 'NEXT'" 158 }, 159 { 160 "comment": "select next in subquery", 161 "query": "select 1 from user where id in (select next value from seq)", 162 "v3-plan": { 163 "QueryType": "SELECT", 164 "Original": "select 1 from user where id in (select next value from seq)", 165 "Instructions": { 166 "OperatorType": "Subquery", 167 "Variant": "PulloutIn", 168 "PulloutVars": [ 169 "__sq_has_values1", 170 "__sq1" 171 ], 172 "Inputs": [ 173 { 174 "OperatorType": "Route", 175 "Variant": "Next", 176 "Keyspace": { 177 "Name": "main", 178 "Sharded": false 179 }, 180 "FieldQuery": "select next 1 values from seq where 1 != 1", 181 "Query": "select next 1 values from seq", 182 "Table": "seq" 183 }, 184 { 185 "OperatorType": "Route", 186 "Variant": "IN", 187 "Keyspace": { 188 "Name": "user", 189 "Sharded": true 190 }, 191 "FieldQuery": "select 1 from `user` where 1 != 1", 192 "Query": "select 1 from `user` where :__sq_has_values1 = 1 and id in ::__vals", 193 "Table": "`user`", 194 "Values": [ 195 ":__sq1" 196 ], 197 "Vindex": "user_index" 198 } 199 ] 200 } 201 }, 202 "gen4-plan": "Incorrect usage/placement of 'NEXT'" 203 }, 204 { 205 "comment": "select next in projection", 206 "query": "select (select next value from seq) from user", 207 "v3-plan": { 208 "QueryType": "SELECT", 209 "Original": "select (select next value from seq) from user", 210 "Instructions": { 211 "OperatorType": "Subquery", 212 "Variant": "PulloutValue", 213 "PulloutVars": [ 214 "__sq_has_values1", 215 "__sq1" 216 ], 217 "Inputs": [ 218 { 219 "OperatorType": "Route", 220 "Variant": "Next", 221 "Keyspace": { 222 "Name": "main", 223 "Sharded": false 224 }, 225 "FieldQuery": "select next 1 values from seq where 1 != 1", 226 "Query": "select next 1 values from seq", 227 "Table": "seq" 228 }, 229 { 230 "OperatorType": "Route", 231 "Variant": "Scatter", 232 "Keyspace": { 233 "Name": "user", 234 "Sharded": true 235 }, 236 "FieldQuery": "select :__sq1 from `user` where 1 != 1", 237 "Query": "select :__sq1 from `user`", 238 "Table": "`user`" 239 } 240 ] 241 } 242 }, 243 "gen4-plan": "Incorrect usage/placement of 'NEXT'" 244 }, 245 { 246 "comment": "Select from reference", 247 "query": "select * from ref", 248 "v3-plan": { 249 "QueryType": "SELECT", 250 "Original": "select * from ref", 251 "Instructions": { 252 "OperatorType": "Route", 253 "Variant": "Reference", 254 "Keyspace": { 255 "Name": "user", 256 "Sharded": true 257 }, 258 "FieldQuery": "select * from ref where 1 != 1", 259 "Query": "select * from ref", 260 "Table": "ref" 261 } 262 }, 263 "gen4-plan": { 264 "QueryType": "SELECT", 265 "Original": "select * from ref", 266 "Instructions": { 267 "OperatorType": "Route", 268 "Variant": "Reference", 269 "Keyspace": { 270 "Name": "user", 271 "Sharded": true 272 }, 273 "FieldQuery": "select * from ref where 1 != 1", 274 "Query": "select * from ref", 275 "Table": "ref" 276 }, 277 "TablesUsed": [ 278 "user.ref" 279 ] 280 } 281 }, 282 { 283 "comment": "Multi-table unsharded", 284 "query": "select m1.col from unsharded as m1 join unsharded as m2", 285 "v3-plan": { 286 "QueryType": "SELECT", 287 "Original": "select m1.col from unsharded as m1 join unsharded as m2", 288 "Instructions": { 289 "OperatorType": "Route", 290 "Variant": "Unsharded", 291 "Keyspace": { 292 "Name": "main", 293 "Sharded": false 294 }, 295 "FieldQuery": "select m1.col from unsharded as m1 join unsharded as m2 where 1 != 1", 296 "Query": "select m1.col from unsharded as m1 join unsharded as m2", 297 "Table": "unsharded" 298 } 299 }, 300 "gen4-plan": { 301 "QueryType": "SELECT", 302 "Original": "select m1.col from unsharded as m1 join unsharded as m2", 303 "Instructions": { 304 "OperatorType": "Route", 305 "Variant": "Unsharded", 306 "Keyspace": { 307 "Name": "main", 308 "Sharded": false 309 }, 310 "FieldQuery": "select m1.col from unsharded as m1 join unsharded as m2 where 1 != 1", 311 "Query": "select m1.col from unsharded as m1 join unsharded as m2", 312 "Table": "unsharded" 313 }, 314 "TablesUsed": [ 315 "main.unsharded" 316 ] 317 } 318 }, 319 { 320 "comment": "Multi-table, multi-chunk", 321 "query": "select music.col from user join music", 322 "v3-plan": { 323 "QueryType": "SELECT", 324 "Original": "select music.col from user join music", 325 "Instructions": { 326 "OperatorType": "Join", 327 "Variant": "Join", 328 "JoinColumnIndexes": "R:0", 329 "TableName": "`user`_music", 330 "Inputs": [ 331 { 332 "OperatorType": "Route", 333 "Variant": "Scatter", 334 "Keyspace": { 335 "Name": "user", 336 "Sharded": true 337 }, 338 "FieldQuery": "select 1 from `user` where 1 != 1", 339 "Query": "select 1 from `user`", 340 "Table": "`user`" 341 }, 342 { 343 "OperatorType": "Route", 344 "Variant": "Scatter", 345 "Keyspace": { 346 "Name": "user", 347 "Sharded": true 348 }, 349 "FieldQuery": "select music.col from music where 1 != 1", 350 "Query": "select music.col from music", 351 "Table": "music" 352 } 353 ] 354 } 355 }, 356 "gen4-plan": { 357 "QueryType": "SELECT", 358 "Original": "select music.col from user join music", 359 "Instructions": { 360 "OperatorType": "Join", 361 "Variant": "Join", 362 "JoinColumnIndexes": "R:0", 363 "TableName": "`user`_music", 364 "Inputs": [ 365 { 366 "OperatorType": "Route", 367 "Variant": "Scatter", 368 "Keyspace": { 369 "Name": "user", 370 "Sharded": true 371 }, 372 "FieldQuery": "select 1 from `user` where 1 != 1", 373 "Query": "select 1 from `user`", 374 "Table": "`user`" 375 }, 376 { 377 "OperatorType": "Route", 378 "Variant": "Scatter", 379 "Keyspace": { 380 "Name": "user", 381 "Sharded": true 382 }, 383 "FieldQuery": "select music.col from music where 1 != 1", 384 "Query": "select music.col from music", 385 "Table": "music" 386 } 387 ] 388 }, 389 "TablesUsed": [ 390 "user.music", 391 "user.user" 392 ] 393 } 394 }, 395 { 396 "comment": "routing rules where table name matches, and there's no alias.", 397 "query": "select * from second_user.user", 398 "v3-plan": { 399 "QueryType": "SELECT", 400 "Original": "select * from second_user.user", 401 "Instructions": { 402 "OperatorType": "Route", 403 "Variant": "Scatter", 404 "Keyspace": { 405 "Name": "user", 406 "Sharded": true 407 }, 408 "FieldQuery": "select * from `user` where 1 != 1", 409 "Query": "select * from `user`", 410 "Table": "`user`" 411 } 412 }, 413 "gen4-plan": { 414 "QueryType": "SELECT", 415 "Original": "select * from second_user.user", 416 "Instructions": { 417 "OperatorType": "Route", 418 "Variant": "Scatter", 419 "Keyspace": { 420 "Name": "user", 421 "Sharded": true 422 }, 423 "FieldQuery": "select * from `user` where 1 != 1", 424 "Query": "select * from `user`", 425 "Table": "`user`" 426 }, 427 "TablesUsed": [ 428 "user.user" 429 ] 430 } 431 }, 432 { 433 "comment": "routing rules where table name matches, and there's an alias.", 434 "query": "select * from second_user.user as a", 435 "v3-plan": { 436 "QueryType": "SELECT", 437 "Original": "select * from second_user.user as a", 438 "Instructions": { 439 "OperatorType": "Route", 440 "Variant": "Scatter", 441 "Keyspace": { 442 "Name": "user", 443 "Sharded": true 444 }, 445 "FieldQuery": "select * from `user` as a where 1 != 1", 446 "Query": "select * from `user` as a", 447 "Table": "`user`" 448 } 449 }, 450 "gen4-plan": { 451 "QueryType": "SELECT", 452 "Original": "select * from second_user.user as a", 453 "Instructions": { 454 "OperatorType": "Route", 455 "Variant": "Scatter", 456 "Keyspace": { 457 "Name": "user", 458 "Sharded": true 459 }, 460 "FieldQuery": "select * from `user` as a where 1 != 1", 461 "Query": "select * from `user` as a", 462 "Table": "`user`" 463 }, 464 "TablesUsed": [ 465 "user.user" 466 ] 467 } 468 }, 469 { 470 "comment": "routing rules where table name does not match, and there's no alias.", 471 "query": "select * from route1", 472 "v3-plan": { 473 "QueryType": "SELECT", 474 "Original": "select * from route1", 475 "Instructions": { 476 "OperatorType": "Route", 477 "Variant": "Scatter", 478 "Keyspace": { 479 "Name": "user", 480 "Sharded": true 481 }, 482 "FieldQuery": "select * from `user` as route1 where 1 != 1", 483 "Query": "select * from `user` as route1", 484 "Table": "`user`" 485 } 486 }, 487 "gen4-plan": { 488 "QueryType": "SELECT", 489 "Original": "select * from route1", 490 "Instructions": { 491 "OperatorType": "Route", 492 "Variant": "Scatter", 493 "Keyspace": { 494 "Name": "user", 495 "Sharded": true 496 }, 497 "FieldQuery": "select * from `user` as route1 where 1 != 1", 498 "Query": "select * from `user` as route1", 499 "Table": "`user`" 500 }, 501 "TablesUsed": [ 502 "user.user" 503 ] 504 } 505 }, 506 { 507 "comment": "routing rules where table name does not match, and there's an alias.", 508 "query": "select * from route1 as a", 509 "v3-plan": { 510 "QueryType": "SELECT", 511 "Original": "select * from route1 as a", 512 "Instructions": { 513 "OperatorType": "Route", 514 "Variant": "Scatter", 515 "Keyspace": { 516 "Name": "user", 517 "Sharded": true 518 }, 519 "FieldQuery": "select * from `user` as a where 1 != 1", 520 "Query": "select * from `user` as a", 521 "Table": "`user`" 522 } 523 }, 524 "gen4-plan": { 525 "QueryType": "SELECT", 526 "Original": "select * from route1 as a", 527 "Instructions": { 528 "OperatorType": "Route", 529 "Variant": "Scatter", 530 "Keyspace": { 531 "Name": "user", 532 "Sharded": true 533 }, 534 "FieldQuery": "select * from `user` as a where 1 != 1", 535 "Query": "select * from `user` as a", 536 "Table": "`user`" 537 }, 538 "TablesUsed": [ 539 "user.user" 540 ] 541 } 542 }, 543 { 544 "comment": "routing rules with primary targeting", 545 "query": "select * from primary_redirect", 546 "v3-plan": { 547 "QueryType": "SELECT", 548 "Original": "select * from primary_redirect", 549 "Instructions": { 550 "OperatorType": "Route", 551 "Variant": "Scatter", 552 "Keyspace": { 553 "Name": "user", 554 "Sharded": true 555 }, 556 "FieldQuery": "select * from `user` as primary_redirect where 1 != 1", 557 "Query": "select * from `user` as primary_redirect", 558 "Table": "`user`" 559 } 560 }, 561 "gen4-plan": { 562 "QueryType": "SELECT", 563 "Original": "select * from primary_redirect", 564 "Instructions": { 565 "OperatorType": "Route", 566 "Variant": "Scatter", 567 "Keyspace": { 568 "Name": "user", 569 "Sharded": true 570 }, 571 "FieldQuery": "select * from `user` as primary_redirect where 1 != 1", 572 "Query": "select * from `user` as primary_redirect", 573 "Table": "`user`" 574 }, 575 "TablesUsed": [ 576 "user.user" 577 ] 578 } 579 }, 580 { 581 "comment": "routing rules bad table", 582 "query": "select * from bad_table", 583 "plan": "VT05003: unknown database 'noks' in vschema" 584 }, 585 { 586 "comment": "routing rules disabled table", 587 "query": "select * from disabled", 588 "plan": "table disabled has been disabled" 589 }, 590 { 591 "comment": "select second_user.foo.col from second_user.foo join user on second_user.foo.id = user.id where second_user.foo.col = 42", 592 "query": "select second_user.foo.col from second_user.foo join user on second_user.foo.id = user.id where second_user.foo.col = 42", 593 "v3-plan": { 594 "QueryType": "SELECT", 595 "Original": "select second_user.foo.col from second_user.foo join user on second_user.foo.id = user.id where second_user.foo.col = 42", 596 "Instructions": { 597 "OperatorType": "Route", 598 "Variant": "Scatter", 599 "Keyspace": { 600 "Name": "user", 601 "Sharded": true 602 }, 603 "FieldQuery": "select foo.col from `user` as foo join `user` on foo.id = `user`.id where 1 != 1", 604 "Query": "select foo.col from `user` as foo join `user` on foo.id = `user`.id where foo.col = 42", 605 "Table": "`user`" 606 } 607 }, 608 "gen4-plan": { 609 "QueryType": "SELECT", 610 "Original": "select second_user.foo.col from second_user.foo join user on second_user.foo.id = user.id where second_user.foo.col = 42", 611 "Instructions": { 612 "OperatorType": "Route", 613 "Variant": "Scatter", 614 "Keyspace": { 615 "Name": "user", 616 "Sharded": true 617 }, 618 "FieldQuery": "select foo.col from `user` as foo, `user` where 1 != 1", 619 "Query": "select foo.col from `user` as foo, `user` where foo.col = 42 and foo.id = `user`.id", 620 "Table": "`user`" 621 }, 622 "TablesUsed": [ 623 "user.user" 624 ] 625 } 626 }, 627 { 628 "comment": "select user.music.foo from user.music join user on user.music.id = user.id where user.music.col = 42", 629 "query": "select user.music.foo from user.music join user on user.music.id = user.id where user.music.col = 42", 630 "v3-plan": { 631 "QueryType": "SELECT", 632 "Original": "select user.music.foo from user.music join user on user.music.id = user.id where user.music.col = 42", 633 "Instructions": { 634 "OperatorType": "Join", 635 "Variant": "Join", 636 "JoinColumnIndexes": "L:0", 637 "JoinVars": { 638 "music_id": 1 639 }, 640 "TableName": "music_`user`", 641 "Inputs": [ 642 { 643 "OperatorType": "Route", 644 "Variant": "Scatter", 645 "Keyspace": { 646 "Name": "user", 647 "Sharded": true 648 }, 649 "FieldQuery": "select music.foo, music.id from music where 1 != 1", 650 "Query": "select music.foo, music.id from music where music.col = 42", 651 "Table": "music" 652 }, 653 { 654 "OperatorType": "Route", 655 "Variant": "EqualUnique", 656 "Keyspace": { 657 "Name": "user", 658 "Sharded": true 659 }, 660 "FieldQuery": "select 1 from `user` where 1 != 1", 661 "Query": "select 1 from `user` where `user`.id = :music_id", 662 "Table": "`user`", 663 "Values": [ 664 ":music_id" 665 ], 666 "Vindex": "user_index" 667 } 668 ] 669 } 670 }, 671 "gen4-plan": { 672 "QueryType": "SELECT", 673 "Original": "select user.music.foo from user.music join user on user.music.id = user.id where user.music.col = 42", 674 "Instructions": { 675 "OperatorType": "Join", 676 "Variant": "Join", 677 "JoinColumnIndexes": "L:1", 678 "JoinVars": { 679 "music_id": 0 680 }, 681 "TableName": "music_`user`", 682 "Inputs": [ 683 { 684 "OperatorType": "Route", 685 "Variant": "Scatter", 686 "Keyspace": { 687 "Name": "user", 688 "Sharded": true 689 }, 690 "FieldQuery": "select music.id, music.foo from music where 1 != 1", 691 "Query": "select music.id, music.foo from music where music.col = 42", 692 "Table": "music" 693 }, 694 { 695 "OperatorType": "Route", 696 "Variant": "EqualUnique", 697 "Keyspace": { 698 "Name": "user", 699 "Sharded": true 700 }, 701 "FieldQuery": "select 1 from `user` where 1 != 1", 702 "Query": "select 1 from `user` where `user`.id = :music_id", 703 "Table": "`user`", 704 "Values": [ 705 ":music_id" 706 ], 707 "Vindex": "user_index" 708 } 709 ] 710 }, 711 "TablesUsed": [ 712 "user.music", 713 "user.user" 714 ] 715 } 716 }, 717 { 718 "comment": "',' join", 719 "query": "select music.col from user, music", 720 "v3-plan": { 721 "QueryType": "SELECT", 722 "Original": "select music.col from user, music", 723 "Instructions": { 724 "OperatorType": "Join", 725 "Variant": "Join", 726 "JoinColumnIndexes": "R:0", 727 "TableName": "`user`_music", 728 "Inputs": [ 729 { 730 "OperatorType": "Route", 731 "Variant": "Scatter", 732 "Keyspace": { 733 "Name": "user", 734 "Sharded": true 735 }, 736 "FieldQuery": "select 1 from `user` where 1 != 1", 737 "Query": "select 1 from `user`", 738 "Table": "`user`" 739 }, 740 { 741 "OperatorType": "Route", 742 "Variant": "Scatter", 743 "Keyspace": { 744 "Name": "user", 745 "Sharded": true 746 }, 747 "FieldQuery": "select music.col from music where 1 != 1", 748 "Query": "select music.col from music", 749 "Table": "music" 750 } 751 ] 752 } 753 }, 754 "gen4-plan": { 755 "QueryType": "SELECT", 756 "Original": "select music.col from user, music", 757 "Instructions": { 758 "OperatorType": "Join", 759 "Variant": "Join", 760 "JoinColumnIndexes": "R:0", 761 "TableName": "`user`_music", 762 "Inputs": [ 763 { 764 "OperatorType": "Route", 765 "Variant": "Scatter", 766 "Keyspace": { 767 "Name": "user", 768 "Sharded": true 769 }, 770 "FieldQuery": "select 1 from `user` where 1 != 1", 771 "Query": "select 1 from `user`", 772 "Table": "`user`" 773 }, 774 { 775 "OperatorType": "Route", 776 "Variant": "Scatter", 777 "Keyspace": { 778 "Name": "user", 779 "Sharded": true 780 }, 781 "FieldQuery": "select music.col from music where 1 != 1", 782 "Query": "select music.col from music", 783 "Table": "music" 784 } 785 ] 786 }, 787 "TablesUsed": [ 788 "user.music", 789 "user.user" 790 ] 791 } 792 }, 793 { 794 "comment": "',' join unsharded", 795 "query": "select u1.a, u2.a from unsharded u1, unsharded u2", 796 "v3-plan": { 797 "QueryType": "SELECT", 798 "Original": "select u1.a, u2.a from unsharded u1, unsharded u2", 799 "Instructions": { 800 "OperatorType": "Route", 801 "Variant": "Unsharded", 802 "Keyspace": { 803 "Name": "main", 804 "Sharded": false 805 }, 806 "FieldQuery": "select u1.a, u2.a from unsharded as u1, unsharded as u2 where 1 != 1", 807 "Query": "select u1.a, u2.a from unsharded as u1, unsharded as u2", 808 "Table": "unsharded" 809 } 810 }, 811 "gen4-plan": { 812 "QueryType": "SELECT", 813 "Original": "select u1.a, u2.a from unsharded u1, unsharded u2", 814 "Instructions": { 815 "OperatorType": "Route", 816 "Variant": "Unsharded", 817 "Keyspace": { 818 "Name": "main", 819 "Sharded": false 820 }, 821 "FieldQuery": "select u1.a, u2.a from unsharded as u1, unsharded as u2 where 1 != 1", 822 "Query": "select u1.a, u2.a from unsharded as u1, unsharded as u2", 823 "Table": "unsharded" 824 }, 825 "TablesUsed": [ 826 "main.unsharded" 827 ] 828 } 829 }, 830 { 831 "comment": "',' 3-way join unsharded", 832 "query": "select u1.a, u2.a from unsharded u1, unsharded u2, unsharded u3", 833 "v3-plan": { 834 "QueryType": "SELECT", 835 "Original": "select u1.a, u2.a from unsharded u1, unsharded u2, unsharded u3", 836 "Instructions": { 837 "OperatorType": "Route", 838 "Variant": "Unsharded", 839 "Keyspace": { 840 "Name": "main", 841 "Sharded": false 842 }, 843 "FieldQuery": "select u1.a, u2.a from unsharded as u1, unsharded as u2, unsharded as u3 where 1 != 1", 844 "Query": "select u1.a, u2.a from unsharded as u1, unsharded as u2, unsharded as u3", 845 "Table": "unsharded" 846 } 847 }, 848 "gen4-plan": { 849 "QueryType": "SELECT", 850 "Original": "select u1.a, u2.a from unsharded u1, unsharded u2, unsharded u3", 851 "Instructions": { 852 "OperatorType": "Route", 853 "Variant": "Unsharded", 854 "Keyspace": { 855 "Name": "main", 856 "Sharded": false 857 }, 858 "FieldQuery": "select u1.a, u2.a from unsharded as u1, unsharded as u2, unsharded as u3 where 1 != 1", 859 "Query": "select u1.a, u2.a from unsharded as u1, unsharded as u2, unsharded as u3", 860 "Table": "unsharded" 861 }, 862 "TablesUsed": [ 863 "main.unsharded" 864 ] 865 } 866 }, 867 { 868 "comment": "Left join, single chunk", 869 "query": "select m1.col from unsharded as m1 left join unsharded as m2 on m1.a=m2.b", 870 "plan": { 871 "QueryType": "SELECT", 872 "Original": "select m1.col from unsharded as m1 left join unsharded as m2 on m1.a=m2.b", 873 "Instructions": { 874 "OperatorType": "Route", 875 "Variant": "Unsharded", 876 "Keyspace": { 877 "Name": "main", 878 "Sharded": false 879 }, 880 "FieldQuery": "select m1.col from unsharded as m1 left join unsharded as m2 on m1.a = m2.b where 1 != 1", 881 "Query": "select m1.col from unsharded as m1 left join unsharded as m2 on m1.a = m2.b", 882 "Table": "unsharded" 883 }, 884 "TablesUsed": [ 885 "main.unsharded" 886 ] 887 } 888 }, 889 { 890 "comment": "Left join, multi-chunk", 891 "query": "select u.col from user u left join unsharded m on u.a = m.b", 892 "plan": { 893 "QueryType": "SELECT", 894 "Original": "select u.col from user u left join unsharded m on u.a = m.b", 895 "Instructions": { 896 "OperatorType": "Join", 897 "Variant": "LeftJoin", 898 "JoinColumnIndexes": "L:1", 899 "JoinVars": { 900 "u_a": 0 901 }, 902 "TableName": "`user`_unsharded", 903 "Inputs": [ 904 { 905 "OperatorType": "Route", 906 "Variant": "Scatter", 907 "Keyspace": { 908 "Name": "user", 909 "Sharded": true 910 }, 911 "FieldQuery": "select u.a, u.col from `user` as u where 1 != 1", 912 "Query": "select u.a, u.col from `user` as u", 913 "Table": "`user`" 914 }, 915 { 916 "OperatorType": "Route", 917 "Variant": "Unsharded", 918 "Keyspace": { 919 "Name": "main", 920 "Sharded": false 921 }, 922 "FieldQuery": "select 1 from unsharded as m where 1 != 1", 923 "Query": "select 1 from unsharded as m where m.b = :u_a", 924 "Table": "unsharded" 925 } 926 ] 927 }, 928 "TablesUsed": [ 929 "main.unsharded", 930 "user.user" 931 ] 932 } 933 }, 934 { 935 "comment": "Three-way left join", 936 "query": "select user.col, m2.foo from user left join unsharded as m1 on user.col = m1.col left join unsharded as m2 on m1.col = m2.col", 937 "plan": { 938 "QueryType": "SELECT", 939 "Original": "select user.col, m2.foo from user left join unsharded as m1 on user.col = m1.col left join unsharded as m2 on m1.col = m2.col", 940 "Instructions": { 941 "OperatorType": "Join", 942 "Variant": "LeftJoin", 943 "JoinColumnIndexes": "L:1,R:0", 944 "JoinVars": { 945 "m1_col": 0 946 }, 947 "TableName": "`user`_unsharded_unsharded", 948 "Inputs": [ 949 { 950 "OperatorType": "Join", 951 "Variant": "LeftJoin", 952 "JoinColumnIndexes": "R:0,L:0", 953 "JoinVars": { 954 "user_col": 0 955 }, 956 "TableName": "`user`_unsharded", 957 "Inputs": [ 958 { 959 "OperatorType": "Route", 960 "Variant": "Scatter", 961 "Keyspace": { 962 "Name": "user", 963 "Sharded": true 964 }, 965 "FieldQuery": "select `user`.col from `user` where 1 != 1", 966 "Query": "select `user`.col from `user`", 967 "Table": "`user`" 968 }, 969 { 970 "OperatorType": "Route", 971 "Variant": "Unsharded", 972 "Keyspace": { 973 "Name": "main", 974 "Sharded": false 975 }, 976 "FieldQuery": "select m1.col from unsharded as m1 where 1 != 1", 977 "Query": "select m1.col from unsharded as m1 where m1.col = :user_col", 978 "Table": "unsharded" 979 } 980 ] 981 }, 982 { 983 "OperatorType": "Route", 984 "Variant": "Unsharded", 985 "Keyspace": { 986 "Name": "main", 987 "Sharded": false 988 }, 989 "FieldQuery": "select m2.foo from unsharded as m2 where 1 != 1", 990 "Query": "select m2.foo from unsharded as m2 where m2.col = :m1_col", 991 "Table": "unsharded" 992 } 993 ] 994 }, 995 "TablesUsed": [ 996 "main.unsharded", 997 "user.user" 998 ] 999 } 1000 }, 1001 { 1002 "comment": "Three-way left join, right-associated", 1003 "query": "select user.col from user left join user_extra as e left join unsharded as m1 on m1.col = e.col on user.col = e.col", 1004 "plan": { 1005 "QueryType": "SELECT", 1006 "Original": "select user.col from user left join user_extra as e left join unsharded as m1 on m1.col = e.col on user.col = e.col", 1007 "Instructions": { 1008 "OperatorType": "Join", 1009 "Variant": "LeftJoin", 1010 "JoinColumnIndexes": "L:0", 1011 "JoinVars": { 1012 "user_col": 0 1013 }, 1014 "TableName": "`user`_user_extra_unsharded", 1015 "Inputs": [ 1016 { 1017 "OperatorType": "Route", 1018 "Variant": "Scatter", 1019 "Keyspace": { 1020 "Name": "user", 1021 "Sharded": true 1022 }, 1023 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1024 "Query": "select `user`.col from `user`", 1025 "Table": "`user`" 1026 }, 1027 { 1028 "OperatorType": "Join", 1029 "Variant": "LeftJoin", 1030 "JoinVars": { 1031 "e_col": 0 1032 }, 1033 "TableName": "user_extra_unsharded", 1034 "Inputs": [ 1035 { 1036 "OperatorType": "Route", 1037 "Variant": "Scatter", 1038 "Keyspace": { 1039 "Name": "user", 1040 "Sharded": true 1041 }, 1042 "FieldQuery": "select e.col from user_extra as e where 1 != 1", 1043 "Query": "select e.col from user_extra as e where e.col = :user_col", 1044 "Table": "user_extra" 1045 }, 1046 { 1047 "OperatorType": "Route", 1048 "Variant": "Unsharded", 1049 "Keyspace": { 1050 "Name": "main", 1051 "Sharded": false 1052 }, 1053 "FieldQuery": "select 1 from unsharded as m1 where 1 != 1", 1054 "Query": "select 1 from unsharded as m1 where m1.col = :e_col", 1055 "Table": "unsharded" 1056 } 1057 ] 1058 } 1059 ] 1060 }, 1061 "TablesUsed": [ 1062 "main.unsharded", 1063 "user.user", 1064 "user.user_extra" 1065 ] 1066 } 1067 }, 1068 { 1069 "comment": "Right join", 1070 "query": "select m1.col from unsharded as m1 right join unsharded as m2 on m1.a=m2.b", 1071 "plan": { 1072 "QueryType": "SELECT", 1073 "Original": "select m1.col from unsharded as m1 right join unsharded as m2 on m1.a=m2.b", 1074 "Instructions": { 1075 "OperatorType": "Route", 1076 "Variant": "Unsharded", 1077 "Keyspace": { 1078 "Name": "main", 1079 "Sharded": false 1080 }, 1081 "FieldQuery": "select m1.col from unsharded as m1 right join unsharded as m2 on m1.a = m2.b where 1 != 1", 1082 "Query": "select m1.col from unsharded as m1 right join unsharded as m2 on m1.a = m2.b", 1083 "Table": "unsharded" 1084 }, 1085 "TablesUsed": [ 1086 "main.unsharded" 1087 ] 1088 } 1089 }, 1090 { 1091 "comment": "Right join with a join LHS", 1092 "query": "select m1.col from unsharded as m1 join unsharded as m2 right join unsharded as m3 on m1.a=m2.b", 1093 "plan": { 1094 "QueryType": "SELECT", 1095 "Original": "select m1.col from unsharded as m1 join unsharded as m2 right join unsharded as m3 on m1.a=m2.b", 1096 "Instructions": { 1097 "OperatorType": "Route", 1098 "Variant": "Unsharded", 1099 "Keyspace": { 1100 "Name": "main", 1101 "Sharded": false 1102 }, 1103 "FieldQuery": "select m1.col from unsharded as m1 join unsharded as m2 right join unsharded as m3 on m1.a = m2.b where 1 != 1", 1104 "Query": "select m1.col from unsharded as m1 join unsharded as m2 right join unsharded as m3 on m1.a = m2.b", 1105 "Table": "unsharded" 1106 }, 1107 "TablesUsed": [ 1108 "main.unsharded" 1109 ] 1110 } 1111 }, 1112 { 1113 "comment": "Straight-join (Gen4 ignores the straight_join hint)", 1114 "query": "select m1.col from unsharded as m1 straight_join unsharded as m2", 1115 "v3-plan": { 1116 "QueryType": "SELECT", 1117 "Original": "select m1.col from unsharded as m1 straight_join unsharded as m2", 1118 "Instructions": { 1119 "OperatorType": "Route", 1120 "Variant": "Unsharded", 1121 "Keyspace": { 1122 "Name": "main", 1123 "Sharded": false 1124 }, 1125 "FieldQuery": "select m1.col from unsharded as m1 straight_join unsharded as m2 where 1 != 1", 1126 "Query": "select m1.col from unsharded as m1 straight_join unsharded as m2", 1127 "Table": "unsharded" 1128 } 1129 }, 1130 "gen4-plan": { 1131 "QueryType": "SELECT", 1132 "Original": "select m1.col from unsharded as m1 straight_join unsharded as m2", 1133 "Instructions": { 1134 "OperatorType": "Route", 1135 "Variant": "Unsharded", 1136 "Keyspace": { 1137 "Name": "main", 1138 "Sharded": false 1139 }, 1140 "FieldQuery": "select m1.col from unsharded as m1 join unsharded as m2 where 1 != 1", 1141 "Query": "select m1.col from unsharded as m1 join unsharded as m2", 1142 "Table": "unsharded" 1143 }, 1144 "TablesUsed": [ 1145 "main.unsharded" 1146 ] 1147 } 1148 }, 1149 { 1150 "comment": "Three-way join", 1151 "query": "select user.col from user join unsharded as m1 join unsharded as m2", 1152 "v3-plan": { 1153 "QueryType": "SELECT", 1154 "Original": "select user.col from user join unsharded as m1 join unsharded as m2", 1155 "Instructions": { 1156 "OperatorType": "Join", 1157 "Variant": "Join", 1158 "JoinColumnIndexes": "L:0", 1159 "TableName": "`user`_unsharded_unsharded", 1160 "Inputs": [ 1161 { 1162 "OperatorType": "Join", 1163 "Variant": "Join", 1164 "JoinColumnIndexes": "L:0", 1165 "TableName": "`user`_unsharded", 1166 "Inputs": [ 1167 { 1168 "OperatorType": "Route", 1169 "Variant": "Scatter", 1170 "Keyspace": { 1171 "Name": "user", 1172 "Sharded": true 1173 }, 1174 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1175 "Query": "select `user`.col from `user`", 1176 "Table": "`user`" 1177 }, 1178 { 1179 "OperatorType": "Route", 1180 "Variant": "Unsharded", 1181 "Keyspace": { 1182 "Name": "main", 1183 "Sharded": false 1184 }, 1185 "FieldQuery": "select 1 from unsharded as m1 where 1 != 1", 1186 "Query": "select 1 from unsharded as m1", 1187 "Table": "unsharded" 1188 } 1189 ] 1190 }, 1191 { 1192 "OperatorType": "Route", 1193 "Variant": "Unsharded", 1194 "Keyspace": { 1195 "Name": "main", 1196 "Sharded": false 1197 }, 1198 "FieldQuery": "select 1 from unsharded as m2 where 1 != 1", 1199 "Query": "select 1 from unsharded as m2", 1200 "Table": "unsharded" 1201 } 1202 ] 1203 } 1204 }, 1205 "gen4-plan": { 1206 "QueryType": "SELECT", 1207 "Original": "select user.col from user join unsharded as m1 join unsharded as m2", 1208 "Instructions": { 1209 "OperatorType": "Join", 1210 "Variant": "Join", 1211 "JoinColumnIndexes": "L:0", 1212 "TableName": "`user`_unsharded", 1213 "Inputs": [ 1214 { 1215 "OperatorType": "Route", 1216 "Variant": "Scatter", 1217 "Keyspace": { 1218 "Name": "user", 1219 "Sharded": true 1220 }, 1221 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1222 "Query": "select `user`.col from `user`", 1223 "Table": "`user`" 1224 }, 1225 { 1226 "OperatorType": "Route", 1227 "Variant": "Unsharded", 1228 "Keyspace": { 1229 "Name": "main", 1230 "Sharded": false 1231 }, 1232 "FieldQuery": "select 1 from unsharded as m1, unsharded as m2 where 1 != 1", 1233 "Query": "select 1 from unsharded as m1, unsharded as m2", 1234 "Table": "unsharded" 1235 } 1236 ] 1237 }, 1238 "TablesUsed": [ 1239 "main.unsharded", 1240 "user.user" 1241 ] 1242 } 1243 }, 1244 { 1245 "comment": "Parenthesized, single chunk", 1246 "query": "select user.col from user join (unsharded as m1 join unsharded as m2)", 1247 "v3-plan": { 1248 "QueryType": "SELECT", 1249 "Original": "select user.col from user join (unsharded as m1 join unsharded as m2)", 1250 "Instructions": { 1251 "OperatorType": "Join", 1252 "Variant": "Join", 1253 "JoinColumnIndexes": "L:0", 1254 "TableName": "`user`_unsharded", 1255 "Inputs": [ 1256 { 1257 "OperatorType": "Route", 1258 "Variant": "Scatter", 1259 "Keyspace": { 1260 "Name": "user", 1261 "Sharded": true 1262 }, 1263 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1264 "Query": "select `user`.col from `user`", 1265 "Table": "`user`" 1266 }, 1267 { 1268 "OperatorType": "Route", 1269 "Variant": "Unsharded", 1270 "Keyspace": { 1271 "Name": "main", 1272 "Sharded": false 1273 }, 1274 "FieldQuery": "select 1 from (unsharded as m1 join unsharded as m2) where 1 != 1", 1275 "Query": "select 1 from (unsharded as m1 join unsharded as m2)", 1276 "Table": "unsharded" 1277 } 1278 ] 1279 } 1280 }, 1281 "gen4-plan": { 1282 "QueryType": "SELECT", 1283 "Original": "select user.col from user join (unsharded as m1 join unsharded as m2)", 1284 "Instructions": { 1285 "OperatorType": "Join", 1286 "Variant": "Join", 1287 "JoinColumnIndexes": "L:0", 1288 "TableName": "`user`_unsharded", 1289 "Inputs": [ 1290 { 1291 "OperatorType": "Route", 1292 "Variant": "Scatter", 1293 "Keyspace": { 1294 "Name": "user", 1295 "Sharded": true 1296 }, 1297 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1298 "Query": "select `user`.col from `user`", 1299 "Table": "`user`" 1300 }, 1301 { 1302 "OperatorType": "Route", 1303 "Variant": "Unsharded", 1304 "Keyspace": { 1305 "Name": "main", 1306 "Sharded": false 1307 }, 1308 "FieldQuery": "select 1 from unsharded as m1, unsharded as m2 where 1 != 1", 1309 "Query": "select 1 from unsharded as m1, unsharded as m2", 1310 "Table": "unsharded" 1311 } 1312 ] 1313 }, 1314 "TablesUsed": [ 1315 "main.unsharded", 1316 "user.user" 1317 ] 1318 } 1319 }, 1320 { 1321 "comment": "Parenthesized, multi-chunk", 1322 "query": "select user.col from user join (user as u1 join unsharded)", 1323 "v3-plan": { 1324 "QueryType": "SELECT", 1325 "Original": "select user.col from user join (user as u1 join unsharded)", 1326 "Instructions": { 1327 "OperatorType": "Join", 1328 "Variant": "Join", 1329 "JoinColumnIndexes": "L:0", 1330 "TableName": "`user`_`user`_unsharded", 1331 "Inputs": [ 1332 { 1333 "OperatorType": "Route", 1334 "Variant": "Scatter", 1335 "Keyspace": { 1336 "Name": "user", 1337 "Sharded": true 1338 }, 1339 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1340 "Query": "select `user`.col from `user`", 1341 "Table": "`user`" 1342 }, 1343 { 1344 "OperatorType": "Join", 1345 "Variant": "Join", 1346 "TableName": "`user`_unsharded", 1347 "Inputs": [ 1348 { 1349 "OperatorType": "Route", 1350 "Variant": "Scatter", 1351 "Keyspace": { 1352 "Name": "user", 1353 "Sharded": true 1354 }, 1355 "FieldQuery": "select 1 from `user` as u1 where 1 != 1", 1356 "Query": "select 1 from `user` as u1", 1357 "Table": "`user`" 1358 }, 1359 { 1360 "OperatorType": "Route", 1361 "Variant": "Unsharded", 1362 "Keyspace": { 1363 "Name": "main", 1364 "Sharded": false 1365 }, 1366 "FieldQuery": "select 1 from unsharded where 1 != 1", 1367 "Query": "select 1 from unsharded", 1368 "Table": "unsharded" 1369 } 1370 ] 1371 } 1372 ] 1373 } 1374 }, 1375 "gen4-plan": { 1376 "QueryType": "SELECT", 1377 "Original": "select user.col from user join (user as u1 join unsharded)", 1378 "Instructions": { 1379 "OperatorType": "Join", 1380 "Variant": "Join", 1381 "JoinColumnIndexes": "R:0", 1382 "TableName": "`user`_`user`_unsharded", 1383 "Inputs": [ 1384 { 1385 "OperatorType": "Route", 1386 "Variant": "Scatter", 1387 "Keyspace": { 1388 "Name": "user", 1389 "Sharded": true 1390 }, 1391 "FieldQuery": "select 1 from `user` as u1 where 1 != 1", 1392 "Query": "select 1 from `user` as u1", 1393 "Table": "`user`" 1394 }, 1395 { 1396 "OperatorType": "Join", 1397 "Variant": "Join", 1398 "JoinColumnIndexes": "L:0", 1399 "TableName": "`user`_unsharded", 1400 "Inputs": [ 1401 { 1402 "OperatorType": "Route", 1403 "Variant": "Scatter", 1404 "Keyspace": { 1405 "Name": "user", 1406 "Sharded": true 1407 }, 1408 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1409 "Query": "select `user`.col from `user`", 1410 "Table": "`user`" 1411 }, 1412 { 1413 "OperatorType": "Route", 1414 "Variant": "Unsharded", 1415 "Keyspace": { 1416 "Name": "main", 1417 "Sharded": false 1418 }, 1419 "FieldQuery": "select 1 from unsharded where 1 != 1", 1420 "Query": "select 1 from unsharded", 1421 "Table": "unsharded" 1422 } 1423 ] 1424 } 1425 ] 1426 }, 1427 "TablesUsed": [ 1428 "main.unsharded", 1429 "user.user" 1430 ] 1431 } 1432 }, 1433 { 1434 "comment": "index hints, make sure they are not stripped.", 1435 "query": "select user.col from user use index(a)", 1436 "v3-plan": { 1437 "QueryType": "SELECT", 1438 "Original": "select user.col from user use index(a)", 1439 "Instructions": { 1440 "OperatorType": "Route", 1441 "Variant": "Scatter", 1442 "Keyspace": { 1443 "Name": "user", 1444 "Sharded": true 1445 }, 1446 "FieldQuery": "select `user`.col from `user` use index (a) where 1 != 1", 1447 "Query": "select `user`.col from `user` use index (a)", 1448 "Table": "`user`" 1449 } 1450 }, 1451 "gen4-plan": { 1452 "QueryType": "SELECT", 1453 "Original": "select user.col from user use index(a)", 1454 "Instructions": { 1455 "OperatorType": "Route", 1456 "Variant": "Scatter", 1457 "Keyspace": { 1458 "Name": "user", 1459 "Sharded": true 1460 }, 1461 "FieldQuery": "select `user`.col from `user` use index (a) where 1 != 1", 1462 "Query": "select `user`.col from `user` use index (a)", 1463 "Table": "`user`" 1464 }, 1465 "TablesUsed": [ 1466 "user.user" 1467 ] 1468 } 1469 }, 1470 { 1471 "comment": "multiple index hints, make sure they are not stripped.", 1472 "query": "select user.col from user use index(a) use index for group by (b)", 1473 "v3-plan": { 1474 "QueryType": "SELECT", 1475 "Original": "select user.col from user use index(a) use index for group by (b)", 1476 "Instructions": { 1477 "OperatorType": "Route", 1478 "Variant": "Scatter", 1479 "Keyspace": { 1480 "Name": "user", 1481 "Sharded": true 1482 }, 1483 "FieldQuery": "select `user`.col from `user` use index (a) use index for group by (b) where 1 != 1", 1484 "Query": "select `user`.col from `user` use index (a) use index for group by (b)", 1485 "Table": "`user`" 1486 } 1487 }, 1488 "gen4-plan": { 1489 "QueryType": "SELECT", 1490 "Original": "select user.col from user use index(a) use index for group by (b)", 1491 "Instructions": { 1492 "OperatorType": "Route", 1493 "Variant": "Scatter", 1494 "Keyspace": { 1495 "Name": "user", 1496 "Sharded": true 1497 }, 1498 "FieldQuery": "select `user`.col from `user` use index (a) use index for group by (b) where 1 != 1", 1499 "Query": "select `user`.col from `user` use index (a) use index for group by (b)", 1500 "Table": "`user`" 1501 }, 1502 "TablesUsed": [ 1503 "user.user" 1504 ] 1505 } 1506 }, 1507 { 1508 "comment": "mergeable sharded join on unique vindex", 1509 "query": "select user.col from user join user_extra on user.id = user_extra.user_id", 1510 "v3-plan": { 1511 "QueryType": "SELECT", 1512 "Original": "select user.col from user join user_extra on user.id = user_extra.user_id", 1513 "Instructions": { 1514 "OperatorType": "Route", 1515 "Variant": "Scatter", 1516 "Keyspace": { 1517 "Name": "user", 1518 "Sharded": true 1519 }, 1520 "FieldQuery": "select `user`.col from `user` join user_extra on `user`.id = user_extra.user_id where 1 != 1", 1521 "Query": "select `user`.col from `user` join user_extra on `user`.id = user_extra.user_id", 1522 "Table": "`user`, user_extra" 1523 } 1524 }, 1525 "gen4-plan": { 1526 "QueryType": "SELECT", 1527 "Original": "select user.col from user join user_extra on user.id = user_extra.user_id", 1528 "Instructions": { 1529 "OperatorType": "Route", 1530 "Variant": "Scatter", 1531 "Keyspace": { 1532 "Name": "user", 1533 "Sharded": true 1534 }, 1535 "FieldQuery": "select `user`.col from `user`, user_extra where 1 != 1", 1536 "Query": "select `user`.col from `user`, user_extra where `user`.id = user_extra.user_id", 1537 "Table": "`user`, user_extra" 1538 }, 1539 "TablesUsed": [ 1540 "user.user", 1541 "user.user_extra" 1542 ] 1543 } 1544 }, 1545 { 1546 "comment": "mergeable sharded join on unique vindex (parenthesized ON clause)", 1547 "query": "select user.col from user join user_extra on (user.id = user_extra.user_id)", 1548 "v3-plan": { 1549 "QueryType": "SELECT", 1550 "Original": "select user.col from user join user_extra on (user.id = user_extra.user_id)", 1551 "Instructions": { 1552 "OperatorType": "Route", 1553 "Variant": "Scatter", 1554 "Keyspace": { 1555 "Name": "user", 1556 "Sharded": true 1557 }, 1558 "FieldQuery": "select `user`.col from `user` join user_extra on `user`.id = user_extra.user_id where 1 != 1", 1559 "Query": "select `user`.col from `user` join user_extra on `user`.id = user_extra.user_id", 1560 "Table": "`user`, user_extra" 1561 } 1562 }, 1563 "gen4-plan": { 1564 "QueryType": "SELECT", 1565 "Original": "select user.col from user join user_extra on (user.id = user_extra.user_id)", 1566 "Instructions": { 1567 "OperatorType": "Route", 1568 "Variant": "Scatter", 1569 "Keyspace": { 1570 "Name": "user", 1571 "Sharded": true 1572 }, 1573 "FieldQuery": "select `user`.col from `user`, user_extra where 1 != 1", 1574 "Query": "select `user`.col from `user`, user_extra where `user`.id = user_extra.user_id", 1575 "Table": "`user`, user_extra" 1576 }, 1577 "TablesUsed": [ 1578 "user.user", 1579 "user.user_extra" 1580 ] 1581 } 1582 }, 1583 { 1584 "comment": "mergeable sharded join on unique vindex, with a stray condition", 1585 "query": "select user.col from user join user_extra on user.col between 1 and 2 and user.id = user_extra.user_id", 1586 "v3-plan": { 1587 "QueryType": "SELECT", 1588 "Original": "select user.col from user join user_extra on user.col between 1 and 2 and user.id = user_extra.user_id", 1589 "Instructions": { 1590 "OperatorType": "Route", 1591 "Variant": "Scatter", 1592 "Keyspace": { 1593 "Name": "user", 1594 "Sharded": true 1595 }, 1596 "FieldQuery": "select `user`.col from `user` join user_extra on `user`.col between 1 and 2 and `user`.id = user_extra.user_id where 1 != 1", 1597 "Query": "select `user`.col from `user` join user_extra on `user`.col between 1 and 2 and `user`.id = user_extra.user_id", 1598 "Table": "`user`, user_extra" 1599 } 1600 }, 1601 "gen4-plan": { 1602 "QueryType": "SELECT", 1603 "Original": "select user.col from user join user_extra on user.col between 1 and 2 and user.id = user_extra.user_id", 1604 "Instructions": { 1605 "OperatorType": "Route", 1606 "Variant": "Scatter", 1607 "Keyspace": { 1608 "Name": "user", 1609 "Sharded": true 1610 }, 1611 "FieldQuery": "select `user`.col from `user`, user_extra where 1 != 1", 1612 "Query": "select `user`.col from `user`, user_extra where `user`.col between 1 and 2 and `user`.id = user_extra.user_id", 1613 "Table": "`user`, user_extra" 1614 }, 1615 "TablesUsed": [ 1616 "user.user", 1617 "user.user_extra" 1618 ] 1619 } 1620 }, 1621 { 1622 "comment": "mergeable sharded join on unique vindex, swapped operands", 1623 "query": "select user.col from user join user_extra on user_extra.user_id = user.id", 1624 "v3-plan": { 1625 "QueryType": "SELECT", 1626 "Original": "select user.col from user join user_extra on user_extra.user_id = user.id", 1627 "Instructions": { 1628 "OperatorType": "Route", 1629 "Variant": "Scatter", 1630 "Keyspace": { 1631 "Name": "user", 1632 "Sharded": true 1633 }, 1634 "FieldQuery": "select `user`.col from `user` join user_extra on user_extra.user_id = `user`.id where 1 != 1", 1635 "Query": "select `user`.col from `user` join user_extra on user_extra.user_id = `user`.id", 1636 "Table": "`user`, user_extra" 1637 } 1638 }, 1639 "gen4-plan": { 1640 "QueryType": "SELECT", 1641 "Original": "select user.col from user join user_extra on user_extra.user_id = user.id", 1642 "Instructions": { 1643 "OperatorType": "Route", 1644 "Variant": "Scatter", 1645 "Keyspace": { 1646 "Name": "user", 1647 "Sharded": true 1648 }, 1649 "FieldQuery": "select `user`.col from `user`, user_extra where 1 != 1", 1650 "Query": "select `user`.col from `user`, user_extra where user_extra.user_id = `user`.id", 1651 "Table": "`user`, user_extra" 1652 }, 1653 "TablesUsed": [ 1654 "user.user", 1655 "user.user_extra" 1656 ] 1657 } 1658 }, 1659 { 1660 "comment": "mergeable sharded join on unique vindex, and condition", 1661 "query": "select user.col from user join user_extra on user.id = 5 and user.id = user_extra.user_id", 1662 "v3-plan": { 1663 "QueryType": "SELECT", 1664 "Original": "select user.col from user join user_extra on user.id = 5 and user.id = user_extra.user_id", 1665 "Instructions": { 1666 "OperatorType": "Route", 1667 "Variant": "EqualUnique", 1668 "Keyspace": { 1669 "Name": "user", 1670 "Sharded": true 1671 }, 1672 "FieldQuery": "select `user`.col from `user` join user_extra on `user`.id = 5 and `user`.id = user_extra.user_id where 1 != 1", 1673 "Query": "select `user`.col from `user` join user_extra on `user`.id = 5 and `user`.id = user_extra.user_id", 1674 "Table": "`user`, user_extra", 1675 "Values": [ 1676 "INT64(5)" 1677 ], 1678 "Vindex": "user_index" 1679 } 1680 }, 1681 "gen4-plan": { 1682 "QueryType": "SELECT", 1683 "Original": "select user.col from user join user_extra on user.id = 5 and user.id = user_extra.user_id", 1684 "Instructions": { 1685 "OperatorType": "Route", 1686 "Variant": "EqualUnique", 1687 "Keyspace": { 1688 "Name": "user", 1689 "Sharded": true 1690 }, 1691 "FieldQuery": "select `user`.col from `user`, user_extra where 1 != 1", 1692 "Query": "select `user`.col from `user`, user_extra where `user`.id = 5 and `user`.id = user_extra.user_id", 1693 "Table": "`user`, user_extra", 1694 "Values": [ 1695 "INT64(5)" 1696 ], 1697 "Vindex": "user_index" 1698 }, 1699 "TablesUsed": [ 1700 "user.user", 1701 "user.user_extra" 1702 ] 1703 } 1704 }, 1705 { 1706 "comment": "sharded join on unique vindex, inequality", 1707 "query": "select user.col from user join user_extra on user.id < user_extra.user_id", 1708 "v3-plan": { 1709 "QueryType": "SELECT", 1710 "Original": "select user.col from user join user_extra on user.id < user_extra.user_id", 1711 "Instructions": { 1712 "OperatorType": "Join", 1713 "Variant": "Join", 1714 "JoinColumnIndexes": "L:0", 1715 "JoinVars": { 1716 "user_id": 1 1717 }, 1718 "TableName": "`user`_user_extra", 1719 "Inputs": [ 1720 { 1721 "OperatorType": "Route", 1722 "Variant": "Scatter", 1723 "Keyspace": { 1724 "Name": "user", 1725 "Sharded": true 1726 }, 1727 "FieldQuery": "select `user`.col, `user`.id from `user` where 1 != 1", 1728 "Query": "select `user`.col, `user`.id from `user`", 1729 "Table": "`user`" 1730 }, 1731 { 1732 "OperatorType": "Route", 1733 "Variant": "Scatter", 1734 "Keyspace": { 1735 "Name": "user", 1736 "Sharded": true 1737 }, 1738 "FieldQuery": "select 1 from user_extra where 1 != 1", 1739 "Query": "select 1 from user_extra where :user_id < user_extra.user_id", 1740 "Table": "user_extra" 1741 } 1742 ] 1743 } 1744 }, 1745 "gen4-plan": { 1746 "QueryType": "SELECT", 1747 "Original": "select user.col from user join user_extra on user.id < user_extra.user_id", 1748 "Instructions": { 1749 "OperatorType": "Join", 1750 "Variant": "Join", 1751 "JoinColumnIndexes": "L:1", 1752 "JoinVars": { 1753 "user_id": 0 1754 }, 1755 "TableName": "`user`_user_extra", 1756 "Inputs": [ 1757 { 1758 "OperatorType": "Route", 1759 "Variant": "Scatter", 1760 "Keyspace": { 1761 "Name": "user", 1762 "Sharded": true 1763 }, 1764 "FieldQuery": "select `user`.id, `user`.col from `user` where 1 != 1", 1765 "Query": "select `user`.id, `user`.col from `user`", 1766 "Table": "`user`" 1767 }, 1768 { 1769 "OperatorType": "Route", 1770 "Variant": "Scatter", 1771 "Keyspace": { 1772 "Name": "user", 1773 "Sharded": true 1774 }, 1775 "FieldQuery": "select 1 from user_extra where 1 != 1", 1776 "Query": "select 1 from user_extra where :user_id < user_extra.user_id", 1777 "Table": "user_extra" 1778 } 1779 ] 1780 }, 1781 "TablesUsed": [ 1782 "user.user", 1783 "user.user_extra" 1784 ] 1785 } 1786 }, 1787 { 1788 "comment": "sharded join, non-col reference RHS", 1789 "query": "select user.col from user join user_extra on user.id = 5", 1790 "v3-plan": { 1791 "QueryType": "SELECT", 1792 "Original": "select user.col from user join user_extra on user.id = 5", 1793 "Instructions": { 1794 "OperatorType": "Join", 1795 "Variant": "Join", 1796 "JoinColumnIndexes": "L:0", 1797 "TableName": "`user`_user_extra", 1798 "Inputs": [ 1799 { 1800 "OperatorType": "Route", 1801 "Variant": "EqualUnique", 1802 "Keyspace": { 1803 "Name": "user", 1804 "Sharded": true 1805 }, 1806 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1807 "Query": "select `user`.col from `user` where `user`.id = 5", 1808 "Table": "`user`", 1809 "Values": [ 1810 "INT64(5)" 1811 ], 1812 "Vindex": "user_index" 1813 }, 1814 { 1815 "OperatorType": "Route", 1816 "Variant": "Scatter", 1817 "Keyspace": { 1818 "Name": "user", 1819 "Sharded": true 1820 }, 1821 "FieldQuery": "select 1 from user_extra where 1 != 1", 1822 "Query": "select 1 from user_extra", 1823 "Table": "user_extra" 1824 } 1825 ] 1826 } 1827 }, 1828 "gen4-plan": { 1829 "QueryType": "SELECT", 1830 "Original": "select user.col from user join user_extra on user.id = 5", 1831 "Instructions": { 1832 "OperatorType": "Join", 1833 "Variant": "Join", 1834 "JoinColumnIndexes": "L:0", 1835 "TableName": "`user`_user_extra", 1836 "Inputs": [ 1837 { 1838 "OperatorType": "Route", 1839 "Variant": "EqualUnique", 1840 "Keyspace": { 1841 "Name": "user", 1842 "Sharded": true 1843 }, 1844 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1845 "Query": "select `user`.col from `user` where `user`.id = 5", 1846 "Table": "`user`", 1847 "Values": [ 1848 "INT64(5)" 1849 ], 1850 "Vindex": "user_index" 1851 }, 1852 { 1853 "OperatorType": "Route", 1854 "Variant": "Scatter", 1855 "Keyspace": { 1856 "Name": "user", 1857 "Sharded": true 1858 }, 1859 "FieldQuery": "select 1 from user_extra where 1 != 1", 1860 "Query": "select 1 from user_extra", 1861 "Table": "user_extra" 1862 } 1863 ] 1864 }, 1865 "TablesUsed": [ 1866 "user.user", 1867 "user.user_extra" 1868 ] 1869 } 1870 }, 1871 { 1872 "comment": "sharded join, non-col reference LHS", 1873 "query": "select user.col from user join user_extra on 5 = user.id", 1874 "v3-plan": { 1875 "QueryType": "SELECT", 1876 "Original": "select user.col from user join user_extra on 5 = user.id", 1877 "Instructions": { 1878 "OperatorType": "Join", 1879 "Variant": "Join", 1880 "JoinColumnIndexes": "L:0", 1881 "TableName": "`user`_user_extra", 1882 "Inputs": [ 1883 { 1884 "OperatorType": "Route", 1885 "Variant": "EqualUnique", 1886 "Keyspace": { 1887 "Name": "user", 1888 "Sharded": true 1889 }, 1890 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1891 "Query": "select `user`.col from `user` where `user`.id = 5", 1892 "Table": "`user`", 1893 "Values": [ 1894 "INT64(5)" 1895 ], 1896 "Vindex": "user_index" 1897 }, 1898 { 1899 "OperatorType": "Route", 1900 "Variant": "Scatter", 1901 "Keyspace": { 1902 "Name": "user", 1903 "Sharded": true 1904 }, 1905 "FieldQuery": "select 1 from user_extra where 1 != 1", 1906 "Query": "select 1 from user_extra", 1907 "Table": "user_extra" 1908 } 1909 ] 1910 } 1911 }, 1912 "gen4-plan": { 1913 "QueryType": "SELECT", 1914 "Original": "select user.col from user join user_extra on 5 = user.id", 1915 "Instructions": { 1916 "OperatorType": "Join", 1917 "Variant": "Join", 1918 "JoinColumnIndexes": "L:0", 1919 "TableName": "`user`_user_extra", 1920 "Inputs": [ 1921 { 1922 "OperatorType": "Route", 1923 "Variant": "EqualUnique", 1924 "Keyspace": { 1925 "Name": "user", 1926 "Sharded": true 1927 }, 1928 "FieldQuery": "select `user`.col from `user` where 1 != 1", 1929 "Query": "select `user`.col from `user` where `user`.id = 5", 1930 "Table": "`user`", 1931 "Values": [ 1932 "INT64(5)" 1933 ], 1934 "Vindex": "user_index" 1935 }, 1936 { 1937 "OperatorType": "Route", 1938 "Variant": "Scatter", 1939 "Keyspace": { 1940 "Name": "user", 1941 "Sharded": true 1942 }, 1943 "FieldQuery": "select 1 from user_extra where 1 != 1", 1944 "Query": "select 1 from user_extra", 1945 "Table": "user_extra" 1946 } 1947 ] 1948 }, 1949 "TablesUsed": [ 1950 "user.user", 1951 "user.user_extra" 1952 ] 1953 } 1954 }, 1955 { 1956 "comment": "sharded join, non-vindex col", 1957 "query": "select user.col from user join user_extra on user.id = user_extra.col", 1958 "v3-plan": { 1959 "QueryType": "SELECT", 1960 "Original": "select user.col from user join user_extra on user.id = user_extra.col", 1961 "Instructions": { 1962 "OperatorType": "Join", 1963 "Variant": "Join", 1964 "JoinColumnIndexes": "L:0", 1965 "JoinVars": { 1966 "user_id": 1 1967 }, 1968 "TableName": "`user`_user_extra", 1969 "Inputs": [ 1970 { 1971 "OperatorType": "Route", 1972 "Variant": "Scatter", 1973 "Keyspace": { 1974 "Name": "user", 1975 "Sharded": true 1976 }, 1977 "FieldQuery": "select `user`.col, `user`.id from `user` where 1 != 1", 1978 "Query": "select `user`.col, `user`.id from `user`", 1979 "Table": "`user`" 1980 }, 1981 { 1982 "OperatorType": "Route", 1983 "Variant": "Scatter", 1984 "Keyspace": { 1985 "Name": "user", 1986 "Sharded": true 1987 }, 1988 "FieldQuery": "select 1 from user_extra where 1 != 1", 1989 "Query": "select 1 from user_extra where user_extra.col = :user_id", 1990 "Table": "user_extra" 1991 } 1992 ] 1993 } 1994 }, 1995 "gen4-plan": { 1996 "QueryType": "SELECT", 1997 "Original": "select user.col from user join user_extra on user.id = user_extra.col", 1998 "Instructions": { 1999 "OperatorType": "Join", 2000 "Variant": "Join", 2001 "JoinColumnIndexes": "R:0", 2002 "JoinVars": { 2003 "user_extra_col": 0 2004 }, 2005 "TableName": "user_extra_`user`", 2006 "Inputs": [ 2007 { 2008 "OperatorType": "Route", 2009 "Variant": "Scatter", 2010 "Keyspace": { 2011 "Name": "user", 2012 "Sharded": true 2013 }, 2014 "FieldQuery": "select user_extra.col from user_extra where 1 != 1", 2015 "Query": "select user_extra.col from user_extra", 2016 "Table": "user_extra" 2017 }, 2018 { 2019 "OperatorType": "Route", 2020 "Variant": "EqualUnique", 2021 "Keyspace": { 2022 "Name": "user", 2023 "Sharded": true 2024 }, 2025 "FieldQuery": "select `user`.col from `user` where 1 != 1", 2026 "Query": "select `user`.col from `user` where `user`.id = :user_extra_col", 2027 "Table": "`user`", 2028 "Values": [ 2029 ":user_extra_col" 2030 ], 2031 "Vindex": "user_index" 2032 } 2033 ] 2034 }, 2035 "TablesUsed": [ 2036 "user.user", 2037 "user.user_extra" 2038 ] 2039 } 2040 }, 2041 { 2042 "comment": "sharded join, non-unique vindex", 2043 "query": "select user.col from user_extra join user on user_extra.user_id = user.name", 2044 "v3-plan": { 2045 "QueryType": "SELECT", 2046 "Original": "select user.col from user_extra join user on user_extra.user_id = user.name", 2047 "Instructions": { 2048 "OperatorType": "Join", 2049 "Variant": "Join", 2050 "JoinColumnIndexes": "R:0", 2051 "JoinVars": { 2052 "user_extra_user_id": 0 2053 }, 2054 "TableName": "user_extra_`user`", 2055 "Inputs": [ 2056 { 2057 "OperatorType": "Route", 2058 "Variant": "Scatter", 2059 "Keyspace": { 2060 "Name": "user", 2061 "Sharded": true 2062 }, 2063 "FieldQuery": "select user_extra.user_id from user_extra where 1 != 1", 2064 "Query": "select user_extra.user_id from user_extra", 2065 "Table": "user_extra" 2066 }, 2067 { 2068 "OperatorType": "Route", 2069 "Variant": "Equal", 2070 "Keyspace": { 2071 "Name": "user", 2072 "Sharded": true 2073 }, 2074 "FieldQuery": "select `user`.col from `user` where 1 != 1", 2075 "Query": "select `user`.col from `user` where `user`.`name` = :user_extra_user_id", 2076 "Table": "`user`", 2077 "Values": [ 2078 ":user_extra_user_id" 2079 ], 2080 "Vindex": "name_user_map" 2081 } 2082 ] 2083 } 2084 }, 2085 "gen4-plan": { 2086 "QueryType": "SELECT", 2087 "Original": "select user.col from user_extra join user on user_extra.user_id = user.name", 2088 "Instructions": { 2089 "OperatorType": "Join", 2090 "Variant": "Join", 2091 "JoinColumnIndexes": "L:1", 2092 "JoinVars": { 2093 "user_name": 0 2094 }, 2095 "TableName": "`user`_user_extra", 2096 "Inputs": [ 2097 { 2098 "OperatorType": "Route", 2099 "Variant": "Scatter", 2100 "Keyspace": { 2101 "Name": "user", 2102 "Sharded": true 2103 }, 2104 "FieldQuery": "select `user`.`name`, `user`.col from `user` where 1 != 1", 2105 "Query": "select `user`.`name`, `user`.col from `user`", 2106 "Table": "`user`" 2107 }, 2108 { 2109 "OperatorType": "Route", 2110 "Variant": "EqualUnique", 2111 "Keyspace": { 2112 "Name": "user", 2113 "Sharded": true 2114 }, 2115 "FieldQuery": "select 1 from user_extra where 1 != 1", 2116 "Query": "select 1 from user_extra where user_extra.user_id = :user_name", 2117 "Table": "user_extra", 2118 "Values": [ 2119 ":user_name" 2120 ], 2121 "Vindex": "user_index" 2122 } 2123 ] 2124 }, 2125 "TablesUsed": [ 2126 "user.user", 2127 "user.user_extra" 2128 ] 2129 } 2130 }, 2131 { 2132 "comment": "join with reference table", 2133 "query": "select user.col from user join ref", 2134 "v3-plan": { 2135 "QueryType": "SELECT", 2136 "Original": "select user.col from user join ref", 2137 "Instructions": { 2138 "OperatorType": "Route", 2139 "Variant": "Scatter", 2140 "Keyspace": { 2141 "Name": "user", 2142 "Sharded": true 2143 }, 2144 "FieldQuery": "select `user`.col from `user` join ref where 1 != 1", 2145 "Query": "select `user`.col from `user` join ref", 2146 "Table": "`user`, ref" 2147 } 2148 }, 2149 "gen4-plan": { 2150 "QueryType": "SELECT", 2151 "Original": "select user.col from user join ref", 2152 "Instructions": { 2153 "OperatorType": "Route", 2154 "Variant": "Scatter", 2155 "Keyspace": { 2156 "Name": "user", 2157 "Sharded": true 2158 }, 2159 "FieldQuery": "select `user`.col from `user`, ref where 1 != 1", 2160 "Query": "select `user`.col from `user`, ref", 2161 "Table": "`user`, ref" 2162 }, 2163 "TablesUsed": [ 2164 "user.ref", 2165 "user.user" 2166 ] 2167 } 2168 }, 2169 { 2170 "comment": "reference table self-join", 2171 "query": "select r1.col from ref r1 join ref", 2172 "v3-plan": { 2173 "QueryType": "SELECT", 2174 "Original": "select r1.col from ref r1 join ref", 2175 "Instructions": { 2176 "OperatorType": "Route", 2177 "Variant": "Reference", 2178 "Keyspace": { 2179 "Name": "user", 2180 "Sharded": true 2181 }, 2182 "FieldQuery": "select r1.col from ref as r1 join ref where 1 != 1", 2183 "Query": "select r1.col from ref as r1 join ref", 2184 "Table": "ref" 2185 } 2186 }, 2187 "gen4-plan": { 2188 "QueryType": "SELECT", 2189 "Original": "select r1.col from ref r1 join ref", 2190 "Instructions": { 2191 "OperatorType": "Route", 2192 "Variant": "Reference", 2193 "Keyspace": { 2194 "Name": "user", 2195 "Sharded": true 2196 }, 2197 "FieldQuery": "select r1.col from ref as r1, ref where 1 != 1", 2198 "Query": "select r1.col from ref as r1, ref", 2199 "Table": "ref" 2200 }, 2201 "TablesUsed": [ 2202 "user.ref" 2203 ] 2204 } 2205 }, 2206 { 2207 "comment": "reference table can merge with other opcodes left to right.", 2208 "query": "select ref.col from ref join user", 2209 "v3-plan": { 2210 "QueryType": "SELECT", 2211 "Original": "select ref.col from ref join user", 2212 "Instructions": { 2213 "OperatorType": "Route", 2214 "Variant": "Scatter", 2215 "Keyspace": { 2216 "Name": "user", 2217 "Sharded": true 2218 }, 2219 "FieldQuery": "select ref.col from ref join `user` where 1 != 1", 2220 "Query": "select ref.col from ref join `user`", 2221 "Table": "`user`, ref" 2222 } 2223 }, 2224 "gen4-plan": { 2225 "QueryType": "SELECT", 2226 "Original": "select ref.col from ref join user", 2227 "Instructions": { 2228 "OperatorType": "Route", 2229 "Variant": "Scatter", 2230 "Keyspace": { 2231 "Name": "user", 2232 "Sharded": true 2233 }, 2234 "FieldQuery": "select ref.col from ref, `user` where 1 != 1", 2235 "Query": "select ref.col from ref, `user`", 2236 "Table": "`user`, ref" 2237 }, 2238 "TablesUsed": [ 2239 "user.ref", 2240 "user.user" 2241 ] 2242 } 2243 }, 2244 { 2245 "comment": "reference table can merge with other opcodes left to right and vindex value is in the plan.\n# This tests that route.Merge also copies the condition to the LHS.", 2246 "query": "select ref.col from ref join (select aa from user where user.id=1) user", 2247 "v3-plan": { 2248 "QueryType": "SELECT", 2249 "Original": "select ref.col from ref join (select aa from user where user.id=1) user", 2250 "Instructions": { 2251 "OperatorType": "Route", 2252 "Variant": "EqualUnique", 2253 "Keyspace": { 2254 "Name": "user", 2255 "Sharded": true 2256 }, 2257 "FieldQuery": "select ref.col from ref join (select aa from `user` where 1 != 1) as `user` where 1 != 1", 2258 "Query": "select ref.col from ref join (select aa from `user` where `user`.id = 1) as `user`", 2259 "Table": "`user`, ref", 2260 "Values": [ 2261 "INT64(1)" 2262 ], 2263 "Vindex": "user_index" 2264 } 2265 }, 2266 "gen4-plan": { 2267 "QueryType": "SELECT", 2268 "Original": "select ref.col from ref join (select aa from user where user.id=1) user", 2269 "Instructions": { 2270 "OperatorType": "Route", 2271 "Variant": "EqualUnique", 2272 "Keyspace": { 2273 "Name": "user", 2274 "Sharded": true 2275 }, 2276 "FieldQuery": "select ref.col from ref, (select aa from `user` where 1 != 1) as `user` where 1 != 1", 2277 "Query": "select ref.col from ref, (select aa from `user` where `user`.id = 1) as `user`", 2278 "Table": "`user`, ref", 2279 "Values": [ 2280 "INT64(1)" 2281 ], 2282 "Vindex": "user_index" 2283 }, 2284 "TablesUsed": [ 2285 "user.ref", 2286 "user.user" 2287 ] 2288 } 2289 }, 2290 { 2291 "comment": "routing rules for join, unsharded route wins if we can't find a merged route", 2292 "query": "select route2.col from route2 join user_extra", 2293 "v3-plan": { 2294 "QueryType": "SELECT", 2295 "Original": "select route2.col from route2 join user_extra", 2296 "Instructions": { 2297 "OperatorType": "Join", 2298 "Variant": "Join", 2299 "JoinColumnIndexes": "L:0", 2300 "TableName": "unsharded_user_extra", 2301 "Inputs": [ 2302 { 2303 "OperatorType": "Route", 2304 "Variant": "Unsharded", 2305 "Keyspace": { 2306 "Name": "main", 2307 "Sharded": false 2308 }, 2309 "FieldQuery": "select route2.col from unsharded as route2 where 1 != 1", 2310 "Query": "select route2.col from unsharded as route2", 2311 "Table": "unsharded" 2312 }, 2313 { 2314 "OperatorType": "Route", 2315 "Variant": "Scatter", 2316 "Keyspace": { 2317 "Name": "user", 2318 "Sharded": true 2319 }, 2320 "FieldQuery": "select 1 from user_extra where 1 != 1", 2321 "Query": "select 1 from user_extra", 2322 "Table": "user_extra" 2323 } 2324 ] 2325 } 2326 }, 2327 "gen4-plan": { 2328 "QueryType": "SELECT", 2329 "Original": "select route2.col from route2 join user_extra", 2330 "Instructions": { 2331 "OperatorType": "Join", 2332 "Variant": "Join", 2333 "JoinColumnIndexes": "L:0", 2334 "TableName": "unsharded_user_extra", 2335 "Inputs": [ 2336 { 2337 "OperatorType": "Route", 2338 "Variant": "Unsharded", 2339 "Keyspace": { 2340 "Name": "main", 2341 "Sharded": false 2342 }, 2343 "FieldQuery": "select route2.col from unsharded as route2 where 1 != 1", 2344 "Query": "select route2.col from unsharded as route2", 2345 "Table": "unsharded" 2346 }, 2347 { 2348 "OperatorType": "Route", 2349 "Variant": "Scatter", 2350 "Keyspace": { 2351 "Name": "user", 2352 "Sharded": true 2353 }, 2354 "FieldQuery": "select 1 from user_extra where 1 != 1", 2355 "Query": "select 1 from user_extra", 2356 "Table": "user_extra" 2357 } 2358 ] 2359 }, 2360 "TablesUsed": [ 2361 "main.unsharded", 2362 "user.user_extra" 2363 ] 2364 } 2365 }, 2366 { 2367 "comment": "derived table", 2368 "query": "select id from (select id, col from user where id = 5) as t", 2369 "v3-plan": { 2370 "QueryType": "SELECT", 2371 "Original": "select id from (select id, col from user where id = 5) as t", 2372 "Instructions": { 2373 "OperatorType": "Route", 2374 "Variant": "EqualUnique", 2375 "Keyspace": { 2376 "Name": "user", 2377 "Sharded": true 2378 }, 2379 "FieldQuery": "select id from (select id, col from `user` where 1 != 1) as t where 1 != 1", 2380 "Query": "select id from (select id, col from `user` where id = 5) as t", 2381 "Table": "`user`", 2382 "Values": [ 2383 "INT64(5)" 2384 ], 2385 "Vindex": "user_index" 2386 } 2387 }, 2388 "gen4-plan": { 2389 "QueryType": "SELECT", 2390 "Original": "select id from (select id, col from user where id = 5) as t", 2391 "Instructions": { 2392 "OperatorType": "Route", 2393 "Variant": "EqualUnique", 2394 "Keyspace": { 2395 "Name": "user", 2396 "Sharded": true 2397 }, 2398 "FieldQuery": "select id from (select id, col from `user` where 1 != 1) as t where 1 != 1", 2399 "Query": "select id from (select id, col from `user` where id = 5) as t", 2400 "Table": "`user`", 2401 "Values": [ 2402 "INT64(5)" 2403 ], 2404 "Vindex": "user_index" 2405 }, 2406 "TablesUsed": [ 2407 "user.user" 2408 ] 2409 } 2410 }, 2411 { 2412 "comment": "derived table with join", 2413 "query": "select t.id from (select id from user where id = 5) as t join user_extra on t.id = user_extra.user_id", 2414 "v3-plan": { 2415 "QueryType": "SELECT", 2416 "Original": "select t.id from (select id from user where id = 5) as t join user_extra on t.id = user_extra.user_id", 2417 "Instructions": { 2418 "OperatorType": "Route", 2419 "Variant": "EqualUnique", 2420 "Keyspace": { 2421 "Name": "user", 2422 "Sharded": true 2423 }, 2424 "FieldQuery": "select t.id from (select id from `user` where 1 != 1) as t join user_extra on t.id = user_extra.user_id where 1 != 1", 2425 "Query": "select t.id from (select id from `user` where id = 5) as t join user_extra on t.id = user_extra.user_id", 2426 "Table": "`user`, user_extra", 2427 "Values": [ 2428 "INT64(5)" 2429 ], 2430 "Vindex": "user_index" 2431 } 2432 }, 2433 "gen4-plan": { 2434 "QueryType": "SELECT", 2435 "Original": "select t.id from (select id from user where id = 5) as t join user_extra on t.id = user_extra.user_id", 2436 "Instructions": { 2437 "OperatorType": "Route", 2438 "Variant": "EqualUnique", 2439 "Keyspace": { 2440 "Name": "user", 2441 "Sharded": true 2442 }, 2443 "FieldQuery": "select t.id from (select id from `user` where 1 != 1) as t, user_extra where 1 != 1", 2444 "Query": "select t.id from (select id from `user` where id = 5) as t, user_extra where t.id = user_extra.user_id", 2445 "Table": "`user`, user_extra", 2446 "Values": [ 2447 "INT64(5)" 2448 ], 2449 "Vindex": "user_index" 2450 }, 2451 "TablesUsed": [ 2452 "user.user", 2453 "user.user_extra" 2454 ] 2455 } 2456 }, 2457 { 2458 "comment": "derived table with join, and aliased references", 2459 "query": "select t.id from (select user.id from user where user.id = 5) as t join user_extra on t.id = user_extra.user_id", 2460 "v3-plan": { 2461 "QueryType": "SELECT", 2462 "Original": "select t.id from (select user.id from user where user.id = 5) as t join user_extra on t.id = user_extra.user_id", 2463 "Instructions": { 2464 "OperatorType": "Route", 2465 "Variant": "EqualUnique", 2466 "Keyspace": { 2467 "Name": "user", 2468 "Sharded": true 2469 }, 2470 "FieldQuery": "select t.id from (select `user`.id from `user` where 1 != 1) as t join user_extra on t.id = user_extra.user_id where 1 != 1", 2471 "Query": "select t.id from (select `user`.id from `user` where `user`.id = 5) as t join user_extra on t.id = user_extra.user_id", 2472 "Table": "`user`, user_extra", 2473 "Values": [ 2474 "INT64(5)" 2475 ], 2476 "Vindex": "user_index" 2477 } 2478 }, 2479 "gen4-plan": { 2480 "QueryType": "SELECT", 2481 "Original": "select t.id from (select user.id from user where user.id = 5) as t join user_extra on t.id = user_extra.user_id", 2482 "Instructions": { 2483 "OperatorType": "Route", 2484 "Variant": "EqualUnique", 2485 "Keyspace": { 2486 "Name": "user", 2487 "Sharded": true 2488 }, 2489 "FieldQuery": "select t.id from (select `user`.id from `user` where 1 != 1) as t, user_extra where 1 != 1", 2490 "Query": "select t.id from (select `user`.id from `user` where `user`.id = 5) as t, user_extra where t.id = user_extra.user_id", 2491 "Table": "`user`, user_extra", 2492 "Values": [ 2493 "INT64(5)" 2494 ], 2495 "Vindex": "user_index" 2496 }, 2497 "TablesUsed": [ 2498 "user.user", 2499 "user.user_extra" 2500 ] 2501 } 2502 }, 2503 { 2504 "comment": "derived table with join, duplicate columns", 2505 "query": "select t.id from (select user.id, id from user where user.id = 5) as t join user_extra on t.id = user_extra.user_id", 2506 "v3-plan": "VT12001: unsupported: duplicate column aliases: id", 2507 "gen4-plan": "Duplicate column name 'id'" 2508 }, 2509 { 2510 "comment": "derived table in RHS of join", 2511 "query": "select t.id from user_extra join (select id from user where id = 5) as t on t.id = user_extra.user_id", 2512 "v3-plan": { 2513 "QueryType": "SELECT", 2514 "Original": "select t.id from user_extra join (select id from user where id = 5) as t on t.id = user_extra.user_id", 2515 "Instructions": { 2516 "OperatorType": "Route", 2517 "Variant": "Scatter", 2518 "Keyspace": { 2519 "Name": "user", 2520 "Sharded": true 2521 }, 2522 "FieldQuery": "select t.id from user_extra join (select id from `user` where 1 != 1) as t on t.id = user_extra.user_id where 1 != 1", 2523 "Query": "select t.id from user_extra join (select id from `user` where id = 5) as t on t.id = user_extra.user_id", 2524 "Table": "user_extra, `user`" 2525 } 2526 }, 2527 "gen4-plan": { 2528 "QueryType": "SELECT", 2529 "Original": "select t.id from user_extra join (select id from user where id = 5) as t on t.id = user_extra.user_id", 2530 "Instructions": { 2531 "OperatorType": "Route", 2532 "Variant": "EqualUnique", 2533 "Keyspace": { 2534 "Name": "user", 2535 "Sharded": true 2536 }, 2537 "FieldQuery": "select t.id from user_extra, (select id from `user` where 1 != 1) as t where 1 != 1", 2538 "Query": "select t.id from user_extra, (select id from `user` where id = 5) as t where t.id = user_extra.user_id", 2539 "Table": "`user`, user_extra", 2540 "Values": [ 2541 "INT64(5)" 2542 ], 2543 "Vindex": "user_index" 2544 }, 2545 "TablesUsed": [ 2546 "user.user", 2547 "user.user_extra" 2548 ] 2549 } 2550 }, 2551 { 2552 "comment": "derived table in FROM with cross-shard join", 2553 "query": "select t.id from (select id from user where id = 5) as t join user_extra on t.id = user_extra.col", 2554 "v3-plan": { 2555 "QueryType": "SELECT", 2556 "Original": "select t.id from (select id from user where id = 5) as t join user_extra on t.id = user_extra.col", 2557 "Instructions": { 2558 "OperatorType": "Join", 2559 "Variant": "Join", 2560 "JoinColumnIndexes": "L:0", 2561 "JoinVars": { 2562 "t_id": 0 2563 }, 2564 "TableName": "`user`_user_extra", 2565 "Inputs": [ 2566 { 2567 "OperatorType": "Route", 2568 "Variant": "EqualUnique", 2569 "Keyspace": { 2570 "Name": "user", 2571 "Sharded": true 2572 }, 2573 "FieldQuery": "select t.id from (select id from `user` where 1 != 1) as t where 1 != 1", 2574 "Query": "select t.id from (select id from `user` where id = 5) as t", 2575 "Table": "`user`", 2576 "Values": [ 2577 "INT64(5)" 2578 ], 2579 "Vindex": "user_index" 2580 }, 2581 { 2582 "OperatorType": "Route", 2583 "Variant": "Scatter", 2584 "Keyspace": { 2585 "Name": "user", 2586 "Sharded": true 2587 }, 2588 "FieldQuery": "select 1 from user_extra where 1 != 1", 2589 "Query": "select 1 from user_extra where user_extra.col = :t_id", 2590 "Table": "user_extra" 2591 } 2592 ] 2593 } 2594 }, 2595 "gen4-plan": { 2596 "QueryType": "SELECT", 2597 "Original": "select t.id from (select id from user where id = 5) as t join user_extra on t.id = user_extra.col", 2598 "Instructions": { 2599 "OperatorType": "Join", 2600 "Variant": "Join", 2601 "JoinColumnIndexes": "L:0", 2602 "JoinVars": { 2603 "t_id": 0 2604 }, 2605 "TableName": "`user`_user_extra", 2606 "Inputs": [ 2607 { 2608 "OperatorType": "Route", 2609 "Variant": "EqualUnique", 2610 "Keyspace": { 2611 "Name": "user", 2612 "Sharded": true 2613 }, 2614 "FieldQuery": "select t.id from (select id from `user` where 1 != 1) as t where 1 != 1", 2615 "Query": "select t.id from (select id from `user` where id = 5) as t", 2616 "Table": "`user`", 2617 "Values": [ 2618 "INT64(5)" 2619 ], 2620 "Vindex": "user_index" 2621 }, 2622 { 2623 "OperatorType": "Route", 2624 "Variant": "Scatter", 2625 "Keyspace": { 2626 "Name": "user", 2627 "Sharded": true 2628 }, 2629 "FieldQuery": "select 1 from user_extra where 1 != 1", 2630 "Query": "select 1 from user_extra where user_extra.col = :t_id", 2631 "Table": "user_extra" 2632 } 2633 ] 2634 }, 2635 "TablesUsed": [ 2636 "user.user", 2637 "user.user_extra" 2638 ] 2639 } 2640 }, 2641 { 2642 "comment": "routing rules for derived table", 2643 "query": "select id from (select id, col from route1 where id = 5) as t", 2644 "v3-plan": { 2645 "QueryType": "SELECT", 2646 "Original": "select id from (select id, col from route1 where id = 5) as t", 2647 "Instructions": { 2648 "OperatorType": "Route", 2649 "Variant": "EqualUnique", 2650 "Keyspace": { 2651 "Name": "user", 2652 "Sharded": true 2653 }, 2654 "FieldQuery": "select id from (select id, col from `user` as route1 where 1 != 1) as t where 1 != 1", 2655 "Query": "select id from (select id, col from `user` as route1 where id = 5) as t", 2656 "Table": "`user`", 2657 "Values": [ 2658 "INT64(5)" 2659 ], 2660 "Vindex": "user_index" 2661 } 2662 }, 2663 "gen4-plan": { 2664 "QueryType": "SELECT", 2665 "Original": "select id from (select id, col from route1 where id = 5) as t", 2666 "Instructions": { 2667 "OperatorType": "Route", 2668 "Variant": "EqualUnique", 2669 "Keyspace": { 2670 "Name": "user", 2671 "Sharded": true 2672 }, 2673 "FieldQuery": "select id from (select id, col from `user` as route1 where 1 != 1) as t where 1 != 1", 2674 "Query": "select id from (select id, col from `user` as route1 where id = 5) as t", 2675 "Table": "`user`", 2676 "Values": [ 2677 "INT64(5)" 2678 ], 2679 "Vindex": "user_index" 2680 }, 2681 "TablesUsed": [ 2682 "user.user" 2683 ] 2684 } 2685 }, 2686 { 2687 "comment": "derived table missing columns", 2688 "query": "select t.id from (select id from user) as t join user_extra on t.id = user_extra.user_id where t.col = 42", 2689 "v3-plan": { 2690 "QueryType": "SELECT", 2691 "Original": "select t.id from (select id from user) as t join user_extra on t.id = user_extra.user_id where t.col = 42", 2692 "Instructions": { 2693 "OperatorType": "Route", 2694 "Variant": "Scatter", 2695 "Keyspace": { 2696 "Name": "user", 2697 "Sharded": true 2698 }, 2699 "FieldQuery": "select t.id from (select id from `user` where 1 != 1) as t join user_extra on t.id = user_extra.user_id where 1 != 1", 2700 "Query": "select t.id from (select id from `user`) as t join user_extra on t.id = user_extra.user_id where t.col = 42", 2701 "Table": "`user`, user_extra" 2702 } 2703 }, 2704 "gen4-plan": "symbol t.col not found" 2705 }, 2706 { 2707 "comment": "routing rules for derived table where the constraint is in the outer query", 2708 "query": "select id from (select id, col from route1) as t where id = 5", 2709 "v3-plan": { 2710 "QueryType": "SELECT", 2711 "Original": "select id from (select id, col from route1) as t where id = 5", 2712 "Instructions": { 2713 "OperatorType": "Route", 2714 "Variant": "EqualUnique", 2715 "Keyspace": { 2716 "Name": "user", 2717 "Sharded": true 2718 }, 2719 "FieldQuery": "select id from (select id, col from `user` as route1 where 1 != 1) as t where 1 != 1", 2720 "Query": "select id from (select id, col from `user` as route1) as t where id = 5", 2721 "Table": "`user`", 2722 "Values": [ 2723 "INT64(5)" 2724 ], 2725 "Vindex": "user_index" 2726 } 2727 }, 2728 "gen4-plan": { 2729 "QueryType": "SELECT", 2730 "Original": "select id from (select id, col from route1) as t where id = 5", 2731 "Instructions": { 2732 "OperatorType": "Route", 2733 "Variant": "EqualUnique", 2734 "Keyspace": { 2735 "Name": "user", 2736 "Sharded": true 2737 }, 2738 "FieldQuery": "select id from (select id, col from `user` as route1 where 1 != 1) as t where 1 != 1", 2739 "Query": "select id from (select id, col from `user` as route1 where id = 5) as t", 2740 "Table": "`user`", 2741 "Values": [ 2742 "INT64(5)" 2743 ], 2744 "Vindex": "user_index" 2745 }, 2746 "TablesUsed": [ 2747 "user.user" 2748 ] 2749 } 2750 }, 2751 { 2752 "comment": "routing rules for derived table where the constraint is in the outer query", 2753 "query": "select id from (select id+col as foo from route1) as t where foo = 5", 2754 "v3-plan": { 2755 "QueryType": "SELECT", 2756 "Original": "select id from (select id+col as foo from route1) as t where foo = 5", 2757 "Instructions": { 2758 "OperatorType": "Route", 2759 "Variant": "Scatter", 2760 "Keyspace": { 2761 "Name": "user", 2762 "Sharded": true 2763 }, 2764 "FieldQuery": "select id from (select id + col as foo from `user` as route1 where 1 != 1) as t where 1 != 1", 2765 "Query": "select id from (select id + col as foo from `user` as route1) as t where foo = 5", 2766 "Table": "`user`" 2767 } 2768 }, 2769 "gen4-plan": "symbol id not found" 2770 }, 2771 { 2772 "comment": "push predicate on joined derived tables", 2773 "query": "select t.id from (select id, textcol1 as baz from route1) as t join (select id, textcol1+textcol1 as baz from user) as s ON t.id = s.id WHERE t.baz = '3' AND s.baz = '3'", 2774 "v3-plan": { 2775 "QueryType": "SELECT", 2776 "Original": "select t.id from (select id, textcol1 as baz from route1) as t join (select id, textcol1+textcol1 as baz from user) as s ON t.id = s.id WHERE t.baz = '3' AND s.baz = '3'", 2777 "Instructions": { 2778 "OperatorType": "Route", 2779 "Variant": "Scatter", 2780 "Keyspace": { 2781 "Name": "user", 2782 "Sharded": true 2783 }, 2784 "FieldQuery": "select t.id from (select id, textcol1 as baz from `user` as route1 where 1 != 1) as t join (select id, textcol1 + textcol1 as baz from `user` where 1 != 1) as s on t.id = s.id where 1 != 1", 2785 "Query": "select t.id from (select id, textcol1 as baz from `user` as route1) as t join (select id, textcol1 + textcol1 as baz from `user`) as s on t.id = s.id where t.baz = '3' and s.baz = '3'", 2786 "Table": "`user`" 2787 } 2788 }, 2789 "gen4-plan": { 2790 "QueryType": "SELECT", 2791 "Original": "select t.id from (select id, textcol1 as baz from route1) as t join (select id, textcol1+textcol1 as baz from user) as s ON t.id = s.id WHERE t.baz = '3' AND s.baz = '3'", 2792 "Instructions": { 2793 "OperatorType": "Route", 2794 "Variant": "Scatter", 2795 "Keyspace": { 2796 "Name": "user", 2797 "Sharded": true 2798 }, 2799 "FieldQuery": "select t.id from (select id, textcol1 as baz from `user` as route1 where 1 != 1) as t, (select id, textcol1 + textcol1 as baz from `user` where 1 != 1) as s where 1 != 1", 2800 "Query": "select t.id from (select id, textcol1 as baz from `user` as route1 where textcol1 = '3') as t, (select id, textcol1 + textcol1 as baz from `user` where textcol1 + textcol1 = '3') as s where t.id = s.id", 2801 "Table": "`user`" 2802 }, 2803 "TablesUsed": [ 2804 "user.user" 2805 ] 2806 } 2807 }, 2808 { 2809 "comment": "recursive derived table predicate push down", 2810 "query": "select bar from (select foo+4 as bar from (select colA+colB as foo from user) as u) as t where bar = 5", 2811 "v3-plan": { 2812 "QueryType": "SELECT", 2813 "Original": "select bar from (select foo+4 as bar from (select colA+colB as foo from user) as u) as t where bar = 5", 2814 "Instructions": { 2815 "OperatorType": "Route", 2816 "Variant": "Scatter", 2817 "Keyspace": { 2818 "Name": "user", 2819 "Sharded": true 2820 }, 2821 "FieldQuery": "select bar from (select foo + 4 as bar from (select colA + colB as foo from `user` where 1 != 1) as u where 1 != 1) as t where 1 != 1", 2822 "Query": "select bar from (select foo + 4 as bar from (select colA + colB as foo from `user`) as u) as t where bar = 5", 2823 "Table": "`user`" 2824 } 2825 }, 2826 "gen4-plan": { 2827 "QueryType": "SELECT", 2828 "Original": "select bar from (select foo+4 as bar from (select colA+colB as foo from user) as u) as t where bar = 5", 2829 "Instructions": { 2830 "OperatorType": "Route", 2831 "Variant": "Scatter", 2832 "Keyspace": { 2833 "Name": "user", 2834 "Sharded": true 2835 }, 2836 "FieldQuery": "select bar from (select foo + 4 as bar from (select colA + colB as foo from `user` where 1 != 1) as u where 1 != 1) as t where 1 != 1", 2837 "Query": "select bar from (select foo + 4 as bar from (select colA + colB as foo from `user` where colA + colB + 4 = 5) as u) as t", 2838 "Table": "`user`" 2839 }, 2840 "TablesUsed": [ 2841 "user.user" 2842 ] 2843 } 2844 }, 2845 { 2846 "comment": "recursive derived table lookups", 2847 "query": "select id from (select id from (select id from user) as u) as t where id = 5", 2848 "v3-plan": { 2849 "QueryType": "SELECT", 2850 "Original": "select id from (select id from (select id from user) as u) as t where id = 5", 2851 "Instructions": { 2852 "OperatorType": "Route", 2853 "Variant": "EqualUnique", 2854 "Keyspace": { 2855 "Name": "user", 2856 "Sharded": true 2857 }, 2858 "FieldQuery": "select id from (select id from (select id from `user` where 1 != 1) as u where 1 != 1) as t where 1 != 1", 2859 "Query": "select id from (select id from (select id from `user`) as u) as t where id = 5", 2860 "Table": "`user`", 2861 "Values": [ 2862 "INT64(5)" 2863 ], 2864 "Vindex": "user_index" 2865 } 2866 }, 2867 "gen4-plan": { 2868 "QueryType": "SELECT", 2869 "Original": "select id from (select id from (select id from user) as u) as t where id = 5", 2870 "Instructions": { 2871 "OperatorType": "Route", 2872 "Variant": "EqualUnique", 2873 "Keyspace": { 2874 "Name": "user", 2875 "Sharded": true 2876 }, 2877 "FieldQuery": "select id from (select id from (select id from `user` where 1 != 1) as u where 1 != 1) as t where 1 != 1", 2878 "Query": "select id from (select id from (select id from `user` where id = 5) as u) as t", 2879 "Table": "`user`", 2880 "Values": [ 2881 "INT64(5)" 2882 ], 2883 "Vindex": "user_index" 2884 }, 2885 "TablesUsed": [ 2886 "user.user" 2887 ] 2888 } 2889 }, 2890 { 2891 "comment": "merge derived tables with single-shard routes", 2892 "query": "select u.col, e.col from (select col from user where id = 5) as u join (select col from user_extra where user_id = 5) as e", 2893 "v3-plan": { 2894 "QueryType": "SELECT", 2895 "Original": "select u.col, e.col from (select col from user where id = 5) as u join (select col from user_extra where user_id = 5) as e", 2896 "Instructions": { 2897 "OperatorType": "Route", 2898 "Variant": "EqualUnique", 2899 "Keyspace": { 2900 "Name": "user", 2901 "Sharded": true 2902 }, 2903 "FieldQuery": "select u.col, e.col from (select col from `user` where 1 != 1) as u join (select col from user_extra where 1 != 1) as e where 1 != 1", 2904 "Query": "select u.col, e.col from (select col from `user` where id = 5) as u join (select col from user_extra where user_id = 5) as e", 2905 "Table": "`user`, user_extra", 2906 "Values": [ 2907 "INT64(5)" 2908 ], 2909 "Vindex": "user_index" 2910 } 2911 }, 2912 "gen4-plan": { 2913 "QueryType": "SELECT", 2914 "Original": "select u.col, e.col from (select col from user where id = 5) as u join (select col from user_extra where user_id = 5) as e", 2915 "Instructions": { 2916 "OperatorType": "Route", 2917 "Variant": "EqualUnique", 2918 "Keyspace": { 2919 "Name": "user", 2920 "Sharded": true 2921 }, 2922 "FieldQuery": "select u.col, e.col from (select col from `user` where 1 != 1) as u, (select col from user_extra where 1 != 1) as e where 1 != 1", 2923 "Query": "select u.col, e.col from (select col from `user` where id = 5) as u, (select col from user_extra where user_id = 5) as e", 2924 "Table": "`user`, user_extra", 2925 "Values": [ 2926 "INT64(5)" 2927 ], 2928 "Vindex": "user_index" 2929 }, 2930 "TablesUsed": [ 2931 "user.user", 2932 "user.user_extra" 2933 ] 2934 } 2935 }, 2936 { 2937 "comment": "join of information_schema with normal table", 2938 "query": "select unsharded.foo from information_schema.CHARACTER_SETS join unsharded", 2939 "v3-plan": { 2940 "QueryType": "SELECT", 2941 "Original": "select unsharded.foo from information_schema.CHARACTER_SETS join unsharded", 2942 "Instructions": { 2943 "OperatorType": "Join", 2944 "Variant": "Join", 2945 "JoinColumnIndexes": "R:0", 2946 "TableName": "information_schema.CHARACTER_SETS_unsharded", 2947 "Inputs": [ 2948 { 2949 "OperatorType": "Route", 2950 "Variant": "DBA", 2951 "Keyspace": { 2952 "Name": "main", 2953 "Sharded": false 2954 }, 2955 "FieldQuery": "select 1 from information_schema.CHARACTER_SETS where 1 != 1", 2956 "Query": "select 1 from information_schema.CHARACTER_SETS", 2957 "Table": "information_schema.CHARACTER_SETS" 2958 }, 2959 { 2960 "OperatorType": "Route", 2961 "Variant": "Unsharded", 2962 "Keyspace": { 2963 "Name": "main", 2964 "Sharded": false 2965 }, 2966 "FieldQuery": "select unsharded.foo from unsharded where 1 != 1", 2967 "Query": "select unsharded.foo from unsharded", 2968 "Table": "unsharded" 2969 } 2970 ] 2971 } 2972 }, 2973 "gen4-plan": { 2974 "QueryType": "SELECT", 2975 "Original": "select unsharded.foo from information_schema.CHARACTER_SETS join unsharded", 2976 "Instructions": { 2977 "OperatorType": "Join", 2978 "Variant": "Join", 2979 "JoinColumnIndexes": "R:0", 2980 "TableName": "information_schema.CHARACTER_SETS_unsharded", 2981 "Inputs": [ 2982 { 2983 "OperatorType": "Route", 2984 "Variant": "DBA", 2985 "Keyspace": { 2986 "Name": "main", 2987 "Sharded": false 2988 }, 2989 "FieldQuery": "select 1 from information_schema.CHARACTER_SETS where 1 != 1", 2990 "Query": "select 1 from information_schema.CHARACTER_SETS", 2991 "Table": "information_schema.CHARACTER_SETS" 2992 }, 2993 { 2994 "OperatorType": "Route", 2995 "Variant": "Unsharded", 2996 "Keyspace": { 2997 "Name": "main", 2998 "Sharded": false 2999 }, 3000 "FieldQuery": "select unsharded.foo from unsharded where 1 != 1", 3001 "Query": "select unsharded.foo from unsharded", 3002 "Table": "unsharded" 3003 } 3004 ] 3005 }, 3006 "TablesUsed": [ 3007 "main.unsharded" 3008 ] 3009 } 3010 }, 3011 { 3012 "comment": "join of normal table with information_schema", 3013 "query": "select unsharded.foo from unsharded join information_schema.CHARACTER_SETS", 3014 "v3-plan": { 3015 "QueryType": "SELECT", 3016 "Original": "select unsharded.foo from unsharded join information_schema.CHARACTER_SETS", 3017 "Instructions": { 3018 "OperatorType": "Join", 3019 "Variant": "Join", 3020 "JoinColumnIndexes": "L:0", 3021 "TableName": "unsharded_information_schema.CHARACTER_SETS", 3022 "Inputs": [ 3023 { 3024 "OperatorType": "Route", 3025 "Variant": "Unsharded", 3026 "Keyspace": { 3027 "Name": "main", 3028 "Sharded": false 3029 }, 3030 "FieldQuery": "select unsharded.foo from unsharded where 1 != 1", 3031 "Query": "select unsharded.foo from unsharded", 3032 "Table": "unsharded" 3033 }, 3034 { 3035 "OperatorType": "Route", 3036 "Variant": "DBA", 3037 "Keyspace": { 3038 "Name": "main", 3039 "Sharded": false 3040 }, 3041 "FieldQuery": "select 1 from information_schema.CHARACTER_SETS where 1 != 1", 3042 "Query": "select 1 from information_schema.CHARACTER_SETS", 3043 "Table": "information_schema.CHARACTER_SETS" 3044 } 3045 ] 3046 } 3047 }, 3048 "gen4-plan": { 3049 "QueryType": "SELECT", 3050 "Original": "select unsharded.foo from unsharded join information_schema.CHARACTER_SETS", 3051 "Instructions": { 3052 "OperatorType": "Join", 3053 "Variant": "Join", 3054 "JoinColumnIndexes": "L:0", 3055 "TableName": "unsharded_information_schema.CHARACTER_SETS", 3056 "Inputs": [ 3057 { 3058 "OperatorType": "Route", 3059 "Variant": "Unsharded", 3060 "Keyspace": { 3061 "Name": "main", 3062 "Sharded": false 3063 }, 3064 "FieldQuery": "select unsharded.foo from unsharded where 1 != 1", 3065 "Query": "select unsharded.foo from unsharded", 3066 "Table": "unsharded" 3067 }, 3068 { 3069 "OperatorType": "Route", 3070 "Variant": "DBA", 3071 "Keyspace": { 3072 "Name": "main", 3073 "Sharded": false 3074 }, 3075 "FieldQuery": "select 1 from information_schema.CHARACTER_SETS where 1 != 1", 3076 "Query": "select 1 from information_schema.CHARACTER_SETS", 3077 "Table": "information_schema.CHARACTER_SETS" 3078 } 3079 ] 3080 }, 3081 "TablesUsed": [ 3082 "main.unsharded" 3083 ] 3084 } 3085 }, 3086 { 3087 "comment": "wire-up on join with cross-shard derived table", 3088 "query": "select t.col1 from (select user.id, user.col1 from user join user_extra) as t join unsharded on unsharded.col1 = t.col1 and unsharded.id = t.id", 3089 "v3-plan": { 3090 "QueryType": "SELECT", 3091 "Original": "select t.col1 from (select user.id, user.col1 from user join user_extra) as t join unsharded on unsharded.col1 = t.col1 and unsharded.id = t.id", 3092 "Instructions": { 3093 "OperatorType": "Join", 3094 "Variant": "Join", 3095 "JoinColumnIndexes": "L:0", 3096 "JoinVars": { 3097 "t_col1": 0, 3098 "t_id": 1 3099 }, 3100 "TableName": "`user`_user_extra_unsharded", 3101 "Inputs": [ 3102 { 3103 "OperatorType": "SimpleProjection", 3104 "Columns": [ 3105 1, 3106 0 3107 ], 3108 "Inputs": [ 3109 { 3110 "OperatorType": "Join", 3111 "Variant": "Join", 3112 "JoinColumnIndexes": "L:0,L:1", 3113 "TableName": "`user`_user_extra", 3114 "Inputs": [ 3115 { 3116 "OperatorType": "Route", 3117 "Variant": "Scatter", 3118 "Keyspace": { 3119 "Name": "user", 3120 "Sharded": true 3121 }, 3122 "FieldQuery": "select `user`.id, `user`.col1 from `user` where 1 != 1", 3123 "Query": "select `user`.id, `user`.col1 from `user`", 3124 "Table": "`user`" 3125 }, 3126 { 3127 "OperatorType": "Route", 3128 "Variant": "Scatter", 3129 "Keyspace": { 3130 "Name": "user", 3131 "Sharded": true 3132 }, 3133 "FieldQuery": "select 1 from user_extra where 1 != 1", 3134 "Query": "select 1 from user_extra", 3135 "Table": "user_extra" 3136 } 3137 ] 3138 } 3139 ] 3140 }, 3141 { 3142 "OperatorType": "Route", 3143 "Variant": "Unsharded", 3144 "Keyspace": { 3145 "Name": "main", 3146 "Sharded": false 3147 }, 3148 "FieldQuery": "select 1 from unsharded where 1 != 1", 3149 "Query": "select 1 from unsharded where unsharded.col1 = :t_col1 and unsharded.id = :t_id", 3150 "Table": "unsharded" 3151 } 3152 ] 3153 } 3154 }, 3155 "gen4-plan": { 3156 "QueryType": "SELECT", 3157 "Original": "select t.col1 from (select user.id, user.col1 from user join user_extra) as t join unsharded on unsharded.col1 = t.col1 and unsharded.id = t.id", 3158 "Instructions": { 3159 "OperatorType": "Join", 3160 "Variant": "Join", 3161 "JoinColumnIndexes": "L:0", 3162 "JoinVars": { 3163 "t_col1": 0, 3164 "t_id": 1 3165 }, 3166 "TableName": "`user`_user_extra_unsharded", 3167 "Inputs": [ 3168 { 3169 "OperatorType": "SimpleProjection", 3170 "Columns": [ 3171 1, 3172 0 3173 ], 3174 "Inputs": [ 3175 { 3176 "OperatorType": "Join", 3177 "Variant": "Join", 3178 "JoinColumnIndexes": "L:0,L:1", 3179 "TableName": "`user`_user_extra", 3180 "Inputs": [ 3181 { 3182 "OperatorType": "Route", 3183 "Variant": "Scatter", 3184 "Keyspace": { 3185 "Name": "user", 3186 "Sharded": true 3187 }, 3188 "FieldQuery": "select `user`.id, `user`.col1 from `user` where 1 != 1", 3189 "Query": "select `user`.id, `user`.col1 from `user`", 3190 "Table": "`user`" 3191 }, 3192 { 3193 "OperatorType": "Route", 3194 "Variant": "Scatter", 3195 "Keyspace": { 3196 "Name": "user", 3197 "Sharded": true 3198 }, 3199 "FieldQuery": "select 1 from user_extra where 1 != 1", 3200 "Query": "select 1 from user_extra", 3201 "Table": "user_extra" 3202 } 3203 ] 3204 } 3205 ] 3206 }, 3207 { 3208 "OperatorType": "Route", 3209 "Variant": "Unsharded", 3210 "Keyspace": { 3211 "Name": "main", 3212 "Sharded": false 3213 }, 3214 "FieldQuery": "select 1 from unsharded where 1 != 1", 3215 "Query": "select 1 from unsharded where unsharded.col1 = :t_col1 and unsharded.id = :t_id", 3216 "Table": "unsharded" 3217 } 3218 ] 3219 }, 3220 "TablesUsed": [ 3221 "main.unsharded", 3222 "user.user", 3223 "user.user_extra" 3224 ] 3225 } 3226 }, 3227 { 3228 "comment": "wire-up on within cross-shard derived table", 3229 "query": "select t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t", 3230 "v3-plan": { 3231 "QueryType": "SELECT", 3232 "Original": "select t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t", 3233 "Instructions": { 3234 "OperatorType": "SimpleProjection", 3235 "Columns": [ 3236 0 3237 ], 3238 "Inputs": [ 3239 { 3240 "OperatorType": "Join", 3241 "Variant": "Join", 3242 "JoinColumnIndexes": "L:0,L:1", 3243 "JoinVars": { 3244 "user_col": 2 3245 }, 3246 "TableName": "`user`_user_extra", 3247 "Inputs": [ 3248 { 3249 "OperatorType": "Route", 3250 "Variant": "Scatter", 3251 "Keyspace": { 3252 "Name": "user", 3253 "Sharded": true 3254 }, 3255 "FieldQuery": "select `user`.id, `user`.col1, `user`.col from `user` where 1 != 1", 3256 "Query": "select `user`.id, `user`.col1, `user`.col from `user`", 3257 "Table": "`user`" 3258 }, 3259 { 3260 "OperatorType": "Route", 3261 "Variant": "Scatter", 3262 "Keyspace": { 3263 "Name": "user", 3264 "Sharded": true 3265 }, 3266 "FieldQuery": "select 1 from user_extra where 1 != 1", 3267 "Query": "select 1 from user_extra where user_extra.col = :user_col", 3268 "Table": "user_extra" 3269 } 3270 ] 3271 } 3272 ] 3273 } 3274 }, 3275 "gen4-plan": { 3276 "QueryType": "SELECT", 3277 "Original": "select t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t", 3278 "Instructions": { 3279 "OperatorType": "SimpleProjection", 3280 "Columns": [ 3281 0 3282 ], 3283 "Inputs": [ 3284 { 3285 "OperatorType": "Join", 3286 "Variant": "Join", 3287 "JoinColumnIndexes": "L:1,L:2", 3288 "JoinVars": { 3289 "user_col": 0 3290 }, 3291 "TableName": "`user`_user_extra", 3292 "Inputs": [ 3293 { 3294 "OperatorType": "Route", 3295 "Variant": "Scatter", 3296 "Keyspace": { 3297 "Name": "user", 3298 "Sharded": true 3299 }, 3300 "FieldQuery": "select `user`.col, `user`.id, `user`.col1 from `user` where 1 != 1", 3301 "Query": "select `user`.col, `user`.id, `user`.col1 from `user`", 3302 "Table": "`user`" 3303 }, 3304 { 3305 "OperatorType": "Route", 3306 "Variant": "Scatter", 3307 "Keyspace": { 3308 "Name": "user", 3309 "Sharded": true 3310 }, 3311 "FieldQuery": "select 1 from user_extra where 1 != 1", 3312 "Query": "select 1 from user_extra where user_extra.col = :user_col", 3313 "Table": "user_extra" 3314 } 3315 ] 3316 } 3317 ] 3318 }, 3319 "TablesUsed": [ 3320 "user.user", 3321 "user.user_extra" 3322 ] 3323 } 3324 }, 3325 { 3326 "comment": "Join with cross-shard derived table on rhs", 3327 "query": "select t.col1 from unsharded_a ua join (select user.id, user.col1 from user join user_extra) as t", 3328 "v3-plan": { 3329 "QueryType": "SELECT", 3330 "Original": "select t.col1 from unsharded_a ua join (select user.id, user.col1 from user join user_extra) as t", 3331 "Instructions": { 3332 "OperatorType": "Join", 3333 "Variant": "Join", 3334 "JoinColumnIndexes": "R:0", 3335 "TableName": "unsharded_a_`user`_user_extra", 3336 "Inputs": [ 3337 { 3338 "OperatorType": "Route", 3339 "Variant": "Unsharded", 3340 "Keyspace": { 3341 "Name": "main", 3342 "Sharded": false 3343 }, 3344 "FieldQuery": "select 1 from unsharded_a as ua where 1 != 1", 3345 "Query": "select 1 from unsharded_a as ua", 3346 "Table": "unsharded_a" 3347 }, 3348 { 3349 "OperatorType": "SimpleProjection", 3350 "Columns": [ 3351 1 3352 ], 3353 "Inputs": [ 3354 { 3355 "OperatorType": "Join", 3356 "Variant": "Join", 3357 "JoinColumnIndexes": "L:0,L:1", 3358 "TableName": "`user`_user_extra", 3359 "Inputs": [ 3360 { 3361 "OperatorType": "Route", 3362 "Variant": "Scatter", 3363 "Keyspace": { 3364 "Name": "user", 3365 "Sharded": true 3366 }, 3367 "FieldQuery": "select `user`.id, `user`.col1 from `user` where 1 != 1", 3368 "Query": "select `user`.id, `user`.col1 from `user`", 3369 "Table": "`user`" 3370 }, 3371 { 3372 "OperatorType": "Route", 3373 "Variant": "Scatter", 3374 "Keyspace": { 3375 "Name": "user", 3376 "Sharded": true 3377 }, 3378 "FieldQuery": "select 1 from user_extra where 1 != 1", 3379 "Query": "select 1 from user_extra", 3380 "Table": "user_extra" 3381 } 3382 ] 3383 } 3384 ] 3385 } 3386 ] 3387 } 3388 }, 3389 "gen4-plan": { 3390 "QueryType": "SELECT", 3391 "Original": "select t.col1 from unsharded_a ua join (select user.id, user.col1 from user join user_extra) as t", 3392 "Instructions": { 3393 "OperatorType": "Join", 3394 "Variant": "Join", 3395 "JoinColumnIndexes": "R:0", 3396 "TableName": "unsharded_a_`user`_user_extra", 3397 "Inputs": [ 3398 { 3399 "OperatorType": "Route", 3400 "Variant": "Unsharded", 3401 "Keyspace": { 3402 "Name": "main", 3403 "Sharded": false 3404 }, 3405 "FieldQuery": "select 1 from unsharded_a as ua where 1 != 1", 3406 "Query": "select 1 from unsharded_a as ua", 3407 "Table": "unsharded_a" 3408 }, 3409 { 3410 "OperatorType": "SimpleProjection", 3411 "Columns": [ 3412 1 3413 ], 3414 "Inputs": [ 3415 { 3416 "OperatorType": "Join", 3417 "Variant": "Join", 3418 "JoinColumnIndexes": "L:0,L:1", 3419 "TableName": "`user`_user_extra", 3420 "Inputs": [ 3421 { 3422 "OperatorType": "Route", 3423 "Variant": "Scatter", 3424 "Keyspace": { 3425 "Name": "user", 3426 "Sharded": true 3427 }, 3428 "FieldQuery": "select `user`.id, `user`.col1 from `user` where 1 != 1", 3429 "Query": "select `user`.id, `user`.col1 from `user`", 3430 "Table": "`user`" 3431 }, 3432 { 3433 "OperatorType": "Route", 3434 "Variant": "Scatter", 3435 "Keyspace": { 3436 "Name": "user", 3437 "Sharded": true 3438 }, 3439 "FieldQuery": "select 1 from user_extra where 1 != 1", 3440 "Query": "select 1 from user_extra", 3441 "Table": "user_extra" 3442 } 3443 ] 3444 } 3445 ] 3446 } 3447 ] 3448 }, 3449 "TablesUsed": [ 3450 "main.unsharded_a", 3451 "user.user", 3452 "user.user_extra" 3453 ] 3454 } 3455 }, 3456 { 3457 "comment": "Join with cross-shard derived table on rhs - push down join predicate to derived table", 3458 "query": "select t.col1 from unsharded_a ua join (select user.id, user.col1 from user join user_extra) as t on t.id = ua.id", 3459 "v3-plan": "VT12001: unsupported: filtering on results of cross-shard subquery", 3460 "gen4-plan": { 3461 "QueryType": "SELECT", 3462 "Original": "select t.col1 from unsharded_a ua join (select user.id, user.col1 from user join user_extra) as t on t.id = ua.id", 3463 "Instructions": { 3464 "OperatorType": "Join", 3465 "Variant": "Join", 3466 "JoinColumnIndexes": "R:0", 3467 "JoinVars": { 3468 "ua_id": 0 3469 }, 3470 "TableName": "unsharded_a_`user`_user_extra", 3471 "Inputs": [ 3472 { 3473 "OperatorType": "Route", 3474 "Variant": "Unsharded", 3475 "Keyspace": { 3476 "Name": "main", 3477 "Sharded": false 3478 }, 3479 "FieldQuery": "select ua.id from unsharded_a as ua where 1 != 1", 3480 "Query": "select ua.id from unsharded_a as ua", 3481 "Table": "unsharded_a" 3482 }, 3483 { 3484 "OperatorType": "SimpleProjection", 3485 "Columns": [ 3486 1 3487 ], 3488 "Inputs": [ 3489 { 3490 "OperatorType": "Join", 3491 "Variant": "Join", 3492 "JoinColumnIndexes": "L:0,L:1", 3493 "TableName": "`user`_user_extra", 3494 "Inputs": [ 3495 { 3496 "OperatorType": "Route", 3497 "Variant": "EqualUnique", 3498 "Keyspace": { 3499 "Name": "user", 3500 "Sharded": true 3501 }, 3502 "FieldQuery": "select `user`.id, `user`.col1 from `user` where 1 != 1", 3503 "Query": "select `user`.id, `user`.col1 from `user` where `user`.id = :ua_id", 3504 "Table": "`user`", 3505 "Values": [ 3506 ":ua_id" 3507 ], 3508 "Vindex": "user_index" 3509 }, 3510 { 3511 "OperatorType": "Route", 3512 "Variant": "Scatter", 3513 "Keyspace": { 3514 "Name": "user", 3515 "Sharded": true 3516 }, 3517 "FieldQuery": "select 1 from user_extra where 1 != 1", 3518 "Query": "select 1 from user_extra", 3519 "Table": "user_extra" 3520 } 3521 ] 3522 } 3523 ] 3524 } 3525 ] 3526 }, 3527 "TablesUsed": [ 3528 "main.unsharded_a", 3529 "user.user", 3530 "user.user_extra" 3531 ] 3532 } 3533 }, 3534 { 3535 "comment": "subquery in ON clause, single route", 3536 "query": "select unsharded_a.col from unsharded_a join unsharded_b on (select col from user)", 3537 "v3-plan": { 3538 "QueryType": "SELECT", 3539 "Original": "select unsharded_a.col from unsharded_a join unsharded_b on (select col from user)", 3540 "Instructions": { 3541 "OperatorType": "Subquery", 3542 "Variant": "PulloutValue", 3543 "PulloutVars": [ 3544 "__sq_has_values1", 3545 "__sq1" 3546 ], 3547 "Inputs": [ 3548 { 3549 "OperatorType": "Route", 3550 "Variant": "Scatter", 3551 "Keyspace": { 3552 "Name": "user", 3553 "Sharded": true 3554 }, 3555 "FieldQuery": "select col from `user` where 1 != 1", 3556 "Query": "select col from `user`", 3557 "Table": "`user`" 3558 }, 3559 { 3560 "OperatorType": "Route", 3561 "Variant": "Unsharded", 3562 "Keyspace": { 3563 "Name": "main", 3564 "Sharded": false 3565 }, 3566 "FieldQuery": "select unsharded_a.col from unsharded_a join unsharded_b on :__sq1 where 1 != 1", 3567 "Query": "select unsharded_a.col from unsharded_a join unsharded_b on :__sq1", 3568 "Table": "unsharded_a, unsharded_b" 3569 } 3570 ] 3571 } 3572 }, 3573 "gen4-plan": { 3574 "QueryType": "SELECT", 3575 "Original": "select unsharded_a.col from unsharded_a join unsharded_b on (select col from user)", 3576 "Instructions": { 3577 "OperatorType": "Subquery", 3578 "Variant": "PulloutValue", 3579 "PulloutVars": [ 3580 "__sq1" 3581 ], 3582 "Inputs": [ 3583 { 3584 "OperatorType": "Route", 3585 "Variant": "Scatter", 3586 "Keyspace": { 3587 "Name": "user", 3588 "Sharded": true 3589 }, 3590 "FieldQuery": "select col from `user` where 1 != 1", 3591 "Query": "select col from `user`", 3592 "Table": "`user`" 3593 }, 3594 { 3595 "OperatorType": "Route", 3596 "Variant": "Unsharded", 3597 "Keyspace": { 3598 "Name": "main", 3599 "Sharded": false 3600 }, 3601 "FieldQuery": "select unsharded_a.col from unsharded_a, unsharded_b where 1 != 1", 3602 "Query": "select unsharded_a.col from unsharded_a, unsharded_b where :__sq1", 3603 "Table": "unsharded_a, unsharded_b" 3604 } 3605 ] 3606 }, 3607 "TablesUsed": [ 3608 "main.unsharded_a", 3609 "main.unsharded_b", 3610 "user.user" 3611 ] 3612 } 3613 }, 3614 { 3615 "comment": "subquery in ON clause as sub-expression", 3616 "query": "select unsharded_a.col from unsharded_a join unsharded_b on unsharded_a.col+(select col from user)", 3617 "v3-plan": { 3618 "QueryType": "SELECT", 3619 "Original": "select unsharded_a.col from unsharded_a join unsharded_b on unsharded_a.col+(select col from user)", 3620 "Instructions": { 3621 "OperatorType": "Subquery", 3622 "Variant": "PulloutValue", 3623 "PulloutVars": [ 3624 "__sq_has_values1", 3625 "__sq1" 3626 ], 3627 "Inputs": [ 3628 { 3629 "OperatorType": "Route", 3630 "Variant": "Scatter", 3631 "Keyspace": { 3632 "Name": "user", 3633 "Sharded": true 3634 }, 3635 "FieldQuery": "select col from `user` where 1 != 1", 3636 "Query": "select col from `user`", 3637 "Table": "`user`" 3638 }, 3639 { 3640 "OperatorType": "Route", 3641 "Variant": "Unsharded", 3642 "Keyspace": { 3643 "Name": "main", 3644 "Sharded": false 3645 }, 3646 "FieldQuery": "select unsharded_a.col from unsharded_a join unsharded_b on unsharded_a.col + :__sq1 where 1 != 1", 3647 "Query": "select unsharded_a.col from unsharded_a join unsharded_b on unsharded_a.col + :__sq1", 3648 "Table": "unsharded_a, unsharded_b" 3649 } 3650 ] 3651 } 3652 }, 3653 "gen4-plan": { 3654 "QueryType": "SELECT", 3655 "Original": "select unsharded_a.col from unsharded_a join unsharded_b on unsharded_a.col+(select col from user)", 3656 "Instructions": { 3657 "OperatorType": "Subquery", 3658 "Variant": "PulloutValue", 3659 "PulloutVars": [ 3660 "__sq1" 3661 ], 3662 "Inputs": [ 3663 { 3664 "OperatorType": "Route", 3665 "Variant": "Scatter", 3666 "Keyspace": { 3667 "Name": "user", 3668 "Sharded": true 3669 }, 3670 "FieldQuery": "select col from `user` where 1 != 1", 3671 "Query": "select col from `user`", 3672 "Table": "`user`" 3673 }, 3674 { 3675 "OperatorType": "Route", 3676 "Variant": "Unsharded", 3677 "Keyspace": { 3678 "Name": "main", 3679 "Sharded": false 3680 }, 3681 "FieldQuery": "select unsharded_a.col from unsharded_a, unsharded_b where 1 != 1", 3682 "Query": "select unsharded_a.col from unsharded_a, unsharded_b where unsharded_a.col + :__sq1", 3683 "Table": "unsharded_a, unsharded_b" 3684 } 3685 ] 3686 }, 3687 "TablesUsed": [ 3688 "main.unsharded_a", 3689 "main.unsharded_b", 3690 "user.user" 3691 ] 3692 } 3693 }, 3694 { 3695 "comment": "IN subquery in ON clause, single route", 3696 "query": "select unsharded_a.col from unsharded_a join unsharded_b on unsharded_a.col in (select col from user)", 3697 "v3-plan": { 3698 "QueryType": "SELECT", 3699 "Original": "select unsharded_a.col from unsharded_a join unsharded_b on unsharded_a.col in (select col from user)", 3700 "Instructions": { 3701 "OperatorType": "Subquery", 3702 "Variant": "PulloutIn", 3703 "PulloutVars": [ 3704 "__sq_has_values1", 3705 "__sq1" 3706 ], 3707 "Inputs": [ 3708 { 3709 "OperatorType": "Route", 3710 "Variant": "Scatter", 3711 "Keyspace": { 3712 "Name": "user", 3713 "Sharded": true 3714 }, 3715 "FieldQuery": "select col from `user` where 1 != 1", 3716 "Query": "select col from `user`", 3717 "Table": "`user`" 3718 }, 3719 { 3720 "OperatorType": "Route", 3721 "Variant": "Unsharded", 3722 "Keyspace": { 3723 "Name": "main", 3724 "Sharded": false 3725 }, 3726 "FieldQuery": "select unsharded_a.col from unsharded_a join unsharded_b on :__sq_has_values1 = 1 and unsharded_a.col in ::__sq1 where 1 != 1", 3727 "Query": "select unsharded_a.col from unsharded_a join unsharded_b on :__sq_has_values1 = 1 and unsharded_a.col in ::__sq1", 3728 "Table": "unsharded_a, unsharded_b" 3729 } 3730 ] 3731 } 3732 }, 3733 "gen4-plan": { 3734 "QueryType": "SELECT", 3735 "Original": "select unsharded_a.col from unsharded_a join unsharded_b on unsharded_a.col in (select col from user)", 3736 "Instructions": { 3737 "OperatorType": "Subquery", 3738 "Variant": "PulloutIn", 3739 "PulloutVars": [ 3740 "__sq_has_values1", 3741 "__sq1" 3742 ], 3743 "Inputs": [ 3744 { 3745 "OperatorType": "Route", 3746 "Variant": "Scatter", 3747 "Keyspace": { 3748 "Name": "user", 3749 "Sharded": true 3750 }, 3751 "FieldQuery": "select col from `user` where 1 != 1", 3752 "Query": "select col from `user`", 3753 "Table": "`user`" 3754 }, 3755 { 3756 "OperatorType": "Route", 3757 "Variant": "Unsharded", 3758 "Keyspace": { 3759 "Name": "main", 3760 "Sharded": false 3761 }, 3762 "FieldQuery": "select unsharded_a.col from unsharded_a, unsharded_b where 1 != 1", 3763 "Query": "select unsharded_a.col from unsharded_a, unsharded_b where :__sq_has_values1 = 1 and unsharded_a.col in ::__sq1", 3764 "Table": "unsharded_a, unsharded_b" 3765 } 3766 ] 3767 }, 3768 "TablesUsed": [ 3769 "main.unsharded_a", 3770 "main.unsharded_b", 3771 "user.user" 3772 ] 3773 } 3774 }, 3775 { 3776 "comment": "subquery in ON clause, with join primitives", 3777 "query": "select unsharded.col from unsharded join user on user.col in (select col from user)", 3778 "v3-plan": { 3779 "QueryType": "SELECT", 3780 "Original": "select unsharded.col from unsharded join user on user.col in (select col from user)", 3781 "Instructions": { 3782 "OperatorType": "Subquery", 3783 "Variant": "PulloutIn", 3784 "PulloutVars": [ 3785 "__sq_has_values1", 3786 "__sq1" 3787 ], 3788 "Inputs": [ 3789 { 3790 "OperatorType": "Route", 3791 "Variant": "Scatter", 3792 "Keyspace": { 3793 "Name": "user", 3794 "Sharded": true 3795 }, 3796 "FieldQuery": "select col from `user` where 1 != 1", 3797 "Query": "select col from `user`", 3798 "Table": "`user`" 3799 }, 3800 { 3801 "OperatorType": "Join", 3802 "Variant": "Join", 3803 "JoinColumnIndexes": "L:0", 3804 "TableName": "unsharded_`user`", 3805 "Inputs": [ 3806 { 3807 "OperatorType": "Route", 3808 "Variant": "Unsharded", 3809 "Keyspace": { 3810 "Name": "main", 3811 "Sharded": false 3812 }, 3813 "FieldQuery": "select unsharded.col from unsharded where 1 != 1", 3814 "Query": "select unsharded.col from unsharded", 3815 "Table": "unsharded" 3816 }, 3817 { 3818 "OperatorType": "Route", 3819 "Variant": "Scatter", 3820 "Keyspace": { 3821 "Name": "user", 3822 "Sharded": true 3823 }, 3824 "FieldQuery": "select 1 from `user` where 1 != 1", 3825 "Query": "select 1 from `user` where :__sq_has_values1 = 1 and `user`.col in ::__sq1", 3826 "Table": "`user`" 3827 } 3828 ] 3829 } 3830 ] 3831 } 3832 }, 3833 "gen4-plan": { 3834 "QueryType": "SELECT", 3835 "Original": "select unsharded.col from unsharded join user on user.col in (select col from user)", 3836 "Instructions": { 3837 "OperatorType": "Subquery", 3838 "Variant": "PulloutIn", 3839 "PulloutVars": [ 3840 "__sq_has_values1", 3841 "__sq1" 3842 ], 3843 "Inputs": [ 3844 { 3845 "OperatorType": "Route", 3846 "Variant": "Scatter", 3847 "Keyspace": { 3848 "Name": "user", 3849 "Sharded": true 3850 }, 3851 "FieldQuery": "select col from `user` where 1 != 1", 3852 "Query": "select col from `user`", 3853 "Table": "`user`" 3854 }, 3855 { 3856 "OperatorType": "Join", 3857 "Variant": "Join", 3858 "JoinColumnIndexes": "L:0", 3859 "TableName": "unsharded_`user`", 3860 "Inputs": [ 3861 { 3862 "OperatorType": "Route", 3863 "Variant": "Unsharded", 3864 "Keyspace": { 3865 "Name": "main", 3866 "Sharded": false 3867 }, 3868 "FieldQuery": "select unsharded.col from unsharded where 1 != 1", 3869 "Query": "select unsharded.col from unsharded", 3870 "Table": "unsharded" 3871 }, 3872 { 3873 "OperatorType": "Route", 3874 "Variant": "Scatter", 3875 "Keyspace": { 3876 "Name": "user", 3877 "Sharded": true 3878 }, 3879 "FieldQuery": "select 1 from `user` where 1 != 1", 3880 "Query": "select 1 from `user` where :__sq_has_values1 = 1 and `user`.col in ::__sq1", 3881 "Table": "`user`" 3882 } 3883 ] 3884 } 3885 ] 3886 }, 3887 "TablesUsed": [ 3888 "main.unsharded", 3889 "user.user" 3890 ] 3891 } 3892 }, 3893 { 3894 "comment": "subquery in ON clause, with left join primitives\n# The subquery is not pulled all the way out.", 3895 "query": "select unsharded.col from unsharded left join user on user.col in (select col from user)", 3896 "plan": { 3897 "QueryType": "SELECT", 3898 "Original": "select unsharded.col from unsharded left join user on user.col in (select col from user)", 3899 "Instructions": { 3900 "OperatorType": "Subquery", 3901 "Variant": "PulloutIn", 3902 "PulloutVars": [ 3903 "__sq_has_values1", 3904 "__sq1" 3905 ], 3906 "Inputs": [ 3907 { 3908 "OperatorType": "Route", 3909 "Variant": "Scatter", 3910 "Keyspace": { 3911 "Name": "user", 3912 "Sharded": true 3913 }, 3914 "FieldQuery": "select col from `user` where 1 != 1", 3915 "Query": "select col from `user`", 3916 "Table": "`user`" 3917 }, 3918 { 3919 "OperatorType": "Join", 3920 "Variant": "LeftJoin", 3921 "JoinColumnIndexes": "L:0", 3922 "TableName": "unsharded_`user`", 3923 "Inputs": [ 3924 { 3925 "OperatorType": "Route", 3926 "Variant": "Unsharded", 3927 "Keyspace": { 3928 "Name": "main", 3929 "Sharded": false 3930 }, 3931 "FieldQuery": "select unsharded.col from unsharded where 1 != 1", 3932 "Query": "select unsharded.col from unsharded", 3933 "Table": "unsharded" 3934 }, 3935 { 3936 "OperatorType": "Route", 3937 "Variant": "Scatter", 3938 "Keyspace": { 3939 "Name": "user", 3940 "Sharded": true 3941 }, 3942 "FieldQuery": "select 1 from `user` where 1 != 1", 3943 "Query": "select 1 from `user` where :__sq_has_values1 = 1 and `user`.col in ::__sq1", 3944 "Table": "`user`" 3945 } 3946 ] 3947 } 3948 ] 3949 }, 3950 "TablesUsed": [ 3951 "main.unsharded", 3952 "user.user" 3953 ] 3954 } 3955 }, 3956 { 3957 "comment": "subquery in ON clause, with join primitives, and join on top\n# The subquery is not pulled all the way out.", 3958 "query": "select unsharded.col from unsharded join user on user.col in (select col from user) join unsharded_a", 3959 "v3-plan": { 3960 "QueryType": "SELECT", 3961 "Original": "select unsharded.col from unsharded join user on user.col in (select col from user) join unsharded_a", 3962 "Instructions": { 3963 "OperatorType": "Join", 3964 "Variant": "Join", 3965 "JoinColumnIndexes": "L:0", 3966 "TableName": "unsharded_`user`_unsharded_a", 3967 "Inputs": [ 3968 { 3969 "OperatorType": "Subquery", 3970 "Variant": "PulloutIn", 3971 "PulloutVars": [ 3972 "__sq_has_values1", 3973 "__sq1" 3974 ], 3975 "Inputs": [ 3976 { 3977 "OperatorType": "Route", 3978 "Variant": "Scatter", 3979 "Keyspace": { 3980 "Name": "user", 3981 "Sharded": true 3982 }, 3983 "FieldQuery": "select col from `user` where 1 != 1", 3984 "Query": "select col from `user`", 3985 "Table": "`user`" 3986 }, 3987 { 3988 "OperatorType": "Join", 3989 "Variant": "Join", 3990 "JoinColumnIndexes": "L:0", 3991 "TableName": "unsharded_`user`", 3992 "Inputs": [ 3993 { 3994 "OperatorType": "Route", 3995 "Variant": "Unsharded", 3996 "Keyspace": { 3997 "Name": "main", 3998 "Sharded": false 3999 }, 4000 "FieldQuery": "select unsharded.col from unsharded where 1 != 1", 4001 "Query": "select unsharded.col from unsharded", 4002 "Table": "unsharded" 4003 }, 4004 { 4005 "OperatorType": "Route", 4006 "Variant": "Scatter", 4007 "Keyspace": { 4008 "Name": "user", 4009 "Sharded": true 4010 }, 4011 "FieldQuery": "select 1 from `user` where 1 != 1", 4012 "Query": "select 1 from `user` where :__sq_has_values1 = 1 and `user`.col in ::__sq1", 4013 "Table": "`user`" 4014 } 4015 ] 4016 } 4017 ] 4018 }, 4019 { 4020 "OperatorType": "Route", 4021 "Variant": "Unsharded", 4022 "Keyspace": { 4023 "Name": "main", 4024 "Sharded": false 4025 }, 4026 "FieldQuery": "select 1 from unsharded_a where 1 != 1", 4027 "Query": "select 1 from unsharded_a", 4028 "Table": "unsharded_a" 4029 } 4030 ] 4031 } 4032 }, 4033 "gen4-plan": { 4034 "QueryType": "SELECT", 4035 "Original": "select unsharded.col from unsharded join user on user.col in (select col from user) join unsharded_a", 4036 "Instructions": { 4037 "OperatorType": "Subquery", 4038 "Variant": "PulloutIn", 4039 "PulloutVars": [ 4040 "__sq_has_values1", 4041 "__sq1" 4042 ], 4043 "Inputs": [ 4044 { 4045 "OperatorType": "Route", 4046 "Variant": "Scatter", 4047 "Keyspace": { 4048 "Name": "user", 4049 "Sharded": true 4050 }, 4051 "FieldQuery": "select col from `user` where 1 != 1", 4052 "Query": "select col from `user`", 4053 "Table": "`user`" 4054 }, 4055 { 4056 "OperatorType": "Join", 4057 "Variant": "Join", 4058 "JoinColumnIndexes": "R:0", 4059 "TableName": "`user`_unsharded, unsharded_a", 4060 "Inputs": [ 4061 { 4062 "OperatorType": "Route", 4063 "Variant": "Scatter", 4064 "Keyspace": { 4065 "Name": "user", 4066 "Sharded": true 4067 }, 4068 "FieldQuery": "select 1 from `user` where 1 != 1", 4069 "Query": "select 1 from `user` where :__sq_has_values1 = 1 and `user`.col in ::__sq1", 4070 "Table": "`user`" 4071 }, 4072 { 4073 "OperatorType": "Route", 4074 "Variant": "Unsharded", 4075 "Keyspace": { 4076 "Name": "main", 4077 "Sharded": false 4078 }, 4079 "FieldQuery": "select unsharded.col from unsharded, unsharded_a where 1 != 1", 4080 "Query": "select unsharded.col from unsharded, unsharded_a", 4081 "Table": "unsharded, unsharded_a" 4082 } 4083 ] 4084 } 4085 ] 4086 }, 4087 "TablesUsed": [ 4088 "main.unsharded", 4089 "main.unsharded_a", 4090 "user.user" 4091 ] 4092 } 4093 }, 4094 { 4095 "comment": "keyspace-qualified queries", 4096 "query": "select user.user.col1, main.unsharded.col1 from user.user join main.unsharded where main.unsharded.col2 = user.user.col2", 4097 "v3-plan": { 4098 "QueryType": "SELECT", 4099 "Original": "select user.user.col1, main.unsharded.col1 from user.user join main.unsharded where main.unsharded.col2 = user.user.col2", 4100 "Instructions": { 4101 "OperatorType": "Join", 4102 "Variant": "Join", 4103 "JoinColumnIndexes": "L:0,R:0", 4104 "JoinVars": { 4105 "user_col2": 1 4106 }, 4107 "TableName": "`user`_unsharded", 4108 "Inputs": [ 4109 { 4110 "OperatorType": "Route", 4111 "Variant": "Scatter", 4112 "Keyspace": { 4113 "Name": "user", 4114 "Sharded": true 4115 }, 4116 "FieldQuery": "select `user`.col1, `user`.col2 from `user` where 1 != 1", 4117 "Query": "select `user`.col1, `user`.col2 from `user`", 4118 "Table": "`user`" 4119 }, 4120 { 4121 "OperatorType": "Route", 4122 "Variant": "Unsharded", 4123 "Keyspace": { 4124 "Name": "main", 4125 "Sharded": false 4126 }, 4127 "FieldQuery": "select unsharded.col1 from unsharded where 1 != 1", 4128 "Query": "select unsharded.col1 from unsharded where unsharded.col2 = :user_col2", 4129 "Table": "unsharded" 4130 } 4131 ] 4132 } 4133 }, 4134 "gen4-plan": { 4135 "QueryType": "SELECT", 4136 "Original": "select user.user.col1, main.unsharded.col1 from user.user join main.unsharded where main.unsharded.col2 = user.user.col2", 4137 "Instructions": { 4138 "OperatorType": "Join", 4139 "Variant": "Join", 4140 "JoinColumnIndexes": "L:1,R:0", 4141 "JoinVars": { 4142 "user_col2": 0 4143 }, 4144 "TableName": "`user`_unsharded", 4145 "Inputs": [ 4146 { 4147 "OperatorType": "Route", 4148 "Variant": "Scatter", 4149 "Keyspace": { 4150 "Name": "user", 4151 "Sharded": true 4152 }, 4153 "FieldQuery": "select `user`.col2, `user`.col1 from `user` where 1 != 1", 4154 "Query": "select `user`.col2, `user`.col1 from `user`", 4155 "Table": "`user`" 4156 }, 4157 { 4158 "OperatorType": "Route", 4159 "Variant": "Unsharded", 4160 "Keyspace": { 4161 "Name": "main", 4162 "Sharded": false 4163 }, 4164 "FieldQuery": "select unsharded.col1 from unsharded where 1 != 1", 4165 "Query": "select unsharded.col1 from unsharded where unsharded.col2 = :user_col2", 4166 "Table": "unsharded" 4167 } 4168 ] 4169 }, 4170 "TablesUsed": [ 4171 "main.unsharded", 4172 "user.user" 4173 ] 4174 } 4175 }, 4176 { 4177 "comment": "implicit table reference for unsharded keyspace", 4178 "query": "select main.foo.col from main.foo", 4179 "v3-plan": { 4180 "QueryType": "SELECT", 4181 "Original": "select main.foo.col from main.foo", 4182 "Instructions": { 4183 "OperatorType": "Route", 4184 "Variant": "Unsharded", 4185 "Keyspace": { 4186 "Name": "main", 4187 "Sharded": false 4188 }, 4189 "FieldQuery": "select foo.col from foo where 1 != 1", 4190 "Query": "select foo.col from foo", 4191 "Table": "foo" 4192 } 4193 }, 4194 "gen4-plan": { 4195 "QueryType": "SELECT", 4196 "Original": "select main.foo.col from main.foo", 4197 "Instructions": { 4198 "OperatorType": "Route", 4199 "Variant": "Unsharded", 4200 "Keyspace": { 4201 "Name": "main", 4202 "Sharded": false 4203 }, 4204 "FieldQuery": "select foo.col from foo where 1 != 1", 4205 "Query": "select foo.col from foo", 4206 "Table": "foo" 4207 }, 4208 "TablesUsed": [ 4209 "main.foo" 4210 ] 4211 } 4212 }, 4213 { 4214 "comment": "col refs should be case-insensitive", 4215 "query": "select user.col from user join user_extra on user.ID = user_extra.User_Id", 4216 "v3-plan": { 4217 "QueryType": "SELECT", 4218 "Original": "select user.col from user join user_extra on user.ID = user_extra.User_Id", 4219 "Instructions": { 4220 "OperatorType": "Route", 4221 "Variant": "Scatter", 4222 "Keyspace": { 4223 "Name": "user", 4224 "Sharded": true 4225 }, 4226 "FieldQuery": "select `user`.col from `user` join user_extra on `user`.ID = user_extra.User_Id where 1 != 1", 4227 "Query": "select `user`.col from `user` join user_extra on `user`.ID = user_extra.User_Id", 4228 "Table": "`user`, user_extra" 4229 } 4230 }, 4231 "gen4-plan": { 4232 "QueryType": "SELECT", 4233 "Original": "select user.col from user join user_extra on user.ID = user_extra.User_Id", 4234 "Instructions": { 4235 "OperatorType": "Route", 4236 "Variant": "Scatter", 4237 "Keyspace": { 4238 "Name": "user", 4239 "Sharded": true 4240 }, 4241 "FieldQuery": "select `user`.col from `user`, user_extra where 1 != 1", 4242 "Query": "select `user`.col from `user`, user_extra where `user`.ID = user_extra.User_Id", 4243 "Table": "`user`, user_extra" 4244 }, 4245 "TablesUsed": [ 4246 "user.user", 4247 "user.user_extra" 4248 ] 4249 } 4250 }, 4251 { 4252 "comment": "derived table with join primitive (FROM)", 4253 "query": "select id, t.id from (select user.id from user join user_extra) as t", 4254 "v3-plan": { 4255 "QueryType": "SELECT", 4256 "Original": "select id, t.id from (select user.id from user join user_extra) as t", 4257 "Instructions": { 4258 "OperatorType": "SimpleProjection", 4259 "Columns": [ 4260 0, 4261 0 4262 ], 4263 "Inputs": [ 4264 { 4265 "OperatorType": "Join", 4266 "Variant": "Join", 4267 "JoinColumnIndexes": "L:0", 4268 "TableName": "`user`_user_extra", 4269 "Inputs": [ 4270 { 4271 "OperatorType": "Route", 4272 "Variant": "Scatter", 4273 "Keyspace": { 4274 "Name": "user", 4275 "Sharded": true 4276 }, 4277 "FieldQuery": "select `user`.id from `user` where 1 != 1", 4278 "Query": "select `user`.id from `user`", 4279 "Table": "`user`" 4280 }, 4281 { 4282 "OperatorType": "Route", 4283 "Variant": "Scatter", 4284 "Keyspace": { 4285 "Name": "user", 4286 "Sharded": true 4287 }, 4288 "FieldQuery": "select 1 from user_extra where 1 != 1", 4289 "Query": "select 1 from user_extra", 4290 "Table": "user_extra" 4291 } 4292 ] 4293 } 4294 ] 4295 } 4296 }, 4297 "gen4-plan": { 4298 "QueryType": "SELECT", 4299 "Original": "select id, t.id from (select user.id from user join user_extra) as t", 4300 "Instructions": { 4301 "OperatorType": "SimpleProjection", 4302 "Columns": [ 4303 0, 4304 0 4305 ], 4306 "Inputs": [ 4307 { 4308 "OperatorType": "Join", 4309 "Variant": "Join", 4310 "JoinColumnIndexes": "L:0", 4311 "TableName": "`user`_user_extra", 4312 "Inputs": [ 4313 { 4314 "OperatorType": "Route", 4315 "Variant": "Scatter", 4316 "Keyspace": { 4317 "Name": "user", 4318 "Sharded": true 4319 }, 4320 "FieldQuery": "select `user`.id from `user` where 1 != 1", 4321 "Query": "select `user`.id from `user`", 4322 "Table": "`user`" 4323 }, 4324 { 4325 "OperatorType": "Route", 4326 "Variant": "Scatter", 4327 "Keyspace": { 4328 "Name": "user", 4329 "Sharded": true 4330 }, 4331 "FieldQuery": "select 1 from user_extra where 1 != 1", 4332 "Query": "select 1 from user_extra", 4333 "Table": "user_extra" 4334 } 4335 ] 4336 } 4337 ] 4338 }, 4339 "TablesUsed": [ 4340 "user.user", 4341 "user.user_extra" 4342 ] 4343 } 4344 }, 4345 { 4346 "comment": "database call in ON clause.\n# The on clause is weird because the substitution must even for root expressions.", 4347 "query": "select u1.a from unsharded u1 join unsharded u2 on database()", 4348 "v3-plan": { 4349 "QueryType": "SELECT", 4350 "Original": "select u1.a from unsharded u1 join unsharded u2 on database()", 4351 "Instructions": { 4352 "OperatorType": "Route", 4353 "Variant": "Unsharded", 4354 "Keyspace": { 4355 "Name": "main", 4356 "Sharded": false 4357 }, 4358 "FieldQuery": "select u1.a from unsharded as u1 join unsharded as u2 on database() where 1 != 1", 4359 "Query": "select u1.a from unsharded as u1 join unsharded as u2 on database()", 4360 "Table": "unsharded" 4361 } 4362 }, 4363 "gen4-plan": { 4364 "QueryType": "SELECT", 4365 "Original": "select u1.a from unsharded u1 join unsharded u2 on database()", 4366 "Instructions": { 4367 "OperatorType": "Route", 4368 "Variant": "Unsharded", 4369 "Keyspace": { 4370 "Name": "main", 4371 "Sharded": false 4372 }, 4373 "FieldQuery": "select u1.a from unsharded as u1 join unsharded as u2 on database() where 1 != 1", 4374 "Query": "select u1.a from unsharded as u1 join unsharded as u2 on database()", 4375 "Table": "unsharded" 4376 }, 4377 "TablesUsed": [ 4378 "main.unsharded" 4379 ] 4380 } 4381 }, 4382 { 4383 "comment": "last_insert_id for dual", 4384 "query": "select last_insert_id()", 4385 "v3-plan": { 4386 "QueryType": "SELECT", 4387 "Original": "select last_insert_id()", 4388 "Instructions": { 4389 "OperatorType": "Projection", 4390 "Expressions": [ 4391 ":__lastInsertId as last_insert_id()" 4392 ], 4393 "Inputs": [ 4394 { 4395 "OperatorType": "SingleRow" 4396 } 4397 ] 4398 } 4399 }, 4400 "gen4-plan": { 4401 "QueryType": "SELECT", 4402 "Original": "select last_insert_id()", 4403 "Instructions": { 4404 "OperatorType": "Projection", 4405 "Expressions": [ 4406 ":__lastInsertId as last_insert_id()" 4407 ], 4408 "Inputs": [ 4409 { 4410 "OperatorType": "SingleRow" 4411 } 4412 ] 4413 }, 4414 "TablesUsed": [ 4415 "main.dual" 4416 ] 4417 } 4418 }, 4419 { 4420 "comment": "last_insert_id for sharded keyspace", 4421 "query": "select last_insert_id() from user", 4422 "v3-plan": { 4423 "QueryType": "SELECT", 4424 "Original": "select last_insert_id() from user", 4425 "Instructions": { 4426 "OperatorType": "Route", 4427 "Variant": "Scatter", 4428 "Keyspace": { 4429 "Name": "user", 4430 "Sharded": true 4431 }, 4432 "FieldQuery": "select :__lastInsertId as `last_insert_id()` from `user` where 1 != 1", 4433 "Query": "select :__lastInsertId as `last_insert_id()` from `user`", 4434 "Table": "`user`" 4435 } 4436 }, 4437 "gen4-plan": { 4438 "QueryType": "SELECT", 4439 "Original": "select last_insert_id() from user", 4440 "Instructions": { 4441 "OperatorType": "Route", 4442 "Variant": "Scatter", 4443 "Keyspace": { 4444 "Name": "user", 4445 "Sharded": true 4446 }, 4447 "FieldQuery": "select :__lastInsertId as `last_insert_id()` from `user` where 1 != 1", 4448 "Query": "select :__lastInsertId as `last_insert_id()` from `user`", 4449 "Table": "`user`" 4450 }, 4451 "TablesUsed": [ 4452 "user.user" 4453 ] 4454 } 4455 }, 4456 { 4457 "comment": "last_insert_id for unsharded route", 4458 "query": "select last_insert_id() from main.unsharded", 4459 "v3-plan": { 4460 "QueryType": "SELECT", 4461 "Original": "select last_insert_id() from main.unsharded", 4462 "Instructions": { 4463 "OperatorType": "Route", 4464 "Variant": "Unsharded", 4465 "Keyspace": { 4466 "Name": "main", 4467 "Sharded": false 4468 }, 4469 "FieldQuery": "select :__lastInsertId as `last_insert_id()` from unsharded where 1 != 1", 4470 "Query": "select :__lastInsertId as `last_insert_id()` from unsharded", 4471 "Table": "unsharded" 4472 } 4473 }, 4474 "gen4-plan": { 4475 "QueryType": "SELECT", 4476 "Original": "select last_insert_id() from main.unsharded", 4477 "Instructions": { 4478 "OperatorType": "Route", 4479 "Variant": "Unsharded", 4480 "Keyspace": { 4481 "Name": "main", 4482 "Sharded": false 4483 }, 4484 "FieldQuery": "select :__lastInsertId as `last_insert_id()` from unsharded where 1 != 1", 4485 "Query": "select :__lastInsertId as `last_insert_id()` from unsharded", 4486 "Table": "unsharded" 4487 }, 4488 "TablesUsed": [ 4489 "main.unsharded" 4490 ] 4491 } 4492 }, 4493 { 4494 "comment": "join with bindvariables", 4495 "query": "SELECT `user`.`id` FROM `user` INNER JOIN `user_extra` ON `user`.`id` = `user_extra`.`assembly_id` WHERE `user_extra`.`user_id` = 2", 4496 "v3-plan": { 4497 "QueryType": "SELECT", 4498 "Original": "SELECT `user`.`id` FROM `user` INNER JOIN `user_extra` ON `user`.`id` = `user_extra`.`assembly_id` WHERE `user_extra`.`user_id` = 2", 4499 "Instructions": { 4500 "OperatorType": "Join", 4501 "Variant": "Join", 4502 "JoinColumnIndexes": "L:0", 4503 "JoinVars": { 4504 "user_id": 0 4505 }, 4506 "TableName": "`user`_user_extra", 4507 "Inputs": [ 4508 { 4509 "OperatorType": "Route", 4510 "Variant": "Scatter", 4511 "Keyspace": { 4512 "Name": "user", 4513 "Sharded": true 4514 }, 4515 "FieldQuery": "select `user`.id from `user` where 1 != 1", 4516 "Query": "select `user`.id from `user`", 4517 "Table": "`user`" 4518 }, 4519 { 4520 "OperatorType": "Route", 4521 "Variant": "EqualUnique", 4522 "Keyspace": { 4523 "Name": "user", 4524 "Sharded": true 4525 }, 4526 "FieldQuery": "select 1 from user_extra where 1 != 1", 4527 "Query": "select 1 from user_extra where user_extra.assembly_id = :user_id and user_extra.user_id = 2", 4528 "Table": "user_extra", 4529 "Values": [ 4530 "INT64(2)" 4531 ], 4532 "Vindex": "user_index" 4533 } 4534 ] 4535 } 4536 }, 4537 "gen4-plan": { 4538 "QueryType": "SELECT", 4539 "Original": "SELECT `user`.`id` FROM `user` INNER JOIN `user_extra` ON `user`.`id` = `user_extra`.`assembly_id` WHERE `user_extra`.`user_id` = 2", 4540 "Instructions": { 4541 "OperatorType": "Join", 4542 "Variant": "Join", 4543 "JoinColumnIndexes": "R:0", 4544 "JoinVars": { 4545 "user_extra_assembly_id": 0 4546 }, 4547 "TableName": "user_extra_`user`", 4548 "Inputs": [ 4549 { 4550 "OperatorType": "Route", 4551 "Variant": "EqualUnique", 4552 "Keyspace": { 4553 "Name": "user", 4554 "Sharded": true 4555 }, 4556 "FieldQuery": "select user_extra.assembly_id from user_extra where 1 != 1", 4557 "Query": "select user_extra.assembly_id from user_extra where user_extra.user_id = 2", 4558 "Table": "user_extra", 4559 "Values": [ 4560 "INT64(2)" 4561 ], 4562 "Vindex": "user_index" 4563 }, 4564 { 4565 "OperatorType": "Route", 4566 "Variant": "EqualUnique", 4567 "Keyspace": { 4568 "Name": "user", 4569 "Sharded": true 4570 }, 4571 "FieldQuery": "select `user`.id from `user` where 1 != 1", 4572 "Query": "select `user`.id from `user` where `user`.id = :user_extra_assembly_id", 4573 "Table": "`user`", 4574 "Values": [ 4575 ":user_extra_assembly_id" 4576 ], 4577 "Vindex": "user_index" 4578 } 4579 ] 4580 }, 4581 "TablesUsed": [ 4582 "user.user", 4583 "user.user_extra" 4584 ] 4585 } 4586 }, 4587 { 4588 "comment": "verify ',' vs JOIN precedence", 4589 "query": "select u1.a from unsharded u1, unsharded u2 join unsharded u3 on u1.a = u2.a", 4590 "v3-plan": "VT03019: symbol u1.a not found", 4591 "gen4-plan": { 4592 "QueryType": "SELECT", 4593 "Original": "select u1.a from unsharded u1, unsharded u2 join unsharded u3 on u1.a = u2.a", 4594 "Instructions": { 4595 "OperatorType": "Route", 4596 "Variant": "Unsharded", 4597 "Keyspace": { 4598 "Name": "main", 4599 "Sharded": false 4600 }, 4601 "FieldQuery": "select u1.a from unsharded as u1, unsharded as u2 join unsharded as u3 on u1.a = u2.a where 1 != 1", 4602 "Query": "select u1.a from unsharded as u1, unsharded as u2 join unsharded as u3 on u1.a = u2.a", 4603 "Table": "unsharded" 4604 }, 4605 "TablesUsed": [ 4606 "main.unsharded" 4607 ] 4608 } 4609 }, 4610 { 4611 "comment": "first expression fails for ',' join (code coverage: ensure error is returned)", 4612 "query": "select user.foo.col from user.foo, user", 4613 "plan": "table foo not found" 4614 }, 4615 { 4616 "comment": "table names should be case-sensitive", 4617 "query": "select unsharded.id from unsharded where Unsharded.val = 1", 4618 "v3-plan": "VT03019: symbol Unsharded.val not found", 4619 "gen4-plan": { 4620 "QueryType": "SELECT", 4621 "Original": "select unsharded.id from unsharded where Unsharded.val = 1", 4622 "Instructions": { 4623 "OperatorType": "Route", 4624 "Variant": "Unsharded", 4625 "Keyspace": { 4626 "Name": "main", 4627 "Sharded": false 4628 }, 4629 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 4630 "Query": "select unsharded.id from unsharded where Unsharded.val = 1", 4631 "Table": "unsharded" 4632 }, 4633 "TablesUsed": [ 4634 "main.unsharded" 4635 ] 4636 } 4637 }, 4638 { 4639 "comment": "implicit table reference for sharded keyspace", 4640 "query": "select user.foo.col from user.foo", 4641 "plan": "table foo not found" 4642 }, 4643 { 4644 "comment": "duplicate symbols", 4645 "query": "select user.id from user join user", 4646 "plan": "VT03013: not unique table/alias: 'user'" 4647 }, 4648 { 4649 "comment": "duplicate symbols for merging routes", 4650 "query": "select user.id from user join user_extra user on user.id = user.user_id", 4651 "plan": "VT03013: not unique table/alias: 'user'" 4652 }, 4653 { 4654 "comment": "non-existent table", 4655 "query": "select c from t", 4656 "plan": "table t not found" 4657 }, 4658 { 4659 "comment": "non-existent table on left of join", 4660 "query": "select c from t join user", 4661 "plan": "table t not found" 4662 }, 4663 { 4664 "comment": "non-existent table on right of join", 4665 "query": "select c from user join t", 4666 "plan": "table t not found" 4667 }, 4668 { 4669 "comment": "query with parens is planned correctly", 4670 "query": "select m1.col from (unsharded as m1, unsharded as m2)", 4671 "v3-plan": { 4672 "QueryType": "SELECT", 4673 "Original": "select m1.col from (unsharded as m1, unsharded as m2)", 4674 "Instructions": { 4675 "OperatorType": "Route", 4676 "Variant": "Unsharded", 4677 "Keyspace": { 4678 "Name": "main", 4679 "Sharded": false 4680 }, 4681 "FieldQuery": "select m1.col from (unsharded as m1, unsharded as m2) where 1 != 1", 4682 "Query": "select m1.col from (unsharded as m1, unsharded as m2)", 4683 "Table": "unsharded" 4684 } 4685 }, 4686 "gen4-plan": { 4687 "QueryType": "SELECT", 4688 "Original": "select m1.col from (unsharded as m1, unsharded as m2)", 4689 "Instructions": { 4690 "OperatorType": "Route", 4691 "Variant": "Unsharded", 4692 "Keyspace": { 4693 "Name": "main", 4694 "Sharded": false 4695 }, 4696 "FieldQuery": "select m1.col from (unsharded as m1, unsharded as m2) where 1 != 1", 4697 "Query": "select m1.col from (unsharded as m1, unsharded as m2)", 4698 "Table": "unsharded" 4699 }, 4700 "TablesUsed": [ 4701 "main.unsharded" 4702 ] 4703 } 4704 }, 4705 { 4706 "comment": "gen4 - optimise plan by merging user_extra and music first, and then querying for user info", 4707 "query": "select 1 from user u join user_extra ue on ue.id = u.id join music m on m.user_id = ue.user_id", 4708 "v3-plan": { 4709 "QueryType": "SELECT", 4710 "Original": "select 1 from user u join user_extra ue on ue.id = u.id join music m on m.user_id = ue.user_id", 4711 "Instructions": { 4712 "OperatorType": "Join", 4713 "Variant": "Join", 4714 "JoinColumnIndexes": "L:0", 4715 "JoinVars": { 4716 "ue_user_id": 1 4717 }, 4718 "TableName": "`user`_user_extra_music", 4719 "Inputs": [ 4720 { 4721 "OperatorType": "Join", 4722 "Variant": "Join", 4723 "JoinColumnIndexes": "L:0,R:0", 4724 "JoinVars": { 4725 "u_id": 1 4726 }, 4727 "TableName": "`user`_user_extra", 4728 "Inputs": [ 4729 { 4730 "OperatorType": "Route", 4731 "Variant": "Scatter", 4732 "Keyspace": { 4733 "Name": "user", 4734 "Sharded": true 4735 }, 4736 "FieldQuery": "select 1, u.id from `user` as u where 1 != 1", 4737 "Query": "select 1, u.id from `user` as u", 4738 "Table": "`user`" 4739 }, 4740 { 4741 "OperatorType": "Route", 4742 "Variant": "Scatter", 4743 "Keyspace": { 4744 "Name": "user", 4745 "Sharded": true 4746 }, 4747 "FieldQuery": "select ue.user_id from user_extra as ue where 1 != 1", 4748 "Query": "select ue.user_id from user_extra as ue where ue.id = :u_id", 4749 "Table": "user_extra" 4750 } 4751 ] 4752 }, 4753 { 4754 "OperatorType": "Route", 4755 "Variant": "EqualUnique", 4756 "Keyspace": { 4757 "Name": "user", 4758 "Sharded": true 4759 }, 4760 "FieldQuery": "select 1 from music as m where 1 != 1", 4761 "Query": "select 1 from music as m where m.user_id = :ue_user_id", 4762 "Table": "music", 4763 "Values": [ 4764 ":ue_user_id" 4765 ], 4766 "Vindex": "user_index" 4767 } 4768 ] 4769 } 4770 }, 4771 "gen4-plan": { 4772 "QueryType": "SELECT", 4773 "Original": "select 1 from user u join user_extra ue on ue.id = u.id join music m on m.user_id = ue.user_id", 4774 "Instructions": { 4775 "OperatorType": "Join", 4776 "Variant": "Join", 4777 "JoinColumnIndexes": "L:1", 4778 "JoinVars": { 4779 "ue_id": 0 4780 }, 4781 "TableName": "music, user_extra_`user`", 4782 "Inputs": [ 4783 { 4784 "OperatorType": "Route", 4785 "Variant": "Scatter", 4786 "Keyspace": { 4787 "Name": "user", 4788 "Sharded": true 4789 }, 4790 "FieldQuery": "select ue.id, 1 from user_extra as ue, music as m where 1 != 1", 4791 "Query": "select ue.id, 1 from user_extra as ue, music as m where m.user_id = ue.user_id", 4792 "Table": "music, user_extra" 4793 }, 4794 { 4795 "OperatorType": "Route", 4796 "Variant": "EqualUnique", 4797 "Keyspace": { 4798 "Name": "user", 4799 "Sharded": true 4800 }, 4801 "FieldQuery": "select 1 from `user` as u where 1 != 1", 4802 "Query": "select 1 from `user` as u where u.id = :ue_id", 4803 "Table": "`user`", 4804 "Values": [ 4805 ":ue_id" 4806 ], 4807 "Vindex": "user_index" 4808 } 4809 ] 4810 }, 4811 "TablesUsed": [ 4812 "user.music", 4813 "user.user", 4814 "user.user_extra" 4815 ] 4816 } 4817 }, 4818 { 4819 "comment": "join column selected as alias", 4820 "query": "SELECT u.id as uid, ue.id as ueid FROM user u join user_extra ue where u.id = ue.id", 4821 "v3-plan": { 4822 "QueryType": "SELECT", 4823 "Original": "SELECT u.id as uid, ue.id as ueid FROM user u join user_extra ue where u.id = ue.id", 4824 "Instructions": { 4825 "OperatorType": "Join", 4826 "Variant": "Join", 4827 "JoinColumnIndexes": "L:0,R:0", 4828 "JoinVars": { 4829 "u_id": 0 4830 }, 4831 "TableName": "`user`_user_extra", 4832 "Inputs": [ 4833 { 4834 "OperatorType": "Route", 4835 "Variant": "Scatter", 4836 "Keyspace": { 4837 "Name": "user", 4838 "Sharded": true 4839 }, 4840 "FieldQuery": "select u.id as uid from `user` as u where 1 != 1", 4841 "Query": "select u.id as uid from `user` as u", 4842 "Table": "`user`" 4843 }, 4844 { 4845 "OperatorType": "Route", 4846 "Variant": "Scatter", 4847 "Keyspace": { 4848 "Name": "user", 4849 "Sharded": true 4850 }, 4851 "FieldQuery": "select ue.id as ueid from user_extra as ue where 1 != 1", 4852 "Query": "select ue.id as ueid from user_extra as ue where ue.id = :u_id", 4853 "Table": "user_extra" 4854 } 4855 ] 4856 } 4857 }, 4858 "gen4-plan": { 4859 "QueryType": "SELECT", 4860 "Original": "SELECT u.id as uid, ue.id as ueid FROM user u join user_extra ue where u.id = ue.id", 4861 "Instructions": { 4862 "OperatorType": "Join", 4863 "Variant": "Join", 4864 "JoinColumnIndexes": "R:0,L:1", 4865 "JoinVars": { 4866 "ue_id": 0 4867 }, 4868 "TableName": "user_extra_`user`", 4869 "Inputs": [ 4870 { 4871 "OperatorType": "Route", 4872 "Variant": "Scatter", 4873 "Keyspace": { 4874 "Name": "user", 4875 "Sharded": true 4876 }, 4877 "FieldQuery": "select ue.id, ue.id as ueid from user_extra as ue where 1 != 1", 4878 "Query": "select ue.id, ue.id as ueid from user_extra as ue", 4879 "Table": "user_extra" 4880 }, 4881 { 4882 "OperatorType": "Route", 4883 "Variant": "EqualUnique", 4884 "Keyspace": { 4885 "Name": "user", 4886 "Sharded": true 4887 }, 4888 "FieldQuery": "select u.id as uid from `user` as u where 1 != 1", 4889 "Query": "select u.id as uid from `user` as u where u.id = :ue_id", 4890 "Table": "`user`", 4891 "Values": [ 4892 ":ue_id" 4893 ], 4894 "Vindex": "user_index" 4895 } 4896 ] 4897 }, 4898 "TablesUsed": [ 4899 "user.user", 4900 "user.user_extra" 4901 ] 4902 } 4903 }, 4904 { 4905 "comment": "alias on column from derived table. TODO: to support alias in SimpleProjection engine primitive.", 4906 "query": "select a as k from (select count(*) as a from user) t", 4907 "v3-plan": { 4908 "QueryType": "SELECT", 4909 "Original": "select a as k from (select count(*) as a from user) t", 4910 "Instructions": { 4911 "OperatorType": "SimpleProjection", 4912 "Columns": [ 4913 0 4914 ], 4915 "Inputs": [ 4916 { 4917 "OperatorType": "Aggregate", 4918 "Variant": "Scalar", 4919 "Aggregates": "sum_count(0) AS count", 4920 "Inputs": [ 4921 { 4922 "OperatorType": "Route", 4923 "Variant": "Scatter", 4924 "Keyspace": { 4925 "Name": "user", 4926 "Sharded": true 4927 }, 4928 "FieldQuery": "select count(*) as a from `user` where 1 != 1", 4929 "Query": "select count(*) as a from `user`", 4930 "Table": "`user`" 4931 } 4932 ] 4933 } 4934 ] 4935 } 4936 }, 4937 "gen4-plan": { 4938 "QueryType": "SELECT", 4939 "Original": "select a as k from (select count(*) as a from user) t", 4940 "Instructions": { 4941 "OperatorType": "SimpleProjection", 4942 "Columns": [ 4943 0 4944 ], 4945 "Inputs": [ 4946 { 4947 "OperatorType": "Aggregate", 4948 "Variant": "Scalar", 4949 "Aggregates": "sum_count_star(0) AS a", 4950 "Inputs": [ 4951 { 4952 "OperatorType": "Route", 4953 "Variant": "Scatter", 4954 "Keyspace": { 4955 "Name": "user", 4956 "Sharded": true 4957 }, 4958 "FieldQuery": "select count(*) as a from `user` where 1 != 1", 4959 "Query": "select count(*) as a from `user`", 4960 "Table": "`user`" 4961 } 4962 ] 4963 } 4964 ] 4965 }, 4966 "TablesUsed": [ 4967 "user.user" 4968 ] 4969 } 4970 }, 4971 { 4972 "comment": "select star from derived table on expandable and unsharded table", 4973 "query": "select u.* from (select * from unsharded) u", 4974 "v3-plan": { 4975 "QueryType": "SELECT", 4976 "Original": "select u.* from (select * from unsharded) u", 4977 "Instructions": { 4978 "OperatorType": "Route", 4979 "Variant": "Unsharded", 4980 "Keyspace": { 4981 "Name": "main", 4982 "Sharded": false 4983 }, 4984 "FieldQuery": "select u.* from (select * from unsharded where 1 != 1) as u where 1 != 1", 4985 "Query": "select u.* from (select * from unsharded) as u", 4986 "Table": "unsharded" 4987 } 4988 }, 4989 "gen4-plan": { 4990 "QueryType": "SELECT", 4991 "Original": "select u.* from (select * from unsharded) u", 4992 "Instructions": { 4993 "OperatorType": "Route", 4994 "Variant": "Unsharded", 4995 "Keyspace": { 4996 "Name": "main", 4997 "Sharded": false 4998 }, 4999 "FieldQuery": "select u.* from (select * from unsharded where 1 != 1) as u where 1 != 1", 5000 "Query": "select u.* from (select * from unsharded) as u", 5001 "Table": "unsharded" 5002 }, 5003 "TablesUsed": [ 5004 "main.unsharded" 5005 ] 5006 } 5007 }, 5008 { 5009 "comment": "filtering on a cross-shard derived table", 5010 "query": "select id from (select user.id, user.col from user join user_extra) as t where id=5", 5011 "v3-plan": "VT12001: unsupported: filtering on results of cross-shard subquery", 5012 "gen4-plan": { 5013 "QueryType": "SELECT", 5014 "Original": "select id from (select user.id, user.col from user join user_extra) as t where id=5", 5015 "Instructions": { 5016 "OperatorType": "SimpleProjection", 5017 "Columns": [ 5018 0 5019 ], 5020 "Inputs": [ 5021 { 5022 "OperatorType": "Join", 5023 "Variant": "Join", 5024 "JoinColumnIndexes": "L:0,L:1", 5025 "TableName": "`user`_user_extra", 5026 "Inputs": [ 5027 { 5028 "OperatorType": "Route", 5029 "Variant": "EqualUnique", 5030 "Keyspace": { 5031 "Name": "user", 5032 "Sharded": true 5033 }, 5034 "FieldQuery": "select `user`.id, `user`.col from `user` where 1 != 1", 5035 "Query": "select `user`.id, `user`.col from `user` where `user`.id = 5", 5036 "Table": "`user`", 5037 "Values": [ 5038 "INT64(5)" 5039 ], 5040 "Vindex": "user_index" 5041 }, 5042 { 5043 "OperatorType": "Route", 5044 "Variant": "Scatter", 5045 "Keyspace": { 5046 "Name": "user", 5047 "Sharded": true 5048 }, 5049 "FieldQuery": "select 1 from user_extra where 1 != 1", 5050 "Query": "select 1 from user_extra", 5051 "Table": "user_extra" 5052 } 5053 ] 5054 } 5055 ] 5056 }, 5057 "TablesUsed": [ 5058 "user.user", 5059 "user.user_extra" 5060 ] 5061 } 5062 }, 5063 { 5064 "comment": "expression on a cross-shard derived table", 5065 "query": "select id+1 from (select user.id, user.col from user join user_extra) as t", 5066 "v3-plan": "VT12001: unsupported: expression on results of a cross-shard subquery", 5067 "gen4-plan": { 5068 "QueryType": "SELECT", 5069 "Original": "select id+1 from (select user.id, user.col from user join user_extra) as t", 5070 "Instructions": { 5071 "OperatorType": "SimpleProjection", 5072 "Columns": [ 5073 2 5074 ], 5075 "Inputs": [ 5076 { 5077 "OperatorType": "Join", 5078 "Variant": "Join", 5079 "JoinColumnIndexes": "L:0,L:1,L:2", 5080 "TableName": "`user`_user_extra", 5081 "Inputs": [ 5082 { 5083 "OperatorType": "Route", 5084 "Variant": "Scatter", 5085 "Keyspace": { 5086 "Name": "user", 5087 "Sharded": true 5088 }, 5089 "FieldQuery": "select `user`.id, `user`.col, `user`.id + 1 from `user` where 1 != 1", 5090 "Query": "select `user`.id, `user`.col, `user`.id + 1 from `user`", 5091 "Table": "`user`" 5092 }, 5093 { 5094 "OperatorType": "Route", 5095 "Variant": "Scatter", 5096 "Keyspace": { 5097 "Name": "user", 5098 "Sharded": true 5099 }, 5100 "FieldQuery": "select 1 from user_extra where 1 != 1", 5101 "Query": "select 1 from user_extra", 5102 "Table": "user_extra" 5103 } 5104 ] 5105 } 5106 ] 5107 }, 5108 "TablesUsed": [ 5109 "user.user", 5110 "user.user_extra" 5111 ] 5112 } 5113 }, 5114 { 5115 "comment": "derived table with aliased columns and outer predicate pushed in derived table", 5116 "query": "select u.a from (select id as b, name from user) u(a, n) where u.n = 1", 5117 "v3-plan": "VT12001: unsupported: column aliases in derived table", 5118 "gen4-plan": { 5119 "QueryType": "SELECT", 5120 "Original": "select u.a from (select id as b, name from user) u(a, n) where u.n = 1", 5121 "Instructions": { 5122 "OperatorType": "VindexLookup", 5123 "Variant": "Equal", 5124 "Keyspace": { 5125 "Name": "user", 5126 "Sharded": true 5127 }, 5128 "Values": [ 5129 "INT64(1)" 5130 ], 5131 "Vindex": "name_user_map", 5132 "Inputs": [ 5133 { 5134 "OperatorType": "Route", 5135 "Variant": "IN", 5136 "Keyspace": { 5137 "Name": "user", 5138 "Sharded": true 5139 }, 5140 "FieldQuery": "select `name`, keyspace_id from name_user_vdx where 1 != 1", 5141 "Query": "select `name`, keyspace_id from name_user_vdx where `name` in ::__vals", 5142 "Table": "name_user_vdx", 5143 "Values": [ 5144 ":name" 5145 ], 5146 "Vindex": "user_index" 5147 }, 5148 { 5149 "OperatorType": "Route", 5150 "Variant": "ByDestination", 5151 "Keyspace": { 5152 "Name": "user", 5153 "Sharded": true 5154 }, 5155 "FieldQuery": "select u.a from (select id as b, `name` from `user` where 1 != 1) as u(a, n) where 1 != 1", 5156 "Query": "select u.a from (select id as b, `name` from `user` where `name` = 1) as u(a, n)", 5157 "Table": "`user`" 5158 } 5159 ] 5160 }, 5161 "TablesUsed": [ 5162 "user.user" 5163 ] 5164 } 5165 }, 5166 { 5167 "comment": "derived table with aliased columns predicate in both the outer and inner", 5168 "query": "select u.a from (select id as b, name from user where b = 1) u(a, n) where u.n = 1", 5169 "v3-plan": "VT12001: unsupported: column aliases in derived table", 5170 "gen4-plan": { 5171 "QueryType": "SELECT", 5172 "Original": "select u.a from (select id as b, name from user where b = 1) u(a, n) where u.n = 1", 5173 "Instructions": { 5174 "OperatorType": "VindexLookup", 5175 "Variant": "Equal", 5176 "Keyspace": { 5177 "Name": "user", 5178 "Sharded": true 5179 }, 5180 "Values": [ 5181 "INT64(1)" 5182 ], 5183 "Vindex": "name_user_map", 5184 "Inputs": [ 5185 { 5186 "OperatorType": "Route", 5187 "Variant": "IN", 5188 "Keyspace": { 5189 "Name": "user", 5190 "Sharded": true 5191 }, 5192 "FieldQuery": "select `name`, keyspace_id from name_user_vdx where 1 != 1", 5193 "Query": "select `name`, keyspace_id from name_user_vdx where `name` in ::__vals", 5194 "Table": "name_user_vdx", 5195 "Values": [ 5196 ":name" 5197 ], 5198 "Vindex": "user_index" 5199 }, 5200 { 5201 "OperatorType": "Route", 5202 "Variant": "ByDestination", 5203 "Keyspace": { 5204 "Name": "user", 5205 "Sharded": true 5206 }, 5207 "FieldQuery": "select u.a from (select id as b, `name` from `user` where 1 != 1) as u(a, n) where 1 != 1", 5208 "Query": "select u.a from (select id as b, `name` from `user` where b = 1 and `name` = 1) as u(a, n)", 5209 "Table": "`user`" 5210 } 5211 ] 5212 }, 5213 "TablesUsed": [ 5214 "user.user" 5215 ] 5216 } 5217 }, 5218 { 5219 "comment": "derived table with aliased columns and a join that requires pushProjection", 5220 "query": "select i+1 from (select user.id from user join user_extra) t(i)", 5221 "v3-plan": "VT12001: unsupported: column aliases in derived table", 5222 "gen4-plan": { 5223 "QueryType": "SELECT", 5224 "Original": "select i+1 from (select user.id from user join user_extra) t(i)", 5225 "Instructions": { 5226 "OperatorType": "SimpleProjection", 5227 "Columns": [ 5228 1 5229 ], 5230 "Inputs": [ 5231 { 5232 "OperatorType": "Join", 5233 "Variant": "Join", 5234 "JoinColumnIndexes": "L:0,L:1", 5235 "TableName": "`user`_user_extra", 5236 "Inputs": [ 5237 { 5238 "OperatorType": "Route", 5239 "Variant": "Scatter", 5240 "Keyspace": { 5241 "Name": "user", 5242 "Sharded": true 5243 }, 5244 "FieldQuery": "select `user`.id, `user`.id + 1 from `user` where 1 != 1", 5245 "Query": "select `user`.id, `user`.id + 1 from `user`", 5246 "Table": "`user`" 5247 }, 5248 { 5249 "OperatorType": "Route", 5250 "Variant": "Scatter", 5251 "Keyspace": { 5252 "Name": "user", 5253 "Sharded": true 5254 }, 5255 "FieldQuery": "select 1 from user_extra where 1 != 1", 5256 "Query": "select 1 from user_extra", 5257 "Table": "user_extra" 5258 } 5259 ] 5260 } 5261 ] 5262 }, 5263 "TablesUsed": [ 5264 "user.user", 5265 "user.user_extra" 5266 ] 5267 } 5268 }, 5269 { 5270 "comment": "two subqueries with different Select and OpCode", 5271 "query": "select id from user where id in (select id from user_extra) and col = (select user_id from user_extra limit 1)", 5272 "v3-plan": { 5273 "QueryType": "SELECT", 5274 "Original": "select id from user where id in (select id from user_extra) and col = (select user_id from user_extra limit 1)", 5275 "Instructions": { 5276 "OperatorType": "Subquery", 5277 "Variant": "PulloutIn", 5278 "PulloutVars": [ 5279 "__sq_has_values2", 5280 "__sq2" 5281 ], 5282 "Inputs": [ 5283 { 5284 "OperatorType": "Route", 5285 "Variant": "Scatter", 5286 "Keyspace": { 5287 "Name": "user", 5288 "Sharded": true 5289 }, 5290 "FieldQuery": "select id from user_extra where 1 != 1", 5291 "Query": "select id from user_extra", 5292 "Table": "user_extra" 5293 }, 5294 { 5295 "OperatorType": "Subquery", 5296 "Variant": "PulloutValue", 5297 "PulloutVars": [ 5298 "__sq_has_values1", 5299 "__sq1" 5300 ], 5301 "Inputs": [ 5302 { 5303 "OperatorType": "Limit", 5304 "Count": "INT64(1)", 5305 "Inputs": [ 5306 { 5307 "OperatorType": "Route", 5308 "Variant": "Scatter", 5309 "Keyspace": { 5310 "Name": "user", 5311 "Sharded": true 5312 }, 5313 "FieldQuery": "select user_id from user_extra where 1 != 1", 5314 "Query": "select user_id from user_extra limit :__upper_limit", 5315 "Table": "user_extra" 5316 } 5317 ] 5318 }, 5319 { 5320 "OperatorType": "Route", 5321 "Variant": "IN", 5322 "Keyspace": { 5323 "Name": "user", 5324 "Sharded": true 5325 }, 5326 "FieldQuery": "select id from `user` where 1 != 1", 5327 "Query": "select id from `user` where col = :__sq1 and :__sq_has_values2 = 1 and id in ::__vals", 5328 "Table": "`user`", 5329 "Values": [ 5330 ":__sq2" 5331 ], 5332 "Vindex": "user_index" 5333 } 5334 ] 5335 } 5336 ] 5337 } 5338 }, 5339 "gen4-plan": { 5340 "QueryType": "SELECT", 5341 "Original": "select id from user where id in (select id from user_extra) and col = (select user_id from user_extra limit 1)", 5342 "Instructions": { 5343 "OperatorType": "Subquery", 5344 "Variant": "PulloutValue", 5345 "PulloutVars": [ 5346 "__sq_has_values2", 5347 "__sq2" 5348 ], 5349 "Inputs": [ 5350 { 5351 "OperatorType": "Limit", 5352 "Count": "INT64(1)", 5353 "Inputs": [ 5354 { 5355 "OperatorType": "Route", 5356 "Variant": "Scatter", 5357 "Keyspace": { 5358 "Name": "user", 5359 "Sharded": true 5360 }, 5361 "FieldQuery": "select user_id from user_extra where 1 != 1", 5362 "Query": "select user_id from user_extra limit :__upper_limit", 5363 "Table": "user_extra" 5364 } 5365 ] 5366 }, 5367 { 5368 "OperatorType": "Subquery", 5369 "Variant": "PulloutIn", 5370 "PulloutVars": [ 5371 "__sq_has_values1", 5372 "__sq1" 5373 ], 5374 "Inputs": [ 5375 { 5376 "OperatorType": "Route", 5377 "Variant": "Scatter", 5378 "Keyspace": { 5379 "Name": "user", 5380 "Sharded": true 5381 }, 5382 "FieldQuery": "select id from user_extra where 1 != 1", 5383 "Query": "select id from user_extra", 5384 "Table": "user_extra" 5385 }, 5386 { 5387 "OperatorType": "Route", 5388 "Variant": "IN", 5389 "Keyspace": { 5390 "Name": "user", 5391 "Sharded": true 5392 }, 5393 "FieldQuery": "select id from `user` where 1 != 1", 5394 "Query": "select id from `user` where :__sq_has_values1 = 1 and id in ::__vals and col = :__sq2", 5395 "Table": "`user`", 5396 "Values": [ 5397 ":__sq1" 5398 ], 5399 "Vindex": "user_index" 5400 } 5401 ] 5402 } 5403 ] 5404 }, 5405 "TablesUsed": [ 5406 "user.user", 5407 "user.user_extra" 5408 ] 5409 } 5410 }, 5411 { 5412 "comment": "join on int columns", 5413 "query": "select u.id from user as u join user as uu on u.intcol = uu.intcol", 5414 "v3-plan": { 5415 "QueryType": "SELECT", 5416 "Original": "select u.id from user as u join user as uu on u.intcol = uu.intcol", 5417 "Instructions": { 5418 "OperatorType": "Join", 5419 "Variant": "Join", 5420 "JoinColumnIndexes": "L:0", 5421 "JoinVars": { 5422 "u_intcol": 1 5423 }, 5424 "TableName": "`user`_`user`", 5425 "Inputs": [ 5426 { 5427 "OperatorType": "Route", 5428 "Variant": "Scatter", 5429 "Keyspace": { 5430 "Name": "user", 5431 "Sharded": true 5432 }, 5433 "FieldQuery": "select u.id, u.intcol from `user` as u where 1 != 1", 5434 "Query": "select u.id, u.intcol from `user` as u", 5435 "Table": "`user`" 5436 }, 5437 { 5438 "OperatorType": "Route", 5439 "Variant": "Scatter", 5440 "Keyspace": { 5441 "Name": "user", 5442 "Sharded": true 5443 }, 5444 "FieldQuery": "select 1 from `user` as uu where 1 != 1", 5445 "Query": "select 1 from `user` as uu where uu.intcol = :u_intcol", 5446 "Table": "`user`" 5447 } 5448 ] 5449 } 5450 }, 5451 "gen4-plan": { 5452 "QueryType": "SELECT", 5453 "Original": "select u.id from user as u join user as uu on u.intcol = uu.intcol", 5454 "Instructions": { 5455 "OperatorType": "Join", 5456 "Variant": "Join", 5457 "JoinColumnIndexes": "L:1", 5458 "JoinVars": { 5459 "u_intcol": 0 5460 }, 5461 "TableName": "`user`_`user`", 5462 "Inputs": [ 5463 { 5464 "OperatorType": "Route", 5465 "Variant": "Scatter", 5466 "Keyspace": { 5467 "Name": "user", 5468 "Sharded": true 5469 }, 5470 "FieldQuery": "select u.intcol, u.id from `user` as u where 1 != 1", 5471 "Query": "select u.intcol, u.id from `user` as u", 5472 "Table": "`user`" 5473 }, 5474 { 5475 "OperatorType": "Route", 5476 "Variant": "Scatter", 5477 "Keyspace": { 5478 "Name": "user", 5479 "Sharded": true 5480 }, 5481 "FieldQuery": "select 1 from `user` as uu where 1 != 1", 5482 "Query": "select 1 from `user` as uu where uu.intcol = :u_intcol", 5483 "Table": "`user`" 5484 } 5485 ] 5486 }, 5487 "TablesUsed": [ 5488 "user.user" 5489 ] 5490 } 5491 }, 5492 { 5493 "comment": "Duplicate output column from derived table having a join", 5494 "query": "select 0 from (select `user`.col1 from `user` join unsharded) as t join unsharded on unsharded.col1 = t.col1 and unsharded.a = t.col1", 5495 "v3-plan": "VT12001: unsupported: expression on results of a cross-shard subquery", 5496 "gen4-plan": { 5497 "QueryType": "SELECT", 5498 "Original": "select 0 from (select `user`.col1 from `user` join unsharded) as t join unsharded on unsharded.col1 = t.col1 and unsharded.a = t.col1", 5499 "Instructions": { 5500 "OperatorType": "Join", 5501 "Variant": "Join", 5502 "JoinColumnIndexes": "L:1", 5503 "JoinVars": { 5504 "t_col1": 0 5505 }, 5506 "TableName": "`user`_unsharded_unsharded", 5507 "Inputs": [ 5508 { 5509 "OperatorType": "SimpleProjection", 5510 "Columns": [ 5511 0, 5512 1 5513 ], 5514 "Inputs": [ 5515 { 5516 "OperatorType": "Join", 5517 "Variant": "Join", 5518 "JoinColumnIndexes": "L:0,L:1", 5519 "TableName": "`user`_unsharded", 5520 "Inputs": [ 5521 { 5522 "OperatorType": "Route", 5523 "Variant": "Scatter", 5524 "Keyspace": { 5525 "Name": "user", 5526 "Sharded": true 5527 }, 5528 "FieldQuery": "select `user`.col1, 0 from `user` where 1 != 1", 5529 "Query": "select `user`.col1, 0 from `user`", 5530 "Table": "`user`" 5531 }, 5532 { 5533 "OperatorType": "Route", 5534 "Variant": "Unsharded", 5535 "Keyspace": { 5536 "Name": "main", 5537 "Sharded": false 5538 }, 5539 "FieldQuery": "select 1 from unsharded where 1 != 1", 5540 "Query": "select 1 from unsharded", 5541 "Table": "unsharded" 5542 } 5543 ] 5544 } 5545 ] 5546 }, 5547 { 5548 "OperatorType": "Route", 5549 "Variant": "Unsharded", 5550 "Keyspace": { 5551 "Name": "main", 5552 "Sharded": false 5553 }, 5554 "FieldQuery": "select 1 from unsharded where 1 != 1", 5555 "Query": "select 1 from unsharded where unsharded.col1 = :t_col1 and unsharded.a = :t_col1", 5556 "Table": "unsharded" 5557 } 5558 ] 5559 }, 5560 "TablesUsed": [ 5561 "main.unsharded", 5562 "user.user" 5563 ] 5564 } 5565 }, 5566 { 5567 "comment": "left join where clauses #2", 5568 "query": "select user.id from user left join user_extra on user.col = user_extra.col where coalesce(user_extra.col, 4) = 5", 5569 "plan": { 5570 "QueryType": "SELECT", 5571 "Original": "select user.id from user left join user_extra on user.col = user_extra.col where coalesce(user_extra.col, 4) = 5", 5572 "Instructions": { 5573 "OperatorType": "SimpleProjection", 5574 "Columns": [ 5575 1 5576 ], 5577 "Inputs": [ 5578 { 5579 "OperatorType": "Filter", 5580 "Predicate": "coalesce(user_extra.col, 4) = 5", 5581 "Inputs": [ 5582 { 5583 "OperatorType": "Join", 5584 "Variant": "LeftJoin", 5585 "JoinColumnIndexes": "R:0,L:1", 5586 "JoinVars": { 5587 "user_col": 0 5588 }, 5589 "TableName": "`user`_user_extra", 5590 "Inputs": [ 5591 { 5592 "OperatorType": "Route", 5593 "Variant": "Scatter", 5594 "Keyspace": { 5595 "Name": "user", 5596 "Sharded": true 5597 }, 5598 "FieldQuery": "select `user`.col, `user`.id from `user` where 1 != 1", 5599 "Query": "select `user`.col, `user`.id from `user`", 5600 "Table": "`user`" 5601 }, 5602 { 5603 "OperatorType": "Route", 5604 "Variant": "Scatter", 5605 "Keyspace": { 5606 "Name": "user", 5607 "Sharded": true 5608 }, 5609 "FieldQuery": "select user_extra.col from user_extra where 1 != 1", 5610 "Query": "select user_extra.col from user_extra where user_extra.col = :user_col", 5611 "Table": "user_extra" 5612 } 5613 ] 5614 } 5615 ] 5616 } 5617 ] 5618 }, 5619 "TablesUsed": [ 5620 "user.user", 5621 "user.user_extra" 5622 ] 5623 } 5624 }, 5625 { 5626 "comment": "dont merge unsharded tables from different keyspaces", 5627 "query": "select 1 from main.unsharded join main_2.unsharded_tab", 5628 "v3-plan": { 5629 "QueryType": "SELECT", 5630 "Original": "select 1 from main.unsharded join main_2.unsharded_tab", 5631 "Instructions": { 5632 "OperatorType": "Join", 5633 "Variant": "Join", 5634 "JoinColumnIndexes": "L:0", 5635 "TableName": "unsharded_unsharded_tab", 5636 "Inputs": [ 5637 { 5638 "OperatorType": "Route", 5639 "Variant": "Unsharded", 5640 "Keyspace": { 5641 "Name": "main", 5642 "Sharded": false 5643 }, 5644 "FieldQuery": "select 1 from unsharded where 1 != 1", 5645 "Query": "select 1 from unsharded", 5646 "Table": "unsharded" 5647 }, 5648 { 5649 "OperatorType": "Route", 5650 "Variant": "Unsharded", 5651 "Keyspace": { 5652 "Name": "main_2", 5653 "Sharded": false 5654 }, 5655 "FieldQuery": "select 1 from unsharded_tab where 1 != 1", 5656 "Query": "select 1 from unsharded_tab", 5657 "Table": "unsharded_tab" 5658 } 5659 ] 5660 } 5661 }, 5662 "gen4-plan": { 5663 "QueryType": "SELECT", 5664 "Original": "select 1 from main.unsharded join main_2.unsharded_tab", 5665 "Instructions": { 5666 "OperatorType": "Join", 5667 "Variant": "Join", 5668 "JoinColumnIndexes": "L:0", 5669 "TableName": "unsharded_unsharded_tab", 5670 "Inputs": [ 5671 { 5672 "OperatorType": "Route", 5673 "Variant": "Unsharded", 5674 "Keyspace": { 5675 "Name": "main", 5676 "Sharded": false 5677 }, 5678 "FieldQuery": "select 1 from unsharded where 1 != 1", 5679 "Query": "select 1 from unsharded", 5680 "Table": "unsharded" 5681 }, 5682 { 5683 "OperatorType": "Route", 5684 "Variant": "Unsharded", 5685 "Keyspace": { 5686 "Name": "main_2", 5687 "Sharded": false 5688 }, 5689 "FieldQuery": "select 1 from unsharded_tab where 1 != 1", 5690 "Query": "select 1 from unsharded_tab", 5691 "Table": "unsharded_tab" 5692 } 5693 ] 5694 }, 5695 "TablesUsed": [ 5696 "main.unsharded", 5697 "main_2.unsharded_tab" 5698 ] 5699 } 5700 }, 5701 { 5702 "comment": "Unsharded join with using", 5703 "query": "select * from unsharded_a join unsharded_b using (propertyId);", 5704 "v3-plan": { 5705 "QueryType": "SELECT", 5706 "Original": "select * from unsharded_a join unsharded_b using (propertyId);", 5707 "Instructions": { 5708 "OperatorType": "Route", 5709 "Variant": "Unsharded", 5710 "Keyspace": { 5711 "Name": "main", 5712 "Sharded": false 5713 }, 5714 "FieldQuery": "select * from unsharded_a join unsharded_b using (propertyId) where 1 != 1", 5715 "Query": "select * from unsharded_a join unsharded_b using (propertyId)", 5716 "Table": "unsharded_a, unsharded_b" 5717 } 5718 }, 5719 "gen4-plan": { 5720 "QueryType": "SELECT", 5721 "Original": "select * from unsharded_a join unsharded_b using (propertyId);", 5722 "Instructions": { 5723 "OperatorType": "Route", 5724 "Variant": "Unsharded", 5725 "Keyspace": { 5726 "Name": "main", 5727 "Sharded": false 5728 }, 5729 "FieldQuery": "select * from unsharded_a join unsharded_b using (propertyId) where 1 != 1", 5730 "Query": "select * from unsharded_a join unsharded_b using (propertyId)", 5731 "Table": "unsharded_a, unsharded_b" 5732 }, 5733 "TablesUsed": [ 5734 "main.unsharded_a", 5735 "main.unsharded_b" 5736 ] 5737 } 5738 }, 5739 { 5740 "comment": "Column aliases in Derived Table", 5741 "query": "select id2 from (select id from user) as x (id2)", 5742 "v3-plan": "VT12001: unsupported: column aliases in derived table", 5743 "gen4-plan": { 5744 "QueryType": "SELECT", 5745 "Original": "select id2 from (select id from user) as x (id2)", 5746 "Instructions": { 5747 "OperatorType": "Route", 5748 "Variant": "Scatter", 5749 "Keyspace": { 5750 "Name": "user", 5751 "Sharded": true 5752 }, 5753 "FieldQuery": "select id2 from (select id from `user` where 1 != 1) as x(id2) where 1 != 1", 5754 "Query": "select id2 from (select id from `user`) as x(id2)", 5755 "Table": "`user`" 5756 }, 5757 "TablesUsed": [ 5758 "user.user" 5759 ] 5760 } 5761 }, 5762 { 5763 "comment": "single unsharded keyspace with derived table", 5764 "query": "select col from (select col from unsharded join unsharded_b) as u join unsharded_a ua limit 1", 5765 "v3-plan": { 5766 "QueryType": "SELECT", 5767 "Original": "select col from (select col from unsharded join unsharded_b) as u join unsharded_a ua limit 1", 5768 "Instructions": { 5769 "OperatorType": "Route", 5770 "Variant": "Unsharded", 5771 "Keyspace": { 5772 "Name": "main", 5773 "Sharded": false 5774 }, 5775 "FieldQuery": "select col from (select col from unsharded join unsharded_b where 1 != 1) as u join unsharded_a as ua where 1 != 1", 5776 "Query": "select col from (select col from unsharded join unsharded_b) as u join unsharded_a as ua limit 1", 5777 "Table": "unsharded, unsharded_b, unsharded_a" 5778 } 5779 }, 5780 "gen4-plan": { 5781 "QueryType": "SELECT", 5782 "Original": "select col from (select col from unsharded join unsharded_b) as u join unsharded_a ua limit 1", 5783 "Instructions": { 5784 "OperatorType": "Route", 5785 "Variant": "Unsharded", 5786 "Keyspace": { 5787 "Name": "main", 5788 "Sharded": false 5789 }, 5790 "FieldQuery": "select col from (select col from unsharded join unsharded_b where 1 != 1) as u join unsharded_a as ua where 1 != 1", 5791 "Query": "select col from (select col from unsharded join unsharded_b) as u join unsharded_a as ua limit 1", 5792 "Table": "unsharded, unsharded_a, unsharded_b" 5793 }, 5794 "TablesUsed": [ 5795 "main.unsharded", 5796 "main.unsharded_a", 5797 "main.unsharded_b" 5798 ] 5799 } 5800 }, 5801 { 5802 "comment": "query builder with derived table having join inside it", 5803 "query": "select u.col from (select user.col from user join user_extra) as u join user_extra ue limit 1", 5804 "v3-plan": { 5805 "QueryType": "SELECT", 5806 "Original": "select u.col from (select user.col from user join user_extra) as u join user_extra ue limit 1", 5807 "Instructions": { 5808 "OperatorType": "Limit", 5809 "Count": "INT64(1)", 5810 "Inputs": [ 5811 { 5812 "OperatorType": "Join", 5813 "Variant": "Join", 5814 "JoinColumnIndexes": "L:0", 5815 "TableName": "`user`_user_extra_user_extra", 5816 "Inputs": [ 5817 { 5818 "OperatorType": "SimpleProjection", 5819 "Columns": [ 5820 0 5821 ], 5822 "Inputs": [ 5823 { 5824 "OperatorType": "Join", 5825 "Variant": "Join", 5826 "JoinColumnIndexes": "L:0", 5827 "TableName": "`user`_user_extra", 5828 "Inputs": [ 5829 { 5830 "OperatorType": "Route", 5831 "Variant": "Scatter", 5832 "Keyspace": { 5833 "Name": "user", 5834 "Sharded": true 5835 }, 5836 "FieldQuery": "select `user`.col from `user` where 1 != 1", 5837 "Query": "select `user`.col from `user`", 5838 "Table": "`user`" 5839 }, 5840 { 5841 "OperatorType": "Route", 5842 "Variant": "Scatter", 5843 "Keyspace": { 5844 "Name": "user", 5845 "Sharded": true 5846 }, 5847 "FieldQuery": "select 1 from user_extra where 1 != 1", 5848 "Query": "select 1 from user_extra", 5849 "Table": "user_extra" 5850 } 5851 ] 5852 } 5853 ] 5854 }, 5855 { 5856 "OperatorType": "Route", 5857 "Variant": "Scatter", 5858 "Keyspace": { 5859 "Name": "user", 5860 "Sharded": true 5861 }, 5862 "FieldQuery": "select 1 from user_extra as ue where 1 != 1", 5863 "Query": "select 1 from user_extra as ue", 5864 "Table": "user_extra" 5865 } 5866 ] 5867 } 5868 ] 5869 } 5870 }, 5871 "gen4-plan": { 5872 "QueryType": "SELECT", 5873 "Original": "select u.col from (select user.col from user join user_extra) as u join user_extra ue limit 1", 5874 "Instructions": { 5875 "OperatorType": "Limit", 5876 "Count": "INT64(1)", 5877 "Inputs": [ 5878 { 5879 "OperatorType": "Join", 5880 "Variant": "Join", 5881 "JoinColumnIndexes": "L:0", 5882 "TableName": "`user`_user_extra_user_extra", 5883 "Inputs": [ 5884 { 5885 "OperatorType": "SimpleProjection", 5886 "Columns": [ 5887 0 5888 ], 5889 "Inputs": [ 5890 { 5891 "OperatorType": "Join", 5892 "Variant": "Join", 5893 "JoinColumnIndexes": "L:0", 5894 "TableName": "`user`_user_extra", 5895 "Inputs": [ 5896 { 5897 "OperatorType": "Route", 5898 "Variant": "Scatter", 5899 "Keyspace": { 5900 "Name": "user", 5901 "Sharded": true 5902 }, 5903 "FieldQuery": "select `user`.col from `user` where 1 != 1", 5904 "Query": "select `user`.col from `user`", 5905 "Table": "`user`" 5906 }, 5907 { 5908 "OperatorType": "Route", 5909 "Variant": "Scatter", 5910 "Keyspace": { 5911 "Name": "user", 5912 "Sharded": true 5913 }, 5914 "FieldQuery": "select 1 from user_extra where 1 != 1", 5915 "Query": "select 1 from user_extra", 5916 "Table": "user_extra" 5917 } 5918 ] 5919 } 5920 ] 5921 }, 5922 { 5923 "OperatorType": "Route", 5924 "Variant": "Scatter", 5925 "Keyspace": { 5926 "Name": "user", 5927 "Sharded": true 5928 }, 5929 "FieldQuery": "select 1 from user_extra as ue where 1 != 1", 5930 "Query": "select 1 from user_extra as ue", 5931 "Table": "user_extra" 5932 } 5933 ] 5934 } 5935 ] 5936 }, 5937 "TablesUsed": [ 5938 "user.user", 5939 "user.user_extra" 5940 ] 5941 } 5942 }, 5943 { 5944 "comment": "left join with expressions", 5945 "query": "select user_extra.col+1 from user left join user_extra on user.col = user_extra.col", 5946 "plan": { 5947 "QueryType": "SELECT", 5948 "Original": "select user_extra.col+1 from user left join user_extra on user.col = user_extra.col", 5949 "Instructions": { 5950 "OperatorType": "Join", 5951 "Variant": "LeftJoin", 5952 "JoinColumnIndexes": "R:0", 5953 "JoinVars": { 5954 "user_col": 0 5955 }, 5956 "TableName": "`user`_user_extra", 5957 "Inputs": [ 5958 { 5959 "OperatorType": "Route", 5960 "Variant": "Scatter", 5961 "Keyspace": { 5962 "Name": "user", 5963 "Sharded": true 5964 }, 5965 "FieldQuery": "select `user`.col from `user` where 1 != 1", 5966 "Query": "select `user`.col from `user`", 5967 "Table": "`user`" 5968 }, 5969 { 5970 "OperatorType": "Route", 5971 "Variant": "Scatter", 5972 "Keyspace": { 5973 "Name": "user", 5974 "Sharded": true 5975 }, 5976 "FieldQuery": "select user_extra.col + 1 from user_extra where 1 != 1", 5977 "Query": "select user_extra.col + 1 from user_extra where user_extra.col = :user_col", 5978 "Table": "user_extra" 5979 } 5980 ] 5981 }, 5982 "TablesUsed": [ 5983 "user.user", 5984 "user.user_extra" 5985 ] 5986 } 5987 }, 5988 { 5989 "comment": "left join with expressions, with three-way join (different code path)", 5990 "query": "select user.id, user_extra.col+1 from user left join user_extra on user.col = user_extra.col join user_extra e", 5991 "plan": { 5992 "QueryType": "SELECT", 5993 "Original": "select user.id, user_extra.col+1 from user left join user_extra on user.col = user_extra.col join user_extra e", 5994 "Instructions": { 5995 "OperatorType": "Join", 5996 "Variant": "Join", 5997 "JoinColumnIndexes": "L:0,L:1", 5998 "TableName": "`user`_user_extra_user_extra", 5999 "Inputs": [ 6000 { 6001 "OperatorType": "Join", 6002 "Variant": "LeftJoin", 6003 "JoinColumnIndexes": "L:1,R:0", 6004 "JoinVars": { 6005 "user_col": 0 6006 }, 6007 "TableName": "`user`_user_extra", 6008 "Inputs": [ 6009 { 6010 "OperatorType": "Route", 6011 "Variant": "Scatter", 6012 "Keyspace": { 6013 "Name": "user", 6014 "Sharded": true 6015 }, 6016 "FieldQuery": "select `user`.col, `user`.id from `user` where 1 != 1", 6017 "Query": "select `user`.col, `user`.id from `user`", 6018 "Table": "`user`" 6019 }, 6020 { 6021 "OperatorType": "Route", 6022 "Variant": "Scatter", 6023 "Keyspace": { 6024 "Name": "user", 6025 "Sharded": true 6026 }, 6027 "FieldQuery": "select user_extra.col + 1 from user_extra where 1 != 1", 6028 "Query": "select user_extra.col + 1 from user_extra where user_extra.col = :user_col", 6029 "Table": "user_extra" 6030 } 6031 ] 6032 }, 6033 { 6034 "OperatorType": "Route", 6035 "Variant": "Scatter", 6036 "Keyspace": { 6037 "Name": "user", 6038 "Sharded": true 6039 }, 6040 "FieldQuery": "select 1 from user_extra as e where 1 != 1", 6041 "Query": "select 1 from user_extra as e", 6042 "Table": "user_extra" 6043 } 6044 ] 6045 }, 6046 "TablesUsed": [ 6047 "user.user", 6048 "user.user_extra" 6049 ] 6050 } 6051 }, 6052 { 6053 "comment": "left join with expressions coming from both sides", 6054 "query": "select user.foo+user_extra.col+1 from user left join user_extra on user.col = user_extra.col", 6055 "plan": { 6056 "QueryType": "SELECT", 6057 "Original": "select user.foo+user_extra.col+1 from user left join user_extra on user.col = user_extra.col", 6058 "Instructions": { 6059 "OperatorType": "Join", 6060 "Variant": "LeftJoin", 6061 "JoinColumnIndexes": "R:0", 6062 "JoinVars": { 6063 "user_col": 0, 6064 "user_foo": 1 6065 }, 6066 "TableName": "`user`_user_extra", 6067 "Inputs": [ 6068 { 6069 "OperatorType": "Route", 6070 "Variant": "Scatter", 6071 "Keyspace": { 6072 "Name": "user", 6073 "Sharded": true 6074 }, 6075 "FieldQuery": "select `user`.col, `user`.foo from `user` where 1 != 1", 6076 "Query": "select `user`.col, `user`.foo from `user`", 6077 "Table": "`user`" 6078 }, 6079 { 6080 "OperatorType": "Route", 6081 "Variant": "Scatter", 6082 "Keyspace": { 6083 "Name": "user", 6084 "Sharded": true 6085 }, 6086 "FieldQuery": "select :user_foo + user_extra.col + 1 from user_extra where 1 != 1", 6087 "Query": "select :user_foo + user_extra.col + 1 from user_extra where user_extra.col = :user_col", 6088 "Table": "user_extra" 6089 } 6090 ] 6091 }, 6092 "TablesUsed": [ 6093 "user.user", 6094 "user.user_extra" 6095 ] 6096 } 6097 }, 6098 { 6099 "comment": "Do not rewrite derived expressions when the derived table is merged with the outer", 6100 "query": "select col1, count(*) from (select colC+colD as col1 from user) as tbl group by col1", 6101 "v3-plan": { 6102 "QueryType": "SELECT", 6103 "Original": "select col1, count(*) from (select colC+colD as col1 from user) as tbl group by col1", 6104 "Instructions": { 6105 "OperatorType": "Aggregate", 6106 "Variant": "Ordered", 6107 "Aggregates": "sum_count(1) AS count", 6108 "GroupBy": "0", 6109 "Inputs": [ 6110 { 6111 "OperatorType": "Route", 6112 "Variant": "Scatter", 6113 "Keyspace": { 6114 "Name": "user", 6115 "Sharded": true 6116 }, 6117 "FieldQuery": "select col1, count(*), weight_string(col1) from (select colC + colD as col1 from `user` where 1 != 1) as tbl where 1 != 1 group by col1, weight_string(col1)", 6118 "OrderBy": "(0|2) ASC", 6119 "Query": "select col1, count(*), weight_string(col1) from (select colC + colD as col1 from `user`) as tbl group by col1, weight_string(col1) order by col1 asc", 6120 "ResultColumns": 2, 6121 "Table": "`user`" 6122 } 6123 ] 6124 } 6125 }, 6126 "gen4-plan": { 6127 "QueryType": "SELECT", 6128 "Original": "select col1, count(*) from (select colC+colD as col1 from user) as tbl group by col1", 6129 "Instructions": { 6130 "OperatorType": "Aggregate", 6131 "Variant": "Ordered", 6132 "Aggregates": "sum_count_star(1) AS count(*)", 6133 "GroupBy": "(0|2)", 6134 "ResultColumns": 2, 6135 "Inputs": [ 6136 { 6137 "OperatorType": "Route", 6138 "Variant": "Scatter", 6139 "Keyspace": { 6140 "Name": "user", 6141 "Sharded": true 6142 }, 6143 "FieldQuery": "select col1, count(*), weight_string(col1) from (select colC + colD as col1 from `user` where 1 != 1) as tbl where 1 != 1 group by col1, weight_string(col1)", 6144 "OrderBy": "(0|2) ASC", 6145 "Query": "select col1, count(*), weight_string(col1) from (select colC + colD as col1 from `user`) as tbl group by col1, weight_string(col1) order by col1 asc", 6146 "Table": "`user`" 6147 } 6148 ] 6149 }, 6150 "TablesUsed": [ 6151 "user.user" 6152 ] 6153 } 6154 }, 6155 { 6156 "comment": "join with USING construct", 6157 "query": "select * from authoritative join unsharded_authoritative using(col1)", 6158 "v3-plan": "VT12001: unsupported: JOIN with USING(column_list) clause for complex queries", 6159 "gen4-plan": { 6160 "QueryType": "SELECT", 6161 "Original": "select * from authoritative join unsharded_authoritative using(col1)", 6162 "Instructions": { 6163 "OperatorType": "Join", 6164 "Variant": "Join", 6165 "JoinColumnIndexes": "L:1,L:2,L:3,R:0", 6166 "JoinVars": { 6167 "authoritative_col1": 0 6168 }, 6169 "TableName": "authoritative_unsharded_authoritative", 6170 "Inputs": [ 6171 { 6172 "OperatorType": "Route", 6173 "Variant": "Scatter", 6174 "Keyspace": { 6175 "Name": "user", 6176 "Sharded": true 6177 }, 6178 "FieldQuery": "select authoritative.col1, authoritative.col1 as col1, authoritative.user_id as user_id, authoritative.col2 as col2 from authoritative where 1 != 1", 6179 "Query": "select authoritative.col1, authoritative.col1 as col1, authoritative.user_id as user_id, authoritative.col2 as col2 from authoritative", 6180 "Table": "authoritative" 6181 }, 6182 { 6183 "OperatorType": "Route", 6184 "Variant": "Unsharded", 6185 "Keyspace": { 6186 "Name": "main", 6187 "Sharded": false 6188 }, 6189 "FieldQuery": "select unsharded_authoritative.col2 as col2 from unsharded_authoritative where 1 != 1", 6190 "Query": "select unsharded_authoritative.col2 as col2 from unsharded_authoritative where unsharded_authoritative.col1 = :authoritative_col1", 6191 "Table": "unsharded_authoritative" 6192 } 6193 ] 6194 }, 6195 "TablesUsed": [ 6196 "main.unsharded_authoritative", 6197 "user.authoritative" 6198 ] 6199 } 6200 }, 6201 { 6202 "comment": "derived table inside derived table with a where clause depending on columns from the derived table", 6203 "query": "select * from (select bar as push_it from (select foo as bar from (select id as foo from user) as t1) as t2) as t3 where push_it = 12", 6204 "v3-plan": { 6205 "QueryType": "SELECT", 6206 "Original": "select * from (select bar as push_it from (select foo as bar from (select id as foo from user) as t1) as t2) as t3 where push_it = 12", 6207 "Instructions": { 6208 "OperatorType": "Route", 6209 "Variant": "EqualUnique", 6210 "Keyspace": { 6211 "Name": "user", 6212 "Sharded": true 6213 }, 6214 "FieldQuery": "select * from (select bar as push_it from (select foo as bar from (select id as foo from `user` where 1 != 1) as t1 where 1 != 1) as t2 where 1 != 1) as t3 where 1 != 1", 6215 "Query": "select * from (select bar as push_it from (select foo as bar from (select id as foo from `user`) as t1) as t2) as t3 where push_it = 12", 6216 "Table": "`user`", 6217 "Values": [ 6218 "INT64(12)" 6219 ], 6220 "Vindex": "user_index" 6221 } 6222 }, 6223 "gen4-plan": { 6224 "QueryType": "SELECT", 6225 "Original": "select * from (select bar as push_it from (select foo as bar from (select id as foo from user) as t1) as t2) as t3 where push_it = 12", 6226 "Instructions": { 6227 "OperatorType": "Route", 6228 "Variant": "EqualUnique", 6229 "Keyspace": { 6230 "Name": "user", 6231 "Sharded": true 6232 }, 6233 "FieldQuery": "select t3.push_it from (select bar as push_it from (select foo as bar from (select id as foo from `user` where 1 != 1) as t1 where 1 != 1) as t2 where 1 != 1) as t3 where 1 != 1", 6234 "Query": "select t3.push_it from (select bar as push_it from (select foo as bar from (select id as foo from `user` where id = 12) as t1) as t2) as t3", 6235 "Table": "`user`", 6236 "Values": [ 6237 "INT64(12)" 6238 ], 6239 "Vindex": "user_index" 6240 }, 6241 "TablesUsed": [ 6242 "user.user" 6243 ] 6244 } 6245 }, 6246 { 6247 "comment": "use a view", 6248 "query": "select * from user.user_details_view", 6249 "v3-plan": { 6250 "QueryType": "SELECT", 6251 "Original": "select * from user.user_details_view", 6252 "Instructions": { 6253 "OperatorType": "Route", 6254 "Variant": "Scatter", 6255 "Keyspace": { 6256 "Name": "user", 6257 "Sharded": true 6258 }, 6259 "FieldQuery": "select * from (select `user`.id, user_extra.col from `user` join user_extra on `user`.id = user_extra.user_id where 1 != 1) as user_details_view where 1 != 1", 6260 "Query": "select * from (select `user`.id, user_extra.col from `user` join user_extra on `user`.id = user_extra.user_id) as user_details_view", 6261 "Table": "`user`, user_extra" 6262 } 6263 }, 6264 "gen4-plan": { 6265 "QueryType": "SELECT", 6266 "Original": "select * from user.user_details_view", 6267 "Instructions": { 6268 "OperatorType": "Route", 6269 "Variant": "Scatter", 6270 "Keyspace": { 6271 "Name": "user", 6272 "Sharded": true 6273 }, 6274 "FieldQuery": "select user_details_view.id, user_details_view.col from (select `user`.id, user_extra.col from `user`, user_extra where 1 != 1) as user_details_view where 1 != 1", 6275 "Query": "select user_details_view.id, user_details_view.col from (select `user`.id, user_extra.col from `user`, user_extra where `user`.id = user_extra.user_id) as user_details_view", 6276 "Table": "`user`, user_extra" 6277 }, 6278 "TablesUsed": [ 6279 "user.user", 6280 "user.user_extra" 6281 ] 6282 } 6283 }, 6284 { 6285 "comment": "use a view without qualifying the keyspace", 6286 "query": "select * from user_details_view", 6287 "v3-plan": { 6288 "QueryType": "SELECT", 6289 "Original": "select * from user_details_view", 6290 "Instructions": { 6291 "OperatorType": "Route", 6292 "Variant": "Scatter", 6293 "Keyspace": { 6294 "Name": "user", 6295 "Sharded": true 6296 }, 6297 "FieldQuery": "select * from (select `user`.id, user_extra.col from `user` join user_extra on `user`.id = user_extra.user_id where 1 != 1) as user_details_view where 1 != 1", 6298 "Query": "select * from (select `user`.id, user_extra.col from `user` join user_extra on `user`.id = user_extra.user_id) as user_details_view", 6299 "Table": "`user`, user_extra" 6300 } 6301 }, 6302 "gen4-plan": { 6303 "QueryType": "SELECT", 6304 "Original": "select * from user_details_view", 6305 "Instructions": { 6306 "OperatorType": "Route", 6307 "Variant": "Scatter", 6308 "Keyspace": { 6309 "Name": "user", 6310 "Sharded": true 6311 }, 6312 "FieldQuery": "select user_details_view.id, user_details_view.col from (select `user`.id, user_extra.col from `user`, user_extra where 1 != 1) as user_details_view where 1 != 1", 6313 "Query": "select user_details_view.id, user_details_view.col from (select `user`.id, user_extra.col from `user`, user_extra where `user`.id = user_extra.user_id) as user_details_view", 6314 "Table": "`user`, user_extra" 6315 }, 6316 "TablesUsed": [ 6317 "user.user", 6318 "user.user_extra" 6319 ] 6320 } 6321 }, 6322 { 6323 "comment": "left join where clauses #3 - assert that we can evaluate BETWEEN with the evalengine", 6324 "query": "select user.id from user left join user_extra on user.col = user_extra.col where user_extra.col between 10 and 20", 6325 "plan": { 6326 "QueryType": "SELECT", 6327 "Original": "select user.id from user left join user_extra on user.col = user_extra.col where user_extra.col between 10 and 20", 6328 "Instructions": { 6329 "OperatorType": "SimpleProjection", 6330 "Columns": [ 6331 1 6332 ], 6333 "Inputs": [ 6334 { 6335 "OperatorType": "Filter", 6336 "Predicate": "user_extra.col between 10 and 20", 6337 "Inputs": [ 6338 { 6339 "OperatorType": "Join", 6340 "Variant": "LeftJoin", 6341 "JoinColumnIndexes": "R:0,L:1", 6342 "JoinVars": { 6343 "user_col": 0 6344 }, 6345 "TableName": "`user`_user_extra", 6346 "Inputs": [ 6347 { 6348 "OperatorType": "Route", 6349 "Variant": "Scatter", 6350 "Keyspace": { 6351 "Name": "user", 6352 "Sharded": true 6353 }, 6354 "FieldQuery": "select `user`.col, `user`.id from `user` where 1 != 1", 6355 "Query": "select `user`.col, `user`.id from `user`", 6356 "Table": "`user`" 6357 }, 6358 { 6359 "OperatorType": "Route", 6360 "Variant": "Scatter", 6361 "Keyspace": { 6362 "Name": "user", 6363 "Sharded": true 6364 }, 6365 "FieldQuery": "select user_extra.col from user_extra where 1 != 1", 6366 "Query": "select user_extra.col from user_extra where user_extra.col = :user_col", 6367 "Table": "user_extra" 6368 } 6369 ] 6370 } 6371 ] 6372 } 6373 ] 6374 }, 6375 "TablesUsed": [ 6376 "user.user", 6377 "user.user_extra" 6378 ] 6379 } 6380 }, 6381 { 6382 "comment": "missing and ambiguous column info is OK as long as we can send the query to a single unsharded keyspace", 6383 "query": "select missing_column from unsharded, unsharded_a", 6384 "v3-plan": { 6385 "QueryType": "SELECT", 6386 "Original": "select missing_column from unsharded, unsharded_a", 6387 "Instructions": { 6388 "OperatorType": "Route", 6389 "Variant": "Unsharded", 6390 "Keyspace": { 6391 "Name": "main", 6392 "Sharded": false 6393 }, 6394 "FieldQuery": "select missing_column from unsharded, unsharded_a where 1 != 1", 6395 "Query": "select missing_column from unsharded, unsharded_a", 6396 "Table": "unsharded, unsharded_a" 6397 } 6398 }, 6399 "gen4-plan": { 6400 "QueryType": "SELECT", 6401 "Original": "select missing_column from unsharded, unsharded_a", 6402 "Instructions": { 6403 "OperatorType": "Route", 6404 "Variant": "Unsharded", 6405 "Keyspace": { 6406 "Name": "main", 6407 "Sharded": false 6408 }, 6409 "FieldQuery": "select missing_column from unsharded, unsharded_a where 1 != 1", 6410 "Query": "select missing_column from unsharded, unsharded_a", 6411 "Table": "unsharded, unsharded_a" 6412 }, 6413 "TablesUsed": [ 6414 "main.unsharded", 6415 "main.unsharded_a" 6416 ] 6417 } 6418 }, 6419 { 6420 "comment": "missing and ambiguous column info is not valid when we have two different unsharded keyspaces in the query", 6421 "query": "select missing_column from unsharded, unsharded_tab", 6422 "v3-plan": "VT03019: symbol missing_column not found", 6423 "gen4-plan": "Column 'missing_column' in field list is ambiguous" 6424 } 6425 ]