github.com/dolthub/go-mysql-server@v0.18.0/sql/planbuilder/parse_old_test.go (about) 1 // Copyright 2020-2021 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package planbuilder 16 17 import ( 18 "fmt" 19 "sort" 20 "testing" 21 "time" 22 23 "github.com/dolthub/vitess/go/vt/sqlparser" 24 "github.com/pmezard/go-difflib/difflib" 25 "github.com/stretchr/testify/assert" 26 "github.com/stretchr/testify/require" 27 "gopkg.in/src-d/go-errors.v1" 28 29 "github.com/dolthub/go-mysql-server/sql" 30 "github.com/dolthub/go-mysql-server/sql/expression" 31 "github.com/dolthub/go-mysql-server/sql/plan" 32 "github.com/dolthub/go-mysql-server/sql/types" 33 ) 34 35 var showCollationProjection = plan.NewProject([]sql.Expression{ 36 expression.NewAlias("collation", expression.NewUnresolvedColumn("collation_name")), 37 expression.NewAlias("charset", expression.NewUnresolvedColumn("character_set_name")), 38 expression.NewUnresolvedColumn("id"), 39 expression.NewAlias("default", expression.NewUnresolvedColumn("is_default")), 40 expression.NewAlias("compiled", expression.NewUnresolvedColumn("is_compiled")), 41 expression.NewUnresolvedColumn("sortlen"), 42 expression.NewUnresolvedColumn("pad_attribute"), 43 }, 44 plan.NewUnresolvedTable("collations", "information_schema"), 45 ) 46 47 type parseTest struct { 48 input string 49 plan sql.Node 50 } 51 52 func TestParse(t *testing.T) { 53 t.Skip("todo use planbuilder") 54 // var fixtures = []parseTest{ 55 // { 56 // input: `CREATE TABLE t1(a INTEGER, b TEXT, c DATE, d TIMESTAMP, e VARCHAR(20), f BLOB NOT NULL, g DATETIME, h CHAR(40))`, 57 // plan: plan.NewCreateTable( 58 // sql.UnresolvedDatabase(""), 59 // "t1", 60 // plan.IfNotExistsAbsent, 61 // plan.IsTempTableAbsent, 62 // &plan.TableSpec{ 63 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 64 // Name: "a", 65 // Type: types.Int32, 66 // Nullable: true, 67 // }, { 68 // Name: "b", 69 // Type: types.Text, 70 // Nullable: true, 71 // }, { 72 // Name: "c", 73 // Type: types.Date, 74 // Nullable: true, 75 // }, { 76 // Name: "d", 77 // Type: types.Timestamp, 78 // Nullable: true, 79 // }, { 80 // Name: "e", 81 // Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), 82 // Nullable: true, 83 // }, { 84 // Name: "f", 85 // Type: types.Blob, 86 // Nullable: false, 87 // }, { 88 // Name: "g", 89 // Type: types.Datetime, 90 // Nullable: true, 91 // }, { 92 // Name: "h", 93 // Type: types.MustCreateStringWithDefaults(sqltypes.Char, 40), 94 // Nullable: true, 95 // }}), 96 // }, 97 // ), 98 // }, 99 // { 100 // input: `CREATE TABLE t1(a INTEGER NOT NULL PRIMARY KEY, b TEXT)`, 101 // plan: plan.NewCreateTable( 102 // sql.UnresolvedDatabase(""), 103 // "t1", 104 // plan.IfNotExistsAbsent, 105 // plan.IsTempTableAbsent, 106 // &plan.TableSpec{ 107 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 108 // Name: "a", 109 // Type: types.Int32, 110 // Nullable: false, 111 // PrimaryKey: true, 112 // }, { 113 // Name: "b", 114 // Type: types.Text, 115 // Nullable: true, 116 // PrimaryKey: false, 117 // }}), 118 // }, 119 // ), 120 // }, 121 // { 122 // input: `CREATE TABLE t1(a INTEGER NOT NULL PRIMARY KEY COMMENT "hello", b TEXT COMMENT "goodbye")`, 123 // plan: plan.NewCreateTable( 124 // sql.UnresolvedDatabase(""), 125 // "t1", 126 // plan.IfNotExistsAbsent, 127 // plan.IsTempTableAbsent, 128 // &plan.TableSpec{ 129 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 130 // Name: "a", 131 // Type: types.Int32, 132 // Nullable: false, 133 // PrimaryKey: true, 134 // Comment: "hello", 135 // }, { 136 // Name: "b", 137 // Type: types.Text, 138 // Nullable: true, 139 // PrimaryKey: false, 140 // Comment: "goodbye", 141 // }}), 142 // }, 143 // ), 144 // }, 145 // { 146 // input: `CREATE TABLE t1(a INTEGER, b TEXT, PRIMARY KEY (a))`, 147 // plan: plan.NewCreateTable( 148 // sql.UnresolvedDatabase(""), 149 // "t1", 150 // plan.IfNotExistsAbsent, 151 // plan.IsTempTableAbsent, 152 // &plan.TableSpec{ 153 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 154 // Name: "a", 155 // Type: types.Int32, 156 // Nullable: false, 157 // PrimaryKey: true, 158 // }, { 159 // Name: "b", 160 // Type: types.Text, 161 // Nullable: true, 162 // PrimaryKey: false, 163 // }}), 164 // IdxDefs: []*plan.IndexDefinition{ 165 // { 166 // IndexName: "PRIMARY", 167 // Columns: []sql.IndexColumn{ 168 // {Name: "a"}, 169 // }, 170 // Constraint: sql.IndexConstraint_Primary, 171 // }, 172 // }, 173 // }, 174 // ), 175 // }, 176 // { 177 // input: `CREATE TABLE t1(a INTEGER, b TEXT, PRIMARY KEY (a, b))`, 178 // plan: plan.NewCreateTable( 179 // sql.UnresolvedDatabase(""), 180 // "t1", 181 // plan.IfNotExistsAbsent, 182 // plan.IsTempTableAbsent, 183 // &plan.TableSpec{ 184 // Schema: sql.NewPrimaryKeySchema( 185 // sql.Schema{{ 186 // Name: "a", 187 // Type: types.Int32, 188 // Nullable: false, 189 // PrimaryKey: true, 190 // }, { 191 // Name: "b", 192 // Type: types.Text, 193 // Nullable: false, 194 // PrimaryKey: true, 195 // }}), 196 // IdxDefs: []*plan.IndexDefinition{ 197 // { 198 // IndexName: "PRIMARY", 199 // Columns: []sql.IndexColumn{ 200 // {Name: "a"}, 201 // {Name: "b"}, 202 // }, 203 // Constraint: sql.IndexConstraint_Primary, 204 // }, 205 // }, 206 // }, 207 // ), 208 // }, 209 // { 210 // input: `CREATE TABLE t1(a INTEGER, b TEXT, PRIMARY KEY (b, a))`, 211 // plan: plan.NewCreateTable( 212 // sql.UnresolvedDatabase(""), 213 // "t1", 214 // plan.IfNotExistsAbsent, 215 // plan.IsTempTableAbsent, 216 // &plan.TableSpec{ 217 // Schema: sql.NewPrimaryKeySchema( 218 // sql.Schema{{ 219 // Name: "a", 220 // Type: types.Int32, 221 // Nullable: false, 222 // PrimaryKey: true, 223 // }, { 224 // Name: "b", 225 // Type: types.Text, 226 // Nullable: false, 227 // PrimaryKey: true, 228 // }}, 1, 0), 229 // IdxDefs: []*plan.IndexDefinition{ 230 // { 231 // IndexName: "PRIMARY", 232 // Columns: []sql.IndexColumn{ 233 // {Name: "b"}, 234 // {Name: "a"}, 235 // }, 236 // Constraint: sql.IndexConstraint_Primary, 237 // }, 238 // }, 239 // }, 240 // ), 241 // }, 242 // { 243 // input: `CREATE TABLE t1(a INTEGER, b int, CONSTRAINT pk PRIMARY KEY (b, a), CONSTRAINT UNIQUE KEY (a))`, 244 // plan: plan.NewCreateTable( 245 // sql.UnresolvedDatabase(""), 246 // "t1", 247 // plan.IfNotExistsAbsent, 248 // plan.IsTempTableAbsent, 249 // &plan.TableSpec{ 250 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 251 // Name: "a", 252 // Type: types.Int32, 253 // Nullable: false, 254 // PrimaryKey: true, 255 // }, { 256 // Name: "b", 257 // Type: types.Int32, 258 // Nullable: false, 259 // PrimaryKey: true, 260 // }}, 1, 0), 261 // IdxDefs: []*plan.IndexDefinition{ 262 // { 263 // IndexName: "pk", 264 // Columns: []sql.IndexColumn{ 265 // {Name: "b"}, 266 // {Name: "a"}, 267 // }, 268 // Constraint: sql.IndexConstraint_Primary, 269 // }, 270 // { 271 // Columns: []sql.IndexColumn{ 272 // {Name: "a"}, 273 // }, 274 // Constraint: sql.IndexConstraint_Unique, 275 // }, 276 // }, 277 // }, 278 // ), 279 // }, 280 // { 281 // input: `CREATE TABLE IF NOT EXISTS t1(a INTEGER, b TEXT, PRIMARY KEY (a, b))`, 282 // plan: plan.NewCreateTable( 283 // sql.UnresolvedDatabase(""), 284 // "t1", 285 // plan.IfNotExists, 286 // plan.IsTempTableAbsent, 287 // &plan.TableSpec{ 288 // Schema: sql.NewPrimaryKeySchema( 289 // sql.Schema{{ 290 // Name: "a", 291 // Type: types.Int32, 292 // Nullable: false, 293 // PrimaryKey: true, 294 // }, { 295 // Name: "b", 296 // Type: types.Text, 297 // Nullable: false, 298 // PrimaryKey: true, 299 // }}), 300 // IdxDefs: []*plan.IndexDefinition{ 301 // { 302 // IndexName: "PRIMARY", 303 // Constraint: sql.IndexConstraint_Primary, 304 // Columns: []sql.IndexColumn{ 305 // {Name: "a"}, 306 // {Name: "b"}, 307 // }, 308 // }, 309 // }, 310 // }, 311 // ), 312 // }, 313 // { 314 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER, INDEX (b))`, 315 // plan: plan.NewCreateTable( 316 // sql.UnresolvedDatabase(""), 317 // "t1", 318 // plan.IfNotExistsAbsent, 319 // plan.IsTempTableAbsent, 320 // &plan.TableSpec{ 321 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 322 // Name: "a", 323 // Type: types.Int32, 324 // Nullable: false, 325 // PrimaryKey: true, 326 // }, { 327 // Name: "b", 328 // Type: types.Int32, 329 // Nullable: true, 330 // PrimaryKey: false, 331 // }}), 332 // IdxDefs: []*plan.IndexDefinition{ 333 // { 334 // IndexName: "", 335 // Using: sql.IndexUsing_Default, 336 // Constraint: sql.IndexConstraint_None, 337 // Columns: []sql.IndexColumn{{"b", 0}}, 338 // Comment: "", 339 // }, 340 // }, 341 // }, 342 // ), 343 // }, 344 // { 345 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER, INDEX idx_name (b))`, 346 // plan: plan.NewCreateTable( 347 // sql.UnresolvedDatabase(""), 348 // "t1", 349 // plan.IfNotExistsAbsent, 350 // plan.IsTempTableAbsent, 351 // &plan.TableSpec{ 352 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 353 // Name: "a", 354 // Type: types.Int32, 355 // Nullable: false, 356 // PrimaryKey: true, 357 // }, { 358 // Name: "b", 359 // Type: types.Int32, 360 // Nullable: true, 361 // PrimaryKey: false, 362 // }}), 363 // IdxDefs: []*plan.IndexDefinition{{ 364 // IndexName: "idx_name", 365 // Using: sql.IndexUsing_Default, 366 // Constraint: sql.IndexConstraint_None, 367 // Columns: []sql.IndexColumn{{"b", 0}}, 368 // Comment: "", 369 // }}, 370 // }, 371 // ), 372 // }, 373 // { 374 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER, INDEX idx_name (b) COMMENT 'hi')`, 375 // plan: plan.NewCreateTable( 376 // sql.UnresolvedDatabase(""), 377 // "t1", 378 // plan.IfNotExistsAbsent, 379 // plan.IsTempTableAbsent, 380 // &plan.TableSpec{ 381 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 382 // Name: "a", 383 // Type: types.Int32, 384 // Nullable: false, 385 // PrimaryKey: true, 386 // }, { 387 // Name: "b", 388 // Type: types.Int32, 389 // Nullable: true, 390 // PrimaryKey: false, 391 // }}), 392 // IdxDefs: []*plan.IndexDefinition{{ 393 // IndexName: "idx_name", 394 // Using: sql.IndexUsing_Default, 395 // Constraint: sql.IndexConstraint_None, 396 // Columns: []sql.IndexColumn{{"b", 0}}, 397 // Comment: "hi", 398 // }}, 399 // }, 400 // ), 401 // }, 402 // { 403 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER, UNIQUE INDEX (b))`, 404 // plan: plan.NewCreateTable( 405 // sql.UnresolvedDatabase(""), 406 // "t1", 407 // plan.IfNotExistsAbsent, 408 // plan.IsTempTableAbsent, 409 // &plan.TableSpec{ 410 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 411 // Name: "a", 412 // Type: types.Int32, 413 // Nullable: false, 414 // PrimaryKey: true, 415 // }, { 416 // Name: "b", 417 // Type: types.Int32, 418 // Nullable: true, 419 // PrimaryKey: false, 420 // }}), 421 // IdxDefs: []*plan.IndexDefinition{{ 422 // IndexName: "", 423 // Using: sql.IndexUsing_Default, 424 // Constraint: sql.IndexConstraint_Unique, 425 // Columns: []sql.IndexColumn{{"b", 0}}, 426 // Comment: "", 427 // }}, 428 // }, 429 // ), 430 // }, 431 // { 432 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER, UNIQUE (b))`, 433 // plan: plan.NewCreateTable( 434 // sql.UnresolvedDatabase(""), 435 // "t1", 436 // plan.IfNotExistsAbsent, 437 // plan.IsTempTableAbsent, 438 // &plan.TableSpec{ 439 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 440 // Name: "a", 441 // Type: types.Int32, 442 // Nullable: false, 443 // PrimaryKey: true, 444 // }, { 445 // Name: "b", 446 // Type: types.Int32, 447 // Nullable: true, 448 // PrimaryKey: false, 449 // }}), 450 // IdxDefs: []*plan.IndexDefinition{{ 451 // IndexName: "", 452 // Using: sql.IndexUsing_Default, 453 // Constraint: sql.IndexConstraint_Unique, 454 // Columns: []sql.IndexColumn{{"b", 0}}, 455 // Comment: "", 456 // }}, 457 // }, 458 // ), 459 // }, 460 // { 461 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER, INDEX (b, a))`, 462 // plan: plan.NewCreateTable( 463 // sql.UnresolvedDatabase(""), 464 // "t1", 465 // plan.IfNotExistsAbsent, 466 // plan.IsTempTableAbsent, 467 // &plan.TableSpec{ 468 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 469 // Name: "a", 470 // Type: types.Int32, 471 // Nullable: false, 472 // PrimaryKey: true, 473 // }, { 474 // Name: "b", 475 // Type: types.Int32, 476 // Nullable: true, 477 // PrimaryKey: false, 478 // }}), 479 // IdxDefs: []*plan.IndexDefinition{{ 480 // IndexName: "", 481 // Using: sql.IndexUsing_Default, 482 // Constraint: sql.IndexConstraint_None, 483 // Columns: []sql.IndexColumn{{"b", 0}, {"a", 0}}, 484 // Comment: "", 485 // }}, 486 // }, 487 // ), 488 // }, 489 // { 490 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER, INDEX (b), INDEX (b, a))`, 491 // plan: plan.NewCreateTable( 492 // sql.UnresolvedDatabase(""), 493 // "t1", 494 // plan.IfNotExistsAbsent, 495 // plan.IsTempTableAbsent, 496 // &plan.TableSpec{ 497 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 498 // Name: "a", 499 // Type: types.Int32, 500 // Nullable: false, 501 // PrimaryKey: true, 502 // }, { 503 // Name: "b", 504 // Type: types.Int32, 505 // Nullable: true, 506 // PrimaryKey: false, 507 // }}), 508 // IdxDefs: []*plan.IndexDefinition{{ 509 // IndexName: "", 510 // Using: sql.IndexUsing_Default, 511 // Constraint: sql.IndexConstraint_None, 512 // Columns: []sql.IndexColumn{{"b", 0}}, 513 // Comment: "", 514 // }, { 515 // IndexName: "", 516 // Using: sql.IndexUsing_Default, 517 // Constraint: sql.IndexConstraint_None, 518 // Columns: []sql.IndexColumn{{"b", 0}, {"a", 0}}, 519 // Comment: "", 520 // }}, 521 // }, 522 // ), 523 // }, 524 // { 525 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b_id INTEGER, FOREIGN KEY (b_id) REFERENCES t0(b))`, 526 // plan: plan.NewCreateTable( 527 // sql.UnresolvedDatabase(""), 528 // "t1", 529 // plan.IfNotExistsAbsent, 530 // plan.IsTempTableAbsent, 531 // &plan.TableSpec{ 532 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 533 // Name: "a", 534 // Type: types.Int32, 535 // Nullable: false, 536 // PrimaryKey: true, 537 // }, { 538 // Name: "b_id", 539 // Type: types.Int32, 540 // Nullable: true, 541 // PrimaryKey: false, 542 // }}), 543 // FkDefs: []*sql.ForeignKeyConstraint{{ 544 // Name: "", 545 // Database: "", 546 // Table: "t1", 547 // Columns: []string{"b_id"}, 548 // ParentDatabase: "", 549 // ParentTable: "t0", 550 // ParentColumns: []string{"b"}, 551 // OnUpdate: sql.ForeignKeyReferentialAction_DefaultAction, 552 // OnDelete: sql.ForeignKeyReferentialAction_DefaultAction, 553 // IsResolved: false, 554 // }}, 555 // }, 556 // ), 557 // }, 558 // { 559 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b_id INTEGER, CONSTRAINT fk_name FOREIGN KEY (b_id) REFERENCES t0(b))`, 560 // plan: plan.NewCreateTable( 561 // sql.UnresolvedDatabase(""), 562 // "t1", 563 // plan.IfNotExistsAbsent, 564 // plan.IsTempTableAbsent, 565 // &plan.TableSpec{ 566 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 567 // Name: "a", 568 // Type: types.Int32, 569 // Nullable: false, 570 // PrimaryKey: true, 571 // }, { 572 // Name: "b_id", 573 // Type: types.Int32, 574 // Nullable: true, 575 // PrimaryKey: false, 576 // }}), 577 // FkDefs: []*sql.ForeignKeyConstraint{{ 578 // Name: "fk_name", 579 // Database: "", 580 // Table: "t1", 581 // Columns: []string{"b_id"}, 582 // ParentDatabase: "", 583 // ParentTable: "t0", 584 // ParentColumns: []string{"b"}, 585 // OnUpdate: sql.ForeignKeyReferentialAction_DefaultAction, 586 // OnDelete: sql.ForeignKeyReferentialAction_DefaultAction, 587 // IsResolved: false, 588 // }}, 589 // }, 590 // ), 591 // }, 592 // { 593 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b_id INTEGER, FOREIGN KEY (b_id) REFERENCES t0(b) ON UPDATE CASCADE)`, 594 // plan: plan.NewCreateTable( 595 // sql.UnresolvedDatabase(""), 596 // "t1", 597 // plan.IfNotExistsAbsent, 598 // plan.IsTempTableAbsent, 599 // &plan.TableSpec{ 600 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 601 // Name: "a", 602 // Type: types.Int32, 603 // Nullable: false, 604 // PrimaryKey: true, 605 // }, { 606 // Name: "b_id", 607 // Type: types.Int32, 608 // Nullable: true, 609 // PrimaryKey: false, 610 // }}), 611 // FkDefs: []*sql.ForeignKeyConstraint{{ 612 // Name: "", 613 // Database: "", 614 // Table: "t1", 615 // Columns: []string{"b_id"}, 616 // ParentDatabase: "", 617 // ParentTable: "t0", 618 // ParentColumns: []string{"b"}, 619 // OnUpdate: sql.ForeignKeyReferentialAction_Cascade, 620 // OnDelete: sql.ForeignKeyReferentialAction_DefaultAction, 621 // IsResolved: false, 622 // }}, 623 // }, 624 // ), 625 // }, 626 // { 627 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b_id INTEGER, FOREIGN KEY (b_id) REFERENCES t0(b) ON DELETE RESTRICT)`, 628 // plan: plan.NewCreateTable( 629 // sql.UnresolvedDatabase(""), 630 // "t1", 631 // plan.IfNotExistsAbsent, 632 // plan.IsTempTableAbsent, 633 // &plan.TableSpec{ 634 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 635 // Name: "a", 636 // Type: types.Int32, 637 // Nullable: false, 638 // PrimaryKey: true, 639 // }, { 640 // Name: "b_id", 641 // Type: types.Int32, 642 // Nullable: true, 643 // PrimaryKey: false, 644 // }}), 645 // FkDefs: []*sql.ForeignKeyConstraint{{ 646 // Name: "", 647 // Database: "", 648 // Table: "t1", 649 // Columns: []string{"b_id"}, 650 // ParentDatabase: "", 651 // ParentTable: "t0", 652 // ParentColumns: []string{"b"}, 653 // OnUpdate: sql.ForeignKeyReferentialAction_DefaultAction, 654 // OnDelete: sql.ForeignKeyReferentialAction_Restrict, 655 // IsResolved: false, 656 // }}, 657 // }, 658 // ), 659 // }, 660 // { 661 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b_id INTEGER, FOREIGN KEY (b_id) REFERENCES t0(b) ON UPDATE SET NULL ON DELETE NO ACTION)`, 662 // plan: plan.NewCreateTable( 663 // sql.UnresolvedDatabase(""), 664 // "t1", 665 // plan.IfNotExistsAbsent, 666 // plan.IsTempTableAbsent, 667 // &plan.TableSpec{ 668 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 669 // Name: "a", 670 // Type: types.Int32, 671 // Nullable: false, 672 // PrimaryKey: true, 673 // }, { 674 // Name: "b_id", 675 // Type: types.Int32, 676 // Nullable: true, 677 // PrimaryKey: false, 678 // }}), 679 // 680 // FkDefs: []*sql.ForeignKeyConstraint{{ 681 // Name: "", 682 // Database: "", 683 // Table: "t1", 684 // Columns: []string{"b_id"}, 685 // ParentDatabase: "", 686 // ParentTable: "t0", 687 // ParentColumns: []string{"b"}, 688 // OnUpdate: sql.ForeignKeyReferentialAction_SetNull, 689 // OnDelete: sql.ForeignKeyReferentialAction_NoAction, 690 // IsResolved: false, 691 // }}, 692 // }, 693 // ), 694 // }, 695 // { 696 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b_id INTEGER, c_id BIGINT, FOREIGN KEY (b_id, c_id) REFERENCES t0(b, c))`, 697 // plan: plan.NewCreateTable( 698 // sql.UnresolvedDatabase(""), 699 // "t1", 700 // plan.IfNotExistsAbsent, 701 // plan.IsTempTableAbsent, 702 // &plan.TableSpec{ 703 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 704 // Name: "a", 705 // Type: types.Int32, 706 // Nullable: false, 707 // PrimaryKey: true, 708 // }, { 709 // Name: "b_id", 710 // Type: types.Int32, 711 // Nullable: true, 712 // PrimaryKey: false, 713 // }, { 714 // Name: "c_id", 715 // Type: types.Int64, 716 // Nullable: true, 717 // PrimaryKey: false, 718 // }}), 719 // FkDefs: []*sql.ForeignKeyConstraint{{ 720 // Name: "", 721 // Database: "", 722 // Table: "t1", 723 // Columns: []string{"b_id", "c_id"}, 724 // ParentDatabase: "", 725 // ParentTable: "t0", 726 // ParentColumns: []string{"b", "c"}, 727 // OnUpdate: sql.ForeignKeyReferentialAction_DefaultAction, 728 // OnDelete: sql.ForeignKeyReferentialAction_DefaultAction, 729 // IsResolved: false, 730 // }}, 731 // }, 732 // ), 733 // }, 734 // { 735 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, b_id INTEGER, c_id BIGINT, CONSTRAINT fk_name FOREIGN KEY (b_id, c_id) REFERENCES t0(b, c) ON UPDATE RESTRICT ON DELETE CASCADE)`, 736 // plan: plan.NewCreateTable( 737 // sql.UnresolvedDatabase(""), 738 // "t1", 739 // plan.IfNotExistsAbsent, 740 // plan.IsTempTableAbsent, 741 // &plan.TableSpec{ 742 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 743 // Name: "a", 744 // Type: types.Int32, 745 // Nullable: false, 746 // PrimaryKey: true, 747 // }, { 748 // Name: "b_id", 749 // Type: types.Int32, 750 // Nullable: true, 751 // PrimaryKey: false, 752 // }, { 753 // Name: "c_id", 754 // Type: types.Int64, 755 // Nullable: true, 756 // PrimaryKey: false, 757 // }}), 758 // FkDefs: []*sql.ForeignKeyConstraint{{ 759 // Name: "fk_name", 760 // Database: "", 761 // Table: "t1", 762 // Columns: []string{"b_id", "c_id"}, 763 // ParentDatabase: "", 764 // ParentTable: "t0", 765 // ParentColumns: []string{"b", "c"}, 766 // OnUpdate: sql.ForeignKeyReferentialAction_Restrict, 767 // OnDelete: sql.ForeignKeyReferentialAction_Cascade, 768 // IsResolved: false, 769 // }}, 770 // }, 771 // ), 772 // }, 773 // { 774 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, CHECK (a > 0))`, 775 // plan: plan.NewCreateTable( 776 // sql.UnresolvedDatabase(""), 777 // "t1", 778 // plan.IfNotExistsAbsent, 779 // plan.IsTempTableAbsent, 780 // &plan.TableSpec{ 781 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 782 // Name: "a", 783 // Type: types.Int32, 784 // Nullable: false, 785 // PrimaryKey: true, 786 // }}), 787 // ChDefs: []*sql.CheckConstraint{{ 788 // Name: "", 789 // Expr: expression.NewGreaterThan( 790 // expression.NewUnresolvedColumn("a"), 791 // expression.NewLiteral(int8(0), types.Int8), 792 // ), 793 // Enforced: true, 794 // }}, 795 // }, 796 // ), 797 // }, 798 // { 799 // input: ` 800 //CREATE TABLE t4 801 //( 802 // CHECK (c1 = c2), 803 // c1 INT CHECK (c1 > 10), 804 // c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), 805 // CHECK (c1 > c3) 806 //);`, 807 // plan: plan.NewCreateTable( 808 // sql.UnresolvedDatabase(""), 809 // "t4", 810 // plan.IfNotExistsAbsent, 811 // plan.IsTempTableAbsent, 812 // &plan.TableSpec{ 813 // Schema: sql.NewPrimaryKeySchema(sql.Schema{ 814 // { 815 // Name: "c1", 816 // Source: "t4", 817 // Type: types.Int32, 818 // Nullable: true, 819 // }, 820 // { 821 // Name: "c2", 822 // Source: "t4", 823 // Type: types.Int32, 824 // Nullable: true, 825 // }, 826 // }), 827 // ChDefs: []*sql.CheckConstraint{ 828 // { 829 // Expr: expression.NewEquals( 830 // expression.NewUnresolvedColumn("c1"), 831 // expression.NewUnresolvedColumn("c2"), 832 // ), 833 // Enforced: true, 834 // }, 835 // { 836 // Expr: expression.NewGreaterThan( 837 // expression.NewUnresolvedColumn("c1"), 838 // expression.NewLiteral(int8(10), types.Int8), 839 // ), 840 // Enforced: true, 841 // }, 842 // { 843 // Name: "c2_positive", 844 // Expr: expression.NewGreaterThan( 845 // expression.NewUnresolvedColumn("c2"), 846 // expression.NewLiteral(int8(0), types.Int8), 847 // ), 848 // Enforced: true, 849 // }, 850 // { 851 // Expr: expression.NewGreaterThan( 852 // expression.NewUnresolvedColumn("c1"), 853 // expression.NewUnresolvedColumn("c3"), 854 // ), 855 // Enforced: true, 856 // }, 857 // }, 858 // }, 859 // ), 860 // }, 861 // { 862 // input: ` 863 //CREATE TABLE t2 864 //( 865 // CHECK (c1 = c2), 866 // c1 INT CHECK (c1 > 10), 867 // c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), 868 // c3 INT CHECK (c3 < 100), 869 // CONSTRAINT c1_nonzero CHECK (c1 = 0), 870 // CHECK (c1 > c3) 871 //);`, 872 // plan: plan.NewCreateTable( 873 // sql.UnresolvedDatabase(""), 874 // "t2", 875 // plan.IfNotExistsAbsent, 876 // plan.IsTempTableAbsent, 877 // &plan.TableSpec{ 878 // Schema: sql.NewPrimaryKeySchema(sql.Schema{ 879 // { 880 // Name: "c1", 881 // Source: "t2", 882 // Type: types.Int32, 883 // Nullable: true, 884 // }, 885 // { 886 // Name: "c2", 887 // Source: "t2", 888 // Type: types.Int32, 889 // Nullable: true, 890 // }, 891 // { 892 // Name: "c3", 893 // Source: "t2", 894 // Type: types.Int32, 895 // Nullable: true, 896 // }, 897 // }), 898 // ChDefs: []*sql.CheckConstraint{ 899 // { 900 // Expr: expression.NewEquals( 901 // expression.NewUnresolvedColumn("c1"), 902 // expression.NewUnresolvedColumn("c2"), 903 // ), 904 // Enforced: true, 905 // }, 906 // { 907 // Expr: expression.NewGreaterThan( 908 // expression.NewUnresolvedColumn("c1"), 909 // expression.NewLiteral(int8(10), types.Int8), 910 // ), 911 // Enforced: true, 912 // }, 913 // { 914 // Name: "c2_positive", 915 // Expr: expression.NewGreaterThan( 916 // expression.NewUnresolvedColumn("c2"), 917 // expression.NewLiteral(int8(0), types.Int8), 918 // ), 919 // Enforced: true, 920 // }, 921 // { 922 // Expr: expression.NewLessThan( 923 // expression.NewUnresolvedColumn("c3"), 924 // expression.NewLiteral(int8(100), types.Int8), 925 // ), 926 // Enforced: true, 927 // }, 928 // { 929 // Name: "c1_nonzero", 930 // Expr: expression.NewEquals( 931 // expression.NewUnresolvedColumn("c1"), 932 // expression.NewLiteral(int8(0), types.Int8), 933 // ), 934 // Enforced: true, 935 // }, 936 // { 937 // Expr: expression.NewGreaterThan( 938 // expression.NewUnresolvedColumn("c1"), 939 // expression.NewUnresolvedColumn("c3"), 940 // ), 941 // Enforced: true, 942 // }, 943 // }, 944 // }, 945 // ), 946 // }, 947 // { 948 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY CHECK (a > 0))`, 949 // plan: plan.NewCreateTable( 950 // sql.UnresolvedDatabase(""), 951 // "t1", 952 // plan.IfNotExistsAbsent, 953 // plan.IsTempTableAbsent, 954 // &plan.TableSpec{ 955 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 956 // Name: "a", 957 // Type: types.Int32, 958 // Nullable: false, 959 // PrimaryKey: true, 960 // }}), 961 // ChDefs: []*sql.CheckConstraint{{ 962 // Name: "", 963 // Expr: expression.NewGreaterThan( 964 // expression.NewUnresolvedColumn("a"), 965 // expression.NewLiteral(int8(0), types.Int8), 966 // ), 967 // Enforced: true, 968 // }}, 969 // }, 970 // ), 971 // }, 972 // { 973 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY, CONSTRAINT ch1 CHECK (a > 0))`, 974 // plan: plan.NewCreateTable( 975 // sql.UnresolvedDatabase(""), 976 // "t1", 977 // plan.IfNotExistsAbsent, 978 // plan.IsTempTableAbsent, 979 // &plan.TableSpec{ 980 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 981 // Name: "a", 982 // Type: types.Int32, 983 // Nullable: false, 984 // PrimaryKey: true, 985 // }}), 986 // ChDefs: []*sql.CheckConstraint{{ 987 // Name: "ch1", 988 // Expr: expression.NewGreaterThan( 989 // expression.NewUnresolvedColumn("a"), 990 // expression.NewLiteral(int8(0), types.Int8), 991 // ), 992 // Enforced: true, 993 // }}, 994 // }, 995 // ), 996 // }, 997 // { 998 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY CHECK (a > 0) ENFORCED)`, 999 // plan: plan.NewCreateTable( 1000 // sql.UnresolvedDatabase(""), 1001 // "t1", 1002 // plan.IfNotExistsAbsent, 1003 // plan.IsTempTableAbsent, 1004 // &plan.TableSpec{ 1005 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 1006 // Name: "a", 1007 // Type: types.Int32, 1008 // Nullable: false, 1009 // PrimaryKey: true, 1010 // }}), 1011 // ChDefs: []*sql.CheckConstraint{{ 1012 // Name: "", 1013 // Expr: expression.NewGreaterThan( 1014 // expression.NewUnresolvedColumn("a"), 1015 // expression.NewLiteral(int8(0), types.Int8), 1016 // ), 1017 // Enforced: true, 1018 // }}, 1019 // }, 1020 // ), 1021 // }, 1022 // { 1023 // input: `CREATE TABLE t1(a INTEGER PRIMARY KEY CHECK (a > 0) NOT ENFORCED)`, 1024 // plan: plan.NewCreateTable( 1025 // sql.UnresolvedDatabase(""), 1026 // "t1", 1027 // plan.IfNotExistsAbsent, 1028 // plan.IsTempTableAbsent, 1029 // &plan.TableSpec{ 1030 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 1031 // Name: "a", 1032 // Type: types.Int32, 1033 // Nullable: false, 1034 // PrimaryKey: true, 1035 // }}), 1036 // ChDefs: []*sql.CheckConstraint{{ 1037 // Name: "", 1038 // Expr: expression.NewGreaterThan( 1039 // expression.NewUnresolvedColumn("a"), 1040 // expression.NewLiteral(int8(0), types.Int8), 1041 // ), 1042 // Enforced: false, 1043 // }}, 1044 // }, 1045 // ), 1046 // }, 1047 // { 1048 // input: `CREATE TEMPORARY TABLE t1(a INTEGER, b TEXT)`, 1049 // plan: plan.NewCreateTable( 1050 // sql.UnresolvedDatabase(""), 1051 // "t1", 1052 // plan.IfNotExistsAbsent, 1053 // plan.IsTempTable, 1054 // &plan.TableSpec{ 1055 // Schema: sql.NewPrimaryKeySchema(sql.Schema{{ 1056 // Name: "a", 1057 // Type: types.Int32, 1058 // Nullable: true, 1059 // }, { 1060 // Name: "b", 1061 // Type: types.Text, 1062 // Nullable: true, 1063 // }}), 1064 // }, 1065 // ), 1066 // }, 1067 // { 1068 // input: `CREATE TEMPORARY TABLE mytable AS SELECT * from othertable`, 1069 // plan: plan.NewCreateTableSelect( 1070 // sql.UnresolvedDatabase(""), 1071 // "mytable", 1072 // plan.NewProject([]sql.Expression{expression.NewStar()}, plan.NewUnresolvedTable("othertable", "")), 1073 // &plan.TableSpec{}, 1074 // plan.IfNotExistsAbsent, 1075 // plan.IsTempTable), 1076 // }, 1077 // { 1078 // input: `DROP TABLE curdb.foo;`, 1079 // plan: plan.NewDropTable( 1080 // []sql.Node{plan.NewUnresolvedTable("foo", "curdb")}, false, 1081 // ), 1082 // }, 1083 // { 1084 // input: `DROP TABLE t1, t2;`, 1085 // plan: plan.NewDropTable( 1086 // []sql.Node{plan.NewUnresolvedTable("t1", ""), plan.NewUnresolvedTable("t2", "")}, false, 1087 // ), 1088 // }, 1089 // { 1090 // input: `DROP TABLE IF EXISTS curdb.foo;`, 1091 // plan: plan.NewDropTable( 1092 // []sql.Node{plan.NewUnresolvedTable("foo", "curdb")}, true, 1093 // ), 1094 // }, 1095 // { 1096 // input: `DROP TABLE IF EXISTS curdb.foo, curdb.bar, curdb.baz;`, 1097 // plan: plan.NewDropTable( 1098 // []sql.Node{plan.NewUnresolvedTable("foo", "curdb"), plan.NewUnresolvedTable("bar", "curdb"), plan.NewUnresolvedTable("baz", "curdb")}, true, 1099 // ), 1100 // }, 1101 // { 1102 // input: `RENAME TABLE foo TO bar`, 1103 // plan: plan.NewRenameTable(sql.UnresolvedDatabase(""), []string{"foo"}, []string{"bar"}, false), 1104 // }, 1105 // { 1106 // input: `RENAME TABLE foo TO bar, baz TO qux`, 1107 // plan: plan.NewRenameTable(sql.UnresolvedDatabase(""), []string{"foo", "baz"}, []string{"bar", "qux"}, false), 1108 // }, 1109 // { 1110 // input: `ALTER TABLE foo RENAME bar`, 1111 // plan: plan.NewRenameTable(sql.UnresolvedDatabase(""), []string{"foo"}, []string{"bar"}, true), 1112 // }, 1113 // { 1114 // input: `ALTER TABLE foo RENAME TO bar`, 1115 // plan: plan.NewRenameTable(sql.UnresolvedDatabase(""), []string{"foo"}, []string{"bar"}, true), 1116 // }, 1117 // { 1118 // input: `ALTER TABLE foo RENAME COLUMN bar TO baz`, 1119 // plan: plan.NewRenameColumn( 1120 // sql.UnresolvedDatabase(""), 1121 // plan.NewUnresolvedTable("foo", ""), "bar", "baz", 1122 // ), 1123 // }, 1124 // { 1125 // input: `ALTER TABLE otherdb.mytable RENAME COLUMN i TO s`, 1126 // plan: plan.NewRenameColumn( 1127 // sql.UnresolvedDatabase("otherdb"), 1128 // plan.NewUnresolvedTable("mytable", "otherdb"), "i", "s", 1129 // ), 1130 // }, 1131 // { 1132 // input: `ALTER TABLE mytable RENAME COLUMN bar TO baz, RENAME COLUMN abc TO xyz`, 1133 // plan: plan.NewBlock( 1134 // []sql.Node{ 1135 // plan.NewRenameColumn(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("mytable", ""), "bar", "baz"), 1136 // plan.NewRenameColumn(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("mytable", ""), "abc", "xyz"), 1137 // }, 1138 // ), 1139 // }, 1140 // { 1141 // input: `ALTER TABLE mytable ADD COLUMN bar INT NOT NULL`, 1142 // plan: plan.NewAddColumn( 1143 // sql.UnresolvedDatabase(""), 1144 // plan.NewUnresolvedTable("mytable", ""), &sql.Column{ 1145 // Name: "bar", 1146 // Type: types.Int32, 1147 // Nullable: false, 1148 // }, nil, 1149 // ), 1150 // }, 1151 // { 1152 // input: `ALTER TABLE mytable ADD COLUMN bar INT NOT NULL DEFAULT 42 COMMENT 'hello' AFTER baz`, 1153 // plan: plan.NewAddColumn( 1154 // sql.UnresolvedDatabase(""), 1155 // plan.NewUnresolvedTable("mytable", ""), &sql.Column{ 1156 // Name: "bar", 1157 // Type: types.Int32, 1158 // Nullable: false, 1159 // Comment: "hello", 1160 // Default: MustStringToColumnDefaultValue(sql.NewEmptyContext(), "42", nil, true), 1161 // }, &sql.ColumnOrder{AfterColumn: "baz"}, 1162 // ), 1163 // }, 1164 // { 1165 // input: `ALTER TABLE mytable ADD COLUMN bar INT NOT NULL DEFAULT -42.0 COMMENT 'hello' AFTER baz`, 1166 // plan: plan.NewAddColumn( 1167 // sql.UnresolvedDatabase(""), 1168 // plan.NewUnresolvedTable("mytable", ""), &sql.Column{ 1169 // Name: "bar", 1170 // Type: types.Int32, 1171 // Nullable: false, 1172 // Comment: "hello", 1173 // Default: MustStringToColumnDefaultValue(sql.NewEmptyContext(), "-42.0", nil, true), 1174 // }, &sql.ColumnOrder{AfterColumn: "baz"}, 1175 // ), 1176 // }, 1177 // { 1178 // input: `ALTER TABLE mytable ADD COLUMN bar INT NOT NULL DEFAULT ((2+2)/2) COMMENT 'hello' AFTER baz`, 1179 // plan: plan.NewAddColumn( 1180 // sql.UnresolvedDatabase(""), 1181 // plan.NewUnresolvedTable("mytable", ""), &sql.Column{ 1182 // Name: "bar", 1183 // Type: types.Int32, 1184 // Nullable: false, 1185 // Comment: "hello", 1186 // Default: MustStringToColumnDefaultValue(sql.NewEmptyContext(), "((2+2)/2)", nil, true), 1187 // }, &sql.ColumnOrder{AfterColumn: "baz"}, 1188 // ), 1189 // }, 1190 // { 1191 // input: `ALTER TABLE mytable ADD COLUMN bar VARCHAR(10) NULL DEFAULT 'string' COMMENT 'hello'`, 1192 // plan: plan.NewAddColumn( 1193 // sql.UnresolvedDatabase(""), 1194 // plan.NewUnresolvedTable("mytable", ""), &sql.Column{ 1195 // Name: "bar", 1196 // Type: types.MustCreateString(sqltypes.VarChar, 10, sql.Collation_Unspecified), 1197 // Nullable: true, 1198 // Comment: "hello", 1199 // Default: MustStringToColumnDefaultValue(sql.NewEmptyContext(), `"string"`, nil, true), 1200 // }, nil, 1201 // ), 1202 // }, 1203 // { 1204 // input: `ALTER TABLE mytable ADD COLUMN bar FLOAT NULL DEFAULT 32.0 COMMENT 'hello'`, 1205 // plan: plan.NewAddColumn( 1206 // sql.UnresolvedDatabase(""), 1207 // plan.NewUnresolvedTable("mytable", ""), &sql.Column{ 1208 // Name: "bar", 1209 // Type: types.Float32, 1210 // Nullable: true, 1211 // Comment: "hello", 1212 // Default: MustStringToColumnDefaultValue(sql.NewEmptyContext(), "32.0", nil, true), 1213 // }, nil, 1214 // ), 1215 // }, 1216 // { 1217 // input: `ALTER TABLE mytable ADD COLUMN bar INT DEFAULT 1 FIRST`, 1218 // plan: plan.NewAddColumn( 1219 // sql.UnresolvedDatabase(""), 1220 // plan.NewUnresolvedTable("mytable", ""), &sql.Column{ 1221 // Name: "bar", 1222 // Type: types.Int32, 1223 // Nullable: true, 1224 // Default: MustStringToColumnDefaultValue(sql.NewEmptyContext(), "1", nil, true), 1225 // }, &sql.ColumnOrder{First: true}, 1226 // ), 1227 // }, 1228 // { 1229 // input: `ALTER TABLE mydb.mytable ADD COLUMN bar INT DEFAULT 1 COMMENT 'otherdb'`, 1230 // plan: plan.NewAddColumn( 1231 // sql.UnresolvedDatabase("mydb"), 1232 // plan.NewUnresolvedTable("mytable", "mydb"), &sql.Column{ 1233 // Name: "bar", 1234 // Type: types.Int32, 1235 // Nullable: true, 1236 // Comment: "otherdb", 1237 // Default: MustStringToColumnDefaultValue(sql.NewEmptyContext(), "1", nil, true), 1238 // }, nil, 1239 // ), 1240 // }, 1241 // { 1242 // input: `ALTER TABLE mytable ADD INDEX (v1)`, 1243 // plan: plan.NewAlterCreateIndex( 1244 // sql.UnresolvedDatabase(""), 1245 // plan.NewUnresolvedTable("mytable", ""), 1246 // "", 1247 // sql.IndexUsing_BTree, 1248 // sql.IndexConstraint_None, 1249 // []sql.IndexColumn{{"v1", 0}}, 1250 // "", 1251 // ), 1252 // }, 1253 // { 1254 // input: `ALTER TABLE mytable DROP COLUMN bar`, 1255 // plan: plan.NewDropColumn( 1256 // sql.UnresolvedDatabase(""), 1257 // plan.NewUnresolvedTable("mytable", ""), "bar", 1258 // ), 1259 // }, 1260 // { 1261 // input: `ALTER TABLE otherdb.mytable DROP COLUMN bar`, 1262 // plan: plan.NewDropColumn( 1263 // sql.UnresolvedDatabase("otherdb"), 1264 // plan.NewUnresolvedTable("mytable", "otherdb"), "bar", 1265 // ), 1266 // }, 1267 // { 1268 // input: `ALTER TABLE tabletest MODIFY COLUMN bar VARCHAR(10) NULL DEFAULT 'string' COMMENT 'hello' FIRST`, 1269 // plan: plan.NewModifyColumn( 1270 // sql.UnresolvedDatabase(""), 1271 // plan.NewUnresolvedTable("tabletest", ""), "bar", &sql.Column{ 1272 // Name: "bar", 1273 // Type: types.MustCreateString(sqltypes.VarChar, 10, sql.Collation_Unspecified), 1274 // Nullable: true, 1275 // Comment: "hello", 1276 // Default: MustStringToColumnDefaultValue(sql.NewEmptyContext(), `"string"`, nil, true), 1277 // }, &sql.ColumnOrder{First: true}, 1278 // ), 1279 // }, 1280 // { 1281 // input: `ALTER TABLE tabletest CHANGE COLUMN bar baz VARCHAR(10) NULL DEFAULT 'string' COMMENT 'hello' FIRST`, 1282 // plan: plan.NewModifyColumn( 1283 // sql.UnresolvedDatabase(""), 1284 // plan.NewUnresolvedTable("tabletest", ""), "bar", &sql.Column{ 1285 // Name: "baz", 1286 // Type: types.MustCreateString(sqltypes.VarChar, 10, sql.Collation_Unspecified), 1287 // Nullable: true, 1288 // Comment: "hello", 1289 // Default: MustStringToColumnDefaultValue(sql.NewEmptyContext(), `"string"`, nil, true), 1290 // }, &sql.ColumnOrder{First: true}, 1291 // ), 1292 // }, 1293 // { 1294 // input: `ALTER TABLE mydb.mytable MODIFY COLUMN col1 VARCHAR(20) NULL DEFAULT 'string' COMMENT 'changed'`, 1295 // plan: plan.NewModifyColumn( 1296 // sql.UnresolvedDatabase("mydb"), 1297 // plan.NewUnresolvedTable("mytable", "mydb"), "col1", &sql.Column{ 1298 // Name: "col1", 1299 // Type: types.MustCreateString(sqltypes.VarChar, 20, sql.Collation_Unspecified), 1300 // Nullable: true, 1301 // Comment: "changed", 1302 // Default: MustStringToColumnDefaultValue(sql.NewEmptyContext(), `"string"`, nil, true), 1303 // }, nil, 1304 // ), 1305 // }, 1306 // { 1307 // input: `ALTER TABLE t1 ADD FOREIGN KEY (b_id) REFERENCES t0(b)`, 1308 // plan: plan.NewAlterAddForeignKey( 1309 // &sql.ForeignKeyConstraint{ 1310 // Name: "", 1311 // Database: "", 1312 // Table: "t1", 1313 // Columns: []string{"b_id"}, 1314 // ParentDatabase: "", 1315 // ParentTable: "t0", 1316 // ParentColumns: []string{"b"}, 1317 // OnUpdate: sql.ForeignKeyReferentialAction_DefaultAction, 1318 // OnDelete: sql.ForeignKeyReferentialAction_DefaultAction, 1319 // IsResolved: false, 1320 // }, 1321 // ), 1322 // }, 1323 // { 1324 // input: `ALTER TABLE t1 ADD CONSTRAINT fk_name FOREIGN KEY (b_id) REFERENCES t0(b)`, 1325 // plan: plan.NewAlterAddForeignKey( 1326 // &sql.ForeignKeyConstraint{ 1327 // Name: "fk_name", 1328 // Database: "", 1329 // Table: "t1", 1330 // Columns: []string{"b_id"}, 1331 // ParentDatabase: "", 1332 // ParentTable: "t0", 1333 // ParentColumns: []string{"b"}, 1334 // OnUpdate: sql.ForeignKeyReferentialAction_DefaultAction, 1335 // OnDelete: sql.ForeignKeyReferentialAction_DefaultAction, 1336 // IsResolved: false, 1337 // }, 1338 // ), 1339 // }, 1340 // { 1341 // input: `ALTER TABLE t1 ADD FOREIGN KEY (b_id) REFERENCES t0(b) ON UPDATE CASCADE`, 1342 // plan: plan.NewAlterAddForeignKey( 1343 // &sql.ForeignKeyConstraint{ 1344 // Name: "", 1345 // Database: "", 1346 // Table: "t1", 1347 // Columns: []string{"b_id"}, 1348 // ParentDatabase: "", 1349 // ParentTable: "t0", 1350 // ParentColumns: []string{"b"}, 1351 // OnUpdate: sql.ForeignKeyReferentialAction_Cascade, 1352 // OnDelete: sql.ForeignKeyReferentialAction_DefaultAction, 1353 // IsResolved: false, 1354 // }, 1355 // ), 1356 // }, 1357 // { 1358 // input: `ALTER TABLE t1 ADD FOREIGN KEY (b_id) REFERENCES t0(b) ON DELETE RESTRICT`, 1359 // plan: plan.NewAlterAddForeignKey( 1360 // &sql.ForeignKeyConstraint{ 1361 // Name: "", 1362 // Database: "", 1363 // Table: "t1", 1364 // Columns: []string{"b_id"}, 1365 // ParentDatabase: "", 1366 // ParentTable: "t0", 1367 // ParentColumns: []string{"b"}, 1368 // OnUpdate: sql.ForeignKeyReferentialAction_DefaultAction, 1369 // OnDelete: sql.ForeignKeyReferentialAction_Restrict, 1370 // IsResolved: false, 1371 // }, 1372 // ), 1373 // }, 1374 // { 1375 // input: `ALTER TABLE t1 ADD FOREIGN KEY (b_id) REFERENCES t0(b) ON UPDATE SET NULL ON DELETE NO ACTION`, 1376 // plan: plan.NewAlterAddForeignKey( 1377 // &sql.ForeignKeyConstraint{ 1378 // Name: "", 1379 // Database: "", 1380 // Table: "t1", 1381 // Columns: []string{"b_id"}, 1382 // ParentDatabase: "", 1383 // ParentTable: "t0", 1384 // ParentColumns: []string{"b"}, 1385 // OnUpdate: sql.ForeignKeyReferentialAction_SetNull, 1386 // OnDelete: sql.ForeignKeyReferentialAction_NoAction, 1387 // IsResolved: false, 1388 // }, 1389 // ), 1390 // }, 1391 // { 1392 // input: `ALTER TABLE t1 ADD FOREIGN KEY (b_id, c_id) REFERENCES t0(b, c)`, 1393 // plan: plan.NewAlterAddForeignKey( 1394 // &sql.ForeignKeyConstraint{ 1395 // Name: "", 1396 // Database: "", 1397 // Table: "t1", 1398 // Columns: []string{"b_id", "c_id"}, 1399 // ParentDatabase: "", 1400 // ParentTable: "t0", 1401 // ParentColumns: []string{"b", "c"}, 1402 // OnUpdate: sql.ForeignKeyReferentialAction_DefaultAction, 1403 // OnDelete: sql.ForeignKeyReferentialAction_DefaultAction, 1404 // IsResolved: false, 1405 // }, 1406 // ), 1407 // }, 1408 // { 1409 // input: `ALTER TABLE t1 ADD CONSTRAINT fk_name FOREIGN KEY (b_id, c_id) REFERENCES t0(b, c) ON UPDATE RESTRICT ON DELETE CASCADE`, 1410 // plan: plan.NewAlterAddForeignKey( 1411 // &sql.ForeignKeyConstraint{ 1412 // Name: "fk_name", 1413 // Database: "", 1414 // Table: "t1", 1415 // Columns: []string{"b_id", "c_id"}, 1416 // ParentDatabase: "", 1417 // ParentTable: "t0", 1418 // ParentColumns: []string{"b", "c"}, 1419 // OnUpdate: sql.ForeignKeyReferentialAction_Restrict, 1420 // OnDelete: sql.ForeignKeyReferentialAction_Cascade, 1421 // IsResolved: false, 1422 // }, 1423 // ), 1424 // }, 1425 // { 1426 // input: `ALTER TABLE t1 ADD CHECK (a > 0)`, 1427 // plan: plan.NewAlterAddCheck( 1428 // plan.NewUnresolvedTable("t1", ""), 1429 // &sql.CheckConstraint{ 1430 // Name: "", 1431 // Expr: expression.NewGreaterThan( 1432 // expression.NewUnresolvedColumn("a"), 1433 // expression.NewLiteral(int8(0), types.Int8), 1434 // ), 1435 // Enforced: true, 1436 // }, 1437 // ), 1438 // }, 1439 // { 1440 // input: `ALTER TABLE t1 ADD CONSTRAINT ch1 CHECK (a > 0)`, 1441 // plan: plan.NewAlterAddCheck( 1442 // plan.NewUnresolvedTable("t1", ""), 1443 // &sql.CheckConstraint{ 1444 // Name: "ch1", 1445 // Expr: expression.NewGreaterThan( 1446 // expression.NewUnresolvedColumn("a"), 1447 // expression.NewLiteral(int8(0), types.Int8), 1448 // ), 1449 // Enforced: true, 1450 // }, 1451 // ), 1452 // }, 1453 // { 1454 // input: `ALTER TABLE t1 ADD CONSTRAINT CHECK (a > 0)`, 1455 // plan: plan.NewAlterAddCheck( 1456 // plan.NewUnresolvedTable("t1", ""), 1457 // &sql.CheckConstraint{ 1458 // Name: "", 1459 // Expr: expression.NewGreaterThan( 1460 // expression.NewUnresolvedColumn("a"), 1461 // expression.NewLiteral(int8(0), types.Int8), 1462 // ), 1463 // Enforced: true, 1464 // }, 1465 // ), 1466 // }, 1467 // { 1468 // input: `ALTER TABLE t1 DROP FOREIGN KEY fk_name`, 1469 // plan: plan.NewAlterDropForeignKey("", "t1", "fk_name"), 1470 // }, 1471 // { 1472 // input: `ALTER TABLE t1 DROP CONSTRAINT fk_name`, 1473 // plan: plan.NewDropConstraint( 1474 // plan.NewUnresolvedTable("t1", ""), 1475 // "fk_name", 1476 // ), 1477 // }, 1478 // { 1479 // input: `DESCRIBE foo;`, 1480 // plan: plan.NewShowColumns(false, 1481 // plan.NewUnresolvedTable("foo", ""), 1482 // ), 1483 // }, 1484 // { 1485 // input: `DESC foo;`, 1486 // plan: plan.NewShowColumns(false, 1487 // plan.NewUnresolvedTable("foo", ""), 1488 // ), 1489 // }, 1490 // { 1491 // input: "DESCRIBE FORMAT=tree SELECT * FROM foo", 1492 // plan: plan.NewDescribeQuery( 1493 // "tree", plan.NewProject( 1494 // []sql.Expression{expression.NewStar()}, 1495 // plan.NewUnresolvedTable("foo", ""), 1496 // )), 1497 // }, 1498 // { 1499 // input: "DESC FORMAT=tree SELECT * FROM foo", 1500 // plan: plan.NewDescribeQuery( 1501 // "tree", plan.NewProject( 1502 // []sql.Expression{expression.NewStar()}, 1503 // plan.NewUnresolvedTable("foo", ""), 1504 // )), 1505 // }, 1506 // { 1507 // input: "EXPLAIN FORMAT=tree SELECT * FROM foo", 1508 // plan: plan.NewDescribeQuery( 1509 // "tree", plan.NewProject( 1510 // []sql.Expression{expression.NewStar()}, 1511 // plan.NewUnresolvedTable("foo", "")), 1512 // ), 1513 // }, 1514 // { 1515 // input: "DESCRIBE SELECT * FROM foo", 1516 // plan: plan.NewDescribeQuery( 1517 // "tree", plan.NewProject( 1518 // []sql.Expression{expression.NewStar()}, 1519 // plan.NewUnresolvedTable("foo", ""), 1520 // )), 1521 // }, 1522 // { 1523 // input: "DESC SELECT * FROM foo", 1524 // plan: plan.NewDescribeQuery( 1525 // "tree", plan.NewProject( 1526 // []sql.Expression{expression.NewStar()}, 1527 // plan.NewUnresolvedTable("foo", ""), 1528 // )), 1529 // }, 1530 // { 1531 // input: "EXPLAIN SELECT * FROM foo", 1532 // plan: plan.NewDescribeQuery( 1533 // "tree", plan.NewProject( 1534 // []sql.Expression{expression.NewStar()}, 1535 // plan.NewUnresolvedTable("foo", "")), 1536 // ), 1537 // }, 1538 // { 1539 // input: `SELECT foo, bar FROM foo;`, 1540 // plan: plan.NewProject( 1541 // []sql.Expression{ 1542 // expression.NewUnresolvedColumn("foo"), 1543 // expression.NewUnresolvedColumn("bar"), 1544 // }, 1545 // plan.NewUnresolvedTable("foo", ""), 1546 // ), 1547 // }, 1548 // { 1549 // input: `SELECT foo IS NULL, bar IS NOT NULL FROM foo;`, 1550 // plan: plan.NewProject( 1551 // []sql.Expression{ 1552 // expression.NewIsNull(expression.NewUnresolvedColumn("foo")), 1553 // expression.NewAlias("bar IS NOT NULL", 1554 // expression.NewNot(expression.NewIsNull(expression.NewUnresolvedColumn("bar"))), 1555 // ), 1556 // }, 1557 // plan.NewUnresolvedTable("foo", ""), 1558 // ), 1559 // }, 1560 // { 1561 // input: `SELECT foo IS TRUE, bar IS NOT FALSE FROM foo;`, 1562 // plan: plan.NewProject( 1563 // []sql.Expression{ 1564 // expression.NewIsTrue(expression.NewUnresolvedColumn("foo")), 1565 // expression.NewAlias("bar IS NOT FALSE", 1566 // expression.NewNot(expression.NewIsFalse(expression.NewUnresolvedColumn("bar"))), 1567 // ), 1568 // }, 1569 // plan.NewUnresolvedTable("foo", ""), 1570 // ), 1571 // }, 1572 // { 1573 // input: `SELECT foo AS bar FROM foo;`, 1574 // plan: plan.NewProject( 1575 // []sql.Expression{ 1576 // expression.NewAlias("bar", expression.NewUnresolvedColumn("foo")), 1577 // }, 1578 // plan.NewUnresolvedTable("foo", ""), 1579 // ), 1580 // }, 1581 // { 1582 // input: `SELECT foo AS bAz FROM foo;`, 1583 // plan: plan.NewProject( 1584 // []sql.Expression{ 1585 // expression.NewAlias("bAz", expression.NewUnresolvedColumn("foo")), 1586 // }, 1587 // plan.NewUnresolvedTable("foo", ""), 1588 // ), 1589 // }, 1590 // { 1591 // input: `SELECT foo AS bar FROM foo AS OF '2019-01-01' AS baz;`, 1592 // plan: plan.NewProject( 1593 // []sql.Expression{ 1594 // expression.NewAlias("bar", expression.NewUnresolvedColumn("foo")), 1595 // }, 1596 // plan.NewTableAlias("baz", 1597 // plan.NewUnresolvedTableAsOf("foo", "", 1598 // expression.NewLiteral("2019-01-01", types.LongText))), 1599 // ), 1600 // }, 1601 // { 1602 // input: `SELECT foo, bar FROM foo WHERE foo = bar;`, 1603 // plan: plan.NewProject( 1604 // []sql.Expression{ 1605 // expression.NewUnresolvedColumn("foo"), 1606 // expression.NewUnresolvedColumn("bar"), 1607 // }, 1608 // plan.NewFilter( 1609 // expression.NewEquals( 1610 // expression.NewUnresolvedColumn("foo"), 1611 // expression.NewUnresolvedColumn("bar"), 1612 // ), 1613 // plan.NewUnresolvedTable("foo", ""), 1614 // ), 1615 // ), 1616 // }, 1617 // { 1618 // input: `SELECT foo, bar FROM foo WHERE foo = 'bar';`, 1619 // plan: plan.NewProject( 1620 // []sql.Expression{ 1621 // expression.NewUnresolvedColumn("foo"), 1622 // expression.NewUnresolvedColumn("bar"), 1623 // }, 1624 // plan.NewFilter( 1625 // expression.NewEquals( 1626 // expression.NewUnresolvedColumn("foo"), 1627 // expression.NewLiteral("bar", types.LongText), 1628 // ), 1629 // plan.NewUnresolvedTable("foo", ""), 1630 // ), 1631 // ), 1632 // }, 1633 // { 1634 // input: `SELECT foo, bar FROM foo WHERE foo = ?;`, 1635 // plan: plan.NewProject( 1636 // []sql.Expression{ 1637 // expression.NewUnresolvedColumn("foo"), 1638 // expression.NewUnresolvedColumn("bar"), 1639 // }, 1640 // plan.NewFilter( 1641 // expression.NewEquals( 1642 // expression.NewUnresolvedColumn("foo"), 1643 // expression.NewBindVar("v1"), 1644 // ), 1645 // plan.NewUnresolvedTable("foo", ""), 1646 // ), 1647 // ), 1648 // }, 1649 // { 1650 // input: `SELECT * FROM (SELECT * FROM foo WHERE bar = ?) a;`, 1651 // plan: plan.NewProject( 1652 // []sql.Expression{ 1653 // expression.NewStar(), 1654 // }, 1655 // plan.NewSubqueryAlias( 1656 // "a", 1657 // "select * from foo where bar = :v1", 1658 // plan.NewProject( 1659 // []sql.Expression{ 1660 // expression.NewStar(), 1661 // }, 1662 // plan.NewFilter( 1663 // expression.NewEquals( 1664 // expression.NewUnresolvedColumn("bar"), 1665 // expression.NewBindVar("v1"), 1666 // ), 1667 // plan.NewUnresolvedTable("foo", ""), 1668 // ), 1669 // ), 1670 // ), 1671 // ), 1672 // }, 1673 // { 1674 // input: `SELECT * FROM (values row(1,2), row(3,4)) a;`, 1675 // plan: plan.NewProject( 1676 // []sql.Expression{ 1677 // expression.NewStar(), 1678 // }, 1679 // plan.NewValueDerivedTable( 1680 // plan.NewValues([][]sql.Expression{ 1681 // { 1682 // expression.NewLiteral(int8(1), types.Int8), 1683 // expression.NewLiteral(int8(2), types.Int8), 1684 // }, 1685 // { 1686 // expression.NewLiteral(int8(3), types.Int8), 1687 // expression.NewLiteral(int8(4), types.Int8), 1688 // }, 1689 // }), 1690 // "a"), 1691 // ), 1692 // }, 1693 // { 1694 // input: `SELECT * FROM (values row(1+1,2+2), row(rand(),concat("a","b"))) a;`, 1695 // plan: plan.NewProject( 1696 // []sql.Expression{ 1697 // expression.NewStar(), 1698 // }, 1699 // plan.NewValueDerivedTable( 1700 // plan.NewValues([][]sql.Expression{ 1701 // { 1702 // expression.NewArithmetic( 1703 // expression.NewLiteral(int8(1), types.Int8), 1704 // expression.NewLiteral(int8(1), types.Int8), 1705 // "+", 1706 // ), 1707 // expression.NewArithmetic( 1708 // expression.NewLiteral(int8(2), types.Int8), 1709 // expression.NewLiteral(int8(2), types.Int8), 1710 // "+", 1711 // ), 1712 // }, 1713 // { 1714 // expression.NewUnresolvedFunction("rand", false, nil), 1715 // expression.NewUnresolvedFunction("concat", false, nil, expression.NewLiteral("a", types.LongText), expression.NewLiteral("b", types.LongText)), 1716 // }, 1717 // }), 1718 // "a"), 1719 // ), 1720 // }, 1721 // { 1722 // input: `SELECT column_0 FROM (values row(1,2), row(3,4)) a limit 1`, 1723 // plan: plan.NewLimit(expression.NewLiteral(int8(1), types.Int8), 1724 // plan.NewProject( 1725 // []sql.Expression{ 1726 // expression.NewUnresolvedColumn("column_0"), 1727 // }, 1728 // plan.NewValueDerivedTable( 1729 // plan.NewValues([][]sql.Expression{ 1730 // { 1731 // expression.NewLiteral(int8(1), types.Int8), 1732 // expression.NewLiteral(int8(2), types.Int8), 1733 // }, 1734 // { 1735 // expression.NewLiteral(int8(3), types.Int8), 1736 // expression.NewLiteral(int8(4), types.Int8), 1737 // }, 1738 // }), 1739 // "a"), 1740 // ), 1741 // ), 1742 // }, 1743 // { 1744 // input: `SELECT foo, bar FROM foo WHERE foo <=> bar;`, 1745 // plan: plan.NewProject( 1746 // []sql.Expression{ 1747 // expression.NewUnresolvedColumn("foo"), 1748 // expression.NewUnresolvedColumn("bar"), 1749 // }, 1750 // plan.NewFilter( 1751 // expression.NewNullSafeEquals( 1752 // expression.NewUnresolvedColumn("foo"), 1753 // expression.NewUnresolvedColumn("bar"), 1754 // ), 1755 // plan.NewUnresolvedTable("foo", ""), 1756 // ), 1757 // ), 1758 // }, 1759 // { 1760 // input: `SELECT foo, bar FROM foo WHERE foo = :var;`, 1761 // plan: plan.NewProject( 1762 // []sql.Expression{ 1763 // expression.NewUnresolvedColumn("foo"), 1764 // expression.NewUnresolvedColumn("bar"), 1765 // }, 1766 // plan.NewFilter( 1767 // expression.NewEquals( 1768 // expression.NewUnresolvedColumn("foo"), 1769 // expression.NewBindVar("var"), 1770 // ), 1771 // plan.NewUnresolvedTable("foo", ""), 1772 // ), 1773 // ), 1774 // }, 1775 // { 1776 // input: `SELECT * FROM foo WHERE foo != 'bar';`, 1777 // plan: plan.NewProject( 1778 // []sql.Expression{ 1779 // expression.NewStar(), 1780 // }, 1781 // plan.NewFilter( 1782 // expression.NewNot(expression.NewEquals( 1783 // expression.NewUnresolvedColumn("foo"), 1784 // expression.NewLiteral("bar", types.LongText), 1785 // )), 1786 // plan.NewUnresolvedTable("foo", ""), 1787 // ), 1788 // ), 1789 // }, 1790 // { 1791 // input: `SELECT foo, bar FROM foo LIMIT 10;`, 1792 // plan: plan.NewLimit(expression.NewLiteral(int8(10), types.Int8), 1793 // plan.NewProject( 1794 // []sql.Expression{ 1795 // expression.NewUnresolvedColumn("foo"), 1796 // expression.NewUnresolvedColumn("bar"), 1797 // }, 1798 // plan.NewUnresolvedTable("foo", ""), 1799 // ), 1800 // ), 1801 // }, 1802 // { 1803 // input: `SELECT foo, bar FROM foo ORDER BY baz DESC;`, 1804 // plan: plan.NewSort( 1805 // []sql.SortField{ 1806 // { 1807 // Column: expression.NewUnresolvedColumn("baz"), 1808 // Column2: expression.NewUnresolvedColumn("baz"), 1809 // Order: sql.Descending, 1810 // NullOrdering: sql.NullsFirst, 1811 // }, 1812 // }, 1813 // plan.NewProject( 1814 // []sql.Expression{ 1815 // expression.NewUnresolvedColumn("foo"), 1816 // expression.NewUnresolvedColumn("bar"), 1817 // }, 1818 // plan.NewUnresolvedTable("foo", ""), 1819 // ), 1820 // ), 1821 // }, 1822 // { 1823 // input: `SELECT foo, bar FROM foo WHERE foo = bar LIMIT 10;`, 1824 // plan: plan.NewLimit(expression.NewLiteral(int8(10), types.Int8), 1825 // plan.NewProject( 1826 // []sql.Expression{ 1827 // expression.NewUnresolvedColumn("foo"), 1828 // expression.NewUnresolvedColumn("bar"), 1829 // }, 1830 // plan.NewFilter( 1831 // expression.NewEquals( 1832 // expression.NewUnresolvedColumn("foo"), 1833 // expression.NewUnresolvedColumn("bar"), 1834 // ), 1835 // plan.NewUnresolvedTable("foo", ""), 1836 // ), 1837 // ), 1838 // ), 1839 // }, 1840 // { 1841 // input: `SELECT foo, bar FROM foo ORDER BY baz DESC LIMIT 1;`, 1842 // plan: plan.NewLimit(expression.NewLiteral(int8(1), types.Int8), 1843 // plan.NewSort( 1844 // []sql.SortField{ 1845 // { 1846 // Column: expression.NewUnresolvedColumn("baz"), 1847 // Column2: expression.NewUnresolvedColumn("baz"), 1848 // Order: sql.Descending, 1849 // NullOrdering: sql.NullsFirst, 1850 // }, 1851 // }, 1852 // plan.NewProject( 1853 // []sql.Expression{ 1854 // expression.NewUnresolvedColumn("foo"), 1855 // expression.NewUnresolvedColumn("bar"), 1856 // }, 1857 // plan.NewUnresolvedTable("foo", ""), 1858 // ), 1859 // ), 1860 // ), 1861 // }, 1862 // { 1863 // input: `SELECT foo, bar FROM foo WHERE qux = 1 ORDER BY baz DESC LIMIT 1;`, 1864 // plan: plan.NewLimit(expression.NewLiteral(int8(1), types.Int8), 1865 // plan.NewSort( 1866 // []sql.SortField{ 1867 // { 1868 // Column: expression.NewUnresolvedColumn("baz"), 1869 // Column2: expression.NewUnresolvedColumn("baz"), 1870 // Order: sql.Descending, 1871 // NullOrdering: sql.NullsFirst, 1872 // }, 1873 // }, 1874 // plan.NewProject( 1875 // []sql.Expression{ 1876 // expression.NewUnresolvedColumn("foo"), 1877 // expression.NewUnresolvedColumn("bar"), 1878 // }, 1879 // plan.NewFilter( 1880 // expression.NewEquals( 1881 // expression.NewUnresolvedColumn("qux"), 1882 // expression.NewLiteral(int8(1), types.Int8), 1883 // ), 1884 // plan.NewUnresolvedTable("foo", ""), 1885 // ), 1886 // ), 1887 // ), 1888 // ), 1889 // }, 1890 // { 1891 // input: `SELECT foo, bar FROM t1, t2;`, 1892 // plan: plan.NewProject( 1893 // []sql.Expression{ 1894 // expression.NewUnresolvedColumn("foo"), 1895 // expression.NewUnresolvedColumn("bar"), 1896 // }, 1897 // plan.NewCrossJoin( 1898 // plan.NewUnresolvedTable("t1", ""), 1899 // plan.NewUnresolvedTable("t2", ""), 1900 // ), 1901 // ), 1902 // }, 1903 // { 1904 // input: `SELECT foo, bar FROM t1 JOIN t2;`, 1905 // plan: plan.NewProject( 1906 // []sql.Expression{ 1907 // expression.NewUnresolvedColumn("foo"), 1908 // expression.NewUnresolvedColumn("bar"), 1909 // }, 1910 // plan.NewCrossJoin( 1911 // plan.NewUnresolvedTable("t1", ""), 1912 // plan.NewUnresolvedTable("t2", ""), 1913 // ), 1914 // ), 1915 // }, 1916 // { 1917 // input: `SELECT foo, bar FROM t1 GROUP BY foo, bar;`, 1918 // plan: plan.NewGroupBy( 1919 // []sql.Expression{ 1920 // expression.NewUnresolvedColumn("foo"), 1921 // expression.NewUnresolvedColumn("bar"), 1922 // }, 1923 // []sql.Expression{ 1924 // expression.NewUnresolvedColumn("foo"), 1925 // expression.NewUnresolvedColumn("bar"), 1926 // }, 1927 // plan.NewUnresolvedTable("t1", ""), 1928 // ), 1929 // }, 1930 // { 1931 // input: `SELECT foo, bar FROM t1 GROUP BY 1, 2;`, 1932 // plan: plan.NewGroupBy( 1933 // []sql.Expression{ 1934 // expression.NewUnresolvedColumn("foo"), 1935 // expression.NewUnresolvedColumn("bar"), 1936 // }, 1937 // []sql.Expression{ 1938 // expression.NewUnresolvedColumn("foo"), 1939 // expression.NewUnresolvedColumn("bar"), 1940 // }, 1941 // plan.NewUnresolvedTable("t1", ""), 1942 // ), 1943 // }, 1944 // { 1945 // input: `SELECT COUNT(*) FROM t1;`, 1946 // plan: plan.NewGroupBy( 1947 // []sql.Expression{ 1948 // expression.NewAlias("COUNT(*)", 1949 // expression.NewUnresolvedFunction("count", true, nil, 1950 // expression.NewStar()), 1951 // ), 1952 // }, 1953 // []sql.Expression{}, 1954 // plan.NewUnresolvedTable("t1", ""), 1955 // ), 1956 // }, 1957 // { 1958 // input: `SELECT a FROM t1 where a regexp '.*test.*';`, 1959 // plan: plan.NewProject( 1960 // []sql.Expression{ 1961 // expression.NewUnresolvedColumn("a"), 1962 // }, 1963 // plan.NewFilter( 1964 // expression.NewRegexp( 1965 // expression.NewUnresolvedColumn("a"), 1966 // expression.NewLiteral(".*test.*", types.LongText), 1967 // ), 1968 // plan.NewUnresolvedTable("t1", ""), 1969 // ), 1970 // ), 1971 // }, 1972 // { 1973 // input: `SELECT a FROM t1 where a regexp '*main.go';`, 1974 // plan: plan.NewProject( 1975 // []sql.Expression{ 1976 // expression.NewUnresolvedColumn("a"), 1977 // }, 1978 // plan.NewFilter( 1979 // expression.NewRegexp( 1980 // expression.NewUnresolvedColumn("a"), 1981 // expression.NewLiteral("*main.go", types.LongText), 1982 // ), 1983 // plan.NewUnresolvedTable("t1", ""), 1984 // ), 1985 // ), 1986 // }, 1987 // { 1988 // input: `SELECT a FROM t1 where a not regexp '.*test.*';`, 1989 // plan: plan.NewProject( 1990 // []sql.Expression{ 1991 // expression.NewUnresolvedColumn("a"), 1992 // }, 1993 // plan.NewFilter( 1994 // expression.NewNot( 1995 // expression.NewRegexp( 1996 // expression.NewUnresolvedColumn("a"), 1997 // expression.NewLiteral(".*test.*", types.LongText), 1998 // ), 1999 // ), 2000 // plan.NewUnresolvedTable("t1", ""), 2001 // ), 2002 // ), 2003 // }, 2004 // { 2005 // input: `INSERT INTO t1 (col1, col2) VALUES ('a', 1)`, 2006 // plan: plan.NewInsertInto(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t1", ""), plan.NewValues([][]sql.Expression{{ 2007 // expression.NewLiteral("a", types.LongText), 2008 // expression.NewLiteral(int8(1), types.Int8), 2009 // }}), false, []string{"col1", "col2"}, []sql.Expression{}, false), 2010 // }, 2011 // { 2012 // input: `INSERT INTO mydb.t1 (col1, col2) VALUES ('a', 1)`, 2013 // plan: plan.NewInsertInto(sql.UnresolvedDatabase("mydb"), plan.NewUnresolvedTable("t1", "mydb"), plan.NewValues([][]sql.Expression{{ 2014 // expression.NewLiteral("a", types.LongText), 2015 // expression.NewLiteral(int8(1), types.Int8), 2016 // }}), false, []string{"col1", "col2"}, []sql.Expression{}, false), 2017 // }, 2018 // { 2019 // input: `INSERT INTO t1 (col1, col2) VALUES (?, ?)`, 2020 // plan: plan.NewInsertInto(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t1", ""), plan.NewValues([][]sql.Expression{{ 2021 // expression.NewBindVar("v1"), 2022 // expression.NewBindVar("v2"), 2023 // }}), false, []string{"col1", "col2"}, []sql.Expression{}, false), 2024 // }, 2025 // { 2026 // input: `INSERT INTO t1 VALUES (b'0111')`, 2027 // plan: plan.NewInsertInto(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t1", ""), plan.NewValues([][]sql.Expression{{ 2028 // expression.NewLiteral(uint64(7), types.Uint64), 2029 // }}), false, []string{}, []sql.Expression{}, false), 2030 // }, 2031 // { 2032 // input: `INSERT INTO t1 (col1, col2) VALUES ('a', DEFAULT)`, 2033 // plan: plan.NewInsertInto(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t1", ""), plan.NewValues([][]sql.Expression{{ 2034 // expression.NewLiteral("a", types.LongText), 2035 // &expression.DefaultColumn{}, 2036 // }}), false, []string{"col1", "col2"}, []sql.Expression{}, false), 2037 // }, 2038 // { 2039 // input: `INSERT INTO test (decimal_col) VALUES (11981.5923291839784651)`, 2040 // plan: plan.NewInsertInto(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("test", ""), plan.NewValues([][]sql.Expression{{ 2041 // expression.NewLiteral(decimal.RequireFromString("11981.5923291839784651"), types.MustCreateDecimalType(21, 16)), 2042 // }}), false, []string{"decimal_col"}, []sql.Expression{}, false), 2043 // }, 2044 // { 2045 // input: `INSERT INTO test (decimal_col) VALUES (119815923291839784651.11981592329183978465111981592329183978465144)`, 2046 // plan: plan.NewInsertInto(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("test", ""), plan.NewValues([][]sql.Expression{{ 2047 // expression.NewLiteral("119815923291839784651.11981592329183978465111981592329183978465144", types.LongText), 2048 // }}), false, []string{"decimal_col"}, []sql.Expression{}, false), 2049 // }, 2050 // { 2051 // input: `UPDATE t1 SET col1 = ?, col2 = ? WHERE id = ?`, 2052 // plan: plan.NewUpdate(plan.NewFilter( 2053 // expression.NewEquals(expression.NewUnresolvedColumn("id"), expression.NewBindVar("v3")), 2054 // plan.NewUnresolvedTable("t1", ""), 2055 // ), false, []sql.Expression{ 2056 // expression.NewSetField(expression.NewUnresolvedColumn("col1"), expression.NewBindVar("v1")), 2057 // expression.NewSetField(expression.NewUnresolvedColumn("col2"), expression.NewBindVar("v2")), 2058 // }), 2059 // }, 2060 // { 2061 // input: `REPLACE INTO t1 (col1, col2) VALUES ('a', 1)`, 2062 // plan: plan.NewInsertInto(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t1", ""), plan.NewValues([][]sql.Expression{{ 2063 // expression.NewLiteral("a", types.LongText), 2064 // expression.NewLiteral(int8(1), types.Int8), 2065 // }}), true, []string{"col1", "col2"}, []sql.Expression{}, false), 2066 // }, 2067 // { 2068 // input: `SHOW TABLES`, 2069 // plan: plan.NewShowTables(sql.UnresolvedDatabase(""), false, nil), 2070 // }, 2071 // { 2072 // input: `SHOW FULL TABLES`, 2073 // plan: plan.NewShowTables(sql.UnresolvedDatabase(""), true, nil), 2074 // }, 2075 // { 2076 // input: `SHOW TABLES FROM foo`, 2077 // plan: plan.NewShowTables(sql.UnresolvedDatabase("foo"), false, nil), 2078 // }, 2079 // { 2080 // input: `SHOW TABLES IN foo`, 2081 // plan: plan.NewShowTables(sql.UnresolvedDatabase("foo"), false, nil), 2082 // }, 2083 // { 2084 // input: `SHOW FULL TABLES FROM foo`, 2085 // plan: plan.NewShowTables(sql.UnresolvedDatabase("foo"), true, nil), 2086 // }, 2087 // { 2088 // input: `SHOW FULL TABLES IN foo`, 2089 // plan: plan.NewShowTables(sql.UnresolvedDatabase("foo"), true, nil), 2090 // }, 2091 // { 2092 // input: `SHOW TABLES AS OF 'abc'`, 2093 // plan: plan.NewShowTables(sql.UnresolvedDatabase(""), false, expression.NewLiteral("abc", types.LongText)), 2094 // }, 2095 // { 2096 // input: `SHOW FULL TABLES AS OF 'abc'`, 2097 // plan: plan.NewShowTables(sql.UnresolvedDatabase(""), true, expression.NewLiteral("abc", types.LongText)), 2098 // }, 2099 // { 2100 // input: `SHOW TABLES FROM foo AS OF 'abc'`, 2101 // plan: plan.NewShowTables(sql.UnresolvedDatabase("foo"), false, expression.NewLiteral("abc", types.LongText)), 2102 // }, 2103 // { 2104 // input: `SHOW FULL TABLES FROM foo AS OF 'abc'`, 2105 // plan: plan.NewShowTables(sql.UnresolvedDatabase("foo"), true, expression.NewLiteral("abc", types.LongText)), 2106 // }, 2107 // { 2108 // input: `SHOW FULL TABLES IN foo AS OF 'abc'`, 2109 // plan: plan.NewShowTables(sql.UnresolvedDatabase("foo"), true, expression.NewLiteral("abc", types.LongText)), 2110 // }, 2111 // { 2112 // input: `SHOW TABLES FROM mydb LIKE 'foo'`, 2113 // plan: plan.NewFilter( 2114 // expression.NewLike( 2115 // expression.NewUnresolvedColumn("Tables_in_mydb"), 2116 // expression.NewLiteral("foo", types.LongText), 2117 // nil, 2118 // ), 2119 // plan.NewShowTables(sql.UnresolvedDatabase("mydb"), false, nil), 2120 // ), 2121 // }, 2122 // { 2123 // input: `SHOW TABLES FROM mydb AS OF 'abc' LIKE 'foo'`, 2124 // plan: plan.NewFilter( 2125 // expression.NewLike( 2126 // expression.NewUnresolvedColumn("Tables_in_mydb"), 2127 // expression.NewLiteral("foo", types.LongText), 2128 // nil, 2129 // ), 2130 // plan.NewShowTables(sql.UnresolvedDatabase("mydb"), false, expression.NewLiteral("abc", types.LongText)), 2131 // ), 2132 // }, 2133 // { 2134 // input: "SHOW TABLES FROM bar WHERE `Tables_in_bar` = 'foo'", 2135 // plan: plan.NewFilter( 2136 // expression.NewEquals( 2137 // expression.NewUnresolvedColumn("Tables_in_bar"), 2138 // expression.NewLiteral("foo", types.LongText), 2139 // ), 2140 // plan.NewShowTables(sql.UnresolvedDatabase("bar"), false, nil), 2141 // ), 2142 // }, 2143 // { 2144 // input: `SHOW FULL TABLES FROM mydb LIKE 'foo'`, 2145 // plan: plan.NewFilter( 2146 // expression.NewLike( 2147 // expression.NewUnresolvedColumn("Tables_in_mydb"), 2148 // expression.NewLiteral("foo", types.LongText), 2149 // nil, 2150 // ), 2151 // plan.NewShowTables(sql.UnresolvedDatabase("mydb"), true, nil), 2152 // ), 2153 // }, 2154 // { 2155 // input: "SHOW FULL TABLES FROM bar WHERE `Tables_in_bar` = 'foo'", 2156 // plan: plan.NewFilter( 2157 // expression.NewEquals( 2158 // expression.NewUnresolvedColumn("Tables_in_bar"), 2159 // expression.NewLiteral("foo", types.LongText), 2160 // ), 2161 // plan.NewShowTables(sql.UnresolvedDatabase("bar"), true, nil), 2162 // ), 2163 // }, 2164 // { 2165 // input: `SHOW FULL TABLES FROM bar LIKE 'foo'`, 2166 // plan: plan.NewFilter( 2167 // expression.NewLike( 2168 // expression.NewUnresolvedColumn("Tables_in_bar"), 2169 // expression.NewLiteral("foo", types.LongText), 2170 // nil, 2171 // ), 2172 // plan.NewShowTables(sql.UnresolvedDatabase("bar"), true, nil), 2173 // ), 2174 // }, 2175 // { 2176 // input: `SHOW FULL TABLES FROM bar AS OF 'abc' LIKE 'foo'`, 2177 // plan: plan.NewFilter( 2178 // expression.NewLike( 2179 // expression.NewUnresolvedColumn("Tables_in_bar"), 2180 // expression.NewLiteral("foo", types.LongText), 2181 // nil, 2182 // ), 2183 // plan.NewShowTables(sql.UnresolvedDatabase("bar"), true, expression.NewLiteral("abc", types.LongText)), 2184 // ), 2185 // }, 2186 // { 2187 // input: "SHOW FULL TABLES FROM bar WHERE `Tables_in_bar` = 'test'", 2188 // plan: plan.NewFilter( 2189 // expression.NewEquals( 2190 // expression.NewUnresolvedColumn("Tables_in_bar"), 2191 // expression.NewLiteral("test", types.LongText), 2192 // ), 2193 // plan.NewShowTables(sql.UnresolvedDatabase("bar"), true, nil), 2194 // ), 2195 // }, 2196 // { 2197 // input: `SELECT DISTINCT foo, bar FROM foo;`, 2198 // plan: plan.NewDistinct( 2199 // plan.NewProject( 2200 // []sql.Expression{ 2201 // expression.NewUnresolvedColumn("foo"), 2202 // expression.NewUnresolvedColumn("bar"), 2203 // }, 2204 // plan.NewUnresolvedTable("foo", ""), 2205 // ), 2206 // ), 2207 // }, 2208 // { 2209 // input: `SELECT * FROM foo`, 2210 // plan: plan.NewProject( 2211 // []sql.Expression{ 2212 // expression.NewStar(), 2213 // }, 2214 // plan.NewUnresolvedTable("foo", ""), 2215 // ), 2216 // }, 2217 // { 2218 // input: `SELECT foo, bar FROM foo LIMIT 2 OFFSET 5;`, 2219 // plan: plan.NewLimit(expression.NewLiteral(int8(2), types.Int8), 2220 // plan.NewOffset(expression.NewLiteral(int8(5), types.Int8), plan.NewProject( 2221 // []sql.Expression{ 2222 // expression.NewUnresolvedColumn("foo"), 2223 // expression.NewUnresolvedColumn("bar"), 2224 // }, 2225 // plan.NewUnresolvedTable("foo", ""), 2226 // )), 2227 // ), 2228 // }, 2229 // { 2230 // input: `SELECT foo, bar FROM foo LIMIT 5,2;`, 2231 // plan: plan.NewLimit(expression.NewLiteral(int8(2), types.Int8), 2232 // plan.NewOffset(expression.NewLiteral(int8(5), types.Int8), plan.NewProject( 2233 // []sql.Expression{ 2234 // expression.NewUnresolvedColumn("foo"), 2235 // expression.NewUnresolvedColumn("bar"), 2236 // }, 2237 // plan.NewUnresolvedTable("foo", ""), 2238 // )), 2239 // ), 2240 // }, 2241 // { 2242 // input: `SELECT * FROM foo WHERE (a = 1)`, 2243 // plan: plan.NewProject( 2244 // []sql.Expression{ 2245 // expression.NewStar(), 2246 // }, 2247 // plan.NewFilter( 2248 // expression.NewEquals( 2249 // expression.NewUnresolvedColumn("a"), 2250 // expression.NewLiteral(int8(1), types.Int8), 2251 // ), 2252 // plan.NewUnresolvedTable("foo", ""), 2253 // ), 2254 // ), 2255 // }, 2256 // { 2257 // input: `SELECT * FROM foo, bar, baz, qux`, 2258 // plan: plan.NewProject( 2259 // []sql.Expression{expression.NewStar()}, 2260 // plan.NewCrossJoin( 2261 // plan.NewCrossJoin( 2262 // plan.NewCrossJoin( 2263 // plan.NewUnresolvedTable("foo", ""), 2264 // plan.NewUnresolvedTable("bar", ""), 2265 // ), 2266 // plan.NewUnresolvedTable("baz", ""), 2267 // ), 2268 // plan.NewUnresolvedTable("qux", ""), 2269 // ), 2270 // ), 2271 // }, 2272 // { 2273 // input: `SELECT * FROM foo join bar join baz join qux`, 2274 // plan: plan.NewProject( 2275 // []sql.Expression{expression.NewStar()}, 2276 // plan.NewCrossJoin( 2277 // plan.NewCrossJoin( 2278 // plan.NewCrossJoin( 2279 // plan.NewUnresolvedTable("foo", ""), 2280 // plan.NewUnresolvedTable("bar", ""), 2281 // ), 2282 // plan.NewUnresolvedTable("baz", ""), 2283 // ), 2284 // plan.NewUnresolvedTable("qux", ""), 2285 // ), 2286 // ), 2287 // }, 2288 // { 2289 // input: `SELECT * FROM foo WHERE a = b AND c = d`, 2290 // plan: plan.NewProject( 2291 // []sql.Expression{expression.NewStar()}, 2292 // plan.NewFilter( 2293 // expression.NewAnd( 2294 // expression.NewEquals( 2295 // expression.NewUnresolvedColumn("a"), 2296 // expression.NewUnresolvedColumn("b"), 2297 // ), 2298 // expression.NewEquals( 2299 // expression.NewUnresolvedColumn("c"), 2300 // expression.NewUnresolvedColumn("d"), 2301 // ), 2302 // ), 2303 // plan.NewUnresolvedTable("foo", ""), 2304 // ), 2305 // ), 2306 // }, 2307 // { 2308 // input: `SELECT * FROM foo WHERE a = b OR c = d`, 2309 // plan: plan.NewProject( 2310 // []sql.Expression{expression.NewStar()}, 2311 // plan.NewFilter( 2312 // expression.NewOr( 2313 // expression.NewEquals( 2314 // expression.NewUnresolvedColumn("a"), 2315 // expression.NewUnresolvedColumn("b"), 2316 // ), 2317 // expression.NewEquals( 2318 // expression.NewUnresolvedColumn("c"), 2319 // expression.NewUnresolvedColumn("d"), 2320 // ), 2321 // ), 2322 // plan.NewUnresolvedTable("foo", ""), 2323 // ), 2324 // ), 2325 // }, 2326 // { 2327 // input: `SELECT * FROM foo as bar`, 2328 // plan: plan.NewProject( 2329 // []sql.Expression{expression.NewStar()}, 2330 // plan.NewTableAlias( 2331 // "bar", 2332 // plan.NewUnresolvedTable("foo", ""), 2333 // ), 2334 // ), 2335 // }, 2336 // { 2337 // input: `SELECT * FROM (SELECT * FROM foo) AS bar`, 2338 // plan: plan.NewProject( 2339 // []sql.Expression{expression.NewStar()}, 2340 // plan.NewSubqueryAlias( 2341 // "bar", "select * from foo", 2342 // plan.NewProject( 2343 // []sql.Expression{expression.NewStar()}, 2344 // plan.NewUnresolvedTable("foo", ""), 2345 // ), 2346 // ), 2347 // ), 2348 // }, 2349 // { 2350 // input: `SELECT * FROM foo WHERE 1 NOT BETWEEN 2 AND 5`, 2351 // plan: plan.NewProject( 2352 // []sql.Expression{expression.NewStar()}, 2353 // plan.NewFilter( 2354 // expression.NewNot( 2355 // expression.NewBetween( 2356 // expression.NewLiteral(int8(1), types.Int8), 2357 // expression.NewLiteral(int8(2), types.Int8), 2358 // expression.NewLiteral(int8(5), types.Int8), 2359 // ), 2360 // ), 2361 // plan.NewUnresolvedTable("foo", ""), 2362 // ), 2363 // ), 2364 // }, 2365 // { 2366 // input: `SELECT * FROM foo WHERE 1 BETWEEN 2 AND 5`, 2367 // plan: plan.NewProject( 2368 // []sql.Expression{expression.NewStar()}, 2369 // plan.NewFilter( 2370 // expression.NewBetween( 2371 // expression.NewLiteral(int8(1), types.Int8), 2372 // expression.NewLiteral(int8(2), types.Int8), 2373 // expression.NewLiteral(int8(5), types.Int8), 2374 // ), 2375 // plan.NewUnresolvedTable("foo", ""), 2376 // ), 2377 // ), 2378 // }, 2379 // { 2380 // input: `SELECT 0x01AF`, 2381 // plan: plan.NewProject( 2382 // []sql.Expression{ 2383 // expression.NewAlias("0x01AF", 2384 // expression.NewLiteral([]byte{1, 175}, types.LongBlob), 2385 // ), 2386 // }, 2387 // plan.NewResolvedDualTable(), 2388 // ), 2389 // }, 2390 // { 2391 // input: `SELECT 0x12345`, 2392 // plan: plan.NewProject( 2393 // []sql.Expression{ 2394 // expression.NewAlias("0x12345", 2395 // expression.NewLiteral([]byte{1, 35, 69}, types.LongBlob), 2396 // ), 2397 // }, 2398 // plan.NewResolvedDualTable(), 2399 // ), 2400 // }, 2401 // { 2402 // input: `SELECT X'41'`, 2403 // plan: plan.NewProject( 2404 // []sql.Expression{ 2405 // expression.NewAlias("X'41'", 2406 // expression.NewLiteral([]byte{'A'}, types.LongBlob), 2407 // ), 2408 // }, 2409 // plan.NewResolvedDualTable(), 2410 // ), 2411 // }, 2412 // { 2413 // input: `SELECT * FROM b WHERE SOMEFUNC((1, 2), (3, 4))`, 2414 // plan: plan.NewProject( 2415 // []sql.Expression{expression.NewStar()}, 2416 // plan.NewFilter( 2417 // expression.NewUnresolvedFunction( 2418 // "somefunc", 2419 // false, 2420 // nil, 2421 // expression.NewTuple( 2422 // expression.NewLiteral(int8(1), types.Int8), 2423 // expression.NewLiteral(int8(2), types.Int8), 2424 // ), 2425 // expression.NewTuple( 2426 // expression.NewLiteral(int8(3), types.Int8), 2427 // expression.NewLiteral(int8(4), types.Int8), 2428 // ), 2429 // ), 2430 // plan.NewUnresolvedTable("b", ""), 2431 // ), 2432 // ), 2433 // }, 2434 // { 2435 // input: `SELECT * FROM foo WHERE :foo_id = 2`, 2436 // plan: plan.NewProject( 2437 // []sql.Expression{expression.NewStar()}, 2438 // plan.NewFilter( 2439 // expression.NewEquals( 2440 // expression.NewBindVar("foo_id"), 2441 // expression.NewLiteral(int8(2), types.Int8), 2442 // ), 2443 // plan.NewUnresolvedTable("foo", ""), 2444 // ), 2445 // ), 2446 // }, 2447 // { 2448 // input: `SELECT * FROM foo WHERE ? = 2 and foo.s = ? and ? <> foo.i`, 2449 // plan: plan.NewProject( 2450 // []sql.Expression{expression.NewStar()}, 2451 // plan.NewFilter( 2452 // expression.NewAnd( 2453 // expression.NewAnd( 2454 // expression.NewEquals( 2455 // expression.NewBindVar("v1"), 2456 // expression.NewLiteral(int8(2), types.Int8), 2457 // ), 2458 // expression.NewEquals( 2459 // expression.NewUnresolvedQualifiedColumn("foo", "s"), 2460 // expression.NewBindVar("v2"), 2461 // ), 2462 // ), 2463 // expression.NewNot(expression.NewEquals( 2464 // expression.NewBindVar("v3"), 2465 // expression.NewUnresolvedQualifiedColumn("foo", "i"), 2466 // )), 2467 // ), 2468 // plan.NewUnresolvedTable("foo", ""), 2469 // ), 2470 // ), 2471 // }, 2472 // { 2473 // input: `SELECT * FROM foo INNER JOIN bar ON a = b`, 2474 // plan: plan.NewProject( 2475 // []sql.Expression{expression.NewStar()}, 2476 // plan.NewInnerJoin( 2477 // plan.NewUnresolvedTable("foo", ""), 2478 // plan.NewUnresolvedTable("bar", ""), 2479 // expression.NewEquals( 2480 // expression.NewUnresolvedColumn("a"), 2481 // expression.NewUnresolvedColumn("b"), 2482 // ), 2483 // ), 2484 // ), 2485 // }, 2486 // { 2487 // input: `SELECT foo.a FROM foo`, 2488 // plan: plan.NewProject( 2489 // []sql.Expression{ 2490 // expression.NewUnresolvedQualifiedColumn("foo", "a"), 2491 // }, 2492 // plan.NewUnresolvedTable("foo", ""), 2493 // ), 2494 // }, 2495 // { 2496 // input: `SELECT CAST(-3 AS UNSIGNED) FROM foo`, 2497 // plan: plan.NewProject( 2498 // []sql.Expression{ 2499 // expression.NewAlias("CAST(-3 AS UNSIGNED)", 2500 // expression.NewConvert(expression.NewLiteral(int8(-3), types.Int8), expression.ConvertToUnsigned), 2501 // ), 2502 // }, 2503 // plan.NewUnresolvedTable("foo", ""), 2504 // ), 2505 // }, 2506 // { 2507 // input: `SELECT 2 = 2 FROM foo`, 2508 // plan: plan.NewProject( 2509 // []sql.Expression{ 2510 // expression.NewAlias("2 = 2", 2511 // expression.NewEquals(expression.NewLiteral(int8(2), types.Int8), expression.NewLiteral(int8(2), types.Int8))), 2512 // }, 2513 // plan.NewUnresolvedTable("foo", ""), 2514 // ), 2515 // }, 2516 // { 2517 // input: `SELECT *, bar FROM foo`, 2518 // plan: plan.NewProject( 2519 // []sql.Expression{ 2520 // expression.NewStar(), 2521 // expression.NewUnresolvedColumn("bar"), 2522 // }, 2523 // plan.NewUnresolvedTable("foo", ""), 2524 // ), 2525 // }, 2526 // { 2527 // input: `SELECT *, foo.* FROM foo`, 2528 // plan: plan.NewProject( 2529 // []sql.Expression{ 2530 // expression.NewStar(), 2531 // expression.NewQualifiedStar("foo"), 2532 // }, 2533 // plan.NewUnresolvedTable("foo", ""), 2534 // ), 2535 // }, 2536 // { 2537 // input: `SELECT bar, foo.* FROM foo`, 2538 // plan: plan.NewProject( 2539 // []sql.Expression{ 2540 // expression.NewUnresolvedColumn("bar"), 2541 // expression.NewQualifiedStar("foo"), 2542 // }, 2543 // plan.NewUnresolvedTable("foo", ""), 2544 // ), 2545 // }, 2546 // { 2547 // input: `SELECT bar, *, foo.* FROM foo`, 2548 // plan: plan.NewProject( 2549 // []sql.Expression{ 2550 // expression.NewUnresolvedColumn("bar"), 2551 // expression.NewStar(), 2552 // expression.NewQualifiedStar("foo"), 2553 // }, 2554 // plan.NewUnresolvedTable("foo", ""), 2555 // ), 2556 // }, 2557 // { 2558 // input: `SELECT *, * FROM foo`, 2559 // plan: plan.NewProject( 2560 // []sql.Expression{ 2561 // expression.NewStar(), 2562 // expression.NewStar(), 2563 // }, 2564 // plan.NewUnresolvedTable("foo", ""), 2565 // ), 2566 // }, 2567 // { 2568 // input: `SELECT * FROM foo WHERE 1 IN ('1', 2)`, 2569 // plan: plan.NewProject( 2570 // []sql.Expression{expression.NewStar()}, 2571 // plan.NewFilter( 2572 // expression.NewInTuple( 2573 // expression.NewLiteral(int8(1), types.Int8), 2574 // expression.NewTuple( 2575 // expression.NewLiteral("1", types.LongText), 2576 // expression.NewLiteral(int8(2), types.Int8), 2577 // ), 2578 // ), 2579 // plan.NewUnresolvedTable("foo", ""), 2580 // ), 2581 // ), 2582 // }, 2583 // { 2584 // input: `SELECT * FROM foo WHERE 1 NOT IN ('1', 2)`, 2585 // plan: plan.NewProject( 2586 // []sql.Expression{expression.NewStar()}, 2587 // plan.NewFilter( 2588 // expression.NewNotInTuple( 2589 // expression.NewLiteral(int8(1), types.Int8), 2590 // expression.NewTuple( 2591 // expression.NewLiteral("1", types.LongText), 2592 // expression.NewLiteral(int8(2), types.Int8), 2593 // ), 2594 // ), 2595 // plan.NewUnresolvedTable("foo", ""), 2596 // ), 2597 // ), 2598 // }, 2599 // { 2600 // input: `SELECT * FROM foo WHERE i IN (SELECT j FROM baz)`, 2601 // plan: plan.NewProject( 2602 // []sql.Expression{expression.NewStar()}, 2603 // plan.NewFilter( 2604 // plan.NewInSubquery( 2605 // expression.NewUnresolvedColumn("i"), 2606 // plan.NewSubquery(plan.NewProject( 2607 // []sql.Expression{expression.NewUnresolvedColumn("j")}, 2608 // plan.NewUnresolvedTable("baz", ""), 2609 // ), "select j from baz"), 2610 // ), 2611 // plan.NewUnresolvedTable("foo", ""), 2612 // ), 2613 // ), 2614 // }, 2615 // { 2616 // input: `SELECT * FROM foo WHERE i NOT IN (SELECT j FROM baz)`, 2617 // plan: plan.NewProject( 2618 // []sql.Expression{expression.NewStar()}, 2619 // plan.NewFilter( 2620 // plan.NewNotInSubquery( 2621 // expression.NewUnresolvedColumn("i"), 2622 // plan.NewSubquery(plan.NewProject( 2623 // []sql.Expression{expression.NewUnresolvedColumn("j")}, 2624 // plan.NewUnresolvedTable("baz", ""), 2625 // ), "select j from baz"), 2626 // ), 2627 // plan.NewUnresolvedTable("foo", ""), 2628 // ), 2629 // ), 2630 // }, 2631 // { 2632 // input: `SELECT a, b FROM t ORDER BY 2, 1`, 2633 // plan: plan.NewSort( 2634 // []sql.SortField{ 2635 // { 2636 // Column: expression.NewLiteral(int8(2), types.Int8), 2637 // Column2: expression.NewLiteral(int8(2), types.Int8), 2638 // Order: sql.Ascending, 2639 // NullOrdering: sql.NullsFirst, 2640 // }, 2641 // { 2642 // Column: expression.NewLiteral(int8(1), types.Int8), 2643 // Column2: expression.NewLiteral(int8(1), types.Int8), 2644 // Order: sql.Ascending, 2645 // NullOrdering: sql.NullsFirst, 2646 // }, 2647 // }, 2648 // plan.NewProject( 2649 // []sql.Expression{ 2650 // expression.NewUnresolvedColumn("a"), 2651 // expression.NewUnresolvedColumn("b"), 2652 // }, 2653 // plan.NewUnresolvedTable("t", ""), 2654 // ), 2655 // ), 2656 // }, 2657 // { 2658 // input: `SELECT -i FROM mytable`, 2659 // plan: plan.NewProject( 2660 // []sql.Expression{ 2661 // expression.NewUnaryMinus( 2662 // expression.NewUnresolvedColumn("i"), 2663 // ), 2664 // }, 2665 // plan.NewUnresolvedTable("mytable", ""), 2666 // ), 2667 // }, 2668 // { 2669 // input: `SELECT +i FROM mytable`, 2670 // plan: plan.NewProject( 2671 // []sql.Expression{ 2672 // expression.NewAlias("+i", 2673 // expression.NewUnresolvedColumn("i"), 2674 // ), 2675 // }, 2676 // plan.NewUnresolvedTable("mytable", ""), 2677 // ), 2678 // }, 2679 // { 2680 // input: `SELECT - 4 - - 80`, 2681 // plan: plan.NewProject( 2682 // []sql.Expression{ 2683 // expression.NewAlias("- 4 - - 80", 2684 // expression.NewMinus( 2685 // expression.NewLiteral(int8(-4), types.Int8), 2686 // expression.NewLiteral(int8(-80), types.Int8), 2687 // ), 2688 // ), 2689 // }, 2690 // plan.NewResolvedDualTable(), 2691 // ), 2692 // }, 2693 // { 2694 // input: `SELECT + - - i FROM mytable`, 2695 // plan: plan.NewProject( 2696 // []sql.Expression{ 2697 // expression.NewAlias("+ - - i", 2698 // expression.NewUnaryMinus( 2699 // expression.NewUnaryMinus( 2700 // expression.NewUnresolvedColumn("i"), 2701 // ), 2702 // ), 2703 // ), 2704 // }, 2705 // plan.NewUnresolvedTable("mytable", ""), 2706 // ), 2707 // }, 2708 // { 2709 // input: `SELECT 1 + 1;`, 2710 // plan: plan.NewProject( 2711 // []sql.Expression{ 2712 // expression.NewAlias("1 + 1", 2713 // expression.NewPlus(expression.NewLiteral(int8(1), types.Int8), expression.NewLiteral(int8(1), types.Int8))), 2714 // }, 2715 // plan.NewResolvedDualTable(), 2716 // ), 2717 // }, 2718 // { 2719 // input: `SELECT 1 + 1 as foo;`, 2720 // plan: plan.NewProject( 2721 // []sql.Expression{ 2722 // expression.NewAlias("foo", 2723 // expression.NewPlus(expression.NewLiteral(int8(1), types.Int8), expression.NewLiteral(int8(1), types.Int8))), 2724 // }, 2725 // plan.NewResolvedDualTable(), 2726 // ), 2727 // }, 2728 // { 2729 // input: `SELECT 1 * (2 + 1);`, 2730 // plan: plan.NewProject( 2731 // []sql.Expression{ 2732 // expression.NewAlias("1 * (2 + 1)", 2733 // expression.NewMult(expression.NewLiteral(int8(1), types.Int8), 2734 // expression.NewPlus(expression.NewLiteral(int8(2), types.Int8), expression.NewLiteral(int8(1), types.Int8))), 2735 // ), 2736 // }, 2737 // plan.NewResolvedDualTable(), 2738 // ), 2739 // }, 2740 // { 2741 // input: `SELECT (0 - 1) * (1 | 1);`, 2742 // plan: plan.NewProject( 2743 // []sql.Expression{ 2744 // expression.NewAlias("(0 - 1) * (1 | 1)", 2745 // expression.NewMult( 2746 // expression.NewMinus(expression.NewLiteral(int8(0), types.Int8), expression.NewLiteral(int8(1), types.Int8)), 2747 // expression.NewBitOr(expression.NewLiteral(int8(1), types.Int8), expression.NewLiteral(int8(1), types.Int8)), 2748 // ), 2749 // ), 2750 // }, 2751 // plan.NewResolvedDualTable(), 2752 // ), 2753 // }, 2754 // { 2755 // input: `SELECT (1 << 3) % (2 div 1);`, 2756 // plan: plan.NewProject( 2757 // []sql.Expression{ 2758 // expression.NewAlias("(1 << 3) % (2 div 1)", 2759 // expression.NewMod( 2760 // expression.NewShiftLeft(expression.NewLiteral(int8(1), types.Int8), expression.NewLiteral(int8(3), types.Int8)), 2761 // expression.NewIntDiv(expression.NewLiteral(int8(2), types.Int8), expression.NewLiteral(int8(1), types.Int8))), 2762 // ), 2763 // }, 2764 // plan.NewResolvedDualTable(), 2765 // ), 2766 // }, 2767 // { 2768 // input: `SELECT 1.0 * a + 2.0 * b FROM t;`, 2769 // plan: plan.NewProject( 2770 // []sql.Expression{ 2771 // expression.NewAlias("1.0 * a + 2.0 * b", 2772 // expression.NewPlus( 2773 // expression.NewMult(expression.NewLiteral(decimal.RequireFromString("1.0"), types.MustCreateDecimalType(2, 1)), expression.NewUnresolvedColumn("a")), 2774 // expression.NewMult(expression.NewLiteral(decimal.RequireFromString("2.0"), types.MustCreateDecimalType(2, 1)), expression.NewUnresolvedColumn("b")), 2775 // ), 2776 // ), 2777 // }, 2778 // plan.NewUnresolvedTable("t", ""), 2779 // ), 2780 // }, 2781 // { 2782 // input: `SELECT '1.0' + 2;`, 2783 // plan: plan.NewProject( 2784 // []sql.Expression{ 2785 // expression.NewAlias("'1.0' + 2", 2786 // expression.NewPlus( 2787 // expression.NewLiteral("1.0", types.LongText), expression.NewLiteral(int8(2), types.Int8), 2788 // ), 2789 // ), 2790 // }, 2791 // plan.NewResolvedDualTable(), 2792 // ), 2793 // }, 2794 // { 2795 // input: `SELECT '1' + '2';`, 2796 // plan: plan.NewProject( 2797 // []sql.Expression{ 2798 // expression.NewAlias("'1' + '2'", 2799 // expression.NewPlus( 2800 // expression.NewLiteral("1", types.LongText), expression.NewLiteral("2", types.LongText), 2801 // ), 2802 // ), 2803 // }, 2804 // plan.NewResolvedDualTable(), 2805 // ), 2806 // }, 2807 // { 2808 // input: `CREATE INDEX foo USING qux ON bar (baz)`, 2809 // plan: plan.NewCreateIndex( 2810 // "foo", 2811 // plan.NewUnresolvedTable("bar", ""), 2812 // []sql.Expression{expression.NewUnresolvedColumn("baz")}, 2813 // "qux", 2814 // make(map[string]string), 2815 // ), 2816 // }, 2817 // { 2818 // input: `CREATE INDEX idx USING BTREE ON foo (bar)`, 2819 // plan: plan.NewAlterCreateIndex( 2820 // sql.UnresolvedDatabase(""), 2821 // plan.NewUnresolvedTable("foo", ""), 2822 // "idx", 2823 // sql.IndexUsing_BTree, 2824 // sql.IndexConstraint_None, 2825 // []sql.IndexColumn{ 2826 // {"bar", 0}, 2827 // }, 2828 // "", 2829 // ), 2830 // }, 2831 // { 2832 // input: ` CREATE INDEX idx USING BTREE ON foo(bar)`, 2833 // plan: plan.NewAlterCreateIndex( 2834 // sql.UnresolvedDatabase(""), 2835 // plan.NewUnresolvedTable("foo", ""), 2836 // "idx", 2837 // sql.IndexUsing_BTree, 2838 // sql.IndexConstraint_None, 2839 // []sql.IndexColumn{ 2840 // {"bar", 0}, 2841 // }, 2842 // "", 2843 // ), 2844 // }, 2845 // { 2846 // input: `SELECT * FROM foo NATURAL JOIN bar`, 2847 // plan: plan.NewProject( 2848 // []sql.Expression{expression.NewStar()}, 2849 // plan.NewNaturalJoin( 2850 // plan.NewUnresolvedTable("foo", ""), 2851 // plan.NewUnresolvedTable("bar", ""), 2852 // ), 2853 // ), 2854 // }, 2855 // { 2856 // input: `SELECT * FROM foo NATURAL JOIN bar NATURAL JOIN baz`, 2857 // plan: plan.NewProject( 2858 // []sql.Expression{expression.NewStar()}, 2859 // plan.NewNaturalJoin( 2860 // plan.NewNaturalJoin( 2861 // plan.NewUnresolvedTable("foo", ""), 2862 // plan.NewUnresolvedTable("bar", ""), 2863 // ), 2864 // plan.NewUnresolvedTable("baz", ""), 2865 // ), 2866 // ), 2867 // }, 2868 // { 2869 // input: `DROP INDEX foo ON bar`, 2870 // plan: plan.NewAlterDropIndex( 2871 // sql.UnresolvedDatabase(""), 2872 // plan.NewUnresolvedTable("bar", ""), 2873 // "foo", 2874 // ), 2875 // }, 2876 // { 2877 // input: `alter table t add index (i), drop index i, add check (i = 0), drop check chk, drop constraint c, add column i int, modify column i text, drop column i, rename column i to j`, 2878 // plan: plan.NewBlock([]sql.Node{ 2879 // plan.NewAlterCreateIndex(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t", ""), "", sql.IndexUsing_BTree, sql.IndexConstraint_None, []sql.IndexColumn{{Name: "i", Length: 0}}, ""), 2880 // plan.NewAlterDropIndex(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t", ""), "i"), 2881 // plan.NewAlterAddCheck(plan.NewUnresolvedTable("t", ""), &sql.CheckConstraint{Name: "", Expr: expression.NewEquals(expression.NewUnresolvedColumn("i"), expression.NewLiteral(int8(0), types.Int8)), Enforced: true}), 2882 // plan.NewAlterDropCheck(plan.NewUnresolvedTable("t", ""), "chk"), 2883 // plan.NewDropConstraint(plan.NewUnresolvedTable("t", ""), "c"), 2884 // plan.NewAddColumn(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t", ""), &sql.Column{Name: "i", Type: types.Int32, Nullable: true, Source: "t"}, nil), 2885 // plan.NewModifyColumn(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t", ""), "i", &sql.Column{Name: "i", Type: types.CreateText(sql.Collation_Unspecified), Nullable: true, Source: "t"}, nil), 2886 // plan.NewDropColumn(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t", ""), "i"), 2887 // plan.NewRenameColumn(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("t", ""), "i", "j"), 2888 // }), 2889 // }, 2890 // { 2891 // input: `DESCRIBE FORMAT=TREE SELECT * FROM foo`, 2892 // plan: plan.NewDescribeQuery( 2893 // "tree", 2894 // plan.NewProject( 2895 // []sql.Expression{expression.NewStar()}, 2896 // plan.NewUnresolvedTable("foo", ""), 2897 // ), 2898 // ), 2899 // }, 2900 // { 2901 // input: `SELECT MAX(i)/2 FROM foo`, 2902 // plan: plan.NewGroupBy( 2903 // []sql.Expression{ 2904 // expression.NewAlias("MAX(i)/2", 2905 // expression.NewDiv( 2906 // expression.NewUnresolvedFunction( 2907 // "max", true, nil, expression.NewUnresolvedColumn("i"), 2908 // ), 2909 // expression.NewLiteral(int8(2), types.Int8), 2910 // ), 2911 // ), 2912 // }, 2913 // []sql.Expression{}, 2914 // plan.NewUnresolvedTable("foo", ""), 2915 // ), 2916 // }, 2917 // { 2918 // input: `SELECT current_user FROM foo`, 2919 // plan: plan.NewProject( 2920 // []sql.Expression{ 2921 // expression.NewAlias("current_user", 2922 // expression.NewUnresolvedFunction("current_user", false, nil), 2923 // ), 2924 // }, 2925 // plan.NewUnresolvedTable("foo", ""), 2926 // ), 2927 // }, 2928 // { 2929 // input: `SELECT current_USER( ) FROM foo`, 2930 // plan: plan.NewProject( 2931 // []sql.Expression{ 2932 // expression.NewAlias("current_USER( )", 2933 // expression.NewUnresolvedFunction("current_user", false, nil), 2934 // ), 2935 // }, 2936 // plan.NewUnresolvedTable("foo", ""), 2937 // ), 2938 // }, 2939 // { 2940 // input: `SHOW INDEXES FROM foo`, 2941 // plan: plan.NewShowIndexes(plan.NewUnresolvedTable("foo", "")), 2942 // }, 2943 // { 2944 // input: `SHOW INDEX FROM foo`, 2945 // plan: plan.NewShowIndexes(plan.NewUnresolvedTable("foo", "")), 2946 // }, 2947 // { 2948 // input: `SHOW KEYS FROM foo`, 2949 // plan: plan.NewShowIndexes(plan.NewUnresolvedTable("foo", "")), 2950 // }, 2951 // { 2952 // input: `SHOW INDEXES IN foo`, 2953 // plan: plan.NewShowIndexes(plan.NewUnresolvedTable("foo", "")), 2954 // }, 2955 // { 2956 // input: `SHOW INDEX IN foo`, 2957 // plan: plan.NewShowIndexes(plan.NewUnresolvedTable("foo", "")), 2958 // }, 2959 // { 2960 // input: `SHOW KEYS IN foo`, 2961 // plan: plan.NewShowIndexes(plan.NewUnresolvedTable("foo", "")), 2962 // }, 2963 // { 2964 // input: `SHOW FULL PROCESSLIST`, 2965 // plan: plan.NewShowProcessList(), 2966 // }, 2967 // { 2968 // input: `SHOW PROCESSLIST`, 2969 // plan: plan.NewShowProcessList(), 2970 // }, 2971 // { 2972 // input: `SELECT @@allowed_max_packet`, 2973 // plan: plan.NewProject([]sql.Expression{ 2974 // expression.NewUnresolvedColumn("@@allowed_max_packet"), 2975 // }, plan.NewResolvedDualTable()), 2976 // }, 2977 // { 2978 // input: `SET autocommit=1, foo="bar", baz=ON, qux=bareword`, 2979 // plan: plan.NewSet( 2980 // []sql.Expression{ 2981 // expression.NewSetField(expression.NewUnresolvedColumn("autocommit"), expression.NewLiteral(int8(1), types.Int8)), 2982 // expression.NewSetField(expression.NewUnresolvedColumn("foo"), expression.NewLiteral("bar", types.LongText)), 2983 // expression.NewSetField(expression.NewUnresolvedColumn("baz"), expression.NewLiteral("ON", types.LongText)), 2984 // expression.NewSetField(expression.NewUnresolvedColumn("qux"), expression.NewUnresolvedColumn("bareword")), 2985 // }, 2986 // ), 2987 // }, 2988 // { 2989 // input: `SET @@session.autocommit=1, foo="true"`, 2990 // plan: plan.NewSet( 2991 // []sql.Expression{ 2992 // expression.NewSetField(expression.NewSystemVar("autocommit", sql.SystemVariableScope_Session), expression.NewLiteral(int8(1), types.Int8)), 2993 // expression.NewSetField(expression.NewUnresolvedColumn("foo"), expression.NewLiteral("true", types.LongText)), 2994 // }, 2995 // ), 2996 // }, 2997 // { 2998 // input: `SET SESSION NET_READ_TIMEOUT= 700, SESSION NET_WRITE_TIMEOUT= 700`, 2999 // plan: plan.NewSet( 3000 // []sql.Expression{ 3001 // expression.NewSetField(expression.NewSystemVar("NET_READ_TIMEOUT", sql.SystemVariableScope_Session), expression.NewLiteral(int16(700), types.Int16)), 3002 // expression.NewSetField(expression.NewSystemVar("NET_WRITE_TIMEOUT", sql.SystemVariableScope_Session), expression.NewLiteral(int16(700), types.Int16)), 3003 // }, 3004 // ), 3005 // }, 3006 // { 3007 // input: `SET gtid_mode=DEFAULT`, 3008 // plan: plan.NewSet( 3009 // []sql.Expression{ 3010 // expression.NewSetField(expression.NewUnresolvedColumn("gtid_mode"), expression.NewDefaultColumn("")), 3011 // }, 3012 // ), 3013 // }, 3014 // { 3015 // input: `SET @@sql_select_limit=default`, 3016 // plan: plan.NewSet( 3017 // []sql.Expression{ 3018 // expression.NewSetField(expression.NewSystemVar("sql_select_limit", sql.SystemVariableScope_Session), expression.NewDefaultColumn("")), 3019 // }, 3020 // ), 3021 // }, 3022 // { 3023 // input: "", 3024 // plan: plan.NothingImpl, 3025 // }, 3026 // { 3027 // input: "/* just a comment */", 3028 // plan: plan.NothingImpl, 3029 // }, 3030 // { 3031 // input: `/*!40101 SET NAMES utf8 */`, 3032 // plan: plan.NewSet( 3033 // []sql.Expression{ 3034 // expression.NewSetField(expression.NewUnresolvedColumn("character_set_client"), expression.NewLiteral("utf8", types.LongText)), 3035 // expression.NewSetField(expression.NewUnresolvedColumn("character_set_connection"), expression.NewLiteral("utf8", types.LongText)), 3036 // expression.NewSetField(expression.NewUnresolvedColumn("character_set_results"), expression.NewLiteral("utf8", types.LongText)), 3037 // }, 3038 // ), 3039 // }, 3040 // { 3041 // input: `SELECT /* a comment */ * FROM foo`, 3042 // plan: plan.NewProject( 3043 // []sql.Expression{ 3044 // expression.NewStar(), 3045 // }, 3046 // plan.NewUnresolvedTable("foo", "").WithComment("/* a comment */"), 3047 // ), 3048 // }, 3049 // { 3050 // input: `SELECT /*!40101 * from */ foo`, 3051 // plan: plan.NewProject( 3052 // []sql.Expression{ 3053 // expression.NewStar(), 3054 // }, 3055 // plan.NewUnresolvedTable("foo", ""), 3056 // ), 3057 // // TODO: other optimizer hints than join_order are ignored for now 3058 // }, 3059 // { 3060 // input: `SELECT /*+ JOIN_ORDER(a,b) */ * from foo`, 3061 // plan: plan.NewProject( 3062 // []sql.Expression{ 3063 // expression.NewStar(), 3064 // }, 3065 // plan.NewUnresolvedTable("foo", "").WithComment("/*+ JOIN_ORDER(a,b) */"), 3066 // ), 3067 // }, 3068 // { 3069 // input: `SELECT /*+ JOIN_ORDER(a,b) */ * FROM b join a on c = d limit 5`, 3070 // plan: plan.NewLimit(expression.NewLiteral(int8(5), types.Int8), 3071 // plan.NewProject( 3072 // []sql.Expression{ 3073 // expression.NewStar(), 3074 // }, 3075 // plan.NewInnerJoin( 3076 // plan.NewUnresolvedTable("b", ""), 3077 // plan.NewUnresolvedTable("a", ""), 3078 // expression.NewEquals( 3079 // expression.NewUnresolvedColumn("c"), 3080 // expression.NewUnresolvedColumn("d"), 3081 // ), 3082 // ).WithComment("/*+ JOIN_ORDER(a,b) */"), 3083 // ), 3084 // ), 3085 // }, 3086 // { 3087 // input: `SHOW DATABASES`, 3088 // plan: plan.NewShowDatabases(), 3089 // }, 3090 // { 3091 // input: `SELECT * FROM foo WHERE i LIKE 'foo'`, 3092 // plan: plan.NewProject( 3093 // []sql.Expression{expression.NewStar()}, 3094 // plan.NewFilter( 3095 // expression.NewLike( 3096 // expression.NewUnresolvedColumn("i"), 3097 // expression.NewLiteral("foo", types.LongText), 3098 // nil, 3099 // ), 3100 // plan.NewUnresolvedTable("foo", ""), 3101 // ), 3102 // ), 3103 // }, 3104 // { 3105 // input: `SELECT * FROM foo WHERE i NOT LIKE 'foo'`, 3106 // plan: plan.NewProject( 3107 // []sql.Expression{expression.NewStar()}, 3108 // plan.NewFilter( 3109 // expression.NewNot(expression.NewLike( 3110 // expression.NewUnresolvedColumn("i"), 3111 // expression.NewLiteral("foo", types.LongText), 3112 // nil, 3113 // )), 3114 // plan.NewUnresolvedTable("foo", ""), 3115 // ), 3116 // ), 3117 // }, 3118 // { 3119 // input: `SHOW FIELDS FROM foo`, 3120 // plan: plan.NewShowColumns(false, plan.NewUnresolvedTable("foo", "")), 3121 // }, 3122 // { 3123 // input: `SHOW FULL COLUMNS FROM foo`, 3124 // plan: plan.NewShowColumns(true, plan.NewUnresolvedTable("foo", "")), 3125 // }, 3126 // { 3127 // input: `SHOW FIELDS FROM foo WHERE Field = 'bar'`, 3128 // plan: plan.NewFilter( 3129 // expression.NewEquals( 3130 // expression.NewUnresolvedColumn("Field"), 3131 // expression.NewLiteral("bar", types.LongText), 3132 // ), 3133 // plan.NewShowColumns(false, plan.NewUnresolvedTable("foo", "")), 3134 // ), 3135 // }, 3136 // { 3137 // input: `SHOW FIELDS FROM foo LIKE 'bar'`, 3138 // plan: plan.NewFilter( 3139 // expression.NewLike( 3140 // expression.NewUnresolvedColumn("Field"), 3141 // expression.NewLiteral("bar", types.LongText), 3142 // nil, 3143 // ), 3144 // plan.NewShowColumns(false, plan.NewUnresolvedTable("foo", "")), 3145 // ), 3146 // }, 3147 // { 3148 // input: `SHOW TABLE STATUS LIKE 'foo'`, 3149 // plan: plan.NewFilter( 3150 // expression.NewLike( 3151 // expression.NewUnresolvedColumn("Name"), 3152 // expression.NewLiteral("foo", types.LongText), 3153 // nil, 3154 // ), 3155 // plan.NewShowTableStatus(sql.UnresolvedDatabase("")), 3156 // ), 3157 // }, 3158 // { 3159 // input: `SHOW TABLE STATUS FROM foo`, 3160 // plan: plan.NewShowTableStatus(sql.UnresolvedDatabase("foo")), 3161 // }, 3162 // { 3163 // input: `SHOW TABLE STATUS IN foo`, 3164 // plan: plan.NewShowTableStatus(sql.UnresolvedDatabase("foo")), 3165 // }, 3166 // { 3167 // input: `SHOW TABLE STATUS`, 3168 // plan: plan.NewShowTableStatus(sql.UnresolvedDatabase("")), 3169 // }, 3170 // { 3171 // input: `SHOW TABLE STATUS WHERE Name = 'foo'`, 3172 // plan: plan.NewFilter( 3173 // expression.NewEquals( 3174 // expression.NewUnresolvedColumn("Name"), 3175 // expression.NewLiteral("foo", types.LongText), 3176 // ), 3177 // plan.NewShowTableStatus(sql.UnresolvedDatabase("")), 3178 // ), 3179 // }, 3180 // { 3181 // input: `USE foo`, 3182 // plan: plan.NewUse(sql.UnresolvedDatabase("foo")), 3183 // }, 3184 // { 3185 // input: `DESCRIBE foo.bar`, 3186 // plan: plan.NewShowColumns(false, 3187 // plan.NewUnresolvedTable("bar", "foo"), 3188 // ), 3189 // }, 3190 // { 3191 // input: `DESC foo.bar`, 3192 // plan: plan.NewShowColumns(false, 3193 // plan.NewUnresolvedTable("bar", "foo"), 3194 // ), 3195 // }, 3196 // { 3197 // input: `SELECT * FROM foo.bar`, 3198 // plan: plan.NewProject( 3199 // []sql.Expression{ 3200 // expression.NewStar(), 3201 // }, 3202 // plan.NewUnresolvedTable("bar", "foo"), 3203 // ), 3204 // }, 3205 // { 3206 // input: `SHOW VARIABLES`, 3207 // plan: plan.NewShowVariables(expression.NewLiteral(true, types.Boolean), false), 3208 // }, 3209 // { 3210 // input: `SHOW GLOBAL VARIABLES`, 3211 // plan: plan.NewShowVariables(expression.NewLiteral(true, types.Boolean), true), 3212 // }, 3213 // { 3214 // input: `SHOW SESSION VARIABLES`, 3215 // plan: plan.NewShowVariables(expression.NewLiteral(true, types.Boolean), false), 3216 // }, 3217 // { 3218 // input: `SHOW VARIABLES LIKE 'gtid_mode'`, 3219 // plan: plan.NewShowVariables(expression.NewLike( 3220 // expression.NewGetField(0, types.LongText, "variable_name", false), 3221 // expression.NewLiteral("gtid_mode", types.LongText), 3222 // nil, 3223 // ), false), 3224 // }, 3225 // { 3226 // input: `SHOW SESSION VARIABLES LIKE 'autocommit'`, 3227 // plan: plan.NewShowVariables(expression.NewLike( 3228 // expression.NewGetField(0, types.LongText, "variable_name", false), 3229 // expression.NewLiteral("autocommit", types.LongText), 3230 // nil, 3231 // ), false), 3232 // }, 3233 // { 3234 // input: `UNLOCK TABLES`, 3235 // plan: plan.NewUnlockTables(), 3236 // }, 3237 // { 3238 // input: `LOCK TABLES foo READ`, 3239 // plan: plan.NewLockTables([]*plan.TableLock{ 3240 // {Table: plan.NewUnresolvedTable("foo", "")}, 3241 // }), 3242 // }, 3243 // { 3244 // input: `LOCK TABLES foo123 READ`, 3245 // plan: plan.NewLockTables([]*plan.TableLock{ 3246 // {Table: plan.NewUnresolvedTable("foo123", "")}, 3247 // }), 3248 // }, 3249 // { 3250 // input: `LOCK TABLES foo AS f READ`, 3251 // plan: plan.NewLockTables([]*plan.TableLock{ 3252 // {Table: plan.NewTableAlias("f", plan.NewUnresolvedTable("foo", ""))}, 3253 // }), 3254 // }, 3255 // { 3256 // input: `LOCK TABLES foo READ LOCAL`, 3257 // plan: plan.NewLockTables([]*plan.TableLock{ 3258 // {Table: plan.NewUnresolvedTable("foo", "")}, 3259 // }), 3260 // }, 3261 // { 3262 // input: `LOCK TABLES foo WRITE`, 3263 // plan: plan.NewLockTables([]*plan.TableLock{ 3264 // {Table: plan.NewUnresolvedTable("foo", ""), Write: true}, 3265 // }), 3266 // }, 3267 // { 3268 // input: `LOCK TABLES foo LOW_PRIORITY WRITE`, 3269 // plan: plan.NewLockTables([]*plan.TableLock{ 3270 // {Table: plan.NewUnresolvedTable("foo", ""), Write: true}, 3271 // }), 3272 // }, 3273 // { 3274 // input: `LOCK TABLES foo WRITE, bar READ`, 3275 // plan: plan.NewLockTables([]*plan.TableLock{ 3276 // {Table: plan.NewUnresolvedTable("foo", ""), Write: true}, 3277 // {Table: plan.NewUnresolvedTable("bar", "")}, 3278 // }), 3279 // }, 3280 // { 3281 // input: "LOCK TABLES `foo` WRITE, `bar` READ", 3282 // plan: plan.NewLockTables([]*plan.TableLock{ 3283 // {Table: plan.NewUnresolvedTable("foo", ""), Write: true}, 3284 // {Table: plan.NewUnresolvedTable("bar", "")}, 3285 // }), 3286 // }, 3287 // { 3288 // input: `LOCK TABLES foo READ, bar WRITE, baz READ`, 3289 // plan: plan.NewLockTables([]*plan.TableLock{ 3290 // {Table: plan.NewUnresolvedTable("foo", "")}, 3291 // {Table: plan.NewUnresolvedTable("bar", ""), Write: true}, 3292 // {Table: plan.NewUnresolvedTable("baz", "")}, 3293 // }), 3294 // }, 3295 // { 3296 // input: `SHOW CREATE DATABASE foo`, 3297 // plan: plan.NewShowCreateDatabase(sql.UnresolvedDatabase("foo"), false), 3298 // }, 3299 // { 3300 // input: `SHOW CREATE SCHEMA foo`, 3301 // plan: plan.NewShowCreateDatabase(sql.UnresolvedDatabase("foo"), false), 3302 // }, 3303 // { 3304 // input: `SHOW CREATE DATABASE IF NOT EXISTS foo`, 3305 // plan: plan.NewShowCreateDatabase(sql.UnresolvedDatabase("foo"), true), 3306 // }, 3307 // { 3308 // input: `SHOW CREATE SCHEMA IF NOT EXISTS foo`, 3309 // plan: plan.NewShowCreateDatabase(sql.UnresolvedDatabase("foo"), true), 3310 // }, 3311 // { 3312 // input: `SHOW WARNINGS`, 3313 // plan: plan.ShowWarnings(sql.NewEmptyContext().Warnings()), 3314 // }, 3315 // { 3316 // input: `SHOW WARNINGS LIMIT 10`, 3317 // plan: plan.NewLimit(expression.NewLiteral(int8(10), types.Int8), plan.ShowWarnings(sql.NewEmptyContext().Warnings())), 3318 // }, 3319 // { 3320 // input: `SHOW WARNINGS LIMIT 5,10`, 3321 // plan: plan.NewLimit(expression.NewLiteral(int8(10), types.Int8), plan.NewOffset(expression.NewLiteral(int8(5), types.Int8), plan.ShowWarnings(sql.NewEmptyContext().Warnings()))), 3322 // }, 3323 // { 3324 // input: "SHOW CREATE DATABASE `foo`", 3325 // plan: plan.NewShowCreateDatabase(sql.UnresolvedDatabase("foo"), false), 3326 // }, 3327 // { 3328 // input: "SHOW CREATE SCHEMA `foo`", 3329 // plan: plan.NewShowCreateDatabase(sql.UnresolvedDatabase("foo"), false), 3330 // }, 3331 // { 3332 // input: "SHOW CREATE DATABASE IF NOT EXISTS `foo`", 3333 // plan: plan.NewShowCreateDatabase(sql.UnresolvedDatabase("foo"), true), 3334 // }, 3335 // { 3336 // input: "SHOW CREATE SCHEMA IF NOT EXISTS `foo`", 3337 // plan: plan.NewShowCreateDatabase(sql.UnresolvedDatabase("foo"), true), 3338 // }, 3339 // { 3340 // input: "SELECT CASE foo WHEN 1 THEN 'foo' WHEN 2 THEN 'bar' ELSE 'baz' END", 3341 // plan: plan.NewProject( 3342 // []sql.Expression{ 3343 // expression.NewAlias("CASE foo WHEN 1 THEN 'foo' WHEN 2 THEN 'bar' ELSE 'baz' END", 3344 // expression.NewCase( 3345 // expression.NewUnresolvedColumn("foo"), 3346 // []expression.CaseBranch{ 3347 // { 3348 // Cond: expression.NewLiteral(int8(1), types.Int8), 3349 // Value: expression.NewLiteral("foo", types.LongText), 3350 // }, 3351 // { 3352 // Cond: expression.NewLiteral(int8(2), types.Int8), 3353 // Value: expression.NewLiteral("bar", types.LongText), 3354 // }, 3355 // }, 3356 // expression.NewLiteral("baz", types.LongText), 3357 // ), 3358 // ), 3359 // }, 3360 // plan.NewResolvedDualTable(), 3361 // ), 3362 // }, 3363 // { 3364 // input: "SELECT CASE foo WHEN 1 THEN 'foo' WHEN 2 THEN 'bar' END", 3365 // plan: plan.NewProject( 3366 // []sql.Expression{ 3367 // expression.NewAlias("CASE foo WHEN 1 THEN 'foo' WHEN 2 THEN 'bar' END", 3368 // expression.NewCase( 3369 // expression.NewUnresolvedColumn("foo"), 3370 // []expression.CaseBranch{ 3371 // { 3372 // Cond: expression.NewLiteral(int8(1), types.Int8), 3373 // Value: expression.NewLiteral("foo", types.LongText), 3374 // }, 3375 // { 3376 // Cond: expression.NewLiteral(int8(2), types.Int8), 3377 // Value: expression.NewLiteral("bar", types.LongText), 3378 // }, 3379 // }, 3380 // nil, 3381 // ), 3382 // ), 3383 // }, 3384 // plan.NewResolvedDualTable(), 3385 // ), 3386 // }, 3387 // { 3388 // input: "SELECT CASE WHEN foo = 1 THEN 'foo' WHEN foo = 2 THEN 'bar' ELSE 'baz' END", 3389 // plan: plan.NewProject( 3390 // []sql.Expression{ 3391 // expression.NewAlias("CASE WHEN foo = 1 THEN 'foo' WHEN foo = 2 THEN 'bar' ELSE 'baz' END", 3392 // expression.NewCase( 3393 // nil, 3394 // []expression.CaseBranch{ 3395 // { 3396 // Cond: expression.NewEquals( 3397 // expression.NewUnresolvedColumn("foo"), 3398 // expression.NewLiteral(int8(1), types.Int8), 3399 // ), 3400 // Value: expression.NewLiteral("foo", types.LongText), 3401 // }, 3402 // { 3403 // Cond: expression.NewEquals( 3404 // expression.NewUnresolvedColumn("foo"), 3405 // expression.NewLiteral(int8(2), types.Int8), 3406 // ), 3407 // Value: expression.NewLiteral("bar", types.LongText), 3408 // }, 3409 // }, 3410 // expression.NewLiteral("baz", types.LongText), 3411 // ), 3412 // ), 3413 // }, 3414 // plan.NewResolvedDualTable(), 3415 // ), 3416 // }, 3417 // { 3418 // input: "SHOW COLLATION", 3419 // plan: showCollationProjection, 3420 // }, 3421 // { 3422 // input: "SHOW COLLATION LIKE 'foo'", 3423 // plan: plan.NewHaving( 3424 // expression.NewLike( 3425 // expression.NewUnresolvedColumn("collation"), 3426 // expression.NewLiteral("foo", types.LongText), 3427 // nil, 3428 // ), 3429 // showCollationProjection, 3430 // ), 3431 // }, 3432 // { 3433 // input: "SHOW COLLATION WHERE Charset = 'foo'", 3434 // plan: plan.NewHaving( 3435 // expression.NewEquals( 3436 // expression.NewUnresolvedColumn("Charset"), 3437 // expression.NewLiteral("foo", types.LongText), 3438 // ), 3439 // showCollationProjection, 3440 // ), 3441 // }, 3442 // { 3443 // input: "BEGIN", 3444 // plan: plan.NewStartTransaction(sql.ReadWrite), 3445 // }, 3446 // { 3447 // input: "START TRANSACTION", 3448 // plan: plan.NewStartTransaction(sql.ReadWrite), 3449 // }, 3450 // { 3451 // input: "COMMIT", 3452 // plan: plan.NewCommit(), 3453 // }, 3454 // { 3455 // input: `ROLLBACK`, 3456 // plan: plan.NewRollback(), 3457 // }, 3458 // { 3459 // input: "SAVEPOINT abc", 3460 // plan: plan.NewCreateSavepoint("abc"), 3461 // }, 3462 // { 3463 // input: "ROLLBACK TO SAVEPOINT abc", 3464 // plan: plan.NewRollbackSavepoint("abc"), 3465 // }, 3466 // { 3467 // input: "RELEASE SAVEPOINT abc", 3468 // plan: plan.NewReleaseSavepoint("abc"), 3469 // }, 3470 // { 3471 // input: "SHOW CREATE TABLE `mytable`", 3472 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("mytable", ""), false), 3473 // }, 3474 // { 3475 // input: "SHOW CREATE TABLE mytable", 3476 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("mytable", ""), false), 3477 // }, 3478 // { 3479 // input: "SHOW CREATE TABLE mydb.`mytable`", 3480 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("mytable", "mydb"), false), 3481 // }, 3482 // { 3483 // input: "SHOW CREATE TABLE `mydb`.mytable", 3484 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("mytable", "mydb"), false), 3485 // }, 3486 // { 3487 // input: "SHOW CREATE TABLE `mydb`.`mytable`", 3488 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("mytable", "mydb"), false), 3489 // }, 3490 // { 3491 // input: "SHOW CREATE TABLE `my.table`", 3492 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("my.table", ""), false), 3493 // }, 3494 // { 3495 // input: "SHOW CREATE TABLE `my.db`.`my.table`", 3496 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("my.table", "my.db"), false), 3497 // }, 3498 // { 3499 // input: "SHOW CREATE TABLE `my``table`", 3500 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("my`table", ""), false), 3501 // }, 3502 // { 3503 // input: "SHOW CREATE TABLE `my``db`.`my``table`", 3504 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("my`table", "my`db"), false), 3505 // }, 3506 // { 3507 // input: "SHOW CREATE TABLE ````", 3508 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("`", ""), false), 3509 // }, 3510 // { 3511 // input: "SHOW CREATE TABLE `.`", 3512 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable(".", ""), false), 3513 // }, 3514 // { 3515 // input: "SHOW CREATE TABLE mytable as of 'version'", 3516 // plan: plan.NewShowCreateTableWithAsOf( 3517 // plan.NewUnresolvedTableAsOf("mytable", "", expression.NewLiteral("version", types.LongText)), 3518 // false, expression.NewLiteral("version", types.LongText)), 3519 // }, 3520 // { 3521 // input: "SHOW CREATE VIEW `mytable`", 3522 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("mytable", ""), true), 3523 // }, 3524 // { 3525 // input: "SHOW CREATE VIEW mytable", 3526 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("mytable", ""), true), 3527 // }, 3528 // { 3529 // input: "SHOW CREATE VIEW mydb.`mytable`", 3530 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("mytable", "mydb"), true), 3531 // }, 3532 // { 3533 // input: "SHOW CREATE VIEW `mydb`.mytable", 3534 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("mytable", "mydb"), true), 3535 // }, 3536 // { 3537 // input: "SHOW CREATE VIEW `mydb`.`mytable`", 3538 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("mytable", "mydb"), true), 3539 // }, 3540 // { 3541 // input: "SHOW CREATE VIEW `my.table`", 3542 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("my.table", ""), true), 3543 // }, 3544 // { 3545 // input: "SHOW CREATE VIEW `my.db`.`my.table`", 3546 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("my.table", "my.db"), true), 3547 // }, 3548 // { 3549 // input: "SHOW CREATE VIEW `my``table`", 3550 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("my`table", ""), true), 3551 // }, 3552 // { 3553 // input: "SHOW CREATE VIEW `my``db`.`my``table`", 3554 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("my`table", "my`db"), true), 3555 // }, 3556 // { 3557 // input: "SHOW CREATE VIEW ````", 3558 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable("`", ""), true), 3559 // }, 3560 // { 3561 // input: "SHOW CREATE VIEW `.`", 3562 // plan: plan.NewShowCreateTable(plan.NewUnresolvedTable(".", ""), true), 3563 // }, 3564 // { 3565 // input: `SELECT '2018-05-01' + INTERVAL 1 DAY`, 3566 // plan: plan.NewProject( 3567 // []sql.Expression{ 3568 // expression.NewAlias("'2018-05-01' + INTERVAL 1 DAY", 3569 // expression.NewArithmetic( 3570 // expression.NewLiteral("2018-05-01", types.LongText), 3571 // expression.NewInterval( 3572 // expression.NewLiteral(int8(1), types.Int8), 3573 // "DAY", 3574 // ), 3575 // "+", 3576 // ), 3577 // ), 3578 // }, 3579 // plan.NewResolvedDualTable(), 3580 // ), 3581 // }, 3582 // { 3583 // input: `SELECT '2018-05-01' - INTERVAL 1 DAY`, 3584 // plan: plan.NewProject( 3585 // []sql.Expression{ 3586 // expression.NewAlias("'2018-05-01' - INTERVAL 1 DAY", 3587 // expression.NewArithmetic( 3588 // expression.NewLiteral("2018-05-01", types.LongText), 3589 // expression.NewInterval( 3590 // expression.NewLiteral(int8(1), types.Int8), 3591 // "DAY", 3592 // ), 3593 // "-", 3594 // ), 3595 // ), 3596 // }, 3597 // plan.NewResolvedDualTable(), 3598 // ), 3599 // }, 3600 // { 3601 // input: `SELECT INTERVAL 1 DAY + '2018-05-01'`, 3602 // plan: plan.NewProject( 3603 // []sql.Expression{ 3604 // expression.NewAlias("INTERVAL 1 DAY + '2018-05-01'", 3605 // expression.NewArithmetic( 3606 // expression.NewInterval( 3607 // expression.NewLiteral(int8(1), types.Int8), 3608 // "DAY", 3609 // ), 3610 // expression.NewLiteral("2018-05-01", types.LongText), 3611 // "+", 3612 // ), 3613 // ), 3614 // }, 3615 // plan.NewResolvedDualTable(), 3616 // ), 3617 // }, 3618 // { 3619 // input: `SELECT '2018-05-01' + INTERVAL 1 DAY + INTERVAL 1 DAY`, 3620 // plan: plan.NewProject( 3621 // []sql.Expression{ 3622 // expression.NewAlias("'2018-05-01' + INTERVAL 1 DAY + INTERVAL 1 DAY", 3623 // expression.NewArithmetic( 3624 // expression.NewArithmetic( 3625 // expression.NewLiteral("2018-05-01", types.LongText), 3626 // expression.NewInterval( 3627 // expression.NewLiteral(int8(1), types.Int8), 3628 // "DAY", 3629 // ), 3630 // "+", 3631 // ), 3632 // expression.NewInterval( 3633 // expression.NewLiteral(int8(1), types.Int8), 3634 // "DAY", 3635 // ), 3636 // "+", 3637 // ), 3638 // ), 3639 // }, 3640 // plan.NewResolvedDualTable(), 3641 // ), 3642 // }, 3643 // { 3644 // input: `SELECT bar, AVG(baz) FROM foo GROUP BY bar HAVING COUNT(*) > 5`, 3645 // plan: plan.NewHaving( 3646 // expression.NewGreaterThan( 3647 // expression.NewUnresolvedFunction("count", true, nil, expression.NewStar()), 3648 // expression.NewLiteral(int8(5), types.Int8), 3649 // ), 3650 // plan.NewGroupBy( 3651 // []sql.Expression{ 3652 // expression.NewUnresolvedColumn("bar"), 3653 // expression.NewAlias("AVG(baz)", 3654 // expression.NewUnresolvedFunction("avg", true, nil, expression.NewUnresolvedColumn("baz")), 3655 // ), 3656 // }, 3657 // []sql.Expression{expression.NewUnresolvedColumn("bar")}, 3658 // plan.NewUnresolvedTable("foo", ""), 3659 // ), 3660 // ), 3661 // }, 3662 // { 3663 // input: `SELECT foo FROM t GROUP BY foo HAVING i > 5`, 3664 // plan: plan.NewHaving( 3665 // expression.NewGreaterThan( 3666 // expression.NewUnresolvedColumn("i"), 3667 // expression.NewLiteral(int8(5), types.Int8), 3668 // ), 3669 // plan.NewGroupBy( 3670 // []sql.Expression{expression.NewUnresolvedColumn("foo")}, 3671 // []sql.Expression{expression.NewUnresolvedColumn("foo")}, 3672 // plan.NewUnresolvedTable("t", ""), 3673 // ), 3674 // ), 3675 // }, 3676 // { 3677 // input: `SELECT COUNT(*) FROM foo GROUP BY a HAVING COUNT(*) > 5`, 3678 // plan: plan.NewHaving( 3679 // expression.NewGreaterThan( 3680 // expression.NewUnresolvedFunction("count", true, nil, expression.NewStar()), 3681 // expression.NewLiteral(int8(5), types.Int8), 3682 // ), 3683 // plan.NewGroupBy( 3684 // []sql.Expression{ 3685 // expression.NewAlias("COUNT(*)", 3686 // expression.NewUnresolvedFunction("count", true, nil, expression.NewStar()), 3687 // ), 3688 // }, 3689 // []sql.Expression{expression.NewUnresolvedColumn("a")}, 3690 // plan.NewUnresolvedTable("foo", ""), 3691 // ), 3692 // ), 3693 // }, 3694 // { 3695 // input: `SELECT DISTINCT COUNT(*) FROM foo GROUP BY a HAVING COUNT(*) > 5`, 3696 // plan: plan.NewDistinct( 3697 // plan.NewHaving( 3698 // expression.NewGreaterThan( 3699 // expression.NewUnresolvedFunction("count", true, nil, expression.NewStar()), 3700 // expression.NewLiteral(int8(5), types.Int8), 3701 // ), 3702 // plan.NewGroupBy( 3703 // []sql.Expression{ 3704 // expression.NewAlias("COUNT(*)", 3705 // expression.NewUnresolvedFunction("count", true, nil, expression.NewStar()), 3706 // ), 3707 // }, 3708 // []sql.Expression{expression.NewUnresolvedColumn("a")}, 3709 // plan.NewUnresolvedTable("foo", ""), 3710 // ), 3711 // ), 3712 // ), 3713 // }, 3714 // { 3715 // input: `SELECT * FROM foo LEFT JOIN bar ON 1=1`, 3716 // plan: plan.NewProject( 3717 // []sql.Expression{expression.NewStar()}, 3718 // plan.NewLeftOuterJoin( 3719 // plan.NewUnresolvedTable("foo", ""), 3720 // plan.NewUnresolvedTable("bar", ""), 3721 // expression.NewEquals( 3722 // expression.NewLiteral(int8(1), types.Int8), 3723 // expression.NewLiteral(int8(1), types.Int8), 3724 // ), 3725 // ), 3726 // ), 3727 // }, 3728 // { 3729 // input: `SELECT * FROM foo LEFT OUTER JOIN bar ON 1=1`, 3730 // plan: plan.NewProject( 3731 // []sql.Expression{expression.NewStar()}, 3732 // plan.NewLeftOuterJoin( 3733 // plan.NewUnresolvedTable("foo", ""), 3734 // plan.NewUnresolvedTable("bar", ""), 3735 // expression.NewEquals( 3736 // expression.NewLiteral(int8(1), types.Int8), 3737 // expression.NewLiteral(int8(1), types.Int8), 3738 // ), 3739 // ), 3740 // ), 3741 // }, 3742 // { 3743 // input: `SELECT * FROM foo RIGHT JOIN bar ON 1=1`, 3744 // plan: plan.NewProject( 3745 // []sql.Expression{expression.NewStar()}, 3746 // plan.NewRightOuterJoin( 3747 // plan.NewUnresolvedTable("foo", ""), 3748 // plan.NewUnresolvedTable("bar", ""), 3749 // expression.NewEquals( 3750 // expression.NewLiteral(int8(1), types.Int8), 3751 // expression.NewLiteral(int8(1), types.Int8), 3752 // ), 3753 // ), 3754 // ), 3755 // }, 3756 // { 3757 // input: `SELECT * FROM foo RIGHT OUTER JOIN bar ON 1=1`, 3758 // plan: plan.NewProject( 3759 // []sql.Expression{expression.NewStar()}, 3760 // plan.NewRightOuterJoin( 3761 // plan.NewUnresolvedTable("foo", ""), 3762 // plan.NewUnresolvedTable("bar", ""), 3763 // expression.NewEquals( 3764 // expression.NewLiteral(int8(1), types.Int8), 3765 // expression.NewLiteral(int8(1), types.Int8), 3766 // ), 3767 // ), 3768 // ), 3769 // }, 3770 // { 3771 // input: `SELECT FIRST(i) FROM foo`, 3772 // plan: plan.NewGroupBy( 3773 // []sql.Expression{ 3774 // expression.NewAlias("FIRST(i)", 3775 // expression.NewUnresolvedFunction("first", true, nil, expression.NewUnresolvedColumn("i")), 3776 // ), 3777 // }, 3778 // []sql.Expression{}, 3779 // plan.NewUnresolvedTable("foo", ""), 3780 // ), 3781 // }, 3782 // { 3783 // input: `SELECT LAST(i) FROM foo`, 3784 // plan: plan.NewGroupBy( 3785 // []sql.Expression{ 3786 // expression.NewAlias("LAST(i)", 3787 // expression.NewUnresolvedFunction("last", true, nil, expression.NewUnresolvedColumn("i")), 3788 // ), 3789 // }, 3790 // []sql.Expression{}, 3791 // plan.NewUnresolvedTable("foo", ""), 3792 // ), 3793 // }, 3794 // { 3795 // input: `SELECT COUNT(DISTINCT i) FROM foo`, 3796 // plan: plan.NewGroupBy( 3797 // []sql.Expression{ 3798 // expression.NewAlias("COUNT(DISTINCT i)", 3799 // aggregation.NewCountDistinct(expression.NewUnresolvedColumn("i"))), 3800 // }, 3801 // []sql.Expression{}, 3802 // plan.NewUnresolvedTable("foo", ""), 3803 // ), 3804 // }, 3805 // { 3806 // input: `SELECT AVG(DISTINCT a) FROM foo`, 3807 // plan: plan.NewGroupBy( 3808 // []sql.Expression{ 3809 // expression.NewAlias("AVG(DISTINCT a)", 3810 // expression.NewUnresolvedFunction("avg", true, nil, expression.NewDistinctExpression(expression.NewUnresolvedColumn("a")))), 3811 // }, 3812 // []sql.Expression{}, 3813 // plan.NewUnresolvedTable("foo", ""), 3814 // ), 3815 // }, 3816 // { 3817 // input: `SELECT SUM(DISTINCT a*b) FROM foo`, 3818 // plan: plan.NewGroupBy( 3819 // []sql.Expression{ 3820 // expression.NewAlias("SUM(DISTINCT a*b)", 3821 // expression.NewUnresolvedFunction("sum", true, nil, 3822 // expression.NewDistinctExpression( 3823 // expression.NewMult(expression.NewUnresolvedColumn("a"), 3824 // expression.NewUnresolvedColumn("b")))))}, 3825 // []sql.Expression{}, 3826 // plan.NewUnresolvedTable("foo", ""), 3827 // ), 3828 // }, 3829 // { 3830 // input: `SELECT AVG(DISTINCT a / b) FROM foo`, 3831 // plan: plan.NewGroupBy( 3832 // []sql.Expression{ 3833 // expression.NewAlias("AVG(DISTINCT a / b)", 3834 // expression.NewUnresolvedFunction("avg", true, nil, 3835 // expression.NewDistinctExpression( 3836 // expression.NewDiv(expression.NewUnresolvedColumn("a"), 3837 // expression.NewUnresolvedColumn("b")))))}, 3838 // []sql.Expression{}, 3839 // plan.NewUnresolvedTable("foo", ""), 3840 // ), 3841 // }, 3842 // { 3843 // input: `SELECT SUM(DISTINCT POWER(a, 2)) FROM foo`, 3844 // plan: plan.NewGroupBy( 3845 // []sql.Expression{ 3846 // expression.NewAlias("SUM(DISTINCT POWER(a, 2))", 3847 // expression.NewUnresolvedFunction("sum", true, nil, 3848 // expression.NewDistinctExpression( 3849 // expression.NewUnresolvedFunction("power", false, nil, 3850 // expression.NewUnresolvedColumn("a"), expression.NewLiteral(int8(2), types.Int8)))))}, 3851 // []sql.Expression{}, 3852 // plan.NewUnresolvedTable("foo", ""), 3853 // ), 3854 // }, 3855 // { 3856 // input: `SELECT a, row_number() over (partition by s order by x) FROM foo`, 3857 // plan: plan.NewWindow( 3858 // []sql.Expression{ 3859 // expression.NewUnresolvedColumn("a"), 3860 // expression.NewAlias("row_number() over (partition by s order by x)", 3861 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 3862 // expression.NewUnresolvedColumn("s"), 3863 // }, sql.SortFields{ 3864 // { 3865 // Column: expression.NewUnresolvedColumn("x"), 3866 // Column2: expression.NewUnresolvedColumn("x"), 3867 // Order: sql.Ascending, 3868 // NullOrdering: sql.NullsFirst, 3869 // }, 3870 // }, nil, "", "")), 3871 // ), 3872 // }, 3873 // plan.NewUnresolvedTable("foo", ""), 3874 // ), 3875 // }, 3876 // { 3877 // input: `SELECT a, count(i) over () FROM foo`, 3878 // plan: plan.NewWindow( 3879 // []sql.Expression{ 3880 // expression.NewUnresolvedColumn("a"), 3881 // expression.NewAlias("count(i) over ()", 3882 // expression.NewUnresolvedFunction("count", true, 3883 // sql.NewWindowDefinition([]sql.Expression{}, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "", ""), 3884 // expression.NewUnresolvedColumn("i")), 3885 // ), 3886 // }, 3887 // plan.NewUnresolvedTable("foo", ""), 3888 // ), 3889 // }, 3890 // { 3891 // input: `SELECT a, row_number() over (order by x), row_number() over (partition by y) FROM foo`, 3892 // plan: plan.NewWindow( 3893 // []sql.Expression{ 3894 // expression.NewUnresolvedColumn("a"), 3895 // expression.NewAlias("row_number() over (order by x)", 3896 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{}, sql.SortFields{ 3897 // { 3898 // Column: expression.NewUnresolvedColumn("x"), 3899 // Column2: expression.NewUnresolvedColumn("x"), 3900 // Order: sql.Ascending, 3901 // NullOrdering: sql.NullsFirst, 3902 // }, 3903 // }, nil, "", "")), 3904 // ), 3905 // expression.NewAlias("row_number() over (partition by y)", 3906 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 3907 // expression.NewUnresolvedColumn("y"), 3908 // }, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "", "")), 3909 // ), 3910 // }, 3911 // plan.NewUnresolvedTable("foo", ""), 3912 // ), 3913 // }, 3914 // { 3915 // input: `SELECT a, row_number() over (order by x), max(b) over () FROM foo`, 3916 // plan: plan.NewWindow( 3917 // []sql.Expression{ 3918 // expression.NewUnresolvedColumn("a"), 3919 // expression.NewAlias("row_number() over (order by x)", 3920 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{}, sql.SortFields{ 3921 // { 3922 // Column: expression.NewUnresolvedColumn("x"), 3923 // Column2: expression.NewUnresolvedColumn("x"), 3924 // Order: sql.Ascending, 3925 // NullOrdering: sql.NullsFirst, 3926 // }, 3927 // }, nil, "", "")), 3928 // ), 3929 // expression.NewAlias("max(b) over ()", 3930 // expression.NewUnresolvedFunction("max", true, sql.NewWindowDefinition([]sql.Expression{}, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "", ""), 3931 // expression.NewUnresolvedColumn("b"), 3932 // ), 3933 // ), 3934 // }, 3935 // plan.NewUnresolvedTable("foo", ""), 3936 // ), 3937 // }, 3938 // { 3939 // input: `SELECT a, row_number() over (partition by b), max(b) over (partition by b) FROM foo`, 3940 // plan: plan.NewWindow( 3941 // []sql.Expression{ 3942 // expression.NewUnresolvedColumn("a"), 3943 // expression.NewAlias("row_number() over (partition by b)", 3944 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 3945 // expression.NewUnresolvedColumn("b"), 3946 // }, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "", "")), 3947 // ), 3948 // expression.NewAlias("max(b) over (partition by b)", 3949 // expression.NewUnresolvedFunction("max", true, sql.NewWindowDefinition([]sql.Expression{ 3950 // expression.NewUnresolvedColumn("b"), 3951 // }, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "", ""), 3952 // expression.NewUnresolvedColumn("b"), 3953 // ), 3954 // ), 3955 // }, 3956 // plan.NewUnresolvedTable("foo", ""), 3957 // ), 3958 // }, 3959 // { 3960 // input: `SELECT a, row_number() over (partition by c), max(b) over (partition by b) FROM foo`, 3961 // plan: plan.NewWindow( 3962 // []sql.Expression{ 3963 // expression.NewUnresolvedColumn("a"), 3964 // expression.NewAlias("row_number() over (partition by c)", 3965 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 3966 // expression.NewUnresolvedColumn("c"), 3967 // }, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "", "")), 3968 // ), 3969 // expression.NewAlias("max(b) over (partition by b)", 3970 // expression.NewUnresolvedFunction("max", true, sql.NewWindowDefinition([]sql.Expression{ 3971 // expression.NewUnresolvedColumn("b"), 3972 // }, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "", ""), 3973 // expression.NewUnresolvedColumn("b"), 3974 // ), 3975 // ), 3976 // }, 3977 // plan.NewUnresolvedTable("foo", ""), 3978 // ), 3979 // }, 3980 // { 3981 // input: `SELECT a, count(i) over (order by x) FROM foo`, 3982 // plan: plan.NewWindow( 3983 // []sql.Expression{ 3984 // expression.NewUnresolvedColumn("a"), 3985 // expression.NewAlias("count(i) over (order by x)", 3986 // expression.NewUnresolvedFunction("count", true, sql.NewWindowDefinition([]sql.Expression{}, sql.SortFields{ 3987 // { 3988 // Column: expression.NewUnresolvedColumn("x"), 3989 // Column2: expression.NewUnresolvedColumn("x"), 3990 // Order: sql.Ascending, 3991 // NullOrdering: sql.NullsFirst, 3992 // }, 3993 // }, nil, "", ""), 3994 // expression.NewUnresolvedColumn("i"), 3995 // ), 3996 // ), 3997 // }, 3998 // plan.NewUnresolvedTable("foo", ""), 3999 // ), 4000 // }, 4001 // { 4002 // input: `SELECT a, count(i) over (partition by y) FROM foo`, 4003 // plan: plan.NewWindow( 4004 // []sql.Expression{ 4005 // expression.NewUnresolvedColumn("a"), 4006 // expression.NewAlias("count(i) over (partition by y)", 4007 // expression.NewUnresolvedFunction("count", true, sql.NewWindowDefinition([]sql.Expression{ 4008 // expression.NewUnresolvedColumn("y"), 4009 // }, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "", ""), 4010 // expression.NewUnresolvedColumn("i"), 4011 // ), 4012 // ), 4013 // }, 4014 // plan.NewUnresolvedTable("foo", ""), 4015 // ), 4016 // }, 4017 // { 4018 // input: `SELECT i, row_number() over (order by a), max(b) from foo`, 4019 // plan: plan.NewWindow( 4020 // []sql.Expression{ 4021 // expression.NewUnresolvedColumn("i"), 4022 // expression.NewAlias("row_number() over (order by a)", 4023 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{}, sql.SortFields{ 4024 // { 4025 // Column: expression.NewUnresolvedColumn("a"), 4026 // Column2: expression.NewUnresolvedColumn("a"), 4027 // Order: sql.Ascending, 4028 // NullOrdering: sql.NullsFirst, 4029 // }, 4030 // }, nil, "", "")), 4031 // ), 4032 // expression.NewAlias("max(b)", 4033 // expression.NewUnresolvedFunction("max", true, nil, 4034 // expression.NewUnresolvedColumn("b"), 4035 // ), 4036 // ), 4037 // }, 4038 // plan.NewUnresolvedTable("foo", ""), 4039 // ), 4040 // }, 4041 // { 4042 // input: `SELECT row_number() over (partition by x ROWS UNBOUNDED PRECEDING) from foo`, 4043 // plan: plan.NewWindow( 4044 // []sql.Expression{ 4045 // expression.NewAlias("row_number() over (partition by x ROWS UNBOUNDED PRECEDING)", 4046 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4047 // expression.NewUnresolvedColumn("x"), 4048 // }, nil, plan.NewRowsUnboundedPrecedingToCurrentRowFrame(), "", "")), 4049 // ), 4050 // }, 4051 // plan.NewUnresolvedTable("foo", ""), 4052 // ), 4053 // }, 4054 // { 4055 // input: `SELECT row_number() over (partition by x ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) from foo`, 4056 // plan: plan.NewWindow( 4057 // []sql.Expression{ 4058 // expression.NewAlias("row_number() over (partition by x ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)", 4059 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4060 // expression.NewUnresolvedColumn("x"), 4061 // }, nil, plan.NewRowsNPrecedingToNFollowingFrame( 4062 // expression.NewLiteral(int8(1), types.Int8), 4063 // expression.NewLiteral(int8(1), types.Int8), 4064 // ), "", ""), 4065 // ), 4066 // ), 4067 // }, 4068 // plan.NewUnresolvedTable("foo", ""), 4069 // ), 4070 // }, 4071 // { 4072 // input: `SELECT row_number() over (partition by x ROWS BETWEEN 1 FOLLOWING AND 2 FOLLOWING) from foo`, 4073 // plan: plan.NewWindow( 4074 // []sql.Expression{ 4075 // expression.NewAlias("row_number() over (partition by x ROWS BETWEEN 1 FOLLOWING AND 2 FOLLOWING)", 4076 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4077 // expression.NewUnresolvedColumn("x"), 4078 // }, nil, plan.NewRowsNFollowingToNFollowingFrame( 4079 // expression.NewLiteral(int8(1), types.Int8), 4080 // expression.NewLiteral(int8(2), types.Int8), 4081 // ), "", ""), 4082 // ), 4083 // ), 4084 // }, 4085 // plan.NewUnresolvedTable("foo", ""), 4086 // ), 4087 // }, 4088 // { 4089 // input: `SELECT row_number() over (partition by x ROWS BETWEEN CURRENT ROW AND CURRENT ROW) from foo`, 4090 // plan: plan.NewWindow( 4091 // []sql.Expression{ 4092 // expression.NewAlias("row_number() over (partition by x ROWS BETWEEN CURRENT ROW AND CURRENT ROW)", 4093 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4094 // expression.NewUnresolvedColumn("x"), 4095 // }, nil, plan.NewRowsCurrentRowToCurrentRowFrame(), "", "")), 4096 // ), 4097 // }, 4098 // plan.NewUnresolvedTable("foo", ""), 4099 // ), 4100 // }, 4101 // { 4102 // input: `SELECT row_number() over (partition by x ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) from foo`, 4103 // plan: plan.NewWindow( 4104 // []sql.Expression{ 4105 // expression.NewAlias("row_number() over (partition by x ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING)", 4106 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4107 // expression.NewUnresolvedColumn("x"), 4108 // }, nil, plan.NewRowsCurrentRowToNFollowingFrame( 4109 // expression.NewLiteral(int8(1), types.Int8), 4110 // ), "", "")), 4111 // ), 4112 // }, 4113 // plan.NewUnresolvedTable("foo", ""), 4114 // ), 4115 // }, 4116 // { 4117 // input: `SELECT row_number() over (partition by x RANGE CURRENT ROW) from foo`, 4118 // plan: plan.NewWindow( 4119 // []sql.Expression{ 4120 // expression.NewAlias("row_number() over (partition by x RANGE CURRENT ROW)", 4121 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4122 // expression.NewUnresolvedColumn("x"), 4123 // }, nil, plan.NewRangeCurrentRowToCurrentRowFrame(), "", "")), 4124 // ), 4125 // }, 4126 // plan.NewUnresolvedTable("foo", ""), 4127 // ), 4128 // }, 4129 // { 4130 // input: `SELECT row_number() over (partition by x RANGE 2 PRECEDING) from foo`, 4131 // plan: plan.NewWindow( 4132 // []sql.Expression{ 4133 // expression.NewAlias("row_number() over (partition by x RANGE 2 PRECEDING)", 4134 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4135 // expression.NewUnresolvedColumn("x"), 4136 // }, nil, plan.NewRangeNPrecedingToCurrentRowFrame( 4137 // expression.NewLiteral(int8(2), types.Int8), 4138 // ), "", "")), 4139 // ), 4140 // }, 4141 // plan.NewUnresolvedTable("foo", ""), 4142 // ), 4143 // }, 4144 // { 4145 // input: `SELECT row_number() over (partition by x RANGE UNBOUNDED PRECEDING) from foo`, 4146 // plan: plan.NewWindow( 4147 // []sql.Expression{ 4148 // expression.NewAlias("row_number() over (partition by x RANGE UNBOUNDED PRECEDING)", 4149 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4150 // expression.NewUnresolvedColumn("x"), 4151 // }, nil, plan.NewRangeUnboundedPrecedingToCurrentRowFrame(), "", "")), 4152 // ), 4153 // }, 4154 // plan.NewUnresolvedTable("foo", ""), 4155 // ), 4156 // }, 4157 // { 4158 // input: `SELECT row_number() over (partition by x RANGE interval 5 DAY PRECEDING) from foo`, 4159 // plan: plan.NewWindow( 4160 // []sql.Expression{ 4161 // expression.NewAlias("row_number() over (partition by x RANGE interval 5 DAY PRECEDING)", 4162 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4163 // expression.NewUnresolvedColumn("x"), 4164 // }, nil, plan.NewRangeNPrecedingToCurrentRowFrame( 4165 // expression.NewInterval( 4166 // expression.NewLiteral(int8(5), types.Int8), 4167 // "DAY", 4168 // ), 4169 // ), "", "")), 4170 // ), 4171 // }, 4172 // plan.NewUnresolvedTable("foo", ""), 4173 // ), 4174 // }, 4175 // { 4176 // input: `SELECT row_number() over (partition by x RANGE interval '2:30' MINUTE_SECOND PRECEDING) from foo`, 4177 // plan: plan.NewWindow( 4178 // []sql.Expression{ 4179 // expression.NewAlias("row_number() over (partition by x RANGE interval '2:30' MINUTE_SECOND PRECEDING)", 4180 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4181 // expression.NewUnresolvedColumn("x"), 4182 // }, nil, plan.NewRangeNPrecedingToCurrentRowFrame( 4183 // expression.NewInterval( 4184 // expression.NewLiteral("2:30", types.LongText), 4185 // "MINUTE_SECOND", 4186 // ), 4187 // ), "", "")), 4188 // ), 4189 // }, 4190 // plan.NewUnresolvedTable("foo", ""), 4191 // ), 4192 // }, 4193 // { 4194 // input: `SELECT row_number() over (partition by x RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING) from foo`, 4195 // plan: plan.NewWindow( 4196 // []sql.Expression{ 4197 // expression.NewAlias("row_number() over (partition by x RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING)", 4198 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4199 // expression.NewUnresolvedColumn("x"), 4200 // }, nil, plan.NewRangeNPrecedingToNFollowingFrame( 4201 // expression.NewLiteral(int8(1), types.Int8), 4202 // expression.NewLiteral(int8(1), types.Int8), 4203 // ), "", "")), 4204 // ), 4205 // }, 4206 // plan.NewUnresolvedTable("foo", ""), 4207 // ), 4208 // }, 4209 // { 4210 // input: `SELECT row_number() over (partition by x RANGE BETWEEN CURRENT ROW AND CURRENT ROW) from foo`, 4211 // plan: plan.NewWindow( 4212 // []sql.Expression{ 4213 // expression.NewAlias("row_number() over (partition by x RANGE BETWEEN CURRENT ROW AND CURRENT ROW)", 4214 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4215 // expression.NewUnresolvedColumn("x"), 4216 // }, nil, plan.NewRangeCurrentRowToCurrentRowFrame(), "", "")), 4217 // ), 4218 // }, 4219 // plan.NewUnresolvedTable("foo", ""), 4220 // ), 4221 // }, 4222 // { 4223 // input: `SELECT row_number() over (partition by x RANGE BETWEEN CURRENT ROW AND 1 FOLLOWING) from foo`, 4224 // plan: plan.NewWindow( 4225 // []sql.Expression{ 4226 // expression.NewAlias("row_number() over (partition by x RANGE BETWEEN CURRENT ROW AND 1 FOLLOWING)", 4227 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4228 // expression.NewUnresolvedColumn("x"), 4229 // }, nil, plan.NewRangeCurrentRowToNFollowingFrame( 4230 // expression.NewLiteral(int8(1), types.Int8), 4231 // ), "", "")), 4232 // ), 4233 // }, 4234 // plan.NewUnresolvedTable("foo", ""), 4235 // ), 4236 // }, 4237 // { 4238 // input: `SELECT row_number() over (partition by x RANGE BETWEEN interval 5 DAY PRECEDING AND CURRENT ROW) from foo`, 4239 // plan: plan.NewWindow( 4240 // []sql.Expression{ 4241 // expression.NewAlias("row_number() over (partition by x RANGE BETWEEN interval 5 DAY PRECEDING AND CURRENT ROW)", 4242 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4243 // expression.NewUnresolvedColumn("x"), 4244 // }, nil, plan.NewRangeNPrecedingToCurrentRowFrame( 4245 // expression.NewInterval( 4246 // expression.NewLiteral(int8(5), types.Int8), 4247 // "DAY", 4248 // ), 4249 // ), "", ""), 4250 // )), 4251 // }, 4252 // plan.NewUnresolvedTable("foo", ""), 4253 // ), 4254 // }, 4255 // { 4256 // input: `SELECT row_number() over (partition by x RANGE BETWEEN interval '2:30' MINUTE_SECOND PRECEDING AND CURRENT ROW) from foo`, 4257 // plan: plan.NewWindow( 4258 // []sql.Expression{ 4259 // expression.NewAlias("row_number() over (partition by x RANGE BETWEEN interval '2:30' MINUTE_SECOND PRECEDING AND CURRENT ROW)", 4260 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{ 4261 // expression.NewUnresolvedColumn("x"), 4262 // }, nil, plan.NewRangeNPrecedingToCurrentRowFrame( 4263 // expression.NewInterval( 4264 // expression.NewLiteral("2:30", types.LongText), 4265 // "MINUTE_SECOND", 4266 // ), 4267 // ), "", "")), 4268 // ), 4269 // }, 4270 // plan.NewUnresolvedTable("foo", ""), 4271 // ), 4272 // }, 4273 // { 4274 // input: `SELECT row_number() over (w) from foo WINDOW w as (partition by x RANGE BETWEEN interval '2:30' MINUTE_SECOND PRECEDING AND CURRENT ROW)`, 4275 // plan: plan.NewNamedWindows( 4276 // map[string]*sql.WindowDefinition{ 4277 // "w": sql.NewWindowDefinition([]sql.Expression{ 4278 // expression.NewUnresolvedColumn("x"), 4279 // }, nil, plan.NewRangeNPrecedingToCurrentRowFrame( 4280 // expression.NewInterval( 4281 // expression.NewLiteral("2:30", types.LongText), 4282 // "MINUTE_SECOND", 4283 // ), 4284 // ), "", "w"), 4285 // }, 4286 // plan.NewWindow( 4287 // []sql.Expression{ 4288 // expression.NewAlias("row_number() over (w)", 4289 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{}, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "w", "")), 4290 // ), 4291 // }, 4292 // plan.NewUnresolvedTable("foo", ""), 4293 // )), 4294 // }, 4295 // { 4296 // input: `SELECT a, row_number() over (w1), max(b) over (w2) FROM foo WINDOW w1 as (w2 order by x), w2 as ()`, 4297 // plan: plan.NewNamedWindows( 4298 // map[string]*sql.WindowDefinition{ 4299 // "w1": sql.NewWindowDefinition([]sql.Expression{}, sql.SortFields{ 4300 // { 4301 // Column: expression.NewUnresolvedColumn("x"), 4302 // Column2: expression.NewUnresolvedColumn("x"), 4303 // Order: sql.Ascending, 4304 // NullOrdering: sql.NullsFirst, 4305 // }, 4306 // }, nil, "w2", "w1"), 4307 // "w2": sql.NewWindowDefinition([]sql.Expression{}, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "", "w2"), 4308 // }, 4309 // plan.NewWindow( 4310 // []sql.Expression{ 4311 // expression.NewUnresolvedColumn("a"), 4312 // expression.NewAlias("row_number() over (w1)", 4313 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition([]sql.Expression{}, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "w1", "")), 4314 // ), 4315 // expression.NewAlias("max(b) over (w2)", 4316 // expression.NewUnresolvedFunction("max", true, sql.NewWindowDefinition([]sql.Expression{}, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "w2", ""), 4317 // expression.NewUnresolvedColumn("b"), 4318 // ), 4319 // ), 4320 // }, 4321 // plan.NewUnresolvedTable("foo", ""), 4322 // ), 4323 // ), 4324 // }, 4325 // { 4326 // input: `SELECT a, row_number() over (w1 partition by y), max(b) over (w2) FROM foo WINDOW w1 as (w2 order by x), w2 as ()`, 4327 // plan: plan.NewNamedWindows( 4328 // map[string]*sql.WindowDefinition{ 4329 // "w1": sql.NewWindowDefinition([]sql.Expression{}, sql.SortFields{ 4330 // { 4331 // Column: expression.NewUnresolvedColumn("x"), 4332 // Column2: expression.NewUnresolvedColumn("x"), 4333 // Order: sql.Ascending, 4334 // NullOrdering: sql.NullsFirst, 4335 // }, 4336 // }, nil, "w2", "w1"), 4337 // "w2": sql.NewWindowDefinition([]sql.Expression{}, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "", "w2"), 4338 // }, plan.NewWindow( 4339 // []sql.Expression{ 4340 // expression.NewUnresolvedColumn("a"), 4341 // expression.NewAlias("row_number() over (w1 partition by y)", 4342 // expression.NewUnresolvedFunction("row_number", true, sql.NewWindowDefinition( 4343 // []sql.Expression{ 4344 // expression.NewUnresolvedColumn("y"), 4345 // }, 4346 // nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "w1", "")), 4347 // ), 4348 // expression.NewAlias("max(b) over (w2)", 4349 // expression.NewUnresolvedFunction("max", true, sql.NewWindowDefinition([]sql.Expression{}, nil, plan.NewRowsUnboundedPrecedingToUnboundedFollowingFrame(), "w2", ""), 4350 // expression.NewUnresolvedColumn("b"), 4351 // ), 4352 // ), 4353 // }, 4354 // plan.NewUnresolvedTable("foo", ""), 4355 // ), 4356 // ), 4357 // }, 4358 // { 4359 // input: `with cte1 as (select a from b) select * from cte1`, 4360 // plan: plan.NewWith( 4361 // plan.NewProject( 4362 // []sql.Expression{ 4363 // expression.NewStar(), 4364 // }, 4365 // plan.NewUnresolvedTable("cte1", "")), 4366 // []*plan.CommonTableExpression{ 4367 // plan.NewCommonTableExpression( 4368 // plan.NewSubqueryAlias("cte1", "select a from b", 4369 // plan.NewProject( 4370 // []sql.Expression{ 4371 // expression.NewUnresolvedColumn("a"), 4372 // }, 4373 // plan.NewUnresolvedTable("b", ""), 4374 // ), 4375 // ), 4376 // []string{}, 4377 // ), 4378 // }, 4379 // false, 4380 // ), 4381 // }, 4382 // { 4383 // input: `with cte1 as (select a from b) update c set d = e where f in (select * from cte1)`, 4384 // plan: plan.NewWith( 4385 // plan.NewUpdate( 4386 // plan.NewFilter( 4387 // plan.NewInSubquery( 4388 // expression.NewUnresolvedColumn("f"), 4389 // plan.NewSubquery(plan.NewProject( 4390 // []sql.Expression{expression.NewStar()}, 4391 // plan.NewUnresolvedTable("cte1", ""), 4392 // ), "select * from cte1"), 4393 // ), 4394 // plan.NewUnresolvedTable("c", ""), 4395 // ), 4396 // false, 4397 // []sql.Expression{ 4398 // expression.NewSetField(expression.NewUnresolvedColumn("d"), expression.NewUnresolvedColumn("e")), 4399 // }, 4400 // ), 4401 // []*plan.CommonTableExpression{ 4402 // plan.NewCommonTableExpression( 4403 // plan.NewSubqueryAlias("cte1", "select a from b", 4404 // plan.NewProject( 4405 // []sql.Expression{ 4406 // expression.NewUnresolvedColumn("a"), 4407 // }, 4408 // plan.NewUnresolvedTable("b", ""), 4409 // ), 4410 // ), 4411 // []string{}, 4412 // ), 4413 // }, 4414 // false, 4415 // ), 4416 // }, 4417 // { 4418 // input: `with cte1 as (select a from b) delete from c where d in (select * from cte1)`, 4419 // plan: plan.NewWith( 4420 // plan.NewDeleteFrom( 4421 // plan.NewFilter( 4422 // plan.NewInSubquery( 4423 // expression.NewUnresolvedColumn("d"), 4424 // plan.NewSubquery(plan.NewProject( 4425 // []sql.Expression{expression.NewStar()}, 4426 // plan.NewUnresolvedTable("cte1", ""), 4427 // ), "select * from cte1"), 4428 // ), 4429 // plan.NewUnresolvedTable("c", ""), 4430 // ), nil), 4431 // []*plan.CommonTableExpression{ 4432 // plan.NewCommonTableExpression( 4433 // plan.NewSubqueryAlias("cte1", "select a from b", 4434 // plan.NewProject( 4435 // []sql.Expression{ 4436 // expression.NewUnresolvedColumn("a"), 4437 // }, 4438 // plan.NewUnresolvedTable("b", ""), 4439 // ), 4440 // ), 4441 // []string{}, 4442 // ), 4443 // }, 4444 // false, 4445 // ), 4446 // }, 4447 // { 4448 // input: `with cte1 as (select a from b) insert into c (select * from cte1)`, 4449 // plan: plan.NewWith( 4450 // plan.NewInsertInto( 4451 // sql.UnresolvedDatabase(""), 4452 // plan.NewUnresolvedTable("c", ""), 4453 // plan.NewProject( 4454 // []sql.Expression{expression.NewStar()}, 4455 // plan.NewUnresolvedTable("cte1", ""), 4456 // ), 4457 // false, []string{}, []sql.Expression{}, false, 4458 // ), 4459 // []*plan.CommonTableExpression{ 4460 // plan.NewCommonTableExpression( 4461 // plan.NewSubqueryAlias("cte1", "select a from b", 4462 // plan.NewProject( 4463 // []sql.Expression{ 4464 // expression.NewUnresolvedColumn("a"), 4465 // }, 4466 // plan.NewUnresolvedTable("b", ""), 4467 // ), 4468 // ), 4469 // []string{}, 4470 // ), 4471 // }, 4472 // false, 4473 // ), 4474 // }, 4475 // { 4476 // input: `with recursive cte1 as (select 1 union select n+1 from cte1 where n < 10) select * from cte1`, 4477 // plan: plan.NewWith( 4478 // plan.NewProject( 4479 // []sql.Expression{ 4480 // expression.NewStar(), 4481 // }, 4482 // plan.NewUnresolvedTable("cte1", "")), 4483 // []*plan.CommonTableExpression{ 4484 // plan.NewCommonTableExpression( 4485 // plan.NewSubqueryAlias("cte1", "select 1 union select n + 1 from cte1 where n < 10", 4486 // plan.NewUnion(plan.NewProject( 4487 // []sql.Expression{ 4488 // expression.NewLiteral(int8(1), types.Int8), 4489 // }, 4490 // plan.NewResolvedDualTable(), 4491 // ), plan.NewProject( 4492 // []sql.Expression{ 4493 // expression.NewArithmetic( 4494 // expression.NewUnresolvedColumn("n"), 4495 // expression.NewLiteral(int8(1), types.Int8), 4496 // sqlparser.PlusStr, 4497 // ), 4498 // }, 4499 // plan.NewFilter( 4500 // expression.NewLessThan( 4501 // expression.NewUnresolvedColumn("n"), 4502 // expression.NewLiteral(int8(10), types.Int8), 4503 // ), 4504 // plan.NewUnresolvedTable("cte1", ""), 4505 // ), 4506 // ), true, nil, nil, nil), 4507 // ), 4508 // []string{}, 4509 // ), 4510 // }, 4511 // true, 4512 // ), 4513 // }, 4514 // { 4515 // input: `with cte1 as (select a from b), cte2 as (select c from d) select * from cte1`, 4516 // plan: plan.NewWith( 4517 // plan.NewProject( 4518 // []sql.Expression{ 4519 // expression.NewStar(), 4520 // }, 4521 // plan.NewUnresolvedTable("cte1", "")), 4522 // []*plan.CommonTableExpression{ 4523 // plan.NewCommonTableExpression( 4524 // plan.NewSubqueryAlias("cte1", "select a from b", 4525 // plan.NewProject( 4526 // []sql.Expression{ 4527 // expression.NewUnresolvedColumn("a"), 4528 // }, 4529 // plan.NewUnresolvedTable("b", ""), 4530 // ), 4531 // ), 4532 // []string{}, 4533 // ), 4534 // plan.NewCommonTableExpression( 4535 // plan.NewSubqueryAlias("cte2", "select c from d", 4536 // plan.NewProject( 4537 // []sql.Expression{ 4538 // expression.NewUnresolvedColumn("c"), 4539 // }, 4540 // plan.NewUnresolvedTable("d", ""), 4541 // ), 4542 // ), 4543 // []string{}, 4544 // ), 4545 // }, 4546 // false, 4547 // ), 4548 // }, 4549 // { 4550 // input: `with cte1 (x) as (select a from b), cte2 (y,z) as (select c from d) select * from cte1`, 4551 // plan: plan.NewWith( 4552 // plan.NewProject( 4553 // []sql.Expression{ 4554 // expression.NewStar(), 4555 // }, 4556 // plan.NewUnresolvedTable("cte1", "")), 4557 // []*plan.CommonTableExpression{ 4558 // plan.NewCommonTableExpression( 4559 // plan.NewSubqueryAlias("cte1", "select a from b", 4560 // plan.NewProject( 4561 // []sql.Expression{ 4562 // expression.NewUnresolvedColumn("a"), 4563 // }, 4564 // plan.NewUnresolvedTable("b", ""), 4565 // ), 4566 // ), 4567 // []string{"x"}, 4568 // ), 4569 // plan.NewCommonTableExpression( 4570 // plan.NewSubqueryAlias("cte2", "select c from d", 4571 // plan.NewProject( 4572 // []sql.Expression{ 4573 // expression.NewUnresolvedColumn("c"), 4574 // }, 4575 // plan.NewUnresolvedTable("d", ""), 4576 // ), 4577 // ), 4578 // []string{"y", "z"}, 4579 // ), 4580 // }, 4581 // false, 4582 // ), 4583 // }, 4584 // { 4585 // input: `with cte1 as (select a from b) select c, (with cte2 as (select c from d) select e from cte2) from cte1`, 4586 // plan: plan.NewWith( 4587 // plan.NewProject( 4588 // []sql.Expression{ 4589 // expression.NewUnresolvedColumn("c"), 4590 // expression.NewAlias("(with cte2 as (select c from d) select e from cte2)", 4591 // plan.NewSubquery( 4592 // plan.NewWith( 4593 // plan.NewProject( 4594 // []sql.Expression{ 4595 // expression.NewUnresolvedColumn("e"), 4596 // }, 4597 // plan.NewUnresolvedTable("cte2", "")), 4598 // []*plan.CommonTableExpression{ 4599 // plan.NewCommonTableExpression( 4600 // plan.NewSubqueryAlias("cte2", "select c from d", 4601 // plan.NewProject( 4602 // []sql.Expression{ 4603 // expression.NewUnresolvedColumn("c"), 4604 // }, 4605 // plan.NewUnresolvedTable("d", ""), 4606 // ), 4607 // ), 4608 // []string{}, 4609 // ), 4610 // }, 4611 // false, 4612 // ), 4613 // "with cte2 as (select c from d) select e from cte2", 4614 // ), 4615 // ), 4616 // }, 4617 // plan.NewUnresolvedTable("cte1", ""), 4618 // ), 4619 // []*plan.CommonTableExpression{ 4620 // plan.NewCommonTableExpression( 4621 // plan.NewSubqueryAlias("cte1", "select a from b", 4622 // plan.NewProject( 4623 // []sql.Expression{ 4624 // expression.NewUnresolvedColumn("a"), 4625 // }, 4626 // plan.NewUnresolvedTable("b", ""), 4627 // ), 4628 // ), 4629 // []string{}, 4630 // ), 4631 // }, 4632 // false, 4633 // ), 4634 // }, 4635 // { 4636 // input: `SELECT -128, 127, 255, -32768, 32767, 65535, -2147483648, 2147483647, 4294967295, -9223372036854775808, 9223372036854775807, 18446744073709551615`, 4637 // plan: plan.NewProject( 4638 // []sql.Expression{ 4639 // expression.NewLiteral(int8(math.MinInt8), types.Int8), 4640 // expression.NewLiteral(int8(math.MaxInt8), types.Int8), 4641 // expression.NewLiteral(uint8(math.MaxUint8), types.Uint8), 4642 // expression.NewLiteral(int16(math.MinInt16), types.Int16), 4643 // expression.NewLiteral(int16(math.MaxInt16), types.Int16), 4644 // expression.NewLiteral(uint16(math.MaxUint16), types.Uint16), 4645 // expression.NewLiteral(int32(math.MinInt32), types.Int32), 4646 // expression.NewLiteral(int32(math.MaxInt32), types.Int32), 4647 // expression.NewLiteral(uint32(math.MaxUint32), types.Uint32), 4648 // expression.NewLiteral(int64(math.MinInt64), types.Int64), 4649 // expression.NewLiteral(int64(math.MaxInt64), types.Int64), 4650 // expression.NewLiteral(uint64(math.MaxUint64), types.Uint64), 4651 // }, 4652 // plan.NewResolvedDualTable(), 4653 // ), 4654 // }, 4655 // { 4656 // input: `CREATE VIEW v AS SELECT * FROM foo`, 4657 // plan: plan.NewCreateView( 4658 // sql.UnresolvedDatabase(""), 4659 // "v", 4660 // []string{}, 4661 // plan.NewSubqueryAlias( 4662 // "v", "SELECT * FROM foo", 4663 // plan.NewProject( 4664 // []sql.Expression{expression.NewStar()}, 4665 // plan.NewUnresolvedTable("foo", ""), 4666 // ), 4667 // ), 4668 // false, 4669 // "CREATE VIEW v AS SELECT * FROM foo", "", "``@``", "", 4670 // ), 4671 // }, 4672 // { 4673 // input: `CREATE VIEW myview AS SELECT AVG(DISTINCT foo) FROM b`, 4674 // plan: plan.NewCreateView( 4675 // sql.UnresolvedDatabase(""), 4676 // "myview", 4677 // []string{}, 4678 // plan.NewSubqueryAlias( 4679 // "myview", "SELECT AVG(DISTINCT foo) FROM b", 4680 // plan.NewGroupBy( 4681 // []sql.Expression{ 4682 // expression.NewUnresolvedFunction("avg", true, nil, expression.NewDistinctExpression(expression.NewUnresolvedColumn("foo"))), 4683 // }, 4684 // []sql.Expression{}, 4685 // plan.NewUnresolvedTable("b", ""), 4686 // ), 4687 // ), 4688 // false, 4689 // "CREATE VIEW myview AS SELECT AVG(DISTINCT foo) FROM b", "", "``@``", "", 4690 // ), 4691 // }, 4692 // { 4693 // input: `CREATE OR REPLACE VIEW v AS SELECT * FROM foo`, 4694 // plan: plan.NewCreateView( 4695 // sql.UnresolvedDatabase(""), 4696 // "v", 4697 // []string{}, 4698 // plan.NewSubqueryAlias( 4699 // "v", "SELECT * FROM foo", 4700 // plan.NewProject( 4701 // []sql.Expression{expression.NewStar()}, 4702 // plan.NewUnresolvedTable("foo", ""), 4703 // ), 4704 // ), 4705 // true, 4706 // "CREATE OR REPLACE VIEW v AS SELECT * FROM foo", "", "``@``", "", 4707 // ), 4708 // }, 4709 // { 4710 // input: `SELECT 2 UNION SELECT 3`, 4711 // plan: plan.NewUnion(plan.NewProject( 4712 // []sql.Expression{expression.NewLiteral(int8(2), types.Int8)}, 4713 // plan.NewResolvedDualTable(), 4714 // ), plan.NewProject( 4715 // []sql.Expression{expression.NewLiteral(int8(3), types.Int8)}, 4716 // plan.NewResolvedDualTable(), 4717 // ), true, nil, nil, nil), 4718 // }, 4719 // { 4720 // input: `(SELECT 2) UNION (SELECT 3)`, 4721 // plan: plan.NewUnion(plan.NewProject( 4722 // []sql.Expression{expression.NewLiteral(int8(2), types.Int8)}, 4723 // plan.NewResolvedDualTable(), 4724 // ), plan.NewProject( 4725 // []sql.Expression{expression.NewLiteral(int8(3), types.Int8)}, 4726 // plan.NewResolvedDualTable(), 4727 // ), true, nil, nil, nil), 4728 // }, 4729 // { 4730 // input: `SELECT 2 UNION ALL SELECT 3 UNION DISTINCT SELECT 4`, 4731 // plan: plan.NewUnion(plan.NewUnion(plan.NewProject( 4732 // []sql.Expression{expression.NewLiteral(int8(2), types.Int8)}, 4733 // plan.NewResolvedDualTable(), 4734 // ), plan.NewProject( 4735 // []sql.Expression{expression.NewLiteral(int8(3), types.Int8)}, 4736 // plan.NewResolvedDualTable(), 4737 // ), false, nil, nil, nil), 4738 // plan.NewProject( 4739 // []sql.Expression{expression.NewLiteral(int8(4), types.Int8)}, 4740 // plan.NewResolvedDualTable(), 4741 // ), true, nil, nil, nil), 4742 // }, 4743 // { 4744 // input: `SELECT 2 UNION SELECT 3 UNION ALL SELECT 4`, 4745 // plan: plan.NewUnion( 4746 // plan.NewUnion(plan.NewProject( 4747 // []sql.Expression{expression.NewLiteral(int8(2), types.Int8)}, 4748 // plan.NewResolvedDualTable(), 4749 // ), plan.NewProject( 4750 // []sql.Expression{expression.NewLiteral(int8(3), types.Int8)}, 4751 // plan.NewResolvedDualTable(), 4752 // ), true, nil, nil, nil), 4753 // plan.NewProject( 4754 // []sql.Expression{expression.NewLiteral(int8(4), types.Int8)}, 4755 // plan.NewResolvedDualTable(), 4756 // ), false, nil, nil, nil), 4757 // }, 4758 // { 4759 // input: `SELECT 2 UNION SELECT 3 UNION SELECT 4`, 4760 // plan: plan.NewUnion( 4761 // plan.NewUnion(plan.NewProject( 4762 // []sql.Expression{expression.NewLiteral(int8(2), types.Int8)}, 4763 // plan.NewResolvedDualTable(), 4764 // ), plan.NewProject( 4765 // []sql.Expression{expression.NewLiteral(int8(3), types.Int8)}, 4766 // plan.NewResolvedDualTable(), 4767 // ), true, nil, nil, nil), 4768 // plan.NewProject( 4769 // []sql.Expression{expression.NewLiteral(int8(4), types.Int8)}, 4770 // plan.NewResolvedDualTable(), 4771 // ), true, nil, nil, nil), 4772 // }, 4773 // { 4774 // input: `SELECT 2 UNION (SELECT 3 UNION SELECT 4)`, 4775 // plan: plan.NewUnion( 4776 // plan.NewProject( 4777 // []sql.Expression{expression.NewLiteral(int8(2), types.Int8)}, 4778 // plan.NewResolvedDualTable(), 4779 // ), 4780 // plan.NewUnion(plan.NewProject( 4781 // []sql.Expression{expression.NewLiteral(int8(3), types.Int8)}, 4782 // plan.NewResolvedDualTable(), 4783 // ), plan.NewProject( 4784 // []sql.Expression{expression.NewLiteral(int8(4), types.Int8)}, 4785 // plan.NewResolvedDualTable(), 4786 // ), true, nil, nil, nil), 4787 // true, nil, nil, nil, 4788 // ), 4789 // }, 4790 // { 4791 // input: `SELECT 2 UNION ALL SELECT 3`, 4792 // plan: plan.NewUnion(plan.NewProject( 4793 // []sql.Expression{expression.NewLiteral(int8(2), types.Int8)}, 4794 // plan.NewResolvedDualTable(), 4795 // ), plan.NewProject( 4796 // []sql.Expression{expression.NewLiteral(int8(3), types.Int8)}, 4797 // plan.NewResolvedDualTable(), 4798 // ), false, nil, nil, nil), 4799 // }, 4800 // { 4801 // input: `SELECT 2 UNION DISTINCT SELECT 3`, 4802 // plan: plan.NewUnion(plan.NewProject( 4803 // []sql.Expression{expression.NewLiteral(int8(2), types.Int8)}, 4804 // plan.NewResolvedDualTable(), 4805 // ), plan.NewProject( 4806 // []sql.Expression{expression.NewLiteral(int8(3), types.Int8)}, 4807 // plan.NewResolvedDualTable(), 4808 // ), true, nil, nil, nil), 4809 // }, 4810 // { 4811 // input: `SELECT 2 UNION SELECT 3 UNION SELECT 4 LIMIT 10`, 4812 // plan: plan.NewUnion( 4813 // plan.NewUnion(plan.NewProject( 4814 // []sql.Expression{expression.NewLiteral(int8(2), types.Int8)}, 4815 // plan.NewResolvedDualTable(), 4816 // ), plan.NewProject( 4817 // []sql.Expression{expression.NewLiteral(int8(3), types.Int8)}, 4818 // plan.NewResolvedDualTable(), 4819 // ), true, nil, nil, nil), 4820 // plan.NewProject( 4821 // []sql.Expression{expression.NewLiteral(int8(4), types.Int8)}, 4822 // plan.NewResolvedDualTable(), 4823 // ), true, expression.NewLiteral(int8(10), types.Int8), nil, nil), 4824 // }, 4825 // { 4826 // input: `SELECT 2 UNION SELECT 3 UNION SELECT 4 ORDER BY 2`, 4827 // plan: plan.NewUnion( 4828 // plan.NewUnion(plan.NewProject( 4829 // []sql.Expression{expression.NewLiteral(int8(2), types.Int8)}, 4830 // plan.NewResolvedDualTable(), 4831 // ), plan.NewProject( 4832 // []sql.Expression{expression.NewLiteral(int8(3), types.Int8)}, 4833 // plan.NewResolvedDualTable(), 4834 // ), true, nil, nil, nil), 4835 // plan.NewProject( 4836 // []sql.Expression{expression.NewLiteral(int8(4), types.Int8)}, 4837 // plan.NewResolvedDualTable(), 4838 // ), true, nil, nil, []sql.SortField{ 4839 // { 4840 // Column: expression.NewLiteral(int8(2), types.Int8), 4841 // Column2: expression.NewLiteral(int8(2), types.Int8), 4842 // Order: sql.Ascending, 4843 // NullOrdering: sql.NullsFirst, 4844 // }, 4845 // }), 4846 // }, 4847 // { 4848 // input: `CREATE DATABASE test`, 4849 // plan: plan.NewCreateDatabase("test", false, sql.Collation_Unspecified), 4850 // }, 4851 // { 4852 // input: `CREATE DATABASE IF NOT EXISTS test`, 4853 // plan: plan.NewCreateDatabase("test", true, sql.Collation_Unspecified), 4854 // }, 4855 // { 4856 // input: `DROP DATABASE test`, 4857 // plan: plan.NewDropDatabase("test", false), 4858 // }, 4859 // { 4860 // input: `DROP DATABASE IF EXISTS test`, 4861 // plan: plan.NewDropDatabase("test", true), 4862 // }, 4863 // { 4864 // input: `KILL QUERY 1`, 4865 // plan: plan.NewKill(plan.KillType_Query, 1), 4866 // }, 4867 // { 4868 // input: `KILL CONNECTION 1`, 4869 // plan: plan.NewKill(plan.KillType_Connection, 1), 4870 // }, 4871 // { 4872 // input: `CREATE PROCEDURE p1(INOUT a INT, IN b SMALLINT) 4873 //BEGIN 4874 // DECLARE c BIGINT; 4875 // DECLARE cur1 CURSOR FOR SELECT 1; 4876 // OPEN cur1; 4877 // FETCH cur1 INTO c; 4878 // CLOSE cur1; 4879 //END;`, 4880 // plan: plan.NewCreateProcedure( 4881 // sql.UnresolvedDatabase(""), 4882 // "p1", 4883 // "", 4884 // []plan.ProcedureParam{ 4885 // { 4886 // Direction: plan.ProcedureParamDirection_Inout, 4887 // Name: "a", 4888 // Type: types.Int32, 4889 // Variadic: false, 4890 // }, 4891 // { 4892 // Direction: plan.ProcedureParamDirection_In, 4893 // Name: "b", 4894 // Type: types.Int16, 4895 // Variadic: false, 4896 // }, 4897 // }, 4898 // time.Now(), 4899 // time.Now(), 4900 // plan.ProcedureSecurityContext_Definer, 4901 // nil, 4902 // plan.NewBeginEndBlock( 4903 // "", 4904 // plan.NewBlock([]sql.Node{ 4905 // plan.NewDeclareVariables([]string{"c"}, types.Int64, nil), 4906 // plan.NewDeclareCursor("cur1", plan.NewProject( 4907 // []sql.Expression{expression.NewLiteral(int8(1), types.Int8)}, 4908 // plan.NewResolvedDualTable(), 4909 // )), 4910 // plan.NewOpen("cur1"), 4911 // plan.NewFetch("cur1", []sql.Expression{expression.NewUnresolvedColumn("c")}), 4912 // plan.NewClose("cur1"), 4913 // }), 4914 // ), 4915 // "", 4916 // `CREATE PROCEDURE p1(INOUT a INT, IN b SMALLINT) 4917 //BEGIN 4918 // DECLARE c BIGINT; 4919 // DECLARE cur1 CURSOR FOR SELECT 1; 4920 // OPEN cur1; 4921 // FETCH cur1 INTO c; 4922 // CLOSE cur1; 4923 //END`, 4924 // `BEGIN 4925 // DECLARE c BIGINT; 4926 // DECLARE cur1 CURSOR FOR SELECT 1; 4927 // OPEN cur1; 4928 // FETCH cur1 INTO c; 4929 // CLOSE cur1; 4930 //END`, 4931 // ), 4932 // }, 4933 // { 4934 // input: "CREATE DEFINER = `user1`@`localhost` EVENT IF NOT EXISTS mydb.event1 ON SCHEDULE AT CURRENT_TIMESTAMP COMMENT 'my event' DO SELECT 1", 4935 // plan: plan.NewCreateEvent( 4936 // sql.UnresolvedDatabase("mydb"), 4937 // "event1", 4938 // "`user1`@`localhost`", 4939 // plan.NewOnScheduleTimestamp( 4940 // expression.NewUnresolvedFunction("current_timestamp", false, nil), 4941 // nil, 4942 // ), 4943 // nil, 4944 // nil, 4945 // nil, 4946 // false, 4947 // plan.EventStatus_Enable, 4948 // "my event", 4949 // "SELECT 1", 4950 // plan.NewProject([]sql.Expression{expression.NewLiteral(int8(1), types.Int8)}, plan.NewResolvedDualTable()), 4951 // true, 4952 // ), 4953 // }, 4954 // { 4955 // input: "CREATE DEFINER = `user1`@`localhost` EVENT IF NOT EXISTS mydb.event1 ON SCHEDULE AT '2037-10-16 23:59:00' + INTERVAL '2:3' HOUR_MINUTE ON COMPLETION NOT PRESERVE ENABLE DO SELECT 1", 4956 // plan: plan.NewCreateEvent( 4957 // sql.UnresolvedDatabase("mydb"), 4958 // "event1", 4959 // "`user1`@`localhost`", 4960 // plan.NewOnScheduleTimestamp( 4961 // expression.NewLiteral("2037-10-16 23:59:00", types.LongText), 4962 // []sql.Expression{expression.NewInterval(expression.NewLiteral("2:3", types.LongText), "HOUR_MINUTE")}, 4963 // ), 4964 // nil, 4965 // nil, 4966 // nil, 4967 // false, 4968 // plan.EventStatus_Enable, 4969 // "", 4970 // "SELECT 1", 4971 // plan.NewProject([]sql.Expression{expression.NewLiteral(int8(1), types.Int8)}, plan.NewResolvedDualTable()), 4972 // true, 4973 // ), 4974 // }, 4975 // { 4976 // input: "CREATE DEFINER = `user1`@`localhost` EVENT IF NOT EXISTS mydb.event1 ON SCHEDULE EVERY 1 HOUR ON COMPLETION PRESERVE DISABLE DO SELECT 1", 4977 // plan: plan.NewCreateEvent( 4978 // sql.UnresolvedDatabase("mydb"), 4979 // "event1", 4980 // "`user1`@`localhost`", 4981 // nil, 4982 // nil, 4983 // nil, 4984 // expression.NewInterval(expression.NewLiteral(int8(1), types.Int8), "HOUR"), 4985 // true, 4986 // plan.EventStatus_Disable, 4987 // "", 4988 // "SELECT 1", 4989 // plan.NewProject([]sql.Expression{expression.NewLiteral(int8(1), types.Int8)}, plan.NewResolvedDualTable()), 4990 // true, 4991 // ), 4992 // }, 4993 // { 4994 // input: "CREATE EVENT mydb.event1 ON SCHEDULE EVERY 1 HOUR STARTS CURRENT_TIMESTAMP + INTERVAL 30 MINUTE ENDS '2037-10-16 23:59:00' ON COMPLETION PRESERVE DISABLE DO SELECT 1", 4995 // plan: plan.NewCreateEvent( 4996 // sql.UnresolvedDatabase("mydb"), 4997 // "event1", 4998 // "``@``", 4999 // nil, 5000 // plan.NewOnScheduleTimestamp( 5001 // expression.NewUnresolvedFunction("current_timestamp", false, nil), 5002 // []sql.Expression{expression.NewInterval(expression.NewLiteral(int8(30), types.Int8), "MINUTE")}, 5003 // ), 5004 // plan.NewOnScheduleTimestamp( 5005 // expression.NewLiteral("2037-10-16 23:59:00", types.LongText), 5006 // nil, 5007 // ), 5008 // expression.NewInterval(expression.NewLiteral(int8(1), types.Int8), "HOUR"), 5009 // true, 5010 // plan.EventStatus_Disable, 5011 // "", 5012 // "SELECT 1", 5013 // plan.NewProject([]sql.Expression{expression.NewLiteral(int8(1), types.Int8)}, plan.NewResolvedDualTable()), 5014 // false, 5015 // ), 5016 // }, 5017 // { 5018 // input: "INSERT INTO instance(id, setup_complete)\n VALUES (CONVERT(UUID() USING utf8mb4), FALSE)", 5019 // plan: plan.NewInsertInto( 5020 // sql.UnresolvedDatabase(""), 5021 // plan.NewUnresolvedTable("instance", ""), 5022 // plan.NewValues([][]sql.Expression{ 5023 // { 5024 // expression.NewCollatedExpression( 5025 // expression.NewUnresolvedFunction("uuid", false, nil), 5026 // sql.CharacterSet_utf8mb4.DefaultCollation()), 5027 // expression.NewLiteral(false, types.Boolean), 5028 // }, 5029 // }), 5030 // false, 5031 // []string{"id", "setup_complete"}, 5032 // []sql.Expression{}, 5033 // false, 5034 // ), 5035 // }, 5036 // } 5037 5038 // TODO use planbuilder 5039 //for _, tt := range fixtures { 5040 // t.Run(tt.input, func(t *testing.T) { 5041 // require := require.New(t) 5042 // ctx := sql.NewEmptyContext() 5043 // p, err := Parse(ctx, tt.input) 5044 // require.NoError(err) 5045 // if createTable, ok := p.(*plan.CreateTable); ok { 5046 // for _, col := range createTable.CreateSchema.Schema { 5047 // if collatedType, ok := col.Type.(sql.TypeWithCollation); ok { 5048 // col.Type, err = collatedType.WithNewCollation(sql.Collation_Default) 5049 // require.NoError(err) 5050 // } 5051 // } 5052 // } else if createProcedure, ok := p.(*plan.CreateProcedure); ok { 5053 // createProcedure.CreatedAt = tt.plan.(*plan.CreateProcedure).CreatedAt 5054 // createProcedure.ModifiedAt = tt.plan.(*plan.CreateProcedure).ModifiedAt 5055 // } 5056 // if !assertNodesEqualWithDiff(t, tt.plan, p) { 5057 // t.Logf("Unexpected result for query %s", tt.input) 5058 // } 5059 // }) 5060 //} 5061 } 5062 5063 func TestParseCreateTrigger(t *testing.T) { 5064 var triggerFixtures = map[string]sql.Node{ 5065 `CREATE TRIGGER myTrigger BEFORE UPDATE ON foo FOR EACH ROW 5066 BEGIN 5067 UPDATE bar SET x = old.y WHERE z = new.y; 5068 DELETE FROM baz WHERE a = old.b; 5069 INSERT INTO zzz (a,b) VALUES (old.a, old.b); 5070 END`: plan.NewCreateTrigger(sql.UnresolvedDatabase(""), "myTrigger", "before", "update", nil, 5071 plan.NewUnresolvedTable("foo", ""), 5072 plan.NewBeginEndBlock( 5073 "", 5074 plan.NewBlock([]sql.Node{ 5075 plan.NewUpdate(plan.NewFilter( 5076 expression.NewEquals(expression.NewUnresolvedColumn("z"), expression.NewUnresolvedQualifiedColumn("new", "y")), 5077 plan.NewUnresolvedTable("bar", ""), 5078 ), false, []sql.Expression{ 5079 expression.NewSetField(expression.NewUnresolvedColumn("x"), expression.NewUnresolvedQualifiedColumn("old", "y")), 5080 }), 5081 plan.NewDeleteFrom( 5082 plan.NewFilter( 5083 expression.NewEquals(expression.NewUnresolvedColumn("a"), expression.NewUnresolvedQualifiedColumn("old", "b")), 5084 plan.NewUnresolvedTable("baz", ""), 5085 ), nil), 5086 plan.NewInsertInto(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("zzz", ""), plan.NewValues([][]sql.Expression{{ 5087 expression.NewUnresolvedQualifiedColumn("old", "a"), 5088 expression.NewUnresolvedQualifiedColumn("old", "b"), 5089 }}, 5090 ), false, []string{"a", "b"}, []sql.Expression{}, false), 5091 }), 5092 ), 5093 `CREATE TRIGGER myTrigger BEFORE UPDATE ON foo FOR EACH ROW 5094 BEGIN 5095 UPDATE bar SET x = old.y WHERE z = new.y; 5096 DELETE FROM baz WHERE a = old.b; 5097 INSERT INTO zzz (a,b) VALUES (old.a, old.b); 5098 END`, 5099 `BEGIN 5100 UPDATE bar SET x = old.y WHERE z = new.y; 5101 DELETE FROM baz WHERE a = old.b; 5102 INSERT INTO zzz (a,b) VALUES (old.a, old.b); 5103 END`, 5104 time.Unix(0, 0), 5105 "``@``", 5106 ), 5107 `CREATE TRIGGER myTrigger BEFORE UPDATE ON foo FOR EACH ROW INSERT INTO zzz (a,b) VALUES (old.a, old.b)`: plan.NewCreateTrigger(sql.UnresolvedDatabase(""), 5108 "myTrigger", "before", "update", nil, 5109 plan.NewUnresolvedTable("foo", ""), 5110 plan.NewInsertInto(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("zzz", ""), plan.NewValues([][]sql.Expression{{ 5111 expression.NewUnresolvedQualifiedColumn("old", "a"), 5112 expression.NewUnresolvedQualifiedColumn("old", "b"), 5113 }}, 5114 ), false, []string{"a", "b"}, []sql.Expression{}, false), 5115 `CREATE TRIGGER myTrigger BEFORE UPDATE ON foo FOR EACH ROW INSERT INTO zzz (a,b) VALUES (old.a, old.b)`, 5116 `INSERT INTO zzz (a,b) VALUES (old.a, old.b)`, 5117 time.Unix(0, 0), 5118 "``@``", 5119 ), 5120 `CREATE TRIGGER myTrigger BEFORE UPDATE ON foo FOR EACH ROW FOLLOWS yourTrigger INSERT INTO zzz (a,b) VALUES (old.a, old.b)`: plan.NewCreateTrigger(sql.UnresolvedDatabase(""), 5121 "myTrigger", "before", "update", 5122 &plan.TriggerOrder{PrecedesOrFollows: sqlparser.FollowsStr, OtherTriggerName: "yourTrigger"}, 5123 plan.NewUnresolvedTable("foo", ""), 5124 plan.NewInsertInto(sql.UnresolvedDatabase(""), plan.NewUnresolvedTable("zzz", ""), plan.NewValues([][]sql.Expression{{ 5125 expression.NewUnresolvedQualifiedColumn("old", "a"), 5126 expression.NewUnresolvedQualifiedColumn("old", "b"), 5127 }}, 5128 ), false, []string{"a", "b"}, []sql.Expression{}, false), 5129 `CREATE TRIGGER myTrigger BEFORE UPDATE ON foo FOR EACH ROW FOLLOWS yourTrigger INSERT INTO zzz (a,b) VALUES (old.a, old.b)`, 5130 `INSERT INTO zzz (a,b) VALUES (old.a, old.b)`, 5131 time.Unix(0, 0), 5132 "``@``", 5133 ), 5134 `create trigger signal_with_user_var 5135 BEFORE DELETE ON FOO FOR EACH ROW 5136 BEGIN 5137 SET @message_text = CONCAT('ouch', 'oof'); 5138 SIGNAL SQLSTATE '45000' 5139 SET MESSAGE_TEXT = @message_text; 5140 END`: plan.NewCreateTrigger(sql.UnresolvedDatabase(""), 5141 "signal_with_user_var", "before", "delete", 5142 nil, 5143 plan.NewUnresolvedTable("FOO", ""), 5144 plan.NewBeginEndBlock("", plan.NewBlock([]sql.Node{ 5145 plan.NewSet([]sql.Expression{ 5146 expression.NewSetField( 5147 expression.NewUserVar("message_text"), 5148 expression.NewUnresolvedFunction("concat", false, nil, expression.NewLiteral("ouch", types.LongText), expression.NewLiteral("oof", types.LongText)), 5149 ), 5150 }), 5151 plan.NewSignal("45000", map[plan.SignalConditionItemName]plan.SignalInfo{ 5152 plan.SignalConditionItemName_MessageText: { 5153 ConditionItemName: plan.SignalConditionItemName_MessageText, 5154 ExprVal: expression.NewUnresolvedColumn("@message_text"), 5155 }, 5156 }), 5157 }, 5158 )), 5159 `create trigger signal_with_user_var 5160 BEFORE DELETE ON FOO FOR EACH ROW 5161 BEGIN 5162 SET @message_text = CONCAT('ouch', 'oof'); 5163 SIGNAL SQLSTATE '45000' 5164 SET MESSAGE_TEXT = @message_text; 5165 END`, 5166 `BEGIN 5167 SET @message_text = CONCAT('ouch', 'oof'); 5168 SIGNAL SQLSTATE '45000' 5169 SET MESSAGE_TEXT = @message_text; 5170 END`, 5171 time.Unix(0, 0), 5172 "``@``"), 5173 } 5174 5175 var queriesInOrder []string 5176 for q := range triggerFixtures { 5177 queriesInOrder = append(queriesInOrder, q) 5178 } 5179 sort.Strings(queriesInOrder) 5180 5181 // TODO use planbuilder 5182 //date := time.Unix(0, 0) 5183 //for _, query := range queriesInOrder { 5184 // expectedPlan := triggerFixtures[query] 5185 // t.Run(query, func(t *testing.T) { 5186 // sql.RunWithNowFunc(func() time.Time { return date }, func() error { 5187 // require := require.New(t) 5188 // ctx := sql.NewEmptyContext() 5189 // p, err := Parse(ctx, query) 5190 // require.NoError(err) 5191 // if !assertNodesEqualWithDiff(t, expectedPlan, p) { 5192 // t.Logf("Unexpected result for query %s", query) 5193 // } 5194 // return nil 5195 // }) 5196 // }) 5197 //} 5198 } 5199 5200 // assertNodesEqualWithDiff asserts the two nodes given to be equal and prints any diff according to their DebugString 5201 // methods. 5202 func assertNodesEqualWithDiff(t *testing.T, expected, actual sql.Node) bool { 5203 if !assert.Equal(t, expected, actual) { 5204 expectedStr := sql.DebugString(expected) 5205 actualStr := sql.DebugString(actual) 5206 diff, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ 5207 A: difflib.SplitLines(expectedStr), 5208 B: difflib.SplitLines(actualStr), 5209 FromFile: "expected", 5210 FromDate: "", 5211 ToFile: "actual", 5212 ToDate: "", 5213 Context: 1, 5214 }) 5215 require.NoError(t, err) 5216 5217 if len(diff) > 0 { 5218 fmt.Println(diff) 5219 } else { 5220 // No textual diff found, but not equal. Ugh. Let's at least figure out which node in the plans isn't equal. 5221 Top: 5222 for { 5223 for i := range expected.Children() { 5224 if !assertNodesEqualWithDiff(t, expected.Children()[i], actual.Children()[i]) { 5225 expected, actual = expected.Children()[i], actual.Children()[i] 5226 continue Top 5227 } 5228 } 5229 // Either no children, or all children were equal. This must the node that's different. Probably should add 5230 // enough information in DebugPrint for this node that it shows up in the textual diff. 5231 fmt.Printf("Non-textual difference found in node %s -- implement a better DebugPrint?\n", sql.DebugString(expected)) 5232 break 5233 } 5234 } 5235 5236 return false 5237 } 5238 return true 5239 } 5240 5241 var fixturesErrors = map[string]*errors.Kind{ 5242 `SELECT INTERVAL 1 DAY - '2018-05-01'`: sql.ErrUnsupportedSyntax, 5243 `SELECT INTERVAL 1 DAY * '2018-05-01'`: sql.ErrUnsupportedSyntax, 5244 `SELECT '2018-05-01' * INTERVAL 1 DAY`: sql.ErrUnsupportedSyntax, 5245 `SELECT '2018-05-01' / INTERVAL 1 DAY`: sql.ErrUnsupportedSyntax, 5246 `SELECT INTERVAL 1 DAY + INTERVAL 1 DAY`: sql.ErrUnsupportedSyntax, 5247 `SELECT '2018-05-01' + (INTERVAL 1 DAY + INTERVAL 1 DAY)`: sql.ErrUnsupportedSyntax, 5248 "DESCRIBE FORMAT=pretty SELECT * FROM foo": errInvalidDescribeFormat, 5249 `CREATE TABLE test (pk int null primary key)`: ErrPrimaryKeyOnNullField, 5250 `CREATE TABLE test (pk int not null null primary key)`: ErrPrimaryKeyOnNullField, 5251 `CREATE TABLE test (pk int null, primary key(pk))`: ErrPrimaryKeyOnNullField, 5252 `CREATE TABLE test (pk int not null null, primary key(pk))`: ErrPrimaryKeyOnNullField, 5253 `SELECT i, row_number() over (order by a) group by 1`: sql.ErrUnsupportedFeature, 5254 `SHOW COUNT(*) WARNINGS`: sql.ErrUnsupportedFeature, 5255 `SHOW ERRORS`: sql.ErrUnsupportedFeature, 5256 `SHOW VARIABLES WHERE Value = ''`: sql.ErrUnsupportedFeature, 5257 `SHOW SESSION VARIABLES WHERE Value IS NOT NULL`: sql.ErrUnsupportedFeature, 5258 `KILL CONNECTION 4294967296`: sql.ErrUnsupportedFeature, 5259 `DROP TABLE IF EXISTS curdb.foo, otherdb.bar`: sql.ErrUnsupportedFeature, 5260 `DROP TABLE curdb.t1, t2`: sql.ErrUnsupportedFeature, 5261 } 5262 5263 // TODO use planbuilder 5264 //func TestParseOne(t *testing.T) { 5265 // type testCase struct { 5266 // input string 5267 // parts []string 5268 // } 5269 // 5270 // cases := []testCase{ 5271 // { 5272 // "SELECT 1", 5273 // []string{"SELECT 1"}, 5274 // }, 5275 // { 5276 // "SELECT 1;", 5277 // []string{"SELECT 1"}, 5278 // }, 5279 // { 5280 // "SELECT 1; SELECT 2", 5281 // []string{"SELECT 1", "SELECT 2"}, 5282 // }, 5283 // { 5284 // "SELECT 1 /* testing */ ;", 5285 // []string{"SELECT 1 /* testing */"}, 5286 // }, 5287 // { 5288 // "SELECT 1 -- this is a test", 5289 // []string{"SELECT 1 -- this is a test"}, 5290 // }, 5291 // { 5292 // "-- empty statement with comment\n; SELECT 1; SELECT 2", 5293 // []string{"-- empty statement with comment", "SELECT 1", "SELECT 2"}, 5294 // }, 5295 // { 5296 // "SELECT 1; -- empty statement with comment\n; SELECT 2", 5297 // []string{"SELECT 1", "-- empty statement with comment", "SELECT 2"}, 5298 // }, 5299 // { 5300 // "SELECT 1; SELECT 2; -- empty statement with comment\n", 5301 // []string{"SELECT 1", "SELECT 2", "-- empty statement with comment"}, 5302 // }, 5303 // } 5304 // for _, tc := range cases { 5305 // t.Run(tc.input, func(t *testing.T) { 5306 // ctx := sql.NewEmptyContext() 5307 // q := tc.input 5308 // for i := 0; i < len(tc.parts); i++ { 5309 // tree, p, r, err := ParseOne(ctx, q) 5310 // require.NoError(t, err) 5311 // require.NotNil(t, tree) 5312 // require.Equal(t, tc.parts[i], p) 5313 // if i == len(tc.parts)-1 { 5314 // require.Empty(t, r) 5315 // } 5316 // q = r 5317 // } 5318 // }) 5319 // } 5320 //} 5321 5322 func TestParseErrors(t *testing.T) { 5323 t.Skip("todo use planbuilder") 5324 for query, _ := range fixturesErrors { 5325 t.Run(query, func(t *testing.T) { 5326 //require := require.New(t) 5327 //ctx := sql.NewEmptyContext() 5328 //_, err := Parse(ctx, query) 5329 //require.Error(err) 5330 //require.True(expectedError.Is(err), "Expected %T but got %T (%v)", expectedError, err, err) 5331 }) 5332 } 5333 }