vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/testdata/vindex_func_cases.json (about) 1 [ 2 { 3 "comment": "vindex func read all cols", 4 "query": "select id, keyspace_id, range_start, range_end, hex_keyspace_id, shard from user_index where id = :id", 5 "v3-plan": { 6 "QueryType": "SELECT", 7 "Original": "select id, keyspace_id, range_start, range_end, hex_keyspace_id, shard from user_index where id = :id", 8 "Instructions": { 9 "OperatorType": "VindexFunc", 10 "Variant": "VindexMap", 11 "Columns": [ 12 0, 13 1, 14 2, 15 3, 16 4, 17 5 18 ], 19 "Fields": { 20 "hex_keyspace_id": "VARBINARY", 21 "id": "VARBINARY", 22 "keyspace_id": "VARBINARY", 23 "range_end": "VARBINARY", 24 "range_start": "VARBINARY", 25 "shard": "VARBINARY" 26 }, 27 "Value": ":id", 28 "Vindex": "user_index" 29 } 30 }, 31 "gen4-plan": { 32 "QueryType": "SELECT", 33 "Original": "select id, keyspace_id, range_start, range_end, hex_keyspace_id, shard from user_index where id = :id", 34 "Instructions": { 35 "OperatorType": "VindexFunc", 36 "Variant": "VindexMap", 37 "Columns": [ 38 0, 39 1, 40 2, 41 3, 42 4, 43 5 44 ], 45 "Fields": { 46 "hex_keyspace_id": "VARBINARY", 47 "id": "VARBINARY", 48 "keyspace_id": "VARBINARY", 49 "range_end": "VARBINARY", 50 "range_start": "VARBINARY", 51 "shard": "VARBINARY" 52 }, 53 "Value": ":id", 54 "Vindex": "user_index" 55 }, 56 "TablesUsed": [ 57 "user_index" 58 ] 59 } 60 }, 61 { 62 "comment": "vindex func select *", 63 "query": "select * from user_index where id = :id", 64 "v3-plan": { 65 "QueryType": "SELECT", 66 "Original": "select * from user_index where id = :id", 67 "Instructions": { 68 "OperatorType": "VindexFunc", 69 "Variant": "VindexMap", 70 "Columns": [ 71 0, 72 1, 73 2, 74 3, 75 4, 76 5 77 ], 78 "Fields": { 79 "hex_keyspace_id": "VARBINARY", 80 "id": "VARBINARY", 81 "keyspace_id": "VARBINARY", 82 "range_end": "VARBINARY", 83 "range_start": "VARBINARY", 84 "shard": "VARBINARY" 85 }, 86 "Value": ":id", 87 "Vindex": "user_index" 88 } 89 }, 90 "gen4-plan": { 91 "QueryType": "SELECT", 92 "Original": "select * from user_index where id = :id", 93 "Instructions": { 94 "OperatorType": "VindexFunc", 95 "Variant": "VindexMap", 96 "Columns": [ 97 0, 98 1, 99 2, 100 3, 101 4, 102 5 103 ], 104 "Fields": { 105 "hex_keyspace_id": "VARBINARY", 106 "id": "VARBINARY", 107 "keyspace_id": "VARBINARY", 108 "range_end": "VARBINARY", 109 "range_start": "VARBINARY", 110 "shard": "VARBINARY" 111 }, 112 "Value": ":id", 113 "Vindex": "user_index" 114 }, 115 "TablesUsed": [ 116 "user_index" 117 ] 118 } 119 }, 120 { 121 "comment": "vindex func read with id repeated", 122 "query": "select id, keyspace_id, id from user_index where id = :id", 123 "v3-plan": { 124 "QueryType": "SELECT", 125 "Original": "select id, keyspace_id, id from user_index where id = :id", 126 "Instructions": { 127 "OperatorType": "VindexFunc", 128 "Variant": "VindexMap", 129 "Columns": [ 130 0, 131 1, 132 0 133 ], 134 "Fields": { 135 "id": "VARBINARY", 136 "keyspace_id": "VARBINARY" 137 }, 138 "Value": ":id", 139 "Vindex": "user_index" 140 } 141 }, 142 "gen4-plan": { 143 "QueryType": "SELECT", 144 "Original": "select id, keyspace_id, id from user_index where id = :id", 145 "Instructions": { 146 "OperatorType": "VindexFunc", 147 "Variant": "VindexMap", 148 "Columns": [ 149 0, 150 1, 151 0 152 ], 153 "Fields": { 154 "id": "VARBINARY", 155 "keyspace_id": "VARBINARY" 156 }, 157 "Value": ":id", 158 "Vindex": "user_index" 159 }, 160 "TablesUsed": [ 161 "user_index" 162 ] 163 } 164 }, 165 { 166 "comment": "ambiguous vindex reference", 167 "query": "select id, keyspace_id, id from hash_dup where id = :id", 168 "plan": "ambiguous vindex reference: hash_dup" 169 }, 170 { 171 "comment": "disambiguated vindex reference", 172 "query": "select id, keyspace_id, id from second_user.hash_dup where id = :id", 173 "v3-plan": { 174 "QueryType": "SELECT", 175 "Original": "select id, keyspace_id, id from second_user.hash_dup where id = :id", 176 "Instructions": { 177 "OperatorType": "VindexFunc", 178 "Variant": "VindexMap", 179 "Columns": [ 180 0, 181 1, 182 0 183 ], 184 "Fields": { 185 "id": "VARBINARY", 186 "keyspace_id": "VARBINARY" 187 }, 188 "Value": ":id", 189 "Vindex": "hash_dup" 190 } 191 }, 192 "gen4-plan": { 193 "QueryType": "SELECT", 194 "Original": "select id, keyspace_id, id from second_user.hash_dup where id = :id", 195 "Instructions": { 196 "OperatorType": "VindexFunc", 197 "Variant": "VindexMap", 198 "Columns": [ 199 0, 200 1, 201 0 202 ], 203 "Fields": { 204 "id": "VARBINARY", 205 "keyspace_id": "VARBINARY" 206 }, 207 "Value": ":id", 208 "Vindex": "hash_dup" 209 }, 210 "TablesUsed": [ 211 "hash_dup" 212 ] 213 } 214 }, 215 { 216 "comment": "You can even join with a vindexFunc primitive", 217 "query": "select user_index.keyspace_id, unsharded.id from user_index join unsharded where user_index.id = :id", 218 "v3-plan": { 219 "QueryType": "SELECT", 220 "Original": "select user_index.keyspace_id, unsharded.id from user_index join unsharded where user_index.id = :id", 221 "Instructions": { 222 "OperatorType": "Join", 223 "Variant": "Join", 224 "JoinColumnIndexes": "L:0,R:0", 225 "TableName": "_unsharded", 226 "Inputs": [ 227 { 228 "OperatorType": "VindexFunc", 229 "Variant": "VindexMap", 230 "Columns": [ 231 1 232 ], 233 "Fields": { 234 "keyspace_id": "VARBINARY" 235 }, 236 "Value": ":id", 237 "Vindex": "user_index" 238 }, 239 { 240 "OperatorType": "Route", 241 "Variant": "Unsharded", 242 "Keyspace": { 243 "Name": "main", 244 "Sharded": false 245 }, 246 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 247 "Query": "select unsharded.id from unsharded", 248 "Table": "unsharded" 249 } 250 ] 251 } 252 }, 253 "gen4-plan": { 254 "QueryType": "SELECT", 255 "Original": "select user_index.keyspace_id, unsharded.id from user_index join unsharded where user_index.id = :id", 256 "Instructions": { 257 "OperatorType": "Join", 258 "Variant": "Join", 259 "JoinColumnIndexes": "L:0,R:0", 260 "TableName": "_unsharded", 261 "Inputs": [ 262 { 263 "OperatorType": "VindexFunc", 264 "Variant": "VindexMap", 265 "Columns": [ 266 1 267 ], 268 "Fields": { 269 "keyspace_id": "VARBINARY" 270 }, 271 "Value": ":id", 272 "Vindex": "user_index" 273 }, 274 { 275 "OperatorType": "Route", 276 "Variant": "Unsharded", 277 "Keyspace": { 278 "Name": "main", 279 "Sharded": false 280 }, 281 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 282 "Query": "select unsharded.id from unsharded", 283 "Table": "unsharded" 284 } 285 ] 286 }, 287 "TablesUsed": [ 288 "main.unsharded", 289 "user_index" 290 ] 291 } 292 }, 293 { 294 "comment": "Join vindexFunc on RHS", 295 "query": "select user_index.keyspace_id, unsharded.id from unsharded join user_index where user_index.id = :id", 296 "v3-plan": { 297 "QueryType": "SELECT", 298 "Original": "select user_index.keyspace_id, unsharded.id from unsharded join user_index where user_index.id = :id", 299 "Instructions": { 300 "OperatorType": "Join", 301 "Variant": "Join", 302 "JoinColumnIndexes": "R:0,L:0", 303 "TableName": "unsharded_", 304 "Inputs": [ 305 { 306 "OperatorType": "Route", 307 "Variant": "Unsharded", 308 "Keyspace": { 309 "Name": "main", 310 "Sharded": false 311 }, 312 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 313 "Query": "select unsharded.id from unsharded", 314 "Table": "unsharded" 315 }, 316 { 317 "OperatorType": "VindexFunc", 318 "Variant": "VindexMap", 319 "Columns": [ 320 1 321 ], 322 "Fields": { 323 "keyspace_id": "VARBINARY" 324 }, 325 "Value": ":id", 326 "Vindex": "user_index" 327 } 328 ] 329 } 330 }, 331 "gen4-plan": { 332 "QueryType": "SELECT", 333 "Original": "select user_index.keyspace_id, unsharded.id from unsharded join user_index where user_index.id = :id", 334 "Instructions": { 335 "OperatorType": "Join", 336 "Variant": "Join", 337 "JoinColumnIndexes": "R:0,L:0", 338 "TableName": "unsharded_", 339 "Inputs": [ 340 { 341 "OperatorType": "Route", 342 "Variant": "Unsharded", 343 "Keyspace": { 344 "Name": "main", 345 "Sharded": false 346 }, 347 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 348 "Query": "select unsharded.id from unsharded", 349 "Table": "unsharded" 350 }, 351 { 352 "OperatorType": "VindexFunc", 353 "Variant": "VindexMap", 354 "Columns": [ 355 1 356 ], 357 "Fields": { 358 "keyspace_id": "VARBINARY" 359 }, 360 "Value": ":id", 361 "Vindex": "user_index" 362 } 363 ] 364 }, 365 "TablesUsed": [ 366 "main.unsharded", 367 "user_index" 368 ] 369 } 370 }, 371 { 372 "comment": "Join with vindexFunc on a column of it, already present in select list", 373 "query": "select user_index.id, user_index.keyspace_id, unsharded.id from user_index join unsharded where user_index.id = :id and unsharded.id = user_index.id", 374 "v3-plan": { 375 "QueryType": "SELECT", 376 "Original": "select user_index.id, user_index.keyspace_id, unsharded.id from user_index join unsharded where user_index.id = :id and unsharded.id = user_index.id", 377 "Instructions": { 378 "OperatorType": "Join", 379 "Variant": "Join", 380 "JoinColumnIndexes": "L:0,L:1,R:0", 381 "JoinVars": { 382 "user_index_id": 0 383 }, 384 "TableName": "_unsharded", 385 "Inputs": [ 386 { 387 "OperatorType": "VindexFunc", 388 "Variant": "VindexMap", 389 "Columns": [ 390 0, 391 1 392 ], 393 "Fields": { 394 "id": "VARBINARY", 395 "keyspace_id": "VARBINARY" 396 }, 397 "Value": ":id", 398 "Vindex": "user_index" 399 }, 400 { 401 "OperatorType": "Route", 402 "Variant": "Unsharded", 403 "Keyspace": { 404 "Name": "main", 405 "Sharded": false 406 }, 407 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 408 "Query": "select unsharded.id from unsharded where unsharded.id = :user_index_id", 409 "Table": "unsharded" 410 } 411 ] 412 } 413 }, 414 "gen4-plan": { 415 "QueryType": "SELECT", 416 "Original": "select user_index.id, user_index.keyspace_id, unsharded.id from user_index join unsharded where user_index.id = :id and unsharded.id = user_index.id", 417 "Instructions": { 418 "OperatorType": "Join", 419 "Variant": "Join", 420 "JoinColumnIndexes": "L:0,L:1,R:0", 421 "JoinVars": { 422 "user_index_id": 0 423 }, 424 "TableName": "_unsharded", 425 "Inputs": [ 426 { 427 "OperatorType": "VindexFunc", 428 "Variant": "VindexMap", 429 "Columns": [ 430 0, 431 1 432 ], 433 "Fields": { 434 "id": "VARBINARY", 435 "keyspace_id": "VARBINARY" 436 }, 437 "Value": ":id", 438 "Vindex": "user_index" 439 }, 440 { 441 "OperatorType": "Route", 442 "Variant": "Unsharded", 443 "Keyspace": { 444 "Name": "main", 445 "Sharded": false 446 }, 447 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 448 "Query": "select unsharded.id from unsharded where unsharded.id = :user_index_id", 449 "Table": "unsharded" 450 } 451 ] 452 }, 453 "TablesUsed": [ 454 "main.unsharded", 455 "user_index" 456 ] 457 } 458 }, 459 { 460 "comment": "Join with vindexFunc on a column of it, already present at the end of the select list", 461 "query": "select user_index.keyspace_id, user_index.id, unsharded.id from user_index join unsharded where user_index.id = :id and unsharded.id = user_index.id", 462 "v3-plan": { 463 "QueryType": "SELECT", 464 "Original": "select user_index.keyspace_id, user_index.id, unsharded.id from user_index join unsharded where user_index.id = :id and unsharded.id = user_index.id", 465 "Instructions": { 466 "OperatorType": "Join", 467 "Variant": "Join", 468 "JoinColumnIndexes": "L:0,L:1,R:0", 469 "JoinVars": { 470 "user_index_id": 1 471 }, 472 "TableName": "_unsharded", 473 "Inputs": [ 474 { 475 "OperatorType": "VindexFunc", 476 "Variant": "VindexMap", 477 "Columns": [ 478 1, 479 0 480 ], 481 "Fields": { 482 "id": "VARBINARY", 483 "keyspace_id": "VARBINARY" 484 }, 485 "Value": ":id", 486 "Vindex": "user_index" 487 }, 488 { 489 "OperatorType": "Route", 490 "Variant": "Unsharded", 491 "Keyspace": { 492 "Name": "main", 493 "Sharded": false 494 }, 495 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 496 "Query": "select unsharded.id from unsharded where unsharded.id = :user_index_id", 497 "Table": "unsharded" 498 } 499 ] 500 } 501 }, 502 "gen4-plan": { 503 "QueryType": "SELECT", 504 "Original": "select user_index.keyspace_id, user_index.id, unsharded.id from user_index join unsharded where user_index.id = :id and unsharded.id = user_index.id", 505 "Instructions": { 506 "OperatorType": "Join", 507 "Variant": "Join", 508 "JoinColumnIndexes": "L:1,L:0,R:0", 509 "JoinVars": { 510 "user_index_id": 0 511 }, 512 "TableName": "_unsharded", 513 "Inputs": [ 514 { 515 "OperatorType": "VindexFunc", 516 "Variant": "VindexMap", 517 "Columns": [ 518 0, 519 1 520 ], 521 "Fields": { 522 "id": "VARBINARY", 523 "keyspace_id": "VARBINARY" 524 }, 525 "Value": ":id", 526 "Vindex": "user_index" 527 }, 528 { 529 "OperatorType": "Route", 530 "Variant": "Unsharded", 531 "Keyspace": { 532 "Name": "main", 533 "Sharded": false 534 }, 535 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 536 "Query": "select unsharded.id from unsharded where unsharded.id = :user_index_id", 537 "Table": "unsharded" 538 } 539 ] 540 }, 541 "TablesUsed": [ 542 "main.unsharded", 543 "user_index" 544 ] 545 } 546 }, 547 { 548 "comment": "Join with vindexFunc on a column of it, not present in select list", 549 "query": "select user_index.keyspace_id, unsharded.id from user_index join unsharded where user_index.id = :id and unsharded.id = user_index.id", 550 "v3-plan": { 551 "QueryType": "SELECT", 552 "Original": "select user_index.keyspace_id, unsharded.id from user_index join unsharded where user_index.id = :id and unsharded.id = user_index.id", 553 "Instructions": { 554 "OperatorType": "Join", 555 "Variant": "Join", 556 "JoinColumnIndexes": "L:0,R:0", 557 "JoinVars": { 558 "user_index_id": 1 559 }, 560 "TableName": "_unsharded", 561 "Inputs": [ 562 { 563 "OperatorType": "VindexFunc", 564 "Variant": "VindexMap", 565 "Columns": [ 566 1, 567 0 568 ], 569 "Fields": { 570 "id": "VARBINARY", 571 "keyspace_id": "VARBINARY" 572 }, 573 "Value": ":id", 574 "Vindex": "user_index" 575 }, 576 { 577 "OperatorType": "Route", 578 "Variant": "Unsharded", 579 "Keyspace": { 580 "Name": "main", 581 "Sharded": false 582 }, 583 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 584 "Query": "select unsharded.id from unsharded where unsharded.id = :user_index_id", 585 "Table": "unsharded" 586 } 587 ] 588 } 589 }, 590 "gen4-plan": { 591 "QueryType": "SELECT", 592 "Original": "select user_index.keyspace_id, unsharded.id from user_index join unsharded where user_index.id = :id and unsharded.id = user_index.id", 593 "Instructions": { 594 "OperatorType": "Join", 595 "Variant": "Join", 596 "JoinColumnIndexes": "L:1,R:0", 597 "JoinVars": { 598 "user_index_id": 0 599 }, 600 "TableName": "_unsharded", 601 "Inputs": [ 602 { 603 "OperatorType": "VindexFunc", 604 "Variant": "VindexMap", 605 "Columns": [ 606 0, 607 1 608 ], 609 "Fields": { 610 "id": "VARBINARY", 611 "keyspace_id": "VARBINARY" 612 }, 613 "Value": ":id", 614 "Vindex": "user_index" 615 }, 616 { 617 "OperatorType": "Route", 618 "Variant": "Unsharded", 619 "Keyspace": { 620 "Name": "main", 621 "Sharded": false 622 }, 623 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 624 "Query": "select unsharded.id from unsharded where unsharded.id = :user_index_id", 625 "Table": "unsharded" 626 } 627 ] 628 }, 629 "TablesUsed": [ 630 "main.unsharded", 631 "user_index" 632 ] 633 } 634 }, 635 { 636 "comment": "Join with aliased table name", 637 "query": "select ui.keyspace_id, unsharded.id from user_index ui join unsharded where ui.id = :id and unsharded.id = ui.id", 638 "v3-plan": { 639 "QueryType": "SELECT", 640 "Original": "select ui.keyspace_id, unsharded.id from user_index ui join unsharded where ui.id = :id and unsharded.id = ui.id", 641 "Instructions": { 642 "OperatorType": "Join", 643 "Variant": "Join", 644 "JoinColumnIndexes": "L:0,R:0", 645 "JoinVars": { 646 "ui_id": 1 647 }, 648 "TableName": "_unsharded", 649 "Inputs": [ 650 { 651 "OperatorType": "VindexFunc", 652 "Variant": "VindexMap", 653 "Columns": [ 654 1, 655 0 656 ], 657 "Fields": { 658 "id": "VARBINARY", 659 "keyspace_id": "VARBINARY" 660 }, 661 "Value": ":id", 662 "Vindex": "user_index" 663 }, 664 { 665 "OperatorType": "Route", 666 "Variant": "Unsharded", 667 "Keyspace": { 668 "Name": "main", 669 "Sharded": false 670 }, 671 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 672 "Query": "select unsharded.id from unsharded where unsharded.id = :ui_id", 673 "Table": "unsharded" 674 } 675 ] 676 } 677 }, 678 "gen4-plan": { 679 "QueryType": "SELECT", 680 "Original": "select ui.keyspace_id, unsharded.id from user_index ui join unsharded where ui.id = :id and unsharded.id = ui.id", 681 "Instructions": { 682 "OperatorType": "Join", 683 "Variant": "Join", 684 "JoinColumnIndexes": "L:1,R:0", 685 "JoinVars": { 686 "ui_id": 0 687 }, 688 "TableName": "_unsharded", 689 "Inputs": [ 690 { 691 "OperatorType": "VindexFunc", 692 "Variant": "VindexMap", 693 "Columns": [ 694 0, 695 1 696 ], 697 "Fields": { 698 "id": "VARBINARY", 699 "keyspace_id": "VARBINARY" 700 }, 701 "Value": ":id", 702 "Vindex": "user_index" 703 }, 704 { 705 "OperatorType": "Route", 706 "Variant": "Unsharded", 707 "Keyspace": { 708 "Name": "main", 709 "Sharded": false 710 }, 711 "FieldQuery": "select unsharded.id from unsharded where 1 != 1", 712 "Query": "select unsharded.id from unsharded where unsharded.id = :ui_id", 713 "Table": "unsharded" 714 } 715 ] 716 }, 717 "TablesUsed": [ 718 "main.unsharded", 719 "user_index" 720 ] 721 } 722 }, 723 { 724 "comment": "select none from user_index where id = :id", 725 "query": "select none from user_index where id = :id", 726 "v3-plan": "VT03019: symbol `none` not found", 727 "gen4-plan": "symbol `none` not found" 728 } 729 ]