Documentation ¶
Index ¶
- Variables
- func MustParseTime(layout, value string) time.Time
- type CharsetCollationEngineTest
- type CharsetCollationEngineTestQuery
- type CharsetCollationWireTest
- type CharsetCollationWireTestQuery
- type CollationCoercionTest
- type GenericErrorQueryTest
- type NoopPlaintextPlugin
- type ParallelismTest
- type QueryErrorTest
- type QueryPlanTest
- type QueryTest
- type QuickPrivilegeTest
- type RegexTest
- type ScriptTest
- type ScriptTestAssertion
- type ServerAuthenticationTest
- type ServerAuthenticationTestAssertion
- type TransactionTest
- type TypeWireTest
- type UserPrivilegeTest
- type UserPrivilegeTestAssertion
- type WriteQueryTest
Constants ¶
This section is empty.
Variables ¶
var AlterTableAddAutoIncrementScripts = []ScriptTest{ { Name: "Add primary key column with auto increment", SetUpScript: []string{ "CREATE TABLE t1 (i int, j int);", "insert into t1 values (1,1), (2,2), (3,3)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 add column pk int primary key auto_increment;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `i` int,\n" + " `j` int,\n" + " `pk` int NOT NULL AUTO_INCREMENT,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select pk from t1 order by pk", Expected: []sql.Row{ {1}, {2}, {3}, }, }, }, }, { Name: "Add primary key column with auto increment, first", SetUpScript: []string{ "CREATE TABLE t1 (i int, j int);", "insert into t1 values (1,1), (2,2), (3,3)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 add column pk int primary key", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "alter table t1 add column pk int primary key auto_increment first", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `pk` int NOT NULL AUTO_INCREMENT,\n" + " `i` int,\n" + " `j` int,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select pk from t1 order by pk", Expected: []sql.Row{ {1}, {2}, {3}, }, }, }, }, { Name: "add column auto_increment, non primary key", SetUpScript: []string{ "CREATE TABLE t1 (i bigint primary key, s varchar(20))", "INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c')", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 add column j int auto_increment unique", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `i` bigint NOT NULL,\n" + " `s` varchar(20),\n" + " `j` int AUTO_INCREMENT,\n" + " PRIMARY KEY (`i`),\n" + " UNIQUE KEY `j` (`j`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select * from t1 order by i", Expected: []sql.Row{ {1, "a", 1}, {2, "b", 2}, {3, "c", 3}, }, }, }, }, { Name: "add column auto_increment, non key", SetUpScript: []string{ "CREATE TABLE t1 (i bigint primary key, s varchar(20))", "INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c')", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 add column j int auto_increment", ExpectedErr: sql.ErrInvalidAutoIncCols, }, }, }, }
var AlterTableScripts = []ScriptTest{ { Name: "Error queries", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE one_pk_two_idx MODIFY COLUMN v1 BIGINT DEFAULT (pk) AFTER v3", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE one_pk_two_idx ADD COLUMN v4 BIGINT DEFAULT (pk) AFTER v3", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE one_pk_two_idx ADD COLUMN v3 BIGINT DEFAULT 5, RENAME COLUMN v3 to v4", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE one_pk_two_idx ADD COLUMN v3 BIGINT DEFAULT 5, modify column v3 bigint default null", ExpectedErr: sql.ErrTableColumnNotFound, }, }, }, { Name: "alter table containing column default value expressions", SetUpScript: []string{ "create table t (pk int primary key, col1 timestamp(6) default current_timestamp(), col2 varchar(1000), index idx1 (pk, col1));", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t alter column col2 DROP DEFAULT;", Expected: []sql.Row{}, }, { Query: "show create table t;", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `pk` int NOT NULL,\n `col1` timestamp(6) DEFAULT (CURRENT_TIMESTAMP()),\n `col2` varchar(1000),\n PRIMARY KEY (`pk`),\n KEY `idx1` (`pk`,`col1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "alter table t alter column col2 SET DEFAULT 'FOO!';", Expected: []sql.Row{}, }, { Query: "show create table t;", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `pk` int NOT NULL,\n `col1` timestamp(6) DEFAULT (CURRENT_TIMESTAMP()),\n `col2` varchar(1000) DEFAULT 'FOO!',\n PRIMARY KEY (`pk`),\n KEY `idx1` (`pk`,`col1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "alter table t drop index idx1;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "drop column drops check constraint", SetUpScript: []string{ "create table t34 (i bigint primary key, s varchar(20))", "ALTER TABLE t34 ADD COLUMN j int", "ALTER TABLE t34 ADD CONSTRAINT test_check CHECK (j < 12345)", "ALTER TABLE t34 DROP COLUMN j", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t34", Expected: []sql.Row{{"t34", "CREATE TABLE `t34` (\n" + " `i` bigint NOT NULL,\n" + " `s` varchar(20),\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "drop column drops all relevant check constraints", SetUpScript: []string{ "create table t42 (i bigint primary key, s varchar(20))", "ALTER TABLE t42 ADD COLUMN j int", "ALTER TABLE t42 ADD CONSTRAINT check1 CHECK (j < 12345)", "ALTER TABLE t42 ADD CONSTRAINT check2 CHECK (j > 0)", "ALTER TABLE t42 DROP COLUMN j", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t42", Expected: []sql.Row{{"t42", "CREATE TABLE `t42` (\n" + " `i` bigint NOT NULL,\n" + " `s` varchar(20),\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "drop column drops correct check constraint", SetUpScript: []string{ "create table t41 (i bigint primary key, s varchar(20))", "ALTER TABLE t41 ADD COLUMN j int", "ALTER TABLE t41 ADD COLUMN k int", "ALTER TABLE t41 ADD CONSTRAINT j_check CHECK (j < 12345)", "ALTER TABLE t41 ADD CONSTRAINT k_check CHECK (k < 123)", "ALTER TABLE t41 DROP COLUMN j", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t41", Expected: []sql.Row{{"t41", "CREATE TABLE `t41` (\n" + " `i` bigint NOT NULL,\n" + " `s` varchar(20),\n" + " `k` int,\n" + " PRIMARY KEY (`i`),\n" + " CONSTRAINT `k_check` CHECK ((`k` < 123))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "drop column does not drop when referenced in constraint with other column", SetUpScript: []string{ "create table t43 (i bigint primary key, s varchar(20))", "ALTER TABLE t43 ADD COLUMN j int", "ALTER TABLE t43 ADD COLUMN k int", "ALTER TABLE t43 ADD CONSTRAINT test_check CHECK (j < k)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t43 drop column j", ExpectedErr: sql.ErrCheckConstraintInvalidatedByColumnAlter, }, { Query: "show create table t43", Expected: []sql.Row{{"t43", "CREATE TABLE `t43` (\n" + " `i` bigint NOT NULL,\n" + " `s` varchar(20),\n" + " `j` int,\n" + " `k` int,\n" + " PRIMARY KEY (`i`),\n" + " CONSTRAINT `test_check` CHECK ((`j` < `k`))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "drop column preserves indexes", SetUpScript: []string{ "create table t35 (i bigint primary key, s varchar(20), s2 varchar(20))", "ALTER TABLE t35 ADD unique key test_key (s)", "ALTER TABLE t35 DROP COLUMN s2", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t35", Expected: []sql.Row{{"t35", "CREATE TABLE `t35` (\n" + " `i` bigint NOT NULL,\n" + " `s` varchar(20),\n" + " PRIMARY KEY (`i`),\n" + " UNIQUE KEY `test_key` (`s`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "drop column prevents foreign key violations", SetUpScript: []string{ "create table t36 (i bigint primary key, j varchar(20))", "create table t37 (i bigint primary key, j varchar(20))", "ALTER TABLE t36 ADD key (j)", "ALTER TABLE t37 ADD constraint fk_36 foreign key (j) references t36(j)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t37 drop column j", ExpectedErr: sql.ErrForeignKeyDropColumn, }, }, }, { Name: "disable keys / enable keys", SetUpScript: []string{ "CREATE TABLE t33(pk BIGINT PRIMARY KEY, v1 int, v2 int)", `alter table t33 add column v4 int after pk, drop column v2, add constraint v1gt0 check (v1 > 0)`, }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t33 DISABLE KEYS", SkipResultsCheck: true, ExpectedWarning: mysql.ERNotSupportedYet, ExpectedWarningsCount: 1, }, { Query: "ALTER TABLE t33 ENABLE KEYS", SkipResultsCheck: true, ExpectedWarning: mysql.ERNotSupportedYet, ExpectedWarningsCount: 1, }, }, }, { Name: "adding a unique constraint errors if violations exist", SetUpScript: []string{ "CREATE TABLE t38 (pk int PRIMARY KEY, col1 int)", "INSERT INTO t38 VALUES (1, 1)", "INSERT INTO t38 VALUES (2, 2)", "INSERT INTO t38 VALUES (3, NULL)", "INSERT INTO t38 VALUES (4, NULL)", "CREATE TABLE t39 (pk int PRIMARY KEY, col1 int, col2 int)", "INSERT INTO t39 VALUES (1, 1, 1)", "INSERT INTO t39 VALUES (2, 1, 2)", "INSERT INTO t39 VALUES (3, 2, 1)", "INSERT INTO t39 VALUES (4, 1, NULL)", "INSERT INTO t39 VALUES (5, 1, NULL)", "INSERT INTO t39 VALUES (6, NULL, 1)", "INSERT INTO t39 VALUES (7, NULL, 1)", "INSERT INTO t39 VALUES (8, NULL, NULL)", "INSERT INTO t39 VALUES (9, NULL, NULL)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t38 ADD UNIQUE u_col1 (col1)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t39 ADD UNIQUE u_col1_col2 (col1, col2)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t38 DROP INDEX u_col1;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO t38 VALUES (5, 1);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "ALTER TABLE t38 ADD UNIQUE u_col1 (col1)", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "show create table t38;", Expected: []sql.Row{{"t38", "CREATE TABLE `t38` (\n" + " `pk` int NOT NULL,\n" + " `col1` int,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "ALTER TABLE t39 DROP INDEX u_col1_col2;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO t39 VALUES (10, 1, 1);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "ALTER TABLE t39 ADD UNIQUE u_col1_col2 (col1, col2)", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "show create table t39;", Expected: []sql.Row{{"t39", "CREATE TABLE `t39` (\n" + " `pk` int NOT NULL,\n" + " `col1` int,\n" + " `col2` int,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "ALTER TABLE remove AUTO_INCREMENT", SetUpScript: []string{ "CREATE TABLE t40 (pk int AUTO_INCREMENT PRIMARY KEY, val int)", "INSERT into t40 VALUES (1, 1), (NULL, 2), (NULL, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t40 MODIFY COLUMN pk int", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "describe t40", Expected: []sql.Row{ {"pk", "int", "NO", "PRI", "NULL", ""}, {"val", "int", "YES", "", "NULL", ""}, }, }, { Query: "INSERT INTO t40 VALUES (NULL, 4)", ExpectedErr: sql.ErrInsertIntoNonNullableProvidedNull, }, { Query: "drop table t40", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CREATE TABLE t40 (pk int AUTO_INCREMENT PRIMARY KEY, val int)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO t40 VALUES (NULL, 1)", Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, InsertID: 1, }}}, }, { Query: "SELECT * FROM t40", Expected: []sql.Row{{1, 1}}, }, }, }, { Name: "add column unique index", SetUpScript: []string{ "CREATE TABLE t1 (i bigint primary key, s varchar(20))", "INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c')", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 add column j int unique", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `i` bigint NOT NULL,\n" + " `s` varchar(20),\n" + " `j` int,\n" + " PRIMARY KEY (`i`),\n" + " UNIQUE KEY `j` (`j`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "multi-alter ddl column errors", SetUpScript: []string{ "create table tbl_i (i int primary key)", "create table tbl_ij (i int primary key, j int)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table tbl_i add column j int, drop column j", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "alter table tbl_i add column j int, rename column j to k;", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "alter table tbl_i add column j int, modify column j varchar(10)", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "alter table tbl_ij drop column j, rename column j to k;", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "alter table tbl_ij drop column k, rename column j to k;", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "alter table tbl_i add index(j), add column j int;", ExpectedErr: sql.ErrKeyColumnDoesNotExist, }, }, }, { Name: "Add column and make unique in separate clauses", SetUpScript: []string{ "create table t (c1 int primary key, c2 int, c3 int)", "insert into t values (1, 1, 1), (2, 2, 2), (3, 3, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add column c4 int null, add unique index uniq(c4)", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t", Expected: []sql.Row{sql.Row{"t", "CREATE TABLE `t` (\n" + " `c1` int NOT NULL,\n" + " `c2` int,\n" + " `c3` int,\n" + " `c4` int,\n" + " PRIMARY KEY (`c1`),\n" + " UNIQUE KEY `uniq` (`c4`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select * from t", Expected: []sql.Row{ {1, 1, 1, nil}, {2, 2, 2, nil}, {3, 3, 3, nil}, }, }, }, }, { Name: "ALTER TABLE does not change column collations", SetUpScript: []string{ "CREATE TABLE test1 (v1 VARCHAR(200), v2 ENUM('a'), v3 SET('a'));", "CREATE TABLE test2 (v1 VARCHAR(200), v2 ENUM('a'), v3 SET('a')) COLLATE=utf8mb4_general_ci;", "CREATE TABLE test3 (v1 VARCHAR(200) COLLATE utf8mb4_general_ci, v2 ENUM('a'), v3 SET('a') CHARACTER SET utf8mb3) COLLATE=utf8mb4_general_ci", "CREATE TABLE test4 (v1 VARCHAR(200) COLLATE utf8mb4_0900_ai_ci, v2 ENUM('a') COLLATE utf8mb4_general_ci, v3 SET('a') COLLATE utf8mb4_unicode_ci) COLLATE=utf8mb4_bin;", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE test1", Expected: []sql.Row{{"test1", "CREATE TABLE `test1` (\n" + " `v1` varchar(200),\n" + " `v2` enum('a'),\n" + " `v3` set('a')\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "SHOW CREATE TABLE test2", Expected: []sql.Row{{"test2", "CREATE TABLE `test2` (\n" + " `v1` varchar(200),\n" + " `v2` enum('a'),\n" + " `v3` set('a')\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"}}, }, { Query: "SHOW CREATE TABLE test3", Expected: []sql.Row{{"test3", "CREATE TABLE `test3` (\n" + " `v1` varchar(200),\n" + " `v2` enum('a'),\n" + " `v3` set('a') CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"}}, }, { Query: "SHOW CREATE TABLE test4", Expected: []sql.Row{{"test4", "CREATE TABLE `test4` (\n" + " `v1` varchar(200) COLLATE utf8mb4_0900_ai_ci,\n" + " `v2` enum('a') COLLATE utf8mb4_general_ci,\n" + " `v3` set('a') COLLATE utf8mb4_unicode_ci\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"}}, }, { Query: "ALTER TABLE test1 COLLATE utf8mb4_general_ci;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE test2 COLLATE utf8mb4_0900_bin;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE test3 COLLATE utf8mb4_0900_bin;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE test4 COLLATE utf8mb4_unicode_ci;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW CREATE TABLE test1", Expected: []sql.Row{{"test1", "CREATE TABLE `test1` (\n" + " `v1` varchar(200) COLLATE utf8mb4_0900_bin,\n" + " `v2` enum('a') COLLATE utf8mb4_0900_bin,\n" + " `v3` set('a') COLLATE utf8mb4_0900_bin\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"}}, }, { Query: "SHOW CREATE TABLE test2", Expected: []sql.Row{{"test2", "CREATE TABLE `test2` (\n" + " `v1` varchar(200) COLLATE utf8mb4_general_ci,\n" + " `v2` enum('a') COLLATE utf8mb4_general_ci,\n" + " `v3` set('a') COLLATE utf8mb4_general_ci\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "SHOW CREATE TABLE test3", Expected: []sql.Row{{"test3", "CREATE TABLE `test3` (\n" + " `v1` varchar(200) COLLATE utf8mb4_general_ci,\n" + " `v2` enum('a') COLLATE utf8mb4_general_ci,\n" + " `v3` set('a') CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "SHOW CREATE TABLE test4", Expected: []sql.Row{{"test4", "CREATE TABLE `test4` (\n" + " `v1` varchar(200) COLLATE utf8mb4_0900_ai_ci,\n" + " `v2` enum('a') COLLATE utf8mb4_general_ci,\n" + " `v3` set('a')\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"}}, }, }, }, }
var AnsiQuotesTests = []ScriptTest{ { Name: "ANSI_QUOTES: basic cases", SetUpScript: []string{ "SET @@sql_mode='ANSI_QUOTES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';", "create table auctions (ai int auto_increment, id varchar(32), data varchar(100), primary key (ai));", "insert into auctions (id, data) values (42, 'forty-two');", }, Assertions: []ScriptTestAssertion{ { Query: `select "data" from auctions order by "ai" desc;`, Expected: []sql.Row{{"forty-two"}}, }, { Query: "select `data` from auctions order by `ai` desc;", Expected: []sql.Row{{"forty-two"}}, }, { Query: `PREPARE prep1 FROM 'select "data" from auctions order by "ai" desc;'`, Expected: []sql.Row{{types.OkResult{RowsAffected: 0x0, InsertID: 0x0, Info: plan.PrepareInfo{}}}}, }, { Query: `PREPARE prep2 FROM 'INSERT INTO auctions (id, "data") VALUES (?, ?);';`, Expected: []sql.Row{{types.OkResult{RowsAffected: 0x0, InsertID: 0x0, Info: plan.PrepareInfo{}}}}, }, { Query: `select "data", '"' from auctions order by "ai";`, Expected: []sql.Row{{"forty-two", "\""}}, }, { Query: `select "data", '\"' from auctions order by "ai";`, Expected: []sql.Row{{"forty-two", "\""}}, }, { Query: `select '''foo''';`, Expected: []sql.Row{{`'foo'`}}, }, { Query: `select """""foo""""";`, ExpectedErrStr: `column "\"\"foo\"\"" could not be found in any table in scope`, }, { Query: "select ```foo```;", ExpectedErrStr: "column \"`foo`\" could not be found in any table in scope", }, { Query: `SET @@sql_mode='NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, Expected: []sql.Row{{}}, }, { Query: `select "data" from auctions order by "ai" desc;`, Expected: []sql.Row{{"data"}}, }, { Query: `show tables;`, Expected: []sql.Row{{"auctions"}, {"myview"}}, }, }, }, { Name: "ANSI_QUOTES: ANSI combination mode", SetUpScript: []string{ `SET @@sql_mode='ANSI';`, }, Assertions: []ScriptTestAssertion{ { Query: `create table "t" ("pk" int primary key, "data" varchar(100));`, Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: `insert into t ("pk", "data") values (1, 'one');`, Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: `select "pk", "data" from "t" order by "pk" asc;`, Expected: []sql.Row{{1, "one"}}, }, }, }, { Name: "ANSI_QUOTES: views", SetUpScript: []string{ `SET @@sql_mode='ANSI_QUOTES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, }, Assertions: []ScriptTestAssertion{ { Query: `CREATE TABLE public_keys (item INTEGER, type CHAR(4), hash INTEGER, "count" INTEGER, "public" VARCHAR(8000))`, Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: `insert into public_keys("item", "type", "hash", "count", "public") values (42, 'type', 1010, 1, 'public');`, Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: `create view view1 as select public_keys."public", public_keys."count" from public_keys;`, Expected: []sql.Row{}, }, { Query: `show tables;`, Expected: []sql.Row{{"myview"}, {"public_keys"}, {"view1"}}, }, { Query: `show create table view1;`, Expected: []sql.Row{{"view1", "CREATE VIEW `view1` AS select public_keys.\"public\", public_keys.\"count\" from public_keys", "utf8mb4", "utf8mb4_0900_bin"}}, }, { Skip: true, Query: `show create table view1;`, Expected: []sql.Row{{"view1", "CREATE VIEW `view1` AS select public_keys.`public`, public_keys.`count` from public_keys", "utf8mb4", "utf8mb4_0900_bin"}}, }, { Query: `select "public", "count" from view1;`, Expected: []sql.Row{{"public", 1}}, }, { Query: `select table_name, view_definition from information_schema.views where table_name='view1';`, Expected: []sql.Row{{"view1", `select public_keys."public", public_keys."count" from public_keys`}}, }, { Query: `SET @@sql_mode='NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, Expected: []sql.Row{{}}, }, { Query: `show create table view1;`, Expected: []sql.Row{{"view1", "CREATE VIEW `view1` AS select public_keys.\"public\", public_keys.\"count\" from public_keys", "utf8mb4", "utf8mb4_0900_bin"}}, }, { Query: `show create table public_keys;`, Expected: []sql.Row{{"public_keys", "CREATE TABLE `public_keys` (\n `item` int,\n `type` char(4),\n `hash` int,\n `count` int,\n `public` varchar(8000)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select public, `count` from view1;", Expected: []sql.Row{{"public", 1}}, }, { Query: `select table_name, view_definition from information_schema.views where table_name='view1';`, Expected: []sql.Row{{"view1", `select public_keys."public", public_keys."count" from public_keys`}}, }, }, }, { Name: "ANSI_QUOTES: triggers", SetUpScript: []string{ `SET @@sql_mode='ANSI_QUOTES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, `create table t (pk int primary key, name varchar(32), data varchar(100));`, `create trigger ansi_quotes_trigger BEFORE INSERT ON "t" FOR EACH ROW SET new."data" = 'triggered!';`, `insert into t values (1, 'John', 'FooBar');`, }, Assertions: []ScriptTestAssertion{ { Query: `select "name", "data" from t order by "pk";`, Expected: []sql.Row{{"John", "triggered!"}}, }, { Query: `select action_statement from information_schema.triggers where trigger_name='ansi_quotes_trigger';`, Expected: []sql.Row{{`SET new."data" = 'triggered!'`}}, }, { Query: `SET @@sql_mode='NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, Expected: []sql.Row{{}}, }, { Query: `insert into t values (2, 'George', 'SomethingElse');`, Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: `select name, data from t where pk=2;`, Expected: []sql.Row{{"George", "triggered!"}}, }, { Query: `select action_statement from information_schema.triggers where trigger_name='ansi_quotes_trigger';`, Expected: []sql.Row{{`SET new."data" = 'triggered!'`}}, }, }, }, { Name: "ANSI_QUOTES: stored procedures", SetUpScript: []string{ `SET @@sql_mode='ANSI_QUOTES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, `create table t (pk int primary key, name varchar(32), data varchar(100));`, `create procedure AnsiProcedure() BEGIN SELECT "name" from "t" where "pk" = 1; END`, `insert into t values (1, 'John', 'FooBar');`, }, Assertions: []ScriptTestAssertion{ { Query: `call AnsiProcedure();`, Expected: []sql.Row{{"John"}}, }, { Query: `select routine_definition from information_schema.routines where routine_name='AnsiProcedure';`, Expected: []sql.Row{{`BEGIN SELECT "name" from "t" where "pk" = 1; END`}}, }, { Query: `SET @@sql_mode='NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, Expected: []sql.Row{{}}, }, { Query: `call AnsiProcedure();`, Expected: []sql.Row{{"John"}}, }, { Skip: true, Query: `select routine_definition from information_schema.routines where routine_name='AnsiProcedure';`, Expected: []sql.Row{{`BEGIN SELECT "name" from "t" where "pk" = 1; END`}}, }, }, }, { Name: "ANSI_QUOTES: column defaults", SetUpScript: []string{ `SET @@sql_mode='ANSI_QUOTES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, `create table t ("pk" int primary key, "name" varchar(20), data varchar(100) DEFAULT(CONCAT("name", '!')));`, `insert into t (pk, name) values (1, 'John');`, }, Assertions: []ScriptTestAssertion{ { Query: `select "name", "data" from t where "pk"=1;`, Expected: []sql.Row{{"John", "John!"}}, }, { Query: `SET @@sql_mode='NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, Expected: []sql.Row{{}}, }, { Query: `insert into t (pk, name) values (2, 'Jill');`, Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: `select name, data from t where pk=2;`, Expected: []sql.Row{{"Jill", "Jill!"}}, }, }, }, { Name: "ANSI_QUOTES: check constraints", SetUpScript: []string{ `SET @@sql_mode='ANSI_QUOTES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, `create table t (pk int primary key, data varchar(100), CONSTRAINT "ansi_check" CHECK ("data" != 'forbidden'));`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into t values (1, 'forbidden');`, ExpectedErrStr: `Check constraint "ansi_check" violated`, }, { Query: `SET @@sql_mode='NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, Expected: []sql.Row{{}}, }, { Query: `insert into t values (1, 'forbidden');`, ExpectedErrStr: `Check constraint "ansi_check" violated`, }, }, }, { Name: "ANSI_QUOTES: events", SetUpScript: []string{ `SET @@sql_mode='ANSI_QUOTES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, `create table t (pk int primary key, "count" int);`, `insert into t values (1, 0);`, }, Assertions: []ScriptTestAssertion{ { Query: `CREATE EVENT myevent ON SCHEDULE EVERY 1 SECOND STARTS '2037-10-16 23:59:00' DO UPDATE "t" SET "count"="count"+1;`, Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: `SHOW EVENTS;`, Expected: []sql.Row{{"mydb", "myevent", "`root`@`localhost`", "SYSTEM", "RECURRING", nil, "1", "SECOND", "2037-10-16 23:59:00", nil, "ENABLED", 0, "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, { Query: `SET @@sql_mode='NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES';`, Expected: []sql.Row{{}}, }, { Query: `SHOW EVENTS;`, Expected: []sql.Row{{"mydb", "myevent", "`root`@`localhost`", "SYSTEM", "RECURRING", nil, "1", "SECOND", "2037-10-16 23:59:00", nil, "ENABLED", 0, "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, }, }, }
var BlobErrors = []QueryErrorTest{ { Query: "alter table mytable modify s blob", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "alter table mytable modify s text", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "alter table blobt add index bidx (b)", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "alter table blobt add index tidx (i, b)", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "alter table blobt add index bidx (b(3073))", ExpectedErr: sql.ErrKeyTooLong, }, { Query: "alter table blobt add column b2 blob default '1'", ExpectedErr: sql.ErrInvalidTextBlobColumnDefault, }, { Query: "alter table textt add index tidx (t)", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "alter table textt add index tidx (t(769))", ExpectedErr: sql.ErrKeyTooLong, }, { Query: "alter table textt add column t2 text default '1'", ExpectedErr: sql.ErrInvalidTextBlobColumnDefault, }, { Query: "alter table textt add index tidx (i, t)", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "create table b (b blob primary key)", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "create table b (b tinyblob primary key)", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "create table t (t text primary key)", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "create table t (t text, primary key (t))", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "create table b (b blob, primary key (b))", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "create table b (b blob, primary key (b(3073)))", ExpectedErr: sql.ErrKeyTooLong, }, { Query: "create table t (t text, primary key (t(769)))", ExpectedErr: sql.ErrKeyTooLong, }, { Query: "create table b (i int primary key, b blob, index bidx(b))", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "create table b (i int primary key, b blob, index bidx(b(3073)))", ExpectedErr: sql.ErrKeyTooLong, }, { Query: "CREATE TABLE b (pk BIGINT PRIMARY KEY, v1 TEXT, INDEX (v1));", ExpectedErr: sql.ErrInvalidBlobTextKey, }, { Query: "CREATE TABLE b (pk BIGINT PRIMARY KEY, v1 TINYTEXT, INDEX (v1));", ExpectedErr: sql.ErrInvalidBlobTextKey, }, }
var BlobQueries = []QueryTest{ { Query: "select i, hex(b) from blobt", Expected: []sql.Row{ {1, "666972737420726F77"}, {2, "7365636F6E6420726F77"}, {3, "746869726420726F77"}, }, }, { Query: "select * from blobt where i = 1", Expected: []sql.Row{ {1, []byte("first row")}, }, }, { Query: "select * from blobt order by b desc", Expected: []sql.Row{ {3, []byte("third row")}, {2, []byte("second row")}, {1, []byte("first row")}, }, }, { Query: "select * from blobt where b <= 'second row'", Expected: []sql.Row{ {2, []byte("second row")}, {1, []byte("first row")}, }, }, { Query: "select i, hex(t) from textt", Expected: []sql.Row{ {1, "666972737420726F77"}, {2, "7365636F6E6420726F77"}, {3, "746869726420726F77"}, }, }, { Query: "select * from textt where i = 1", Expected: []sql.Row{ {1, "first row"}, }, }, { Query: "select * from textt order by t desc", Expected: []sql.Row{ {3, "third row"}, {2, "second row"}, {1, "first row"}, }, }, { Query: "select * from textt where t <= 'second row'", Expected: []sql.Row{ {1, "first row"}, {2, "second row"}, }, }, }
var BlobUnsupported = []QueryTest{ { Query: "select convert(`b` using utf8) from blobt", Expected: []sql.Row{ {1, "first row"}, {2, "second row"}, {3, "third row"}, }, }, }
var BlobWriteQueries = []WriteQueryTest{ { WriteQuery: "insert into blobt values (4, '100000000')", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "select * from blobt where i = 4", ExpectedSelect: []sql.Row{{4, []byte("100000000")}}, }, { WriteQuery: "update blobt set b = '100000000' where i = 1", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "select * from blobt where i = 1", ExpectedSelect: []sql.Row{{1, []byte("100000000")}}, }, { WriteQuery: "delete from blobt where i = 1", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "select * from blobt", ExpectedSelect: []sql.Row{ {2, []byte("second row")}, {3, []byte("third row")}, }, }, { WriteQuery: "alter table blobt rename column b to v, add v1 int", ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "select * from blobt", ExpectedSelect: []sql.Row{ {1, []byte("first row"), nil}, {2, []byte("second row"), nil}, {3, []byte("third row"), nil}, }, }, { WriteQuery: "ALTER TABLE blobt ADD COLUMN v2 BIGINT DEFAULT (i + 2) AFTER b", ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "select * from blobt", ExpectedSelect: []sql.Row{ {1, []byte("first row"), 3}, {2, []byte("second row"), 4}, {3, []byte("third row"), 5}, }, }, { WriteQuery: "insert into textt values (4, '100000000')", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "select * from textt where i = 4", ExpectedSelect: []sql.Row{{4, "100000000"}}, }, { WriteQuery: "update textt set t = '100000000' where i = 1", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "select * from textt where i = 1", ExpectedSelect: []sql.Row{{1, "100000000"}}, }, { WriteQuery: "delete from textt where i = 1", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "select * from textt", ExpectedSelect: []sql.Row{ {2, "second row"}, {3, "third row"}, }, }, { WriteQuery: "alter table textt rename column t to v, add v1 int", ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "select * from textt", ExpectedSelect: []sql.Row{ {1, "first row", nil}, {2, "second row", nil}, {3, "third row", nil}, }, }, { WriteQuery: "ALTER TABLE textt ADD COLUMN v2 BIGINT DEFAULT (i + 2) AFTER t", ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "select * from textt", ExpectedSelect: []sql.Row{ {1, "first row", 3}, {2, "second row", 4}, {3, "third row", 5}, }, }, }
var BrokenCreateTableQueries = []WriteQueryTest{ { WriteQuery: `create table t1 (b blob, primary key(b(1)))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `show create table t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `b` blob NOT NULL,\n PRIMARY KEY (`b`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `create table t1 (b1 blob, b2 blob, primary key(b1(123), b2(456)))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `show create table t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `b1` blob NOT NULL,\n `b2` blob NOT NULL,\n PRIMARY KEY (`b1`(123),`b2`(456))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `create table t1 (i int, b1 blob, b2 blob, primary key(b1(123), b2(456), i))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `show create table t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `b1` blob NOT NULL,\n `b2` blob NOT NULL,\n PRIMARY KEY (`b1`(123),`b2`(456),`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }
var BrokenErrorQueries = []QueryErrorTest{ { Query: `WITH recursive n(i) as (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i+1 <= 10 GROUP BY i HAVING i+1 <= 10 ORDER BY 1 LIMIT 5) SELECT count(i) FROM n;`, ExpectedErrStr: "Not supported: 'ORDER BY over UNION in recursive Common Table Expression'", }, { Query: "with a(j) as (select 1) select j from a union select x from xy order by x;", ExpectedErrStr: "Unknown column 'x' in 'order clause'", }, { Query: "WITH Numbers AS ( SELECT n = 1 UNION ALL SELECT n + 1 FROM Numbers WHERE n+1 <= 10) SELECT n FROM Numbers;", ExpectedErr: sql.ErrTableNotFound, }, { Query: "SELECT col0, floor(col1) FROM tab1 GROUP by col0;", ExpectedErr: analyzererrors.ErrValidationGroupBy, }, { Query: "SELECT floor(cor0.col1) * ceil(cor0.col0) AS col2 FROM tab1 AS cor0 GROUP BY cor0.col0", ExpectedErr: analyzererrors.ErrValidationGroupBy, }, { Query: "select * from two_pk group by pk1, pk2", }, { Query: "select * from two_pk group by pk1", ExpectedErr: analyzererrors.ErrValidationGroupBy, }, { Query: "select * from two_pk group by pk1 + 1, mod(pk2, 2)", ExpectedErr: analyzererrors.ErrValidationGroupBy, }, { Query: "select pk1+1 from two_pk group by pk1 + 1, mod(pk2, 2)", }, { Query: "select mod(pk2, 2) from two_pk group by pk1 + 1, mod(pk2, 2)", }, { Query: "select mod(pk2, 2) from two_pk group by pk1 + 1, mod(pk2, 2)", }, { Query: `SELECT any_value(pk), (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x FROM one_pk opk WHERE (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) > 0 GROUP BY (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) ORDER BY x`, }, }
var BrokenJSONTableScriptTests = []ScriptTest{ { Name: "json_table out of cte", SetUpScript: []string{ "create table t (i int, j json)", `insert into t values (1, '["test"]')`, }, Assertions: []ScriptTestAssertion{ { Query: "with tt as (select * from t) select * from json_table(tt.j, '$[*]' columns (a varchar(10) path '$')) as jt;", ExpectedErr: sql.ErrUnknownTable, }, { Query: "with tt as (select * from t) select * from tt, json_table(tt.j, '$[*]' columns (a varchar(10) path '$')) as jt;", ExpectedErr: sql.ErrInvalidArgument, }, }, }, { Name: "json_table out of cte", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM JSON_TABLE('[ {\"c1\": null} ]', '$[*]' COLUMNS( c1 INT PATH '$.c1' ERROR ON ERROR )) as jt;", Expected: []sql.Row{ {nil}, }, }, { Query: "SELECT * FROM JSON_TABLE('[{\"a\":\"3\"},{\"a\":2},{\"b\":1},{\"a\":0},{\"a\":[1,2]}]', \"$[*]\" COLUMNS(rowid FOR ORDINALITY, ac VARCHAR(100) PATH \"$.a\" DEFAULT '111' ON EMPTY DEFAULT '999' ON ERROR, aj JSON PATH \"$.a\" DEFAULT '{\"x\": 333}' ON EMPTY, bx INT EXISTS PATH \"$.b\")) AS tt;", Expected: []sql.Row{ {1, 3, "3", 0}, {2, 2, 2, 0}, {3, 111, types.MustJSON("{\"x\": 333}"), 1}, {4, 0, 0, 0}, {5, 999, types.MustJSON("[1, 2]"), 0}, }, }, { Query: "SELECT * FROM JSON_TABLE('[ {\"a\": 1, \"b\": [11,111]}, {\"a\": 2, \"b\": [22,222]}, {\"a\":3}]', '$[*]' COLUMNS(a INT PATH '$.a', NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) AS jt WHERE b IS NOT NULL;", Expected: []sql.Row{ {1, 11}, {1, 111}, {2, 22}, {2, 222}, }, }, }, }, }
var BrokenQueries = []QueryTest{ { Query: `WITH RECURSIVE rt (foo) AS ( SELECT 1 as foo UNION ALL SELECT foo + 1 as foo FROM rt WHERE foo < 5 ), ladder (depth, foo) AS ( SELECT 1 as depth, NULL as foo from rt UNION ALL SELECT ladder.depth + 1 as depth, rt.foo FROM ladder JOIN rt WHERE ladder.foo = rt.foo ) SELECT * FROM ladder;`, }, { Query: "with recursive t (n) as (select sum('1') from dual union all select (2.00) from dual) select sum(n) from t;", Expected: []sql.Row{ {float64(3)}, }, }, { Query: "with recursive t (n) as (select sum(1.0) from dual union all select n+1 from t where n < 10) select sum(n) from t;", Expected: []sql.Row{ {"55.0"}, }, }, { Query: "select t2.* from mytable t1 natural join mytable t2 join othertable t3 on t2.i = t3.i2;", Expected: []sql.Row{ {1, "first row"}, {2, "second row"}, {3, "third row"}, }, }, { Query: "select t1.*, t2.*, i from mytable t1 natural join mytable t2 join othertable t3 on t2.i = t3.i2;", Expected: []sql.Row{ {1, "first row", 1, "first row", 1}, {2, "second row", 2, "second row", 2}, {3, "third row", 3, "third row", 3}, }, }, { Query: "with recursive MYTABLE(j) as (select 2 union select MYTABLE.j from MYTABLE join mytable on MYTABLE.j = mytable.i) select j from MYTABLE", Expected: []sql.Row{{2}}, }, { Query: "with recursive MYTABLE(j) as (select 2 union select MYTABLE.j from MYTABLE join mytable on MYTABLE.j = mytable.i) select i from mytable;", Expected: []sql.Row{{1}, {2}, {3}}, }, { Query: "with a(j) as (select 1), b(i) as (select 2) (select j from a union select i from b order by 1 desc) union select j from a;", Expected: []sql.Row{{2}, {1}}, }, { Query: "with a(j) as (select 1 union select 2 union select 3), b(i) as (select 2 union select 3) select (3,4) in (select a.j, b.i+1 from a, b where a.j = b.i) as k group by k having k = 1;", Expected: []sql.Row{{1}}, }, { Query: "With recursive a(x) as (select 1 union select 2 union select x in (select t1.i from mytable t1) from a) select x from a;", Expected: []sql.Row{{1}, {2}}, }, { Query: "with a(j) as (select 1) ( with c(k) as (select 3) select k from c union select 6) union select k from c;", Expected: []sql.Row{{3}, {6}}, }, { Query: "SELECT pk1, SUM(c1) FROM two_pk", Expected: []sql.Row{{0, 60.0}}, }, { Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS x FROM one_pk opk WHERE x > 0 ORDER BY x`, Expected: []sql.Row{ {2, 1}, {3, 2}, }, }, { Query: `SELECT pk, (SELECT max(pk) FROM one_pk WHERE pk < opk.pk) AS min, (SELECT min(pk) FROM one_pk WHERE pk > opk.pk) AS max FROM one_pk opk WHERE max > 1 ORDER BY max;`, Expected: []sql.Row{ {1, 0, 2}, {2, 1, 3}, }, }, { Query: `SELECT pk, (SELECT sum(c1) FROM two_pk WHERE c1 IN (SELECT c4 FROM two_pk WHERE c3 > opk.c5)) AS sum, (SELECT avg(c1) FROM two_pk WHERE pk2 IN (SELECT pk2 FROM two_pk WHERE c1 < opk.c2)) AS avg FROM one_pk opk ORDER BY pk`, Expected: []sql.Row{ {0, 60.0, nil}, {1, 50.0, 10.0}, {2, 30.0, 15.0}, {3, nil, 15.0}, }, }, { Query: `SELECT column_0, sum(column_1) FROM (values row(1,1), row(1,3), row(2,2), row(2,5), row(3,9)) a group by 1 having avg(column_1) > 2 order by 1`, Expected: []sql.Row{ {2, 7.0}, {3, 9.0}, }, }, { Query: `WITH t AS (SELECT 1) SELECT * FROM t UNION (WITH t AS (SELECT 2) SELECT * FROM t)`, Expected: []sql.Row{ {1}, {2}, }, }, { Query: "SELECT json_array() FROM dual;", }, { Query: "SELECT json_array_append() FROM dual;", }, { Query: "SELECT json_array_insert() FROM dual;", }, { Query: "SELECT json_contains() FROM dual;", }, { Query: "SELECT json_contains_path() FROM dual;", }, { Query: "SELECT json_depth() FROM dual;", }, { Query: "SELECT json_insert() FROM dual;", }, { Query: "SELECT json_keys() FROM dual;", }, { Query: "SELECT json_length() FROM dual;", }, { Query: "SELECT json_merge_patch() FROM dual;", }, { Query: "SELECT json_merge_preserve() FROM dual;", }, { Query: "SELECT json_object() FROM dual;", }, { Query: "SELECT json_overlaps() FROM dual;", }, { Query: "SELECT json_pretty() FROM dual;", }, { Query: "SELECT json_quote() FROM dual;", }, { Query: "SELECT json_remove() FROM dual;", }, { Query: "SELECT json_replace() FROM dual;", }, { Query: "SELECT json_schema_valid() FROM dual;", }, { Query: "SELECT json_schema_validation_report() FROM dual;", }, { Query: "SELECT json_set() FROM dual;", }, { Query: "SELECT json_search() FROM dual;", }, { Query: "SELECT json_storage_free() FROM dual;", }, { Query: "SELECT json_storage_size() FROM dual;", }, { Query: "SELECT json_type() FROM dual;", }, { Query: "SELECT json_table() FROM dual;", }, { Query: "SELECT json_valid() FROM dual;", }, { Query: "SELECT json_value() FROM dual;", }, { Query: `SELECT s as i, i as i from mytable order by i`, }, { Query: "SELECT i, I, s, S FROM mytable;", Expected: []sql.Row{ {1, 1, "first row", "first row"}, {2, 2, "second row", "second row"}, {3, 3, "third row", "third row"}, }, ExpectedColumns: sql.Schema{ { Name: "i", Type: types.Int64, }, { Name: "I", Type: types.Int64, }, { Name: "s", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), }, { Name: "S", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), }, }, }, { Query: "SELECT `i`, `I`, `s`, `S` FROM mytable;", Expected: []sql.Row{ {1, 1, "first row", "first row"}, {2, 2, "second row", "second row"}, {3, 3, "third row", "third row"}, }, ExpectedColumns: sql.Schema{ { Name: "i", Type: types.Int64, }, { Name: "I", Type: types.Int64, }, { Name: "s", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), }, { Name: "S", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), }, }, }, { Query: "SELECT `mytable`.`i`, `mytable`.`I`, `mytable`.`s`, `mytable`.`S` FROM mytable;", Expected: []sql.Row{ {1, 1, "first row", "first row"}, {2, 2, "second row", "second row"}, {3, 3, "third row", "third row"}, }, ExpectedColumns: sql.Schema{ { Name: "i", Type: types.Int64, }, { Name: "I", Type: types.Int64, }, { Name: "s", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), }, { Name: "S", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), }, }, }, { Query: `SELECT json_unquote(json_extract('{"hi":"there"}', '$.nope'))`, Expected: []sql.Row{{nil}}, }, { Query: "SELECT 1 FROM DUAL WHERE (1, null) in ((1, null))", Expected: []sql.Row{}, }, { Query: "SELECT 1 FROM DUAL WHERE (1, null) != (0, null)", Expected: []sql.Row{}, }, { Query: "SELECT 1 FROM DUAL WHERE (0, null) = (0, null)", Expected: []sql.Row{}, }, { Query: "SELECT 1 FROM DUAL WHERE ('0', 0) = (0, '0')", Expected: []sql.Row{{1}}, }, { Query: "SELECT 1 FROM DUAL WHERE (null, null) = (select null, null from dual)", Expected: []sql.Row{}, }, { Query: "SELECT c AS i_do_not_conflict, COUNT(*), MIN((SELECT COUNT(*) FROM (SELECT 1 AS d) b WHERE b.d = a.c)) FROM (SELECT 1 AS c) a GROUP BY i_do_not_conflict;", }, { Query: "SELECT c AS c, COUNT(*), MIN((SELECT COUNT(*) FROM (SELECT 1 AS d) b WHERE b.d = a.c)) FROM (SELECT 1 AS c) a GROUP BY a.c;", }, { Query: ` with recursive t1 (sub_part, part, quantity) as ( with recursive t2 (sub_part, part, quantity) as ( SELECT p2.sub_part, p2.part, p2.quantity FROM parts as p2 UNION SELECT p1.sub_part, p1.part, p1.quantity FROM parts as p1 JOIN t2 ON p1.sub_part = t2.sub_part WHERE p1.part = 'pie' and t2.part = 'crust' ) select * from t2 UNION SELECT t1.sub_part, t1.part, t1.quantity FROM t1 JOIN parts AS p ON p.part = p.part ) SELECT t1.sub_part, sum(t1.quantity) as total_quantity FROM t1 GROUP BY t1.sub_part;`, Expected: []sql.Row{ {"crust", float64(1)}, {"filling", float64(2)}, {"flour", float64(20)}, {"butter", float64(18)}, {"salt", float64(18)}, {"sugar", float64(7)}, {"fruit", float64(9)}, }, }, { Query: "select i, date_col from datetime_table", Expected: []sql.Row{{1, "2019-12-31"}}, }, { Query: "SELECT X'0a'", Expected: []sql.Row{{"0x0A"}}, }, { Query: "STR_TO_DATE('2013 32 Tuesday', '%X %V %W')", Expected: []sql.Row{{"2013-08-13"}}, }, { Query: "select 2000.0 / 250000000.0 * (24.0 * 6.0 * 6.25 * 10.0);", Expected: []sql.Row{{"0.0720000000"}}, }, { Query: ` WITH RECURSIVE cte(i, j) AS ( SELECT 0, 1, 2 FROM mytable UNION ALL SELECT * FROM mytable, cte WHERE cte.i = mytable.i ) SELECT * FROM mytable;`, Expected: []sql.Row{ {1, "first row"}, {2, "second row"}, {3, "third row"}, }, }, { Query: ` SELECT * FROM (SELECT * FROM mytable) t UNION ALL (SELECT * FROM mytable) ORDER BY 1;`, Expected: []sql.Row{ {1, "first row"}, {1, "first row"}, {2, "second row"}, {2, "second row"}, {3, "third row"}, {3, "third row"}, }, }, }
BrokenQueries are queries that are known to be broken in the engine.
var BrokenScriptTests = []ScriptTest{ { Name: "ALTER TABLE MODIFY column with multiple UNIQUE KEYS", SetUpScript: []string{ "CREATE table test (pk int primary key, uk1 int, uk2 int, unique(uk1, uk2))", "ALTER TABLE `test` MODIFY column uk1 int auto_increment", }, Assertions: []ScriptTestAssertion{ { Query: "describe test", Expected: []sql.Row{ {"pk", "int", "NO", "PRI", "NULL", ""}, {"uk1", "int", "NO", "MUL", "NULL", "auto_increment"}, {"uk1", "int", "YES", "", "NULL", ""}, }, }, }, }, { Name: "ALTER TABLE MODIFY column with multiple KEYS", SetUpScript: []string{ "CREATE table test (pk int primary key, mk1 int, mk2 int, index(mk1, mk2))", "ALTER TABLE `test` MODIFY column mk1 int auto_increment", }, Assertions: []ScriptTestAssertion{ { Query: "describe test", Expected: []sql.Row{ {"pk", "int", "NO", "PRI", "NULL", ""}, {"mk1", "int", "NO", "MUL", "NULL", "auto_increment"}, {"mk1", "int", "YES", "", "NULL", ""}, }, }, }, }, { Name: "ALTER TABLE RENAME on a column when another column has a default dependency on it", SetUpScript: []string{ "CREATE TABLE `test` (`pk` bigint NOT NULL,`v2` int NOT NULL DEFAULT '100',`v3` int DEFAULT ((`v2` + 1)),PRIMARY KEY (`pk`));", }, Assertions: []ScriptTestAssertion{ { Query: "alter table test rename column v2 to mycol", ExpectedErr: sql.ErrAlterTableNotSupported, }, }, }, { Name: "Keyless Table with Unique Index", SetUpScript: []string{ "create table a (x int, val int unique)", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO a VALUES (1, 1)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT INTO a VALUES (1, 1)", ExpectedErr: sql.ErrUniqueKeyViolation, }, }, }, { Name: "Multialter DDL with ADD/DROP Primary Key", SetUpScript: []string{ "CREATE TABLE t(pk int primary key, v1 int)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t ADD COLUMN (v2 int), drop primary key, add primary key (v2)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "DESCRIBE t", Expected: []sql.Row{ {"pk", "int", "NO", "", "NULL", ""}, {"v1", "int", "YES", "", "NULL", ""}, {"v2", "int", "NO", "PRI", "NULL", ""}, }, }, { Query: "ALTER TABLE t ADD COLUMN (v3 int), drop primary key, add primary key (notacolumn)", ExpectedErr: sql.ErrKeyColumnDoesNotExist, }, { Query: "DESCRIBE t", Expected: []sql.Row{ {"pk", "int", "NO", "", "NULL", ""}, {"v1", "int", "YES", "", "NULL", ""}, {"v2", "int", "NO", "PRI", "NULL", ""}, }, }, { Query: "ALTER TABLE t ADD column `v4` int NOT NULL, ADD column `v5` int NOT NULL, DROP COLUMN `v1`, ADD COLUMN `v6` int NOT NULL, DROP COLUMN `v2`, ADD COLUMN v7 int NOT NULL", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "DESCRIBE t", Expected: []sql.Row{ {"pk", "int", "NO", "", "NULL", ""}, {"v4", "int", "NO", "", "NULL", ""}, {"v5", "int", "NO", "", "NULL", ""}, {"v6", "int", "NO", "", "NULL", ""}, {"v7", "int", "NO", "", "NULL", ""}, }, }, }, }, { Name: "REGEXP operator", SetUpScript: []string{ "CREATE TABLE IF NOT EXISTS `person` (`id` INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` VARCHAR(255) NOT NULL);", "INSERT INTO `person` (`name`) VALUES ('n1'), ('n2'), ('n3')", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT `t1`.`id`, `t1`.`name` FROM `person` AS `t1` WHERE (`t1`.`name` REGEXP 'N[1,3]') ORDER BY `t1`.`name`;", Expected: []sql.Row{{1, "n1"}, {3, "n3"}}, }, }, }, { Name: "non-existent procedure in trigger body", SetUpScript: []string{ "CREATE TABLE XA(YW VARCHAR(24) NOT NULL, XB VARCHAR(100), XC VARCHAR(2500),\n XD VARCHAR(2500), XE VARCHAR(100), XF VARCHAR(100), XG VARCHAR(100),\n XI VARCHAR(100), XJ VARCHAR(100), XK VARCHAR(100), XL VARCHAR(100),\n XM VARCHAR(1000), XN TEXT, XO TEXT, PRIMARY KEY (YW));", "CREATE TABLE XP(YW VARCHAR(24) NOT NULL, XQ VARCHAR(100) NOT NULL,\n XR VARCHAR(1000), PRIMARY KEY (YW));", "CREATE TABLE XS(YW VARCHAR(24) NOT NULL, XT VARCHAR(24) NOT NULL,\n XU VARCHAR(24), XV VARCHAR(100) NOT NULL, XW DOUBLE NOT NULL,\n XX DOUBLE NOT NULL, XY VARCHAR(100), XC VARCHAR(100), XZ VARCHAR(100) NOT NULL,\n YA DOUBLE, YB VARCHAR(24) NOT NULL, YC VARCHAR(1000), XO VARCHAR(1000),\n YD DOUBLE NOT NULL, YE DOUBLE NOT NULL, PRIMARY KEY (YW));", "CREATE TABLE YF(YW VARCHAR(24) NOT NULL, XB VARCHAR(100) NOT NULL, YG VARCHAR(100),\n YH VARCHAR(100), XO TEXT, PRIMARY KEY (YW));", "CREATE TABLE yp(YW VARCHAR(24) NOT NULL, XJ VARCHAR(100) NOT NULL, XL VARCHAR(100),\n XT VARCHAR(24) NOT NULL, YI INT NOT NULL, XO VARCHAR(1000), PRIMARY KEY (YW),\n FOREIGN KEY (XT) REFERENCES XP (YW));", "INSERT INTO XS VALUES ('', '', NULL, 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC', 0, 0,\n NULL, NULL, '', NULL, '', NULL, NULL, 0, 0);", "INSERT INTO YF VALUES ('', '', NULL, NULL, NULL);", "INSERT INTO XA VALUES ('', '', '', '', '', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC',\n '', '', '', '', '', '', '', '');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT DISTINCT YM.YW AS YW,\n (SELECT YW FROM YF WHERE YF.XB = YM.XB) AS YF_YW,\n (\n SELECT YW\n FROM yp\n WHERE\n yp.XJ = YM.XJ AND\n (yp.XL = YM.XL OR (yp.XL IS NULL AND YM.XL IS NULL)) AND\n yp.XT = nd.XT\n ) AS YJ,\n XE AS XE,\n XI AS YO,\n XK AS XK,\n XM AS XM,\n CASE\n WHEN YM.XO <> 'Z'\n THEN YM.XO\n ELSE NULL\n END AS XO\n FROM (\n SELECT YW, XB, XC, XE, XF, XI, XJ, XK,\n CASE WHEN XL = 'Z' OR XL = 'Z' THEN NULL ELSE XL END AS XL,\n XM, XO\n FROM XA\n ) YM\n INNER JOIN XS nd\n ON nd.XV = XF\n WHERE\n XB IN (SELECT XB FROM YF) AND\n (XF IS NOT NULL AND XF <> 'Z')\n UNION\n SELECT DISTINCT YL.YW AS YW,\n (\n SELECT YW\n FROM YF\n WHERE YF.XB = YL.XB\n ) AS YF_YW,\n (\n SELECT YW FROM yp\n WHERE\n yp.XJ = YL.XJ AND\n (yp.XL = YL.XL OR (yp.XL IS NULL AND YL.XL IS NULL)) AND\n yp.XT = YN.XT\n ) AS YJ,\n XE AS XE,\n XI AS YO,\n XK AS XK,\n XM AS XM,\n CASE WHEN YL.XO <> 'Z' THEN YL.XO ELSE NULL END AS XO\n FROM (\n SELECT YW, XB, XC, XE, XF, XI, XJ, XK,\n CASE WHEN XL = 'Z' OR XL = 'Z' THEN NULL ELSE XL END AS XL,\n XM, XO\n FROM XA\n ) YL\n INNER JOIN XS YN\n ON YN.XC = YL.XC\n WHERE\n XB IN (SELECT XB FROM YF) AND \n (XF IS NULL OR XF = 'Z');", Expected: []sql.Row{{"", "", "", "", "", "", "", ""}}, }, }, }, { Name: "non-existent procedure in trigger body", SetUpScript: []string{ "create table tbl_I (i int primary key);", }, Assertions: []ScriptTestAssertion{ { Query: "alter table tbl_i add column j int, add check (j < 10);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, }, }, { Name: "renaming table name that is referenced in existing view", SetUpScript: []string{ "create table t1 (id int primary key, v1 int);", "insert into t1 values (1,1);", "create view v1 as select * from t1;", }, Assertions: []ScriptTestAssertion{ { Query: "select * from v1;", Expected: []sql.Row{{1, 1}}, }, { Query: "rename table t1 to t2;", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "show tables;", Expected: []sql.Row{{"myview"}, {"t2"}, {"v1"}}, }, { Query: "select * from v1;", ExpectedErrStr: "View 'v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them", }, { Query: "show create view v1;", Expected: []sql.Row{{"v1", "CREATE VIEW `v1` AS select * from t1", "utf8mb4", "utf8mb4_0900_bin"}}, ExpectedWarningsCount: 1, }, { Query: "show warnings;", Expected: []sql.Row{{"Warning", 1356, "View 'v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them"}}, }, }, }, }
var BrokenTriggerQueries = []ScriptTest{ { Name: "update common table multiple times in single insert", SetUpScript: []string{ "create table mytable (id integer PRIMARY KEY DEFAULT 0, sometext text);", "create table sequence_table (max_id integer PRIMARY KEY);", "create trigger update_position_id before insert on mytable for each row begin set new.id = (select coalesce(max(max_id),1) from sequence_table); update sequence_table set max_id = max_id + 1; end;", "insert into sequence_table values (1);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into mytable () values (), ();", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "select * from mytable order by id", Expected: []sql.Row{ {1, nil}, {2, nil}, {3, nil}, }, }, }, }, { Name: "insert into table multiple times", SetUpScript: []string{ "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT);", "CREATE TABLE test2(pk BIGINT PRIMARY KEY, v1 BIGINT);", "INSERT INTO test VALUES (0,2),(1,3)", `CREATE TRIGGER tt BEFORE INSERT ON test FOR EACH ROW BEGIN insert into test2 values (new.pk * 3, new.v1); insert into test2 values (new.pk * 5, new.v1); END;`, "INSERT INTO test VALUES (2,4), (6,8);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test ORDER BY 1", Expected: []sql.Row{ {0, 2}, {1, 3}, {2, -440}, }, }, { Query: "SELECT * FROM test2 ORDER BY 1", Expected: []sql.Row{ {2, -440}, }, }, }, }, { Name: "trigger after update, delete from other table", SetUpScript: []string{ "create table foo.a (x int primary key)", "create table foo.b (y int primary key)", "insert into foo.a values (0), (2), (4), (6), (8)", "insert into foo.b values (1), (3), (5), (7), (9)", "use foo", "create trigger insert_into_b after update on a for each row insert into b values (old.x + new.x + 1)", "use mydb", "update foo.a set x = x + 1 where x in (2,4)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from foo.a order by 1", Expected: []sql.Row{ {0}, {3}, {5}, {6}, {8}, }, }, { Query: "select y from foo.b order by 1", Expected: []sql.Row{ {1}, {3}, {7}, }, }, }, }, { Name: "trigger before update, begin block with references to other table", SetUpScript: []string{ "CREATE TABLE a (i int primary key, j int)", "INSERT INTO a VALUES (0,1),(2,3),(4,5)", "CREATE TABLE b (x int)", "INSERT INTO b VALUES (1)", "CREATE TRIGGER trig BEFORE UPDATE ON a FOR EACH ROW BEGIN SET NEW.i = (SELECT x FROM b); SET NEW.j = OLD.j + NEW.j; UPDATE b SET x = x + 1; END;", "UPDATE a SET j = 10;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM a ORDER BY 1", Expected: []sql.Row{ {1, 11}, {2, 13}, {3, 15}, }, }, { Query: "SELECT * FROM b ORDER BY x", Expected: []sql.Row{ {4}, }, }, }, }, { Name: "trigger after inserts, use updated self reference", SetUpScript: []string{ "create table a (i int primary key, j int)", "create table b (x int primary key)", "insert into b values (1)", "create trigger trig after insert on a for each row begin update b set x = (select count(*) from a); end;", "insert into a values (1,0), (2,0), (3,0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from a order by i", Expected: []sql.Row{ {1, 0}, {2, 0}, {3, 0}, }, }, { Query: "select x from b", Expected: []sql.Row{ {3}, }, }, { Query: "insert into a values (4,0), (5,0)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, }, }, }
BrokenTriggerQueries contains trigger queries that should work but do not yet
var CallAsofScripts = []ScriptTest{ { Name: "AS OF propagates to nested CALLs", SetUpScript: []string{ "CREATE PROCEDURE p1() BEGIN CALL p2(); END", "CREATE PROCEDURE p1a() BEGIN CALL p2() AS OF '2019-01-01'; END", "CREATE PROCEDURE p1b() BEGIN CALL p2a(); END", "CREATE PROCEDURE p2() BEGIN SELECT * FROM myhistorytable; END", "CREATE PROCEDURE p2a() BEGIN SELECT * FROM myhistorytable AS OF '2019-01-02'; END", }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {int64(1), "first row, 3", "1"}, {int64(2), "second row, 3", "2"}, {int64(3), "third row, 3", "3"}, }, }, { Query: "CALL p1a();", Expected: []sql.Row{ {int64(1), "first row, 1"}, {int64(2), "second row, 1"}, {int64(3), "third row, 1"}, }, }, { Query: "CALL p1b();", Expected: []sql.Row{ {int64(1), "first row, 2"}, {int64(2), "second row, 2"}, {int64(3), "third row, 2"}, }, }, { Query: "CALL p2();", Expected: []sql.Row{ {int64(1), "first row, 3", "1"}, {int64(2), "second row, 3", "2"}, {int64(3), "third row, 3", "3"}, }, }, { Query: "CALL p2a();", Expected: []sql.Row{ {int64(1), "first row, 2"}, {int64(2), "second row, 2"}, {int64(3), "third row, 2"}, }, }, { Query: "CALL p1() AS OF '2019-01-01';", Expected: []sql.Row{ {int64(1), "first row, 1"}, {int64(2), "second row, 1"}, {int64(3), "third row, 1"}, }, }, { Query: "CALL p1a() AS OF '2019-01-03';", Expected: []sql.Row{ {int64(1), "first row, 1"}, {int64(2), "second row, 1"}, {int64(3), "third row, 1"}, }, }, { Query: "CALL p1b() AS OF '2019-01-03';", Expected: []sql.Row{ {int64(1), "first row, 2"}, {int64(2), "second row, 2"}, {int64(3), "third row, 2"}, }, }, { Query: "CALL p2() AS OF '2019-01-01';", Expected: []sql.Row{ {int64(1), "first row, 1"}, {int64(2), "second row, 1"}, {int64(3), "third row, 1"}, }, }, { Query: "CALL p2a() AS OF '2019-01-03';", Expected: []sql.Row{ {int64(1), "first row, 2"}, {int64(2), "second row, 2"}, {int64(3), "third row, 2"}, }, }, }, }, }
var CharsetCollationEngineTests = []CharsetCollationEngineTest{ { Name: "Uppercase and lowercase collations", Queries: []CharsetCollationEngineTestQuery{ { Query: "CREATE TABLE test1 (v1 VARCHAR(255) COLLATE utf16_unicode_ci, v2 VARCHAR(255) COLLATE UTF16_UNICODE_CI);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CREATE TABLE test2 (v1 VARCHAR(255) CHARACTER SET utf16, v2 VARCHAR(255) CHARACTER SET UTF16);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Insert multiple character sets", SetUpScript: []string{ "CREATE TABLE test (v1 VARCHAR(255) COLLATE utf16_unicode_ci);", }, Queries: []CharsetCollationEngineTestQuery{ { Query: "INSERT INTO test VALUES ('hey');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT INTO test VALUES (_utf16'\x00h\x00i');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT INTO test VALUES (_utf8mb4'\x68\x65\x6c\x6c\x6f');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM test ORDER BY 1;", Expected: []sql.Row{{"hello"}, {"hey"}, {"hi"}}, }, }, }, { Name: "Sorting differences", SetUpScript: []string{ "CREATE TABLE test1 (v1 VARCHAR(255) COLLATE utf8mb4_0900_bin);", "CREATE TABLE test2 (v1 VARCHAR(255) COLLATE utf16_unicode_ci);", }, Queries: []CharsetCollationEngineTestQuery{ { Query: "INSERT INTO test1 VALUES ('HEY2'), ('hey1');", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "INSERT INTO test2 VALUES ('HEY2'), ('hey1');", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "SELECT * FROM test1 ORDER BY 1;", Expected: []sql.Row{{"HEY2"}, {"hey1"}}, }, { Query: "SELECT * FROM test2 ORDER BY 1;", Expected: []sql.Row{{"hey1"}, {"HEY2"}}, }, }, }, { Name: "Character set introducer with invalid collate", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT _utf16'\x00a' COLLATE utf8mb4_0900_bin;", Error: true, }, { Query: "SELECT _utf16'\x00a' COLLATE binary;", Error: true, }, }, }, { Name: "Properly block using not-yet-implemented character sets/collations", Queries: []CharsetCollationEngineTestQuery{ { Query: "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) CHARACTER SET utf16le);", ErrKind: sql.ErrCharSetNotYetImplementedTemp, }, { Query: "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) COLLATE utf16le_general_ci);", ErrKind: sql.ErrCharSetNotYetImplementedTemp, }, { Query: "CREATE TABLE test3 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) CHARACTER SET utf8mb4);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE test3 MODIFY COLUMN v1 VARCHAR(255) COLLATE utf8mb4_sr_latn_0900_as_cs;", ErrKind: sql.ErrCollationNotYetImplementedTemp, }, }, }, { Name: "Order by behaves differently according to case-sensitivity", SetUpScript: []string{ "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) COLLATE utf16_unicode_ci, INDEX(v1));", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) COLLATE utf8mb4_0900_bin, INDEX(v1));", "INSERT INTO test1 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", "INSERT INTO test2 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", }, Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT v1, pk FROM test1 ORDER BY pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test1 ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test2 ORDER BY pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test2 ORDER BY v1, pk;", Expected: []sql.Row{ {"ABC", int64(2)}, {"AbC", int64(4)}, {"aBc", int64(3)}, {"abc", int64(1)}, }, }, }, }, { Name: "Proper index access", SetUpScript: []string{ "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) COLLATE utf16_unicode_ci, INDEX(v1));", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) COLLATE utf8mb4_0900_bin, INDEX(v1));", "INSERT INTO test1 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", "INSERT INTO test2 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", }, Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT v1, pk FROM test1 WHERE v1 > 'AbC' ORDER BY v1, pk;", Expected: []sql.Row(nil), }, { Query: "SELECT v1, pk FROM test1 WHERE v1 >= 'AbC' ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test1 WHERE v1 <= 'aBc' ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test1 WHERE v1 = 'ABC' ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test1 WHERE v1 BETWEEN 'ABC' AND 'AbC' ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test1 WHERE v1 IN ('abc') ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 > 'AbC' ORDER BY v1, pk;", Expected: []sql.Row{ {"aBc", int64(3)}, {"abc", int64(1)}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 >= 'AbC' ORDER BY v1, pk;", Expected: []sql.Row{ {"AbC", int64(4)}, {"aBc", int64(3)}, {"abc", int64(1)}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 <= 'aBc' ORDER BY v1, pk;", Expected: []sql.Row{ {"ABC", int64(2)}, {"AbC", int64(4)}, {"aBc", int64(3)}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 = 'ABC' ORDER BY v1, pk;", Expected: []sql.Row{ {"ABC", int64(2)}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 BETWEEN 'ABC' AND 'AbC' ORDER BY v1, pk;", Expected: []sql.Row{ {"ABC", int64(2)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 IN ('abc') ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, }, }, }, }, { Name: "Table collation is respected", SetUpScript: []string{ "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255)) COLLATE utf16_unicode_ci;", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255)) COLLATE utf8mb4_unicode_ci;", "CREATE TABLE test3 LIKE test2;", "INSERT INTO test1 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", "INSERT INTO test2 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", "INSERT INTO test3 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", "CREATE TABLE test4 AS SELECT * FROM test2;", }, Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT v1, pk FROM test1 WHERE v1 <= 'aBc' ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 <= 'aBc' ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "ALTER TABLE test2 MODIFY COLUMN v1 VARCHAR(100);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 <= 'aBc' ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test3 WHERE v1 <= 'aBc' ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v1, pk FROM test4 WHERE v1 <= 'aBc' ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SHOW CREATE TABLE test1;", Expected: []sql.Row{ {"test1", "CREATE TABLE `test1` (\n `pk` bigint NOT NULL,\n `v1` varchar(255),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci"}, }, }, { Query: "SHOW CREATE TABLE test2;", Expected: []sql.Row{ {"test2", "CREATE TABLE `test2` (\n `pk` bigint NOT NULL,\n `v1` varchar(100),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"}, }, }, { Query: "SHOW CREATE TABLE test3;", Expected: []sql.Row{ {"test3", "CREATE TABLE `test3` (\n `pk` bigint NOT NULL,\n `v1` varchar(255),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"}, }, }, { Query: "SHOW CREATE TABLE test4;", Expected: []sql.Row{ {"test4", "CREATE TABLE `test4` (\n `pk` bigint NOT NULL,\n `v1` varchar(255) COLLATE utf8mb4_unicode_ci\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "ALTER TABLE test3 ADD COLUMN v2 VARCHAR(255);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "SHOW CREATE TABLE test3;", Expected: []sql.Row{ {"test3", "CREATE TABLE `test3` (\n `pk` bigint NOT NULL,\n `v1` varchar(255),\n `v2` varchar(255),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"}, }, }, { Query: "ALTER TABLE test2 CHANGE COLUMN v1 v1 VARCHAR(220);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "SHOW CREATE TABLE test2;", Expected: []sql.Row{ {"test2", "CREATE TABLE `test2` (\n `pk` bigint NOT NULL,\n `v1` varchar(220),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"}, }, }, { Query: "ALTER TABLE test2 CHARACTER SET latin1 COLLATE utf8mb4_bin;", Error: true, }, { Query: "ALTER TABLE test2 COLLATE utf8mb4_bin;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "ALTER TABLE test2 ADD COLUMN v2 VARCHAR(255);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "REPLACE INTO test2 VALUES (1, 'abc', 'abc'), (2, 'ABC', 'ABC'), (3, 'aBc', 'aBc'), (4, 'AbC', 'AbC');", Expected: []sql.Row{ {types.NewOkResult(8)}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 <= 'aBc' ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", int64(1)}, {"ABC", int64(2)}, {"aBc", int64(3)}, {"AbC", int64(4)}, }, }, { Query: "SELECT v2, pk FROM test2 WHERE v2 <= 'aBc' ORDER BY v2, pk;", Expected: []sql.Row{ {"ABC", int64(2)}, {"AbC", int64(4)}, {"aBc", int64(3)}, }, }, { Query: "SHOW CREATE TABLE test2;", Expected: []sql.Row{ {"test2", "CREATE TABLE `test2` (\n `pk` bigint NOT NULL,\n `v1` varchar(220) COLLATE utf8mb4_unicode_ci,\n `v2` varchar(255),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"}, }, }, }, }, { Name: "SET NAMES does not interfere with column charset", SetUpScript: []string{ "SET NAMES utf8mb3;", "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 VARCHAR(100) COLLATE utf8mb4_0900_bin);", "INSERT INTO test VALUES (1, 'a'), (2, 'b');", }, Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT * FROM test ORDER BY v1 COLLATE utf8mb4_bin ASC;", Expected: []sql.Row{{int64(1), "a"}, {int64(2), "b"}}, }, { Query: "SELECT * FROM test ORDER BY v1 COLLATE utf8mb3_bin ASC;", ErrKind: sql.ErrCollationInvalidForCharSet, }, { Query: "SELECT 'a' COLLATE utf8mb3_bin;", Expected: []sql.Row{{"a"}}, }, { Query: "SELECT 'a' COLLATE utf8mb4_bin;", ErrKind: sql.ErrCollationInvalidForCharSet, }, }, }, { Name: "ENUM collation handling", SetUpScript: []string{ "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 ENUM('abc','def','ghi') COLLATE utf16_unicode_ci);", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 ENUM('abc','def','ghi') COLLATE utf8mb4_0900_bin);", }, Queries: []CharsetCollationEngineTestQuery{ { Query: "INSERT INTO test1 VALUES (1, 'ABC');", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "INSERT INTO test2 VALUES (1, 'ABC');", Error: true, }, { Query: "INSERT INTO test1 VALUES (2, _utf16'\x00d\x00e\x00f' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "INSERT INTO test2 VALUES (2, _utf16'\x00d\x00e\x00f' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "SELECT * FROM test1 ORDER BY pk;", Expected: []sql.Row{ {int64(1), uint16(1)}, {int64(2), uint16(2)}, }, }, { Query: "SELECT * FROM test2 ORDER BY pk;", Expected: []sql.Row{ {int64(2), uint16(2)}, }, }, }, }, { Name: "SET collation handling", SetUpScript: []string{ "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 SET('a','b','c') COLLATE utf16_unicode_ci);", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 SET('a','b','c') COLLATE utf8mb4_0900_bin);", }, Queries: []CharsetCollationEngineTestQuery{ { Query: "INSERT INTO test1 VALUES (1, 'A');", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "INSERT INTO test2 VALUES (1, 'A');", Error: true, }, { Query: "INSERT INTO test1 VALUES (2, _utf16'\x00b\x00,\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "INSERT INTO test2 VALUES (2, _utf16'\x00b\x00,\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "SELECT * FROM test1 ORDER BY pk;", Expected: []sql.Row{ {int64(1), uint64(1)}, {int64(2), uint64(6)}, }, }, { Query: "SELECT * FROM test2 ORDER BY pk;", Expected: []sql.Row{ {int64(2), uint64(6)}, }, }, }, }, { Name: "LIKE respects table collations", SetUpScript: []string{ "SET NAMES utf8mb4;", "CREATE TABLE test(v1 VARCHAR(100) COLLATE utf8mb4_0900_bin, v2 VARCHAR(100) COLLATE utf8mb4_0900_ai_ci);", "INSERT INTO test VALUES ('abc', 'abc'), ('ABC', 'ABC');", }, Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT COUNT(*) FROM test WHERE v1 LIKE 'ABC';", Expected: []sql.Row{ {int64(1)}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v2 LIKE 'ABC';", Expected: []sql.Row{ {int64(2)}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v1 LIKE 'A%';", Expected: []sql.Row{ {int64(1)}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v2 LIKE 'A%';", Expected: []sql.Row{ {int64(2)}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v1 LIKE '%C';", Expected: []sql.Row{ {int64(1)}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v2 LIKE '%C';", Expected: []sql.Row{ {int64(2)}, }, }, { Query: "SET collation_connection = 'utf8mb4_0900_bin';", Expected: []sql.Row{{}}, }, { Query: "SELECT COUNT(*) FROM test WHERE v1 LIKE 'ABC';", Expected: []sql.Row{ {int64(1)}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v2 LIKE 'ABC';", Expected: []sql.Row{ {int64(2)}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v1 LIKE 'ABC' COLLATE utf8mb4_0900_ai_ci;", Expected: []sql.Row{ {int64(2)}, }, }, }, }, { Name: "LIKE respects connection collation", SetUpScript: []string{ "SET NAMES utf8mb4;", }, Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT 'abc' LIKE 'ABC';", Expected: []sql.Row{ {true}, }, }, { Query: "SELECT 'abc' COLLATE utf8mb4_0900_bin LIKE 'ABC';", Expected: []sql.Row{ {false}, }, }, { Query: "SELECT 'abc' LIKE 'ABC' COLLATE utf8mb4_0900_bin;", Expected: []sql.Row{ {false}, }, }, { Query: "SELECT 'abc' COLLATE utf8mb4_0900_ai_ci LIKE 'ABC';", Expected: []sql.Row{ {true}, }, }, { Query: "SELECT 'abc' LIKE 'ABC' COLLATE utf8mb4_0900_ai_ci;", Expected: []sql.Row{ {true}, }, }, { Query: "SET collation_connection = 'utf8mb4_0900_bin';", Expected: []sql.Row{{}}, }, { Query: "SELECT 'abc' LIKE 'ABC';", Expected: []sql.Row{ {false}, }, }, { Query: "SELECT 'abc' COLLATE utf8mb4_0900_ai_ci LIKE 'ABC';", Expected: []sql.Row{ {true}, }, }, { Query: "SELECT 'abc' LIKE 'ABC' COLLATE utf8mb4_0900_ai_ci;", Expected: []sql.Row{ {true}, }, }, { Query: "SELECT 'abc' COLLATE utf8mb4_0900_bin LIKE 'ABC';", Expected: []sql.Row{ {false}, }, }, { Query: "SELECT 'abc' LIKE 'ABC' COLLATE utf8mb4_0900_bin;", Expected: []sql.Row{ {false}, }, }, { Query: "SELECT _utf8mb4'abc' LIKE 'ABC';", Expected: []sql.Row{ {false}, }, }, { Query: "SELECT 'abc' LIKE _utf8mb4'ABC';", Expected: []sql.Row{ {false}, }, }, }, }, { Name: "STRCMP() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT STRCMP(_utf8mb4'A' COLLATE utf8mb4_0900_ai_ci, _latin1'b' COLLATE latin1_general_cs)", Expected: []sql.Row{ {int(-1)}, }, }, }, }, { Name: "LENGTH() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT LENGTH(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {int32(6)}, }, }, { Query: "SELECT LENGTH(_utf8mb4'abc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {int32(3)}, }, }, { Query: "SELECT LENGTH(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {int32(6)}, }, }, }, }, { Name: "CHAR_LENGTH() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT CHAR_LENGTH(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {int32(3)}, }, }, { Query: "SELECT CHAR_LENGTH(_utf8mb4'abc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {int32(3)}, }, }, { Query: "SELECT CHAR_LENGTH(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {int32(6)}, }, }, }, }, { Name: "UPPER() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT UPPER(_utf16'\x00a\x00B\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"ABC"}, }, }, { Query: "SELECT UPPER(_utf8mb4'aBc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"ABC"}, }, }, { Query: "SELECT UPPER(_utf8mb4'\x00a\x00B\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00A\x00B\x00C"}, }, }, }, }, { Name: "LOWER() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT LOWER(_utf16'\x00A\x00b\x00C' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"abc"}, }, }, { Query: "SELECT LOWER(_utf8mb4'AbC' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abc"}, }, }, { Query: "SELECT LOWER(_utf8mb4'\x00A\x00b\x00C' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, }, }, { Name: "RPAD() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT RPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, 'z');", Expected: []sql.Row{ {"abczzz"}, }, }, { Query: "SELECT RPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, _utf8mb4'z' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abczzz"}, }, }, { Query: "SELECT RPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"abczzz"}, }, }, { Query: "SELECT RPAD(_utf8mb4'abc' COLLATE utf8mb4_0900_bin, 6, _utf8mb4'z' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abczzz"}, }, }, { Query: "SELECT RPAD(_utf8mb4'abc' COLLATE utf8mb4_0900_bin, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"abczzz"}, }, }, { Query: "SELECT RPAD(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, { Query: "SELECT RPAD(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin, 9, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00a\x00b\x00czzz"}, }, }, }, }, { Name: "LPAD() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT LPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, 'z');", Expected: []sql.Row{ {"zzzabc"}, }, }, { Query: "SELECT LPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, _utf8mb4'z' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"zzzabc"}, }, }, { Query: "SELECT LPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"zzzabc"}, }, }, { Query: "SELECT LPAD(_utf8mb4'abc' COLLATE utf8mb4_0900_bin, 6, _utf8mb4'z' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"zzzabc"}, }, }, { Query: "SELECT LPAD(_utf8mb4'abc' COLLATE utf8mb4_0900_bin, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"zzzabc"}, }, }, { Query: "SELECT LPAD(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, { Query: "SELECT LPAD(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin, 9, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"zzz\x00a\x00b\x00c"}, }, }, }, }, { Name: "HEX() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT HEX(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"006100620063"}, }, }, { Query: "SELECT HEX(_utf8mb4'abc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"616263"}, }, }, { Query: "SELECT HEX(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"006100620063"}, }, }, }, }, { Name: "UNHEX() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT UNHEX(_utf16'\x006\x001\x006\x002\x006\x003' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {[]byte("abc")}, }, }, { Query: "SELECT UNHEX(_utf8mb4'616263' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {[]byte("abc")}, }, }, }, }, { Name: "SUBSTRING() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT SUBSTRING(_utf16'\x00a\x00b\x00c\x00d' COLLATE utf16_unicode_ci, 2, 2);", Expected: []sql.Row{ {"bc"}, }, }, { Query: "SELECT SUBSTRING(_utf8mb4'abcd' COLLATE utf8mb4_0900_bin, 2, 2);", Expected: []sql.Row{ {"bc"}, }, }, { Query: "SELECT SUBSTRING(_utf8mb4'\x00a\x00b\x00c\x00d' COLLATE utf8mb4_0900_bin, 2, 2);", Expected: []sql.Row{ {"a\x00"}, }, }, }, }, { Name: "TO_BASE64() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT TO_BASE64(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"AGEAYgBj"}, }, }, { Query: "SELECT TO_BASE64(_utf8mb4'abc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"YWJj"}, }, }, { Query: "SELECT TO_BASE64(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"AGEAYgBj"}, }, }, }, }, { Name: "FROM_BASE64() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT FROM_BASE64(_utf16'\x00Y\x00W\x00J\x00j' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {[]byte("abc")}, }, }, { Query: "SELECT FROM_BASE64(_utf8mb4'YWJj' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {[]byte("abc")}, }, }, }, }, { Name: "TRIM() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT TRIM(_utf16'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"abc"}, }, }, { Query: "SELECT TRIM(_utf8mb4' abc ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abc"}, }, }, { Query: "SELECT TRIM(_utf8mb4'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00 \x00a\x00b\x00c\x00"}, }, }, }, }, { Name: "RTRIM() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT RTRIM(_utf16'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {" abc"}, }, }, { Query: "SELECT RTRIM(_utf8mb4' abc ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {" abc"}, }, }, { Query: "SELECT RTRIM(_utf8mb4'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00 \x00a\x00b\x00c\x00"}, }, }, }, }, { Name: "LTRIM() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT LTRIM(_utf16'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"abc "}, }, }, { Query: "SELECT LTRIM(_utf8mb4' abc ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abc "}, }, }, { Query: "SELECT LTRIM(_utf8mb4'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00 \x00a\x00b\x00c\x00 "}, }, }, }, }, { Name: "BINARY() function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT BINARY(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {[]byte("\x00a\x00b\x00c")}, }, }, { Query: "SELECT BINARY(_utf8mb4'abc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {[]byte("abc")}, }, }, { Query: "SELECT BINARY(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {[]byte("\x00a\x00b\x00c")}, }, }, }, }, { Name: "CAST(... AS BINARY) function", Queries: []CharsetCollationEngineTestQuery{ { Query: "SELECT CAST(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci AS BINARY);", Expected: []sql.Row{ {[]byte("\x00a\x00b\x00c")}, }, }, { Query: "SELECT CAST(_utf8mb4'abc' COLLATE utf8mb4_0900_bin AS BINARY);", Expected: []sql.Row{ {[]byte("abc")}, }, }, { Query: "SELECT CAST(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin AS BINARY);", Expected: []sql.Row{ {[]byte("\x00a\x00b\x00c")}, }, }, }, }, { Name: "Issue #5482", Queries: []CharsetCollationEngineTestQuery{ { Query: `SELECT T.TABLE_NAME AS label, 'connection.table' as type, T.TABLE_SCHEMA AS 'schema', T.TABLE_SCHEMA AS 'database', T.TABLE_CATALOG AS 'catalog', 0 AS isView FROM INFORMATION_SCHEMA.TABLES AS T WHERE T.TABLE_CATALOG = 'def' AND UPPER(T.TABLE_TYPE) = 'BASE TABLE' ORDER BY T.TABLE_NAME;`, Expected: []sql.Row(nil), }, }, }, }
CharsetCollationEngineTests are used to ensure that character sets and collations have the correct behavior over the engine. Return values should all have the `utf8mb4` encoding, as it's returning the internal encoding type.
var CharsetCollationWireTests = []CharsetCollationWireTest{ { Name: "Uppercase and lowercase collations", Queries: []CharsetCollationWireTestQuery{ { Query: "CREATE TABLE test1 (v1 VARCHAR(255) COLLATE utf16_unicode_ci, v2 VARCHAR(255) COLLATE UTF16_UNICODE_CI);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CREATE TABLE test2 (v1 VARCHAR(255) CHARACTER SET utf16, v2 VARCHAR(255) CHARACTER SET UTF16);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Insert multiple character sets", SetUpScript: []string{ "SET character_set_results = 'binary';", "CREATE TABLE test (v1 VARCHAR(255) COLLATE utf16_unicode_ci);", }, Queries: []CharsetCollationWireTestQuery{ { Query: "INSERT INTO test VALUES ('hey');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT INTO test VALUES (_utf16'\x00h\x00i');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT INTO test VALUES (_utf8mb4'\x68\x65\x6c\x6c\x6f');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM test ORDER BY 1;", Expected: []sql.Row{{"\x00h\x00e\x00l\x00l\x00o"}, {"\x00h\x00e\x00y"}, {"\x00h\x00i"}}, }, }, }, { Name: "Sorting differences", SetUpScript: []string{ "SET character_set_results = 'binary';", "CREATE TABLE test1 (v1 VARCHAR(255) COLLATE utf8mb4_0900_bin);", "CREATE TABLE test2 (v1 VARCHAR(255) COLLATE utf16_unicode_ci);", }, Queries: []CharsetCollationWireTestQuery{ { Query: "INSERT INTO test1 VALUES ('HEY2'), ('hey1');", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "INSERT INTO test2 VALUES ('HEY2'), ('hey1');", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "SELECT * FROM test1 ORDER BY 1;", Expected: []sql.Row{{"HEY2"}, {"hey1"}}, }, { Query: "SELECT * FROM test2 ORDER BY 1;", Expected: []sql.Row{{"\x00h\x00e\x00y\x001"}, {"\x00H\x00E\x00Y\x002"}}, }, }, }, { Name: "Order by behaves differently according to case-sensitivity", SetUpScript: []string{ "SET character_set_results = 'binary';", "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) COLLATE utf16_unicode_ci, INDEX(v1));", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) COLLATE utf8mb4_0900_bin, INDEX(v1));", "INSERT INTO test1 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", "INSERT INTO test2 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT v1, pk FROM test1 ORDER BY pk;", Expected: []sql.Row{ {"\x00a\x00b\x00c", "1"}, {"\x00A\x00B\x00C", "2"}, {"\x00a\x00B\x00c", "3"}, {"\x00A\x00b\x00C", "4"}, }, }, { Query: "SELECT v1, pk FROM test1 ORDER BY v1, pk;", Expected: []sql.Row{ {"\x00a\x00b\x00c", "1"}, {"\x00A\x00B\x00C", "2"}, {"\x00a\x00B\x00c", "3"}, {"\x00A\x00b\x00C", "4"}, }, }, { Query: "SELECT v1, pk FROM test2 ORDER BY pk;", Expected: []sql.Row{ {"abc", "1"}, {"ABC", "2"}, {"aBc", "3"}, {"AbC", "4"}, }, }, { Query: "SELECT v1, pk FROM test2 ORDER BY v1, pk;", Expected: []sql.Row{ {"ABC", "2"}, {"AbC", "4"}, {"aBc", "3"}, {"abc", "1"}, }, }, }, }, { Name: "Proper index access", SetUpScript: []string{ "SET character_set_results = 'binary';", "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) COLLATE utf16_unicode_ci, INDEX(v1));", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 VARCHAR(255) COLLATE utf8mb4_0900_bin, INDEX(v1));", "INSERT INTO test1 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", "INSERT INTO test2 VALUES (1, 'abc'), (2, 'ABC'), (3, 'aBc'), (4, 'AbC');", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT v1, pk FROM test1 WHERE v1 > 'AbC' ORDER BY v1, pk;", Expected: []sql.Row(nil), }, { Query: "SELECT v1, pk FROM test1 WHERE v1 >= 'AbC' ORDER BY v1, pk;", Expected: []sql.Row{ {"\x00a\x00b\x00c", "1"}, {"\x00A\x00B\x00C", "2"}, {"\x00a\x00B\x00c", "3"}, {"\x00A\x00b\x00C", "4"}, }, }, { Query: "SELECT v1, pk FROM test1 WHERE v1 <= 'aBc' ORDER BY v1, pk;", Expected: []sql.Row{ {"\x00a\x00b\x00c", "1"}, {"\x00A\x00B\x00C", "2"}, {"\x00a\x00B\x00c", "3"}, {"\x00A\x00b\x00C", "4"}, }, }, { Query: "SELECT v1, pk FROM test1 WHERE v1 = 'ABC' ORDER BY v1, pk;", Expected: []sql.Row{ {"\x00a\x00b\x00c", "1"}, {"\x00A\x00B\x00C", "2"}, {"\x00a\x00B\x00c", "3"}, {"\x00A\x00b\x00C", "4"}, }, }, { Query: "SELECT v1, pk FROM test1 WHERE v1 BETWEEN 'ABC' AND 'AbC' ORDER BY v1, pk;", Expected: []sql.Row{ {"\x00a\x00b\x00c", "1"}, {"\x00A\x00B\x00C", "2"}, {"\x00a\x00B\x00c", "3"}, {"\x00A\x00b\x00C", "4"}, }, }, { Query: "SELECT v1, pk FROM test1 WHERE v1 IN ('abc') ORDER BY v1, pk;", Expected: []sql.Row{ {"\x00a\x00b\x00c", "1"}, {"\x00A\x00B\x00C", "2"}, {"\x00a\x00B\x00c", "3"}, {"\x00A\x00b\x00C", "4"}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 > 'AbC' ORDER BY v1, pk;", Expected: []sql.Row{ {"aBc", "3"}, {"abc", "1"}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 >= 'AbC' ORDER BY v1, pk;", Expected: []sql.Row{ {"AbC", "4"}, {"aBc", "3"}, {"abc", "1"}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 <= 'aBc' ORDER BY v1, pk;", Expected: []sql.Row{ {"ABC", "2"}, {"AbC", "4"}, {"aBc", "3"}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 = 'ABC' ORDER BY v1, pk;", Expected: []sql.Row{ {"ABC", "2"}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 BETWEEN 'ABC' AND 'AbC' ORDER BY v1, pk;", Expected: []sql.Row{ {"ABC", "2"}, {"AbC", "4"}, }, }, { Query: "SELECT v1, pk FROM test2 WHERE v1 IN ('abc') ORDER BY v1, pk;", Expected: []sql.Row{ {"abc", "1"}, }, }, }, }, { Name: "SET NAMES does not interfere with column charset", SetUpScript: []string{ "SET NAMES utf8mb3;", "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 VARCHAR(100) COLLATE utf8mb4_0900_bin);", "INSERT INTO test VALUES (1, 'a'), (2, 'b');", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT * FROM test ORDER BY v1 COLLATE utf8mb4_bin ASC;", Expected: []sql.Row{{"1", "a"}, {"2", "b"}}, }, { Query: "SELECT * FROM test ORDER BY v1 COLLATE utf8mb3_bin ASC;", Error: true, }, { Query: "SELECT 'a' COLLATE utf8mb3_bin;", Expected: []sql.Row{{"a"}}, }, { Query: "SELECT 'a' COLLATE utf8mb4_bin;", Error: true, }, }, }, { Name: "Coercibility test using HEX", SetUpScript: []string{ "SET NAMES utf8mb4;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT HEX(UNHEX('c0a80000')) = 'c0a80000'", Expected: []sql.Row{{"1"}}, }, { Query: "SET collation_connection = 'utf8mb4_0900_bin';", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT HEX(UNHEX('c0a80000')) = 'c0a80000'", Expected: []sql.Row{{"0"}}, }, }, }, { Name: "ENUM collation handling", SetUpScript: []string{ "SET character_set_results = 'binary';", "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 ENUM('abc','def','ghi') COLLATE utf16_unicode_ci);", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 ENUM('abc','def','ghi') COLLATE utf8mb4_0900_bin);", }, Queries: []CharsetCollationWireTestQuery{ { Query: "INSERT INTO test1 VALUES (1, 'ABC');", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "INSERT INTO test2 VALUES (1, 'ABC');", Error: true, }, { Query: "INSERT INTO test1 VALUES (2, _utf16'\x00d\x00e\x00f' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "INSERT INTO test2 VALUES (2, _utf16'\x00d\x00e\x00f' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "SELECT * FROM test1 ORDER BY pk;", Expected: []sql.Row{ {"1", "\x00a\x00b\x00c"}, {"2", "\x00d\x00e\x00f"}, }, }, { Query: "SELECT * FROM test2 ORDER BY pk;", Expected: []sql.Row{ {"2", "def"}, }, }, }, }, { Name: "SET collation handling", SetUpScript: []string{ "SET character_set_results = 'binary';", "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 SET('a','b','c') COLLATE utf16_unicode_ci);", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 SET('a','b','c') COLLATE utf8mb4_0900_bin);", }, Queries: []CharsetCollationWireTestQuery{ { Query: "INSERT INTO test1 VALUES (1, 'A');", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "INSERT INTO test2 VALUES (1, 'A');", Error: true, }, { Query: "INSERT INTO test1 VALUES (2, _utf16'\x00b\x00,\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "INSERT INTO test2 VALUES (2, _utf16'\x00b\x00,\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "SELECT * FROM test1 ORDER BY pk;", Expected: []sql.Row{ {"1", "\x00a"}, {"2", "\x00b\x00,\x00c"}, }, }, { Query: "SELECT * FROM test2 ORDER BY pk;", Expected: []sql.Row{ {"2", "b,c"}, }, }, }, }, { Name: "Correct behavior with `character_set_results`", SetUpScript: []string{ "SET character_set_results = 'binary';", "CREATE TABLE test (v1 VARCHAR(255) COLLATE utf16_unicode_ci);", "INSERT INTO test VALUES (_utf8mb4'hey');", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT * FROM test;", Expected: []sql.Row{{"\x00h\x00e\x00y"}}, }, { Query: "SET character_set_results = 'utf8mb4';", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test;", Expected: []sql.Row{{"hey"}}, }, { Query: "SET character_set_results = 'utf32';", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test;", Expected: []sql.Row{{"\x00\x00\x00h\x00\x00\x00e\x00\x00\x00y"}}, }, }, }, { Name: "LIKE respects table collations", SetUpScript: []string{ "SET NAMES utf8mb4;", "CREATE TABLE test(v1 VARCHAR(100) COLLATE utf8mb4_0900_bin, v2 VARCHAR(100) COLLATE utf8mb4_0900_ai_ci);", "INSERT INTO test VALUES ('abc', 'abc'), ('ABC', 'ABC');", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT COUNT(*) FROM test WHERE v1 LIKE 'ABC';", Expected: []sql.Row{ {"1"}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v2 LIKE 'ABC';", Expected: []sql.Row{ {"2"}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v1 LIKE 'A%';", Expected: []sql.Row{ {"1"}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v2 LIKE 'A%';", Expected: []sql.Row{ {"2"}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v1 LIKE '%C';", Expected: []sql.Row{ {"1"}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v2 LIKE '%C';", Expected: []sql.Row{ {"2"}, }, }, { Query: "SET collation_connection = 'utf8mb4_0900_bin';", Expected: []sql.Row{{}}, }, { Query: "SELECT COUNT(*) FROM test WHERE v1 LIKE 'ABC';", Expected: []sql.Row{ {"1"}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v2 LIKE 'ABC';", Expected: []sql.Row{ {"2"}, }, }, { Query: "SELECT COUNT(*) FROM test WHERE v1 LIKE 'ABC' COLLATE utf8mb4_0900_ai_ci;", Expected: []sql.Row{ {"2"}, }, }, }, }, { Name: "LIKE respects connection collation", SetUpScript: []string{ "SET NAMES utf8mb4;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT 'abc' LIKE 'ABC';", Expected: []sql.Row{ {"1"}, }, }, { Query: "SELECT 'abc' COLLATE utf8mb4_0900_bin LIKE 'ABC';", Expected: []sql.Row{ {"0"}, }, }, { Query: "SELECT 'abc' LIKE 'ABC' COLLATE utf8mb4_0900_bin;", Expected: []sql.Row{ {"0"}, }, }, { Query: "SELECT 'abc' COLLATE utf8mb4_0900_ai_ci LIKE 'ABC';", Expected: []sql.Row{ {"1"}, }, }, { Query: "SELECT 'abc' LIKE 'ABC' COLLATE utf8mb4_0900_ai_ci;", Expected: []sql.Row{ {"1"}, }, }, { Query: "SET collation_connection = 'utf8mb4_0900_bin';", Expected: []sql.Row{{}}, }, { Query: "SELECT 'abc' LIKE 'ABC';", Expected: []sql.Row{ {"0"}, }, }, { Query: "SELECT 'abc' COLLATE utf8mb4_0900_ai_ci LIKE 'ABC';", Expected: []sql.Row{ {"1"}, }, }, { Query: "SELECT 'abc' LIKE 'ABC' COLLATE utf8mb4_0900_ai_ci;", Expected: []sql.Row{ {"1"}, }, }, { Query: "SELECT 'abc' COLLATE utf8mb4_0900_bin LIKE 'ABC';", Expected: []sql.Row{ {"0"}, }, }, { Query: "SELECT 'abc' LIKE 'ABC' COLLATE utf8mb4_0900_bin;", Expected: []sql.Row{ {"0"}, }, }, { Query: "SELECT _utf8mb4'abc' LIKE 'ABC';", Expected: []sql.Row{ {"0"}, }, }, { Query: "SELECT 'abc' LIKE _utf8mb4'ABC';", Expected: []sql.Row{ {"0"}, }, }, }, }, { Name: "STRCMP() function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT STRCMP(_utf8mb4'A' COLLATE utf8mb4_0900_ai_ci, _latin1'b' COLLATE latin1_general_cs)", Expected: []sql.Row{ {"-1"}, }, }, }, }, { Name: "LENGTH() function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT LENGTH(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"6"}, }, }, { Query: "SELECT LENGTH(_utf8mb4'abc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"3"}, }, }, { Query: "SELECT LENGTH(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"6"}, }, }, }, }, { Name: "CHAR_LENGTH() function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT CHAR_LENGTH(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"3"}, }, }, { Query: "SELECT CHAR_LENGTH(_utf8mb4'abc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"3"}, }, }, { Query: "SELECT CHAR_LENGTH(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"6"}, }, }, }, }, { Name: "UPPER() function", SetUpScript: []string{ "SET character_set_results = 'binary';", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT UPPER(_utf16'\x00a\x00B\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00A\x00B\x00C"}, }, }, { Query: "SELECT UPPER(_utf8mb4'aBc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"ABC"}, }, }, { Query: "SELECT UPPER(_utf8mb4'\x00a\x00B\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00A\x00B\x00C"}, }, }, }, }, { Name: "LOWER() function", SetUpScript: []string{ "SET character_set_results = 'binary';", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT LOWER(_utf16'\x00A\x00b\x00C' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, { Query: "SELECT LOWER(_utf8mb4'AbC' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abc"}, }, }, { Query: "SELECT LOWER(_utf8mb4'\x00A\x00b\x00C' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, }, }, { Name: "RPAD() function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT RPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, 'z');", Expected: []sql.Row{ {"abczzz"}, }, }, { Query: "SELECT RPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, _utf8mb4'z' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abczzz"}, }, }, { Query: "SELECT RPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"abczzz"}, }, }, { Query: "SELECT RPAD(_utf8mb4'abc' COLLATE utf8mb4_0900_bin, 6, _utf8mb4'z' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abczzz"}, }, }, { Query: "SELECT RPAD(_utf8mb4'abc' COLLATE utf8mb4_0900_bin, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"abczzz"}, }, }, { Query: "SELECT RPAD(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, { Query: "SELECT RPAD(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin, 9, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00a\x00b\x00czzz"}, }, }, }, }, { Name: "LPAD() function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT LPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, 'z');", Expected: []sql.Row{ {"zzzabc"}, }, }, { Query: "SELECT LPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, _utf8mb4'z' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"zzzabc"}, }, }, { Query: "SELECT LPAD(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"zzzabc"}, }, }, { Query: "SELECT LPAD(_utf8mb4'abc' COLLATE utf8mb4_0900_bin, 6, _utf8mb4'z' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"zzzabc"}, }, }, { Query: "SELECT LPAD(_utf8mb4'abc' COLLATE utf8mb4_0900_bin, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"zzzabc"}, }, }, { Query: "SELECT LPAD(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin, 6, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, { Query: "SELECT LPAD(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin, 9, _utf16'\x00z' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"zzz\x00a\x00b\x00c"}, }, }, }, }, { Name: "HEX() function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT HEX(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"006100620063"}, }, }, { Query: "SELECT HEX(_utf8mb4'abc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"616263"}, }, }, { Query: "SELECT HEX(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"006100620063"}, }, }, }, }, { Name: "UNHEX() function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT UNHEX(_utf16'\x006\x001\x006\x002\x006\x003' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"abc"}, }, }, { Query: "SELECT UNHEX(_utf8mb4'616263' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abc"}, }, }, }, }, { Name: "SUBSTRING() function", SetUpScript: []string{ "SET character_set_results = 'binary';", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT SUBSTRING(_utf16'\x00a\x00b\x00c\x00d' COLLATE utf16_unicode_ci, 2, 2);", Expected: []sql.Row{ {"\x00b\x00c"}, }, }, { Query: "SELECT SUBSTRING(_utf8mb4'abcd' COLLATE utf8mb4_0900_bin, 2, 2);", Expected: []sql.Row{ {"bc"}, }, }, { Query: "SELECT SUBSTRING(_utf8mb4'\x00a\x00b\x00c\x00d' COLLATE utf8mb4_0900_bin, 2, 2);", Expected: []sql.Row{ {"a\x00"}, }, }, }, }, { Name: "TO_BASE64() function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT TO_BASE64(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"AGEAYgBj"}, }, }, { Query: "SELECT TO_BASE64(_utf8mb4'abc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"YWJj"}, }, }, { Query: "SELECT TO_BASE64(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"AGEAYgBj"}, }, }, }, }, { Name: "FROM_BASE64() function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT FROM_BASE64(_utf16'\x00Y\x00W\x00J\x00j' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"abc"}, }, }, { Query: "SELECT FROM_BASE64(_utf8mb4'YWJj' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abc"}, }, }, }, }, { Name: "TRIM() function", SetUpScript: []string{ "SET character_set_results = 'binary';", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT TRIM(_utf16'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, { Query: "SELECT TRIM(_utf8mb4' abc ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abc"}, }, }, { Query: "SELECT TRIM(_utf8mb4'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00 \x00a\x00b\x00c\x00"}, }, }, }, }, { Name: "RTRIM() function", SetUpScript: []string{ "SET character_set_results = 'binary';", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT RTRIM(_utf16'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00 \x00a\x00b\x00c"}, }, }, { Query: "SELECT RTRIM(_utf8mb4' abc ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {" abc"}, }, }, { Query: "SELECT RTRIM(_utf8mb4'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00 \x00a\x00b\x00c\x00"}, }, }, }, }, { Name: "LTRIM() function", SetUpScript: []string{ "SET character_set_results = 'binary';", }, Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT LTRIM(_utf16'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00a\x00b\x00c\x00 "}, }, }, { Query: "SELECT LTRIM(_utf8mb4' abc ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abc "}, }, }, { Query: "SELECT LTRIM(_utf8mb4'\x00 \x00a\x00b\x00c\x00 ' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00 \x00a\x00b\x00c\x00 "}, }, }, }, }, { Name: "BINARY() function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT BINARY(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, { Query: "SELECT BINARY(_utf8mb4'abc' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"abc"}, }, }, { Query: "SELECT BINARY(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, }, }, { Name: "CAST(... AS BINARY) function", Queries: []CharsetCollationWireTestQuery{ { Query: "SELECT CAST(_utf16'\x00a\x00b\x00c' COLLATE utf16_unicode_ci AS BINARY);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, { Query: "SELECT CAST(_utf8mb4'abc' COLLATE utf8mb4_0900_bin AS BINARY);", Expected: []sql.Row{ {"abc"}, }, }, { Query: "SELECT CAST(_utf8mb4'\x00a\x00b\x00c' COLLATE utf8mb4_0900_bin AS BINARY);", Expected: []sql.Row{ {"\x00a\x00b\x00c"}, }, }, }, }, }
CharsetCollationWireTests are used to ensure that character sets and collations have the correct behavior over the wire. Return values should all have the table encoding, as it's returning the table's encoding type.
var ChecksOnUpdateScriptTests = []ScriptTest{ { Name: "Single table updates", SetUpScript: []string{ "CREATE TABLE t1 (a INTEGER PRIMARY KEY, b INTEGER)", "ALTER TABLE t1 ADD CONSTRAINT chk1 CHECK (b > 10) NOT ENFORCED", "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (b > 0)", "ALTER TABLE t1 ADD CONSTRAINT chk3 CHECK ((a + b) / 2 >= 1) ENFORCED", "INSERT INTO t1 VALUES (1,1)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t1;", Expected: []sql.Row{{1, 1}}, }, { Query: "UPDATE t1 set b = 0;", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "UPDATE t1 set a = 0, b = 1;", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "UPDATE t1 set b = 0 WHERE b = 1;", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "UPDATE t1 set a = 0, b = 1 WHERE b = 1;", ExpectedErr: sql.ErrCheckConstraintViolated, }, }, }, { Name: "Update join updates", SetUpScript: []string{ "CREATE TABLE sales (year_built int primary key, CONSTRAINT `valid_year_built` CHECK (year_built <= 2022));", "INSERT INTO sales VALUES (1981);", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE sales JOIN (SELECT year_built FROM sales) AS t ON sales.year_built = t.year_built SET sales.year_built = 1901;", Expected: []sql.Row{{types.OkResult{1, 0, plan.UpdateInfo{1, 1, 0}}}}, }, { Query: "select * from sales;", Expected: []sql.Row{{1901}}, }, { Query: "UPDATE sales as s1 JOIN (SELECT year_built FROM sales) AS t SET S1.year_built = 1902;", Expected: []sql.Row{{types.OkResult{1, 0, plan.UpdateInfo{1, 1, 0}}}}, }, { Query: "select * from sales;", Expected: []sql.Row{{1902}}, }, { Query: "UPDATE sales as s1 JOIN (SELECT year_built FROM sales) AS t SET t.year_built = 1903;", ExpectedErr: plan.ErrUpdateForTableNotSupported, }, { Query: "UPDATE sales JOIN (SELECT year_built FROM sales) AS t SET sales.year_built = 2030;", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "UPDATE sales as s1 JOIN (SELECT year_built FROM sales) AS t SET s1.year_built = 2030;", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "UPDATE sales as s1 JOIN (SELECT year_built FROM sales) AS t SET t.year_built = 2030;", ExpectedErr: plan.ErrUpdateForTableNotSupported, }, }, }, }
var CollationCoercionSetup = []string{
`SET CHARACTER SET "utf8mb4";`,
`SET collation_connection = "utf8mb4_0900_bin";`,
`SET character_set_results = "binary";`,
`CREATE TABLE temp_tbl (v1 VARCHAR(200) COLLATE utf8mb4_0900_bin,
v2 VARCHAR(200) COLLATE utf8mb4_0900_as_cs DEFAULT 'z',
v3 VARCHAR(200) COLLATE utf8mb4_0900_ai_ci,
v4 VARCHAR(200) COLLATE utf8mb3_bin,
v5 VARCHAR(200) COLLATE utf8mb3_general_ci,
v6 VARCHAR(200) COLLATE latin1_bin,
v7 VARCHAR(200) COLLATE latin1_general_ci,
v8 VARBINARY(200));`,
`INSERT INTO temp_tbl VALUES ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h');`,
}
CollationCoercionSetup is the setup that is run before every CollationCoercionTest
var CollationCoercionTests = []CollationCoercionTest{ { Parameters: `'26:27:28'`, Collation: sql.Collation_utf8mb4_0900_bin, Coercibility: 4, }, { Parameters: `'str' COLLATE utf8mb4_bin`, Collation: sql.Collation_utf8mb4_bin, Coercibility: 0, }, { Parameters: `1001`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `2002.5`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `CONVERT('2020-02-20 20:20:20', DATETIME)`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `CONVERT('2020-02-20', DATE)`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `CONVERT('23:24:25', TIME)`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `CONVERT('34', BINARY)`, Collation: sql.Collation_binary, Coercibility: 2, }, { Parameters: `CONVERT('34', SIGNED)`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `CONVERT('34', UNSIGNED)`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `CONVERT('[1]', JSON)`, Collation: sql.Collation_utf8mb4_bin, Coercibility: 2, }, { Parameters: `CURDATE()`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `CURRENT_USER()`, Collation: sql.Collation_utf8_general_ci, Coercibility: 3, }, { Parameters: `FALSE`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `TRUE`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `NOW()`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `NULL`, Collation: sql.Collation_binary, Coercibility: 6, }, { Parameters: `UUID()`, Collation: sql.Collation_utf8_general_ci, Coercibility: 4, }, { Parameters: `v1`, Collation: sql.Collation_utf8mb4_0900_bin, Coercibility: 2, }, { Parameters: `v1 COLLATE utf8mb4_0900_bin`, Collation: sql.Collation_utf8mb4_0900_bin, Coercibility: 0, }, { Parameters: `v2`, Collation: sql.Collation_utf8mb4_0900_as_cs, Coercibility: 2, }, { Parameters: `v2 COLLATE utf8mb4_0900_as_cs`, Collation: sql.Collation_utf8mb4_0900_as_cs, Coercibility: 0, }, { Parameters: `v3`, Collation: sql.Collation_utf8mb4_0900_ai_ci, Coercibility: 2, }, { Parameters: `v3 COLLATE utf8mb4_0900_ai_ci`, Collation: sql.Collation_utf8mb4_0900_ai_ci, Coercibility: 0, }, { Parameters: `v4`, Collation: sql.Collation_utf8_bin, Coercibility: 2, }, { Parameters: `v4 COLLATE utf8mb3_bin`, Collation: sql.Collation_utf8_bin, Coercibility: 0, }, { Parameters: `v5`, Collation: sql.Collation_utf8_general_ci, Coercibility: 2, }, { Parameters: `v5 COLLATE utf8mb3_general_ci`, Collation: sql.Collation_utf8_general_ci, Coercibility: 0, }, { Parameters: `v6`, Collation: sql.Collation_latin1_bin, Coercibility: 2, }, { Parameters: `v6 COLLATE latin1_bin`, Collation: sql.Collation_latin1_bin, Coercibility: 0, }, { Parameters: `v7`, Collation: sql.Collation_latin1_general_ci, Coercibility: 2, }, { Parameters: `v7 COLLATE latin1_general_ci`, Collation: sql.Collation_latin1_general_ci, Coercibility: 0, }, { Parameters: `v8`, Collation: sql.Collation_binary, Coercibility: 2, }, { Parameters: `v8 COLLATE 'binary'`, Collation: sql.Collation_binary, Coercibility: 0, }, { Parameters: `!('26:27:28')`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `!('str' COLLATE utf8mb4_bin)`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `-(CONVERT('2020-02-20', DATE))`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `-(CONVERT('34', BINARY))`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `-(v6)`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `NOT('{"a": 1, "b": {"c": 30}}')`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `CURRENT_TIME() != '26:27:28'`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `v4 != '26:27:28'`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `FALSE * '26:27:28'`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `FALSE * '26:27:28'`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `v5 + '26:27:28'`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `v5 COLLATE utf8mb3_general_ci + '26:27:28'`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `v6 + '26:27:28'`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `v6 COLLATE latin1_bin + '26:27:28'`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `'str' - CURRENT_TIME()`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `v2 / 1001`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `v2 COLLATE utf8mb4_0900_as_cs / 1001`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `1001 < CONVERT('34', CHAR)`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `2002.5 < CONVERT('34', CHAR)`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `1001 <= RAND()`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `2002.5 <= RAND()`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `CONVERT('23:24:25', TIME) DIV NOW()`, Collation: sql.Collation_binary, Coercibility: 5, }, { Parameters: `NULLIF('str' COLLATE utf8mb4_bin, '26:27:28')`, Collation: sql.Collation_utf8mb4_bin, Coercibility: 0, }, { Parameters: `NULLIF('{"a": 1, "b": {"c": 30}}', '26:27:28')`, Collation: sql.Collation_utf8mb4_0900_bin, Coercibility: 4, }, { Parameters: `REPEAT(v1, 1001)`, Collation: sql.Collation_utf8mb4_0900_bin, Coercibility: 2, }, { Parameters: `SUBSTR(v6, CONVERT('2020-02-20 20:20:20', DATETIME))`, Collation: sql.Collation_latin1_bin, Coercibility: 2, }, { Parameters: `SUBSTR(v6 COLLATE latin1_bin, CONVERT('2020-02-20 20:20:20', DATETIME))`, Collation: sql.Collation_latin1_bin, Coercibility: 0, }, }
var ColumnAliasQueries = []ScriptTest{ { Name: "column aliases in a single scope", SetUpScript: []string{ "create table xy (x int primary key, y int);", "create table uv (u int primary key, v int);", "insert into xy values (0,0),(1,1),(2,2),(3,3);", "insert into uv values (0,3),(3,0),(2,1),(1,2);", }, Assertions: []ScriptTestAssertion{ { Query: `SELECT i AS cOl FROM mytable`, ExpectedColumns: sql.Schema{ { Name: "cOl", Type: types.Int64, }, }, Expected: []sql.Row{{int64(1)}, {int64(2)}, {int64(3)}}, }, { Query: `SELECT i AS cOl, s as COL FROM mytable`, ExpectedColumns: sql.Schema{ { Name: "cOl", Type: types.Int64, }, { Name: "COL", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), }, }, Expected: []sql.Row{{int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}}, }, { Query: `SELECT i AS new1, new1 as new2 FROM mytable`, ExpectedErr: sql.ErrMisusedAlias, }, { Query: `SELECT i AS cOl, s as COL FROM mytable where cOl = 1`, ExpectedErr: sql.ErrColumnNotFound, }, { Query: "select t1.i as a, t1.s as b from mytable as t1 left join mytable as t2 on a = t2.i;", ExpectedErr: sql.ErrColumnNotFound, }, { Query: "select 1 as a order by a desc;", Expected: []sql.Row{{1}}, }, { Query: "select v as u from uv order by u;", Expected: []sql.Row{{0}, {1}, {2}, {3}}, }, { Query: "select u as u, v as u from uv order by u;", ExpectedErr: sql.ErrAmbiguousColumnOrAliasName, }, { Query: `SELECT s as COL1, SUM(i) COL2 FROM mytable group by col1 order by col2`, ExpectedColumns: sql.Schema{ { Name: "COL1", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), }, { Name: "COL2", Type: types.Float64, }, }, Expected: []sql.Row{ {"first row", float64(1)}, {"second row", float64(2)}, {"third row", float64(3)}, }, }, { Query: "select t1.u as a from uv as t1 having a > 0 order by a;", Expected: []sql.Row{{1}, {2}, {3}}, }, { Query: "select t1.u as a from uv as t1 having a = t1.u order by a;", Expected: []sql.Row{{0}, {1}, {2}, {3}}, }, { Query: `SELECT s as coL1, SUM(i) coL2 FROM mytable group by 1 order by 2`, ExpectedColumns: sql.Schema{ { Name: "coL1", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), }, { Name: "coL2", Type: types.Float64, }, }, Expected: []sql.Row{ {"first row", float64(1)}, {"second row", float64(2)}, {"third row", float64(3)}, }, }, { Query: `SELECT s as Date, SUM(i) TimeStamp FROM mytable group by 1 order by 2`, ExpectedColumns: sql.Schema{ { Name: "Date", Type: types.MustCreateStringWithDefaults(sqltypes.VarChar, 20), }, { Name: "TimeStamp", Type: types.Float64, }, }, Expected: []sql.Row{ {"first row", float64(1)}, {"second row", float64(2)}, {"third row", float64(3)}, }, }, { Query: "select t1.i as a from mytable as t1 having a = t1.i;", Expected: []sql.Row{{1}, {2}, {3}}, }, }, }, { Name: "column aliases in two scopes", SetUpScript: []string{ "create table xy (x int primary key, y int);", "create table uv (u int primary key, v int);", "insert into xy values (0,0),(1,1),(2,2),(3,3);", "insert into uv values (0,3),(3,0),(2,1),(1,2);", }, Assertions: []ScriptTestAssertion{ { Query: `select "foo" as dummy, (select dummy)`, Expected: []sql.Row{{"foo", "foo"}}, }, { Query: "select x as v, (select u from uv where v = y) as u from xy;", Expected: []sql.Row{{0, 3}, {1, 2}, {2, 1}, {3, 0}}, }, { Skip: true, Query: "select 0 as a, 1 as a, (SELECT x from xy where x = a);", Expected: []sql.Row{{0, 1, 0}}, }, { Query: "SELECT 1 as a, (select a) as a;", Expected: []sql.Row{{1, 1}}, }, { Query: "SELECT 1 as a, (select a) as b;", Expected: []sql.Row{{1, 1}}, }, { Query: "SELECT 1 as a, (select a) as b from dual;", Expected: []sql.Row{{1, 1}}, }, { Query: "SELECT 1 as a, (select a) as b from xy;", Expected: []sql.Row{{1, 1}, {1, 1}, {1, 1}, {1, 1}}, }, { Query: "select x, (select 1) as y from xy;", Expected: []sql.Row{{0, 1}, {1, 1}, {2, 1}, {3, 1}}, }, { Query: "SELECT 1 as a, (select a) from xy;", Expected: []sql.Row{{1, 1}, {1, 1}, {1, 1}, {1, 1}}, }, }, }, { Name: "column aliases in three scopes", SetUpScript: []string{ "create table xy (x int primary key, y int);", "create table uv (u int primary key, v int);", "insert into xy values (0,0),(1,1),(2,2),(3,3);", "insert into uv values (0,3),(3,0),(2,1),(1,2);", }, Assertions: []ScriptTestAssertion{ { Query: "select x, (select 1) as y, (select (select y as q)) as z from (select * from xy) as xy;", Expected: []sql.Row{{0, 1, 0}, {1, 1, 1}, {2, 1, 2}, {3, 1, 3}}, }, }, }, { Name: "various broken alias queries", Assertions: []ScriptTestAssertion{ { Skip: true, Query: `SELECT *, (select i union select i) as a from mytable;`, Expected: []sql.Row{{1, "first row", 1}, {2, "second row", 2}, {3, "third row", 3}}, }, { Skip: true, Query: `SELECT 1 as a, (select a union select a) as b;`, Expected: []sql.Row{{1, 1}}, }, { Skip: true, Query: `select 1 as a, (select b), 0 as b;`, ExpectedErr: sql.ErrColumnNotFound, }, { Skip: true, Query: "select 1 as a, one + 1 as mod1, dt.* from mytable as t1, (select 1, 2 from mytable) as dt (one, two) where dt.one > 0 group by one;", Expected: []sql.Row{{1, 2, 1, 2}}, }, { Skip: true, Query: "select 1 as b, (select b group by b order by b) order by 1;", Expected: []sql.Row{{1, 1}}, }, }, }, }
var ComplexIndexQueries = []QueryTest{}/* 702 elements not displayed */
var ConvertTests = []struct { Field string Op string Operand string ExpCnt int }{}/* 200 elements not displayed */
var CreateCheckConstraintsScripts = []ScriptTest{ { Name: "Run SHOW CREATE TABLE with different types of check constraints", SetUpScript: []string{ "CREATE TABLE mytable1(pk int PRIMARY KEY, CONSTRAINT check1 CHECK (pk = 5))", "ALTER TABLE mytable1 ADD CONSTRAINT check11 CHECK (pk < 6)", "CREATE TABLE mytable2(pk int PRIMARY KEY, v int, CONSTRAINT check2 CHECK (v < 5))", "ALTER TABLE mytable2 ADD CONSTRAINT check12 CHECK (pk + v = 6)", "CREATE TABLE mytable3(pk int PRIMARY KEY, v int, CONSTRAINT check3 CHECK (pk > 2 AND v < 5))", "ALTER TABLE mytable3 ADD CONSTRAINT check13 CHECK (pk BETWEEN 2 AND 100)", "CREATE TABLE mytable4(pk int PRIMARY KEY, v int, CONSTRAINT check4 CHECK (pk > 2 AND v < 5 AND pk < 9))", "CREATE TABLE mytable5(pk int PRIMARY KEY, v int, CONSTRAINT check5 CHECK (pk > 2 OR (v < 5 AND pk < 9)))", "CREATE TABLE mytable6(pk int PRIMARY KEY, v int, CONSTRAINT check6 CHECK (NOT pk))", "CREATE TABLE mytable7(pk int PRIMARY KEY, v int, CONSTRAINT check7 CHECK (pk != v))", "CREATE TABLE mytable8(pk int PRIMARY KEY, v int, CONSTRAINT check8 CHECK (pk > 2 OR v < 5 OR pk < 10))", "CREATE TABLE mytable9(pk int PRIMARY KEY, v int, CONSTRAINT check9 CHECK ((pk + v) / 2 >= 1))", "CREATE TABLE mytable10(pk int PRIMARY KEY, v int, CONSTRAINT check10 CHECK (v < 5) NOT ENFORCED)", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE mytable1", Expected: []sql.Row{ { "mytable1", "CREATE TABLE `mytable1` (\n `pk` int NOT NULL,\n" + " PRIMARY KEY (`pk`),\n" + " CONSTRAINT `check1` CHECK ((`pk` = 5)),\n" + " CONSTRAINT `check11` CHECK ((`pk` < 6))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE TABLE mytable2", Expected: []sql.Row{ { "mytable2", "CREATE TABLE `mytable2` (\n `pk` int NOT NULL,\n" + " `v` int,\n" + " PRIMARY KEY (`pk`),\n" + " CONSTRAINT `check2` CHECK ((`v` < 5)),\n" + " CONSTRAINT `check12` CHECK (((`pk` + `v`) = 6))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE TABLE mytable3", Expected: []sql.Row{ { "mytable3", "CREATE TABLE `mytable3` (\n `pk` int NOT NULL,\n" + " `v` int,\n" + " PRIMARY KEY (`pk`),\n" + " CONSTRAINT `check3` CHECK (((`pk` > 2) AND (`v` < 5))),\n" + " CONSTRAINT `check13` CHECK ((`pk` BETWEEN 2 AND 100))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE TABLE mytable4", Expected: []sql.Row{ { "mytable4", "CREATE TABLE `mytable4` (\n `pk` int NOT NULL,\n" + " `v` int,\n" + " PRIMARY KEY (`pk`),\n" + " CONSTRAINT `check4` CHECK ((((`pk` > 2) AND (`v` < 5)) AND (`pk` < 9)))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE TABLE mytable5", Expected: []sql.Row{ { "mytable5", "CREATE TABLE `mytable5` (\n `pk` int NOT NULL,\n" + " `v` int,\n" + " PRIMARY KEY (`pk`),\n" + " CONSTRAINT `check5` CHECK (((`pk` > 2) OR ((`v` < 5) AND (`pk` < 9))))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE TABLE mytable6", Expected: []sql.Row{ { "mytable6", "CREATE TABLE `mytable6` (\n `pk` int NOT NULL,\n" + " `v` int,\n" + " PRIMARY KEY (`pk`),\n" + " CONSTRAINT `check6` CHECK ((NOT(`pk`)))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE TABLE mytable7", Expected: []sql.Row{ { "mytable7", "CREATE TABLE `mytable7` (\n `pk` int NOT NULL,\n" + " `v` int,\n" + " PRIMARY KEY (`pk`),\n" + " CONSTRAINT `check7` CHECK ((NOT((`pk` = `v`))))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE TABLE mytable8", Expected: []sql.Row{ { "mytable8", "CREATE TABLE `mytable8` (\n `pk` int NOT NULL,\n" + " `v` int,\n" + " PRIMARY KEY (`pk`),\n" + " CONSTRAINT `check8` CHECK ((((`pk` > 2) OR (`v` < 5)) OR (`pk` < 10)))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE TABLE mytable9", Expected: []sql.Row{ { "mytable9", "CREATE TABLE `mytable9` (\n `pk` int NOT NULL,\n" + " `v` int,\n" + " PRIMARY KEY (`pk`),\n" + " CONSTRAINT `check9` CHECK ((((`pk` + `v`) / 2) >= 1))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE TABLE mytable10", Expected: []sql.Row{ { "mytable10", "CREATE TABLE `mytable10` (\n `pk` int NOT NULL,\n" + " `v` int,\n" + " PRIMARY KEY (`pk`),\n" + " CONSTRAINT `check10` CHECK ((`v` < 5)) /*!80016 NOT ENFORCED */\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, }, }, { Name: "Create a table with a check and validate that it appears in check_constraints and table_constraints", SetUpScript: []string{ "CREATE TABLE mytable (pk int primary key, test_score int, height int, CONSTRAINT mycheck CHECK (test_score >= 50), CONSTRAINT hcheck CHECK (height < 10), CONSTRAINT vcheck CHECK (height > 0))", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * from information_schema.check_constraints where constraint_name IN ('mycheck', 'hcheck') ORDER BY constraint_name", Expected: []sql.Row{ {"def", "mydb", "hcheck", "(height < 10)"}, {"def", "mydb", "mycheck", "(test_score >= 50)"}, }, }, { Query: "SELECT * FROM information_schema.table_constraints where table_name='mytable' ORDER BY constraint_type,constraint_name", Expected: []sql.Row{ {"def", "mydb", "hcheck", "mydb", "mytable", "CHECK", "YES"}, {"def", "mydb", "mycheck", "mydb", "mytable", "CHECK", "YES"}, {"def", "mydb", "vcheck", "mydb", "mytable", "CHECK", "YES"}, {"def", "mydb", "PRIMARY", "mydb", "mytable", "PRIMARY KEY", "YES"}, }, }, }, }, { Name: "multi column index, lower()", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 varchar(100), v2 varchar(100), INDEX (v1,v2));", "INSERT INTO test VALUES (1,'happy','birthday'), (2,'HAPPY','BIRTHDAY'), (3,'hello','sailor');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT pk FROM test where lower(v1) = 'happy' and lower(v2) = 'birthday' order by 1", Expected: []sql.Row{{1}, {2}}, }, }, }, { Name: "adding check constraint to a table that violates said constraint correctly throws an error", SetUpScript: []string{ "CREATE TABLE test (pk int)", "INSERT INTO test VALUES (1),(2),(300)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE test ADD CONSTRAINT bad_check CHECK (pk < 5)", ExpectedErr: plan.ErrCheckViolated, }, }, }, { Name: "duplicate indexes still returns correct results", SetUpScript: []string{ "CREATE TABLE test (i int)", "CREATE INDEX test_idx1 on test (i)", "CREATE INDEX test_idx2 on test (i)", "INSERT INTO test values (1), (2), (3)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test ORDER BY i", Expected: []sql.Row{{1}, {2}, {3}}, }, { Query: "SELECT * FROM test where i = 2", Expected: []sql.Row{ {2}, }, }, }, }, }
var CreateTableAutoIncrementTests = []ScriptTest{ { Name: "create table with non primary auto_increment column", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "create table t1 (a int auto_increment unique, b int, primary key(b))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "insert into t1 (b) values (1), (2)", Expected: []sql.Row{ { types.OkResult{ RowsAffected: 2, InsertID: 1, }, }, }, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `a` int AUTO_INCREMENT,\n" + " `b` int NOT NULL,\n" + " PRIMARY KEY (`b`),\n" + " UNIQUE KEY `a` (`a`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, 1}, {2, 2}}, }, }, }, { Name: "create table with non primary auto_increment column, separate unique key", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "create table t1 (a int auto_increment, b int, primary key(b), unique key(a))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "insert into t1 (b) values (1), (2)", Expected: []sql.Row{ { types.OkResult{ RowsAffected: 2, InsertID: 1, }, }, }, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `a` int AUTO_INCREMENT,\n" + " `b` int NOT NULL,\n" + " PRIMARY KEY (`b`),\n" + " UNIQUE KEY `a` (`a`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, 1}, {2, 2}}, }, }, }, { Name: "create table with non primary auto_increment column, missing unique key", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "create table t1 (a int auto_increment, b int, primary key(b))", ExpectedErr: sql.ErrInvalidAutoIncCols, }, }, }, }
var CreateTableQueries = []WriteQueryTest{ { WriteQuery: `create table floattypedefs (a float(10), b float(10, 2), c double(10, 2))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE floattypedefs", ExpectedSelect: []sql.Row{sql.Row{"floattypedefs", "CREATE TABLE `floattypedefs` (\n `a` float,\n `b` float,\n `c` double\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (a INTEGER, b TEXT, c DATE, d TIMESTAMP, e VARCHAR(20), f BLOB NOT NULL, b1 BOOL, b2 BOOLEAN NOT NULL, g DATETIME, h CHAR(40))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `a` int,\n `b` text,\n `c` date,\n `d` timestamp,\n `e` varchar(20),\n `f` blob NOT NULL,\n `b1` tinyint,\n `b2` tinyint NOT NULL,\n `g` datetime,\n `h` char(40)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (a INTEGER NOT NULL PRIMARY KEY, b VARCHAR(10) NOT NULL)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `a` int NOT NULL,\n `b` varchar(10) NOT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (a INTEGER, b TEXT NOT NULL COMMENT 'comment', c bool, primary key (a))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `a` int NOT NULL,\n `b` text NOT NULL COMMENT 'comment',\n `c` tinyint,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (a INTEGER, create_time timestamp(6) NOT NULL DEFAULT NOW(6), primary key (a))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `a` int NOT NULL,\n `create_time` timestamp(6) NOT NULL DEFAULT (NOW(6)),\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 LIKE mytable`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `i` bigint NOT NULL,\n `s` varchar(20) NOT NULL COMMENT 'column s',\n PRIMARY KEY (`i`),\n KEY `idx_si` (`s`,`i`),\n KEY `mytable_i_s` (`i`,`s`),\n UNIQUE KEY `mytable_s` (`s`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 ( pk bigint primary key, v1 bigint default (2) comment 'hi there', index idx_v1 (v1) comment 'index here' )`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `pk` bigint NOT NULL,\n `v1` bigint DEFAULT (2) COMMENT 'hi there',\n PRIMARY KEY (`pk`),\n KEY `idx_v1` (`v1`) COMMENT 'index here'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `create table t1 like foo.other_table`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `text` varchar(20) NOT NULL,\n `number` mediumint,\n PRIMARY KEY (`text`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (a INTEGER NOT NULL PRIMARY KEY, b VARCHAR(10) UNIQUE)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `a` int NOT NULL,\n `b` varchar(10),\n PRIMARY KEY (`a`),\n UNIQUE KEY `b` (`b`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (a INTEGER NOT NULL PRIMARY KEY, b VARCHAR(10) UNIQUE KEY)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `a` int NOT NULL,\n `b` varchar(10),\n PRIMARY KEY (`a`),\n UNIQUE KEY `b` (`b`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 SELECT * from mytable`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `i` bigint NOT NULL,\n `s` varchar(20) NOT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE mydb.t1 (a INTEGER NOT NULL PRIMARY KEY, b VARCHAR(10) NOT NULL)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE mydb.t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `a` int NOT NULL,\n `b` varchar(10) NOT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (i int primary key, j int auto_increment unique)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `j` int AUTO_INCREMENT,\n PRIMARY KEY (`i`),\n UNIQUE KEY `j` (`j`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (i int primary key, j int auto_increment, index (j))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `j` int AUTO_INCREMENT,\n PRIMARY KEY (`i`),\n KEY `j` (`j`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (i int primary key, j int auto_increment, k int, unique(j,k))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `j` int AUTO_INCREMENT,\n `k` int,\n PRIMARY KEY (`i`),\n UNIQUE KEY `jk` (`j`,`k`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (i int primary key, j int auto_increment, k int, index (j,k))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `j` int AUTO_INCREMENT,\n `k` int,\n PRIMARY KEY (`i`),\n KEY `jk` (`j`,`k`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 ( pk int NOT NULL, col1 blob DEFAULT (_utf8mb4'abc'), col2 json DEFAULT (json_object(_utf8mb4'a',1)), col3 text DEFAULT (_utf8mb4'abc'), PRIMARY KEY (pk) )`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []sql.Row{sql.Row{"t1", "CREATE TABLE `t1` (\n `pk` int NOT NULL,\n `col1` blob DEFAULT ('abc'),\n `col2` json DEFAULT (json_object('a',1)),\n `col3` text DEFAULT ('abc'),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE td ( pk int PRIMARY KEY, col2 int NOT NULL DEFAULT 2, col3 double NOT NULL DEFAULT (round(-(1.58),0)), col4 varchar(10) DEFAULT 'new row', col5 float DEFAULT 33.33, col6 int DEFAULT NULL, col7 timestamp DEFAULT NOW(), col8 bigint DEFAULT (NOW()) )`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE td", ExpectedSelect: []sql.Row{sql.Row{"td", "CREATE TABLE `td` (\n `pk` int NOT NULL,\n `col2` int NOT NULL DEFAULT '2',\n `col3` double NOT NULL DEFAULT (round(-1.58,0)),\n `col4` varchar(10) DEFAULT 'new row',\n `col5` float DEFAULT '33.33',\n `col6` int DEFAULT NULL,\n `col7` timestamp DEFAULT (NOW()),\n `col8` bigint DEFAULT (NOW()),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (i int PRIMARY KEY, j varchar(MAX))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `SHOW CREATE TABLE t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `j` varchar(16383),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `create table t1 (i int primary key, b1 blob, b2 blob, index(b1(123), b2(456)))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `show create table t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `b1` blob,\n `b2` blob,\n PRIMARY KEY (`i`),\n KEY `b1b2` (`b1`(123),`b2`(456))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `create table t1 (i int primary key, b1 blob, b2 blob, unique index(b1(123), b2(456)))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `show create table t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `b1` blob,\n `b2` blob,\n PRIMARY KEY (`i`),\n UNIQUE KEY `b1b2` (`b1`(123),`b2`(456))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `create table t1 (i int primary key, b1 blob, b2 blob, index(b1(10)), index(b2(20)), index(b1(123), b2(456)))`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `show create table t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `b1` blob,\n `b2` blob,\n PRIMARY KEY (`i`),\n KEY `b1` (`b1`(10)),\n KEY `b1b2` (`b1`(123),`b2`(456)),\n KEY `b2` (`b2`(20))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 as select * from mytable`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: `select * from t1 order by i`, ExpectedSelect: []sql.Row{{1, "first row"}, {2, "second row"}, {3, "third row"}}, }, { WriteQuery: `CREATE TABLE t1 as select * from mytable`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: `show create table t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `i` bigint NOT NULL,\n `s` varchar(20) NOT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 as select s, i from mytable`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: `select * from t1 order by i`, ExpectedSelect: []sql.Row{{"first row", 1}, {"second row", 2}, {"third row", 3}}, }, { WriteQuery: `CREATE TABLE t1 as select distinct s, i from mytable`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: `select * from t1 order by i`, ExpectedSelect: []sql.Row{{"first row", 1}, {"second row", 2}, {"third row", 3}}, }, { WriteQuery: `CREATE TABLE t1 as select s, i from mytable order by s`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: `select * from t1 order by i`, ExpectedSelect: []sql.Row{{"first row", 1}, {"second row", 2}, {"third row", 3}}, }, { WriteQuery: `CREATE TABLE t1 as select s, sum(i) from mytable group by s`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: `select * from t1 order by s`, ExpectedSelect: []sql.Row{{"first row", float64(1)}, {"second row", float64(2)}, {"third row", float64(3)}}, }, { WriteQuery: `CREATE TABLE t1 as select s, sum(i) from mytable group by s having sum(i) > 2`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "select * from t1", ExpectedSelect: []sql.Row{{"third row", float64(3)}}, }, { WriteQuery: `CREATE TABLE t1 as select s, i from mytable order by s limit 1`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: `select * from t1 order by i`, ExpectedSelect: []sql.Row{{"first row", 1}}, }, { WriteQuery: `CREATE TABLE t1 as select concat("new", s), i from mytable`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: `select * from t1 order by i`, ExpectedSelect: []sql.Row{{"newfirst row", 1}, {"newsecond row", 2}, {"newthird row", 3}}, }, }
var CreateTableScriptTests = []ScriptTest{ { Name: "Validate that CREATE LIKE preserves checks", SetUpScript: []string{ "CREATE TABLE t1 (pk int primary key, test_score int, height int CHECK (height < 10) , CONSTRAINT mycheck CHECK (test_score >= 50))", "CREATE TABLE t2 LIKE t1", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO t2 VALUE (1, 40, 5)", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "INSERT INTO t2 VALUE (1, 60, 15)", ExpectedErr: sql.ErrCheckConstraintViolated, }, }, }, { Name: "datetime precision", SetUpScript: []string{ "CREATE TABLE t1 (pk int primary key, d datetime)", "CREATE TABLE t2 (pk int primary key, d datetime(3))", "CREATE TABLE t3 (pk int primary key, d datetime(6))", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `pk` int NOT NULL,\n" + " `d` datetime,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t1 values (1, '2020-01-01 00:00:00.123456')", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 order by pk", Expected: []sql.Row{{1, MustParseTime(time.DateTime, "2020-01-01 00:00:00")}}, }, { Query: "show create table t2", Expected: []sql.Row{{"t2", "CREATE TABLE `t2` (\n" + " `pk` int NOT NULL,\n" + " `d` datetime(3),\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t2 values (1, '2020-01-01 00:00:00.123456')", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t2 order by pk", Expected: []sql.Row{{1, MustParseTime(time.RFC3339Nano, "2020-01-01T00:00:00.123000000Z")}}, }, { Query: "show create table t3", Expected: []sql.Row{{"t3", "CREATE TABLE `t3` (\n" + " `pk` int NOT NULL,\n" + " `d` datetime(6),\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t3 values (1, '2020-01-01 00:00:00.123456')", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t3 order by pk", Expected: []sql.Row{{1, MustParseTime(time.RFC3339Nano, "2020-01-01T00:00:00.123456000Z")}}, }, { Query: "create table t4 (pk int primary key, d datetime(-1))", ExpectedErr: sql.ErrSyntaxError, }, { Query: "create table t4 (pk int primary key, d datetime(7))", ExpectedErrStr: "DATETIME supports precision from 0 to 6", }, }, }, { Name: "timestamp precision", SetUpScript: []string{ "CREATE TABLE t1 (pk int primary key, d timestamp)", "CREATE TABLE t2 (pk int primary key, d timestamp(3))", "CREATE TABLE t3 (pk int primary key, d timestamp(6))", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `pk` int NOT NULL,\n" + " `d` timestamp,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t1 values (1, '2020-01-01 00:00:00.123456')", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 order by pk", Expected: []sql.Row{{1, MustParseTime(time.DateTime, "2020-01-01 00:00:00")}}, }, { Query: "show create table t2", Expected: []sql.Row{{"t2", "CREATE TABLE `t2` (\n" + " `pk` int NOT NULL,\n" + " `d` timestamp(3),\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t2 values (1, '2020-01-01 00:00:00.123456')", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t2 order by pk", Expected: []sql.Row{{1, MustParseTime(time.RFC3339Nano, "2020-01-01T00:00:00.123000000Z")}}, }, { Query: "show create table t3", Expected: []sql.Row{{"t3", "CREATE TABLE `t3` (\n" + " `pk` int NOT NULL,\n" + " `d` timestamp(6),\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t3 values (1, '2020-01-01 00:00:00.123456')", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t3 order by pk", Expected: []sql.Row{{1, MustParseTime(time.RFC3339Nano, "2020-01-01T00:00:00.123456000Z")}}, }, { Query: "create table t4 (pk int primary key, d TIMESTAMP(-1))", ExpectedErr: sql.ErrSyntaxError, }, { Query: "create table t4 (pk int primary key, d TIMESTAMP(7))", ExpectedErrStr: "TIMESTAMP supports precision from 0 to 6", }, }, }, }
var DatabaseCollationWireTests = []CharsetCollationWireTest{ { Name: "CREATE DATABASE default collation", SetUpScript: []string{ "CREATE DATABASE test_db;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "USE test_db;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"utf8mb4", "utf8mb4_0900_bin"}, }, }, { Query: "DROP DATABASE test_db;", Expected: []sql.Row{}, }, }, }, { Name: "CREATE DATABASE set character set only", SetUpScript: []string{ "CREATE DATABASE test_db CHARACTER SET utf8mb3;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "USE test_db;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"utf8mb3", "utf8mb3_general_ci"}, }, }, { Query: "DROP DATABASE test_db;", Expected: []sql.Row{}, }, }, }, { Name: "CREATE DATABASE set collation only", SetUpScript: []string{ "CREATE DATABASE test_db_a COLLATE latin1_general_ci;", "CREATE DATABASE test_db_b COLLATE latin1_general_cs;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "USE test_db_a;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"latin1", "latin1_general_ci"}, }, }, { Query: "USE test_db_b;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"latin1", "latin1_general_cs"}, }, }, { Query: "DROP DATABASE test_db_a;", Expected: []sql.Row{}, }, { Query: "DROP DATABASE test_db_b;", Expected: []sql.Row{}, }, }, }, { Name: "CREATE DATABASE set character set and collation", SetUpScript: []string{ "CREATE DATABASE test_db CHARACTER SET utf8mb3 COLLATE utf8mb3_bin;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "USE test_db;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"utf8mb3", "utf8mb3_bin"}, }, }, { Query: "CREATE DATABASE invalid_db CHARACTER SET utf8mb4 COLLATE ascii_bin;", Error: true, }, { Query: "DROP DATABASE test_db;", Expected: []sql.Row{}, }, }, }, { Name: "ALTER DATABASE requires character set or collation", SetUpScript: []string{ "CREATE DATABASE test_db;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "ALTER DATABASE test_db;", Error: true, }, { Query: "DROP DATABASE test_db;", Expected: []sql.Row{}, }, }, }, { Name: "ALTER DATABASE set character set only", SetUpScript: []string{ "CREATE DATABASE test_db;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "USE test_db;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"utf8mb4", "utf8mb4_0900_bin"}, }, }, { Query: "ALTER DATABASE test_db CHARACTER SET utf8mb3;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"utf8mb3", "utf8mb3_general_ci"}, }, }, { Query: "DROP DATABASE test_db;", Expected: []sql.Row{}, }, }, }, { Name: "ALTER DATABASE set collation only", SetUpScript: []string{ "CREATE DATABASE test_db_a COLLATE latin1_general_ci;", "CREATE DATABASE test_db_b COLLATE latin1_general_cs;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "USE test_db_a;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"latin1", "latin1_general_ci"}, }, }, { Query: "USE test_db_b;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"latin1", "latin1_general_cs"}, }, }, { Query: "ALTER DATABASE test_db_a COLLATE utf8mb3_bin;", Expected: []sql.Row{}, }, { Query: "ALTER DATABASE test_db_b COLLATE utf8mb3_general_ci;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"utf8mb3", "utf8mb3_general_ci"}, }, }, { Query: "USE test_db_a;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"utf8mb3", "utf8mb3_bin"}, }, }, { Query: "DROP DATABASE test_db_a;", Expected: []sql.Row{}, }, { Query: "DROP DATABASE test_db_b;", Expected: []sql.Row{}, }, }, }, { Name: "ALTER DATABASE set character set and collation", SetUpScript: []string{ "CREATE DATABASE test_db CHARACTER SET utf8mb3 COLLATE utf8mb3_bin;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "USE test_db;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"utf8mb3", "utf8mb3_bin"}, }, }, { Query: "ALTER DATABASE test_db CHARACTER SET ascii COLLATE ascii_bin;", Expected: []sql.Row{}, }, { Query: "SELECT @@character_set_database, @@collation_database;", Expected: []sql.Row{ {"ascii", "ascii_bin"}, }, }, { Query: "DROP DATABASE test_db;", Expected: []sql.Row{}, }, }, }, { Name: "Tables inherit database collation", SetUpScript: []string{ "CREATE DATABASE test_db COLLATE utf8mb3_bin;", "CREATE TABLE test_db.other (pk VARCHAR(20) PRIMARY KEY) COLLATE utf8mb3_unicode_ci;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "USE test_db;", Expected: []sql.Row{}, }, { Query: "CREATE TABLE test_a (pk VARCHAR(20) PRIMARY KEY);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "CREATE TABLE test_b LIKE other;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "CREATE TABLE test_c AS SELECT * FROM other;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "SHOW CREATE TABLE test_a;", Expected: []sql.Row{ {"test_a", "CREATE TABLE `test_a` (\n `pk` varchar(20) NOT NULL,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin"}, }, }, { Query: "SHOW CREATE TABLE test_b;", Expected: []sql.Row{ {"test_b", "CREATE TABLE `test_b` (\n `pk` varchar(20) NOT NULL,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci"}, }, }, { Query: "SHOW CREATE TABLE test_c;", Expected: []sql.Row{ {"test_c", "CREATE TABLE `test_c` (\n `pk` varchar(20) COLLATE utf8mb3_unicode_ci NOT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin"}, }, }, { Query: "ALTER DATABASE test_db COLLATE utf8mb3_general_ci;", Expected: []sql.Row{}, }, { Query: "CREATE TABLE test_d (pk VARCHAR(20) PRIMARY KEY);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "SHOW CREATE TABLE test_d;", Expected: []sql.Row{ {"test_d", "CREATE TABLE `test_d` (\n `pk` varchar(20) NOT NULL,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci"}, }, }, { Query: "DROP DATABASE test_db;", Expected: []sql.Row{}, }, }, }, { Name: "INFORMATION_SCHEMA shows character set and collation", SetUpScript: []string{ "CREATE DATABASE test_db_a COLLATE latin1_general_ci;", "CREATE DATABASE test_db_b COLLATE latin1_general_cs;", }, Queries: []CharsetCollationWireTestQuery{ { Query: "USE test_db_a;", Expected: []sql.Row{}, }, { Query: "SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'test_db_a';", Expected: []sql.Row{ {"latin1", "latin1_general_ci"}, }, }, { Query: "SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'test_db_b';", Expected: []sql.Row{ {"latin1", "latin1_general_cs"}, }, }, { Query: "ALTER DATABASE test_db_a COLLATE utf8mb3_general_ci;", Expected: []sql.Row{}, }, { Query: "SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'test_db_a';", Expected: []sql.Row{ {"utf8mb3", "utf8mb3_general_ci"}, }, }, { Query: "DROP DATABASE test_db_a;", Expected: []sql.Row{}, }, { Query: "DROP DATABASE test_db_b;", Expected: []sql.Row{}, }, }, }, { Name: "Issue #5482", Queries: []CharsetCollationWireTestQuery{ { Query: `SELECT T.TABLE_NAME AS label, 'connection.table' as type, T.TABLE_SCHEMA AS 'schema', T.TABLE_SCHEMA AS 'database', T.TABLE_CATALOG AS 'catalog', 0 AS isView FROM INFORMATION_SCHEMA.TABLES AS T WHERE T.TABLE_CATALOG = 'def' AND UPPER(T.TABLE_TYPE) = 'BASE TABLE' ORDER BY T.TABLE_NAME;`, Expected: []sql.Row(nil), }, }, }, }
DatabaseCollationWireTests are used to validate that CREATE DATABASE and ALTER DATABASE correctly handle having their character set and collations modified.
var DateParseQueries = []QueryTest{ { Query: "SELECT STR_TO_DATE('Jan 3, 2000', '%b %e, %Y')", Expected: []sql.Row{{"2000-01-03"}}, }, { Query: "SELECT STR_TO_DATE('01,5,2013', '%d,%m,%Y')", Expected: []sql.Row{{"2013-05-01"}}, }, { Query: "SELECT STR_TO_DATE('May 1, 2013','%M %d,%Y')", Expected: []sql.Row{{"2013-05-01"}}, }, { Query: "SELECT STR_TO_DATE('a09:30:17','a%h:%i:%s')", Expected: []sql.Row{{"09:30:17"}}, }, { Query: "SELECT STR_TO_DATE('a09:30:17','%h:%i:%s')", Expected: []sql.Row{{nil}}, }, { Query: "SELECT STR_TO_DATE('09:30:17a','%h:%i:%s')", Expected: []sql.Row{{"09:30:17"}}, }, { Query: "SELECT STR_TO_DATE('09:30:17 pm','%h:%i:%s %p')", Expected: []sql.Row{{"21:30:17"}}, }, { Query: "SELECT STR_TO_DATE('9','%m')", Expected: []sql.Row{{"0000-09-00"}}, }, { Query: "SELECT STR_TO_DATE('9','%s')", Expected: []sql.Row{{"00:00:09"}}, }, { Query: "SELECT STR_TO_DATE('01/02/99 314', '%m/%e/%y %f')", Expected: []sql.Row{{"1999-01-02 00:00:00.314000"}}, }, { Query: "SELECT STR_TO_DATE('01/02/99 0', '%m/%e/%y %f')", Expected: []sql.Row{{"1999-01-02 00:00:00.000000"}}, }, { Query: "SELECT STR_TO_DATE('01/02/99 05:14:12 PM', '%m/%e/%y %r')", Expected: []sql.Row{{"1999-01-02 17:14:12"}}, }, { Query: "SELECT STR_TO_DATE('May 3, 10:23:00 2000', '%b %e, %H:%i:%s %Y')", Expected: []sql.Row{{"2000-05-03 10:23:00"}}, }, { Query: "SELECT STR_TO_DATE('May 3, 10:23:00 PM 2000', '%b %e, %h:%i:%s %p %Y')", Expected: []sql.Row{{"2000-05-03 22:23:00"}}, }, { Query: "SELECT STR_TO_DATE('May 3, 10:23:00 PM 2000', '%b %e, %H:%i:%s %p %Y')", Expected: []sql.Row{{nil}}, }, { Query: "SELECT STR_TO_DATE('abc','abc')", Expected: []sql.Row{{nil}}, }, { Query: "SELECT STR_TO_DATE('invalid', 'notvalid')", Expected: []sql.Row{{nil}}, }, }
var DeleteErrorTests = []ScriptTest{ { Name: "DELETE FROM error cases", Assertions: []ScriptTestAssertion{ { Query: "DELETE FROM invalidtable WHERE x < 1;", ExpectedErrStr: "table not found: invalidtable", }, { Query: "DELETE FROM mytable WHERE z = 'dne';", ExpectedErrStr: "column \"z\" could not be found in any table in scope", }, { Query: "DELETE FROM mytable WHERE i = ?;", ExpectedErrStr: "unbound variable \"v1\" in query", }, { Query: "DELETE FROM mytable LIMIT -1;", ExpectedErrStr: "syntax error at position 28 near 'LIMIT'", }, { Query: "DELETE FROM mytable LIMIT 1 OFFSET -1;", ExpectedErrStr: "syntax error at position 37 near 'OFFSET'", }, { Query: "DELETE mytable WHERE i = 1;", ExpectedErrStr: "syntax error at position 21 near 'WHERE'", }, { Query: "DELETE FROM (SELECT * FROM mytable) mytable WHERE i = 1;", ExpectedErrStr: "syntax error at position 14 near 'FROM'", }, }, }, { Name: "DELETE FROM JOIN error cases", Assertions: []ScriptTestAssertion{ { Query: "DELETE mydb.mytable, test.other FROM mydb.mytable inner join test.other on mydb.mytable.i=test.other.pk;", ExpectedErrStr: "multiple databases specified as delete from targets", }, { Query: "DELETE unknowntable FROM mytable WHERE i < 1;", ExpectedErrStr: "table not found: unknowntable", }, { Query: "DELETE tabletest FROM mytable WHERE i < 1;", ExpectedErrStr: "table \"tabletest\" not found in DELETE FROM sources", }, { Query: "DELETE mytable, mytable FROM mytable WHERE i < 1;", ExpectedErrStr: "duplicate tables specified as delete from targets", }, { Query: "DELETE FROM mytable one, mytable two WHERE one.i = 1;", ExpectedErrStr: "syntax error at position 24 near 'one'", }, { Query: "DELETE jt FROM mytable join tabletest on mytable.i=tabletest.i join JSON_TABLE('[{\"x\": 1},{\"x\": 2}]', '$[*]' COLUMNS (x INT PATH '$.x')) as jt on jt.x=mytable.i;", ExpectedErrStr: "target table jt of the DELETE is not updatable", }, { Query: "DELETE mytable, jt FROM mytable join tabletest on mytable.i=tabletest.i join JSON_TABLE('[{\"x\": 1},{\"x\": 2}]', '$[*]' COLUMNS (x INT PATH '$.x')) as jt on jt.x=mytable.i;", ExpectedErrStr: "target table jt of the DELETE is not updatable", }, }, }, }
var DeleteJoinTests = []WriteQueryTest{ { WriteQuery: "DELETE mytable FROM mytable join tabletest where mytable.i=tabletest.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{0, 3}}, }, { WriteQuery: "DELETE MYTABLE FROM mytAble join tAbletest where mytable.i=tabletest.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{0, 3}}, }, { WriteQuery: "DELETE tabletest FROM mytable join tabletest where mytable.i=tabletest.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{3, 0}}, }, { WriteQuery: "DELETE t1 FROM mytable as t1 join tabletest where t1.i=tabletest.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{0, 3}}, }, { WriteQuery: "DELETE mytable, tabletest FROM mytable join tabletest where mytable.i=tabletest.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{0, 0}}, }, { WriteQuery: "DELETE MYTABLE, TABLETEST FROM mytable join tabletest where mytable.i=tabletest.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{0, 0}}, }, { WriteQuery: "DELETE mytable FROM mytable;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT count(*) FROM mytable;", ExpectedSelect: []sql.Row{{0}}, }, { WriteQuery: "DELETE mytable FROM mytable WHERE i > 9999;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SELECT count(*) FROM mytable;", ExpectedSelect: []sql.Row{{3}}, }, { WriteQuery: "DELETE FROM mytable USING mytable inner join tabletest on mytable.i=tabletest.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{0, 3}}, }, { WriteQuery: "DELETE FROM tabletest USING mytable inner join tabletest on mytable.i=tabletest.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{3, 0}}, }, { WriteQuery: "DELETE FROM mytable, tabletest USING mytable inner join tabletest on mytable.i=tabletest.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{0, 0}}, }, { WriteQuery: "DELETE mytable FROM mytable join tabletest where mytable.i=tabletest.i and mytable.i = 2;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{2, 3}}, }, { WriteQuery: "DELETE mytable, tabletest FROM mytable join tabletest where mytable.i=tabletest.i and mytable.i = 2;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{2, 2}}, }, { WriteQuery: "DELETE tabletest, mytable FROM mytable join tabletest where mytable.i=tabletest.i and mytable.i = 2;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{2, 2}}, }, { WriteQuery: "DELETE mytable FROM mytable join (select 1 as i union all select 2 as i) dt where mytable.i=dt.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{1, 3}}, }, { WriteQuery: "with t (n) as (select (1) from dual) delete mytable from mytable join tabletest where mytable.i=tabletest.i and mytable.i in (select n from t)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1}}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{2, 3}}, }, { WriteQuery: "with t (n) as (select (1) from dual) delete mytable, tabletest from mytable join tabletest where mytable.i=tabletest.i and mytable.i in (select n from t)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1}}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{2, 2}}, }, { WriteQuery: "DELETE mytable FROM mytable join tabletest on mytable.i=tabletest.i join JSON_TABLE('[{\"x\": 1},{\"x\": 2}]', '$[*]' COLUMNS (x INT PATH '$.x')) as jt on jt.x=mytable.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{1, 3}}, }, { WriteQuery: "DELETE mytable, tabletest FROM mytable join tabletest on mytable.i=tabletest.i join JSON_TABLE('[{\"x\": 1},{\"x\": 2}]', '$[*]' COLUMNS (x INT PATH '$.x')) as jt on jt.x=mytable.i;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT (select count(*) FROM mytable), (SELECT count(*) from tabletest);", ExpectedSelect: []sql.Row{{1, 1}}, }, }
DeleteJoinTests contains tests for deletes that explicitly list the table from which to delete, and whose source may contain joined table relations.
var DeleteTests = []WriteQueryTest{ { WriteQuery: "DELETE FROM mytable;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: nil, }, { WriteQuery: "DELETE FROM mytable WHERE i = 2;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(3), "third row"}}, }, { WriteQuery: "DELETE FROM mytable WHERE I = 2;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(3), "third row"}}, }, { WriteQuery: "DELETE FROM mytable WHERE i < 3;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(3), "third row"}}, }, { WriteQuery: "DELETE FROM mytable WHERE i > 1;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}}, }, { WriteQuery: "DELETE FROM mytable WHERE i <= 2;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(3), "third row"}}, }, { WriteQuery: "DELETE FROM mytable WHERE i >= 2;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}}, }, { WriteQuery: "DELETE FROM mytable WHERE s = 'first row';", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(2), "second row"}, {int64(3), "third row"}}, }, { WriteQuery: "DELETE FROM mytable WHERE s <> 'dne';", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: nil, }, { WriteQuery: "DELETE FROM mytable WHERE i in (2,3);", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}}, }, { WriteQuery: "DELETE FROM mytable WHERE s LIKE '%row';", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: nil, }, { WriteQuery: "DELETE FROM mytable WHERE s = 'dne';", ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}}, }, { WriteQuery: "DELETE FROM mytable WHERE i = 'invalid';", ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}}, }, { WriteQuery: "DELETE FROM mytable ORDER BY i ASC LIMIT 2;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(3), "third row"}}, }, { WriteQuery: "DELETE FROM mytable ORDER BY i DESC LIMIT 1;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(2), "second row"}}, }, { WriteQuery: "DELETE FROM mytable ORDER BY i DESC LIMIT 1 OFFSET 1;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(3), "third row"}}, }, { WriteQuery: "DELETE FROM mytable WHERE (i,s) = (1, 'first row');", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(2), "second row"}, {int64(3), "third row"}}, }, { WriteQuery: `DELETE FROM tabletest where 's' = 'something'`, ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 0}}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}}, }, { WriteQuery: "with t (n) as (select (1) from dual) delete from mytable where i in (select n from t)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1}}}, SelectQuery: "select * from mytable order by i", ExpectedSelect: []sql.Row{ sql.NewRow(2, "second row"), sql.NewRow(3, "third row"), }, }, { WriteQuery: "with recursive t (n) as (select (1) from dual union all select n + 1 from t where n < 2) delete from mytable where i in (select n from t)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 2}}}, SelectQuery: "select * from mytable order by i", ExpectedSelect: []sql.Row{ sql.NewRow(3, "third row"), }, }, }
DeleteTests contains tests for deletes that implicitly target the single table mentioned in the from clause.
var DerivedTableOuterScopeVisibilityQueries = []ScriptTest{ { Name: "outer scope visibility for derived tables", SetUpScript: []string{ "create table t1 (a int primary key, b int, c int, d int, e int);", "create table t2 (a int primary key, b int, c int, d int, e int);", "insert into t1 values (1, 1, 1, 100, 100), (2, 2, 2, 200, 200);", "insert into t2 values (2, 2, 2, 2, 2);", "create table numbers (val int);", "insert into numbers values (1), (1), (2), (3), (3), (3), (4), (5), (6), (6), (6);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t1 WHERE t1.d > (SELECT dt.a FROM (SELECT t2.a AS a FROM t2 WHERE t2.b = t1.b) dt);", Expected: []sql.Row{{2, 2, 2, 200, 200}}, }, { Query: "SELECT * FROM t1 HAVING t1.d > (SELECT dt.a FROM (SELECT t2.a AS a FROM t2 WHERE t2.b = t1.b) dt);", Expected: []sql.Row{{2, 2, 2, 200, 200}}, }, { Query: "SELECT (SELECT dt.z FROM (SELECT t2.a AS z FROM t2 WHERE t2.b = t1.b) dt) FROM t1;", Expected: []sql.Row{{nil}, {2}}, }, { Query: "SELECT (SELECT max(dt.z) FROM (SELECT t2.a AS z FROM t2 WHERE t2.b = t1.b) dt) FROM t1;", Expected: []sql.Row{{nil}, {2}}, }, { Query: "SELECT t1.*, (SELECT max(dt.a) FROM (SELECT t2.a AS a FROM t2 WHERE t2.b = t1.b) dt) FROM t1;", Expected: []sql.Row{{1, 1, 1, 100, 100, nil}, {2, 2, 2, 200, 200, 2}}, }, { Query: "SELECT t1.a, t1.b, (SELECT max(dt.a) FROM (SELECT t2.a AS a FROM t2 WHERE t2.b = t1.b) dt) FROM t1 GROUP BY 1, 2, 3;", Expected: []sql.Row{{1, 1, nil}, {2, 2, 2}}, }, { Query: "SELECT val, row_number() over (partition by val) as 'row_number', (SELECT two from (SELECT val*2, val*3) as dt(one, two)) as a1 from numbers having a1 > 10;", Expected: []sql.Row{{4, 1, 12}, {5, 1, 15}, {6, 1, 18}, {6, 2, 18}, {6, 3, 18}}, }, { Query: "SELECT max(val), (select max(dt.a) from (SELECT val as a) as dt(a)) as a1 from numbers group by a1;", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}, }, { Query: "SELECT DISTINCT numbers.val, (WITH cte1 AS (SELECT val * 2 as val2 from numbers) SELECT count(*) from cte1 where numbers.val = cte1.val2) as count from numbers having count > 0;", Expected: []sql.Row{{2, 2}, {4, 1}, {6, 3}}, }, { Query: "select distinct n1.val, (with recursive cte1(n) as (select (n1.val) from dual union all select n + 1 from cte1 where n < 10) select sum(n) from cte1) from numbers n1 where n1.val > 4;", Expected: []sql.Row{{5, 45.0}, {6, 40.0}}, }, }, }, { Name: "outer scope visibility for derived tables – error cases", SetUpScript: []string{ "create table numbers (val int);", "insert into numbers values (1), (1), (2), (3), (3), (3), (4), (5), (6), (6), (6);", }, Assertions: []ScriptTestAssertion{ { Query: "select 'foo' as foo, (select dt.b from (select 1 as a, foo as b) dt);", ExpectedErr: sql.ErrColumnNotFound, }, { Query: "SELECT n1.val as a1 from numbers n1, (select n1.val, n2.val * -1 from numbers n2 where n1.val = n2.val) as dt;", ExpectedErr: sql.ErrTableNotFound, }, { Query: "SELECT 1 as a1, dt.* from (select * from (select a1 from numbers group by val having val = a1) as dt2(val)) as dt(val);", ExpectedErr: sql.ErrColumnNotFound, }, { Skip: true, Query: "with cte1 as (SELECT c3 FROM one_pk WHERE c4 < opk.c2 ORDER BY 1 DESC LIMIT 1) SELECT pk, (select c3 from cte1) FROM one_pk opk ORDER BY 1", ExpectedErr: sql.ErrTableNotFound, }, }, }, { Name: "https://github.com/dolthub/go-mysql-server/issues/1282", SetUpScript: []string{ "CREATE TABLE `dcim_rackgroup` (`id` char(32) NOT NULL, `lft` int unsigned NOT NULL, `rght` int unsigned NOT NULL, `tree_id` int unsigned NOT NULL, `level` int unsigned NOT NULL, `parent_id` char(32), PRIMARY KEY (`id`), KEY `dcim_rackgroup_tree_id_9c2ad6f4` (`tree_id`), CONSTRAINT `dcim_rackgroup_parent_id_cc315105_fk_dcim_rackgroup_id` FOREIGN KEY (`parent_id`) REFERENCES `dcim_rackgroup` (`id`));", "CREATE TABLE `dcim_rack` (`id` char(32) NOT NULL, `group_id` char(32), PRIMARY KEY (`id`), KEY `dcim_rack_group_id_44e90ea9` (`group_id`), CONSTRAINT `dcim_rack_group_id_44e90ea9_fk_dcim_rackgroup_id` FOREIGN KEY (`group_id`) REFERENCES `dcim_rackgroup` (`id`));", "INSERT INTO dcim_rackgroup VALUES ('rackgroup-parent', 100, 200, 1000, 1, NULL), ('rackgroup1', 101, 201, 1000, 1, 'rackgroup-parent'), ('rackgroup2', 102, 202, 1000, 1, 'rackgroup-parent');", "INSERT INTO dcim_rack VALUES ('rack1', 'rackgroup1'), ('rack2', 'rackgroup1'), ('rack3', 'rackgroup1'), ('rack4', 'rackgroup2');", }, Assertions: []ScriptTestAssertion{ { Query: ` SELECT ( SELECT count(*) FROM ( SELECT U0.id FROM dcim_rack U0 INNER JOIN dcim_rackgroup U1 ON (U0.group_id = U1.id) WHERE U1.lft >= dcim_rackgroup.lft AND U1.lft <= dcim_rackgroup.rght AND U1.tree_id = dcim_rackgroup.tree_id ) _count ) AS rack_count FROM dcim_rackgroup WHERE dcim_rackgroup.id IN ('rackgroup1', 'rackgroup2')`, Expected: []sql.Row{{4}, {1}}, }, { Query: "SELECT COUNT(*) FROM (SELECT (SELECT count(*) FROM (SELECT U0.`id` FROM `dcim_rack` U0 INNER JOIN `dcim_rackgroup` U1 ON (U0.`group_id` = U1.`id`) WHERE (U1.`lft` >= `dcim_rackgroup`.`lft` AND U1.`lft` <= `dcim_rackgroup`.`rght` AND U1.`tree_id` = `dcim_rackgroup`.`tree_id`)) _count) AS `rack_count` FROM `dcim_rackgroup` WHERE `dcim_rackgroup`.`id` IN ('rackgroup1', 'rackgroup2')) subquery;", Expected: []sql.Row{{2}}, }, }, }, }
var ErrorQueries = []QueryErrorTest{}/* 101 elements not displayed */
var EventTests = []ScriptTest{ { Name: "EVENTs with ON SCHEDULE EVERY", SetUpScript: []string{ "USE mydb;", "CREATE TABLE totals (num int);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE EVENT event_with_starts_and_ends ON SCHEDULE EVERY '1:2' MINUTE_SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR ENDS CURRENT_TIMESTAMP + INTERVAL 1 DAY DISABLE DO INSERT INTO totals VALUES (1);", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CREATE EVENT event_with_starts_only ON SCHEDULE EVERY '1:2' MINUTE_SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DISABLE DO INSERT INTO totals VALUES (1);", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CREATE EVENT event_with_ends_only ON SCHEDULE EVERY '1:2' MINUTE_SECOND ENDS CURRENT_TIMESTAMP + INTERVAL 1 DAY DISABLE DO INSERT INTO totals VALUES (1);", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CREATE EVENT event_without_starts_and_ends ON SCHEDULE EVERY '1:2' MINUTE_SECOND DISABLE DO INSERT INTO totals VALUES (1);", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CREATE EVENT event2 ON SCHEDULE EVERY 3 DAY STARTS '2037-10-16 23:59:00' + INTERVAL 2 DAY ENDS '2037-11-16 23:59:00' + INTERVAL 1 MONTH DO INSERT INTO totals VALUES (1000);", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW EVENTS LIKE 'event2';", Expected: []sql.Row{{"mydb", "event2", "`root`@`localhost`", "SYSTEM", "RECURRING", nil, "3", "DAY", "2037-10-18 23:59:00", "2037-12-16 23:59:00", "ENABLED", 0, "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, { Query: "SHOW CREATE EVENT event2;", Expected: []sql.Row{ {"event2", "", "SYSTEM", "CREATE DEFINER = `root`@`localhost` EVENT `event2` ON SCHEDULE EVERY 3 DAY STARTS '2037-10-18 23:59:00' ENDS '2037-12-16 23:59:00' ON COMPLETION NOT PRESERVE ENABLE DO INSERT INTO totals VALUES (1000)", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}, }, }, }, }, { Name: "EVENTs with ON SCHEDULE AT", SetUpScript: []string{ "USE mydb;", "CREATE TABLE totals (num int);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE EVENT event2 ON SCHEDULE AT '2038-01-16 23:59:00 +0000 UTC' + INTERVAL 1 DAY ON COMPLETION PRESERVE DISABLE DO INSERT INTO totals VALUES (100);", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW EVENTS;", Expected: []sql.Row{{"mydb", "event2", "`root`@`localhost`", "SYSTEM", "ONE TIME", "2038-01-17 23:59:00", nil, nil, nil, nil, "DISABLED", 0, "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, }, }, { Name: "DROP EVENTs", SetUpScript: []string{ "USE mydb;", "CREATE TABLE totals (num int);", "CREATE EVENT event1 ON SCHEDULE AT '2038-01-15 23:59:00 +0000 UTC' + INTERVAL 2 DAY DISABLE DO INSERT INTO totals VALUES (100);", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW EVENTS;", Expected: []sql.Row{{"mydb", "event1", "`root`@`localhost`", "SYSTEM", "ONE TIME", "2038-01-17 23:59:00", nil, nil, nil, nil, "DISABLED", 0, "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, { Query: "DROP EVENT event1", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW EVENTS;", Expected: []sql.Row{}, }, }, }, { Name: "invalid events actions", SetUpScript: []string{ "USE mydb;", "CREATE TABLE totals (num int);", "CREATE EVENT my_event1 ON SCHEDULE EVERY '1:2' MINUTE_SECOND DISABLE DO INSERT INTO totals VALUES (1);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE EVENT my_event1 ON SCHEDULE EVERY '1:2' MINUTE_SECOND DISABLE DO INSERT INTO totals VALUES (1);", ExpectedErr: sql.ErrEventAlreadyExists, }, { Query: "CREATE EVENT mY_EVENt1 ON SCHEDULE EVERY '1:2' HOUR_MINUTE DISABLE DO INSERT INTO totals VALUES (2);", ExpectedErr: sql.ErrEventAlreadyExists, }, { Query: "CREATE EVENT IF NOT EXISTS my_event1 ON SCHEDULE EVERY '1:2' MINUTE_SECOND DISABLE DO INSERT INTO totals VALUES (1);", Expected: []sql.Row{{types.OkResult{}}}, ExpectedWarningsCount: 1, }, { Query: "SHOW WARNINGS;", Expected: []sql.Row{{"Note", 1537, "Event 'my_event1' already exists"}}, }, { Query: "CREATE EVENT ends_before_starts ON SCHEDULE EVERY 1 MINUTE ENDS '2006-02-10 23:59:00' DO INSERT INTO totals VALUES (1);", ExpectedErrStr: "ENDS is either invalid or before STARTS", }, { Query: "SHOW CREATE EVENT non_existent_event;", ExpectedErr: sql.ErrUnknownEvent, }, { Query: "DROP EVENT non_existent_event", ExpectedErr: sql.ErrEventDoesNotExist, }, { Query: "DROP EVENT IF EXISTS non_existent_event", Expected: []sql.Row{{types.OkResult{}}}, ExpectedWarningsCount: 1, }, { Query: "SHOW WARNINGS;", Expected: []sql.Row{{"Note", 1305, "Event non_existent_event does not exist"}}, }, { Query: "CREATE EVENT past_event1 ON SCHEDULE AT '2006-02-10 23:59:00' DISABLE DO INSERT INTO totals VALUES (100);", Expected: []sql.Row{{types.OkResult{}}}, ExpectedWarningsCount: 1, }, { Query: "SHOW WARNINGS;", Expected: []sql.Row{{"Note", 1588, "Event execution time is in the past and ON COMPLETION NOT PRESERVE is set. The event was dropped immediately after creation."}}, }, { Query: "SHOW EVENTS LIKE 'past_event1';", Expected: []sql.Row{}, }, { Query: "CREATE EVENT past_event2 ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION PRESERVE DO INSERT INTO totals VALUES (100);", Expected: []sql.Row{{types.OkResult{}}}, ExpectedWarningsCount: 1, }, { Query: "SHOW WARNINGS;", Expected: []sql.Row{{"Note", 1544, "Event execution time is in the past. Event has been disabled"}}, }, { Query: "SHOW EVENTS LIKE 'past_event2';", Expected: []sql.Row{{"mydb", "past_event2", "`root`@`localhost`", "SYSTEM", "ONE TIME", "2006-02-10 23:59:00", nil, nil, nil, nil, "DISABLED", 0, "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, }, }, { Name: "invalid ALTER EVENT actions", SetUpScript: []string{ "USE mydb;", "CREATE TABLE totals (num int);", "CREATE EVENT my_event1 ON SCHEDULE EVERY '1:2' MINUTE_SECOND DISABLE DO INSERT INTO totals VALUES (1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER EVENT my_event1 ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION NOT PRESERVE;", ExpectedErrStr: "Event execution time is in the past and ON COMPLETION NOT PRESERVE is set. The event was not changed. Specify a time in the future.", }, { Query: "ALTER EVENT my_event1 ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION PRESERVE;", Expected: []sql.Row{{types.OkResult{}}}, ExpectedWarningsCount: 1, }, { Query: "SHOW WARNINGS;", Expected: []sql.Row{{"Note", 1544, "Event execution time is in the past. Event has been disabled"}}, }, { Query: "CREATE EVENT my_event2 ON SCHEDULE EVERY '1:2' MINUTE_SECOND DISABLE DO INSERT INTO totals VALUES (2);", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "ALTER EVENT my_event2 RENAME TO my_event1;", ExpectedErr: sql.ErrEventAlreadyExists, }, }, }, { Name: "enabling expired event stays disabled", SetUpScript: []string{ "USE mydb;", "CREATE TABLE totals (num int);", "CREATE EVENT my_event1 ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION PRESERVE DISABLE DO INSERT INTO totals VALUES (1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER EVENT my_event1 ENABLE;", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW CREATE EVENT my_event1;", Expected: []sql.Row{{"my_event1", "", "SYSTEM", "CREATE DEFINER = `root`@`localhost` EVENT `my_event1` ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION PRESERVE DISABLE DO INSERT INTO totals VALUES (1)", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, }, }, { Name: "enabling expired event with ON COMPLETION NOT PRESERVE drops the event", SetUpScript: []string{ "USE mydb;", "CREATE TABLE totals (num int);", "CREATE EVENT my_event1 ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION PRESERVE DISABLE DO INSERT INTO totals VALUES (1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER EVENT my_event1 ON COMPLETION NOT PRESERVE;", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW CREATE EVENT my_event1;", Expected: []sql.Row{{"my_event1", "", "SYSTEM", "CREATE DEFINER = `root`@`localhost` EVENT `my_event1` ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION NOT PRESERVE DISABLE DO INSERT INTO totals VALUES (1)", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, { Query: "SHOW EVENTS;", Expected: []sql.Row{{"mydb", "my_event1", "`root`@`localhost`", "SYSTEM", "ONE TIME", "2006-02-10 23:59:00", nil, nil, nil, nil, "DISABLED", 0, "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, { Query: "ALTER EVENT my_event1 ENABLE;", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW EVENTS;", Expected: []sql.Row{}, }, }, }, { Name: "altering event schedule between AT and EVERY", SetUpScript: []string{ "USE mydb;", "CREATE TABLE totals (num int);", "CREATE EVENT my_event1 ON SCHEDULE EVERY '1:2' MINUTE_SECOND DISABLE DO INSERT INTO totals VALUES (1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER EVENT my_event1 ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION PRESERVE;", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW CREATE EVENT my_event1;", Expected: []sql.Row{{"my_event1", "", "SYSTEM", "CREATE DEFINER = `root`@`localhost` EVENT `my_event1` ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION PRESERVE DISABLE DO INSERT INTO totals VALUES (1)", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, { Query: "ALTER EVENT my_event1 ON SCHEDULE EVERY 5 HOUR STARTS '2037-10-16 23:59:00' COMMENT 'updating the event schedule from AT';", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW CREATE EVENT my_event1;", Expected: []sql.Row{{"my_event1", "", "SYSTEM", "CREATE DEFINER = `root`@`localhost` EVENT `my_event1` ON SCHEDULE EVERY 5 HOUR STARTS '2037-10-16 23:59:00' ON COMPLETION PRESERVE DISABLE COMMENT 'updating the event schedule from AT' DO INSERT INTO totals VALUES (1)", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, }, }, { Name: "altering event fields", SetUpScript: []string{ "USE mydb;", "CREATE TABLE totals (num int);", "CREATE EVENT my_event1 ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION PRESERVE DISABLE DO INSERT INTO totals VALUES (1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER EVENT my_event1 RENAME TO newEventName;", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW CREATE EVENT newEventName;", Expected: []sql.Row{{"newEventName", "", "SYSTEM", "CREATE DEFINER = `root`@`localhost` EVENT `newEventName` ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION PRESERVE DISABLE DO INSERT INTO totals VALUES (1)", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, { Query: "ALTER EVENT newEventName COMMENT 'insert 2 instead of 1' DO INSERT INTO totals VALUES (2);", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW CREATE EVENT newEventName;", Expected: []sql.Row{{"newEventName", "", "SYSTEM", "CREATE DEFINER = `root`@`localhost` EVENT `newEventName` ON SCHEDULE AT '2006-02-10 23:59:00' ON COMPLETION PRESERVE DISABLE COMMENT 'insert 2 instead of 1' DO INSERT INTO totals VALUES (2)", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}}, }, }, }, }
EventTests tests any EVENT related behavior. Events have at least one timestamp value (AT/STARTS/ENDS), so to test SHOW EVENTS and SHOW CREATE EVENTS statements, some tests have those timestamps defined in 2037.
var ExternalProcedureTests = []ScriptTest{ { Name: "Call external stored procedure that does not exist", Assertions: []ScriptTestAssertion{ { Query: "CALL procedure_does_not_exist('foo');", ExpectedErr: sql.ErrStoredProcedureDoesNotExist, }, }, }, { Name: "INOUT on first param, IN on second param", SetUpScript: []string{ "SET @outparam = 5;", "CALL memory_inout_add(@outparam, 11);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @outparam;", Expected: []sql.Row{{16}}, }, }, }, { Name: "Handle setting uninitialized user variables", SetUpScript: []string{ "CALL memory_inout_set_unitialized(@uservar12, @uservar13, @uservar14, @uservar15);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @uservar12;", Expected: []sql.Row{{5}}, }, { Query: "SELECT @uservar13;", Expected: []sql.Row{{uint(5)}}, }, { Query: "SELECT @uservar14;", Expected: []sql.Row{{"5"}}, }, { Query: "SELECT @uservar15;", Expected: []sql.Row{{0}}, }, }, }, { Name: "Called from standard stored procedure", SetUpScript: []string{ "CREATE PROCEDURE p1(x BIGINT) BEGIN CALL memory_inout_add(x, x); SELECT x; END;", }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(11);", Expected: []sql.Row{{22}}, }, }, }, { Name: "Overloaded Name", Assertions: []ScriptTestAssertion{ { Query: "CALL memory_overloaded_mult(1);", Expected: []sql.Row{{1}}, }, { Query: "CALL memory_overloaded_mult(2, 3);", Expected: []sql.Row{{6}}, }, { Query: "CALL memory_overloaded_mult(4, 5, 6);", Expected: []sql.Row{{120}}, }, }, }, { Name: "Passing in all supported types", Assertions: []ScriptTestAssertion{ { Query: "CALL memory_overloaded_type_test(1, 100, 10000, 1000000, 100000000, 3, 300," + "10, 1000, 100000, 10000000, 1000000000, 30, 3000);", Expected: []sql.Row{{1111114444}}, }, { Query: "CALL memory_overloaded_type_test(false, 'hi', 'A', '2020-02-20 12:00:00', 123.456," + "true, 'bye', 'B', '2022-02-02 12:00:00', 654.32);", Expected: []sql.Row{{`aa:false,ba:true,ab:"hi",bb:"bye",ac:[65],bc:[66],ad:2020-02-20,bd:2022-02-02,ae:123.456,be:654.32`}}, }, { Query: "CALL memory_type_test3(1, 100, 10000, 1000000, 100000000, 3, 300," + "10, 1000, 100000, 10000000, 1000000000, 30, 3000);", Expected: []sql.Row{{uint64(1111114444)}}, }, }, }, { Name: "BOOL and []BYTE INOUT conversions", SetUpScript: []string{ "SET @outparam1 = 1;", "SET @outparam2 = 0;", "SET @outparam3 = 'A';", "SET @outparam4 = 'B';", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @outparam1, @outparam2, @outparam3, @outparam4;", Expected: []sql.Row{{1, 0, "A", "B"}}, }, { Query: "CALL memory_inout_bool_byte(@outparam1, @outparam2, @outparam3, @outparam4);", Expected: []sql.Row{}, }, { Query: "SELECT @outparam1, @outparam2, @outparam3, @outparam4;", Expected: []sql.Row{{1, 1, "A", []byte("C")}}, }, { Query: "CALL memory_inout_bool_byte(@outparam1, @outparam2, @outparam3, @outparam4);", Expected: []sql.Row{}, }, { Query: "SELECT @outparam1, @outparam2, @outparam3, @outparam4;", Expected: []sql.Row{{1, 0, "A", []byte("D")}}, }, }, }, { Name: "Errors returned", Assertions: []ScriptTestAssertion{ { Query: "CALL memory_error_table_not_found();", ExpectedErr: sql.ErrTableNotFound, }, }, }, { Name: "Variadic parameter", Assertions: []ScriptTestAssertion{ { Query: "CALL memory_variadic_add();", Expected: []sql.Row{{0}}, }, { Query: "CALL memory_variadic_add(1);", Expected: []sql.Row{{1}}, }, { Query: "CALL memory_variadic_add(1, 2);", Expected: []sql.Row{{3}}, }, { Query: "CALL memory_variadic_add(1, 2, 3);", Expected: []sql.Row{{6}}, }, { Query: "CALL memory_variadic_add(1, 2, 3, 4);", Expected: []sql.Row{{10}}, }, }, }, { Name: "Variadic byte slices", Assertions: []ScriptTestAssertion{ { Query: "CALL memory_variadic_byte_slice();", Expected: []sql.Row{{""}}, }, { Query: "CALL memory_variadic_byte_slice('A');", Expected: []sql.Row{{"A"}}, }, { Query: "CALL memory_variadic_byte_slice('A', 'B');", Expected: []sql.Row{{"AB"}}, }, }, }, { Name: "Variadic overloading", Assertions: []ScriptTestAssertion{ { Query: "CALL memory_variadic_overload();", ExpectedErr: sql.ErrCallIncorrectParameterCount, }, { Query: "CALL memory_variadic_overload('A');", ExpectedErr: sql.ErrCallIncorrectParameterCount, }, { Query: "CALL memory_variadic_overload('A', 'B');", Expected: []sql.Row{{"A-B"}}, }, { Query: "CALL memory_variadic_overload('A', 'B', 'C');", ExpectedErr: sql.ErrInvalidValue, }, { Query: "CALL memory_variadic_overload('A', 'B', 5);", Expected: []sql.Row{{"A,B,[5]"}}, }, }, }, { Name: "show create procedure for external stored procedures", Assertions: []ScriptTestAssertion{ { Query: "show create procedure memory_variadic_overload;", Expected: []sql.Row{{ "memory_variadic_overload", "", "CREATE PROCEDURE memory_variadic_overload() SELECT 'External stored procedure';", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }}, }, }, }, }
var ForeignKeyTests = []ScriptTest{ { Name: "ALTER TABLE Single Named FOREIGN KEY", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk_named FOREIGN KEY (v1) REFERENCES parent(v1);", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE child;", Expected: []sql.Row{{"child", "CREATE TABLE `child` (\n `id` int NOT NULL,\n `v1` int,\n `v2` int,\n PRIMARY KEY (`id`),\n KEY `v1` (`v1`),\n CONSTRAINT `fk_named` FOREIGN KEY (`v1`) REFERENCES `parent` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "CREATE TABLE Single Named FOREIGN KEY", SetUpScript: []string{ "CREATE TABLE sibling (id int PRIMARY KEY, v1 int, CONSTRAINT fk_named FOREIGN KEY (v1) REFERENCES parent(v1));", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE sibling;", Expected: []sql.Row{{"sibling", "CREATE TABLE `sibling` (\n `id` int NOT NULL,\n `v1` int,\n PRIMARY KEY (`id`),\n KEY `v1` (`v1`),\n CONSTRAINT `fk_named` FOREIGN KEY (`v1`) REFERENCES `parent` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "Parent table index required", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1,v2) REFERENCES parent(v1,v2);", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, { Query: "ALTER TABLE child ADD CONSTRAINT fk_id FOREIGN KEY (v1) REFERENCES parent(id);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "indexes with prefix lengths are ignored for foreign keys", SetUpScript: []string{ "create table prefixParent(v varchar(100), index(v(1)))", }, Assertions: []ScriptTestAssertion{ { Query: "create table prefixChild(v varchar(100), foreign key (v) references prefixParent(v))", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, }, }, { Name: "CREATE TABLE Name Collision", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE child2 (id INT PRIMARY KEY, v1 INT, CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1), CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1));", ExpectedErr: sql.ErrForeignKeyDuplicateName, }, }, }, { Name: "CREATE TABLE Type Mismatch", SetUpScript: []string{ "CREATE TABLE sibling (pk INT PRIMARY KEY, v1 TIME);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE sibling ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1);", ExpectedErr: sql.ErrForeignKeyColumnTypeMismatch, }, }, }, { Name: "CREATE TABLE Type Mismatch special case for strings", SetUpScript: []string{ "CREATE TABLE parent1 (pk BIGINT PRIMARY KEY, v1 CHAR(20), INDEX (v1));", "CREATE TABLE parent2 (pk BIGINT PRIMARY KEY, v1 VARCHAR(20), INDEX (v1));", "CREATE TABLE parent3 (pk BIGINT PRIMARY KEY, v1 BINARY(20), INDEX (v1));", "CREATE TABLE parent4 (pk BIGINT PRIMARY KEY, v1 VARBINARY(20), INDEX (v1));", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE child1 (pk BIGINT PRIMARY KEY, v1 CHAR(30), CONSTRAINT fk_child1 FOREIGN KEY (v1) REFERENCES parent1 (v1));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CREATE TABLE child2 (pk BIGINT PRIMARY KEY, v1 VARCHAR(30), CONSTRAINT fk_child2 FOREIGN KEY (v1) REFERENCES parent2 (v1));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CREATE TABLE child3 (pk BIGINT PRIMARY KEY, v1 BINARY(30), CONSTRAINT fk_child3 FOREIGN KEY (v1) REFERENCES parent3 (v1));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CREATE TABLE child4 (pk BIGINT PRIMARY KEY, v1 VARBINARY(30), CONSTRAINT fk_child4 FOREIGN KEY (v1) REFERENCES parent4 (v1));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "CREATE TABLE Key Count Mismatch", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1, v2);", ExpectedErr: sql.ErrForeignKeyColumnCountMismatch, }, { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1, v2) REFERENCES parent(v1);", ExpectedErr: sql.ErrForeignKeyColumnCountMismatch, }, }, }, { Name: "SET DEFAULT not supported", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1) ON DELETE SET DEFAULT;", ExpectedErr: sql.ErrForeignKeySetDefault, }, { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1) ON UPDATE SET DEFAULT;", ExpectedErr: sql.ErrForeignKeySetDefault, }, { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1) ON UPDATE SET DEFAULT ON DELETE SET DEFAULT;", ExpectedErr: sql.ErrForeignKeySetDefault, }, }, }, { Name: "CREATE TABLE Disallow TEXT/BLOB", SetUpScript: []string{ "CREATE TABLE parent1 (id INT PRIMARY KEY, v1 TINYTEXT, v2 TEXT, v3 MEDIUMTEXT, v4 LONGTEXT);", "CREATE TABLE parent2 (id INT PRIMARY KEY, v1 TINYBLOB, v2 BLOB, v3 MEDIUMBLOB, v4 LONGBLOB);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE child11 (id INT PRIMARY KEY, parent_v1 TINYTEXT, FOREIGN KEY (parent_v1) REFERENCES parent1(v1));", ExpectedErr: sql.ErrForeignKeyTextBlob, }, { Query: "CREATE TABLE child12 (id INT PRIMARY KEY, parent_v2 TEXT, FOREIGN KEY (parent_v2) REFERENCES parent1(v2));", ExpectedErr: sql.ErrForeignKeyTextBlob, }, { Query: "CREATE TABLE child13 (id INT PRIMARY KEY, parent_v3 MEDIUMTEXT, FOREIGN KEY (parent_v3) REFERENCES parent1(v3));", ExpectedErr: sql.ErrForeignKeyTextBlob, }, { Query: "CREATE TABLE child14 (id INT PRIMARY KEY, parent_v4 LONGTEXT, FOREIGN KEY (parent_v4) REFERENCES parent1(v4));", ExpectedErr: sql.ErrForeignKeyTextBlob, }, { Query: "CREATE TABLE child21 (id INT PRIMARY KEY, parent_v1 TINYBLOB, FOREIGN KEY (parent_v1) REFERENCES parent2(v1));", ExpectedErr: sql.ErrForeignKeyTextBlob, }, { Query: "CREATE TABLE child22 (id INT PRIMARY KEY, parent_v2 BLOB, FOREIGN KEY (parent_v2) REFERENCES parent2(v2));", ExpectedErr: sql.ErrForeignKeyTextBlob, }, { Query: "CREATE TABLE child23 (id INT PRIMARY KEY, parent_v3 MEDIUMBLOB, FOREIGN KEY (parent_v3) REFERENCES parent2(v3));", ExpectedErr: sql.ErrForeignKeyTextBlob, }, { Query: "CREATE TABLE child24 (id INT PRIMARY KEY, parent_v4 LONGBLOB, FOREIGN KEY (parent_v4) REFERENCES parent2(v4));", ExpectedErr: sql.ErrForeignKeyTextBlob, }, }, }, { Name: "CREATE TABLE Non-existent Table", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES father(v1);", ExpectedErr: sql.ErrTableNotFound, }, }, }, { Name: "CREATE TABLE Non-existent Columns", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (random) REFERENCES parent(v1);", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(random);", ExpectedErr: sql.ErrTableColumnNotFound, }, }, }, { Name: "ALTER TABLE Foreign Key Name Collision", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1);", ExpectedErr: sql.ErrForeignKeyDuplicateName, }, }, }, { Name: "ALTER TABLE DROP FOREIGN KEY", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1);", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE child;", Expected: []sql.Row{{"child", "CREATE TABLE `child` (\n `id` int NOT NULL,\n `v1` int,\n `v2` int,\n PRIMARY KEY (`id`),\n KEY `v1` (`v1`),\n CONSTRAINT `fk_name` FOREIGN KEY (`v1`) REFERENCES `parent` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "ALTER TABLE child DROP FOREIGN KEY fk_name;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW CREATE TABLE child;", Expected: []sql.Row{{"child", "CREATE TABLE `child` (\n `id` int NOT NULL,\n `v1` int,\n `v2` int,\n PRIMARY KEY (`id`),\n KEY `v1` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "ALTER TABLE child DROP FOREIGN KEY fk_name;", ExpectedErr: sql.ErrForeignKeyNotFound, }, }, }, { Name: "ALTER TABLE SET NULL on non-nullable column", SetUpScript: []string{ "ALTER TABLE child MODIFY v1 int NOT NULL;", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1) ON DELETE SET NULL;", ExpectedErr: sql.ErrForeignKeySetNullNonNullable, }, { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1) ON UPDATE SET NULL;", ExpectedErr: sql.ErrForeignKeySetNullNonNullable, }, { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1) ON DELETE SET NULL ON UPDATE SET NULL;", ExpectedErr: sql.ErrForeignKeySetNullNonNullable, }, }, }, { Name: "ADD FOREIGN KEY fails on existing table when data would cause violation", SetUpScript: []string{ "INSERT INTO parent VALUES (1, 1, 1), (2, 2, 2);", "INSERT INTO child VALUES (1, 1, 1), (2, 3, 2);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1)", ExpectedErr: sql.ErrForeignKeyChildViolation, }, }, }, { Name: "RENAME TABLE", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1);", "RENAME TABLE parent TO new_parent;", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE child;", Expected: []sql.Row{{"child", "CREATE TABLE `child` (\n `id` int NOT NULL,\n `v1` int,\n `v2` int,\n PRIMARY KEY (`id`),\n KEY `v1` (`v1`),\n CONSTRAINT `fk_name` FOREIGN KEY (`v1`) REFERENCES `new_parent` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "RENAME TABLE child TO new_child;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW CREATE TABLE new_child;", Expected: []sql.Row{{"new_child", "CREATE TABLE `new_child` (\n `id` int NOT NULL,\n `v1` int,\n `v2` int,\n PRIMARY KEY (`id`),\n KEY `v1` (`v1`),\n CONSTRAINT `fk_name` FOREIGN KEY (`v1`) REFERENCES `new_parent` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "RENAME TABLE with primary key indexes", SetUpScript: []string{ "CREATE TABLE parent1 (pk BIGINT PRIMARY KEY);", "CREATE TABLE child1 (pk BIGINT PRIMARY KEY, CONSTRAINT `fk` FOREIGN KEY (pk) REFERENCES parent1(pk))", "RENAME TABLE parent1 TO new_parent1;", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE child1;", Expected: []sql.Row{{"child1", "CREATE TABLE `child1` (\n `pk` bigint NOT NULL,\n PRIMARY KEY (`pk`),\n CONSTRAINT `fk` FOREIGN KEY (`pk`) REFERENCES `new_parent1` (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "RENAME TABLE child1 TO new_child1;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW CREATE TABLE new_child1;", Expected: []sql.Row{{"new_child1", "CREATE TABLE `new_child1` (\n `pk` bigint NOT NULL,\n PRIMARY KEY (`pk`),\n CONSTRAINT `fk` FOREIGN KEY (`pk`) REFERENCES `new_parent1` (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "DROP TABLE", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1);", }, Assertions: []ScriptTestAssertion{ { Query: "DROP TABLE parent;", ExpectedErr: sql.ErrForeignKeyDropTable, }, { Query: "DROP TABLE child;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "DROP TABLE parent;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Indexes used by foreign keys can't be dropped", SetUpScript: []string{ "ALTER TABLE child ADD INDEX v1 (v1);", "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child DROP INDEX v1;", ExpectedErr: sql.ErrForeignKeyDropIndex, }, { Query: "ALTER TABLE parent DROP INDEX v1;", ExpectedErr: sql.ErrForeignKeyDropIndex, }, { Query: "ALTER TABLE child DROP FOREIGN KEY fk_name;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE child DROP INDEX v1;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE parent DROP INDEX v1;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "ALTER TABLE RENAME COLUMN", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1);", "ALTER TABLE parent RENAME COLUMN v1 TO v1_new;", "ALTER TABLE child RENAME COLUMN v1 TO v1_new;", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE child;", Expected: []sql.Row{{"child", "CREATE TABLE `child` (\n `id` int NOT NULL,\n `v1_new` int,\n `v2` int,\n PRIMARY KEY (`id`),\n KEY `v1` (`v1_new`),\n CONSTRAINT `fk1` FOREIGN KEY (`v1_new`) REFERENCES `parent` (`v1_new`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "ALTER TABLE MODIFY COLUMN type change not allowed", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE parent MODIFY v1 MEDIUMINT;", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE child MODIFY v1 MEDIUMINT;", ExpectedErr: sql.ErrForeignKeyTypeChange, }, }, }, { Name: "ALTER TABLE MODIFY COLUMN type change allowed when lengthening string", SetUpScript: []string{ "CREATE TABLE parent1 (pk BIGINT PRIMARY KEY, v1 CHAR(20), INDEX (v1));", "CREATE TABLE parent2 (pk BIGINT PRIMARY KEY, v1 VARCHAR(20), INDEX (v1));", "CREATE TABLE parent3 (pk BIGINT PRIMARY KEY, v1 BINARY(20), INDEX (v1));", "CREATE TABLE parent4 (pk BIGINT PRIMARY KEY, v1 VARBINARY(20), INDEX (v1));", "CREATE TABLE child1 (pk BIGINT PRIMARY KEY, v1 CHAR(20), CONSTRAINT fk_child1 FOREIGN KEY (v1) REFERENCES parent1 (v1));", "CREATE TABLE child2 (pk BIGINT PRIMARY KEY, v1 VARCHAR(20), CONSTRAINT fk_child2 FOREIGN KEY (v1) REFERENCES parent2 (v1));", "CREATE TABLE child3 (pk BIGINT PRIMARY KEY, v1 BINARY(20), CONSTRAINT fk_child3 FOREIGN KEY (v1) REFERENCES parent3 (v1));", "CREATE TABLE child4 (pk BIGINT PRIMARY KEY, v1 VARBINARY(20), CONSTRAINT fk_child4 FOREIGN KEY (v1) REFERENCES parent4 (v1));", "INSERT INTO parent2 VALUES (1, 'aa'), (2, 'bb');", "INSERT INTO child2 VALUES (1, 'aa');", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE parent1 MODIFY v1 CHAR(10);", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE child1 MODIFY v1 CHAR(10);", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE parent2 MODIFY v1 VARCHAR(10);", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE child2 MODIFY v1 VARCHAR(10);", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE parent3 MODIFY v1 BINARY(10);", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE child3 MODIFY v1 BINARY(10);", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE parent4 MODIFY v1 VARBINARY(10);", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE child4 MODIFY v1 VARBINARY(10);", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE parent1 MODIFY v1 CHAR(30);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE child1 MODIFY v1 CHAR(30);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE parent2 MODIFY v1 VARCHAR(30);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE child2 MODIFY v1 VARCHAR(30);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE parent3 MODIFY v1 BINARY(30);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE child3 MODIFY v1 BINARY(30);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE parent4 MODIFY v1 VARBINARY(30);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE child4 MODIFY v1 VARBINARY(30);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO child2 VALUES (2, 'bb');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT INTO child2 VALUES (3, 'cc');", ExpectedErr: sql.ErrForeignKeyChildViolation, }, }, }, { Name: "ALTER TABLE MODIFY COLUMN type change only cares about foreign key columns", SetUpScript: []string{ "CREATE TABLE parent1 (pk INT PRIMARY KEY, v1 INT UNSIGNED, v2 INT UNSIGNED, INDEX (v1));", "CREATE TABLE child1 (pk INT PRIMARY KEY, v1 INT UNSIGNED, v2 INT UNSIGNED, CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent1(v1));", "INSERT INTO parent1 VALUES (1, 2, 3), (4, 5, 6);", "INSERT INTO child1 VALUES (7, 2, 9);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE parent1 MODIFY v1 BIGINT;", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE child1 MODIFY v1 BIGINT;", ExpectedErr: sql.ErrForeignKeyTypeChange, }, { Query: "ALTER TABLE parent1 MODIFY v2 BIGINT;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE child1 MODIFY v2 BIGINT;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "DROP COLUMN parent", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE parent DROP COLUMN v1;", ExpectedErr: sql.ErrForeignKeyDropColumn, }, { Query: "ALTER TABLE child DROP FOREIGN KEY fk_name;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE parent DROP COLUMN v1;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "DROP COLUMN child", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child DROP COLUMN v1;", ExpectedErr: sql.ErrForeignKeyDropColumn, }, { Query: "ALTER TABLE child DROP FOREIGN KEY fk_name;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE child DROP COLUMN v1;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Disallow change column to nullable with ON UPDATE SET NULL", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1) ON UPDATE SET NULL", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child CHANGE COLUMN v1 v1 INT NOT NULL;", ExpectedErr: sql.ErrForeignKeyTypeChangeSetNull, }, }, }, { Name: "Disallow change column to nullable with ON DELETE SET NULL", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent(v1) ON DELETE SET NULL", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child CHANGE COLUMN v1 v1 INT NOT NULL;", ExpectedErr: sql.ErrForeignKeyTypeChangeSetNull, }, }, }, { Name: "SQL CASCADE", SetUpScript: []string{ "CREATE TABLE one (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX v1 (v1));", "CREATE TABLE two (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX v1v2 (v1, v2), CONSTRAINT fk_name_1 FOREIGN KEY (v1) REFERENCES one(v1) ON DELETE CASCADE ON UPDATE CASCADE);", "CREATE TABLE three (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, CONSTRAINT fk_name_2 FOREIGN KEY (v1, v2) REFERENCES two(v1, v2) ON DELETE CASCADE ON UPDATE CASCADE);", "INSERT INTO one VALUES (1, 1, 4), (2, 2, 5), (3, 3, 6), (4, 4, 5);", "INSERT INTO two VALUES (2, 1, 1), (3, 2, 2), (4, 3, 3), (5, 4, 4);", "INSERT INTO three VALUES (3, 1, 1), (4, 2, 2), (5, 3, 3), (6, 4, 4);", "UPDATE one SET v1 = v1 + v2;", "DELETE one FROM one WHERE pk = 3;", "UPDATE two SET v2 = v1 - 2;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM one;", Expected: []sql.Row{{1, 5, 4}, {2, 7, 5}, {4, 9, 5}}, }, { Query: "SELECT * FROM two;", Expected: []sql.Row{{2, 5, 3}, {3, 7, 5}}, }, { Query: "SELECT * FROM three;", Expected: []sql.Row{{3, 5, 3}, {4, 7, 5}}, }, }, }, { Name: "SQL SET NULL", SetUpScript: []string{ "CREATE TABLE one (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX v1 (v1));", "CREATE TABLE two (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, CONSTRAINT fk_name_1 FOREIGN KEY (v1) REFERENCES one(v1) ON DELETE SET NULL ON UPDATE SET NULL);", "INSERT INTO one VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);", "INSERT INTO two VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);", "UPDATE one SET v1 = v1 * v2;", "INSERT INTO one VALUES (4, 4, 4);", "INSERT INTO two VALUES (4, 4, 4);", "UPDATE one SET v2 = v1 * v2;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM one;", Expected: []sql.Row{{1, 1, 1}, {2, 4, 8}, {3, 9, 27}, {4, 4, 16}}, }, { Query: "SELECT * FROM two;", Expected: []sql.Row{{1, 1, 1}, {2, nil, 2}, {3, nil, 3}, {4, 4, 4}}, }, { Query: "DELETE one FROM one inner join two on one.pk=two.pk;", Expected: []sql.Row{{types.NewOkResult(4)}}, }, { Query: "select * from two;", Expected: []sql.Row{{1, nil, 1}, {2, nil, 2}, {3, nil, 3}, {4, nil, 4}}, }, }, }, { Name: "SQL RESTRICT", SetUpScript: []string{ "CREATE TABLE one (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX v1 (v1));", "CREATE TABLE two (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, CONSTRAINT fk_name_1 FOREIGN KEY (v1) REFERENCES one(v1) ON DELETE RESTRICT ON UPDATE RESTRICT);", "INSERT INTO one VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);", "INSERT INTO two VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE one SET v1 = v1 + v2;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "UPDATE one SET v1 = v1;", Expected: []sql.Row{{types.OkResult{Info: plan.UpdateInfo{Matched: 3}}}}, }, { Query: "DELETE FROM one;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "DELETE one FROM one inner join two on one.pk=two.pk;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "DELETE one, two FROM one inner join two on one.pk=two.pk;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, }, }, { Name: "Multi-table DELETE FROM JOIN with multiple foreign keys", SetUpScript: []string{ "CREATE TABLE one (pk int PRIMARY KEY);", "CREATE TABLE two (pk int PRIMARY KEY);", "CREATE TABLE three (pk int PRIMARY KEY, fk3 int, CONSTRAINT fk_3 FOREIGN KEY (fk3) REFERENCES one(pk) ON DELETE CASCADE);", "CREATE TABLE four (pk int PRIMARY KEY, fk4 int, CONSTRAINT fk_4 FOREIGN KEY (fk4) REFERENCES two(pk) ON DELETE CASCADE);", "INSERT INTO one VALUES (1), (2), (3);", "INSERT INTO two VALUES (1), (2), (3);", "INSERT INTO three VALUES (1, 1), (2, 2), (3, 3);", "INSERT INTO four VALUES (1, 1), (2, 2), (3, 3);", "DELETE one, two FROM one inner join two on one.pk=two.pk", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * from three union all select * from four;", Expected: []sql.Row{}, }, }, }, { Name: "Single-table DELETE FROM JOIN with multiple foreign keys", SetUpScript: []string{ "CREATE TABLE one (pk int PRIMARY KEY);", "CREATE TABLE two (pk int PRIMARY KEY);", "CREATE TABLE three (pk int PRIMARY KEY, fk3 int, CONSTRAINT fk_3 FOREIGN KEY (fk3) REFERENCES one(pk) ON DELETE CASCADE);", "CREATE TABLE four (pk int PRIMARY KEY, fk4 int, CONSTRAINT fk_4 FOREIGN KEY (fk4) REFERENCES two(pk) ON DELETE CASCADE);", "INSERT INTO one VALUES (1), (2), (3);", "INSERT INTO two VALUES (1), (2), (3);", "INSERT INTO three VALUES (1, 1), (2, 2), (3, 3);", "INSERT INTO four VALUES (1, 1), (2, 2), (3, 3);", "DELETE t1 FROM one t1 inner join two t2 on t1.pk=t2.pk", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * from three;", Expected: []sql.Row{}, }, { Query: "select * from four;", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, }, }, { Name: "SQL no reference options", SetUpScript: []string{ "CREATE TABLE one (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX v1 (v1));", "CREATE TABLE two (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, CONSTRAINT fk_name_1 FOREIGN KEY (v1) REFERENCES one(v1));", "INSERT INTO one VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);", "INSERT INTO two VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE one SET v1 = v1 + v2;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "UPDATE one SET v1 = v1;", Expected: []sql.Row{{types.OkResult{Info: plan.UpdateInfo{Matched: 3}}}}, }, { Query: "DELETE FROM one;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, }, }, { Name: "SQL INSERT multiple keys violates only one", SetUpScript: []string{ "CREATE TABLE one (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX v1 (v1), INDEX v2 (v2));", "CREATE TABLE two (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, CONSTRAINT fk_name_1 FOREIGN KEY (v1) REFERENCES one(v1), CONSTRAINT fk_name_2 FOREIGN KEY (v2) REFERENCES one(v2));", "INSERT INTO one VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);", "INSERT INTO two VALUES (1, NULL, 1);", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO two VALUES (2, NULL, 4);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, { Query: "INSERT INTO two VALUES (3, 4, NULL);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, { Query: "INSERT INTO two VALUES (4, NULL, NULL);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, }, }, { Name: "Self-referential same column(s)", SetUpScript: []string{ "CREATE INDEX v1v2 ON parent(v1, v2);", "CREATE TABLE parent2 (id INT PRIMARY KEY, v1 INT, v2 INT, INDEX v1v2 (v1, v2));", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE parent ADD CONSTRAINT fk_name1 FOREIGN KEY (v1) REFERENCES parent(v1);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE parent ADD CONSTRAINT fk_name2 FOREIGN KEY (v1, v2) REFERENCES parent(v1, v2);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Self-referential child column follows parent RESTRICT", SetUpScript: []string{ "ALTER TABLE parent ADD CONSTRAINT fk_named FOREIGN KEY (v2) REFERENCES parent(v1);", "INSERT INTO parent VALUES (1, 1, 1), (2, 2, 1), (3, 3, NULL);", "UPDATE parent SET v1 = 1 WHERE id = 1;", "UPDATE parent SET v1 = 4 WHERE id = 3;", "DELETE FROM parent WHERE id = 3;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM parent;", Expected: []sql.Row{{1, 1, 1}, {2, 2, 1}}, }, { Query: "DELETE FROM parent WHERE v1 = 1;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "UPDATE parent SET v1 = 2;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "REPLACE INTO parent VALUES (1, 1, 1);", ExpectedErr: sql.ErrForeignKeyParentViolation, }, }, }, { Name: "Self-referential child column follows parent CASCADE", SetUpScript: []string{ "ALTER TABLE parent ADD CONSTRAINT fk_named FOREIGN KEY (v2) REFERENCES parent(v1) ON UPDATE CASCADE ON DELETE CASCADE;", "INSERT INTO parent VALUES (1, 1, 1), (2, 2, 1), (3, 3, NULL);", "UPDATE parent SET v1 = 1 WHERE id = 1;", "UPDATE parent SET v1 = 4 WHERE id = 3;", "DELETE FROM parent WHERE id = 3;", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE parent SET v1 = 2;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "REPLACE INTO parent VALUES (1, 1, 1), (2, 2, 2);", Expected: []sql.Row{{types.NewOkResult(3)}}, }, { Query: "SELECT * FROM parent;", Expected: []sql.Row{{1, 1, 1}, {2, 2, 2}}, }, { Query: "UPDATE parent SET v1 = 2;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "UPDATE parent SET v1 = 2 WHERE id = 1;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "REPLACE INTO parent VALUES (1, 1, 2), (2, 2, 1);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, { Query: "UPDATE parent SET v2 = 2 WHERE id = 1;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "UPDATE parent SET v2 = 1 WHERE id = 2;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "SELECT * FROM parent;", Expected: []sql.Row{{1, 1, 2}, {2, 2, 1}}, }, { Query: "UPDATE parent SET v1 = 2;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "UPDATE parent SET v1 = 2 WHERE id = 1;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "DELETE FROM parent WHERE v1 = 1;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM parent;", Expected: []sql.Row{}, }, }, }, { Name: "Self-referential child column follows parent SET NULL", SetUpScript: []string{ "ALTER TABLE parent ADD CONSTRAINT fk_named FOREIGN KEY (v2) REFERENCES parent(v1) ON UPDATE SET NULL ON DELETE SET NULL;", "INSERT INTO parent VALUES (1,1,1), (2, 2, 1), (3, 3, NULL);", "UPDATE parent SET v1 = 1 WHERE id = 1;", "UPDATE parent SET v1 = 4 WHERE id = 3;", "DELETE FROM parent WHERE id = 3;", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE parent SET v1 = 2;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "REPLACE INTO parent VALUES (1, 1, 1), (2, 2, 2);", Expected: []sql.Row{{types.NewOkResult(4)}}, }, { Query: "SELECT * FROM parent;", Expected: []sql.Row{{1, 1, 1}, {2, 2, 2}}, }, { Query: "UPDATE parent SET v1 = 2;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "UPDATE parent SET v1 = 2 WHERE id = 1;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "REPLACE INTO parent VALUES (1,1,2), (2,2,1);", Expected: []sql.Row{{types.NewOkResult(4)}}, }, { Query: "SELECT * FROM parent;", Expected: []sql.Row{{1, 1, nil}, {2, 2, 1}}, }, { Query: "UPDATE parent SET v2 = 2 WHERE id = 1;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "UPDATE parent SET v2 = 1 WHERE id = 2;", Expected: []sql.Row{{types.OkResult{RowsAffected: 0, Info: plan.UpdateInfo{Matched: 1}}}}, }, { Query: "SELECT * FROM parent;", Expected: []sql.Row{{1, 1, 2}, {2, 2, 1}}, }, { Query: "UPDATE parent SET v1 = 2;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "UPDATE parent SET v1 = 2 WHERE id = 1;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "DELETE FROM parent WHERE v1 = 1;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM parent;", Expected: []sql.Row{{2, 2, nil}}, }, }, }, { Name: "Multiple self-referential foreign keys without data", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE, v2 BIGINT UNIQUE, v3 BIGINT UNIQUE, v4 BIGINT UNIQUE," + "v5 BIGINT UNIQUE, v6 BIGINT UNIQUE, v7 BIGINT UNIQUE," + "CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES test (pk)," + "CONSTRAINT fk2 FOREIGN KEY (v2) REFERENCES test (pk)," + "CONSTRAINT fk3 FOREIGN KEY (v3) REFERENCES test (pk)," + "CONSTRAINT fk4 FOREIGN KEY (v4) REFERENCES test (pk)," + "CONSTRAINT fk5 FOREIGN KEY (v5) REFERENCES test (pk)," + "CONSTRAINT fk6 FOREIGN KEY (v6) REFERENCES test (pk)," + "CONSTRAINT fk7 FOREIGN KEY (v7) REFERENCES test (pk));", }, Assertions: []ScriptTestAssertion{ { Query: `UPDATE test SET v1 = NULL, v2 = NULL WHERE test.pk = 0;`, Expected: []sql.Row{{types.OkResult{ RowsAffected: 0, InsertID: 0, Info: plan.UpdateInfo{ Matched: 0, Updated: 0, Warnings: 0, }, }}}, }, }, }, { Name: "Self-referential delete cascade depth limit", SetUpScript: []string{ "CREATE TABLE under_limit(pk BIGINT PRIMARY KEY, v1 BIGINT, INDEX idx_v1(v1));", "CREATE TABLE over_limit(pk BIGINT PRIMARY KEY, v1 BIGINT, INDEX idx_v1(v1));", "INSERT INTO under_limit VALUES (1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(8,9),(9,10),(10,11),(11,12),(12,13),(13,14),(14,1);", "INSERT INTO over_limit VALUES (1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(8,9),(9,10),(10,11),(11,12),(12,13),(13,14),(14,15),(15,1);", "ALTER TABLE under_limit ADD CONSTRAINT fk_under FOREIGN KEY (v1) REFERENCES under_limit(pk) ON UPDATE CASCADE ON DELETE CASCADE;", "ALTER TABLE over_limit ADD CONSTRAINT fk_over FOREIGN KEY (v1) REFERENCES over_limit(pk) ON UPDATE CASCADE ON DELETE CASCADE;", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE FROM under_limit WHERE pk = 1;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "DELETE FROM over_limit WHERE pk = 1;", ExpectedErr: sql.ErrForeignKeyDepthLimit, }, { Query: "DELETE FROM over_limit WHERE pk = 0;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "UPDATE over_limit SET pk = 1 WHERE pk = 1;", Expected: []sql.Row{{types.OkResult{ RowsAffected: 0, InsertID: 0, Info: plan.UpdateInfo{ Matched: 1, Updated: 0, Warnings: 0, }, }}}, }, { Query: "UPDATE over_limit SET pk = 2 WHERE pk = 1;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, }, }, { Name: "Cyclic 2-table delete cascade depth limit", SetUpScript: []string{ "CREATE TABLE under_cycle1(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);", "CREATE TABLE under_cycle2(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);", "INSERT INTO under_cycle1 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7);", "INSERT INTO under_cycle2 VALUES (1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,1);", "ALTER TABLE under_cycle1 ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES under_cycle2(pk) ON UPDATE CASCADE ON DELETE CASCADE;", "ALTER TABLE under_cycle2 ADD CONSTRAINT fk2 FOREIGN KEY (v1) REFERENCES under_cycle1(pk) ON UPDATE CASCADE ON DELETE CASCADE;", "CREATE TABLE over_cycle1(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);", "CREATE TABLE over_cycle2(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);", "INSERT INTO over_cycle1 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8);", "INSERT INTO over_cycle2 VALUES (1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(8,1);", "ALTER TABLE over_cycle1 ADD CONSTRAINT fk3 FOREIGN KEY (v1) REFERENCES over_cycle2(pk) ON UPDATE CASCADE ON DELETE CASCADE;", "ALTER TABLE over_cycle2 ADD CONSTRAINT fk4 FOREIGN KEY (v1) REFERENCES over_cycle1(pk) ON UPDATE CASCADE ON DELETE CASCADE;", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE FROM under_cycle1 WHERE pk = 1;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "DELETE FROM over_cycle1 WHERE pk = 1;", ExpectedErr: sql.ErrForeignKeyDepthLimit, }, }, }, { Name: "Cyclic 3-table delete cascade depth limit", SetUpScript: []string{ "CREATE TABLE under_cycle1(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);", "CREATE TABLE under_cycle2(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);", "CREATE TABLE under_cycle3(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);", "INSERT INTO under_cycle1 VALUES (1,1),(2,2),(3,3),(4,4);", "INSERT INTO under_cycle2 VALUES (1,1),(2,2),(3,3),(4,4);", "INSERT INTO under_cycle3 VALUES (1,2),(2,3),(3,4),(4,1);", "ALTER TABLE under_cycle1 ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES under_cycle2(pk) ON UPDATE CASCADE ON DELETE CASCADE;", "ALTER TABLE under_cycle2 ADD CONSTRAINT fk2 FOREIGN KEY (v1) REFERENCES under_cycle3(pk) ON UPDATE CASCADE ON DELETE CASCADE;", "ALTER TABLE under_cycle3 ADD CONSTRAINT fk3 FOREIGN KEY (v1) REFERENCES under_cycle1(pk) ON UPDATE CASCADE ON DELETE CASCADE;", "CREATE TABLE over_cycle1(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);", "CREATE TABLE over_cycle2(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);", "CREATE TABLE over_cycle3(pk BIGINT PRIMARY KEY, v1 BIGINT UNIQUE);", "INSERT INTO over_cycle1 VALUES (1,1),(2,2),(3,3),(4,4),(5,5);", "INSERT INTO over_cycle2 VALUES (1,1),(2,2),(3,3),(4,4),(5,5);", "INSERT INTO over_cycle3 VALUES (1,2),(2,3),(3,4),(4,5),(5,1);", "ALTER TABLE over_cycle1 ADD CONSTRAINT fk4 FOREIGN KEY (v1) REFERENCES over_cycle2(pk) ON UPDATE CASCADE ON DELETE CASCADE;", "ALTER TABLE over_cycle2 ADD CONSTRAINT fk5 FOREIGN KEY (v1) REFERENCES over_cycle3(pk) ON UPDATE CASCADE ON DELETE CASCADE;", "ALTER TABLE over_cycle3 ADD CONSTRAINT fk6 FOREIGN KEY (v1) REFERENCES over_cycle1(pk) ON UPDATE CASCADE ON DELETE CASCADE;", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE FROM under_cycle1 WHERE pk = 1;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "DELETE FROM over_cycle1 WHERE pk = 1;", ExpectedErr: sql.ErrForeignKeyDepthLimit, }, }, }, { Name: "Acyclic delete cascade depth limit", SetUpScript: []string{ "CREATE TABLE t1(pk BIGINT PRIMARY KEY);", "CREATE TABLE t2(pk BIGINT PRIMARY KEY, CONSTRAINT fk1 FOREIGN KEY (pk) REFERENCES t1(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t3(pk BIGINT PRIMARY KEY, CONSTRAINT fk2 FOREIGN KEY (pk) REFERENCES t2(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t4(pk BIGINT PRIMARY KEY, CONSTRAINT fk3 FOREIGN KEY (pk) REFERENCES t3(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t5(pk BIGINT PRIMARY KEY, CONSTRAINT fk4 FOREIGN KEY (pk) REFERENCES t4(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t6(pk BIGINT PRIMARY KEY, CONSTRAINT fk5 FOREIGN KEY (pk) REFERENCES t5(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t7(pk BIGINT PRIMARY KEY, CONSTRAINT fk6 FOREIGN KEY (pk) REFERENCES t6(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t8(pk BIGINT PRIMARY KEY, CONSTRAINT fk7 FOREIGN KEY (pk) REFERENCES t7(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t9(pk BIGINT PRIMARY KEY, CONSTRAINT fk8 FOREIGN KEY (pk) REFERENCES t8(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t10(pk BIGINT PRIMARY KEY, CONSTRAINT fk9 FOREIGN KEY (pk) REFERENCES t9(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t11(pk BIGINT PRIMARY KEY, CONSTRAINT fk10 FOREIGN KEY (pk) REFERENCES t10(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t12(pk BIGINT PRIMARY KEY, CONSTRAINT fk11 FOREIGN KEY (pk) REFERENCES t11(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t13(pk BIGINT PRIMARY KEY, CONSTRAINT fk12 FOREIGN KEY (pk) REFERENCES t12(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t14(pk BIGINT PRIMARY KEY, CONSTRAINT fk13 FOREIGN KEY (pk) REFERENCES t13(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t15(pk BIGINT PRIMARY KEY, CONSTRAINT fk14 FOREIGN KEY (pk) REFERENCES t14(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t16(pk BIGINT PRIMARY KEY, CONSTRAINT fk15 FOREIGN KEY (pk) REFERENCES t15(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "INSERT INTO t1 VALUES (1);", "INSERT INTO t2 VALUES (1);", "INSERT INTO t3 VALUES (1);", "INSERT INTO t4 VALUES (1);", "INSERT INTO t5 VALUES (1);", "INSERT INTO t6 VALUES (1);", "INSERT INTO t7 VALUES (1);", "INSERT INTO t8 VALUES (1);", "INSERT INTO t9 VALUES (1);", "INSERT INTO t10 VALUES (1);", "INSERT INTO t11 VALUES (1);", "INSERT INTO t12 VALUES (1);", "INSERT INTO t13 VALUES (1);", "INSERT INTO t14 VALUES (1);", "INSERT INTO t15 VALUES (1);", "INSERT INTO t16 VALUES (1);", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE FROM t1;", ExpectedErr: sql.ErrForeignKeyDepthLimit, }, { Query: "DELETE FROM t16;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "DELETE FROM t1;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, }, }, { Name: "Acyclic update cascade depth limit", SetUpScript: []string{ "CREATE TABLE t1(pk BIGINT PRIMARY KEY);", "CREATE TABLE t2(pk BIGINT PRIMARY KEY, CONSTRAINT fk1 FOREIGN KEY (pk) REFERENCES t1(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t3(pk BIGINT PRIMARY KEY, CONSTRAINT fk2 FOREIGN KEY (pk) REFERENCES t2(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t4(pk BIGINT PRIMARY KEY, CONSTRAINT fk3 FOREIGN KEY (pk) REFERENCES t3(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t5(pk BIGINT PRIMARY KEY, CONSTRAINT fk4 FOREIGN KEY (pk) REFERENCES t4(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t6(pk BIGINT PRIMARY KEY, CONSTRAINT fk5 FOREIGN KEY (pk) REFERENCES t5(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t7(pk BIGINT PRIMARY KEY, CONSTRAINT fk6 FOREIGN KEY (pk) REFERENCES t6(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t8(pk BIGINT PRIMARY KEY, CONSTRAINT fk7 FOREIGN KEY (pk) REFERENCES t7(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t9(pk BIGINT PRIMARY KEY, CONSTRAINT fk8 FOREIGN KEY (pk) REFERENCES t8(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t10(pk BIGINT PRIMARY KEY, CONSTRAINT fk9 FOREIGN KEY (pk) REFERENCES t9(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t11(pk BIGINT PRIMARY KEY, CONSTRAINT fk10 FOREIGN KEY (pk) REFERENCES t10(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t12(pk BIGINT PRIMARY KEY, CONSTRAINT fk11 FOREIGN KEY (pk) REFERENCES t11(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t13(pk BIGINT PRIMARY KEY, CONSTRAINT fk12 FOREIGN KEY (pk) REFERENCES t12(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t14(pk BIGINT PRIMARY KEY, CONSTRAINT fk13 FOREIGN KEY (pk) REFERENCES t13(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t15(pk BIGINT PRIMARY KEY, CONSTRAINT fk14 FOREIGN KEY (pk) REFERENCES t14(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "CREATE TABLE t16(pk BIGINT PRIMARY KEY, CONSTRAINT fk15 FOREIGN KEY (pk) REFERENCES t15(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "INSERT INTO t1 VALUES (1);", "INSERT INTO t2 VALUES (1);", "INSERT INTO t3 VALUES (1);", "INSERT INTO t4 VALUES (1);", "INSERT INTO t5 VALUES (1);", "INSERT INTO t6 VALUES (1);", "INSERT INTO t7 VALUES (1);", "INSERT INTO t8 VALUES (1);", "INSERT INTO t9 VALUES (1);", "INSERT INTO t10 VALUES (1);", "INSERT INTO t11 VALUES (1);", "INSERT INTO t12 VALUES (1);", "INSERT INTO t13 VALUES (1);", "INSERT INTO t14 VALUES (1);", "INSERT INTO t15 VALUES (1);", "INSERT INTO t16 VALUES (1);", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE t1 SET pk = 2;", ExpectedErr: sql.ErrForeignKeyDepthLimit, }, { Query: "DELETE FROM t16;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "UPDATE t1 SET pk = 2;", Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, InsertID: 0, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, Warnings: 0, }, }}}, }, }, }, { Name: "VARCHAR child violation detection", SetUpScript: []string{ "CREATE TABLE colors (id INT NOT NULL, color VARCHAR(32) NOT NULL, PRIMARY KEY (id), INDEX color_index(color));", "CREATE TABLE objects (id INT NOT NULL, name VARCHAR(64) NOT NULL, color VARCHAR(32), PRIMARY KEY(id), CONSTRAINT color_fk FOREIGN KEY (color) REFERENCES colors(color));", "INSERT INTO colors (id, color) VALUES (1, 'red'), (2, 'green'), (3, 'blue'), (4, 'purple');", "INSERT INTO objects (id, name, color) VALUES (1, 'truck', 'red'), (2, 'ball', 'green'), (3, 'shoe', 'blue');", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE FROM colors where color='green';", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "SELECT * FROM colors;", Expected: []sql.Row{{1, "red"}, {2, "green"}, {3, "blue"}, {4, "purple"}}, }, }, }, { Name: "INSERT IGNORE INTO works correctly with foreign key violations", SetUpScript: []string{ "CREATE TABLE colors (id INT NOT NULL, color VARCHAR(32) NOT NULL, PRIMARY KEY (id), INDEX color_index(color));", "CREATE TABLE objects (id INT NOT NULL, name VARCHAR(64) NOT NULL, color VARCHAR(32), PRIMARY KEY(id), CONSTRAINT color_fk FOREIGN KEY (color) REFERENCES colors(color));", "INSERT INTO colors (id, color) VALUES (1, 'red'), (2, 'green'), (3, 'blue'), (4, 'purple');", "INSERT INTO objects (id, name, color) VALUES (1, 'truck', 'red'), (2, 'ball', 'green'), (3, 'shoe', 'blue');", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT IGNORE INTO objects (id, name, color) VALUES (5, 'hi', 'yellow');", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM objects;", Expected: []sql.Row{{1, "truck", "red"}, {2, "ball", "green"}, {3, "shoe", "blue"}}, }, }, }, { Name: "Delayed foreign key resolution", SetUpScript: []string{ "SET FOREIGN_KEY_CHECKS=0;", "CREATE TABLE delayed_child (pk INT PRIMARY KEY, v1 INT, CONSTRAINT fk_delayed FOREIGN KEY (v1) REFERENCES delayed_parent(v1));", "CREATE TABLE delayed_parent (pk INT PRIMARY KEY, v1 INT, INDEX (v1));", "INSERT INTO delayed_child VALUES (1, 2);", "SET FOREIGN_KEY_CHECKS=1;", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE delayed_child;", Expected: []sql.Row{{"delayed_child", "CREATE TABLE `delayed_child` (\n `pk` int NOT NULL,\n `v1` int,\n PRIMARY KEY (`pk`),\n KEY `v1` (`v1`),\n CONSTRAINT `fk_delayed` FOREIGN KEY (`v1`) REFERENCES `delayed_parent` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "SELECT * FROM delayed_parent;", Expected: []sql.Row{}, }, { Query: "SELECT * FROM delayed_child;", Expected: []sql.Row{{1, 2}}, }, { Query: "INSERT INTO delayed_child VALUES (2, 3);", ExpectedErr: sql.ErrForeignKeyNotResolved, }, { Query: "INSERT INTO delayed_parent VALUES (1, 2), (2, 3);", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "INSERT INTO delayed_child VALUES (2, 3);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM delayed_child;", Expected: []sql.Row{{1, 2}, {2, 3}}, }, }, }, { Name: "Delayed foreign key still does some validation", SetUpScript: []string{ "SET FOREIGN_KEY_CHECKS=0;", "CREATE TABLE valid_delayed_child (i INT, CONSTRAINT valid_fk FOREIGN KEY (i) REFERENCES delayed_parent(i))", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE delayed_child1(i int, CONSTRAINT fk_delayed1 FOREIGN KEY (badcolumn) REFERENCES delayed_parent(i));", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "CREATE TABLE delayed_child2(i int, CONSTRAINT fk_delayed2 FOREIGN KEY (i) REFERENCES delayed_parent(c1, c2, c3));", ExpectedErr: sql.ErrForeignKeyColumnCountMismatch, }, { Query: "CREATE TABLE delayed_child3(i int, j int, CONSTRAINT fk_i FOREIGN KEY (i) REFERENCES delayed_parent(i), CONSTRAINT fk_i FOREIGN KEY (j) REFERENCES delayed_parent(j));", ExpectedErr: sql.ErrForeignKeyDuplicateName, }, { Query: "CREATE TABLE delayed_child4(i int, CONSTRAINT fk_delayed4 FOREIGN KEY (i,i,i) REFERENCES delayed_parent(c1, c2, c3));", ExpectedErr: sql.ErrAddForeignKeyDuplicateColumn, }, { Query: "ALTER TABLE valid_delayed_child drop index i", ExpectedErr: sql.ErrForeignKeyDropIndex, }, }, }, { Name: "Delayed foreign key resolution resetting FOREIGN_KEY_CHECKS", SetUpScript: []string{ "SET FOREIGN_KEY_CHECKS=0;", "CREATE TABLE delayed_child (pk INT PRIMARY KEY, v1 INT, CONSTRAINT fk_delayed FOREIGN KEY (v1) REFERENCES delayed_parent(v1));", "INSERT INTO delayed_child VALUES (1, 2);", "SET FOREIGN_KEY_CHECKS=1;", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE delayed_child;", Expected: []sql.Row{{"delayed_child", "CREATE TABLE `delayed_child` (\n `pk` int NOT NULL,\n `v1` int,\n PRIMARY KEY (`pk`),\n KEY `v1` (`v1`),\n CONSTRAINT `fk_delayed` FOREIGN KEY (`v1`) REFERENCES `delayed_parent` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "SELECT * FROM delayed_child;", Expected: []sql.Row{{1, 2}}, }, { Query: "INSERT INTO delayed_child VALUES (2, 3);", ExpectedErr: sql.ErrForeignKeyNotResolved, }, { Query: "CREATE TABLE delayed_parent (pk INT PRIMARY KEY, v1 INT, INDEX (v1));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO delayed_parent VALUES (1, 2), (2, 3);", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "INSERT INTO delayed_child VALUES (2, 3);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM delayed_child;", Expected: []sql.Row{{1, 2}, {2, 3}}, }, }, }, { Name: "DROP TABLE with FOREIGN_KEY_CHECKS=0", SetUpScript: []string{ "ALTER TABLE child ADD CONSTRAINT fk_dropped FOREIGN KEY (v1) REFERENCES parent(v1);", }, Assertions: []ScriptTestAssertion{ { Query: "TRUNCATE parent;", ExpectedErr: sql.ErrTruncateReferencedFromForeignKey, }, { Query: "DROP TABLE parent;", ExpectedErr: sql.ErrForeignKeyDropTable, }, { Query: "SET FOREIGN_KEY_CHECKS=0;", Expected: []sql.Row{{}}, }, { Query: "TRUNCATE parent;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "DROP TABLE parent;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SET FOREIGN_KEY_CHECKS=1;", Expected: []sql.Row{{}}, }, { Query: "INSERT INTO child VALUES (4, 5, 6);", ExpectedErr: sql.ErrForeignKeyNotResolved, }, { Query: "CREATE TABLE parent (pk INT PRIMARY KEY, v1 INT, INDEX (v1));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO parent VALUES (1, 5);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT INTO child VALUES (4, 5, 6);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM parent;", Expected: []sql.Row{{1, 5}}, }, { Query: "SELECT * FROM child;", Expected: []sql.Row{{4, 5, 6}}, }, }, }, { Name: "ALTER TABLE ADD CONSTRAINT for different database", SetUpScript: []string{ "CREATE DATABASE public;", "CREATE TABLE public.cities (pk INT PRIMARY KEY, city VARCHAR(255), state VARCHAR(2));", "CREATE TABLE public.states (state_id INT PRIMARY KEY, state VARCHAR(2));", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE public.cities ADD CONSTRAINT foreign_key1 FOREIGN KEY (state) REFERENCES public.states(state);", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, { Query: "CREATE INDEX foreign_key1 ON public.states(state);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE public.cities ADD CONSTRAINT foreign_key1 FOREIGN KEY (state) REFERENCES public.states(state);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Creating a foreign key on a table with an unsupported type works", SetUpScript: []string{ "CREATE TABLE IF NOT EXISTS restaurants (id INT PRIMARY KEY, coordinate POINT);", "CREATE TABLE IF NOT EXISTS hours (restaurant_id INT PRIMARY KEY AUTO_INCREMENT, CONSTRAINT fk_name FOREIGN KEY (restaurant_id) REFERENCES restaurants(id));", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE hours;", Expected: []sql.Row{{"hours", "CREATE TABLE `hours` (\n `restaurant_id` int NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`restaurant_id`),\n CONSTRAINT `fk_name` FOREIGN KEY (`restaurant_id`) REFERENCES `restaurants` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "Create foreign key onto primary key", SetUpScript: []string{ "DROP TABLE child;", "DROP TABLE parent;", "CREATE TABLE parent (a INT, b INT, c INT, PRIMARY KEY (b, a));", "CREATE TABLE child (a INT PRIMARY KEY, b INT);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (b) REFERENCES parent (b);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE child ADD CONSTRAINT fk2 FOREIGN KEY (a) REFERENCES parent (b);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE child ADD CONSTRAINT fk3 FOREIGN KEY (a, b) REFERENCES parent (a, b);", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, { Query: "ALTER TABLE child ADD CONSTRAINT fk4 FOREIGN KEY (b, a) REFERENCES parent (b, a);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Reordered foreign key columns do match", SetUpScript: []string{ "DROP TABLE child;", "DROP TABLE parent;", "CREATE TABLE parent(fk1 int, fk2 int, primary key(fk1, fk2));", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE child(id int unique, fk1 int, fk2 int, primary key(fk2, fk1, id), constraint `fk` foreign key(fk1, fk2) references parent (fk1, fk2));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "Show create table child;", Expected: []sql.Row{ {"child", "CREATE TABLE `child` (\n" + " `id` int NOT NULL,\n" + " `fk1` int NOT NULL,\n" + " `fk2` int NOT NULL,\n" + " PRIMARY KEY (`fk2`,`fk1`,`id`),\n" + " KEY `fk1fk2` (`fk1`,`fk2`),\n" + " UNIQUE KEY `id` (`id`),\n" + " CONSTRAINT `fk` FOREIGN KEY (`fk1`,`fk2`) REFERENCES `parent` (`fk1`,`fk2`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, }, }, { Name: "Reordered foreign key columns do not match", SetUpScript: []string{ "DROP TABLE child;", "DROP TABLE parent;", "CREATE TABLE parent(pk DOUBLE PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX(v1, v2, pk));", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE child(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, CONSTRAINT fk_child FOREIGN KEY (v2, v1) REFERENCES parent(v2, v1));", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, }, }, { Name: "Reordered foreign key columns match an index's prefix, ALTER TABLE ADD FOREIGN KEY fails check", SetUpScript: []string{ "DROP TABLE child;", "DROP TABLE parent;", "CREATE TABLE parent(pk DOUBLE PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX(v1, v2, pk));", "INSERT INTO parent VALUES (1, 1, 1), (2, 1, 2);", "CREATE TABLE child(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT);", "INSERT INTO child VALUES (1, 2, 1);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child ADD CONSTRAINT fk_child FOREIGN KEY (v2, v1) REFERENCES parent(v2, v1);", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, }, }, { Name: "Self-referential deletion with ON UPDATE CASCADE", SetUpScript: []string{ "CREATE TABLE self(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX(v1), CONSTRAINT fk_self FOREIGN KEY(v2) REFERENCES self(v1) ON UPDATE CASCADE);", "INSERT INTO self VALUES (0, 1, 1), (1, 2, 1);", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE FROM self WHERE v1 = 1;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "DELETE FROM self WHERE v1 = 2;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, }, }, { Name: "Self-referential deletion with ON DELETE CASCADE", SetUpScript: []string{ "CREATE TABLE self(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX(v1), CONSTRAINT fk_self FOREIGN KEY(v2) REFERENCES self(v1) ON DELETE CASCADE);", "INSERT INTO self VALUES (0, 1, 1), (1, 2, 1);", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE FROM self WHERE v1 = 1;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM self;", Expected: []sql.Row{}, }, }, }, { Name: "Cascaded DELETE becomes cascading UPDATE after first child, using ON DELETE for second child", SetUpScript: []string{ "DROP TABLE child;", "DROP TABLE parent;", "CREATE TABLE parent (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX (v1), INDEX (v2), INDEX (v1, v2));", "CREATE TABLE child (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, CONSTRAINT fk_child FOREIGN KEY (v1, v2) REFERENCES parent (v1, v2) ON DELETE SET NULL);", "CREATE TABLE child2 (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, CONSTRAINT fk_child2 FOREIGN KEY (v1, v2) REFERENCES child (v1, v2) ON DELETE SET NULL);", "INSERT INTO parent VALUES (1,1,1), (2,2,2), (3,3,3);", "INSERT INTO child VALUES (1,1,1), (2,2,2), (3,3,3);", "INSERT INTO child2 VALUES (1,1,1), (2,2,2), (3,3,3);", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE FROM parent WHERE pk = 1;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, }, }, { Name: "Cascaded DELETE becomes cascading UPDATE after first child, using ON UPDATE for second child", SetUpScript: []string{ "DROP TABLE child;", "DROP TABLE parent;", "CREATE TABLE parent (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX (v1), INDEX (v2), INDEX (v1, v2));", "CREATE TABLE child (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, CONSTRAINT fk_child FOREIGN KEY (v1, v2) REFERENCES parent (v1, v2) ON DELETE SET NULL);", "CREATE TABLE child2 (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, CONSTRAINT fk_child2 FOREIGN KEY (v1, v2) REFERENCES child (v1, v2) ON UPDATE CASCADE);", "INSERT INTO parent VALUES (1,1,1), (2,2,2), (3,3,3);", "INSERT INTO child VALUES (1,1,1), (2,2,2), (3,3,3);", "INSERT INTO child2 VALUES (1,1,1), (2,2,2), (3,3,3);", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE FROM parent WHERE pk = 1;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM parent;", Expected: []sql.Row{{2, 2, 2}, {3, 3, 3}}, }, { Query: "SELECT * FROM child;", Expected: []sql.Row{{1, nil, nil}, {2, 2, 2}, {3, 3, 3}}, }, { Query: "SELECT * FROM child2;", Expected: []sql.Row{{1, nil, nil}, {2, 2, 2}, {3, 3, 3}}, }, }, }, { Name: "INSERT on DUPLICATE correctly works with FKs", SetUpScript: []string{ "INSERT INTO parent values (1,1,1),(2,2,2),(3,3,3)", "ALTER TABLE child ADD CONSTRAINT fk_named FOREIGN KEY (v1) REFERENCES parent(v1);", "INSERT into child values (1, 1, 1)", "CREATE TABLE one (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX v1 (v1));", "CREATE TABLE two (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, INDEX v1v2 (v1, v2), CONSTRAINT fk_name_1 FOREIGN KEY (v1) REFERENCES one(v1) ON DELETE CASCADE ON UPDATE CASCADE);", "INSERT INTO one VALUES (1, 1, 4), (2, 2, 5), (3, 3, 6), (4, 4, 5);", "INSERT INTO two VALUES (2, 1, 1), (3, 2, 2), (4, 3, 3), (5, 4, 4);", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO parent VALUES (1,200,1) ON DUPLICATE KEY UPDATE v1 = values(v1)", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "INSERT INTO one VALUES (1, 2, 4) on duplicate key update v1 = VALUES(v1)", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "SELECT * FROM two where pk = 2", Expected: []sql.Row{{2, 2, 1}}, }, }, }, { Name: "Referencing Primary Key", SetUpScript: []string{ "CREATE table parent1 (pk BIGINT PRIMARY KEY, v1 BIGINT);", "CREATE table child1 (pk BIGINT PRIMARY KEY, v1 BIGINT, FOREIGN KEY (v1) REFERENCES parent1(pk) ON UPDATE CASCADE ON DELETE CASCADE);", "INSERT INTO parent1 VALUES (1, 1);", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO child1 VALUES (1, 1);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM child1;", Expected: []sql.Row{{1, 1}}, }, { Query: "UPDATE parent1 SET pk = 2;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "SELECT * FROM child1;", Expected: []sql.Row{{1, 2}}, }, }, }, { Name: "Referencing Composite Primary Key", SetUpScript: []string{ "CREATE table parent1 (pk1 BIGINT, pk2 BIGINT, v1 BIGINT, PRIMARY KEY(pk1, pk2));", "CREATE table child1 (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, FOREIGN KEY (v1, v2) REFERENCES parent1(pk1, pk2) ON UPDATE CASCADE ON DELETE CASCADE);", "INSERT INTO parent1 VALUES (1, 2, 3), (4, 5, 6);", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO child1 VALUES (1, 1, 2), (2, 4, 5);", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "SELECT * FROM child1;", Expected: []sql.Row{{1, 1, 2}, {2, 4, 5}}, }, { Query: "UPDATE parent1 SET pk2 = pk1 + pk2;", Expected: []sql.Row{{types.OkResult{RowsAffected: 2, Info: plan.UpdateInfo{Matched: 2, Updated: 2}}}}, }, { Query: "SELECT * FROM child1;", Expected: []sql.Row{{1, 1, 3}, {2, 4, 9}}, }, }, }, { Name: "Keyless CASCADE deleting all rows", SetUpScript: []string{ "CREATE TABLE one (v0 BIGINT, v1 BIGINT, INDEX one_v0 (v0), INDEX one_v1 (v1));", "CREATE TABLE two (v1 BIGINT, CONSTRAINT fk_name_1 FOREIGN KEY (v1) REFERENCES one(v1) ON DELETE CASCADE ON UPDATE CASCADE);", "INSERT INTO one VALUES (1, 2);", "INSERT INTO two VALUES (2);", "UPDATE one SET v1 = v0 + v1;", "DELETE FROM one WHERE v0 = 1;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM one;", Expected: []sql.Row{}, }, { Query: "SELECT * FROM two;", Expected: []sql.Row{}, }, }, }, { Name: "Keyless CASCADE over three tables", SetUpScript: []string{ "CREATE TABLE one (v0 BIGINT, v1 BIGINT, v2 BIGINT, INDEX idx (v0));", "ALTER TABLE one ADD INDEX v1 (v1);", "CREATE TABLE two (v0 BIGINT, v1 BIGINT, v2 BIGINT, INDEX idx (v0), CONSTRAINT fk_name_1 FOREIGN KEY (v1) REFERENCES one(v1) ON DELETE CASCADE ON UPDATE CASCADE);", "ALTER TABLE two ADD INDEX v1v2 (v1, v2);", "CREATE TABLE three (v0 BIGINT, v1 BIGINT, v2 BIGINT, INDEX idx (v0), CONSTRAINT fk_name_2 FOREIGN KEY (v1, v2) REFERENCES two(v1, v2) ON DELETE CASCADE ON UPDATE CASCADE);", "INSERT INTO one VALUES (1, 1, 4), (2, 2, 5), (3, 3, 6), (4, 4, 5);", "INSERT INTO two VALUES (2, 1, 1), (3, 2, 2), (4, 3, 3), (5, 4, 4);", "INSERT INTO three VALUES (3, 1, 1), (4, 2, 2), (5, 3, 3), (6, 4, 4);", "UPDATE one SET v1 = v1 + v2;", "DELETE FROM one WHERE v0 = 3;", "UPDATE two SET v2 = v1 - 2;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM one;", Expected: []sql.Row{{1, 5, 4}, {2, 7, 5}, {4, 9, 5}}, }, { Query: "SELECT * FROM two;", Expected: []sql.Row{{2, 5, 3}, {3, 7, 5}}, }, { Query: "SELECT * FROM three;", Expected: []sql.Row{{3, 5, 3}, {4, 7, 5}}, }, }, }, { Name: "Table with inverted primary key referencing another table can insert rows", SetUpScript: []string{ "create table a (x int, y int, primary key (x,y), INDEX `a_y_idx` (y));", "create table b (x int, y int, primary key (y,x), foreign key (y) references a(y) on update cascade on delete cascade);", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT into a (x, y) VALUES (1, 3);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT into b (x, y) VALUES (2, 3);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT x, y from a;", Expected: []sql.Row{{1, 3}}, }, { Query: "SELECT x, y from b;", Expected: []sql.Row{{2, 3}}, }, { Query: "INSERT into b (x, y) VALUES (3, 5);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, }, }, { Name: "Table with inverted primary key referencing another table with inverted primary keys can be inserted", SetUpScript: []string{ "create table a (x int, y int, primary key (y,x));", "create table b (x int, y int, primary key (y,x), foreign key (y) references a(y) on update cascade on delete cascade);", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT into a (x, y) VALUES (1, 3);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT into b (x, y) VALUES (2, 3);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT x, y from a;", Expected: []sql.Row{{1, 3}}, }, { Query: "SELECT x, y from b;", Expected: []sql.Row{{2, 3}}, }, { Query: "INSERT into b (x, y) VALUES (3, 5);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, }, }, { Name: "Table with inverted primary key referencing another table can be updated", SetUpScript: []string{ "create table a (x int, y int, primary key (x,y), INDEX `a_y_idx` (y));", "create table b (x int, y int, primary key (y,x), foreign key (y) references a(y) on update cascade on delete cascade);", "INSERT into a VALUES (1, 3);", "INSERT into b VALUES (2, 3);", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE a SET y = 4 where y = 3;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "SELECT x, y from a;", Expected: []sql.Row{{1, 4}}, }, { Query: "SELECT x, y from b;", Expected: []sql.Row{{2, 4}}, }, }, }, { Name: "Table with inverted primary key referencing another table with inverted primary keys can be updated", SetUpScript: []string{ "create table a (x int, y int, primary key (y,x));", "create table b (x int, y int, primary key (y,x), foreign key (y) references a(y) on update cascade on delete cascade);", "INSERT into a VALUES (1, 3)", "INSERT into b VALUES (2, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE a SET y = 4 where y = 3;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "SELECT x, y from a;", Expected: []sql.Row{{1, 4}}, }, { Query: "SELECT x, y from b;", Expected: []sql.Row{{2, 4}}, }, }, }, { Name: "Table with inverted primary key referencing another table can be deleted", SetUpScript: []string{ "create table a (x int, y int, primary key (x,y), INDEX `a_y_idx` (y));", "create table b (x int, y int, primary key (y,x), foreign key (y) references a(y) on update cascade on delete cascade);", "INSERT into a VALUES (1, 3);", "INSERT into b VALUES (2, 3);", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE from a where x = 1 AND y = 3;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * from a;", Expected: []sql.Row{}, }, { Query: "SELECT * from b;", Expected: []sql.Row{}, }, }, }, { Name: "Table with inverted primary key referencing another table with inverted primary keys can be deleted", SetUpScript: []string{ "create table a (x int, y int, primary key (y,x));", "create table b (x int, y int, primary key (y,x), foreign key (y) references a(y) on update cascade on delete cascade);", "INSERT into a VALUES (1, 3)", "INSERT into b VALUES (2, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "DELETE from a where x = 1 AND y = 3;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * from a;", Expected: []sql.Row{}, }, { Query: "SELECT * from b;", Expected: []sql.Row{}, }, }, }, { Name: "May use different collations as long as the character sets are equivalent", SetUpScript: []string{ "CREATE TABLE t1 (pk char(32) COLLATE utf8mb4_0900_ai_ci PRIMARY KEY);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t2 (pk char(32) COLLATE utf8mb4_0900_bin PRIMARY KEY, CONSTRAINT fk_1 FOREIGN KEY (pk) REFERENCES t1 (pk));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Referenced index includes implicit primary key columns", SetUpScript: []string{ "create table parent1 (fk1 int, pk1 int, pk2 int, pk3 int, primary key(pk1, pk2, pk3), index (fk1, pk2));", "insert into parent1 values (0, 1, 2, 3);", "create table child1 (fk1 int, pk1 int, pk2 int, pk3 int, primary key (pk1, pk2, pk3));", "create table child2 (fk1 int, pk1 int, pk2 int, pk3 int, primary key (pk1, pk2, pk3));", "create table child3 (fk1 int, pk1 int, pk2 int, pk3 int, primary key (pk1, pk2, pk3));", "create table child4 (fk1 int, pk1 int, pk2 int, pk3 int, primary key (pk1, pk2, pk3));", "create index idx4 on child4 (fk1, pk2);", }, Assertions: []ScriptTestAssertion{ { Query: "alter table child1 add foreign key (fk1, pk1) references parent1 (fk1, pk1);", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, { Query: "alter table child1 add foreign key (fk1, pk1, pk2) references parent1 (fk1, pk1, pk2);", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, { Query: "alter table child1 add foreign key (fk1, pk2, pk3, pk1) references parent1 (fk1, pk2, pk3, pk1);", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, { Query: "alter table child1 add constraint fk1 foreign key (fk1, pk2) references parent1 (fk1, pk2);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table child1", Expected: []sql.Row{ {"child1", "CREATE TABLE `child1` (\n" + " `fk1` int,\n" + " `pk1` int NOT NULL,\n" + " `pk2` int NOT NULL,\n" + " `pk3` int NOT NULL,\n" + " PRIMARY KEY (`pk1`,`pk2`,`pk3`),\n" + " KEY `fk1pk2` (`fk1`,`pk2`),\n" + " CONSTRAINT `fk1` FOREIGN KEY (`fk1`,`pk2`) REFERENCES `parent1` (`fk1`,`pk2`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into child1 values (0, 1, 2, 3);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "insert into child1 values (0, 99, 2, 99);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "insert into child1 values (0, 99, 99, 99);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, { Query: "alter table child2 add constraint fk2 foreign key (fk1, pk2, pk1) references parent1 (fk1, pk2, pk1);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table child2", Expected: []sql.Row{ {"child2", "CREATE TABLE `child2` (\n" + " `fk1` int,\n" + " `pk1` int NOT NULL,\n" + " `pk2` int NOT NULL,\n" + " `pk3` int NOT NULL,\n" + " PRIMARY KEY (`pk1`,`pk2`,`pk3`),\n" + " KEY `fk1pk2pk1` (`fk1`,`pk2`,`pk1`),\n" + " CONSTRAINT `fk2` FOREIGN KEY (`fk1`,`pk2`,`pk1`) REFERENCES `parent1` (`fk1`,`pk2`,`pk1`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into child2 values (0, 1, 2, 3);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "insert into child2 values (0, 1, 2, 99);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "insert into child2 values (0, 99, 2, 99);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, { Query: "alter table child3 add constraint fk3 foreign key (fk1, pk2, pk1, pk3) references parent1 (fk1, pk2, pk1, pk3);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "insert into child3 values (0, 1, 2, 3);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "show create table child3", Expected: []sql.Row{ {"child3", "CREATE TABLE `child3` (\n" + " `fk1` int,\n" + " `pk1` int NOT NULL,\n" + " `pk2` int NOT NULL,\n" + " `pk3` int NOT NULL,\n" + " PRIMARY KEY (`pk1`,`pk2`,`pk3`),\n" + " KEY `fk1pk2pk1pk3` (`fk1`,`pk2`,`pk1`,`pk3`),\n" + " CONSTRAINT `fk3` FOREIGN KEY (`fk1`,`pk2`,`pk1`,`pk3`) REFERENCES `parent1` (`fk1`,`pk2`,`pk1`,`pk3`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into child3 values (0, 1, 2, 99);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, { Query: "alter table child4 add constraint fk4 foreign key (fk1, pk2, pk1, pk3) references parent1 (fk1, pk2, pk1, pk3);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table child4", Expected: []sql.Row{ {"child4", "CREATE TABLE `child4` (\n" + " `fk1` int,\n" + " `pk1` int NOT NULL,\n" + " `pk2` int NOT NULL,\n" + " `pk3` int NOT NULL,\n" + " PRIMARY KEY (`pk1`,`pk2`,`pk3`),\n" + " KEY `fk1pk2pk1pk3` (`fk1`,`pk2`,`pk1`,`pk3`),\n" + " KEY `idx4` (`fk1`,`pk2`),\n" + " CONSTRAINT `fk4` FOREIGN KEY (`fk1`,`pk2`,`pk1`,`pk3`) REFERENCES `parent1` (`fk1`,`pk2`,`pk1`,`pk3`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table child4 add constraint fk5 foreign key (fk1) references parent1 (fk1);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table child4", Expected: []sql.Row{ {"child4", "CREATE TABLE `child4` (\n" + " `fk1` int,\n" + " `pk1` int NOT NULL,\n" + " `pk2` int NOT NULL,\n" + " `pk3` int NOT NULL,\n" + " PRIMARY KEY (`pk1`,`pk2`,`pk3`),\n" + " KEY `fk1pk2pk1pk3` (`fk1`,`pk2`,`pk1`,`pk3`),\n" + " KEY `idx4` (`fk1`,`pk2`),\n" + " CONSTRAINT `fk4` FOREIGN KEY (`fk1`,`pk2`,`pk1`,`pk3`) REFERENCES `parent1` (`fk1`,`pk2`,`pk1`,`pk3`),\n" + " CONSTRAINT `fk5` FOREIGN KEY (`fk1`) REFERENCES `parent1` (`fk1`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, }, }, }
ForeignKeyTests will run the following statements BEFORE the SetUpScript: CREATE TABLE parent (id INT PRIMARY KEY, v1 INT, v2 INT, INDEX v1 (v1), INDEX v2 (v2)); CREATE TABLE child (id INT PRIMARY KEY, v1 INT, v2 INT);
var FulltextTests = []ScriptTest{ { Name: "Basic matching 1 PK", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT pk, v1 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi"}}, }, { Query: "SELECT v1, v2 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{"ghi", "jkl"}}, }, { Query: "SELECT pk, v1, v2 FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT pk, v2 FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", Expected: []sql.Row{{uint64(2), "jkl"}}, }, { Query: "SELECT v1 FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", Expected: []sql.Row{{"ghi"}}, }, { Query: "SELECT v2 FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", Expected: []sql.Row{{"jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl') = 0;", Expected: []sql.Row{{uint64(1), "abc", "def pqr"}, {uint64(3), "mno", "mno"}, {uint64(4), "stu vwx", "xyz zyx yzx"}, {uint64(5), "ghs", "mno shg"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl') > 0;", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}, {uint64(3), "mno", "mno"}, {uint64(5), "ghs", "mno shg"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno') AND pk = 3;", Expected: []sql.Row{{uint64(3), "mno", "mno"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno') OR pk = 1;", Expected: []sql.Row{{uint64(1), "abc", "def pqr"}, {uint64(2), "ghi", "jkl"}, {uint64(3), "mno", "mno"}, {uint64(5), "ghs", "mno shg"}}, }, }, }, { Name: "Basic matching 1 UK", SetUpScript: []string{ "CREATE TABLE test (uk BIGINT UNSIGNED NOT NULL UNIQUE, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT uk, v1 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi"}}, }, { Query: "SELECT uk, v2, v1 FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", Expected: []sql.Row{{uint64(2), "jkl", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}, {uint64(3), "mno", "mno"}, {uint64(5), "ghs", "mno shg"}}, }, }, }, { Name: "Basic matching No Keys", SetUpScript: []string{ "CREATE TABLE test (v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES ('abc', 'def pqr'), ('ghi', 'jkl'), ('mno', 'mno'), ('stu vwx', 'xyz zyx yzx'), ('ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{"ghi", "jkl"}}, }, { Query: "SELECT v1 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{"ghi"}}, }, { Query: "SELECT v2 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{"jkl"}}, }, { Query: "SELECT v2, v1 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{"jkl", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", Expected: []sql.Row{{"ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{"ghi", "jkl"}, {"mno", "mno"}, {"ghs", "mno shg"}}, }, }, }, { Name: "Basic matching 2 PKs", SetUpScript: []string{ "CREATE TABLE test (pk1 BIGINT UNSIGNED, pk2 BIGINT UNSIGNED, v1 VARCHAR(200), v2 VARCHAR(200), PRIMARY KEY (pk1, pk2), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 1, 'abc', 'def pqr'), (2, 1, 'ghi', 'jkl'), (3, 1, 'mno', 'mno'), (4, 1, 'stu vwx', 'xyz zyx yzx'), (5, 1, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}, {uint64(3), uint64(1), "mno", "mno"}, {uint64(5), uint64(1), "ghs", "mno shg"}}, }, }, }, { Name: "Basic matching 2 PKs Reversed", SetUpScript: []string{ "CREATE TABLE test (pk1 BIGINT UNSIGNED, pk2 BIGINT UNSIGNED, v1 VARCHAR(200), v2 VARCHAR(200), PRIMARY KEY (pk2, pk1), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 1, 'abc', 'def pqr'), (2, 1, 'ghi', 'jkl'), (3, 1, 'mno', 'mno'), (4, 1, 'stu vwx', 'xyz zyx yzx'), (5, 1, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}, {uint64(3), uint64(1), "mno", "mno"}, {uint64(5), uint64(1), "ghs", "mno shg"}}, }, }, }, { Name: "Basic matching 2 PKs Non-Sequential", SetUpScript: []string{ "CREATE TABLE test (pk1 BIGINT UNSIGNED, v1 VARCHAR(200), pk2 BIGINT UNSIGNED, v2 VARCHAR(200), PRIMARY KEY (pk2, pk1), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 1, 'def pqr'), (2, 'ghi', 1, 'jkl'), (3, 'mno', 1, 'mno'), (4, 'stu vwx', 1, 'xyz zyx yzx'), (5, 'ghs', 1, 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", uint64(1), "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), "ghi", uint64(1), "jkl"}, {uint64(3), "mno", uint64(1), "mno"}, {uint64(5), "ghs", uint64(1), "mno shg"}}, }, }, }, { Name: "Basic matching 2 UKs", SetUpScript: []string{ "CREATE TABLE test (uk1 BIGINT UNSIGNED NOT NULL, uk2 BIGINT UNSIGNED NOT NULL, v1 VARCHAR(200), v2 VARCHAR(200), UNIQUE KEY (uk1, uk2), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 1, 'abc', 'def pqr'), (2, 1, 'ghi', 'jkl'), (3, 1, 'mno', 'mno'), (4, 1, 'stu vwx', 'xyz zyx yzx'), (5, 1, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}}, }, { Query: "SELECT v2, uk2 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{"jkl", uint64(1)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}, {uint64(3), uint64(1), "mno", "mno"}, {uint64(5), uint64(1), "ghs", "mno shg"}}, }, }, }, { Name: "Basic matching 2 UKs Reversed", SetUpScript: []string{ "CREATE TABLE test (uk1 BIGINT UNSIGNED NOT NULL, uk2 BIGINT UNSIGNED NOT NULL, v1 VARCHAR(200), v2 VARCHAR(200), UNIQUE KEY (uk2, uk1), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 1, 'abc', 'def pqr'), (2, 1, 'ghi', 'jkl'), (3, 1, 'mno', 'mno'), (4, 1, 'stu vwx', 'xyz zyx yzx'), (5, 1, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}, {uint64(3), uint64(1), "mno", "mno"}, {uint64(5), uint64(1), "ghs", "mno shg"}}, }, }, }, { Name: "Basic matching 2 UKs Non-Sequential", SetUpScript: []string{ "CREATE TABLE test (uk1 BIGINT UNSIGNED NOT NULL, v1 VARCHAR(200), uk2 BIGINT UNSIGNED NOT NULL, v2 VARCHAR(200), UNIQUE KEY (uk1, uk2), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 1, 'def pqr'), (2, 'ghi', 1, 'jkl'), (3, 'mno', 1, 'mno'), (4, 'stu vwx', 1, 'xyz zyx yzx'), (5, 'ghs', 1, 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", uint64(1), "jkl"}}, }, { Query: "SELECT v2, uk2 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{"jkl", uint64(1)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), "ghi", uint64(1), "jkl"}, {uint64(3), "mno", uint64(1), "mno"}, {uint64(5), "ghs", uint64(1), "mno shg"}}, }, }, }, { Name: "Basic UPDATE and DELETE checks", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "UPDATE test SET v1 = 'rgb' WHERE pk = 2;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('rgb');", Expected: []sql.Row{{uint64(2), "rgb", "jkl"}}, }, { Query: "UPDATE test SET v2 = 'mno' WHERE pk = 2;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('mno');", Expected: []sql.Row{{uint64(2), "rgb", "mno"}, {uint64(3), "mno", "mno"}, {uint64(5), "ghs", "mno shg"}}, }, { Query: "DELETE FROM test WHERE pk = 3;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('mno');", Expected: []sql.Row{{uint64(2), "rgb", "mno"}, {uint64(5), "ghs", "mno shg"}}, }, }, }, { Name: "NULL handling", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', NULL), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, NULL, NULL), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('abc');", Expected: []sql.Row{{uint64(1), "abc", nil}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "UPDATE test SET v1 = NULL WHERE pk = 2;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('jkl');", Expected: []sql.Row{{uint64(2), nil, "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST (NULL);", Expected: []sql.Row{}, }, { Query: "SELECT pk, v1, v2, MATCH(v1, v2) AGAINST (NULL) FROM test;", Expected: []sql.Row{ {uint64(1), "abc", nil, float32(0)}, {uint64(2), nil, "jkl", float32(0)}, {uint64(3), "mno", "mno", float32(0)}, {uint64(4), nil, nil, float32(0)}, {uint64(5), "ghs", "mno shg", float32(0)}, }, }, { Query: "DROP INDEX idx ON test;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE test ADD FULLTEXT INDEX idx (v1, v2);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Collation handling", SetUpScript: []string{ "CREATE TABLE test1 (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200) COLLATE utf8mb4_0900_bin, v2 VARCHAR(200) COLLATE utf8mb4_0900_bin, FULLTEXT idx (v1, v2));", "CREATE TABLE test2 (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200) COLLATE utf8mb4_0900_ai_ci, v2 VARCHAR(200) COLLATE utf8mb4_0900_ai_ci, FULLTEXT idx (v1, v2));", "INSERT INTO test1 VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", "INSERT INTO test2 VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test1 WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v2, v1) AGAINST ('jkl') = 0;", Expected: []sql.Row{{uint64(1), "abc", "def pqr"}, {uint64(3), "mno", "mno"}, {uint64(4), "stu vwx", "xyz zyx yzx"}, {uint64(5), "ghs", "mno shg"}}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v2, v1) AGAINST ('jkl mno') AND pk = 3;", Expected: []sql.Row{{uint64(3), "mno", "mno"}}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v1, v2) AGAINST ('GHI');", Expected: []sql.Row{}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v2, v1) AGAINST ('JKL') = 0;", Expected: []sql.Row{{uint64(1), "abc", "def pqr"}, {uint64(2), "ghi", "jkl"}, {uint64(3), "mno", "mno"}, {uint64(4), "stu vwx", "xyz zyx yzx"}, {uint64(5), "ghs", "mno shg"}}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v2, v1) AGAINST ('JKL MNO') AND pk = 3;", Expected: []sql.Row{}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v2, v1) AGAINST ('jkl') = 0;", Expected: []sql.Row{{uint64(1), "abc", "def pqr"}, {uint64(3), "mno", "mno"}, {uint64(4), "stu vwx", "xyz zyx yzx"}, {uint64(5), "ghs", "mno shg"}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v2, v1) AGAINST ('jkl mno') AND pk = 3;", Expected: []sql.Row{{uint64(3), "mno", "mno"}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v1, v2) AGAINST ('GHI');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v2, v1) AGAINST ('JKL') = 0;", Expected: []sql.Row{{uint64(1), "abc", "def pqr"}, {uint64(3), "mno", "mno"}, {uint64(4), "stu vwx", "xyz zyx yzx"}, {uint64(5), "ghs", "mno shg"}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v2, v1) AGAINST ('JKL MNO') AND pk = 3;", Expected: []sql.Row{{uint64(3), "mno", "mno"}}, }, }, }, { Name: "Relevancy Ordering", SetUpScript: []string{ "CREATE TABLE test (pk INT PRIMARY KEY, doc TEXT, FULLTEXT idx (doc)) COLLATE=utf8mb4_general_ci;", "INSERT INTO test VALUES (2, 'g hhhh aaaab ooooo aaaa'), (1, 'bbbb ff cccc ddd eee'), (4, 'AAAA aaaa aaaac aaaa Aaaa aaaa'), (3, 'aaaA ff j kkkk llllllll');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT MATCH(doc) AGAINST('aaaa') AS relevance FROM test ORDER BY relevance DESC;", Expected: []sql.Row{ {float32(5.9636202)}, {float32(4.0278959)}, {float32(3.3721533)}, {float32(0)}, }, }, { Query: "SELECT MATCH(doc) AGAINST('aaaa') AS relevance, pk FROM test ORDER BY relevance DESC;", Expected: []sql.Row{ {float32(5.9636202), int32(4)}, {float32(4.0278959), int32(2)}, {float32(3.3721533), int32(3)}, {float32(0), int32(1)}, }, }, { Query: "SELECT pk, MATCH(doc) AGAINST('aaaa') AS relevance FROM test ORDER BY relevance ASC;", Expected: []sql.Row{ {int32(1), float32(0)}, {int32(3), float32(3.3721533)}, {int32(2), float32(4.0278959)}, {int32(4), float32(5.9636202)}, }, }, { Query: "SELECT pk, doc, MATCH(doc) AGAINST('aaaa') AS relevance FROM test ORDER BY relevance DESC;", Expected: []sql.Row{ {int32(4), "AAAA aaaa aaaac aaaa Aaaa aaaa", float32(5.9636202)}, {int32(2), "g hhhh aaaab ooooo aaaa", float32(4.0278959)}, {int32(3), "aaaA ff j kkkk llllllll", float32(3.3721533)}, {int32(1), "bbbb ff cccc ddd eee", float32(0)}, }, }, { Query: "SELECT pk, doc, MATCH(doc) AGAINST('aaaa') AS relevance FROM test ORDER BY relevance ASC;", Expected: []sql.Row{ {int32(1), "bbbb ff cccc ddd eee", float32(0)}, {int32(3), "aaaA ff j kkkk llllllll", float32(3.3721533)}, {int32(2), "g hhhh aaaab ooooo aaaa", float32(4.0278959)}, {int32(4), "AAAA aaaa aaaac aaaa Aaaa aaaa", float32(5.9636202)}, }, }, { Query: "SELECT pk FROM test ORDER BY MATCH(doc) AGAINST('aaaa') DESC;", Expected: []sql.Row{ {int32(4)}, {int32(2)}, {int32(3)}, {int32(1)}, }, }, { Query: "SELECT pk, doc FROM test ORDER BY MATCH(doc) AGAINST('aaaa') ASC;", Expected: []sql.Row{ {int32(1), "bbbb ff cccc ddd eee"}, {int32(3), "aaaA ff j kkkk llllllll"}, {int32(2), "g hhhh aaaab ooooo aaaa"}, {int32(4), "AAAA aaaa aaaac aaaa Aaaa aaaa"}, }, }, { Query: "SELECT 1 FROM test ORDER BY MATCH(doc) AGAINST('aaaa') DESC;", Expected: []sql.Row{ {int32(1)}, {int32(1)}, {int32(1)}, {int32(1)}, }, }, { Query: "SELECT pk, MATCH(doc) AGAINST('aaaa') AS relevance FROM test HAVING relevance > 4 ORDER BY relevance DESC;", Expected: []sql.Row{ {int32(4), float32(5.9636202)}, {int32(2), float32(4.0278959)}, }, }, { Query: "ALTER TABLE test ADD COLUMN extracol INT DEFAULT 7;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT pk FROM test ORDER BY MATCH(doc) AGAINST('aaaa') DESC;", Expected: []sql.Row{ {int32(4)}, {int32(2)}, {int32(3)}, {int32(1)}, }, }, { Query: "ALTER TABLE test DROP PRIMARY KEY;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT pk FROM test ORDER BY MATCH(doc) AGAINST('aaaa') ASC;", Expected: []sql.Row{ {int32(1)}, {int32(3)}, {int32(2)}, {int32(4)}, }, }, { Query: "SELECT pk, MATCH(doc) AGAINST('aaaa') AS relevance FROM test ORDER BY relevance DESC;", Expected: []sql.Row{ {int32(4), float32(5.9636202)}, {int32(2), float32(4.0278959)}, {int32(3), float32(3.3721533)}, {int32(1), float32(0)}, }, }, }, }, { Name: "CREATE INDEX before insertions", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200));", "CREATE FULLTEXT INDEX idx ON test (v1, v2);", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}, {uint64(3), "mno", "mno"}, {uint64(5), "ghs", "mno shg"}}, }, }, }, { Name: "CREATE INDEX after insertions", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", "CREATE FULLTEXT INDEX idx ON test (v1, v2);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}, {uint64(3), "mno", "mno"}, {uint64(5), "ghs", "mno shg"}}, }, }, }, { Name: "ALTER TABLE CREATE INDEX before insertions", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200));", "ALTER TABLE test ADD FULLTEXT INDEX idx (v1, v2);", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}, {uint64(3), "mno", "mno"}, {uint64(5), "ghs", "mno shg"}}, }, }, }, { Name: "ALTER TABLE CREATE INDEX after insertions", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", "ALTER TABLE test ADD FULLTEXT INDEX idx (v1, v2);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}, {uint64(3), "mno", "mno"}, {uint64(5), "ghs", "mno shg"}}, }, }, }, { Name: "DROP INDEX", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "DROP INDEX idx ON test;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", ExpectedErr: sql.ErrNoFullTextIndexFound, }, }, }, { Name: "ALTER TABLE DROP INDEX", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", "CREATE FULLTEXT INDEX idx ON test (v1, v2);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "ALTER TABLE test DROP INDEX idx;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", ExpectedErr: sql.ErrNoFullTextIndexFound, }, }, }, { Name: "ALTER TABLE ADD COLUMN", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE test ADD COLUMN v3 FLOAT DEFAULT 7 FIRST;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{float32(7), uint64(2), "ghi", "jkl"}}, }, }, }, { Name: "ALTER TABLE MODIFY COLUMN not used by index", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), v3 BIGINT UNSIGNED, FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr', 7), (2, 'ghi', 'jkl', 7), (3, 'mno', 'mno', 7), (4, 'stu vwx', 'xyz zyx yzx', 7), (5, 'ghs', 'mno shg', 7);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE test MODIFY COLUMN v3 FLOAT AFTER pk;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), float32(7), "ghi", "jkl"}}, }, }, }, { Name: "ALTER TABLE MODIFY COLUMN used by index to valid type", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE test MODIFY COLUMN v2 TEXT;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, }, }, { Name: "ALTER TABLE MODIFY COLUMN used by index to invalid type", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE test MODIFY COLUMN v2 VARBINARY(200);", ExpectedErr: sql.ErrFullTextInvalidColumnType, }, }, }, { Name: "ALTER TABLE DROP COLUMN not used by index", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), v3 BIGINT UNSIGNED, FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr', 7), (2, 'ghi', 'jkl', 7), (3, 'mno', 'mno', 7), (4, 'stu vwx', 'xyz zyx yzx', 7), (5, 'ghs', 'mno shg', 7);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE test DROP COLUMN v3;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, }, }, { Name: "ALTER TABLE DROP COLUMN used by index", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), v3 VARCHAR(200), FULLTEXT idx1 (v1, v2), FULLTEXT idx2 (v2), FULLTEXT idx3 (v2, v3));", "INSERT INTO test VALUES (1, 'abc', 'def', 'ghi');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('abc');", Expected: []sql.Row{{uint64(1), "abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2) AGAINST ('def');", Expected: []sql.Row{{uint64(1), "abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v3) AGAINST ('ghi');", Expected: []sql.Row{{uint64(1), "abc", "def", "ghi"}}, }, { Query: "SHOW CREATE TABLE test;", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `pk` bigint unsigned NOT NULL,\n `v1` varchar(200),\n `v2` varchar(200),\n `v3` varchar(200),\n PRIMARY KEY (`pk`),\n FULLTEXT KEY `idx1` (`v1`,`v2`),\n FULLTEXT KEY `idx2` (`v2`),\n FULLTEXT KEY `idx3` (`v2`,`v3`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "ALTER TABLE test DROP COLUMN v2;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('abc');", ExpectedErr: sql.ErrColumnNotFound, }, { Query: "SELECT * FROM test WHERE MATCH(v2) AGAINST ('def');", ExpectedErr: sql.ErrColumnNotFound, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v3) AGAINST ('ghi');", ExpectedErr: sql.ErrColumnNotFound, }, { Query: "SELECT * FROM test WHERE MATCH(v1) AGAINST ('abc');", Expected: []sql.Row{{uint64(1), "abc", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v3) AGAINST ('ghi');", Expected: []sql.Row{{uint64(1), "abc", "ghi"}}, }, { Query: "SHOW CREATE TABLE test;", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `pk` bigint unsigned NOT NULL,\n `v1` varchar(200),\n `v3` varchar(200),\n PRIMARY KEY (`pk`),\n FULLTEXT KEY `idx1` (`v1`),\n FULLTEXT KEY `idx3` (`v3`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "ALTER TABLE test DROP COLUMN v3;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1) AGAINST ('abc');", Expected: []sql.Row{{uint64(1), "abc"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v3) AGAINST ('ghi');", ExpectedErr: sql.ErrColumnNotFound, }, { Query: "SHOW CREATE TABLE test;", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `pk` bigint unsigned NOT NULL,\n `v1` varchar(200),\n PRIMARY KEY (`pk`),\n FULLTEXT KEY `idx1` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "ALTER TABLE ADD PRIMARY KEY", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE test ADD PRIMARY KEY (pk);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, }, }, { Name: "ALTER TABLE DROP PRIMARY KEY", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE test DROP PRIMARY KEY;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, }, }, { Name: "ALTER TABLE DROP TABLE", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "DROP TABLE test;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "TRUNCATE TABLE", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test VALUES (1, 'abc', 'def pqr'), (2, 'ghi', 'jkl'), (3, 'mno', 'mno'), (4, 'stu vwx', 'xyz zyx yzx'), (5, 'ghs', 'mno shg');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "TRUNCATE TABLE test;", Expected: []sql.Row{{types.NewOkResult(5)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{}, }, }, }, { Name: "No prefix needed for TEXT columns", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE `film_text` (`film_id` SMALLINT NOT NULL, `title` VARCHAR(255) NOT NULL, `description` TEXT, PRIMARY KEY (`film_id`), FULLTEXT KEY `idx_title_description` (`title`,`description`));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CREATE TABLE other_table (pk BIGINT PRIMARY KEY, v1 TEXT);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE other_table ADD FULLTEXT INDEX idx (v1);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Rename new table to match old table", SetUpScript: []string{ "CREATE TABLE test1 (v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", "INSERT INTO test1 VALUES ('abc', 'def');", }, Assertions: []ScriptTestAssertion{ { Query: "RENAME TABLE test1 TO test2;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v1, v2) AGAINST ('abc');", Expected: []sql.Row{{"abc", "def"}}, }, { Query: "CREATE TABLE test1 (v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v2));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO test1 VALUES ('ghi', 'jkl');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v1, v2) AGAINST ('abc');", Expected: []sql.Row{}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v1, v2) AGAINST ('abc');", Expected: []sql.Row{{"abc", "def"}}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v1, v2) AGAINST ('jkl');", Expected: []sql.Row{{"ghi", "jkl"}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v1, v2) AGAINST ('jkl');", Expected: []sql.Row{}, }, }, }, { Name: "Rename index", SetUpScript: []string{ "CREATE TABLE test (v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v2, v1));", "INSERT INTO test VALUES ('abc', 'def');", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE test;", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `v1` varchar(200),\n `v2` varchar(200),\n FULLTEXT KEY `idx` (`v2`,`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "ALTER TABLE test RENAME INDEX idx TO new_idx;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('abc');", Expected: []sql.Row{{"abc", "def"}}, }, { Query: "SHOW CREATE TABLE test;", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `v1` varchar(200),\n `v2` varchar(200),\n FULLTEXT KEY `new_idx` (`v2`,`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "Multiple overlapping indexes", SetUpScript: []string{ "CREATE TABLE test (v1 TEXT, v2 VARCHAR(200), v3 MEDIUMTEXT, FULLTEXT idx1 (v1, v2), FULLTEXT idx2 (v1, v3), FULLTEXT idx3 (v2, v3));", "INSERT INTO test VALUES ('abc', 'def', 'ghi');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('abc');", Expected: []sql.Row{{"abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('def');", Expected: []sql.Row{{"abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v3) AGAINST ('abc');", Expected: []sql.Row{{"abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v3) AGAINST ('def');", Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v3) AGAINST ('ghi');", Expected: []sql.Row{{"abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v3) AGAINST ('abc');", Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v3) AGAINST ('def');", Expected: []sql.Row{{"abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v3) AGAINST ('ghi');", Expected: []sql.Row{{"abc", "def", "ghi"}}, }, }, }, { Name: "Duplicate column names", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE test (v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v1));", ExpectedErr: sql.ErrFullTextDuplicateColumn, }, }, }, { Name: "References missing column", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE test (v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v3));", ExpectedErr: sql.ErrUnknownIndexColumn, }, }, }, { Name: "Creating an index on an invalid type", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE test (v1 VARCHAR(200), v2 BIGINT, FULLTEXT idx (v1, v2));", ExpectedErr: sql.ErrFullTextInvalidColumnType, }, }, }, { Name: "Foreign keys ignore Full-Text indexes", SetUpScript: []string{ "CREATE TABLE parent (pk BIGINT, v1 VARCHAR(200), FULLTEXT idx (v1));", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE child1 (pk BIGINT, v1 VARCHAR(200), FULLTEXT idx (v1), CONSTRAINT fk FOREIGN KEY (v1) REFERENCES parent(v1));", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, { Query: "CREATE TABLE child2 (pk BIGINT, v1 VARCHAR(200), INDEX idx (v1), CONSTRAINT fk FOREIGN KEY (v1) REFERENCES parent(v1));", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, }, }, { Name: "Full-Text with autoincrement", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, v1 VARCHAR(200), PRIMARY KEY(pk), FULLTEXT idx (v1));", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO test (v1) VALUES ('abc'), ('def');", Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 1}}}, }, { Query: "SELECT * FROM test;", Expected: []sql.Row{{uint64(1), "abc"}, {uint64(2), "def"}}, }, }, }, }
var GeneratedColumnTests = []ScriptTest{ { Name: "stored generated column", SetUpScript: []string{ "create table t1 (a int primary key, b int as (a + 1) stored)", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `a` int NOT NULL,\n" + " `b` int GENERATED ALWAYS AS ((a + 1)) STORED,\n" + " PRIMARY KEY (`a`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t1 values (1,2)", ExpectedErr: sql.ErrGeneratedColumnValue, }, { Query: "insert into t1(a,b) values (1,2)", ExpectedErr: sql.ErrGeneratedColumnValue, }, { Query: "select * from t1 order by a", Expected: []sql.Row{}, }, { Query: "insert into t1(a) values (1), (2), (3)", Expected: []sql.Row{{types.NewOkResult(3)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2}, {2, 3}, {3, 4}}, }, }, }, }
var GenericUpdateErrorTests = []GenericErrorQueryTest{
{
Name: "invalid table",
Query: "UPDATE doesnotexist SET i = 0;",
},
{
Name: "missing binding",
Query: "UPDATE mytable SET i = ?;",
},
{
Name: "wrong number of columns",
Query: `UPDATE mytable SET i = ("one", "two");`,
},
{
Name: "type mismatch: string -> int",
Query: `UPDATE mytable SET i = "one"`,
},
{
Name: "type mismatch: string -> float",
Query: `UPDATE floattable SET f64 = "one"`,
},
{
Name: "type mismatch: string -> uint",
Query: `UPDATE typestable SET f64 = "one"`,
},
{
Name: "invalid column set",
Query: "UPDATE mytable SET z = 0;",
},
{
Name: "invalid column set value",
Query: "UPDATE mytable SET i = z;",
},
{
Name: "invalid column where",
Query: "UPDATE mytable SET s = 'hi' WHERE z = 1;",
},
{
Name: "invalid column order by",
Query: "UPDATE mytable SET s = 'hi' ORDER BY z;",
},
{
Name: "negative limit",
Query: "UPDATE mytable SET s = 'hi' LIMIT -1;",
},
{
Name: "negative offset",
Query: "UPDATE mytable SET s = 'hi' LIMIT 1 OFFSET -1;",
},
{
Name: "set null on non-nullable",
Query: "UPDATE mytable SET s = NULL;",
},
{
Name: "targets join",
Query: "UPDATE mytable one, mytable two SET s = NULL;",
},
{
Name: "targets subquery alias",
Query: "UPDATE (SELECT * FROM mytable) mytable SET s = NULL;",
},
}
var IgnoreWithDuplicateUniqueKeyKeylessScripts = []ScriptTest{ { Name: "Test that INSERT IGNORE INTO works with unique keys on a keyless table", SetUpScript: []string{ "CREATE TABLE one_uniq(not_pk int, value int UNIQUE)", "CREATE TABLE two_uniq(not_pk int, col1 int, col2 int, UNIQUE KEY col1_col2_uniq (col1, col2));", "INSERT INTO one_uniq values (1, 1)", "INSERT INTO two_uniq values (1, 1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT IGNORE INTO one_uniq VALUES (3, 2), (2, 1), (4, null), (5, null)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3}}, }, ExpectedWarning: mysql.ERDupEntry, }, { Query: "SELECT * from one_uniq;", Expected: []sql.Row{ {1, 1}, {3, 2}, {4, nil}, {5, nil}, }, }, { Query: "INSERT IGNORE INTO two_uniq VALUES (4, 1, 2), (5, 2, 1), (6, null, 1), (7, null, 1), (12, 1, 1), (8, 1, null), (9, 1, null), (10, null, null), (11, null, null)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 8}}, }, ExpectedWarning: mysql.ERDupEntry, }, { Query: "SELECT * from two_uniq;", Expected: []sql.Row{ {1, 1, 1}, {4, 1, 2}, {5, 2, 1}, {6, nil, 1}, {7, nil, 1}, {8, 1, nil}, {9, 1, nil}, {10, nil, nil}, {11, nil, nil}, }, }, }, }, { Name: "INSERT IGNORE INTO multiple violations of a unique secondary index", SetUpScript: []string{ "CREATE TABLE keyless(pk int, val int)", "INSERT INTO keyless values (1, 1), (2, 2), (3, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT IGNORE INTO keyless VALUES (1, 2);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "ALTER TABLE keyless ADD CONSTRAINT c UNIQUE(val)", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "DELETE FROM keyless where pk = 1 and val = 2", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "ALTER TABLE keyless ADD CONSTRAINT c UNIQUE(val)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT IGNORE INTO keyless VALUES (1, 3)", Expected: []sql.Row{{types.NewOkResult(0)}}, ExpectedWarning: mysql.ERDupEntry, }, }, }, { Name: "UPDATE IGNORE keyless tables and secondary indexes", SetUpScript: []string{ "CREATE TABLE keyless(pk int, val int)", "INSERT INTO keyless VALUES (1, 1), (2, 2), (3, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE IGNORE keyless SET val = 2 where pk = 1", Expected: []sql.Row{{newUpdateResult(1, 1)}}, }, { Query: "SELECT * FROM keyless ORDER BY pk", Expected: []sql.Row{{1, 2}, {2, 2}, {3, 3}}, }, { Query: "ALTER TABLE keyless ADD CONSTRAINT c UNIQUE(val)", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "UPDATE IGNORE keyless SET val = 1 where pk = 1", Expected: []sql.Row{{newUpdateResult(1, 1)}}, ExpectedWarning: mysql.ERDupEntry, }, { Query: "ALTER TABLE keyless ADD CONSTRAINT c UNIQUE(val)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "UPDATE IGNORE keyless SET val = 3 where pk = 1", Expected: []sql.Row{{newUpdateResult(1, 0)}}, ExpectedWarning: mysql.ERDupEntry, }, { Query: "SELECT * FROM keyless ORDER BY pk", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, { Query: "UPDATE IGNORE keyless SET val = val + 1 ORDER BY pk", Expected: []sql.Row{{newUpdateResult(3, 1)}}, ExpectedWarning: mysql.ERDupEntry, }, { Query: "SELECT * FROM keyless ORDER BY pk", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 4}}, }, }, }, }
var IndexPlanTests = []QueryPlanTest{}/* 732 elements not displayed */
var IndexPrefixQueries = []ScriptTest{ { Name: "int prefix", SetUpScript: []string{ "create table t (i int)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add primary key (i(10))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "alter table t add index (i(10))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "create table c_tbl (i int, primary key (i(10)))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "create table c_tbl (i int primary key, j int, index (j(10)))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, }, }, { Name: "float prefix", SetUpScript: []string{ "create table t (f float)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add primary key (f(10))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "alter table t add index (f(10))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "create table c_tbl (f float, primary key (f(10)))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "create table c_tbl (i int primary key, f float, index (f(10)))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, }, }, { Name: "string index prefix errors", SetUpScript: []string{ "create table v_tbl (v varchar(10))", "create table c_tbl (c char(10))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table v_tbl add primary key (v(0))", ExpectedErr: sql.ErrKeyZero, }, { Query: "alter table v_tbl add primary key (v(11))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "alter table v_tbl add index (v(0))", ExpectedErr: sql.ErrKeyZero, }, { Query: "alter table v_tbl add index (v(11))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "alter table c_tbl add primary key (c(11))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "alter table c_tbl add index (c(11))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "create table t (v varchar(10), primary key(v(0)))", ExpectedErr: sql.ErrKeyZero, }, { Query: "create table t (v varchar(10), primary key(v(11)))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "create table t (v varchar(10), index(v(11)))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "create table t (c char(10), primary key(c(11)))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, { Query: "create table t (c char(10), index(c(11)))", ExpectedErr: sql.ErrInvalidIndexPrefix, }, }, }, { Name: "varchar primary key prefix", SetUpScript: []string{ "create table t (v varchar(100))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add primary key (v(10))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, { Query: "create table v_tbl (v varchar(100), primary key (v(10)))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, }, }, { Name: "varchar keyed secondary index prefix", SetUpScript: []string{ "create table t (i int primary key, v varchar(10))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (v(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `v` varchar(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `v` (`v`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values (0, 'aa'), (1, 'ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "insert into t values (0, 'aa'), (1, 'bb'), (2, 'cc')", Expected: []sql.Row{{types.NewOkResult(3)}}, }, { Query: "select * from t where v = 'a'", Expected: []sql.Row{}, }, { Query: "select * from t where v = 'aa'", Expected: []sql.Row{ {0, "aa"}, }, }, { Query: "create table v_tbl (i int primary key, v varchar(100), index (v(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table v_tbl", Expected: []sql.Row{{"v_tbl", "CREATE TABLE `v_tbl` (\n `i` int NOT NULL,\n `v` varchar(100),\n PRIMARY KEY (`i`),\n KEY `v` (`v`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "varchar keyless secondary index prefix", SetUpScript: []string{ "create table t (v varchar(10))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (v(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `v` varchar(10),\n UNIQUE KEY `v` (`v`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values ('aa'), ('ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table v_tbl (v varchar(100), index (v(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table v_tbl", Expected: []sql.Row{{"v_tbl", "CREATE TABLE `v_tbl` (\n `v` varchar(100),\n KEY `v` (`v`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "char primary key prefix", SetUpScript: []string{ "create table t (c char(100))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add primary key (c(10))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, { Query: "create table c_tbl (c char(100), primary key (c(10)))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, }, }, { Name: "char keyed secondary index prefix", SetUpScript: []string{ "create table t (i int primary key, c char(10))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (c(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `c` char(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `c` (`c`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values (0, 'aa'), (1, 'ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table c_tbl (i int primary key, c varchar(100), index (c(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table c_tbl", Expected: []sql.Row{{"c_tbl", "CREATE TABLE `c_tbl` (\n `i` int NOT NULL,\n `c` varchar(100),\n PRIMARY KEY (`i`),\n KEY `c` (`c`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "char keyless secondary index prefix", SetUpScript: []string{ "create table t (c char(10))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (c(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `c` char(10),\n UNIQUE KEY `c` (`c`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values ('aa'), ('ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table c_tbl (c char(100), index (c(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table c_tbl", Expected: []sql.Row{{"c_tbl", "CREATE TABLE `c_tbl` (\n `c` char(100),\n KEY `c` (`c`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "varbinary primary key prefix", SetUpScript: []string{ "create table t (v varbinary(100))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add primary key (v(10))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, { Query: "create table v_tbl (v varbinary(100), primary key (v(10)))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, }, }, { Name: "varbinary keyed secondary index prefix", SetUpScript: []string{ "create table t (i int primary key, v varbinary(10))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (v(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `v` varbinary(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `v` (`v`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values (0, 'aa'), (1, 'ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table v_tbl (i int primary key, v varbinary(100), index (v(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table v_tbl", Expected: []sql.Row{{"v_tbl", "CREATE TABLE `v_tbl` (\n `i` int NOT NULL,\n `v` varbinary(100),\n PRIMARY KEY (`i`),\n KEY `v` (`v`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "varbinary keyless secondary index prefix", SetUpScript: []string{ "create table t (v varbinary(10))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (v(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `v` varbinary(10),\n UNIQUE KEY `v` (`v`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values ('aa'), ('ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table v_tbl (v varbinary(100), index (v(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table v_tbl", Expected: []sql.Row{{"v_tbl", "CREATE TABLE `v_tbl` (\n `v` varbinary(100),\n KEY `v` (`v`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "binary primary key prefix", SetUpScript: []string{ "create table t (b binary(100))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add primary key (b(10))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, { Query: "create table b_tbl (b binary(100), primary key (b(10)))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, }, }, { Name: "binary keyed secondary index prefix", SetUpScript: []string{ "create table t (i int primary key, b binary(10))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (b(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `b` binary(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `b` (`b`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values (0, 'aa'), (1, 'ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table b_tbl (i int primary key, b binary(100), index (b(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table b_tbl", Expected: []sql.Row{{"b_tbl", "CREATE TABLE `b_tbl` (\n `i` int NOT NULL,\n `b` binary(100),\n PRIMARY KEY (`i`),\n KEY `b` (`b`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "binary keyless secondary index prefix", SetUpScript: []string{ "create table t (b binary(10))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (b(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `b` binary(10),\n UNIQUE KEY `b` (`b`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values ('aa'), ('ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table b_tbl (b binary(100), index (b(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table b_tbl", Expected: []sql.Row{{"b_tbl", "CREATE TABLE `b_tbl` (\n `b` binary(100),\n KEY `b` (`b`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "blob primary key prefix", SetUpScript: []string{ "create table t (b blob)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add primary key (b(10))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, { Query: "create table b_tbl (b blob, primary key (b(10)))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, }, }, { Name: "blob keyed secondary index prefix", SetUpScript: []string{ "create table t (i int primary key, b blob)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (b(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `b` blob,\n PRIMARY KEY (`i`),\n UNIQUE KEY `b` (`b`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values (0, 'aa'), (1, 'ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table b_tbl (i int primary key, b blob, index (b(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table b_tbl", Expected: []sql.Row{{"b_tbl", "CREATE TABLE `b_tbl` (\n `i` int NOT NULL,\n `b` blob,\n PRIMARY KEY (`i`),\n KEY `b` (`b`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "blob keyless secondary index prefix", SetUpScript: []string{ "create table t (b blob)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (b(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `b` blob,\n UNIQUE KEY `b` (`b`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values ('aa'), ('ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table b_tbl (b blob, index (b(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table b_tbl", Expected: []sql.Row{{"b_tbl", "CREATE TABLE `b_tbl` (\n `b` blob,\n KEY `b` (`b`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "text primary key prefix", SetUpScript: []string{ "create table t (t text)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add primary key (t(10))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, { Query: "create table b_tbl (t text, primary key (t(10)))", ExpectedErr: sql.ErrUnsupportedIndexPrefix, }, }, }, { Name: "text keyed secondary index prefix", SetUpScript: []string{ "create table t (i int primary key, t text)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (t(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `t` text,\n PRIMARY KEY (`i`),\n UNIQUE KEY `t` (`t`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values (0, 'aa'), (1, 'ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table t_tbl (i int primary key, t text, index (t(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t_tbl", Expected: []sql.Row{{"t_tbl", "CREATE TABLE `t_tbl` (\n `i` int NOT NULL,\n `t` text,\n PRIMARY KEY (`i`),\n KEY `t` (`t`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "text keyless secondary index prefix", SetUpScript: []string{ "create table t (t text)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add unique index (t(1))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `t` text,\n UNIQUE KEY `t` (`t`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values ('aa'), ('ab')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create table t_tbl (t text, index (t(10)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t_tbl", Expected: []sql.Row{{"t_tbl", "CREATE TABLE `t_tbl` (\n `t` text,\n KEY `t` (`t`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "inline secondary indexes", SetUpScript: []string{ "create table t (i int primary key, v1 varchar(10), v2 varchar(10), unique index (v1(3),v2(5)))", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `v1` varchar(10),\n `v2` varchar(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `v1v2` (`v1`(3),`v2`(5))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values (0, 'a', 'a'), (1, 'ab','ab'), (2, 'abc', 'abc'), (3, 'abcde', 'abcde')", Expected: []sql.Row{{types.NewOkResult(4)}}, }, { Query: "insert into t values (99, 'abc', 'abcde')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "insert into t values (99, 'abc123', 'abcde123')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "select * from t where v1 = 'a'", Expected: []sql.Row{ {0, "a", "a"}, }, }, { Query: "select * from t where v1 = 'abc'", Expected: []sql.Row{ {2, "abc", "abc"}, }, }, { Query: "select * from t where v1 = 'abcd'", Expected: []sql.Row{}, }, { Query: "select * from t where v1 > 'a' and v1 < 'abcde'", Expected: []sql.Row{ {1, "ab", "ab"}, {2, "abc", "abc"}, }, }, { Query: "select * from t where v1 > 'a' and v2 < 'abcde'", Expected: []sql.Row{ {1, "ab", "ab"}, {2, "abc", "abc"}, }, }, { Query: "update t set v1 = concat(v1, 'z') where v1 >= 'a'", Expected: []sql.Row{ {types.OkResult{RowsAffected: 4, InsertID: 0, Info: plan.UpdateInfo{Matched: 4, Updated: 4}}}, }, }, { Query: "select * from t", Expected: []sql.Row{ {0, "az", "a"}, {1, "abz", "ab"}, {2, "abcz", "abc"}, {3, "abcdez", "abcde"}, }, }, { Query: "delete from t where v1 >= 'a'", Expected: []sql.Row{ {types.OkResult{RowsAffected: 4}}, }, }, { Query: "select * from t", Expected: []sql.Row{}, }, }, }, { Name: "inline secondary indexes keyless", SetUpScript: []string{ "create table t (v1 varchar(10), v2 varchar(10), unique index (v1(3),v2(5)))", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `v1` varchar(10),\n `v2` varchar(10),\n UNIQUE KEY `v1v2` (`v1`(3),`v2`(5))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values ('a', 'a'), ('ab','ab'), ('abc', 'abc'), ('abcde', 'abcde')", Expected: []sql.Row{{types.NewOkResult(4)}}, }, { Query: "insert into t values ('abc', 'abcde')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "insert into t values ('abc123', 'abcde123')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "select * from t where v1 = 'a'", Expected: []sql.Row{ {"a", "a"}, }, }, { Query: "select * from t where v1 = 'abc'", Expected: []sql.Row{ {"abc", "abc"}, }, }, { Query: "select * from t where v1 = 'abcd'", Expected: []sql.Row{}, }, { Query: "select * from t where v1 > 'a' and v1 < 'abcde'", Expected: []sql.Row{ {"ab", "ab"}, {"abc", "abc"}, }, }, { Query: "select * from t where v1 > 'a' and v2 < 'abcde'", Expected: []sql.Row{ {"ab", "ab"}, {"abc", "abc"}, }, }, { Query: "update t set v1 = concat(v1, 'z') where v1 >= 'a'", Expected: []sql.Row{ {types.OkResult{RowsAffected: 4, InsertID: 0, Info: plan.UpdateInfo{Matched: 4, Updated: 4}}}, }, }, { Query: "select * from t", Expected: []sql.Row{ {"az", "a"}, {"abz", "ab"}, {"abcz", "abc"}, {"abcdez", "abcde"}, }, }, { Query: "delete from t where v1 >= 'a'", Expected: []sql.Row{ {types.OkResult{RowsAffected: 4}}, }, }, { Query: "select * from t", Expected: []sql.Row{}, }, }, }, { Name: "inline secondary indexes with collation", SetUpScript: []string{ "create table t (i int primary key, v1 varchar(10), v2 varchar(10), unique index (v1(3),v2(5))) collate utf8mb4_0900_ai_ci", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `v1` varchar(10),\n `v2` varchar(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `v1v2` (`v1`(3),`v2`(5))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"}}, }, { Query: "insert into t values (0, 'a', 'a'), (1, 'ab','ab'), (2, 'abc', 'abc'), (3, 'abcde', 'abcde')", Expected: []sql.Row{{types.NewOkResult(4)}}, }, { Skip: true, Query: "insert into t values (99, 'ABC', 'ABCDE')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Skip: true, Query: "insert into t values (99, 'ABC123', 'ABCDE123')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Skip: true, Query: "select * from t where v1 = 'A'", Expected: []sql.Row{ {0, "a", "a"}, }, }, { Skip: true, Query: "select * from t where v1 = 'ABC'", Expected: []sql.Row{ {2, "abc", "abc"}, }, }, { Query: "select * from t where v1 = 'ABCD'", Expected: []sql.Row{}, }, { Skip: true, Query: "select * from t where v1 > 'A' and v1 < 'ABCDE'", Expected: []sql.Row{ {1, "ab", "ab"}, }, }, { Query: "select * from t where v1 > 'A' and v2 < 'ABCDE'", Expected: []sql.Row{ {1, "ab", "ab"}, {2, "abc", "abc"}, }, }, { Skip: true, Query: "update t set v1 = concat(v1, 'Z') where v1 >= 'A'", Expected: []sql.Row{ {types.OkResult{RowsAffected: 4, InsertID: 0, Info: plan.UpdateInfo{Matched: 4, Updated: 4}}}, }, }, { Skip: true, Query: "select * from t", Expected: []sql.Row{ {0, "aZ", "a"}, {1, "abZ", "ab"}, {2, "abcZ", "abc"}, {3, "abcdeZ", "abcde"}, }, }, { Skip: true, Query: "delete from t where v1 >= 'A'", Expected: []sql.Row{ {types.OkResult{RowsAffected: 4}}, }, }, { Skip: true, Query: "select * from t", Expected: []sql.Row{}, }, }, }, { Name: "referenced secondary indexes", SetUpScript: []string{ "create table t (i int primary key, v1 text, v2 text, unique index (v1(3),v2(5)))", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `v1` text,\n `v2` text,\n PRIMARY KEY (`i`),\n UNIQUE KEY `v1v2` (`v1`(3),`v2`(5))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values (0, 'a', 'a'), (1, 'ab','ab'), (2, 'abc', 'abc'), (3, 'abcde', 'abcde')", Expected: []sql.Row{{types.NewOkResult(4)}}, }, { Query: "insert into t values (99, 'abc', 'abcde')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "insert into t values (99, 'abc123', 'abcde123')", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "select * from t where v1 = 'a'", Expected: []sql.Row{ {0, "a", "a"}, }, }, { Query: "select * from t where v1 = 'abc'", Expected: []sql.Row{ {2, "abc", "abc"}, }, }, { Query: "select * from t where v1 = 'abcd'", Expected: []sql.Row{}, }, { Query: "select * from t where v1 > 'a' and v1 < 'abcde'", Expected: []sql.Row{ {1, "ab", "ab"}, {2, "abc", "abc"}, }, }, { Query: "select * from t where v1 > 'a' and v2 < 'abcde'", Expected: []sql.Row{ {1, "ab", "ab"}, {2, "abc", "abc"}, }, }, { Query: "update t set v1 = concat(v1, 'z') where v1 >= 'a'", Expected: []sql.Row{ {types.OkResult{RowsAffected: 4, InsertID: 0, Info: plan.UpdateInfo{Matched: 4, Updated: 4}}}, }, }, { Query: "select * from t", Expected: []sql.Row{ {0, "az", "a"}, {1, "abz", "ab"}, {2, "abcz", "abc"}, {3, "abcdez", "abcde"}, }, }, { Query: "delete from t where v1 >= 'a'", Expected: []sql.Row{ {types.OkResult{RowsAffected: 4}}, }, }, { Query: "select * from t", Expected: []sql.Row{}, }, }, }, { Name: "test prefix limits", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "create table varchar_limit(c varchar(10000), index (c(768)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "create table text_limit(c text, index (c(768)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "create table varbinary_limit(c varbinary(10000), index (c(3072)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "create table blob_limit(c blob, index (c(3072)))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "create table bad(c varchar(10000), index (c(769)))", ExpectedErr: sql.ErrKeyTooLong, }, { Query: "create table bad(c text, index (c(769)))", ExpectedErr: sql.ErrKeyTooLong, }, { Query: "create table bad(c varbinary(10000), index (c(3073)))", ExpectedErr: sql.ErrKeyTooLong, }, { Query: "create table bad(c blob, index (c(3073)))", ExpectedErr: sql.ErrKeyTooLong, }, }, }, }
var IndexQueries = []ScriptTest{ { Name: "unique key violation prevents insert", SetUpScript: []string{ "create table users (id varchar(26) primary key, namespace varchar(50), name varchar(50));", }, Assertions: []ScriptTestAssertion{ { Query: "create unique index namespace__name on users (namespace, name)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, }, { Query: "show create table users", Expected: []sql.Row{ {"users", "CREATE TABLE `users` (\n `id` varchar(26) NOT NULL,\n `namespace` varchar(50),\n `name` varchar(50),\n PRIMARY KEY (`id`),\n UNIQUE KEY `namespace__name` (`namespace`,`name`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into users values ('user1', 'namespace1', 'name1')", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, { Query: "insert into users values ('user2', 'namespace1', 'name1')", ExpectedErr: sql.ErrUniqueKeyViolation, }, }, }, { Name: "unique key duplicate key update", SetUpScript: []string{ "CREATE TABLE auniquetable (pk int primary key, uk int unique key, i int);", "INSERT INTO auniquetable VALUES(0,0,0);", "INSERT INTO auniquetable (pk,uk) VALUES(1,0) on duplicate key update i = 99;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT pk, uk, i from auniquetable", Expected: []sql.Row{ {0, 0, 99}, }, }, }, }, { Name: "non-unique indexes on keyless tables", SetUpScript: []string{ "create table t (i int, j int, index(i))", "insert into t values (0, 100), (0, 200), (1, 100), (1, 200), (2, 100), (2, 200)", }, Assertions: []ScriptTestAssertion{ { Query: "select i, j from t where i = 0 order by i, j", Expected: []sql.Row{ {0, 100}, {0, 200}, }, }, { Query: "select i, j from t where i = 1 order by i, j", Expected: []sql.Row{ {1, 100}, {1, 200}, }, }, { Query: "select i, j from t where i > 0 order by i, j", Expected: []sql.Row{ {1, 100}, {1, 200}, {2, 100}, {2, 200}, }, }, { Query: "select i, j from t where i > 0 and i < 2 order by i, j", Expected: []sql.Row{ {1, 100}, {1, 200}, }, }, }, }, { Name: "more non-unique indexes on keyless tables", SetUpScript: []string{ "create table t (i int, j int, k int, index(i, j))", "insert into t values (0, 0, 123), (0, 1, 456), (1, 0, 123), (1, 1, 456), (2, 0, 123), (2, 1, 456)", }, Assertions: []ScriptTestAssertion{ { Query: "select i, j, k from t where i = 0 order by i, j, k", Expected: []sql.Row{ {0, 0, 123}, {0, 1, 456}, }, }, { Query: "select i, j, k from t where i = 0 and j = 0 order by i, j, k", Expected: []sql.Row{ {0, 0, 123}, }, }, { Query: "select i, j, k from t where i = 1 and (j = 0 or j = 1) order by i, j, k", Expected: []sql.Row{ {1, 0, 123}, {1, 1, 456}, }, }, { Query: "select i, j, k from t where i > 0 and j > 0 order by i, j, k", Expected: []sql.Row{ {1, 1, 456}, {2, 1, 456}, }, }, { Query: "select i, j, k from t where i > 0 and i < 2 order by i, j, k", Expected: []sql.Row{ {1, 0, 123}, {1, 1, 456}, }, }, }, }, }
var InfoSchemaQueries = []QueryTest{ { Query: `SELECT table_name, index_name, comment, non_unique, GROUP_CONCAT(column_name ORDER BY seq_in_index) AS COLUMNS FROM information_schema.statistics WHERE table_schema='mydb' AND table_name='mytable' AND index_name!="PRIMARY" GROUP BY index_name;`, ExpectedColumns: sql.Schema{ { Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default), }, { Name: "INDEX_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default), }, { Name: "COMMENT", Type: types.MustCreateString(sqltypes.VarChar, 8, sql.Collation_Information_Schema_Default), }, { Name: "NON_UNIQUE", Type: types.Int32, }, { Name: "COLUMNS", Type: types.Text, }, }, Expected: []sql.Row{ {"mytable", "idx_si", "", 1, "s,i"}, {"mytable", "mytable_i_s", "", 1, "i,s"}, {"mytable", "mytable_s", "", 0, "s"}, }, }, { Query: `select table_name from information_schema.tables where table_name = 'mytable' limit 1;`, ExpectedColumns: sql.Schema{ { Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default), }, }, Expected: []sql.Row{{"mytable"}}, }, { Query: `select table_catalog, table_schema, table_name from information_schema.tables where table_name = 'mytable' limit 1;`, ExpectedColumns: sql.Schema{ {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)}, {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)}, {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)}, }, Expected: []sql.Row{{"def", "mydb", "mytable"}}, }, { Query: `select table_name from information_schema.tables where table_schema = 'information_schema' order by table_name;`, Expected: []sql.Row{ {"administrable_role_authorizations"}, {"applicable_roles"}, {"character_sets"}, {"check_constraints"}, {"collations"}, {"collation_character_set_applicability"}, {"columns"}, {"columns_extensions"}, {"column_privileges"}, {"column_statistics"}, {"enabled_roles"}, {"engines"}, {"events"}, {"files"}, {"innodb_buffer_page"}, {"innodb_buffer_page_lru"}, {"innodb_buffer_pool_stats"}, {"innodb_cached_indexes"}, {"innodb_cmp"}, {"innodb_cmpmem"}, {"innodb_cmpmem_reset"}, {"innodb_cmp_per_index"}, {"innodb_cmp_per_index_reset"}, {"innodb_cmp_reset"}, {"innodb_columns"}, {"innodb_datafiles"}, {"innodb_fields"}, {"innodb_foreign"}, {"innodb_foreign_cols"}, {"innodb_ft_being_deleted"}, {"innodb_ft_config"}, {"innodb_ft_default_stopword"}, {"innodb_ft_deleted"}, {"innodb_ft_index_cache"}, {"innodb_ft_index_table"}, {"innodb_indexes"}, {"innodb_metrics"}, {"innodb_session_temp_tablespaces"}, {"innodb_tables"}, {"innodb_tablespaces"}, {"innodb_tablespaces_brief"}, {"innodb_tablestats"}, {"innodb_temp_table_info"}, {"innodb_trx"}, {"innodb_virtual"}, {"keywords"}, {"key_column_usage"}, {"optimizer_trace"}, {"parameters"}, {"partitions"}, {"plugins"}, {"processlist"}, {"profiling"}, {"referential_constraints"}, {"resource_groups"}, {"role_column_grants"}, {"role_routine_grants"}, {"role_table_grants"}, {"routines"}, {"schemata"}, {"schemata_extensions"}, {"schema_privileges"}, {"statistics"}, {"st_geometry_columns"}, {"st_spatial_reference_systems"}, {"st_units_of_measure"}, {"tables"}, {"tablespaces"}, {"tablespaces_extensions"}, {"tables_extensions"}, {"table_constraints"}, {"table_constraints_extensions"}, {"table_privileges"}, {"triggers"}, {"user_attributes"}, {"user_privileges"}, {"views"}, {"view_routine_usage"}, {"view_table_usage"}, }, }, { Query: "SHOW TABLES", Expected: []sql.Row{ {"myview"}, {"fk_tbl"}, {"mytable"}, }, }, { Query: "SHOW FULL TABLES", Expected: []sql.Row{ {"fk_tbl", "BASE TABLE"}, {"myview", "VIEW"}, {"mytable", "BASE TABLE"}, }, }, { Query: "SHOW TABLES FROM foo", Expected: []sql.Row{ {"other_table"}, }, }, { Query: "SHOW TABLES LIKE '%table'", Expected: []sql.Row{ {"mytable"}, }, }, { Query: `SHOW COLUMNS FROM mytable`, Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", "NULL", ""}, {"s", "varchar(20)", "NO", "UNI", "NULL", ""}, }, }, { Query: `DESCRIBE mytable`, Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", "NULL", ""}, {"s", "varchar(20)", "NO", "UNI", "NULL", ""}, }, }, { Query: `DESC mytable`, Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", "NULL", ""}, {"s", "varchar(20)", "NO", "UNI", "NULL", ""}, }, }, { Query: `SHOW COLUMNS FROM mytable WHERE Field = 'i'`, Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", "NULL", ""}, }, }, { Query: `SHOW COLUMNS FROM mytable LIKE 'i'`, Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", "NULL", ""}, }, }, { Query: `SHOW FULL COLUMNS FROM mytable`, Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", "NULL", "", "", ""}, {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "UNI", "NULL", "", "", "column s"}, }, }, { Query: "SHOW TABLES WHERE `Tables_in_mydb` = 'mytable'", Expected: []sql.Row{ {"mytable"}, }, }, { Query: ` SELECT LOGFILE_GROUP_NAME, FILE_NAME, TOTAL_EXTENTS, INITIAL_SIZE, ENGINE, EXTRA FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'UNDO LOG' AND FILE_NAME IS NOT NULL AND LOGFILE_GROUP_NAME IS NOT NULL GROUP BY LOGFILE_GROUP_NAME, FILE_NAME, ENGINE, TOTAL_EXTENTS, INITIAL_SIZE ORDER BY LOGFILE_GROUP_NAME `, Expected: nil, }, { Query: ` SELECT DISTINCT TABLESPACE_NAME, FILE_NAME, LOGFILE_GROUP_NAME, EXTENT_SIZE, INITIAL_SIZE, ENGINE FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'DATAFILE' ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME `, Expected: nil, }, { Query: ` SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='mydb' AND (TABLE_TYPE='BASE TABLE' OR TABLE_TYPE='VIEW') ORDER BY 1 `, Expected: []sql.Row{ {"fk_tbl"}, {"mytable"}, {"myview"}, }, }, { Query: ` SELECT COLUMN_NAME, DATA_TYPE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='mydb' AND TABLE_NAME='mytable' `, Expected: []sql.Row{ {"s", "varchar"}, {"i", "bigint"}, }, }, { Query: ` SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME LIKE '%table' GROUP BY COLUMN_NAME `, Expected: []sql.Row{ {"s"}, {"i"}, }, }, { Query: ` SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME LIKE '%table' GROUP BY 1 `, Expected: []sql.Row{ {"s"}, {"i"}, }, }, { Query: ` SELECT COLUMN_NAME AS COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME LIKE '%table' GROUP BY 1 `, Expected: []sql.Row{ {"s"}, {"i"}, }, }, { Query: `SHOW INDEXES FROM mytaBLE`, Expected: []sql.Row{ {"mytable", 0, "PRIMARY", 1, "i", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"mytable", 0, "mytable_s", 1, "s", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"mytable", 1, "mytable_i_s", 1, "i", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"mytable", 1, "mytable_i_s", 2, "s", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"mytable", 1, "idx_si", 1, "s", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"mytable", 1, "idx_si", 2, "i", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { Query: `SHOW KEYS FROM mytaBLE`, Expected: []sql.Row{ {"mytable", 0, "PRIMARY", 1, "i", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"mytable", 0, "mytable_s", 1, "s", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"mytable", 1, "mytable_i_s", 1, "i", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"mytable", 1, "mytable_i_s", 2, "s", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"mytable", 1, "idx_si", 1, "s", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"mytable", 1, "idx_si", 2, "i", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { Query: `SHOW CREATE TABLE mytaBLE`, Expected: []sql.Row{ {"mytable", "CREATE TABLE `mytable` (\n" + " `i` bigint NOT NULL,\n" + " `s` varchar(20) NOT NULL COMMENT 'column s',\n" + " PRIMARY KEY (`i`),\n" + " KEY `idx_si` (`s`,`i`),\n" + " KEY `mytable_i_s` (`i`,`s`),\n" + " UNIQUE KEY `mytable_s` (`s`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: `SHOW CREATE TABLE fk_TBL`, Expected: []sql.Row{ {"fk_tbl", "CREATE TABLE `fk_tbl` (\n" + " `pk` bigint NOT NULL,\n" + " `a` bigint,\n" + " `b` varchar(20),\n" + " PRIMARY KEY (`pk`),\n" + " KEY `ab` (`a`,`b`),\n" + " CONSTRAINT `fk1` FOREIGN KEY (`a`,`b`) REFERENCES `mytable` (`i`,`s`) ON DELETE CASCADE\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "SELECT table_name, `auto_increment` FROM information_schema.tables " + "WHERE TABLE_SCHEMA='mydb' AND TABLE_TYPE='BASE TABLE' ORDER BY 1", Expected: []sql.Row{ {"fk_tbl", nil}, {"mytable", nil}, }, }, { Query: "SHOW ENGINES", Expected: []sql.Row{ {"InnoDB", "DEFAULT", "Supports transactions, row-level locking, and foreign keys", "YES", "YES", "YES"}, }, }, { Query: "SELECT * FROM information_schema.table_constraints ORDER BY table_name, constraint_type;", Expected: []sql.Row{ {"def", "mydb", "fk1", "mydb", "fk_tbl", "FOREIGN KEY", "YES"}, {"def", "mydb", "PRIMARY", "mydb", "fk_tbl", "PRIMARY KEY", "YES"}, {"def", "mydb", "PRIMARY", "mydb", "mytable", "PRIMARY KEY", "YES"}, {"def", "mydb", "mytable_s", "mydb", "mytable", "UNIQUE", "YES"}, {"def", "foo", "PRIMARY", "foo", "other_table", "PRIMARY KEY", "YES"}, }, }, { Query: "SELECT * FROM information_schema.check_constraints ORDER BY constraint_schema, constraint_name, check_clause ", Expected: []sql.Row{}, }, { Query: "SELECT * FROM information_schema.key_column_usage ORDER BY constraint_schema, table_name", Expected: []sql.Row{ {"def", "foo", "PRIMARY", "def", "foo", "other_table", "text", 1, nil, nil, nil, nil}, {"def", "mydb", "PRIMARY", "def", "mydb", "fk_tbl", "pk", 1, nil, nil, nil, nil}, {"def", "mydb", "fk1", "def", "mydb", "fk_tbl", "a", 1, 1, "mydb", "mytable", "i"}, {"def", "mydb", "fk1", "def", "mydb", "fk_tbl", "b", 2, 2, "mydb", "mytable", "s"}, {"def", "mydb", "PRIMARY", "def", "mydb", "mytable", "i", 1, nil, nil, nil, nil}, {"def", "mydb", "mytable_s", "def", "mydb", "mytable", "s", 1, nil, nil, nil, nil}, }, }, { Query: ` select CONCAT(tbl.table_schema, '.', tbl.table_name) as the_table, col.column_name, GROUP_CONCAT(kcu.column_name SEPARATOR ',') as pk from information_schema.tables as tbl join information_schema.columns as col on tbl.table_name = col.table_name join information_schema.key_column_usage as kcu on tbl.table_name = kcu.table_name join information_schema.table_constraints as tc on kcu.constraint_name = tc.constraint_name where tbl.table_schema = 'mydb' and tbl.table_name = kcu.table_name and tc.constraint_type = 'PRIMARY KEY' and col.column_name like 'pk%' group by the_table, col.column_name `, Expected: []sql.Row{ {"mydb.fk_tbl", "pk", "pk,pk,pk"}, }, }, { Query: `SELECT count(*) FROM information_schema.COLLATIONS`, Expected: []sql.Row{{286}}, }, { Query: `SELECT * FROM information_schema.COLLATIONS ORDER BY collation_name LIMIT 4`, Expected: []sql.Row{ {"armscii8_bin", "armscii8", uint64(64), "", "Yes", uint32(1), "PAD SPACE"}, {"armscii8_general_ci", "armscii8", uint64(32), "Yes", "Yes", uint32(1), "PAD SPACE"}, {"ascii_bin", "ascii", uint64(65), "", "Yes", uint32(1), "PAD SPACE"}, {"ascii_general_ci", "ascii", uint64(11), "Yes", "Yes", uint32(1), "PAD SPACE"}, }, }, { Query: `SELECT * FROM information_schema.COLLATION_CHARACTER_SET_APPLICABILITY ORDER BY collation_name LIMIT 4 `, Expected: []sql.Row{ {"armscii8_bin", "armscii8"}, {"armscii8_general_ci", "armscii8"}, {"ascii_bin", "ascii"}, {"ascii_general_ci", "ascii"}, }, }, { Query: `SELECT * FROM information_schema.ENGINES ORDER BY engine`, Expected: []sql.Row{ {"InnoDB", "DEFAULT", "Supports transactions, row-level locking, and foreign keys", "YES", "YES", "YES"}, }, }, { Query: `SELECT * from information_schema.administrable_role_authorizations`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.applicable_roles`, Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.column_privileges`, Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.optimizer_trace`, Expected: []sql.Row{}, }, { Query: "SELECT * FROM information_schema.partitions", Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.plugins`, Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.profiling`, Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.resource_groups`, Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.role_column_grants`, Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.role_routine_grants`, Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.tablespaces`, Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.tablespaces_extensions`, Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.view_routine_usage`, Expected: []sql.Row{}, }, { Query: `SELECT * FROM information_schema.view_table_usage`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_buffer_page`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_buffer_page_lru`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_buffer_pool_stats`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_cached_indexes`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_cmp`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_cmp_reset`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_cmpmem`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_cmpmem_reset`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_cmp_per_index`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_cmp_per_index_reset`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_columns`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_datafiles`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_fields`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_foreign`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_foreign_cols`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_ft_being_deleted`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_ft_config`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_ft_default_stopword`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_ft_deleted`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_ft_index_cache`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_ft_index_table`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_indexes`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_metrics`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_session_temp_tablespaces`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_tables`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_tablespaces`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_tablespaces_brief`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_tablestats`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_temp_table_info`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_trx`, Expected: []sql.Row{}, }, { Query: `SELECT * from information_schema.innodb_virtual`, Expected: []sql.Row{}, }, { Query: `SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, SEQ_IN_INDEX, 'PRIMARY' AS PK_NAME FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = 'mydb' AND INDEX_NAME='PRIMARY' ORDER BY TABLE_SCHEMA, TABLE_NAME, INDEX_NAME, SEQ_IN_INDEX;`, Expected: []sql.Row{ {"mydb", "fk_tbl", "pk", 1, "PRIMARY"}, {"mydb", "mytable", "i", 1, "PRIMARY"}, }, }, { Query: "select * from information_schema.character_sets;", Expected: []sql.Row{{"utf8mb4", "utf8mb4_0900_ai_ci", "UTF-8 Unicode", uint32(4)}}, }, { Query: `show columns from fk_tbl from mydb`, Expected: []sql.Row{ {"pk", "bigint", "NO", "PRI", "NULL", ""}, {"a", "bigint", "YES", "MUL", "NULL", ""}, {"b", "varchar(20)", "YES", "", "NULL", ""}, }, }, { Query: "SELECT * FROM information_schema.referential_constraints where CONSTRAINT_SCHEMA = 'mydb'", Expected: []sql.Row{ {"def", "mydb", "fk1", "def", "mydb", nil, "NONE", "NO ACTION", "CASCADE", "fk_tbl", "mytable"}, }, }, { Query: "SELECT count(*) FROM information_schema.keywords", Expected: []sql.Row{{747}}, }, { Query: "SELECT * FROM information_schema.st_spatial_reference_systems order by srs_id desc limit 10", Expected: []sql.Row{ {`WGS 84 / TM 36 SE`, uint32(32766), `EPSG`, 32766, `PROJCS["WGS 84 / TM 36 SE",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["Latitude of natural origin",0,AUTHORITY["EPSG","8801"]],PARAMETER["Longitude of natural origin",36,AUTHORITY["EPSG","8802"]],PARAMETER["Scale factor at natural origin",0.9996,AUTHORITY["EPSG","8805"]],PARAMETER["False easting",500000,AUTHORITY["EPSG","8806"]],PARAMETER["False northing",10000000,AUTHORITY["EPSG","8807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["E",EAST],AXIS["N",NORTH],AUTHORITY["EPSG","32766"]]`, nil}, {`WGS 84 / UPS South (N,E)`, uint32(32761), `EPSG`, 32761, `PROJCS["WGS 84 / UPS South (N,E)",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4326"]],PROJECTION["Polar Stereographic (variant A)",AUTHORITY["EPSG","9810"]],PARAMETER["Latitude of natural origin",-90,AUTHORITY["EPSG","8801"]],PARAMETER["Longitude of natural origin",0,AUTHORITY["EPSG","8802"]],PARAMETER["Scale factor at natural origin",0.994,AUTHORITY["EPSG","8805"]],PARAMETER["False easting",2000000,AUTHORITY["EPSG","8806"]],PARAMETER["False northing",2000000,AUTHORITY["EPSG","8807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["N",NORTH],AXIS["E",NORTH],AUTHORITY["EPSG","32761"]]`, nil}, {`WGS 84 / UTM zone 60S`, uint32(32760), `EPSG`, 32760, `PROJCS["WGS 84 / UTM zone 60S",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["Latitude of natural origin",0,AUTHORITY["EPSG","8801"]],PARAMETER["Longitude of natural origin",177,AUTHORITY["EPSG","8802"]],PARAMETER["Scale factor at natural origin",0.9996,AUTHORITY["EPSG","8805"]],PARAMETER["False easting",500000,AUTHORITY["EPSG","8806"]],PARAMETER["False northing",10000000,AUTHORITY["EPSG","8807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["E",EAST],AXIS["N",NORTH],AUTHORITY["EPSG","32760"]]`, nil}, {`WGS 84 / UTM zone 59S`, uint32(32759), `EPSG`, 32759, `PROJCS["WGS 84 / UTM zone 59S",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["Latitude of natural origin",0,AUTHORITY["EPSG","8801"]],PARAMETER["Longitude of natural origin",171,AUTHORITY["EPSG","8802"]],PARAMETER["Scale factor at natural origin",0.9996,AUTHORITY["EPSG","8805"]],PARAMETER["False easting",500000,AUTHORITY["EPSG","8806"]],PARAMETER["False northing",10000000,AUTHORITY["EPSG","8807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["E",EAST],AXIS["N",NORTH],AUTHORITY["EPSG","32759"]]`, nil}, {`WGS 84 / UTM zone 58S`, uint32(32758), `EPSG`, 32758, `PROJCS["WGS 84 / UTM zone 58S",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["Latitude of natural origin",0,AUTHORITY["EPSG","8801"]],PARAMETER["Longitude of natural origin",165,AUTHORITY["EPSG","8802"]],PARAMETER["Scale factor at natural origin",0.9996,AUTHORITY["EPSG","8805"]],PARAMETER["False easting",500000,AUTHORITY["EPSG","8806"]],PARAMETER["False northing",10000000,AUTHORITY["EPSG","8807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["E",EAST],AXIS["N",NORTH],AUTHORITY["EPSG","32758"]]`, nil}, {`WGS 84 / UTM zone 57S`, uint32(32757), `EPSG`, 32757, `PROJCS["WGS 84 / UTM zone 57S",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["Latitude of natural origin",0,AUTHORITY["EPSG","8801"]],PARAMETER["Longitude of natural origin",159,AUTHORITY["EPSG","8802"]],PARAMETER["Scale factor at natural origin",0.9996,AUTHORITY["EPSG","8805"]],PARAMETER["False easting",500000,AUTHORITY["EPSG","8806"]],PARAMETER["False northing",10000000,AUTHORITY["EPSG","8807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["E",EAST],AXIS["N",NORTH],AUTHORITY["EPSG","32757"]]`, nil}, {`WGS 84 / UTM zone 56S`, uint32(32756), `EPSG`, 32756, `PROJCS["WGS 84 / UTM zone 56S",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["Latitude of natural origin",0,AUTHORITY["EPSG","8801"]],PARAMETER["Longitude of natural origin",153,AUTHORITY["EPSG","8802"]],PARAMETER["Scale factor at natural origin",0.9996,AUTHORITY["EPSG","8805"]],PARAMETER["False easting",500000,AUTHORITY["EPSG","8806"]],PARAMETER["False northing",10000000,AUTHORITY["EPSG","8807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["E",EAST],AXIS["N",NORTH],AUTHORITY["EPSG","32756"]]`, nil}, {`WGS 84 / UTM zone 55S`, uint32(32755), `EPSG`, 32755, `PROJCS["WGS 84 / UTM zone 55S",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["Latitude of natural origin",0,AUTHORITY["EPSG","8801"]],PARAMETER["Longitude of natural origin",147,AUTHORITY["EPSG","8802"]],PARAMETER["Scale factor at natural origin",0.9996,AUTHORITY["EPSG","8805"]],PARAMETER["False easting",500000,AUTHORITY["EPSG","8806"]],PARAMETER["False northing",10000000,AUTHORITY["EPSG","8807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["E",EAST],AXIS["N",NORTH],AUTHORITY["EPSG","32755"]]`, nil}, {`WGS 84 / UTM zone 54S`, uint32(32754), `EPSG`, 32754, `PROJCS["WGS 84 / UTM zone 54S",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["Latitude of natural origin",0,AUTHORITY["EPSG","8801"]],PARAMETER["Longitude of natural origin",141,AUTHORITY["EPSG","8802"]],PARAMETER["Scale factor at natural origin",0.9996,AUTHORITY["EPSG","8805"]],PARAMETER["False easting",500000,AUTHORITY["EPSG","8806"]],PARAMETER["False northing",10000000,AUTHORITY["EPSG","8807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["E",EAST],AXIS["N",NORTH],AUTHORITY["EPSG","32754"]]`, nil}, {`WGS 84 / UTM zone 53S`, uint32(32753), `EPSG`, 32753, `PROJCS["WGS 84 / UTM zone 53S",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["Latitude of natural origin",0,AUTHORITY["EPSG","8801"]],PARAMETER["Longitude of natural origin",135,AUTHORITY["EPSG","8802"]],PARAMETER["Scale factor at natural origin",0.9996,AUTHORITY["EPSG","8805"]],PARAMETER["False easting",500000,AUTHORITY["EPSG","8806"]],PARAMETER["False northing",10000000,AUTHORITY["EPSG","8807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["E",EAST],AXIS["N",NORTH],AUTHORITY["EPSG","32753"]]`, nil}, }, }, { Query: "SELECT count(*) FROM information_schema.st_units_of_measure", Expected: []sql.Row{{47}}, }, { Query: "SELECT * FROM information_schema.schemata_extensions", Expected: []sql.Row{{"def", "information_schema", ""}, {"def", "foo", ""}, {"def", "mydb", ""}}, }, { Query: `SELECT * FROM information_schema.columns_extensions where table_name = 'mytable'`, Expected: []sql.Row{{"def", "mydb", "mytable", "i", nil, nil}, {"def", "mydb", "mytable", "s", nil, nil}}, }, { Query: `SELECT * FROM information_schema.table_constraints_extensions where table_name = 'fk_tbl'`, Expected: []sql.Row{{"def", "mydb", "PRIMARY", "fk_tbl", nil, nil}, {"def", "mydb", "ab", "fk_tbl", nil, nil}}, }, { Query: `SELECT * FROM information_schema.tables_extensions where table_name = 'mytable'`, Expected: []sql.Row{{"def", "mydb", "mytable", nil, nil}}, }, { Query: "SELECT table_rows FROM INFORMATION_SCHEMA.TABLES where table_name='mytable'", Expected: []sql.Row{{uint64(3)}}, }, { Query: "select table_name from information_schema.tables where table_schema collate utf8_general_ci = 'information_schema' and table_name collate utf8_general_ci = 'parameters'", Expected: []sql.Row{{"parameters"}}, }, }
var InfoSchemaScripts = []ScriptTest{ { Name: "query does not use optimization rule on LIKE clause because info_schema db charset is utf8mb3", SetUpScript: []string{ "CREATE TABLE t1 (a int, condition_choose varchar(10));", }, Assertions: []ScriptTestAssertion{ { Query: "select column_name from information_schema.columns where column_name like 'condition%';", Expected: []sql.Row{{"condition_choose"}}, }, { Query: "select column_name from information_schema.columns where column_name like '%condition%';", Expected: []sql.Row{{"ACTION_CONDITION"}, {"condition_choose"}}, }, }, }, { Name: "test databases created with non default collation and charset", SetUpScript: []string{ "CREATE DATABASE test_db CHARACTER SET utf8mb3 COLLATE utf8mb3_bin;", "USE test_db", "CREATE TABLE small_table (a binary, b VARCHAR(50));", "CREATE TABLE test_table (id INT PRIMARY KEY, col1 TEXT, col2 CHAR(20) CHARACTER SET latin1 COLLATE latin1_german1_ci) CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT table_schema, table_name, column_name, character_set_name, collation_name, column_type FROM information_schema.columns where table_schema = 'test_db' order by column_name", Expected: []sql.Row{ {"test_db", "small_table", "a", nil, nil, "binary(1)"}, {"test_db", "small_table", "b", "utf8mb3", "utf8mb3_bin", "varchar(50)"}, {"test_db", "test_table", "col1", "utf8mb4", "utf8mb4_0900_bin", "text"}, {"test_db", "test_table", "col2", "latin1", "latin1_german1_ci", "char(20)"}, {"test_db", "test_table", "id", nil, nil, "int"}, }, }, }, }, { Name: "information_schema.table_constraints ignores non-unique indexes", SetUpScript: []string{ "CREATE TABLE t (pk int primary key, test_score int, height int)", "CREATE INDEX myindex on t(test_score)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.table_constraints where table_name='t' ORDER BY constraint_type,constraint_name", Expected: []sql.Row{ {"def", "mydb", "PRIMARY", "mydb", "t", "PRIMARY KEY", "YES"}, }, }, }, }, { Name: "information_schema.key_column_usage ignores non-unique indexes", SetUpScript: []string{ "CREATE TABLE t (pk int primary key, test_score int, height int)", "CREATE INDEX myindex on t(test_score)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.key_column_usage where table_name='t'", Expected: []sql.Row{ {"def", "mydb", "PRIMARY", "def", "mydb", "t", "pk", 1, nil, nil, nil, nil}, }, }, }, }, { Name: "information_schema.key_column_usage works with composite foreign and primary keys", SetUpScript: []string{ "CREATE TABLE ptable (pk int primary key, test_score int, height int)", "CREATE INDEX myindex on ptable(test_score, height)", "CREATE TABLE ptable2 (pk int primary key, test_score2 int, height2 int, CONSTRAINT fkr FOREIGN KEY (test_score2, height2) REFERENCES ptable(test_score,height));", "CREATE TABLE atable (pk int, test_score int, height int, PRIMARY KEY (pk, test_score))", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.key_column_usage where table_name='ptable2' ORDER BY constraint_name", Expected: []sql.Row{ {"def", "mydb", "fkr", "def", "mydb", "ptable2", "test_score2", 1, 1, "mydb", "ptable", "test_score"}, {"def", "mydb", "fkr", "def", "mydb", "ptable2", "height2", 2, 2, "mydb", "ptable", "height"}, {"def", "mydb", "PRIMARY", "def", "mydb", "ptable2", "pk", 1, nil, nil, nil, nil}, }, }, { Query: "SELECT * FROM information_schema.key_column_usage where table_name='atable' ORDER BY constraint_name", Expected: []sql.Row{ {"def", "mydb", "PRIMARY", "def", "mydb", "atable", "pk", 1, nil, nil, nil, nil}, {"def", "mydb", "PRIMARY", "def", "mydb", "atable", "test_score", 2, nil, nil, nil, nil}, }, }, }, }, { Name: "information_schema.referential_constraints works with primary, non-unique and unique keys", SetUpScript: []string{ "CREATE TABLE my_table (i int primary key, height int, weight int)", "CREATE INDEX h on my_TABLE(height)", "CREATE UNIQUE INDEX w on my_TABLE(weight)", "CREATE TABLE ref_table (a int primary key, height int, weight int)", "alter table ref_table add constraint fk_across_dbs_ref_pk foreign key (a) references my_table(i)", "alter table ref_table add constraint fk_across_dbs_key foreign key (a) references my_table(height)", "alter table ref_table add constraint fk_across_dbs_unique foreign key (a) references my_table(weight)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.referential_constraints where constraint_schema = 'mydb' and table_name = 'ref_table'", Expected: []sql.Row{ {"def", "mydb", "fk_across_dbs_ref_pk", "def", "mydb", "PRIMARY", "NONE", "NO ACTION", "NO ACTION", "ref_table", "my_table"}, {"def", "mydb", "fk_across_dbs_key", "def", "mydb", nil, "NONE", "NO ACTION", "NO ACTION", "ref_table", "my_table"}, {"def", "mydb", "fk_across_dbs_unique", "def", "mydb", "w", "NONE", "NO ACTION", "NO ACTION", "ref_table", "my_table"}, }, }, }, }, { Name: "information_schema.triggers create trigger definer defined", SetUpScript: []string{ "CREATE TABLE aa (x INT PRIMARY KEY, y INT)", "CREATE DEFINER=`dolt`@`localhost` TRIGGER trigger1 BEFORE INSERT ON aa FOR EACH ROW SET NEW.x = NEW.x + 1", "CREATE TRIGGER trigger2 BEFORE INSERT ON aa FOR EACH ROW SET NEW.y = NEW.y + 2", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT trigger_name, event_object_table, definer FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_name = 'trigger1'", Expected: []sql.Row{ {"trigger1", "aa", "dolt@localhost"}, }, }, { Query: `SELECT trigger_catalog, trigger_schema, trigger_name, event_manipulation, event_object_catalog, event_object_schema, event_object_table, action_order, action_condition, action_statement, action_orientation, action_timing, action_reference_old_table, action_reference_new_table, action_reference_old_row, action_reference_new_row, sql_mode, definer, character_set_client, collation_connection, database_collation FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'mydb'`, Expected: []sql.Row{ {"def", "mydb", "trigger1", "INSERT", "def", "mydb", "aa", 1, nil, "SET NEW.x = NEW.x + 1", "ROW", "BEFORE", nil, nil, "OLD", "NEW", "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY", "dolt@localhost", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}, {"def", "mydb", "trigger2", "INSERT", "def", "mydb", "aa", 2, nil, "SET NEW.y = NEW.y + 2", "ROW", "BEFORE", nil, nil, "OLD", "NEW", "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY", "root@localhost", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}, }, }, }, }, { Name: "information_schema.statistics shows non unique index", SetUpScript: []string{ "CREATE TABLE t (pk int primary key, test_score int, height int)", "CREATE INDEX myindex on t(test_score)", "INSERT INTO t VALUES (2,23,25), (3,24,26)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.statistics where table_name='t'", Expected: []sql.Row{ {"def", "mydb", "t", 1, "mydb", "myindex", 1, "test_score", "A", 0, nil, nil, "YES", "BTREE", "", "", "YES", nil}, {"def", "mydb", "t", 0, "mydb", "PRIMARY", 1, "pk", "A", 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, }, }, { Name: "information_schema.columns shows default value", SetUpScript: []string{ "CREATE TABLE t (pk int primary key, fname varchar(20), lname varchar(20), height int)", "ALTER TABLE t CHANGE fname fname varchar(20) NOT NULL DEFAULT ''", "ALTER TABLE t CHANGE lname lname varchar(20) NOT NULL DEFAULT 'ln'", "ALTER TABLE t CHANGE height h int DEFAULT NULL", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT table_name, column_name, column_default, is_nullable FROM information_schema.columns where table_name='t' order by 1,2", Expected: []sql.Row{ {"t", "fname", "", "NO"}, {"t", "h", nil, "YES"}, {"t", "lname", "ln", "NO"}, {"t", "pk", nil, "NO"}, }, }, }, }, { Name: "information_schema.columns shows default value with more types", SetUpScript: []string{ "CREATE TABLE test_table (pk int primary key, col2 float NOT NULL DEFAULT 4.5, col3 double NOT NULL DEFAULT 3.14159, col4 datetime NULL DEFAULT '2008-04-22 16:16:16', col5 boolean NULL DEFAULT FALSE)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT table_name, column_name, column_default, is_nullable FROM information_schema.CoLuMnS where table_name='test_table'", Expected: []sql.Row{ {"test_table", "pk", nil, "NO"}, {"test_table", "col2", "4.5", "NO"}, {"test_table", "col3", "3.14159", "NO"}, {"test_table", "col4", "2008-04-22 16:16:16", "YES"}, {"test_table", "col5", "0", "YES"}, }, }, }, }, { Name: "information_schema.columns shows default value with more types", SetUpScript: []string{ "CREATE TABLE test_table (pk int primary key, col2 float DEFAULT (length('he`Llo')), col3 int DEFAULT (greatest(`pk`, 2)), col4 int DEFAULT (5 + 5), col5 datetime default NOW(), create_time timestamp(6) NOT NULL DEFAULT NOW(6));", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT table_name, column_name, column_default, is_nullable FROM information_schema.columns where table_name='test_table'", Expected: []sql.Row{ {"test_table", "pk", nil, "NO"}, {"test_table", "col2", "length('he`Llo')", "YES"}, {"test_table", "col3", "greatest(pk,2)", "YES"}, {"test_table", "col4", "(5 + 5)", "YES"}, {"test_table", "col5", "CURRENT_TIMESTAMP", "YES"}, {"test_table", "create_time", "CURRENT_TIMESTAMP(6)", "NO"}, }, }, }, }, { Name: "information_schema.columns correctly shows numeric precision and scale for a wide variety of types", SetUpScript: []string{ "CREATE TABLE `digits` (`c0` tinyint,`c1` tinyint unsigned,`c2` smallint,`c3` smallint unsigned,`c4` mediumint,`c5` mediumint unsigned,`c6` int,`c7` int unsigned,`c8` bigint,`c9` bigint unsigned,`c10` float,`c11` dec(5,2),`st` varchar(100))", }, Assertions: []ScriptTestAssertion{ { Query: "select column_name, numeric_precision, numeric_scale from information_schema.columns where table_name='digits' order by ordinal_position;", Expected: []sql.Row{ {"c0", 3, 0}, {"c1", 3, 0}, {"c2", 5, 0}, {"c3", 5, 0}, {"c4", 7, 0}, {"c5", 7, 0}, {"c6", 10, 0}, {"c7", 10, 0}, {"c8", 19, 0}, {"c9", 20, 0}, {"c10", 12, nil}, {"c11", 5, 2}, {"st", nil, nil}, }, }, }, }, { Name: "information_schema.routines", SetUpScript: []string{ "CREATE PROCEDURE p1() COMMENT 'hi' DETERMINISTIC SELECT 6", "CREATE definer=`user` PROCEDURE p2() SQL SECURITY INVOKER SELECT 7", "CREATE PROCEDURE p21() SQL SECURITY DEFINER SELECT 8", "USE foo", "CREATE PROCEDURE p12() COMMENT 'hello' DETERMINISTIC SELECT 6", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT specific_name, routine_catalog, routine_schema, routine_name, routine_type, " + "data_type, character_maximum_length, character_octet_length, numeric_precision, numeric_scale, " + "datetime_precision, character_set_name, collation_name, dtd_identifier, " + "routine_body, external_name, external_language, parameter_style, is_deterministic, " + "sql_data_access, sql_path, security_type, sql_mode, routine_comment, definer, " + "character_set_client, collation_connection, database_collation FROM information_schema.routines", Expected: []sql.Row{ {"p1", "def", "mydb", "p1", "PROCEDURE", "", nil, nil, nil, nil, nil, nil, nil, nil, "SQL", nil, "SQL", "SQL", "YES", "CONTAINS SQL", nil, "DEFINER", "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY", "hi", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}, {"p2", "def", "mydb", "p2", "PROCEDURE", "", nil, nil, nil, nil, nil, nil, nil, nil, "SQL", nil, "SQL", "SQL", "NO", "CONTAINS SQL", nil, "INVOKER", "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY", "", "user@%", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}, {"p12", "def", "foo", "p12", "PROCEDURE", "", nil, nil, nil, nil, nil, nil, nil, nil, "SQL", nil, "SQL", "SQL", "YES", "CONTAINS SQL", nil, "DEFINER", "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY", "hello", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}, {"p21", "def", "mydb", "p21", "PROCEDURE", "", nil, nil, nil, nil, nil, nil, nil, nil, "SQL", nil, "SQL", "SQL", "NO", "CONTAINS SQL", nil, "DEFINER", "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY", "", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}, }, }, }, }, { Name: "information_schema.columns for view", SetUpScript: []string{ "USE foo", "drop table other_table", "CREATE TABLE t (i int)", "CREATE VIEW v as select * from t", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'foo'", Expected: []sql.Row{ {"def", "foo", "t", "i", uint32(1), nil, "YES", "int", nil, nil, int64(10), int64(0), nil, nil, nil, "int", "", "", "insert,references,select,update", "", "", nil}, {"def", "foo", "v", "", uint32(0), nil, "", nil, nil, nil, nil, nil, nil, "", "", "", "", "", "select", "", "", nil}, }, }, }, }, { Name: "information_schema.columns with column key check for PRI and UNI", SetUpScript: []string{ "CREATE TABLE about (id int unsigned NOT NULL AUTO_INCREMENT, uuid char(36) NOT NULL, " + "status varchar(255) NOT NULL DEFAULT 'draft', date_created timestamp DEFAULT NULL, date_updated timestamp DEFAULT NULL, " + "url_key varchar(255) NOT NULL, PRIMARY KEY (uuid), UNIQUE KEY about_url_key_unique (url_key), UNIQUE KEY id (id))", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLUMN_TYPE, COLUMN_KEY, CHARACTER_MAXIMUM_LENGTH, EXTRA FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'about'", Expected: []sql.Row{ {"about", "id", nil, "NO", "int unsigned", "UNI", nil, "auto_increment"}, {"about", "uuid", nil, "NO", "char(36)", "PRI", 36, ""}, {"about", "status", "draft", "NO", "varchar(255)", "", 255, ""}, {"about", "date_created", nil, "YES", "timestamp", "", nil, ""}, {"about", "date_updated", nil, "YES", "timestamp", "", nil, ""}, {"about", "url_key", nil, "NO", "varchar(255)", "UNI", 255, ""}, }, }, }, }, { Name: "information_schema.columns with column key check for MUL", SetUpScript: []string{ "create table new_table (id int, name varchar(30), cname varbinary(100));", "alter table new_table modify column id int NOT NULL, add key(id);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE, COLUMN_TYPE, COLUMN_KEY, CHARACTER_MAXIMUM_LENGTH, EXTRA FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'new_table'", Expected: []sql.Row{ {"new_table", "id", "NO", "int", "int", "MUL", nil, ""}, {"new_table", "name", "YES", "varchar", "varchar(30)", "", 30, ""}, {"new_table", "cname", "YES", "varbinary", "varbinary(100)", "", 100, ""}, }, }, }, }, { Name: "information_schema.columns with column key check for MUL for only the first column of composite unique key", SetUpScript: []string{ "create table comp_uni (pk int not null, c0 int, c1 int, primary key (pk), unique key c0c1 (c0, c1));", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, COLUMN_TYPE, COLUMN_KEY FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comp_uni'", Expected: []sql.Row{ {"comp_uni", "pk", "NO", "int", "PRI"}, {"comp_uni", "c0", "YES", "int", "MUL"}, {"comp_uni", "c1", "YES", "int", ""}, }, }, }, }, { Name: "information_schema.columns with column key UNI is displayed as PRI if it cannot contain NULL values and there is no PRIMARY KEY in the table", SetUpScript: []string{ "create table ptable (id int not null, id2 int not null, col1 bool, UNIQUE KEY unique_key (id), UNIQUE KEY unique_key2 (id2));", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE, COLUMN_TYPE, COLUMN_KEY FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'ptable'", Expected: []sql.Row{ {"ptable", "id", "NO", "int", "int", "PRI"}, {"ptable", "id2", "NO", "int", "int", "UNI"}, {"ptable", "col1", "YES", "tinyint", "tinyint", ""}, }, }, }, }, { Name: "information_schema.columns with srs_id defined in spatial columns", SetUpScript: []string{ "CREATE TABLE stable (geo GEOMETRY NOT NULL DEFAULT (POINT(2, 5)), line LINESTRING NOT NULL, pnt POINT SRID 4326, pol POLYGON NOT NULL SRID 0);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, DATA_TYPE, COLUMN_TYPE, COLUMN_KEY, SRS_ID FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'stable'", Expected: []sql.Row{ {"stable", "geo", "point(2,5)", "NO", "geometry", "geometry", "", nil}, {"stable", "line", nil, "NO", "linestring", "linestring", "", nil}, {"stable", "pnt", nil, "YES", "point", "point", "", uint32(4326)}, {"stable", "pol", nil, "NO", "polygon", "polygon", "", uint32(0)}, }, }, }, }, { Name: "column specific tests information_schema.statistics table", SetUpScript: []string{ `create table ptable (i int primary key, b blob, c char(10))`, `alter table ptable add unique index (c(3))`, `alter table ptable add unique index (b(4))`, `create index b_and_c on ptable (b(5), c(6))`, `insert into ptable values (0 , ('abc'), 'abc'), (1 , ('bcd'), 'bcdefg'), (2 , null, 'bceff')`, }, Assertions: []ScriptTestAssertion{ { Query: `select index_name, seq_in_index, column_name, sub_part from information_schema.statistics where table_schema = 'mydb' and table_name = 'ptable' ORDER BY INDEX_NAME`, Expected: []sql.Row{ {"b", 1, "b", 4}, {"b_and_c", 1, "b", 5}, {"b_and_c", 2, "c", 6}, {"c", 1, "c", 3}, {"PRIMARY", 1, "i", nil}, }, }, { Skip: true, Query: `select index_name, seq_in_index, column_name, cardinality, sub_part from information_schema.statistics where table_schema = 'mydb' and table_name = 'ptable' ORDER BY INDEX_NAME`, Expected: []sql.Row{{2}, {2}, {2}, {2}, {2}}, }, { Query: `SELECT seq_in_index, sub_part, index_name, index_type, CASE non_unique WHEN 0 THEN 'TRUE' ELSE 'FALSE' END AS is_unique, column_name FROM information_schema.statistics WHERE table_schema='mydb' AND table_name='ptable' ORDER BY index_name, seq_in_index;`, Expected: []sql.Row{ {1, 4, "b", "BTREE", "TRUE", "b"}, {1, 5, "b_and_c", "BTREE", "FALSE", "b"}, {2, 6, "b_and_c", "BTREE", "FALSE", "c"}, {1, 3, "c", "BTREE", "TRUE", "c"}, {1, nil, "PRIMARY", "BTREE", "TRUE", "i"}, }, }, }, }, { Name: "column specific tests on information_schema.columns table", SetUpScript: []string{ `CREATE TABLE all_types ( pk int NOT NULL, binary_1 binary(1) DEFAULT "1", big_int bigint DEFAULT "1", bit_2 bit(2) DEFAULT 2, some_blob blob DEFAULT ("abc"), char_1 char(1) DEFAULT "A", some_date date DEFAULT "2022-02-22", date_time datetime(6) DEFAULT "2022-02-22 22:22:21", decimal_52 decimal(5,2) DEFAULT "994.45", some_double double DEFAULT "1.1", some_enum enum('s','m','l') DEFAULT "s", some_float float DEFAULT "4.4", some_geometry geometry srid 4326 DEFAULT (POINT(1, 2)), some_int int DEFAULT "3", some_json json DEFAULT (JSON_OBJECT("a", 1)), line_string linestring DEFAULT (LINESTRING(POINT(0, 0),POINT(1, 2))), long_blob longblob DEFAULT ("abc"), long_text longtext DEFAULT ("abc"), medium_blob mediumblob DEFAULT ("abc"), medium_int mediumint DEFAULT "7", medium_text mediumtext DEFAULT ("abc"), some_point point DEFAULT (POINT(2, 2)), some_polygon polygon DEFAULT NULL, some_set set('one','two') DEFAULT "one,two", small_int smallint DEFAULT "5", some_text text DEFAULT ("abc"), time_6 time(6) DEFAULT "11:59:59.000010", time_stamp timestamp(6) DEFAULT (CURRENT_TIMESTAMP()), tiny_blob tinyblob DEFAULT ("abc"), tiny_int tinyint DEFAULT "4", tiny_text tinytext DEFAULT ("abc"), var_char varchar(255) DEFAULT "varchar value", var_binary varbinary(255) DEFAULT "11111", some_year year DEFAULT "2023", PRIMARY KEY (pk) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;`, }, Assertions: []ScriptTestAssertion{ { Query: `SELECT table_catalog, table_schema, table_name, column_name, ordinal_position FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='mydb' AND TABLE_NAME='all_types' ORDER BY ORDINAL_POSITION`, Expected: []sql.Row{ {"def", "mydb", "all_types", "pk", uint32(1)}, {"def", "mydb", "all_types", "binary_1", uint32(2)}, {"def", "mydb", "all_types", "big_int", uint32(3)}, {"def", "mydb", "all_types", "bit_2", uint32(4)}, {"def", "mydb", "all_types", "some_blob", uint32(5)}, {"def", "mydb", "all_types", "char_1", uint32(6)}, {"def", "mydb", "all_types", "some_date", uint32(7)}, {"def", "mydb", "all_types", "date_time", uint32(8)}, {"def", "mydb", "all_types", "decimal_52", uint32(9)}, {"def", "mydb", "all_types", "some_double", uint32(10)}, {"def", "mydb", "all_types", "some_enum", uint32(11)}, {"def", "mydb", "all_types", "some_float", uint32(12)}, {"def", "mydb", "all_types", "some_geometry", uint32(13)}, {"def", "mydb", "all_types", "some_int", uint32(14)}, {"def", "mydb", "all_types", "some_json", uint32(15)}, {"def", "mydb", "all_types", "line_string", uint32(16)}, {"def", "mydb", "all_types", "long_blob", uint32(17)}, {"def", "mydb", "all_types", "long_text", uint32(18)}, {"def", "mydb", "all_types", "medium_blob", uint32(19)}, {"def", "mydb", "all_types", "medium_int", uint32(20)}, {"def", "mydb", "all_types", "medium_text", uint32(21)}, {"def", "mydb", "all_types", "some_point", uint32(22)}, {"def", "mydb", "all_types", "some_polygon", uint32(23)}, {"def", "mydb", "all_types", "some_set", uint32(24)}, {"def", "mydb", "all_types", "small_int", uint32(25)}, {"def", "mydb", "all_types", "some_text", uint32(26)}, {"def", "mydb", "all_types", "time_6", uint32(27)}, {"def", "mydb", "all_types", "time_stamp", uint32(28)}, {"def", "mydb", "all_types", "tiny_blob", uint32(29)}, {"def", "mydb", "all_types", "tiny_int", uint32(30)}, {"def", "mydb", "all_types", "tiny_text", uint32(31)}, {"def", "mydb", "all_types", "var_char", uint32(32)}, {"def", "mydb", "all_types", "var_binary", uint32(33)}, {"def", "mydb", "all_types", "some_year", uint32(34)}, }, }, { Query: `SELECT column_name, column_default, is_nullable, data_type, column_type, character_maximum_length, character_octet_length FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='mydb' AND TABLE_NAME='all_types' ORDER BY ORDINAL_POSITION`, Expected: []sql.Row{ {"pk", nil, "NO", "int", "int", nil, nil}, {"binary_1", "0x31", "YES", "binary", "binary(1)", 1, 1}, {"big_int", "1", "YES", "bigint", "bigint", nil, nil}, {"bit_2", "b'10'", "YES", "bit", "bit(2)", nil, nil}, {"some_blob", "'abc'", "YES", "blob", "blob", 65535, 65535}, {"char_1", "A", "YES", "char", "char(1)", 1, 4}, {"some_date", "2022-02-22 00:00:00", "YES", "date", "date", nil, nil}, {"date_time", "2022-02-22 22:22:21", "YES", "datetime", "datetime(6)", nil, nil}, {"decimal_52", "994.45", "YES", "decimal", "decimal(5,2)", nil, nil}, {"some_double", "1.1", "YES", "double", "double", nil, nil}, {"some_enum", "s", "YES", "enum", "enum('s','m','l')", 1, 4}, {"some_float", "4.4", "YES", "float", "float", nil, nil}, {"some_geometry", "point(1,2)", "YES", "geometry", "geometry", nil, nil}, {"some_int", "3", "YES", "int", "int", nil, nil}, {"some_json", "json_object('a',1)", "YES", "json", "json", nil, nil}, {"line_string", "linestring(point(0,0),point(1,2))", "YES", "linestring", "linestring", nil, nil}, {"long_blob", "'abc'", "YES", "longblob", "longblob", 4294967295, 4294967295}, {"long_text", "'abc'", "YES", "longtext", "longtext", 1073741823, 4294967295}, {"medium_blob", "'abc'", "YES", "mediumblob", "mediumblob", 16777215, 16777215}, {"medium_int", "7", "YES", "mediumint", "mediumint", nil, nil}, {"medium_text", "'abc'", "YES", "mediumtext", "mediumtext", 4194303, 16777215}, {"some_point", "point(2,2)", "YES", "point", "point", nil, nil}, {"some_polygon", nil, "YES", "polygon", "polygon", nil, nil}, {"some_set", "one,two", "YES", "set", "set('one','two')", 7, 28}, {"small_int", "5", "YES", "smallint", "smallint", nil, nil}, {"some_text", "'abc'", "YES", "text", "text", 16383, 65535}, {"time_6", "11:59:59.000010", "YES", "time", "time(6)", nil, nil}, {"time_stamp", "CURRENT_TIMESTAMP", "YES", "timestamp", "timestamp(6)", nil, nil}, {"tiny_blob", "'abc'", "YES", "tinyblob", "tinyblob", 255, 255}, {"tiny_int", "4", "YES", "tinyint", "tinyint", nil, nil}, {"tiny_text", "'abc'", "YES", "tinytext", "tinytext", 63, 255}, {"var_char", "varchar value", "YES", "varchar", "varchar(255)", 255, 1020}, {"var_binary", "0x3131313131", "YES", "varbinary", "varbinary(255)", 255, 255}, {"some_year", "2023", "YES", "year", "year", nil, nil}, }, }, { Query: `SELECT column_name, column_type, numeric_precision, numeric_scale, datetime_precision, character_set_name, collation_name, column_key, extra, column_comment, generation_expression, srs_id FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='mydb' AND TABLE_NAME='all_types' ORDER BY ORDINAL_POSITION`, Expected: []sql.Row{ {"pk", "int", 10, 0, nil, nil, nil, "PRI", "", "", "", nil}, {"binary_1", "binary(1)", nil, nil, nil, nil, nil, "", "", "", "", nil}, {"big_int", "bigint", 19, 0, nil, nil, nil, "", "", "", "", nil}, {"bit_2", "bit(2)", 2, nil, nil, nil, nil, "", "", "", "", nil}, {"some_blob", "blob", nil, nil, nil, nil, nil, "", "DEFAULT_GENERATED", "", "", nil}, {"char_1", "char(1)", nil, nil, nil, "utf8mb4", "utf8mb4_0900_bin", "", "", "", "", nil}, {"some_date", "date", nil, nil, nil, nil, nil, "", "", "", "", nil}, {"date_time", "datetime(6)", nil, nil, 0, nil, nil, "", "", "", "", nil}, {"decimal_52", "decimal(5,2)", 5, 2, nil, nil, nil, "", "", "", "", nil}, {"some_double", "double", 22, nil, nil, nil, nil, "", "", "", "", nil}, {"some_enum", "enum('s','m','l')", nil, nil, nil, "utf8mb4", "utf8mb4_0900_bin", "", "", "", "", nil}, {"some_float", "float", 12, nil, nil, nil, nil, "", "", "", "", nil}, {"some_geometry", "geometry", nil, nil, nil, nil, nil, "", "DEFAULT_GENERATED", "", "", uint32(4326)}, {"some_int", "int", 10, 0, nil, nil, nil, "", "", "", "", nil}, {"some_json", "json", nil, nil, nil, nil, nil, "", "DEFAULT_GENERATED", "", "", nil}, {"line_string", "linestring", nil, nil, nil, nil, nil, "", "DEFAULT_GENERATED", "", "", nil}, {"long_blob", "longblob", nil, nil, nil, nil, nil, "", "DEFAULT_GENERATED", "", "", nil}, {"long_text", "longtext", nil, nil, nil, "utf8mb4", "utf8mb4_0900_bin", "", "DEFAULT_GENERATED", "", "", nil}, {"medium_blob", "mediumblob", nil, nil, nil, nil, nil, "", "DEFAULT_GENERATED", "", "", nil}, {"medium_int", "mediumint", 7, 0, nil, nil, nil, "", "", "", "", nil}, {"medium_text", "mediumtext", nil, nil, nil, "utf8mb4", "utf8mb4_0900_bin", "", "DEFAULT_GENERATED", "", "", nil}, {"some_point", "point", nil, nil, nil, nil, nil, "", "DEFAULT_GENERATED", "", "", nil}, {"some_polygon", "polygon", nil, nil, nil, nil, nil, "", "", "", "", nil}, {"some_set", "set('one','two')", nil, nil, nil, "utf8mb4", "utf8mb4_0900_bin", "", "", "", "", nil}, {"small_int", "smallint", 5, 0, nil, nil, nil, "", "", "", "", nil}, {"some_text", "text", nil, nil, nil, "utf8mb4", "utf8mb4_0900_bin", "", "DEFAULT_GENERATED", "", "", nil}, {"time_6", "time(6)", nil, nil, 6, nil, nil, "", "", "", "", nil}, {"time_stamp", "timestamp(6)", nil, nil, 0, nil, nil, "", "DEFAULT_GENERATED", "", "", nil}, {"tiny_blob", "tinyblob", nil, nil, nil, nil, nil, "", "DEFAULT_GENERATED", "", "", nil}, {"tiny_int", "tinyint", 3, 0, nil, nil, nil, "", "", "", "", nil}, {"tiny_text", "tinytext", nil, nil, nil, "utf8mb4", "utf8mb4_0900_bin", "", "DEFAULT_GENERATED", "", "", nil}, {"var_char", "varchar(255)", nil, nil, nil, "utf8mb4", "utf8mb4_0900_bin", "", "", "", "", nil}, {"var_binary", "varbinary(255)", nil, nil, nil, nil, nil, "", "", "", "", nil}, {"some_year", "year", nil, nil, nil, nil, nil, "", "", "", "", nil}, }, }, }, }, { Name: "column specific tests on information_schema.tables table", SetUpScript: []string{ `create table bigtable (text varchar(20) primary key, number mediumint, pt point default (POINT(1,1)))`, `insert into bigtable values ('a',4,POINT(1,4)),('b',2,null),('c',0,null),('d',2,POINT(1, 2)),('e',2,POINT(1, 2))`, `create index bigtable_number on bigtable (number)`, `CREATE VIEW myview1 AS SELECT * FROM mytable`, `CREATE VIEW myview2 AS SELECT * FROM myview1 WHERE i = 1`, }, Assertions: []ScriptTestAssertion{ { Query: `SELECT table_catalog, table_schema, table_name, table_type, table_comment FROM information_schema.tables WHERE table_schema = 'mydb' and table_type IN ('VIEW') ORDER BY TABLE_NAME;`, Expected: []sql.Row{ {"def", "mydb", "myview", "VIEW", "VIEW"}, {"def", "mydb", "myview1", "VIEW", "VIEW"}, {"def", "mydb", "myview2", "VIEW", "VIEW"}, }, }, { Query: "SELECT table_rows as count FROM information_schema.TABLES WHERE TABLE_SCHEMA='mydb' AND TABLE_NAME='bigtable';", Expected: []sql.Row{ {uint64(5)}, }, }, }, }, { Name: "column specific tests on information_schema table, check and referential constraints", SetUpScript: []string{ `CREATE TABLE checks (a INTEGER PRIMARY KEY, b INTEGER, c varchar(20))`, `ALTER TABLE checks ADD CONSTRAINT chk1 CHECK (B > 0)`, `ALTER TABLE checks ADD CONSTRAINT chk2 CHECK (b > 0) NOT ENFORCED`, `ALTER TABLE checks ADD CONSTRAINT chk3 CHECK (B > 1)`, `ALTER TABLE checks ADD CONSTRAINT chk4 CHECK (upper(C) = c)`, `create table ptable (i int primary key, b blob, c char(10))`, `alter table ptable add index (c(3))`, `alter table ptable add unique index (b(4))`, `create index b_and_c on ptable (b(5), c(6))`, `ALTER TABLE ptable ADD CONSTRAINT ptable_checks FOREIGN KEY (i) REFERENCES checks(a)`, }, Assertions: []ScriptTestAssertion{ { Query: `SELECT TC.CONSTRAINT_NAME, CC.CHECK_CLAUSE, TC.ENFORCED FROM information_schema.TABLE_CONSTRAINTS TC, information_schema.CHECK_CONSTRAINTS CC WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'checks' AND TC.TABLE_SCHEMA = CC.CONSTRAINT_SCHEMA AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME AND TC.CONSTRAINT_TYPE = 'CHECK';`, Expected: []sql.Row{ {"chk1", "(B > 0)", "YES"}, {"chk2", "(b > 0)", "NO"}, {"chk3", "(B > 1)", "YES"}, {"chk4", "(upper(C) = c)", "YES"}, }, }, { Query: `select * from information_schema.table_constraints where table_schema = 'mydb' and table_name = 'checks';`, Expected: []sql.Row{ {"def", "mydb", "PRIMARY", "mydb", "checks", "PRIMARY KEY", "YES"}, {"def", "mydb", "chk1", "mydb", "checks", "CHECK", "YES"}, {"def", "mydb", "chk2", "mydb", "checks", "CHECK", "NO"}, {"def", "mydb", "chk3", "mydb", "checks", "CHECK", "YES"}, {"def", "mydb", "chk4", "mydb", "checks", "CHECK", "YES"}, }, }, { Query: `select * from information_schema.check_constraints where constraint_schema = 'mydb';`, Expected: []sql.Row{ {"def", "mydb", "chk1", "(B > 0)"}, {"def", "mydb", "chk2", "(b > 0)"}, {"def", "mydb", "chk3", "(B > 1)"}, {"def", "mydb", "chk4", "(upper(C) = c)"}, }, }, { Query: `select * from information_schema.table_constraints where table_schema = 'mydb' and table_name = 'ptable';`, Expected: []sql.Row{ {"def", "mydb", "PRIMARY", "mydb", "ptable", "PRIMARY KEY", "YES"}, {"def", "mydb", "b", "mydb", "ptable", "UNIQUE", "YES"}, {"def", "mydb", "ptable_checks", "mydb", "ptable", "FOREIGN KEY", "YES"}, }, }, }, }, { Name: "column specific tests on information_schema.routines table", SetUpScript: []string{ `CREATE DEFINER=root@localhost PROCEDURE count_i_from_mytable(OUT total_i INT) READS SQL DATA BEGIN SELECT SUM(i) FROM mytable INTO total_i; END ;`, }, Assertions: []ScriptTestAssertion{ { Query: `select specific_name, routine_catalog, routine_schema, routine_name, routine_type, data_type, routine_body, external_language, parameter_style, is_deterministic, sql_data_access, security_type, sql_mode, routine_comment, definer, character_set_client, collation_connection, database_collation from information_schema.routines where routine_schema = 'mydb' and routine_type like 'PROCEDURE' order by routine_name;`, Expected: []sql.Row{ {"count_i_from_mytable", "def", "mydb", "count_i_from_mytable", "PROCEDURE", "", "SQL", "SQL", "SQL", "NO", "READS SQL DATA", "DEFINER", "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY", "", "root@localhost", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}, }, }, { Query: `select routine_definition from information_schema.routines where routine_schema = 'mydb' and routine_type like 'PROCEDURE' order by routine_name;`, Expected: []sql.Row{ {"BEGIN\n SELECT SUM(i)\n FROM mytable\n INTO total_i;\nEND"}, }, }, }, }, { Name: "column specific tests on information_schema.tables table", SetUpScript: []string{ `create table bigtable (text varchar(20) primary key, number mediumint, pt point default (POINT(1,1)))`, `insert into bigtable values ('a',4,POINT(1,4)),('b',2,null),('c',0,null),('d',2,POINT(1, 2)),('e',2,POINT(1, 2))`, `create index bigtable_number on bigtable (number)`, `CREATE TABLE names (actor_id smallint PRIMARY KEY AUTO_INCREMENT, first_name varchar(45) NOT NULL);`, `INSERT INTO names (first_name) VALUES ('PENELOPE'), ('NICK'), ('JUNE');`, `CREATE VIEW myview1 AS SELECT * FROM myview WHERE i = 1`, }, Assertions: []ScriptTestAssertion{ { Query: `SELECT table_catalog, table_schema, table_name, table_type, engine, version, row_format, table_rows, auto_increment, table_collation, checksum, create_options, table_comment FROM information_schema.tables where table_schema = 'mydb' order by table_name`, Expected: []sql.Row{ {"def", "mydb", "bigtable", "BASE TABLE", "InnoDB", 10, "Dynamic", uint64(5), nil, "utf8mb4_0900_bin", nil, "", ""}, {"def", "mydb", "fk_tbl", "BASE TABLE", "InnoDB", 10, "Dynamic", uint64(0), nil, "utf8mb4_0900_bin", nil, "", ""}, {"def", "mydb", "mytable", "BASE TABLE", "InnoDB", 10, "Dynamic", uint64(3), nil, "utf8mb4_0900_bin", nil, "", ""}, {"def", "mydb", "myview", "VIEW", nil, nil, nil, nil, nil, nil, nil, nil, "VIEW"}, {"def", "mydb", "myview1", "VIEW", nil, nil, nil, nil, nil, nil, nil, nil, "VIEW"}, {"def", "mydb", "names", "BASE TABLE", "InnoDB", 10, "Dynamic", uint64(3), uint64(4), "utf8mb4_0900_bin", nil, "", ""}, }, }, { Query: "SELECT table_comment,table_rows,auto_increment FROM information_schema.tables WHERE TABLE_NAME = 'names' AND TABLE_SCHEMA = 'mydb';", Expected: []sql.Row{ {"", uint64(3), uint64(4)}, }, }, }, }, { Name: "information_schema.views has definer and security information", SetUpScript: []string{ "create view myview1 as select count(*) from mytable;", "CREATE ALGORITHM=TEMPTABLE DEFINER=UserName@localhost SQL SECURITY INVOKER VIEW myview2 AS SELECT * FROM myview WHERE i > 1;", }, Assertions: []ScriptTestAssertion{ { Query: "select * from information_schema.views where table_schema = 'mydb' order by table_name", Expected: []sql.Row{ {"def", "mydb", "myview", "SELECT * FROM mytable", "NONE", "YES", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"}, {"def", "mydb", "myview1", "select count(*) from mytable", "NONE", "NO", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"}, {"def", "mydb", "myview2", "SELECT * FROM myview WHERE i > 1", "NONE", "NO", "UserName@localhost", "INVOKER", "utf8mb4", "utf8mb4_0900_bin"}, }, }, }, }, { Name: "information_schema.schemata shows all column values", SetUpScript: []string{ "CREATE DATABASE mydb1 COLLATE latin1_general_ci;", "CREATE DATABASE mydb2 COLLATE utf8mb3_general_ci;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.schemata where schema_name like 'mydb%' order by schema_name", Expected: []sql.Row{ {"def", "mydb", "utf8mb4", "utf8mb4_0900_bin", nil, "NO"}, {"def", "mydb1", "latin1", "latin1_general_ci", nil, "NO"}, {"def", "mydb2", "utf8mb3", "utf8mb3_general_ci", nil, "NO"}, }, }, }, }, { Name: "information_schema.st_geometry_columns shows all column values", SetUpScript: []string{ "CREATE TABLE spatial_table (id INT PRIMARY KEY, g GEOMETRY SRID 0, m MULTIPOINT, p POLYGON SRID 4326);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.st_geometry_columns where table_schema = 'mydb' order by column_name", Expected: []sql.Row{ {"def", "mydb", "spatial_table", "g", "", uint32(0), "geometry"}, {"def", "mydb", "spatial_table", "m", nil, nil, "multipoint"}, {"def", "mydb", "spatial_table", "p", "WGS 84", uint32(4326), "polygon"}, }, }, }, }, { Name: "information_schema.parameters shows all column values", SetUpScript: []string{ "CREATE PROCEDURE testabc(IN x DOUBLE, IN y FLOAT, OUT abc DECIMAL(5,1)) SELECT x*y INTO abc", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.parameters where specific_name = 'testabc'", Expected: []sql.Row{ {"def", "mydb", "testabc", uint64(1), "IN", "x", "double", nil, nil, 22, 0, nil, nil, nil, "double", "PROCEDURE"}, {"def", "mydb", "testabc", uint64(2), "IN", "y", "float", nil, nil, 12, 0, nil, nil, nil, "float", "PROCEDURE"}, {"def", "mydb", "testabc", uint64(3), "OUT", "abc", "decimal", nil, nil, 5, 1, nil, nil, nil, "decimal(5,1)", "PROCEDURE"}, }, }, }, }, { Name: "information_schema.st_spatial_reference_systems can be modified", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "create or replace spatial reference system 1234 " + "organization 'test_org' identified by 1234 " + "definition 'test_definition' " + "description 'test_description'", ExpectedErrStr: "missing mandatory attribute NAME", }, { Query: "create or replace spatial reference system 1234 " + "name 'test_name' " + "definition 'test_definition' " + "description 'test_description'", ExpectedErrStr: "missing mandatory attribute ORGANIZATION NAME", }, { Query: "create or replace spatial reference system 1234 " + "name 'test_name' " + "organization 'test_org' identified by 1234 " + "description 'test_description'", ExpectedErrStr: "missing mandatory attribute DEFINITION", }, { Query: "create or replace spatial reference system 1234 " + "name ' test_name ' " + "definition 'test_definition' " + "organization 'test_org' identified by 1234 " + "description 'test_description'", ExpectedErrStr: "the spatial reference system name can't be an empty string or start or end with whitespace", }, { Query: "create or replace spatial reference system 1234 " + "name 'test_name' " + "definition 'test_definition' " + "organization ' test_org ' identified by 1234 " + "description 'test_description'", ExpectedErrStr: "the organization name can't be an empty string or start or end with whitespace", }, { Skip: true, Query: "create spatial reference system 1234 " + "name 'test_name' " + "organization 'test_org' identified by 1234 " + "definition 'test_definition' " + "description 'test_description'", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "create or replace spatial reference system 1234 " + "name 'test_name' " + "organization 'test_org' identified by 1234 " + "definition 'test_definition' " + "description 'test_description'", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "select srs_id, srs_name, organization, organization_coordsys_id, definition, description from information_schema.st_spatial_reference_systems where srs_id = 1234", Expected: []sql.Row{ {uint32(1234), "test_name", "test_org", uint32(1234), "test_definition", "test_description"}, }, }, { Query: "create spatial reference system if not exists 1234 " + "name 'new_test_name' " + "organization 'new_test_org' identified by 1234 " + "definition 'new_test_definition' " + "description 'new_test_description'", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "select srs_id, srs_name, organization, organization_coordsys_id, definition, description from information_schema.st_spatial_reference_systems where srs_id = 1234", Expected: []sql.Row{ {uint32(1234), "test_name", "test_org", uint32(1234), "test_definition", "test_description"}, }, }, }, }, }
var InsertBrokenScripts = []ScriptTest{ { Name: "Test that INSERT IGNORE works with FK Violations", SetUpScript: []string{ "CREATE TABLE t1 (id INT PRIMARY KEY, v int);", "CREATE TABLE t2 (id INT PRIMARY KEY, v2 int, CONSTRAINT mfk FOREIGN KEY (v2) REFERENCES t1(id));", "INSERT INTO t1 values (1,1)", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT IGNORE INTO t2 VALUES (1,2);", Expected: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, ExpectedWarning: mysql.ErNoReferencedRow2, }, }, }, { Name: "Test that INSERT IGNORE assigns the closest dataype correctly", SetUpScript: []string{ "CREATE TABLE x (pk int primary key, c1 varchar(20) NOT NULL);", `INSERT IGNORE INTO x VALUES (1, "one"), (2, TRUE), (3, "three")`, "CREATE TABLE y (pk int primary key, c1 int NOT NULL);", `INSERT IGNORE INTO y VALUES (1, 1), (2, "two"), (3,3);`, }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM x", Expected: []sql.Row{ {1, "one"}, {2, 1}, {3, "three"}, }, }, { Query: "SELECT * FROM y", Expected: []sql.Row{ {1, 1}, {2, 0}, {3, 3}, }, }, { Query: `INSERT IGNORE INTO y VALUES (4, "four")`, Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, ExpectedWarning: mysql.ERTruncatedWrongValueForField, }, }, }, }
var InsertDuplicateKeyKeyless = []ScriptTest{ { Name: "insert on duplicate key for keyless table", SetUpScript: []string{ `create table t (i int unique, j varchar(128))`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into t values (0, "first")`, Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: `insert into t values (0, "second") on duplicate key update j = "third"`, Expected: []sql.Row{ {types.NewOkResult(2)}, }, }, { Query: `select i, j from t order by i`, Expected: []sql.Row{ {0, "third"}, }, }, }, }, { Name: "insert on duplicate key for keyless table multiple unique columns", SetUpScript: []string{ `create table t (c1 int, c2 int, c3 int, unique key(c1,c2))`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into t(c1, c2, c3) values (0, 0, 0) on duplicate key update c3 = 0`, Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: `select c1, c2, c3 from t order by c1`, Expected: []sql.Row{ {0, 0, 0}, }, }, { Query: `insert into t(c1, c2, c3) values (0, 0, 1) on duplicate key update c3 = 0`, Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: `select c1, c2, c3 from t order by c1`, Expected: []sql.Row{ {0, 0, 0}, }, }, { Query: `insert into t(c1, c2, c3) values (0, 0, 0) on duplicate key update c3 = 1`, Expected: []sql.Row{ {types.NewOkResult(2)}, }, }, { Query: `select c1, c2, c3 from t order by c1`, Expected: []sql.Row{ {0, 0, 1}, }, }, }, }, { Name: "insert on duplicate key for keyless tables with nulls", SetUpScript: []string{ `create table t (c1 int, c2 int, c3 int, unique key(c1, c2))`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into t(c1, c2, c3) values (0, null, 0) on duplicate key update c3 = 0`, Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: `select c1, c2, c3 from t order by c1`, Expected: []sql.Row{ {0, nil, 0}, }, }, { Query: `insert into t(c1, c2, c3) values (0, null, 1) on duplicate key update c3 = 0`, Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: `select c1, c2, c3 from t order by c1, c2, c3`, Expected: []sql.Row{ {0, nil, 0}, {0, nil, 1}, }, }, { Query: `insert into t(c1, c2, c3) values (0, null, 0) on duplicate key update c3 = 1`, Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: `select c1, c2, c3 from t order by c1, c2, c3`, Expected: []sql.Row{ {0, nil, 0}, {0, nil, 0}, {0, nil, 1}, }, }, { Query: `insert into t(c1, c2, c3) values (0, 0, 0) on duplicate key update c3 = null`, Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: `select c1, c2, c3 from t order by c1, c2, c3`, Expected: []sql.Row{ {0, nil, 0}, {0, nil, 0}, {0, nil, 1}, {0, 0, 0}, }, }, { Query: `insert into t(c1, c2, c3) values (0, 0, 0) on duplicate key update c3 = null`, Expected: []sql.Row{ {types.NewOkResult(2)}, }, }, { Query: `select c1, c2, c3 from t order by c1, c2, c3`, Expected: []sql.Row{ {0, nil, 0}, {0, nil, 0}, {0, nil, 1}, {0, 0, nil}, }, }, }, }, { Name: "insert on duplicate key for keyless table mixed ordering", SetUpScript: []string{ `create table t (c1 int, c2 int, c3 int, unique key(c2, c1))`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into t(c1, c2, c3) values (0, 0, 0) on duplicate key update c3 = 0`, Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: `select c1, c2, c3 from t order by c1`, Expected: []sql.Row{ {0, 0, 0}, }, }, { Query: `insert into t(c1, c2, c3) values (0, 0, 1) on duplicate key update c3 = 0`, Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: `select c1, c2, c3 from t order by c1`, Expected: []sql.Row{ {0, 0, 0}, }, }, { Query: `insert into t(c1, c2, c3) values (0, 0, 0) on duplicate key update c3 = 1`, Expected: []sql.Row{ {types.NewOkResult(2)}, }, }, { Query: `select c1, c2, c3 from t order by c1`, Expected: []sql.Row{ {0, 0, 1}, }, }, }, }, { Name: "insert on duplicate key for keyless table multiple unique columns batched", SetUpScript: []string{ `create table t (c1 int, c2 int, c3 int, unique key(c1,c2))`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into t(c1, c2, c3) values (0, 0, 0), (0, 0, 0), (0, 0, 1), (0, 0, 1) on duplicate key update c3 = 1`, Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: `select c1, c2, c3 from t order by c1, c2, c3`, Expected: []sql.Row{ {0, 0, 1}, }, }, { Query: `insert into t(c1, c2, c3) values (0, 0, 1), (0, 0, 2), (0, 0, 3), (0, 0, 4) on duplicate key update c3 = 100`, Expected: []sql.Row{ {types.NewOkResult(2)}, }, }, { Query: `select c1, c2, c3 from t order by c1, c2, c3`, Expected: []sql.Row{ {0, 0, 100}, }, }, { Query: `insert into t(c1, c2, c3) values (0, 0, 1), (0, 1, 1), (0, 2, 2), (0, 3, 3) on duplicate key update c3 = 200`, Expected: []sql.Row{ {types.NewOkResult(5)}, }, }, { Query: `select c1, c2, c3 from t order by c1, c2, c3`, Expected: []sql.Row{ {0, 0, 200}, {0, 1, 1}, {0, 2, 2}, {0, 3, 3}, }, }, }, }, }
var InsertErrorScripts = []ScriptTest{ { Name: "create table with non-pk auto_increment column", Query: "create table bad (pk int primary key, c0 int auto_increment);", ExpectedErr: sql.ErrInvalidAutoIncCols, }, { Name: "create multiple auto_increment columns", Query: "create table bad (pk1 int auto_increment, pk2 int auto_increment, primary key (pk1,pk2));", ExpectedErr: sql.ErrInvalidAutoIncCols, }, { Name: "create auto_increment column with default", Query: "create table bad (pk1 int auto_increment default 10, c0 int);", ExpectedErr: sql.ErrInvalidAutoIncCols, }, { Name: "try inserting string that is too long", SetUpScript: []string{ "create table bad (s varchar(9))", }, Query: "insert into bad values ('1234567890')", ExpectedErr: types.ErrLengthBeyondLimit, }, { Name: "try inserting varbinary larger than max limit", SetUpScript: []string{ "create table bad (vb varbinary(65535))", }, Query: "insert into bad values (repeat('0', 65536))", ExpectedErr: types.ErrLengthBeyondLimit, }, }
var InsertErrorTests = []GenericErrorQueryTest{
{
Name: "try to insert empty into col without default value",
Query: "INSERT INTO mytable VALUES ();",
},
{
Name: "try to insert empty into col without default value",
Query: "INSERT INTO mytable () VALUES ();",
},
{
Name: "too few values",
Query: "INSERT INTO mytable (s, i) VALUES ('x');",
},
{
Name: "too many values one column",
Query: "INSERT INTO mytable (s) VALUES ('x', 999);",
},
{
Name: "missing binding",
Query: "INSERT INTO mytable (s) VALUES (?);",
},
{
Name: "too many values two columns",
Query: "INSERT INTO mytable (i, s) VALUES (999, 'x', 'y');",
},
{
Name: "too few values no columns specified",
Query: "INSERT INTO mytable VALUES (999);",
},
{
Name: "too many values no columns specified",
Query: "INSERT INTO mytable VALUES (999, 'x', 'y');",
},
{
Name: "non-existent column values",
Query: "INSERT INTO mytable (i, s, z) VALUES (999, 'x', 999);",
},
{
Name: "non-existent column set",
Query: "INSERT INTO mytable SET i = 999, s = 'x', z = 999;",
},
{
Name: "duplicate column",
Query: "INSERT INTO mytable (i, s, s) VALUES (999, 'x', 'x');",
},
{
Name: "duplicate column set",
Query: "INSERT INTO mytable SET i = 999, s = 'y', s = 'y';",
},
{
Name: "null given to non-nullable",
Query: "INSERT INTO mytable (i, s) VALUES (null, 'y');",
},
{
Name: "incompatible types",
Query: "INSERT INTO mytable (i, s) select * FROM othertable",
},
{
Name: "column count mismatch in select",
Query: "INSERT INTO mytable (i) select * FROM othertable",
},
{
Name: "column count mismatch in select",
Query: "INSERT INTO mytable select s FROM othertable",
},
{
Name: "column count mismatch in join select",
Query: "INSERT INTO mytable (s,i) SELECT * FROM othertable o JOIN mytable m ON m.i=o.i2",
},
{
Name: "duplicate key",
Query: "INSERT INTO mytable (i,s) values (1, 'hello')",
},
{
Name: "duplicate keys",
Query: "INSERT INTO mytable SELECT * from mytable",
},
{
Name: "bad column in on duplicate key update clause",
Query: "INSERT INTO mytable values (10, 'b') ON DUPLICATE KEY UPDATE notExist = 1",
},
}
var InsertIgnoreScripts = []ScriptTest{ { Name: "Test that INSERT IGNORE with Non nullable columns works", SetUpScript: []string{ "CREATE TABLE x (pk int primary key, c1 varchar(20) NOT NULL);", "INSERT IGNORE INTO x VALUES (1, NULL)", "CREATE TABLE y (pk int primary key, c1 int NOT NULL);", "INSERT IGNORE INTO y VALUES (1, NULL);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM x", Expected: []sql.Row{ {1, ""}, }, }, { Query: "SELECT * FROM y", Expected: []sql.Row{ {1, 0}, }, }, { Query: "INSERT IGNORE INTO y VALUES (2, NULL)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, ExpectedWarning: mysql.ERBadNullError, }, }, }, { Name: "Test that INSERT IGNORE properly addresses data conversion", SetUpScript: []string{ "CREATE TABLE t1 (pk int primary key, v1 int)", "CREATE TABLE t2 (pk int primary key, v2 varchar(1))", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT IGNORE INTO t1 VALUES (1, 'dasd')", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, ExpectedWarning: mysql.ERTruncatedWrongValueForField, }, { Query: "SELECT * FROM t1", Expected: []sql.Row{ {1, 0}, }, }, { Query: "INSERT IGNORE INTO t2 values (1, 'adsda')", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, ExpectedWarning: mysql.ERUnknownError, }, { Query: "SELECT * FROM t2", Expected: []sql.Row{ {1, "a"}, }, }, }, }, { Name: "Insert Ignore works correctly with ON DUPLICATE UPDATE", SetUpScript: []string{ "CREATE TABLE t1 (id INT PRIMARY KEY, v int);", "INSERT INTO t1 VALUES (1,1)", "CREATE TABLE t2 (pk int primary key, v2 varchar(1))", "ALTER TABLE t2 ADD CONSTRAINT cx CHECK (pk < 100)", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT IGNORE INTO t1 VALUES (1,2) ON DUPLICATE KEY UPDATE v='dsd';", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, ExpectedWarning: mysql.ERTruncatedWrongValueForField, }, { Query: "SELECT * FROM t1", Expected: []sql.Row{ {1, 0}, }, }, { Query: "INSERT IGNORE INTO t2 values (1, 'adsda')", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, ExpectedWarning: mysql.ERUnknownError, }, { Query: "SELECT * FROM t2", Expected: []sql.Row{ {1, "a"}, }, }, { Query: "INSERT IGNORE INTO t2 VALUES (1, 's') ON DUPLICATE KEY UPDATE pk = 1000", Expected: []sql.Row{{types.OkResult{RowsAffected: 0}}}, }, { Query: "SELECT * FROM t2", Expected: []sql.Row{ {1, "a"}, }, }, }, }, { Name: "Test that INSERT IGNORE INTO works with unique keys", SetUpScript: []string{ "CREATE TABLE one_uniq(pk int PRIMARY KEY, col1 int UNIQUE)", "CREATE TABLE two_uniq(pk int PRIMARY KEY, col1 int, col2 int, UNIQUE KEY col1_col2_uniq (col1, col2))", "INSERT INTO one_uniq values (1, 1)", "INSERT INTO two_uniq values (1, 1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT IGNORE INTO one_uniq VALUES (3, 2), (2, 1), (4, null), (5, null)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3}}, }, ExpectedWarning: mysql.ERDupEntry, }, { Query: "SELECT * from one_uniq;", Expected: []sql.Row{ {1, 1}, {3, 2}, {4, nil}, {5, nil}, }, }, { Query: "INSERT IGNORE INTO two_uniq VALUES (4, 1, 2), (5, 2, 1), (6, null, 1), (7, null, 1), (12, 1, 1), (8, 1, null), (9, 1, null), (10, null, null), (11, null, null)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 8}}, }, ExpectedWarning: mysql.ERDupEntry, }, { Query: "SELECT * from two_uniq;", Expected: []sql.Row{ {1, 1, 1}, {4, 1, 2}, {5, 2, 1}, {6, nil, 1}, {7, nil, 1}, {8, 1, nil}, {9, 1, nil}, {10, nil, nil}, {11, nil, nil}, }, }, }, }, }
var InsertQueries = []WriteQueryTest{ { WriteQuery: "INSERT INTO keyless VALUES ();", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM keyless WHERE c0 IS NULL;", ExpectedSelect: []sql.Row{{nil, nil}}, }, { WriteQuery: "INSERT INTO keyless () VALUES ();", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM keyless WHERE c0 IS NULL;", ExpectedSelect: []sql.Row{{nil, nil}}, }, { WriteQuery: "INSERT INTO mytable (s, i) VALUES ('x', '10.0');", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT i FROM mytable WHERE s = 'x';", ExpectedSelect: []sql.Row{{int64(10)}}, }, { WriteQuery: "INSERT INTO mytable (s, i) VALUES ('x', '64.6');", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT i FROM mytable WHERE s = 'x';", ExpectedSelect: []sql.Row{{int64(64)}}, }, { WriteQuery: "INSERT INTO mytable (s, i) VALUES ('x', 999);", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT i FROM mytable WHERE s = 'x';", ExpectedSelect: []sql.Row{{int64(999)}}, }, { WriteQuery: "INSERT INTO niltable (i, f) VALUES (10, 10.0), (12, 12.0);", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT i,f FROM niltable WHERE f IN (10.0, 12.0) ORDER BY f;", ExpectedSelect: []sql.Row{{int64(10), 10.0}, {int64(12), 12.0}}, }, { WriteQuery: "INSERT INTO mytable SET s = 'x', i = 999;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT i FROM mytable WHERE s = 'x';", ExpectedSelect: []sql.Row{{int64(999)}}, }, { WriteQuery: "INSERT INTO mytable VALUES (999, 'x');", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT i FROM mytable WHERE s = 'x';", ExpectedSelect: []sql.Row{{int64(999)}}, }, { WriteQuery: "INSERT INTO mytable SET i = 999, s = 'x';", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT i FROM mytable WHERE s = 'x';", ExpectedSelect: []sql.Row{{int64(999)}}, }, { WriteQuery: "INSERT INTO mytable VALUES (999, _binary 'x');", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT s FROM mytable WHERE i = 999;", ExpectedSelect: []sql.Row{{"x"}}, }, { WriteQuery: "INSERT INTO mytable SET i = 999, s = _binary 'x';", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT s FROM mytable WHERE i = 999;", ExpectedSelect: []sql.Row{{"x"}}, }, { WriteQuery: `INSERT INTO typestable VALUES ( 999, 127, 32767, 2147483647, 9223372036854775807, 255, 65535, 4294967295, 18446744073709551615, 3.40282346638528859811704183484516925440e+38, 1.797693134862315708145274237317043567981e+308, '2037-04-05 12:51:36', '2231-11-07', 'random text', true, '{"key":"value"}', 'blobdata', 'v1', 'v2' );`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{ int64(999), int8(math.MaxInt8), int16(math.MaxInt16), int32(math.MaxInt32), int64(math.MaxInt64), uint8(math.MaxUint8), uint16(math.MaxUint16), uint32(math.MaxUint32), uint64(math.MaxUint64), float32(math.MaxFloat32), float64(math.MaxFloat64), sql.MustConvert(types.Timestamp.Convert("2037-04-05 12:51:36")), sql.MustConvert(types.Date.Convert("2231-11-07")), "random text", sql.True, types.MustJSON(`{"key":"value"}`), []byte("blobdata"), uint(2), uint(4), }}, }, { WriteQuery: `INSERT INTO typestable SET id = 999, i8 = 127, i16 = 32767, i32 = 2147483647, i64 = 9223372036854775807, u8 = 255, u16 = 65535, u32 = 4294967295, u64 = 18446744073709551615, f32 = 3.40282346638528859811704183484516925440e+38, f64 = 1.797693134862315708145274237317043567981e+308, ti = '2037-04-05 12:51:36', da = '2231-11-07', te = 'random text', bo = true, js = '{"key":"value"}', bl = 'blobdata', e1 = 'v1', s1 = 'v2' ;`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{ int64(999), int8(math.MaxInt8), int16(math.MaxInt16), int32(math.MaxInt32), int64(math.MaxInt64), uint8(math.MaxUint8), uint16(math.MaxUint16), uint32(math.MaxUint32), uint64(math.MaxUint64), float32(math.MaxFloat32), float64(math.MaxFloat64), sql.MustConvert(types.Timestamp.Convert("2037-04-05 12:51:36")), sql.MustConvert(types.Date.Convert("2231-11-07")), "random text", sql.True, types.MustJSON(`{"key":"value"}`), []byte("blobdata"), uint(2), uint(4), }}, }, { WriteQuery: `INSERT INTO typestable VALUES ( 999, -128, -32768, -2147483648, -9223372036854775808, 0, 0, 0, 0, 1.401298464324817070923729583289916131280e-45, 4.940656458412465441765687928682213723651e-324, '0000-00-00 00:00:00', '0000-00-00', '', false, '""', '', '', '' );`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{ int64(999), int8(-math.MaxInt8 - 1), int16(-math.MaxInt16 - 1), int32(-math.MaxInt32 - 1), int64(-math.MaxInt64 - 1), uint8(0), uint16(0), uint32(0), uint64(0), float32(math.SmallestNonzeroFloat32), float64(math.SmallestNonzeroFloat64), types.Timestamp.Zero(), types.Date.Zero(), "", sql.False, types.MustJSON(`""`), []byte(""), uint(1), uint(0), }}, }, { WriteQuery: `INSERT INTO typestable SET id = 999, i8 = -128, i16 = -32768, i32 = -2147483648, i64 = -9223372036854775808, u8 = 0, u16 = 0, u32 = 0, u64 = 0, f32 = 1.401298464324817070923729583289916131280e-45, f64 = 4.940656458412465441765687928682213723651e-324, ti = '0000-00-00 00:00:00', da = '0000-00-00', te = '', bo = false, js = '""', bl = '', e1 = 'v1', s1 = 'v2' ;`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{ int64(999), int8(-math.MaxInt8 - 1), int16(-math.MaxInt16 - 1), int32(-math.MaxInt32 - 1), int64(-math.MaxInt64 - 1), uint8(0), uint16(0), uint32(0), uint64(0), float32(math.SmallestNonzeroFloat32), float64(math.SmallestNonzeroFloat64), types.Timestamp.Zero(), types.Date.Zero(), "", sql.False, types.MustJSON(`""`), []byte(""), uint(2), uint(4), }}, }, { WriteQuery: `INSERT INTO typestable SET id = 999, i8 = -128, i16 = -32768, i32 = -2147483648, i64 = -9223372036854775808, u8 = 0, u16 = 0, u32 = 0, u64 = 0, f32 = 1.401298464324817070923729583289916131280e-45, f64 = 4.940656458412465441765687928682213723651e-324, ti = '2037-04-05 12:51:36 -0000 UTC', da = '0000-00-00', te = '', bo = false, js = '""', bl = '', e1 = 'v1', s1 = 'v2' ;`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{ int64(999), int8(-math.MaxInt8 - 1), int16(-math.MaxInt16 - 1), int32(-math.MaxInt32 - 1), int64(-math.MaxInt64 - 1), uint8(0), uint16(0), uint32(0), uint64(0), float32(math.SmallestNonzeroFloat32), float64(math.SmallestNonzeroFloat64), sql.MustConvert(types.Timestamp.Convert("2037-04-05 12:51:36")), types.Date.Zero(), "", sql.False, types.MustJSON(`""`), []byte(""), uint(2), uint(4), }}, }, { WriteQuery: `INSERT INTO mytable (i,s) VALUES (10, 'NULL')`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM mytable WHERE i = 10;", ExpectedSelect: []sql.Row{{int64(10), "NULL"}}, }, { WriteQuery: `INSERT INTO typestable VALUES (999, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{int64(999), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}}, }, { WriteQuery: `INSERT INTO typestable (id, ti, da) VALUES (999, '2021-09-1', '2021-9-01');`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT id, ti, da FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{int64(999), sql.MustConvert(types.Timestamp.Convert("2021-09-01")), sql.MustConvert(types.Date.Convert("2021-09-01"))}}, }, { WriteQuery: `INSERT INTO typestable SET id=999, i8=null, i16=null, i32=null, i64=null, u8=null, u16=null, u32=null, u64=null, f32=null, f64=null, ti=null, da=null, te=null, bo=null, js=null, bl=null, e1=null, s1=null;`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{int64(999), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}}, }, { WriteQuery: "INSERT INTO mytable SELECT i+100,s FROM mytable", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM mytable ORDER BY i", ExpectedSelect: []sql.Row{ {int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}, {int64(101), "first row"}, {int64(102), "second row"}, {int64(103), "third row"}, }, }, { WriteQuery: "INSERT INTO emptytable SELECT * FROM mytable", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM emptytable ORDER BY i", ExpectedSelect: []sql.Row{ {int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}, }, }, { WriteQuery: "INSERT INTO emptytable SELECT * FROM mytable where mytable.i > 2", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM emptytable ORDER BY i", ExpectedSelect: []sql.Row{ {int64(3), "third row"}, }, }, { WriteQuery: "INSERT INTO niltable (i,f) SELECT i+10, NULL FROM mytable where mytable.i > 2", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM niltable where i > 10 ORDER BY i", ExpectedSelect: []sql.Row{ {13, nil, nil, nil}, }, }, { WriteQuery: "INSERT INTO mytable (i,s) SELECT i+10, 'new' FROM mytable", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM mytable ORDER BY i", ExpectedSelect: []sql.Row{ {int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}, {int64(11), "new"}, {int64(12), "new"}, {int64(13), "new"}, }, }, { WriteQuery: "INSERT INTO mytable SELECT i2+100, s2 FROM othertable", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM mytable ORDER BY i,s", ExpectedSelect: []sql.Row{ {int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}, {int64(101), "third"}, {int64(102), "second"}, {int64(103), "first"}, }, }, { WriteQuery: "INSERT INTO emptytable (s,i) SELECT * FROM othertable", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM emptytable ORDER BY i,s", ExpectedSelect: []sql.Row{ {int64(1), "third"}, {int64(2), "second"}, {int64(3), "first"}, }, }, { WriteQuery: "INSERT INTO emptytable (s,i) SELECT concat(m.s, o.s2), m.i FROM othertable o JOIN mytable m ON m.i=o.i2", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM emptytable ORDER BY i,s", ExpectedSelect: []sql.Row{ {int64(1), "first rowthird"}, {int64(2), "second rowsecond"}, {int64(3), "third rowfirst"}, }, }, { WriteQuery: `INSERT INTO emptytable (s,i) SELECT s,i from mytable where i = 1 union select s,i from mytable where i = 3`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM emptytable ORDER BY i,s", ExpectedSelect: []sql.Row{ {int64(1), "first row"}, {int64(3), "third row"}, }, }, { WriteQuery: `INSERT INTO emptytable (s,i) SELECT s,i from mytable where i = 1 union select s,i from mytable where i = 3 union select s,i from mytable where i > 2`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM emptytable ORDER BY i,s", ExpectedSelect: []sql.Row{ {int64(1), "first row"}, {int64(3), "third row"}, }, }, { WriteQuery: `INSERT INTO emptytable (s,i) SELECT s,i from mytable where i = 1 union all select s,i+1 from mytable where i < 2 union all select s,i+2 from mytable where i in (1)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM emptytable ORDER BY i,s", ExpectedSelect: []sql.Row{ {int64(1), "first row"}, {int64(2), "first row"}, {int64(3), "first row"}, }, }, { WriteQuery: "INSERT INTO emptytable (s,i) SELECT distinct s,i from mytable", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM emptytable ORDER BY i,s", ExpectedSelect: []sql.Row{ {int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}, }, }, { WriteQuery: "INSERT INTO mytable (i,s) SELECT (i + 10.0) / 10.0 + 10 + i, concat(s, ' new') FROM mytable", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM mytable ORDER BY i, s", ExpectedSelect: []sql.Row{ {int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}, {int64(12), "first row new"}, {int64(13), "second row new"}, {int64(14), "third row new"}, }, }, { WriteQuery: "INSERT INTO mytable (i,s) SELECT CHAR_LENGTH(s), concat('numrows: ', count(*)) from mytable group by 1", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable ORDER BY i, s", ExpectedSelect: []sql.Row{ {1, "first row"}, {2, "second row"}, {3, "third row"}, {9, "numrows: 2"}, {10, "numrows: 1"}, }, }, { WriteQuery: "INSERT INTO mytable (i,s) SELECT CHAR_LENGTH(s), concat('numrows: ', count(*)) from mytable group by 1 HAVING CHAR_LENGTH(s) > 9", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM mytable ORDER BY i, s", ExpectedSelect: []sql.Row{ {1, "first row"}, {2, "second row"}, {3, "third row"}, {10, "numrows: 1"}, }, }, { WriteQuery: "INSERT INTO mytable (i,s) SELECT i * 2, concat(s,s) from mytable order by 1 desc limit 1", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM mytable ORDER BY i, s", ExpectedSelect: []sql.Row{ {1, "first row"}, {2, "second row"}, {3, "third row"}, {6, "third rowthird row"}, }, }, { WriteQuery: "INSERT INTO mytable (i,s) SELECT i + 3, concat(s,s) from mytable order by 1 desc", ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM mytable ORDER BY i, s", ExpectedSelect: []sql.Row{ {1, "first row"}, {2, "second row"}, {3, "third row"}, {4, "first rowfirst row"}, {5, "second rowsecond row"}, {6, "third rowthird row"}, }, }, { WriteQuery: `INSERT INTO mytable (i,s) SELECT sub.i + 10, ot.s2 FROM othertable ot INNER JOIN (SELECT i, i2, s2 FROM mytable INNER JOIN othertable ON i = i2) sub ON sub.i = ot.i2 order by 1`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM mytable where i > 10 ORDER BY i, s", ExpectedSelect: []sql.Row{ {11, "third"}, {12, "second"}, {13, "first"}, }, }, { WriteQuery: `INSERT INTO mytable (i,s) SELECT sub.i + 10, ot.s2 FROM (SELECT i, i2, s2 FROM mytable INNER JOIN othertable ON i = i2) sub INNER JOIN othertable ot ON sub.i = ot.i2 order by 1`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(3)}}, SelectQuery: "SELECT * FROM mytable where i > 10 ORDER BY i, s", ExpectedSelect: []sql.Row{ {11, "third"}, {12, "second"}, {13, "first"}, }, }, { WriteQuery: "INSERT INTO mytable (i,s) values (1, 'hello') ON DUPLICATE KEY UPDATE s='hello'", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable WHERE i = 1", ExpectedSelect: []sql.Row{{int64(1), "hello"}}, }, { WriteQuery: "INSERT INTO mytable (i,s) values (1, 'hello2') ON DUPLICATE KEY UPDATE s='hello3'", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable WHERE i = 1", ExpectedSelect: []sql.Row{{int64(1), "hello3"}}, }, { WriteQuery: "INSERT INTO mytable (i,s) values (1, 'hello') ON DUPLICATE KEY UPDATE i=10", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable WHERE i = 10", ExpectedSelect: []sql.Row{{int64(10), "first row"}}, }, { WriteQuery: "INSERT INTO mytable (i,s) values (1, 'hello2') ON DUPLICATE KEY UPDATE s='hello3'", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable WHERE i = 1", ExpectedSelect: []sql.Row{{int64(1), "hello3"}}, }, { WriteQuery: "INSERT INTO mytable (i,s) values (1, 'hello2'), (2, 'hello3'), (4, 'no conflict') ON DUPLICATE KEY UPDATE s='hello4'", ExpectedWriteResult: []sql.Row{{types.NewOkResult(5)}}, SelectQuery: "SELECT * FROM mytable ORDER BY 1", ExpectedSelect: []sql.Row{ {1, "hello4"}, {2, "hello4"}, {3, "third row"}, {4, "no conflict"}, }, }, { WriteQuery: "INSERT INTO mytable (i,s) values (10, 'hello') ON DUPLICATE KEY UPDATE s='hello'", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM mytable ORDER BY 1", ExpectedSelect: []sql.Row{ {1, "first row"}, {2, "second row"}, {3, "third row"}, {10, "hello"}, }, }, { WriteQuery: "INSERT INTO mytable (i,s) values (1,'hi') ON DUPLICATE KEY UPDATE s=VALUES(s)", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable WHERE i = 1", ExpectedSelect: []sql.Row{{int64(1), "hi"}}, }, { WriteQuery: "INSERT INTO mytable (s,i) values ('dup',1) ON DUPLICATE KEY UPDATE s=CONCAT(VALUES(s), 'licate')", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable WHERE i = 1", ExpectedSelect: []sql.Row{{int64(1), "duplicate"}}, }, { WriteQuery: "INSERT INTO mytable (i,s) values (1,'mar'), (2,'par') ON DUPLICATE KEY UPDATE s=CONCAT(VALUES(s), 'tial')", ExpectedWriteResult: []sql.Row{{types.NewOkResult(4)}}, SelectQuery: "SELECT * FROM mytable WHERE i IN (1,2) ORDER BY i", ExpectedSelect: []sql.Row{{int64(1), "martial"}, {int64(2), "partial"}}, }, { WriteQuery: "INSERT INTO mytable (i,s) values (1,'maybe') ON DUPLICATE KEY UPDATE i=VALUES(i)+8000, s=VALUES(s)", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable WHERE i = 8001", ExpectedSelect: []sql.Row{{int64(8001), "maybe"}}, }, { WriteQuery: "INSERT INTO auto_increment_tbl (c0) values (44)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 4}}}, SelectQuery: "SELECT * FROM auto_increment_tbl ORDER BY pk", ExpectedSelect: []sql.Row{ {1, 11}, {2, 22}, {3, 33}, {4, 44}, }, }, { WriteQuery: "INSERT INTO auto_increment_tbl (c0) values (44),(55)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 4}}}, SelectQuery: "SELECT * FROM auto_increment_tbl ORDER BY pk", ExpectedSelect: []sql.Row{ {1, 11}, {2, 22}, {3, 33}, {4, 44}, {5, 55}, }, }, { WriteQuery: "INSERT INTO auto_increment_tbl values (NULL, 44)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 4}}}, SelectQuery: "SELECT * FROM auto_increment_tbl ORDER BY pk", ExpectedSelect: []sql.Row{ {1, 11}, {2, 22}, {3, 33}, {4, 44}, }, }, { WriteQuery: "INSERT INTO auto_increment_tbl values (0, 44)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 4}}}, SelectQuery: "SELECT * FROM auto_increment_tbl ORDER BY pk", ExpectedSelect: []sql.Row{ {1, 11}, {2, 22}, {3, 33}, {4, 44}, }, }, { WriteQuery: "INSERT INTO auto_increment_tbl values (5, 44)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 5}}}, SelectQuery: "SELECT * FROM auto_increment_tbl ORDER BY pk", ExpectedSelect: []sql.Row{ {1, 11}, {2, 22}, {3, 33}, {5, 44}, }, }, { WriteQuery: "INSERT INTO auto_increment_tbl values " + "(NULL, 44), (NULL, 55), (9, 99), (NULL, 110), (NULL, 121)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 5, InsertID: 4}}}, SelectQuery: "SELECT * FROM auto_increment_tbl ORDER BY pk", ExpectedSelect: []sql.Row{ {1, 11}, {2, 22}, {3, 33}, {4, 44}, {5, 55}, {9, 99}, {10, 110}, {11, 121}, }, }, { WriteQuery: `INSERT INTO auto_increment_tbl (c0) SELECT 44 FROM dual`, ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 4}}}, SelectQuery: "SELECT * FROM auto_increment_tbl", ExpectedSelect: []sql.Row{ {1, 11}, {2, 22}, {3, 33}, {4, 44}, }, }, { WriteQuery: `INSERT INTO othertable VALUES ("fourth", 1) ON DUPLICATE KEY UPDATE s2="fourth"`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM othertable", ExpectedSelect: []sql.Row{ sql.NewRow("first", int64(3)), sql.NewRow("second", int64(2)), sql.NewRow("fourth", int64(1)), }, }, { WriteQuery: `INSERT INTO othertable(S2,I2) values ('fourth',0)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: `SELECT * FROM othertable where s2='fourth'`, ExpectedSelect: []sql.Row{ {"fourth", 0}, }, }, { WriteQuery: `INSERT INTO auto_increment_tbl VALUES ('4', 44)`, ExpectedWriteResult: []sql.Row{ {types.OkResult{InsertID: 4, RowsAffected: 1}}, }, SelectQuery: `SELECT * from auto_increment_tbl where pk=4`, ExpectedSelect: []sql.Row{ {4, 44}, }, }, { WriteQuery: `INSERT INTO keyless (c0, c1) SELECT * from keyless where c0=0 and c1=0`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: `SELECT * from keyless where c0=0`, ExpectedSelect: []sql.Row{ {0, 0}, {0, 0}, }, }, { WriteQuery: `insert into keyless (c0, c1) select a.c0, a.c1 from (select 1, 1) as a(c0, c1) join keyless on a.c0 = keyless.c0`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: `SELECT * from keyless where c0=1`, ExpectedSelect: []sql.Row{ {1, 1}, {1, 1}, {1, 1}, {1, 1}, }, }, { WriteQuery: "with t (i,f) as (select 4,'fourth row' from dual) insert into mytable select i,f from t", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1}}}, SelectQuery: "select * from mytable order by i", ExpectedSelect: []sql.Row{ sql.NewRow(1, "first row"), sql.NewRow(2, "second row"), sql.NewRow(3, "third row"), sql.NewRow(4, "fourth row"), }, }, { WriteQuery: "with recursive t (i,f) as (select 4,4 from dual union all select i + 1, i + 1 from t where i < 5) insert into mytable select i,f from t", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 2}}}, SelectQuery: "select * from mytable order by i", ExpectedSelect: []sql.Row{ sql.NewRow(1, "first row"), sql.NewRow(2, "second row"), sql.NewRow(3, "third row"), sql.NewRow(4, "4"), sql.NewRow(5, "5"), }, }, }
var InsertScripts = []ScriptTest{ { Name: "issue 4857: insert cte column alias with table alias qualify panic", SetUpScript: []string{ "create table xy (x int primary key, y int)", "insert into xy values (0,0), (1,1), (2,2)", }, Assertions: []ScriptTestAssertion{ { Query: `With a as ( With b as ( Select sum(x) as x, y from xy where x < 2 group by y ) Select * from b d ) insert into xy (x,y) select x+9,y+9 from a;`, Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 0}}}, }, }, }, { Name: "INSERT zero date DATETIME NOT NULL is valid", SetUpScript: []string{ "CREATE TABLE t1 (dt datetime not null)", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO t1 (dt) VALUES ('0001-01-01 00:00:00');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, }, }, { Name: "insert into sparse auto_increment table", SetUpScript: []string{ "create table auto (pk int primary key auto_increment)", "insert into auto values (10), (20), (30)", "insert into auto values (NULL)", "insert into auto values (40)", "insert into auto values (0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {10}, {20}, {30}, {31}, {40}, {41}, }, }, }, }, { Name: "insert negative values into auto_increment values", SetUpScript: []string{ "create table auto (pk int primary key auto_increment)", "insert into auto values (10), (20), (30)", "insert into auto values (-1), (-2), (-3)", "insert into auto () values ()", "insert into auto values (0), (0), (0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {-3}, {-2}, {-1}, {10}, {20}, {30}, {31}, {32}, {33}, {34}, }, }, }, }, { Name: "insert into auto_increment unique key column", SetUpScript: []string{ "create table auto (pk int primary key, npk int unique auto_increment)", "insert into auto (pk) values (10), (20), (30)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {10, 1}, {20, 2}, {30, 3}, }, }, }, }, { Name: "insert into auto_increment with multiple unique key columns", SetUpScript: []string{ "create table auto (pk int primary key, npk1 int auto_increment, npk2 int, unique(npk1, npk2))", "insert into auto (pk) values (10), (20), (30)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {10, 1, nil}, {20, 2, nil}, {30, 3, nil}, }, }, }, }, { Name: "insert into auto_increment key/index column", SetUpScript: []string{ "create table auto_no_primary (i int auto_increment, index(i))", "insert into auto_no_primary (i) values (0), (0), (0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto_no_primary order by 1", Expected: []sql.Row{ {1}, {2}, {3}, }, }, }, }, { Name: "insert into auto_increment with multiple key/index columns", SetUpScript: []string{ "create table auto_no_primary (i int auto_increment, j int, index(i))", "insert into auto_no_primary (i) values (0), (0), (0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto_no_primary order by 1", Expected: []sql.Row{ {1, nil}, {2, nil}, {3, nil}, }, }, }, }, { Name: "auto increment table handles deletes", SetUpScript: []string{ "create table auto (pk int primary key auto_increment)", "insert into auto values (10)", "delete from auto where pk = 10", "insert into auto values (NULL)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {11}, }, }, }, }, { Name: "create auto_increment table with out-of-line primary key def", SetUpScript: []string{ `create table auto ( pk int auto_increment, c0 int, primary key(pk) );`, "insert into auto values (NULL,10), (NULL,20), (NULL,30)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {1, 10}, {2, 20}, {3, 30}, }, }, }, }, { Name: "alter auto_increment value", SetUpScript: []string{ `create table auto ( pk int auto_increment, c0 int, primary key(pk) );`, "insert into auto values (NULL,10), (NULL,20), (NULL,30)", "alter table auto auto_increment 9;", "insert into auto values (NULL,90)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {1, 10}, {2, 20}, {3, 30}, {9, 90}, }, }, }, }, { Name: "alter auto_increment value to float", SetUpScript: []string{ `create table auto ( pk int auto_increment, c0 int, primary key(pk) );`, "insert into auto values (NULL,10), (NULL,20), (NULL,30)", "alter table auto auto_increment = 19.9;", "insert into auto values (NULL,190)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {1, 10}, {2, 20}, {3, 30}, {19, 190}, }, }, }, }, { Name: "auto increment on tinyint", SetUpScript: []string{ "create table auto (pk tinyint primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {1}, {10}, {11}, }, }, }, }, { Name: "auto increment on smallint", SetUpScript: []string{ "create table auto (pk smallint primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {1}, {10}, {11}, }, }, }, }, { Name: "auto increment on mediumint", SetUpScript: []string{ "create table auto (pk mediumint primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {1}, {10}, {11}, }, }, }, }, { Name: "auto increment on int", SetUpScript: []string{ "create table auto (pk int primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {1}, {10}, {11}, }, }, }, }, { Name: "auto increment on bigint", SetUpScript: []string{ "create table auto (pk bigint primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {1}, {10}, {11}, }, }, }, }, { Name: "auto increment on tinyint unsigned", SetUpScript: []string{ "create table auto (pk tinyint unsigned primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {uint64(1)}, {uint64(10)}, {uint64(11)}, }, }, }, }, { Name: "auto increment on smallint unsigned", SetUpScript: []string{ "create table auto (pk smallint unsigned primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {uint64(1)}, {uint64(10)}, {uint64(11)}, }, }, }, }, { Name: "auto increment on mediumint unsigned", SetUpScript: []string{ "create table auto (pk mediumint unsigned primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {uint64(1)}, {uint64(10)}, {uint64(11)}, }, }, }, }, { Name: "auto increment on int unsigned", SetUpScript: []string{ "create table auto (pk int unsigned primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {uint64(1)}, {uint64(10)}, {uint64(11)}, }, }, }, }, { Name: "auto increment on bigint unsigned", SetUpScript: []string{ "create table auto (pk bigint unsigned primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {uint64(1)}, {uint64(10)}, {uint64(11)}, }, }, }, }, { Name: "auto increment on float", SetUpScript: []string{ "create table auto (pk float primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {float64(1)}, {float64(10)}, {float64(11)}, }, }, }, }, { Name: "auto increment on double", SetUpScript: []string{ "create table auto (pk double primary key auto_increment)", "insert into auto values (NULL),(10),(0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from auto order by 1", Expected: []sql.Row{ {float64(1)}, {float64(10)}, {float64(11)}, }, }, }, }, { Name: "explicit DEFAULT", SetUpScript: []string{ "CREATE TABLE t1(id int DEFAULT '2', dt datetime DEFAULT now());", "CREATE TABLE t2(id varchar(100) DEFAULT (uuid()));", "CREATE TABLE t3(a int DEFAULT '1', b int default (2 * a));", "CREATE TABLE t4(c0 varchar(10) null default 'c0', c1 varchar(10) null default 'c1');", "CREATE TABLE t5(c0 varchar(100) DEFAULT (repeat('_', 100)), c1 datetime DEFAULT current_timestamp());", "create table t6 (color enum('red', 'blue', 'green') default 'blue', createdAt timestamp default (current_timestamp()));", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO T1 values (DEFAULT, DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "INSERT INTO t1 (id, dt) values (DEFAULT, DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "INSERT INTO t1 (dt, ID) values (DEFAULT, DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "INSERT INTO t1 (ID) values (DEFAULT), (3)", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "INSERT INTO t1 (dt) values (DEFAULT), ('1981-02-16 00:00:00')", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "INSERT INTO t1 values (100, '2000-01-01 12:34:56'), (DEFAULT, DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "INSERT INTO t1 (id, dt) values (100, '2022-01-01 01:01:01'), (DEFAULT, DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "INSERT INTO t1 (id) values (10), (DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "INSERT INTO t1 (DT) values ('2022-02-02 02:02:02'), (DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "INSERT INTO t2 values ('10'), (DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "INSERT INTO t2 (id) values (DEFAULT), ('11'), (DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 3}}}, }, { Query: "select count(distinct id) from t2", Expected: []sql.Row{{5}}, }, { Query: "INSERT INTO t3 (a) values (DEFAULT), ('2'), (DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 3}}}, }, { Query: "SELECT b from t3 order by b asc", Expected: []sql.Row{{2}, {2}, {4}}, }, { Query: "INSERT INTO T4 (c1, c0) values (DEFAULT, NULL)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "select * from t4", Expected: []sql.Row{{nil, "c1"}}, }, { Query: "INSERT INTO T5 values (DEFAULT, DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "INSERT INTO T5 (c0, c1) values (DEFAULT, DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "INSERT INTO T5 (c1) values (DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "insert into T6(createdAt, color) values (DEFAULT, DEFAULT);", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, }, }, { Name: "Try INSERT IGNORE with primary key, non null, and single row violations", SetUpScript: []string{ "CREATE TABLE y (pk int primary key, c1 int NOT NULL);", "INSERT IGNORE INTO y VALUES (1, 1), (1,2), (2, 2), (3, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM y", Expected: []sql.Row{ {1, 1}, {2, 2}, {3, 3}, }, }, { Query: "INSERT IGNORE INTO y VALUES (1, 2), (4,4)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, ExpectedWarning: mysql.ERDupEntry, }, { Query: "INSERT IGNORE INTO y VALUES (5, NULL)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, ExpectedWarning: mysql.ERBadNullError, }, { Query: "INSERT IGNORE INTO y SELECT * FROM y WHERE pk=(SELECT pk+10 FROM y WHERE pk > 1);", Expected: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, ExpectedWarning: mysql.ERSubqueryNo1Row, }, { Query: "INSERT IGNORE INTO y SELECT 10, 0 FROM dual WHERE 1=(SELECT 1 FROM dual UNION SELECT 2 FROM dual);", Expected: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, ExpectedWarning: mysql.ERSubqueryNo1Row, }, { Query: "INSERT IGNORE INTO y SELECT 11, 0 FROM dual WHERE 1=(SELECT 1 FROM dual UNION SELECT 2 FROM dual) UNION SELECT 12, 0 FROM dual;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, ExpectedWarning: mysql.ERSubqueryNo1Row, }, { Query: "INSERT IGNORE INTO y SELECT 13, 0 FROM dual UNION SELECT 14, 0 FROM dual WHERE 1=(SELECT 1 FROM dual UNION SELECT 2 FROM dual);", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, ExpectedWarning: mysql.ERSubqueryNo1Row, }, { Query: "INSERT IGNORE INTO y VALUES (3, 8)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, ExpectedWarning: mysql.ERDupEntry, }, }, }, { Name: "INSERT Accumulator tests", SetUpScript: []string{ "CREATE TABLE test(pk int primary key, val int)", "INSERT INTO test values (1,1)", }, Assertions: []ScriptTestAssertion{ { Query: `INSERT INTO test VALUES (2,2),(2,3)`, ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: `DELETE FROM test where pk = 1;`, Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: `INSERT INTO test VALUES (1,1)`, Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, }, }, { Name: "INSERT Case Sensitivity", SetUpScript: []string{ "CREATE TABLE test (PK int PRIMARY KEY);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into test(pk) values (1)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, }, }, { Name: "INSERT string with exact char length but extra byte length", SetUpScript: []string{ "CREATE TABLE city (id int PRIMARY KEY, district char(20) NOT NULL DEFAULT '');", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO city VALUES (1,'San Pedro de Macorís');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, }, }, { Name: "Insert on duplicate key", SetUpScript: []string{ `CREATE TABLE users ( id varchar(42) PRIMARY KEY )`, `CREATE TABLE nodes ( id varchar(42) PRIMARY KEY, owner varchar(42), status varchar(12), timestamp bigint NOT NULL, FOREIGN KEY(owner) REFERENCES users(id) )`, "INSERT INTO users values ('milo'), ('dabe')", "INSERT INTO nodes values ('id1', 'milo', 'off', 1)", }, Assertions: []ScriptTestAssertion{ { Query: "insert into nodes(id,owner,status,timestamp) values('id1','dabe','off',2) on duplicate key update owner='milo',status='on'", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "insert into nodes(id,owner,status,timestamp) values('id2','dabe','off',3) on duplicate key update owner='milo',status='on'", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, { Query: "select * from nodes", Expected: []sql.Row{ {"id1", "milo", "on", 1}, {"id2", "dabe", "off", 3}, }, }, }, }, { Name: "Insert on duplicate key references table in subquery", SetUpScript: []string{ `create table a (i int primary key)`, `insert into a values (1)`, `create table b (j int primary key)`, `insert into b values (1), (2), (3)`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into a (select * from b) on duplicate key update a.i = b.j + 100`, Expected: []sql.Row{ {types.OkResult{RowsAffected: 4}}, }, }, { Query: "select * from a", Expected: []sql.Row{ {101}, {2}, {3}, }, }, }, }, { Name: "Insert on duplicate key references table in aliased subquery", SetUpScript: []string{ `create table a (i int primary key)`, `insert into a values (1)`, `create table b (j int primary key)`, `insert into b values (1), (2), (3)`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into a (select * from b as t) on duplicate key update a.i = b.j + 100`, ExpectedErr: sql.ErrTableNotFound, }, { Query: `insert into a (select * from b as t) on duplicate key update a.i = t.j + 100`, Expected: []sql.Row{ {types.OkResult{RowsAffected: 4}}, }, }, { Query: "select * from a", Expected: []sql.Row{ {101}, {2}, {3}, }, }, }, }, { Name: "insert on duplicate key update errors", SetUpScript: []string{ `create table a (i int primary key)`, `create table b (i int primary key)`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into a (select * from b) on duplicate key update i = i`, ExpectedErr: sql.ErrAmbiguousColumnName, }, { Query: `insert into a (select * from b) on duplicate key update b.i = a.i`, ExpectedErr: sql.ErrTableNotFound, }, }, }, { Name: "Insert on duplicate key references table in subquery with join", SetUpScript: []string{ `create table a (i int primary key, j int)`, `insert into a values (1,1)`, `create table b (x int primary key)`, `insert into b values (1), (2), (3)`, `create table c (y int primary key)`, `insert into c values (1), (2), (3)`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into a (select * from b join c where b.x = c.y) on duplicate key update a.j = b.x + c.y + 100`, Expected: []sql.Row{ {types.OkResult{RowsAffected: 4}}, }, }, { Query: "select * from a", Expected: []sql.Row{ {1, 102}, {2, 2}, {3, 3}, }, }, }, }, { Name: "Insert on duplicate key references table in subquery with alias", SetUpScript: []string{ `create table a (i int primary key)`, `insert into a values (1)`, `create table b (i int primary key)`, `insert into b values (1), (2), (3)`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into a (select t.i from b as t, b where t.i = b.i) on duplicate key update i = b.i;`, Skip: true, Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "select * from a", Skip: true, Expected: []sql.Row{ {1}, {2}, {3}, }, }, }, }, { Name: "Insert on duplicate key references table in cte", SetUpScript: []string{ `create table a (i int primary key)`, `insert into a values (1)`, `create table b (j int primary key)`, `insert into b values (1), (2), (3)`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into a with cte as (select * from b) select * from cte on duplicate key update a.i = cte.j + 100`, Skip: true, Expected: []sql.Row{ {types.OkResult{RowsAffected: 4}}, }, }, { Query: "select * from a", Skip: true, Expected: []sql.Row{ {101}, {2}, {3}, }, }, }, }, { Name: "Insert throws primary key violations", SetUpScript: []string{ "CREATE TABLE t (pk int PRIMARY key);", "CREATE TABLE t2 (pk1 int, pk2 int, PRIMARY KEY (pk1, pk2));", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO t VALUES (1), (2);", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "INSERT into t VALUES (1);", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "SELECT * from t;", Expected: []sql.Row{{1}, {2}}, }, { Query: "INSERT into t2 VALUES (1, 1), (2, 2);", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "INSERT into t2 VALUES (1, 1);", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "SELECT * from t2;", Expected: []sql.Row{{1, 1}, {2, 2}}, }, }, }, { Name: "Insert throws unique key violations", SetUpScript: []string{ "CREATE TABLE t (pk int PRIMARY key, col1 int UNIQUE);", "CREATE TABLE t2 (pk int PRIMARY key, col1 int, col2 int, UNIQUE KEY (col1, col2));", "INSERT into t VALUES (1, 1);", "INSERT into t2 VALUES (1, 1, 1);", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO t VALUES (2, 2), (3, 1), (4, 4);", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "SELECT * from t;", Expected: []sql.Row{{1, 1}}, }, { Query: "INSERT INTO t2 VALUES (2, 2, 2), (3, 1, 1), (4, 4, 4);", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "SELECT * from t2;", Expected: []sql.Row{{1, 1, 1}}, }, { Query: "INSERT INTO t VALUES (5, 2), (6, 2);", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "SELECT * from t;", Expected: []sql.Row{{1, 1}}, }, { Query: "INSERT INTO t2 VALUES (5, 2, 2), (6, 2, 2);", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "SELECT * from t2;", Expected: []sql.Row{{1, 1, 1}}, }, { Query: "INSERT into t2 VALUES (5, NULL, 1), (6, NULL, 1), (7, 1, NULL), (8, 1, NULL), (9, NULL, NULL), (10, NULL, NULL)", Expected: []sql.Row{{types.NewOkResult(6)}}, }, { Query: "SELECT * from t2;", Expected: []sql.Row{{1, 1, 1}, {5, nil, 1}, {6, nil, 1}, {7, 1, nil}, {8, 1, nil}, {9, nil, nil}, {10, nil, nil}}, }, }, }, { Name: "Insert throws unique key violations for keyless tables", SetUpScript: []string{ "CREATE TABLE t (not_pk int NOT NULL, col1 int UNIQUE);", "CREATE TABLE t2 (not_pk int NOT NULL, col1 int, col2 int, UNIQUE KEY (col1, col2));", "INSERT into t VALUES (1, 1);", "INSERT into t2 VALUES (1, 1, 1);", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO t VALUES (2, 2), (3, 1), (4, 4);", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "SELECT * from t;", Expected: []sql.Row{{1, 1}}, }, { Query: "INSERT INTO t2 VALUES (2, 2, 2), (3, 1, 1), (4, 4, 4);", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "SELECT * from t2;", Expected: []sql.Row{{1, 1, 1}}, }, { Query: "INSERT INTO t VALUES (5, 2), (6, 2);", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "SELECT * from t;", Expected: []sql.Row{{1, 1}}, }, { Query: "INSERT INTO t2 VALUES (5, 2, 2), (6, 2, 2);", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "SELECT * from t2;", Expected: []sql.Row{{1, 1, 1}}, }, { Query: "INSERT into t2 VALUES (5, NULL, 1), (6, NULL, 1), (7, 1, NULL), (8, 1, NULL), (9, NULL, NULL), (10, NULL, NULL)", Expected: []sql.Row{{types.NewOkResult(6)}}, }, { Query: "SELECT * from t2;", Expected: []sql.Row{{1, 1, 1}, {5, nil, 1}, {6, nil, 1}, {7, 1, nil}, {8, 1, nil}, {9, nil, nil}, {10, nil, nil}}, }, }, }, { Name: "Insert into unique key that overlaps with primary key", SetUpScript: []string{ "CREATE TABLE t (pk1 int, pk2 int, col int, PRIMARY KEY(pk1, pk2), UNIQUE KEY(col, pk2));", "INSERT into t (pk1, pk2, col) VALUES (1, 1, 1), (2, 1, 2);", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO t (pk1, pk2, col) VALUES (3, 1, 1);", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "UPDATE t SET col = col + 1", ExpectedErr: sql.ErrUniqueKeyViolation, }, }, }, { Name: "INSERT INTO ... SELECT works properly with ENUM", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY NOT NULL, v1 ENUM('a','b','c'));", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO test (pk, v1) VALUES (1, 'a');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT INTO test (pk, v1) SELECT 2 as pk, 'a' as v1;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, }, }, { Name: "INSERT INTO ... SELECT works properly with SET", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY NOT NULL, v1 SET('a','b','c'));", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO test (pk, v1) VALUES (1, 'a');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "INSERT INTO test (pk, v1) SELECT 2 as pk, 'a' as v1;", Expected: []sql.Row{{types.NewOkResult(1)}}, }, }, }, { Name: "Defaults with escaped strings", SetUpScript: []string{ `CREATE TABLE escpe ( id int NOT NULL AUTO_INCREMENT, t1 varchar(15) DEFAULT 'foo''s baz', t2 varchar(15) DEFAULT 'who\'s dat', t3 varchar(15) DEFAULT "joe\'s bar", t4 varchar(15) DEFAULT "quote""bazzar", t5 varchar(15) DEFAULT 'back\\''slash', t6 varchar(15) DEFAULT 'tab\ttab', t7 varchar(15) DEFAULT 'new\nline', PRIMARY KEY (id) );`, "INSERT INTO escpe VALUES ();", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT t1 from escpe", Expected: []sql.Row{{"foo's baz"}}, }, { Query: "SELECT t2 from escpe", Expected: []sql.Row{{"who's dat"}}, }, { Query: "SELECT t3 from escpe", Expected: []sql.Row{{"joe's bar"}}, }, { Query: "SELECT t4 from escpe", Expected: []sql.Row{{"quote\"bazzar"}}, }, { Query: "SELECT t5 from escpe", Expected: []sql.Row{{"back\\'slash"}}, }, { Query: "SELECT t6 from escpe", Expected: []sql.Row{{"tab\ttab"}}, }, { Query: "SELECT t7 from escpe", Expected: []sql.Row{{"new\nline"}}, }, }, }, { Name: "check constrains with escaped strings", SetUpScript: []string{ `CREATE TABLE quoted ( id int NOT NULL AUTO_INCREMENT, val varchar(15) NOT NULL CHECK (val IN ('joe''s', "jan's", 'mia\\''s', 'bob\'s', 'tab\tvs\tcoke', 'percent\%')), PRIMARY KEY (id));`, `INSERT INTO quoted VALUES (0,"joe's");`, `INSERT INTO quoted VALUES (0,"jan's");`, `INSERT INTO quoted VALUES (0,"mia\\'s");`, `INSERT INTO quoted VALUES (0,"bob's");`, `INSERT INTO quoted VALUES (0,"tab\tvs\tcoke");`, }, Assertions: []ScriptTestAssertion{ { Query: "SELECT val from quoted order by id", Expected: []sql.Row{ {"joe's"}, {"jan's"}, {"mia\\'s"}, {"bob's"}, {"tab\tvs\tcoke"}}, }, }, }, { Name: "check IN TUPLE constraint with duplicate key update", SetUpScript: []string{ "create table alphabet (letter varchar(1), constraint `good_letters` check (letter in ('a','l','e','c')))", }, Assertions: []ScriptTestAssertion{ { Query: "insert into alphabet values ('a') on duplicate key update letter = values(letter)", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "insert into alphabet values ('z') on duplicate key update letter = values(letter)", ExpectedErr: sql.ErrCheckConstraintViolated, }, }, }, }
var IntegrationPlanTests = []QueryPlanTest{
{
Query: `
SELECT
id, FTQLQ
FROM
YK2GW
WHERE
id NOT IN (SELECT IXUXU FROM THNTS)
;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [yk2gw.id:0!null, yk2gw.FTQLQ:1!null]\n" +
" └─ Project\n" +
" ├─ columns: [yk2gw.id:0!null, YK2GW.FTQLQ:1!null, YK2GW.TUXML:2, YK2GW.PAEF5:3, YK2GW.RUCY4:4, YK2GW.TPNJ6:5!null, YK2GW.LBL53:6, YK2GW.NB3QS:7, YK2GW.EO7IV:8, YK2GW.MUHJF:9, YK2GW.FM34L:10, YK2GW.TY5RF:11, YK2GW.ZHTLH:12, YK2GW.NPB7W:13, YK2GW.SX3HH:14, YK2GW.ISBNF:15, YK2GW.YA7YB:16, YK2GW.C5YKB:17, YK2GW.QK7KT:18, YK2GW.FFGE6:19, YK2GW.FIIGJ:20, YK2GW.SH3NC:21, YK2GW.NTENA:22, YK2GW.M4AUB:23, YK2GW.X5AIR:24, YK2GW.SAB6M:25, YK2GW.G5QI5:26, YK2GW.ZVQVD:27, YK2GW.YKSSU:28, YK2GW.FHCYT:29]\n" +
" └─ Filter\n" +
" ├─ scalarSubq0.IXUXU:30 IS NULL\n" +
" └─ LeftOuterMergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ yk2gw.id:0!null\n" +
" │ └─ scalarSubq0.IXUXU:30\n" +
" ├─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
" └─ Project\n" +
" ├─ columns: [scalarSubq0.IXUXU:2]\n" +
" └─ TableAlias(scalarSubq0)\n" +
" └─ IndexedTableAccess(THNTS)\n" +
" ├─ index: [THNTS.IXUXU]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id nfryn ixuxu fhcyt]\n" +
"",
},
{
Query: `
SELECT
PBMRX.id AS id,
PBMRX.TW55N AS TEYBZ,
PBMRX.ZH72S AS FB6N7
FROM
(
SELECT
ZH72S AS ZH72S,
COUNT(ZH72S) AS JTOA7,
MIN(WGBRL) AS TTDPM,
SUM(WGBRL) AS FBSRS
FROM
(
SELECT
nd.id AS id,
nd.ZH72S AS ZH72S,
(SELECT COUNT(*) FROM HDDVB WHERE UJ6XY = nd.id) AS WGBRL
FROM
E2I7U nd
WHERE nd.ZH72S IS NOT NULL
) CCEFL
GROUP BY
ZH72S
HAVING
JTOA7 > 1
) CL3DT
INNER JOIN
E2I7U PBMRX
ON
PBMRX.ZH72S IS NOT NULL AND PBMRX.ZH72S = CL3DT.ZH72S
WHERE
CL3DT.TTDPM = 0
AND
CL3DT.FBSRS > 0
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [pbmrx.id:0!null as id, pbmrx.TW55N:1!null as TEYBZ, pbmrx.ZH72S:2 as FB6N7]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ pbmrx.ZH72S:2 IS NULL\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ pbmrx.ZH72S:2\n" +
" │ └─ cl3dt.ZH72S:3\n" +
" ├─ Filter\n" +
" │ ├─ NOT\n" +
" │ │ └─ pbmrx.ZH72S:2 IS NULL\n" +
" │ └─ TableAlias(pbmrx)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ ├─ static: [{(NULL, ∞)}]\n" +
" │ └─ columns: [id tw55n zh72s]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(pbmrx.ZH72S:2)\n" +
" ├─ right-key: TUPLE(cl3dt.ZH72S:0)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: cl3dt\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ TTDPM:2!null\n" +
" │ │ └─ 0 (tinyint)\n" +
" │ └─ GreaterThan\n" +
" │ ├─ FBSRS:3!null\n" +
" │ └─ 0 (tinyint)\n" +
" └─ Project\n" +
" ├─ columns: [ccefl.ZH72S:3 as ZH72S, count(ccefl.zh72s):0!null as JTOA7, min(ccefl.wgbrl):1!null as TTDPM, sum(ccefl.wgbrl):2!null as FBSRS]\n" +
" └─ Having\n" +
" ├─ GreaterThan\n" +
" │ ├─ JTOA7:5!null\n" +
" │ └─ 1 (tinyint)\n" +
" └─ Project\n" +
" ├─ columns: [count(ccefl.zh72s):0!null, min(ccefl.wgbrl):1!null, sum(ccefl.wgbrl):2!null, ccefl.ZH72S:3, ccefl.ZH72S:3 as ZH72S, count(ccefl.zh72s):0!null as JTOA7, min(ccefl.wgbrl):1!null as TTDPM, sum(ccefl.wgbrl):2!null as FBSRS]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(ccefl.ZH72S:1), MIN(ccefl.WGBRL:2), SUM(ccefl.WGBRL:2), ccefl.ZH72S:1\n" +
" ├─ group: ccefl.ZH72S:1 as ZH72S\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ccefl\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.id:0!null as id, nd.ZH72S:7 as ZH72S, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(1):20!null as COUNT(*)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: COUNT(1 (bigint))\n" +
" │ ├─ group: \n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ hddvb.UJ6XY:20!null\n" +
" │ │ └─ nd.id:0!null\n" +
" │ └─ IndexedTableAccess(HDDVB)\n" +
" │ ├─ index: [HDDVB.UJ6XY]\n" +
" │ └─ columns: [uj6xy]\n" +
" │ as WGBRL]\n" +
" └─ Project\n" +
" ├─ columns: [nd.id:0!null, nd.DKCAJ:1!null, nd.KNG7T:2, nd.TW55N:3!null, nd.QRQXW:4!null, nd.ECXAJ:5!null, nd.FGG57:6, nd.ZH72S:7, nd.FSK67:8!null, nd.XQDYT:9!null, nd.TCE7A:10, nd.IWV2H:11, nd.HPCMS:12!null, nd.N5CC2:13, nd.FHCYT:14, nd.ETAQ7:15, nd.A75X7:16, nd.id:0!null as id, nd.ZH72S:7 as ZH72S, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(1):17!null as COUNT(*)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: COUNT(1 (bigint))\n" +
" │ ├─ group: \n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ hddvb.UJ6XY:17!null\n" +
" │ │ └─ nd.id:0!null\n" +
" │ └─ IndexedTableAccess(HDDVB)\n" +
" │ ├─ index: [HDDVB.UJ6XY]\n" +
" │ └─ columns: [uj6xy]\n" +
" │ as WGBRL]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nd.ZH72S:7 IS NULL\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ static: [{(NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT
ism.*
FROM
HDDVB ism
WHERE
(
ism.PRUV2 IS NOT NULL
AND
(
(SELECT NHMXW.SWCQV FROM WGSDC NHMXW WHERE NHMXW.id = ism.PRUV2) = 1
OR
(
(
ism.FV24E IS NOT NULL
AND
(SELECT nd.id FROM E2I7U nd WHERE nd.TW55N =
(SELECT NHMXW.FZXV5 FROM WGSDC NHMXW
WHERE NHMXW.id = ism.PRUV2))
<> ism.FV24E
)
OR
(
ism.UJ6XY IS NOT NULL
AND
(SELECT nd.id FROM E2I7U nd WHERE nd.TW55N =
(SELECT NHMXW.DQYGV FROM WGSDC NHMXW
WHERE NHMXW.id = ism.PRUV2))
<> ism.UJ6XY
)
)
)
)
OR
(
ism.ETPQV IS NOT NULL
AND
ism.ETPQV IN
(
SELECT
TIZHK.id AS FWATE
FROM
WGSDC NHMXW
INNER JOIN
WRZVO TIZHK
ON
TIZHK.TVNW2 = NHMXW.NOHHR
AND
TIZHK.ZHITY = NHMXW.AVPYF
AND
TIZHK.SYPKF = NHMXW.SYPKF
AND
TIZHK.IDUT2 = NHMXW.IDUT2
WHERE
NHMXW.SWCQV = 0
AND
NHMXW.id NOT IN (SELECT PRUV2 FROM HDDVB WHERE PRUV2 IS NOT NULL)
)
)
`,
ExpectedPlan: "Filter\n" +
" ├─ Or\n" +
" │ ├─ AND\n" +
" │ │ ├─ NOT\n" +
" │ │ │ └─ ism.PRUV2:6 IS NULL\n" +
" │ │ └─ Or\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [nhmxw.SWCQV:10!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ nhmxw.id:9!null\n" +
" │ │ │ │ │ └─ ism.PRUV2:6\n" +
" │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ └─ IndexedTableAccess(WGSDC)\n" +
" │ │ │ │ ├─ index: [WGSDC.id]\n" +
" │ │ │ │ └─ columns: [id swcqv]\n" +
" │ │ │ └─ 1 (tinyint)\n" +
" │ │ └─ Or\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ ism.FV24E:1!null IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [nd.id:9!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ nd.TW55N:12!null\n" +
" │ │ │ │ │ └─ Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [nhmxw.FZXV5:27]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nhmxw.id:26!null\n" +
" │ │ │ │ │ │ └─ ism.PRUV2:6\n" +
" │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(WGSDC)\n" +
" │ │ │ │ │ ├─ index: [WGSDC.id]\n" +
" │ │ │ │ │ └─ columns: [id fzxv5]\n" +
" │ │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ │ └─ ism.FV24E:1!null\n" +
" │ │ └─ AND\n" +
" │ │ ├─ NOT\n" +
" │ │ │ └─ ism.UJ6XY:2!null IS NULL\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [nd.id:9!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ nd.TW55N:12!null\n" +
" │ │ │ │ └─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [nhmxw.DQYGV:27]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ nhmxw.id:26!null\n" +
" │ │ │ │ │ └─ ism.PRUV2:6\n" +
" │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ └─ IndexedTableAccess(WGSDC)\n" +
" │ │ │ │ ├─ index: [WGSDC.id]\n" +
" │ │ │ │ └─ columns: [id dqygv]\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ └─ ism.UJ6XY:2!null\n" +
" │ └─ AND\n" +
" │ ├─ NOT\n" +
" │ │ └─ ism.ETPQV:5 IS NULL\n" +
" │ └─ InSubquery\n" +
" │ ├─ left: ism.ETPQV:5\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tizhk.id:9!null as FWATE]\n" +
" │ └─ HashJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ tizhk.TVNW2:10\n" +
" │ │ │ │ │ └─ nhmxw.NOHHR:20!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ tizhk.ZHITY:11\n" +
" │ │ │ │ └─ nhmxw.AVPYF:21!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ tizhk.SYPKF:12\n" +
" │ │ │ └─ nhmxw.SYPKF:22!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ tizhk.IDUT2:13\n" +
" │ │ └─ nhmxw.IDUT2:23!null\n" +
" │ ├─ TableAlias(tizhk)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: WRZVO\n" +
" │ │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(tizhk.TVNW2:10, tizhk.ZHITY:11, tizhk.SYPKF:12, tizhk.IDUT2:13)\n" +
" │ ├─ right-key: TUPLE(nhmxw.NOHHR:10!null, nhmxw.AVPYF:11!null, nhmxw.SYPKF:12!null, nhmxw.IDUT2:13!null)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nhmxw.id:9!null, nhmxw.NOHHR:10!null, nhmxw.AVPYF:11!null, nhmxw.SYPKF:12!null, nhmxw.IDUT2:13!null, nhmxw.FZXV5:14, nhmxw.DQYGV:15, nhmxw.SWCQV:16!null, nhmxw.YKSSU:17, nhmxw.FHCYT:18]\n" +
" │ └─ Filter\n" +
" │ ├─ scalarSubq0.PRUV2:19 IS NULL\n" +
" │ └─ LeftOuterMergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ nhmxw.id:19!null\n" +
" │ │ └─ scalarSubq0.PRUV2:29\n" +
" │ ├─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ nhmxw.SWCQV:16!null\n" +
" │ │ │ └─ 0 (tinyint)\n" +
" │ │ └─ TableAlias(nhmxw)\n" +
" │ │ └─ IndexedTableAccess(WGSDC)\n" +
" │ │ ├─ index: [WGSDC.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id nohhr avpyf sypkf idut2 fzxv5 dqygv swcqv ykssu fhcyt]\n" +
" │ └─ Filter\n" +
" │ ├─ NOT\n" +
" │ │ └─ scalarSubq0.PRUV2:9 IS NULL\n" +
" │ └─ TableAlias(scalarSubq0)\n" +
" │ └─ IndexedTableAccess(HDDVB)\n" +
" │ ├─ index: [HDDVB.PRUV2]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [pruv2]\n" +
" └─ TableAlias(ism)\n" +
" └─ Table\n" +
" ├─ name: HDDVB\n" +
" └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
TIZHK.*
FROM
WRZVO TIZHK
WHERE id IN
(
SELECT /*+ JOIN_ORDER( J4JYP, TIZHK, RHUZN, mf, aac ) */DISTINCT
TIZHK.id
FROM
WRZVO TIZHK
INNER JOIN
E2I7U J4JYP
ON
J4JYP.ZH72S = TIZHK.TVNW2
INNER JOIN
E2I7U RHUZN
ON
RHUZN.ZH72S = TIZHK.ZHITY
INNER JOIN
HGMQ6 mf ON mf.LUEVY = J4JYP.id
INNER JOIN
TPXBU aac ON aac.id = mf.M22QN
WHERE
aac.BTXC5 = TIZHK.SYPKF
)
AND
TIZHK.id NOT IN (SELECT ETPQV FROM HDDVB)
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [tizhk.id:1!null, tizhk.TVNW2:2, tizhk.ZHITY:3, tizhk.SYPKF:4, tizhk.IDUT2:5, tizhk.O6QJ3:6, tizhk.NO2JA:7, tizhk.YKSSU:8, tizhk.FHCYT:9, tizhk.QZ6VT:10]\n" +
" └─ Filter\n" +
" ├─ scalarSubq1.ETPQV:11 IS NULL\n" +
" └─ LeftOuterHashJoinExcludeNulls\n" +
" ├─ Eq\n" +
" │ ├─ tizhk.id:1!null\n" +
" │ └─ scalarSubq1.ETPQV:11\n" +
" ├─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ tizhk.id:1!null\n" +
" │ │ └─ scalarSubq0.id:0!null\n" +
" │ ├─ Distinct\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: scalarSubq0\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tizhk.id:17!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.BTXC5:62\n" +
" │ │ │ └─ tizhk.SYPKF:20\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ mf.LUEVY:46!null\n" +
" │ │ │ └─ j4jyp.id:0!null\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ rhuzn.ZH72S:34\n" +
" │ │ │ │ └─ tizhk.ZHITY:19\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ j4jyp.ZH72S:7\n" +
" │ │ │ │ │ └─ tizhk.TVNW2:18\n" +
" │ │ │ │ ├─ TableAlias(j4jyp)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ │ │ └─ TableAlias(tizhk)\n" +
" │ │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ │ ├─ index: [WRZVO.TVNW2]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(tizhk.ZHITY:19)\n" +
" │ │ │ ├─ right-key: TUPLE(rhuzn.ZH72S:7)\n" +
" │ │ │ └─ TableAlias(rhuzn)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(j4jyp.id:0!null)\n" +
" │ │ ├─ right-key: TUPLE(mf.LUEVY:2!null)\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ mf.M22QN:47!null\n" +
" │ │ │ └─ aac.id:61!null\n" +
" │ │ ├─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ └─ TableAlias(tizhk)\n" +
" │ └─ IndexedTableAccess(WRZVO)\n" +
" │ ├─ index: [WRZVO.id]\n" +
" │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(tizhk.id:1!null)\n" +
" ├─ right-key: TUPLE(scalarSubq1.ETPQV:0)\n" +
" └─ Project\n" +
" ├─ columns: [scalarSubq1.ETPQV:5]\n" +
" └─ TableAlias(scalarSubq1)\n" +
" └─ Table\n" +
" ├─ name: HDDVB\n" +
" └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
TIZHK.*
FROM
WRZVO TIZHK
WHERE id IN
(
SELECT DISTINCT
TIZHK.id
FROM
WRZVO TIZHK
INNER JOIN
E2I7U J4JYP
ON
J4JYP.ZH72S = TIZHK.TVNW2
INNER JOIN
E2I7U RHUZN
ON
RHUZN.ZH72S = TIZHK.ZHITY
INNER JOIN
HGMQ6 mf ON mf.LUEVY = J4JYP.id
INNER JOIN
TPXBU aac ON aac.id = mf.M22QN
WHERE
aac.BTXC5 = TIZHK.SYPKF
)
AND
TIZHK.id NOT IN (SELECT ETPQV FROM HDDVB)
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [tizhk.id:1!null, tizhk.TVNW2:2, tizhk.ZHITY:3, tizhk.SYPKF:4, tizhk.IDUT2:5, tizhk.O6QJ3:6, tizhk.NO2JA:7, tizhk.YKSSU:8, tizhk.FHCYT:9, tizhk.QZ6VT:10]\n" +
" └─ Filter\n" +
" ├─ scalarSubq1.ETPQV:11 IS NULL\n" +
" └─ LeftOuterHashJoinExcludeNulls\n" +
" ├─ Eq\n" +
" │ ├─ tizhk.id:1!null\n" +
" │ └─ scalarSubq1.ETPQV:11\n" +
" ├─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ tizhk.id:1!null\n" +
" │ │ └─ scalarSubq0.id:0!null\n" +
" │ ├─ Distinct\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: scalarSubq0\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tizhk.id:37!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.BTXC5:1\n" +
" │ │ │ └─ tizhk.SYPKF:40\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ mf.LUEVY:5!null\n" +
" │ │ │ └─ j4jyp.id:47!null\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ aac.id:0!null\n" +
" │ │ │ │ └─ mf.M22QN:6!null\n" +
" │ │ │ ├─ TableAlias(aac)\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(mf.LUEVY:5!null)\n" +
" │ │ ├─ right-key: TUPLE(j4jyp.id:27!null)\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ j4jyp.ZH72S:54\n" +
" │ │ │ └─ tizhk.TVNW2:38\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ rhuzn.ZH72S:27\n" +
" │ │ │ │ └─ tizhk.ZHITY:39\n" +
" │ │ │ ├─ TableAlias(rhuzn)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ │ └─ TableAlias(tizhk)\n" +
" │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ ├─ index: [WRZVO.ZHITY]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(tizhk.TVNW2:38)\n" +
" │ │ ├─ right-key: TUPLE(j4jyp.ZH72S:7)\n" +
" │ │ └─ TableAlias(j4jyp)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ TableAlias(tizhk)\n" +
" │ └─ IndexedTableAccess(WRZVO)\n" +
" │ ├─ index: [WRZVO.id]\n" +
" │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(tizhk.id:1!null)\n" +
" ├─ right-key: TUPLE(scalarSubq1.ETPQV:0)\n" +
" └─ Project\n" +
" ├─ columns: [scalarSubq1.ETPQV:5]\n" +
" └─ TableAlias(scalarSubq1)\n" +
" └─ Table\n" +
" ├─ name: HDDVB\n" +
" └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
PBMRX.id AS id,
PBMRX.TW55N AS TEYBZ,
PBMRX.ZH72S AS FB6N7
FROM
(
SELECT
ZH72S AS ZH72S,
COUNT(ZH72S) AS JTOA7,
MIN(LEA4J) AS BADTB,
SUM(LEA4J) AS FLHXH
FROM
(
SELECT
nd.id AS id,
nd.ZH72S AS ZH72S,
(SELECT COUNT(*) FROM FLQLP WHERE LUEVY = nd.id) AS LEA4J
FROM
E2I7U nd
WHERE nd.ZH72S IS NOT NULL
) WOOJ5
GROUP BY
ZH72S
HAVING
JTOA7 > 1
) CL3DT
INNER JOIN
E2I7U PBMRX
ON
PBMRX.ZH72S IS NOT NULL AND PBMRX.ZH72S = CL3DT.ZH72S
WHERE
CL3DT.BADTB = 0
AND
CL3DT.FLHXH > 0
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [pbmrx.id:0!null as id, pbmrx.TW55N:1!null as TEYBZ, pbmrx.ZH72S:2 as FB6N7]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ pbmrx.ZH72S:2 IS NULL\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ pbmrx.ZH72S:2\n" +
" │ └─ cl3dt.ZH72S:3\n" +
" ├─ Filter\n" +
" │ ├─ NOT\n" +
" │ │ └─ pbmrx.ZH72S:2 IS NULL\n" +
" │ └─ TableAlias(pbmrx)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ ├─ static: [{(NULL, ∞)}]\n" +
" │ └─ columns: [id tw55n zh72s]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(pbmrx.ZH72S:2)\n" +
" ├─ right-key: TUPLE(cl3dt.ZH72S:0)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: cl3dt\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ BADTB:2!null\n" +
" │ │ └─ 0 (tinyint)\n" +
" │ └─ GreaterThan\n" +
" │ ├─ FLHXH:3!null\n" +
" │ └─ 0 (tinyint)\n" +
" └─ Project\n" +
" ├─ columns: [wooj5.ZH72S:3 as ZH72S, count(wooj5.zh72s):0!null as JTOA7, min(wooj5.lea4j):1!null as BADTB, sum(wooj5.lea4j):2!null as FLHXH]\n" +
" └─ Having\n" +
" ├─ GreaterThan\n" +
" │ ├─ JTOA7:5!null\n" +
" │ └─ 1 (tinyint)\n" +
" └─ Project\n" +
" ├─ columns: [count(wooj5.zh72s):0!null, min(wooj5.lea4j):1!null, sum(wooj5.lea4j):2!null, wooj5.ZH72S:3, wooj5.ZH72S:3 as ZH72S, count(wooj5.zh72s):0!null as JTOA7, min(wooj5.lea4j):1!null as BADTB, sum(wooj5.lea4j):2!null as FLHXH]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(wooj5.ZH72S:1), MIN(wooj5.LEA4J:2), SUM(wooj5.LEA4J:2), wooj5.ZH72S:1\n" +
" ├─ group: wooj5.ZH72S:1 as ZH72S\n" +
" └─ SubqueryAlias\n" +
" ├─ name: wooj5\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.id:0!null as id, nd.ZH72S:7 as ZH72S, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(1):20!null as COUNT(*)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: COUNT(1 (bigint))\n" +
" │ ├─ group: \n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ flqlp.LUEVY:20!null\n" +
" │ │ └─ nd.id:0!null\n" +
" │ └─ IndexedTableAccess(FLQLP)\n" +
" │ ├─ index: [FLQLP.LUEVY]\n" +
" │ └─ columns: [luevy]\n" +
" │ as LEA4J]\n" +
" └─ Project\n" +
" ├─ columns: [nd.id:0!null, nd.DKCAJ:1!null, nd.KNG7T:2, nd.TW55N:3!null, nd.QRQXW:4!null, nd.ECXAJ:5!null, nd.FGG57:6, nd.ZH72S:7, nd.FSK67:8!null, nd.XQDYT:9!null, nd.TCE7A:10, nd.IWV2H:11, nd.HPCMS:12!null, nd.N5CC2:13, nd.FHCYT:14, nd.ETAQ7:15, nd.A75X7:16, nd.id:0!null as id, nd.ZH72S:7 as ZH72S, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(1):17!null as COUNT(*)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: COUNT(1 (bigint))\n" +
" │ ├─ group: \n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ flqlp.LUEVY:17!null\n" +
" │ │ └─ nd.id:0!null\n" +
" │ └─ IndexedTableAccess(FLQLP)\n" +
" │ ├─ index: [FLQLP.LUEVY]\n" +
" │ └─ columns: [luevy]\n" +
" │ as LEA4J]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nd.ZH72S:7 IS NULL\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ static: [{(NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT
ct.id AS id,
ci.FTQLQ AS VCGT3,
nd.TW55N AS UWBAI,
aac.BTXC5 AS TPXBU,
ct.V5DPX AS V5DPX,
ct.S3Q3Y AS S3Q3Y,
ct.ZRV3B AS ZRV3B
FROM
FLQLP ct
INNER JOIN
JDLNA ci
ON
ci.id = ct.FZ2R5
INNER JOIN
E2I7U nd
ON
nd.id = ct.LUEVY
INNER JOIN
TPXBU aac
ON
aac.id = ct.M22QN
WHERE
(
ct.OCA7E IS NOT NULL
AND
(
(SELECT I7HCR.SWCQV FROM EPZU6 I7HCR WHERE I7HCR.id = ct.OCA7E) = 1
OR
(SELECT nd.id FROM E2I7U nd WHERE nd.TW55N =
(SELECT I7HCR.FVUCX FROM EPZU6 I7HCR
WHERE I7HCR.id = ct.OCA7E))
<> ct.LUEVY
)
)
OR
(
ct.NRURT IS NOT NULL
AND
ct.NRURT IN
(
SELECT
uct.id AS FDL23
FROM
EPZU6 I7HCR
INNER JOIN
OUBDL uct
ON
uct.FTQLQ = I7HCR.TOFPN
AND
uct.ZH72S = I7HCR.SJYN2
AND
uct.LJLUM = I7HCR.BTXC5
WHERE
I7HCR.SWCQV = 0
AND
I7HCR.id NOT IN (SELECT OCA7E FROM FLQLP WHERE OCA7E IS NOT NULL)
)
)
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [ct.id:0!null as id, ci.FTQLQ:16!null as VCGT3, nd.TW55N:23!null as UWBAI, aac.BTXC5:13 as TPXBU, ct.V5DPX:8!null as V5DPX, ct.S3Q3Y:9!null as S3Q3Y, ct.ZRV3B:10!null as ZRV3B]\n" +
" └─ Filter\n" +
" ├─ Or\n" +
" │ ├─ AND\n" +
" │ │ ├─ NOT\n" +
" │ │ │ └─ ct.OCA7E:6 IS NULL\n" +
" │ │ └─ Or\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [i7hcr.SWCQV:38!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ i7hcr.id:37!null\n" +
" │ │ │ │ │ └─ ct.OCA7E:6\n" +
" │ │ │ │ └─ TableAlias(i7hcr)\n" +
" │ │ │ │ └─ IndexedTableAccess(EPZU6)\n" +
" │ │ │ │ ├─ index: [EPZU6.id]\n" +
" │ │ │ │ └─ columns: [id swcqv]\n" +
" │ │ │ └─ 1 (tinyint)\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [nd.id:37!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ nd.TW55N:40!null\n" +
" │ │ │ │ └─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [i7hcr.FVUCX:55!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ i7hcr.id:54!null\n" +
" │ │ │ │ │ └─ ct.OCA7E:6\n" +
" │ │ │ │ └─ TableAlias(i7hcr)\n" +
" │ │ │ │ └─ IndexedTableAccess(EPZU6)\n" +
" │ │ │ │ ├─ index: [EPZU6.id]\n" +
" │ │ │ │ └─ columns: [id fvucx]\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ └─ ct.LUEVY:2!null\n" +
" │ └─ AND\n" +
" │ ├─ NOT\n" +
" │ │ └─ ct.NRURT:5 IS NULL\n" +
" │ └─ InSubquery\n" +
" │ ├─ left: ct.NRURT:5\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [uct.id:45!null as FDL23]\n" +
" │ └─ HashJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ uct.FTQLQ:46\n" +
" │ │ │ │ └─ i7hcr.TOFPN:38!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ uct.ZH72S:47\n" +
" │ │ │ └─ i7hcr.SJYN2:39!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ uct.LJLUM:50\n" +
" │ │ └─ i7hcr.BTXC5:40!null\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [i7hcr.id:37!null, i7hcr.TOFPN:38!null, i7hcr.SJYN2:39!null, i7hcr.BTXC5:40!null, i7hcr.FVUCX:41!null, i7hcr.SWCQV:42!null, i7hcr.YKSSU:43, i7hcr.FHCYT:44]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ scalarSubq0.OCA7E:45 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ i7hcr.id:37!null\n" +
" │ │ │ └─ scalarSubq0.OCA7E:45\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ i7hcr.SWCQV:42!null\n" +
" │ │ │ │ └─ 0 (tinyint)\n" +
" │ │ │ └─ TableAlias(i7hcr)\n" +
" │ │ │ └─ IndexedTableAccess(EPZU6)\n" +
" │ │ │ ├─ index: [EPZU6.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id tofpn sjyn2 btxc5 fvucx swcqv ykssu fhcyt]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ NOT\n" +
" │ │ │ └─ scalarSubq0.OCA7E:37 IS NULL\n" +
" │ │ └─ TableAlias(scalarSubq0)\n" +
" │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ ├─ index: [FLQLP.OCA7E]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [oca7e]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(i7hcr.TOFPN:38!null, i7hcr.SJYN2:39!null, i7hcr.BTXC5:40!null)\n" +
" │ ├─ right-key: TUPLE(uct.FTQLQ:38, uct.ZH72S:39, uct.LJLUM:42)\n" +
" │ └─ TableAlias(uct)\n" +
" │ └─ Table\n" +
" │ ├─ name: OUBDL\n" +
" │ └─ columns: [id ftqlq zh72s sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e ykssu fhcyt qz6vt]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.id:20!null\n" +
" │ └─ ct.LUEVY:2!null\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ci.id:15!null\n" +
" │ │ └─ ct.FZ2R5:1!null\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.id:12!null\n" +
" │ │ │ └─ ct.M22QN:3!null\n" +
" │ │ ├─ TableAlias(ct)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: FLQLP\n" +
" │ │ │ └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ct.FZ2R5:1!null)\n" +
" │ ├─ right-key: TUPLE(ci.id:0!null)\n" +
" │ └─ TableAlias(ci)\n" +
" │ └─ Table\n" +
" │ ├─ name: JDLNA\n" +
" │ └─ columns: [id ftqlq fwwiq o3qxw fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(ct.LUEVY:2!null)\n" +
" ├─ right-key: TUPLE(nd.id:0!null)\n" +
" └─ TableAlias(nd)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT
uct.*
FROM
(
SELECT DISTINCT
YLKSY.id AS FDL23
FROM
OUBDL YLKSY
INNER JOIN
JDLNA ci
ON
ci.FTQLQ = YLKSY.FTQLQ
INNER JOIN
E2I7U nd
ON
nd.ZH72S = YLKSY.ZH72S
INNER JOIN
TPXBU aac
ON
aac.BTXC5 = YLKSY.LJLUM
WHERE
YLKSY.LJLUM NOT LIKE '%|%'
AND
YLKSY.id NOT IN (SELECT NRURT FROM FLQLP WHERE NRURT IS NOT NULL)
) FZWBD
INNER JOIN
OUBDL uct
ON
uct.id = FZWBD.FDL23
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [uct.id:1!null, uct.FTQLQ:2, uct.ZH72S:3, uct.SFJ6L:4, uct.V5DPX:5, uct.LJLUM:6, uct.IDPK7:7, uct.NO52D:8, uct.ZRV3B:9, uct.VYO5E:10, uct.YKSSU:11, uct.FHCYT:12, uct.QZ6VT:13]\n" +
" └─ LookupJoin\n" +
" ├─ Eq\n" +
" │ ├─ uct.id:1!null\n" +
" │ └─ fzwbd.FDL23:0!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fzwbd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ylksy.id:3!null as FDL23]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ nd.ZH72S:28\n" +
" │ │ └─ ylksy.ZH72S:5\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ ci.FTQLQ:17!null\n" +
" │ │ │ └─ ylksy.FTQLQ:4\n" +
" │ │ ├─ Project\n" +
" │ │ │ ├─ columns: [aac.id:13!null, aac.BTXC5:14, aac.FHCYT:15, ylksy.id:0!null, ylksy.FTQLQ:1, ylksy.ZH72S:2, ylksy.SFJ6L:3, ylksy.V5DPX:4, ylksy.LJLUM:5, ylksy.IDPK7:6, ylksy.NO52D:7, ylksy.ZRV3B:8, ylksy.VYO5E:9, ylksy.YKSSU:10, ylksy.FHCYT:11, ylksy.QZ6VT:12]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ scalarSubq0.NRURT:16 IS NULL\n" +
" │ │ │ └─ LeftOuterHashJoinExcludeNulls\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ylksy.id:0!null\n" +
" │ │ │ │ └─ scalarSubq0.NRURT:16\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ aac.BTXC5:14\n" +
" │ │ │ │ │ └─ ylksy.LJLUM:5\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ ylksy.LJLUM LIKE '%|%'\n" +
" │ │ │ │ │ └─ TableAlias(ylksy)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: OUBDL\n" +
" │ │ │ │ │ └─ columns: [id ftqlq zh72s sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e ykssu fhcyt qz6vt]\n" +
" │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(ylksy.id:0!null)\n" +
" │ │ │ ├─ right-key: TUPLE(scalarSubq0.NRURT:0)\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [scalarSubq0.NRURT:5]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ scalarSubq0.NRURT:5 IS NULL\n" +
" │ │ │ └─ TableAlias(scalarSubq0)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: FLQLP\n" +
" │ │ │ └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(ylksy.FTQLQ:4)\n" +
" │ │ ├─ right-key: TUPLE(ci.FTQLQ:1!null)\n" +
" │ │ └─ TableAlias(ci)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: JDLNA\n" +
" │ │ └─ columns: [id ftqlq fwwiq o3qxw fhcyt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ylksy.ZH72S:5)\n" +
" │ ├─ right-key: TUPLE(nd.ZH72S:7)\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" └─ TableAlias(uct)\n" +
" └─ IndexedTableAccess(OUBDL)\n" +
" ├─ index: [OUBDL.id]\n" +
" └─ columns: [id ftqlq zh72s sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e ykssu fhcyt qz6vt]\n" +
"",
},
{
Query: `
SELECT
ct.id AS id,
ci.FTQLQ AS VCGT3,
nd.TW55N AS UWBAI,
aac.BTXC5 AS TPXBU,
ct.V5DPX AS V5DPX,
ct.S3Q3Y AS S3Q3Y,
ct.ZRV3B AS ZRV3B
FROM
FLQLP ct
INNER JOIN
HU5A5 TVTJS
ON
TVTJS.id = ct.XMM6Q
INNER JOIN
JDLNA ci
ON
ci.id = ct.FZ2R5
INNER JOIN
E2I7U nd
ON
nd.id = ct.LUEVY
INNER JOIN
TPXBU aac
ON
aac.id = ct.M22QN
WHERE
TVTJS.SWCQV = 1
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [ct.id:0!null as id, ci.FTQLQ:13!null as VCGT3, nd.TW55N:15!null as UWBAI, aac.BTXC5:9 as TPXBU, ct.V5DPX:5!null as V5DPX, ct.S3Q3Y:6!null as S3Q3Y, ct.ZRV3B:7!null as ZRV3B]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ tvtjs.SWCQV:11!null\n" +
" │ └─ 1 (tinyint)\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.id:14!null\n" +
" │ └─ ct.LUEVY:2!null\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ci.id:12!null\n" +
" │ │ └─ ct.FZ2R5:1!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ tvtjs.id:10!null\n" +
" │ │ │ └─ ct.XMM6Q:4\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ aac.id:8!null\n" +
" │ │ │ │ └─ ct.M22QN:3!null\n" +
" │ │ │ ├─ TableAlias(ct)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: FLQLP\n" +
" │ │ │ │ └─ columns: [id fz2r5 luevy m22qn xmm6q v5dpx s3q3y zrv3b]\n" +
" │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ └─ columns: [id btxc5]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(ct.XMM6Q:4)\n" +
" │ │ ├─ right-key: TUPLE(tvtjs.id:0!null)\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ tvtjs.SWCQV:1!null\n" +
" │ │ │ └─ 1 (tinyint)\n" +
" │ │ └─ TableAlias(tvtjs)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HU5A5\n" +
" │ │ └─ columns: [id swcqv]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ct.FZ2R5:1!null)\n" +
" │ ├─ right-key: TUPLE(ci.id:0!null)\n" +
" │ └─ TableAlias(ci)\n" +
" │ └─ Table\n" +
" │ ├─ name: JDLNA\n" +
" │ └─ columns: [id ftqlq]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(ct.LUEVY:2!null)\n" +
" ├─ right-key: TUPLE(nd.id:0!null)\n" +
" └─ TableAlias(nd)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n]\n" +
"",
},
{
Query: `
SELECT
*
FROM
HU5A5
WHERE
id NOT IN
(
SELECT
XMM6Q
FROM
FLQLP
WHERE XMM6Q IS NOT NULL
)
AND
SWCQV = 0
`,
ExpectedPlan: "Filter\n" +
" ├─ Eq\n" +
" │ ├─ hu5a5.SWCQV:10!null\n" +
" │ └─ 0 (tinyint)\n" +
" └─ Project\n" +
" ├─ columns: [hu5a5.id:0!null, HU5A5.TOFPN:1!null, HU5A5.I3VTA:2!null, HU5A5.SFJ6L:3, HU5A5.V5DPX:4!null, HU5A5.LJLUM:5!null, HU5A5.IDPK7:6!null, HU5A5.NO52D:7!null, HU5A5.ZRV3B:8!null, HU5A5.VYO5E:9, HU5A5.SWCQV:10!null, HU5A5.YKSSU:11, HU5A5.FHCYT:12]\n" +
" └─ Filter\n" +
" ├─ scalarSubq0.XMM6Q:13 IS NULL\n" +
" └─ LeftOuterMergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ hu5a5.id:0!null\n" +
" │ └─ scalarSubq0.XMM6Q:13\n" +
" ├─ IndexedTableAccess(HU5A5)\n" +
" │ ├─ index: [HU5A5.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id tofpn i3vta sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e swcqv ykssu fhcyt]\n" +
" └─ Project\n" +
" ├─ columns: [scalarSubq0.XMM6Q:7]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ scalarSubq0.XMM6Q:7 IS NULL\n" +
" └─ TableAlias(scalarSubq0)\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.XMM6Q]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
"",
},
{
Query: `
SELECT
rn.id AS id,
CONCAT(NSPLT.TW55N, 'FDNCN', LQNCX.TW55N) AS X37NA,
CONCAT(XLZA5.TW55N, 'FDNCN', AFJMD.TW55N) AS THWCS,
rn.HVHRZ AS HVHRZ
FROM
QYWQD rn
INNER JOIN
NOXN3 PV6R5
ON
rn.WNUNU = PV6R5.id
INNER JOIN
NOXN3 ZYUTC
ON
rn.HHVLX = ZYUTC.id
INNER JOIN
E2I7U NSPLT
ON
NSPLT.id = PV6R5.BRQP2
INNER JOIN
E2I7U LQNCX
ON
LQNCX.id = PV6R5.FFTBJ
INNER JOIN
E2I7U XLZA5
ON
XLZA5.id = ZYUTC.BRQP2
INNER JOIN
E2I7U AFJMD
ON
AFJMD.id = ZYUTC.FFTBJ
WHERE
PV6R5.FFTBJ <> ZYUTC.BRQP2
OR
PV6R5.NUMK2 <> 1
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [rn.id:8!null as id, concat(nsplt.TW55N:1!null,FDNCN (longtext),lqncx.TW55N:7!null) as X37NA, concat(xlza5.TW55N:13!null,FDNCN (longtext),afjmd.TW55N:18!null) as THWCS, rn.HVHRZ:11!null as HVHRZ]\n" +
" └─ Filter\n" +
" ├─ Or\n" +
" │ ├─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ pv6r5.FFTBJ:4!null\n" +
" │ │ └─ zyutc.BRQP2:15!null\n" +
" │ └─ NOT\n" +
" │ └─ Eq\n" +
" │ ├─ pv6r5.NUMK2:5!null\n" +
" │ └─ 1 (tinyint)\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ rn.HHVLX:10!null\n" +
" │ └─ zyutc.id:14!null\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ rn.WNUNU:9!null\n" +
" │ │ └─ pv6r5.id:2!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ lqncx.id:6!null\n" +
" │ │ │ └─ pv6r5.FFTBJ:4!null\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ nsplt.id:0!null\n" +
" │ │ │ │ └─ pv6r5.BRQP2:3!null\n" +
" │ │ │ ├─ TableAlias(nsplt)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id tw55n]\n" +
" │ │ │ └─ TableAlias(pv6r5)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj numk2]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(pv6r5.FFTBJ:4!null)\n" +
" │ │ ├─ right-key: TUPLE(lqncx.id:0!null)\n" +
" │ │ └─ TableAlias(lqncx)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(pv6r5.id:2!null)\n" +
" │ ├─ right-key: TUPLE(rn.WNUNU:1!null)\n" +
" │ └─ TableAlias(rn)\n" +
" │ └─ Table\n" +
" │ ├─ name: QYWQD\n" +
" │ └─ columns: [id wnunu hhvlx hvhrz]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(rn.HHVLX:10!null)\n" +
" ├─ right-key: TUPLE(zyutc.id:2!null)\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ afjmd.id:17!null\n" +
" │ └─ zyutc.FFTBJ:16!null\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ xlza5.id:12!null\n" +
" │ │ └─ zyutc.BRQP2:15!null\n" +
" │ ├─ TableAlias(xlza5)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ TableAlias(zyutc)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id brqp2 fftbj]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(zyutc.FFTBJ:16!null)\n" +
" ├─ right-key: TUPLE(afjmd.id:0!null)\n" +
" └─ TableAlias(afjmd)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n]\n" +
"",
},
{
Query: `
SELECT
sn.id AS DRIWM,
CONCAT(OE56M.TW55N, 'FDNCN', CGFRZ.TW55N) AS GRVSE,
SKPM6.id AS JIEVY,
CONCAT(V5SAY.TW55N, 'FDNCN', FQTHF.TW55N) AS ENCM3,
1.0 AS OHD3R
FROM
NOXN3 sn
INNER JOIN
NOXN3 SKPM6
ON
SKPM6.BRQP2 = sn.FFTBJ
LEFT JOIN
QYWQD rn
ON
rn.WNUNU = sn.id
AND
rn.HHVLX = SKPM6.id
INNER JOIN
E2I7U OE56M
ON
OE56M.id = sn.BRQP2
INNER JOIN
E2I7U CGFRZ
ON
CGFRZ.id = sn.FFTBJ
INNER JOIN
E2I7U V5SAY
ON
V5SAY.id = SKPM6.BRQP2
INNER JOIN
E2I7U FQTHF
ON
FQTHF.id = SKPM6.FFTBJ
WHERE
sn.NUMK2 = 1
AND
rn.WNUNU IS NULL AND rn.HHVLX IS NULL
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [sn.id:7!null as DRIWM, concat(oe56m.TW55N:6!null,FDNCN (longtext),cgfrz.TW55N:16!null) as GRVSE, skpm6.id:2!null as JIEVY, concat(v5say.TW55N:14!null,FDNCN (longtext),fqthf.TW55N:1!null) as ENCM3, 1 (decimal(2,1)) as OHD3R]\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ rn.WNUNU:11!null IS NULL\n" +
" │ └─ rn.HHVLX:12!null IS NULL\n" +
" └─ HashJoin\n" +
" ├─ AND\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ cgfrz.id:15!null\n" +
" │ │ │ │ └─ sn.FFTBJ:9!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ v5say.id:13!null\n" +
" │ │ │ └─ skpm6.BRQP2:3!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ sn.FFTBJ:9!null\n" +
" │ │ └─ v5say.id:13!null\n" +
" │ └─ Eq\n" +
" │ ├─ skpm6.BRQP2:3!null\n" +
" │ └─ cgfrz.id:15!null\n" +
" ├─ LeftOuterHashJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ rn.WNUNU:11!null\n" +
" │ │ │ └─ sn.id:7!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ rn.HHVLX:12!null\n" +
" │ │ └─ skpm6.id:2!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ skpm6.BRQP2:3!null\n" +
" │ │ │ └─ sn.FFTBJ:9!null\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ fqthf.id:0!null\n" +
" │ │ │ │ └─ skpm6.FFTBJ:4!null\n" +
" │ │ │ ├─ TableAlias(fqthf)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id tw55n]\n" +
" │ │ │ └─ TableAlias(skpm6)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(skpm6.BRQP2:3!null)\n" +
" │ │ ├─ right-key: TUPLE(sn.FFTBJ:4!null)\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ oe56m.id:5!null\n" +
" │ │ │ └─ sn.BRQP2:8!null\n" +
" │ │ ├─ TableAlias(oe56m)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id tw55n]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ sn.NUMK2:3!null\n" +
" │ │ │ └─ 1 (tinyint)\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id brqp2 fftbj numk2]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(sn.id:7!null, skpm6.id:2!null)\n" +
" │ ├─ right-key: TUPLE(rn.WNUNU:0!null, rn.HHVLX:1!null)\n" +
" │ └─ TableAlias(rn)\n" +
" │ └─ Table\n" +
" │ ├─ name: QYWQD\n" +
" │ └─ columns: [wnunu hhvlx]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(sn.FFTBJ:9!null, skpm6.BRQP2:3!null, sn.FFTBJ:9!null, skpm6.BRQP2:3!null)\n" +
" ├─ right-key: TUPLE(cgfrz.id:2!null, v5say.id:0!null, v5say.id:0!null, cgfrz.id:2!null)\n" +
" └─ MergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ v5say.id:13!null\n" +
" │ └─ cgfrz.id:15!null\n" +
" ├─ TableAlias(v5say)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ TableAlias(cgfrz)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id tw55n]\n" +
"",
},
{
Query: `
SELECT
id, FGG57, SSHPJ, SFJ6L
FROM
TDRVG
WHERE
id IN
(SELECT
(SELECT id FROM TDRVG WHERE SSHPJ = S7BYT.SSHPJ ORDER BY id LIMIT 1) AS id
FROM
(SELECT DISTINCT
S5KBM.SSHPJ AS SSHPJ,
S5KBM.SFJ6L AS SFJ6L
FROM
TDRVG S5KBM
INNER JOIN
E2I7U nd
ON
nd.FGG57 = S5KBM.FGG57) S7BYT
WHERE
S7BYT.SSHPJ NOT IN (SELECT SSHPJ FROM WE72E)
)
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [tdrvg.id:1!null, tdrvg.FGG57:2!null, tdrvg.SSHPJ:3!null, tdrvg.SFJ6L:4!null]\n" +
" └─ LookupJoin\n" +
" ├─ Eq\n" +
" │ ├─ tdrvg.id:1!null\n" +
" │ └─ scalarSubq0.id:0\n" +
" ├─ Distinct\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: scalarSubq0\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tdrvg.id:3!null]\n" +
" │ │ └─ Sort(tdrvg.id:3!null ASC nullsFirst)\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ tdrvg.SSHPJ:5!null\n" +
" │ │ │ └─ s7byt.SSHPJ:0!null\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.SSHPJ]\n" +
" │ │ └─ columns: [id fgg57 sshpj sfj6l zh72s]\n" +
" │ │ as id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [s7byt.SSHPJ:0!null, s7byt.SFJ6L:1!null, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tdrvg.id:2!null]\n" +
" │ │ └─ Sort(tdrvg.id:2!null ASC nullsFirst)\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ tdrvg.SSHPJ:4!null\n" +
" │ │ │ └─ s7byt.SSHPJ:0!null\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.SSHPJ]\n" +
" │ │ └─ columns: [id fgg57 sshpj sfj6l zh72s]\n" +
" │ │ as id]\n" +
" │ └─ AntiLookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ s7byt.SSHPJ:0!null\n" +
" │ │ └─ scalarSubq0.SSHPJ:4!null\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: s7byt\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [s5kbm.SSHPJ:19!null as SSHPJ, s5kbm.SFJ6L:20!null as SFJ6L]\n" +
" │ │ └─ LookupJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ nd.FGG57:6\n" +
" │ │ │ └─ s5kbm.FGG57:18!null\n" +
" │ │ ├─ TableAlias(nd)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ └─ TableAlias(s5kbm)\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.FGG57]\n" +
" │ │ └─ columns: [id fgg57 sshpj sfj6l zh72s]\n" +
" │ └─ TableAlias(scalarSubq0)\n" +
" │ └─ IndexedTableAccess(WE72E)\n" +
" │ ├─ index: [WE72E.SSHPJ]\n" +
" │ └─ columns: [id qz7e7 sshpj fhcyt]\n" +
" └─ IndexedTableAccess(TDRVG)\n" +
" ├─ index: [TDRVG.id]\n" +
" └─ columns: [id fgg57 sshpj sfj6l zh72s]\n" +
"",
},
{
Query: `
SELECT
PBMRX.id AS id,
PBMRX.TW55N AS UYOGN,
PBMRX.ZH72S AS H4JEA
FROM
(
SELECT
ZH72S AS ZH72S,
COUNT(ZH72S) AS JTOA7,
MIN(TJ66D) AS B4OVH,
SUM(TJ66D) AS R5CKX
FROM
(
SELECT
nd.id AS id,
nd.ZH72S AS ZH72S,
(SELECT COUNT(*) FROM AMYXQ WHERE LUEVY = nd.id) AS TJ66D
FROM
E2I7U nd
WHERE nd.ZH72S IS NOT NULL
) TQ57W
GROUP BY
ZH72S
HAVING
JTOA7 > 1
) CL3DT
INNER JOIN
E2I7U PBMRX
ON
PBMRX.ZH72S IS NOT NULL AND PBMRX.ZH72S = CL3DT.ZH72S
WHERE
CL3DT.B4OVH = 0
AND
CL3DT.R5CKX > 0
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [pbmrx.id:0!null as id, pbmrx.TW55N:1!null as UYOGN, pbmrx.ZH72S:2 as H4JEA]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ pbmrx.ZH72S:2 IS NULL\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ pbmrx.ZH72S:2\n" +
" │ └─ cl3dt.ZH72S:3\n" +
" ├─ Filter\n" +
" │ ├─ NOT\n" +
" │ │ └─ pbmrx.ZH72S:2 IS NULL\n" +
" │ └─ TableAlias(pbmrx)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ ├─ static: [{(NULL, ∞)}]\n" +
" │ └─ columns: [id tw55n zh72s]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(pbmrx.ZH72S:2)\n" +
" ├─ right-key: TUPLE(cl3dt.ZH72S:0)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: cl3dt\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ B4OVH:2!null\n" +
" │ │ └─ 0 (tinyint)\n" +
" │ └─ GreaterThan\n" +
" │ ├─ R5CKX:3!null\n" +
" │ └─ 0 (tinyint)\n" +
" └─ Project\n" +
" ├─ columns: [tq57w.ZH72S:3 as ZH72S, count(tq57w.zh72s):0!null as JTOA7, min(tq57w.tj66d):1!null as B4OVH, sum(tq57w.tj66d):2!null as R5CKX]\n" +
" └─ Having\n" +
" ├─ GreaterThan\n" +
" │ ├─ JTOA7:5!null\n" +
" │ └─ 1 (tinyint)\n" +
" └─ Project\n" +
" ├─ columns: [count(tq57w.zh72s):0!null, min(tq57w.tj66d):1!null, sum(tq57w.tj66d):2!null, tq57w.ZH72S:3, tq57w.ZH72S:3 as ZH72S, count(tq57w.zh72s):0!null as JTOA7, min(tq57w.tj66d):1!null as B4OVH, sum(tq57w.tj66d):2!null as R5CKX]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(tq57w.ZH72S:1), MIN(tq57w.TJ66D:2), SUM(tq57w.TJ66D:2), tq57w.ZH72S:1\n" +
" ├─ group: tq57w.ZH72S:1 as ZH72S\n" +
" └─ SubqueryAlias\n" +
" ├─ name: tq57w\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.id:0!null as id, nd.ZH72S:7 as ZH72S, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(1):20!null as COUNT(*)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: COUNT(1 (bigint))\n" +
" │ ├─ group: \n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ amyxq.LUEVY:20!null\n" +
" │ │ └─ nd.id:0!null\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ └─ columns: [luevy]\n" +
" │ as TJ66D]\n" +
" └─ Project\n" +
" ├─ columns: [nd.id:0!null, nd.DKCAJ:1!null, nd.KNG7T:2, nd.TW55N:3!null, nd.QRQXW:4!null, nd.ECXAJ:5!null, nd.FGG57:6, nd.ZH72S:7, nd.FSK67:8!null, nd.XQDYT:9!null, nd.TCE7A:10, nd.IWV2H:11, nd.HPCMS:12!null, nd.N5CC2:13, nd.FHCYT:14, nd.ETAQ7:15, nd.A75X7:16, nd.id:0!null as id, nd.ZH72S:7 as ZH72S, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(1):17!null as COUNT(*)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: COUNT(1 (bigint))\n" +
" │ ├─ group: \n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ amyxq.LUEVY:17!null\n" +
" │ │ └─ nd.id:0!null\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ └─ columns: [luevy]\n" +
" │ as TJ66D]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nd.ZH72S:7 IS NULL\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ static: [{(NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT /*+ JOIN_ORDER(ufc, nd, cla) */ DISTINCT
ufc.*
FROM
SISUT ufc
INNER JOIN
E2I7U nd
ON
nd.ZH72S = ufc.ZH72S
INNER JOIN
YK2GW cla
ON
cla.FTQLQ = ufc.T4IBQ
WHERE
nd.ZH72S IS NOT NULL
AND
ufc.id NOT IN (SELECT KKGN5 FROM AMYXQ)
`,
ExpectedPlan: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ufc.id:0!null, ufc.T4IBQ:1, ufc.ZH72S:2, ufc.AMYXQ:3, ufc.KTNZ2:4, ufc.HIID2:5, ufc.DN3OQ:6, ufc.VVKNB:7, ufc.SH7TP:8, ufc.SRZZO:9, ufc.QZ6VT:10]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nd.ZH72S:48 IS NULL\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.ZH72S:48\n" +
" │ └─ ufc.ZH72S:2\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ cla.FTQLQ:12!null\n" +
" │ │ └─ ufc.T4IBQ:1\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [ufc.id:0!null, ufc.T4IBQ:1, ufc.ZH72S:2, ufc.AMYXQ:3, ufc.KTNZ2:4, ufc.HIID2:5, ufc.DN3OQ:6, ufc.VVKNB:7, ufc.SH7TP:8, ufc.SRZZO:9, ufc.QZ6VT:10]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ scalarSubq0.KKGN5:11 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ ufc.id:0!null\n" +
" │ │ │ └─ scalarSubq0.KKGN5:11\n" +
" │ │ ├─ TableAlias(ufc)\n" +
" │ │ │ └─ IndexedTableAccess(SISUT)\n" +
" │ │ │ ├─ index: [SISUT.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id t4ibq zh72s amyxq ktnz2 hiid2 dn3oq vvknb sh7tp srzzo qz6vt]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [scalarSubq0.KKGN5:7]\n" +
" │ │ └─ TableAlias(scalarSubq0)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.KKGN5]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ufc.T4IBQ:1)\n" +
" │ ├─ right-key: TUPLE(cla.FTQLQ:1!null)\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ Table\n" +
" │ ├─ name: YK2GW\n" +
" │ └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(ufc.ZH72S:2)\n" +
" ├─ right-key: TUPLE(nd.ZH72S:7)\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nd.ZH72S:7 IS NULL\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ static: [{(NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT DISTINCT
ufc.*
FROM
SISUT ufc
INNER JOIN
E2I7U nd
ON
nd.ZH72S = ufc.ZH72S
INNER JOIN
YK2GW cla
ON
cla.FTQLQ = ufc.T4IBQ
WHERE
nd.ZH72S IS NOT NULL
AND
ufc.id NOT IN (SELECT KKGN5 FROM AMYXQ)
`,
ExpectedPlan: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ufc.id:0!null, ufc.T4IBQ:1, ufc.ZH72S:2, ufc.AMYXQ:3, ufc.KTNZ2:4, ufc.HIID2:5, ufc.DN3OQ:6, ufc.VVKNB:7, ufc.SH7TP:8, ufc.SRZZO:9, ufc.QZ6VT:10]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nd.ZH72S:48 IS NULL\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.ZH72S:48\n" +
" │ └─ ufc.ZH72S:2\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ cla.FTQLQ:12!null\n" +
" │ │ └─ ufc.T4IBQ:1\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [ufc.id:0!null, ufc.T4IBQ:1, ufc.ZH72S:2, ufc.AMYXQ:3, ufc.KTNZ2:4, ufc.HIID2:5, ufc.DN3OQ:6, ufc.VVKNB:7, ufc.SH7TP:8, ufc.SRZZO:9, ufc.QZ6VT:10]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ scalarSubq0.KKGN5:11 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ ufc.id:0!null\n" +
" │ │ │ └─ scalarSubq0.KKGN5:11\n" +
" │ │ ├─ TableAlias(ufc)\n" +
" │ │ │ └─ IndexedTableAccess(SISUT)\n" +
" │ │ │ ├─ index: [SISUT.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id t4ibq zh72s amyxq ktnz2 hiid2 dn3oq vvknb sh7tp srzzo qz6vt]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [scalarSubq0.KKGN5:7]\n" +
" │ │ └─ TableAlias(scalarSubq0)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.KKGN5]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ufc.T4IBQ:1)\n" +
" │ ├─ right-key: TUPLE(cla.FTQLQ:1!null)\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ Table\n" +
" │ ├─ name: YK2GW\n" +
" │ └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(ufc.ZH72S:2)\n" +
" ├─ right-key: TUPLE(nd.ZH72S:7)\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nd.ZH72S:7 IS NULL\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ static: [{(NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT
ums.*
FROM
FG26Y ums
INNER JOIN
YK2GW cla
ON
cla.FTQLQ = ums.T4IBQ
WHERE
ums.id NOT IN (SELECT JOGI6 FROM SZQWJ)
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [ums.id:0!null, ums.T4IBQ:1, ums.ner:2, ums.ber:3, ums.hr:4, ums.mmr:5, ums.QZ6VT:6]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ cla.FTQLQ:8!null\n" +
" │ └─ ums.T4IBQ:1\n" +
" ├─ Project\n" +
" │ ├─ columns: [ums.id:0!null, ums.T4IBQ:1, ums.ner:2, ums.ber:3, ums.hr:4, ums.mmr:5, ums.QZ6VT:6]\n" +
" │ └─ Filter\n" +
" │ ├─ scalarSubq0.JOGI6:7 IS NULL\n" +
" │ └─ LeftOuterMergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ ums.id:0!null\n" +
" │ │ └─ scalarSubq0.JOGI6:7\n" +
" │ ├─ TableAlias(ums)\n" +
" │ │ └─ IndexedTableAccess(FG26Y)\n" +
" │ │ ├─ index: [FG26Y.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id t4ibq ner ber hr mmr qz6vt]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [scalarSubq0.JOGI6:4]\n" +
" │ └─ TableAlias(scalarSubq0)\n" +
" │ └─ IndexedTableAccess(SZQWJ)\n" +
" │ ├─ index: [SZQWJ.JOGI6]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id gxlub ch3fr d237e jogi6]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(ums.T4IBQ:1)\n" +
" ├─ right-key: TUPLE(cla.FTQLQ:1!null)\n" +
" └─ TableAlias(cla)\n" +
" └─ Table\n" +
" ├─ name: YK2GW\n" +
" └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
mf.id AS id,
cla.FTQLQ AS T4IBQ,
nd.TW55N AS UWBAI,
aac.BTXC5 AS TPXBU,
mf.FSDY2 AS FSDY2
FROM
HGMQ6 mf
INNER JOIN
THNTS bs
ON
bs.id = mf.GXLUB
INNER JOIN
YK2GW cla
ON
cla.id = bs.IXUXU
INNER JOIN
E2I7U nd
ON
nd.id = mf.LUEVY
INNER JOIN
TPXBU aac
ON
aac.id = mf.M22QN
WHERE
(
mf.QQV4M IS NOT NULL
AND
(
(SELECT TJ5D2.SWCQV FROM SZW6V TJ5D2 WHERE TJ5D2.id = mf.QQV4M) = 1
OR
(SELECT nd.id FROM E2I7U nd WHERE nd.TW55N =
(SELECT TJ5D2.H4DMT FROM SZW6V TJ5D2
WHERE TJ5D2.id = mf.QQV4M))
<> mf.LUEVY
)
)
OR
(
mf.TEUJA IS NOT NULL
AND
mf.TEUJA IN
(
SELECT
umf.id AS ORB3K
FROM
SZW6V TJ5D2
INNER JOIN
NZKPM umf
ON
umf.T4IBQ = TJ5D2.T4IBQ
AND
umf.FGG57 = TJ5D2.V7UFH
AND
umf.SYPKF = TJ5D2.SYPKF
WHERE
TJ5D2.SWCQV = 0
AND
TJ5D2.id NOT IN (SELECT QQV4M FROM HGMQ6 WHERE QQV4M IS NOT NULL)
)
)
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [mf.id:17!null as id, cla.FTQLQ:38!null as T4IBQ, nd.TW55N:3!null as UWBAI, aac.BTXC5:35 as TPXBU, mf.FSDY2:27!null as FSDY2]\n" +
" └─ Filter\n" +
" ├─ Or\n" +
" │ ├─ AND\n" +
" │ │ ├─ NOT\n" +
" │ │ │ └─ mf.QQV4M:32 IS NULL\n" +
" │ │ └─ Or\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [tj5d2.SWCQV:72!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ tj5d2.id:71!null\n" +
" │ │ │ │ │ └─ mf.QQV4M:32\n" +
" │ │ │ │ └─ TableAlias(tj5d2)\n" +
" │ │ │ │ └─ IndexedTableAccess(SZW6V)\n" +
" │ │ │ │ ├─ index: [SZW6V.id]\n" +
" │ │ │ │ └─ columns: [id swcqv]\n" +
" │ │ │ └─ 1 (tinyint)\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [nd.id:71!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ nd.TW55N:74!null\n" +
" │ │ │ │ └─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [tj5d2.H4DMT:89!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ tj5d2.id:88!null\n" +
" │ │ │ │ │ └─ mf.QQV4M:32\n" +
" │ │ │ │ └─ TableAlias(tj5d2)\n" +
" │ │ │ │ └─ IndexedTableAccess(SZW6V)\n" +
" │ │ │ │ ├─ index: [SZW6V.id]\n" +
" │ │ │ │ └─ columns: [id h4dmt]\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ └─ mf.LUEVY:19!null\n" +
" │ └─ AND\n" +
" │ ├─ NOT\n" +
" │ │ └─ mf.TEUJA:31 IS NULL\n" +
" │ └─ InSubquery\n" +
" │ ├─ left: mf.TEUJA:31\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [umf.id:79!null as ORB3K]\n" +
" │ └─ AntiLookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ tj5d2.id:71!null\n" +
" │ │ └─ scalarSubq0.QQV4M:104\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ umf.T4IBQ:80\n" +
" │ │ │ │ │ └─ tj5d2.T4IBQ:72!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ umf.FGG57:81\n" +
" │ │ │ │ └─ tj5d2.V7UFH:73!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ umf.SYPKF:87\n" +
" │ │ │ └─ tj5d2.SYPKF:74!null\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ tj5d2.SWCQV:76!null\n" +
" │ │ │ │ └─ 0 (tinyint)\n" +
" │ │ │ └─ TableAlias(tj5d2)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SZW6V\n" +
" │ │ │ └─ columns: [id t4ibq v7ufh sypkf h4dmt swcqv ykssu fhcyt]\n" +
" │ │ └─ TableAlias(umf)\n" +
" │ │ └─ IndexedTableAccess(NZKPM)\n" +
" │ │ ├─ index: [NZKPM.FGG57]\n" +
" │ │ └─ columns: [id t4ibq fgg57 sshpj nla6o sfj6l tjpt7 arn5p sypkf ivfmk ide43 az6sp fsdy2 xosd4 hmw4h s76om vaf zroh6 qcgts lnfm6 tvawl hdlcl bhhw6 fhcyt qz6vt]\n" +
" │ └─ Filter\n" +
" │ ├─ NOT\n" +
" │ │ └─ scalarSubq0.QQV4M:71 IS NULL\n" +
" │ └─ TableAlias(scalarSubq0)\n" +
" │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ ├─ index: [HGMQ6.QQV4M]\n" +
" │ └─ columns: [qqv4m]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ bs.id:67!null\n" +
" │ └─ mf.GXLUB:18!null\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ aac.id:34!null\n" +
" │ │ └─ mf.M22QN:20!null\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ nd.id:0!null\n" +
" │ │ │ └─ mf.LUEVY:19!null\n" +
" │ │ ├─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ └─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.M22QN:20!null)\n" +
" │ ├─ right-key: TUPLE(aac.id:0!null)\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXBU\n" +
" │ └─ columns: [id btxc5 fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(mf.GXLUB:18!null)\n" +
" ├─ right-key: TUPLE(bs.id:30!null)\n" +
" └─ MergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ cla.id:37!null\n" +
" │ └─ bs.IXUXU:69\n" +
" ├─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
" └─ TableAlias(bs)\n" +
" └─ IndexedTableAccess(THNTS)\n" +
" ├─ index: [THNTS.IXUXU]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id nfryn ixuxu fhcyt]\n" +
"",
},
{
Query: `
SELECT
umf.*
FROM
NZKPM umf
INNER JOIN
E2I7U nd
ON
nd.FGG57 = umf.FGG57
INNER JOIN
YK2GW cla
ON
cla.FTQLQ = umf.T4IBQ
WHERE
nd.FGG57 IS NOT NULL
AND
umf.ARN5P <> 'N/A'
AND
umf.id NOT IN (SELECT TEUJA FROM HGMQ6)
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [umf.id:0!null, umf.T4IBQ:1, umf.FGG57:2, umf.SSHPJ:3, umf.NLA6O:4, umf.SFJ6L:5, umf.TJPT7:6, umf.ARN5P:7, umf.SYPKF:8, umf.IVFMK:9, umf.IDE43:10, umf.AZ6SP:11, umf.FSDY2:12, umf.XOSD4:13, umf.HMW4H:14, umf.S76OM:15, umf.vaf:16, umf.ZROH6:17, umf.QCGTS:18, umf.LNFM6:19, umf.TVAWL:20, umf.HDLCL:21, umf.BHHW6:22, umf.FHCYT:23, umf.QZ6VT:24]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nd.FGG57:61 IS NULL\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.FGG57:61\n" +
" │ └─ umf.FGG57:2\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ cla.FTQLQ:26!null\n" +
" │ │ └─ umf.T4IBQ:1\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [umf.id:0!null, umf.T4IBQ:1, umf.FGG57:2, umf.SSHPJ:3, umf.NLA6O:4, umf.SFJ6L:5, umf.TJPT7:6, umf.ARN5P:7, umf.SYPKF:8, umf.IVFMK:9, umf.IDE43:10, umf.AZ6SP:11, umf.FSDY2:12, umf.XOSD4:13, umf.HMW4H:14, umf.S76OM:15, umf.vaf:16, umf.ZROH6:17, umf.QCGTS:18, umf.LNFM6:19, umf.TVAWL:20, umf.HDLCL:21, umf.BHHW6:22, umf.FHCYT:23, umf.QZ6VT:24]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ scalarSubq0.TEUJA:25 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ umf.id:0!null\n" +
" │ │ │ └─ scalarSubq0.TEUJA:25\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ umf.ARN5P:7\n" +
" │ │ │ │ └─ N/A (longtext)\n" +
" │ │ │ └─ TableAlias(umf)\n" +
" │ │ │ └─ IndexedTableAccess(NZKPM)\n" +
" │ │ │ ├─ index: [NZKPM.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id t4ibq fgg57 sshpj nla6o sfj6l tjpt7 arn5p sypkf ivfmk ide43 az6sp fsdy2 xosd4 hmw4h s76om vaf zroh6 qcgts lnfm6 tvawl hdlcl bhhw6 fhcyt qz6vt]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [scalarSubq0.TEUJA:14]\n" +
" │ │ └─ TableAlias(scalarSubq0)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.TEUJA]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(umf.T4IBQ:1)\n" +
" │ ├─ right-key: TUPLE(cla.FTQLQ:1!null)\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ Table\n" +
" │ ├─ name: YK2GW\n" +
" │ └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(umf.FGG57:2)\n" +
" ├─ right-key: TUPLE(nd.FGG57:6)\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nd.FGG57:6 IS NULL\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.FGG57]\n" +
" ├─ static: [{(NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `SELECT
HVHRZ
FROM
QYWQD
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [qywqd.HVHRZ:3!null]\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id wnunu hhvlx hvhrz ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
cla.FTQLQ AS T4IBQ,
SL3S5.TOFPN AS DL754,
sn.id AS BDNYB,
SL3S5.ADURZ AS ADURZ,
(SELECT aac.BTXC5 FROM TPXBU aac WHERE aac.id = SL3S5.M22QN) AS TPXBU,
SL3S5.NO52D AS NO52D,
SL3S5.IDPK7 AS IDPK7
FROM
YK2GW cla
INNER JOIN THNTS bs ON cla.id = bs.IXUXU
INNER JOIN HGMQ6 mf ON bs.id = mf.GXLUB
INNER JOIN NOXN3 sn ON sn.BRQP2 = mf.LUEVY
INNER JOIN
(
SELECT /*+ JOIN_ORDER( ci, ct, cec, KHJJO ) */
KHJJO.BDNYB AS BDNYB,
ci.FTQLQ AS TOFPN,
ct.M22QN AS M22QN,
cec.ADURZ AS ADURZ,
cec.NO52D AS NO52D,
ct.S3Q3Y AS IDPK7
FROM
(
SELECT DISTINCT
mf.M22QN AS M22QN,
sn.id AS BDNYB,
mf.LUEVY AS LUEVY
FROM
HGMQ6 mf
INNER JOIN NOXN3 sn ON sn.BRQP2 = mf.LUEVY
) KHJJO
INNER JOIN
FLQLP ct
ON
ct.M22QN = KHJJO.M22QN
AND
ct.LUEVY = KHJJO.LUEVY
INNER JOIN JDLNA ci ON ci.id = ct.FZ2R5 AND ct.ZRV3B = '='
INNER JOIN SFEGG cec ON cec.id = ct.OVE3E
WHERE
ci.FTQLQ IN ('SQ1')
) SL3S5
ON
SL3S5.BDNYB = sn.id
AND
SL3S5.M22QN = mf.M22QN
WHERE
cla.FTQLQ IN ('SQ1')
UNION ALL
SELECT
AOEV5.*,
VUMUY.*
FROM (
SELECT
SL3S5.TOFPN AS DL754,
sn.id AS BDNYB,
SL3S5.ADURZ AS ADURZ,
(SELECT aac.BTXC5 FROM TPXBU aac WHERE aac.id = SL3S5.M22QN) AS TPXBU,
SL3S5.NO52D AS NO52D,
SL3S5.IDPK7 AS IDPK7
FROM
NOXN3 sn
INNER JOIN
(
SELECT
sn.id AS BDNYB,
ci.FTQLQ AS TOFPN,
ct.M22QN AS M22QN,
cec.ADURZ AS ADURZ,
cec.NO52D AS NO52D,
ct.S3Q3Y AS IDPK7
FROM
NOXN3 sn
INNER JOIN
FLQLP ct
ON
ct.M22QN = (SELECT aac.id FROM TPXBU aac WHERE BTXC5 = 'WT')
AND
ct.LUEVY = sn.BRQP2
INNER JOIN JDLNA ci ON ci.id = ct.FZ2R5 AND ct.ZRV3B = '='
INNER JOIN SFEGG cec ON cec.id = ct.OVE3E
WHERE
ci.FTQLQ IN ('SQ1')
) SL3S5
ON
SL3S5.BDNYB = sn.id ) VUMUY
CROSS JOIN
(
SELECT * FROM (VALUES
ROW("1"),
ROW("2"),
ROW("3"),
ROW("4"),
ROW("5")
) AS temp_AOEV5(T4IBQ)
) AOEV5`,
ExpectedPlan: "Union all\n" +
" ├─ Project\n" +
" │ ├─ columns: [convert\n" +
" │ │ ├─ type: char\n" +
" │ │ └─ T4IBQ:0!null\n" +
" │ │ as T4IBQ, DL754:1!null, BDNYB:2!null, ADURZ:3!null, TPXBU:4, NO52D:5!null, IDPK7:6!null]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:1!null as T4IBQ, sl3s5.TOFPN:62!null as DL754, sn.id:51!null as BDNYB, sl3s5.ADURZ:64!null as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5:75]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.id:74!null\n" +
" │ │ │ └─ sl3s5.M22QN:63!null\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as TPXBU, sl3s5.NO52D:65!null as NO52D, sl3s5.IDPK7:66!null as IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.id:33!null, cla.FTQLQ:34!null, cla.TUXML:35, cla.PAEF5:36, cla.RUCY4:37, cla.TPNJ6:38!null, cla.LBL53:39, cla.NB3QS:40, cla.EO7IV:41, cla.MUHJF:42, cla.FM34L:43, cla.TY5RF:44, cla.ZHTLH:45, cla.NPB7W:46, cla.SX3HH:47, cla.ISBNF:48, cla.YA7YB:49, cla.C5YKB:50, cla.QK7KT:51, cla.FFGE6:52, cla.FIIGJ:53, cla.SH3NC:54, cla.NTENA:55, cla.M4AUB:56, cla.X5AIR:57, cla.SAB6M:58, cla.G5QI5:59, cla.ZVQVD:60, cla.YKSSU:61, cla.FHCYT:62, bs.id:63!null, bs.NFRYN:64!null, bs.IXUXU:65, bs.FHCYT:66, mf.id:0!null, mf.GXLUB:1!null, mf.LUEVY:2!null, mf.M22QN:3!null, mf.TJPT7:4!null, mf.ARN5P:5!null, mf.XOSD4:6!null, mf.IDE43:7, mf.HMW4H:8, mf.ZBT6R:9, mf.FSDY2:10!null, mf.LT7K6:11, mf.SPPYD:12, mf.QCGTS:13, mf.TEUJA:14, mf.QQV4M:15, mf.FHCYT:16, sn.id:23!null, sn.BRQP2:24!null, sn.FFTBJ:25!null, sn.A7XO2:26, sn.KBO7R:27!null, sn.ECDKM:28, sn.NUMK2:29!null, sn.LETOE:30!null, sn.YKSSU:31, sn.FHCYT:32, sl3s5.BDNYB:17!null, sl3s5.TOFPN:18!null, sl3s5.M22QN:19!null, sl3s5.ADURZ:20!null, sl3s5.NO52D:21!null, sl3s5.IDPK7:22!null, cla.FTQLQ:34!null as T4IBQ, sl3s5.TOFPN:18!null as DL754, sn.id:23!null as BDNYB, sl3s5.ADURZ:20!null as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5:68]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.id:67!null\n" +
" │ │ │ └─ sl3s5.M22QN:19!null\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as TPXBU, sl3s5.NO52D:21!null as NO52D, sl3s5.IDPK7:22!null as IDPK7]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ bs.id:63!null\n" +
" │ │ └─ mf.GXLUB:1!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ sn.BRQP2:24!null\n" +
" │ │ │ │ └─ mf.LUEVY:2!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ sl3s5.M22QN:19!null\n" +
" │ │ │ └─ mf.M22QN:3!null\n" +
" │ │ ├─ TableAlias(mf)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(mf.LUEVY:2!null, mf.M22QN:3!null)\n" +
" │ │ ├─ right-key: TUPLE(sn.BRQP2:7!null, sl3s5.M22QN:2!null)\n" +
" │ │ └─ LookupJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ sl3s5.BDNYB:17!null\n" +
" │ │ │ └─ sn.id:23!null\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: sl3s5\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [khjjo.BDNYB:12!null as BDNYB, ci.FTQLQ:1!null as TOFPN, ct.M22QN:4!null as M22QN, cec.ADURZ:10!null as ADURZ, cec.NO52D:9!null as NO52D, ct.S3Q3Y:6!null as IDPK7]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ ct.ZRV3B:7!null\n" +
" │ │ │ │ │ └─ = (longtext)\n" +
" │ │ │ │ └─ HashIn\n" +
" │ │ │ │ ├─ ci.FTQLQ:1!null\n" +
" │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ ct.M22QN:4!null\n" +
" │ │ │ │ │ └─ khjjo.M22QN:11!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ ct.LUEVY:3!null\n" +
" │ │ │ │ └─ khjjo.LUEVY:13!null\n" +
" │ │ │ ├─ HashJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ cec.id:8!null\n" +
" │ │ │ │ │ └─ ct.OVE3E:5!null\n" +
" │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ ├─ ci.id:0!null\n" +
" │ │ │ │ │ │ └─ ct.FZ2R5:2!null\n" +
" │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ │ │ ├─ ci.FTQLQ:1!null\n" +
" │ │ │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ │ │ │ ├─ index: [JDLNA.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ ct.ZRV3B:5!null\n" +
" │ │ │ │ │ │ └─ = (longtext)\n" +
" │ │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ │ ├─ index: [FLQLP.FZ2R5]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [fz2r5 luevy m22qn ove3e s3q3y zrv3b]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(ct.OVE3E:5!null)\n" +
" │ │ │ │ ├─ right-key: TUPLE(cec.id:0!null)\n" +
" │ │ │ │ └─ TableAlias(cec)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: SFEGG\n" +
" │ │ │ │ └─ columns: [id no52d adurz]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(ct.M22QN:4!null, ct.LUEVY:3!null)\n" +
" │ │ │ ├─ right-key: TUPLE(khjjo.M22QN:0!null, khjjo.LUEVY:2!null)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: khjjo\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Distinct\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [mf.M22QN:13!null as M22QN, sn.id:0!null as BDNYB, mf.LUEVY:12!null as LUEVY]\n" +
" │ │ │ └─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ │ │ └─ mf.LUEVY:12!null\n" +
" │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.id]\n" +
" │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.GXLUB:1!null)\n" +
" │ ├─ right-key: TUPLE(bs.id:30!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ cla.id:33!null\n" +
" │ │ └─ bs.IXUXU:65\n" +
" │ ├─ Filter\n" +
" │ │ ├─ HashIn\n" +
" │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq:0!null as t4ibq, vumuy.DL754:1!null, vumuy.BDNYB:2!null, vumuy.ADURZ:3!null, vumuy.TPXBU:4, vumuy.NO52D:5!null, vumuy.IDPK7:6!null]\n" +
" └─ CrossHashJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: aoev5\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [temp_aoev5.t4ibq:0!null]\n" +
" │ └─ Values() as temp_AOEV5\n" +
" │ ├─ Row(\n" +
" │ │ 1 (longtext))\n" +
" │ ├─ Row(\n" +
" │ │ 2 (longtext))\n" +
" │ ├─ Row(\n" +
" │ │ 3 (longtext))\n" +
" │ ├─ Row(\n" +
" │ │ 4 (longtext))\n" +
" │ └─ Row(\n" +
" │ 5 (longtext))\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE()\n" +
" ├─ right-key: TUPLE()\n" +
" └─ SubqueryAlias\n" +
" ├─ name: vumuy\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [sl3s5.TOFPN:11!null as DL754, sn.id:0!null as BDNYB, sl3s5.ADURZ:13!null as ADURZ, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [aac.BTXC5:23]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ aac.id:22!null\n" +
" │ │ └─ sl3s5.M22QN:12!null\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ columns: [id btxc5]\n" +
" │ as TPXBU, sl3s5.NO52D:14!null as NO52D, sl3s5.IDPK7:15!null as IDPK7]\n" +
" └─ Project\n" +
" ├─ columns: [sn.id:6!null, sn.BRQP2:7!null, sn.FFTBJ:8!null, sn.A7XO2:9, sn.KBO7R:10!null, sn.ECDKM:11, sn.NUMK2:12!null, sn.LETOE:13!null, sn.YKSSU:14, sn.FHCYT:15, sl3s5.BDNYB:0!null, sl3s5.TOFPN:1!null, sl3s5.M22QN:2!null, sl3s5.ADURZ:3!null, sl3s5.NO52D:4!null, sl3s5.IDPK7:5!null, sl3s5.TOFPN:1!null as DL754, sn.id:6!null as BDNYB, sl3s5.ADURZ:3!null as ADURZ, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [aac.BTXC5:17]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ aac.id:16!null\n" +
" │ │ └─ sl3s5.M22QN:2!null\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ columns: [id btxc5]\n" +
" │ as TPXBU, sl3s5.NO52D:4!null as NO52D, sl3s5.IDPK7:5!null as IDPK7]\n" +
" └─ LookupJoin\n" +
" ├─ Eq\n" +
" │ ├─ sl3s5.BDNYB:0!null\n" +
" │ └─ sn.id:6!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: sl3s5\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id:17!null as BDNYB, ci.FTQLQ:1!null as TOFPN, ct.M22QN:5!null as M22QN, cec.ADURZ:16!null as ADURZ, cec.NO52D:15!null as NO52D, ct.S3Q3Y:11!null as IDPK7]\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ct.M22QN:5!null\n" +
" │ │ │ │ └─ Subquery\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [aac.id:27!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ aac.BTXC5:28\n" +
" │ │ │ │ │ └─ WT (longtext)\n" +
" │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ ├─ static: [{[WT, WT]}]\n" +
" │ │ │ │ └─ columns: [id btxc5]\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ ct.ZRV3B:12!null\n" +
" │ │ │ └─ = (longtext)\n" +
" │ │ └─ HashIn\n" +
" │ │ ├─ ci.FTQLQ:1!null\n" +
" │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ct.LUEVY:4!null\n" +
" │ │ └─ sn.BRQP2:18!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cec.id:14!null\n" +
" │ │ │ └─ ct.OVE3E:6!null\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ ci.id:0!null\n" +
" │ │ │ │ └─ ct.FZ2R5:3!null\n" +
" │ │ │ ├─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ ci.FTQLQ:1!null\n" +
" │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ │ ├─ index: [JDLNA.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ct.ZRV3B:10!null\n" +
" │ │ │ │ └─ = (longtext)\n" +
" │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ ├─ index: [FLQLP.FZ2R5]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(ct.OVE3E:6!null)\n" +
" │ │ ├─ right-key: TUPLE(cec.id:0!null)\n" +
" │ │ └─ TableAlias(cec)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ └─ columns: [id no52d adurz]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ct.LUEVY:4!null)\n" +
" │ ├─ right-key: TUPLE(sn.BRQP2:1!null)\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" └─ TableAlias(sn)\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
cla.FTQLQ AS T4IBQ,
SL3S5.TOFPN AS DL754,
sn.id AS BDNYB,
SL3S5.ADURZ AS ADURZ,
(SELECT aac.BTXC5 FROM TPXBU aac WHERE aac.id = SL3S5.M22QN) AS TPXBU,
SL3S5.NO52D AS NO52D,
SL3S5.IDPK7 AS IDPK7
FROM
YK2GW cla
INNER JOIN THNTS bs ON cla.id = bs.IXUXU
INNER JOIN HGMQ6 mf ON bs.id = mf.GXLUB
INNER JOIN NOXN3 sn ON sn.BRQP2 = mf.LUEVY
INNER JOIN
(
SELECT
KHJJO.BDNYB AS BDNYB,
ci.FTQLQ AS TOFPN,
ct.M22QN AS M22QN,
cec.ADURZ AS ADURZ,
cec.NO52D AS NO52D,
ct.S3Q3Y AS IDPK7
FROM
(
SELECT DISTINCT
mf.M22QN AS M22QN,
sn.id AS BDNYB,
mf.LUEVY AS LUEVY
FROM
HGMQ6 mf
INNER JOIN NOXN3 sn ON sn.BRQP2 = mf.LUEVY
) KHJJO
INNER JOIN
FLQLP ct
ON
ct.M22QN = KHJJO.M22QN
AND
ct.LUEVY = KHJJO.LUEVY
INNER JOIN JDLNA ci ON ci.id = ct.FZ2R5 AND ct.ZRV3B = '='
INNER JOIN SFEGG cec ON cec.id = ct.OVE3E
WHERE
ci.FTQLQ IN ('SQ1')
) SL3S5
ON
SL3S5.BDNYB = sn.id
AND
SL3S5.M22QN = mf.M22QN
WHERE
cla.FTQLQ IN ('SQ1')
UNION ALL
SELECT
AOEV5.*,
VUMUY.*
FROM (
SELECT
SL3S5.TOFPN AS DL754,
sn.id AS BDNYB,
SL3S5.ADURZ AS ADURZ,
(SELECT aac.BTXC5 FROM TPXBU aac WHERE aac.id = SL3S5.M22QN) AS TPXBU,
SL3S5.NO52D AS NO52D,
SL3S5.IDPK7 AS IDPK7
FROM
NOXN3 sn
INNER JOIN
(
SELECT
sn.id AS BDNYB,
ci.FTQLQ AS TOFPN,
ct.M22QN AS M22QN,
cec.ADURZ AS ADURZ,
cec.NO52D AS NO52D,
ct.S3Q3Y AS IDPK7
FROM
NOXN3 sn
INNER JOIN
FLQLP ct
ON
ct.M22QN = (SELECT aac.id FROM TPXBU aac WHERE BTXC5 = 'WT')
AND
ct.LUEVY = sn.BRQP2
INNER JOIN JDLNA ci ON ci.id = ct.FZ2R5 AND ct.ZRV3B = '='
INNER JOIN SFEGG cec ON cec.id = ct.OVE3E
WHERE
ci.FTQLQ IN ('SQ1')
) SL3S5
ON
SL3S5.BDNYB = sn.id ) VUMUY
CROSS JOIN
(
SELECT * FROM (VALUES
ROW("1"),
ROW("2"),
ROW("3"),
ROW("4"),
ROW("5")
) AS temp_AOEV5(T4IBQ)
) AOEV5`,
ExpectedPlan: "Union all\n" +
" ├─ Project\n" +
" │ ├─ columns: [convert\n" +
" │ │ ├─ type: char\n" +
" │ │ └─ T4IBQ:0!null\n" +
" │ │ as T4IBQ, DL754:1!null, BDNYB:2!null, ADURZ:3!null, TPXBU:4, NO52D:5!null, IDPK7:6!null]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:1!null as T4IBQ, sl3s5.TOFPN:62!null as DL754, sn.id:51!null as BDNYB, sl3s5.ADURZ:64!null as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5:75]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.id:74!null\n" +
" │ │ │ └─ sl3s5.M22QN:63!null\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as TPXBU, sl3s5.NO52D:65!null as NO52D, sl3s5.IDPK7:66!null as IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.id:33!null, cla.FTQLQ:34!null, cla.TUXML:35, cla.PAEF5:36, cla.RUCY4:37, cla.TPNJ6:38!null, cla.LBL53:39, cla.NB3QS:40, cla.EO7IV:41, cla.MUHJF:42, cla.FM34L:43, cla.TY5RF:44, cla.ZHTLH:45, cla.NPB7W:46, cla.SX3HH:47, cla.ISBNF:48, cla.YA7YB:49, cla.C5YKB:50, cla.QK7KT:51, cla.FFGE6:52, cla.FIIGJ:53, cla.SH3NC:54, cla.NTENA:55, cla.M4AUB:56, cla.X5AIR:57, cla.SAB6M:58, cla.G5QI5:59, cla.ZVQVD:60, cla.YKSSU:61, cla.FHCYT:62, bs.id:63!null, bs.NFRYN:64!null, bs.IXUXU:65, bs.FHCYT:66, mf.id:0!null, mf.GXLUB:1!null, mf.LUEVY:2!null, mf.M22QN:3!null, mf.TJPT7:4!null, mf.ARN5P:5!null, mf.XOSD4:6!null, mf.IDE43:7, mf.HMW4H:8, mf.ZBT6R:9, mf.FSDY2:10!null, mf.LT7K6:11, mf.SPPYD:12, mf.QCGTS:13, mf.TEUJA:14, mf.QQV4M:15, mf.FHCYT:16, sn.id:23!null, sn.BRQP2:24!null, sn.FFTBJ:25!null, sn.A7XO2:26, sn.KBO7R:27!null, sn.ECDKM:28, sn.NUMK2:29!null, sn.LETOE:30!null, sn.YKSSU:31, sn.FHCYT:32, sl3s5.BDNYB:17!null, sl3s5.TOFPN:18!null, sl3s5.M22QN:19!null, sl3s5.ADURZ:20!null, sl3s5.NO52D:21!null, sl3s5.IDPK7:22!null, cla.FTQLQ:34!null as T4IBQ, sl3s5.TOFPN:18!null as DL754, sn.id:23!null as BDNYB, sl3s5.ADURZ:20!null as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5:68]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.id:67!null\n" +
" │ │ │ └─ sl3s5.M22QN:19!null\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as TPXBU, sl3s5.NO52D:21!null as NO52D, sl3s5.IDPK7:22!null as IDPK7]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ bs.id:63!null\n" +
" │ │ └─ mf.GXLUB:1!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ sn.BRQP2:24!null\n" +
" │ │ │ │ └─ mf.LUEVY:2!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ sl3s5.M22QN:19!null\n" +
" │ │ │ └─ mf.M22QN:3!null\n" +
" │ │ ├─ TableAlias(mf)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(mf.LUEVY:2!null, mf.M22QN:3!null)\n" +
" │ │ ├─ right-key: TUPLE(sn.BRQP2:7!null, sl3s5.M22QN:2!null)\n" +
" │ │ └─ LookupJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ sl3s5.BDNYB:17!null\n" +
" │ │ │ └─ sn.id:23!null\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: sl3s5\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [khjjo.BDNYB:12!null as BDNYB, ci.FTQLQ:1!null as TOFPN, ct.M22QN:4!null as M22QN, cec.ADURZ:10!null as ADURZ, cec.NO52D:9!null as NO52D, ct.S3Q3Y:6!null as IDPK7]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ ct.ZRV3B:7!null\n" +
" │ │ │ │ │ └─ = (longtext)\n" +
" │ │ │ │ └─ HashIn\n" +
" │ │ │ │ ├─ ci.FTQLQ:1!null\n" +
" │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ ct.M22QN:4!null\n" +
" │ │ │ │ │ └─ khjjo.M22QN:11!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ ct.LUEVY:3!null\n" +
" │ │ │ │ └─ khjjo.LUEVY:13!null\n" +
" │ │ │ ├─ HashJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ cec.id:8!null\n" +
" │ │ │ │ │ └─ ct.OVE3E:5!null\n" +
" │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ ├─ ci.id:0!null\n" +
" │ │ │ │ │ │ └─ ct.FZ2R5:2!null\n" +
" │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ │ │ ├─ ci.FTQLQ:1!null\n" +
" │ │ │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ │ │ │ ├─ index: [JDLNA.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ ct.ZRV3B:5!null\n" +
" │ │ │ │ │ │ └─ = (longtext)\n" +
" │ │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ │ ├─ index: [FLQLP.FZ2R5]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [fz2r5 luevy m22qn ove3e s3q3y zrv3b]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(ct.OVE3E:5!null)\n" +
" │ │ │ │ ├─ right-key: TUPLE(cec.id:0!null)\n" +
" │ │ │ │ └─ TableAlias(cec)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: SFEGG\n" +
" │ │ │ │ └─ columns: [id no52d adurz]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(ct.M22QN:4!null, ct.LUEVY:3!null)\n" +
" │ │ │ ├─ right-key: TUPLE(khjjo.M22QN:0!null, khjjo.LUEVY:2!null)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: khjjo\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Distinct\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [mf.M22QN:13!null as M22QN, sn.id:0!null as BDNYB, mf.LUEVY:12!null as LUEVY]\n" +
" │ │ │ └─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ │ │ └─ mf.LUEVY:12!null\n" +
" │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.id]\n" +
" │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.GXLUB:1!null)\n" +
" │ ├─ right-key: TUPLE(bs.id:30!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ cla.id:33!null\n" +
" │ │ └─ bs.IXUXU:65\n" +
" │ ├─ Filter\n" +
" │ │ ├─ HashIn\n" +
" │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq:0!null as t4ibq, vumuy.DL754:1!null, vumuy.BDNYB:2!null, vumuy.ADURZ:3!null, vumuy.TPXBU:4, vumuy.NO52D:5!null, vumuy.IDPK7:6!null]\n" +
" └─ CrossHashJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: aoev5\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [temp_aoev5.t4ibq:0!null]\n" +
" │ └─ Values() as temp_AOEV5\n" +
" │ ├─ Row(\n" +
" │ │ 1 (longtext))\n" +
" │ ├─ Row(\n" +
" │ │ 2 (longtext))\n" +
" │ ├─ Row(\n" +
" │ │ 3 (longtext))\n" +
" │ ├─ Row(\n" +
" │ │ 4 (longtext))\n" +
" │ └─ Row(\n" +
" │ 5 (longtext))\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE()\n" +
" ├─ right-key: TUPLE()\n" +
" └─ SubqueryAlias\n" +
" ├─ name: vumuy\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [sl3s5.TOFPN:11!null as DL754, sn.id:0!null as BDNYB, sl3s5.ADURZ:13!null as ADURZ, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [aac.BTXC5:23]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ aac.id:22!null\n" +
" │ │ └─ sl3s5.M22QN:12!null\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ columns: [id btxc5]\n" +
" │ as TPXBU, sl3s5.NO52D:14!null as NO52D, sl3s5.IDPK7:15!null as IDPK7]\n" +
" └─ Project\n" +
" ├─ columns: [sn.id:6!null, sn.BRQP2:7!null, sn.FFTBJ:8!null, sn.A7XO2:9, sn.KBO7R:10!null, sn.ECDKM:11, sn.NUMK2:12!null, sn.LETOE:13!null, sn.YKSSU:14, sn.FHCYT:15, sl3s5.BDNYB:0!null, sl3s5.TOFPN:1!null, sl3s5.M22QN:2!null, sl3s5.ADURZ:3!null, sl3s5.NO52D:4!null, sl3s5.IDPK7:5!null, sl3s5.TOFPN:1!null as DL754, sn.id:6!null as BDNYB, sl3s5.ADURZ:3!null as ADURZ, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [aac.BTXC5:17]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ aac.id:16!null\n" +
" │ │ └─ sl3s5.M22QN:2!null\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ columns: [id btxc5]\n" +
" │ as TPXBU, sl3s5.NO52D:4!null as NO52D, sl3s5.IDPK7:5!null as IDPK7]\n" +
" └─ LookupJoin\n" +
" ├─ Eq\n" +
" │ ├─ sl3s5.BDNYB:0!null\n" +
" │ └─ sn.id:6!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: sl3s5\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id:17!null as BDNYB, ci.FTQLQ:1!null as TOFPN, ct.M22QN:5!null as M22QN, cec.ADURZ:16!null as ADURZ, cec.NO52D:15!null as NO52D, ct.S3Q3Y:11!null as IDPK7]\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ct.M22QN:5!null\n" +
" │ │ │ │ └─ Subquery\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [aac.id:27!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ aac.BTXC5:28\n" +
" │ │ │ │ │ └─ WT (longtext)\n" +
" │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ ├─ static: [{[WT, WT]}]\n" +
" │ │ │ │ └─ columns: [id btxc5]\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ ct.ZRV3B:12!null\n" +
" │ │ │ └─ = (longtext)\n" +
" │ │ └─ HashIn\n" +
" │ │ ├─ ci.FTQLQ:1!null\n" +
" │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ct.LUEVY:4!null\n" +
" │ │ └─ sn.BRQP2:18!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cec.id:14!null\n" +
" │ │ │ └─ ct.OVE3E:6!null\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ ci.id:0!null\n" +
" │ │ │ │ └─ ct.FZ2R5:3!null\n" +
" │ │ │ ├─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ ci.FTQLQ:1!null\n" +
" │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ │ ├─ index: [JDLNA.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ct.ZRV3B:10!null\n" +
" │ │ │ │ └─ = (longtext)\n" +
" │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ ├─ index: [FLQLP.FZ2R5]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(ct.OVE3E:6!null)\n" +
" │ │ ├─ right-key: TUPLE(cec.id:0!null)\n" +
" │ │ └─ TableAlias(cec)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ └─ columns: [id no52d adurz]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ct.LUEVY:4!null)\n" +
" │ ├─ right-key: TUPLE(sn.BRQP2:1!null)\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" └─ TableAlias(sn)\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT COUNT(*) FROM NOXN3`,
ExpectedPlan: "Project\n" +
" ├─ columns: [count(1):0!null as COUNT(*)]\n" +
" └─ Project\n" +
" ├─ columns: [NOXN3.COUNT(1):0!null as COUNT(1)]\n" +
" └─ table_count(NOXN3) as COUNT(1)\n" +
"",
},
{
Query: `
SELECT
NB6PJ.Y3IOU AS Y3IOU,
S7EGW.TW55N AS FJVD7,
TYMVL.TW55N AS KBXXJ,
NB6PJ.NUMK2 AS NUMK2,
NB6PJ.LETOE AS LETOE
FROM
(SELECT
ROW_NUMBER() OVER (ORDER BY id ASC) Y3IOU,
id,
BRQP2,
FFTBJ,
NUMK2,
LETOE
FROM
NOXN3
ORDER BY id ASC) NB6PJ
INNER JOIN
E2I7U S7EGW
ON
S7EGW.id = NB6PJ.BRQP2
INNER JOIN
E2I7U TYMVL
ON
TYMVL.id = NB6PJ.FFTBJ
ORDER BY Y3IOU`,
ExpectedPlan: "Project\n" +
" ├─ columns: [nb6pj.Y3IOU:0!null as Y3IOU, s7egw.TW55N:9!null as FJVD7, tymvl.TW55N:26!null as KBXXJ, nb6pj.NUMK2:4!null as NUMK2, nb6pj.LETOE:5!null as LETOE]\n" +
" └─ Sort(nb6pj.Y3IOU:0!null as Y3IOU ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [nb6pj.Y3IOU:0!null, nb6pj.id:1!null, nb6pj.BRQP2:2!null, nb6pj.FFTBJ:3!null, nb6pj.NUMK2:4!null, nb6pj.LETOE:5!null, s7egw.id:23!null, s7egw.DKCAJ:24!null, s7egw.KNG7T:25, s7egw.TW55N:26!null, s7egw.QRQXW:27!null, s7egw.ECXAJ:28!null, s7egw.FGG57:29, s7egw.ZH72S:30, s7egw.FSK67:31!null, s7egw.XQDYT:32!null, s7egw.TCE7A:33, s7egw.IWV2H:34, s7egw.HPCMS:35!null, s7egw.N5CC2:36, s7egw.FHCYT:37, s7egw.ETAQ7:38, s7egw.A75X7:39, tymvl.id:6!null, tymvl.DKCAJ:7!null, tymvl.KNG7T:8, tymvl.TW55N:9!null, tymvl.QRQXW:10!null, tymvl.ECXAJ:11!null, tymvl.FGG57:12, tymvl.ZH72S:13, tymvl.FSK67:14!null, tymvl.XQDYT:15!null, tymvl.TCE7A:16, tymvl.IWV2H:17, tymvl.HPCMS:18!null, tymvl.N5CC2:19, tymvl.FHCYT:20, tymvl.ETAQ7:21, tymvl.A75X7:22, nb6pj.Y3IOU:0!null as Y3IOU, s7egw.TW55N:26!null as FJVD7, tymvl.TW55N:9!null as KBXXJ, nb6pj.NUMK2:4!null as NUMK2, nb6pj.LETOE:5!null as LETOE]\n" +
" └─ LookupJoin\n" +
" ├─ Eq\n" +
" │ ├─ s7egw.id:23!null\n" +
" │ └─ nb6pj.BRQP2:2!null\n" +
" ├─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ tymvl.id:6!null\n" +
" │ │ └─ nb6pj.FFTBJ:3!null\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: nb6pj\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [row_number() over ( order by noxn3.id asc):0!null as Y3IOU, noxn3.id:1!null, noxn3.BRQP2:2!null, noxn3.FFTBJ:3!null, noxn3.NUMK2:4!null, noxn3.LETOE:5!null]\n" +
" │ │ └─ Sort(noxn3.id:1!null ASC nullsFirst)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [row_number() over ( order by noxn3.id asc):0!null, noxn3.id:1!null, noxn3.BRQP2:2!null, noxn3.FFTBJ:3!null, noxn3.NUMK2:4!null, noxn3.LETOE:5!null, row_number() over ( order by noxn3.id asc):0!null as Y3IOU]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:0!null\n" +
" │ │ ├─ noxn3.BRQP2:1!null\n" +
" │ │ ├─ noxn3.FFTBJ:2!null\n" +
" │ │ ├─ noxn3.NUMK2:3!null\n" +
" │ │ ├─ noxn3.LETOE:4!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2 fftbj numk2 letoe]\n" +
" │ └─ TableAlias(tymvl)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" └─ TableAlias(s7egw)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT
nd.TW55N AS TW55N,
NB6PJ.Y3IOU AS Y3IOU
FROM
(SELECT
ROW_NUMBER() OVER (ORDER BY id ASC) Y3IOU,
id,
BRQP2,
FFTBJ,
NUMK2,
LETOE
FROM
NOXN3
ORDER BY id ASC) NB6PJ
INNER JOIN
E2I7U nd
ON
nd.id = NB6PJ.BRQP2
ORDER BY TW55N, Y3IOU`,
ExpectedPlan: "Project\n" +
" ├─ columns: [nd.TW55N:9!null as TW55N, nb6pj.Y3IOU:0!null as Y3IOU]\n" +
" └─ Sort(nd.TW55N:9!null as TW55N ASC nullsFirst, nb6pj.Y3IOU:0!null as Y3IOU ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [nb6pj.Y3IOU:0!null, nb6pj.id:1!null, nb6pj.BRQP2:2!null, nb6pj.FFTBJ:3!null, nb6pj.NUMK2:4!null, nb6pj.LETOE:5!null, nd.id:6!null, nd.DKCAJ:7!null, nd.KNG7T:8, nd.TW55N:9!null, nd.QRQXW:10!null, nd.ECXAJ:11!null, nd.FGG57:12, nd.ZH72S:13, nd.FSK67:14!null, nd.XQDYT:15!null, nd.TCE7A:16, nd.IWV2H:17, nd.HPCMS:18!null, nd.N5CC2:19, nd.FHCYT:20, nd.ETAQ7:21, nd.A75X7:22, nd.TW55N:9!null as TW55N, nb6pj.Y3IOU:0!null as Y3IOU]\n" +
" └─ LookupJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.id:6!null\n" +
" │ └─ nb6pj.BRQP2:2!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nb6pj\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [row_number() over ( order by noxn3.id asc):0!null as Y3IOU, noxn3.id:1!null, noxn3.BRQP2:2!null, noxn3.FFTBJ:3!null, noxn3.NUMK2:4!null, noxn3.LETOE:5!null]\n" +
" │ └─ Sort(noxn3.id:1!null ASC nullsFirst)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [row_number() over ( order by noxn3.id asc):0!null, noxn3.id:1!null, noxn3.BRQP2:2!null, noxn3.FFTBJ:3!null, noxn3.NUMK2:4!null, noxn3.LETOE:5!null, row_number() over ( order by noxn3.id asc):0!null as Y3IOU]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:0!null\n" +
" │ ├─ noxn3.BRQP2:1!null\n" +
" │ ├─ noxn3.FFTBJ:2!null\n" +
" │ ├─ noxn3.NUMK2:3!null\n" +
" │ ├─ noxn3.LETOE:4!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2 fftbj numk2 letoe]\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT
ROW_NUMBER() OVER (ORDER BY sn.id ASC) - 1 M6T2N,
S7EGW.TW55N FJVD7,
TYMVL.TW55N KBXXJ,
NUMK2,
LETOE,
sn.id XLFIA
FROM
NOXN3 sn
INNER JOIN
E2I7U S7EGW ON (sn.BRQP2 = S7EGW.id)
INNER JOIN
E2I7U TYMVL ON (sn.FFTBJ = TYMVL.id)
ORDER BY M6T2N ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [(row_number() over ( order by sn.id asc):0!null - 1 (tinyint)) as M6T2N, s7egw.TW55N:1!null as FJVD7, tymvl.TW55N:31!null as KBXXJ, sn.NUMK2:2!null, sn.LETOE:3!null, sn.id:4!null as XLFIA]\n" +
" └─ Sort((row_number() over ( order by sn.id asc):0!null - 1 (tinyint)) as M6T2N ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by sn.id asc):0!null, s7egw.TW55N:1!null, sn.NUMK2:2!null, sn.LETOE:3!null, sn.id:4!null, (row_number() over ( order by sn.id asc):0!null - 1 (tinyint)) as M6T2N, s7egw.TW55N:1!null as FJVD7, tymvl.TW55N:31!null as KBXXJ, sn.id:4!null as XLFIA]\n" +
" └─ Window\n" +
" ├─ row_number() over ( order by sn.id ASC)\n" +
" ├─ s7egw.TW55N:8!null\n" +
" ├─ sn.NUMK2:5!null\n" +
" ├─ sn.LETOE:6!null\n" +
" ├─ sn.id:2!null\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ sn.BRQP2:3!null\n" +
" │ └─ s7egw.id:7!null\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ tymvl.id:0!null\n" +
" │ │ └─ sn.FFTBJ:4!null\n" +
" │ ├─ TableAlias(tymvl)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id brqp2 fftbj numk2 letoe]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(sn.BRQP2:3!null)\n" +
" ├─ right-key: TUPLE(s7egw.id:0!null)\n" +
" └─ TableAlias(s7egw)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n]\n" +
"",
},
{
Query: `
SELECT id FZZVR, ROW_NUMBER() OVER (ORDER BY sn.id ASC) - 1 M6T2N FROM NOXN3 sn`,
ExpectedPlan: "Project\n" +
" ├─ columns: [sn.id:1!null as FZZVR, (row_number() over ( order by sn.id asc):0!null - 1 (tinyint)) as M6T2N]\n" +
" └─ Window\n" +
" ├─ row_number() over ( order by sn.id ASC)\n" +
" ├─ sn.id:0!null\n" +
" └─ TableAlias(sn)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\n" +
"",
},
{
Query: `
SELECT
nd.TW55N,
il.LIILR,
il.KSFXH,
il.KLMAU,
il.ecm
FROM RLOHD il
INNER JOIN E2I7U nd
ON il.LUEVY = nd.id
INNER JOIN F35MI nt
ON nd.DKCAJ = nt.id
WHERE nt.DZLIM <> 'SUZTA'
ORDER BY nd.TW55N`,
ExpectedPlan: "Project\n" +
" ├─ columns: [nd.TW55N:11!null, il.LIILR:2, il.KSFXH:3, il.KLMAU:4, il.ecm:5]\n" +
" └─ Sort(nd.TW55N:11!null ASC nullsFirst)\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ Eq\n" +
" │ ├─ nt.DZLIM:26!null\n" +
" │ └─ SUZTA (longtext)\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.DKCAJ:9!null\n" +
" │ └─ nt.id:25!null\n" +
" ├─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ il.LUEVY:1!null\n" +
" │ │ └─ nd.id:8!null\n" +
" │ ├─ TableAlias(il)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: RLOHD\n" +
" │ │ └─ columns: [id luevy liilr ksfxh klmau ecm rqi4m fhcyt]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(nd.DKCAJ:9!null)\n" +
" ├─ right-key: TUPLE(nt.id:0!null)\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ Eq\n" +
" │ ├─ nt.DZLIM:1!null\n" +
" │ └─ SUZTA (longtext)\n" +
" └─ TableAlias(nt)\n" +
" └─ IndexedTableAccess(F35MI)\n" +
" ├─ index: [F35MI.DZLIM]\n" +
" ├─ static: [{(NULL, SUZTA)}, {(SUZTA, ∞)}]\n" +
" └─ columns: [id dzlim f3yue]\n" +
"",
},
{
Query: `
SELECT
FTQLQ, TPNJ6
FROM YK2GW
WHERE FTQLQ IN ('SQ1')`,
ExpectedPlan: "Filter\n" +
" ├─ HashIn\n" +
" │ ├─ yk2gw.FTQLQ:0!null\n" +
" │ └─ TUPLE(SQ1 (longtext))\n" +
" └─ IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.FTQLQ]\n" +
" ├─ static: [{[SQ1, SQ1]}]\n" +
" └─ columns: [ftqlq tpnj6]\n" +
"",
},
{
Query: `
SELECT
ATHCU.T4IBQ AS T4IBQ,
ATHCU.TW55N AS TW55N,
CASE
WHEN fc.OZTQF IS NULL THEN 0
WHEN ATHCU.SJ5DU IN ('log', 'com', 'ex') THEN 0
WHEN ATHCU.SOWRY = 'CRZ2X' THEN 0
WHEN ATHCU.SOWRY = 'z' THEN fc.OZTQF
WHEN ATHCU.SOWRY = 'o' THEN fc.OZTQF - 1
END AS OZTQF
FROM
(
SELECT
B2TX3,
T4IBQ,
nd.id AS YYKXN,
nd.TW55N AS TW55N,
nd.FSK67 AS SOWRY,
(SELECT nt.DZLIM FROM F35MI nt WHERE nt.id = nd.DKCAJ) AS SJ5DU
FROM
(
SELECT
bs.id AS B2TX3,
cla.FTQLQ AS T4IBQ
FROM
YK2GW cla
INNER JOIN
THNTS bs
ON
bs.IXUXU = cla.id
WHERE
cla.FTQLQ IN ('SQ1')
) TMDTP
CROSS JOIN
E2I7U nd
) ATHCU
LEFT JOIN
AMYXQ fc
ON
fc.LUEVY = YYKXN
AND
fc.GXLUB = B2TX3
ORDER BY
YYKXN
`,
ExpectedPlan: "Project\n" +
" ├─ columns: [athcu.T4IBQ:1!null as T4IBQ, athcu.TW55N:3!null as TW55N, CASE WHEN fc.OZTQF:11!null IS NULL THEN 0 (tinyint) WHEN IN\n" +
" │ ├─ left: athcu.SJ5DU:5\n" +
" │ └─ right: TUPLE(log (longtext), com (longtext), ex (longtext))\n" +
" │ THEN 0 (tinyint) WHEN Eq\n" +
" │ ├─ athcu.SOWRY:4!null\n" +
" │ └─ CRZ2X (longtext)\n" +
" │ THEN 0 (tinyint) WHEN Eq\n" +
" │ ├─ athcu.SOWRY:4!null\n" +
" │ └─ z (longtext)\n" +
" │ THEN fc.OZTQF:11!null WHEN Eq\n" +
" │ ├─ athcu.SOWRY:4!null\n" +
" │ └─ o (longtext)\n" +
" │ THEN (fc.OZTQF:11!null - 1 (tinyint)) END as OZTQF]\n" +
" └─ Sort(athcu.YYKXN:2!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [athcu.B2TX3:0!null, athcu.T4IBQ:1!null, athcu.YYKXN:2!null, athcu.TW55N:3!null, athcu.SOWRY:4!null, athcu.SJ5DU:5, fc.id:6!null, fc.GXLUB:7!null, fc.LUEVY:8!null, fc.XQDYT:9!null, fc.AMYXQ:10!null, fc.OZTQF:11!null, fc.Z35GY:12!null, fc.KKGN5:13, athcu.T4IBQ:1!null as T4IBQ, athcu.TW55N:3!null as TW55N, CASE WHEN fc.OZTQF:11!null IS NULL THEN 0 (tinyint) WHEN IN\n" +
" │ ├─ left: athcu.SJ5DU:5\n" +
" │ └─ right: TUPLE(log (longtext), com (longtext), ex (longtext))\n" +
" │ THEN 0 (tinyint) WHEN Eq\n" +
" │ ├─ athcu.SOWRY:4!null\n" +
" │ └─ CRZ2X (longtext)\n" +
" │ THEN 0 (tinyint) WHEN Eq\n" +
" │ ├─ athcu.SOWRY:4!null\n" +
" │ └─ z (longtext)\n" +
" │ THEN fc.OZTQF:11!null WHEN Eq\n" +
" │ ├─ athcu.SOWRY:4!null\n" +
" │ └─ o (longtext)\n" +
" │ THEN (fc.OZTQF:11!null - 1 (tinyint)) END as OZTQF]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ fc.LUEVY:8!null\n" +
" │ │ └─ athcu.YYKXN:2!null\n" +
" │ └─ Eq\n" +
" │ ├─ fc.GXLUB:7!null\n" +
" │ └─ athcu.B2TX3:0!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: athcu\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tmdtp.B2TX3:0!null, tmdtp.T4IBQ:1!null, nd.id:2!null as YYKXN, nd.TW55N:5!null as TW55N, nd.FSK67:10!null as SOWRY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nt.DZLIM:24!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ nt.id:23!null\n" +
" │ │ │ └─ nd.DKCAJ:3!null\n" +
" │ │ └─ TableAlias(nt)\n" +
" │ │ └─ IndexedTableAccess(F35MI)\n" +
" │ │ ├─ index: [F35MI.id]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as SJ5DU]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tmdtp.B2TX3:17!null, tmdtp.T4IBQ:18!null, nd.id:0!null, nd.DKCAJ:1!null, nd.KNG7T:2, nd.TW55N:3!null, nd.QRQXW:4!null, nd.ECXAJ:5!null, nd.FGG57:6, nd.ZH72S:7, nd.FSK67:8!null, nd.XQDYT:9!null, nd.TCE7A:10, nd.IWV2H:11, nd.HPCMS:12!null, nd.N5CC2:13, nd.FHCYT:14, nd.ETAQ7:15, nd.A75X7:16, nd.id:0!null as YYKXN, nd.TW55N:3!null as TW55N, nd.FSK67:8!null as SOWRY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nt.DZLIM:20!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ nt.id:19!null\n" +
" │ │ │ └─ nd.DKCAJ:1!null\n" +
" │ │ └─ TableAlias(nt)\n" +
" │ │ └─ IndexedTableAccess(F35MI)\n" +
" │ │ ├─ index: [F35MI.id]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as SJ5DU]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ TableAlias(nd)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE()\n" +
" │ ├─ right-key: TUPLE()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: tmdtp\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.id:2!null as B2TX3, cla.FTQLQ:1!null as T4IBQ]\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ cla.id:0!null\n" +
" │ │ └─ bs.IXUXU:3\n" +
" │ ├─ Filter\n" +
" │ │ ├─ HashIn\n" +
" │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(athcu.YYKXN:2!null, athcu.B2TX3:0!null)\n" +
" ├─ right-key: TUPLE(fc.LUEVY:2!null, fc.GXLUB:1!null)\n" +
" └─ TableAlias(fc)\n" +
" └─ Table\n" +
" ├─ name: AMYXQ\n" +
" └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
"",
},
{
Query: `
WITH AX7FV AS
(SELECT
bs.T4IBQ AS T4IBQ,
pa.DZLIM AS ECUWU,
pga.DZLIM AS GSTQA,
pog.B5OUF,
fc.OZTQF,
F26ZW.YHYLK,
nd.TW55N AS TW55N
FROM
SZQWJ ms
INNER JOIN XOAOP pa
ON ms.CH3FR = pa.id
LEFT JOIN NPCYY pog
ON pa.id = pog.CH3FR
INNER JOIN PG27A pga
ON pog.XVSBH = pga.id
INNER JOIN FEIOE GZ7Z4
ON pog.id = GZ7Z4.GMSGA
INNER JOIN E2I7U nd
ON GZ7Z4.LUEVY = nd.id
RIGHT JOIN (
SELECT
THNTS.id,
YK2GW.FTQLQ AS T4IBQ
FROM THNTS
INNER JOIN YK2GW
ON IXUXU = YK2GW.id
) bs
ON ms.GXLUB = bs.id
LEFT JOIN AMYXQ fc
ON bs.id = fc.GXLUB AND nd.id = fc.LUEVY
LEFT JOIN (
SELECT
iq.T4IBQ,
iq.BRQP2,
iq.Z7CP5,
CASE
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P = 'L5Q44' AND iq.IDWIO = 'KAOAS'
THEN 0
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P = 'L5Q44' AND iq.IDWIO = 'OG'
THEN 0
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P = 'L5Q44' AND iq.IDWIO = 'TSG'
THEN 0
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P <> 'L5Q44' AND iq.IDWIO = 'W6W24'
THEN 1
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P <> 'L5Q44' AND iq.IDWIO = 'OG'
THEN 1
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P <> 'L5Q44' AND iq.IDWIO = 'TSG'
THEN 0
ELSE NULL
END AS YHYLK
FROM (
SELECT /*+ JOIN_ORDER( cla, bs, mf, nd, nma, sn ) */
cla.FTQLQ AS T4IBQ,
sn.BRQP2,
mf.id AS Z7CP5,
mf.FSDY2,
nma.DZLIM AS IDWIO
FROM
HGMQ6 mf
INNER JOIN THNTS bs
ON mf.GXLUB = bs.id
INNER JOIN YK2GW cla
ON bs.IXUXU = cla.id
INNER JOIN E2I7U nd
ON mf.LUEVY = nd.id
INNER JOIN TNMXI nma
ON nd.HPCMS = nma.id
INNER JOIN NOXN3 sn
ON sn.BRQP2 = nd.id
WHERE cla.FTQLQ IN ('SQ1')
) iq
LEFT JOIN SEQS3 W2MAO
ON iq.Z7CP5 = W2MAO.Z7CP5
LEFT JOIN D34QP vc
ON W2MAO.YH4XB = vc.id
) F26ZW
ON F26ZW.T4IBQ = bs.T4IBQ AND F26ZW.BRQP2 = nd.id
LEFT JOIN TNMXI nma
ON nd.HPCMS = nma.id
WHERE bs.T4IBQ IN ('SQ1') AND ms.D237E = TRUE)
SELECT
XPRW6.T4IBQ AS T4IBQ,
XPRW6.ECUWU AS ECUWU,
SUM(XPRW6.B5OUF) AS B5OUF,
SUM(XPRW6.SP4SI) AS SP4SI
FROM (
SELECT
NRFJ3.T4IBQ AS T4IBQ,
NRFJ3.ECUWU AS ECUWU,
NRFJ3.GSTQA AS GSTQA,
NRFJ3.B5OUF AS B5OUF,
SUM(CASE
WHEN NRFJ3.OZTQF < 0.5 OR NRFJ3.YHYLK = 0 THEN 1
ELSE 0
END) AS SP4SI
FROM (
SELECT DISTINCT
T4IBQ,
ECUWU,
GSTQA,
B5OUF,
TW55N,
OZTQF,
YHYLK
FROM
AX7FV) NRFJ3
GROUP BY T4IBQ, ECUWU, GSTQA
) XPRW6
GROUP BY T4IBQ, ECUWU`,
ExpectedPlan: "Project\n" +
" ├─ columns: [xprw6.T4IBQ:2!null as T4IBQ, xprw6.ECUWU:3!null as ECUWU, sum(xprw6.b5ouf):0!null as B5OUF, sum(xprw6.sp4si):1!null as SP4SI]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(xprw6.B5OUF:3), SUM(xprw6.SP4SI:4!null), xprw6.T4IBQ:0!null, xprw6.ECUWU:1!null\n" +
" ├─ group: xprw6.T4IBQ:0!null as T4IBQ, xprw6.ECUWU:1!null as ECUWU\n" +
" └─ SubqueryAlias\n" +
" ├─ name: xprw6\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nrfj3.T4IBQ:1!null as T4IBQ, nrfj3.ECUWU:2!null as ECUWU, nrfj3.GSTQA:3!null as GSTQA, nrfj3.B5OUF:4 as B5OUF, sum(case when ((nrfj3.oztqf < 0.5) or (nrfj3.yhylk = 0)) then 1 else 0 end):0!null as SP4SI]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(CASE WHEN Or\n" +
" │ ├─ LessThan\n" +
" │ │ ├─ nrfj3.OZTQF:5!null\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ └─ Eq\n" +
" │ ├─ nrfj3.YHYLK:6\n" +
" │ └─ 0 (tinyint)\n" +
" │ THEN 1 (tinyint) ELSE 0 (tinyint) END), nrfj3.T4IBQ:0!null, nrfj3.ECUWU:1!null, nrfj3.GSTQA:2!null, nrfj3.B5OUF:3\n" +
" ├─ group: nrfj3.T4IBQ:0!null as T4IBQ, nrfj3.ECUWU:1!null as ECUWU, nrfj3.GSTQA:2!null as GSTQA\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nrfj3\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ax7fv.T4IBQ:0!null, ax7fv.ECUWU:1!null, ax7fv.GSTQA:2!null, ax7fv.B5OUF:3, ax7fv.TW55N:6!null, ax7fv.OZTQF:4!null, ax7fv.YHYLK:5]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ax7fv\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [bs.T4IBQ:1!null as T4IBQ, pa.DZLIM:8!null as ECUWU, pga.DZLIM:17!null as GSTQA, pog.B5OUF:15, fc.OZTQF:20!null, f26zw.YHYLK:24, nd.TW55N:3!null as TW55N]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ ms.D237E:11!null\n" +
" │ └─ true (tinyint)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.HPCMS:4!null\n" +
" │ └─ nma.id:25!null\n" +
" ├─ LeftOuterHashJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ f26zw.T4IBQ:21!null\n" +
" │ │ │ └─ bs.T4IBQ:1!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ f26zw.BRQP2:22!null\n" +
" │ │ └─ nd.id:2!null\n" +
" │ ├─ LeftOuterHashJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ bs.id:0!null\n" +
" │ │ │ │ └─ fc.GXLUB:18!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ nd.id:2!null\n" +
" │ │ │ └─ fc.LUEVY:19!null\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ms.GXLUB:9!null\n" +
" │ │ │ │ └─ bs.id:0!null\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: bs\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ T4IBQ:1!null\n" +
" │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [thnts.id:2!null, yk2gw.FTQLQ:1!null as T4IBQ]\n" +
" │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ yk2gw.id:0!null\n" +
" │ │ │ │ │ └─ thnts.IXUXU:3\n" +
" │ │ │ │ ├─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(bs.id:0!null)\n" +
" │ │ │ ├─ right-key: TUPLE(ms.GXLUB:7!null)\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ pog.id:12!null\n" +
" │ │ │ │ └─ gz7z4.GMSGA:6!null\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ nd.id:2!null\n" +
" │ │ │ │ │ └─ gz7z4.LUEVY:5!null\n" +
" │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id tw55n hpcms]\n" +
" │ │ │ │ └─ TableAlias(gz7z4)\n" +
" │ │ │ │ └─ IndexedTableAccess(FEIOE)\n" +
" │ │ │ │ ├─ index: [FEIOE.LUEVY,FEIOE.GMSGA]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [luevy gmsga]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(gz7z4.GMSGA:6!null)\n" +
" │ │ │ ├─ right-key: TUPLE(pog.id:5!null)\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ pog.XVSBH:14\n" +
" │ │ │ │ └─ pga.id:16!null\n" +
" │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ pa.id:7!null\n" +
" │ │ │ │ │ └─ pog.CH3FR:13!null\n" +
" │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ ├─ pa.id:7!null\n" +
" │ │ │ │ │ │ └─ ms.CH3FR:10!null\n" +
" │ │ │ │ │ ├─ TableAlias(pa)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ │ │ │ │ ├─ index: [XOAOP.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ │ └─ TableAlias(ms)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(SZQWJ)\n" +
" │ │ │ │ │ ├─ index: [SZQWJ.CH3FR]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [gxlub ch3fr d237e]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(pa.id:7!null)\n" +
" │ │ │ │ ├─ right-key: TUPLE(pog.CH3FR:1!null)\n" +
" │ │ │ │ └─ TableAlias(pog)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NPCYY\n" +
" │ │ │ │ └─ columns: [id ch3fr xvsbh b5ouf]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(pog.XVSBH:14)\n" +
" │ │ │ ├─ right-key: TUPLE(pga.id:0!null)\n" +
" │ │ │ └─ TableAlias(pga)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: PG27A\n" +
" │ │ │ └─ columns: [id dzlim]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(bs.id:0!null, nd.id:2!null)\n" +
" │ │ ├─ right-key: TUPLE(fc.GXLUB:0!null, fc.LUEVY:1!null)\n" +
" │ │ └─ TableAlias(fc)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: AMYXQ\n" +
" │ │ └─ columns: [gxlub luevy oztqf]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(bs.T4IBQ:1!null, nd.id:2!null)\n" +
" │ ├─ right-key: TUPLE(f26zw.T4IBQ:0!null, f26zw.BRQP2:1!null)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: f26zw\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [iq.T4IBQ:0!null, iq.BRQP2:1!null, iq.Z7CP5:2!null, CASE WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ KAOAS (longtext)\n" +
" │ │ THEN 0 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ OG (longtext)\n" +
" │ │ THEN 0 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ TSG (longtext)\n" +
" │ │ THEN 0 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ W6W24 (longtext)\n" +
" │ │ THEN 1 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ OG (longtext)\n" +
" │ │ THEN 1 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ TSG (longtext)\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as YHYLK]\n" +
" │ └─ LeftOuterHashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ w2mao.YH4XB:6!null\n" +
" │ │ └─ vc.id:7!null\n" +
" │ ├─ LeftOuterHashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ iq.Z7CP5:2!null\n" +
" │ │ │ └─ w2mao.Z7CP5:5!null\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: iq\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [cla.FTQLQ:1!null as T4IBQ, sn.BRQP2:12!null, mf.id:4!null as Z7CP5, mf.FSDY2:7!null, nma.DZLIM:11!null as IDWIO]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ HashIn\n" +
" │ │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ mf.LUEVY:6!null\n" +
" │ │ │ │ │ └─ nd.id:8!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ mf.LUEVY:6!null\n" +
" │ │ │ │ └─ sn.BRQP2:12!null\n" +
" │ │ │ ├─ HashJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ mf.GXLUB:5!null\n" +
" │ │ │ │ │ └─ bs.id:2!null\n" +
" │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ ├─ cla.id:0!null\n" +
" │ │ │ │ │ │ └─ bs.IXUXU:3\n" +
" │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(bs.id:2!null)\n" +
" │ │ │ │ ├─ right-key: TUPLE(mf.GXLUB:1!null)\n" +
" │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ │ └─ columns: [id gxlub luevy fsdy2]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(mf.LUEVY:6!null, mf.LUEVY:6!null)\n" +
" │ │ │ ├─ right-key: TUPLE(nd.id:0!null, sn.BRQP2:4!null)\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ sn.BRQP2:12!null\n" +
" │ │ │ │ └─ nd.id:8!null\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ nd.HPCMS:9!null\n" +
" │ │ │ │ │ └─ nma.id:10!null\n" +
" │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.HPCMS]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id hpcms]\n" +
" │ │ │ │ └─ TableAlias(nma)\n" +
" │ │ │ │ └─ IndexedTableAccess(TNMXI)\n" +
" │ │ │ │ ├─ index: [TNMXI.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(nd.id:8!null)\n" +
" │ │ │ ├─ right-key: TUPLE(sn.BRQP2:0!null)\n" +
" │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [brqp2]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(iq.Z7CP5:2!null)\n" +
" │ │ ├─ right-key: TUPLE(w2mao.Z7CP5:0!null)\n" +
" │ │ └─ TableAlias(w2mao)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SEQS3\n" +
" │ │ └─ columns: [z7cp5 yh4xb]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(w2mao.YH4XB:6!null)\n" +
" │ ├─ right-key: TUPLE(vc.id:0!null)\n" +
" │ └─ TableAlias(vc)\n" +
" │ └─ Table\n" +
" │ ├─ name: D34QP\n" +
" │ └─ columns: [id znp4p]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(nd.HPCMS:4!null)\n" +
" ├─ right-key: TUPLE(nma.id:0!null)\n" +
" └─ TableAlias(nma)\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" └─ columns: [id]\n" +
"",
},
{
Query: `
WITH AX7FV AS
(SELECT
bs.T4IBQ AS T4IBQ,
pa.DZLIM AS ECUWU,
pga.DZLIM AS GSTQA,
pog.B5OUF,
fc.OZTQF,
F26ZW.YHYLK,
nd.TW55N AS TW55N
FROM
SZQWJ ms
INNER JOIN XOAOP pa
ON ms.CH3FR = pa.id
LEFT JOIN NPCYY pog
ON pa.id = pog.CH3FR
INNER JOIN PG27A pga
ON pog.XVSBH = pga.id
INNER JOIN FEIOE GZ7Z4
ON pog.id = GZ7Z4.GMSGA
INNER JOIN E2I7U nd
ON GZ7Z4.LUEVY = nd.id
RIGHT JOIN (
SELECT
THNTS.id,
YK2GW.FTQLQ AS T4IBQ
FROM THNTS
INNER JOIN YK2GW
ON IXUXU = YK2GW.id
) bs
ON ms.GXLUB = bs.id
LEFT JOIN AMYXQ fc
ON bs.id = fc.GXLUB AND nd.id = fc.LUEVY
LEFT JOIN (
SELECT
iq.T4IBQ,
iq.BRQP2,
iq.Z7CP5,
CASE
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P = 'L5Q44' AND iq.IDWIO = 'KAOAS'
THEN 0
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P = 'L5Q44' AND iq.IDWIO = 'OG'
THEN 0
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P = 'L5Q44' AND iq.IDWIO = 'TSG'
THEN 0
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P <> 'L5Q44' AND iq.IDWIO = 'W6W24'
THEN 1
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P <> 'L5Q44' AND iq.IDWIO = 'OG'
THEN 1
WHEN iq.FSDY2 IN ('SRARY','UBQWG') AND vc.ZNP4P <> 'L5Q44' AND iq.IDWIO = 'TSG'
THEN 0
ELSE NULL
END AS YHYLK
FROM (
SELECT
cla.FTQLQ AS T4IBQ,
sn.BRQP2,
mf.id AS Z7CP5,
mf.FSDY2,
nma.DZLIM AS IDWIO
FROM
HGMQ6 mf
INNER JOIN THNTS bs
ON mf.GXLUB = bs.id
INNER JOIN YK2GW cla
ON bs.IXUXU = cla.id
INNER JOIN E2I7U nd
ON mf.LUEVY = nd.id
INNER JOIN TNMXI nma
ON nd.HPCMS = nma.id
INNER JOIN NOXN3 sn
ON sn.BRQP2 = nd.id
WHERE cla.FTQLQ IN ('SQ1')
) iq
LEFT JOIN SEQS3 W2MAO
ON iq.Z7CP5 = W2MAO.Z7CP5
LEFT JOIN D34QP vc
ON W2MAO.YH4XB = vc.id
) F26ZW
ON F26ZW.T4IBQ = bs.T4IBQ AND F26ZW.BRQP2 = nd.id
LEFT JOIN TNMXI nma
ON nd.HPCMS = nma.id
WHERE bs.T4IBQ IN ('SQ1') AND ms.D237E = TRUE)
SELECT
XPRW6.T4IBQ AS T4IBQ,
XPRW6.ECUWU AS ECUWU,
SUM(XPRW6.B5OUF) AS B5OUF,
SUM(XPRW6.SP4SI) AS SP4SI
FROM (
SELECT
NRFJ3.T4IBQ AS T4IBQ,
NRFJ3.ECUWU AS ECUWU,
NRFJ3.GSTQA AS GSTQA,
NRFJ3.B5OUF AS B5OUF,
SUM(CASE
WHEN NRFJ3.OZTQF < 0.5 OR NRFJ3.YHYLK = 0 THEN 1
ELSE 0
END) AS SP4SI
FROM (
SELECT DISTINCT
T4IBQ,
ECUWU,
GSTQA,
B5OUF,
TW55N,
OZTQF,
YHYLK
FROM
AX7FV) NRFJ3
GROUP BY T4IBQ, ECUWU, GSTQA
) XPRW6
GROUP BY T4IBQ, ECUWU`,
ExpectedPlan: "Project\n" +
" ├─ columns: [xprw6.T4IBQ:2!null as T4IBQ, xprw6.ECUWU:3!null as ECUWU, sum(xprw6.b5ouf):0!null as B5OUF, sum(xprw6.sp4si):1!null as SP4SI]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(xprw6.B5OUF:3), SUM(xprw6.SP4SI:4!null), xprw6.T4IBQ:0!null, xprw6.ECUWU:1!null\n" +
" ├─ group: xprw6.T4IBQ:0!null as T4IBQ, xprw6.ECUWU:1!null as ECUWU\n" +
" └─ SubqueryAlias\n" +
" ├─ name: xprw6\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nrfj3.T4IBQ:1!null as T4IBQ, nrfj3.ECUWU:2!null as ECUWU, nrfj3.GSTQA:3!null as GSTQA, nrfj3.B5OUF:4 as B5OUF, sum(case when ((nrfj3.oztqf < 0.5) or (nrfj3.yhylk = 0)) then 1 else 0 end):0!null as SP4SI]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(CASE WHEN Or\n" +
" │ ├─ LessThan\n" +
" │ │ ├─ nrfj3.OZTQF:5!null\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ └─ Eq\n" +
" │ ├─ nrfj3.YHYLK:6\n" +
" │ └─ 0 (tinyint)\n" +
" │ THEN 1 (tinyint) ELSE 0 (tinyint) END), nrfj3.T4IBQ:0!null, nrfj3.ECUWU:1!null, nrfj3.GSTQA:2!null, nrfj3.B5OUF:3\n" +
" ├─ group: nrfj3.T4IBQ:0!null as T4IBQ, nrfj3.ECUWU:1!null as ECUWU, nrfj3.GSTQA:2!null as GSTQA\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nrfj3\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ax7fv.T4IBQ:0!null, ax7fv.ECUWU:1!null, ax7fv.GSTQA:2!null, ax7fv.B5OUF:3, ax7fv.TW55N:6!null, ax7fv.OZTQF:4!null, ax7fv.YHYLK:5]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ax7fv\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [bs.T4IBQ:1!null as T4IBQ, pa.DZLIM:8!null as ECUWU, pga.DZLIM:17!null as GSTQA, pog.B5OUF:15, fc.OZTQF:20!null, f26zw.YHYLK:24, nd.TW55N:3!null as TW55N]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ ms.D237E:11!null\n" +
" │ └─ true (tinyint)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.HPCMS:4!null\n" +
" │ └─ nma.id:25!null\n" +
" ├─ LeftOuterHashJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ f26zw.T4IBQ:21!null\n" +
" │ │ │ └─ bs.T4IBQ:1!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ f26zw.BRQP2:22!null\n" +
" │ │ └─ nd.id:2!null\n" +
" │ ├─ LeftOuterHashJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ bs.id:0!null\n" +
" │ │ │ │ └─ fc.GXLUB:18!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ nd.id:2!null\n" +
" │ │ │ └─ fc.LUEVY:19!null\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ms.GXLUB:9!null\n" +
" │ │ │ │ └─ bs.id:0!null\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: bs\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ T4IBQ:1!null\n" +
" │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [thnts.id:2!null, yk2gw.FTQLQ:1!null as T4IBQ]\n" +
" │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ yk2gw.id:0!null\n" +
" │ │ │ │ │ └─ thnts.IXUXU:3\n" +
" │ │ │ │ ├─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(bs.id:0!null)\n" +
" │ │ │ ├─ right-key: TUPLE(ms.GXLUB:7!null)\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ pog.id:12!null\n" +
" │ │ │ │ └─ gz7z4.GMSGA:6!null\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ nd.id:2!null\n" +
" │ │ │ │ │ └─ gz7z4.LUEVY:5!null\n" +
" │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id tw55n hpcms]\n" +
" │ │ │ │ └─ TableAlias(gz7z4)\n" +
" │ │ │ │ └─ IndexedTableAccess(FEIOE)\n" +
" │ │ │ │ ├─ index: [FEIOE.LUEVY,FEIOE.GMSGA]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [luevy gmsga]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(gz7z4.GMSGA:6!null)\n" +
" │ │ │ ├─ right-key: TUPLE(pog.id:5!null)\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ pog.XVSBH:14\n" +
" │ │ │ │ └─ pga.id:16!null\n" +
" │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ pa.id:7!null\n" +
" │ │ │ │ │ └─ pog.CH3FR:13!null\n" +
" │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ ├─ pa.id:7!null\n" +
" │ │ │ │ │ │ └─ ms.CH3FR:10!null\n" +
" │ │ │ │ │ ├─ TableAlias(pa)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ │ │ │ │ ├─ index: [XOAOP.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ │ └─ TableAlias(ms)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(SZQWJ)\n" +
" │ │ │ │ │ ├─ index: [SZQWJ.CH3FR]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [gxlub ch3fr d237e]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(pa.id:7!null)\n" +
" │ │ │ │ ├─ right-key: TUPLE(pog.CH3FR:1!null)\n" +
" │ │ │ │ └─ TableAlias(pog)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NPCYY\n" +
" │ │ │ │ └─ columns: [id ch3fr xvsbh b5ouf]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(pog.XVSBH:14)\n" +
" │ │ │ ├─ right-key: TUPLE(pga.id:0!null)\n" +
" │ │ │ └─ TableAlias(pga)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: PG27A\n" +
" │ │ │ └─ columns: [id dzlim]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(bs.id:0!null, nd.id:2!null)\n" +
" │ │ ├─ right-key: TUPLE(fc.GXLUB:0!null, fc.LUEVY:1!null)\n" +
" │ │ └─ TableAlias(fc)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: AMYXQ\n" +
" │ │ └─ columns: [gxlub luevy oztqf]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(bs.T4IBQ:1!null, nd.id:2!null)\n" +
" │ ├─ right-key: TUPLE(f26zw.T4IBQ:0!null, f26zw.BRQP2:1!null)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: f26zw\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [iq.T4IBQ:0!null, iq.BRQP2:1!null, iq.Z7CP5:2!null, CASE WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ KAOAS (longtext)\n" +
" │ │ THEN 0 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ OG (longtext)\n" +
" │ │ THEN 0 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ TSG (longtext)\n" +
" │ │ THEN 0 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ W6W24 (longtext)\n" +
" │ │ THEN 1 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ OG (longtext)\n" +
" │ │ THEN 1 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ IN\n" +
" │ │ │ │ ├─ left: iq.FSDY2:3!null\n" +
" │ │ │ │ └─ right: TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ vc.ZNP4P:8!null\n" +
" │ │ │ └─ L5Q44 (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ iq.IDWIO:4!null\n" +
" │ │ └─ TSG (longtext)\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as YHYLK]\n" +
" │ └─ LeftOuterHashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ w2mao.YH4XB:6!null\n" +
" │ │ └─ vc.id:7!null\n" +
" │ ├─ LeftOuterHashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ iq.Z7CP5:2!null\n" +
" │ │ │ └─ w2mao.Z7CP5:5!null\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: iq\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [cla.FTQLQ:7!null as T4IBQ, sn.BRQP2:8!null, mf.id:2!null as Z7CP5, mf.FSDY2:5!null, nma.DZLIM:10!null as IDWIO]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ HashIn\n" +
" │ │ │ │ ├─ cla.FTQLQ:7!null\n" +
" │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ mf.LUEVY:4!null\n" +
" │ │ │ │ │ └─ nd.id:11!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ mf.LUEVY:4!null\n" +
" │ │ │ │ └─ sn.BRQP2:8!null\n" +
" │ │ │ ├─ HashJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ bs.IXUXU:1\n" +
" │ │ │ │ │ └─ cla.id:6!null\n" +
" │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ ├─ bs.id:0!null\n" +
" │ │ │ │ │ │ └─ mf.GXLUB:3!null\n" +
" │ │ │ │ │ ├─ TableAlias(bs)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ │ │ ├─ index: [THNTS.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ ├─ index: [HGMQ6.GXLUB]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id gxlub luevy fsdy2]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(bs.IXUXU:1)\n" +
" │ │ │ │ ├─ right-key: TUPLE(cla.id:0!null)\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ ├─ index: [YK2GW.FTQLQ]\n" +
" │ │ │ │ ├─ static: [{[SQ1, SQ1]}]\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(mf.LUEVY:4!null, mf.LUEVY:4!null)\n" +
" │ │ │ ├─ right-key: TUPLE(nd.id:3!null, sn.BRQP2:0!null)\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ sn.BRQP2:8!null\n" +
" │ │ │ │ └─ nd.id:11!null\n" +
" │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [brqp2]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(sn.BRQP2:8!null)\n" +
" │ │ │ ├─ right-key: TUPLE(nd.id:2!null)\n" +
" │ │ │ └─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ nma.id:9!null\n" +
" │ │ │ │ └─ nd.HPCMS:12!null\n" +
" │ │ │ ├─ TableAlias(nma)\n" +
" │ │ │ │ └─ IndexedTableAccess(TNMXI)\n" +
" │ │ │ │ ├─ index: [TNMXI.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.HPCMS]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id hpcms]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(iq.Z7CP5:2!null)\n" +
" │ │ ├─ right-key: TUPLE(w2mao.Z7CP5:0!null)\n" +
" │ │ └─ TableAlias(w2mao)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SEQS3\n" +
" │ │ └─ columns: [z7cp5 yh4xb]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(w2mao.YH4XB:6!null)\n" +
" │ ├─ right-key: TUPLE(vc.id:0!null)\n" +
" │ └─ TableAlias(vc)\n" +
" │ └─ Table\n" +
" │ ├─ name: D34QP\n" +
" │ └─ columns: [id znp4p]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(nd.HPCMS:4!null)\n" +
" ├─ right-key: TUPLE(nma.id:0!null)\n" +
" └─ TableAlias(nma)\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" └─ columns: [id]\n" +
"",
},
{
Query: `
SELECT
TUSAY.Y3IOU AS RWGEU
FROM
(SELECT
id AS Y46B2,
WNUNU AS WNUNU,
HVHRZ AS HVHRZ
FROM
QYWQD) XJ2RD
INNER JOIN
(SELECT
ROW_NUMBER() OVER (ORDER BY id ASC) Y3IOU,
id AS XLFIA
FROM
NOXN3) TUSAY
ON XJ2RD.WNUNU = TUSAY.XLFIA
ORDER BY Y46B2 ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [tusay.Y3IOU:3!null as RWGEU]\n" +
" └─ Sort(xj2rd.Y46B2:0!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [xj2rd.Y46B2:2!null, xj2rd.WNUNU:3!null, xj2rd.HVHRZ:4!null, tusay.Y3IOU:0!null, tusay.XLFIA:1!null, tusay.Y3IOU:0!null as RWGEU]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ xj2rd.WNUNU:3!null\n" +
" │ └─ tusay.XLFIA:1!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: tusay\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [row_number() over ( order by noxn3.id asc):0!null as Y3IOU, noxn3.id:1!null as XLFIA]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:0!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(tusay.XLFIA:1!null)\n" +
" ├─ right-key: TUPLE(xj2rd.WNUNU:1!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: xj2rd\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [qywqd.id:0!null as Y46B2, qywqd.WNUNU:1!null as WNUNU, qywqd.HVHRZ:2!null as HVHRZ]\n" +
" └─ Table\n" +
" ├─ name: QYWQD\n" +
" └─ columns: [id wnunu hvhrz]\n" +
"",
},
{
Query: `
SELECT
ECXAJ
FROM
E2I7U
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [e2i7u.ECXAJ:5!null]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT
CASE
WHEN YZXYP.Z35GY IS NOT NULL THEN YZXYP.Z35GY
ELSE -1
END AS FMSOH
FROM
(SELECT
nd.T722E,
fc.Z35GY
FROM
(SELECT
id AS T722E
FROM
E2I7U) nd
LEFT JOIN
(SELECT
LUEVY AS ZPAIK,
MAX(Z35GY) AS Z35GY
FROM AMYXQ
GROUP BY LUEVY) fc
ON nd.T722E = fc.ZPAIK
ORDER BY nd.T722E ASC) YZXYP`,
ExpectedPlan: "Project\n" +
" ├─ columns: [CASE WHEN NOT\n" +
" │ └─ yzxyp.Z35GY:1!null IS NULL\n" +
" │ THEN yzxyp.Z35GY:1!null ELSE -1 (tinyint) END as FMSOH]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: yzxyp\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.T722E:0!null, fc.Z35GY:2!null]\n" +
" └─ Sort(nd.T722E:0!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [nd.T722E:0!null, fc.ZPAIK:1!null, fc.Z35GY:2!null]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.T722E:0!null\n" +
" │ └─ fc.ZPAIK:1!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id:0!null as T722E]\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(nd.T722E:0!null)\n" +
" ├─ right-key: TUPLE(fc.ZPAIK:0!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: fc\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [amyxq.LUEVY:1!null as ZPAIK, max(amyxq.z35gy):0!null as Z35GY]\n" +
" └─ GroupBy\n" +
" ├─ select: MAX(amyxq.Z35GY:1!null), amyxq.LUEVY:0!null\n" +
" ├─ group: amyxq.luevy:0!null\n" +
" └─ Table\n" +
" ├─ name: AMYXQ\n" +
" └─ columns: [luevy z35gy]\n" +
"",
},
{
Query: `
SELECT
CASE
WHEN
FGG57 IS NULL
THEN 0
WHEN
id IN (SELECT id FROM E2I7U WHERE NOT id IN (SELECT LUEVY FROM AMYXQ))
THEN 1
WHEN
FSK67 = 'z'
THEN 2
WHEN
FSK67 = 'CRZ2X'
THEN 0
ELSE 3
END AS SZ6KK
FROM E2I7U
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [CASE WHEN e2i7u.FGG57:6 IS NULL THEN 0 (tinyint) WHEN InSubquery\n" +
" │ ├─ left: e2i7u.id:0!null\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id:18!null]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id:18!null, E2I7U.DKCAJ:19!null, E2I7U.KNG7T:20, E2I7U.TW55N:21!null, E2I7U.QRQXW:22!null, E2I7U.ECXAJ:23!null, E2I7U.FGG57:24, E2I7U.ZH72S:25, E2I7U.FSK67:26!null, E2I7U.XQDYT:27!null, E2I7U.TCE7A:28, E2I7U.IWV2H:29, E2I7U.HPCMS:30!null, E2I7U.N5CC2:31, E2I7U.FHCYT:32, E2I7U.ETAQ7:33, E2I7U.A75X7:34]\n" +
" │ └─ Filter\n" +
" │ ├─ scalarSubq0.LUEVY:35!null IS NULL\n" +
" │ └─ LeftOuterMergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ e2i7u.id:18!null\n" +
" │ │ └─ scalarSubq0.LUEVY:35!null\n" +
" │ ├─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ TableAlias(scalarSubq0)\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [luevy]\n" +
" │ THEN 1 (tinyint) WHEN Eq\n" +
" │ ├─ e2i7u.FSK67:8!null\n" +
" │ └─ z (longtext)\n" +
" │ THEN 2 (tinyint) WHEN Eq\n" +
" │ ├─ e2i7u.FSK67:8!null\n" +
" │ └─ CRZ2X (longtext)\n" +
" │ THEN 0 (tinyint) ELSE 3 (tinyint) END as SZ6KK]\n" +
" └─ Project\n" +
" ├─ columns: [e2i7u.id:0!null, e2i7u.DKCAJ:1!null, e2i7u.KNG7T:2, e2i7u.TW55N:3!null, e2i7u.QRQXW:4!null, e2i7u.ECXAJ:5!null, e2i7u.FGG57:6, e2i7u.ZH72S:7, e2i7u.FSK67:8!null, e2i7u.XQDYT:9!null, e2i7u.TCE7A:10, e2i7u.IWV2H:11, e2i7u.HPCMS:12!null, e2i7u.N5CC2:13, e2i7u.FHCYT:14, e2i7u.ETAQ7:15, e2i7u.A75X7:16, CASE WHEN e2i7u.FGG57:6 IS NULL THEN 0 (tinyint) WHEN InSubquery\n" +
" │ ├─ left: e2i7u.id:0!null\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id:17!null]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id:17!null, E2I7U.DKCAJ:18!null, E2I7U.KNG7T:19, E2I7U.TW55N:20!null, E2I7U.QRQXW:21!null, E2I7U.ECXAJ:22!null, E2I7U.FGG57:23, E2I7U.ZH72S:24, E2I7U.FSK67:25!null, E2I7U.XQDYT:26!null, E2I7U.TCE7A:27, E2I7U.IWV2H:28, E2I7U.HPCMS:29!null, E2I7U.N5CC2:30, E2I7U.FHCYT:31, E2I7U.ETAQ7:32, E2I7U.A75X7:33]\n" +
" │ └─ Filter\n" +
" │ ├─ scalarSubq0.LUEVY:34!null IS NULL\n" +
" │ └─ LeftOuterMergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ e2i7u.id:17!null\n" +
" │ │ └─ scalarSubq0.LUEVY:34!null\n" +
" │ ├─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ TableAlias(scalarSubq0)\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [luevy]\n" +
" │ THEN 1 (tinyint) WHEN Eq\n" +
" │ ├─ e2i7u.FSK67:8!null\n" +
" │ └─ z (longtext)\n" +
" │ THEN 2 (tinyint) WHEN Eq\n" +
" │ ├─ e2i7u.FSK67:8!null\n" +
" │ └─ CRZ2X (longtext)\n" +
" │ THEN 0 (tinyint) ELSE 3 (tinyint) END as SZ6KK]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
WITH
BMRZU AS
(SELECT /*+ JOIN_ORDER( cla, bs, mf, sn, aac, W2MAO, vc ) */
cla.FTQLQ AS T4IBQ,
sn.id AS BDNYB,
aac.BTXC5 AS BTXC5,
mf.id AS Z7CP5,
CASE
WHEN mf.LT7K6 IS NOT NULL THEN mf.LT7K6
ELSE mf.SPPYD
END AS vaf,
CASE
WHEN mf.QCGTS IS NOT NULL THEN QCGTS
ELSE 0.5
END AS QCGTS,
CASE
WHEN vc.ZNP4P = 'L5Q44' THEN 1
ELSE 0
END AS SNY4H
FROM YK2GW cla
INNER JOIN THNTS bs ON bs.IXUXU = cla.id
INNER JOIN HGMQ6 mf ON mf.GXLUB = bs.id
INNER JOIN NOXN3 sn ON sn.BRQP2 = mf.LUEVY
INNER JOIN TPXBU aac ON aac.id = mf.M22QN
INNER JOIN SEQS3 W2MAO ON W2MAO.Z7CP5 = mf.id
INNER JOIN D34QP vc ON vc.id = W2MAO.YH4XB
WHERE cla.FTQLQ IN ('SQ1')
AND mf.FSDY2 IN ('SRARY', 'UBQWG')),
YU7NY AS
(SELECT
nd.TW55N AS KUXQY,
sn.id AS BDNYB,
nma.DZLIM AS YHVEZ,
CASE
WHEN nd.TCE7A < 0.9 THEN 1
ELSE 0
END AS YAZ4X
FROM NOXN3 sn
LEFT JOIN E2I7U nd ON sn.BRQP2 = nd.id
LEFT JOIN TNMXI nma ON nd.HPCMS = nma.id
WHERE nma.DZLIM != 'Q5I4E'
ORDER BY sn.id ASC)
SELECT DISTINCT
OXXEI.T4IBQ,
OXXEI.Z7CP5,
E52AP.KUXQY,
OXXEI.BDNYB,
CKELE.M6T2N,
OXXEI.BTXC5 as BTXC5,
OXXEI.vaf as vaf,
OXXEI.QCGTS as QCGTS,
OXXEI.SNY4H as SNY4H,
E52AP.YHVEZ as YHVEZ,
E52AP.YAZ4X as YAZ4X
FROM
BMRZU OXXEI
INNER JOIN YU7NY E52AP ON E52AP.BDNYB = OXXEI.BDNYB
INNER JOIN
(SELECT
NOXN3.id as LWQ6O,
ROW_NUMBER() OVER (ORDER BY NOXN3.id ASC) M6T2N
FROM NOXN3) CKELE
ON CKELE.LWQ6O = OXXEI.BDNYB
ORDER BY CKELE.M6T2N ASC`,
ExpectedPlan: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [oxxei.T4IBQ:0!null, oxxei.Z7CP5:3!null, e52ap.KUXQY:7!null, oxxei.BDNYB:1!null, ckele.M6T2N:12!null, oxxei.BTXC5:2 as BTXC5, oxxei.vaf:4 as vaf, oxxei.QCGTS:5 as QCGTS, oxxei.SNY4H:6!null as SNY4H, e52ap.YHVEZ:9!null as YHVEZ, e52ap.YAZ4X:10!null as YAZ4X]\n" +
" └─ Sort(ckele.M6T2N:12!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [oxxei.T4IBQ:2!null, oxxei.BDNYB:3!null, oxxei.BTXC5:4, oxxei.Z7CP5:5!null, oxxei.vaf:6, oxxei.QCGTS:7, oxxei.SNY4H:8!null, e52ap.KUXQY:9!null, e52ap.BDNYB:10!null, e52ap.YHVEZ:11!null, e52ap.YAZ4X:12!null, ckele.LWQ6O:0!null, ckele.M6T2N:1!null, oxxei.BTXC5:4 as BTXC5, oxxei.vaf:6 as vaf, oxxei.QCGTS:7 as QCGTS, oxxei.SNY4H:8!null as SNY4H, e52ap.YHVEZ:11!null as YHVEZ, e52ap.YAZ4X:12!null as YAZ4X]\n" +
" └─ HashJoin\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ e52ap.BDNYB:10!null\n" +
" │ │ └─ oxxei.BDNYB:3!null\n" +
" │ └─ Eq\n" +
" │ ├─ e52ap.BDNYB:10!null\n" +
" │ └─ ckele.LWQ6O:0!null\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ckele.LWQ6O:0!null\n" +
" │ │ └─ oxxei.BDNYB:3!null\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: ckele\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [noxn3.id:1!null as LWQ6O, row_number() over ( order by noxn3.id asc):0!null as M6T2N]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:0!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ckele.LWQ6O:0!null)\n" +
" │ ├─ right-key: TUPLE(oxxei.BDNYB:1!null)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: oxxei\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:1!null as T4IBQ, sn.id:12!null as BDNYB, aac.BTXC5:15 as BTXC5, mf.id:4!null as Z7CP5, CASE WHEN NOT\n" +
" │ │ └─ mf.LT7K6:9 IS NULL\n" +
" │ │ THEN mf.LT7K6:9 ELSE mf.SPPYD:10 END as vaf, CASE WHEN NOT\n" +
" │ │ └─ mf.QCGTS:11 IS NULL\n" +
" │ │ THEN mf.QCGTS:11 ELSE 0.500000 (double) END as QCGTS, CASE WHEN Eq\n" +
" │ │ ├─ vc.ZNP4P:19!null\n" +
" │ │ └─ L5Q44 (longtext)\n" +
" │ │ THEN 1 (tinyint) ELSE 0 (tinyint) END as SNY4H]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ mf.FSDY2:8!null\n" +
" │ │ └─ TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ w2mao.Z7CP5:16!null\n" +
" │ │ └─ mf.id:4!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.id:14!null\n" +
" │ │ │ └─ mf.M22QN:7!null\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ sn.BRQP2:13!null\n" +
" │ │ │ │ └─ mf.LUEVY:6!null\n" +
" │ │ │ ├─ HashJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ mf.GXLUB:5!null\n" +
" │ │ │ │ │ └─ bs.id:2!null\n" +
" │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ ├─ cla.id:0!null\n" +
" │ │ │ │ │ │ └─ bs.IXUXU:3\n" +
" │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(bs.id:2!null)\n" +
" │ │ │ │ ├─ right-key: TUPLE(mf.GXLUB:1!null)\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ mf.FSDY2:4!null\n" +
" │ │ │ │ │ └─ TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ │ └─ columns: [id gxlub luevy m22qn fsdy2 lt7k6 sppyd qcgts]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(mf.LUEVY:6!null)\n" +
" │ │ │ ├─ right-key: TUPLE(sn.BRQP2:1!null)\n" +
" │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(mf.M22QN:7!null)\n" +
" │ │ ├─ right-key: TUPLE(aac.id:0!null)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.id:4!null)\n" +
" │ ├─ right-key: TUPLE(w2mao.Z7CP5:0!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ w2mao.YH4XB:17!null\n" +
" │ │ └─ vc.id:18!null\n" +
" │ ├─ TableAlias(w2mao)\n" +
" │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ ├─ index: [SEQS3.YH4XB]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [z7cp5 yh4xb]\n" +
" │ └─ TableAlias(vc)\n" +
" │ └─ IndexedTableAccess(D34QP)\n" +
" │ ├─ index: [D34QP.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id znp4p]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(oxxei.BDNYB:3!null, ckele.LWQ6O:0!null)\n" +
" ├─ right-key: TUPLE(e52ap.BDNYB:1!null, e52ap.BDNYB:1!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: e52ap\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.TW55N:13!null as KUXQY, sn.id:0!null as BDNYB, nma.DZLIM:28!null as YHVEZ, CASE WHEN LessThan\n" +
" │ ├─ nd.TCE7A:20\n" +
" │ └─ 0.900000 (double)\n" +
" │ THEN 1 (tinyint) ELSE 0 (tinyint) END as YAZ4X]\n" +
" └─ Sort(sn.id:0!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sn.id:0!null, sn.BRQP2:1!null, sn.FFTBJ:2!null, sn.A7XO2:3, sn.KBO7R:4!null, sn.ECDKM:5, sn.NUMK2:6!null, sn.LETOE:7!null, sn.YKSSU:8, sn.FHCYT:9, nd.id:10!null, nd.DKCAJ:11!null, nd.KNG7T:12, nd.TW55N:13!null, nd.QRQXW:14!null, nd.ECXAJ:15!null, nd.FGG57:16, nd.ZH72S:17, nd.FSK67:18!null, nd.XQDYT:19!null, nd.TCE7A:20, nd.IWV2H:21, nd.HPCMS:22!null, nd.N5CC2:23, nd.FHCYT:24, nd.ETAQ7:25, nd.A75X7:26, nma.id:27!null, nma.DZLIM:28!null, nma.F3YUE:29, nd.TW55N:13!null as KUXQY, sn.id:0!null as BDNYB, nma.DZLIM:28!null as YHVEZ, CASE WHEN LessThan\n" +
" │ ├─ nd.TCE7A:20\n" +
" │ └─ 0.900000 (double)\n" +
" │ THEN 1 (tinyint) ELSE 0 (tinyint) END as YAZ4X]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ Eq\n" +
" │ ├─ nma.DZLIM:28!null\n" +
" │ └─ Q5I4E (longtext)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.HPCMS:22!null\n" +
" │ └─ nma.id:27!null\n" +
" ├─ LeftOuterMergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ └─ nd.id:10!null\n" +
" │ ├─ TableAlias(sn)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(nd.HPCMS:22!null)\n" +
" ├─ right-key: TUPLE(nma.id:0!null)\n" +
" └─ TableAlias(nma)\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" └─ columns: [id dzlim f3yue]\n" +
"",
},
{
Query: `
WITH
BMRZU AS
(SELECT
cla.FTQLQ AS T4IBQ,
sn.id AS BDNYB,
aac.BTXC5 AS BTXC5,
mf.id AS Z7CP5,
CASE
WHEN mf.LT7K6 IS NOT NULL THEN mf.LT7K6
ELSE mf.SPPYD
END AS vaf,
CASE
WHEN mf.QCGTS IS NOT NULL THEN QCGTS
ELSE 0.5
END AS QCGTS,
CASE
WHEN vc.ZNP4P = 'L5Q44' THEN 1
ELSE 0
END AS SNY4H
FROM YK2GW cla
INNER JOIN THNTS bs ON bs.IXUXU = cla.id
INNER JOIN HGMQ6 mf ON mf.GXLUB = bs.id
INNER JOIN NOXN3 sn ON sn.BRQP2 = mf.LUEVY
INNER JOIN TPXBU aac ON aac.id = mf.M22QN
INNER JOIN SEQS3 W2MAO ON W2MAO.Z7CP5 = mf.id
INNER JOIN D34QP vc ON vc.id = W2MAO.YH4XB
WHERE cla.FTQLQ IN ('SQ1')
AND mf.FSDY2 IN ('SRARY', 'UBQWG')),
YU7NY AS
(SELECT
nd.TW55N AS KUXQY,
sn.id AS BDNYB,
nma.DZLIM AS YHVEZ,
CASE
WHEN nd.TCE7A < 0.9 THEN 1
ELSE 0
END AS YAZ4X
FROM NOXN3 sn
LEFT JOIN E2I7U nd ON sn.BRQP2 = nd.id
LEFT JOIN TNMXI nma ON nd.HPCMS = nma.id
WHERE nma.DZLIM != 'Q5I4E'
ORDER BY sn.id ASC)
SELECT DISTINCT
OXXEI.T4IBQ,
OXXEI.Z7CP5,
E52AP.KUXQY,
OXXEI.BDNYB,
CKELE.M6T2N,
OXXEI.BTXC5 as BTXC5,
OXXEI.vaf as vaf,
OXXEI.QCGTS as QCGTS,
OXXEI.SNY4H as SNY4H,
E52AP.YHVEZ as YHVEZ,
E52AP.YAZ4X as YAZ4X
FROM
BMRZU OXXEI
INNER JOIN YU7NY E52AP ON E52AP.BDNYB = OXXEI.BDNYB
INNER JOIN
(SELECT
NOXN3.id as LWQ6O,
ROW_NUMBER() OVER (ORDER BY NOXN3.id ASC) M6T2N
FROM NOXN3) CKELE
ON CKELE.LWQ6O = OXXEI.BDNYB
ORDER BY CKELE.M6T2N ASC`,
ExpectedPlan: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [oxxei.T4IBQ:0!null, oxxei.Z7CP5:3!null, e52ap.KUXQY:7!null, oxxei.BDNYB:1!null, ckele.M6T2N:12!null, oxxei.BTXC5:2 as BTXC5, oxxei.vaf:4 as vaf, oxxei.QCGTS:5 as QCGTS, oxxei.SNY4H:6!null as SNY4H, e52ap.YHVEZ:9!null as YHVEZ, e52ap.YAZ4X:10!null as YAZ4X]\n" +
" └─ Sort(ckele.M6T2N:12!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [oxxei.T4IBQ:2!null, oxxei.BDNYB:3!null, oxxei.BTXC5:4, oxxei.Z7CP5:5!null, oxxei.vaf:6, oxxei.QCGTS:7, oxxei.SNY4H:8!null, e52ap.KUXQY:9!null, e52ap.BDNYB:10!null, e52ap.YHVEZ:11!null, e52ap.YAZ4X:12!null, ckele.LWQ6O:0!null, ckele.M6T2N:1!null, oxxei.BTXC5:4 as BTXC5, oxxei.vaf:6 as vaf, oxxei.QCGTS:7 as QCGTS, oxxei.SNY4H:8!null as SNY4H, e52ap.YHVEZ:11!null as YHVEZ, e52ap.YAZ4X:12!null as YAZ4X]\n" +
" └─ HashJoin\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ e52ap.BDNYB:10!null\n" +
" │ │ └─ oxxei.BDNYB:3!null\n" +
" │ └─ Eq\n" +
" │ ├─ e52ap.BDNYB:10!null\n" +
" │ └─ ckele.LWQ6O:0!null\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ckele.LWQ6O:0!null\n" +
" │ │ └─ oxxei.BDNYB:3!null\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: ckele\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [noxn3.id:1!null as LWQ6O, row_number() over ( order by noxn3.id asc):0!null as M6T2N]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:0!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ckele.LWQ6O:0!null)\n" +
" │ ├─ right-key: TUPLE(oxxei.BDNYB:1!null)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: oxxei\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:13!null as T4IBQ, sn.id:0!null as BDNYB, aac.BTXC5:11 as BTXC5, mf.id:2!null as Z7CP5, CASE WHEN NOT\n" +
" │ │ └─ mf.LT7K6:7 IS NULL\n" +
" │ │ THEN mf.LT7K6:7 ELSE mf.SPPYD:8 END as vaf, CASE WHEN NOT\n" +
" │ │ └─ mf.QCGTS:9 IS NULL\n" +
" │ │ THEN mf.QCGTS:9 ELSE 0.500000 (double) END as QCGTS, CASE WHEN Eq\n" +
" │ │ ├─ vc.ZNP4P:17!null\n" +
" │ │ └─ L5Q44 (longtext)\n" +
" │ │ THEN 1 (tinyint) ELSE 0 (tinyint) END as SNY4H]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ mf.FSDY2:6!null\n" +
" │ │ └─ TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ w2mao.Z7CP5:18!null\n" +
" │ │ └─ mf.id:2!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ mf.GXLUB:3!null\n" +
" │ │ │ └─ bs.id:14!null\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ aac.id:10!null\n" +
" │ │ │ │ └─ mf.M22QN:5!null\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ │ │ │ └─ mf.LUEVY:4!null\n" +
" │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ mf.FSDY2:4!null\n" +
" │ │ │ │ │ └─ TUPLE(SRARY (longtext), UBQWG (longtext))\n" +
" │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id gxlub luevy m22qn fsdy2 lt7k6 sppyd qcgts]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(mf.M22QN:5!null)\n" +
" │ │ │ ├─ right-key: TUPLE(aac.id:0!null)\n" +
" │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: TPXBU\n" +
" │ │ │ └─ columns: [id btxc5]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(mf.GXLUB:3!null)\n" +
" │ │ ├─ right-key: TUPLE(bs.id:2!null)\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:12!null\n" +
" │ │ │ └─ bs.IXUXU:15\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ HashIn\n" +
" │ │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.id:2!null)\n" +
" │ ├─ right-key: TUPLE(w2mao.Z7CP5:2!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ vc.id:16!null\n" +
" │ │ └─ w2mao.YH4XB:19!null\n" +
" │ ├─ TableAlias(vc)\n" +
" │ │ └─ IndexedTableAccess(D34QP)\n" +
" │ │ ├─ index: [D34QP.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id znp4p]\n" +
" │ └─ TableAlias(w2mao)\n" +
" │ └─ IndexedTableAccess(SEQS3)\n" +
" │ ├─ index: [SEQS3.YH4XB]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [z7cp5 yh4xb]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(oxxei.BDNYB:3!null, ckele.LWQ6O:0!null)\n" +
" ├─ right-key: TUPLE(e52ap.BDNYB:1!null, e52ap.BDNYB:1!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: e52ap\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.TW55N:13!null as KUXQY, sn.id:0!null as BDNYB, nma.DZLIM:28!null as YHVEZ, CASE WHEN LessThan\n" +
" │ ├─ nd.TCE7A:20\n" +
" │ └─ 0.900000 (double)\n" +
" │ THEN 1 (tinyint) ELSE 0 (tinyint) END as YAZ4X]\n" +
" └─ Sort(sn.id:0!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sn.id:0!null, sn.BRQP2:1!null, sn.FFTBJ:2!null, sn.A7XO2:3, sn.KBO7R:4!null, sn.ECDKM:5, sn.NUMK2:6!null, sn.LETOE:7!null, sn.YKSSU:8, sn.FHCYT:9, nd.id:10!null, nd.DKCAJ:11!null, nd.KNG7T:12, nd.TW55N:13!null, nd.QRQXW:14!null, nd.ECXAJ:15!null, nd.FGG57:16, nd.ZH72S:17, nd.FSK67:18!null, nd.XQDYT:19!null, nd.TCE7A:20, nd.IWV2H:21, nd.HPCMS:22!null, nd.N5CC2:23, nd.FHCYT:24, nd.ETAQ7:25, nd.A75X7:26, nma.id:27!null, nma.DZLIM:28!null, nma.F3YUE:29, nd.TW55N:13!null as KUXQY, sn.id:0!null as BDNYB, nma.DZLIM:28!null as YHVEZ, CASE WHEN LessThan\n" +
" │ ├─ nd.TCE7A:20\n" +
" │ └─ 0.900000 (double)\n" +
" │ THEN 1 (tinyint) ELSE 0 (tinyint) END as YAZ4X]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ Eq\n" +
" │ ├─ nma.DZLIM:28!null\n" +
" │ └─ Q5I4E (longtext)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.HPCMS:22!null\n" +
" │ └─ nma.id:27!null\n" +
" ├─ LeftOuterMergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ └─ nd.id:10!null\n" +
" │ ├─ TableAlias(sn)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(nd.HPCMS:22!null)\n" +
" ├─ right-key: TUPLE(nma.id:0!null)\n" +
" └─ TableAlias(nma)\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" └─ columns: [id dzlim f3yue]\n" +
"",
},
{
Query: `
WITH
FZFVD AS (
SELECT id, ROW_NUMBER() OVER (ORDER BY id ASC) - 1 AS M6T2N FROM NOXN3),
JCHIR AS (
SELECT
ism.FV24E AS FJDP5,
CPMFE.id AS BJUF2,
CPMFE.TW55N AS PSMU6,
ism.M22QN AS M22QN,
G3YXS.GE5EL,
G3YXS.F7A4Q,
G3YXS.ESFVY,
CASE
WHEN G3YXS.SL76B IN ('FO422', 'SJ53H') THEN 0
WHEN G3YXS.SL76B IN ('DCV4Z', 'UOSM4', 'FUGIP', 'H5MCC', 'YKEQE', 'D3AKL') THEN 1
WHEN G3YXS.SL76B IN ('QJEXM', 'J6S7P', 'VT7FI') THEN 2
WHEN G3YXS.SL76B IN ('Y62X7') THEN 3
END AS CC4AX,
G3YXS.SL76B AS SL76B,
YQIF4.id AS QNI57,
YVHJZ.id AS TDEIU
FROM
HDDVB ism
INNER JOIN YYBCX G3YXS ON G3YXS.id = ism.NZ4MQ
LEFT JOIN
WGSDC NHMXW
ON
NHMXW.id = ism.PRUV2
LEFT JOIN
E2I7U CPMFE
ON
CPMFE.ZH72S = NHMXW.NOHHR AND CPMFE.id <> ism.FV24E
LEFT JOIN
NOXN3 YQIF4
ON
YQIF4.BRQP2 = ism.FV24E
AND
YQIF4.FFTBJ = ism.UJ6XY
LEFT JOIN
NOXN3 YVHJZ
ON
YVHJZ.BRQP2 = ism.UJ6XY
AND
YVHJZ.FFTBJ = ism.FV24E
WHERE
YQIF4.id IS NOT NULL
OR
YVHJZ.id IS NOT NULL
),
OXDGK AS (
SELECT
FJDP5,
BJUF2,
PSMU6,
M22QN,
GE5EL,
F7A4Q,
ESFVY,
CC4AX,
SL76B,
QNI57,
TDEIU
FROM
JCHIR
WHERE
(QNI57 IS NOT NULL AND TDEIU IS NULL)
OR
(QNI57 IS NULL AND TDEIU IS NOT NULL)
UNION
SELECT
FJDP5,
BJUF2,
PSMU6,
M22QN,
GE5EL,
F7A4Q,
ESFVY,
CC4AX,
SL76B,
QNI57,
NULL AS TDEIU
FROM
JCHIR
WHERE
(QNI57 IS NOT NULL AND TDEIU IS NOT NULL)
UNION
SELECT
FJDP5,
BJUF2,
PSMU6,
M22QN,
GE5EL,
F7A4Q,
ESFVY,
CC4AX,
SL76B,
NULL AS QNI57,
TDEIU
FROM
JCHIR
WHERE
(QNI57 IS NOT NULL AND TDEIU IS NOT NULL)
)
SELECT
mf.FTQLQ AS T4IBQ,
CASE
WHEN MJR3D.QNI57 IS NOT NULL
THEN (SELECT ei.M6T2N FROM FZFVD ei WHERE ei.id = MJR3D.QNI57)
WHEN MJR3D.TDEIU IS NOT NULL
THEN (SELECT ei.M6T2N FROM FZFVD ei WHERE ei.id = MJR3D.TDEIU)
END AS M6T2N,
GE5EL AS GE5EL,
F7A4Q AS F7A4Q,
CC4AX AS CC4AX,
SL76B AS SL76B,
aac.BTXC5 AS YEBDJ,
PSMU6
FROM
OXDGK MJR3D
LEFT JOIN
NOXN3 sn
ON
(
QNI57 IS NOT NULL
AND
sn.id = MJR3D.QNI57
AND
MJR3D.BJUF2 IS NULL
)
OR
(
QNI57 IS NOT NULL
AND
MJR3D.BJUF2 IS NOT NULL
AND
sn.id IN (SELECT JTEHG.id FROM NOXN3 JTEHG WHERE BRQP2 = MJR3D.BJUF2)
)
OR
(
TDEIU IS NOT NULL
AND
MJR3D.BJUF2 IS NULL
AND
sn.id IN (SELECT XMAFZ.id FROM NOXN3 XMAFZ WHERE BRQP2 = MJR3D.FJDP5)
)
OR
(
TDEIU IS NOT NULL
AND
MJR3D.BJUF2 IS NOT NULL
AND
sn.id IN (SELECT XMAFZ.id FROM NOXN3 XMAFZ WHERE BRQP2 = MJR3D.BJUF2)
)
INNER JOIN
(
SELECT FTQLQ, mf.LUEVY, mf.M22QN
FROM YK2GW cla
INNER JOIN THNTS bs ON cla.id = bs.IXUXU
INNER JOIN HGMQ6 mf ON bs.id = mf.GXLUB
WHERE cla.FTQLQ IN ('SQ1')
) mf
ON mf.LUEVY = sn.BRQP2 AND mf.M22QN = MJR3D.M22QN
INNER JOIN
(SELECT * FROM TPXBU) aac
ON aac.id = MJR3D.M22QN`,
ExpectedPlan: "Project\n" +
" ├─ columns: [mf.FTQLQ:21!null as T4IBQ, CASE WHEN NOT\n" +
" │ └─ mjr3d.QNI57:9!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:35!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:34!null\n" +
" │ │ └─ mjr3d.QNI57:9!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:35!null, (row_number() over ( order by noxn3.id asc):34!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:34!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:10!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:35!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:34!null\n" +
" │ │ └─ mjr3d.TDEIU:10!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:35!null, (row_number() over ( order by noxn3.id asc):34!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:34!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, mjr3d.GE5EL:4 as GE5EL, mjr3d.F7A4Q:5 as F7A4Q, mjr3d.CC4AX:7 as CC4AX, mjr3d.SL76B:8!null as SL76B, aac.BTXC5:25 as YEBDJ, mjr3d.PSMU6:2!null]\n" +
" └─ Project\n" +
" ├─ columns: [mjr3d.FJDP5:0!null, mjr3d.BJUF2:1!null, mjr3d.PSMU6:2!null, mjr3d.M22QN:3!null, mjr3d.GE5EL:4, mjr3d.F7A4Q:5, mjr3d.ESFVY:6!null, mjr3d.CC4AX:7, mjr3d.SL76B:8!null, mjr3d.QNI57:9!null, mjr3d.TDEIU:10!null, sn.id:11!null, sn.BRQP2:12!null, sn.FFTBJ:13!null, sn.A7XO2:14, sn.KBO7R:15!null, sn.ECDKM:16, sn.NUMK2:17!null, sn.LETOE:18!null, sn.YKSSU:19, sn.FHCYT:20, mf.FTQLQ:24!null, mf.LUEVY:25!null, mf.M22QN:26!null, aac.id:21!null, aac.btxc5:22, aac.fhcyt:23, mf.FTQLQ:24!null as T4IBQ, CASE WHEN NOT\n" +
" │ └─ mjr3d.QNI57:9!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:28!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:27!null\n" +
" │ │ └─ mjr3d.QNI57:9!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:28!null, (row_number() over ( order by noxn3.id asc):27!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:27!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:10!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:28!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:27!null\n" +
" │ │ └─ mjr3d.TDEIU:10!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:28!null, (row_number() over ( order by noxn3.id asc):27!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:27!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, mjr3d.GE5EL:4 as GE5EL, mjr3d.F7A4Q:5 as F7A4Q, mjr3d.CC4AX:7 as CC4AX, mjr3d.SL76B:8!null as SL76B, aac.BTXC5:22 as YEBDJ]\n" +
" └─ HashJoin\n" +
" ├─ AND\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ mf.LUEVY:25!null\n" +
" │ │ │ └─ sn.BRQP2:12!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ mf.M22QN:26!null\n" +
" │ │ └─ mjr3d.M22QN:3!null\n" +
" │ └─ Eq\n" +
" │ ├─ aac.id:21!null\n" +
" │ └─ mjr3d.M22QN:3!null\n" +
" ├─ LeftOuterJoin\n" +
" │ ├─ Or\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ Or\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ └─ mjr3d.QNI57:9!null IS NULL\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ sn.id:11!null\n" +
" │ │ │ │ │ │ └─ mjr3d.QNI57:9!null\n" +
" │ │ │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ │ │ └─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ mjr3d.QNI57:9!null IS NULL\n" +
" │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ ├─ left: sn.id:11!null\n" +
" │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [jtehg.id:21!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ jtehg.BRQP2:22!null\n" +
" │ │ │ │ │ └─ mjr3d.BJUF2:1!null\n" +
" │ │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ └─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ mjr3d.TDEIU:10!null IS NULL\n" +
" │ │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ │ └─ InSubquery\n" +
" │ │ │ ├─ left: sn.id:11!null\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id:21!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ xmafz.BRQP2:22!null\n" +
" │ │ │ │ └─ mjr3d.FJDP5:0!null\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ mjr3d.TDEIU:10!null IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ └─ InSubquery\n" +
" │ │ ├─ left: sn.id:11!null\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xmafz.id:21!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xmafz.BRQP2:22!null\n" +
" │ │ │ └─ mjr3d.BJUF2:1!null\n" +
" │ │ └─ TableAlias(xmafz)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ └─ columns: [id brqp2]\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: mjr3d\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Union distinct\n" +
" │ │ ├─ Project\n" +
" │ │ │ ├─ columns: [jchir.FJDP5:0!null, jchir.BJUF2:1!null, jchir.PSMU6:2!null, jchir.M22QN:3!null, jchir.GE5EL:4, jchir.F7A4Q:5, jchir.ESFVY:6!null, jchir.CC4AX:7, jchir.SL76B:8!null, convert\n" +
" │ │ │ │ ├─ type: char\n" +
" │ │ │ │ └─ jchir.QNI57:9!null\n" +
" │ │ │ │ as QNI57, jchir.TDEIU:10]\n" +
" │ │ │ └─ Union distinct\n" +
" │ │ │ ├─ Project\n" +
" │ │ │ │ ├─ columns: [jchir.FJDP5:0!null, jchir.BJUF2:1!null, jchir.PSMU6:2!null, jchir.M22QN:3!null, jchir.GE5EL:4, jchir.F7A4Q:5, jchir.ESFVY:6!null, jchir.CC4AX:7, jchir.SL76B:8!null, jchir.QNI57:9!null, convert\n" +
" │ │ │ │ │ ├─ type: char\n" +
" │ │ │ │ │ └─ jchir.TDEIU:10!null\n" +
" │ │ │ │ │ as TDEIU]\n" +
" │ │ │ │ └─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: jchir\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Or\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ └─ QNI57:9!null IS NULL\n" +
" │ │ │ │ │ │ └─ TDEIU:10!null IS NULL\n" +
" │ │ │ │ │ └─ AND\n" +
" │ │ │ │ │ ├─ QNI57:9!null IS NULL\n" +
" │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ └─ TDEIU:10!null IS NULL\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [ism.FV24E:5!null as FJDP5, cpmfe.id:12!null as BJUF2, cpmfe.TW55N:13!null as PSMU6, ism.M22QN:7!null as M22QN, g3yxs.GE5EL:3, g3yxs.F7A4Q:4, g3yxs.ESFVY:1!null, CASE WHEN IN\n" +
" │ │ │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ │ │ └─ right: TUPLE(FO422 (longtext), SJ53H (longtext))\n" +
" │ │ │ │ │ THEN 0 (tinyint) WHEN IN\n" +
" │ │ │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ │ │ └─ right: TUPLE(DCV4Z (longtext), UOSM4 (longtext), FUGIP (longtext), H5MCC (longtext), YKEQE (longtext), D3AKL (longtext))\n" +
" │ │ │ │ │ THEN 1 (tinyint) WHEN IN\n" +
" │ │ │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ │ │ └─ right: TUPLE(QJEXM (longtext), J6S7P (longtext), VT7FI (longtext))\n" +
" │ │ │ │ │ THEN 2 (tinyint) WHEN IN\n" +
" │ │ │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ │ │ └─ right: TUPLE(Y62X7 (longtext))\n" +
" │ │ │ │ │ THEN 3 (tinyint) END as CC4AX, g3yxs.SL76B:2!null as SL76B, yqif4.id:15!null as QNI57, yvhjz.id:18!null as TDEIU]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Or\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ yqif4.id:15!null IS NULL\n" +
" │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ └─ yvhjz.id:18!null IS NULL\n" +
" │ │ │ │ └─ LeftOuterHashJoin\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ yvhjz.BRQP2:19!null\n" +
" │ │ │ │ │ │ └─ ism.UJ6XY:6!null\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ yvhjz.FFTBJ:20!null\n" +
" │ │ │ │ │ └─ ism.FV24E:5!null\n" +
" │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ yqif4.BRQP2:16!null\n" +
" │ │ │ │ │ │ │ └─ ism.FV24E:5!null\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ yqif4.FFTBJ:17!null\n" +
" │ │ │ │ │ │ └─ ism.UJ6XY:6!null\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ cpmfe.ZH72S:14\n" +
" │ │ │ │ │ │ │ │ └─ nhmxw.NOHHR:11!null\n" +
" │ │ │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ │ ├─ cpmfe.id:12!null\n" +
" │ │ │ │ │ │ │ └─ ism.FV24E:5!null\n" +
" │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ nhmxw.id:10!null\n" +
" │ │ │ │ │ │ │ │ └─ ism.PRUV2:9\n" +
" │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ │ ├─ g3yxs.id:0!null\n" +
" │ │ │ │ │ │ │ │ │ └─ ism.NZ4MQ:8!null\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:9)\n" +
" │ │ │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ │ │ └─ columns: [id nohhr]\n" +
" │ │ │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ │ └─ columns: [id tw55n zh72s]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: TUPLE(ism.FV24E:5!null, ism.UJ6XY:6!null)\n" +
" │ │ │ │ │ ├─ right-key: TUPLE(yqif4.BRQP2:1!null, yqif4.FFTBJ:2!null)\n" +
" │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(ism.UJ6XY:6!null, ism.FV24E:5!null)\n" +
" │ │ │ │ ├─ right-key: TUPLE(yvhjz.BRQP2:1!null, yvhjz.FFTBJ:2!null)\n" +
" │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jchir.FJDP5:0!null, jchir.BJUF2:1!null, jchir.PSMU6:2!null, jchir.M22QN:3!null, jchir.GE5EL:4, jchir.F7A4Q:5, jchir.ESFVY:6!null, jchir.CC4AX:7, jchir.SL76B:8!null, jchir.QNI57:9!null, convert\n" +
" │ │ │ │ ├─ type: char\n" +
" │ │ │ │ └─ TDEIU:10\n" +
" │ │ │ │ as TDEIU]\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jchir.FJDP5:0!null, jchir.BJUF2:1!null, jchir.PSMU6:2!null, jchir.M22QN:3!null, jchir.GE5EL:4, jchir.F7A4Q:5, jchir.ESFVY:6!null, jchir.CC4AX:7, jchir.SL76B:8!null, jchir.QNI57:9!null, NULL (null) as TDEIU]\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: jchir\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ QNI57:9!null IS NULL\n" +
" │ │ │ │ └─ NOT\n" +
" │ │ │ │ └─ TDEIU:10!null IS NULL\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ism.FV24E:5!null as FJDP5, cpmfe.id:12!null as BJUF2, cpmfe.TW55N:13!null as PSMU6, ism.M22QN:7!null as M22QN, g3yxs.GE5EL:3, g3yxs.F7A4Q:4, g3yxs.ESFVY:1!null, CASE WHEN IN\n" +
" │ │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ │ └─ right: TUPLE(FO422 (longtext), SJ53H (longtext))\n" +
" │ │ │ │ THEN 0 (tinyint) WHEN IN\n" +
" │ │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ │ └─ right: TUPLE(DCV4Z (longtext), UOSM4 (longtext), FUGIP (longtext), H5MCC (longtext), YKEQE (longtext), D3AKL (longtext))\n" +
" │ │ │ │ THEN 1 (tinyint) WHEN IN\n" +
" │ │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ │ └─ right: TUPLE(QJEXM (longtext), J6S7P (longtext), VT7FI (longtext))\n" +
" │ │ │ │ THEN 2 (tinyint) WHEN IN\n" +
" │ │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ │ └─ right: TUPLE(Y62X7 (longtext))\n" +
" │ │ │ │ THEN 3 (tinyint) END as CC4AX, g3yxs.SL76B:2!null as SL76B, yqif4.id:15!null as QNI57, yvhjz.id:18!null as TDEIU]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Or\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ yqif4.id:15!null IS NULL\n" +
" │ │ │ │ └─ NOT\n" +
" │ │ │ │ └─ yvhjz.id:18!null IS NULL\n" +
" │ │ │ └─ LeftOuterHashJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ yvhjz.BRQP2:19!null\n" +
" │ │ │ │ │ └─ ism.UJ6XY:6!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ yvhjz.FFTBJ:20!null\n" +
" │ │ │ │ └─ ism.FV24E:5!null\n" +
" │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ yqif4.BRQP2:16!null\n" +
" │ │ │ │ │ │ └─ ism.FV24E:5!null\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ yqif4.FFTBJ:17!null\n" +
" │ │ │ │ │ └─ ism.UJ6XY:6!null\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ cpmfe.ZH72S:14\n" +
" │ │ │ │ │ │ │ └─ nhmxw.NOHHR:11!null\n" +
" │ │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ cpmfe.id:12!null\n" +
" │ │ │ │ │ │ └─ ism.FV24E:5!null\n" +
" │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ nhmxw.id:10!null\n" +
" │ │ │ │ │ │ │ └─ ism.PRUV2:9\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ ├─ g3yxs.id:0!null\n" +
" │ │ │ │ │ │ │ │ └─ ism.NZ4MQ:8!null\n" +
" │ │ │ │ │ │ │ ├─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:9)\n" +
" │ │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ │ └─ columns: [id nohhr]\n" +
" │ │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ └─ columns: [id tw55n zh72s]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(ism.FV24E:5!null, ism.UJ6XY:6!null)\n" +
" │ │ │ │ ├─ right-key: TUPLE(yqif4.BRQP2:1!null, yqif4.FFTBJ:2!null)\n" +
" │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(ism.UJ6XY:6!null, ism.FV24E:5!null)\n" +
" │ │ │ ├─ right-key: TUPLE(yvhjz.BRQP2:1!null, yvhjz.FFTBJ:2!null)\n" +
" │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jchir.FJDP5:0!null, jchir.BJUF2:1!null, jchir.PSMU6:2!null, jchir.M22QN:3!null, jchir.GE5EL:4, jchir.F7A4Q:5, jchir.ESFVY:6!null, jchir.CC4AX:7, jchir.SL76B:8!null, convert\n" +
" │ │ │ ├─ type: char\n" +
" │ │ │ └─ QNI57:9\n" +
" │ │ │ as QNI57, jchir.TDEIU:10!null]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jchir.FJDP5:0!null, jchir.BJUF2:1!null, jchir.PSMU6:2!null, jchir.M22QN:3!null, jchir.GE5EL:4, jchir.F7A4Q:5, jchir.ESFVY:6!null, jchir.CC4AX:7, jchir.SL76B:8!null, NULL (null) as QNI57, jchir.TDEIU:10!null]\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: jchir\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ QNI57:9!null IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ TDEIU:10!null IS NULL\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ism.FV24E:5!null as FJDP5, cpmfe.id:12!null as BJUF2, cpmfe.TW55N:13!null as PSMU6, ism.M22QN:7!null as M22QN, g3yxs.GE5EL:3, g3yxs.F7A4Q:4, g3yxs.ESFVY:1!null, CASE WHEN IN\n" +
" │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ └─ right: TUPLE(FO422 (longtext), SJ53H (longtext))\n" +
" │ │ │ THEN 0 (tinyint) WHEN IN\n" +
" │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ └─ right: TUPLE(DCV4Z (longtext), UOSM4 (longtext), FUGIP (longtext), H5MCC (longtext), YKEQE (longtext), D3AKL (longtext))\n" +
" │ │ │ THEN 1 (tinyint) WHEN IN\n" +
" │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ └─ right: TUPLE(QJEXM (longtext), J6S7P (longtext), VT7FI (longtext))\n" +
" │ │ │ THEN 2 (tinyint) WHEN IN\n" +
" │ │ │ ├─ left: g3yxs.SL76B:2!null\n" +
" │ │ │ └─ right: TUPLE(Y62X7 (longtext))\n" +
" │ │ │ THEN 3 (tinyint) END as CC4AX, g3yxs.SL76B:2!null as SL76B, yqif4.id:15!null as QNI57, yvhjz.id:18!null as TDEIU]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ yqif4.id:15!null IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ yvhjz.id:18!null IS NULL\n" +
" │ │ └─ LeftOuterHashJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ yvhjz.BRQP2:19!null\n" +
" │ │ │ │ └─ ism.UJ6XY:6!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ yvhjz.FFTBJ:20!null\n" +
" │ │ │ └─ ism.FV24E:5!null\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ yqif4.BRQP2:16!null\n" +
" │ │ │ │ │ └─ ism.FV24E:5!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ yqif4.FFTBJ:17!null\n" +
" │ │ │ │ └─ ism.UJ6XY:6!null\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ cpmfe.ZH72S:14\n" +
" │ │ │ │ │ │ └─ nhmxw.NOHHR:11!null\n" +
" │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ cpmfe.id:12!null\n" +
" │ │ │ │ │ └─ ism.FV24E:5!null\n" +
" │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nhmxw.id:10!null\n" +
" │ │ │ │ │ │ └─ ism.PRUV2:9\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ ├─ g3yxs.id:0!null\n" +
" │ │ │ │ │ │ │ └─ ism.NZ4MQ:8!null\n" +
" │ │ │ │ │ │ ├─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ └─ TableAlias(ism)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:9)\n" +
" │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ └─ columns: [id nohhr]\n" +
" │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ └─ columns: [id tw55n zh72s]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(ism.FV24E:5!null, ism.UJ6XY:6!null)\n" +
" │ │ │ ├─ right-key: TUPLE(yqif4.BRQP2:1!null, yqif4.FFTBJ:2!null)\n" +
" │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(ism.UJ6XY:6!null, ism.FV24E:5!null)\n" +
" │ │ ├─ right-key: TUPLE(yvhjz.BRQP2:1!null, yvhjz.FFTBJ:2!null)\n" +
" │ │ └─ TableAlias(yvhjz)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(sn.BRQP2:12!null, mjr3d.M22QN:3!null, mjr3d.M22QN:3!null)\n" +
" ├─ right-key: TUPLE(mf.LUEVY:4!null, mf.M22QN:5!null, aac.id:0!null)\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ mf.M22QN:26!null\n" +
" │ └─ aac.id:21!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: aac\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXBU\n" +
" │ └─ columns: [id btxc5 fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(aac.id:21!null)\n" +
" ├─ right-key: TUPLE(mf.M22QN:2!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: mf\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ:6!null, mf.LUEVY:3!null, mf.M22QN:4!null]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ cla.id:5!null\n" +
" │ └─ bs.IXUXU:1\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ bs.id:0!null\n" +
" │ │ └─ mf.GXLUB:2!null\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ TableAlias(mf)\n" +
" │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ ├─ index: [HGMQ6.GXLUB]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [gxlub luevy m22qn]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(bs.IXUXU:1)\n" +
" ├─ right-key: TUPLE(cla.id:0!null)\n" +
" └─ Filter\n" +
" ├─ HashIn\n" +
" │ ├─ cla.FTQLQ:1!null\n" +
" │ └─ TUPLE(SQ1 (longtext))\n" +
" └─ TableAlias(cla)\n" +
" └─ IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.FTQLQ]\n" +
" ├─ static: [{[SQ1, SQ1]}]\n" +
" └─ columns: [id ftqlq]\n" +
"",
},
{
Query: `
WITH
FZFVD AS (
SELECT id, ROW_NUMBER() OVER (ORDER BY id ASC) - 1 AS M6T2N FROM NOXN3
),
OXDGK AS (
SELECT DISTINCT
ism.FV24E AS FJDP5,
CPMFE.id AS BJUF2,
ism.M22QN AS M22QN,
G3YXS.TUV25 AS TUV25,
G3YXS.ESFVY AS ESFVY,
YQIF4.id AS QNI57,
YVHJZ.id AS TDEIU
FROM
HDDVB ism
INNER JOIN YYBCX G3YXS ON G3YXS.id = ism.NZ4MQ
LEFT JOIN
WGSDC NHMXW
ON
NHMXW.id = ism.PRUV2
LEFT JOIN
E2I7U CPMFE
ON
CPMFE.ZH72S = NHMXW.NOHHR AND CPMFE.id <> ism.FV24E
LEFT JOIN
NOXN3 YQIF4
ON
YQIF4.BRQP2 = ism.FV24E
AND
YQIF4.FFTBJ = ism.UJ6XY
LEFT JOIN
NOXN3 YVHJZ
ON
YVHJZ.BRQP2 = ism.UJ6XY
AND
YVHJZ.FFTBJ = ism.FV24E
WHERE
G3YXS.TUV25 IS NOT NULL
AND
(YQIF4.id IS NOT NULL
OR
YVHJZ.id IS NOT NULL)
),
HTKBS AS (
SELECT /*+ JOIN_ORDER(cla, bs, mf, sn) */
cla.FTQLQ AS T4IBQ,
sn.id AS BDNYB,
mf.M22QN AS M22QN
FROM HGMQ6 mf
INNER JOIN THNTS bs ON bs.id = mf.GXLUB
INNER JOIN YK2GW cla ON cla.id = bs.IXUXU
INNER JOIN NOXN3 sn ON sn.BRQP2 = mf.LUEVY
WHERE cla.FTQLQ IN ('SQ1')
),
JQHRG AS (
SELECT
CASE
WHEN MJR3D.QNI57 IS NOT NULL
THEN (SELECT ei.M6T2N FROM FZFVD ei WHERE ei.id = MJR3D.QNI57)
WHEN MJR3D.TDEIU IS NOT NULL
THEN (SELECT ei.M6T2N FROM FZFVD ei WHERE ei.id = MJR3D.TDEIU)
END AS M6T2N,
aac.BTXC5 AS BTXC5,
aac.id AS NTOFG,
sn.id AS LWQ6O,
MJR3D.TUV25 AS TUV25
FROM
OXDGK MJR3D
INNER JOIN TPXBU aac ON aac.id = MJR3D.M22QN
LEFT JOIN
NOXN3 sn
ON
(
QNI57 IS NOT NULL
AND
sn.id = MJR3D.QNI57
AND
MJR3D.BJUF2 IS NULL
)
OR
(
QNI57 IS NOT NULL
AND
sn.id IN (SELECT JTEHG.id FROM NOXN3 JTEHG WHERE BRQP2 = MJR3D.BJUF2)
AND
MJR3D.BJUF2 IS NOT NULL
)
OR
(
TDEIU IS NOT NULL
AND
sn.id IN (SELECT XMAFZ.id FROM NOXN3 XMAFZ WHERE BRQP2 = MJR3D.FJDP5)
AND
MJR3D.BJUF2 IS NULL
)
OR
(
TDEIU IS NOT NULL
AND
sn.id IN (SELECT XMAFZ.id FROM NOXN3 XMAFZ WHERE BRQP2 = MJR3D.BJUF2)
AND
MJR3D.BJUF2 IS NOT NULL
)
),
F6BRC AS (
SELECT
RSA3Y.T4IBQ AS T4IBQ,
JMHIE.M6T2N AS M6T2N,
JMHIE.BTXC5 AS BTXC5,
JMHIE.TUV25 AS TUV25
FROM
(SELECT DISTINCT M6T2N, BTXC5, TUV25 FROM JQHRG) JMHIE
CROSS JOIN
(SELECT DISTINCT T4IBQ FROM HTKBS) RSA3Y
),
ZMSPR AS (
SELECT DISTINCT
cld.T4IBQ AS T4IBQ,
P4PJZ.M6T2N AS M6T2N,
P4PJZ.BTXC5 AS BTXC5,
P4PJZ.TUV25 AS TUV25
FROM
HTKBS cld
LEFT JOIN
JQHRG P4PJZ
ON P4PJZ.LWQ6O = cld.BDNYB AND P4PJZ.NTOFG = cld.M22QN
WHERE
P4PJZ.M6T2N IS NOT NULL
)
SELECT
fs.T4IBQ AS T4IBQ,
fs.M6T2N AS M6T2N,
fs.TUV25 AS TUV25,
fs.BTXC5 AS YEBDJ
FROM
F6BRC fs
WHERE
(fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25)
NOT IN (
SELECT
ZMSPR.T4IBQ,
ZMSPR.M6T2N,
ZMSPR.BTXC5,
ZMSPR.TUV25
FROM
ZMSPR
)`,
ExpectedPlan: "Project\n" +
" ├─ columns: [fs.T4IBQ:0!null as T4IBQ, fs.M6T2N:1 as M6T2N, fs.TUV25:3 as TUV25, fs.BTXC5:2 as YEBDJ]\n" +
" └─ AntiJoin\n" +
" ├─ Eq\n" +
" │ ├─ TUPLE(fs.T4IBQ:0!null, fs.M6T2N:1, fs.BTXC5:2, fs.TUV25:3)\n" +
" │ └─ TUPLE(scalarSubq0.T4IBQ:4!null, scalarSubq0.M6T2N:5, scalarSubq0.BTXC5:6, scalarSubq0.TUV25:7)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [rsa3y.T4IBQ:0!null as T4IBQ, jmhie.M6T2N:1 as M6T2N, jmhie.BTXC5:2 as BTXC5, jmhie.TUV25:3 as TUV25]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: rsa3y\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [htkbs.T4IBQ:0!null]\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: htkbs\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [cla.FTQLQ:1!null as T4IBQ, sn.id:7!null as BDNYB, mf.M22QN:6!null as M22QN]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ HashIn\n" +
" │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ sn.BRQP2:8!null\n" +
" │ │ │ └─ mf.LUEVY:5!null\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ bs.id:2!null\n" +
" │ │ │ │ └─ mf.GXLUB:4!null\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ cla.id:0!null\n" +
" │ │ │ │ │ └─ bs.IXUXU:3\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(bs.id:2!null)\n" +
" │ │ │ ├─ right-key: TUPLE(mf.GXLUB:0!null)\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(mf.LUEVY:5!null)\n" +
" │ │ ├─ right-key: TUPLE(sn.BRQP2:1!null)\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE()\n" +
" │ ├─ right-key: TUPLE()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: jmhie\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [jqhrg.M6T2N:0, jqhrg.BTXC5:1, jqhrg.TUV25:4]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: jqhrg\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [CASE WHEN NOT\n" +
" │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ei.M6T2N:26!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ ei.id:25!null\n" +
" │ │ │ └─ mjr3d.QNI57:5!null\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: ei\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [noxn3.id:26!null, (row_number() over ( order by noxn3.id asc):25!null - 1 (tinyint)) as M6T2N]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:25!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id]\n" +
" │ │ WHEN NOT\n" +
" │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ei.M6T2N:26!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ ei.id:25!null\n" +
" │ │ │ └─ mjr3d.TDEIU:6!null\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: ei\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [noxn3.id:26!null, (row_number() over ( order by noxn3.id asc):25!null - 1 (tinyint)) as M6T2N]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:25!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id]\n" +
" │ │ END as M6T2N, aac.BTXC5:8 as BTXC5, aac.id:7!null as NTOFG, sn.id:10!null as LWQ6O, mjr3d.TUV25:3 as TUV25]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [mjr3d.FJDP5:0!null, mjr3d.BJUF2:1!null, mjr3d.M22QN:2!null, mjr3d.TUV25:3, mjr3d.ESFVY:4!null, mjr3d.QNI57:5!null, mjr3d.TDEIU:6!null, aac.id:7!null, aac.BTXC5:8, aac.FHCYT:9, sn.id:10!null, sn.BRQP2:11!null, sn.FFTBJ:12!null, sn.A7XO2:13, sn.KBO7R:14!null, sn.ECDKM:15, sn.NUMK2:16!null, sn.LETOE:17!null, sn.YKSSU:18, sn.FHCYT:19, CASE WHEN NOT\n" +
" │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ei.M6T2N:21!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ ei.id:20!null\n" +
" │ │ │ └─ mjr3d.QNI57:5!null\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: ei\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [noxn3.id:21!null, (row_number() over ( order by noxn3.id asc):20!null - 1 (tinyint)) as M6T2N]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:20!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id]\n" +
" │ │ WHEN NOT\n" +
" │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ei.M6T2N:21!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ ei.id:20!null\n" +
" │ │ │ └─ mjr3d.TDEIU:6!null\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: ei\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [noxn3.id:21!null, (row_number() over ( order by noxn3.id asc):20!null - 1 (tinyint)) as M6T2N]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:20!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id]\n" +
" │ │ END as M6T2N, aac.BTXC5:8 as BTXC5, aac.id:7!null as NTOFG, sn.id:10!null as LWQ6O, mjr3d.TUV25:3 as TUV25]\n" +
" │ └─ LeftOuterJoin\n" +
" │ ├─ Or\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ Or\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ sn.id:10!null\n" +
" │ │ │ │ │ │ └─ mjr3d.QNI57:5!null\n" +
" │ │ │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ │ │ └─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ │ ├─ left: sn.id:10!null\n" +
" │ │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [jtehg.id:20!null]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ jtehg.BRQP2:21!null\n" +
" │ │ │ │ │ │ └─ mjr3d.BJUF2:1!null\n" +
" │ │ │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ └─ NOT\n" +
" │ │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ │ └─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ ├─ left: sn.id:10!null\n" +
" │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [xmafz.id:20!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ xmafz.BRQP2:21!null\n" +
" │ │ │ │ │ └─ mjr3d.FJDP5:0!null\n" +
" │ │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ └─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ │ └─ InSubquery\n" +
" │ │ │ ├─ left: sn.id:10!null\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id:20!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ xmafz.BRQP2:21!null\n" +
" │ │ │ │ └─ mjr3d.BJUF2:1!null\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ NOT\n" +
" │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.id:7!null\n" +
" │ │ │ └─ mjr3d.M22QN:2!null\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: mjr3d\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Distinct\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ism.FV24E:9!null as FJDP5, cpmfe.id:27!null as BJUF2, ism.M22QN:11!null as M22QN, g3yxs.TUV25:5 as TUV25, g3yxs.ESFVY:1!null as ESFVY, yqif4.id:44!null as QNI57, yvhjz.id:54!null as TDEIU]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ g3yxs.TUV25:5 IS NULL\n" +
" │ │ │ │ └─ Or\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ yqif4.id:44!null IS NULL\n" +
" │ │ │ │ └─ NOT\n" +
" │ │ │ │ └─ yvhjz.id:54!null IS NULL\n" +
" │ │ │ └─ LeftOuterHashJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ yvhjz.BRQP2:55!null\n" +
" │ │ │ │ │ └─ ism.UJ6XY:10!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ yvhjz.FFTBJ:56!null\n" +
" │ │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ yqif4.BRQP2:45!null\n" +
" │ │ │ │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ yqif4.FFTBJ:46!null\n" +
" │ │ │ │ │ └─ ism.UJ6XY:10!null\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ cpmfe.ZH72S:34\n" +
" │ │ │ │ │ │ │ └─ nhmxw.NOHHR:18!null\n" +
" │ │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ cpmfe.id:27!null\n" +
" │ │ │ │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ nhmxw.id:17!null\n" +
" │ │ │ │ │ │ │ └─ ism.PRUV2:14\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ ├─ g3yxs.id:0!null\n" +
" │ │ │ │ │ │ │ │ └─ ism.NZ4MQ:12!null\n" +
" │ │ │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ │ │ └─ g3yxs.TUV25:5 IS NULL\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q tuv25 ykssu fhcyt]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
" │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:14)\n" +
" │ │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ │ └─ columns: [id nohhr avpyf sypkf idut2 fzxv5 dqygv swcqv ykssu fhcyt]\n" +
" │ │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(ism.FV24E:9!null, ism.UJ6XY:10!null)\n" +
" │ │ │ │ ├─ right-key: TUPLE(yqif4.BRQP2:1!null, yqif4.FFTBJ:2!null)\n" +
" │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(ism.UJ6XY:10!null, ism.FV24E:9!null)\n" +
" │ │ │ ├─ right-key: TUPLE(yvhjz.BRQP2:1!null, yvhjz.FFTBJ:2!null)\n" +
" │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: scalarSubq0\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ SubqueryAlias\n" +
" ├─ name: zmspr\n" +
" ├─ outerVisibility: true\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cld.T4IBQ:0!null as T4IBQ, p4pjz.M6T2N:3 as M6T2N, p4pjz.BTXC5:4 as BTXC5, p4pjz.TUV25:7 as TUV25]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ p4pjz.M6T2N:3 IS NULL\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ p4pjz.LWQ6O:6!null\n" +
" │ │ └─ cld.BDNYB:1!null\n" +
" │ └─ Eq\n" +
" │ ├─ p4pjz.NTOFG:5!null\n" +
" │ └─ cld.M22QN:2!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cld\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:1!null as T4IBQ, sn.id:7!null as BDNYB, mf.M22QN:6!null as M22QN]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ sn.BRQP2:8!null\n" +
" │ │ └─ mf.LUEVY:5!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ bs.id:2!null\n" +
" │ │ │ └─ mf.GXLUB:4!null\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ cla.id:0!null\n" +
" │ │ │ │ └─ bs.IXUXU:3\n" +
" │ │ │ ├─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(bs.id:2!null)\n" +
" │ │ ├─ right-key: TUPLE(mf.GXLUB:0!null)\n" +
" │ │ └─ TableAlias(mf)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HGMQ6\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.LUEVY:5!null)\n" +
" │ ├─ right-key: TUPLE(sn.BRQP2:1!null)\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(cld.BDNYB:1!null, cld.M22QN:2!null)\n" +
" ├─ right-key: TUPLE(p4pjz.LWQ6O:3!null, p4pjz.NTOFG:2!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: p4pjz\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [CASE WHEN NOT\n" +
" │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:26!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:25!null\n" +
" │ │ └─ mjr3d.QNI57:5!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:26!null, (row_number() over ( order by noxn3.id asc):25!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:25!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:26!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:25!null\n" +
" │ │ └─ mjr3d.TDEIU:6!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:26!null, (row_number() over ( order by noxn3.id asc):25!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:25!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5:8 as BTXC5, aac.id:7!null as NTOFG, sn.id:10!null as LWQ6O, mjr3d.TUV25:3 as TUV25]\n" +
" └─ Project\n" +
" ├─ columns: [mjr3d.FJDP5:0!null, mjr3d.BJUF2:1!null, mjr3d.M22QN:2!null, mjr3d.TUV25:3, mjr3d.ESFVY:4!null, mjr3d.QNI57:5!null, mjr3d.TDEIU:6!null, aac.id:7!null, aac.BTXC5:8, aac.FHCYT:9, sn.id:10!null, sn.BRQP2:11!null, sn.FFTBJ:12!null, sn.A7XO2:13, sn.KBO7R:14!null, sn.ECDKM:15, sn.NUMK2:16!null, sn.LETOE:17!null, sn.YKSSU:18, sn.FHCYT:19, CASE WHEN NOT\n" +
" │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:21!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:20!null\n" +
" │ │ └─ mjr3d.QNI57:5!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:21!null, (row_number() over ( order by noxn3.id asc):20!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:20!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:21!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:20!null\n" +
" │ │ └─ mjr3d.TDEIU:6!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:21!null, (row_number() over ( order by noxn3.id asc):20!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:20!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5:8 as BTXC5, aac.id:7!null as NTOFG, sn.id:10!null as LWQ6O, mjr3d.TUV25:3 as TUV25]\n" +
" └─ LeftOuterJoin\n" +
" ├─ Or\n" +
" │ ├─ Or\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ sn.id:10!null\n" +
" │ │ │ │ │ └─ mjr3d.QNI57:5!null\n" +
" │ │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ │ └─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ ├─ left: sn.id:10!null\n" +
" │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [jtehg.id:20!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ jtehg.BRQP2:21!null\n" +
" │ │ │ │ │ └─ mjr3d.BJUF2:1!null\n" +
" │ │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ └─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ │ └─ InSubquery\n" +
" │ │ │ ├─ left: sn.id:10!null\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id:20!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ xmafz.BRQP2:21!null\n" +
" │ │ │ │ └─ mjr3d.FJDP5:0!null\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ └─ AND\n" +
" │ ├─ AND\n" +
" │ │ ├─ NOT\n" +
" │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ └─ InSubquery\n" +
" │ │ ├─ left: sn.id:10!null\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xmafz.id:20!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xmafz.BRQP2:21!null\n" +
" │ │ │ └─ mjr3d.BJUF2:1!null\n" +
" │ │ └─ TableAlias(xmafz)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ └─ columns: [id brqp2]\n" +
" │ └─ NOT\n" +
" │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" ├─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ aac.id:7!null\n" +
" │ │ └─ mjr3d.M22QN:2!null\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: mjr3d\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ism.FV24E:9!null as FJDP5, cpmfe.id:27!null as BJUF2, ism.M22QN:11!null as M22QN, g3yxs.TUV25:5 as TUV25, g3yxs.ESFVY:1!null as ESFVY, yqif4.id:44!null as QNI57, yvhjz.id:54!null as TDEIU]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ g3yxs.TUV25:5 IS NULL\n" +
" │ │ │ └─ Or\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ yqif4.id:44!null IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ yvhjz.id:54!null IS NULL\n" +
" │ │ └─ LeftOuterHashJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ yvhjz.BRQP2:55!null\n" +
" │ │ │ │ └─ ism.UJ6XY:10!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ yvhjz.FFTBJ:56!null\n" +
" │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ yqif4.BRQP2:45!null\n" +
" │ │ │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ yqif4.FFTBJ:46!null\n" +
" │ │ │ │ └─ ism.UJ6XY:10!null\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ cpmfe.ZH72S:34\n" +
" │ │ │ │ │ │ └─ nhmxw.NOHHR:18!null\n" +
" │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ cpmfe.id:27!null\n" +
" │ │ │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nhmxw.id:17!null\n" +
" │ │ │ │ │ │ └─ ism.PRUV2:14\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ ├─ g3yxs.id:0!null\n" +
" │ │ │ │ │ │ │ └─ ism.NZ4MQ:12!null\n" +
" │ │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ │ └─ g3yxs.TUV25:5 IS NULL\n" +
" │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q tuv25 ykssu fhcyt]\n" +
" │ │ │ │ │ │ └─ TableAlias(ism)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:14)\n" +
" │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ └─ columns: [id nohhr avpyf sypkf idut2 fzxv5 dqygv swcqv ykssu fhcyt]\n" +
" │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(ism.FV24E:9!null, ism.UJ6XY:10!null)\n" +
" │ │ │ ├─ right-key: TUPLE(yqif4.BRQP2:1!null, yqif4.FFTBJ:2!null)\n" +
" │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(ism.UJ6XY:10!null, ism.FV24E:9!null)\n" +
" │ │ ├─ right-key: TUPLE(yvhjz.BRQP2:1!null, yvhjz.FFTBJ:2!null)\n" +
" │ │ └─ TableAlias(yvhjz)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ columns: [id btxc5 fhcyt]\n" +
" └─ TableAlias(sn)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
"",
},
{
Query: `
WITH
FZFVD AS (
SELECT id, ROW_NUMBER() OVER (ORDER BY id ASC) - 1 AS M6T2N FROM NOXN3
),
OXDGK AS (
SELECT DISTINCT
ism.FV24E AS FJDP5,
CPMFE.id AS BJUF2,
ism.M22QN AS M22QN,
G3YXS.TUV25 AS TUV25,
G3YXS.ESFVY AS ESFVY,
YQIF4.id AS QNI57,
YVHJZ.id AS TDEIU
FROM
HDDVB ism
INNER JOIN YYBCX G3YXS ON G3YXS.id = ism.NZ4MQ
LEFT JOIN
WGSDC NHMXW
ON
NHMXW.id = ism.PRUV2
LEFT JOIN
E2I7U CPMFE
ON
CPMFE.ZH72S = NHMXW.NOHHR AND CPMFE.id <> ism.FV24E
LEFT JOIN
NOXN3 YQIF4
ON
YQIF4.BRQP2 = ism.FV24E
AND
YQIF4.FFTBJ = ism.UJ6XY
LEFT JOIN
NOXN3 YVHJZ
ON
YVHJZ.BRQP2 = ism.UJ6XY
AND
YVHJZ.FFTBJ = ism.FV24E
WHERE
G3YXS.TUV25 IS NOT NULL
AND
(YQIF4.id IS NOT NULL
OR
YVHJZ.id IS NOT NULL)
),
HTKBS AS (
SELECT
cla.FTQLQ AS T4IBQ,
sn.id AS BDNYB,
mf.M22QN AS M22QN
FROM HGMQ6 mf
INNER JOIN THNTS bs ON bs.id = mf.GXLUB
INNER JOIN YK2GW cla ON cla.id = bs.IXUXU
INNER JOIN NOXN3 sn ON sn.BRQP2 = mf.LUEVY
WHERE cla.FTQLQ IN ('SQ1')
),
JQHRG AS (
SELECT
CASE
WHEN MJR3D.QNI57 IS NOT NULL
THEN (SELECT ei.M6T2N FROM FZFVD ei WHERE ei.id = MJR3D.QNI57)
WHEN MJR3D.TDEIU IS NOT NULL
THEN (SELECT ei.M6T2N FROM FZFVD ei WHERE ei.id = MJR3D.TDEIU)
END AS M6T2N,
aac.BTXC5 AS BTXC5,
aac.id AS NTOFG,
sn.id AS LWQ6O,
MJR3D.TUV25 AS TUV25
FROM
OXDGK MJR3D
INNER JOIN TPXBU aac ON aac.id = MJR3D.M22QN
LEFT JOIN
NOXN3 sn
ON
(
QNI57 IS NOT NULL
AND
sn.id = MJR3D.QNI57
AND
MJR3D.BJUF2 IS NULL
)
OR
(
QNI57 IS NOT NULL
AND
sn.id IN (SELECT JTEHG.id FROM NOXN3 JTEHG WHERE BRQP2 = MJR3D.BJUF2)
AND
MJR3D.BJUF2 IS NOT NULL
)
OR
(
TDEIU IS NOT NULL
AND
sn.id IN (SELECT XMAFZ.id FROM NOXN3 XMAFZ WHERE BRQP2 = MJR3D.FJDP5)
AND
MJR3D.BJUF2 IS NULL
)
OR
(
TDEIU IS NOT NULL
AND
sn.id IN (SELECT XMAFZ.id FROM NOXN3 XMAFZ WHERE BRQP2 = MJR3D.BJUF2)
AND
MJR3D.BJUF2 IS NOT NULL
)
),
F6BRC AS (
SELECT
RSA3Y.T4IBQ AS T4IBQ,
JMHIE.M6T2N AS M6T2N,
JMHIE.BTXC5 AS BTXC5,
JMHIE.TUV25 AS TUV25
FROM
(SELECT DISTINCT M6T2N, BTXC5, TUV25 FROM JQHRG) JMHIE
CROSS JOIN
(SELECT DISTINCT T4IBQ FROM HTKBS) RSA3Y
),
ZMSPR AS (
SELECT DISTINCT
cld.T4IBQ AS T4IBQ,
P4PJZ.M6T2N AS M6T2N,
P4PJZ.BTXC5 AS BTXC5,
P4PJZ.TUV25 AS TUV25
FROM
HTKBS cld
LEFT JOIN
JQHRG P4PJZ
ON P4PJZ.LWQ6O = cld.BDNYB AND P4PJZ.NTOFG = cld.M22QN
WHERE
P4PJZ.M6T2N IS NOT NULL
)
SELECT
fs.T4IBQ AS T4IBQ,
fs.M6T2N AS M6T2N,
fs.TUV25 AS TUV25,
fs.BTXC5 AS YEBDJ
FROM
F6BRC fs
WHERE
(fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25)
NOT IN (
SELECT
ZMSPR.T4IBQ,
ZMSPR.M6T2N,
ZMSPR.BTXC5,
ZMSPR.TUV25
FROM
ZMSPR
)`,
ExpectedPlan: "Project\n" +
" ├─ columns: [fs.T4IBQ:0!null as T4IBQ, fs.M6T2N:1 as M6T2N, fs.TUV25:3 as TUV25, fs.BTXC5:2 as YEBDJ]\n" +
" └─ AntiJoin\n" +
" ├─ Eq\n" +
" │ ├─ TUPLE(fs.T4IBQ:0!null, fs.M6T2N:1, fs.BTXC5:2, fs.TUV25:3)\n" +
" │ └─ TUPLE(scalarSubq0.T4IBQ:4!null, scalarSubq0.M6T2N:5, scalarSubq0.BTXC5:6, scalarSubq0.TUV25:7)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [rsa3y.T4IBQ:0!null as T4IBQ, jmhie.M6T2N:1 as M6T2N, jmhie.BTXC5:2 as BTXC5, jmhie.TUV25:3 as TUV25]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: rsa3y\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [htkbs.T4IBQ:0!null]\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: htkbs\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [cla.FTQLQ:6!null as T4IBQ, sn.id:0!null as BDNYB, mf.M22QN:4!null as M22QN]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ HashIn\n" +
" │ │ │ ├─ cla.FTQLQ:6!null\n" +
" │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ bs.id:7!null\n" +
" │ │ │ └─ mf.GXLUB:2!null\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ │ │ └─ mf.LUEVY:3!null\n" +
" │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(mf.GXLUB:2!null)\n" +
" │ │ ├─ right-key: TUPLE(bs.id:2!null)\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:5!null\n" +
" │ │ │ └─ bs.IXUXU:8\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ HashIn\n" +
" │ │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE()\n" +
" │ ├─ right-key: TUPLE()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: jmhie\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [jqhrg.M6T2N:0, jqhrg.BTXC5:1, jqhrg.TUV25:4]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: jqhrg\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [CASE WHEN NOT\n" +
" │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ei.M6T2N:26!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ ei.id:25!null\n" +
" │ │ │ └─ mjr3d.QNI57:5!null\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: ei\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [noxn3.id:26!null, (row_number() over ( order by noxn3.id asc):25!null - 1 (tinyint)) as M6T2N]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:25!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id]\n" +
" │ │ WHEN NOT\n" +
" │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ei.M6T2N:26!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ ei.id:25!null\n" +
" │ │ │ └─ mjr3d.TDEIU:6!null\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: ei\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [noxn3.id:26!null, (row_number() over ( order by noxn3.id asc):25!null - 1 (tinyint)) as M6T2N]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:25!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id]\n" +
" │ │ END as M6T2N, aac.BTXC5:8 as BTXC5, aac.id:7!null as NTOFG, sn.id:10!null as LWQ6O, mjr3d.TUV25:3 as TUV25]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [mjr3d.FJDP5:0!null, mjr3d.BJUF2:1!null, mjr3d.M22QN:2!null, mjr3d.TUV25:3, mjr3d.ESFVY:4!null, mjr3d.QNI57:5!null, mjr3d.TDEIU:6!null, aac.id:7!null, aac.BTXC5:8, aac.FHCYT:9, sn.id:10!null, sn.BRQP2:11!null, sn.FFTBJ:12!null, sn.A7XO2:13, sn.KBO7R:14!null, sn.ECDKM:15, sn.NUMK2:16!null, sn.LETOE:17!null, sn.YKSSU:18, sn.FHCYT:19, CASE WHEN NOT\n" +
" │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ei.M6T2N:21!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ ei.id:20!null\n" +
" │ │ │ └─ mjr3d.QNI57:5!null\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: ei\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [noxn3.id:21!null, (row_number() over ( order by noxn3.id asc):20!null - 1 (tinyint)) as M6T2N]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:20!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id]\n" +
" │ │ WHEN NOT\n" +
" │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ei.M6T2N:21!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ ei.id:20!null\n" +
" │ │ │ └─ mjr3d.TDEIU:6!null\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: ei\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [noxn3.id:21!null, (row_number() over ( order by noxn3.id asc):20!null - 1 (tinyint)) as M6T2N]\n" +
" │ │ └─ Window\n" +
" │ │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ │ ├─ noxn3.id:20!null\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id]\n" +
" │ │ END as M6T2N, aac.BTXC5:8 as BTXC5, aac.id:7!null as NTOFG, sn.id:10!null as LWQ6O, mjr3d.TUV25:3 as TUV25]\n" +
" │ └─ LeftOuterJoin\n" +
" │ ├─ Or\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ Or\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ sn.id:10!null\n" +
" │ │ │ │ │ │ └─ mjr3d.QNI57:5!null\n" +
" │ │ │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ │ │ └─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ │ ├─ left: sn.id:10!null\n" +
" │ │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [jtehg.id:20!null]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ jtehg.BRQP2:21!null\n" +
" │ │ │ │ │ │ └─ mjr3d.BJUF2:1!null\n" +
" │ │ │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ └─ NOT\n" +
" │ │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ │ └─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ ├─ left: sn.id:10!null\n" +
" │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [xmafz.id:20!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ xmafz.BRQP2:21!null\n" +
" │ │ │ │ │ └─ mjr3d.FJDP5:0!null\n" +
" │ │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ └─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ │ └─ InSubquery\n" +
" │ │ │ ├─ left: sn.id:10!null\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id:20!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ xmafz.BRQP2:21!null\n" +
" │ │ │ │ └─ mjr3d.BJUF2:1!null\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ NOT\n" +
" │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.id:7!null\n" +
" │ │ │ └─ mjr3d.M22QN:2!null\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: mjr3d\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Distinct\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ism.FV24E:9!null as FJDP5, cpmfe.id:27!null as BJUF2, ism.M22QN:11!null as M22QN, g3yxs.TUV25:5 as TUV25, g3yxs.ESFVY:1!null as ESFVY, yqif4.id:44!null as QNI57, yvhjz.id:54!null as TDEIU]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ g3yxs.TUV25:5 IS NULL\n" +
" │ │ │ │ └─ Or\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ yqif4.id:44!null IS NULL\n" +
" │ │ │ │ └─ NOT\n" +
" │ │ │ │ └─ yvhjz.id:54!null IS NULL\n" +
" │ │ │ └─ LeftOuterHashJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ yvhjz.BRQP2:55!null\n" +
" │ │ │ │ │ └─ ism.UJ6XY:10!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ yvhjz.FFTBJ:56!null\n" +
" │ │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ yqif4.BRQP2:45!null\n" +
" │ │ │ │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ yqif4.FFTBJ:46!null\n" +
" │ │ │ │ │ └─ ism.UJ6XY:10!null\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ cpmfe.ZH72S:34\n" +
" │ │ │ │ │ │ │ └─ nhmxw.NOHHR:18!null\n" +
" │ │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ cpmfe.id:27!null\n" +
" │ │ │ │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ nhmxw.id:17!null\n" +
" │ │ │ │ │ │ │ └─ ism.PRUV2:14\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ ├─ g3yxs.id:0!null\n" +
" │ │ │ │ │ │ │ │ └─ ism.NZ4MQ:12!null\n" +
" │ │ │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ │ │ └─ g3yxs.TUV25:5 IS NULL\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q tuv25 ykssu fhcyt]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
" │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:14)\n" +
" │ │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ │ └─ columns: [id nohhr avpyf sypkf idut2 fzxv5 dqygv swcqv ykssu fhcyt]\n" +
" │ │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ ├─ left-key: TUPLE(ism.FV24E:9!null, ism.UJ6XY:10!null)\n" +
" │ │ │ │ ├─ right-key: TUPLE(yqif4.BRQP2:1!null, yqif4.FFTBJ:2!null)\n" +
" │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(ism.UJ6XY:10!null, ism.FV24E:9!null)\n" +
" │ │ │ ├─ right-key: TUPLE(yvhjz.BRQP2:1!null, yvhjz.FFTBJ:2!null)\n" +
" │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: scalarSubq0\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ SubqueryAlias\n" +
" ├─ name: zmspr\n" +
" ├─ outerVisibility: true\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cld.T4IBQ:0!null as T4IBQ, p4pjz.M6T2N:3 as M6T2N, p4pjz.BTXC5:4 as BTXC5, p4pjz.TUV25:7 as TUV25]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ p4pjz.M6T2N:3 IS NULL\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ p4pjz.LWQ6O:6!null\n" +
" │ │ └─ cld.BDNYB:1!null\n" +
" │ └─ Eq\n" +
" │ ├─ p4pjz.NTOFG:5!null\n" +
" │ └─ cld.M22QN:2!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cld\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:6!null as T4IBQ, sn.id:0!null as BDNYB, mf.M22QN:4!null as M22QN]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ cla.FTQLQ:6!null\n" +
" │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ bs.id:7!null\n" +
" │ │ └─ mf.GXLUB:2!null\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ │ └─ mf.LUEVY:3!null\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.GXLUB:2!null)\n" +
" │ ├─ right-key: TUPLE(bs.id:2!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ cla.id:5!null\n" +
" │ │ └─ bs.IXUXU:8\n" +
" │ ├─ Filter\n" +
" │ │ ├─ HashIn\n" +
" │ │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(cld.BDNYB:1!null, cld.M22QN:2!null)\n" +
" ├─ right-key: TUPLE(p4pjz.LWQ6O:3!null, p4pjz.NTOFG:2!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: p4pjz\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [CASE WHEN NOT\n" +
" │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:26!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:25!null\n" +
" │ │ └─ mjr3d.QNI57:5!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:26!null, (row_number() over ( order by noxn3.id asc):25!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:25!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:26!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:25!null\n" +
" │ │ └─ mjr3d.TDEIU:6!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:26!null, (row_number() over ( order by noxn3.id asc):25!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:25!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5:8 as BTXC5, aac.id:7!null as NTOFG, sn.id:10!null as LWQ6O, mjr3d.TUV25:3 as TUV25]\n" +
" └─ Project\n" +
" ├─ columns: [mjr3d.FJDP5:0!null, mjr3d.BJUF2:1!null, mjr3d.M22QN:2!null, mjr3d.TUV25:3, mjr3d.ESFVY:4!null, mjr3d.QNI57:5!null, mjr3d.TDEIU:6!null, aac.id:7!null, aac.BTXC5:8, aac.FHCYT:9, sn.id:10!null, sn.BRQP2:11!null, sn.FFTBJ:12!null, sn.A7XO2:13, sn.KBO7R:14!null, sn.ECDKM:15, sn.NUMK2:16!null, sn.LETOE:17!null, sn.YKSSU:18, sn.FHCYT:19, CASE WHEN NOT\n" +
" │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:21!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:20!null\n" +
" │ │ └─ mjr3d.QNI57:5!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:21!null, (row_number() over ( order by noxn3.id asc):20!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:20!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N:21!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ei.id:20!null\n" +
" │ │ └─ mjr3d.TDEIU:6!null\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:21!null, (row_number() over ( order by noxn3.id asc):20!null - 1 (tinyint)) as M6T2N]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:20!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5:8 as BTXC5, aac.id:7!null as NTOFG, sn.id:10!null as LWQ6O, mjr3d.TUV25:3 as TUV25]\n" +
" └─ LeftOuterJoin\n" +
" ├─ Or\n" +
" │ ├─ Or\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ sn.id:10!null\n" +
" │ │ │ │ │ └─ mjr3d.QNI57:5!null\n" +
" │ │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ │ └─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ ├─ left: sn.id:10!null\n" +
" │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [jtehg.id:20!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ jtehg.BRQP2:21!null\n" +
" │ │ │ │ │ └─ mjr3d.BJUF2:1!null\n" +
" │ │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ └─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ │ └─ InSubquery\n" +
" │ │ │ ├─ left: sn.id:10!null\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id:20!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ xmafz.BRQP2:21!null\n" +
" │ │ │ │ └─ mjr3d.FJDP5:0!null\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ └─ AND\n" +
" │ ├─ AND\n" +
" │ │ ├─ NOT\n" +
" │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ └─ InSubquery\n" +
" │ │ ├─ left: sn.id:10!null\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xmafz.id:20!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xmafz.BRQP2:21!null\n" +
" │ │ │ └─ mjr3d.BJUF2:1!null\n" +
" │ │ └─ TableAlias(xmafz)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ └─ columns: [id brqp2]\n" +
" │ └─ NOT\n" +
" │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" ├─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ aac.id:7!null\n" +
" │ │ └─ mjr3d.M22QN:2!null\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: mjr3d\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ism.FV24E:9!null as FJDP5, cpmfe.id:27!null as BJUF2, ism.M22QN:11!null as M22QN, g3yxs.TUV25:5 as TUV25, g3yxs.ESFVY:1!null as ESFVY, yqif4.id:44!null as QNI57, yvhjz.id:54!null as TDEIU]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ g3yxs.TUV25:5 IS NULL\n" +
" │ │ │ └─ Or\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ yqif4.id:44!null IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ yvhjz.id:54!null IS NULL\n" +
" │ │ └─ LeftOuterHashJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ yvhjz.BRQP2:55!null\n" +
" │ │ │ │ └─ ism.UJ6XY:10!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ yvhjz.FFTBJ:56!null\n" +
" │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ yqif4.BRQP2:45!null\n" +
" │ │ │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ yqif4.FFTBJ:46!null\n" +
" │ │ │ │ └─ ism.UJ6XY:10!null\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ cpmfe.ZH72S:34\n" +
" │ │ │ │ │ │ └─ nhmxw.NOHHR:18!null\n" +
" │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ cpmfe.id:27!null\n" +
" │ │ │ │ │ └─ ism.FV24E:9!null\n" +
" │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nhmxw.id:17!null\n" +
" │ │ │ │ │ │ └─ ism.PRUV2:14\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ ├─ g3yxs.id:0!null\n" +
" │ │ │ │ │ │ │ └─ ism.NZ4MQ:12!null\n" +
" │ │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ │ └─ g3yxs.TUV25:5 IS NULL\n" +
" │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q tuv25 ykssu fhcyt]\n" +
" │ │ │ │ │ │ └─ TableAlias(ism)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:14)\n" +
" │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ └─ columns: [id nohhr avpyf sypkf idut2 fzxv5 dqygv swcqv ykssu fhcyt]\n" +
" │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(ism.FV24E:9!null, ism.UJ6XY:10!null)\n" +
" │ │ │ ├─ right-key: TUPLE(yqif4.BRQP2:1!null, yqif4.FFTBJ:2!null)\n" +
" │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(ism.UJ6XY:10!null, ism.FV24E:9!null)\n" +
" │ │ ├─ right-key: TUPLE(yvhjz.BRQP2:1!null, yvhjz.FFTBJ:2!null)\n" +
" │ │ └─ TableAlias(yvhjz)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ columns: [id btxc5 fhcyt]\n" +
" └─ TableAlias(sn)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
TW55N
FROM
E2I7U
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [e2i7u.TW55N:3!null]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT
TW55N, FGG57
FROM
E2I7U
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [e2i7u.TW55N:3!null, e2i7u.FGG57:6]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT COUNT(*) FROM E2I7U`,
ExpectedPlan: "Project\n" +
" ├─ columns: [count(1):0!null as COUNT(*)]\n" +
" └─ Project\n" +
" ├─ columns: [E2I7U.COUNT(1):0!null as COUNT(1)]\n" +
" └─ table_count(E2I7U) as COUNT(1)\n" +
"",
},
{
Query: `
SELECT
ROW_NUMBER() OVER (ORDER BY id ASC) -1 DICQO,
TW55N
FROM
E2I7U`,
ExpectedPlan: "Project\n" +
" ├─ columns: [(row_number() over ( order by e2i7u.id asc):0!null - 1 (tinyint)) as DICQO, e2i7u.TW55N:1!null]\n" +
" └─ Window\n" +
" ├─ row_number() over ( order by e2i7u.id ASC)\n" +
" ├─ e2i7u.TW55N:1!null\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n]\n" +
"",
},
{
Query: `
SELECT
TUSAY.Y3IOU AS Q7H3X
FROM
(SELECT
id AS Y46B2,
HHVLX AS HHVLX,
HVHRZ AS HVHRZ
FROM
QYWQD) XJ2RD
INNER JOIN
(SELECT
ROW_NUMBER() OVER (ORDER BY id ASC) Y3IOU,
id AS XLFIA
FROM
NOXN3) TUSAY
ON XJ2RD.HHVLX = TUSAY.XLFIA
ORDER BY Y46B2 ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [tusay.Y3IOU:3!null as Q7H3X]\n" +
" └─ Sort(xj2rd.Y46B2:0!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [xj2rd.Y46B2:2!null, xj2rd.HHVLX:3!null, xj2rd.HVHRZ:4!null, tusay.Y3IOU:0!null, tusay.XLFIA:1!null, tusay.Y3IOU:0!null as Q7H3X]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ xj2rd.HHVLX:3!null\n" +
" │ └─ tusay.XLFIA:1!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: tusay\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [row_number() over ( order by noxn3.id asc):0!null as Y3IOU, noxn3.id:1!null as XLFIA]\n" +
" │ └─ Window\n" +
" │ ├─ row_number() over ( order by noxn3.id ASC)\n" +
" │ ├─ noxn3.id:0!null\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(tusay.XLFIA:1!null)\n" +
" ├─ right-key: TUPLE(xj2rd.HHVLX:1!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: xj2rd\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [qywqd.id:0!null as Y46B2, qywqd.HHVLX:1!null as HHVLX, qywqd.HVHRZ:2!null as HVHRZ]\n" +
" └─ Table\n" +
" ├─ name: QYWQD\n" +
" └─ columns: [id hhvlx hvhrz]\n" +
"",
},
{
Query: `
SELECT
I2GJ5.R2SR7
FROM
(SELECT
id AS XLFIA,
BRQP2
FROM
NOXN3
ORDER BY id ASC) sn
LEFT JOIN
(SELECT
nd.LUEVY,
CASE
WHEN nma.DZLIM = 'Q5I4E' THEN 1
ELSE 0
END AS R2SR7
FROM
(SELECT
id AS LUEVY,
HPCMS AS HPCMS
FROM
E2I7U) nd
LEFT JOIN
(SELECT
id AS MLECF,
DZLIM
FROM
TNMXI) nma
ON nd.HPCMS = nma.MLECF) I2GJ5
ON sn.BRQP2 = I2GJ5.LUEVY
ORDER BY sn.XLFIA ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [i2gj5.R2SR7:3!null]\n" +
" └─ Sort(sn.XLFIA:0!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sn.XLFIA:0!null, sn.BRQP2:1!null, i2gj5.LUEVY:2!null, i2gj5.R2SR7:3!null]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ sn.BRQP2:1!null\n" +
" │ └─ i2gj5.LUEVY:2!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: sn\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:0!null as XLFIA, noxn3.BRQP2:1!null]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:0!null, noxn3.BRQP2:1!null, noxn3.FFTBJ:2!null, noxn3.A7XO2:3, noxn3.KBO7R:4!null, noxn3.ECDKM:5, noxn3.NUMK2:6!null, noxn3.LETOE:7!null, noxn3.YKSSU:8, noxn3.FHCYT:9, noxn3.id:0!null as XLFIA]\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(sn.BRQP2:1!null)\n" +
" ├─ right-key: TUPLE(i2gj5.LUEVY:0!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: i2gj5\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.LUEVY:0!null, CASE WHEN Eq\n" +
" │ ├─ nma.DZLIM:3!null\n" +
" │ └─ Q5I4E (longtext)\n" +
" │ THEN 1 (tinyint) ELSE 0 (tinyint) END as R2SR7]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.HPCMS:1!null\n" +
" │ └─ nma.MLECF:2!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id:0!null as LUEVY, e2i7u.HPCMS:1!null as HPCMS]\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id hpcms]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(nd.HPCMS:1!null)\n" +
" ├─ right-key: TUPLE(nma.MLECF:0!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nma\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [tnmxi.id:0!null as MLECF, tnmxi.DZLIM:1!null]\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" └─ columns: [id dzlim]\n" +
"",
},
{
Query: `
SELECT
QI2IE.DICQO AS DICQO
FROM
(SELECT
id AS XLFIA,
BRQP2 AS AHMDT
FROM
NOXN3) GRRB6
LEFT JOIN
(SELECT
ROW_NUMBER() OVER (ORDER BY id ASC) DICQO,
id AS VIBZI
FROM
E2I7U) QI2IE
ON QI2IE.VIBZI = GRRB6.AHMDT
ORDER BY GRRB6.XLFIA ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [qi2ie.DICQO:2!null as DICQO]\n" +
" └─ Sort(grrb6.XLFIA:0!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [grrb6.XLFIA:0!null, grrb6.AHMDT:1!null, qi2ie.DICQO:2!null, qi2ie.VIBZI:3!null, qi2ie.DICQO:2!null as DICQO]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ qi2ie.VIBZI:3!null\n" +
" │ └─ grrb6.AHMDT:1!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: grrb6\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id:0!null as XLFIA, noxn3.BRQP2:1!null as AHMDT]\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(grrb6.AHMDT:1!null)\n" +
" ├─ right-key: TUPLE(qi2ie.VIBZI:1!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: qi2ie\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by e2i7u.id asc):0!null as DICQO, e2i7u.id:1!null as VIBZI]\n" +
" └─ Window\n" +
" ├─ row_number() over ( order by e2i7u.id ASC)\n" +
" ├─ e2i7u.id:0!null\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id]\n" +
"",
},
{
Query: `
SELECT
DISTINCT cla.FTQLQ
FROM
YK2GW cla
WHERE
cla.id IN (
SELECT bs.IXUXU
FROM THNTS bs
WHERE
bs.id IN (SELECT GXLUB FROM HGMQ6)
AND bs.id IN (SELECT GXLUB FROM AMYXQ)
)
ORDER BY cla.FTQLQ ASC`,
ExpectedPlan: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ:1!null]\n" +
" └─ Sort(cla.FTQLQ:1!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [cla.id:1!null, cla.FTQLQ:2!null, cla.TUXML:3, cla.PAEF5:4, cla.RUCY4:5, cla.TPNJ6:6!null, cla.LBL53:7, cla.NB3QS:8, cla.EO7IV:9, cla.MUHJF:10, cla.FM34L:11, cla.TY5RF:12, cla.ZHTLH:13, cla.NPB7W:14, cla.SX3HH:15, cla.ISBNF:16, cla.YA7YB:17, cla.C5YKB:18, cla.QK7KT:19, cla.FFGE6:20, cla.FIIGJ:21, cla.SH3NC:22, cla.NTENA:23, cla.M4AUB:24, cla.X5AIR:25, cla.SAB6M:26, cla.G5QI5:27, cla.ZVQVD:28, cla.YKSSU:29, cla.FHCYT:30]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ cla.id:1!null\n" +
" │ └─ scalarSubq0.IXUXU:0\n" +
" ├─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [scalarSubq0.IXUXU:2]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [scalarSubq0.id:0!null, scalarSubq0.NFRYN:1!null, scalarSubq0.IXUXU:2, scalarSubq0.FHCYT:3]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ scalarSubq0.id:0!null\n" +
" │ │ └─ scalarSubq2.GXLUB:4!null\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [scalarSubq0.id:0!null, scalarSubq0.NFRYN:1!null, scalarSubq0.IXUXU:2, scalarSubq0.FHCYT:3]\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ scalarSubq0.id:0!null\n" +
" │ │ │ └─ scalarSubq1.GXLUB:4!null\n" +
" │ │ ├─ TableAlias(scalarSubq0)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [scalarSubq1.GXLUB:1!null]\n" +
" │ │ └─ TableAlias(scalarSubq1)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.GXLUB]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(scalarSubq0.id:0!null)\n" +
" │ ├─ right-key: TUPLE(scalarSubq2.GXLUB:0!null)\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [scalarSubq2.GXLUB:1!null]\n" +
" │ └─ TableAlias(scalarSubq2)\n" +
" │ └─ Table\n" +
" │ ├─ name: AMYXQ\n" +
" │ └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(scalarSubq0.IXUXU:0)\n" +
" ├─ right-key: TUPLE(cla.id:0!null)\n" +
" └─ TableAlias(cla)\n" +
" └─ Table\n" +
" ├─ name: YK2GW\n" +
" └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
DISTINCT cla.FTQLQ
FROM HGMQ6 mf
INNER JOIN THNTS bs
ON mf.GXLUB = bs.id
INNER JOIN YK2GW cla
ON bs.IXUXU = cla.id
ORDER BY cla.FTQLQ ASC`,
ExpectedPlan: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ:22!null]\n" +
" └─ Sort(cla.FTQLQ:22!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [mf.id:4!null, mf.GXLUB:5!null, mf.LUEVY:6!null, mf.M22QN:7!null, mf.TJPT7:8!null, mf.ARN5P:9!null, mf.XOSD4:10!null, mf.IDE43:11, mf.HMW4H:12, mf.ZBT6R:13, mf.FSDY2:14!null, mf.LT7K6:15, mf.SPPYD:16, mf.QCGTS:17, mf.TEUJA:18, mf.QQV4M:19, mf.FHCYT:20, bs.id:0!null, bs.NFRYN:1!null, bs.IXUXU:2, bs.FHCYT:3, cla.id:21!null, cla.FTQLQ:22!null, cla.TUXML:23, cla.PAEF5:24, cla.RUCY4:25, cla.TPNJ6:26!null, cla.LBL53:27, cla.NB3QS:28, cla.EO7IV:29, cla.MUHJF:30, cla.FM34L:31, cla.TY5RF:32, cla.ZHTLH:33, cla.NPB7W:34, cla.SX3HH:35, cla.ISBNF:36, cla.YA7YB:37, cla.C5YKB:38, cla.QK7KT:39, cla.FFGE6:40, cla.FIIGJ:41, cla.SH3NC:42, cla.NTENA:43, cla.M4AUB:44, cla.X5AIR:45, cla.SAB6M:46, cla.G5QI5:47, cla.ZVQVD:48, cla.YKSSU:49, cla.FHCYT:50]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ bs.IXUXU:2\n" +
" │ └─ cla.id:21!null\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ bs.id:0!null\n" +
" │ │ └─ mf.GXLUB:5!null\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" │ └─ TableAlias(mf)\n" +
" │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ ├─ index: [HGMQ6.GXLUB]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(bs.IXUXU:2)\n" +
" ├─ right-key: TUPLE(cla.id:0!null)\n" +
" └─ TableAlias(cla)\n" +
" └─ Table\n" +
" ├─ name: YK2GW\n" +
" └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
DISTINCT cla.FTQLQ
FROM YK2GW cla
WHERE cla.id IN
(SELECT IXUXU FROM THNTS bs
WHERE bs.id IN (SELECT GXLUB FROM AMYXQ))
ORDER BY cla.FTQLQ ASC`,
ExpectedPlan: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ:1!null]\n" +
" └─ Sort(cla.FTQLQ:1!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [cla.id:1!null, cla.FTQLQ:2!null, cla.TUXML:3, cla.PAEF5:4, cla.RUCY4:5, cla.TPNJ6:6!null, cla.LBL53:7, cla.NB3QS:8, cla.EO7IV:9, cla.MUHJF:10, cla.FM34L:11, cla.TY5RF:12, cla.ZHTLH:13, cla.NPB7W:14, cla.SX3HH:15, cla.ISBNF:16, cla.YA7YB:17, cla.C5YKB:18, cla.QK7KT:19, cla.FFGE6:20, cla.FIIGJ:21, cla.SH3NC:22, cla.NTENA:23, cla.M4AUB:24, cla.X5AIR:25, cla.SAB6M:26, cla.G5QI5:27, cla.ZVQVD:28, cla.YKSSU:29, cla.FHCYT:30]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ cla.id:1!null\n" +
" │ └─ scalarSubq0.IXUXU:0\n" +
" ├─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [scalarSubq0.IXUXU:2]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [scalarSubq0.id:0!null, scalarSubq0.NFRYN:1!null, scalarSubq0.IXUXU:2, scalarSubq0.FHCYT:3]\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ scalarSubq0.id:0!null\n" +
" │ │ └─ scalarSubq1.GXLUB:4!null\n" +
" │ ├─ TableAlias(scalarSubq0)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [scalarSubq1.GXLUB:1!null]\n" +
" │ └─ TableAlias(scalarSubq1)\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.GXLUB]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(scalarSubq0.IXUXU:0)\n" +
" ├─ right-key: TUPLE(cla.id:0!null)\n" +
" └─ TableAlias(cla)\n" +
" └─ Table\n" +
" ├─ name: YK2GW\n" +
" └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
DISTINCT ci.FTQLQ
FROM FLQLP ct
INNER JOIN JDLNA ci
ON ct.FZ2R5 = ci.id
ORDER BY ci.FTQLQ`,
ExpectedPlan: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ci.FTQLQ:13!null]\n" +
" └─ Sort(ci.FTQLQ:13!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [ct.id:5!null, ct.FZ2R5:6!null, ct.LUEVY:7!null, ct.M22QN:8!null, ct.OVE3E:9!null, ct.NRURT:10, ct.OCA7E:11, ct.XMM6Q:12, ct.V5DPX:13!null, ct.S3Q3Y:14!null, ct.ZRV3B:15!null, ct.FHCYT:16, ci.id:0!null, ci.FTQLQ:1!null, ci.FWWIQ:2, ci.O3QXW:3, ci.FHCYT:4]\n" +
" └─ MergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ ci.id:0!null\n" +
" │ └─ ct.FZ2R5:6!null\n" +
" ├─ TableAlias(ci)\n" +
" │ └─ IndexedTableAccess(JDLNA)\n" +
" │ ├─ index: [JDLNA.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ftqlq fwwiq o3qxw fhcyt]\n" +
" └─ TableAlias(ct)\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.FZ2R5]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
"",
},
{
Query: `
SELECT
YPGDA.LUEVY AS LUEVY,
YPGDA.TW55N AS TW55N,
YPGDA.IYDZV AS IYDZV,
'' AS IIISV,
YPGDA.QRQXW AS QRQXW,
YPGDA.CAECS AS CAECS,
YPGDA.CJLLY AS CJLLY,
YPGDA.SHP7H AS SHP7H,
YPGDA.HARAZ AS HARAZ,
'' AS ECUWU,
'' AS LDMO7,
CASE
WHEN YBBG5.DZLIM = 'HGUEM' THEN 's30'
WHEN YBBG5.DZLIM = 'YUHMV' THEN 'r90'
WHEN YBBG5.DZLIM = 'T3JIU' THEN 'r50'
WHEN YBBG5.DZLIM = 's' THEN 's'
WHEN YBBG5.DZLIM = 'AX25H' THEN 'r70'
WHEN YBBG5.DZLIM IS NULL then ''
ELSE YBBG5.DZLIM
END AS UBUYI,
YPGDA.FUG6J AS FUG6J,
YPGDA.NF5AM AS NF5AM,
YPGDA.FRCVC AS FRCVC
FROM
(SELECT
nd.id AS LUEVY,
nd.TW55N AS TW55N,
nd.FGG57 AS IYDZV,
nd.QRQXW AS QRQXW,
nd.IWV2H AS CAECS,
nd.ECXAJ AS CJLLY,
nma.DZLIM AS SHP7H,
nd.N5CC2 AS HARAZ,
(SELECT
XQDYT
FROM AMYXQ
WHERE LUEVY = nd.id
LIMIT 1) AS I3L5A,
nd.ETAQ7 AS FUG6J,
nd.A75X7 AS NF5AM,
nd.FSK67 AS FRCVC
FROM E2I7U nd
LEFT JOIN TNMXI nma
ON nma.id = nd.HPCMS) YPGDA
LEFT JOIN XGSJM YBBG5
ON YPGDA.I3L5A = YBBG5.id
ORDER BY LUEVY`,
ExpectedPlan: "Project\n" +
" ├─ columns: [ypgda.LUEVY:0!null as LUEVY, ypgda.TW55N:1!null as TW55N, ypgda.IYDZV:2 as IYDZV, (longtext) as IIISV, ypgda.QRQXW:3!null as QRQXW, ypgda.CAECS:4 as CAECS, ypgda.CJLLY:5!null as CJLLY, ypgda.SHP7H:6!null as SHP7H, ypgda.HARAZ:7 as HARAZ, (longtext) as ECUWU, (longtext) as LDMO7, CASE WHEN Eq\n" +
" │ ├─ ybbg5.DZLIM:13!null\n" +
" │ └─ HGUEM (longtext)\n" +
" │ THEN s30 (longtext) WHEN Eq\n" +
" │ ├─ ybbg5.DZLIM:13!null\n" +
" │ └─ YUHMV (longtext)\n" +
" │ THEN r90 (longtext) WHEN Eq\n" +
" │ ├─ ybbg5.DZLIM:13!null\n" +
" │ └─ T3JIU (longtext)\n" +
" │ THEN r50 (longtext) WHEN Eq\n" +
" │ ├─ ybbg5.DZLIM:13!null\n" +
" │ └─ s (longtext)\n" +
" │ THEN s (longtext) WHEN Eq\n" +
" │ ├─ ybbg5.DZLIM:13!null\n" +
" │ └─ AX25H (longtext)\n" +
" │ THEN r70 (longtext) WHEN ybbg5.DZLIM:13!null IS NULL THEN (longtext) ELSE ybbg5.DZLIM:13!null END as UBUYI, ypgda.FUG6J:9 as FUG6J, ypgda.NF5AM:10 as NF5AM, ypgda.FRCVC:11!null as FRCVC]\n" +
" └─ Sort(ypgda.LUEVY:0!null as LUEVY ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [ypgda.LUEVY:0!null, ypgda.TW55N:1!null, ypgda.IYDZV:2, ypgda.QRQXW:3!null, ypgda.CAECS:4, ypgda.CJLLY:5!null, ypgda.SHP7H:6!null, ypgda.HARAZ:7, ypgda.I3L5A:8, ypgda.FUG6J:9, ypgda.NF5AM:10, ypgda.FRCVC:11!null, ybbg5.id:12!null, ybbg5.DZLIM:13!null, ybbg5.F3YUE:14, ypgda.LUEVY:0!null as LUEVY, ypgda.TW55N:1!null as TW55N, ypgda.IYDZV:2 as IYDZV, (longtext) as IIISV, ypgda.QRQXW:3!null as QRQXW, ypgda.CAECS:4 as CAECS, ypgda.CJLLY:5!null as CJLLY, ypgda.SHP7H:6!null as SHP7H, ypgda.HARAZ:7 as HARAZ, (longtext) as ECUWU, (longtext) as LDMO7, CASE WHEN Eq\n" +
" │ ├─ ybbg5.DZLIM:13!null\n" +
" │ └─ HGUEM (longtext)\n" +
" │ THEN s30 (longtext) WHEN Eq\n" +
" │ ├─ ybbg5.DZLIM:13!null\n" +
" │ └─ YUHMV (longtext)\n" +
" │ THEN r90 (longtext) WHEN Eq\n" +
" │ ├─ ybbg5.DZLIM:13!null\n" +
" │ └─ T3JIU (longtext)\n" +
" │ THEN r50 (longtext) WHEN Eq\n" +
" │ ├─ ybbg5.DZLIM:13!null\n" +
" │ └─ s (longtext)\n" +
" │ THEN s (longtext) WHEN Eq\n" +
" │ ├─ ybbg5.DZLIM:13!null\n" +
" │ └─ AX25H (longtext)\n" +
" │ THEN r70 (longtext) WHEN ybbg5.DZLIM:13!null IS NULL THEN (longtext) ELSE ybbg5.DZLIM:13!null END as UBUYI, ypgda.FUG6J:9 as FUG6J, ypgda.NF5AM:10 as NF5AM, ypgda.FRCVC:11!null as FRCVC]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ ypgda.I3L5A:8\n" +
" │ └─ ybbg5.id:12!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: ypgda\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id:0!null as LUEVY, nd.TW55N:3!null as TW55N, nd.FGG57:6 as IYDZV, nd.QRQXW:4!null as QRQXW, nd.IWV2H:11 as CAECS, nd.ECXAJ:5!null as CJLLY, nma.DZLIM:18!null as SHP7H, nd.N5CC2:13 as HARAZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.XQDYT:33!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ amyxq.LUEVY:32!null\n" +
" │ │ │ └─ nd.id:0!null\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ │ └─ columns: [luevy xqdyt]\n" +
" │ │ as I3L5A, nd.ETAQ7:15 as FUG6J, nd.A75X7:16 as NF5AM, nd.FSK67:8!null as FRCVC]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id:0!null, nd.DKCAJ:1!null, nd.KNG7T:2, nd.TW55N:3!null, nd.QRQXW:4!null, nd.ECXAJ:5!null, nd.FGG57:6, nd.ZH72S:7, nd.FSK67:8!null, nd.XQDYT:9!null, nd.TCE7A:10, nd.IWV2H:11, nd.HPCMS:12!null, nd.N5CC2:13, nd.FHCYT:14, nd.ETAQ7:15, nd.A75X7:16, nma.id:17!null, nma.DZLIM:18!null, nma.F3YUE:19, nd.id:0!null as LUEVY, nd.TW55N:3!null as TW55N, nd.FGG57:6 as IYDZV, nd.QRQXW:4!null as QRQXW, nd.IWV2H:11 as CAECS, nd.ECXAJ:5!null as CJLLY, nma.DZLIM:18!null as SHP7H, nd.N5CC2:13 as HARAZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.XQDYT:21!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ amyxq.LUEVY:20!null\n" +
" │ │ │ └─ nd.id:0!null\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ │ └─ columns: [luevy xqdyt]\n" +
" │ │ as I3L5A, nd.ETAQ7:15 as FUG6J, nd.A75X7:16 as NF5AM, nd.FSK67:8!null as FRCVC]\n" +
" │ └─ LeftOuterMergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ nd.HPCMS:12!null\n" +
" │ │ └─ nma.id:17!null\n" +
" │ ├─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.HPCMS]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ TableAlias(nma)\n" +
" │ └─ IndexedTableAccess(TNMXI)\n" +
" │ ├─ index: [TNMXI.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id dzlim f3yue]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(ypgda.I3L5A:8)\n" +
" ├─ right-key: TUPLE(ybbg5.id:0!null)\n" +
" └─ TableAlias(ybbg5)\n" +
" └─ Table\n" +
" ├─ name: XGSJM\n" +
" └─ columns: [id dzlim f3yue]\n" +
"",
},
{
Query: `
SELECT LUEVY, F6NSZ FROM ARLV5`,
ExpectedPlan: "Table\n" +
" ├─ name: ARLV5\n" +
" └─ columns: [luevy f6nsz]\n" +
"",
},
{
Query: `
SELECT id, DZLIM FROM IIISV`,
ExpectedPlan: "Table\n" +
" ├─ name: IIISV\n" +
" └─ columns: [id dzlim]\n" +
"",
},
{
Query: `
SELECT
TVQG4.TW55N
AS FJVD7,
LSM32.TW55N
AS KBXXJ,
sn.NUMK2
AS NUMK2,
CASE
WHEN it.DZLIM IS NULL
THEN "N/A"
ELSE it.DZLIM
END
AS TP6BK,
sn.ECDKM
AS ECDKM,
sn.KBO7R
AS KBO7R,
CASE
WHEN sn.YKSSU IS NULL
THEN "N/A"
ELSE sn.YKSSU
END
AS RQI4M,
CASE
WHEN sn.FHCYT IS NULL
THEN "N/A"
ELSE sn.FHCYT
END
AS RNVLS,
sn.LETOE
AS LETOE
FROM
NOXN3 sn
LEFT JOIN
E2I7U TVQG4
ON sn.BRQP2 = TVQG4.id
LEFT JOIN
E2I7U LSM32
ON sn.FFTBJ = LSM32.id
LEFT JOIN
FEVH4 it
ON sn.A7XO2 = it.id
ORDER BY sn.id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [tvqg4.TW55N:13!null as FJVD7, lsm32.TW55N:30!null as KBXXJ, sn.NUMK2:6!null as NUMK2, CASE WHEN it.DZLIM:45!null IS NULL THEN N/A (longtext) ELSE it.DZLIM:45!null END as TP6BK, sn.ECDKM:5 as ECDKM, sn.KBO7R:4!null as KBO7R, CASE WHEN sn.YKSSU:8 IS NULL THEN N/A (longtext) ELSE sn.YKSSU:8 END as RQI4M, CASE WHEN sn.FHCYT:9 IS NULL THEN N/A (longtext) ELSE sn.FHCYT:9 END as RNVLS, sn.LETOE:7!null as LETOE]\n" +
" └─ Sort(sn.id:0!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sn.id:0!null, sn.BRQP2:1!null, sn.FFTBJ:2!null, sn.A7XO2:3, sn.KBO7R:4!null, sn.ECDKM:5, sn.NUMK2:6!null, sn.LETOE:7!null, sn.YKSSU:8, sn.FHCYT:9, tvqg4.id:10!null, tvqg4.DKCAJ:11!null, tvqg4.KNG7T:12, tvqg4.TW55N:13!null, tvqg4.QRQXW:14!null, tvqg4.ECXAJ:15!null, tvqg4.FGG57:16, tvqg4.ZH72S:17, tvqg4.FSK67:18!null, tvqg4.XQDYT:19!null, tvqg4.TCE7A:20, tvqg4.IWV2H:21, tvqg4.HPCMS:22!null, tvqg4.N5CC2:23, tvqg4.FHCYT:24, tvqg4.ETAQ7:25, tvqg4.A75X7:26, lsm32.id:27!null, lsm32.DKCAJ:28!null, lsm32.KNG7T:29, lsm32.TW55N:30!null, lsm32.QRQXW:31!null, lsm32.ECXAJ:32!null, lsm32.FGG57:33, lsm32.ZH72S:34, lsm32.FSK67:35!null, lsm32.XQDYT:36!null, lsm32.TCE7A:37, lsm32.IWV2H:38, lsm32.HPCMS:39!null, lsm32.N5CC2:40, lsm32.FHCYT:41, lsm32.ETAQ7:42, lsm32.A75X7:43, it.id:44!null, it.DZLIM:45!null, it.F3YUE:46, tvqg4.TW55N:13!null as FJVD7, lsm32.TW55N:30!null as KBXXJ, sn.NUMK2:6!null as NUMK2, CASE WHEN it.DZLIM:45!null IS NULL THEN N/A (longtext) ELSE it.DZLIM:45!null END as TP6BK, sn.ECDKM:5 as ECDKM, sn.KBO7R:4!null as KBO7R, CASE WHEN sn.YKSSU:8 IS NULL THEN N/A (longtext) ELSE sn.YKSSU:8 END as RQI4M, CASE WHEN sn.FHCYT:9 IS NULL THEN N/A (longtext) ELSE sn.FHCYT:9 END as RNVLS, sn.LETOE:7!null as LETOE]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ sn.A7XO2:3\n" +
" │ └─ it.id:44!null\n" +
" ├─ LeftOuterHashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ sn.FFTBJ:2!null\n" +
" │ │ └─ lsm32.id:27!null\n" +
" │ ├─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ │ └─ tvqg4.id:10!null\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ TableAlias(tvqg4)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(sn.FFTBJ:2!null)\n" +
" │ ├─ right-key: TUPLE(lsm32.id:0!null)\n" +
" │ └─ TableAlias(lsm32)\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(sn.A7XO2:3)\n" +
" ├─ right-key: TUPLE(it.id:0!null)\n" +
" └─ TableAlias(it)\n" +
" └─ Table\n" +
" ├─ name: FEVH4\n" +
" └─ columns: [id dzlim f3yue]\n" +
"",
},
{
Query: `
SELECT
KBO7R
FROM
NOXN3
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [noxn3.KBO7R:4!null]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
SDLLR.TW55N
AS FZX4Y,
JGT2H.LETOE
AS QWTOI,
RIIW6.TW55N
AS PDX5Y,
AYFCD.NUMK2
AS V45YB ,
AYFCD.LETOE
AS DAGQN,
FA75Y.TW55N
AS SFQTS,
rn.HVHRZ
AS HVHRZ,
CASE
WHEN rn.YKSSU IS NULL
THEN "N/A"
ELSE rn.YKSSU
END
AS RQI4M,
CASE
WHEN rn.FHCYT IS NULL
THEN "N/A"
ELSE rn.FHCYT
END
AS RNVLS
FROM
QYWQD rn
LEFT JOIN
NOXN3 JGT2H
ON rn.WNUNU = JGT2H.id
LEFT JOIN
NOXN3 AYFCD
ON rn.HHVLX = AYFCD.id
LEFT JOIN
E2I7U SDLLR
ON JGT2H.BRQP2 = SDLLR.id
LEFT JOIN
E2I7U RIIW6
ON JGT2H.FFTBJ = RIIW6.id
LEFT JOIN
E2I7U FA75Y
ON AYFCD.FFTBJ = FA75Y.id
ORDER BY rn.id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [sdllr.TW55N:29!null as FZX4Y, jgt2h.LETOE:13!null as QWTOI, riiw6.TW55N:46!null as PDX5Y, ayfcd.NUMK2:22!null as V45YB, ayfcd.LETOE:23!null as DAGQN, fa75y.TW55N:63!null as SFQTS, rn.HVHRZ:3!null as HVHRZ, CASE WHEN rn.YKSSU:4 IS NULL THEN N/A (longtext) ELSE rn.YKSSU:4 END as RQI4M, CASE WHEN rn.FHCYT:5 IS NULL THEN N/A (longtext) ELSE rn.FHCYT:5 END as RNVLS]\n" +
" └─ Sort(rn.id:0!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [rn.id:0!null, rn.WNUNU:1!null, rn.HHVLX:2!null, rn.HVHRZ:3!null, rn.YKSSU:4, rn.FHCYT:5, jgt2h.id:6!null, jgt2h.BRQP2:7!null, jgt2h.FFTBJ:8!null, jgt2h.A7XO2:9, jgt2h.KBO7R:10!null, jgt2h.ECDKM:11, jgt2h.NUMK2:12!null, jgt2h.LETOE:13!null, jgt2h.YKSSU:14, jgt2h.FHCYT:15, ayfcd.id:16!null, ayfcd.BRQP2:17!null, ayfcd.FFTBJ:18!null, ayfcd.A7XO2:19, ayfcd.KBO7R:20!null, ayfcd.ECDKM:21, ayfcd.NUMK2:22!null, ayfcd.LETOE:23!null, ayfcd.YKSSU:24, ayfcd.FHCYT:25, sdllr.id:26!null, sdllr.DKCAJ:27!null, sdllr.KNG7T:28, sdllr.TW55N:29!null, sdllr.QRQXW:30!null, sdllr.ECXAJ:31!null, sdllr.FGG57:32, sdllr.ZH72S:33, sdllr.FSK67:34!null, sdllr.XQDYT:35!null, sdllr.TCE7A:36, sdllr.IWV2H:37, sdllr.HPCMS:38!null, sdllr.N5CC2:39, sdllr.FHCYT:40, sdllr.ETAQ7:41, sdllr.A75X7:42, riiw6.id:43!null, riiw6.DKCAJ:44!null, riiw6.KNG7T:45, riiw6.TW55N:46!null, riiw6.QRQXW:47!null, riiw6.ECXAJ:48!null, riiw6.FGG57:49, riiw6.ZH72S:50, riiw6.FSK67:51!null, riiw6.XQDYT:52!null, riiw6.TCE7A:53, riiw6.IWV2H:54, riiw6.HPCMS:55!null, riiw6.N5CC2:56, riiw6.FHCYT:57, riiw6.ETAQ7:58, riiw6.A75X7:59, fa75y.id:60!null, fa75y.DKCAJ:61!null, fa75y.KNG7T:62, fa75y.TW55N:63!null, fa75y.QRQXW:64!null, fa75y.ECXAJ:65!null, fa75y.FGG57:66, fa75y.ZH72S:67, fa75y.FSK67:68!null, fa75y.XQDYT:69!null, fa75y.TCE7A:70, fa75y.IWV2H:71, fa75y.HPCMS:72!null, fa75y.N5CC2:73, fa75y.FHCYT:74, fa75y.ETAQ7:75, fa75y.A75X7:76, sdllr.TW55N:29!null as FZX4Y, jgt2h.LETOE:13!null as QWTOI, riiw6.TW55N:46!null as PDX5Y, ayfcd.NUMK2:22!null as V45YB, ayfcd.LETOE:23!null as DAGQN, fa75y.TW55N:63!null as SFQTS, rn.HVHRZ:3!null as HVHRZ, CASE WHEN rn.YKSSU:4 IS NULL THEN N/A (longtext) ELSE rn.YKSSU:4 END as RQI4M, CASE WHEN rn.FHCYT:5 IS NULL THEN N/A (longtext) ELSE rn.FHCYT:5 END as RNVLS]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ ayfcd.FFTBJ:18!null\n" +
" │ └─ fa75y.id:60!null\n" +
" ├─ LeftOuterHashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ jgt2h.FFTBJ:8!null\n" +
" │ │ └─ riiw6.id:43!null\n" +
" │ ├─ LeftOuterHashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ jgt2h.BRQP2:7!null\n" +
" │ │ │ └─ sdllr.id:26!null\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ rn.HHVLX:2!null\n" +
" │ │ │ │ └─ ayfcd.id:16!null\n" +
" │ │ │ ├─ LeftOuterMergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ rn.WNUNU:1!null\n" +
" │ │ │ │ │ └─ jgt2h.id:6!null\n" +
" │ │ │ │ ├─ TableAlias(rn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(QYWQD)\n" +
" │ │ │ │ │ ├─ index: [QYWQD.WNUNU]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id wnunu hhvlx hvhrz ykssu fhcyt]\n" +
" │ │ │ │ └─ TableAlias(jgt2h)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(rn.HHVLX:2!null)\n" +
" │ │ │ ├─ right-key: TUPLE(ayfcd.id:0!null)\n" +
" │ │ │ └─ TableAlias(ayfcd)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(jgt2h.BRQP2:7!null)\n" +
" │ │ ├─ right-key: TUPLE(sdllr.id:0!null)\n" +
" │ │ └─ TableAlias(sdllr)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(jgt2h.FFTBJ:8!null)\n" +
" │ ├─ right-key: TUPLE(riiw6.id:0!null)\n" +
" │ └─ TableAlias(riiw6)\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(ayfcd.FFTBJ:18!null)\n" +
" ├─ right-key: TUPLE(fa75y.id:0!null)\n" +
" └─ TableAlias(fa75y)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT
QRQXW
FROM
E2I7U
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [e2i7u.QRQXW:4!null]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
SELECT
sn.Y3IOU,
sn.ECDKM
FROM
(SELECT
ROW_NUMBER() OVER (ORDER BY id ASC) Y3IOU,
id,
NUMK2,
ECDKM
FROM
NOXN3) sn
WHERE NUMK2 = 4
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [sn.Y3IOU:0!null, sn.ECDKM:3]\n" +
" └─ Sort(sn.id:1!null ASC nullsFirst)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: sn\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ noxn3.NUMK2:2!null\n" +
" │ └─ 4 (tinyint)\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by noxn3.id asc):0!null as Y3IOU, noxn3.id:1!null, noxn3.NUMK2:2!null, noxn3.ECDKM:3]\n" +
" └─ Window\n" +
" ├─ row_number() over ( order by noxn3.id ASC)\n" +
" ├─ noxn3.id:0!null\n" +
" ├─ noxn3.NUMK2:2!null\n" +
" ├─ noxn3.ECDKM:1\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id ecdkm numk2]\n" +
"",
},
{
Query: `
SELECT id, NUMK2, ECDKM
FROM NOXN3
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [noxn3.id:0!null, noxn3.NUMK2:6!null, noxn3.ECDKM:5]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
CASE
WHEN NUMK2 = 2 THEN ECDKM
ELSE 0
END AS RGXLL
FROM NOXN3
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [CASE WHEN Eq\n" +
" │ ├─ noxn3.NUMK2:6!null\n" +
" │ └─ 2 (tinyint)\n" +
" │ THEN noxn3.ECDKM:5 ELSE 0 (tinyint) END as RGXLL]\n" +
" └─ Project\n" +
" ├─ columns: [noxn3.id:0!null, noxn3.BRQP2:1!null, noxn3.FFTBJ:2!null, noxn3.A7XO2:3, noxn3.KBO7R:4!null, noxn3.ECDKM:5, noxn3.NUMK2:6!null, noxn3.LETOE:7!null, noxn3.YKSSU:8, noxn3.FHCYT:9, CASE WHEN Eq\n" +
" │ ├─ noxn3.NUMK2:6!null\n" +
" │ └─ 2 (tinyint)\n" +
" │ THEN noxn3.ECDKM:5 ELSE 0 (tinyint) END as RGXLL]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
"",
},
{
Query: `
SELECT
pa.DZLIM as ECUWU,
nd.TW55N
FROM JJGQT QNRBH
INNER JOIN E2I7U nd
ON QNRBH.LUEVY = nd.id
INNER JOIN XOAOP pa
ON QNRBH.CH3FR = pa.id`,
ExpectedPlan: "Project\n" +
" ├─ columns: [pa.DZLIM:3!null as ECUWU, nd.TW55N:5!null]\n" +
" └─ LookupJoin\n" +
" ├─ Eq\n" +
" │ ├─ qnrbh.LUEVY:1!null\n" +
" │ └─ nd.id:4!null\n" +
" ├─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ qnrbh.CH3FR:0!null\n" +
" │ │ └─ pa.id:2!null\n" +
" │ ├─ TableAlias(qnrbh)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: JJGQT\n" +
" │ │ └─ columns: [ch3fr luevy]\n" +
" │ └─ TableAlias(pa)\n" +
" │ └─ IndexedTableAccess(XOAOP)\n" +
" │ ├─ index: [XOAOP.id]\n" +
" │ └─ columns: [id dzlim]\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" └─ columns: [id tw55n]\n" +
"",
},
{
Query: `-- deletes
DELETE FROM QYWQD
WHERE id IN ('1','2','3')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Delete\n" +
" └─ Filter\n" +
" ├─ HashIn\n" +
" │ ├─ qywqd.id:0!null\n" +
" │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" └─ columns: [id wnunu hhvlx hvhrz ykssu fhcyt]\n" +
"",
},
{
Query: `
DELETE FROM HDDVB
WHERE
FV24E IN ('1', '2', '3') OR
UJ6XY IN ('1', '2', '3')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Delete\n" +
" └─ Filter\n" +
" ├─ Or\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ hddvb.FV24E:1!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ HashIn\n" +
" │ ├─ hddvb.UJ6XY:2!null\n" +
" │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" └─ Table\n" +
" ├─ name: HDDVB\n" +
" └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
"",
},
{
Query: `
DELETE FROM QYWQD
WHERE id IN ('1', '2', '3')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Delete\n" +
" └─ Filter\n" +
" ├─ HashIn\n" +
" │ ├─ qywqd.id:0!null\n" +
" │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" └─ columns: [id wnunu hhvlx hvhrz ykssu fhcyt]\n" +
"",
},
{
Query: `
DELETE FROM AMYXQ
WHERE LUEVY IN ('1', '2', '3')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Delete\n" +
" └─ Filter\n" +
" ├─ HashIn\n" +
" │ ├─ amyxq.LUEVY:2!null\n" +
" │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" └─ IndexedTableAccess(AMYXQ)\n" +
" ├─ index: [AMYXQ.LUEVY]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
"",
},
{
Query: `
DELETE FROM HGMQ6
WHERE id IN ('1', '2', '3')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Delete\n" +
" └─ Filter\n" +
" ├─ HashIn\n" +
" │ ├─ hgmq6.id:0!null\n" +
" │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" └─ IndexedTableAccess(HGMQ6)\n" +
" ├─ index: [HGMQ6.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
"",
},
{
Query: `
DELETE FROM HDDVB
WHERE id IN ('1', '2', '3')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Delete\n" +
" └─ Filter\n" +
" ├─ HashIn\n" +
" │ ├─ hddvb.id:0!null\n" +
" │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" └─ IndexedTableAccess(HDDVB)\n" +
" ├─ index: [HDDVB.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
"",
},
{
Query: `
DELETE FROM FLQLP
WHERE LUEVY IN ('1', '2', '3')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Delete\n" +
" └─ Filter\n" +
" ├─ HashIn\n" +
" │ ├─ flqlp.LUEVY:2!null\n" +
" │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.LUEVY]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
"",
},
{
Query: `
DELETE FROM FLQLP
WHERE id IN ('1', '2', '3')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Delete\n" +
" └─ Filter\n" +
" ├─ HashIn\n" +
" │ ├─ flqlp.id:0!null\n" +
" │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
"",
},
{
Query: `
DELETE FROM FLQLP
WHERE id IN ('1', '2', '3')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Delete\n" +
" └─ Filter\n" +
" ├─ HashIn\n" +
" │ ├─ flqlp.id:0!null\n" +
" │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
"",
},
{
Query: `
-- updates
UPDATE E2I7U nd
SET nd.KNG7T = (SELECT gn.id FROM WE72E gn INNER JOIN TDRVG ltnm ON ltnm.SSHPJ = gn.SSHPJ WHERE ltnm.FGG57 = nd.FGG57)
WHERE nd.FGG57 IS NOT NULL AND nd.KNG7T IS NULL`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Update\n" +
" └─ UpdateSource(SET nd.KNG7T:2 = Subquery\n" +
" ├─ cacheable: false\n" +
" └─ Project\n" +
" ├─ columns: [gn.id:17!null]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ ltnm.FGG57:19!null\n" +
" │ └─ nd.FGG57:6\n" +
" └─ MergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ gn.SSHPJ:18!null\n" +
" │ └─ ltnm.SSHPJ:20!null\n" +
" ├─ TableAlias(gn)\n" +
" │ └─ IndexedTableAccess(WE72E)\n" +
" │ ├─ index: [WE72E.SSHPJ]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id sshpj]\n" +
" └─ TableAlias(ltnm)\n" +
" └─ IndexedTableAccess(TDRVG)\n" +
" ├─ index: [TDRVG.SSHPJ]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" └─ columns: [fgg57 sshpj]\n" +
" )\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ NOT\n" +
" │ │ └─ nd.FGG57:6 IS NULL\n" +
" │ └─ nd.KNG7T:2 IS NULL\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.KNG7T]\n" +
" ├─ static: [{[NULL, NULL]}]\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
UPDATE S3FQX SET ADWYM = 0, FPUYA = 0`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Update\n" +
" └─ Trigger(CREATE TRIGGER S3FQX_on_update BEFORE UPDATE ON S3FQX\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF NEW.ADWYM NOT IN (0, 1)\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The ADWYM field is an int boolean (0/1).';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The ADWYM field is an int boolean (0/1).';\n" +
" END IF;\n" +
" IF NEW.FPUYA NOT IN (0, 1)\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The FPUYA field is an int boolean (0/1).';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The FPUYA field is an int boolean (0/1).';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ UpdateSource(SET s3fqx.ADWYM:1!null = 0 (tinyint),SET s3fqx.FPUYA:2!null = 0 (tinyint))\n" +
" │ └─ Table\n" +
" │ ├─ name: S3FQX\n" +
" │ └─ columns: [id adwym fpuya]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(NOT\n" +
" │ └─ IN\n" +
" │ ├─ left: new.ADWYM:4!null\n" +
" │ └─ right: TUPLE(0 (tinyint), 1 (tinyint))\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The ADWYM field is an int boolean (0/1)., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(NOT\n" +
" └─ IN\n" +
" ├─ left: new.FPUYA:5!null\n" +
" └─ right: TUPLE(0 (tinyint), 1 (tinyint))\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The FPUYA field is an int boolean (0/1)., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
-- inserts
INSERT INTO THNTS
(id, NFRYN, IXUXU, FHCYT)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
(SELECT id FROM JMRQL WHERE DZLIM = 'T4IBQ') AS NFRYN,
id AS IXUXU,
NULL AS FHCYT
FROM
YK2GW
WHERE
id IN ('1','2','3')`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, NFRYN, IXUXU, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: THNTS\n" +
" │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" └─ Trigger(CREATE TRIGGER THNTS_on_insert BEFORE INSERT ON THNTS\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" NEW.IXUXU IS NULL\n" +
" THEN\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The IXUXU field is mandatory.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, NFRYN:1!null, IXUXU:2, FHCYT:3]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jmrql.id:34!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ jmrql.DZLIM:35!null\n" +
" │ │ │ └─ T4IBQ (longtext)\n" +
" │ │ └─ IndexedTableAccess(JMRQL)\n" +
" │ │ ├─ index: [JMRQL.DZLIM]\n" +
" │ │ ├─ static: [{[T4IBQ, T4IBQ]}]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as NFRYN, yk2gw.id:0!null as IXUXU, NULL (null) as FHCYT]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [yk2gw.id:0!null, yk2gw.FTQLQ:1!null, yk2gw.TUXML:2, yk2gw.PAEF5:3, yk2gw.RUCY4:4, yk2gw.TPNJ6:5!null, yk2gw.LBL53:6, yk2gw.NB3QS:7, yk2gw.EO7IV:8, yk2gw.MUHJF:9, yk2gw.FM34L:10, yk2gw.TY5RF:11, yk2gw.ZHTLH:12, yk2gw.NPB7W:13, yk2gw.SX3HH:14, yk2gw.ISBNF:15, yk2gw.YA7YB:16, yk2gw.C5YKB:17, yk2gw.QK7KT:18, yk2gw.FFGE6:19, yk2gw.FIIGJ:20, yk2gw.SH3NC:21, yk2gw.NTENA:22, yk2gw.M4AUB:23, yk2gw.X5AIR:24, yk2gw.SAB6M:25, yk2gw.G5QI5:26, yk2gw.ZVQVD:27, yk2gw.YKSSU:28, yk2gw.FHCYT:29, lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jmrql.id:30!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ jmrql.DZLIM:31!null\n" +
" │ │ │ └─ T4IBQ (longtext)\n" +
" │ │ └─ IndexedTableAccess(JMRQL)\n" +
" │ │ ├─ index: [JMRQL.DZLIM]\n" +
" │ │ ├─ static: [{[T4IBQ, T4IBQ]}]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as NFRYN, yk2gw.id:0!null as IXUXU, NULL (null) as FHCYT]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ yk2gw.id:0!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
" └─ BEGIN .. END\n" +
" └─ IF BLOCK\n" +
" └─ IF(new.IXUXU:2 IS NULL)\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The IXUXU field is mandatory., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO QYWQD
(id, WNUNU, HHVLX, HVHRZ, YKSSU, FHCYT)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
ITWML.DRIWM AS WNUNU,
ITWML.JIEVY AS HHVLX,
1.0 AS HVHRZ,
NULL AS YKSSU,
NULL AS FHCYT
FROM
(
SELECT
sn.id AS DRIWM,
SKPM6.id AS JIEVY,
sn.ECDKM AS HVHRZ
FROM
NOXN3 sn -- Potential upstream VUMUY
INNER JOIN
NOXN3 SKPM6 -- We can find a potential downstream edge
ON
SKPM6.BRQP2 = sn.FFTBJ
LEFT JOIN
QYWQD rn -- Join existing regnet records and keep where no corresponding is found
ON
rn.WNUNU = sn.id
AND
rn.HHVLX = SKPM6.id
WHERE
sn.NUMK2 = 1 -- Potential upstream edge is activity TAFAX
AND
rn.WNUNU IS NULL AND rn.HHVLX IS NULL -- Keep only where no corresponding is found
) ITWML`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, WNUNU, HHVLX, HVHRZ, YKSSU, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: QYWQD\n" +
" │ └─ columns: [id wnunu hhvlx hvhrz ykssu fhcyt]\n" +
" └─ Trigger(CREATE TRIGGER QYWQD_on_insert BEFORE INSERT ON QYWQD\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" (SELECT FFTBJ FROM NOXN3 WHERE id = NEW.WNUNU) <> (SELECT BRQP2 FROM NOXN3 WHERE id = NEW.HHVLX)\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The target UWBAI of the upstream edge must be the same as the source UWBAI of the downstream edge (the enzyme UWBAI).';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The target UWBAI of the upstream edge must be the same as the source UWBAI of the downstream edge (the enzyme UWBAI).';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, WNUNU:1!null, HHVLX:2!null, HVHRZ:3!null, YKSSU:4, FHCYT:5]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, itwml.DRIWM:0!null as WNUNU, itwml.JIEVY:1!null as HHVLX, 1 (decimal(2,1)) as HVHRZ, NULL (null) as YKSSU, NULL (null) as FHCYT]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: itwml\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id:0!null as DRIWM, skpm6.id:4!null as JIEVY, sn.ECDKM:2 as HVHRZ]\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ rn.WNUNU:6!null IS NULL\n" +
" │ │ └─ rn.HHVLX:7!null IS NULL\n" +
" │ └─ LeftOuterHashJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ rn.WNUNU:6!null\n" +
" │ │ │ └─ sn.id:0!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ rn.HHVLX:7!null\n" +
" │ │ └─ skpm6.id:4!null\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ sn.FFTBJ:1!null\n" +
" │ │ │ └─ skpm6.BRQP2:5!null\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ sn.NUMK2:3!null\n" +
" │ │ │ │ └─ 1 (tinyint)\n" +
" │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id fftbj ecdkm numk2]\n" +
" │ │ └─ TableAlias(skpm6)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id brqp2]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(sn.id:0!null, skpm6.id:4!null)\n" +
" │ ├─ right-key: TUPLE(rn.WNUNU:0!null, rn.HHVLX:1!null)\n" +
" │ └─ TableAlias(rn)\n" +
" │ └─ Table\n" +
" │ ├─ name: QYWQD\n" +
" │ └─ columns: [wnunu hhvlx]\n" +
" └─ BEGIN .. END\n" +
" └─ IF BLOCK\n" +
" └─ IF(NOT\n" +
" └─ Eq\n" +
" ├─ Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.FFTBJ:7!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ noxn3.id:6!null\n" +
" │ │ └─ new.WNUNU:1!null\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.id]\n" +
" │ └─ columns: [id fftbj]\n" +
" └─ Subquery\n" +
" ├─ cacheable: false\n" +
" └─ Project\n" +
" ├─ columns: [noxn3.BRQP2:7!null]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ noxn3.id:6!null\n" +
" │ └─ new.HHVLX:2!null\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" └─ columns: [id brqp2]\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The target UWBAI of the upstream edge must be the same as the source UWBAI of the downstream edge (the enzyme UWBAI)., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO WE72E
(id, QZ7E7, SSHPJ, FHCYT)
SELECT
id,
SFJ6L,
SSHPJ,
NULL AS FHCYT
FROM
TDRVG
WHERE
id IN ('1','2','3')`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, QZ7E7, SSHPJ, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: WE72E\n" +
" │ └─ columns: [id qz7e7 sshpj fhcyt]\n" +
" └─ Trigger(CREATE TRIGGER WE72E_on_insert BEFORE INSERT ON WE72E\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" NEW.QZ7E7 IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" OR\n" +
" NEW.SSHPJ IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" THEN\n" +
" -- SET @custom_error_message = (SELECT error_message FROM trigger_helper_error_message WHERE DZLIM = 'SVAZ4');\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'String field contains invalid value, like empty string, ''none'', ''null'', ''n/a'', ''nan'' etc.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, QZ7E7:1!null, SSHPJ:2!null, FHCYT:3]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tdrvg.id:0!null, tdrvg.SFJ6L:2!null, tdrvg.SSHPJ:1!null, NULL (null) as FHCYT]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ tdrvg.id:0!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ IndexedTableAccess(TDRVG)\n" +
" │ ├─ index: [TDRVG.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ └─ columns: [id sshpj sfj6l]\n" +
" └─ BEGIN .. END\n" +
" └─ IF BLOCK\n" +
" └─ IF(Or\n" +
" ├─ InSubquery\n" +
" │ ├─ left: new.QZ7E7:1!null\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ └─ columns: [svaz4]\n" +
" └─ InSubquery\n" +
" ├─ left: new.SSHPJ:2!null\n" +
" └─ right: Subquery\n" +
" ├─ cacheable: false\n" +
" └─ Table\n" +
" ├─ name: TPXHZ\n" +
" └─ columns: [svaz4]\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = String field contains invalid value, like empty string, 'none', 'null', 'n/a', 'nan' etc., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO AMYXQ
(id, GXLUB, LUEVY, XQDYT, AMYXQ, OZTQF, Z35GY, KKGN5)
SELECT /*+ JOIN_ORDER(ufc, nd, YBBG5) */
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
(SELECT /*+ JOIN_ORDER(cla, bs) */ bs.id FROM THNTS bs INNER JOIN YK2GW cla ON cla.id = bs.IXUXU WHERE cla.FTQLQ = ufc.T4IBQ) AS GXLUB,
nd.id AS LUEVY,
nd.XQDYT AS XQDYT,
ufc.AMYXQ + 0.0 AS AMYXQ,
CASE
WHEN
YBBG5.DZLIM = 'KTNZ2'
THEN ufc.KTNZ2 + 0.0
WHEN
YBBG5.DZLIM = 'HIID2'
THEN ufc.HIID2 + 0.0
WHEN
YBBG5.DZLIM = 'SH7TP'
THEN ufc.SH7TP + 0.0
WHEN
YBBG5.DZLIM = 'VVKNB'
THEN ufc.VVKNB + 0.0
WHEN
YBBG5.DZLIM = 'DN3OQ'
THEN ufc.DN3OQ + 0.0
ELSE NULL
END AS OZTQF,
ufc.SRZZO + 0.0 AS Z35GY,
ufc.id AS KKGN5
FROM
SISUT ufc
INNER JOIN
E2I7U nd
ON
nd.ZH72S = ufc.ZH72S
INNER JOIN
XGSJM YBBG5
ON
YBBG5.id = nd.XQDYT
WHERE
ufc.id IN ('1','2','3')`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, GXLUB, LUEVY, XQDYT, AMYXQ, OZTQF, Z35GY, KKGN5)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: AMYXQ\n" +
" │ └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
" └─ Trigger(CREATE TRIGGER AMYXQ_on_insert BEFORE INSERT ON AMYXQ\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" (SELECT FGG57 FROM E2I7U WHERE id = NEW.LUEVY) IS NULL\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The given UWBAI can not be connected to a AMYXQ record as it does not have IYDZV.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The given UWBAI can not be connected to a AMYXQ record as it does not have IYDZV.';\n" +
" END IF;\n" +
" IF\n" +
" NEW.AMYXQ < 0 OR NEW.OZTQF < 0 OR NEW.Z35GY < 0\n" +
" THEN\n" +
" -- SET @custom_error_message = 'All values in AMYXQ must ne non-negative.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'All values in AMYXQ must ne non-negative.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, GXLUB:1!null, LUEVY:2!null, XQDYT:3!null, AMYXQ:4!null, OZTQF:5!null, Z35GY:6!null, KKGN5:7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:41!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:40!null\n" +
" │ │ │ └─ ufc.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:39!null\n" +
" │ │ │ └─ bs.IXUXU:42\n" +
" │ │ ├─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ │ as GXLUB, nd.id:11!null as LUEVY, nd.XQDYT:20!null as XQDYT, (ufc.AMYXQ:3 + 0 (decimal(2,1))) as AMYXQ, CASE WHEN Eq\n" +
" │ │ ├─ ybbg5.DZLIM:29!null\n" +
" │ │ └─ KTNZ2 (longtext)\n" +
" │ │ THEN (ufc.KTNZ2:4 + 0 (decimal(2,1))) WHEN Eq\n" +
" │ │ ├─ ybbg5.DZLIM:29!null\n" +
" │ │ └─ HIID2 (longtext)\n" +
" │ │ THEN (ufc.HIID2:5 + 0 (decimal(2,1))) WHEN Eq\n" +
" │ │ ├─ ybbg5.DZLIM:29!null\n" +
" │ │ └─ SH7TP (longtext)\n" +
" │ │ THEN (ufc.SH7TP:8 + 0 (decimal(2,1))) WHEN Eq\n" +
" │ │ ├─ ybbg5.DZLIM:29!null\n" +
" │ │ └─ VVKNB (longtext)\n" +
" │ │ THEN (ufc.VVKNB:7 + 0 (decimal(2,1))) WHEN Eq\n" +
" │ │ ├─ ybbg5.DZLIM:29!null\n" +
" │ │ └─ DN3OQ (longtext)\n" +
" │ │ THEN (ufc.DN3OQ:6 + 0 (decimal(2,1))) ELSE NULL (null) END as OZTQF, (ufc.SRZZO:9 + 0 (decimal(2,1))) as Z35GY, ufc.id:0!null as KKGN5]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ufc.id:0!null, ufc.T4IBQ:1, ufc.ZH72S:2, ufc.AMYXQ:3, ufc.KTNZ2:4, ufc.HIID2:5, ufc.DN3OQ:6, ufc.VVKNB:7, ufc.SH7TP:8, ufc.SRZZO:9, ufc.QZ6VT:10, nd.id:11!null, nd.DKCAJ:12!null, nd.KNG7T:13, nd.TW55N:14!null, nd.QRQXW:15!null, nd.ECXAJ:16!null, nd.FGG57:17, nd.ZH72S:18, nd.FSK67:19!null, nd.XQDYT:20!null, nd.TCE7A:21, nd.IWV2H:22, nd.HPCMS:23!null, nd.N5CC2:24, nd.FHCYT:25, nd.ETAQ7:26, nd.A75X7:27, ybbg5.id:28!null, ybbg5.DZLIM:29!null, ybbg5.F3YUE:30, lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:33!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:32!null\n" +
" │ │ │ └─ ufc.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:31!null\n" +
" │ │ │ └─ bs.IXUXU:34\n" +
" │ │ ├─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ │ as GXLUB, nd.id:11!null as LUEVY, nd.XQDYT:20!null as XQDYT, (ufc.AMYXQ:3 + 0 (decimal(2,1))) as AMYXQ, CASE WHEN Eq\n" +
" │ │ ├─ ybbg5.DZLIM:29!null\n" +
" │ │ └─ KTNZ2 (longtext)\n" +
" │ │ THEN (ufc.KTNZ2:4 + 0 (decimal(2,1))) WHEN Eq\n" +
" │ │ ├─ ybbg5.DZLIM:29!null\n" +
" │ │ └─ HIID2 (longtext)\n" +
" │ │ THEN (ufc.HIID2:5 + 0 (decimal(2,1))) WHEN Eq\n" +
" │ │ ├─ ybbg5.DZLIM:29!null\n" +
" │ │ └─ SH7TP (longtext)\n" +
" │ │ THEN (ufc.SH7TP:8 + 0 (decimal(2,1))) WHEN Eq\n" +
" │ │ ├─ ybbg5.DZLIM:29!null\n" +
" │ │ └─ VVKNB (longtext)\n" +
" │ │ THEN (ufc.VVKNB:7 + 0 (decimal(2,1))) WHEN Eq\n" +
" │ │ ├─ ybbg5.DZLIM:29!null\n" +
" │ │ └─ DN3OQ (longtext)\n" +
" │ │ THEN (ufc.DN3OQ:6 + 0 (decimal(2,1))) ELSE NULL (null) END as OZTQF, (ufc.SRZZO:9 + 0 (decimal(2,1))) as Z35GY, ufc.id:0!null as KKGN5]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ nd.ZH72S:18\n" +
" │ │ └─ ufc.ZH72S:2\n" +
" │ ├─ Filter\n" +
" │ │ ├─ HashIn\n" +
" │ │ │ ├─ ufc.id:0!null\n" +
" │ │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ │ └─ TableAlias(ufc)\n" +
" │ │ └─ IndexedTableAccess(SISUT)\n" +
" │ │ ├─ index: [SISUT.id]\n" +
" │ │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ │ └─ columns: [id t4ibq zh72s amyxq ktnz2 hiid2 dn3oq vvknb sh7tp srzzo qz6vt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ufc.ZH72S:2)\n" +
" │ ├─ right-key: TUPLE(nd.ZH72S:7)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ nd.XQDYT:20!null\n" +
" │ │ └─ ybbg5.id:28!null\n" +
" │ ├─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.XQDYT]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ TableAlias(ybbg5)\n" +
" │ └─ IndexedTableAccess(XGSJM)\n" +
" │ ├─ index: [XGSJM.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id dzlim f3yue]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.FGG57:9]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ e2i7u.id:8!null\n" +
" │ │ └─ new.LUEVY:2!null\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ └─ columns: [id fgg57]\n" +
" │ IS NULL)\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The given UWBAI can not be connected to a AMYXQ record as it does not have IYDZV., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(Or\n" +
" ├─ Or\n" +
" │ ├─ LessThan\n" +
" │ │ ├─ new.AMYXQ:4!null\n" +
" │ │ └─ 0 (tinyint)\n" +
" │ └─ LessThan\n" +
" │ ├─ new.OZTQF:5!null\n" +
" │ └─ 0 (tinyint)\n" +
" └─ LessThan\n" +
" ├─ new.Z35GY:6!null\n" +
" └─ 0 (tinyint)\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = All values in AMYXQ must ne non-negative., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO SZQWJ
(id, GXLUB, CH3FR, D237E, JOGI6)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
(SELECT bs.id FROM THNTS bs INNER JOIN YK2GW cla ON cla.id = bs.IXUXU WHERE cla.FTQLQ = ums.T4IBQ) AS GXLUB,
(SELECT id FROM XOAOP WHERE DZLIM = 'NER') AS CH3FR,
CASE -- This ugly thing is because of Dolt's problematic conversion handling at insertions
WHEN ums.ner > 0.5 THEN 1
WHEN ums.ner < 0.5 THEN 0
ELSE NULL
END AS D237E,
ums.id AS JOGI6
FROM
FG26Y ums
WHERE
ums.id IN ('1','2','3')`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, GXLUB, CH3FR, D237E, JOGI6)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: SZQWJ\n" +
" │ └─ columns: [id gxlub ch3fr d237e jogi6]\n" +
" └─ Trigger(CREATE TRIGGER SZQWJ_on_insert BEFORE INSERT ON SZQWJ\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" (SELECT DZLIM FROM XOAOP WHERE id = NEW.CH3FR) NOT IN ('NER', 'BER', 'HR', 'MMR')\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The ECUWU must be one of the following: ''NER'', ''BER'', ''HR'', ''MMR''.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The ECUWU must be one of the following: ''NER'', ''BER'', ''HR'', ''MMR''.';\n" +
" END IF;\n" +
" IF\n" +
" NEW.D237E NOT IN (0, 1)\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The D237E field must be either 0 or 1.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The D237E field must be either 0 or 1.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, GXLUB:1!null, CH3FR:2!null, D237E:3!null, JOGI6:4]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:14!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:13!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:12!null\n" +
" │ │ │ └─ bs.IXUXU:15\n" +
" │ │ ├─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:12!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.DZLIM:13!null\n" +
" │ │ │ └─ NER (longtext)\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[NER, NER]}]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.ner:2\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.ner:2\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ums.id:0!null, ums.T4IBQ:1, ums.ner:2, ums.ber:3, ums.hr:4, ums.mmr:5, ums.QZ6VT:6, lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:9!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:8!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:7!null\n" +
" │ │ │ └─ bs.IXUXU:10\n" +
" │ │ ├─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:7!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.DZLIM:8!null\n" +
" │ │ │ └─ NER (longtext)\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[NER, NER]}]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.ner:2\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.ner:2\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ ums.id:0!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ TableAlias(ums)\n" +
" │ └─ IndexedTableAccess(FG26Y)\n" +
" │ ├─ index: [FG26Y.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ └─ columns: [id t4ibq ner ber hr mmr qz6vt]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(NOT\n" +
" │ └─ IN\n" +
" │ ├─ left: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.DZLIM:6!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.id:5!null\n" +
" │ │ │ └─ new.CH3FR:2!null\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.id]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ └─ right: TUPLE(NER (longtext), BER (longtext), HR (longtext), MMR (longtext))\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The ECUWU must be one of the following: 'NER', 'BER', 'HR', 'MMR'., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(NOT\n" +
" └─ IN\n" +
" ├─ left: new.D237E:3!null\n" +
" └─ right: TUPLE(0 (tinyint), 1 (tinyint))\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The D237E field must be either 0 or 1., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO SZQWJ
(id, GXLUB, CH3FR, D237E, JOGI6)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
(SELECT bs.id FROM THNTS bs INNER JOIN YK2GW cla ON cla.id = bs.IXUXU WHERE cla.FTQLQ = ums.T4IBQ) AS GXLUB,
(SELECT id FROM XOAOP WHERE DZLIM = 'BER') AS CH3FR,
CASE -- This ugly thing is because of Dolt's problematic conversion handling at insertions
WHEN ums.ber > 0.5 THEN 1
WHEN ums.ber < 0.5 THEN 0
ELSE NULL
END AS D237E,
ums.id AS JOGI6
FROM
FG26Y ums
WHERE
ums.id IN ('1','2','3')`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, GXLUB, CH3FR, D237E, JOGI6)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: SZQWJ\n" +
" │ └─ columns: [id gxlub ch3fr d237e jogi6]\n" +
" └─ Trigger(CREATE TRIGGER SZQWJ_on_insert BEFORE INSERT ON SZQWJ\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" (SELECT DZLIM FROM XOAOP WHERE id = NEW.CH3FR) NOT IN ('NER', 'BER', 'HR', 'MMR')\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The ECUWU must be one of the following: ''NER'', ''BER'', ''HR'', ''MMR''.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The ECUWU must be one of the following: ''NER'', ''BER'', ''HR'', ''MMR''.';\n" +
" END IF;\n" +
" IF\n" +
" NEW.D237E NOT IN (0, 1)\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The D237E field must be either 0 or 1.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The D237E field must be either 0 or 1.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, GXLUB:1!null, CH3FR:2!null, D237E:3!null, JOGI6:4]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:14!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:13!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:12!null\n" +
" │ │ │ └─ bs.IXUXU:15\n" +
" │ │ ├─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:12!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.DZLIM:13!null\n" +
" │ │ │ └─ BER (longtext)\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[BER, BER]}]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.ber:3\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.ber:3\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ums.id:0!null, ums.T4IBQ:1, ums.ner:2, ums.ber:3, ums.hr:4, ums.mmr:5, ums.QZ6VT:6, lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:9!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:8!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:7!null\n" +
" │ │ │ └─ bs.IXUXU:10\n" +
" │ │ ├─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:7!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.DZLIM:8!null\n" +
" │ │ │ └─ BER (longtext)\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[BER, BER]}]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.ber:3\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.ber:3\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ ums.id:0!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ TableAlias(ums)\n" +
" │ └─ IndexedTableAccess(FG26Y)\n" +
" │ ├─ index: [FG26Y.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ └─ columns: [id t4ibq ner ber hr mmr qz6vt]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(NOT\n" +
" │ └─ IN\n" +
" │ ├─ left: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.DZLIM:6!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.id:5!null\n" +
" │ │ │ └─ new.CH3FR:2!null\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.id]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ └─ right: TUPLE(NER (longtext), BER (longtext), HR (longtext), MMR (longtext))\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The ECUWU must be one of the following: 'NER', 'BER', 'HR', 'MMR'., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(NOT\n" +
" └─ IN\n" +
" ├─ left: new.D237E:3!null\n" +
" └─ right: TUPLE(0 (tinyint), 1 (tinyint))\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The D237E field must be either 0 or 1., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO SZQWJ
(id, GXLUB, CH3FR, D237E, JOGI6)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
(SELECT bs.id FROM THNTS bs INNER JOIN YK2GW cla ON cla.id = bs.IXUXU WHERE cla.FTQLQ = ums.T4IBQ) AS GXLUB,
(SELECT id FROM XOAOP WHERE DZLIM = 'HR') AS CH3FR,
CASE -- This ugly thing is because of Dolt's problematic conversion handling at insertions
WHEN ums.hr > 0.5 THEN 1
WHEN ums.hr < 0.5 THEN 0
ELSE NULL
END AS D237E,
ums.id AS JOGI6
FROM
FG26Y ums
WHERE
ums.id IN ('1','2','3')`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, GXLUB, CH3FR, D237E, JOGI6)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: SZQWJ\n" +
" │ └─ columns: [id gxlub ch3fr d237e jogi6]\n" +
" └─ Trigger(CREATE TRIGGER SZQWJ_on_insert BEFORE INSERT ON SZQWJ\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" (SELECT DZLIM FROM XOAOP WHERE id = NEW.CH3FR) NOT IN ('NER', 'BER', 'HR', 'MMR')\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The ECUWU must be one of the following: ''NER'', ''BER'', ''HR'', ''MMR''.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The ECUWU must be one of the following: ''NER'', ''BER'', ''HR'', ''MMR''.';\n" +
" END IF;\n" +
" IF\n" +
" NEW.D237E NOT IN (0, 1)\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The D237E field must be either 0 or 1.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The D237E field must be either 0 or 1.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, GXLUB:1!null, CH3FR:2!null, D237E:3!null, JOGI6:4]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:14!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:13!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:12!null\n" +
" │ │ │ └─ bs.IXUXU:15\n" +
" │ │ ├─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:12!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.DZLIM:13!null\n" +
" │ │ │ └─ HR (longtext)\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[HR, HR]}]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.hr:4\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.hr:4\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ums.id:0!null, ums.T4IBQ:1, ums.ner:2, ums.ber:3, ums.hr:4, ums.mmr:5, ums.QZ6VT:6, lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:9!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:8!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:7!null\n" +
" │ │ │ └─ bs.IXUXU:10\n" +
" │ │ ├─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:7!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.DZLIM:8!null\n" +
" │ │ │ └─ HR (longtext)\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[HR, HR]}]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.hr:4\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.hr:4\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ ums.id:0!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ TableAlias(ums)\n" +
" │ └─ IndexedTableAccess(FG26Y)\n" +
" │ ├─ index: [FG26Y.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ └─ columns: [id t4ibq ner ber hr mmr qz6vt]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(NOT\n" +
" │ └─ IN\n" +
" │ ├─ left: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.DZLIM:6!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.id:5!null\n" +
" │ │ │ └─ new.CH3FR:2!null\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.id]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ └─ right: TUPLE(NER (longtext), BER (longtext), HR (longtext), MMR (longtext))\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The ECUWU must be one of the following: 'NER', 'BER', 'HR', 'MMR'., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(NOT\n" +
" └─ IN\n" +
" ├─ left: new.D237E:3!null\n" +
" └─ right: TUPLE(0 (tinyint), 1 (tinyint))\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The D237E field must be either 0 or 1., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO SZQWJ
(id, GXLUB, CH3FR, D237E, JOGI6)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
(SELECT bs.id FROM THNTS bs INNER JOIN YK2GW cla ON cla.id = bs.IXUXU WHERE cla.FTQLQ = ums.T4IBQ) AS GXLUB,
(SELECT id FROM XOAOP WHERE DZLIM = 'MMR') AS CH3FR,
CASE -- This ugly thing is because of Dolt's problematic conversion handling at insertions
WHEN ums.mmr > 0.5 THEN 1
WHEN ums.mmr < 0.5 THEN 0
ELSE NULL
END AS D237E,
ums.id AS JOGI6
FROM
FG26Y ums
WHERE
ums.id IN ('1','2','3')`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, GXLUB, CH3FR, D237E, JOGI6)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: SZQWJ\n" +
" │ └─ columns: [id gxlub ch3fr d237e jogi6]\n" +
" └─ Trigger(CREATE TRIGGER SZQWJ_on_insert BEFORE INSERT ON SZQWJ\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" (SELECT DZLIM FROM XOAOP WHERE id = NEW.CH3FR) NOT IN ('NER', 'BER', 'HR', 'MMR')\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The ECUWU must be one of the following: ''NER'', ''BER'', ''HR'', ''MMR''.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The ECUWU must be one of the following: ''NER'', ''BER'', ''HR'', ''MMR''.';\n" +
" END IF;\n" +
" IF\n" +
" NEW.D237E NOT IN (0, 1)\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The D237E field must be either 0 or 1.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The D237E field must be either 0 or 1.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, GXLUB:1!null, CH3FR:2!null, D237E:3!null, JOGI6:4]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:14!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:13!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:12!null\n" +
" │ │ │ └─ bs.IXUXU:15\n" +
" │ │ ├─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:12!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.DZLIM:13!null\n" +
" │ │ │ └─ MMR (longtext)\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[MMR, MMR]}]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.mmr:5\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.mmr:5\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ums.id:0!null, ums.T4IBQ:1, ums.ner:2, ums.ber:3, ums.hr:4, ums.mmr:5, ums.QZ6VT:6, lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:9!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:8!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ cla.id:7!null\n" +
" │ │ │ └─ bs.IXUXU:10\n" +
" │ │ ├─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:7!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.DZLIM:8!null\n" +
" │ │ │ └─ MMR (longtext)\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[MMR, MMR]}]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.mmr:5\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.mmr:5\n" +
" │ │ └─ 0.500000 (double)\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ ums.id:0!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ TableAlias(ums)\n" +
" │ └─ IndexedTableAccess(FG26Y)\n" +
" │ ├─ index: [FG26Y.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ └─ columns: [id t4ibq ner ber hr mmr qz6vt]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(NOT\n" +
" │ └─ IN\n" +
" │ ├─ left: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.DZLIM:6!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ xoaop.id:5!null\n" +
" │ │ │ └─ new.CH3FR:2!null\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.id]\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ └─ right: TUPLE(NER (longtext), BER (longtext), HR (longtext), MMR (longtext))\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The ECUWU must be one of the following: 'NER', 'BER', 'HR', 'MMR'., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(NOT\n" +
" └─ IN\n" +
" ├─ left: new.D237E:3!null\n" +
" └─ right: TUPLE(0 (tinyint), 1 (tinyint))\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The D237E field must be either 0 or 1., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO TPXBU
(id, BTXC5, FHCYT)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
NCVD2.BTXC5 AS BTXC5,
NULL AS FHCYT
FROM
(
SELECT DISTINCT
umf.SYPKF AS BTXC5
FROM
NZKPM umf
WHERE
umf.SYPKF NOT IN (SELECT BTXC5 FROM TPXBU WHERE BTXC5 IS NOT NULL)
AND
umf.SYPKF IS NOT NULL
AND
umf.SYPKF <> 'N/A'
AND
umf.id IN ('1','2','3')
) NCVD2`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, BTXC5, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXBU\n" +
" │ └─ columns: [id btxc5 fhcyt]\n" +
" └─ Trigger(CREATE TRIGGER TPXBU_on_insert BEFORE INSERT ON TPXBU\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" NEW.BTXC5 IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" THEN\n" +
" -- SET @custom_error_message = (SELECT error_message FROM trigger_helper_error_message WHERE DZLIM = 'SVAZ4');\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'String field contains invalid value, like empty string, ''none'', ''null'', ''n/a'', ''nan'' etc.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, BTXC5:1, FHCYT:2]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, ncvd2.BTXC5:0 as BTXC5, NULL (null) as FHCYT]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ncvd2\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [umf.SYPKF:8 as BTXC5]\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ │ ├─ left: umf.SYPKF:8\n" +
" │ │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ tpxbu.BTXC5:25 IS NULL\n" +
" │ │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ │ ├─ static: [{(NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [btxc5]\n" +
" │ │ │ │ └─ NOT\n" +
" │ │ │ │ └─ umf.SYPKF:8 IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ umf.SYPKF:8\n" +
" │ │ │ └─ N/A (longtext)\n" +
" │ │ └─ HashIn\n" +
" │ │ ├─ umf.id:0!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ TableAlias(umf)\n" +
" │ └─ IndexedTableAccess(NZKPM)\n" +
" │ ├─ index: [NZKPM.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ └─ columns: [id t4ibq fgg57 sshpj nla6o sfj6l tjpt7 arn5p sypkf ivfmk ide43 az6sp fsdy2 xosd4 hmw4h s76om vaf zroh6 qcgts lnfm6 tvawl hdlcl bhhw6 fhcyt qz6vt]\n" +
" └─ BEGIN .. END\n" +
" └─ IF BLOCK\n" +
" └─ IF(InSubquery\n" +
" ├─ left: new.BTXC5:1\n" +
" └─ right: Subquery\n" +
" ├─ cacheable: false\n" +
" └─ Table\n" +
" ├─ name: TPXHZ\n" +
" └─ columns: [svaz4]\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = String field contains invalid value, like empty string, 'none', 'null', 'n/a', 'nan' etc., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO HGMQ6
(id, GXLUB, LUEVY, M22QN, TJPT7, ARN5P, XOSD4, IDE43, HMW4H, ZBT6R, FSDY2, LT7K6, SPPYD, QCGTS, TEUJA, QQV4M, FHCYT)
SELECT
umf.id AS id,
bs.id AS GXLUB,
CASE
WHEN TJ5D2.id IS NOT NULL THEN (SELECT nd_for_id_overridden.id FROM E2I7U nd_for_id_overridden WHERE nd_for_id_overridden.TW55N = TJ5D2.H4DMT)
ELSE (SELECT nd_for_id.id FROM E2I7U nd_for_id WHERE nd_for_id.FGG57 IS NOT NULL AND nd_for_id.FGG57 = umf.FGG57)
END AS LUEVY,
CASE
WHEN umf.SYPKF = 'N/A' THEN (SELECT id FROM TPXBU WHERE BTXC5 IS NULL)
ELSE (SELECT aac.id FROM TPXBU aac WHERE aac.BTXC5 = umf.SYPKF)
END AS M22QN,
umf.TJPT7 AS TJPT7,
umf.ARN5P AS ARN5P,
umf.XOSD4 AS XOSD4,
umf.IDE43 AS IDE43,
CASE
WHEN umf.HMW4H <> 'N/A' THEN umf.HMW4H
ELSE NULL
END AS HMW4H,
CASE
WHEN umf.S76OM <> 'N/A' THEN (umf.S76OM + 0)
ELSE NULL
END AS ZBT6R,
CASE
WHEN umf.FSDY2 <> 'N/A' THEN umf.FSDY2
ELSE 'VUS'
END AS FSDY2,
CASE
WHEN umf.vaf <> '' THEN (umf.vaf + 0.0)
ELSE NULL
END AS LT7K6,
CASE
WHEN umf.ZROH6 <> '' THEN (umf.ZROH6 + 0.0)
ELSE NULL
END AS SPPYD,
CASE
WHEN umf.QCGTS <> '' THEN (umf.QCGTS + 0.0)
ELSE NULL
END AS QCGTS,
umf.id AS TEUJA,
TJ5D2.id AS QQV4M,
umf.FHCYT AS FHCYT
FROM
(SELECT
*
FROM
NZKPM
WHERE
id IN ('1','2','3')
AND ARN5P <> 'N/A'
AND T4IBQ IN (SELECT FTQLQ FROM YK2GW)
AND FGG57 IN (SELECT FGG57 FROM E2I7U WHERE FGG57 IS NOT NULL)
) umf
LEFT JOIN
SZW6V TJ5D2
ON
TJ5D2.SWCQV = 0 -- Override is turned on
AND
TJ5D2.T4IBQ = umf.T4IBQ
AND
TJ5D2.V7UFH = umf.FGG57
AND
TJ5D2.SYPKF = umf.SYPKF
INNER JOIN YK2GW cla ON umf.T4IBQ = cla.FTQLQ
INNER JOIN THNTS bs ON cla.id = bs.IXUXU`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, GXLUB, LUEVY, M22QN, TJPT7, ARN5P, XOSD4, IDE43, HMW4H, ZBT6R, FSDY2, LT7K6, SPPYD, QCGTS, TEUJA, QQV4M, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: HGMQ6\n" +
" │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" └─ Trigger(CREATE TRIGGER HGMQ6_on_insert BEFORE INSERT ON HGMQ6\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" NEW.TJPT7 IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" OR\n" +
" NEW.ARN5P IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" OR\n" +
" NEW.XOSD4 IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" OR\n" +
" NEW.IDE43 IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" OR\n" +
" NEW.HMW4H IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" THEN\n" +
" -- SET @custom_error_message = (SELECT error_message FROM trigger_helper_error_message WHERE DZLIM = 'SVAZ4');\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'String field contains invalid value, like empty string, ''none'', ''null'', ''n/a'', ''nan'' etc.';\n" +
" END IF;\n" +
" IF\n" +
" NEW.FSDY2 NOT IN ('benign', 'VUS', 'SRARY', 'UBQWG')\n" +
" THEN\n" +
" -- SET @custom_error_message = 'FSDY2 must be either ''benign'', ''VUS'', ''SRARY'' or ''UBQWG''.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'FSDY2 must be either ''benign'', ''VUS'', ''SRARY'' or ''UBQWG''.';\n" +
" END IF;\n" +
" IF NEW.LT7K6 IS NOT NULL AND NEW.SPPYD IS NOT NULL\n" +
" THEN\n" +
" -- SET @custom_error_message = 'If LT7K6 has value, SPPYD must be NULL.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'If LT7K6 has value, SPPYD must be NULL.';\n" +
" END IF;\n" +
" IF NEW.LT7K6 IS NULL AND (NEW.SPPYD IS NULL OR NEW.SPPYD <> 0.5)\n" +
" THEN\n" +
" -- SET @custom_error_message = 'If LT7K6 does not have value, SPPYD must be 0.5.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'If LT7K6 does not have value, SPPYD must be 0.5.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, GXLUB:1!null, LUEVY:2!null, M22QN:3!null, TJPT7:4!null, ARN5P:5!null, XOSD4:6!null, IDE43:7, HMW4H:8, ZBT6R:9, FSDY2:10!null, LT7K6:11, SPPYD:12, QCGTS:13, TEUJA:14, QQV4M:15, FHCYT:16]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [umf.id:0!null as id, bs.id:63!null as GXLUB, CASE WHEN NOT\n" +
" │ │ └─ tj5d2.id:25!null IS NULL\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nd_for_id_overridden.id:84!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ nd_for_id_overridden.TW55N:85!null\n" +
" │ │ │ └─ tj5d2.H4DMT:29!null\n" +
" │ │ └─ TableAlias(nd_for_id_overridden)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ │ ELSE Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nd_for_id.id:84!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ nd_for_id.FGG57:85 IS NULL\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ nd_for_id.FGG57:85\n" +
" │ │ │ └─ umf.FGG57:2\n" +
" │ │ └─ TableAlias(nd_for_id)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.FGG57]\n" +
" │ │ ├─ static: [{(NULL, ∞)}]\n" +
" │ │ └─ columns: [id fgg57]\n" +
" │ │ END as LUEVY, CASE WHEN Eq\n" +
" │ │ ├─ umf.SYPKF:8\n" +
" │ │ └─ N/A (longtext)\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tpxbu.id:84!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ tpxbu.BTXC5:85 IS NULL\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ ├─ static: [{[NULL, NULL]}]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ ELSE Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.id:84!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.BTXC5:85\n" +
" │ │ │ └─ umf.SYPKF:8\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ END as M22QN, umf.TJPT7:6 as TJPT7, umf.ARN5P:7 as ARN5P, umf.XOSD4:13 as XOSD4, umf.IDE43:10 as IDE43, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.HMW4H:14\n" +
" │ │ └─ N/A (longtext)\n" +
" │ │ THEN umf.HMW4H:14 ELSE NULL (null) END as HMW4H, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.S76OM:15\n" +
" │ │ └─ N/A (longtext)\n" +
" │ │ THEN (umf.S76OM:15 + 0 (tinyint)) ELSE NULL (null) END as ZBT6R, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.FSDY2:12\n" +
" │ │ └─ N/A (longtext)\n" +
" │ │ THEN umf.FSDY2:12 ELSE VUS (longtext) END as FSDY2, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.vaf:16\n" +
" │ │ └─ (longtext)\n" +
" │ │ THEN (umf.vaf:16 + 0 (decimal(2,1))) ELSE NULL (null) END as LT7K6, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.ZROH6:17\n" +
" │ │ └─ (longtext)\n" +
" │ │ THEN (umf.ZROH6:17 + 0 (decimal(2,1))) ELSE NULL (null) END as SPPYD, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.QCGTS:18\n" +
" │ │ └─ (longtext)\n" +
" │ │ THEN (umf.QCGTS:18 + 0 (decimal(2,1))) ELSE NULL (null) END as QCGTS, umf.id:0!null as TEUJA, tj5d2.id:25!null as QQV4M, umf.FHCYT:23 as FHCYT]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [umf.id:4!null, umf.t4ibq:5, umf.fgg57:6, umf.sshpj:7, umf.nla6o:8, umf.sfj6l:9, umf.tjpt7:10, umf.arn5p:11, umf.sypkf:12, umf.ivfmk:13, umf.ide43:14, umf.az6sp:15, umf.fsdy2:16, umf.xosd4:17, umf.hmw4h:18, umf.s76om:19, umf.vaf:20, umf.zroh6:21, umf.qcgts:22, umf.lnfm6:23, umf.tvawl:24, umf.hdlcl:25, umf.bhhw6:26, umf.fhcyt:27, umf.qz6vt:28, tj5d2.id:59!null, tj5d2.T4IBQ:60!null, tj5d2.V7UFH:61!null, tj5d2.SYPKF:62!null, tj5d2.H4DMT:63!null, tj5d2.SWCQV:64!null, tj5d2.YKSSU:65, tj5d2.FHCYT:66, cla.id:29!null, cla.FTQLQ:30!null, cla.TUXML:31, cla.PAEF5:32, cla.RUCY4:33, cla.TPNJ6:34!null, cla.LBL53:35, cla.NB3QS:36, cla.EO7IV:37, cla.MUHJF:38, cla.FM34L:39, cla.TY5RF:40, cla.ZHTLH:41, cla.NPB7W:42, cla.SX3HH:43, cla.ISBNF:44, cla.YA7YB:45, cla.C5YKB:46, cla.QK7KT:47, cla.FFGE6:48, cla.FIIGJ:49, cla.SH3NC:50, cla.NTENA:51, cla.M4AUB:52, cla.X5AIR:53, cla.SAB6M:54, cla.G5QI5:55, cla.ZVQVD:56, cla.YKSSU:57, cla.FHCYT:58, bs.id:0!null, bs.NFRYN:1!null, bs.IXUXU:2, bs.FHCYT:3, umf.id:4!null as id, bs.id:0!null as GXLUB, CASE WHEN NOT\n" +
" │ │ └─ tj5d2.id:59!null IS NULL\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nd_for_id_overridden.id:67!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ nd_for_id_overridden.TW55N:68!null\n" +
" │ │ │ └─ tj5d2.H4DMT:63!null\n" +
" │ │ └─ TableAlias(nd_for_id_overridden)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ │ ELSE Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nd_for_id.id:67!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ nd_for_id.FGG57:68 IS NULL\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ nd_for_id.FGG57:68\n" +
" │ │ │ └─ umf.FGG57:6\n" +
" │ │ └─ TableAlias(nd_for_id)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.FGG57]\n" +
" │ │ ├─ static: [{(NULL, ∞)}]\n" +
" │ │ └─ columns: [id fgg57]\n" +
" │ │ END as LUEVY, CASE WHEN Eq\n" +
" │ │ ├─ umf.SYPKF:12\n" +
" │ │ └─ N/A (longtext)\n" +
" │ │ THEN Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tpxbu.id:67!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ tpxbu.BTXC5:68 IS NULL\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ ├─ static: [{[NULL, NULL]}]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ ELSE Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.id:67!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.BTXC5:68\n" +
" │ │ │ └─ umf.SYPKF:12\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ END as M22QN, umf.TJPT7:10 as TJPT7, umf.ARN5P:11 as ARN5P, umf.XOSD4:17 as XOSD4, umf.IDE43:14 as IDE43, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.HMW4H:18\n" +
" │ │ └─ N/A (longtext)\n" +
" │ │ THEN umf.HMW4H:18 ELSE NULL (null) END as HMW4H, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.S76OM:19\n" +
" │ │ └─ N/A (longtext)\n" +
" │ │ THEN (umf.S76OM:19 + 0 (tinyint)) ELSE NULL (null) END as ZBT6R, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.FSDY2:16\n" +
" │ │ └─ N/A (longtext)\n" +
" │ │ THEN umf.FSDY2:16 ELSE VUS (longtext) END as FSDY2, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.vaf:20\n" +
" │ │ └─ (longtext)\n" +
" │ │ THEN (umf.vaf:20 + 0 (decimal(2,1))) ELSE NULL (null) END as LT7K6, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.ZROH6:21\n" +
" │ │ └─ (longtext)\n" +
" │ │ THEN (umf.ZROH6:21 + 0 (decimal(2,1))) ELSE NULL (null) END as SPPYD, CASE WHEN NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.QCGTS:22\n" +
" │ │ └─ (longtext)\n" +
" │ │ THEN (umf.QCGTS:22 + 0 (decimal(2,1))) ELSE NULL (null) END as QCGTS, umf.id:4!null as TEUJA, tj5d2.id:59!null as QQV4M, umf.FHCYT:27 as FHCYT]\n" +
" │ └─ LeftOuterJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ tj5d2.SWCQV:64!null\n" +
" │ │ │ │ │ └─ 0 (tinyint)\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ tj5d2.T4IBQ:60!null\n" +
" │ │ │ │ └─ umf.T4IBQ:5\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ tj5d2.V7UFH:61!null\n" +
" │ │ │ └─ umf.FGG57:6\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ tj5d2.SYPKF:62!null\n" +
" │ │ └─ umf.SYPKF:12\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.id:29!null\n" +
" │ │ │ └─ bs.IXUXU:2\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(bs.IXUXU:2)\n" +
" │ │ ├─ right-key: TUPLE(cla.id:25!null)\n" +
" │ │ └─ LookupJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ umf.T4IBQ:5\n" +
" │ │ │ └─ cla.FTQLQ:30!null\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: umf\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ │ │ ├─ nzkpm.id:0!null\n" +
" │ │ │ │ │ │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ nzkpm.ARN5P:7\n" +
" │ │ │ │ │ │ └─ N/A (longtext)\n" +
" │ │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ │ ├─ left: nzkpm.T4IBQ:1\n" +
" │ │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: YK2GW\n" +
" │ │ │ │ │ └─ columns: [ftqlq]\n" +
" │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ ├─ left: nzkpm.FGG57:2\n" +
" │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ e2i7u.FGG57:25 IS NULL\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.FGG57]\n" +
" │ │ │ │ ├─ static: [{(NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [fgg57]\n" +
" │ │ │ └─ IndexedTableAccess(NZKPM)\n" +
" │ │ │ ├─ index: [NZKPM.id]\n" +
" │ │ │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ │ │ └─ columns: [id t4ibq fgg57 sshpj nla6o sfj6l tjpt7 arn5p sypkf ivfmk ide43 az6sp fsdy2 xosd4 hmw4h s76om vaf zroh6 qcgts lnfm6 tvawl hdlcl bhhw6 fhcyt qz6vt]\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.FTQLQ]\n" +
" │ │ └─ columns: [id ftqlq tuxml paef5 rucy4 tpnj6 lbl53 nb3qs eo7iv muhjf fm34l ty5rf zhtlh npb7w sx3hh isbnf ya7yb c5ykb qk7kt ffge6 fiigj sh3nc ntena m4aub x5air sab6m g5qi5 zvqvd ykssu fhcyt]\n" +
" │ └─ TableAlias(tj5d2)\n" +
" │ └─ Table\n" +
" │ ├─ name: SZW6V\n" +
" │ └─ columns: [id t4ibq v7ufh sypkf h4dmt swcqv ykssu fhcyt]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(Or\n" +
" │ ├─ Or\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ Or\n" +
" │ │ │ │ ├─ InSubquery\n" +
" │ │ │ │ │ ├─ left: new.TJPT7:4!null\n" +
" │ │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: TPXHZ\n" +
" │ │ │ │ │ └─ columns: [svaz4]\n" +
" │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ ├─ left: new.ARN5P:5!null\n" +
" │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: TPXHZ\n" +
" │ │ │ │ └─ columns: [svaz4]\n" +
" │ │ │ └─ InSubquery\n" +
" │ │ │ ├─ left: new.XOSD4:6!null\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: TPXHZ\n" +
" │ │ │ └─ columns: [svaz4]\n" +
" │ │ └─ InSubquery\n" +
" │ │ ├─ left: new.IDE43:7\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXHZ\n" +
" │ │ └─ columns: [svaz4]\n" +
" │ └─ InSubquery\n" +
" │ ├─ left: new.HMW4H:8\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ └─ columns: [svaz4]\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = String field contains invalid value, like empty string, 'none', 'null', 'n/a', 'nan' etc., MYSQL_ERRNO = 1644\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(NOT\n" +
" │ └─ IN\n" +
" │ ├─ left: new.FSDY2:10!null\n" +
" │ └─ right: TUPLE(benign (longtext), VUS (longtext), SRARY (longtext), UBQWG (longtext))\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = FSDY2 must be either 'benign', 'VUS', 'SRARY' or 'UBQWG'., MYSQL_ERRNO = 1644\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(AND\n" +
" │ ├─ NOT\n" +
" │ │ └─ new.LT7K6:11 IS NULL\n" +
" │ └─ NOT\n" +
" │ └─ new.SPPYD:12 IS NULL\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = If LT7K6 has value, SPPYD must be NULL., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(AND\n" +
" ├─ new.LT7K6:11 IS NULL\n" +
" └─ Or\n" +
" ├─ new.SPPYD:12 IS NULL\n" +
" └─ NOT\n" +
" └─ Eq\n" +
" ├─ new.SPPYD:12\n" +
" └─ 0.500000 (double)\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = If LT7K6 does not have value, SPPYD must be 0.5., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO SEQS3
(id, Z7CP5, YH4XB)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
C6PUD.id AS Z7CP5,
vc.id AS YH4XB
FROM (
SELECT
mf.id AS id,
umf.AZ6SP AS AZ6SP
FROM
HGMQ6 mf
INNER JOIN NZKPM umf ON umf.id = mf.TEUJA
WHERE
umf.id IN ('1','2','3')
) C6PUD
INNER JOIN D34QP vc ON C6PUD.AZ6SP LIKE CONCAT(CONCAT('%', vc.TWMSR), '%')`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Insert(id, Z7CP5, YH4XB)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: SEQS3\n" +
" │ └─ columns: [id z7cp5 yh4xb]\n" +
" └─ Project\n" +
" ├─ columns: [id:0!null, Z7CP5:1!null, YH4XB:2!null]\n" +
" └─ Project\n" +
" ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, c6pud.id:0!null as Z7CP5, vc.id:2!null as YH4XB]\n" +
" └─ InnerJoin\n" +
" ├─ c6pud.AZ6SP LIKE concat(concat('%',vc.TWMSR),'%')\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: c6pud\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [mf.id:0!null as id, umf.AZ6SP:3 as AZ6SP]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ umf.id:2!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ umf.id:2!null\n" +
" │ │ └─ mf.TEUJA:1\n" +
" │ ├─ TableAlias(mf)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HGMQ6\n" +
" │ │ └─ columns: [id teuja]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ umf.id:0!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ TableAlias(umf)\n" +
" │ └─ IndexedTableAccess(NZKPM)\n" +
" │ ├─ index: [NZKPM.id]\n" +
" │ └─ columns: [id az6sp]\n" +
" └─ TableAlias(vc)\n" +
" └─ Table\n" +
" ├─ name: D34QP\n" +
" └─ columns: [id twmsr]\n" +
"",
},
{
Query: `
INSERT INTO HDDVB(id, FV24E, UJ6XY, M22QN, NZ4MQ, ETPQV, PRUV2, YKSSU, FHCYT)
-- The ones without overrides - mutfunc check is necessary
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
BPNW2.FV24E AS FV24E,
BPNW2.UJ6XY AS UJ6XY,
BPNW2.M22QN AS M22QN,
BPNW2.NZ4MQ AS NZ4MQ,
BPNW2.MU3KG AS ETPQV,
NULL AS PRUV2,
BPNW2.YKSSU AS YKSSU,
BPNW2.FHCYT AS FHCYT
FROM
(
SELECT DISTINCT
TIZHK.id AS MU3KG,
J4JYP.id AS FV24E,
RHUZN.id AS UJ6XY,
aac.id AS M22QN,
(SELECT G3YXS.id FROM YYBCX G3YXS WHERE CONCAT(G3YXS.ESFVY, '(MI:', G3YXS.SL76B, ')') = TIZHK.IDUT2) AS NZ4MQ,
NULL AS FHCYT,
NULL AS YKSSU
FROM
WRZVO TIZHK
LEFT JOIN
WGSDC NHMXW
ON
NHMXW.SWCQV = 0 -- Override is turned on
AND
NHMXW.NOHHR = TIZHK.TVNW2
AND
NHMXW.AVPYF = TIZHK.ZHITY
AND
NHMXW.SYPKF = TIZHK.SYPKF
AND
NHMXW.IDUT2 = TIZHK.IDUT2
INNER JOIN
E2I7U J4JYP ON J4JYP.ZH72S = TIZHK.TVNW2
INNER JOIN
E2I7U RHUZN ON RHUZN.ZH72S = TIZHK.ZHITY
INNER JOIN
HGMQ6 mf ON mf.LUEVY = J4JYP.id
INNER JOIN
TPXBU aac ON aac.id = mf.M22QN
WHERE
TIZHK.id IN ('1','2','3')
AND
aac.BTXC5 = TIZHK.SYPKF
AND
NHMXW.id IS NULL -- No overrides here
) BPNW2
UNION
-- The ones with overrides - no mutfunc check is necessary
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
BPNW2.FV24E AS FV24E,
BPNW2.UJ6XY AS UJ6XY,
(SELECT aac.id FROM TPXBU aac WHERE aac.BTXC5 = BPNW2.SYPKF) AS M22QN,
BPNW2.NZ4MQ AS NZ4MQ,
BPNW2.MU3KG AS ETPQV,
BPNW2.I4NDZ AS PRUV2,
BPNW2.YKSSU AS YKSSU,
BPNW2.FHCYT AS FHCYT
FROM
(
SELECT DISTINCT
TIZHK.id AS MU3KG,
CASE
WHEN NHMXW.FZXV5 IS NOT NULL
THEN (SELECT overridden_nd_mutant.id FROM E2I7U overridden_nd_mutant WHERE overridden_nd_mutant.TW55N = NHMXW.FZXV5)
ELSE J4JYP.id
END AS FV24E,
CASE
WHEN NHMXW.DQYGV IS NOT NULL
THEN (SELECT overridden_QI2IEner.id FROM E2I7U overridden_QI2IEner WHERE overridden_QI2IEner.TW55N = NHMXW.DQYGV)
ELSE RHUZN.id
END AS UJ6XY,
TIZHK.SYPKF AS SYPKF,
(SELECT G3YXS.id FROM YYBCX G3YXS WHERE CONCAT(G3YXS.ESFVY, '(MI:', G3YXS.SL76B, ')') = TIZHK.IDUT2) AS NZ4MQ,
NULL AS FHCYT,
NULL AS YKSSU,
NHMXW.id AS I4NDZ
FROM
WRZVO TIZHK
LEFT JOIN
WGSDC NHMXW
ON
NHMXW.SWCQV = 0 -- Override is turned on
AND
NHMXW.NOHHR = TIZHK.TVNW2
AND
NHMXW.AVPYF = TIZHK.ZHITY
AND
NHMXW.SYPKF = TIZHK.SYPKF
AND
NHMXW.IDUT2 = TIZHK.IDUT2
LEFT JOIN
E2I7U J4JYP ON J4JYP.ZH72S = TIZHK.TVNW2
LEFT JOIN
E2I7U RHUZN ON RHUZN.ZH72S = TIZHK.ZHITY
WHERE
TIZHK.id IN ('1','2','3')
AND
NHMXW.id IS NOT NULL -- Only overrides here
) BPNW2`,
ExpectedPlan: "RowUpdateAccumulator\n" +
" └─ Insert(id, FV24E, UJ6XY, M22QN, NZ4MQ, ETPQV, PRUV2, YKSSU, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: HDDVB\n" +
" │ └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
" └─ Project\n" +
" ├─ columns: [id:0!null, FV24E:1!null, UJ6XY:2!null, M22QN:3!null, NZ4MQ:4!null, ETPQV:5, PRUV2:6, YKSSU:7, FHCYT:8]\n" +
" └─ Union distinct\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, convert\n" +
" │ │ ├─ type: char\n" +
" │ │ └─ FV24E:1!null\n" +
" │ │ as FV24E, convert\n" +
" │ │ ├─ type: char\n" +
" │ │ └─ UJ6XY:2!null\n" +
" │ │ as UJ6XY, M22QN:3!null, NZ4MQ:4, ETPQV:5!null, convert\n" +
" │ │ ├─ type: char\n" +
" │ │ └─ PRUV2:6\n" +
" │ │ as PRUV2, YKSSU:7, FHCYT:8]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, bpnw2.FV24E:1!null as FV24E, bpnw2.UJ6XY:2!null as UJ6XY, bpnw2.M22QN:3!null as M22QN, bpnw2.NZ4MQ:4 as NZ4MQ, bpnw2.MU3KG:0!null as ETPQV, NULL (null) as PRUV2, bpnw2.YKSSU:6 as YKSSU, bpnw2.FHCYT:5 as FHCYT]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: bpnw2\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tizhk.id:0!null as MU3KG, j4jyp.id:20!null as FV24E, rhuzn.id:37!null as UJ6XY, aac.id:71!null as M22QN, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [g3yxs.id:81!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ concat(g3yxs.ESFVY:82!null,(MI: (longtext),g3yxs.SL76B:83!null,) (longtext))\n" +
" │ │ │ └─ tizhk.IDUT2:4\n" +
" │ │ └─ TableAlias(g3yxs)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YYBCX\n" +
" │ │ └─ columns: [id esfvy sl76b]\n" +
" │ │ as NZ4MQ, NULL (null) as FHCYT, NULL (null) as YKSSU]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tizhk.id:0!null, tizhk.TVNW2:1, tizhk.ZHITY:2, tizhk.SYPKF:3, tizhk.IDUT2:4, tizhk.O6QJ3:5, tizhk.NO2JA:6, tizhk.YKSSU:7, tizhk.FHCYT:8, tizhk.QZ6VT:9, nhmxw.id:10!null, nhmxw.NOHHR:11!null, nhmxw.AVPYF:12!null, nhmxw.SYPKF:13!null, nhmxw.IDUT2:14!null, nhmxw.FZXV5:15, nhmxw.DQYGV:16, nhmxw.SWCQV:17!null, nhmxw.YKSSU:18, nhmxw.FHCYT:19, j4jyp.id:37!null, j4jyp.DKCAJ:38!null, j4jyp.KNG7T:39, j4jyp.TW55N:40!null, j4jyp.QRQXW:41!null, j4jyp.ECXAJ:42!null, j4jyp.FGG57:43, j4jyp.ZH72S:44, j4jyp.FSK67:45!null, j4jyp.XQDYT:46!null, j4jyp.TCE7A:47, j4jyp.IWV2H:48, j4jyp.HPCMS:49!null, j4jyp.N5CC2:50, j4jyp.FHCYT:51, j4jyp.ETAQ7:52, j4jyp.A75X7:53, rhuzn.id:20!null, rhuzn.DKCAJ:21!null, rhuzn.KNG7T:22, rhuzn.TW55N:23!null, rhuzn.QRQXW:24!null, rhuzn.ECXAJ:25!null, rhuzn.FGG57:26, rhuzn.ZH72S:27, rhuzn.FSK67:28!null, rhuzn.XQDYT:29!null, rhuzn.TCE7A:30, rhuzn.IWV2H:31, rhuzn.HPCMS:32!null, rhuzn.N5CC2:33, rhuzn.FHCYT:34, rhuzn.ETAQ7:35, rhuzn.A75X7:36, mf.id:57!null, mf.GXLUB:58!null, mf.LUEVY:59!null, mf.M22QN:60!null, mf.TJPT7:61!null, mf.ARN5P:62!null, mf.XOSD4:63!null, mf.IDE43:64, mf.HMW4H:65, mf.ZBT6R:66, mf.FSDY2:67!null, mf.LT7K6:68, mf.SPPYD:69, mf.QCGTS:70, mf.TEUJA:71, mf.QQV4M:72, mf.FHCYT:73, aac.id:54!null, aac.BTXC5:55, aac.FHCYT:56, tizhk.id:0!null as MU3KG, j4jyp.id:37!null as FV24E, rhuzn.id:20!null as UJ6XY, aac.id:54!null as M22QN, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [g3yxs.id:74!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ concat(g3yxs.ESFVY:75!null,(MI: (longtext),g3yxs.SL76B:76!null,) (longtext))\n" +
" │ │ │ └─ tizhk.IDUT2:4\n" +
" │ │ └─ TableAlias(g3yxs)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YYBCX\n" +
" │ │ └─ columns: [id esfvy sl76b]\n" +
" │ │ as NZ4MQ, NULL (null) as FHCYT, NULL (null) as YKSSU]\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.BTXC5:55\n" +
" │ │ │ └─ tizhk.SYPKF:3\n" +
" │ │ └─ nhmxw.id:10!null IS NULL\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ mf.LUEVY:59!null\n" +
" │ │ └─ j4jyp.id:37!null\n" +
" │ ├─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ j4jyp.ZH72S:44\n" +
" │ │ │ └─ tizhk.TVNW2:1\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ rhuzn.ZH72S:27\n" +
" │ │ │ │ └─ tizhk.ZHITY:2\n" +
" │ │ │ ├─ LeftOuterMergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ tizhk.TVNW2:1\n" +
" │ │ │ │ │ └─ nhmxw.NOHHR:11!null\n" +
" │ │ │ │ ├─ sel: AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ nhmxw.SWCQV:17!null\n" +
" │ │ │ │ │ │ │ │ └─ 0 (tinyint)\n" +
" │ │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ │ ├─ nhmxw.AVPYF:12!null\n" +
" │ │ │ │ │ │ │ └─ tizhk.ZHITY:2\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ nhmxw.SYPKF:13!null\n" +
" │ │ │ │ │ │ └─ tizhk.SYPKF:3\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ nhmxw.IDUT2:14!null\n" +
" │ │ │ │ │ └─ tizhk.IDUT2:4\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ │ ├─ tizhk.id:0!null\n" +
" │ │ │ │ │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ │ │ │ │ └─ TableAlias(tizhk)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ │ │ ├─ index: [WRZVO.TVNW2]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ └─ IndexedTableAccess(WGSDC)\n" +
" │ │ │ │ ├─ index: [WGSDC.NOHHR]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id nohhr avpyf sypkf idut2 fzxv5 dqygv swcqv ykssu fhcyt]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(tizhk.ZHITY:2)\n" +
" │ │ │ ├─ right-key: TUPLE(rhuzn.ZH72S:7)\n" +
" │ │ │ └─ TableAlias(rhuzn)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(tizhk.TVNW2:1)\n" +
" │ │ ├─ right-key: TUPLE(j4jyp.ZH72S:7)\n" +
" │ │ └─ TableAlias(j4jyp)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(j4jyp.id:37!null)\n" +
" │ ├─ right-key: TUPLE(mf.LUEVY:5!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ aac.id:54!null\n" +
" │ │ └─ mf.M22QN:60!null\n" +
" │ ├─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ └─ TableAlias(mf)\n" +
" │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ ├─ index: [HGMQ6.M22QN]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id gxlub luevy m22qn tjpt7 arn5p xosd4 ide43 hmw4h zbt6r fsdy2 lt7k6 sppyd qcgts teuja qqv4m fhcyt]\n" +
" └─ Project\n" +
" ├─ columns: [id:0!null, FV24E:1 as FV24E, UJ6XY:2 as UJ6XY, M22QN:3, NZ4MQ:4, ETPQV:5!null, convert\n" +
" │ ├─ type: char\n" +
" │ └─ PRUV2:6!null\n" +
" │ as PRUV2, YKSSU:7, FHCYT:8]\n" +
" └─ Project\n" +
" ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, bpnw2.FV24E:1 as FV24E, bpnw2.UJ6XY:2 as UJ6XY, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [aac.id:17!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ aac.BTXC5:18\n" +
" │ │ └─ bpnw2.SYPKF:3\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.BTXC5]\n" +
" │ └─ columns: [id btxc5]\n" +
" │ as M22QN, bpnw2.NZ4MQ:4 as NZ4MQ, bpnw2.MU3KG:0!null as ETPQV, bpnw2.I4NDZ:7!null as PRUV2, bpnw2.YKSSU:6 as YKSSU, bpnw2.FHCYT:5 as FHCYT]\n" +
" └─ Project\n" +
" ├─ columns: [bpnw2.MU3KG:0!null, bpnw2.FV24E:1, bpnw2.UJ6XY:2, bpnw2.SYPKF:3, bpnw2.NZ4MQ:4, bpnw2.FHCYT:5, bpnw2.YKSSU:6, bpnw2.I4NDZ:7!null, lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, bpnw2.FV24E:1 as FV24E, bpnw2.UJ6XY:2 as UJ6XY, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [aac.id:8!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ aac.BTXC5:9\n" +
" │ │ └─ bpnw2.SYPKF:3\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.BTXC5]\n" +
" │ └─ columns: [id btxc5]\n" +
" │ as M22QN, bpnw2.NZ4MQ:4 as NZ4MQ, bpnw2.MU3KG:0!null as ETPQV, bpnw2.I4NDZ:7!null as PRUV2, bpnw2.YKSSU:6 as YKSSU, bpnw2.FHCYT:5 as FHCYT]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: bpnw2\n" +
" ├─ outerVisibility: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [tizhk.id:0!null as MU3KG, CASE WHEN NOT\n" +
" │ └─ nhmxw.FZXV5:15 IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [overridden_nd_mutant.id:62!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ overridden_nd_mutant.TW55N:63!null\n" +
" │ │ └─ nhmxw.FZXV5:15\n" +
" │ └─ TableAlias(overridden_nd_mutant)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.TW55N]\n" +
" │ └─ columns: [id tw55n]\n" +
" │ ELSE j4jyp.id:20!null END as FV24E, CASE WHEN NOT\n" +
" │ └─ nhmxw.DQYGV:16 IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [overridden_qi2iener.id:62!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ overridden_qi2iener.TW55N:63!null\n" +
" │ │ └─ nhmxw.DQYGV:16\n" +
" │ └─ TableAlias(overridden_qi2iener)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.TW55N]\n" +
" │ └─ columns: [id tw55n]\n" +
" │ ELSE rhuzn.id:37!null END as UJ6XY, tizhk.SYPKF:3 as SYPKF, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [g3yxs.id:62!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ concat(g3yxs.ESFVY:63!null,(MI: (longtext),g3yxs.SL76B:64!null,) (longtext))\n" +
" │ │ └─ tizhk.IDUT2:4\n" +
" │ └─ TableAlias(g3yxs)\n" +
" │ └─ Table\n" +
" │ ├─ name: YYBCX\n" +
" │ └─ columns: [id esfvy sl76b]\n" +
" │ as NZ4MQ, NULL (null) as FHCYT, NULL (null) as YKSSU, nhmxw.id:10!null as I4NDZ]\n" +
" └─ Project\n" +
" ├─ columns: [tizhk.id:0!null, tizhk.TVNW2:1, tizhk.ZHITY:2, tizhk.SYPKF:3, tizhk.IDUT2:4, tizhk.O6QJ3:5, tizhk.NO2JA:6, tizhk.YKSSU:7, tizhk.FHCYT:8, tizhk.QZ6VT:9, nhmxw.id:10!null, nhmxw.NOHHR:11!null, nhmxw.AVPYF:12!null, nhmxw.SYPKF:13!null, nhmxw.IDUT2:14!null, nhmxw.FZXV5:15, nhmxw.DQYGV:16, nhmxw.SWCQV:17!null, nhmxw.YKSSU:18, nhmxw.FHCYT:19, j4jyp.id:20!null, j4jyp.DKCAJ:21!null, j4jyp.KNG7T:22, j4jyp.TW55N:23!null, j4jyp.QRQXW:24!null, j4jyp.ECXAJ:25!null, j4jyp.FGG57:26, j4jyp.ZH72S:27, j4jyp.FSK67:28!null, j4jyp.XQDYT:29!null, j4jyp.TCE7A:30, j4jyp.IWV2H:31, j4jyp.HPCMS:32!null, j4jyp.N5CC2:33, j4jyp.FHCYT:34, j4jyp.ETAQ7:35, j4jyp.A75X7:36, rhuzn.id:37!null, rhuzn.DKCAJ:38!null, rhuzn.KNG7T:39, rhuzn.TW55N:40!null, rhuzn.QRQXW:41!null, rhuzn.ECXAJ:42!null, rhuzn.FGG57:43, rhuzn.ZH72S:44, rhuzn.FSK67:45!null, rhuzn.XQDYT:46!null, rhuzn.TCE7A:47, rhuzn.IWV2H:48, rhuzn.HPCMS:49!null, rhuzn.N5CC2:50, rhuzn.FHCYT:51, rhuzn.ETAQ7:52, rhuzn.A75X7:53, tizhk.id:0!null as MU3KG, CASE WHEN NOT\n" +
" │ └─ nhmxw.FZXV5:15 IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [overridden_nd_mutant.id:54!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ overridden_nd_mutant.TW55N:55!null\n" +
" │ │ └─ nhmxw.FZXV5:15\n" +
" │ └─ TableAlias(overridden_nd_mutant)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.TW55N]\n" +
" │ └─ columns: [id tw55n]\n" +
" │ ELSE j4jyp.id:20!null END as FV24E, CASE WHEN NOT\n" +
" │ └─ nhmxw.DQYGV:16 IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [overridden_qi2iener.id:54!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ overridden_qi2iener.TW55N:55!null\n" +
" │ │ └─ nhmxw.DQYGV:16\n" +
" │ └─ TableAlias(overridden_qi2iener)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.TW55N]\n" +
" │ └─ columns: [id tw55n]\n" +
" │ ELSE rhuzn.id:37!null END as UJ6XY, tizhk.SYPKF:3 as SYPKF, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [g3yxs.id:54!null]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ concat(g3yxs.ESFVY:55!null,(MI: (longtext),g3yxs.SL76B:56!null,) (longtext))\n" +
" │ │ └─ tizhk.IDUT2:4\n" +
" │ └─ TableAlias(g3yxs)\n" +
" │ └─ Table\n" +
" │ ├─ name: YYBCX\n" +
" │ └─ columns: [id esfvy sl76b]\n" +
" │ as NZ4MQ, NULL (null) as FHCYT, NULL (null) as YKSSU, nhmxw.id:10!null as I4NDZ]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nhmxw.id:10!null IS NULL\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ rhuzn.ZH72S:44\n" +
" │ └─ tizhk.ZHITY:2\n" +
" ├─ LeftOuterHashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ j4jyp.ZH72S:27\n" +
" │ │ └─ tizhk.TVNW2:1\n" +
" │ ├─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ tizhk.TVNW2:1\n" +
" │ │ │ └─ nhmxw.NOHHR:11!null\n" +
" │ │ ├─ sel: AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nhmxw.SWCQV:17!null\n" +
" │ │ │ │ │ │ └─ 0 (tinyint)\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ nhmxw.AVPYF:12!null\n" +
" │ │ │ │ │ └─ tizhk.ZHITY:2\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ nhmxw.SYPKF:13!null\n" +
" │ │ │ │ └─ tizhk.SYPKF:3\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ nhmxw.IDUT2:14!null\n" +
" │ │ │ └─ tizhk.IDUT2:4\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ HashIn\n" +
" │ │ │ │ ├─ tizhk.id:0!null\n" +
" │ │ │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ │ │ └─ TableAlias(tizhk)\n" +
" │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ ├─ index: [WRZVO.TVNW2]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" │ │ └─ TableAlias(nhmxw)\n" +
" │ │ └─ IndexedTableAccess(WGSDC)\n" +
" │ │ ├─ index: [WGSDC.NOHHR]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id nohhr avpyf sypkf idut2 fzxv5 dqygv swcqv ykssu fhcyt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(tizhk.TVNW2:1)\n" +
" │ ├─ right-key: TUPLE(j4jyp.ZH72S:7)\n" +
" │ └─ TableAlias(j4jyp)\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(tizhk.ZHITY:2)\n" +
" ├─ right-key: TUPLE(rhuzn.ZH72S:7)\n" +
" └─ TableAlias(rhuzn)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
"",
},
{
Query: `
INSERT INTO
SFEGG(id, NO52D, VYO5E, DKCAJ, ADURZ, FHCYT)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
rs.NO52D AS NO52D,
rs.VYO5E AS VYO5E,
rs.DKCAJ AS DKCAJ,
CASE
WHEN rs.NO52D = 'FZB3D' AND rs.F35MI = 'SUZTA' THEN 1
WHEN rs.NO52D = 'FZB3D' AND rs.F35MI <> 'SUZTA' THEN 3
WHEN rs.NO52D LIKE 'AC%' OR rs.NO52D LIKE 'EC%' THEN 3
WHEN rs.NO52D LIKE 'IC%' AND rs.VYO5E IS NULL THEN 2
WHEN rs.NO52D LIKE 'IC%' AND rs.VYO5E = 'CF' THEN 1
WHEN rs.NO52D LIKE 'IC%' AND rs.VYO5E IS NOT NULL AND NOT(rs.VYO5E = 'CF') THEN 4
WHEN rs.NO52D = 'Ki' THEN 1
WHEN rs.NO52D = 'Kd' THEN 2
ELSE NULL
END AS ADURZ,
NULL AS FHCYT
FROM
(
SELECT DISTINCT
NK7FP.NO52D AS NO52D,
CASE
WHEN NK7FP.VYO5E = 'N/A' THEN NULL
ELSE NK7FP.VYO5E
END AS VYO5E,
nt.id AS DKCAJ,
nt.DZLIM AS F35MI
FROM
(
SELECT DISTINCT
uct.NO52D,
uct.VYO5E,
uct.ZH72S,
I7HCR.FVUCX
FROM
OUBDL uct
LEFT JOIN -- Joining overrides, we need the overridden UWBAI TAFAX in this case
EPZU6 I7HCR
ON
I7HCR.SWCQV = 0 -- Override is turned on
AND
I7HCR.TOFPN = uct.FTQLQ
AND
I7HCR.SJYN2 = uct.ZH72S
AND
I7HCR.BTXC5 = uct.LJLUM
WHERE
uct.id IN ('1','2','3')
) NK7FP
INNER JOIN
E2I7U nd
ON
(
NK7FP.FVUCX IS NULL
AND
nd.ZH72S = NK7FP.ZH72S
)
OR
(
NK7FP.FVUCX IS NOT NULL
AND
nd.TW55N = NK7FP.FVUCX
)
INNER JOIN
F35MI nt ON nt.id = nd.DKCAJ
) rs
WHERE
(
rs.VYO5E IS NOT NULL
AND
(rs.NO52D, rs.VYO5E, rs.DKCAJ) NOT IN (SELECT DISTINCT NO52D, VYO5E, DKCAJ FROM SFEGG WHERE VYO5E IS NOT NULL)
)
OR
(
rs.VYO5E IS NULL
AND
(rs.NO52D, rs.DKCAJ) NOT IN (SELECT DISTINCT NO52D, DKCAJ FROM SFEGG WHERE VYO5E IS NULL)
)`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, NO52D, VYO5E, DKCAJ, ADURZ, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: SFEGG\n" +
" │ └─ columns: [id no52d vyo5e dkcaj adurz fhcyt]\n" +
" └─ Trigger(CREATE TRIGGER SFEGG_on_insert BEFORE INSERT ON SFEGG\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" NEW.NO52D IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" OR NEW.VYO5E IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" THEN\n" +
" -- SET @custom_error_message = (SELECT error_message FROM trigger_helper_error_message WHERE DZLIM = 'SVAZ4');\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'String field contains invalid value, like empty string, ''none'', ''null'', ''n/a'', ''nan'' etc.';\n" +
" END IF;\n" +
" IF\n" +
" NEW.ADURZ <= 0\n" +
" THEN\n" +
" -- SET @custom_error_message = 'ADURZ must be positive.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'ADURZ must be positive.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, NO52D:1!null, VYO5E:2, DKCAJ:3!null, ADURZ:4!null, FHCYT:5]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, rs.NO52D:0 as NO52D, rs.VYO5E:1 as VYO5E, rs.DKCAJ:2!null as DKCAJ, CASE WHEN AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ rs.NO52D:0\n" +
" │ │ │ └─ FZB3D (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ rs.F35MI:3!null\n" +
" │ │ └─ SUZTA (longtext)\n" +
" │ │ THEN 1 (tinyint) WHEN AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ rs.NO52D:0\n" +
" │ │ │ └─ FZB3D (longtext)\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ rs.F35MI:3!null\n" +
" │ │ └─ SUZTA (longtext)\n" +
" │ │ THEN 3 (tinyint) WHEN Or\n" +
" │ │ ├─ rs.NO52D LIKE 'AC%'\n" +
" │ │ └─ rs.NO52D LIKE 'EC%'\n" +
" │ │ THEN 3 (tinyint) WHEN AND\n" +
" │ │ ├─ rs.NO52D LIKE 'IC%'\n" +
" │ │ └─ rs.VYO5E:1 IS NULL\n" +
" │ │ THEN 2 (tinyint) WHEN AND\n" +
" │ │ ├─ rs.NO52D LIKE 'IC%'\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ rs.VYO5E:1\n" +
" │ │ └─ CF (longtext)\n" +
" │ │ THEN 1 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ rs.NO52D LIKE 'IC%'\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ rs.VYO5E:1 IS NULL\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ rs.VYO5E:1\n" +
" │ │ └─ CF (longtext)\n" +
" │ │ THEN 4 (tinyint) WHEN Eq\n" +
" │ │ ├─ rs.NO52D:0\n" +
" │ │ └─ Ki (longtext)\n" +
" │ │ THEN 1 (tinyint) WHEN Eq\n" +
" │ │ ├─ rs.NO52D:0\n" +
" │ │ └─ Kd (longtext)\n" +
" │ │ THEN 2 (tinyint) ELSE NULL (null) END as ADURZ, NULL (null) as FHCYT]\n" +
" │ └─ Filter\n" +
" │ ├─ Or\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ rs.VYO5E:1 IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ InSubquery\n" +
" │ │ │ ├─ left: TUPLE(rs.NO52D:0, rs.VYO5E:1, rs.DKCAJ:2!null)\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Distinct\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [sfegg.NO52D:5!null, sfegg.VYO5E:6, sfegg.DKCAJ:7!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ sfegg.VYO5E:6 IS NULL\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SFEGG\n" +
" │ │ │ └─ columns: [id no52d vyo5e dkcaj adurz fhcyt]\n" +
" │ │ └─ AND\n" +
" │ │ ├─ rs.VYO5E:1 IS NULL\n" +
" │ │ └─ NOT\n" +
" │ │ └─ InSubquery\n" +
" │ │ ├─ left: TUPLE(rs.NO52D:0, rs.DKCAJ:2!null)\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sfegg.NO52D:5!null, sfegg.DKCAJ:7!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ sfegg.VYO5E:6 IS NULL\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ └─ columns: [id no52d vyo5e dkcaj adurz fhcyt]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: rs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nk7fp.NO52D:0 as NO52D, CASE WHEN Eq\n" +
" │ │ ├─ nk7fp.VYO5E:1\n" +
" │ │ └─ N/A (longtext)\n" +
" │ │ THEN NULL (null) ELSE nk7fp.VYO5E:1 END as VYO5E, nt.id:21!null as DKCAJ, nt.DZLIM:22!null as F35MI]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ nt.id:21!null\n" +
" │ │ └─ nd.DKCAJ:5!null\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ nk7fp.FVUCX:3!null IS NULL\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ nd.ZH72S:11\n" +
" │ │ │ │ └─ nk7fp.ZH72S:2\n" +
" │ │ │ └─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ nk7fp.FVUCX:3!null IS NULL\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ nd.TW55N:7!null\n" +
" │ │ │ └─ nk7fp.FVUCX:3!null\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: nk7fp\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Distinct\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [uct.NO52D:7, uct.VYO5E:9, uct.ZH72S:2, i7hcr.FVUCX:17!null]\n" +
" │ │ │ └─ LeftOuterMergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ uct.FTQLQ:1\n" +
" │ │ │ │ └─ i7hcr.TOFPN:14!null\n" +
" │ │ │ ├─ sel: AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ i7hcr.SWCQV:18!null\n" +
" │ │ │ │ │ │ └─ 0 (tinyint)\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ i7hcr.SJYN2:15!null\n" +
" │ │ │ │ │ └─ uct.ZH72S:2\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ i7hcr.BTXC5:16!null\n" +
" │ │ │ │ └─ uct.LJLUM:5\n" +
" │ │ │ ├─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ uct.id:0!null\n" +
" │ │ │ │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ │ │ │ └─ TableAlias(uct)\n" +
" │ │ │ │ └─ IndexedTableAccess(OUBDL)\n" +
" │ │ │ │ ├─ index: [OUBDL.FTQLQ]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ftqlq zh72s sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e ykssu fhcyt qz6vt]\n" +
" │ │ │ └─ TableAlias(i7hcr)\n" +
" │ │ │ └─ IndexedTableAccess(EPZU6)\n" +
" │ │ │ ├─ index: [EPZU6.TOFPN]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id tofpn sjyn2 btxc5 fvucx swcqv ykssu fhcyt]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ Concat\n" +
" │ │ ├─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(nd.DKCAJ:5!null)\n" +
" │ ├─ right-key: TUPLE(nt.id:0!null)\n" +
" │ └─ TableAlias(nt)\n" +
" │ └─ Table\n" +
" │ ├─ name: F35MI\n" +
" │ └─ columns: [id dzlim f3yue]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(Or\n" +
" │ ├─ InSubquery\n" +
" │ │ ├─ left: new.NO52D:1!null\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXHZ\n" +
" │ │ └─ columns: [svaz4]\n" +
" │ └─ InSubquery\n" +
" │ ├─ left: new.VYO5E:2\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ └─ columns: [svaz4]\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = String field contains invalid value, like empty string, 'none', 'null', 'n/a', 'nan' etc., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(LessThanOrEqual\n" +
" ├─ new.ADURZ:4!null\n" +
" └─ 0 (tinyint)\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = ADURZ must be positive., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO FLQLP
(id, FZ2R5, LUEVY, M22QN, OVE3E, NRURT, OCA7E, XMM6Q, V5DPX, S3Q3Y, ZRV3B, FHCYT)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
PQSXB.FZ2R5 AS FZ2R5,
nd.id AS LUEVY,
(SELECT aac.id FROM TPXBU aac WHERE aac.BTXC5 = PQSXB.BTXC5) AS M22QN,
PQSXB.OVE3E AS OVE3E,
PQSXB.NRURT AS NRURT,
PQSXB.OCA7E AS OCA7E,
PQSXB.XMM6Q AS XMM6Q,
PQSXB.V5DPX AS V5DPX,
PQSXB.S3Q3Y AS S3Q3Y,
PQSXB.ZRV3B AS ZRV3B,
PQSXB.FHCYT AS FHCYT
FROM
(
SELECT
-- Base fields to insert to FLQLP
(SELECT id FROM JDLNA WHERE JDLNA.FTQLQ = uct.FTQLQ) AS FZ2R5,
(SELECT id FROM SFEGG WHERE
SFEGG.NO52D = uct.NO52D AND
(
SFEGG.VYO5E = uct.VYO5E OR
(SFEGG.VYO5E IS NULL AND (uct.VYO5E IS NULL OR uct.VYO5E = 'N/A' OR uct.VYO5E = 'NA'))
) AND
SFEGG.DKCAJ = (
SELECT
CASE
WHEN I7HCR.FVUCX IS NULL
THEN (SELECT nd.DKCAJ FROM E2I7U nd WHERE nd.ZH72S = uct.ZH72S LIMIT 1)
ELSE
(SELECT nd.DKCAJ FROM E2I7U nd WHERE nd.TW55N = I7HCR.FVUCX)
END
)
) AS OVE3E,
uct.id AS NRURT,
I7HCR.id AS OCA7E,
NULL AS XMM6Q, -- Here we do not care with additionals
uct.V5DPX AS V5DPX,
uct.IDPK7 + 0.0 AS S3Q3Y,
uct.ZRV3B AS ZRV3B,
CASE
WHEN uct.FHCYT <> 'N/A' THEN uct.FHCYT
ELSE NULL
END AS FHCYT,
-- Extra fields to use
uct.ZH72S AS K3B6V,
uct.LJLUM AS BTXC5,
I7HCR.FVUCX AS H4DMT
FROM
OUBDL uct
LEFT JOIN -- Joining overrides
EPZU6 I7HCR
ON
I7HCR.SWCQV = 0 -- Override is turned on
AND
I7HCR.TOFPN = uct.FTQLQ
AND
I7HCR.SJYN2 = uct.ZH72S
AND
I7HCR.BTXC5 = uct.LJLUM
WHERE
uct.id IN ('1','2','3')
) PQSXB
INNER JOIN
E2I7U nd
ON
(
PQSXB.H4DMT IS NOT NULL
AND
nd.TW55N = PQSXB.H4DMT
)
OR
(
PQSXB.H4DMT IS NULL
AND
nd.ZH72S = PQSXB.K3B6V
)
WHERE
-- In the case we could not build-in evidence class for some
PQSXB.OVE3E IS NOT NULL`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, FZ2R5, LUEVY, M22QN, OVE3E, NRURT, OCA7E, XMM6Q, V5DPX, S3Q3Y, ZRV3B, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: FLQLP\n" +
" │ └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
" └─ Trigger(CREATE TRIGGER FLQLP_on_insert BEFORE INSERT ON FLQLP\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" NEW.V5DPX IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" THEN\n" +
" -- SET @custom_error_message = (SELECT error_message FROM trigger_helper_error_message WHERE DZLIM = 'SVAZ4');\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'String field contains invalid value, like empty string, ''none'', ''null'', ''n/a'', ''nan'' etc.';\n" +
" END IF;\n" +
" IF\n" +
" NEW.ZRV3B NOT IN ('=', '<=', '>=', '<', '>')\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The ZRV3B must be on of the following: ''='', ''<='', ''>='', ''<'', ''>''.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The ZRV3B must be on of the following: ''='', ''<='', ''>='', ''<'', ''>''.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, FZ2R5:1!null, LUEVY:2!null, M22QN:3!null, OVE3E:4!null, NRURT:5, OCA7E:6, XMM6Q:7, V5DPX:8!null, S3Q3Y:9!null, ZRV3B:10!null, FHCYT:11]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, pqsxb.FZ2R5:0 as FZ2R5, nd.id:12!null as LUEVY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.id:41!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.BTXC5:42\n" +
" │ │ │ └─ pqsxb.BTXC5:10\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as M22QN, pqsxb.OVE3E:1 as OVE3E, pqsxb.NRURT:2!null as NRURT, pqsxb.OCA7E:3!null as OCA7E, pqsxb.XMM6Q:4 as XMM6Q, pqsxb.V5DPX:5 as V5DPX, pqsxb.S3Q3Y:6 as S3Q3Y, pqsxb.ZRV3B:7 as ZRV3B, pqsxb.FHCYT:8 as FHCYT]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [pqsxb.FZ2R5:0, pqsxb.OVE3E:1, pqsxb.NRURT:2!null, pqsxb.OCA7E:3!null, pqsxb.XMM6Q:4, pqsxb.V5DPX:5, pqsxb.S3Q3Y:6, pqsxb.ZRV3B:7, pqsxb.FHCYT:8, pqsxb.K3B6V:9, pqsxb.BTXC5:10, pqsxb.H4DMT:11!null, nd.id:12!null, nd.DKCAJ:13!null, nd.KNG7T:14, nd.TW55N:15!null, nd.QRQXW:16!null, nd.ECXAJ:17!null, nd.FGG57:18, nd.ZH72S:19, nd.FSK67:20!null, nd.XQDYT:21!null, nd.TCE7A:22, nd.IWV2H:23, nd.HPCMS:24!null, nd.N5CC2:25, nd.FHCYT:26, nd.ETAQ7:27, nd.A75X7:28, lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, pqsxb.FZ2R5:0 as FZ2R5, nd.id:12!null as LUEVY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.id:29!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.BTXC5:30\n" +
" │ │ │ └─ pqsxb.BTXC5:10\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as M22QN, pqsxb.OVE3E:1 as OVE3E, pqsxb.NRURT:2!null as NRURT, pqsxb.OCA7E:3!null as OCA7E, pqsxb.XMM6Q:4 as XMM6Q, pqsxb.V5DPX:5 as V5DPX, pqsxb.S3Q3Y:6 as S3Q3Y, pqsxb.ZRV3B:7 as ZRV3B, pqsxb.FHCYT:8 as FHCYT]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ Or\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ pqsxb.H4DMT:11!null IS NULL\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ nd.TW55N:15!null\n" +
" │ │ │ └─ pqsxb.H4DMT:11!null\n" +
" │ │ └─ AND\n" +
" │ │ ├─ pqsxb.H4DMT:11!null IS NULL\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ nd.ZH72S:19\n" +
" │ │ └─ pqsxb.K3B6V:9\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: pqsxb\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ NOT\n" +
" │ │ │ └─ OVE3E:1 IS NULL\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jdlna.id:33!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ jdlna.FTQLQ:34!null\n" +
" │ │ │ │ └─ uct.FTQLQ:1\n" +
" │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ as FZ2R5, Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [sfegg.id:33!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ sfegg.NO52D:34!null\n" +
" │ │ │ │ │ │ └─ uct.NO52D:7\n" +
" │ │ │ │ │ └─ Or\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ sfegg.VYO5E:35\n" +
" │ │ │ │ │ │ └─ uct.VYO5E:9\n" +
" │ │ │ │ │ └─ AND\n" +
" │ │ │ │ │ ├─ sfegg.VYO5E:35 IS NULL\n" +
" │ │ │ │ │ └─ Or\n" +
" │ │ │ │ │ ├─ Or\n" +
" │ │ │ │ │ │ ├─ uct.VYO5E:9 IS NULL\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ uct.VYO5E:9\n" +
" │ │ │ │ │ │ └─ N/A (longtext)\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ uct.VYO5E:9\n" +
" │ │ │ │ │ └─ NA (longtext)\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ sfegg.DKCAJ:36!null\n" +
" │ │ │ │ └─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [CASE WHEN i7hcr.FVUCX:17!null IS NULL THEN Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ └─ Limit(1)\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [nd.DKCAJ:40!null]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nd.ZH72S:41\n" +
" │ │ │ │ │ │ └─ uct.ZH72S:2\n" +
" │ │ │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ └─ columns: [dkcaj zh72s]\n" +
" │ │ │ │ │ ELSE Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [nd.DKCAJ:40!null]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nd.TW55N:41!null\n" +
" │ │ │ │ │ │ └─ i7hcr.FVUCX:17!null\n" +
" │ │ │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ │ │ │ └─ columns: [dkcaj tw55n]\n" +
" │ │ │ │ │ END]\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: \n" +
" │ │ │ │ └─ columns: []\n" +
" │ │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ │ ├─ index: [SFEGG.NO52D,SFEGG.VYO5E,SFEGG.DKCAJ]\n" +
" │ │ │ └─ columns: [id no52d vyo5e dkcaj adurz fhcyt]\n" +
" │ │ │ as OVE3E, uct.id:0!null as NRURT, i7hcr.id:13!null as OCA7E, NULL (null) as XMM6Q, uct.V5DPX:4 as V5DPX, (uct.IDPK7:6 + 0 (decimal(2,1))) as S3Q3Y, uct.ZRV3B:8 as ZRV3B, CASE WHEN NOT\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ uct.FHCYT:11\n" +
" │ │ │ └─ N/A (longtext)\n" +
" │ │ │ THEN uct.FHCYT:11 ELSE NULL (null) END as FHCYT, uct.ZH72S:2 as K3B6V, uct.LJLUM:5 as BTXC5, i7hcr.FVUCX:17!null as H4DMT]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [uct.id:0!null, uct.FTQLQ:1, uct.ZH72S:2, uct.SFJ6L:3, uct.V5DPX:4, uct.LJLUM:5, uct.IDPK7:6, uct.NO52D:7, uct.ZRV3B:8, uct.VYO5E:9, uct.YKSSU:10, uct.FHCYT:11, uct.QZ6VT:12, i7hcr.id:13!null, i7hcr.TOFPN:14!null, i7hcr.SJYN2:15!null, i7hcr.BTXC5:16!null, i7hcr.FVUCX:17!null, i7hcr.SWCQV:18!null, i7hcr.YKSSU:19, i7hcr.FHCYT:20, Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jdlna.id:21!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ jdlna.FTQLQ:22!null\n" +
" │ │ │ │ └─ uct.FTQLQ:1\n" +
" │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ as FZ2R5, Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [sfegg.id:21!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ sfegg.NO52D:22!null\n" +
" │ │ │ │ │ │ └─ uct.NO52D:7\n" +
" │ │ │ │ │ └─ Or\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ sfegg.VYO5E:23\n" +
" │ │ │ │ │ │ └─ uct.VYO5E:9\n" +
" │ │ │ │ │ └─ AND\n" +
" │ │ │ │ │ ├─ sfegg.VYO5E:23 IS NULL\n" +
" │ │ │ │ │ └─ Or\n" +
" │ │ │ │ │ ├─ Or\n" +
" │ │ │ │ │ │ ├─ uct.VYO5E:9 IS NULL\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ uct.VYO5E:9\n" +
" │ │ │ │ │ │ └─ N/A (longtext)\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ uct.VYO5E:9\n" +
" │ │ │ │ │ └─ NA (longtext)\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ sfegg.DKCAJ:24!null\n" +
" │ │ │ │ └─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [CASE WHEN i7hcr.FVUCX:17!null IS NULL THEN Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ └─ Limit(1)\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [nd.DKCAJ:28!null]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nd.ZH72S:29\n" +
" │ │ │ │ │ │ └─ uct.ZH72S:2\n" +
" │ │ │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ └─ columns: [dkcaj zh72s]\n" +
" │ │ │ │ │ ELSE Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [nd.DKCAJ:28!null]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nd.TW55N:29!null\n" +
" │ │ │ │ │ │ └─ i7hcr.FVUCX:17!null\n" +
" │ │ │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ │ │ │ └─ columns: [dkcaj tw55n]\n" +
" │ │ │ │ │ END]\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: \n" +
" │ │ │ │ └─ columns: []\n" +
" │ │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ │ ├─ index: [SFEGG.NO52D,SFEGG.VYO5E,SFEGG.DKCAJ]\n" +
" │ │ │ └─ columns: [id no52d vyo5e dkcaj adurz fhcyt]\n" +
" │ │ │ as OVE3E, uct.id:0!null as NRURT, i7hcr.id:13!null as OCA7E, NULL (null) as XMM6Q, uct.V5DPX:4 as V5DPX, (uct.IDPK7:6 + 0 (decimal(2,1))) as S3Q3Y, uct.ZRV3B:8 as ZRV3B, CASE WHEN NOT\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ uct.FHCYT:11\n" +
" │ │ │ └─ N/A (longtext)\n" +
" │ │ │ THEN uct.FHCYT:11 ELSE NULL (null) END as FHCYT, uct.ZH72S:2 as K3B6V, uct.LJLUM:5 as BTXC5, i7hcr.FVUCX:17!null as H4DMT]\n" +
" │ │ └─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ uct.FTQLQ:1\n" +
" │ │ │ └─ i7hcr.TOFPN:14!null\n" +
" │ │ ├─ sel: AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ i7hcr.SWCQV:18!null\n" +
" │ │ │ │ │ └─ 0 (tinyint)\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ i7hcr.SJYN2:15!null\n" +
" │ │ │ │ └─ uct.ZH72S:2\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ i7hcr.BTXC5:16!null\n" +
" │ │ │ └─ uct.LJLUM:5\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ HashIn\n" +
" │ │ │ │ ├─ uct.id:0!null\n" +
" │ │ │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ │ │ └─ TableAlias(uct)\n" +
" │ │ │ └─ IndexedTableAccess(OUBDL)\n" +
" │ │ │ ├─ index: [OUBDL.FTQLQ]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq zh72s sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e ykssu fhcyt qz6vt]\n" +
" │ │ └─ TableAlias(i7hcr)\n" +
" │ │ └─ IndexedTableAccess(EPZU6)\n" +
" │ │ ├─ index: [EPZU6.TOFPN]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tofpn sjyn2 btxc5 fvucx swcqv ykssu fhcyt]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Concat\n" +
" │ ├─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.TW55N]\n" +
" │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(InSubquery\n" +
" │ ├─ left: new.V5DPX:8!null\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ └─ columns: [svaz4]\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = String field contains invalid value, like empty string, 'none', 'null', 'n/a', 'nan' etc., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(NOT\n" +
" └─ IN\n" +
" ├─ left: new.ZRV3B:10!null\n" +
" └─ right: TUPLE(= (longtext), <= (longtext), >= (longtext), < (longtext), > (longtext))\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The ZRV3B must be on of the following: '=', '<=', '>=', '<', '>'., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO
SFEGG(id, NO52D, VYO5E, DKCAJ, ADURZ, FHCYT)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
rs.NO52D AS NO52D,
rs.VYO5E AS VYO5E,
rs.DKCAJ AS DKCAJ,
CASE
WHEN rs.NO52D = 'FZB3D' AND rs.F35MI = 'SUZTA' THEN 1
WHEN rs.NO52D = 'FZB3D' AND rs.F35MI <> 'SUZTA' THEN 3
WHEN rs.NO52D LIKE 'AC%' OR rs.NO52D LIKE 'EC%' THEN 3
WHEN rs.NO52D LIKE 'IC%' AND rs.VYO5E IS NULL THEN 2
WHEN rs.NO52D LIKE 'IC%' AND rs.VYO5E = 'CF' THEN 1
WHEN rs.NO52D LIKE 'IC%' AND rs.VYO5E IS NOT NULL AND NOT(rs.VYO5E = 'CF') THEN 4
WHEN rs.NO52D = 'Ki' THEN 1
WHEN rs.NO52D = 'Kd' THEN 2
ELSE NULL
END AS ADURZ,
NULL AS FHCYT
FROM
(
SELECT DISTINCT
TVTJS.NO52D AS NO52D,
TVTJS.VYO5E AS VYO5E,
nt.id AS DKCAJ,
nt.DZLIM AS F35MI
FROM
HU5A5 TVTJS
INNER JOIN
E2I7U nd ON nd.TW55N = TVTJS.I3VTA
INNER JOIN
F35MI nt ON nt.id = nd.DKCAJ
WHERE
TVTJS.id IN ('1','2','3')
) rs
WHERE
(
rs.VYO5E IS NOT NULL
AND
(rs.NO52D, rs.VYO5E, rs.DKCAJ) NOT IN (SELECT DISTINCT NO52D, VYO5E, DKCAJ FROM SFEGG WHERE VYO5E IS NOT NULL)
)
OR
(
rs.VYO5E IS NULL
AND
(rs.NO52D, rs.DKCAJ) NOT IN (SELECT DISTINCT NO52D, DKCAJ FROM SFEGG WHERE VYO5E IS NULL)
)`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, NO52D, VYO5E, DKCAJ, ADURZ, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: SFEGG\n" +
" │ └─ columns: [id no52d vyo5e dkcaj adurz fhcyt]\n" +
" └─ Trigger(CREATE TRIGGER SFEGG_on_insert BEFORE INSERT ON SFEGG\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" NEW.NO52D IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" OR NEW.VYO5E IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" THEN\n" +
" -- SET @custom_error_message = (SELECT error_message FROM trigger_helper_error_message WHERE DZLIM = 'SVAZ4');\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'String field contains invalid value, like empty string, ''none'', ''null'', ''n/a'', ''nan'' etc.';\n" +
" END IF;\n" +
" IF\n" +
" NEW.ADURZ <= 0\n" +
" THEN\n" +
" -- SET @custom_error_message = 'ADURZ must be positive.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'ADURZ must be positive.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, NO52D:1!null, VYO5E:2, DKCAJ:3!null, ADURZ:4!null, FHCYT:5]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, rs.NO52D:0!null as NO52D, rs.VYO5E:1 as VYO5E, rs.DKCAJ:2!null as DKCAJ, CASE WHEN AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ rs.NO52D:0!null\n" +
" │ │ │ └─ FZB3D (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ rs.F35MI:3!null\n" +
" │ │ └─ SUZTA (longtext)\n" +
" │ │ THEN 1 (tinyint) WHEN AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ rs.NO52D:0!null\n" +
" │ │ │ └─ FZB3D (longtext)\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ rs.F35MI:3!null\n" +
" │ │ └─ SUZTA (longtext)\n" +
" │ │ THEN 3 (tinyint) WHEN Or\n" +
" │ │ ├─ rs.NO52D LIKE 'AC%'\n" +
" │ │ └─ rs.NO52D LIKE 'EC%'\n" +
" │ │ THEN 3 (tinyint) WHEN AND\n" +
" │ │ ├─ rs.NO52D LIKE 'IC%'\n" +
" │ │ └─ rs.VYO5E:1 IS NULL\n" +
" │ │ THEN 2 (tinyint) WHEN AND\n" +
" │ │ ├─ rs.NO52D LIKE 'IC%'\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ rs.VYO5E:1\n" +
" │ │ └─ CF (longtext)\n" +
" │ │ THEN 1 (tinyint) WHEN AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ rs.NO52D LIKE 'IC%'\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ rs.VYO5E:1 IS NULL\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ rs.VYO5E:1\n" +
" │ │ └─ CF (longtext)\n" +
" │ │ THEN 4 (tinyint) WHEN Eq\n" +
" │ │ ├─ rs.NO52D:0!null\n" +
" │ │ └─ Ki (longtext)\n" +
" │ │ THEN 1 (tinyint) WHEN Eq\n" +
" │ │ ├─ rs.NO52D:0!null\n" +
" │ │ └─ Kd (longtext)\n" +
" │ │ THEN 2 (tinyint) ELSE NULL (null) END as ADURZ, NULL (null) as FHCYT]\n" +
" │ └─ Filter\n" +
" │ ├─ Or\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ rs.VYO5E:1 IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ InSubquery\n" +
" │ │ │ ├─ left: TUPLE(rs.NO52D:0!null, rs.VYO5E:1, rs.DKCAJ:2!null)\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Distinct\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [sfegg.NO52D:5!null, sfegg.VYO5E:6, sfegg.DKCAJ:7!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ sfegg.VYO5E:6 IS NULL\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SFEGG\n" +
" │ │ │ └─ columns: [id no52d vyo5e dkcaj adurz fhcyt]\n" +
" │ │ └─ AND\n" +
" │ │ ├─ rs.VYO5E:1 IS NULL\n" +
" │ │ └─ NOT\n" +
" │ │ └─ InSubquery\n" +
" │ │ ├─ left: TUPLE(rs.NO52D:0!null, rs.DKCAJ:2!null)\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sfegg.NO52D:5!null, sfegg.DKCAJ:7!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ sfegg.VYO5E:6 IS NULL\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ └─ columns: [id no52d vyo5e dkcaj adurz fhcyt]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: rs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tvtjs.NO52D:7!null as NO52D, tvtjs.VYO5E:9 as VYO5E, nt.id:30!null as DKCAJ, nt.DZLIM:31!null as F35MI]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ nt.id:30!null\n" +
" │ │ └─ nd.DKCAJ:14!null\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ nd.TW55N:16!null\n" +
" │ │ │ └─ tvtjs.I3VTA:2!null\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ HashIn\n" +
" │ │ │ │ ├─ tvtjs.id:0!null\n" +
" │ │ │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ │ │ └─ TableAlias(tvtjs)\n" +
" │ │ │ └─ IndexedTableAccess(HU5A5)\n" +
" │ │ │ ├─ index: [HU5A5.id]\n" +
" │ │ │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ │ │ └─ columns: [id tofpn i3vta sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e swcqv ykssu fhcyt]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(nd.DKCAJ:14!null)\n" +
" │ ├─ right-key: TUPLE(nt.id:0!null)\n" +
" │ └─ TableAlias(nt)\n" +
" │ └─ Table\n" +
" │ ├─ name: F35MI\n" +
" │ └─ columns: [id dzlim f3yue]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(Or\n" +
" │ ├─ InSubquery\n" +
" │ │ ├─ left: new.NO52D:1!null\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXHZ\n" +
" │ │ └─ columns: [svaz4]\n" +
" │ └─ InSubquery\n" +
" │ ├─ left: new.VYO5E:2\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ └─ columns: [svaz4]\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = String field contains invalid value, like empty string, 'none', 'null', 'n/a', 'nan' etc., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(LessThanOrEqual\n" +
" ├─ new.ADURZ:4!null\n" +
" └─ 0 (tinyint)\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = ADURZ must be positive., MYSQL_ERRNO = 1644\n" +
"",
},
{
Query: `
INSERT INTO FLQLP
(id, FZ2R5, LUEVY, M22QN, OVE3E, NRURT, OCA7E, XMM6Q, V5DPX, S3Q3Y, ZRV3B, FHCYT)
SELECT
LPAD(LOWER(CONCAT(CONCAT(HEX(RAND()*4294967296),LOWER(HEX(RAND()*4294967296)),LOWER(HEX(RAND()*4294967296))))), 24, '0') AS id,
(SELECT id FROM JDLNA WHERE JDLNA.FTQLQ = TVTJS.TOFPN) AS FZ2R5,
(SELECT id FROM E2I7U WHERE TW55N = TVTJS.I3VTA) AS LUEVY,
(SELECT id FROM TPXBU WHERE BTXC5 = TVTJS.LJLUM) AS M22QN,
(SELECT id FROM SFEGG WHERE
SFEGG.NO52D = TVTJS.NO52D AND
(
SFEGG.VYO5E = TVTJS.VYO5E OR
(SFEGG.VYO5E IS NULL AND (TVTJS.VYO5E IS NULL OR TVTJS.VYO5E = 'N/A' OR TVTJS.VYO5E = 'NA'))
) AND
SFEGG.DKCAJ = (
SELECT nd.DKCAJ FROM E2I7U nd WHERE nd.TW55N = TVTJS.I3VTA
)
) AS OVE3E,
NULL AS NRURT, -- Not coming from unprocessed
NULL AS OCA7E, -- Can not be overridden
TVTJS.id AS XMM6Q, -- It is an additional
TVTJS.V5DPX AS V5DPX,
TVTJS.IDPK7 + 0.0 AS S3Q3Y,
TVTJS.ZRV3B AS ZRV3B,
TVTJS.FHCYT AS FHCYT
FROM
HU5A5 TVTJS
WHERE
TVTJS.id IN ('1','2','3')`,
ExpectedPlan: "TriggerRollback\n" +
" └─ RowUpdateAccumulator\n" +
" └─ Insert(id, FZ2R5, LUEVY, M22QN, OVE3E, NRURT, OCA7E, XMM6Q, V5DPX, S3Q3Y, ZRV3B, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ Table\n" +
" │ ├─ name: FLQLP\n" +
" │ └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
" └─ Trigger(CREATE TRIGGER FLQLP_on_insert BEFORE INSERT ON FLQLP\n" +
" FOR EACH ROW\n" +
" BEGIN\n" +
" IF\n" +
" NEW.V5DPX IN (SELECT SVAZ4 FROM TPXHZ)\n" +
" THEN\n" +
" -- SET @custom_error_message = (SELECT error_message FROM trigger_helper_error_message WHERE DZLIM = 'SVAZ4');\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'String field contains invalid value, like empty string, ''none'', ''null'', ''n/a'', ''nan'' etc.';\n" +
" END IF;\n" +
" IF\n" +
" NEW.ZRV3B NOT IN ('=', '<=', '>=', '<', '>')\n" +
" THEN\n" +
" -- SET @custom_error_message = 'The ZRV3B must be on of the following: ''='', ''<='', ''>='', ''<'', ''>''.';\n" +
" -- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @custom_error_message;\n" +
" SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The ZRV3B must be on of the following: ''='', ''<='', ''>='', ''<'', ''>''.';\n" +
" END IF;\n" +
" END//)\n" +
" ├─ Project\n" +
" │ ├─ columns: [id:0!null, FZ2R5:1!null, LUEVY:2!null, M22QN:3!null, OVE3E:4!null, NRURT:5, OCA7E:6, XMM6Q:7, V5DPX:8!null, S3Q3Y:9!null, ZRV3B:10!null, FHCYT:11]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jdlna.id:25!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ jdlna.FTQLQ:26!null\n" +
" │ │ │ └─ tvtjs.TOFPN:1!null\n" +
" │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as FZ2R5, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [e2i7u.id:25!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ e2i7u.TW55N:26!null\n" +
" │ │ │ └─ tvtjs.I3VTA:2!null\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ │ as LUEVY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tpxbu.id:25!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ tpxbu.BTXC5:26\n" +
" │ │ │ └─ tvtjs.LJLUM:5!null\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as M22QN, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sfegg.id:25!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ sfegg.NO52D:26!null\n" +
" │ │ │ │ │ └─ tvtjs.NO52D:7!null\n" +
" │ │ │ │ └─ Or\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ sfegg.VYO5E:27\n" +
" │ │ │ │ │ └─ tvtjs.VYO5E:9\n" +
" │ │ │ │ └─ AND\n" +
" │ │ │ │ ├─ sfegg.VYO5E:27 IS NULL\n" +
" │ │ │ │ └─ Or\n" +
" │ │ │ │ ├─ Or\n" +
" │ │ │ │ │ ├─ tvtjs.VYO5E:9 IS NULL\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ tvtjs.VYO5E:9\n" +
" │ │ │ │ │ └─ N/A (longtext)\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ tvtjs.VYO5E:9\n" +
" │ │ │ │ └─ NA (longtext)\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ sfegg.DKCAJ:28!null\n" +
" │ │ │ └─ Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [nd.DKCAJ:31!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ nd.TW55N:32!null\n" +
" │ │ │ │ └─ tvtjs.I3VTA:2!null\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ │ └─ columns: [dkcaj tw55n]\n" +
" │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ ├─ index: [SFEGG.NO52D,SFEGG.VYO5E,SFEGG.DKCAJ]\n" +
" │ │ └─ columns: [id no52d vyo5e dkcaj adurz fhcyt]\n" +
" │ │ as OVE3E, NULL (null) as NRURT, NULL (null) as OCA7E, tvtjs.id:0!null as XMM6Q, tvtjs.V5DPX:4!null as V5DPX, (tvtjs.IDPK7:6!null + 0 (decimal(2,1))) as S3Q3Y, tvtjs.ZRV3B:8!null as ZRV3B, tvtjs.FHCYT:12 as FHCYT]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tvtjs.id:0!null, tvtjs.TOFPN:1!null, tvtjs.I3VTA:2!null, tvtjs.SFJ6L:3, tvtjs.V5DPX:4!null, tvtjs.LJLUM:5!null, tvtjs.IDPK7:6!null, tvtjs.NO52D:7!null, tvtjs.ZRV3B:8!null, tvtjs.VYO5E:9, tvtjs.SWCQV:10!null, tvtjs.YKSSU:11, tvtjs.FHCYT:12, lpad(lower(concat(concat(hex((rand() * 4294967296)),lower(hex((rand() * 4294967296))),lower(hex((rand() * 4294967296)))))), 24, '0') as id, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jdlna.id:13!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ jdlna.FTQLQ:14!null\n" +
" │ │ │ └─ tvtjs.TOFPN:1!null\n" +
" │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as FZ2R5, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [e2i7u.id:13!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ e2i7u.TW55N:14!null\n" +
" │ │ │ └─ tvtjs.I3VTA:2!null\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ │ as LUEVY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tpxbu.id:13!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ tpxbu.BTXC5:14\n" +
" │ │ │ └─ tvtjs.LJLUM:5!null\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as M22QN, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sfegg.id:13!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ sfegg.NO52D:14!null\n" +
" │ │ │ │ │ └─ tvtjs.NO52D:7!null\n" +
" │ │ │ │ └─ Or\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ sfegg.VYO5E:15\n" +
" │ │ │ │ │ └─ tvtjs.VYO5E:9\n" +
" │ │ │ │ └─ AND\n" +
" │ │ │ │ ├─ sfegg.VYO5E:15 IS NULL\n" +
" │ │ │ │ └─ Or\n" +
" │ │ │ │ ├─ Or\n" +
" │ │ │ │ │ ├─ tvtjs.VYO5E:9 IS NULL\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ tvtjs.VYO5E:9\n" +
" │ │ │ │ │ └─ N/A (longtext)\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ tvtjs.VYO5E:9\n" +
" │ │ │ │ └─ NA (longtext)\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ sfegg.DKCAJ:16!null\n" +
" │ │ │ └─ Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [nd.DKCAJ:19!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ nd.TW55N:20!null\n" +
" │ │ │ │ └─ tvtjs.I3VTA:2!null\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ │ └─ columns: [dkcaj tw55n]\n" +
" │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ ├─ index: [SFEGG.NO52D,SFEGG.VYO5E,SFEGG.DKCAJ]\n" +
" │ │ └─ columns: [id no52d vyo5e dkcaj adurz fhcyt]\n" +
" │ │ as OVE3E, NULL (null) as NRURT, NULL (null) as OCA7E, tvtjs.id:0!null as XMM6Q, tvtjs.V5DPX:4!null as V5DPX, (tvtjs.IDPK7:6!null + 0 (decimal(2,1))) as S3Q3Y, tvtjs.ZRV3B:8!null as ZRV3B, tvtjs.FHCYT:12 as FHCYT]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ tvtjs.id:0!null\n" +
" │ │ └─ TUPLE(1 (longtext), 2 (longtext), 3 (longtext))\n" +
" │ └─ TableAlias(tvtjs)\n" +
" │ └─ IndexedTableAccess(HU5A5)\n" +
" │ ├─ index: [HU5A5.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ └─ columns: [id tofpn i3vta sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e swcqv ykssu fhcyt]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(InSubquery\n" +
" │ ├─ left: new.V5DPX:8!null\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ └─ columns: [svaz4]\n" +
" │ )\n" +
" │ └─ BLOCK\n" +
" │ └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = String field contains invalid value, like empty string, 'none', 'null', 'n/a', 'nan' etc., MYSQL_ERRNO = 1644\n" +
" └─ IF BLOCK\n" +
" └─ IF(NOT\n" +
" └─ IN\n" +
" ├─ left: new.ZRV3B:10!null\n" +
" └─ right: TUPLE(= (longtext), <= (longtext), >= (longtext), < (longtext), > (longtext))\n" +
" )\n" +
" └─ BLOCK\n" +
" └─ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = The ZRV3B must be on of the following: '=', '<=', '>=', '<', '>'., MYSQL_ERRNO = 1644\n" +
"",
},
}
IntegrationPlanTests is a test of generating the right query plans for more complex queries that closely represent real use cases by customers. Like other query plan tests, these tests are fragile because they rely on string representations of query plans, but they're much easier to construct this way. To regenerate these plans after analyzer changes, use the TestWriteIntegrationQueryPlans function in testgen_test.go.
var JSONTableQueryTests = []QueryTest{ { Query: "SELECT * FROM JSON_TABLE(NULL,'$[*]' COLUMNS(x int path '$.a')) as t;", Expected: []sql.Row{}, }, { Query: "SELECT * FROM JSON_TABLE('{}','$[*]' COLUMNS(x int path '$.a')) as t;", Expected: []sql.Row{}, }, { Query: "SELECT * FROM JSON_TABLE('{\"a\":1}','$.b' COLUMNS(x varchar(100) path '$.a')) as tt;", Expected: []sql.Row{}, }, { Query: "SELECT * FROM JSON_TABLE('[{\"a\":1},{\"a\":2}]','$[*]' COLUMNS(x varchar(100) path '$.a')) as tt;", Expected: []sql.Row{ {"1"}, {"2"}, }, }, { Query: "SELECT * FROM JSON_TABLE('[{\"a\":1, \"b\":2},{\"a\":3, \"b\":4}]',\"$[*]\" COLUMNS(x int path '$.a', y int path '$.b')) as tt;", Expected: []sql.Row{ {1, 2}, {3, 4}, }, }, { Query: "SELECT * FROM JSON_TABLE('[{\"a\":1.5, \"b\":2.25},{\"a\":3.125, \"b\":4.0625}]','$[*]' COLUMNS(x float path '$.a', y float path '$.b')) as tt;", Expected: []sql.Row{ {1.5, 2.25}, {3.125, 4.0625}, }, }, { Query: "SELECT * FROM JSON_TABLE(concat('[{},','{}]'),'$[*]' COLUMNS(x varchar(100) path '$.a',y varchar(100) path '$.b')) as t;", Expected: []sql.Row{ {nil, nil}, {nil, nil}, }, }, { Query: "select * from JSON_TABLE('[{\"a\":1},{\"a\":2}]', '$[*]' COLUMNS(x int path '$.a')) as t1 join JSON_TABLE('[{\"a\":1},{\"a\":2}]', '$[*]' COLUMNS(x int path '$.a')) as t2;", Expected: []sql.Row{ {1, 1}, {1, 2}, {2, 1}, {2, 2}, }, }, { Query: "select * from JSON_TABLE('[{\"a\":1},{\"a\":2}]', '$[*]' COLUMNS(x int path '$.a')) as t1 join one_pk order by x, pk;", Expected: []sql.Row{ {1, 0, 0, 1, 2, 3, 4}, {1, 1, 10, 11, 12, 13, 14}, {1, 2, 20, 21, 22, 23, 24}, {1, 3, 30, 31, 32, 33, 34}, {2, 0, 0, 1, 2, 3, 4}, {2, 1, 10, 11, 12, 13, 14}, {2, 2, 20, 21, 22, 23, 24}, {2, 3, 30, 31, 32, 33, 34}, }, }, { Query: "select * from one_pk join JSON_TABLE('[{\"a\":1},{\"a\":2}]', '$[*]' COLUMNS(x int path '$.a')) as t1 order by x, pk;", Expected: []sql.Row{ {0, 0, 1, 2, 3, 4, 1}, {1, 10, 11, 12, 13, 14, 1}, {2, 20, 21, 22, 23, 24, 1}, {3, 30, 31, 32, 33, 34, 1}, {0, 0, 1, 2, 3, 4, 2}, {1, 10, 11, 12, 13, 14, 2}, {2, 20, 21, 22, 23, 24, 2}, {3, 30, 31, 32, 33, 34, 2}, }, }, { Query: "select * from JSON_TABLE('[{\"a\":1},{\"a\":2}]', '$[*]' COLUMNS(x int path '$.a')) as t1 union select * from JSON_TABLE('[{\"b\":3},{\"b\":4}]', '$[*]' COLUMNS(y int path '$.b')) as t2", Expected: []sql.Row{ {1}, {2}, {3}, {4}, }, }, { Query: "select * from one_pk where pk in (select x from JSON_TABLE('[{\"a\":1},{\"a\":2}]', '$[*]' COLUMNS(x int path '$.a')) as t)", Expected: []sql.Row{ {1, 10, 11, 12, 13, 14}, {2, 20, 21, 22, 23, 24}, }, }, { Query: "select * from JSON_TABLE('[{\"a\":1},{\"a\":2}]', '$[*]' COLUMNS(x int path '$.a')) t1 where x in (select y from JSON_TABLE('[{\"b\":1},{\"b\":100}]', '$[*]' COLUMNS(y int path '$.b')) as t2)", Expected: []sql.Row{ {1}, }, }, { Query: "with c as (select jt.a from json_table('[{\"a\":1,\"b\":2,\"c\":3},{\"a\":4,\"b\":5,\"c\":6},{\"a\":7,\"b\":8,\"c\":9}]', '$[*]' columns (a int path '$.a')) as jt) select * from c", Expected: []sql.Row{ {1}, {4}, {7}, }, }, { Query: "select * from json_table('[{\"a\":1,\"b\":2,\"c\":3},{\"a\":4,\"b\":5,\"c\":6},{\"a\":7,\"b\":8,\"c\":9}]', '$[*]' columns (a int path '$.a')) as jt\nunion\nselect * from json_table('[{\"a\":1,\"b\":2,\"c\":3},{\"a\":4,\"b\":5,\"c\":6},{\"a\":7,\"b\":8,\"c\":9}]', '$[*]' columns (b int path '$.b')) as jt\nunion\nselect * from json_table('[{\"a\":1,\"b\":2,\"c\":3},{\"a\":4,\"b\":5,\"c\":6},{\"a\":7,\"b\":8,\"c\":9}]', '$[*]' columns (c int path '$.c')) as jt;", Expected: []sql.Row{ {1}, {4}, {7}, {2}, {5}, {8}, {3}, {6}, {9}, }, }, }
var JSONTableScriptTests = []ScriptTest{ { Name: "create table from json column", SetUpScript: []string{ "create table organizations (organization varchar(10), members json)", `insert into organizations values("orgA", '["bob", "john"]'), ("orgB", '["alice", "mary"]'), ('orgC', '["kevin", "john"]'), ('orgD', '["alice", "alice"]')`, "create table t1(json_col json);", "insert into t1 values ('{ \"people\": [{\"name\":\"John Smith\", \"address\":\"780 Mission St, San Francisco, CA 94103\"}, { \"name\":\"Sally Brown\", \"address\":\"75 37th Ave S, St Cloud, MN 94103\"}, { \"name\":\"John Johnson\", \"address\":\"1262 Roosevelt Trail, Raymond, ME 04071\"}]}')", }, Assertions: []ScriptTestAssertion{ { Query: "select names from organizations, JSON_TABLE(members, '$[*]' columns (names varchar(100) path '$')) as jt;", Expected: []sql.Row{ {"bob"}, {"john"}, {"alice"}, {"mary"}, {"kevin"}, {"john"}, {"alice"}, {"alice"}, }, }, { Query: "SELECT names, COUNT(names) AS count FROM organizations, JSON_TABLE(members, '$[*]' COLUMNS (names varchar(100) path '$')) AS jt GROUP BY names ORDER BY names asc;", Expected: []sql.Row{ {"alice", 3}, {"bob", 1}, {"john", 2}, {"kevin", 1}, {"mary", 1}, }, }, { Query: "select names from organizations, JSON_TABLE(organizations.members, '$[*]' columns (names varchar(100) path '$')) as jt;", Expected: []sql.Row{ {"bob"}, {"john"}, {"alice"}, {"mary"}, {"kevin"}, {"john"}, {"alice"}, {"alice"}, }, }, { Query: "select names from organizations o, JSON_TABLE(o.members, '$[*]' columns (names varchar(100) path '$')) as jt;", Expected: []sql.Row{ {"bob"}, {"john"}, {"alice"}, {"mary"}, {"kevin"}, {"john"}, {"alice"}, {"alice"}, }, }, { Query: "SELECT jt.names, COUNT(jt.names) AS count FROM organizations AS o, JSON_TABLE(o.members, '$[*]' COLUMNS (names varchar(100) path '$')) AS jt GROUP BY jt.names ORDER BY jt.names asc;", Expected: []sql.Row{ {"alice", 3}, {"bob", 1}, {"john", 2}, {"kevin", 1}, {"mary", 1}, }, }, { Query: "select o.organization, jt.names from organizations o, JSON_TABLE(o.members, '$[*]' columns (names varchar(100) path '$')) as jt;", Expected: []sql.Row{ {"orgA", "bob"}, {"orgA", "john"}, {"orgB", "alice"}, {"orgB", "mary"}, {"orgC", "kevin"}, {"orgC", "john"}, {"orgD", "alice"}, {"orgD", "alice"}, }, }, { Query: "SELECT people.* FROM t1, JSON_TABLE(t1.json_col, '$.people[*]' COLUMNS (name VARCHAR(40) PATH '$.name', address VARCHAR(100) PATH '$.address')) people;", Expected: []sql.Row{ {"John Smith", "780 Mission St, San Francisco, CA 94103"}, {"Sally Brown", "75 37th Ave S, St Cloud, MN 94103"}, {"John Johnson", "1262 Roosevelt Trail, Raymond, ME 04071"}, }, }, }, }, { Name: "test other join types", SetUpScript: []string{ "create table organizations (organization varchar(10), members json)", `insert into organizations values ("orgA", '["bob","john"]'), ("orgB", '["alice","mary"]')`, `create table p (i int primary key)`, `insert into p values (1),(2),(3)`, }, Assertions: []ScriptTestAssertion{ { Query: "select o.organization, jt.names from organizations o CROSS JOIN JSON_TABLE(o.members, '$[*]' columns (names varchar(100) path '$')) as jt;", Expected: []sql.Row{ {"orgA", "bob"}, {"orgA", "john"}, {"orgB", "alice"}, {"orgB", "mary"}, }, }, { Query: "select o.organization, jt.names from organizations o NATURAL JOIN JSON_TABLE(o.members, '$[*]' columns (names varchar(100) path '$')) as jt;", Expected: []sql.Row{ {"orgA", "bob"}, {"orgA", "john"}, {"orgB", "alice"}, {"orgB", "mary"}, }, }, { Query: "select o.organization, jt.names from organizations o INNER JOIN JSON_TABLE(o.members, '$[*]' columns (names varchar(100) path '$')) as jt on o.organization = 'orgA';", Expected: []sql.Row{ {"orgA", "bob"}, {"orgA", "john"}, }, }, { Query: `select (select jt.i from p inner join JSON_TABLE('[1,2,3]', '$[*]' columns (i int path '$')) as jt where p.i >= jt.i LIMIT 1);`, Expected: []sql.Row{ {1}, }, }, { Query: `select * from p left join JSON_TABLE('[1,2,3]', '$[*]' columns (i int path '$')) as jt on p.i > jt.i;`, Expected: []sql.Row{ {1, nil}, {2, 1}, {3, 1}, {3, 2}, }, }, { Query: `select * from p right join JSON_TABLE('[1,2,3]', '$[*]' columns (i int path '$')) as jt on p.i > jt.i;`, Expected: []sql.Row{ {2, 1}, {3, 1}, {3, 2}, {nil, 3}, }, }, }, }, { Name: "json table in subquery references parent data", SetUpScript: []string{ "create table t (i int, j json)", `insert into t values (1, '["test"]')`, }, Assertions: []ScriptTestAssertion{ { Query: "select i, (select names from JSON_Table(t.j, '$[*]' columns (names varchar(100) path '$')) jt) from t;", Expected: []sql.Row{ {1, "test"}, }, }, { Query: "select (select jt.a from t, json_table('[\"abc\"]', '$[*]' columns (a varchar(10) path '$')) as jt)", Expected: []sql.Row{ {"abc"}, }, }, { Query: "select (select a from t, json_table(t.j, '$[*]' columns (a varchar(10) path '$')) as jt)", Expected: []sql.Row{ {"test"}, }, }, }, }, { Name: "json table in cte", SetUpScript: []string{ `create table tbl (i int primary key, j json)`, `insert into tbl values (0, '[{"a":1,"b":2,"c":3},{"a":4,"b":5,"c":6},{"a":7,"b":8,"c":9}]')`, `create table t (i int primary key)`, `insert into t values (1), (2)`, }, Assertions: []ScriptTestAssertion{ { Query: "with c as (select jt.a from tbl, json_table(tbl.j, '$[*]' columns (a int path '$.a')) as jt) select * from c", Expected: []sql.Row{ {1}, {4}, {7}, }, }, { Query: "with tt as (select * from t) select * from tt, json_table('[{\"a\":3}]', '$[*]' columns (a int path '$.a')) as jt", Expected: []sql.Row{ {1, 3}, {2, 3}, }, }, }, }, { Name: "table union cross join with json table", SetUpScript: []string{ "create table t (i int, j json)", `insert into t values (1, '["test"]')`, }, Assertions: []ScriptTestAssertion{ { Query: "select t.j from t union select a from t, json_table(t.j, '$[*]' columns (a varchar(10) path '$')) as jt;", Expected: []sql.Row{ {"[\"test\"]"}, {"test"}, }, }, }, }, { Name: "join table, json_table, json_table", SetUpScript: []string{ `create table tbl (i int primary key, j json)`, `insert into tbl values (0, '[{"a":1,"b":2,"c":3},{"a":4,"b":5,"c":6},{"a":7,"b":8,"c":9}]')`, }, Query: "select j1.a, j2.b, j3.c from tbl, json_table(tbl.j, '$[*]' columns (a int path '$.a')) as j1, json_table(tbl.j, '$[*]' columns (b int path '$.b')) as j2, json_table(tbl.j, '$[*]' columns (c int path '$.c')) as j3;", Expected: []sql.Row{ {1, 2, 3}, {1, 2, 6}, {1, 2, 9}, {1, 5, 3}, {1, 5, 6}, {1, 5, 9}, {1, 8, 3}, {1, 8, 6}, {1, 8, 9}, {4, 2, 3}, {4, 2, 6}, {4, 2, 9}, {4, 5, 3}, {4, 5, 6}, {4, 5, 9}, {4, 8, 3}, {4, 8, 6}, {4, 8, 9}, {7, 2, 3}, {7, 2, 6}, {7, 2, 9}, {7, 5, 3}, {7, 5, 6}, {7, 5, 9}, {7, 8, 3}, {7, 8, 6}, {7, 8, 9}, }, }, { Name: "join table, table, json_table", SetUpScript: []string{ `create table t1 (x int primary key)`, `insert into t1 values (1), (2)`, `create table t2 (y int primary key)`, `insert into t2 values (3), (4)`, `create table tbl (j json)`, `insert into tbl values ('[{"a":5},{"a":6}]')`, }, Query: "select t1.x, t2.y, jt.a from t1, t2, tbl, json_table(tbl.j, '$[*]' columns (a int path '$.a')) as jt", Expected: []sql.Row{ {1, 3, 5}, {1, 3, 6}, {1, 4, 5}, {1, 4, 6}, {2, 3, 5}, {2, 3, 6}, {2, 4, 5}, {2, 4, 6}, }, }, { Name: "join table, table, json_table two references past one node", SetUpScript: []string{ `create table t1 (i int, x json)`, `insert into t1 values (1, '[{"a":5},{"a":6}]')`, `create table t2 (y int primary key)`, `insert into t2 values (3), (4)`, `create table tbl (j json)`, `insert into tbl values ('[{"a":5},{"a":6}]')`, }, Query: "select t1.i, t2.y, jt.a from t1, t2, tbl, json_table(t1.x, '$[*]' columns (a int path '$.a')) as jt", Expected: []sql.Row{ {1, 3, 5}, {1, 3, 6}, {1, 4, 5}, {1, 4, 6}, }, }, { Name: "non existent unqualified column", SetUpScript: []string{ "create table t (i int, j json)", }, Query: "select j.a from t, json_table(k, '$[*]' columns (a INT path '$.a')) AS j", ExpectedErr: sql.ErrColumnNotFound, }, { Name: "non existent qualified column", SetUpScript: []string{ "create table t (i int, j json)", }, Query: "select t.a from t, json_table(t.k, '$[*]' columns (a INT path '$.a')) AS j", ExpectedErr: sql.ErrTableColumnNotFound, }, { Name: "select from non existent json table column", SetUpScript: []string{ "create table t (i int, j json)", }, Query: "select j.b from t, json_table(t.j, '$[*]' columns (a INT path '$.a')) AS j", ExpectedErr: sql.ErrTableColumnNotFound, }, { Name: "subquery argument to json_table not allowed", SetUpScript: []string{ "create table t (i int, j json)", `insert into t values (1, '["test"]')`, }, Query: "select * from json_table((select j from t), '$[*]' columns (a varchar(10) path '$')) as jt;", ExpectedErr: sql.ErrInvalidArgument, }, { Name: "test FOR ORDINALITY", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM JSON_TABLE('{}', '$' COLUMNS( pk FOR ORDINALITY, c1 INT PATH '$.c1')) as jt;", Expected: []sql.Row{ {1, nil}, }, }, { Query: "SELECT * FROM JSON_TABLE('{}', '$[*]' COLUMNS( pk FOR ORDINALITY, c1 INT PATH '$.c1')) as jt;", Expected: []sql.Row{}, }, { Query: "SELECT * FROM JSON_TABLE('[{\"c1\": 333}, {\"c1\": 222}, {\"c1\": 111}]', '$[*]' COLUMNS( pk FOR ORDINALITY, c1 INT PATH '$.c1')) as jt;", Expected: []sql.Row{ {1, 333}, {2, 222}, {3, 111}, }, }, { Query: "SELECT * FROM JSON_TABLE('[{\"c1\": 333}, {\"c1\": 222}, {\"c1\": 111}]', '$[*]' COLUMNS( pk1 FOR ORDINALITY, pk2 FOR ORDINALITY, c1 INT PATH '$.c1')) as jt;", Expected: []sql.Row{ {1, 1, 333}, {2, 2, 222}, {3, 3, 111}, }, }, }, }, { Name: "test EXISTS", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(c1 INT EXISTS PATH '$.c1')) as jt;", Expected: []sql.Row{ {0}, }, }, { Query: "SELECT * FROM JSON_TABLE('{\"c1\": 123}', '$' COLUMNS(c1 INT EXISTS PATH '$.c1')) as jt;", Expected: []sql.Row{ {1}, }, }, { Query: "SELECT * FROM JSON_TABLE('[{\"c1\": 333}, {\"c1\": 222}, {\"c1\": 111}, {\"notc1\": 123}]', '$[*]' COLUMNS(c1 INT EXISTS PATH '$.c1')) as jt;", Expected: []sql.Row{ {1}, {1}, {1}, {0}, }, }, { Query: "SELECT * FROM JSON_TABLE('[{\"a\": 333}, {\"b\": 222}, {\"a\": 111}, {\"b\": 123}]', '$[*]' COLUMNS(a INT EXISTS PATH '$.a', b INT EXISTS PATH '$.b')) as jt;", Expected: []sql.Row{ {1, 0}, {0, 1}, {1, 0}, {0, 1}, }, }, }, }, { Name: "test DEFAULT ON ERROR", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(c1 INT PATH '$.c1' DEFAULT '123' ON ERROR)) as jt;", Expected: []sql.Row{ {nil}, }, }, { Query: "SELECT * FROM JSON_TABLE('{\"c1\":\"abc\"}', '$' COLUMNS(c1 INT PATH '$.c1' DEFAULT '123' ON ERROR)) as jt;", Expected: []sql.Row{ {123}, }, }, { Query: "SELECT * FROM JSON_TABLE('{\"c1\":\"abc\"}', '$' COLUMNS(c1 INT PATH '$.c1' DEFAULT 'def' ON ERROR)) as jt;", ExpectedErrStr: "error: 'def' is not a valid value for 'int'", }, }, }, { Name: "test DEFAULT ON EMPTY", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(c1 INT PATH '$.c1' DEFAULT '123' ON EMPTY)) as jt;", Expected: []sql.Row{ {123}, }, }, { Query: "SELECT * FROM JSON_TABLE('{\"notc1\": \"321321\"}', '$' COLUMNS(c1 INT PATH '$.c1' DEFAULT '123' ON EMPTY)) as jt;", Expected: []sql.Row{ {123}, }, }, { Query: "SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(c1 INT PATH '$.c1' DEFAULT 123 ON EMPTY)) as jt;", Expected: []sql.Row{ {123}, }, }, }, }, { Name: "test ERROR ON ERROR", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(c1 INT PATH '$.c1' ERROR ON ERROR)) as jt;", Expected: []sql.Row{ {nil}, }, }, { Query: "SELECT * FROM JSON_TABLE('{\"c1\":\"abc\"}', '$' COLUMNS(c1 INT PATH '$.c1' ERROR ON ERROR)) as jt;", ExpectedErrStr: "error: 'abc' is not a valid value for 'int'", }, }, }, { Name: "test ERROR ON EMPTY", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(c1 INT PATH '$.c1' ERROR ON EMPTY)) as jt;", ExpectedErrStr: "missing value for JSON_TABLE column 'c1'", }, { Query: "SELECT * FROM JSON_TABLE('{\"notc1\": \"321321\"}', '$' COLUMNS(c1 INT PATH '$.c1' ERROR ON EMPTY)) as jt;", ExpectedErrStr: "missing value for JSON_TABLE column 'c1'", }, }, }, { Name: "test NESTED simple", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM JSON_TABLE('[{\"a\": 1, \"b\": [11,111]}, {\"a\": 2, \"b\": [22,222]}]', '$[*]' COLUMNS(a INT PATH '$.a', NESTED PATH '$.b[*]' COLUMNS (b1 INT PATH '$'))) AS jt;", Expected: []sql.Row{ {1, 11}, {1, 111}, {2, 22}, {2, 222}, }, }, { Query: "SELECT * FROM JSON_TABLE('[{\"a\": 1, \"b\": [11,111]}, {\"a\": 2, \"b\": [22,222]}]', '$[*]' COLUMNS( a INT PATH '$.a', NESTED PATH '$.b[*]' COLUMNS (b1 INT PATH '$', b2 INT PATH '$'))) AS jt;", Expected: []sql.Row{ {1, 11, 11}, {1, 111, 111}, {2, 22, 22}, {2, 222, 222}, }, }, { Query: "SELECT * FROM JSON_TABLE('[{\"a\": 1, \"b\": [11,111]}, {\"a\": 2, \"b\": [22,222]}]', '$[*]' COLUMNS( a INT PATH '$.a', NESTED PATH '$.b' COLUMNS (b1 INT PATH '$[0]', b2 INT PATH '$[1]'))) AS jt;", Skip: true, Expected: []sql.Row{ {1, 11, 111}, {2, 22, 222}, }, }, }, }, { Name: "test NESTED siblings", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM JSON_TABLE('[{\"a\": 1, \"b\": [11,111]}, {\"a\": 2, \"b\": [22,222]}]', '$[*]' COLUMNS( a INT PATH '$.a', NESTED PATH '$.b[*]' COLUMNS (b1 INT PATH '$'), NESTED PATH '$.b[*]' COLUMNS (b2 INT PATH '$'), NESTED PATH '$.b[*]' COLUMNS (b3 INT PATH '$'))) AS jt;", Expected: []sql.Row{ {1, 11, nil, nil}, {1, 111, nil, nil}, {1, nil, 11, nil}, {1, nil, 111, nil}, {1, nil, nil, 11}, {1, nil, nil, 111}, {2, 22, nil, nil}, {2, 222, nil, nil}, {2, nil, 22, nil}, {2, nil, 222, nil}, {2, nil, nil, 22}, {2, nil, nil, 222}, }, }, }, }, { Name: "test NESTED NESTED", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: ` SELECT * FROM JSON_TABLE( '{"a": [123, 456]}', '$.a[*]' COLUMNS( id1 FOR ORDINALITY, a1 INT PATH '$', b1 INT PATH '$', c1 INT PATH '$', NESTED PATH '$' COLUMNS ( id2 FOR ORDINALITY, i1 INT PATH '$', j1 INT PATH '$', k1 INT PATH '$', NESTED PATH '$' COLUMNS ( id4 FOR ORDINALITY, x1 INT PATH '$', y1 INT PATH '$', z1 INT PATH '$' ), NESTED PATH '$' COLUMNS ( id5 FOR ORDINALITY, x2 INT PATH '$', y2 INT PATH '$', z2 INT PATH '$' ) ), NESTED PATH '$' COLUMNS ( id6 FOR ORDINALITY, i2 INT PATH '$', j2 INT PATH '$', k2 INT PATH '$', NESTED PATH '$' COLUMNS ( id7 FOR ORDINALITY, x3 INT PATH '$', y3 INT PATH '$', z3 INT PATH '$' ), NESTED PATH '$' COLUMNS ( id8 FOR ORDINALITY, x4 INT PATH '$', y4 INT PATH '$', z4 INT PATH '$' ) ) ) ) as jt; `, Expected: []sql.Row{ {1, 123, 123, 123, 1, 123, 123, 123, 1, 123, 123, 123, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {1, 123, 123, 123, 1, 123, 123, 123, nil, nil, nil, nil, 1, 123, 123, 123, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {1, 123, 123, 123, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 1, 123, 123, 123, 1, 123, 123, 123, nil, nil, nil, nil}, {1, 123, 123, 123, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 1, 123, 123, 123, nil, nil, nil, nil, 1, 123, 123, 123}, {2, 456, 456, 456, 1, 456, 456, 456, 1, 456, 456, 456, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {2, 456, 456, 456, 1, 456, 456, 456, nil, nil, nil, nil, 1, 456, 456, 456, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {2, 456, 456, 456, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 1, 456, 456, 456, 1, 456, 456, 456, nil, nil, nil, nil}, {2, 456, 456, 456, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 1, 456, 456, 456, nil, nil, nil, nil, 1, 456, 456, 456}, }, }, }, }, { Name: "test combinations of options", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM JSON_TABLE('[{\"a\":\"3\"},{\"a\":2},{\"b\":1},{\"a\":0},{\"a\":[1,2]}]', \"$[*]\" COLUMNS (rowid FOR ORDINALITY, ac VARCHAR(100) PATH \"$.a\" DEFAULT '111' ON EMPTY DEFAULT '999' ON ERROR, aj JSON PATH \"$.a\" DEFAULT '{\"x\": 333}' ON EMPTY, bx INT EXISTS PATH \"$.b\")) AS tt;", Expected: []sql.Row{ {1, "3", types.MustJSON("3"), 0}, {2, "2", types.MustJSON("2"), 0}, {3, "111", types.MustJSON("{\"x\": 333}"), 1}, {4, "0", types.MustJSON("0"), 0}, {5, "999", types.MustJSON("[1, 2]"), 0}, }, }, { Query: "SELECT * FROM JSON_TABLE('[{\"x\":2,\"y\":\"8\"},{\"x\":\"3\",\"y\":\"7\"},{\"x\":\"4\",\"y\":6}]', \"$[*]\" COLUMNS (xval VARCHAR(100) PATH \"$.x\", yval VARCHAR(100) PATH \"$.y\")) AS jt1;", Expected: []sql.Row{ {"2", "8"}, {"3", "7"}, {"4", "6"}, }, }, { Query: "SELECT * FROM JSON_TABLE('[{\"x\":2,\"y\":\"8\"},{\"x\":\"3\",\"y\":\"7\"},{\"x\":\"4\",\"y\":6}]', \"$[1]\" COLUMNS (xval VARCHAR(100) PATH \"$.x\", yval VARCHAR(100) PATH \"$.y\")) AS jt1;", Expected: []sql.Row{ {"3", "7"}, }, }, }, }, }
var JoinQueryTests = []QueryTest{ { Query: "select ab.* from ab join pq on a = p where b = (select y from xy where y in (select v from uv where v = b)) order by a;", Expected: []sql.Row{ {0, 2}, {1, 2}, {2, 2}, {3, 1}, }, }, { Query: "select * from ab where b in (select y from xy where y in (select v from uv where v = b));", Expected: []sql.Row{ {0, 2}, {1, 2}, {2, 2}, {3, 1}, }, }, { Query: "select * from ab where a in (select y from xy where y in (select v from uv where v = a));", Expected: []sql.Row{ {1, 2}, {2, 2}, }, }, { Query: "select * from ab where a in (select x from xy where x in (select u from uv where u = a));", Expected: []sql.Row{ {1, 2}, {2, 2}, {0, 2}, {3, 1}, }, }, { Query: `select y, (select 1 from uv where y = 1 and u = x) is_one from xy join uv on x = v order by y;`, Expected: []sql.Row{ {0, nil}, {0, nil}, {1, 1}, {1, 1}, }, }, { Query: `select y, (select 1 where y = 1) is_one from xy join uv on x = v order by y`, Expected: []sql.Row{ {0, nil}, {0, nil}, {1, 1}, {1, 1}, }, }, { Query: `select * from (select y, (select 1 where y = 1) is_one from xy join uv on x = v) sq order by y`, Expected: []sql.Row{ {0, nil}, {0, nil}, {1, 1}, {1, 1}, }, }, { Query: `SELECT (SELECT 1 FROM (SELECT x FROM xy INNER JOIN uv ON (x = u OR y = v) LIMIT 1) r) AS s FROM xy`, Expected: []sql.Row{{1}, {1}, {1}, {1}}, }, { Query: `select a from ab where exists (select 1 from xy where a =x)`, Expected: []sql.Row{{0}, {1}, {2}, {3}}, }, { Query: "select a from ab where exists (select 1 from xy where a = x and b = 2 and y = 2);", Expected: []sql.Row{{0}}, }, { Query: "select * from uv where exists (select 1, count(a) from ab where u = a group by a)", Expected: []sql.Row{{0, 1}, {1, 1}, {2, 2}, {3, 2}}, }, { Query: ` select * from ( select * from ab left join uv on a = u where exists (select * from pq where u = p) ) alias2 inner join xy on a = x;`, Expected: []sql.Row{ {0, 2, 0, 1, 0, 2}, {1, 2, 1, 1, 1, 0}, {2, 2, 2, 2, 2, 1}, {3, 1, 3, 2, 3, 3}, }, }, { Query: ` select * from ab where exists ( select * from uv left join pq on u = p where a = u );`, Expected: []sql.Row{ {0, 2}, {1, 2}, {2, 2}, {3, 1}, }, }, { Query: ` select * from ( select * from ab where not exists (select * from uv where a = v) ) alias1 where exists (select * from xy where a = x);`, Expected: []sql.Row{ {0, 2}, {3, 1}, }}, { Query: ` select * from ( select * from ab inner join xy on true ) alias1 inner join uv on true inner join pq on true order by 1,2,3,4,5,6,7,8 limit 5;`, Expected: []sql.Row{ {0, 2, 0, 2, 0, 1, 0, 0}, {0, 2, 0, 2, 0, 1, 1, 1}, {0, 2, 0, 2, 0, 1, 2, 2}, {0, 2, 0, 2, 0, 1, 3, 3}, {0, 2, 0, 2, 1, 1, 0, 0}, }, }, { Query: ` select * from ( select * from ab where not exists (select * from xy where a = y+1) ) alias1 left join pq on alias1.a = p where exists (select * from uv where a = u);`, Expected: []sql.Row{ {0, 2, 0, 0}, }}, { Query: "SELECT mytable.i " + "FROM mytable " + "INNER JOIN othertable ON (mytable.i = othertable.i2) " + "LEFT JOIN othertable T4 ON (mytable.i = T4.i2) " + "ORDER BY othertable.i2, T4.s2", Expected: []sql.Row{{1}, {2}, {3}}, }, { Query: "select 1 as exprAlias, 2, 3, (select exprAlias + count(*) from one_pk_three_idx a cross join one_pk_three_idx b);", Expected: []sql.Row{{1, 2, 3, 65}}, }, { Query: "select pk, v1, v2 from one_pk_three_idx where v1 in (select max(a.v1) from one_pk_three_idx a cross join (select 'foo' from dual) b);", Expected: []sql.Row{{7, 4, 4}}, }, { Query: "select * from (select a.v1, b.v2 from one_pk_three_idx a cross join one_pk_three_idx b) dt order by 1 desc, 2 desc limit 5;", Expected: []sql.Row{ {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, }, }, { Query: "select a.pk, c.v2 from one_pk_three_idx a cross join one_pk_three_idx b left join one_pk_three_idx c on b.pk = c.v2 where b.pk = 0 and a.v2 = 1;", Expected: []sql.Row{ {2, 0}, {2, 0}, {2, 0}, {2, 0}, }, }, { Query: "select a.pk, c.v2 from one_pk_three_idx a cross join one_pk_three_idx b right join one_pk_three_idx c on b.pk = c.v3 where b.pk = 0 and c.v2 = 0 order by a.pk;", Expected: []sql.Row{ {0, 0}, {0, 0}, {1, 0}, {1, 0}, {2, 0}, {2, 0}, {3, 0}, {3, 0}, {4, 0}, {4, 0}, {5, 0}, {5, 0}, {6, 0}, {6, 0}, {7, 0}, {7, 0}, }, }, { Query: "select a.pk, c.v2 from one_pk_three_idx a cross join one_pk_three_idx b inner join (select * from one_pk_three_idx where v2 = 0) c on b.pk = c.v3 where b.pk = 0 and c.v2 = 0 order by a.pk;", Expected: []sql.Row{ {0, 0}, {0, 0}, {1, 0}, {1, 0}, {2, 0}, {2, 0}, {3, 0}, {3, 0}, {4, 0}, {4, 0}, {5, 0}, {5, 0}, {6, 0}, {6, 0}, {7, 0}, {7, 0}, }, }, { Query: "select a.pk, c.v2 from one_pk_three_idx a cross join one_pk_three_idx b left join one_pk_three_idx c on b.pk = c.v1+1 where b.pk = 0 order by a.pk;", Expected: []sql.Row{ {0, nil}, {1, nil}, {2, nil}, {3, nil}, {4, nil}, {5, nil}, {6, nil}, {7, nil}, }, }, { Query: "select a.pk, c.v2 from one_pk_three_idx a cross join one_pk_three_idx b right join one_pk_three_idx c on b.pk = c.v1 where b.pk = 0 and c.v2 = 0 order by a.pk;", Expected: []sql.Row{ {0, 0}, {0, 0}, {1, 0}, {1, 0}, {2, 0}, {2, 0}, {3, 0}, {3, 0}, {4, 0}, {4, 0}, {5, 0}, {5, 0}, {6, 0}, {6, 0}, {7, 0}, {7, 0}, }, }, { Query: "select * from mytable a CROSS JOIN mytable b RIGHT JOIN mytable c ON b.i = c.i + 1 order by 1,2,3,4,5,6;", Expected: []sql.Row{ {nil, nil, nil, nil, 3, "third row"}, {1, "first row", 2, "second row", 1, "first row"}, {1, "first row", 3, "third row", 2, "second row"}, {2, "second row", 2, "second row", 1, "first row"}, {2, "second row", 3, "third row", 2, "second row"}, {3, "third row", 2, "second row", 1, "first row"}, {3, "third row", 3, "third row", 2, "second row"}, }, }, { Query: "select * from mytable a CROSS JOIN mytable b LEFT JOIN mytable c ON b.i = c.i + 1 order by 1,2,3,4,5,6;", Expected: []sql.Row{ {1, "first row", 1, "first row", nil, nil}, {1, "first row", 2, "second row", 1, "first row"}, {1, "first row", 3, "third row", 2, "second row"}, {2, "second row", 1, "first row", nil, nil}, {2, "second row", 2, "second row", 1, "first row"}, {2, "second row", 3, "third row", 2, "second row"}, {3, "third row", 1, "first row", nil, nil}, {3, "third row", 2, "second row", 1, "first row"}, {3, "third row", 3, "third row", 2, "second row"}, }, }, { Query: "select a.i, b.i, c.i from mytable a CROSS JOIN mytable b LEFT JOIN mytable c ON b.i+1 = c.i order by 1,2,3;", Expected: []sql.Row{ {1, 1, 2}, {1, 2, 3}, {1, 3, nil}, {2, 1, 2}, {2, 2, 3}, {2, 3, nil}, {3, 1, 2}, {3, 2, 3}, {3, 3, nil}, }}, { Query: "select * from mytable a LEFT JOIN mytable b on a.i = b.i LEFT JOIN mytable c ON b.i = c.i + 1 order by 1,2,3,4,5,6;", Expected: []sql.Row{ {1, "first row", 1, "first row", nil, nil}, {2, "second row", 2, "second row", 1, "first row"}, {3, "third row", 3, "third row", 2, "second row"}, }, }, { Query: "select * from mytable a LEFT JOIN mytable b on a.i = b.i RIGHT JOIN mytable c ON b.i = c.i + 1 order by 1,2,3,4,5,6;", Expected: []sql.Row{ {nil, nil, nil, nil, 3, "third row"}, {2, "second row", 2, "second row", 1, "first row"}, {3, "third row", 3, "third row", 2, "second row"}, }, }, { Query: "select * from mytable a RIGHT JOIN mytable b on a.i = b.i RIGHT JOIN mytable c ON b.i = c.i + 1 order by 1,2,3,4,5,6;", Expected: []sql.Row{ {nil, nil, nil, nil, 3, "third row"}, {2, "second row", 2, "second row", 1, "first row"}, {3, "third row", 3, "third row", 2, "second row"}, }, }, { Query: "select * from mytable a RIGHT JOIN mytable b on a.i = b.i LEFT JOIN mytable c ON b.i = c.i + 1;", Expected: []sql.Row{ {1, "first row", 1, "first row", nil, nil}, {2, "second row", 2, "second row", 1, "first row"}, {3, "third row", 3, "third row", 2, "second row"}, }, }, { Query: "select * from mytable a LEFT JOIN mytable b on a.i = b.i LEFT JOIN mytable c ON b.i+1 = c.i;", Expected: []sql.Row{ {1, "first row", 1, "first row", 2, "second row"}, {2, "second row", 2, "second row", 3, "third row"}, {3, "third row", 3, "third row", nil, nil}, }}, { Query: "select * from mytable a LEFT JOIN mytable b on a.i = b.i RIGHT JOIN mytable c ON b.i+1 = c.i order by 1,2,3,4,5,6;", Expected: []sql.Row{ {nil, nil, nil, nil, 1, "first row"}, {1, "first row", 1, "first row", 2, "second row"}, {2, "second row", 2, "second row", 3, "third row"}, }}, { Query: "select * from mytable a RIGHT JOIN mytable b on a.i = b.i RIGHT JOIN mytable c ON b.i+1= c.i order by 1,2,3,4,5,6;", Expected: []sql.Row{ {nil, nil, nil, nil, 1, "first row"}, {1, "first row", 1, "first row", 2, "second row"}, {2, "second row", 2, "second row", 3, "third row"}, }}, { Query: "select * from mytable a RIGHT JOIN mytable b on a.i = b.i LEFT JOIN mytable c ON b.i+1 = c.i order by 1,2,3,4,5,6;", Expected: []sql.Row{ {1, "first row", 1, "first row", 2, "second row"}, {2, "second row", 2, "second row", 3, "third row"}, {3, "third row", 3, "third row", nil, nil}, }, }, { Query: "select * from mytable a CROSS JOIN mytable b RIGHT JOIN mytable c ON b.i+1 = c.i order by 1,2,3,4,5,6;", Expected: []sql.Row{ {nil, nil, nil, nil, 1, "first row"}, {1, "first row", 1, "first row", 2, "second row"}, {1, "first row", 2, "second row", 3, "third row"}, {2, "second row", 1, "first row", 2, "second row"}, {2, "second row", 2, "second row", 3, "third row"}, {3, "third row", 1, "first row", 2, "second row"}, {3, "third row", 2, "second row", 3, "third row"}, }, }, { Query: "with a as (select a.i, a.s from mytable a CROSS JOIN mytable b) select * from a RIGHT JOIN mytable c on a.i+1 = c.i-1;", Expected: []sql.Row{ {nil, nil, 1, "first row"}, {nil, nil, 2, "second row"}, {1, "first row", 3, "third row"}, {1, "first row", 3, "third row"}, {1, "first row", 3, "third row"}, }, }, { Query: "select a.* from mytable a RIGHT JOIN mytable b on a.i = b.i+1 LEFT JOIN mytable c on a.i = c.i-1 RIGHT JOIN mytable d on b.i = d.i;", Expected: []sql.Row{ {2, "second row"}, {3, "third row"}, {nil, nil}, }, }, { Query: "select a.*,b.* from mytable a RIGHT JOIN othertable b on a.i = b.i2+1 LEFT JOIN mytable c on a.i = c.i-1 LEFT JOIN othertable d on b.i2 = d.i2;", Expected: []sql.Row{ {2, "second row", "third", 1}, {3, "third row", "second", 2}, {nil, nil, "first", 3}, }, }, { Query: "select a.*,b.* from mytable a RIGHT JOIN othertable b on a.i = b.i2+1 RIGHT JOIN mytable c on a.i = c.i-1 LEFT JOIN othertable d on b.i2 = d.i2;", Expected: []sql.Row{ {nil, nil, nil, nil}, {nil, nil, nil, nil}, {2, "second row", "third", 1}, }, }, { Query: "select i.pk, j.v3 from one_pk_two_idx i JOIN one_pk_three_idx j on i.v1 = j.pk;", Expected: []sql.Row{{0, 0}, {1, 1}, {2, 0}, {3, 2}, {4, 0}, {5, 3}, {6, 0}, {7, 4}}, }, { Query: "select i.pk, j.v3, k.c1 from one_pk_two_idx i JOIN one_pk_three_idx j on i.v1 = j.pk JOIN one_pk k on j.v3 = k.pk;", Expected: []sql.Row{{0, 0, 0}, {1, 1, 10}, {2, 0, 0}, {3, 2, 20}, {4, 0, 0}, {5, 3, 30}, {6, 0, 0}}, }, { Query: "select i.pk, j.v3 from (one_pk_two_idx i JOIN one_pk_three_idx j on((i.v1 = j.pk)));", Expected: []sql.Row{{0, 0}, {1, 1}, {2, 0}, {3, 2}, {4, 0}, {5, 3}, {6, 0}, {7, 4}}, }, { Query: "select i.pk, j.v3, k.c1 from ((one_pk_two_idx i JOIN one_pk_three_idx j on ((i.v1 = j.pk))) JOIN one_pk k on((j.v3 = k.pk)));", Expected: []sql.Row{{0, 0, 0}, {1, 1, 10}, {2, 0, 0}, {3, 2, 20}, {4, 0, 0}, {5, 3, 30}, {6, 0, 0}}, }, { Query: "select i.pk, j.v3, k.c1 from (one_pk_two_idx i JOIN one_pk_three_idx j on ((i.v1 = j.pk)) JOIN one_pk k on((j.v3 = k.pk)));", Expected: []sql.Row{{0, 0, 0}, {1, 1, 10}, {2, 0, 0}, {3, 2, 20}, {4, 0, 0}, {5, 3, 30}, {6, 0, 0}}, }, { Query: "select a.* from one_pk_two_idx a RIGHT JOIN (one_pk_two_idx i JOIN one_pk_three_idx j on i.v1 = j.pk) on a.pk = i.v1 LEFT JOIN (one_pk_two_idx k JOIN one_pk_three_idx l on k.v1 = l.pk) on a.pk = l.v2;", Expected: []sql.Row{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {2, 2, 2}, {3, 3, 3}, {4, 4, 4}, {5, 5, 5}, {6, 6, 6}, {7, 7, 7}}, }, { Query: "select a.* from one_pk_two_idx a LEFT JOIN (one_pk_two_idx i JOIN one_pk_three_idx j on i.pk = j.v3) on a.pk = i.pk RIGHT JOIN (one_pk_two_idx k JOIN one_pk_three_idx l on k.v2 = l.v3) on a.v1 = l.v2;", Expected: []sql.Row{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {2, 2, 2}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {3, 3, 3}, {4, 4, 4}, }, }, { Query: "select a.* from mytable a join mytable b on a.i = b.i and a.i > 2", Expected: []sql.Row{ {3, "third row"}, }, }, { Query: "select a.* from mytable a join mytable b on a.i = b.i and now() >= coalesce(NULL, NULL, now())", Expected: []sql.Row{ {1, "first row"}, {2, "second row"}, {3, "third row"}}, }, { Query: "select * from mytable a join niltable b on a.i = b.i and b <=> NULL", Expected: []sql.Row{ {1, "first row", 1, nil, nil, nil}, }, }, { Query: "select * from mytable a join niltable b on a.i = b.i and s IS NOT NULL", Expected: []sql.Row{ {1, "first row", 1, nil, nil, nil}, {2, "second row", 2, 2, 1, nil}, {3, "third row", 3, nil, 0, nil}, }, }, { Query: "select * from mytable a join niltable b on a.i = b.i and b IS NOT NULL", Expected: []sql.Row{ {2, "second row", 2, 2, 1, nil}, {3, "third row", 3, nil, 0, nil}, }, }, { Query: "select * from mytable a join niltable b on a.i = b.i and b != 0", Expected: []sql.Row{ {2, "second row", 2, 2, 1, nil}, }, }, { Query: "select * from mytable a join niltable b on a.i <> b.i and b != 0;", Expected: []sql.Row{ {3, "third row", 2, 2, 1, nil}, {1, "first row", 2, 2, 1, nil}, {3, "third row", 5, nil, 1, float64(5)}, {2, "second row", 5, nil, 1, float64(5)}, {1, "first row", 5, nil, 1, float64(5)}, }, }, { Query: "select * from mytable a join niltable b on a.i <> b.i;", Expected: []sql.Row{ {3, "third row", 1, nil, nil, nil}, {2, "second row", 1, nil, nil, nil}, {3, "third row", 2, 2, 1, nil}, {1, "first row", 2, 2, 1, nil}, {2, "second row", 3, nil, 0, nil}, {1, "first row", 3, nil, 0, nil}, {3, "third row", 5, nil, 1, float64(5)}, {2, "second row", 5, nil, 1, float64(5)}, {1, "first row", 5, nil, 1, float64(5)}, {3, "third row", 4, 4, nil, float64(4)}, {2, "second row", 4, 4, nil, float64(4)}, {1, "first row", 4, 4, nil, float64(4)}, {3, "third row", 6, 6, 0, float64(6)}, {2, "second row", 6, 6, 0, float64(6)}, {1, "first row", 6, 6, 0, float64(6)}, }, }, { Query: `SELECT pk as pk, nt.i as i, nt2.i as i FROM one_pk RIGHT JOIN niltable nt ON pk=nt.i RIGHT JOIN niltable nt2 ON pk=nt2.i - 1 ORDER BY 3;`, Expected: []sql.Row{ {nil, nil, 1}, {1, 1, 2}, {2, 2, 3}, {3, 3, 4}, {nil, nil, 5}, {nil, nil, 6}, }, }, { Query: "select * from ab full join pq on a = p order by 1,2,3,4;", Expected: []sql.Row{ {0, 2, 0, 0}, {1, 2, 1, 1}, {2, 2, 2, 2}, {3, 1, 3, 3}, }, }, { Query: ` select * from ab inner join uv on a = u full join pq on a = p order by 1,2,3,4,5,6;`, Expected: []sql.Row{ {0, 2, 0, 1, 0, 0}, {1, 2, 1, 1, 1, 1}, {2, 2, 2, 2, 2, 2}, {3, 1, 3, 2, 3, 3}, }, }, { Query: ` select * from ab full join pq on a = p left join xy on a = x order by 1,2,3,4,5,6;`, Expected: []sql.Row{ {0, 2, 0, 0, 0, 2}, {1, 2, 1, 1, 1, 0}, {2, 2, 2, 2, 2, 1}, {3, 1, 3, 3, 3, 3}, }, }, { Query: `select * from (select a,v from ab join uv on a=u) av join (select x,q from xy join pq on x = p) xq on av.v = xq.x`, Expected: []sql.Row{ {0, 1, 1, 1}, {1, 1, 1, 1}, {2, 2, 2, 2}, {3, 2, 2, 2}, }, }, { Query: "select x from xy join uv on y = v join ab on y = b and u = -1", Expected: []sql.Row{}, }, { Query: "select a.* from one_pk_two_idx a LEFT JOIN (one_pk_two_idx i JOIN one_pk_three_idx j on i.pk = j.v3) on a.pk = i.pk LEFT JOIN (one_pk_two_idx k JOIN one_pk_three_idx l on k.v2 = l.v3) on a.v1 = l.v2;", Expected: []sql.Row{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {2, 2, 2}, {3, 3, 3}, {4, 4, 4}, {5, 5, 5}, {6, 6, 6}, {7, 7, 7}, }, }, { Query: "with recursive a(x,y) as (select i,i from mytable where i < 4 union select a.x, mytable.i from a join mytable on a.x+1 = mytable.i limit 2) select * from a;", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: ` select * from ( (ab JOIN pq ON (1 = p)) LEFT OUTER JOIN uv on (2 = u) );`, Expected: []sql.Row{ {0, 2, 1, 1, 2, 2}, {1, 2, 1, 1, 2, 2}, {2, 2, 1, 1, 2, 2}, {3, 1, 1, 1, 2, 2}, }, }, { Query: "select * from (ab JOIN pq ON (a = 1)) where a in (1,2,3)", Expected: []sql.Row{ {1, 2, 0, 0}, {1, 2, 1, 1}, {1, 2, 2, 2}, {1, 2, 3, 3}}, }, { Query: "select * from (ab JOIN pq ON (a = p)) where a in (select a from ab)", Expected: []sql.Row{ {0, 2, 0, 0}, {1, 2, 1, 1}, {2, 2, 2, 2}, {3, 1, 3, 3}}, }, { Query: "select * from (ab JOIN pq ON (a = 1)) where a in (select a from ab)", Expected: []sql.Row{ {1, 2, 0, 0}, {1, 2, 1, 1}, {1, 2, 2, 2}, {1, 2, 3, 3}}, }, { Query: "select * from (ab JOIN pq) where a in (select a from ab)", Expected: []sql.Row{ {0, 2, 0, 0}, {0, 2, 1, 1}, {0, 2, 2, 2}, {0, 2, 3, 3}, {1, 2, 0, 0}, {1, 2, 1, 1}, {1, 2, 2, 2}, {1, 2, 3, 3}, {2, 2, 0, 0}, {2, 2, 1, 1}, {2, 2, 2, 2}, {2, 2, 3, 3}, {3, 1, 0, 0}, {3, 1, 1, 1}, {3, 1, 2, 2}, {3, 1, 3, 3}}, }, { Query: "select * from (ab JOIN pq ON (a = 1)) where a in (1,2,3)", Expected: []sql.Row{ {1, 2, 0, 0}, {1, 2, 1, 1}, {1, 2, 2, 2}, {1, 2, 3, 3}}, }, { Query: "select * from (ab JOIN pq ON (a = 1)) where a in (select a from ab)", Expected: []sql.Row{ {1, 2, 0, 0}, {1, 2, 1, 1}, {1, 2, 2, 2}, {1, 2, 3, 3}}, }, { Query: `SELECT count(*) FROM JSON_TABLE( '[{"a":1.5, "b":2.25},{"a":3.125, "b":4.0625}]', '$[*]' COLUMNS(x float path '$.a', y float path '$.b') ) as t1 join JSON_TABLE( '[{"c":2, "d":3},{"c":4, "d":5}]', '$[*]' COLUMNS(z float path '$.c', w float path '$.d') ) as t2 on w = 0;`, Expected: []sql.Row{{0}}, }, { Query: `SELECT * from xy_hasnull where y not in (SELECT b from ab_hasnull)`, Expected: []sql.Row{}, }, { Query: `SELECT * from xy_hasnull where y not in (SELECT b from ab)`, Expected: []sql.Row{{1, 0}}, }, { Query: `SELECT * from xy where y not in (SELECT b from ab_hasnull)`, Expected: []sql.Row{}, }, { Query: `SELECT * from xy where null not in (SELECT b from ab)`, Expected: []sql.Row{}, }, }
var JoinScriptTests = []ScriptTest{ { Name: "Complex join query with foreign key constraints", SetUpScript: []string{ "CREATE TABLE `users` (`id` int NOT NULL AUTO_INCREMENT, `username` varchar(255) NOT NULL, PRIMARY KEY (`id`));", "CREATE TABLE `tweet` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `content` text NOT NULL, `timestamp` bigint NOT NULL, PRIMARY KEY (`id`), KEY `tweet_user_id` (`user_id`), CONSTRAINT `0qpfesgd` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`));", "INSERT INTO `users` (`id`,`username`) VALUES (1,'huey'), (2,'zaizee'), (3,'mickey')", "INSERT INTO `tweet` (`id`,`user_id`,`content`,`timestamp`) VALUES (1,1,'meow',1647463727), (2,1,'purr',1647463727), (3,2,'hiss',1647463727), (4,3,'woof',1647463727)", }, Assertions: []ScriptTestAssertion{ { Query: " SELECT `t1`.`username`, COUNT(`t1`.`id`) AS `ct` FROM ((SELECT `t2`.`id`, `t2`.`content`, `t3`.`username` FROM `tweet` AS `t2` INNER JOIN `users` AS `t3` ON (`t2`.`user_id` = `t3`.`id`) WHERE (`t3`.`username` = 'u3')) UNION (SELECT `t4`.`id`, `t4`.`content`, `t5`.`username` FROM `tweet` AS `t4` INNER JOIN `users` AS `t5` ON (`t4`.`user_id` = `t5`.`id`) WHERE (`t5`.`username` IN ('u2', 'u4')))) AS `t1` GROUP BY `t1`.`username` ORDER BY COUNT(`t1`.`id`) DESC;", Expected: []sql.Row{}, }, }, }, { Name: "USING join tests", SetUpScript: []string{ "create table t1 (i int primary key, j int);", "create table t2 (i int primary key, j int);", "create table t3 (i int primary key, j int);", "insert into t1 values (1, 10), (2, 20), (3, 30);", "insert into t2 values (1, 30), (2, 20), (5, 50);", "insert into t3 values (1, 200), (2, 20), (6, 600);", }, Assertions: []ScriptTestAssertion{ { Query: "select * from t1 join t2 using (badcol);", ExpectedErr: sql.ErrUnknownColumn, }, { Query: "select i from t1 join t2 using (i);", Expected: []sql.Row{ {1}, {2}, }, }, { Query: "select j from t1 join t2 using (i);", ExpectedErr: sql.ErrAmbiguousColumnName, }, { Query: "select * from t1 join t2 using (i);", Expected: []sql.Row{ {1, 10, 30}, {2, 20, 20}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j from t1 join t2 using (i);", Expected: []sql.Row{ {1, 10, 1, 30}, {2, 20, 2, 20}, }, }, { Query: "select * from t1 join t2 using (j);", Expected: []sql.Row{ {30, 3, 1}, {20, 2, 2}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j from t1 join t2 using (j);", Expected: []sql.Row{ {3, 30, 1, 30}, {2, 20, 2, 20}, }, }, { Query: "select * from t1 join t2 using (i, j);", Expected: []sql.Row{ {2, 20}, }, }, { Query: "select * from t1 join t2 using (j, i);", Expected: []sql.Row{ {2, 20}, }, }, { Query: "select * from t1 natural join t2;", Expected: []sql.Row{ {2, 20}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j from t1 join t2 using (i, j);", Expected: []sql.Row{ {2, 20, 2, 20}, }, }, { Query: "select i, j, t1.*, t2.*, t1.i, t1.j, t2.i, t2.j from t1 join t2 using (i, j);", Expected: []sql.Row{ {2, 20, 2, 20, 2, 20, 2, 20, 2, 20}, }, }, { Query: "select i, j, t1.*, t2.*, t1.i, t1.j, t2.i, t2.j from t1 natural join t2;", Expected: []sql.Row{ {2, 20, 2, 20, 2, 20, 2, 20, 2, 20}, }, }, { Query: "select i, j, a.*, b.*, a.i, a.j, b.i, b.j from t1 a join t2 b using (i, j);", Expected: []sql.Row{ {2, 20, 2, 20, 2, 20, 2, 20, 2, 20}, }, }, { Query: "select i, j, a.*, b.*, a.i, a.j, b.i, b.j from t1 a natural join t2 b;", Expected: []sql.Row{ {2, 20, 2, 20, 2, 20, 2, 20, 2, 20}, }, }, { Query: "select * from t1 left join t2 using (i);", Expected: []sql.Row{ {1, 10, 30}, {2, 20, 20}, {3, 30, nil}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j from t1 left join t2 using (i);", Expected: []sql.Row{ {1, 10, 1, 30}, {2, 20, 2, 20}, {3, 30, nil, nil}, }, }, { Query: "select * from t1 left join t2 using (i, j);", Expected: []sql.Row{ {1, 10}, {2, 20}, {3, 30}, }, }, { Query: "select * from t1 natural left join t2;", Expected: []sql.Row{ {1, 10}, {2, 20}, {3, 30}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j from t1 left join t2 using (i, j);", Expected: []sql.Row{ {1, 10, nil, nil}, {2, 20, 2, 20}, {3, 30, nil, nil}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j from t1 natural left join t2;", Expected: []sql.Row{ {1, 10, nil, nil}, {2, 20, 2, 20}, {3, 30, nil, nil}, }, }, { Query: "select * from t1 right join t2 using (i);", Expected: []sql.Row{ {1, 30, 10}, {2, 20, 20}, {5, 50, nil}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j from t1 right join t2 using (i);", Expected: []sql.Row{ {1, 10, 1, 30}, {2, 20, 2, 20}, {nil, nil, 5, 50}, }, }, { Query: "select * from t1 right join t2 using (j);", Expected: []sql.Row{ {30, 1, 3}, {20, 2, 2}, {50, 5, nil}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j from t1 right join t2 using (j);", Expected: []sql.Row{ {3, 30, 1, 30}, {2, 20, 2, 20}, {nil, nil, 5, 50}, }, }, { Query: "select * from t1 right join t2 using (i, j);", Expected: []sql.Row{ {1, 30}, {2, 20}, {5, 50}, }, }, { Query: "select * from t1 natural right join t2;", Expected: []sql.Row{ {1, 30}, {2, 20}, {5, 50}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j from t1 right join t2 using (i, j);", Expected: []sql.Row{ {nil, nil, 1, 30}, {2, 20, 2, 20}, {nil, nil, 5, 50}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j from t1 natural right join t2;", Expected: []sql.Row{ {nil, nil, 1, 30}, {2, 20, 2, 20}, {nil, nil, 5, 50}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j, t3.i, t3.j from t1 join t2 using (i) join t3 on t1.i = t3.i;", Expected: []sql.Row{ {1, 10, 1, 30, 1, 200}, {2, 20, 2, 20, 2, 20}, }, }, { Query: "select t1.i, t1.j, t2.i, t2.j, t3.i, t3.j from t1 join t2 on t1.i = t2.i join t3 using (i);", ExpectedErr: sql.ErrAmbiguousColumnName, }, { Query: "select t1.i, t1.j, t2.i, t2.j, t3.i, t3.j from t1 join t2 using (i) join t3 using (i);", Expected: []sql.Row{ {1, 10, 1, 30, 1, 200}, {2, 20, 2, 20, 2, 20}, }, }, { Query: "select * from t1 join t2 using (i) join t3 using (i);", Expected: []sql.Row{ {1, 10, 30, 200}, {2, 20, 20, 20}, }, }, { Query: "select t1.i, t1.j, tt.i from t1 join (select 1 as i) tt using (i);", Expected: []sql.Row{ {1, 10, 1}, }, }, { Query: "select t1.i, t1.j, tt.i, tt.j from t1 join (select * from t2) tt using (i);", Expected: []sql.Row{ {1, 10, 1, 30}, {2, 20, 2, 20}, }, }, { Query: "select tt1.i, tt1.j, tt2.i, tt2.j from (select * from t1) tt1 join (select * from t2) tt2 using (i);", Expected: []sql.Row{ {1, 10, 1, 30}, {2, 20, 2, 20}, }, }, { Query: "with cte as (select * from t1) select cte.i, cte.j, t2.i, t2.j from cte join t2 using (i);", Expected: []sql.Row{ {1, 10, 1, 30}, {2, 20, 2, 20}, }, }, { Query: "with cte1 as (select * from t1), cte2 as (select * from t2) select cte1.i, cte1.j, cte2.i, cte2.j from cte1 join cte2 using (i);", Expected: []sql.Row{ {1, 10, 1, 30}, {2, 20, 2, 20}, }, }, { Query: "WITH cte(i, j) AS (SELECT 1, 1 UNION ALL SELECT i, j from t1) SELECT cte.i, cte.j, t2.i, t2.j from cte join t2 using (i);", Expected: []sql.Row{ {1, 1, 1, 30}, {1, 10, 1, 30}, {2, 20, 2, 20}, }, }, { Query: "with recursive cte(i, j) AS (select 1, 1 union all select i + 1, j * 10 from cte where i < 3) select cte.i, cte.j, t2.i, t2.j from cte join t2 using (i);", Expected: []sql.Row{ {1, 1, 1, 30}, {2, 10, 2, 20}, }, }, { Skip: true, Query: "with cte as (select * from t1 join t2 using (i)) select * from cte;", ExpectedErr: sql.ErrDuplicateColumn, }, { Skip: true, Query: "select * from (select t1.i, t1.j, t2.i, t2.j from t1 join t2 using (i)) tt;", ExpectedErr: sql.ErrDuplicateColumn, }, }, }, { Name: "Join with truthy condition", SetUpScript: []string{ "CREATE TABLE `a` (aa int);", "INSERT INTO `a` VALUES (1), (2);", "CREATE TABLE `b` (bb int);", "INSERT INTO `b` VALUES (1), (2);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM a LEFT JOIN b ON 1;", Expected: []sql.Row{ {1, 2}, {1, 1}, {2, 2}, {2, 1}, }, }, { Query: "SELECT * FROM a RIGHT JOIN b ON 8+9;", Expected: []sql.Row{ {1, 2}, {1, 1}, {2, 2}, {2, 1}, }, }, }, }, }
var JsonScripts = []ScriptTest{ { Name: "JSON_ARRAY properly handles CHAR bind vars", SetUpScript: []string{ "CREATE TABLE `users` (`id` bigint unsigned AUTO_INCREMENT,`name` longtext,`languages` JSON, PRIMARY KEY (`id`))", `INSERT INTO users (name, languages) VALUES ('Tom', CAST('["ZH", "EN"]' AS JSON));`, }, Assertions: []ScriptTestAssertion{ { Query: `SELECT * FROM users WHERE JSON_CONTAINS (languages, JSON_ARRAY(?)) ORDER BY users.id LIMIT 1`, Bindings: map[string]*querypb.BindVariable{ "v1": {Type: querypb.Type_VARBINARY, Value: []byte("ZH")}, }, Expected: []sql.Row{{uint64(1), "Tom", types.JSONDocument{Val: []interface{}{"ZH", "EN"}}}}, }, }, }, { Name: "JSON_ARRAYAGG on one column", SetUpScript: []string{ "create table t (o_id int primary key)", "INSERT INTO t VALUES (1),(2)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT JSON_ARRAYAGG(o_id) FROM (SELECT * FROM t ORDER BY o_id) as sub", Expected: []sql.Row{ { types.MustJSON(`[1,2]`), }, }, }, }, }, { Name: "Simple JSON_ARRAYAGG on two columns", SetUpScript: []string{ "create table t (o_id int primary key, attribute longtext)", "INSERT INTO t VALUES (1, 'color'), (2, 'fabric')", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT JSON_ARRAYAGG(o_id), JSON_ARRAYAGG(`attribute`) FROM (SELECT * FROM t ORDER BY o_id) as sub;", Expected: []sql.Row{ { types.MustJSON(`[1,2]`), types.MustJSON(`["color","fabric"]`), }, }, }, }, }, { Name: "JSON_ARRAYAGG on column with string values w/ groupby", SetUpScript: []string{ "create table t (o_id int primary key, c0 int, attribute longtext, value longtext)", "INSERT INTO t VALUES (1, 2, 'color', 'red'), (2, 2, 'fabric', 'silk')", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT c0, JSON_ARRAYAGG(`attribute`) FROM (SELECT * FROM t ORDER BY o_id) as sub GROUP BY c0", Expected: []sql.Row{ { 2, types.MustJSON(`["color","fabric"]`), }, }, }, { Query: "SELECT c0, JSON_ARRAYAGG(value) FROM (SELECT * FROM t ORDER BY o_id) as sub GROUP BY c0", Expected: []sql.Row{ { 2, types.MustJSON(`["red","silk"]`), }, }, }, }, }, { Name: "JSON_ARRAYAGG on column with int values w/ groupby", SetUpScript: []string{ "create table t2 (o_id int primary key, val int)", "INSERT INTO t2 VALUES (1,1), (2,1), (3,1)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT val, JSON_ARRAYAGG(o_id) FROM (SELECT * FROM t2 ORDER BY o_id) AS sub GROUP BY val", Expected: []sql.Row{ { 1, types.MustJSON(`[1,2,3]`), }, }, }, }, }, { Name: "JSON_ARRAYAGG on unknown column throws error", SetUpScript: []string{ "create table t2 (o_id int primary key, val int)", "INSERT INTO t2 VALUES (1,1), (2,2), (3,3)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT o_id, JSON_ARRAYAGG(val2) FROM t2 GROUP BY o_id", ExpectedErr: sql.ErrColumnNotFound, }, }, }, { Name: "JSON_ARRAYAGG on column with no rows returns NULL", SetUpScript: []string{ "create table t2 (o_id int primary key)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT JSON_ARRAYAGG(o_id) FROM t2", Expected: []sql.Row{ { types.MustJSON(`[]`), }, }, }, }, }, { Name: "JSON_ARRAYAGG on row with 1 value, 1 null is fine", SetUpScript: []string{ "create table x(pk int primary key, c1 int)", "INSERT INTO x VALUES (1,NULL)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT pk, JSON_ARRAYAGG(c1) FROM x GROUP BY pk", Expected: []sql.Row{ {1, types.MustJSON(`[null]`)}, }, }, { Query: "SELECT JSON_ARRAYAGG(c1) FROM x", Expected: []sql.Row{ {types.MustJSON(`[null]`)}, }, }, }, }, { Name: "JSON_ARRAYAGG and group by use the same field.", SetUpScript: []string{ "create table x(pk int primary key, c1 int)", "INSERT INTO x VALUES (1, 1)", "INSERT INTO x VALUES (2, 1)", "INSERT INTO x VALUES (3, 3)", "INSERT INTO x VALUES (4, 3)", "INSERT INTO x VALUES (5, 5)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT JSON_ARRAYAGG(pk) FROM (SELECT * FROM x ORDER BY pk) as sub GROUP BY c1", Expected: []sql.Row{ {types.MustJSON(`[1,2]`)}, {types.MustJSON(`[3,4]`)}, {types.MustJSON(`[5]`)}, }, }, }, }, { Name: "JSON_ARRAGG with simple and nested json objects.", SetUpScript: []string{ "create table j(pk int primary key, field JSON)", `INSERT INTO j VALUES(1, '{"key1": {"key": "value"}}')`, `INSERT INTO j VALUES(2, '{"key1": "value1", "key2": "value2"}')`, `INSERT INTO j VALUES(3, '{"key1": {"key": [2,3]}}')`, `INSERT INTO j VALUES(4, '["a", 1]')`, }, Assertions: []ScriptTestAssertion{ { Query: "SELECT pk, JSON_ARRAYAGG(field) FROM (SELECT * FROM j ORDER BY pk) as sub GROUP BY field ORDER BY pk", Expected: []sql.Row{ {1, types.MustJSON(`[{"key1": {"key": "value"}}]`)}, {2, types.MustJSON(`[{"key1": "value1", "key2": "value2"}]`)}, {3, types.MustJSON(`[{"key1":{"key":[2,3]}}]`)}, {4, types.MustJSON(`[["a",1]]`)}, }, }, }, }, { Name: "Simple JSON_OBJECTAGG with GROUP BY", SetUpScript: []string{ "create table t2 (o_id int primary key, val int)", "INSERT INTO t2 VALUES (1,1), (2,1), (3,1)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT JSON_OBJECTAGG(val, o_id) FROM (SELECT * FROM t2 ORDER BY o_id) as sub GROUP BY val", Expected: []sql.Row{ {types.MustJSON(`{"1": 3}`)}, }, }, }, }, { Name: "More complex JSON_OBJECTAGG WITH GROUP BY", SetUpScript: []string{ "create table t (o_id int primary key, c0 int, attribute longtext, value longtext)", "INSERT INTO t VALUES (1, 2, 'color', 'red'), (2, 2, 'fabric', 'silk')", "INSERT INTO t VALUES (3, 3, 'color', 'green'), (4, 3, 'shape', 'square')", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT c0, JSON_OBJECTAGG(`attribute`, value) FROM (SELECT * FROM t ORDER BY o_id) as sub GROUP BY c0", Expected: []sql.Row{ {2, types.MustJSON(`{"color": "red", "fabric": "silk"}`)}, {3, types.MustJSON(`{"color": "green", "shape": "square"}`)}, }, }, { Query: `SELECT c0, JSON_OBJECTAGG(c0, value) FROM (SELECT * FROM t ORDER BY o_id) as sub GROUP BY c0`, Expected: []sql.Row{ {2, types.MustJSON(`{"2": "silk"}`)}, {3, types.MustJSON(`{"3": "square"}`)}, }, }, }, }, { Name: "3 column table that uses JSON_OBJECTAGG without groupby", SetUpScript: []string{ "create table t (o_id int primary key, c0 int, attribute longtext, value longtext)", "INSERT INTO t VALUES (1, 2, 'color', 'red'), (2, 2, 'fabric', 'silk')", "INSERT INTO t VALUES (3, 3, 'color', 'green'), (4, 3, 'shape', 'square')", }, Assertions: []ScriptTestAssertion{ { Query: `select JSON_OBJECTAGG(c0, value) from (SELECT * FROM t ORDER BY o_id) as sub`, Expected: []sql.Row{ {types.MustJSON(`{"2": "silk", "3": "square"}`)}, }, }, { Query: "select JSON_OBJECTAGG(`attribute`, value) from (SELECT * FROM t ORDER BY o_id) as sub", Expected: []sql.Row{ {types.MustJSON(`{"color": "green", "fabric": "silk", "shape": "square"}`)}, }, }, }, }, { Name: "JSON_OBJECTAGG and null values", SetUpScript: []string{ `create table test (pk int primary key, val longtext)`, `insert into test values (1, NULL)`, }, Assertions: []ScriptTestAssertion{ { Query: `SELECT JSON_OBJECTAGG(pk, val) from test`, Expected: []sql.Row{ {types.MustJSON(`{"1": null}`)}, }, }, }, }, { Name: "JSON_OBJECTAGG and nested json values", SetUpScript: []string{ "create table j(pk int primary key, c0 int, val JSON)", `INSERT INTO j VALUES(1, 1, '{"key1": "value1", "key2": "value2"}')`, `INSERT INTO j VALUES(2, 1, '{"key1": {"key": [2,3]}}')`, `INSERT INTO j VALUES(3, 2, '["a", 1]')`, }, Assertions: []ScriptTestAssertion{ { Query: `SELECT JSON_OBJECTAGG(c0, val) from (SELECT * FROM j ORDER BY pk) as sub`, Expected: []sql.Row{ {types.MustJSON(`{"1": {"key1": {"key": [2, 3]}}, "2": ["a", 1]}`)}, }, }, }, }, { Name: "JSON_OBJECTAGG correctly returns null when no rows are present", SetUpScript: []string{ `create table test (pk int primary key, val longtext)`, }, Assertions: []ScriptTestAssertion{ { Query: `SELECT JSON_OBJECTAGG(pk, val) from test`, Expected: []sql.Row{ {nil}, }, }, }, }, { Name: "JSON_OBJECTAGG handles errors appropriately", SetUpScript: []string{ `create table test (pk int primary key, c0 int, val longtext)`, `insert into test values (1, 1, NULL)`, `insert into test values (2, NULL, 1)`, }, Assertions: []ScriptTestAssertion{ { Query: `SELECT JSON_OBJECTAGG(c0, notval) from test`, ExpectedErr: sql.ErrColumnNotFound, }, { Query: `SELECT JSON_OBJECTAGG(notpk, val) from test`, ExpectedErr: sql.ErrColumnNotFound, }, { Query: `SELECT JSON_OBJECTAGG(c0, val) from nottest`, ExpectedErr: sql.ErrTableNotFound, }, { Query: `SELECT JSON_OBJECTAGG(c0, val, 'badarg') from test`, ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: `SELECT JSON_OBJECTAGG(c0, val, badarg) from test`, ExpectedErr: sql.ErrColumnNotFound, }, { Query: `SELECT JSON_OBJECTAGG(c0) from test`, ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: `SELECT JSON_OBJECTAGG(c0, val) from test`, ExpectedErr: sql.ErrJSONObjectAggNullKey, }, }, }, { Name: "JSON -> and ->> operator support", SetUpScript: []string{ "create table t (pk int primary key, col1 JSON, col2 JSON);", `insert into t values (1, JSON_OBJECT('key1', 1, 'key2', '"abc"'), JSON_ARRAY(3,10,5,17,"z"));`, `insert into t values (2, JSON_OBJECT('key1', 100, 'key2', '"ghi"'), JSON_ARRAY(3,10,5,17,JSON_ARRAY(22,"y",66)));`, `CREATE TABLE t2 (i INT PRIMARY KEY, j JSON);`, `INSERT INTO t2 VALUES (0, '{"a": "123", "outer": {"inner": 456}}');`, }, Assertions: []ScriptTestAssertion{ { Query: `select col1->'$.key1' from t;`, Expected: []sql.Row{{types.MustJSON("1")}, {types.MustJSON("100")}}, }, { Query: `select col1->>'$.key2' from t;`, Expected: []sql.Row{{"abc"}, {"ghi"}}, }, { Query: `select pk, col1 from t where col1->'$.key1' = 1;`, Expected: []sql.Row{{1, types.MustJSON(`{"key1":1, "key2":"\"abc\""}`)}}, }, { Query: `select pk, col1 from t where col1->>'$.key2' = 'abc';`, Expected: []sql.Row{{1, types.MustJSON(`{"key1":1, "key2":"\"abc\""}`)}}, }, { Query: `select * from t where col1->>'$.key2' = 'def';`, Expected: []sql.Row{}, }, { Query: `SELECT col2->"$[3]", col2->>"$[3]" FROM t;`, Expected: []sql.Row{{types.MustJSON("17"), "17"}, {types.MustJSON("17"), "17"}}, }, { Query: `SELECT col2->"$[4]", col2->>"$[4]" FROM t where pk=1;`, Expected: []sql.Row{{types.MustJSON("\"z\""), "z"}}, }, { Skip: true, Query: `SELECT col2->>"$[3]", col2->>"$[4][0]" FROM t;`, Expected: []sql.Row{{17, 44}, {17, "y"}}, }, { Query: `SELECT k->"$.inner" from (SELECT j->"$.outer" AS k FROM t2) sq;`, Expected: []sql.Row{{types.MustJSON("456")}}, }, }, }, { Name: "json is ordered correctly", SetUpScript: []string{ "create table t (pk int primary key, col1 json);", "insert into t values (1, null);", "insert into t values (2, '{}');", "insert into t values (3, (select json_extract('{\"a\": null}', '$.a')));", "insert into t values (4, 0);", }, Assertions: []ScriptTestAssertion{ { Query: "select * from t order by col1 asc;", Expected: []sql.Row{ {1, nil}, {3, types.MustJSON("null")}, {4, types.MustJSON("0")}, {2, types.MustJSON("{}")}, }, }, { Query: "select * from t order by col1 desc;", Expected: []sql.Row{ {2, types.MustJSON("{}")}, {4, types.MustJSON("0")}, {3, types.MustJSON("null")}, {1, nil}, }, }, }, }, { Name: "json is formatted correctly", SetUpScript: []string{ "create table t (pk int primary key, col1 json);", `insert into t values (1, '{"a": 1, "b": 2}');`, `insert into t values (2, '{"b": 2, "a": 1}');`, `insert into t values (3, '{"a":1,"b":2}');`, `insert into t values (4, '{"b":2,"a":1}');`, `insert into t values (5, '{ "b": 2 , "a" : 1 }');`, `insert into t values (6, '{"a":[1,2,3],"b":[4,5,6]}');`, `insert into t values (7, '{"b":[4,5,6],"a":[1,2,3]}');`, `insert into t values (8, '{ "a" : [ 1 , 2 , 3 ] , "b" : [ 4 , 5 , 6 ] }');`, `insert into t values (9, '{ "b" : [ 4 , 5 , 6 ] , "a" : [ 1 , 2 , 3 ] }');`, `insert into t values (10, '{"a":[{"a":1},{"b":2}],"b":[{"c":3},{"d":4}]}');`, `insert into t values (11, '{ "a" : [ { "a" : 1 } , { "b" : 2 } ] , "b" : [ { "c" : 3 } , { "d" : 4 } ] }');`, `insert into t values (12, '{"b":[{"c":3},{"d":4}],"a":[{"a":1},{"b":2}]}');`, `insert into t values (13, '{ "b" : [ { "c" : 3 } , { "d" : 4 } ] , "a" : [ { "a" : 1 } , { "b" : 2 } ] }');`, `insert into t values (14, '[{"a":"<>&"}]');`, }, Assertions: []ScriptTestAssertion{ { Query: "select pk, cast(col1 as char) from t order by pk asc;", Expected: []sql.Row{ {1, `{"a": 1, "b": 2}`}, {2, `{"a": 1, "b": 2}`}, {3, `{"a": 1, "b": 2}`}, {4, `{"a": 1, "b": 2}`}, {5, `{"a": 1, "b": 2}`}, {6, `{"a": [1, 2, 3], "b": [4, 5, 6]}`}, {7, `{"a": [1, 2, 3], "b": [4, 5, 6]}`}, {8, `{"a": [1, 2, 3], "b": [4, 5, 6]}`}, {9, `{"a": [1, 2, 3], "b": [4, 5, 6]}`}, {10, `{"a": [{"a": 1}, {"b": 2}], "b": [{"c": 3}, {"d": 4}]}`}, {11, `{"a": [{"a": 1}, {"b": 2}], "b": [{"c": 3}, {"d": 4}]}`}, {12, `{"a": [{"a": 1}, {"b": 2}], "b": [{"c": 3}, {"d": 4}]}`}, {13, `{"a": [{"a": 1}, {"b": 2}], "b": [{"c": 3}, {"d": 4}]}`}, {14, `[{"a": "<>&"}]`}, }, }, }, }, { Name: "json_extract returns missing keys as sql null and handles json null literals correctly", SetUpScript: []string{ "create table t (pk int primary key, col1 json);", "insert into t values (1, '{\"items\": {\"1\": 1, \"2\": 2}}');", "insert into t values (2, null);", "insert into t values (3, '{}');", "insert into t values (4, '{\"items\": null}');", "insert into t values (5, (select json_extract('{\"a\": null}', '$.a')));", }, Assertions: []ScriptTestAssertion{ { Query: "select pk, json_extract(col1, '$.items') from t order by pk;", Expected: []sql.Row{ {1, types.MustJSON("{\"1\":1,\"2\":2}")}, {2, nil}, {3, nil}, {4, types.MustJSON("null")}, {5, nil}, }, }, { Query: "select pk, json_extract(col1, '$') from t order by pk;", Expected: []sql.Row{ {1, types.MustJSON("{\"items\": {\"1\": 1, \"2\": 2}}")}, {2, nil}, {3, types.MustJSON("{}")}, {4, types.MustJSON("{\"items\": null}")}, {5, types.MustJSON("null")}, }, }, { Query: "select pk, json_extract(col1, '$.items') is null from t order by pk;", Expected: []sql.Row{ {1, false}, {2, true}, {3, true}, {4, false}, {5, true}, }, }, { Query: "select pk, json_extract(col1, '$.items') <> null from t order by pk;", Expected: []sql.Row{ {1, nil}, {2, nil}, {3, nil}, {4, nil}, {5, nil}, }, }, { Query: "select pk, json_extract(col1, '$.items.*') from t order by pk;", Expected: []sql.Row{ {1, types.MustJSON("[1, 2]")}, {2, nil}, {3, nil}, {4, types.MustJSON("null")}, {5, nil}, }, }, { Query: "select pk from t where json_extract(col1, '$.items') is null;", Expected: []sql.Row{{2}, {3}, {5}}, }, { Query: "select pk from t where json_extract(col1, '$.items') <> null;", Expected: []sql.Row{}, }, }, }, { Name: "json_contains_path returns true if the path exists", SetUpScript: []string{ `create table t (pk int primary key, col1 json);`, `insert into t values (1, '{"a": 1}');`, `insert into t values (2, '{"a": 1, "b": 2, "c": {"d": 4}}');`, `insert into t values (3, '{"w": 1, "x": 2, "c": {"d": 4}}');`, `insert into t values (4, '{}');`, `insert into t values (5, null);`, }, Assertions: []ScriptTestAssertion{ { Query: "select pk, json_contains_path(col1, 'one', '$.a') from t order by pk;", Expected: []sql.Row{ {1, true}, {2, true}, {3, false}, {4, false}, {5, nil}, }, }, { Query: "select pk, json_contains_path(col1, 'one', '$.a', '$.x', '$.c.d') from t order by pk;", Expected: []sql.Row{ {1, true}, {2, true}, {3, true}, {4, false}, {5, nil}, }, }, { Query: "select pk, json_contains_path(col1, 'all', '$.a', '$.x') from t order by pk;", Expected: []sql.Row{ {1, false}, {2, false}, {3, false}, {4, false}, {5, nil}, }, }, { Query: "select pk, json_contains_path(col1, 'all', '$.c.d', '$.x') from t order by pk;", Expected: []sql.Row{ {1, false}, {2, false}, {3, true}, {4, false}, {5, nil}, }, }, { Query: "select pk, json_contains_path(col1, 'other', '$.c.d', '$.x') from t order by pk;", ExpectedErrStr: "The oneOrAll argument to json_contains_path may take these values: 'one' or 'all'", }, }, }, }
var KeylessQueries = []QueryTest{ { Query: "SELECT * FROM keyless ORDER BY c0", Expected: []sql.Row{ {0, 0}, {1, 1}, {1, 1}, {2, 2}, }, }, { Query: "SELECT * FROM keyless ORDER BY c1 DESC", Expected: []sql.Row{ {2, 2}, {1, 1}, {1, 1}, {0, 0}, }, }, { Query: "SELECT * FROM keyless JOIN myTable where c0 = i", Expected: []sql.Row{ {1, 1, 1, "first row"}, {1, 1, 1, "first row"}, {2, 2, 2, "second row"}, }, }, { Query: "SELECT * FROM myTable JOIN keyless WHERE i = c0 ORDER BY i", Expected: []sql.Row{ {1, "first row", 1, 1}, {1, "first row", 1, 1}, {2, "second row", 2, 2}, }, }, { Query: "DESCRIBE keyless", Expected: []sql.Row{ {"c0", "bigint", "YES", "", "NULL", ""}, {"c1", "bigint", "YES", "", "NULL", ""}, }, }, { Query: "SHOW COLUMNS FROM keyless", Expected: []sql.Row{ {"c0", "bigint", "YES", "", "NULL", ""}, {"c1", "bigint", "YES", "", "NULL", ""}, }, }, { Query: "SHOW FULL COLUMNS FROM keyless", Expected: []sql.Row{ {"c0", "bigint", nil, "YES", "", "NULL", "", "", ""}, {"c1", "bigint", nil, "YES", "", "NULL", "", "", ""}, }, }, { Query: "SHOW CREATE TABLE keyless", Expected: []sql.Row{ {"keyless", "CREATE TABLE `keyless` (\n `c0` bigint,\n `c1` bigint\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, }
var LateralJoinScriptTests = []ScriptTest{ { Name: "basic lateral join test", SetUpScript: []string{ "create table t (i int primary key)", "create table t1 (j int primary key)", "insert into t values (1), (2), (3)", "insert into t1 values (1), (4), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from t, lateral (select * from t1 where t.i = t1.j) as tt order by t.i, tt.j;", Expected: []sql.Row{ {1, 1}, }, }, { Query: "select * from t, lateral (select * from t1 where t.i != t1.j) as tt order by tt.j, t.i;", Expected: []sql.Row{ {2, 1}, {3, 1}, {1, 4}, {2, 4}, {3, 4}, {1, 5}, {2, 5}, {3, 5}, }, }, { Query: "select * from t, t1, lateral (select * from t1 where t.i != t1.j) as tt where t.i > t1.j and t1.j = tt.j order by t.i, t1.j, tt.j;", Expected: []sql.Row{ {2, 1, 1}, {3, 1, 1}, }, }, { Skip: true, Query: "select * from t, lateral (select * from t1 where t.i = t1.j) tt, lateral (select * from t1 where t.i != t1.j) as ttt order by t.i, tt.j, ttt.j;", Expected: []sql.Row{ {1, 1, 4}, {1, 1, 5}, }, }, { Skip: true, Query: `WITH RECURSIVE cte(x) AS (SELECT 1 union all SELECT x + 1 from cte where x < 5) SELECT * FROM cte, lateral (select * from t where t.i = cte.x) tt;`, Expected: []sql.Row{ {1, 1}, {2, 2}, {3, 3}, }, }, { Query: "select * from (select * from t, lateral (select * from t1 where t.i = t1.j) as tt order by t.i, tt.j) ttt;", Expected: []sql.Row{ {1, 1}, }, }, { Query: "select * from t inner join lateral (select * from t1 where t.i != t1.j) as tt on t.i > tt.j", Expected: []sql.Row{ {2, 1}, {3, 1}, }, }, { Query: "select * from t inner join lateral (select * from t1 where t.i = t1.j) as tt on t.i = tt.j", Expected: []sql.Row{ {1, 1}, }, }, { Query: "select * from t inner join lateral (select * from t1 where t.i = t1.j) as tt on t.i != tt.j", Expected: []sql.Row{}, }, { Query: "select * from t left join lateral (select * from t1 where t.i = t1.j) as tt on t.i = tt.j order by t.i, tt.j", Expected: []sql.Row{ {1, 1}, {2, nil}, {3, nil}, }, }, { Query: "select * from t left join lateral (select * from t1 where t.i != t1.j) as tt on t.i + 1 = tt.j or t.i + 2 = tt.j order by t.i, tt.j", Expected: []sql.Row{ {1, nil}, {2, 4}, {3, 4}, {3, 5}, }, }, { Query: "select * from t right join lateral (select * from t1 where t.i != t1.j) as tt on t.i > tt.j", ExpectedErr: sql.ErrTableNotFound, }, { Query: "select * from t right join lateral (select * from t1) as tt on t.i > tt.j order by t.i, tt.j", Expected: []sql.Row{ {nil, 4}, {nil, 5}, {2, 1}, {3, 1}, }, }, }, }, }
var LoadDataErrorScripts = []ScriptTest{ { Name: "Load data into table that doesn't exist throws error.", Query: "LOAD DATA INFILE 'test1.txt' INTO TABLE loadtable", ExpectedErr: sql.ErrTableNotFound, }, { Name: "Load data with unknown files throws an error.", SetUpScript: []string{ "create table loadtable(pk longtext, c1 int)", }, Assertions: []ScriptTestAssertion{ { Query: "LOAD DATA INFILE '/x/ytx' INTO TABLE loadtable", ExpectedErr: sql.ErrLoadDataCannotOpen, }, }, }, { Name: "Load data with unknown columns throws an error", SetUpScript: []string{ "create table loadtable(pk int primary key)", }, Assertions: []ScriptTestAssertion{ { Query: "LOAD DATA INFILE './testdata/test1.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"' (bad)", ExpectedErr: plan.ErrInsertIntoNonexistentColumn, }, }, }, { Name: "Load data escaped by terms longer than 1 character throws an error", SetUpScript: []string{ "create table loadtable(pk int primary key)", }, Assertions: []ScriptTestAssertion{ { Query: "LOAD DATA INFILE './testdata/test1.txt' INTO TABLE loadtable FIELDS ESCAPED BY 'xx' (pk)", ExpectedErr: sql.ErrLoadDataCharacterLength, }, }, }, { Name: "Load data enclosed by term longer than 1 character throws an error", SetUpScript: []string{ "create table loadtable(pk int primary key)", }, Assertions: []ScriptTestAssertion{ { Query: "LOAD DATA INFILE './testdata/test1.txt' INTO TABLE loadtable FIELDS ENCLOSED BY 'xx' (pk)", ExpectedErr: sql.ErrLoadDataCharacterLength, }, }, }, { Name: "Load data errors on primary key duplicate", SetUpScript: []string{ "create table loadtable(pk int primary key, c1 varchar(10))", "insert into loadtable values (1, 'test')", }, Assertions: []ScriptTestAssertion{ { Query: "LOAD DATA INFILE './testdata/test2.csv' INTO TABLE loadtable FIELDS TERMINATED BY ',' IGNORE 1 LINES", ExpectedErrStr: "duplicate primary key given: [1]", }, }, }, }
var LoadDataFailingScripts = []ScriptTest{ { Name: "Escaped values are correctly parsed.", SetUpScript: []string{ "create table loadtable(pk longtext)", "LOAD DATA INFILE 'test5.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"' IGNORE 1 LINES", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{{"hi"}, {"hello"}, {nil}, {"TryN"}, {fmt.Sprintf("%c", 26)}, {fmt.Sprintf("%c", 0)}, {"new\n"}}, }, }, }, { Name: "Load and terminate have the same values.", SetUpScript: []string{ "create table loadtable(pk int primary key)", "LOAD DATA INFILE 'test1.txt' INTO TABLE loadtable FIELDS TERMINATED BY '\"' ENCLOSED BY '\"'", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{{int8(1)}, {int8(2)}, {int8(3)}, {int8(4)}}, }, }, }, { Name: "Loading value into different column type results in default value.", SetUpScript: []string{ "create table loadtable(pk longtext, c1 int)", "LOAD DATA INFILE 'test4.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"' (c1)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{{nil, 0}, {nil, 0}}, }, }, }, { Name: "LOAD DATA handles nulls", SetUpScript: []string{ "create table loadtable(pk longtext, c1 int)", "LOAD DATA INFILE 'test4.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"'", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{{"hi", 1}, {"hello", nil}}, }, }, }, { Name: "LOAD DATA can handle a differing column order", SetUpScript: []string{ "create table loadtable(pk int, c1 string) ", "LOAD DATA INFILE 'test4.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"' (c1, pk)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{{1, "hi"}, {nil, "hello"}}, }, }, }, }
var LoadDataScripts = []ScriptTest{ { Name: "Basic load data with enclosed values.", SetUpScript: []string{ "create table loadtable(pk int primary key)", "LOAD DATA INFILE './testdata/test1.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"'", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{{int8(1)}, {int8(2)}, {int8(3)}, {int8(4)}}, }, }, }, { Name: "Basic load data check error", SetUpScript: []string{ "create table loadtable(pk int primary key, check (pk > 1))", }, Assertions: []ScriptTestAssertion{ { Query: "LOAD DATA INFILE './testdata/test1.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"'", ExpectedErrStr: "Check constraint \"loadtable_chk_1\" violated", }, }, }, { Name: "Load data with csv", SetUpScript: []string{ "create table loadtable(pk int primary key, c1 longtext)", "LOAD DATA INFILE './testdata/test2.csv' INTO TABLE loadtable FIELDS TERMINATED BY ',' IGNORE 1 LINES", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{{int8(1), "hi"}, {int8(2), "hello"}}, }, }, }, { Name: "Load data with csv but use IGNORE ROWS syntax", SetUpScript: []string{ "create table loadtable(pk int primary key, c1 longtext)", "LOAD DATA INFILE './testdata/test2.csv' INTO TABLE loadtable FIELDS TERMINATED BY ',' IGNORE 1 ROWS", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{{int8(1), "hi"}, {int8(2), "hello"}}, }, }, }, { Name: "Load data with csv with prefix.", SetUpScript: []string{ "create table loadtable(pk longtext, c1 int)", "LOAD DATA INFILE './testdata/test3.csv' INTO TABLE loadtable FIELDS TERMINATED BY ',' LINES STARTING BY 'xxx' IGNORE 1 LINES (`pk`, `c1`)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{{"\"abc\"", int8(1)}, {"\"def\"", int8(2)}, {"\"hello\"", nil}}, }, }, }, { Name: "LOAD DATA with all columns reordered in projection", SetUpScript: []string{ "create table loadtable(pk longtext, c1 int)", "LOAD DATA INFILE './testdata/test3backwards.csv' INTO TABLE loadtable FIELDS TERMINATED BY ',' LINES STARTING BY 'xxx' IGNORE 1 LINES (`c1`, `pk`)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{{"\"abc\"", int8(1)}, {"\"def\"", int8(2)}, {"\"hello\"", nil}}, }, }, }, { Name: "Table has more columns than import.", SetUpScript: []string{ "create table loadtable(pk int primary key, c1 int)", "LOAD DATA INFILE './testdata/test1.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"'", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable ORDER BY pk", Expected: []sql.Row{{1, nil}, {2, nil}, {3, nil}, {4, nil}}, }, }, }, { Name: "LOAD DATA handles Windows line-endings and a subset of columns that are not in order", SetUpScript: []string{ "CREATE TABLE inmate_population_snapshots (id char(21) NOT NULL, snapshot_date date NOT NULL, total int," + "total_off_site int, male int, female int, other_gender int, white int, black int, hispanic int," + "asian int, american_indian int, mexican_american int, multi_racial int, other_race int," + "on_probation int, on_parole int, felony int, misdemeanor int, other_offense int," + "convicted_or_sentenced int, detained_or_awaiting_trial int, first_time_incarcerated int, employed int," + "unemployed int, citizen int, noncitizen int, juvenile int, juvenile_male int, juvenile_female int," + "death_row_condemned int, solitary_confinement int, technical_parole_violators int," + "source_url varchar(2043) NOT NULL, source_url_2 varchar(2043), civil_offense int, federal_offense int," + "PRIMARY KEY (id,snapshot_date), KEY id (id));", "LOAD DATA INFILE './testdata/test6.csv' INTO TABLE inmate_population_snapshots " + "FIELDS TERMINATED BY ',' " + "LINES TERMINATED BY '\r\n' " + "IGNORE 1 LINES " + "(federal_offense, misdemeanor, total, detained_or_awaiting_trial, felony, snapshot_date, id, source_url, source_url_2)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM inmate_population_snapshots", Expected: []sql.Row{ {"8946", time.Date(2020, 5, 1, 0, 0, 0, 0, time.UTC), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0, nil, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, "https://www.website.gov", "https://www.website.gov/other.html", nil, nil}, {"8976", time.Date(2020, 5, 1, 0, 0, 0, 0, time.UTC), 196, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0, 73, nil, nil, 123, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, "https://www.website.gov", "https://www.website.gov/other.html", nil, 0}, {"8978", time.Date(2020, 5, 1, 0, 0, 0, 0, time.UTC), 0, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0, nil, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, "https://www.website.gov", "https://www.website.gov/other.html", nil, nil}, {"8979", time.Date(2020, 5, 1, 0, 0, 0, 0, time.UTC), 71, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 5, 3, nil, nil, 63, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, "https://www.website.gov", "https://www.website.gov/other.html", nil, 0}, }, }, }, }, { Name: "LOAD DATA handles non-nil default values", SetUpScript: []string{ "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2 * 10), v2 BIGINT DEFAULT 5);", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2 * 10), v2 BIGINT DEFAULT 5);", "CREATE TABLE test3 (pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk * 10), v2 BIGINT DEFAULT (v1 - 1));", "CREATE TABLE test4 (pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk * 10), v2 BIGINT DEFAULT (v1 - 1));", "LOAD DATA INFILE './testdata/test7.txt' INTO TABLE test1;", "LOAD DATA INFILE './testdata/test7.txt' INTO TABLE test2 (pk);", "LOAD DATA INFILE './testdata/test7.txt' INTO TABLE test3;", "LOAD DATA INFILE './testdata/test7.txt' INTO TABLE test4 (pk);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test1", Expected: []sql.Row{ {1, 50, 5}, {2, 50, 5}, {3, 50, 5}, }, }, { Query: "SELECT * FROM test2", Expected: []sql.Row{ {1, 50, 5}, {2, 50, 5}, {3, 50, 5}, }, }, { Query: "SELECT * FROM test3", Expected: []sql.Row{ {1, 10, 9}, {2, 20, 19}, {3, 30, 29}, }, }, { Query: "SELECT * FROM test4", Expected: []sql.Row{ {1, 10, 9}, {2, 20, 19}, {3, 30, 29}, }, }, }, }, { Name: "LOAD DATA handles non-nil default values with varying field counts per row", SetUpScript: []string{ "CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2 * 10), v2 BIGINT DEFAULT 5);", "CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk * 10), v2 BIGINT DEFAULT (v1 - 1));", "LOAD DATA INFILE './testdata/test8.txt' INTO TABLE test1 FIELDS TERMINATED BY ',';", "LOAD DATA INFILE './testdata/test8.txt' INTO TABLE test2 FIELDS TERMINATED BY ',';", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test1", Expected: []sql.Row{ {1, 50, 5}, {2, 100, 5}, {3, 50, 5}, }, }, { Query: "SELECT * FROM test2", Expected: []sql.Row{ {1, 10, 9}, {2, 100, 99}, {3, 30, 29}, }, }, }, }, { Name: "Load data can ignore row with existing primary key", SetUpScript: []string{ "create table loadtable(pk int primary key, c1 varchar(10))", "insert into loadtable values (1, 'test')", "LOAD DATA INFILE './testdata/test2.csv' IGNORE INTO TABLE loadtable FIELDS TERMINATED BY ',' IGNORE 1 LINES", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{ {1, "test"}, {2, "hello"}, }, }, }, }, { Name: "Load data can replace row with existing primary key", SetUpScript: []string{ "create table loadtable(pk int primary key, c1 varchar(10))", "insert into loadtable values (1, 'test')", "LOAD DATA INFILE './testdata/test2.csv' REPLACE INTO TABLE loadtable FIELDS TERMINATED BY ',' IGNORE 1 LINES", }, Assertions: []ScriptTestAssertion{ { Query: "select * from loadtable", Expected: []sql.Row{ {1, "hi"}, {2, "hello"}, }, }, }, }, }
var MySqlDbTests = []ScriptTest{ { Name: "test mysql database help_ tables ", Assertions: []ScriptTestAssertion{ { Query: "show create table mysql.help_topic;", Expected: []sql.Row{{"help_topic", "CREATE TABLE `help_topic` (\n `help_topic_id` bigint unsigned NOT NULL,\n `name` char(64) COLLATE utf8mb3_general_ci NOT NULL,\n `help_category_id` tinyint unsigned NOT NULL,\n `description` text COLLATE utf8mb3_general_ci NOT NULL,\n `example` text COLLATE utf8mb3_general_ci NOT NULL,\n `url` text COLLATE utf8mb3_general_ci NOT NULL,\n PRIMARY KEY (`help_topic_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin"}}, }, { Query: "show create table mysql.help_category;", Expected: []sql.Row{{"help_category", "CREATE TABLE `help_category` (\n `help_category_id` tinyint unsigned NOT NULL,\n `name` char(64) COLLATE utf8mb3_general_ci NOT NULL,\n `parent_category_id` tinyint unsigned NOT NULL,\n `url` text COLLATE utf8mb3_general_ci NOT NULL,\n PRIMARY KEY (`help_category_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin"}}, }, { Query: "show create table mysql.help_keyword;", Expected: []sql.Row{{"help_keyword", "CREATE TABLE `help_keyword` (\n `help_keyword_id` bigint unsigned NOT NULL,\n `name` char(64) COLLATE utf8mb3_general_ci NOT NULL,\n PRIMARY KEY (`help_keyword_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin"}}, }, { Query: "show create table mysql.help_relation;", Expected: []sql.Row{{"help_relation", "CREATE TABLE `help_relation` (\n `help_keyword_id` bigint unsigned NOT NULL,\n `help_topic_id` bigint unsigned NOT NULL,\n PRIMARY KEY (`help_keyword_id`,`help_topic_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin"}}, }, }, }, }
var NoDbProcedureTests = []ScriptTestAssertion{ { Query: "SHOW databases;", Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}}, }, { Query: "SELECT database();", Expected: []sql.Row{{nil}}, }, { Query: "CREATE PROCEDURE mydb.p5() SELECT 42;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW CREATE PROCEDURE mydb.p5;", SkipResultsCheck: true, }, { Query: "SHOW CREATE PROCEDURE p5;", ExpectedErr: sql.ErrNoDatabaseSelected, }, }
var NullRangeTests = []QueryTest{ { Query: "select * from null_ranges where y IS NULL or y < 1", Expected: []sql.Row{ {0, 0}, {3, nil}, {4, nil}, }, }, { Query: "select * from null_ranges where y IS NULL and y < 1", Expected: []sql.Row{}, }, { Query: "select * from null_ranges where y IS NULL or y IS NOT NULL", Expected: []sql.Row{ {0, 0}, {1, 1}, {2, 2}, {3, nil}, {4, nil}, }, }, { Query: "select * from null_ranges where y IS NOT NULL", Expected: []sql.Row{ {0, 0}, {1, 1}, {2, 2}, }, }, { Query: "select * from null_ranges where y IS NULL or y = 0 or y = 1", Expected: []sql.Row{ {0, 0}, {1, 1}, {3, nil}, {4, nil}, }, }, { Query: "select * from null_ranges where y IS NULL or y < 1 or y > 1", Expected: []sql.Row{ {0, 0}, {2, 2}, {3, nil}, {4, nil}, }, }, { Query: "select * from null_ranges where y IS NOT NULL and x > 1", Expected: []sql.Row{ {2, 2}, }, }, { Query: "select * from null_ranges where y IS NULL and x = 4", Expected: []sql.Row{ {4, nil}, }, }, { Query: "select * from null_ranges where y IS NULL and x > 1", Expected: []sql.Row{ {3, nil}, {4, nil}, }, }, { Query: "select * from null_ranges where y IS NULL and y IS NOT NULL", Expected: []sql.Row{}, }, { Query: "select * from null_ranges where y is NULL and y > -1 and y > -2", Expected: []sql.Row{}, }, { Query: "select * from null_ranges where y > -1 and y < 7 and y IS NULL", Expected: []sql.Row{}, }, { Query: "select * from null_ranges where y > -1 and y > -2 and y IS NOT NULL", Expected: []sql.Row{ {0, 0}, {1, 1}, {2, 2}, }, }, { Query: "select * from null_ranges where y > -1 and y > 1 and y IS NOT NULL", Expected: []sql.Row{ {2, 2}, }, }, { Query: "select * from null_ranges where y < 6 and y > -1 and y IS NOT NULL", Expected: []sql.Row{ {0, 0}, {1, 1}, {2, 2}, }, }, }
var OrderByGroupByScriptTests = []ScriptTest{ { Name: "Basic order by/group by cases", SetUpScript: []string{ "use mydb;", "create table members (id bigint primary key, team text);", "insert into members values (3,'red'), (4,'red'),(5,'orange'),(6,'orange'),(7,'orange'),(8,'purple');", }, Assertions: []ScriptTestAssertion{ { Query: "select team as f from members order by id, f", Expected: []sql.Row{{"red"}, {"red"}, {"orange"}, {"orange"}, {"orange"}, {"purple"}}, }, { Query: "SELECT team, COUNT(*) FROM members GROUP BY team ORDER BY 2", Expected: []sql.Row{ {"purple", int64(1)}, {"red", int64(2)}, {"orange", int64(3)}, }, }, { Query: "SELECT team, COUNT(*) FROM members GROUP BY 1 ORDER BY 2", Expected: []sql.Row{ {"purple", int64(1)}, {"red", int64(2)}, {"orange", int64(3)}, }, }, { Query: "SELECT team, COUNT(*) FROM members GROUP BY team ORDER BY columndoesnotexist", ExpectedErr: sql.ErrColumnNotFound, }, { Query: "SELECT DISTINCT BINARY t1.id as id FROM members AS t1 JOIN members AS t2 ON t1.id = t2.id WHERE t1.id > 0 ORDER BY BINARY t1.id", Expected: []sql.Row{{[]uint8{0x33}}, {[]uint8{0x34}}, {[]uint8{0x35}}, {[]uint8{0x36}}, {[]uint8{0x37}}, {[]uint8{0x38}}}, }, { Query: "SELECT DISTINCT BINARY t1.id as id FROM members AS t1 JOIN members AS t2 ON t1.id = t2.id WHERE t1.id > 0 ORDER BY t1.id", Expected: []sql.Row{{[]uint8{0x33}}, {[]uint8{0x34}}, {[]uint8{0x35}}, {[]uint8{0x36}}, {[]uint8{0x37}}, {[]uint8{0x38}}}, }, { Query: "SELECT DISTINCT t1.id as id FROM members AS t1 JOIN members AS t2 ON t1.id = t2.id WHERE t2.id > 0 ORDER BY t1.id", Expected: []sql.Row{{3}, {4}, {5}, {6}, {7}, {8}}, }, { Query: "SELECT id as alias1, (SELECT alias1+1 group by alias1 having alias1 > 0) FROM members where id < 6;", Expected: []sql.Row{{3, 4}, {4, 5}, {5, 6}}, }, { Query: "SELECT id, (SELECT UPPER(team) having id > 3) as upper_team FROM members where id < 6;", Expected: []sql.Row{{3, nil}, {4, "RED"}, {5, "ORANGE"}}, }, { Query: "SELECT id, (SELECT -1 as id having id < 10) as upper_team FROM members where id < 6;", Expected: []sql.Row{{3, -1}, {4, -1}, {5, -1}}, }, }, }, { Name: "Group by BINARY: https://github.com/dolthub/dolt/issues/6179", SetUpScript: []string{ "create table t (s varchar(100));", "insert into t values ('abc'), ('def');", "create table t1 (b binary(3));", "insert into t1 values ('abc'), ('abc'), ('def'), ('abc'), ('def');", }, Assertions: []ScriptTestAssertion{ { Query: "select binary s from t group by binary s order by binary s", Expected: []sql.Row{ {[]uint8("abc")}, {[]uint8("def")}, }, }, { Query: "select count(b), b from t1 group by b order by b", Expected: []sql.Row{ {3, []uint8("abc")}, {2, []uint8("def")}, }, }, { Query: "select binary s from t group by binary s order by s", Expected: []sql.Row{ {[]uint8("abc")}, {[]uint8("def")}, }, }, }, }, { Name: "https://github.com/dolthub/dolt/issues/3016", SetUpScript: []string{ "CREATE TABLE `users` (`id` int NOT NULL AUTO_INCREMENT, `username` varchar(255) NOT NULL, PRIMARY KEY (`id`));", "INSERT INTO `users` (`id`,`username`) VALUES (1,'u2');", "INSERT INTO `users` (`id`,`username`) VALUES (2,'u3');", "INSERT INTO `users` (`id`,`username`) VALUES (3,'u4');", "CREATE TABLE `tweet` (`id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `content` text NOT NULL, `timestamp` bigint NOT NULL, PRIMARY KEY (`id`), KEY `tweet_user_id` (`user_id`));", "INSERT INTO `tweet` (`id`,`user_id`,`content`,`timestamp`) VALUES (1,1,'meow',1647463727);", "INSERT INTO `tweet` (`id`,`user_id`,`content`,`timestamp`) VALUES (2,1,'purr',1647463727);", "INSERT INTO `tweet` (`id`,`user_id`,`content`,`timestamp`) VALUES (3,2,'hiss',1647463727);", "INSERT INTO `tweet` (`id`,`user_id`,`content`,`timestamp`) VALUES (4,3,'woof',1647463727);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT t1.username, COUNT(t1.id) FROM ((SELECT t2.id, t2.content, t3.username FROM tweet AS t2 INNER JOIN users AS t3 ON (-t2.user_id = -t3.id) WHERE (t3.username = 'u3')) UNION (SELECT t4.id, t4.content, `t5`.`username` FROM `tweet` AS t4 INNER JOIN users AS t5 ON (-t4.user_id = -t5.id) WHERE (t5.username IN ('u2', 'u4')))) AS t1 GROUP BY `t1`.`username` ORDER BY 1,2 DESC;", Expected: []sql.Row{{"u2", 2}, {"u3", 1}, {"u4", 1}}, }, { Query: "SELECT t1.username, COUNT(t1.id) AS ct FROM ((SELECT t2.id, t2.content, t3.username FROM tweet AS t2 INNER JOIN users AS t3 ON (-t2.user_id = -t3.id) WHERE (t3.username = 'u3')) UNION (SELECT t4.id, t4.content, `t5`.`username` FROM `tweet` AS t4 INNER JOIN users AS t5 ON (-t4.user_id = -t5.id) WHERE (t5.username IN ('u2', 'u4')))) AS t1 GROUP BY `t1`.`username` ORDER BY 1,2 DESC;", Expected: []sql.Row{{"u2", 2}, {"u3", 1}, {"u4", 1}}, }, { Query: "SELECT COUNT(id) as ct, user_id as uid FROM tweet GROUP BY tweet.user_id ORDER BY COUNT(id), user_id;", Expected: []sql.Row{{1, 2}, {1, 3}, {2, 1}}, }, { Query: "SELECT COUNT(tweet.id) as ct, user_id as uid FROM tweet GROUP BY tweet.user_id ORDER BY COUNT(id), user_id;", Expected: []sql.Row{{1, 2}, {1, 3}, {2, 1}}, }, { Query: "SELECT COUNT(id) as ct, user_id as uid FROM tweet GROUP BY tweet.user_id ORDER BY COUNT(tweet.id), user_id;", Expected: []sql.Row{{1, 2}, {1, 3}, {2, 1}}, }, { Query: "SELECT COUNT(id) as ct, user_id as uid FROM tweet GROUP BY tweet.user_id HAVING COUNT(tweet.id) > 0 ORDER BY COUNT(tweet.id), user_id;", Expected: []sql.Row{{1, 2}, {1, 3}, {2, 1}}, }, { Query: "SELECT COUNT(id) as ct, user_id as uid FROM tweet WHERE tweet.id is NOT NULL GROUP BY tweet.user_id ORDER BY COUNT(tweet.id), user_id;", Expected: []sql.Row{{1, 2}, {1, 3}, {2, 1}}, }, { Query: "SELECT COUNT(id) as ct, user_id as uid FROM tweet WHERE tweet.id is NOT NULL GROUP BY tweet.user_id HAVING COUNT(tweet.id) > 0 ORDER BY COUNT(tweet.id), user_id;", Expected: []sql.Row{{1, 2}, {1, 3}, {2, 1}}, }, { Query: "SELECT COUNT(id) as ct, user_id as uid FROM tweet WHERE tweet.id is NOT NULL GROUP BY tweet.user_id HAVING COUNT(tweet.id) > 0 ORDER BY COUNT(tweet.id), user_id LIMIT 1;", Expected: []sql.Row{{1, 2}}, }, }, }, { Name: "Group by with decimal columns", Assertions: []ScriptTestAssertion{ { Query: "SELECT column_0, sum(column_1) FROM (values row(1.00,1), row(1.00,3), row(2,2), row(2,5), row(3,9)) a group by 1 order by 1;", Expected: []sql.Row{{"1.00", float64(4)}, {"2.00", float64(7)}, {"3.00", float64(9)}}, }, }, }, { Name: "Validation for use of non-aggregated columns with implicit grouping of all rows", SetUpScript: []string{ "CREATE TABLE t (num INTEGER, val DOUBLE);", "INSERT INTO t VALUES (1, 0.01), (2,0.5);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT AVG(val), LAST_VALUE(val) OVER w FROM t WINDOW w AS (ORDER BY num RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING);", ExpectedErr: sql.ErrNonAggregatedColumnWithoutGroupBy, }, { Query: "SELECT 1 + AVG(val) + 1, LAST_VALUE(val) OVER w FROM t WINDOW w AS (ORDER BY num RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING);", ExpectedErr: sql.ErrNonAggregatedColumnWithoutGroupBy, }, { Query: "SELECT AVG(1), 1 + LAST_VALUE(val) OVER w FROM t WINDOW w AS (ORDER BY num RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING);", ExpectedErr: sql.ErrNonAggregatedColumnWithoutGroupBy, }, { Skip: true, Query: "select AVG(val), val from t;", ExpectedErr: sql.ErrNonAggregatedColumnWithoutGroupBy, }, { Query: "select * from (SELECT AVG(val), LAST_VALUE(val) OVER w FROM t WINDOW w AS (ORDER BY num RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)) as dt;", ExpectedErr: sql.ErrNonAggregatedColumnWithoutGroupBy, }, { Query: "select 1, 1 union SELECT AVG(val), LAST_VALUE(val) OVER w FROM t WINDOW w AS (ORDER BY num RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING);", ExpectedErr: sql.ErrNonAggregatedColumnWithoutGroupBy, }, { Query: "select * from (with recursive a as (select 1 as c1, 1 as c2 union SELECT AVG(t.val), LAST_VALUE(t.val) OVER w FROM t WINDOW w AS (ORDER BY num RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)) select * from a union select * from a limit 1) as dt;", ExpectedErr: sql.ErrNonAggregatedColumnWithoutGroupBy, }, }, }, { Name: "group by with any_value()", SetUpScript: []string{ "use mydb;", "create table members (id bigint primary key, team text);", "insert into members values (3,'red'), (4,'red'),(5,'orange'),(6,'orange'),(7,'orange'),(8,'purple');", }, Assertions: []ScriptTestAssertion{ { Query: "select @@global.sql_mode", Expected: []sql.Row{ {"STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY"}, }, }, { Query: "select @@session.sql_mode", Expected: []sql.Row{ {"STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY"}, }, }, { Query: "select any_value(id), any_value(team) from members order by id", Expected: []sql.Row{ {3, "red"}, {4, "red"}, {5, "orange"}, {6, "orange"}, {7, "orange"}, {8, "purple"}, }, }, }, }, { Name: "group by with strict errors", SetUpScript: []string{ "use mydb;", "create table members (id bigint primary key, team text);", "insert into members values (3,'red'), (4,'red'),(5,'orange'),(6,'orange'),(7,'orange'),(8,'purple');", }, Assertions: []ScriptTestAssertion{ { Query: "select @@global.sql_mode", Expected: []sql.Row{ {"STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY"}, }, }, { Query: "select @@session.sql_mode", Expected: []sql.Row{ {"STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY"}, }, }, { Query: "select id, team from members group by team", ExpectedErr: analyzererrors.ErrValidationGroupBy, }, }, }, { Name: "Group by null handling", SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(10));", "insert into t values (1, 'foo'), (2, 'foo'), (3, NULL);", }, Assertions: []ScriptTestAssertion{ { Query: "select c1, count(pk) from t group by c1;", Expected: []sql.Row{ {"foo", 2}, {nil, 1}, }, }, { Query: "select c1, count(c1) from t group by c1;", Expected: []sql.Row{ {"foo", 2}, {nil, 0}, }, }, }, }, }
var OrdinalDDLQueries = []QueryTest{ { Query: "show keys from short_ord_pk", Expected: []sql.Row{ {"short_ord_pk", 0, "PRIMARY", 1, "y", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"short_ord_pk", 0, "PRIMARY", 2, "x", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { Query: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'short_ord_pk'", Expected: []sql.Row{ {"x", uint(1)}, {"y", uint(2)}, }, }, { Query: "show keys from long_ord_pk1", Expected: []sql.Row{ {"long_ord_pk1", 0, "PRIMARY", 1, "y", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk1", 0, "PRIMARY", 2, "v", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { Query: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'long_ord_pk1' and column_key = 'PRI'", Expected: []sql.Row{ {"v", uint(2)}, {"y", uint(5)}, }, }, { Query: "show keys from long_ord_pk2", Expected: []sql.Row{ {"long_ord_pk2", 0, "PRIMARY", 1, "y", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 2, "v", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 3, "x", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 4, "z", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 5, "u", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { Query: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'long_ord_pk2' and column_key = 'PRI'", Expected: []sql.Row{ {"u", uint(1)}, {"v", uint(2)}, {"x", uint(4)}, {"y", uint(5)}, {"z", uint(6)}, }, }, { Query: "show keys from long_ord_pk3", Expected: []sql.Row{ {"long_ord_pk3", 0, "PRIMARY", 1, "y", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk3", 0, "PRIMARY", 2, "v", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk3", 0, "PRIMARY", 3, "x", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk3", 0, "PRIMARY", 4, "z", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk3", 0, "PRIMARY", 5, "u", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { Query: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'long_ord_pk3' and column_key = 'PRI'", Expected: []sql.Row{ {"u", uint(1)}, {"v", uint(2)}, {"x", uint(5)}, {"y", uint(6)}, {"z", uint(7)}, }, }, { Query: "show keys from ord_kl", Expected: []sql.Row{}, }, { Query: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'ord_kl' and column_key = 'PRI'", Expected: []sql.Row{}, }, }
var OrdinalDDLWriteQueries = []WriteQueryTest{ { WriteQuery: "ALTER TABLE long_ord_pk1 ADD COLUMN ww int AFTER v", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'long_ord_pk1' and column_key = 'PRI'", ExpectedSelect: []sql.Row{ {"v", uint(2)}, {"y", uint(6)}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk1 MODIFY COLUMN w int AFTER y", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'long_ord_pk1' and column_key = 'PRI'", ExpectedSelect: []sql.Row{ {"v", uint(2)}, {"y", uint(4)}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk1 DROP PRIMARY KEY", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "show keys from ord_kl", ExpectedSelect: []sql.Row{}, }, { WriteQuery: "ALTER TABLE ord_kl ADD PRIMARY KEY (y,v)", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "show keys from ord_kl", ExpectedSelect: []sql.Row{ {"ord_kl", 0, "PRIMARY", 1, "y", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"ord_kl", 0, "PRIMARY", 2, "v", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { WriteQuery: "ALTER TABLE ord_kl ADD PRIMARY KEY (y,v)", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'ord_kl' and column_key = 'PRI'", ExpectedSelect: []sql.Row{ {"v", uint(2)}, {"y", uint(5)}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk1 MODIFY COLUMN y int AFTER u", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: `SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'long_ord_pk1' and column_key = 'PRI' order by 2`, ExpectedSelect: []sql.Row{ {"y", uint(2)}, {"v", uint(3)}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk1 MODIFY COLUMN y int AFTER u", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "show keys from long_ord_pk1", ExpectedSelect: []sql.Row{ {"long_ord_pk1", 0, "PRIMARY", 1, "y", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk1", 0, "PRIMARY", 2, "v", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk1 RENAME COLUMN y to yy", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'long_ord_pk1' and column_key = 'PRI'", ExpectedSelect: []sql.Row{ {"v", uint(2)}, {"yy", uint(5)}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk1 RENAME COLUMN y to yy", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "show keys from long_ord_pk1", ExpectedSelect: []sql.Row{ {"long_ord_pk1", 0, "PRIMARY", 1, "yy", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk1", 0, "PRIMARY", 2, "v", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk2 ADD COLUMN ww int AFTER w", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'long_ord_pk2' and column_key = 'PRI'", ExpectedSelect: []sql.Row{ {"u", uint(1)}, {"v", uint(2)}, {"x", uint(5)}, {"y", uint(6)}, {"z", uint(7)}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk2 ADD COLUMN ww int AFTER w", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "show keys from long_ord_pk2", ExpectedSelect: []sql.Row{ {"long_ord_pk2", 0, "PRIMARY", 1, "y", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 2, "v", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 3, "x", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 4, "z", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 5, "u", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk3 DROP COLUMN ww", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'long_ord_pk3' and column_key = 'PRI'", ExpectedSelect: []sql.Row{ {"u", uint(1)}, {"v", uint(2)}, {"x", uint(4)}, {"y", uint(5)}, {"z", uint(6)}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk3 DROP COLUMN ww", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "show keys from long_ord_pk3", ExpectedSelect: []sql.Row{ {"long_ord_pk3", 0, "PRIMARY", 1, "y", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk3", 0, "PRIMARY", 2, "v", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk3", 0, "PRIMARY", 3, "x", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk3", 0, "PRIMARY", 4, "z", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk3", 0, "PRIMARY", 5, "u", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk2 MODIFY COLUMN y int AFTER u", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "SELECT column_name, ordinal_position FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'long_ord_pk2' and column_key = 'PRI'", ExpectedSelect: []sql.Row{ {"u", uint(1)}, {"y", uint(2)}, {"v", uint(3)}, {"x", uint(5)}, {"z", uint(6)}, }, }, { WriteQuery: "ALTER TABLE long_ord_pk2 MODIFY COLUMN y int AFTER u", ExpectedWriteResult: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, SelectQuery: "show keys from long_ord_pk2", ExpectedSelect: []sql.Row{ {"long_ord_pk2", 0, "PRIMARY", 1, "y", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 2, "v", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 3, "x", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 4, "z", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, {"long_ord_pk2", 0, "PRIMARY", 5, "u", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, }
var ParallelismTests = []ParallelismTest{ { Query: "SELECT /*+ JOIN_ORDER(scalarSubq0,xy) LOOKUP_JOIN(xy,scalarSubq0) */ count(*) from xy where y in (select distinct v from uv)", Parallel: true, }, { Query: "SELECT /*+ JOIN_ORDER(scalarSubq0,xy) LOOKUP_JOIN(xy,scalarSubq0) */ count(*) from xy where y in (select distinct u from uv)", Parallel: false, }, }
var PlanTests = []QueryPlanTest{}/* 362 elements not displayed */
PlanTests is a test of generating the right query plans for different queries in the presence of indexes and other features. These tests are fragile because they rely on string representations of query plans, but they're much easier to construct this way. To regenerate these plans after analyzer changes, use the TestWriteQueryPlans function in testgen_test.go.
var PreparedScriptTests = []ScriptTest{ { Name: "table_count optimization refreshes result", SetUpScript: []string{ "create table a (a int primary key);", "insert into a values (0), (1), (2);", }, Assertions: []ScriptTestAssertion{ { Query: "prepare cnt from 'select count(*) from a';", Expected: []sql.Row{{types.OkResult{Info: plan.PrepareInfo{}}}}, }, { Query: "execute cnt", Expected: []sql.Row{{3}}, }, { Query: "insert into a values (3), (4)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "execute cnt", Expected: []sql.Row{{5}}, }, }, }, { Name: "bad prepare", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "prepare s from 'prepare t from ?'", ExpectedErrStr: "syntax error at position 17 near ':v1'", }, { Query: "prepare s from 'a very real query'", ExpectedErrStr: "syntax error at position 2 near 'a'", }, { Query: "deallocate prepare idontexist", ExpectedErr: sql.ErrUnknownPreparedStatement, }, }, }, { Name: "simple select case no bindings", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "execute s", ExpectedErr: sql.ErrUnknownPreparedStatement, }, { Query: "prepare s from 'select 1'", Expected: []sql.Row{ {types.OkResult{Info: plan.PrepareInfo{}}}, }, }, { Query: "execute s", Expected: []sql.Row{ {1}, }, }, { Query: "deallocate prepare s", Expected: []sql.Row{ {types.OkResult{}}, }, }, { Query: "execute s", ExpectedErr: sql.ErrUnknownPreparedStatement, }, }, }, { Name: "simple select case one binding", SetUpScript: []string{ "set @a = 1", "set @b = 100", "set @c = 'abc'", }, Assertions: []ScriptTestAssertion{ { Query: "prepare s from 'select ?'", Expected: []sql.Row{ {types.OkResult{Info: plan.PrepareInfo{}}}, }, }, { Query: "execute s", ExpectedErrStr: "missing bind var v1", }, { Query: "execute s using @abc", Expected: []sql.Row{ {nil}, }, }, { Query: "execute s using @a, @b, @c, @abc", ExpectedErrStr: "invalid arguments. expected: 1, found: 4", }, { Query: "execute s using @a", Expected: []sql.Row{ {1}, }, }, { Query: "execute s using @b", Expected: []sql.Row{ {100}, }, }, { Query: "execute s using @c", Expected: []sql.Row{ {"abc"}, }, }, { Query: "deallocate prepare s", Expected: []sql.Row{ {types.OkResult{}}, }, }, { Query: "execute s using @a", ExpectedErr: sql.ErrUnknownPreparedStatement, }, }, }, { Name: "prepare insert", SetUpScript: []string{ "set @a = 123", "set @b = 'abc'", "create table t (i int, j varchar(100))", }, Assertions: []ScriptTestAssertion{ { Query: "prepare s from 'insert into t values (?,?)'", Expected: []sql.Row{ {types.OkResult{Info: plan.PrepareInfo{}}}, }, }, { Query: "execute s using @a", ExpectedErrStr: "missing bind var v2", }, { Query: "execute s using @a, @b", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, { Query: "select * from t order by i", Expected: []sql.Row{ {123, "abc"}, }, }, { Query: "deallocate prepare s", Expected: []sql.Row{ {types.OkResult{}}, }, }, { Query: "execute s using @a", ExpectedErr: sql.ErrUnknownPreparedStatement, }, }, }, { Name: "prepare using user vars", SetUpScript: []string{ "create table t (i int primary key);", "insert into t values (0), (1), (2);", "set @num = 123", "set @bad = 'bad'", "set @a = 'select * from t order by i'", "set @b = concat('select 1',' + 1')", "set @c = 'select 1 from dual limit ?'", "set @d = 'select @num'", }, Assertions: []ScriptTestAssertion{ { Query: "prepare stmt from @asdf", ExpectedErrStr: "syntax error at position 5 near 'NULL'", }, { Query: "prepare stmt from @num", ExpectedErrStr: "syntax error at position 4 near '123'", }, { Query: "prepare stmt from @bad", ExpectedErrStr: "syntax error at position 4 near 'bad'", }, { Query: "prepare stmt from @a", Expected: []sql.Row{ {types.OkResult{Info: plan.PrepareInfo{}}}, }, }, { Query: "execute stmt", Expected: []sql.Row{ {0}, {1}, {2}, }, }, { Query: "prepare stmt from @b", Expected: []sql.Row{ {types.OkResult{Info: plan.PrepareInfo{}}}, }, }, { Query: "execute stmt", Expected: []sql.Row{ {2}, }, }, { Query: "prepare stmt from @c", Expected: []sql.Row{ {types.OkResult{Info: plan.PrepareInfo{}}}, }, }, { Query: "execute stmt using @num", Expected: []sql.Row{ {1}, }, }, { Query: "prepare stmt from @d", Expected: []sql.Row{ {types.OkResult{Info: plan.PrepareInfo{}}}, }, }, { Query: "execute stmt", Expected: []sql.Row{ {123}, }, }, }, }, { Name: "Complex join query with foreign key constraints", SetUpScript: []string{ "CREATE TABLE `users` (`id` int NOT NULL AUTO_INCREMENT, `username` varchar(255) NOT NULL, PRIMARY KEY (`id`));", "CREATE TABLE `tweet` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `content` text NOT NULL, `timestamp` bigint NOT NULL, PRIMARY KEY (`id`), KEY `tweet_user_id` (`user_id`), CONSTRAINT `0qpfesgd` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`));", "INSERT INTO `users` (`id`,`username`) VALUES (1,'huey'), (2,'zaizee'), (3,'mickey');", "INSERT INTO `tweet` (`id`,`user_id`,`content`,`timestamp`) VALUES (1,1,'meow',1647463727), (2,1,'purr',1647463727), (3,2,'hiss',1647463727), (4,3,'woof',1647463727);", "set @u2 = 'u2';", "set @u3 = 'u3';", "set @u4 = 'u4';", }, Assertions: []ScriptTestAssertion{ { Query: "prepare s from 'SELECT `t1`.`username`, COUNT(`t1`.`id`) AS `ct` FROM ((SELECT `t2`.`id`, `t2`.`content`, `t3`.`username` FROM `tweet` AS `t2` INNER JOIN `users` AS `t3` ON (`t2`.`user_id` = `t3`.`id`) WHERE (`t3`.`username` = ?)) UNION (SELECT `t4`.`id`, `t4`.`content`, `t5`.`username` FROM `tweet` AS `t4` INNER JOIN `users` AS `t5` ON (`t4`.`user_id` = `t5`.`id`) WHERE (`t5`.`username` IN (?, ?)))) AS `t1` GROUP BY `t1`.`username` ORDER BY COUNT(`t1`.`id`) DESC'", Expected: []sql.Row{ {types.OkResult{Info: plan.PrepareInfo{}}}, }, }, { Query: "execute s using @u3, @u2, @u4", Expected: []sql.Row{}, }, }, }, { Name: "Drop column with check constraint, no other columns", SetUpScript: []string{ "create table mytable (pk int primary key);", "ALTER TABLE mytable ADD COLUMN col2 text NOT NULL;", "ALTER TABLE mytable ADD CONSTRAINT constraint_check CHECK (col2 LIKE '%myregex%');", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable DROP COLUMN col2", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Drop column with check constraint, other column referenced first", SetUpScript: []string{ "create table mytable (pk int primary key);", "ALTER TABLE mytable ADD COLUMN col2 text NOT NULL;", "ALTER TABLE mytable ADD COLUMN col3 text NOT NULL;", "ALTER TABLE mytable ADD CONSTRAINT constraint_check CHECK (col3 LIKE col2);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable DROP COLUMN col2", ExpectedErr: sql.ErrCheckConstraintInvalidatedByColumnAlter, }, }, }, { Name: "Drop column with check constraint, other column referenced second", SetUpScript: []string{ "create table mytable (pk int primary key);", "ALTER TABLE mytable ADD COLUMN col2 text NOT NULL;", "ALTER TABLE mytable ADD COLUMN col3 text NOT NULL;", "ALTER TABLE mytable ADD CONSTRAINT constraint_check CHECK (col2 LIKE col3);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable DROP COLUMN col2", ExpectedErr: sql.ErrCheckConstraintInvalidatedByColumnAlter, }, }, }, { Name: "Drop column with check constraint, multiple constraints", SetUpScript: []string{ "create table mytable (pk int primary key);", "ALTER TABLE mytable ADD COLUMN col2 text NOT NULL;", "ALTER TABLE mytable ADD COLUMN col3 text NOT NULL;", "ALTER TABLE mytable ADD CONSTRAINT ok_check CHECK (col2 LIKE '%myregex%');", "ALTER TABLE mytable ADD CONSTRAINT bad_check CHECK (col2 LIKE col3);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable DROP COLUMN col2", ExpectedErr: sql.ErrCheckConstraintInvalidatedByColumnAlter, }, }, }, { Name: "Large character data", SetUpScript: []string{ "CREATE TABLE `test` (`id` int NOT NULL AUTO_INCREMENT, `data` blob NOT NULL, PRIMARY KEY (`id`))", }, Assertions: []ScriptTestAssertion{ { Query: `INSERT INTO test (data) values (?)`, Bindings: map[string]*querypb.BindVariable{ "v1": {Type: querypb.Type_VARBINARY, Value: []byte( "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "")}, }, Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, InsertID: 1, }}}, }, }, }, }
var ProcedureCallTests = []ScriptTest{ { Name: "OUT param with SET", SetUpScript: []string{ "SET @outparam = 5", "CREATE PROCEDURE testabc(OUT x BIGINT) SET x = 9", "CALL testabc(@outparam)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @outparam", Expected: []sql.Row{ { int64(9), }, }, }, }, }, { Name: "OUT param without SET", SetUpScript: []string{ "SET @outparam = 5", "CREATE PROCEDURE testabc(OUT x BIGINT) SELECT x", "CALL testabc(@outparam)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @outparam", Expected: []sql.Row{ { nil, }, }, }, }, }, { Name: "INOUT param with SET", SetUpScript: []string{ "SET @outparam = 5", "CREATE PROCEDURE testabc(INOUT x BIGINT) BEGIN SET x = x + 1; SET x = x + 3; END;", "CALL testabc(@outparam)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @outparam", Expected: []sql.Row{ { int64(9), }, }, }, }, }, { Name: "INOUT param without SET", SetUpScript: []string{ "SET @outparam = 5", "CREATE PROCEDURE testabc(INOUT x BIGINT) SELECT x", "CALL testabc(@outparam)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @outparam", Expected: []sql.Row{ { int64(5), }, }, }, }, }, { Name: "Nested CALL with INOUT param", SetUpScript: []string{ "SET @outparam = 5", "CREATE PROCEDURE p3(INOUT z INT) BEGIN SET z = z * 111; END;", "CREATE PROCEDURE p2(INOUT y DOUBLE) BEGIN SET y = y + 4; CALL p3(y); END;", "CREATE PROCEDURE p1(INOUT x BIGINT) BEGIN SET x = 3; CALL p2(x); END;", "CALL p1(@outparam)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @outparam", Expected: []sql.Row{ { int64(777), }, }, }, }, }, { Name: "OUT param without SET", SetUpScript: []string{ "SET @outparam = 5", "CREATE PROCEDURE testabc(OUT x BIGINT) SELECT x", "CALL testabc(@outparam)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @outparam", Expected: []sql.Row{ { nil, }, }, }, }, }, { Name: "Incompatible type for parameter", SetUpScript: []string{ "CREATE PROCEDURE p1(x DATETIME) SELECT x", }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1('hi')", ExpectedErr: types.ErrConvertingToTime, }, }, }, { Name: "Incorrect parameter count", SetUpScript: []string{ "CREATE PROCEDURE p1(x BIGINT, y BIGINT) SELECT x + y", }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(1)", ExpectedErr: sql.ErrCallIncorrectParameterCount, }, { Query: "CALL p1(1, 2, 3)", ExpectedErr: sql.ErrCallIncorrectParameterCount, }, }, }, { Name: "use procedure parameter in filter expressions and multiple statements", SetUpScript: []string{ "CREATE TABLE inventory (store_id int, product varchar(5))", "INSERT INTO inventory VALUES (1, 'a'), (1, 'b'), (1, 'c'), (1, 'd'), (2, 'e'), (2, 'f'), (1, 'g'), (1, 'h'), (3, 'i')", "CREATE PROCEDURE proc1 (IN p_store_id INT) SELECT COUNT(*) FROM inventory WHERE store_id = p_store_id;", "CREATE PROCEDURE proc2 (IN p_store_id INT, OUT p_film_count INT) READS SQL DATA BEGIN SELECT COUNT(*) as counted FROM inventory WHERE store_id = p_store_id; SET p_film_count = 44; END ;", }, Assertions: []ScriptTestAssertion{ { Query: "CALL proc1(1)", Expected: []sql.Row{ { int64(6), }, }, }, { Query: "CALL proc1(2)", Expected: []sql.Row{ { int64(2), }, }, }, { Query: "CALL proc1(4)", Expected: []sql.Row{ { int64(0), }, }, }, { Query: "CALL proc2(3, @foo)", Expected: []sql.Row{ { int64(1), }, }, }, { Query: "SELECT @foo", Expected: []sql.Row{ { int64(44), }, }, }, }, }, { Name: "Call procedures by their qualified name", SetUpScript: []string{ "CREATE DATABASE otherdb", "CREATE PROCEDURE mydb.p1() SELECT 42", "CREATE PROCEDURE otherdb.p1() SELECT 43", }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1()", Expected: []sql.Row{{42}}, }, { Query: "CALL mydb.p1()", Expected: []sql.Row{{42}}, }, { Query: "CALL otherdb.p1()", Expected: []sql.Row{{43}}, }, { Query: "USE otherdb", Expected: []sql.Row{}, }, { Query: "CALL p1()", Expected: []sql.Row{{43}}, }, }, }, { Name: "String literals with escaped chars", SetUpScript: []string{ `CREATE PROCEDURE joe(IN str VARCHAR(15)) SELECT CONCAT('joe''s bar:', str);`, `CREATE PROCEDURE jill(IN str VARCHAR(15)) SELECT CONCAT('jill\'s bar:', str);`, `CREATE PROCEDURE stan(IN str VARCHAR(15)) SELECT CONCAT("stan\'s bar:", str);`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL joe('open')", Expected: []sql.Row{{"joe's bar:open"}}, }, { Query: "CALL jill('closed')", Expected: []sql.Row{{"jill's bar:closed"}}, }, { Query: "CALL stan('quarantined')", Expected: []sql.Row{{"stan's bar:quarantined"}}, }, }, }, }
var ProcedureDropTests = []ScriptTest{ { Name: "DROP procedures", SetUpScript: []string{ "CREATE PROCEDURE p1() SELECT 5", "CREATE PROCEDURE p2() SELECT 6", }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1", Expected: []sql.Row{ { int64(5), }, }, }, { Query: "CALL p2", Expected: []sql.Row{ { int64(6), }, }, }, { Query: "DROP PROCEDURE p1", Expected: []sql.Row{}, }, { Query: "CALL p1", ExpectedErr: sql.ErrStoredProcedureDoesNotExist, }, { Query: "DROP PROCEDURE IF EXISTS p2", Expected: []sql.Row{}, }, { Query: "CALL p2", ExpectedErr: sql.ErrStoredProcedureDoesNotExist, }, { Query: "DROP PROCEDURE p3", ExpectedErr: sql.ErrStoredProcedureDoesNotExist, }, { Query: "DROP PROCEDURE IF EXISTS p4", Expected: []sql.Row{}, }, }, }, }
var ProcedureLogicTests = []ScriptTest{ { Name: "REPEAT with OnceBefore returns first loop evaluation result set", SetUpScript: []string{ `CREATE PROCEDURE p1() BEGIN SET @counter = 0; REPEAT SELECT 42 from dual; SET @counter = @counter + 1; UNTIL @counter >= 0 END REPEAT; END`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1;", Expected: []sql.Row{{42}}, }, }, }, { Name: "WHILE returns previous loop evaluation result set", SetUpScript: []string{ `CREATE PROCEDURE p1() BEGIN SET @counter = 0; WHILE @counter <= 0 DO SET @counter = @counter + 1; SELECT CAST(@counter + 41 as SIGNED) from dual; END WHILE; END`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1;", Expected: []sql.Row{{42}}, }, }, }, { Name: "Simple SELECT", SetUpScript: []string{ "CREATE PROCEDURE testabc(x DOUBLE, y DOUBLE) SELECT x*y", }, Assertions: []ScriptTestAssertion{ { Query: "CALL testabc(2, 3)", Expected: []sql.Row{ { "6", }, }, }, { Query: "CALL testabc(9, 9.5)", Expected: []sql.Row{ { "85.5", }, }, }, }, }, { Name: "Multiple SELECTs", SetUpScript: []string{ "CREATE TABLE t1(pk VARCHAR(20) PRIMARY KEY)", "INSERT INTO t1 VALUES (3), (4), (50)", `CREATE PROCEDURE p1() BEGIN SELECT * FROM t1; UPDATE t1 SET pk = CONCAT(pk, '0'); SELECT * FROM t1; INSERT INTO t1 VALUES (1), (2); SELECT * FROM t1; REPLACE INTO t1 VALUES (1), (30); DELETE FROM t1 WHERE pk LIKE '%00'; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1()", Expected: []sql.Row{ {"1"}, {"2"}, {"30"}, {"40"}, {"500"}, }, }, { Query: "SELECT * FROM t1 ORDER BY 1", Expected: []sql.Row{ {"1"}, {"2"}, {"30"}, {"40"}, }, }, }, }, { Name: "IF/ELSE with 1 SELECT at end", SetUpScript: []string{ "SET @outparam = ''", `CREATE PROCEDURE p1(OUT s VARCHAR(200), N DOUBLE, m DOUBLE) BEGIN SET s = ''; IF n = m THEN SET s = 'equals'; ELSE IF n > m THEN SET s = 'greater'; ELSE SET s = 'less'; END IF; SET s = CONCAT('is ', s, ' than'); END IF; SET s = CONCAT(n, ' ', s, ' ', m, '.'); SELECT s; END;`, `CREATE PROCEDURE p2(s VARCHAR(200), N DOUBLE, m DOUBLE) BEGIN SET s = ''; IF n = m THEN SET s = 'equals'; ELSE IF n > m THEN SET s = 'greater'; ELSE SET s = 'less'; END IF; SET s = CONCAT('is ', s, ' than'); END IF; SET s = CONCAT(n, ' ', s, ' ', m, '.'); SELECT s; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(@outparam, 1, 2)", Expected: []sql.Row{ { "1 is less than 2.", }, }, }, { Query: "SELECT @outparam", Expected: []sql.Row{ { "1 is less than 2.", }, }, }, { Query: "CALL p1(@outparam, null, 2)", Expected: []sql.Row{ { nil, }, }, }, { Query: "CALL p1(@outparam, 7, 4)", Expected: []sql.Row{ { "7 is greater than 4.", }, }, }, { Query: "SELECT @outparam", Expected: []sql.Row{ { "7 is greater than 4.", }, }, }, { Query: "CALL p1(@outparam, 5, 5)", Expected: []sql.Row{ { "5 equals 5.", }, }, }, { Query: "SELECT @outparam", Expected: []sql.Row{ { "5 equals 5.", }, }, }, { Query: "CALL p2(@outparam, 9, 3)", Expected: []sql.Row{ { "9 is greater than 3.", }, }, }, { Query: "SELECT @outparam", Expected: []sql.Row{ { "5 equals 5.", }, }, }, }, }, { Name: "IF/ELSE with nested SELECT in branches", SetUpScript: []string{ "CREATE TABLE t1(pk BIGINT PRIMARY KEY)", `CREATE PROCEDURE p1(x BIGINT) BEGIN DELETE FROM t1; IF x < 10 THEN IF x = 0 THEN SELECT 1000; ELSEIF x = 1 THEN SELECT 1001; ELSE INSERT INTO t1 VALUES (3), (4), (5); END IF; ELSEIF x < 20 THEN IF x = 10 THEN INSERT INTO t1 VALUES (1), (2), (6), (7); ELSEIF x = 11 THEN INSERT INTO t1 VALUES (8), (9), (10), (11), (12); SELECT * FROM t1; ELSE SELECT 2002; SELECT 2003; END IF; END IF; INSERT INTO t1 VALUES (1), (2); END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(0)", Expected: []sql.Row{ { int64(1000), }, }, }, { Query: "CALL p1(1)", Expected: []sql.Row{ { int64(1001), }, }, }, { Query: "CALL p1(2)", Expected: []sql.Row{ { types.NewOkResult(2), }, }, }, { Query: "CALL p1(10)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "CALL p1(11)", Expected: []sql.Row{ {int64(8)}, {int64(9)}, {int64(10)}, {int64(11)}, {int64(12)}, }, }, { Query: "CALL p1(12)", Expected: []sql.Row{ { int64(2003), }, }, }, }, }, { Name: "REPEAT loop over user variable", SetUpScript: []string{ `CREATE PROCEDURE p1(p1 INT) BEGIN SET @x = 0; REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT; END`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(0)", Expected: []sql.Row{{}}, }, { Query: "CALL p1(1)", Expected: []sql.Row{{}}, }, { Query: "CALL p1(2)", Expected: []sql.Row{{}}, }, { Query: "CALL p1(200)", Expected: []sql.Row{{}}, }, }, }, { Name: "WHILE loop over user variable", SetUpScript: []string{ `CREATE PROCEDURE p1(p1 INT) BEGIN SET @x = 0; WHILE @x <= p1 DO SET @x = @x + 1; END WHILE; END`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(0)", Expected: []sql.Row{{}}, }, { Query: "CALL p1(1)", Expected: []sql.Row{{}}, }, { Query: "CALL p1(2)", Expected: []sql.Row{{}}, }, }, }, { Name: "CASE statements", SetUpScript: []string{ `CREATE PROCEDURE p1(IN a BIGINT) BEGIN DECLARE b VARCHAR(200) DEFAULT ""; tloop: LOOP CASE WHEN a < 4 THEN SET b = CONCAT(b, "a"); SET a = a + 1; WHEN a < 8 THEN SET b = CONCAT(b, "b"); SET a = a + 1; ELSE LEAVE tloop; END CASE; END LOOP; SELECT b; END;`, `CREATE PROCEDURE p2(IN a BIGINT) BEGIN DECLARE b VARCHAR(200) DEFAULT ""; tloop: LOOP CASE a WHEN 1 THEN SET b = CONCAT(b, "a"); SET a = a + 1; WHEN 2 THEN SET b = CONCAT(b, "b"); SET a = a + 1; WHEN 3 THEN SET b = CONCAT(b, "c"); SET a = a + 1; ELSE LEAVE tloop; END CASE; END LOOP; SELECT b; END;`, `CREATE PROCEDURE p3(IN a BIGINT) BEGIN DECLARE b VARCHAR(200) DEFAULT ""; tloop: LOOP CASE a WHEN 1 THEN SET b = CONCAT(b, "a"); SET a = a + 1; END CASE; END LOOP; SELECT b; END;`, `CREATE PROCEDURE p4(IN a BIGINT) BEGIN DECLARE b VARCHAR(200) DEFAULT ""; tloop: LOOP CASE WHEN a = 1 THEN SET b = CONCAT(b, "a"); SET a = a + 1; END CASE; END LOOP; SELECT b; END;`, `CREATE PROCEDURE p5(IN a BIGINT) BEGIN DECLARE b VARCHAR(200) DEFAULT ""; REPEAT CASE WHEN a <= 1 THEN SET b = CONCAT(b, "a"); SET a = a + 1; END CASE; UNTIL a > 1 END REPEAT; SELECT b; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(0)", Expected: []sql.Row{ {"aaaabbbb"}, }, }, { Query: "CALL p1(3)", Expected: []sql.Row{ {"abbbb"}, }, }, { Query: "CALL p1(6)", Expected: []sql.Row{ {"bb"}, }, }, { Query: "CALL p1(9)", Expected: []sql.Row{ {""}, }, }, { Query: "CALL p2(1)", Expected: []sql.Row{ {"abc"}, }, }, { Query: "CALL p2(2)", Expected: []sql.Row{ {"bc"}, }, }, { Query: "CALL p2(3)", Expected: []sql.Row{ {"c"}, }, }, { Query: "CALL p2(4)", Expected: []sql.Row{ {""}, }, }, { Query: "CALL p3(1)", ExpectedErrStr: "Case not found for CASE statement (errno 1339) (sqlstate 20000)", }, { Query: "CALL p3(2)", ExpectedErrStr: "Case not found for CASE statement (errno 1339) (sqlstate 20000)", }, { Query: "CALL p4(1)", ExpectedErrStr: "Case not found for CASE statement (errno 1339) (sqlstate 20000)", }, { Query: "CALL p4(-1)", ExpectedErrStr: "Case not found for CASE statement (errno 1339) (sqlstate 20000)", }, { Query: "CALL p5(0)", Expected: []sql.Row{ {"aa"}, }, }, { Query: "CALL p5(1)", Expected: []sql.Row{ {"a"}, }, }, }, }, { Name: "SELECT with JOIN and table aliases", SetUpScript: []string{ "CREATE TABLE foo(a BIGINT PRIMARY KEY, b VARCHAR(20))", "INSERT INTO foo VALUES (1, 'd'), (2, 'e'), (3, 'f')", "CREATE TABLE bar(b VARCHAR(30) PRIMARY KEY, c BIGINT)", "INSERT INTO bar VALUES ('x', 3), ('y', 2), ('z', 1)", "CREATE PROCEDURE p1() SELECT f.a, bar.b, f.b FROM foo f INNER JOIN bar ON f.a = bar.c ORDER BY 1", "CREATE PROCEDURE p2() BEGIN SELECT f.a, bar.b, f.b FROM foo f INNER JOIN bar ON f.a = bar.c ORDER BY 1; END;", "CREATE PROCEDURE p3() IF 0 = 0 THEN SELECT f.a, bar.b, f.b FROM foo f INNER JOIN bar ON f.a = bar.c ORDER BY 1; END IF;", "CREATE PROCEDURE p4() BEGIN SELECT 7; SELECT f.a, bar.b, f.b FROM foo f INNER JOIN bar ON f.a = bar.c ORDER BY 1; END;", "CREATE PROCEDURE p5() IF 0 = 0 THEN SELECT 7; SELECT f.a, bar.b, f.b FROM foo f INNER JOIN bar ON f.a = bar.c ORDER BY 1; END IF;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT f.a, bar.b, f.b FROM foo f INNER JOIN bar ON f.a = bar.c ORDER BY 1", Expected: []sql.Row{ {int64(1), "z", "d"}, {int64(2), "y", "e"}, {int64(3), "x", "f"}, }, }, { Query: "CALL p1()", Expected: []sql.Row{ {int64(1), "z", "d"}, {int64(2), "y", "e"}, {int64(3), "x", "f"}, }, }, { Query: "CALL p2()", Expected: []sql.Row{ {int64(1), "z", "d"}, {int64(2), "y", "e"}, {int64(3), "x", "f"}, }, }, { Query: "CALL p3()", Expected: []sql.Row{ {int64(1), "z", "d"}, {int64(2), "y", "e"}, {int64(3), "x", "f"}, }, }, { Query: "CALL p4()", Expected: []sql.Row{ {int64(1), "z", "d"}, {int64(2), "y", "e"}, {int64(3), "x", "f"}, }, }, { Query: "CALL p5()", Expected: []sql.Row{ {int64(1), "z", "d"}, {int64(2), "y", "e"}, {int64(3), "x", "f"}, }, }, }, }, { Name: "Nested CALL in IF/ELSE branch", SetUpScript: []string{ "CREATE TABLE t1(pk BIGINT PRIMARY KEY)", "INSERT INTO t1 VALUES (2), (3)", "CREATE PROCEDURE p1(INOUT x BIGINT) BEGIN IF X = 1 THEN CALL p2(10); ELSEIF x = 2 THEN CALL p2(100); ELSE CALL p2(X); END IF; END;", "CREATE PROCEDURE p2(INOUT y BIGINT) BEGIN SELECT pk * y FROM t1 ORDER BY 1; END;", }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(1)", Expected: []sql.Row{ {int64(20)}, {int64(30)}, }, }, { Query: "CALL p1(2)", Expected: []sql.Row{ {int64(200)}, {int64(300)}, }, }, { Query: "CALL p1(5)", Expected: []sql.Row{ {int64(10)}, {int64(15)}, }, }, }, }, { Name: "INSERT INTO SELECT doesn't override SELECT", SetUpScript: []string{ "CREATE TABLE t1(pk BIGINT PRIMARY KEY)", "CREATE TABLE t2(pk BIGINT PRIMARY KEY)", "INSERT INTO t1 VALUES (2), (3)", "INSERT INTO t2 VALUES (1)", `CREATE PROCEDURE p1(x BIGINT) BEGIN DELETE FROM t2 WHERE pk > 1; INSERT INTO t2 SELECT pk FROM t1; SELECT * FROM t2; INSERT INTO t2 SELECT pk + 10 FROM t1; IF x = 1 THEN SELECT * FROM t2; END IF; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(0)", Expected: []sql.Row{ {int64(1)}, {int64(2)}, {int64(3)}, }, }, { Query: "CALL p1(1)", Expected: []sql.Row{ {int64(1)}, {int64(2)}, {int64(3)}, {int64(12)}, {int64(13)}, }, }, }, }, { Name: "Parameters resolve inside of INSERT", SetUpScript: []string{ `CREATE TABLE items ( id INT PRIMARY KEY AUTO_INCREMENT, item TEXT NOT NULL );`, `CREATE PROCEDURE add_item (IN txt TEXT) MODIFIES SQL DATA INSERT INTO items (item) VALUES (txt)`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL add_item('A test item');", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, InsertID: 1}}, }, }, { Query: "SELECT * FROM items;", Expected: []sql.Row{ {1, "A test item"}, }, }, }, }, { Name: "Parameters resolve inside of SELECT UNION", SetUpScript: []string{ "CREATE TABLE t1(pk BIGINT PRIMARY KEY, v1 BIGINT)", "INSERT INTO t1 VALUES (1, 2)", "SELECT pk, v1 FROM t1 UNION SELECT 1, 2;", `CREATE PROCEDURE p1(x BIGINT, y BIGINT) BEGIN SELECT pk+x, v1+y FROM t1 UNION SELECT x, y; END;`, `CREATE PROCEDURE p2(u BIGINT, v BIGINT) SELECT pk+u, v1+v FROM t1 UNION SELECT u, v;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(3, 4)", Expected: []sql.Row{ {"4", "6"}, {"3", "4"}, }, }, { Query: "CALL p2(5, 6)", Expected: []sql.Row{ {"6", "8"}, {"5", "6"}, }, }, }, }, { Name: "Parameters resolve inside of REPLACE", SetUpScript: []string{ `CREATE TABLE items ( id INT PRIMARY KEY AUTO_INCREMENT, item INT NOT NULL );`, `CREATE PROCEDURE add_item (IN num INT) MODIFIES SQL DATA BEGIN REPLACE INTO items (item) VALUES (5), (num), (num+1); END`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL add_item(6);", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "SELECT * FROM items ORDER BY 1;", Expected: []sql.Row{ {1, 5}, {2, 6}, {3, 7}, }, }, }, }, { Name: "Parameters resolve inside of INSERT INTO SELECT", SetUpScript: []string{ "CREATE TABLE t1(pk BIGINT PRIMARY KEY)", "CREATE TABLE t2(pk BIGINT PRIMARY KEY)", "INSERT INTO t1 VALUES (1), (2)", `CREATE PROCEDURE p1(x BIGINT) BEGIN TRUNCATE t2; INSERT INTO t2 SELECT pk+x FROM t1; SELECT * FROM t2; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(0)", Expected: []sql.Row{ {int64(1)}, {int64(2)}, }, }, { Query: "CALL p1(5)", Expected: []sql.Row{ {int64(6)}, {int64(7)}, }, }, }, }, { Name: "Subquery on SET user variable captures parameter", SetUpScript: []string{ `CREATE PROCEDURE p1(x VARCHAR(20)) BEGIN SET @randomvar = (SELECT LENGTH(x)); SELECT @randomvar; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1('hi')", Expected: []sql.Row{ {int64(2)}, }, }, { Query: "CALL p1('hello')", Expected: []sql.Row{ {int64(5)}, }, }, }, }, { Name: "Simple SELECT INTO", SetUpScript: []string{ "CREATE PROCEDURE testabc(IN x DOUBLE, IN y DOUBLE, OUT abc DOUBLE) SELECT x*y INTO abc", "CALL testabc(2, 3, @res1)", "CALL testabc(9, 9.5, @res2)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @res1", Expected: []sql.Row{{float64(6)}}, }, { Query: "SELECT @res2", Expected: []sql.Row{{float64(85.5)}}, }, }, }, { Name: "Multiple variables in SELECT INTO", SetUpScript: []string{ "CREATE PROCEDURE new_proc(IN x DOUBLE, IN y DOUBLE, OUT abc DOUBLE, OUT def DOUBLE) SELECT x*y, x+y INTO abc, def", "CALL new_proc(2, 3, @res1, @res2)", "CALL new_proc(9, 9.5, @res3, @res4)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @res1, @res2", Expected: []sql.Row{{float64(6), float64(5)}}, }, { Query: "SELECT @res3, @res4", Expected: []sql.Row{{float64(85.5), float64(18.5)}}, }, }, }, { Name: "SELECT INTO with condition", SetUpScript: []string{ "CREATE TABLE inventory (item_id int primary key, shelf_id int, items varchar(100))", "INSERT INTO inventory VALUES (1, 1, 'a'), (2, 1, 'b'), (3, 2, 'c'), (4, 1, 'd'), (5, 4, 'e')", "CREATE PROCEDURE in_stock (IN p_id INT, OUT p_count INT) SELECT COUNT(*) FROM inventory WHERE shelf_id = p_id INTO p_count", "CALL in_stock(1, @shelf1)", "CALL in_stock(2, @shelf2)", "CALL in_stock(3, @shelf3)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @shelf1, @shelf2, @shelf3", Expected: []sql.Row{{3, 1, 0}}, }, }, }, { Name: "SELECT INTO with group by, order by and limit", SetUpScript: []string{ "CREATE TABLE inventory (item_id int primary key, shelf_id int, item varchar(10))", "INSERT INTO inventory VALUES (1, 1, 'a'), (2, 1, 'b'), (3, 2, 'c'), (4, 1, 'd'), (5, 4, 'e')", "CREATE PROCEDURE first_shelf (OUT p_count INT) SELECT COUNT(*) FROM inventory GROUP BY shelf_id ORDER BY shelf_id ASC LIMIT 1 INTO p_count", "CREATE PROCEDURE last_shelf (OUT p_count INT) SELECT COUNT(*) FROM inventory GROUP BY shelf_id ORDER BY shelf_id DESC LIMIT 1 INTO p_count", "CALL first_shelf(@result1)", "CALL last_shelf(@result2)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @result1", Expected: []sql.Row{{3}}, }, { Query: "SELECT @result2", Expected: []sql.Row{{1}}, }, }, }, { Name: "multiple SELECT INTO in begin end block", SetUpScript: []string{ "CREATE TABLE inventory (item_id int primary key, shelf_id int, item varchar(10))", "INSERT INTO inventory VALUES (1, 1, 'a'), (2, 1, 'b'), (3, 2, 'c'), (4, 1, 'd'), (5, 4, 'e')", "CREATE PROCEDURE random_info(OUT p_count1 INT, OUT p_count2 VARCHAR(10)) BEGIN " + "SELECT COUNT(*) FROM inventory GROUP BY shelf_id ORDER BY shelf_id ASC LIMIT 1 INTO p_count1;" + "SELECT item INTO p_count2 FROM inventory WHERE shelf_id = 1 ORDER BY item DESC LIMIT 1; " + "END", "CALL random_info(@s1, @s2)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @s1, @s2", Expected: []sql.Row{{3, "d"}}, }, }, }, { Name: "multiple statement with single SELECT INTO in begin end block", SetUpScript: []string{ "CREATE TABLE inventory (item_id int primary key, shelf_id int, item varchar(10))", "INSERT INTO inventory VALUES (1, 1, 'a'), (2, 1, 'b'), (3, 2, 'c'), (4, 1, 'd'), (5, 4, 'e')", `CREATE PROCEDURE count_and_print(IN p_shelf_id INT, OUT p_count INT) BEGIN SELECT item FROM inventory WHERE shelf_id = p_shelf_id ORDER BY item ASC; SELECT COUNT(*) INTO p_count FROM inventory WHERE shelf_id = p_shelf_id; END`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL count_and_print(1, @total)", Expected: []sql.Row{{"a"}, {"b"}, {"d"}}, }, { Query: "SELECT @total", Expected: []sql.Row{{3}}, }, }, }, { Name: "DECLARE variables, proper nesting support", SetUpScript: []string{ `CREATE PROCEDURE p1(OUT x BIGINT) BEGIN DECLARE a INT; DECLARE b MEDIUMINT; DECLARE c VARCHAR(20); SELECT 1, 2, 'a' INTO a, b, c; BEGIN DECLARE b MEDIUMINT; SET a = 4; SET b = 5; END; SET x = a + b; SELECT a, b, c; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(@x);", Expected: []sql.Row{ {4, 2, "a"}, }, }, { Query: "SELECT @x;", Expected: []sql.Row{ {6}, }, }, }, }, { Name: "DECLARE multiple variables, same statement", SetUpScript: []string{ `CREATE PROCEDURE p1() BEGIN DECLARE a, b, c INT; SELECT 2, 3, 4 INTO a, b, c; SELECT a + b + c; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {9}, }, }, }, }, { Name: "DECLARE variable shadows parameter", SetUpScript: []string{ `CREATE PROCEDURE p1(INOUT x INT) BEGIN DECLARE x INT; SET x = 5; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "SET @x = 2;", Expected: []sql.Row{{}}, }, { Query: "CALL p1(@x);", Expected: []sql.Row{{}}, }, { Query: "SELECT @x;", Expected: []sql.Row{ {2}, }, }, }, }, { Name: "DECLARE CONDITION", SetUpScript: []string{ `CREATE PROCEDURE p1(x INT) BEGIN DECLARE specialty CONDITION FOR SQLSTATE '45000'; DECLARE specialty2 CONDITION FOR SQLSTATE '02000'; IF x = 0 THEN SIGNAL SQLSTATE '01000'; ELSEIF x = 1 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A custom error occurred 1'; ELSEIF x = 2 THEN SIGNAL specialty SET MESSAGE_TEXT = 'A custom error occurred 2', MYSQL_ERRNO = 1002; ELSEIF x = 3 THEN SIGNAL specialty; ELSEIF x = 4 THEN SIGNAL specialty2; ELSE SIGNAL SQLSTATE '01000' SET MESSAGE_TEXT = 'A warning occurred', MYSQL_ERRNO = 1000; SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'An error occurred', MYSQL_ERRNO = 1001; END IF; BEGIN DECLARE specialty3 CONDITION FOR SQLSTATE '45000'; END; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(0)", ExpectedErrStr: "warnings not yet implemented", }, { Query: "CALL p1(1)", ExpectedErrStr: "A custom error occurred 1 (errno 1644) (sqlstate 45000)", }, { Query: "CALL p1(2)", ExpectedErrStr: "A custom error occurred 2 (errno 1002) (sqlstate 45000)", }, { Query: "CALL p1(3)", ExpectedErrStr: "Unhandled user-defined exception condition (errno 1644) (sqlstate 45000)", }, { Query: "CALL p1(4)", ExpectedErrStr: "Unhandled user-defined not found condition (errno 1643) (sqlstate 02000)", }, }, }, { Name: "DECLARE CONDITION nesting priority", SetUpScript: []string{ `CREATE PROCEDURE p1(x INT) BEGIN DECLARE cond_name CONDITION FOR SQLSTATE '02000'; BEGIN DECLARE cond_name CONDITION FOR SQLSTATE '45000'; IF x = 0 THEN SIGNAL cond_name; END IF; END; SIGNAL cond_name; END;`, `CREATE PROCEDURE p2(x INT) BEGIN DECLARE cond_name CONDITION FOR SQLSTATE '45000'; BEGIN DECLARE cond_name CONDITION FOR SQLSTATE '02000'; IF x = 0 THEN SIGNAL cond_name; END IF; END; SIGNAL cond_name; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(0)", ExpectedErrStr: "Unhandled user-defined exception condition (errno 1644) (sqlstate 45000)", }, { Query: "CALL p1(1)", ExpectedErrStr: "Unhandled user-defined not found condition (errno 1643) (sqlstate 02000)", }, { Query: "CALL p2(0)", ExpectedErrStr: "Unhandled user-defined not found condition (errno 1643) (sqlstate 02000)", }, { Query: "CALL p2(1)", ExpectedErrStr: "Unhandled user-defined exception condition (errno 1644) (sqlstate 45000)", }, }, }, { Name: "FETCH multiple rows", SetUpScript: []string{ `CREATE TABLE t1 (pk BIGINT PRIMARY KEY);`, `CREATE PROCEDURE p1() BEGIN DECLARE a, b INT; DECLARE cur1 CURSOR FOR SELECT pk FROM t1; DELETE FROM t1; INSERT INTO t1 VALUES (1), (2); OPEN cur1; FETCH cur1 INTO a; FETCH cur1 INTO b; CLOSE cur1; SELECT a, b; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {1, 2}, }, }, }, }, { Name: "FETCH with multiple opens and closes", SetUpScript: []string{ `CREATE TABLE t1 (pk BIGINT PRIMARY KEY);`, `CREATE PROCEDURE p1() BEGIN DECLARE a, b INT; DECLARE cur1 CURSOR FOR SELECT pk FROM t1; DELETE FROM t1; INSERT INTO t1 VALUES (1); OPEN cur1; FETCH cur1 INTO a; CLOSE cur1; UPDATE t1 SET pk = 2; OPEN cur1; FETCH cur1 INTO b; CLOSE cur1; SELECT a, b; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {1, 2}, }, }, }, }, { Name: "FETCH captures state at OPEN", SetUpScript: []string{ `CREATE TABLE t1 (pk BIGINT PRIMARY KEY);`, `CREATE PROCEDURE p1() BEGIN DECLARE a, b INT; DECLARE cur1 CURSOR FOR SELECT pk FROM t1; DELETE FROM t1; INSERT INTO t1 VALUES (1); OPEN cur1; UPDATE t1 SET pk = 2; FETCH cur1 INTO a; CLOSE cur1; OPEN cur1; FETCH cur1 INTO b; CLOSE cur1; SELECT a, b; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {1, 2}, }, }, }, }, { Name: "FETCH implicitly closes", SetUpScript: []string{ `CREATE TABLE t1 (pk BIGINT PRIMARY KEY);`, `CREATE PROCEDURE p1() BEGIN DECLARE a INT; DECLARE cur1 CURSOR FOR SELECT pk FROM t1; DELETE FROM t1; INSERT INTO t1 VALUES (4); OPEN cur1; FETCH cur1 INTO a; SELECT a; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {4}, }, }, }, }, { Name: "DECLARE HANDLERs exit according to the block they were declared in", SetUpScript: []string{ `DROP TABLE IF EXISTS t1;`, `CREATE TABLE t1 (pk BIGINT PRIMARY KEY);`, `CREATE PROCEDURE outer_declare() BEGIN DECLARE a, b INT DEFAULT 1; DECLARE cur1 CURSOR FOR SELECT * FROM t1; DECLARE EXIT HANDLER FOR NOT FOUND SET a = 1001; OPEN cur1; BEGIN tloop: LOOP FETCH cur1 INTO b; IF a > 1000 THEN LEAVE tloop; END IF; END LOOP; END; CLOSE cur1; SELECT a; END;`, `CREATE PROCEDURE inner_declare() BEGIN DECLARE a, b INT DEFAULT 1; DECLARE cur1 CURSOR FOR SELECT * FROM t1; DECLARE EXIT HANDLER FOR NOT FOUND SET a = a + 1; OPEN cur1; BEGIN DECLARE EXIT HANDLER FOR NOT FOUND SET a = 1001; tloop: LOOP FETCH cur1 INTO b; IF a > 1000 THEN LEAVE tloop; END IF; END LOOP; END; CLOSE cur1; SELECT a; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL outer_declare();", Expected: []sql.Row{}, }, { Query: "CALL inner_declare();", Expected: []sql.Row{ {1001}, }, }, }, }, { Name: "Labeled BEGIN...END", SetUpScript: []string{ `CREATE PROCEDURE p1() BEGIN DECLARE a INT DEFAULT 1; tblock: BEGIN LOOP SET a = a + 3; LEAVE tblock; END LOOP; END; SELECT a; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {4}, }, }, { Query: `CREATE PROCEDURE p2() BEGIN tblock: BEGIN ITERATE tblock; END; END;`, ExpectedErr: sql.ErrLoopLabelNotFound, }, }, }, { Name: "REPEAT runs loop before first evaluation", SetUpScript: []string{ `CREATE PROCEDURE p1() BEGIN DECLARE a INT DEFAULT 10; REPEAT SET a = a * 5; UNTIL a > 0 END REPEAT; SELECT a; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {50}, }, }, }, }, { Name: "WHILE runs evaluation before first loop", SetUpScript: []string{ `CREATE PROCEDURE p1() BEGIN DECLARE a INT DEFAULT 10; WHILE a < 10 DO SET a = a * 10; END WHILE; SELECT a; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {10}, }, }, }, }, { Name: "ITERATE and LEAVE LOOP", SetUpScript: []string{ `CREATE TABLE t1 (pk BIGINT PRIMARY KEY);`, `INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9)`, `CREATE PROCEDURE p1() BEGIN DECLARE a, b INT DEFAULT 1; DECLARE cur1 CURSOR FOR SELECT * FROM t1; DECLARE EXIT HANDLER FOR NOT FOUND BEGIN END; OPEN cur1; BEGIN tloop: LOOP FETCH cur1 INTO b; SET a = (a + b) * 10; IF a < 1000 THEN ITERATE tloop; ELSE LEAVE tloop; END IF; END LOOP; END; CLOSE cur1; SELECT a; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {2230}, }, }, }, }, { Name: "ITERATE and LEAVE REPEAT", SetUpScript: []string{ `CREATE TABLE t1 (pk BIGINT PRIMARY KEY);`, `INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9)`, `CREATE PROCEDURE p1() BEGIN DECLARE a, b INT DEFAULT 1; DECLARE cur1 CURSOR FOR SELECT * FROM t1; DECLARE EXIT HANDLER FOR NOT FOUND BEGIN END; OPEN cur1; BEGIN tloop: REPEAT FETCH cur1 INTO b; SET a = (a + b) * 10; IF a < 1000 THEN ITERATE tloop; ELSE LEAVE tloop; END IF; UNTIL false END REPEAT; END; CLOSE cur1; SELECT a; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {2230}, }, }, }, }, { Name: "ITERATE and LEAVE WHILE", SetUpScript: []string{ `CREATE TABLE t1 (pk BIGINT PRIMARY KEY);`, `INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9)`, `CREATE PROCEDURE p1() BEGIN DECLARE a, b INT DEFAULT 1; DECLARE cur1 CURSOR FOR SELECT * FROM t1; DECLARE EXIT HANDLER FOR NOT FOUND BEGIN END; OPEN cur1; BEGIN tloop: WHILE true DO FETCH cur1 INTO b; SET a = (a + b) * 10; IF a < 1000 THEN ITERATE tloop; ELSE LEAVE tloop; END IF; END WHILE; END; CLOSE cur1; SELECT a; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {2230}, }, }, }, }, { Name: "Handle setting an uninitialized user variable", SetUpScript: []string{ `CREATE PROCEDURE p1(INOUT param VARCHAR(10)) BEGIN SELECT param; SET param = '5'; END`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(@uservar4);", Expected: []sql.Row{ {nil}, }, }, { Query: "SELECT @uservar4;", Expected: []sql.Row{ {"5"}, }, }, }, }, { Name: "Dolt Issue #4980", SetUpScript: []string{ `CREATE TABLE person_cal_entries (id VARCHAR(36) PRIMARY KEY, cal_entry_id_fk VARCHAR(36), person_id_fk VARCHAR(36));`, `CREATE TABLE personnel (id VARCHAR(36) PRIMARY KEY, event_id VARCHAR(36));`, `CREATE TABLE season_participants (person_id_fk VARCHAR(36), season_id_fk VARCHAR(36));`, `CREATE TABLE cal_entries (id VARCHAR(36) PRIMARY KEY, season_id_fk VARCHAR(36));`, `INSERT INTO personnel VALUES ('6140e23e-7b9b-11ed-a1eb-0242ac120002', 'c546abc4-7b9b-11ed-a1eb-0242ac120002');`, `INSERT INTO season_participants VALUES ('6140e23e-7b9b-11ed-a1eb-0242ac120002', '46d7041e-7b9b-11ed-a1eb-0242ac120002');`, `INSERT INTO cal_entries VALUES ('cb8ba301-6c27-4bf8-b99b-617082d72621', '46d7041e-7b9b-11ed-a1eb-0242ac120002');`, `CREATE PROCEDURE create_cal_entries_for_event(IN event_id VARCHAR(36)) BEGIN INSERT INTO person_cal_entries (id, cal_entry_id_fk, person_id_fk) SELECT 'd17cb898-7b9b-11ed-a1eb-0242ac120002' as id, event_id as cal_entry_id_fk, id as person_id_fk FROM personnel WHERE id IN ( SELECT person_id_fk FROM season_participants WHERE season_id_fk = ( SELECT season_id_fk FROM cal_entries WHERE id = event_id ) ); END`, }, Assertions: []ScriptTestAssertion{ { Query: "call create_cal_entries_for_event('cb8ba301-6c27-4bf8-b99b-617082d72621');", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "SELECT * FROM person_cal_entries;", Expected: []sql.Row{ {"d17cb898-7b9b-11ed-a1eb-0242ac120002", "cb8ba301-6c27-4bf8-b99b-617082d72621", "6140e23e-7b9b-11ed-a1eb-0242ac120002"}, }, }, }, }, { Name: "HANDLERs ignore variables declared after them", SetUpScript: []string{ `CREATE TABLE t1 (pk BIGINT PRIMARY KEY);`, `CREATE PROCEDURE p1() BEGIN DECLARE dvar BIGINT DEFAULT 1; DECLARE cur1 CURSOR FOR SELECT * FROM t1; OPEN cur1; BEGIN DECLARE EXIT HANDLER FOR NOT FOUND SET dvar = 10; BEGIN DECLARE dvar BIGINT DEFAULT 2; BEGIN DECLARE dvar BIGINT DEFAULT 3; LOOP FETCH cur1 INTO dvar; # Handler is triggered here, but should only set the first "dvar" END LOOP; END; END; END; SELECT dvar; END`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {10}, }, }, }, }, { Name: "Duplicate parameter names", Query: "CREATE PROCEDURE p1(abc DATETIME, abc DOUBLE) SELECT abc", ExpectedErr: sql.ErrDeclareVariableDuplicate, }, { Name: "Duplicate parameter names mixed casing", Query: "CREATE PROCEDURE p1(abc DATETIME, ABC DOUBLE) SELECT abc", ExpectedErr: sql.ErrDeclareVariableDuplicate, }, { Name: "Invalid parameter type", Query: "CREATE PROCEDURE p1(x FAKETYPE) SELECT x", ExpectedErr: sql.ErrSyntaxError, }, { Name: "Invalid USE statement", Query: `CREATE PROCEDURE p1() USE mydb`, ExpectedErr: sql.ErrSyntaxError, }, { Name: "Invalid LOCK/UNLOCK statements", SetUpScript: []string{ "CREATE TABLE t1(pk BIGINT PRIMARY KEY)", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE PROCEDURE p1(x BIGINT) LOCK TABLES t1 READ", ExpectedErr: sql.ErrSyntaxError, }, { Query: "CREATE PROCEDURE p1(x BIGINT) UNLOCK TABLES", ExpectedErr: sql.ErrSyntaxError, }, }, }, { Name: "DECLARE CONDITION wrong positions", Assertions: []ScriptTestAssertion{ { Query: `CREATE PROCEDURE p1(x INT) BEGIN SELECT x; DECLARE cond_name CONDITION FOR SQLSTATE '45000'; END;`, ExpectedErr: sql.ErrDeclareConditionOrderInvalid, }, { Query: `CREATE PROCEDURE p1(x INT) BEGIN BEGIN SELECT x; DECLARE cond_name CONDITION FOR SQLSTATE '45000'; END; END;`, ExpectedErr: sql.ErrDeclareConditionOrderInvalid, }, { Query: `CREATE PROCEDURE p1(x INT) BEGIN IF x = 0 THEN DECLARE cond_name CONDITION FOR SQLSTATE '45000'; END IF; END;`, ExpectedErr: sql.ErrDeclareConditionOrderInvalid, }, { Query: `CREATE PROCEDURE p1(x INT) BEGIN IF x = 0 THEN SELECT x; ELSE DECLARE cond_name CONDITION FOR SQLSTATE '45000'; END IF; END;`, ExpectedErr: sql.ErrDeclareConditionOrderInvalid, }, }, }, { Name: "DECLARE CONDITION duplicate name", Query: `CREATE PROCEDURE p1() BEGIN DECLARE cond_name CONDITION FOR SQLSTATE '45000'; DECLARE cond_name CONDITION FOR SQLSTATE '45000'; END;`, ExpectedErr: sql.ErrDeclareConditionDuplicate, }, { Name: "SIGNAL references condition name for MySQL error code", Query: `CREATE PROCEDURE p1(x INT) BEGIN DECLARE mysql_err_code CONDITION FOR 1000; SIGNAL mysql_err_code; END;`, ExpectedErr: sql.ErrUnsupportedSyntax, }, { Name: "SIGNAL non-existent condition name", Query: `CREATE PROCEDURE p1(x INT) BEGIN DECLARE abcdefg CONDITION FOR SQLSTATE '45000'; SIGNAL abcdef; END;`, ExpectedErr: sql.ErrDeclareConditionNotFound, }, { Name: "Duplicate procedure name", SetUpScript: []string{ "CREATE PROCEDURE test_proc(x DOUBLE, y DOUBLE) SELECT x*y", }, Query: "CREATE PROCEDURE test_proc(z VARCHAR(20)) SELECT z", ExpectedErr: sql.ErrStoredProcedureAlreadyExists, }, { Name: "Broken procedure shouldn't break other procedures", SetUpScript: []string{ "CREATE TABLE t (pk INT PRIMARY KEY, other INT);", "INSERT INTO t VALUES (1, 1), (2, 2), (3, 3);", "CREATE PROCEDURE fragile() select other from t;", "CREATE PROCEDURE stable() select pk from t;", }, Assertions: []ScriptTestAssertion{ { Query: "CALL stable();", Expected: []sql.Row{{1}, {2}, {3}}, }, { Query: "CALL fragile();", Expected: []sql.Row{{1}, {2}, {3}}, }, { Query: "SHOW PROCEDURE STATUS LIKE 'stable'", SkipResultsCheck: true, }, { Query: "SHOW PROCEDURE STATUS LIKE 'fragile'", SkipResultsCheck: true, }, { Query: "alter table t drop other;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CALL stable();", Expected: []sql.Row{{1}, {2}, {3}}, }, { Query: "CALL fragile();", ExpectedErrStr: "column \"other\" could not be found in any table in scope", }, { Query: "SHOW PROCEDURE STATUS LIKE 'stable'", SkipResultsCheck: true, }, { Query: "SHOW PROCEDURE STATUS LIKE 'fragile'", SkipResultsCheck: true, }, { Query: "ALTER TABLE t ADD COLUMN other INT", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CALL stable();", Expected: []sql.Row{{1}, {2}, {3}}, }, { Query: "CALL fragile();", Expected: []sql.Row{{nil}, {nil}, {nil}}, }, { Query: "INSERT INTO t VALUES (4, 4), (5, 5), (6, 6);", Expected: []sql.Row{{types.NewOkResult(3)}}, }, { Query: "CALL stable();", Expected: []sql.Row{{1}, {2}, {3}, {4}, {5}, {6}}, }, { Query: "CALL fragile();", Expected: []sql.Row{{nil}, {nil}, {nil}, {4}, {5}, {6}}, }, }, }, { Name: "DECLARE name duplicate same type", Assertions: []ScriptTestAssertion{ { Query: `CREATE PROCEDURE p1() BEGIN DECLARE x INT; DECLARE x INT; SELECT 1; END;`, ExpectedErr: sql.ErrDeclareVariableDuplicate, }, }, }, { Name: "DECLARE name duplicate different type", Assertions: []ScriptTestAssertion{ { Query: `CREATE PROCEDURE p1() BEGIN DECLARE x INT; DECLARE x VARCHAR(20); SELECT 1; END;`, ExpectedErr: sql.ErrDeclareVariableDuplicate, }, }, }, { Name: "Variable, condition, and cursor in invalid order", Assertions: []ScriptTestAssertion{ { Query: `CREATE PROCEDURE p1() BEGIN DECLARE var_name INT; DECLARE cur_name CURSOR FOR SELECT 1; DECLARE cond_name CONDITION FOR SQLSTATE '45000'; SELECT 1; END;`, ExpectedErr: sql.ErrDeclareConditionOrderInvalid, }, { Query: `CREATE PROCEDURE p2() BEGIN DECLARE cond_name CONDITION FOR SQLSTATE '45000'; DECLARE cur_name CURSOR FOR SELECT 1; DECLARE var_name INT; SELECT 1; END;`, ExpectedErr: sql.ErrDeclareVariableOrderInvalid, }, { Query: `CREATE PROCEDURE p3() BEGIN DECLARE cond_name CONDITION FOR SQLSTATE '45000'; DECLARE var_name INT; SELECT 1; DECLARE cur_name CURSOR FOR SELECT 1; END;`, ExpectedErr: sql.ErrDeclareCursorOrderInvalid, }, }, }, { Name: "FETCH non-existent cursor", Assertions: []ScriptTestAssertion{ { Query: `CREATE PROCEDURE p1() BEGIN DECLARE a INT; FETCH no_cursor INTO a; END;`, ExpectedErr: sql.ErrCursorNotFound, }, }, }, { Name: "OPEN non-existent cursor", Assertions: []ScriptTestAssertion{ { Query: `CREATE PROCEDURE p1() BEGIN OPEN no_cursor; END;`, ExpectedErr: sql.ErrCursorNotFound, }, }, }, { Name: "CLOSE non-existent cursor", Assertions: []ScriptTestAssertion{ { Query: `CREATE PROCEDURE p1() BEGIN CLOSE no_cursor; END;`, ExpectedErr: sql.ErrCursorNotFound, }, }, }, { Name: "CLOSE without OPEN", SetUpScript: []string{ `CREATE PROCEDURE p1() BEGIN DECLARE cur1 CURSOR FOR SELECT 1; CLOSE cur1; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", ExpectedErr: sql.ErrCursorNotOpen, }, }, }, { Name: "OPEN repeatedly", SetUpScript: []string{ `CREATE PROCEDURE p1() BEGIN DECLARE cur1 CURSOR FOR SELECT 1; OPEN cur1; OPEN cur1; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", ExpectedErr: sql.ErrCursorAlreadyOpen, }, }, }, { Name: "CLOSE repeatedly", SetUpScript: []string{ `CREATE PROCEDURE p1() BEGIN DECLARE cur1 CURSOR FOR SELECT 1; OPEN cur1; CLOSE cur1; CLOSE cur1; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", ExpectedErr: sql.ErrCursorNotOpen, }, }, }, { Name: "With CTE using variable", SetUpScript: []string{ `CREATE PROCEDURE p1() BEGIN DECLARE v1 INT DEFAULT 1234; WITH cte as (SELECT v1) SELECT * FROM cte; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1();", Expected: []sql.Row{ {1234}, }, }, }, }, { Name: "With CTE using parameter", SetUpScript: []string{ `CREATE PROCEDURE p1(v1 int) BEGIN WITH cte as (SELECT v1) SELECT * FROM cte; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL p1(1234);", Expected: []sql.Row{ {1234}, }, }, }, }, { Name: "Dolt Issue #4480", SetUpScript: []string{ "create table p1 (row_id int primary key, pred int, actual int)", "create table p2 (row_id int primary key, pred int, actual int)", "insert into p1 values (0, 0, 0), (1, 0, 1), (2, 1, 0), (3, 1, 1)", "insert into p2 values (0, 0, 0), (1, 0, 1), (2, 1, 0), (3, 1, 1)", `CREATE PROCEDURE computeSummary(c VARCHAR(200)) BEGIN with t as ( select case when p1.pred = p2.actual then 1 else 0 end as correct, p1.actual from p1 join p2 on p1.row_id = p2.row_id ) select sum(correct)/count(*), count(*) as row_num from t; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL computeSummary('i am not used');", Expected: []sql.Row{ {float64(0.5), 4}, }, }, }, }, }
var ProcedureShowCreate = []ScriptTest{ { Name: "SHOW procedures", SetUpScript: []string{ "CREATE PROCEDURE p1() COMMENT 'hi' DETERMINISTIC SELECT 6", "CREATE definer=`user` PROCEDURE p2() SQL SECURITY INVOKER SELECT 7", "CREATE PROCEDURE p21() SQL SECURITY DEFINER SELECT 8", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE PROCEDURE p1", Expected: []sql.Row{ { "p1", "", "CREATE PROCEDURE p1() COMMENT 'hi' DETERMINISTIC SELECT 6", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE PROCEDURE p2", Expected: []sql.Row{ { "p2", "", "CREATE definer=`user` PROCEDURE p2() SQL SECURITY INVOKER SELECT 7", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, }, }, { Query: "SHOW CREATE PROCEDURE p21", Expected: []sql.Row{ { "p21", "", "CREATE PROCEDURE p21() SQL SECURITY DEFINER SELECT 8", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, }, }, }, }, { Name: "SHOW non-existent procedures", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE PROCEDURE p1", ExpectedErr: sql.ErrStoredProcedureDoesNotExist, }, }, }, }
var ProcedureShowStatus = []ScriptTest{ { Name: "SHOW procedures", SetUpScript: []string{ "CREATE PROCEDURE p1() COMMENT 'hi' DETERMINISTIC SELECT 6", "CREATE definer=`user` PROCEDURE p2() SQL SECURITY INVOKER SELECT 7", "CREATE PROCEDURE p21() SQL SECURITY DEFINER SELECT 8", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW PROCEDURE STATUS", Expected: []sql.Row{ { "mydb", "p1", "PROCEDURE", "", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "DEFINER", "hi", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, { "mydb", "p2", "PROCEDURE", "user@%", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "INVOKER", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, { "mydb", "p21", "PROCEDURE", "", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "DEFINER", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, }, }, { Query: "SHOW PROCEDURE STATUS LIKE 'p2%'", Expected: []sql.Row{ { "mydb", "p2", "PROCEDURE", "user@%", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "INVOKER", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, { "mydb", "p21", "PROCEDURE", "", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "DEFINER", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, }, }, { Query: "SHOW PROCEDURE STATUS LIKE 'p4'", Expected: []sql.Row{}, }, { Query: "SHOW PROCEDURE STATUS WHERE Db = 'mydb'", Expected: []sql.Row{ { "mydb", "p1", "PROCEDURE", "", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "DEFINER", "hi", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, { "mydb", "p2", "PROCEDURE", "user@%", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "INVOKER", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, { "mydb", "p21", "PROCEDURE", "", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "DEFINER", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, }, }, { Query: "SHOW PROCEDURE STATUS WHERE Name LIKE '%1'", Expected: []sql.Row{ { "mydb", "p1", "PROCEDURE", "", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "DEFINER", "hi", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, { "mydb", "p21", "PROCEDURE", "", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "DEFINER", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, }, }, { Query: "SHOW PROCEDURE STATUS WHERE Security_type = 'INVOKER'", Expected: []sql.Row{ { "mydb", "p2", "PROCEDURE", "user@%", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "INVOKER", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, }, }, { Query: "SHOW PROCEDURE STATUS", Expected: []sql.Row{ { "mydb", "p1", "PROCEDURE", "", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "DEFINER", "hi", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, { "mydb", "p2", "PROCEDURE", "user@%", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "INVOKER", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, { "mydb", "p21", "PROCEDURE", "", time.Unix(0, 0).UTC(), time.Unix(0, 0).UTC(), "DEFINER", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin", }, }, }, }, }, }
var QueryPlanTODOs = []QueryPlanTest{
{
Query: `SELECT pk,i,f FROM one_pk RIGHT JOIN niltable ON pk=i and pk > 0 ORDER BY 2,3`,
ExpectedPlan: "Sort(niltable.i ASC, niltable.f ASC)\n" +
" └─ Project(one_pk.pk, niltable.i, niltable.f)\n" +
" └─ RightJoin((one_pk.pk = niltable.i) AND (one_pk.pk > 0))\n" +
" ├─ Projected table access on [pk]\n" +
" │ └─ Table(one_pk)\n" +
" └─ Projected table access on [i f]\n" +
" └─ Table(niltable)\n" +
"",
},
}
QueryPlanTODOs are queries where the query planner produces a correct (results) but suboptimal plan.
var QueryTests = []QueryTest{}/* 1194 elements not displayed */
var QuickPrivTests = []QuickPrivilegeTest{ { Queries: []string{ "GRANT SELECT ON *.* TO tester@localhost", "SELECT * FROM mydb.test", }, Expected: []sql.Row{{0, 0}, {1, 1}}, }, { Queries: []string{ "GRANT SELECT ON mydb.* TO tester@localhost", "SELECT * FROM mydb.test", }, Expected: []sql.Row{{0, 0}, {1, 1}}, }, { Queries: []string{ "GRANT SELECT ON mydb.* TO tester@localhost", "SELECT * FROM mydb.test2", }, Expected: []sql.Row{{0, 1}, {1, 2}}, }, { Queries: []string{ "GRANT SELECT ON mydb.test TO tester@localhost", "SELECT * FROM mydb.test", }, Expected: []sql.Row{{0, 0}, {1, 1}}, }, { Queries: []string{ "GRANT SELECT ON mydb.test TO tester@localhost", "SELECT * FROM mydb.test2", }, ExpectingErr: true, }, { Queries: []string{ "GRANT SELECT ON otherdb.* TO tester@localhost", "SELECT * FROM mydb.test", }, ExpectingErr: true, }, { Queries: []string{ "GRANT SELECT ON otherdb.test TO tester@localhost", "SELECT * FROM mydb.test", }, ExpectingErr: true, }, { Queries: []string{ "GRANT SELECT ON otherdb.test TO tester@localhost", "SELECT * FROM mydb.test", }, ExpectingErr: true, }, { Queries: []string{ "GRANT SELECT ON *.* TO tester@localhost", "USE mydb;", "SHOW TABLES;", }, Expected: []sql.Row{{"test"}, {"test2"}}, }, { Queries: []string{ "GRANT SELECT ON mydb.* TO tester@localhost", "USE mydb;", "SHOW TABLES;", }, Expected: []sql.Row{{"test"}, {"test2"}}, }, { Queries: []string{ "GRANT SELECT ON mydb.test TO tester@localhost", "USE mydb;", "SHOW TABLES;", }, Expected: []sql.Row{{"test"}}, }, { Queries: []string{ "GRANT SELECT ON mydb.non_exist TO tester@localhost", "USE mydb;", "SHOW TABLES;", }, Expected: []sql.Row{}, }, { Queries: []string{ "ALTER TABLE mydb.test ADD COLUMN new_column BIGINT;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT ALTER ON *.* TO tester@localhost", "ALTER TABLE mydb.test ADD COLUMN new_column BIGINT", }, }, { Queries: []string{ "GRANT ALTER ON mydb.* TO tester@localhost", "ALTER TABLE mydb.test ADD COLUMN new_column BIGINT;", }, }, { Queries: []string{ "GRANT ALTER ON mydb.test TO tester@localhost", "ALTER TABLE mydb.test ADD COLUMN new_column BIGINT;", }, }, { Queries: []string{ "ALTER TABLE mydb.test RENAME TO mydb.new_test;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT ALTER ON *.* TO tester@localhost", "ALTER TABLE mydb.test RENAME TO mydb.new_test;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT ALTER, CREATE, DROP, INSERT ON *.* TO tester@localhost", "ALTER TABLE mydb.test RENAME TO mydb.new_test;", }, }, { Queries: []string{ "GRANT ALTER, CREATE, DROP, INSERT ON mydb.* TO tester@localhost", "ALTER TABLE mydb.test RENAME TO mydb.new_test;", }, }, { Queries: []string{ "GRANT ALTER, CREATE, DROP, INSERT ON mydb.test TO tester@localhost", "ALTER TABLE mydb.test RENAME TO mydb.new_test;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT ALTER, DROP ON mydb.test TO tester@localhost", "GRANT CREATE, INSERT ON mydb.new_test TO tester@localhost", "ALTER TABLE mydb.test RENAME TO mydb.new_test;", }, }, { Queries: []string{ "GRANT ALTER ON mydb.test TO tester@localhost", "GRANT CREATE, INSERT ON mydb.new_test TO tester@localhost", "ALTER TABLE mydb.test RENAME TO mydb.new_test;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT DROP ON mydb.test TO tester@localhost", "GRANT CREATE, INSERT ON mydb.new_test TO tester@localhost", "ALTER TABLE mydb.test RENAME TO mydb.new_test;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT ALTER, DROP ON mydb.test TO tester@localhost", "GRANT CREATE ON mydb.new_test TO tester@localhost", "ALTER TABLE mydb.test RENAME TO mydb.new_test;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT ALTER, DROP ON mydb.test TO tester@localhost", "GRANT INSERT ON mydb.new_test TO tester@localhost", "ALTER TABLE mydb.test RENAME TO mydb.new_test;", }, ExpectingErr: true, }, { Queries: []string{ "USE mydb;", "CREATE PROCEDURE new_proc (x DOUBLE, y DOUBLE) SELECT x*y;", "DROP PROCEDURE new_proc;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT ALTER ROUTINE ON *.* TO tester@localhost", "USE mydb;", "CREATE PROCEDURE new_proc (x DOUBLE, y DOUBLE) SELECT x*y;", "DROP PROCEDURE new_proc;", }, }, { Queries: []string{ "GRANT ALTER ROUTINE ON mydb.* TO tester@localhost", "USE mydb;", "CREATE PROCEDURE new_proc (x DOUBLE, y DOUBLE) SELECT x*y;", "DROP PROCEDURE new_proc;", }, }, { Queries: []string{ "CREATE DATABASE new_db;", }, ExpectingErr: true, }, { Queries: []string{ "CREATE TABLE mydb.new_table (pk BIGINT PRIMARY KEY);", }, ExpectingErr: true, }, { Queries: []string{ "GRANT CREATE ON *.* TO tester@localhost", "CREATE DATABASE new_db2;", "GRANT DROP ON *.* TO tester@localhost", "drop database new_db2", }, }, { Queries: []string{ "GRANT CREATE ON *.* TO tester@localhost", "CREATE TABLE mydb.new_table (pk BIGINT PRIMARY KEY);", }, }, { Queries: []string{ "GRANT CREATE ON mydb.* TO tester@localhost", "CREATE DATABASE new_db3;", "GRANT DROP ON *.* TO tester@localhost", "drop database new_db3", }, }, { Queries: []string{ "GRANT CREATE ON mydb.* TO tester@localhost", "CREATE TABLE mydb.new_table (pk BIGINT PRIMARY KEY);", }, }, { Queries: []string{ "CREATE ROLE new_role;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT CREATE ROLE ON *.* TO tester@localhost", "CREATE ROLE new_role;", }, }, { Queries: []string{ "USE mydb;", "CREATE PROCEDURE new_proc (x DOUBLE, y DOUBLE) SELECT x*y;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT CREATE ROUTINE ON *.* TO tester@localhost", "USE mydb;", "CREATE PROCEDURE new_proc (x DOUBLE, y DOUBLE) SELECT x*y;", }, }, { Queries: []string{ "GRANT CREATE ROUTINE ON mydb.* TO tester@localhost", "USE mydb;", "CREATE PROCEDURE new_proc (x DOUBLE, y DOUBLE) SELECT x*y;", }, }, { Queries: []string{ "CREATE USER new_user;", }, ExpectingErr: true, }, { Queries: []string{ "CREATE USER new_user;", "DROP USER new_user;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT CREATE USER ON *.* TO tester@localhost", "CREATE USER new_user;", }, }, { Queries: []string{ "GRANT CREATE USER ON *.* TO tester@localhost", "CREATE USER new_user;", "DROP USER new_user;", }, }, { Queries: []string{ "GRANT CREATE USER ON *.* TO tester@localhost", "CREATE ROLE new_role;", }, }, { Queries: []string{ "GRANT CREATE USER ON *.* TO tester@localhost", "CREATE ROLE new_role;", "DROP ROLE new_role;", }, }, { Queries: []string{ "CREATE VIEW new_view AS SELECT 1;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT CREATE VIEW ON *.* TO tester@localhost", "CREATE VIEW new_view AS SELECT 1;", }, }, { Queries: []string{ "DELETE FROM mydb.test WHERE pk >= 0;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT DELETE ON *.* TO tester@localhost", "DELETE FROM mydb.test WHERE pk >= 0;", }, }, { Queries: []string{ "GRANT DELETE ON mydb.* TO tester@localhost", "DELETE FROM mydb.test WHERE pk >= 0;", }, }, { Queries: []string{ "GRANT DELETE ON mydb.test TO tester@localhost", "DELETE FROM mydb.test WHERE pk >= 0;", }, }, { Queries: []string{ "DELETE test, test2 FROM mydb.test join mydb.test2 where test.pk=test2.pk", }, ExpectingErr: true, }, { Queries: []string{ "GRANT DELETE ON mydb.test TO tester@localhost", "DELETE test, test2 FROM mydb.test join mydb.test2 where test.pk=test2.pk", }, ExpectingErr: true, }, { Queries: []string{ "GRANT DELETE ON mydb.test2 TO tester@localhost", "DELETE test, test2 FROM mydb.test join mydb.test2 where test.pk=test2.pk", }, ExpectingErr: true, }, { Queries: []string{ "GRANT DELETE ON mydb.test TO tester@localhost", "GRANT DELETE ON mydb.test2 TO tester@localhost", "DELETE test, test2 FROM mydb.test join mydb.test2 where test.pk=test2.pk", }, }, { Queries: []string{ "CREATE DATABASE new_db4;", }, ExpectingErr: true, }, { Queries: []string{ "CREATE TABLE mydb.new_table (pk BIGINT PRIMARY KEY);", "DROP TABLE mydb.new_table;", }, ExpectingErr: true, }, { Queries: []string{ "CREATE VIEW new_view AS SELECT 1;", "DROP VIEW new_view;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT DROP ON *.* TO tester@localhost", "CREATE DATABASE new_db5;", "GRANT DROP ON *.* TO tester@localhost", "DROP DATABASE new_db5;", }, }, { Queries: []string{ "GRANT DROP ON *.* TO tester@localhost", "CREATE TABLE mydb.new_table (pk BIGINT PRIMARY KEY);", "DROP TABLE mydb.new_table;", }, }, { Queries: []string{ "GRANT DROP ON *.* TO tester@localhost", "CREATE TABLE mydb.new_table1 (pk BIGINT PRIMARY KEY);", "CREATE TABLE mydb.new_table2 (pk BIGINT PRIMARY KEY);", "DROP TABLE mydb.new_table1, mydb.new_table2;", }, }, { Queries: []string{ "GRANT DROP ON *.* TO tester@localhost", "CREATE VIEW new_view AS SELECT 1;", "DROP VIEW new_view;", }, }, { Queries: []string{ "GRANT DROP ON mydb.* TO tester@localhost", "CREATE TABLE mydb.new_table (pk BIGINT PRIMARY KEY);", "DROP TABLE mydb.new_table;", }, }, { Queries: []string{ "GRANT DROP ON mydb.* TO tester@localhost", "CREATE TABLE mydb.new_table1 (pk BIGINT PRIMARY KEY);", "CREATE TABLE mydb.new_table2 (pk BIGINT PRIMARY KEY);", "DROP TABLE mydb.new_table1, mydb.new_table2;", }, }, { Queries: []string{ "GRANT DROP ON mydb.new_table TO tester@localhost", "CREATE TABLE mydb.new_table (pk BIGINT PRIMARY KEY);", "DROP TABLE mydb.new_table;", }, }, { Queries: []string{ "GRANT DROP ON mydb.new_table1 TO tester@localhost", "CREATE TABLE mydb.new_table1 (pk BIGINT PRIMARY KEY);", "CREATE TABLE mydb.new_table2 (pk BIGINT PRIMARY KEY);", "DROP TABLE mydb.new_table1, mydb.new_table2;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT DROP ON mydb.new_table2 TO tester@localhost", "CREATE TABLE mydb.new_table1 (pk BIGINT PRIMARY KEY);", "CREATE TABLE mydb.new_table2 (pk BIGINT PRIMARY KEY);", "DROP TABLE mydb.new_table1, mydb.new_table2;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT DROP ON mydb.new_table1 TO tester@localhost", "GRANT DROP ON mydb.new_table2 TO tester@localhost", "CREATE TABLE mydb.new_table1 (pk BIGINT PRIMARY KEY);", "CREATE TABLE mydb.new_table2 (pk BIGINT PRIMARY KEY);", "DROP TABLE mydb.new_table1, mydb.new_table2;", }, }, { Queries: []string{ "CREATE ROLE new_role;", "DROP ROLE new_role;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT DROP ROLE ON *.* TO tester@localhost", "CREATE ROLE new_role;", "DROP ROLE new_role;", }, }, { Queries: []string{ "CREATE INDEX new_idx ON mydb.test (v1);", }, ExpectingErr: true, }, { Queries: []string{ "CREATE INDEX new_idx ON mydb.test (v1);", "DROP INDEX new_idx ON mydb.test;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT INDEX ON *.* TO tester@localhost", "CREATE INDEX new_idx ON mydb.test (v1);", }, }, { Queries: []string{ "GRANT INDEX ON *.* TO tester@localhost", "CREATE INDEX new_idx ON mydb.test (v1);", "DROP INDEX new_idx ON mydb.test;", }, }, { Queries: []string{ "GRANT INDEX ON mydb.* TO tester@localhost", "CREATE INDEX new_idx ON mydb.test (v1);", }, }, { Queries: []string{ "GRANT INDEX ON mydb.* TO tester@localhost", "CREATE INDEX new_idx ON mydb.test (v1);", "DROP INDEX new_idx ON mydb.test;", }, }, { Queries: []string{ "GRANT INDEX ON mydb.test TO tester@localhost", "CREATE INDEX new_idx ON mydb.test (v1);", }, }, { Queries: []string{ "GRANT INDEX ON mydb.test TO tester@localhost", "CREATE INDEX new_idx ON mydb.test (v1);", "DROP INDEX new_idx ON mydb.test;", }, }, { Queries: []string{ "INSERT INTO mydb.test VALUES (9, 9);", }, ExpectingErr: true, }, { Queries: []string{ "GRANT INSERT ON *.* TO tester@localhost", "INSERT INTO mydb.test VALUES (9, 9);", }, }, { Queries: []string{ "GRANT INSERT ON mydb.* TO tester@localhost", "INSERT INTO mydb.test VALUES (9, 9);", }, }, { Queries: []string{ "GRANT INSERT ON mydb.test TO tester@localhost", "INSERT INTO mydb.test VALUES (9, 9);", }, }, { Queries: []string{ "CREATE TRIGGER new_trig BEFORE INSERT ON mydb.test2 FOR EACH ROW SET NEW.v1 = NEW.pk * NEW.v1;", }, ExpectingErr: true, }, { Queries: []string{ "CREATE TRIGGER new_trig BEFORE INSERT ON mydb.test2 FOR EACH ROW SET NEW.v1 = NEW.pk * NEW.v1;", "DROP TRIGGER new_trig;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT TRIGGER ON *.* TO tester@localhost", "CREATE TRIGGER new_trig BEFORE INSERT ON mydb.test2 FOR EACH ROW SET NEW.v1 = NEW.pk * NEW.v1;", }, }, { Queries: []string{ "GRANT TRIGGER ON *.* TO tester@localhost", "CREATE TRIGGER new_trig BEFORE INSERT ON mydb.test2 FOR EACH ROW SET NEW.v1 = NEW.pk * NEW.v1;", "DROP TRIGGER new_trig;", }, }, { Queries: []string{ "GRANT TRIGGER ON mydb.* TO tester@localhost", "CREATE TRIGGER new_trig BEFORE INSERT ON mydb.test2 FOR EACH ROW SET NEW.v1 = NEW.pk * NEW.v1;", }, }, { Queries: []string{ "GRANT TRIGGER ON mydb.* TO tester@localhost", "CREATE TRIGGER new_trig BEFORE INSERT ON mydb.test2 FOR EACH ROW SET NEW.v1 = NEW.pk * NEW.v1;", "DROP TRIGGER new_trig;", }, }, { Queries: []string{ "UPDATE mydb.test SET v1 = 0;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT UPDATE ON *.* TO tester@localhost", "UPDATE mydb.test SET v1 = 0;", }, }, { Queries: []string{ "GRANT UPDATE ON mydb.* TO tester@localhost", "UPDATE mydb.test SET v1 = 0;", }, }, { Queries: []string{ "GRANT UPDATE ON mydb.test TO tester@localhost", "UPDATE mydb.test SET v1 = 0;", }, }, { Queries: []string{ "FLUSH PRIVILEGES;", }, ExpectingErr: true, }, { Queries: []string{ "GRANT RELOAD ON *.* TO tester@localhost", "FLUSH PRIVILEGES;", }, }, }
QuickPrivTests are test that specifically attempt to test as many privileges against as many statements as possible, while being as succinct as possible. All tests here could be fully represented as a UserPrivilegeTest, however each equivalent test would comparatively take up many more lines. This is intended to have as many tests as possible that are as quick to write as possible.
var RegexTests = []RegexTest{}/* 514 elements not displayed */
var ReplaceErrorTests = []GenericErrorQueryTest{
{
Name: "too few values",
Query: "REPLACE INTO mytable (s, i) VALUES ('x');",
},
{
Name: "too many values one column",
Query: "REPLACE INTO mytable (s) VALUES ('x', 999);",
},
{
Name: "too many values two columns",
Query: "REPLACE INTO mytable (i, s) VALUES (999, 'x', 'y');",
},
{
Name: "too few values no columns specified",
Query: "REPLACE INTO mytable VALUES (999);",
},
{
Name: "too many values no columns specified",
Query: "REPLACE INTO mytable VALUES (999, 'x', 'y');",
},
{
Name: "non-existent column values",
Query: "REPLACE INTO mytable (i, s, z) VALUES (999, 'x', 999);",
},
{
Name: "non-existent column set",
Query: "REPLACE INTO mytable SET i = 999, s = 'x', z = 999;",
},
{
Name: "duplicate column values",
Query: "REPLACE INTO mytable (i, s, s) VALUES (999, 'x', 'x');",
},
{
Name: "duplicate column set",
Query: "REPLACE INTO mytable SET i = 999, s = 'y', s = 'y';",
},
{
Name: "null given to non-nullable values",
Query: "INSERT INTO mytable (i, s) VALUES (null, 'y');",
},
{
Name: "null given to non-nullable set",
Query: "INSERT INTO mytable SET i = null, s = 'y';",
},
}
var ReplaceQueries = []WriteQueryTest{ { WriteQuery: "REPLACE INTO mytable VALUES (1, 'first row');", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT s FROM mytable WHERE i = 1;", ExpectedSelect: []sql.Row{{"first row"}}, }, { WriteQuery: "REPLACE INTO mytable SET i = 1, s = 'first row';", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT s FROM mytable WHERE i = 1;", ExpectedSelect: []sql.Row{{"first row"}}, }, { WriteQuery: "REPLACE INTO mytable VALUES (1, 'new row same i');", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT s FROM mytable WHERE i = 1;", ExpectedSelect: []sql.Row{{"new row same i"}}, }, { WriteQuery: "REPLACE INTO mytable SET i = 1, s = 'new row same i';", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT s FROM mytable WHERE i = 1;", ExpectedSelect: []sql.Row{{"new row same i"}}, }, { WriteQuery: "REPLACE INTO mytable (s, i) VALUES ('x', 999);", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT i FROM mytable WHERE s = 'x';", ExpectedSelect: []sql.Row{{int64(999)}}, }, { WriteQuery: "REPLACE INTO mytable SET s = 'x', i = 999;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT i FROM mytable WHERE s = 'x';", ExpectedSelect: []sql.Row{{int64(999)}}, }, { WriteQuery: "REPLACE INTO mytable VALUES (999, 'x');", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT i FROM mytable WHERE s = 'x';", ExpectedSelect: []sql.Row{{int64(999)}}, }, { WriteQuery: "REPLACE INTO mytable SET i = 999, s = 'x';", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT i FROM mytable WHERE s = 'x';", ExpectedSelect: []sql.Row{{int64(999)}}, }, { WriteQuery: `REPLACE INTO typestable VALUES ( 999, 127, 32767, 2147483647, 9223372036854775807, 255, 65535, 4294967295, 18446744073709551615, 3.40282346638528859811704183484516925440e+38, 1.797693134862315708145274237317043567981e+308, '2037-04-05 12:51:36', '2231-11-07', 'random text', true, '{"key":"value"}', 'blobdata', 'v1', 'v2' );`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{ int64(999), int8(math.MaxInt8), int16(math.MaxInt16), int32(math.MaxInt32), int64(math.MaxInt64), uint8(math.MaxUint8), uint16(math.MaxUint16), uint32(math.MaxUint32), uint64(math.MaxUint64), float32(math.MaxFloat32), float64(math.MaxFloat64), sql.MustConvert(types.Timestamp.Convert("2037-04-05 12:51:36")), sql.MustConvert(types.Date.Convert("2231-11-07")), "random text", sql.True, types.MustJSON(`{"key":"value"}`), []byte("blobdata"), uint(2), uint(4), }}, }, { WriteQuery: `REPLACE INTO typestable SET id = 999, i8 = 127, i16 = 32767, i32 = 2147483647, i64 = 9223372036854775807, u8 = 255, u16 = 65535, u32 = 4294967295, u64 = 18446744073709551615, f32 = 3.40282346638528859811704183484516925440e+38, f64 = 1.797693134862315708145274237317043567981e+308, ti = '2037-04-05 12:51:36', da = '2231-11-07', te = 'random text', bo = true, js = '{"key":"value"}', bl = 'blobdata', e1 = 'v1', s1 = 'v2' ;`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{ int64(999), int8(math.MaxInt8), int16(math.MaxInt16), int32(math.MaxInt32), int64(math.MaxInt64), uint8(math.MaxUint8), uint16(math.MaxUint16), uint32(math.MaxUint32), uint64(math.MaxUint64), float32(math.MaxFloat32), float64(math.MaxFloat64), sql.MustConvert(types.Timestamp.Convert("2037-04-05 12:51:36")), sql.MustConvert(types.Date.Convert("2231-11-07")), "random text", sql.True, types.MustJSON(`{"key":"value"}`), []byte("blobdata"), uint(2), uint(4), }}, }, { WriteQuery: `REPLACE INTO typestable VALUES ( 999, -128, -32768, -2147483648, -9223372036854775808, 0, 0, 0, 0, 1.401298464324817070923729583289916131280e-45, 4.940656458412465441765687928682213723651e-324, '0000-00-00 00:00:00', '0000-00-00', '', false, '""', '', '', '' );`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{ int64(999), int8(-math.MaxInt8 - 1), int16(-math.MaxInt16 - 1), int32(-math.MaxInt32 - 1), int64(-math.MaxInt64 - 1), uint8(0), uint16(0), uint32(0), uint64(0), float32(math.SmallestNonzeroFloat32), float64(math.SmallestNonzeroFloat64), types.Timestamp.Zero(), types.Date.Zero(), "", sql.False, types.MustJSON(`""`), []byte(""), uint(1), uint(0), }}, }, { WriteQuery: `REPLACE INTO typestable SET id = 999, i8 = -128, i16 = -32768, i32 = -2147483648, i64 = -9223372036854775808, u8 = 0, u16 = 0, u32 = 0, u64 = 0, f32 = 1.401298464324817070923729583289916131280e-45, f64 = 4.940656458412465441765687928682213723651e-324, ti = '0000-00-00 00:00:00', da = '0000-00-00', te = '', bo = false, js = '""', bl = '', e1 = '', s1 = '' ;`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{ int64(999), int8(-math.MaxInt8 - 1), int16(-math.MaxInt16 - 1), int32(-math.MaxInt32 - 1), int64(-math.MaxInt64 - 1), uint8(0), uint16(0), uint32(0), uint64(0), float32(math.SmallestNonzeroFloat32), float64(math.SmallestNonzeroFloat64), types.Timestamp.Zero(), types.Date.Zero(), "", sql.False, types.MustJSON(`""`), []byte(""), uint(1), uint(0), }}, }, { WriteQuery: `REPLACE INTO typestable VALUES (999, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{int64(999), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}}, }, { WriteQuery: `REPLACE INTO typestable SET id=999, i8=null, i16=null, i32=null, i64=null, u8=null, u16=null, u32=null, u64=null, f32=null, f64=null, ti=null, da=null, te=null, bo=null, js=null, bl=null, e1=null, s1=null;`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM typestable WHERE id = 999;", ExpectedSelect: []sql.Row{{int64(999), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}}, }, }
TODO: none of these tests insert into tables without primary key columns, which have different semantics for REPLACE INTO queries. Add some tables / data without primary keys.
var RollbackTriggerTests = []ScriptTest{ { Name: "trigger before insert, reverts insert when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "create trigger trig before insert on a for each row insert into b values (new.i);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (2)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "select x from b order by x", Expected: []sql.Row{ {1}, {2}, }, }, { Query: "insert into a values (1)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from b", Expected: []sql.Row{ {1}, {2}, }, }, }, }, { Name: "trigger after insert, reverts insert when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "create trigger trig after insert on a for each row insert into b values (new.i);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (2)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "select x from b order by x", Expected: []sql.Row{ {1}, {2}, }, }, { Query: "insert into a values (1)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from b", Expected: []sql.Row{ {1}, {2}, }, }, }, }, { Name: "trigger before insert, reverts update when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "insert into b values (0)", "create trigger trig before insert on a for each row update b set x = x + 1;", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (2)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "select * from b", Expected: []sql.Row{ {2}, }, }, { Query: "insert into a values (1)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from b", Expected: []sql.Row{ {2}, }, }, }, }, { Name: "trigger after insert, reverts update when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "insert into b values (0)", "create trigger trig after insert on a for each row update b set x = x + 1;", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (2)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "select * from b", Expected: []sql.Row{ {2}, }, }, { Query: "insert into a values (1)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from b", Expected: []sql.Row{ {2}, }, }, }, }, { Name: "trigger before insert, reverts delete when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "insert into a values (1)", "insert into b values (1), (2)", "create trigger trig before insert on a for each row delete from b where x = new.i;", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (2)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, { Query: "select x from b order by x", Expected: []sql.Row{ {1}, }, }, { Query: "insert into a values (1)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from b", Expected: []sql.Row{ {1}, }, }, }, }, { Name: "trigger after insert, reverts delete when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "insert into a values (1)", "insert into b values (1), (2)", "create trigger trig after insert on a for each row delete from b where x = new.i;", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (2)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, { Query: "select x from b order by x", Expected: []sql.Row{ {1}, }, }, { Query: "insert into a values (1)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from b", Expected: []sql.Row{ {1}, }, }, }, }, { Name: "trigger before insert, reverts multiple inserts when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "create trigger trig before insert on a for each row insert into b values (new.i);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (1)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from a", Expected: []sql.Row{}, }, { Query: "select * from b", Expected: []sql.Row{}, }, { Query: "insert into a values (0)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, { Query: "insert into a values (1), (2), (0)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from a", Expected: []sql.Row{ {0}, }, }, { Query: "select * from b", Expected: []sql.Row{ {0}, }, }, }, }, { Name: "trigger after insert, reverts multiple inserts when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "create trigger trig after insert on a for each row insert into b values (new.i);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (1)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from a", Expected: []sql.Row{}, }, { Query: "select * from b", Expected: []sql.Row{}, }, { Query: "insert into a values (0)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, { Query: "insert into a values (1), (2), (0)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from a", Expected: []sql.Row{ {0}, }, }, { Query: "select * from b", Expected: []sql.Row{ {0}, }, }, }, }, { Name: "trigger before update, reverts insert when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "insert into a values (0)", "create trigger trig before update on a for each row insert into b values (new.i);", }, Assertions: []ScriptTestAssertion{ { Query: "update a set i = 1", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }, }}, }, }, { Query: "select x from b", Expected: []sql.Row{ {1}, }, }, { Query: "update a set i = 'not int'", ExpectedErrStr: "error: 'not int' is not a valid value for 'int'", }, { Query: "select * from b", Expected: []sql.Row{ {1}, }, }, }, }, { Name: "trigger after update, reverts insert when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "insert into a values (0)", "create trigger trig after update on a for each row insert into b values (new.i);", }, Assertions: []ScriptTestAssertion{ { Query: "update a set i = 1", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }, }}, }, }, { Query: "select x from b", Expected: []sql.Row{ {1}, }, }, { Query: "update a set i = 'not int'", ExpectedErrStr: "error: 'not int' is not a valid value for 'int'", }, { Query: "select * from b", Expected: []sql.Row{ {1}, }, }, }, }, { Name: "trigger before update, reverts update when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "insert into a values (0)", "insert into b values (0)", "create trigger trig before update on a for each row update b set x = x + new.i;", }, Assertions: []ScriptTestAssertion{ { Query: "update a set i = 1", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }, }}, }, }, { Query: "select x from b", Expected: []sql.Row{ {1}, }, }, { Query: "update a set i = 'not int'", ExpectedErrStr: "error: 'not int' is not a valid value for 'int'", }, { Query: "select * from b", Expected: []sql.Row{ {1}, }, }, }, }, { Name: "trigger after update, reverts update when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "insert into a values (0)", "insert into b values (0)", "create trigger trig after update on a for each row update b set x = x + new.i;", }, Assertions: []ScriptTestAssertion{ { Query: "update a set i = 1", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }, }}, }, }, { Query: "select x from b", Expected: []sql.Row{ {1}, }, }, { Query: "update a set i = 'not int'", ExpectedErrStr: "error: 'not int' is not a valid value for 'int'", }, { Query: "select * from b", Expected: []sql.Row{ {1}, }, }, }, }, { Name: "trigger before update, reverts delete when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "insert into a values (0)", "insert into b values (1), (2)", "create trigger trig before update on a for each row delete from b where x = new.i;", }, Assertions: []ScriptTestAssertion{ { Query: "update a set i = 1", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }, }}, }, }, { Query: "select x from b", Expected: []sql.Row{ {2}, }, }, { Query: "update a set i = 'not int'", ExpectedErrStr: "error: 'not int' is not a valid value for 'int'", }, { Query: "select * from b", Expected: []sql.Row{ {2}, }, }, }, }, { Name: "trigger after update, reverts delete when query fails", SetUpScript: []string{ "create table a (i int primary key)", "create table b (x int)", "insert into a values (0)", "insert into b values (1), (2)", "create trigger trig after update on a for each row delete from b where x = new.i;", }, Assertions: []ScriptTestAssertion{ { Query: "update a set i = 1", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }, }}, }, }, { Query: "select x from b", Expected: []sql.Row{ {2}, }, }, { Query: "update a set i = 'not int'", ExpectedErrStr: "error: 'not int' is not a valid value for 'int'", }, { Query: "select * from b", Expected: []sql.Row{ {2}, }, }, }, }, { Name: "triggers before and after insert fails, rollback", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create trigger a1 before insert on a for each row insert into b values (NEW.x * 7)", "create trigger a2 after insert on a for each row insert into b values (New.x * 11)", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (2), (3), (5)", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select x from a order by 1", Expected: []sql.Row{ {2}, {3}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {14}, {21}, {22}, {33}, {35}, {55}, }, }, { Query: "insert into a values (2), (3), (5)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select x from a order by 1", Expected: []sql.Row{ {2}, {3}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {14}, {21}, {22}, {33}, {35}, {55}, }, }, }, }, { Name: "autocommit off, trigger before insert, reverts insert when query fails", SetUpScript: []string{ "set @@autocommit = off", "create table a (i int primary key)", "create table b (x int)", "create trigger trig before insert on a for each row insert into b values (new.i);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (2)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "select x from b order by x", Expected: []sql.Row{ {1}, {2}, }, }, { Query: "insert into a values (1)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "select * from b", Expected: []sql.Row{ {1}, {2}, }, }, }, }, { Name: "trigger before update, reverts insert when query fails", SetUpScript: []string{ "set @@autocommit = off", "create table a (i int primary key)", "create table b (x int)", "insert into a values (0)", "create trigger trig before update on a for each row insert into b values (new.i);", }, Assertions: []ScriptTestAssertion{ { Query: "update a set i = 1", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }, }}, }, }, { Query: "select x from b", Expected: []sql.Row{ {1}, }, }, { Query: "update a set i = 'not int'", ExpectedErrStr: "error: 'not int' is not a valid value for 'int'", }, { Query: "select * from b", Expected: []sql.Row{ {1}, }, }, }, }, }
RollbackTriggerTests are trigger tests that require rollback logic to work correctly
var ScriptTests = []ScriptTest{}/* 101 elements not displayed */
ScriptTests are a set of test scripts to run. Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of the tests.
var ServerAuthTests = []ServerAuthenticationTest{ { Name: "DROP USER reports correct string for missing address", Assertions: []ServerAuthenticationTestAssertion{ { Username: "root", Password: "", Query: "DROP USER xyz;", ExpectedErrStr: "Error 1105: Operation DROP USER failed for 'xyz'@'%'", }, }, }, { Name: "CREATE USER with an empty password", Assertions: []ServerAuthenticationTestAssertion{ { Username: "root", Password: "", Query: "CREATE TABLE mydb.test (pk BIGINT PRIMARY KEY);", ExpectedErr: false, }, { Username: "root", Password: "", Query: "CREATE USER rand_user@localhost IDENTIFIED BY '';", ExpectedErr: false, }, { Username: "root", Password: "", Query: "GRANT ALL ON *.* TO rand_user@localhost;", ExpectedErr: false, }, { Username: "rand_user", Password: "", Query: "SELECT * FROM mydb.test;", ExpectedErr: false, }, }, }, { Name: "Basic root authentication", Assertions: []ServerAuthenticationTestAssertion{ { Username: "root", Password: "", Query: "SELECT * FROM mysql.user;", ExpectedErr: false, }, { Username: "root", Password: "pass", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, }, }, { Name: "Create User without plugin specification", SetUpScript: []string{ "CREATE USER rand_user@localhost IDENTIFIED BY 'rand_pass';", "GRANT ALL ON *.* TO rand_user@localhost WITH GRANT OPTION;", }, Assertions: []ServerAuthenticationTestAssertion{ { Username: "rand_user", Password: "rand_pass", Query: "SELECT * FROM mysql.user;", ExpectedErr: false, }, { Username: "rand_user", Password: "rand_pass1", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, { Username: "rand_user", Password: "", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, { Username: "rand_use", Password: "rand_pass", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, }, }, { Name: "Create User with plugin specification", SetUpScript: []string{ "CREATE USER ranuse@localhost IDENTIFIED WITH mysql_native_password BY 'ranpas';", "GRANT ALL ON *.* TO ranuse@localhost WITH GRANT OPTION;", }, Assertions: []ServerAuthenticationTestAssertion{ { Username: "ranuse", Password: "ranpas", Query: "SELECT * FROM mysql.user;", ExpectedErr: false, }, { Username: "ranuse", Password: "what", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, { Username: "ranuse", Password: "", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, }, }, { Name: "Create User with jwt plugin specification", SetUpScript: []string{ "CREATE USER `test-user`@localhost IDENTIFIED WITH authentication_dolt_jwt AS 'jwks=testing,sub=test-user,iss=dolthub.com,aud=some_id';", "GRANT ALL ON *.* TO `test-user`@localhost WITH GRANT OPTION;", }, SetUpFunc: func(ctx *sql.Context, t *testing.T, engine *sqle.Engine) { plugins := map[string]mysql_db.PlaintextAuthPlugin{"authentication_dolt_jwt": &NoopPlaintextPlugin{}} engine.Analyzer.Catalog.MySQLDb.SetPlugins(plugins) }, Assertions: []ServerAuthenticationTestAssertion{ { Username: "test-user", Password: "what", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, { Username: "test-user", Password: "", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, { Username: "test-user", Password: "right-password", Query: "SELECT * FROM mysql.user;", ExpectedErr: false, }, }, }, { Name: "Adding a Super User directly", SetUpFunc: func(ctx *sql.Context, t *testing.T, engine *sqle.Engine) { ed := engine.Analyzer.Catalog.MySQLDb.Editor() defer ed.Close() engine.Analyzer.Catalog.MySQLDb.AddSuperUser(ed, "bestuser", "localhost", "the_pass") }, Assertions: []ServerAuthenticationTestAssertion{ { Username: "bestuser", Password: "the_past", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, { Username: "bestuser", Password: "the_pass", Query: "SELECT * FROM mysql.user;", ExpectedErr: false, }, }, }, }
ServerAuthTests test the server authentication system. These tests always have the root account available, and the root account is used with any queries in the SetUpScript, along as being set to the context passed to SetUpFunc.
var ShowTableStatusQueries = []QueryTest{ { Query: `SHOW TABLE STATUS FROM mydb`, Expected: []sql.Row{ {"mytable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil}, {"othertable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil}, }, }, { Query: `SHOW TABLE STATUS LIKE '%table'`, Expected: []sql.Row{ {"mytable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil}, {"othertable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil}, }, }, { Query: `SHOW TABLE STATUS FROM mydb LIKE 'othertable'`, Expected: []sql.Row{ {"othertable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil}, }, }, { Query: `SHOW TABLE STATUS WHERE Name = 'mytable'`, Expected: []sql.Row{ {"mytable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil}, }, }, { Query: `SHOW TABLE STATUS`, Expected: []sql.Row{ {"mytable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil}, {"othertable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil}, }, }, { Query: `SHOW TABLE STATUS FROM mydb LIKE 'othertable'`, Expected: []sql.Row{ {"othertable", "InnoDB", "10", "Fixed", uint64(3), uint64(88), uint64(264), uint64(0), int64(0), int64(0), nil, nil, nil, nil, "utf8mb4_0900_bin", nil, nil, nil}, }, }, }
var SkippedInfoSchemaQueries = []QueryTest{ { Query: ` SELECT COLUMN_NAME AS COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME LIKE '%table' GROUP BY 1 HAVING SUBSTRING(COLUMN_NAME, 1, 1) = "s" `, Expected: []sql.Row{{"s"}}, }, }
var SkippedInfoSchemaScripts = []ScriptTest{ { Name: "information_schema.key_column_usage works with foreign key across different databases", SetUpScript: []string{ "CREATE TABLE my_table (i int primary key, height int)", "CREATE DATABASE keydb", "USE keydb", "CREATE TABLE key_table (a int primary key, weight int)", "alter table key_table add constraint fk_across_dbs foreign key (a) references mydb.my_table(i)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.key_column_usage where constraint_name = 'fk_across_dbs'", Expected: []sql.Row{ {"def", "keydb", "fk_across_dbs", "def", "keydb", "key_table", "a", 1, 1, "mydb", "my_table", "i"}, }, }, }, }, }
var SkippedJoinQueryTests = []QueryTest{ { Query: "select x from xy, uv join ab on x = a and u = -1", Expected: []sql.Row{{}}, }, }
var SkippedUpdateTests = []WriteQueryTest{ { WriteQuery: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 SET one_pk.c1 = one_pk.c1 + 1, two_pk.c1 = two_pk.c2 + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(8, 6)}}, SelectQuery: "SELECT * FROM two_pk;", ExpectedSelect: []sql.Row{ sql.NewRow(0, 0, 2, 1, 2, 3, 4), sql.NewRow(0, 1, 12, 11, 12, 13, 14), sql.NewRow(1, 0, 22, 21, 22, 23, 24), sql.NewRow(1, 1, 32, 31, 32, 33, 34), }, }, { WriteQuery: `UPDATE othertable INNER JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET othertable.s2 = 'fourth'`, ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM othertable;", ExpectedSelect: []sql.Row{ sql.NewRow("third", 1), sql.NewRow("second", 2), sql.NewRow("fourth", 3), }, }, }
These tests return the correct select query answer but the wrong write result.
var SpatialDeleteTests = []WriteQueryTest{ { WriteQuery: "DELETE FROM point_table;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM point_table;", ExpectedSelect: nil, }, { WriteQuery: "DELETE FROM line_table;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM line_table;", ExpectedSelect: nil, }, { WriteQuery: "DELETE FROM polygon_table;", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM polygon_table;", ExpectedSelect: nil, }, }
var SpatialIndexScriptTests = []ScriptTest{ { Name: "create spatial index errors", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "create table geom(g geometry, SPATIAL INDEX(g))", ExpectedErr: sql.ErrNullableSpatialIdx, }, { Query: "create table geom(g geometry SRID 4326, SPATIAL INDEX(g))", ExpectedErr: sql.ErrNullableSpatialIdx, }, { Query: "create table geom(g1 geometry NOT NULL SRID 0, g2 geometry NOT NULL SRID 4326, SPATIAL INDEX(g1, g2))", ExpectedErr: sql.ErrTooManyKeyParts, }, }, }, { Name: "alter table spatial index nullable", SetUpScript: []string{ "create table geom(g geometry)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table geom add spatial index (g)", ExpectedErr: sql.ErrNullableSpatialIdx, }, }, }, { Name: "alter table spatial index with srid nullable", SetUpScript: []string{ "create table geom(g geometry SRID 4326)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table geom add spatial index (g)", ExpectedErr: sql.ErrNullableSpatialIdx, }, }, }, { Name: "show table with spatial indexes", SetUpScript: []string{ "create table geom(" + "p point not null srid 0," + "l linestring not null srid 0," + "py polygon not null srid 0," + "mp multipoint not null srid 0," + "ml multilinestring not null srid 0," + "mpy multipolygon not null srid 0," + "gc geometrycollection not null srid 0," + "g geometry not null srid 0)", "alter table geom add spatial index (p)", "alter table geom add spatial index (l)", "alter table geom add spatial index (py)", "alter table geom add spatial index (mp)", "alter table geom add spatial index (ml)", "alter table geom add spatial index (mpy)", "alter table geom add spatial index (gc)", "alter table geom add spatial index (g)", }, Assertions: []ScriptTestAssertion{ { Query: "show create table geom", Expected: []sql.Row{ { "geom", "CREATE TABLE `geom` (\n" + " `p` point NOT NULL /*!80003 SRID 0 */,\n" + " `l` linestring NOT NULL /*!80003 SRID 0 */,\n" + " `py` polygon NOT NULL /*!80003 SRID 0 */,\n" + " `mp` multipoint NOT NULL /*!80003 SRID 0 */,\n" + " `ml` multilinestring NOT NULL /*!80003 SRID 0 */,\n" + " `mpy` multipolygon NOT NULL /*!80003 SRID 0 */,\n" + " `gc` geometrycollection NOT NULL /*!80003 SRID 0 */,\n" + " `g` geometry NOT NULL /*!80003 SRID 0 */,\n" + " SPATIAL KEY `g` (`g`),\n" + " SPATIAL KEY `gc` (`gc`),\n" + " SPATIAL KEY `l` (`l`),\n" + " SPATIAL KEY `ml` (`ml`),\n" + " SPATIAL KEY `mp` (`mp`),\n" + " SPATIAL KEY `mpy` (`mpy`),\n" + " SPATIAL KEY `p` (`p`),\n" + " SPATIAL KEY `py` (`py`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, }, }, { Name: "add spatial index to non-empty table", SetUpScript: []string{ "create table geom_tbl(g geometry not null srid 0)", "insert into geom_tbl values (point(0,0)), (linestring(point(1,1), point(2,2)))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table geom_tbl add spatial index (g)", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table geom_tbl", Expected: []sql.Row{ {"geom_tbl", "CREATE TABLE `geom_tbl` (\n `g` geometry NOT NULL /*!80003 SRID 0 */,\n SPATIAL KEY `g` (`g`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "select count(*) from geom_tbl where st_intersects(g, st_geomfromtext('polygon((0 0,0 10,10 10,10 0,0 0))'))", Expected: []sql.Row{ {2}, }, }, }, }, { Name: "add spatial index to non-empty table with primary key", SetUpScript: []string{ "create table geom_tbl(i int, j int, g geometry not null srid 0, primary key (i, j))", "insert into geom_tbl values (1, 10, point(0,0)), (2, 20, linestring(point(1,1), point(2,2)))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table geom_tbl add spatial index (g)", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table geom_tbl", Expected: []sql.Row{ {"geom_tbl", "CREATE TABLE `geom_tbl` (\n `i` int NOT NULL,\n `j` int NOT NULL,\n `g` geometry NOT NULL /*!80003 SRID 0 */,\n PRIMARY KEY (`i`,`j`),\n SPATIAL KEY `g` (`g`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "select count(*) from geom_tbl where st_intersects(g, st_geomfromtext('polygon((0 0,0 10,10 10,10 0,0 0))'))", Expected: []sql.Row{ {2}, }, }, }, }, { Name: "spatial indexes do not work as foreign keys", SetUpScript: []string{ "create table parent (i int primary key, p point not null srid 0, spatial index (p))", "create table child1 (j int primary key, p point not null srid 0, spatial index (p))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table child1 add foreign key (p) references parent (p)", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, { Query: "create table child2 (p point not null srid 0, spatial index (p), foreign key (p) references parent (p))", ExpectedErr: sql.ErrForeignKeyMissingReferenceIndex, }, }, }, }
var SpatialInsertQueries = []WriteQueryTest{ { WriteQuery: "INSERT INTO point_table VALUES (1, POINT(1,1));", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM point_table;", ExpectedSelect: []sql.Row{{5, types.Point{X: 1, Y: 2}}, {1, types.Point{X: 1, Y: 1}}}, }, { WriteQuery: "INSERT INTO point_table VALUES (1, 0x000000000101000000000000000000F03F0000000000000040);", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM point_table;", ExpectedSelect: []sql.Row{{5, types.Point{X: 1, Y: 2}}, {1, types.Point{X: 1, Y: 2}}}, }, { WriteQuery: "INSERT INTO line_table VALUES (2, LINESTRING(POINT(1,2),POINT(3,4)));", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM line_table;", ExpectedSelect: []sql.Row{{0, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {1, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}, {X: 5, Y: 6}}}}, {2, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}}, }, { WriteQuery: "INSERT INTO line_table VALUES (2, 0x00000000010200000002000000000000000000F03F000000000000004000000000000008400000000000001040);", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM line_table;", ExpectedSelect: []sql.Row{{0, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {1, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}, {X: 5, Y: 6}}}}, {2, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}}, }, { WriteQuery: "INSERT INTO polygon_table VALUES (2, POLYGON(LINESTRING(POINT(1,1),POINT(1,-1),POINT(-1,-1),POINT(-1,1),POINT(1,1))));", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM polygon_table;", ExpectedSelect: []sql.Row{ {0, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {1, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}, {Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {2, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 1}, {X: 1, Y: -1}, {X: -1, Y: -1}, {X: -1, Y: 1}, {X: 1, Y: 1}}}}}}, }, }, { WriteQuery: "INSERT INTO polygon_table VALUES (2, 0x0000000001030000000100000005000000000000000000F03F000000000000F03F000000000000F03F000000000000F0BF000000000000F0BF000000000000F0BF000000000000F0BF000000000000F03F000000000000F03F000000000000F03F);", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM polygon_table;", ExpectedSelect: []sql.Row{ {0, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {1, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}, {Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {2, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 1}, {X: 1, Y: -1}, {X: -1, Y: -1}, {X: -1, Y: 1}, {X: 1, Y: 1}}}}}}}, }, { WriteQuery: "INSERT INTO geometry_table VALUES (100, POINT(123.456,7.89));", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM geometry_table;", ExpectedSelect: []sql.Row{ {1, types.Point{X: 1, Y: 2}}, {2, types.Point{SRID: 4326, X: 1, Y: 2}}, {3, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {4, types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {5, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {6, types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, {7, types.MultiPoint{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {8, types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {9, types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}}}, {10, types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}}}, {11, types.MultiPolygon{Polygons: []types.Polygon{{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 2}, {X: 3, Y: 4}, {X: 0, Y: 0}}}}}}}}, {12, types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 0, Y: 0}}}}}}}}, {13, types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}}, {14, types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}}, {100, types.Point{X: 123.456, Y: 7.89}}, }, }, { WriteQuery: "INSERT INTO geometry_table VALUES (100, 0x00000000010100000077BE9F1A2FDD5E408FC2F5285C8F1F40);", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM geometry_table;", ExpectedSelect: []sql.Row{ {1, types.Point{X: 1, Y: 2}}, {2, types.Point{SRID: 4326, X: 1, Y: 2}}, {3, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {4, types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {5, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {6, types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, {7, types.MultiPoint{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {8, types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {9, types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}}}, {10, types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}}}, {11, types.MultiPolygon{Polygons: []types.Polygon{{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 2}, {X: 3, Y: 4}, {X: 0, Y: 0}}}}}}}}, {12, types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 0, Y: 0}}}}}}}}, {13, types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}}, {14, types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}}, {100, types.Point{X: 123.456, Y: 7.89}}, }, }, { WriteQuery: "INSERT INTO geometry_table VALUES (100, LINESTRING(POINT(1,2),POINT(3,4)));", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM geometry_table;", ExpectedSelect: []sql.Row{ {1, types.Point{X: 1, Y: 2}}, {2, types.Point{SRID: 4326, X: 1, Y: 2}}, {3, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {4, types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {5, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {6, types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, {7, types.MultiPoint{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {8, types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {9, types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}}}, {10, types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}}}, {11, types.MultiPolygon{Polygons: []types.Polygon{{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 2}, {X: 3, Y: 4}, {X: 0, Y: 0}}}}}}}}, {12, types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 0, Y: 0}}}}}}}}, {13, types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}}, {14, types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}}, {100, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, }, }, { WriteQuery: "INSERT INTO geometry_table VALUES (100, 0x00000000010200000002000000000000000000F03F000000000000004000000000000008400000000000001040);", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM geometry_table;", ExpectedSelect: []sql.Row{ {1, types.Point{X: 1, Y: 2}}, {2, types.Point{SRID: 4326, X: 1, Y: 2}}, {3, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {4, types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {5, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {6, types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, {7, types.MultiPoint{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {8, types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {9, types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}}}, {10, types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}}}, {11, types.MultiPolygon{Polygons: []types.Polygon{{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 2}, {X: 3, Y: 4}, {X: 0, Y: 0}}}}}}}}, {12, types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 0, Y: 0}}}}}}}}, {13, types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}}, {14, types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}}, {100, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, }, }, { WriteQuery: "INSERT INTO geometry_table VALUES (100, POLYGON(LINESTRING(POINT(1,1),POINT(1,-1),POINT(-1,-1),POINT(-1,1),POINT(1,1))));", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM geometry_table;", ExpectedSelect: []sql.Row{ {1, types.Point{X: 1, Y: 2}}, {2, types.Point{SRID: 4326, X: 1, Y: 2}}, {3, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {4, types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {5, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {6, types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, {7, types.MultiPoint{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {8, types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {9, types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}}}, {10, types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}}}, {11, types.MultiPolygon{Polygons: []types.Polygon{{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 2}, {X: 3, Y: 4}, {X: 0, Y: 0}}}}}}}}, {12, types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 0, Y: 0}}}}}}}}, {13, types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}}, {14, types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}}, {100, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 1}, {X: 1, Y: -1}, {X: -1, Y: -1}, {X: -1, Y: 1}, {X: 1, Y: 1}}}}}}, }, }, { WriteQuery: "INSERT INTO geometry_table VALUES (100, 0x0000000001030000000100000005000000000000000000F03F000000000000F03F000000000000F03F000000000000F0BF000000000000F0BF000000000000F0BF000000000000F0BF000000000000F03F000000000000F03F000000000000F03F);", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM geometry_table;", ExpectedSelect: []sql.Row{ {1, types.Point{X: 1, Y: 2}}, {2, types.Point{SRID: 4326, X: 1, Y: 2}}, {3, types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {4, types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {5, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {6, types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, {7, types.MultiPoint{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {8, types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {9, types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}}}, {10, types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}}}, {11, types.MultiPolygon{Polygons: []types.Polygon{{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 2}, {X: 3, Y: 4}, {X: 0, Y: 0}}}}}}}}, {12, types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 0, Y: 0}}}}}}}}, {13, types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}}, {14, types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}}, {100, types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 1}, {X: 1, Y: -1}, {X: -1, Y: -1}, {X: -1, Y: 1}, {X: 1, Y: 1}}}}}}, }, }, }
var SpatialQueryTests = []QueryTest{ { Query: `SHOW CREATE TABLE point_table`, Expected: []sql.Row{{ "point_table", "CREATE TABLE `point_table` (\n" + " `i` bigint NOT NULL,\n" + " `p` point NOT NULL,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }}, }, { Query: `SHOW CREATE TABLE line_table`, Expected: []sql.Row{{ "line_table", "CREATE TABLE `line_table` (\n" + " `i` bigint NOT NULL,\n" + " `l` linestring NOT NULL,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }}, }, { Query: `SHOW CREATE TABLE polygon_table`, Expected: []sql.Row{{ "polygon_table", "CREATE TABLE `polygon_table` (\n" + " `i` bigint NOT NULL,\n" + " `p` polygon NOT NULL,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }}, }, { Query: `SHOW CREATE TABLE mpoint_table`, Expected: []sql.Row{{ "mpoint_table", "CREATE TABLE `mpoint_table` (\n" + " `i` bigint NOT NULL,\n" + " `p` multipoint NOT NULL,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }}, }, { Query: `SHOW CREATE TABLE mline_table`, Expected: []sql.Row{{ "mline_table", "CREATE TABLE `mline_table` (\n" + " `i` bigint NOT NULL,\n" + " `l` multilinestring NOT NULL,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }}, }, { Query: `SHOW CREATE TABLE mpoly_table`, Expected: []sql.Row{{ "mpoly_table", "CREATE TABLE `mpoly_table` (\n" + " `i` bigint NOT NULL,\n" + " `p` multipolygon NOT NULL,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }}, }, { Query: `SHOW CREATE TABLE geometry_table`, Expected: []sql.Row{{ "geometry_table", "CREATE TABLE `geometry_table` (\n" + " `i` bigint NOT NULL,\n" + " `g` geometry NOT NULL,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }}, }, { Query: `SELECT HEX(ST_ASWKB(p)) from point_table`, Expected: []sql.Row{{"0101000000000000000000F03F0000000000000040"}}, }, { Query: `SELECT HEX(ST_ASWKB(l)) from line_table`, Expected: []sql.Row{ {"010200000002000000000000000000F03F000000000000004000000000000008400000000000001040"}, {"010200000003000000000000000000F03F00000000000000400000000000000840000000000000104000000000000014400000000000001840"}, }, }, { Query: `SELECT HEX(ST_ASWKB(p)) from polygon_table`, Expected: []sql.Row{ {"01030000000100000004000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F00000000000000000000000000000000"}, {"01030000000200000004000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F00000000000000000000000000000000"}, }, }, { Query: `SELECT ST_GEOMFROMWKB(ST_ASWKB(POINT(123.45,6.78)))`, Expected: []sql.Row{{types.Point{X: 123.45, Y: 6.78}}}, }, { Query: `SELECT ST_GEOMFROMWKB(ST_ASWKB(LINESTRING(POINT(1.2,3.45),point(67.8,9))))`, Expected: []sql.Row{{types.LineString{Points: []types.Point{{X: 1.2, Y: 3.45}, {X: 67.8, Y: 9}}}}}, }, { Query: `SELECT ST_GEOMFROMWKB(ST_ASWKB(POLYGON(LINESTRING(POINT(0,0),POINT(2,2),POINT(1,1),POINT(0,0)))))`, Expected: []sql.Row{{types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 2, Y: 2}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}}, }, { Query: `SELECT ST_ASWKT(p) from point_table`, Expected: []sql.Row{{"POINT(1 2)"}}, }, { Query: `SELECT ST_ASWKT(l) from line_table`, Expected: []sql.Row{ {"LINESTRING(1 2,3 4)"}, {"LINESTRING(1 2,3 4,5 6)"}, }, }, { Query: `SELECT ST_ASWKT(p) from polygon_table`, Expected: []sql.Row{ {"POLYGON((0 0,0 1,1 1,0 0))"}, {"POLYGON((0 0,0 1,1 1,0 0),(0 0,0 1,1 1,0 0))"}, }, }, { Query: `SELECT ST_ASTEXT(p) from polygon_table`, Expected: []sql.Row{ {"POLYGON((0 0,0 1,1 1,0 0))"}, {"POLYGON((0 0,0 1,1 1,0 0),(0 0,0 1,1 1,0 0))"}, }, }, { Query: `SELECT ST_GEOMFROMTEXT(ST_ASWKT(POINT(1,2)))`, Expected: []sql.Row{{types.Point{X: 1, Y: 2}}}, }, { Query: `SELECT ST_GEOMFROMTEXT(ST_ASWKT(LINESTRING(POINT(1.1,2.22),POINT(3.333,4.4444))))`, Expected: []sql.Row{{types.LineString{Points: []types.Point{{X: 1.1, Y: 2.22}, {X: 3.333, Y: 4.4444}}}}}, }, { Query: `SELECT ST_GEOMFROMTEXT(ST_ASWKT(POLYGON(LINESTRING(POINT(1.2, 3.4),POINT(2.5, -6.7),POINT(33, 44),POINT(1.2,3.4)))))`, Expected: []sql.Row{{types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 1.2, Y: 3.4}, {X: 2.5, Y: -6.7}, {X: 33, Y: 44}, {X: 1.2, Y: 3.4}}}}}}}, }, { Query: `SELECT ST_X(POINT(1,2))`, Expected: []sql.Row{{1.0}}, }, { Query: `SELECT ST_Y(POINT(1,2))`, Expected: []sql.Row{{2.0}}, }, { Query: `SELECT ST_X(POINT(123.45,6.789))`, Expected: []sql.Row{{123.45}}, }, { Query: `SELECT ST_Y(POINT(123.45,6.789))`, Expected: []sql.Row{{6.789}}, }, { Query: `SELECT ST_X(POINT(1,2),99.9)`, Expected: []sql.Row{{types.Point{X: 99.9, Y: 2}}}, }, { Query: `SELECT ST_Y(POINT(1,2),99.9)`, Expected: []sql.Row{{types.Point{X: 1, Y: 99.9}}}, }, { Query: `SELECT ST_X(p) from point_table`, Expected: []sql.Row{{1.0}}, }, { Query: `SELECT ST_X(p) from point_table`, Expected: []sql.Row{{1.0}}, }, { Query: `SELECT ST_Y(p) from point_table`, Expected: []sql.Row{{2.0}}, }, { Query: `SELECT ST_SRID(p) from point_table`, Expected: []sql.Row{{uint32(0)}}, }, { Query: `SELECT ST_SRID(l) from line_table`, Expected: []sql.Row{{uint32(0)}, {uint32(0)}}, }, { Query: `SELECT ST_SRID(p) from polygon_table`, Expected: []sql.Row{ {uint32(0)}, {uint32(0)}, }, }, { Query: `SELECT ST_SRID(p, 4326) from point_table`, Expected: []sql.Row{{types.Point{SRID: 4326, X: 1, Y: 2}}}, }, { Query: `SELECT ST_SRID(l, 4326) from line_table ORDER BY l`, Expected: []sql.Row{ {types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 5, Y: 6}}}}, }, }, { Query: `SELECT ST_SRID(p, 4326) from polygon_table`, Expected: []sql.Row{ {types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, {types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}, {SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, }, }, { Query: `SELECT ST_GEOMFROMGEOJSON(s) from stringtogeojson_table`, Expected: []sql.Row{ {types.Point{SRID: 4326, X: 1, Y: 2}}, {types.Point{SRID: 4326, X: 123.45, Y: 56.789}}, {types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1.23, Y: 2.345}, {SRID: 4326, X: 3.56789, Y: 4.56}}}}, {types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1.1, Y: 2.2}, {SRID: 4326, X: 3.3, Y: 4.4}, {SRID: 4326, X: 5.5, Y: 6.6}, {SRID: 4326, X: 1.1, Y: 2.2}}}}}}, {types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 2, Y: 2}, {SRID: 4326, X: 0, Y: 0}}}}}}, {types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1.23, Y: 2.345}, {SRID: 4326, X: 3.56789, Y: 4.56}}}}, {types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1.1, Y: 2.2}, {SRID: 4326, X: 3.3, Y: 4.4}}}, {SRID: 4326, Points: []types.Point{{SRID: 4326, X: 5.5, Y: 6.6}, {SRID: 4326, X: 7.7, Y: 8.8}}}}}}, {types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{ {SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1.1, Y: 2.2}, {SRID: 4326, X: 3.3, Y: 4.4}, {SRID: 4326, X: 0, Y: 0}}}}}, {SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1.1, Y: 1.1}, {SRID: 4326, X: 1.1, Y: 2.2}, {SRID: 4326, X: 3.3, Y: 4.4}, {SRID: 4326, X: 1.1, Y: 1.1}}}}}, }}}, {types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}}, }, }, { Query: `SELECT ST_ASGEOJSON(p) from point_table`, Expected: []sql.Row{ {types.JSONDocument{Val: map[string]interface{}{"type": "Point", "coordinates": [2]float64{1, 2}}}}, }, }, { Query: `SELECT ST_ASGEOJSON(l) from line_table`, Expected: []sql.Row{ {types.JSONDocument{Val: map[string]interface{}{"type": "LineString", "coordinates": [][2]float64{{1, 2}, {3, 4}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "LineString", "coordinates": [][2]float64{{1, 2}, {3, 4}, {5, 6}}}}}, }, }, { Query: `SELECT ST_ASGEOJSON(p) from polygon_table`, Expected: []sql.Row{ {types.JSONDocument{Val: map[string]interface{}{"type": "Polygon", "coordinates": [][][2]float64{{{0, 0}, {0, 1}, {1, 1}, {0, 0}}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "Polygon", "coordinates": [][][2]float64{{{0, 0}, {0, 1}, {1, 1}, {0, 0}}, {{0, 0}, {0, 1}, {1, 1}, {0, 0}}}}}}, }, }, { Query: `SELECT ST_ASGEOJSON(p) from mpoint_table`, Expected: []sql.Row{ {types.JSONDocument{Val: map[string]interface{}{"type": "MultiPoint", "coordinates": [][2]float64{{1, 2}, {3, 4}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "MultiPoint", "coordinates": [][2]float64{{1, 2}, {3, 4}, {5, 6}}}}}, }, }, { Query: `SELECT ST_ASGEOJSON(l) from mline_table`, Expected: []sql.Row{ {types.JSONDocument{Val: map[string]interface{}{"type": "MultiLineString", "coordinates": [][][2]float64{{{1, 2}, {3, 4}}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "MultiLineString", "coordinates": [][][2]float64{{{1, 2}, {3, 4}, {5, 6}}}}}}, }, }, { Query: `SELECT ST_ASGEOJSON(ST_GEOMFROMGEOJSON(s)) from stringtogeojson_table`, Expected: []sql.Row{ {types.JSONDocument{Val: map[string]interface{}{"type": "Point", "coordinates": [2]float64{1, 2}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "Point", "coordinates": [2]float64{123.45, 56.789}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "LineString", "coordinates": [][2]float64{{1, 2}, {3, 4}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "LineString", "coordinates": [][2]float64{{1.23, 2.345}, {3.56789, 4.56}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "Polygon", "coordinates": [][][2]float64{{{1.1, 2.2}, {3.3, 4.4}, {5.5, 6.6}, {1.1, 2.2}}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "Polygon", "coordinates": [][][2]float64{{{0, 0}, {1, 1}, {2, 2}, {0, 0}}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "MultiPoint", "coordinates": [][2]float64{{1, 2}, {3, 4}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "MultiPoint", "coordinates": [][2]float64{{1.23, 2.345}, {3.56789, 4.56}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "MultiLineString", "coordinates": [][][2]float64{{{1.1, 2.2}, {3.3, 4.4}}, {{5.5, 6.6}, {7.7, 8.8}}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "MultiPolygon", "coordinates": [][][][2]float64{{{{0, 0}, {1.1, 2.2}, {3.3, 4.4}, {0, 0}}}, {{{1.1, 1.1}, {1.1, 2.2}, {3.3, 4.4}, {1.1, 1.1}}}}}}}, {types.JSONDocument{Val: map[string]interface{}{"type": "GeometryCollection", "geometries": []interface{}{map[string]interface{}{"type": "GeometryCollection", "geometries": []interface{}{}}}}}}, }, }, { Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(p)) from point_table`, Expected: []sql.Row{ {types.Point{SRID: 4326, X: 1, Y: 2}}, }, }, { Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(l)) from line_table`, Expected: []sql.Row{ {types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 5, Y: 6}}}}, }, }, { Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(p)) from polygon_table`, Expected: []sql.Row{ {types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, {types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}, {SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 0, Y: 1}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, }, }, { Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(p)) from mpoint_table`, Expected: []sql.Row{ {types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}, {types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 5, Y: 6}}}}, }, }, { Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(l)) from mline_table`, Expected: []sql.Row{ {types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}}}}}}, {types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 5, Y: 6}}}}}}, }, }, { Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(p)) from mpoly_table`, Expected: []sql.Row{ {types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 0, Y: 0}}}}}}}}, {types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{ {SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 2}, {SRID: 4326, X: 3, Y: 4}, {SRID: 4326, X: 0, Y: 0}}}}}, {SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 2, Y: 3}, {SRID: 4326, X: 4, Y: 5}, {SRID: 4326, X: 1, Y: 1}}}}}}}}, }, }, { Query: `SELECT ST_GEOMFROMGEOJSON(ST_ASGEOJSON(g)) from geom_coll_table`, Expected: []sql.Row{ {types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}}, }, }, { Query: `SELECT ST_DIMENSION(p) from point_table`, Expected: []sql.Row{ {0}, }, }, { Query: `SELECT ST_DIMENSION(l) from line_table`, Expected: []sql.Row{ {1}, {1}, }, }, { Query: `SELECT ST_DIMENSION(p) from polygon_table`, Expected: []sql.Row{ {2}, {2}, }, }, { Query: `SELECT ST_DIMENSION(p) from mpoint_table`, Expected: []sql.Row{ {0}, {0}, }, }, { Query: `SELECT ST_DIMENSION(l) from mline_table`, Expected: []sql.Row{ {1}, {1}, }, }, { Query: `SELECT ST_DIMENSION(p) from mpoly_table`, Expected: []sql.Row{ {2}, {2}, }, }, { Query: `SELECT ST_DIMENSION(g) from geom_coll_table`, Expected: []sql.Row{ {nil}, }, }, { Query: `SELECT ST_SWAPXY(p) from point_table`, Expected: []sql.Row{ {types.Point{X: 2, Y: 1}}, }, }, { Query: `SELECT ST_SWAPXY(l) from line_table`, Expected: []sql.Row{ {types.LineString{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}}}}, {types.LineString{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}, {X: 6, Y: 5}}}}, }, }, { Query: `SELECT ST_SWAPXY(p) from polygon_table`, Expected: []sql.Row{ {types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: 0}}}, {Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, }, }, { Query: `SELECT ST_ASWKT(g) from geometry_table ORDER BY i`, Expected: []sql.Row{ {"POINT(1 2)"}, {"POINT(2 1)"}, {"LINESTRING(1 2,3 4)"}, {"LINESTRING(2 1,4 3)"}, {"POLYGON((0 0,0 1,1 1,0 0))"}, {"POLYGON((0 0,1 0,1 1,0 0))"}, {"MULTIPOINT(1 2,3 4)"}, {"MULTIPOINT(2 1,4 3)"}, {"MULTILINESTRING((1 2,3 4))"}, {"MULTILINESTRING((2 1,4 3))"}, {"MULTIPOLYGON(((0 0,1 2,3 4,0 0)))"}, {"MULTIPOLYGON(((0 0,2 1,4 3,0 0)))"}, {"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION())"}, {"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION())"}, }, }, { Query: `SELECT ST_SWAPXY(p) from mpoint_table`, Expected: []sql.Row{ {types.MultiPoint{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}}}}, {types.MultiPoint{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}, {X: 6, Y: 5}}}}, }, }, { Query: `SELECT ST_SWAPXY(l) from mline_table`, Expected: []sql.Row{ {types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}}}}}}, {types.MultiLineString{Lines: []types.LineString{{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}, {X: 6, Y: 5}}}}}}, }, }, { Query: `SELECT ST_SWAPXY(p) from mpoly_table`, Expected: []sql.Row{ {types.MultiPolygon{Polygons: []types.Polygon{{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 2, Y: 1}, {X: 4, Y: 3}, {X: 0, Y: 0}}}}}}}}, {types.MultiPolygon{Polygons: []types.Polygon{ {Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 2, Y: 1}, {X: 4, Y: 3}, {X: 0, Y: 0}}}}}, {Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 1}, {X: 3, Y: 2}, {X: 5, Y: 4}, {X: 1, Y: 1}}}}}, }}}, }, }, { Query: `SELECT HEX(ST_ASWKB(g)) from geometry_table ORDER BY i`, Expected: []sql.Row{ {"0101000000000000000000F03F0000000000000040"}, {"01010000000000000000000040000000000000F03F"}, {"010200000002000000000000000000F03F000000000000004000000000000008400000000000001040"}, {"0102000000020000000000000000000040000000000000F03F00000000000010400000000000000840"}, {"01030000000100000004000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F00000000000000000000000000000000"}, {"0103000000010000000400000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000"}, {"0104000000020000000101000000000000000000F03F0000000000000040010100000000000000000008400000000000001040"}, {"01040000000200000001010000000000000000000040000000000000F03F010100000000000000000010400000000000000840"}, {"010500000001000000010200000002000000000000000000F03F000000000000004000000000000008400000000000001040"}, {"0105000000010000000102000000020000000000000000000040000000000000F03F00000000000010400000000000000840"}, {"0106000000010000000103000000010000000400000000000000000000000000000000000000000000000000F03F00000000000000400000000000000840000000000000104000000000000000000000000000000000"}, {"01060000000100000001030000000100000004000000000000000000000000000000000000000000000000000040000000000000F03F0000000000001040000000000000084000000000000000000000000000000000"}, {"010700000001000000010700000000000000"}, {"010700000001000000010700000000000000"}, }, }, { Query: `SELECT ST_SRID(g) from geometry_table order by i`, Expected: []sql.Row{ {uint64(0)}, {uint64(4326)}, {uint64(0)}, {uint64(4326)}, {uint64(0)}, {uint64(4326)}, {uint64(0)}, {uint64(4326)}, {uint64(0)}, {uint64(4326)}, {uint64(0)}, {uint64(4326)}, {uint64(0)}, {uint64(4326)}, }, }, { Query: `SELECT ST_SRID(g, 0) from geometry_table order by i`, Expected: []sql.Row{ {types.Point{X: 1, Y: 2}}, {types.Point{X: 1, Y: 2}}, {types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {types.LineString{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {types.MultiPoint{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {types.MultiPoint{Points: []types.Point{{X: 1, Y: 2}, {X: 3, Y: 4}}}}, {types.MultiLineString{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 1, Y: 2}, {SRID: 0, X: 3, Y: 4}}}}}}, {types.MultiLineString{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 1, Y: 2}, {SRID: 0, X: 3, Y: 4}}}}}}, {types.MultiPolygon{SRID: 0, Polygons: []types.Polygon{{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 0, Y: 0}, {SRID: 0, X: 1, Y: 2}, {SRID: 0, X: 3, Y: 4}, {SRID: 0, X: 0, Y: 0}}}}}}}}, {types.MultiPolygon{SRID: 0, Polygons: []types.Polygon{{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 0, Y: 0}, {SRID: 0, X: 1, Y: 2}, {SRID: 0, X: 3, Y: 4}, {SRID: 0, X: 0, Y: 0}}}}}}}}, {types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}}, {types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}}, }, }, { Query: `SELECT ST_DIMENSION(g) from geometry_table order by i`, Expected: []sql.Row{ {0}, {0}, {1}, {1}, {2}, {2}, {0}, {0}, {1}, {1}, {2}, {2}, {nil}, {nil}, }, }, { Query: `SELECT ST_SWAPXY(g) from geometry_table order by i`, Expected: []sql.Row{ {types.Point{X: 2, Y: 1}}, {types.Point{SRID: 4326, X: 2, Y: 1}}, {types.LineString{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}}}}, {types.LineString{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 2, Y: 1}, {SRID: 4326, X: 4, Y: 3}}}}, {types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: 0}}}}}}, {types.Polygon{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 1, Y: 0}, {SRID: 4326, X: 1, Y: 1}, {SRID: 4326, X: 0, Y: 0}}}}}}, {types.MultiPoint{Points: []types.Point{{X: 2, Y: 1}, {X: 4, Y: 3}}}}, {types.MultiPoint{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 2, Y: 1}, {SRID: 4326, X: 4, Y: 3}}}}, {types.MultiLineString{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 2, Y: 1}, {SRID: 0, X: 4, Y: 3}}}}}}, {types.MultiLineString{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 2, Y: 1}, {SRID: 4326, X: 4, Y: 3}}}}}}, {types.MultiPolygon{SRID: 0, Polygons: []types.Polygon{{SRID: 0, Lines: []types.LineString{{SRID: 0, Points: []types.Point{{SRID: 0, X: 0, Y: 0}, {SRID: 0, X: 2, Y: 1}, {SRID: 0, X: 4, Y: 3}, {SRID: 0, X: 0, Y: 0}}}}}}}}, {types.MultiPolygon{SRID: 4326, Polygons: []types.Polygon{{SRID: 4326, Lines: []types.LineString{{SRID: 4326, Points: []types.Point{{SRID: 4326, X: 0, Y: 0}, {SRID: 4326, X: 2, Y: 1}, {SRID: 4326, X: 4, Y: 3}, {SRID: 4326, X: 0, Y: 0}}}}}}}}, {types.GeomColl{Geoms: []types.GeometryValue{types.GeomColl{Geoms: []types.GeometryValue{}}}}}, {types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{types.GeomColl{SRID: 4326, Geoms: []types.GeometryValue{}}}}}, }, }, { Query: `SELECT ST_AREA(p) from polygon_table`, Expected: []sql.Row{ {0.5}, {0.0}, }, }, { Query: `SELECT ST_PERIMETER(p) from polygon_table`, Expected: []sql.Row{ {3.414213562373095}, {6.82842712474619}, }, }, { Query: `SELECT ST_LENGTH(l) from line_table`, Expected: []sql.Row{ {2.8284271247461903}, {5.656854249492381}, }, }, { Query: `SELECT ST_ASWKT(g) from geometry_table where g = point(1,2)`, Expected: []sql.Row{ {"POINT(1 2)"}, }, }, { Query: `SELECT ST_ASWKT(g) from geometry_table where g = st_srid(point(1,2),4326)`, Expected: []sql.Row{ {"POINT(2 1)"}, }, }, { Query: `SELECT ST_ASWKT(g) from geometry_table where g = unhex(hex(point(1,2)))`, Expected: []sql.Row{ {"POINT(1 2)"}, }, }, { Query: `SELECT unhex(hex(point(1,2))) < unhex(hex(point(3,4)))`, Expected: []sql.Row{ {false}, }, }, { Query: `SELECT ST_ASWKT(g) from geometry_table where g = st_geomfromtext('MultiPolygon(((0 0,1 2,3 4,0 0)))')`, Expected: []sql.Row{ {"MULTIPOLYGON(((0 0,1 2,3 4,0 0)))"}, }, }, { Query: `SELECT ST_ASWKT(g) from geometry_table ORDER BY g`, Expected: []sql.Row{ {"POINT(1 2)"}, {"LINESTRING(1 2,3 4)"}, {"POLYGON((0 0,0 1,1 1,0 0))"}, {"MULTIPOINT(1 2,3 4)"}, {"MULTILINESTRING((1 2,3 4))"}, {"MULTIPOLYGON(((0 0,1 2,3 4,0 0)))"}, {"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION())"}, {"POINT(2 1)"}, {"LINESTRING(2 1,4 3)"}, {"POLYGON((0 0,1 0,1 1,0 0))"}, {"MULTIPOINT(2 1,4 3)"}, {"MULTILINESTRING((2 1,4 3))"}, {"MULTIPOLYGON(((0 0,2 1,4 3,0 0)))"}, {"GEOMETRYCOLLECTION(GEOMETRYCOLLECTION())"}, }, }, { Query: `SELECT ST_DISTANCE(st_srid(g, 0), point(0,0)) from geometry_table ORDER BY g`, Expected: []sql.Row{ {math.Sqrt(5)}, {math.Sqrt(5)}, {0.0}, {math.Sqrt(5)}, {math.Sqrt(5)}, {0.0}, {nil}, {math.Sqrt(5)}, {math.Sqrt(5)}, {0.0}, {math.Sqrt(5)}, {math.Sqrt(5)}, {0.0}, {nil}, }, }, { Query: `SELECT st_startpoint(g) from geometry_table ORDER BY g`, Expected: []sql.Row{ {nil}, {types.Point{X: 1, Y: 2}}, {nil}, {nil}, {nil}, {nil}, {nil}, {nil}, {types.Point{SRID: types.GeoSpatialSRID, X: 1, Y: 2}}, {nil}, {nil}, {nil}, {nil}, {nil}, }, }, { Query: `SELECT st_endpoint(g) from geometry_table ORDER BY g`, Expected: []sql.Row{ {nil}, {types.Point{X: 3, Y: 4}}, {nil}, {nil}, {nil}, {nil}, {nil}, {nil}, {types.Point{SRID: types.GeoSpatialSRID, X: 3, Y: 4}}, {nil}, {nil}, {nil}, {nil}, {nil}, }, }, { Query: `SELECT st_isclosed(g) from geometry_table ORDER BY g`, Expected: []sql.Row{ {nil}, {false}, {nil}, {nil}, {false}, {nil}, {nil}, {nil}, {false}, {nil}, {nil}, {false}, {nil}, {nil}, }, }, { Query: `SELECT st_intersects(st_srid(g, 0), point(1,2)) from geometry_table ORDER BY g`, Expected: []sql.Row{ {true}, {true}, {false}, {true}, {true}, {true}, {false}, {true}, {true}, {false}, {true}, {true}, {true}, {false}, }, }, }
var SpatialScriptTests = []ScriptTest{ { Name: "create table using default point value", SetUpScript: []string{ "CREATE TABLE test (i int primary key, p point default (point(123.456, 7.89)));", "insert into test (i) values (0);", }, Assertions: []ScriptTestAssertion{ { Query: "select st_aswkt(p) from test", Expected: []sql.Row{{"POINT(123.456 7.89)"}}, }, { Query: "show create table test", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `p` point DEFAULT (point(123.456,7.89)),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "describe test", Expected: []sql.Row{{"i", "int", "NO", "PRI", "NULL", ""}, {"p", "point", "YES", "", "(point(123.456,7.89))", "DEFAULT_GENERATED"}}, }, }, }, { Name: "create table using default linestring value", SetUpScript: []string{ "CREATE TABLE test (i int primary key, l linestring default (linestring(point(1,2), point(3,4))));", "insert into test (i) values (0);", }, Assertions: []ScriptTestAssertion{ { Query: "select st_aswkt(l) from test", Expected: []sql.Row{{"LINESTRING(1 2,3 4)"}}, }, { Query: "show create table test", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `l` linestring DEFAULT (linestring(point(1,2),point(3,4))),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "describe test", Expected: []sql.Row{{"i", "int", "NO", "PRI", "NULL", ""}, {"l", "linestring", "YES", "", "(linestring(point(1,2),point(3,4)))", "DEFAULT_GENERATED"}}, }, }, }, { Name: "create table using default polygon value", SetUpScript: []string{ "CREATE TABLE test (i int primary key, p polygon default (polygon(linestring(point(0,0), point(1,1), point(2,2), point(0,0)))));", "insert into test (i) values (0);", }, Assertions: []ScriptTestAssertion{ { Query: "select st_aswkt(p) from test", Expected: []sql.Row{{"POLYGON((0 0,1 1,2 2,0 0))"}}, }, { Query: "show create table test", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `p` polygon DEFAULT (polygon(linestring(point(0,0),point(1,1),point(2,2),point(0,0)))),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "describe test", Expected: []sql.Row{{"i", "int", "NO", "PRI", "NULL", ""}, {"p", "polygon", "YES", "", "(polygon(linestring(point(0,0),point(1,1),point(2,2),point(0,0))))", "DEFAULT_GENERATED"}}, }, }, }, { Name: "create geometry table using default point value", SetUpScript: []string{ "CREATE TABLE test (i int primary key, g geometry default (point(123.456, 7.89)));", "insert into test (i) values (0);", }, Assertions: []ScriptTestAssertion{ { Query: "select st_aswkt(g) from test", Expected: []sql.Row{{"POINT(123.456 7.89)"}}, }, { Query: "show create table test", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `g` geometry DEFAULT (point(123.456,7.89)),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "describe test", Expected: []sql.Row{{"i", "int", "NO", "PRI", "NULL", ""}, {"g", "geometry", "YES", "", "(point(123.456,7.89))", "DEFAULT_GENERATED"}}, }, }, }, { Name: "create geometry table using default linestring value", SetUpScript: []string{ "CREATE TABLE test (i int primary key, g geometry default (linestring(point(1,2), point(3,4))));", "insert into test (i) values (0);", }, Assertions: []ScriptTestAssertion{ { Query: "select st_aswkt(g) from test", Expected: []sql.Row{{"LINESTRING(1 2,3 4)"}}, }, { Query: "show create table test", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `g` geometry DEFAULT (linestring(point(1,2),point(3,4))),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "describe test", Expected: []sql.Row{{"i", "int", "NO", "PRI", "NULL", ""}, {"g", "geometry", "YES", "", "(linestring(point(1,2),point(3,4)))", "DEFAULT_GENERATED"}}, }, }, }, { Name: "create geometry table using default polygon value", SetUpScript: []string{ "CREATE TABLE test (i int primary key, g geometry default (polygon(linestring(point(0,0), point(1,1), point(2,2), point(0,0)))));", "insert into test (i) values (0);", }, Assertions: []ScriptTestAssertion{ { Query: "select st_aswkt(g) from test", Expected: []sql.Row{{"POLYGON((0 0,1 1,2 2,0 0))"}}, }, { Query: "show create table test", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `g` geometry DEFAULT (polygon(linestring(point(0,0),point(1,1),point(2,2),point(0,0)))),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "describe test", Expected: []sql.Row{{"i", "int", "NO", "PRI", "NULL", ""}, {"g", "geometry", "YES", "", "(polygon(linestring(point(0,0),point(1,1),point(2,2),point(0,0))))", "DEFAULT_GENERATED"}}, }, }, }, { Name: "create table with NULL default values for geometry types", SetUpScript: []string{ "CREATE TABLE null_default (pk int NOT NULL PRIMARY KEY, v1 geometry DEFAULT NULL, v2 linestring DEFAULT NULL, v3 point DEFAULT NULL, v4 polygon DEFAULT NULL)", "insert into null_default(pk) values (0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from null_default", Expected: []sql.Row{{0, nil, nil, nil, nil}}, }, }, }, { Name: "create table using SRID value for geometry type", SetUpScript: []string{ "CREATE TABLE tab0 (i int primary key, g geometry srid 4326 default (point(1,1)));", }, Assertions: []ScriptTestAssertion{ { Query: "show create table tab0", Expected: []sql.Row{{"tab0", "CREATE TABLE `tab0` (\n `i` int NOT NULL,\n `g` geometry /*!80003 SRID 4326 */ DEFAULT (point(1,1)),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "INSERT INTO tab0 VALUES (1, ST_GEOMFROMTEXT(ST_ASWKT(POINT(1,2)), 4326))", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select i, ST_ASWKT(g) FROM tab0", Expected: []sql.Row{{1, "POINT(1 2)"}}, }, { Query: "INSERT INTO tab0 VALUES (2, ST_GEOMFROMTEXT(ST_ASWKT(POINT(2,4))))", ExpectedErr: sql.ErrNotMatchingSRIDWithColName, }, { Query: "INSERT INTO tab0 VALUES (2, ST_GEOMFROMTEXT(ST_ASWKT(LINESTRING(POINT(1, 6),POINT(4, 3))), 4326))", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select i, ST_ASWKT(g) FROM tab0", Expected: []sql.Row{{1, "POINT(1 2)"}, {2, "LINESTRING(1 6,4 3)"}}, }, }, }, { Name: "create table using SRID value for linestring type", SetUpScript: []string{ "CREATE TABLE tab1 (i int primary key, l linestring srid 0);", }, Assertions: []ScriptTestAssertion{ { Query: "show create table tab1", Expected: []sql.Row{{"tab1", "CREATE TABLE `tab1` (\n `i` int NOT NULL,\n `l` linestring /*!80003 SRID 0 */,\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "INSERT INTO tab1 VALUES (1, LINESTRING(POINT(0, 0),POINT(2, 2)))", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select i, ST_ASWKT(l) FROM tab1", Expected: []sql.Row{{1, "LINESTRING(0 0,2 2)"}}, }, { Query: "INSERT INTO tab1 VALUES (2, ST_GEOMFROMTEXT(ST_ASWKT(LINESTRING(POINT(1, 6),POINT(4, 3))), 4326))", ExpectedErr: sql.ErrNotMatchingSRIDWithColName, }, { Query: "select i, ST_ASWKT(l) FROM tab1", Expected: []sql.Row{{1, "LINESTRING(0 0,2 2)"}}, }, }, }, { Name: "create table using SRID value for point type", SetUpScript: []string{ "CREATE TABLE tab2 (i int primary key);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE tab2 ADD COLUMN p POINT NOT NULL SRID 0", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table tab2", Expected: []sql.Row{{"tab2", "CREATE TABLE `tab2` (\n `i` int NOT NULL,\n `p` point NOT NULL /*!80003 SRID 0 */,\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "INSERT INTO tab2 VALUES (1, POINT(2, 2))", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select i, ST_ASWKT(p) FROM tab2", Expected: []sql.Row{{1, "POINT(2 2)"}}, }, { Query: "INSERT INTO tab2 VALUES (2, ST_GEOMFROMTEXT(ST_ASWKT(POINT(1, 6)), 4326))", ExpectedErr: sql.ErrNotMatchingSRIDWithColName, }, { Query: "select i, ST_ASWKT(p) FROM tab2", Expected: []sql.Row{{1, "POINT(2 2)"}}, }, { Query: "ALTER TABLE tab2 CHANGE COLUMN p p POINT NOT NULL", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO tab2 VALUES (2, ST_GEOMFROMTEXT(ST_ASWKT(POINT(1, 6)), 4326))", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select i, ST_ASWKT(p) FROM tab2", Expected: []sql.Row{{1, "POINT(2 2)"}, {2, "POINT(1 6)"}}, }, { Query: "ALTER TABLE tab2 CHANGE COLUMN p p POINT NOT NULL SRID 4326", ExpectedErr: sql.ErrNotMatchingSRIDWithColName, }, { Query: "delete from tab2 where i = 1", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "ALTER TABLE tab2 CHANGE COLUMN p p POINT NOT NULL SRID 4326", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table tab2", Expected: []sql.Row{{"tab2", "CREATE TABLE `tab2` (\n `i` int NOT NULL,\n `p` point NOT NULL /*!80003 SRID 4326 */,\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "create table using SRID value for polygon type", SetUpScript: []string{ "CREATE TABLE tab3 (i int primary key, y polygon NOT NULL);", }, Assertions: []ScriptTestAssertion{ { Query: "show create table tab3", Expected: []sql.Row{{"tab3", "CREATE TABLE `tab3` (\n `i` int NOT NULL,\n `y` polygon NOT NULL,\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "INSERT INTO tab3 VALUES (1, polygon(linestring(point(0,0),point(8,0),point(12,9),point(0,9),point(0,0))))", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select i, ST_ASWKT(y) FROM tab3", Expected: []sql.Row{{1, "POLYGON((0 0,8 0,12 9,0 9,0 0))"}}, }, { Query: "ALTER TABLE tab3 MODIFY COLUMN y POLYGON NOT NULL SRID 0", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE tab3 MODIFY COLUMN y POLYGON NOT NULL SRID 4326", ExpectedErr: sql.ErrNotMatchingSRIDWithColName, }, { Query: "select i, ST_ASWKT(y) FROM tab3", Expected: []sql.Row{{1, "POLYGON((0 0,8 0,12 9,0 9,0 0))"}}, }, { Query: "ALTER TABLE tab3 MODIFY COLUMN y GEOMETRY NULL SRID 0", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "select i, ST_ASWKT(y) FROM tab3", Expected: []sql.Row{{1, "POLYGON((0 0,8 0,12 9,0 9,0 0))"}}, }, }, }, { Name: "invalid cases of SRID value", SetUpScript: []string{ "CREATE TABLE table1 (i int primary key, p point srid 4326);", "INSERT INTO table1 VALUES (1, ST_SRID(POINT(1, 5), 4326))", "CREATE TABLE table2 (i int primary key, g geometry /*!80003 SRID 3857*/);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE table3 (i int primary key, p point srid 1);", ExpectedErr: sql.ErrNoSRID, }, { Query: "CREATE TABLE table3 (i int primary key, p point srid 3857);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table table2", Expected: []sql.Row{ {"table2", "CREATE TABLE `table2` (\n `i` int NOT NULL,\n `g` geometry /*!80003 SRID 3857 */,\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "SELECT i, ST_ASWKT(p) FROM table1;", Expected: []sql.Row{{1, "POINT(5 1)"}}, }, { Query: "INSERT INTO table1 VALUES (2, POINT(2, 5))", ExpectedErr: sql.ErrNotMatchingSRIDWithColName, }, { Query: "SELECT i, ST_ASWKT(p) FROM table1;", Expected: []sql.Row{{1, "POINT(5 1)"}}, }, { Query: "ALTER TABLE table1 CHANGE COLUMN p p linestring srid 4326", ExpectedErr: sql.ErrSpatialTypeConversion, }, { Query: "ALTER TABLE table1 CHANGE COLUMN p p geometry srid 0", ExpectedErr: sql.ErrNotMatchingSRIDWithColName, }, { Query: "ALTER TABLE table1 CHANGE COLUMN p p geometry srid 4326", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table table1", Expected: []sql.Row{{"table1", "CREATE TABLE `table1` (\n `i` int NOT NULL,\n `p` geometry /*!80003 SRID 4326 */,\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "INSERT INTO table1 VALUES (2, ST_SRID(LINESTRING(POINT(0, 0),POINT(2, 2)),4326))", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "ALTER TABLE table1 CHANGE COLUMN p p point srid 4326", ExpectedErr: sql.ErrSpatialTypeConversion, }, }, }, }
var SpatialUpdateTests = []WriteQueryTest{ { WriteQuery: "UPDATE point_table SET p = point(123.456,789);", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM point_table;", ExpectedSelect: []sql.Row{{int64(5), types.Point{X: 123.456, Y: 789}}}, }, { WriteQuery: "UPDATE line_table SET l = linestring(point(1.2,3.4),point(5.6,7.8));", ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, SelectQuery: "SELECT * FROM line_table;", ExpectedSelect: []sql.Row{{int64(0), types.LineString{Points: []types.Point{{X: 1.2, Y: 3.4}, {X: 5.6, Y: 7.8}}}}, {int64(1), types.LineString{Points: []types.Point{{X: 1.2, Y: 3.4}, {X: 5.6, Y: 7.8}}}}}, }, { WriteQuery: "UPDATE polygon_table SET p = polygon(linestring(point(1,1),point(1,-1),point(-1,-1),point(-1,1),point(1,1)));", ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, SelectQuery: "SELECT * FROM polygon_table;", ExpectedSelect: []sql.Row{ {int64(0), types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 1}, {X: 1, Y: -1}, {X: -1, Y: -1}, {X: -1, Y: 1}, {X: 1, Y: 1}}}}}}, {int64(1), types.Polygon{Lines: []types.LineString{{Points: []types.Point{{X: 1, Y: 1}, {X: 1, Y: -1}, {X: -1, Y: -1}, {X: -1, Y: 1}, {X: 1, Y: 1}}}}}}, }, }, }
var StatisticsQueries = []ScriptTest{ { Name: "analyze single int column", SetUpScript: []string{ "CREATE TABLE t (i int primary key)", "INSERT INTO t VALUES (1), (2), (3)", "ANALYZE TABLE t", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.column_statistics", Expected: []sql.Row{ {"mydb", "t", "i", types.JSONDocument{Val: map[string]interface{}{"buckets": []interface{}{[]interface{}{"1.00", "1.00", "0.33"}, []interface{}{"2.00", "2.00", "0.33"}, []interface{}{"3.00", "3.00", "0.33"}}}}}, }, }, }, }, { Name: "analyze two int columns", SetUpScript: []string{ "CREATE TABLE t (i int, j int)", "INSERT INTO t VALUES (1, 4), (2, 5), (3, 6)", "ANALYZE TABLE t", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.column_statistics", Expected: []sql.Row{ {"mydb", "t", "i", types.JSONDocument{Val: map[string]interface{}{"buckets": []interface{}{[]interface{}{"1.00", "1.00", "0.33"}, []interface{}{"2.00", "2.00", "0.33"}, []interface{}{"3.00", "3.00", "0.33"}}}}}, {"mydb", "t", "j", types.JSONDocument{Val: map[string]interface{}{"buckets": []interface{}{[]interface{}{"4.00", "4.00", "0.33"}, []interface{}{"5.00", "5.00", "0.33"}, []interface{}{"6.00", "6.00", "0.33"}}}}}, }, }, }, }, { Name: "analyze float columns", SetUpScript: []string{ "CREATE TABLE t (i float)", "INSERT INTO t VALUES (1.25), (45.25), (7.5), (10.5)", "ANALYZE TABLE t", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.column_statistics", Expected: []sql.Row{ {"mydb", "t", "i", types.JSONDocument{Val: map[string]interface{}{"buckets": []interface{}{[]interface{}{"1.25", "1.25", "0.25"}, []interface{}{"7.50", "7.50", "0.25"}, []interface{}{"10.50", "10.50", "0.25"}, []interface{}{"45.25", "45.25", "0.25"}}}}}, }, }, }, }, { Name: "analyze empty table creates stats with 0s", SetUpScript: []string{ "CREATE TABLE t (i float)", "ANALYZE TABLE t", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.column_statistics", Expected: []sql.Row{ {"mydb", "t", "i", types.JSONDocument{Val: map[string]interface{}{"buckets": []interface{}{}}}}, }, }, }, }, { Name: "analyze columns that can't be converted to float throws error", SetUpScript: []string{ "CREATE TABLE t (t longtext)", "INSERT INTO t VALUES ('not a number')", "ANALYZE TABLE t", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM information_schema.column_statistics", Expected: []sql.Row{}, }, }, }, { Query: ` SELECT COLUMN_NAME, JSON_EXTRACT(HISTOGRAM, '$."number-of-buckets-specified"') FROM information_schema.COLUMN_STATISTICS WHERE SCHEMA_NAME = 'mydb' AND TABLE_NAME = 'mytable' `, Expected: nil, }, }
var TableFunctionScriptTests = []ScriptTest{ { Name: "undefined table function", Query: "SELECT * from does_not_exist('q', 123);", ExpectedErr: sql.ErrTableFunctionNotFound, }, { Name: "projection of non-existent column from table function", Query: "SELECT none from simple_TABLE_function(123);", ExpectedErr: sql.ErrColumnNotFound, }, { Name: "projection of non-existent qualified column from table function", Query: "SELECT simple_TABLE_function.none from simple_TABLE_function(123);", ExpectedErr: sql.ErrTableNotFound, }, { Name: "projection of non-existent aliased qualified column from table function", Query: "SELECT stf.none from simple_TABLE_function(123) as stf;", ExpectedErr: sql.ErrTableColumnNotFound, }, { Name: "projection of non-existent aliased qualified column from table function in join", Query: "SELECT stf1.none from simple_TABLE_function(123) as stf1 join simple_TABLE_function(123) stf2;", ExpectedErr: sql.ErrTableColumnNotFound, }, { Name: "alias overwrites original name", Query: "SELECT simple_table_function.none from simple_TABLE_function(123) stf;", ExpectedErr: sql.ErrTableNotFound, }, { Name: "projection of aliased non-existent qualified column from table function", Query: "SELECT stf.none as none from simple_TABLE_function(123) as stf;", ExpectedErr: sql.ErrTableColumnNotFound, }, { Name: "basic table function", Query: "SELECT * from simple_table_function(123);", Expected: []sql.Row{{"foo", 123}}, }, { Name: "basic table function", Query: "SELECT * from simple_TABLE_function(123);", Expected: []sql.Row{{"foo", 123}}, }, { Name: "aggregate function applied to a table function", Query: "SELECT count(*) from simple_TABLE_function(123);", Expected: []sql.Row{{1}}, }, { Name: "projection of table function", Query: "SELECT one from simple_TABLE_function(123);", Expected: []sql.Row{{"foo"}}, }, { Name: "nested expressions in table function arguments", Query: "SELECT * from simple_TABLE_function(concat('f', 'o', 'o'));", Expected: []sql.Row{{"foo", 123}}, }, { Name: "filtering table function results", Query: "SELECT * from simple_TABLE_function(123) where one='foo';", Expected: []sql.Row{{"foo", 123}}, }, { Name: "filtering table function results to no results", Query: "SELECT * from simple_TABLE_function(123) where one='none';", Expected: []sql.Row{}, }, { Name: "grouping table function results", Query: "SELECT count(one) from simple_TABLE_function(123) group by one;", Expected: []sql.Row{{1}}, }, { Name: "table function as subquery", Query: "SELECT * from (select * from simple_TABLE_function(123)) as tf;", Expected: []sql.Row{{"foo", 123}}, }, { Query: "select * from sequence_table('x', 5)", Expected: []sql.Row{{0}, {1}, {2}, {3}, {4}}, }, { Query: "select sequence_table.x from sequence_table('x', 5)", Expected: []sql.Row{{0}, {1}, {2}, {3}, {4}}, }, { Query: "select sequence_table.x from sequence_table('x', 5)", Expected: []sql.Row{{0}, {1}, {2}, {3}, {4}}, }, { Query: "select * from sequence_table('x', 5) join sequence_table('y', 5) on x = y", ExpectedErr: sql.ErrDuplicateAliasOrTable, }, { Query: "select * from sequence_table('x', 5) join sequence_table('y', 5) on x = 0", ExpectedErr: sql.ErrDuplicateAliasOrTable, }, { Query: "select * from sequence_table('x', 2) where x is not null", Expected: []sql.Row{{0}, {1}}, }, { Query: "select seq.x from sequence_table('x', 5) as seq", Expected: []sql.Row{{0}, {1}, {2}, {3}, {4}}, }, { Query: "select seq.x from sequence_table('x', 5) seq", Expected: []sql.Row{{0}, {1}, {2}, {3}, {4}}, }, { Query: "select not_seq.x from sequence_table('x', 5) as seq", ExpectedErr: sql.ErrTableNotFound, }, { Query: "select seq1.x, seq2.y from sequence_table('x', 5) seq1 join sequence_table('y', 5) seq2 on seq1.x = seq2.y", Expected: []sql.Row{{0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}}, ExpectedIndexes: []string{"y", "x"}, }, { Query: "select * from sequence_table('x', 5) seq1 join sequence_table('y', 5) seq2 on x = 0", Expected: []sql.Row{{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}}, ExpectedIndexes: []string{"x"}, }, { Query: "with cte as (select seq.x from sequence_table('x', 5) seq) select cte.x from cte", Expected: []sql.Row{{0}, {1}, {2}, {3}, {4}}, }, { Query: "select sq.x from (select seq.x from sequence_table('x', 5) seq) sq", Expected: []sql.Row{{0}, {1}, {2}, {3}, {4}}, }, { Query: "select seq.x from (select seq.x from sequence_table('x', 5) seq) sq", ExpectedErr: sql.ErrTableNotFound, }, { Query: "select sq.xx from (select seq.x as xx from sequence_table('x', 5) seq) sq", Expected: []sql.Row{{0}, {1}, {2}, {3}, {4}}, }, { Query: "select * from sequence_table('x', 5) where x = 2", Expected: []sql.Row{{2}}, ExpectedIndexes: []string{"x"}, }, }
var TransactionTests = []TransactionTest{ { Name: "Changes from transactions are available before analyzing statements in other sessions (autocommit off)", Assertions: []ScriptTestAssertion{ { Query: "/* client a */ set @@autocommit = 0;", Expected: []sql.Row{{}}, }, { Query: "/* client b */ set @@autocommit = 0;", Expected: []sql.Row{{}}, }, { Query: "/* client a */ select @@autocommit;", Expected: []sql.Row{{0}}, }, { Query: "/* client b */ select @@autocommit;", Expected: []sql.Row{{0}}, }, { Query: "/* client a */ start transaction;", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t;", ExpectedErr: sql.ErrTableNotFound, }, { Query: "/* client a */ create table t(pk int primary key);", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "/* client a */ select * from t2;", ExpectedErr: sql.ErrTableNotFound, }, { Query: "/* client a */ commit;", Expected: []sql.Row{}, }, { Query: "/* client b */ start transaction;", Expected: []sql.Row{}, }, { Query: "/* client b */ select count(*) from t;", Expected: []sql.Row{{0}}, }, }, }, { Name: "autocommit on", SetUpScript: []string{ "create table t (x int primary key, y int)", "insert into t values (1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ insert into t values (2, 2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client b */ insert into t values (3, 3)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, }, }, { Name: "autocommit off", SetUpScript: []string{ "create table t (x int primary key, y int)", "insert into t values (1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client b */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}}, }, { Query: "/* client b */ insert into t values (2, 2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{ {1, 1}, }, }, { Query: "/* client a */ insert into t values (3,3)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client b */ commit", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client a */ commit", Expected: []sql.Row{}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client b */ start transaction", Expected: []sql.Row{}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, }, }, { Name: "toggle autocommit", SetUpScript: []string{ "create table t (x int primary key, y int)", "insert into t values (1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client b */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client b */ insert into t values (2,2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}}, }, { Query: "/* client b */ set autocommit = on", Expected: []sql.Row{{}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}}, }, { Query: "/* client a */ set autocommit = on", Expected: []sql.Row{{}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, }, }, { Name: "autocommit on with explicit transactions", SetUpScript: []string{ "create table t (x int primary key, y int)", "insert into t values (1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ start transaction", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from doesnotexist;", ExpectedErr: sql.ErrTableNotFound, }, { Query: "/* client a */ insert into t values (2, 2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}}, }, { Query: "/* client a */ select * from doesnotexist;", ExpectedErr: sql.ErrTableNotFound, }, { Query: "/* client a */ commit", Expected: []sql.Row{}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client a */ insert into t values (3, 3)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, }, }, { Name: "rollback", SetUpScript: []string{ "create table t (x int primary key, y int)", "insert into t values (1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client b */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client a */ start transaction", Expected: []sql.Row{}, }, { Query: "/* client b */ start transaction", Expected: []sql.Row{}, }, { Query: "/* client a */ insert into t values (2, 2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client b */ insert into t values (3, 3)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client b */ commit", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client a */ rollback", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}}, }, { Query: "/* client a */ insert into t values (2, 2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}}, }, { Query: "/* client a */ commit", Expected: []sql.Row{}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}}, }, { Query: "/* client b */ rollback", Expected: []sql.Row{}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, }, }, { Name: "rollback to savepoint", SetUpScript: []string{ "create table t (x int primary key, y int)", "insert into t values (1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client b */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client a */ start transaction", Expected: []sql.Row{}, }, { Query: "/* client b */ start transaction", Expected: []sql.Row{}, }, { Query: "/* client a */ insert into t values (2, 2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client b */ insert into t values (3, 3)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ savepoint spa1", Expected: []sql.Row{}, }, { Query: "/* client b */ savepoint spb1", Expected: []sql.Row{}, }, { Query: "/* client a */ insert into t values (4, 4)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client b */ insert into t values (5, 5)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ savepoint spa2", Expected: []sql.Row{}, }, { Query: "/* client b */ savepoint spb2", Expected: []sql.Row{}, }, { Query: "/* client a */ insert into t values (6, 6)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client b */ insert into t values (7, 7)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {4, 4}, {6, 6}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}, {5, 5}, {7, 7}}, }, { Query: "/* client a */ rollback to SPA2", Expected: []sql.Row{}, }, { Query: "/* client b */ rollback to spB2", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {4, 4}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}, {5, 5}}, }, { Query: "/* client a */ rollback to sPa2", Expected: []sql.Row{}, }, { Query: "/* client b */ rollback to Spb2", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {4, 4}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}, {5, 5}}, }, { Query: "/* client a */ rollback to spA1", Expected: []sql.Row{}, }, { Query: "/* client b */ rollback to SPb1", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}}, }, { Query: "/* client a */ rollback to spa2", ExpectedErr: sql.ErrSavepointDoesNotExist, }, { Query: "/* client b */ rollback to spb2", ExpectedErr: sql.ErrSavepointDoesNotExist, }, { Query: "/* client a */ rollback to Spa1", Expected: []sql.Row{}, }, { Query: "/* client b */ rollback to spB1", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}}, }, { Query: "/* client a */ rollback", Expected: []sql.Row{}, }, { Query: "/* client b */ commit", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}}, }, { Query: "/* client a */ rollback to spa1", ExpectedErr: sql.ErrSavepointDoesNotExist, }, { Query: "/* client b */ rollback to spb1", ExpectedErr: sql.ErrSavepointDoesNotExist, }, }, }, { Name: "release savepoint", SetUpScript: []string{ "create table t (x int primary key, y int)", "insert into t values (1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client b */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client a */ start transaction", Expected: []sql.Row{}, }, { Query: "/* client b */ start transaction", Expected: []sql.Row{}, }, { Query: "/* client a */ insert into t values (2, 2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client b */ insert into t values (3, 3)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ savepoint spa1", Expected: []sql.Row{}, }, { Query: "/* client b */ savepoint spb1", Expected: []sql.Row{}, }, { Query: "/* client a */ release savepoint Spa1", Expected: []sql.Row{}, }, { Query: "/* client b */ release savepoint sPb1", Expected: []sql.Row{}, }, { Query: "/* client a */ rollback to spa1", ExpectedErr: sql.ErrSavepointDoesNotExist, }, { Query: "/* client b */ rollback to spb1", ExpectedErr: sql.ErrSavepointDoesNotExist, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}}, }, }, }, { Name: "overwrite savepoint", SetUpScript: []string{ "create table t (x int primary key, y int)", "insert into t values (1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ start transaction", Expected: []sql.Row{}, }, { Query: "/* client a */ insert into t values (2, 2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ savepoint spa1", Expected: []sql.Row{}, }, { Query: "/* client a */ insert into t values (3, 3)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ savepoint spa2", Expected: []sql.Row{}, }, { Query: "/* client a */ insert into t values (4, 4)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ savepoint SPA1", Expected: []sql.Row{}, }, { Query: "/* client a */ insert into t values (5, 5)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}}, }, { Query: "/* client a */ rollback to Spa1", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}, {4, 4}}, }, { Query: "/* client a */ rollback to spa2", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, { Query: "/* client a */ rollback to spa1", ExpectedErr: sql.ErrSavepointDoesNotExist, }, { Query: "/* client a */ release savepoint spa1", ExpectedErr: sql.ErrSavepointDoesNotExist, }, }, }, { Name: "Test AUTO INCREMENT with no autocommit", SetUpScript: []string{ "CREATE table t (x int PRIMARY KEY AUTO_INCREMENT, y int);", "CREATE table t2 (x int PRIMARY KEY AUTO_INCREMENT, y int);", "CREATE table t3 (x int PRIMARY KEY AUTO_INCREMENT, y int);", "insert into t (y) values (1);", "insert into t2 values (10, 10);", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client b */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client c */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client a */ insert into t (y) values (2)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 2}}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}}, }, { Query: "/* client c*/ select * from t order by x", Expected: []sql.Row{{1, 1}}, }, { Query: "/* client b */ insert into t (y) values (3)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 3}}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{ {1, 1}, {2, 2}, }, }, { Query: "/* client c */ select * from t order by x", Expected: []sql.Row{ {1, 1}, }, }, { Query: "/* client c */ insert into t2 (y) values (11)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 11}}}, }, { Query: "/* client a */ select * from t2 order by x", Expected: []sql.Row{{10, 10}}, }, { Query: "/* client b */ select * from t2 order by x", Expected: []sql.Row{{10, 10}}, }, { Query: "/* client c */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {11, 11}}, }, { Query: "/* client a */ insert into t2 (y) values (12)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 12}}}, }, { Query: "/* client a */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {12, 12}}, }, { Query: "/* client b */ select * from t2 order by x", Expected: []sql.Row{{10, 10}}, }, { Query: "/* client c */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {11, 11}}, }, { Query: "/* client a */ commit", Expected: []sql.Row{}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {3, 3}}, }, { Query: "/* client b */ select * from t2 order by x", Expected: []sql.Row{{10, 10}}, }, { Query: "/* client c */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {11, 11}}, }, { Query: "/* client c */ select * from t order by x", Expected: []sql.Row{ {1, 1}, }, }, { Query: "/* client b */ commit", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, { Query: "/* client a */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {12, 12}}, }, { Query: "/* client c */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {11, 11}}, }, { Query: "/* client c */ select * from t order by x", Expected: []sql.Row{{1, 1}}, }, { Query: "/* client c */ commit", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, { Query: "/* client a */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {12, 12}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, { Query: "/* client b */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {11, 11}, {12, 12}}, }, { Query: "/* client a */ start transaction", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, { Query: "/* client c */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, { Query: "/* client a */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {11, 11}, {12, 12}}, }, { Query: "/* client b */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {11, 11}, {12, 12}}, }, { Query: "/* client c */ select * from t2 order by x", Expected: []sql.Row{{10, 10}, {11, 11}, {12, 12}}, }, { Query: "/* client a */ insert into t values (10, 10)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 10}}}, }, { Query: "/* client b */ insert into t (y) values (11)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 11}}}, }, { Query: "/* client c */ insert into t values (50, 50)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 50}}}, }, { Query: "/* client b */ insert into t (y) values (51)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 51}}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}, {10, 10}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}, {11, 11}, {51, 51}}, }, { Query: "/* client c */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}, {50, 50}}, }, { Query: "/* client a */ commit", Expected: []sql.Row{}, }, { Query: "/* client b */ commit", Expected: []sql.Row{}, }, { Query: "/* client c */ commit", Expected: []sql.Row{}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}, {10, 10}, {11, 11}, {50, 50}, {51, 51}}, }, { Query: "/* client b */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}, {10, 10}, {11, 11}, {50, 50}, {51, 51}}, }, { Query: "/* client c */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}, {10, 10}, {11, 11}, {50, 50}, {51, 51}}, }, { Query: "/* client a */ insert into t values (NULL, 52)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 52}}}, }, { Query: "/* client a */ select * from t order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}, {10, 10}, {11, 11}, {50, 50}, {51, 51}, {52, 52}}, }, }, }, { Name: "AUTO_INCREMENT transactions off", SetUpScript: []string{ "CREATE table t2 (x int PRIMARY KEY AUTO_INCREMENT, y int);", "insert into t2 (y) values (1);", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ insert into t2 (y) values (2)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 2}}}, }, { Query: "/* client b */ select * from t2 order by x", Expected: []sql.Row{{1, 1}, {2, 2}}, }, { Query: "/* client b */ insert into t2 (y) values (3)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 3}}}, }, { Query: "/* client a */ select * from t2 order by x", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, }, { Query: "/* client a */ alter table t2 modify column x int", Expected: []sql.Row{{types.OkResult{RowsAffected: 0, InsertID: 0}}}, }, { Query: "/* client a */ INSERT INTO t2 values (NULL, 3)", ExpectedErr: sql.ErrInsertIntoNonNullableProvidedNull, }, { Query: "/* client a */ DROP TABLE t2", Expected: []sql.Row{{types.OkResult{RowsAffected: 0, InsertID: 0}}}, }, { Query: "/* client a */ CREATE table t2 (x int PRIMARY KEY AUTO_INCREMENT, y int)", Expected: []sql.Row{{types.OkResult{RowsAffected: 0, InsertID: 0}}}, }, { Query: "/* client a */ insert into t2 (y) values (4)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 1}}}, }, { Query: "/* client a */ SELECT * FROM t2", Expected: []sql.Row{{1, 4}}, }, }, }, { Name: "READ ONLY Transactions", SetUpScript: []string{ "create table t2 (pk int primary key, val int)", "insert into t2 values (0,0)", "commit", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ set autocommit = off", Expected: []sql.Row{{}}, }, { Query: "/* client a */ create temporary table tmp(pk int primary key)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "/* client a */ START TRANSACTION READ ONLY", Expected: []sql.Row{}, }, { Query: "/* client a */ INSERT INTO tmp VALUES (1)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ insert into t2 values (1, 1)", ExpectedErr: sql.ErrReadOnlyTransaction, }, { Query: "/* client a */ insert into t2 values (2, 2)", ExpectedErr: sql.ErrReadOnlyTransaction, }, { Query: "/* client a */ delete from t2 where pk = 0", ExpectedErr: sql.ErrReadOnlyTransaction, }, { Query: "/* client a */ alter table t2 add val2 int", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "/* client a */ select * from t2", Expected: []sql.Row{{0, 0, nil}}, }, { Query: "/* client a */ create temporary table tmp2(pk int primary key)", ExpectedErr: sql.ErrReadOnlyTransaction, }, { Query: "/* client a */ COMMIT", Expected: []sql.Row{}, }, { Query: "/* client b */ START TRANSACTION READ ONLY", Expected: []sql.Row{}, }, { Query: "/* client b */ SELECT * FROM t2", Expected: []sql.Row{{0, 0, nil}}, }, }, }, }
var TriggerErrorTests = []ScriptTest{ { Name: "table doesn't exist", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", }, Query: "create trigger not_found before insert on y for each row set new.a = new.a + 1", ExpectedErr: sql.ErrTableNotFound, }, { Name: "trigger errors on execution", SetUpScript: []string{ "create table x (a int primary key, b int)", "create table y (c int primary key not null)", "create trigger trigger_has_error before insert on x for each row insert into y values (null)", }, Query: "insert into x values (1,2)", ExpectedErr: sql.ErrInsertIntoNonNullableProvidedNull, }, { Name: "self update on insert", SetUpScript: []string{ "create table a (x int primary key)", "create trigger a1 before insert on a for each row insert into a values (new.x * 2)", }, Query: "insert into a values (1), (2), (3)", ExpectedErr: sql.ErrTriggerTableInUse, }, { Name: "self update on delete", SetUpScript: []string{ "create table a (x int primary key)", "create trigger a1 before delete on a for each row delete from a", }, Query: "delete from a", ExpectedErr: sql.ErrTriggerTableInUse, }, { Name: "self update on update", SetUpScript: []string{ "create table a (x int primary key)", "create trigger a1 before update on a for each row update a set x = 1", }, Query: "update a set x = 2", ExpectedErr: sql.ErrTriggerTableInUse, }, { Name: "circular dependency", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create trigger a1 before insert on a for each row insert into b values (new.x * 2)", "create trigger b1 before insert on b for each row insert into a values (new.y * 7)", }, Query: "insert into a values (1), (2), (3)", ExpectedErr: sql.ErrTriggerTableInUse, }, { Name: "circular dependency, nested two deep", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create table c (z int primary key)", "create trigger a1 before insert on a for each row insert into b values (new.x * 2)", "create trigger b1 before insert on b for each row insert into c values (new.y * 5)", "create trigger c1 before insert on c for each row insert into a values (new.z * 7)", }, Query: "insert into a values (1), (2), (3)", ExpectedErr: sql.ErrTriggerTableInUse, }, { Name: "reference to old on insert", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", }, Query: "create trigger old_on_insert before insert on x for each row set new.c = old.a + 1", ExpectedErr: sql.ErrTableNotFound, }, { Name: "reference to new on delete", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", }, Query: "create trigger new_on_delete before delete on x for each row set new.c = old.a + 1", ExpectedErr: sql.ErrTableNotFound, }, { Name: "set old row on update", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", }, Query: "create trigger update_old before update on x for each row set old.c = new.a + 1", ExpectedErr: sql.ErrInvalidUpdateOfOldRow, }, { Name: "set old row on update, begin block", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", }, Query: "create trigger update_old before update on x for each row BEGIN set old.c = new.a + 1; END", ExpectedErr: sql.ErrInvalidUpdateOfOldRow, }, { Name: "set new row after insert", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", }, Query: "create trigger update_new after insert on x for each row set new.c = new.a + 1", ExpectedErr: sql.ErrInvalidUpdateInAfterTrigger, }, { Name: "set new row after update", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", }, Query: "create trigger update_new after update on x for each row set new.c = new.a + 1", ExpectedErr: sql.ErrInvalidUpdateInAfterTrigger, }, { Name: "set new row after update, begin block", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", }, Query: "create trigger update_new after update on x for each row BEGIN set new.c = new.a + 1; END", ExpectedErr: sql.ErrInvalidUpdateInAfterTrigger, }, { Name: "source column doesn't exist", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", }, Query: "create trigger not_found before insert on x for each row set new.d = new.d + 1", ExpectedErr: sql.ErrTableNotFound, }, { Name: "target column doesn't exist", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", }, Query: "create trigger not_found before insert on x for each row set new.d = new.a + 1", ExpectedErr: sql.ErrTableNotFound, }, }
var TriggerTests = []ScriptTest{ { Name: "trigger before inserts, use updated reference to other table", SetUpScript: []string{ "create table a (i int primary key, j int)", "create table b (x int primary key)", "create trigger trig before insert on a for each row begin set new.j = (select coalesce(max(x),1) from b); update b set x = x + 1; end;", "insert into b values (1)", "insert into a values (1,0), (2,0), (3,0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from a order by i", Expected: []sql.Row{ {1, 1}, {2, 2}, {3, 3}, }, }, { Query: "select x from b", Expected: []sql.Row{ {4}, }, }, { Query: "insert into a values (4,0), (5,0)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, }, }, { Name: "trigger before inserts, use count updated reference to other table", SetUpScript: []string{ "create table a (i int, j int)", "create table b (x int)", "create trigger trig before insert on a for each row begin set new.j = (select count(x) from b); insert into b values (new.i + new.j); end;", "insert into a values (0,0), (0,0), (0,0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from a order by j", Expected: []sql.Row{ {0, 0}, {0, 1}, {0, 2}, }, }, { Query: "select x from b", Expected: []sql.Row{ {0}, {1}, {2}, }, }, { Query: "insert into a values (0,0), (0,0)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, }, }, { Name: "trigger after insert, insert into other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create trigger insert_into_b after insert on a for each row insert into b values (new.x + 1)", "insert into a values (1), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {3}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {2}, {4}, {6}, }, }, { Query: "insert into a values (7), (9)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, }, }, { Name: "trigger after insert, delete from other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into b values (0), (2), (4), (6), (8)", "create trigger insert_into_b after insert on a for each row delete from b where y = (new.x + 1)", "insert into a values (1), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {3}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {0}, {8}, }, }, { Query: "insert into a values (7), (9)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, }, }, { Name: "trigger after insert, update other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into b values (0), (2), (4), (6), (8)", "create trigger insert_into_b after insert on a for each row update b set y = new.x where y = new.x + 1", "insert into a values (1), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {3}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {0}, {1}, {3}, {5}, {8}, }, }, }, }, { Name: "trigger before insert, insert into other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create trigger insert_into_b before insert on a for each row insert into b values (new.x + 1)", "insert into a values (1), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {3}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {2}, {4}, {6}, }, }, { Query: "insert into a values (7), (9)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, }, }, { Name: "trigger before insert, insert into other table with different schema", SetUpScript: []string{ "create table a (x int primary key, y int)", "create table b (z int primary key)", "create trigger insert_into_b before insert on a for each row insert into b values (new.x + 1)", "insert into a values (1,2), (3,4), (5,6)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {3}, {5}, }, }, { Query: "select z from b order by 1", Expected: []sql.Row{ {2}, {4}, {6}, }, }, { Query: "insert into a values (7,8), (9,10)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, }, }, { Name: "trigger before insert, delete from other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into b values (0), (2), (4), (6), (8)", "create trigger insert_into_b before insert on a for each row delete from b where y = (new.x + 1)", "insert into a values (1), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {3}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {0}, {8}, }, }, { Query: "insert into a values (7), (9)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, }, }, { Name: "trigger before insert, update other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into b values (0), (2), (4), (6), (8)", "create trigger insert_into_b before insert on a for each row update b set y = new.x where y = new.x + 1", "insert into a values (1), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {3}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {0}, {1}, {3}, {5}, {8}, }, }, }, }, { Name: "trigger before insert, updates references to 2 tables", SetUpScript: []string{ "create table a (i int, j int, k int)", "create table b (x int)", "create table c (y int)", "insert into b values (0)", "insert into c values (0)", "create trigger trig before insert on a for each row begin set new.j = (select x from b); set new.k = (select y from c); update b set x = x + 1; update c set y = y + 2; end;", "insert into a values (0, 0, 0), (1, 0, 0), (2, 0, 0), (3, 0, 0), (4, 0, 0)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from a order by 1", Expected: []sql.Row{ {0, 0, 0}, {1, 1, 2}, {2, 2, 4}, {3, 3, 6}, {4, 4, 8}, }, }, { Query: "select x from b order by 1", Expected: []sql.Row{ {5}, }, }, { Query: "select y from c order by 1", Expected: []sql.Row{ {10}, }, }, }, }, { Name: "trigger before insert, alter inserted value", SetUpScript: []string{ "create table a (x int primary key)", "create trigger insert_into_a before insert on a for each row set new.x = new.x + 1", "insert into a values (1)", }, Query: "select x from a order by 1", Expected: []sql.Row{ {2}, }, }, { Name: "trigger before insert, alter inserted value, multiple columns", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", "create trigger insert_into_x before insert on x for each row set new.a = new.a + 1, new.b = new.c, new.c = 0", "insert into x values (1, 10, 100)", }, Query: "select * from x order by 1", Expected: []sql.Row{ {2, 100, 0}, }, }, { Name: "trigger before insert, alter inserted value, multiple columns, system var", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", "set @@auto_increment_increment = 1", "create trigger insert_into_x before insert on x for each row " + "set new.a = new.a + 1, new.b = new.c, new.c = 0, @@auto_increment_increment = @@auto_increment_increment + 1", "insert into x values (1, 10, 100), (2, 20, 200)", }, Query: "select *, @@auto_increment_increment from x order by 1", Expected: []sql.Row{ {2, 100, 0, 3}, {3, 200, 0, 3}, }, }, { Name: "trigger before insert, alter inserted value, out of order insertion", SetUpScript: []string{ "create table a (x int primary key, y int)", "create trigger a1 before insert on a for each row set new.x = new.x * 2, new.y = new.y * 3", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a (y, x) values (5,7), (9,11)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "select x, y from a order by 1", Expected: []sql.Row{ {14, 15}, {22, 27}, }, }, }, }, { Name: "trigger before insert, alter inserted value, incomplete insertion", SetUpScript: []string{ "create table a (x int primary key, y int, z int default 5)", "create trigger a1 before insert on a for each row set new.x = new.x * 2, new.y = new.y * 3, new.z = new.z * 5", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a (y, x) values (5,7), (9,11)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "select x, y, z from a order by 1", Expected: []sql.Row{ {14, 15, 25}, {22, 27, 25}, }, }, }, }, { Name: "trigger before insert, begin block with multiple set statements", SetUpScript: []string{ "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT);", "INSERT INTO test VALUES (0,2),(1,3)", `CREATE TRIGGER tt BEFORE INSERT ON test FOR EACH ROW BEGIN SET NEW.v1 = NEW.v1 * 11; SET NEW.v1 = NEW.v1 * -10; END;`, "INSERT INTO test VALUES (2,4), (6,8);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test ORDER BY 1", Expected: []sql.Row{ {0, 2}, {1, 3}, {2, -440}, {6, -880}, }, }, }, }, { Name: "trigger before insert, begin block with multiple set statements and inserts", SetUpScript: []string{ "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT);", "CREATE TABLE test2(pk BIGINT PRIMARY KEY, v1 BIGINT);", "CREATE TABLE test3(pk BIGINT PRIMARY KEY, v1 BIGINT);", "INSERT INTO test VALUES (0,2),(1,3)", `CREATE TRIGGER tt BEFORE INSERT ON test FOR EACH ROW BEGIN SET NEW.v1 = NEW.v1 * 11; insert into test2 values (new.pk * 3, new.v1); SET NEW.v1 = NEW.v1 * -10; insert into test3 values (new.pk * 5, new.v1); set @var = 0; END;`, "INSERT INTO test VALUES (2,4), (6,8);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test ORDER BY 1", Expected: []sql.Row{ {0, 2}, {1, 3}, {2, -440}, {6, -880}, }, }, { Query: "SELECT * FROM test2 ORDER BY 1", Expected: []sql.Row{ {6, 44}, {18, 88}, }, }, { Query: "SELECT * FROM test3 ORDER BY 1", Expected: []sql.Row{ {10, -440}, {30, -880}, }, }, }, }, { Name: "Create a trigger on a new database and verify that the trigger works when selected on another database", SetUpScript: []string{ "create table foo.a (x int primary key)", "create table foo.b (y int primary key)", "use foo", "create trigger insert_into_b after insert on foo.a for each row insert into foo.b values (new.x + 1)", "use mydb", "insert into foo.a values (1), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from foo.a order by 1", Expected: []sql.Row{ {1}, {3}, {5}, }, }, { Query: "select y from foo.b order by 1", Expected: []sql.Row{ {2}, {4}, {6}, }, }, { Query: "insert into foo.a values (7), (9)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, }, }, { Name: "trigger with escaped chars", SetUpScript: []string{ "CREATE TABLE testInt(v1 BIGINT);", "CREATE TABLE testStr(s1 VARCHAR(255), s2 VARCHAR(255), s3 VARCHAR(255));", `CREATE TRIGGER tt BEFORE INSERT ON testInt FOR EACH ROW BEGIN insert into testStr values (CONCAT('joe''s:', NEW.v1), CONCAT('jill\'s:', NEW.v1 + 1), CONCAT("stan""s:", NEW.v1 + 2) ); END;`, "INSERT INTO testInt VALUES (1);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM testStr", Expected: []sql.Row{ {"joe's:1", "jill's:2", "stan\"s:3"}, }, }, }, }, { Name: "trigger after update, insert into other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (1), (3), (5)", "create trigger insert_into_b after update on a for each row insert into b values (old.x + new.x + 1)", "update a set x = x + 1 where x in (1, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {2}, {4}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {4}, {8}, }, }, { Query: "update a set x = x + 1 where x = 5", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }, }}, }, }, }, }, { Name: "trigger after update, delete from other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (0), (2), (4), (6), (8)", "insert into b values (1), (3), (5), (7), (9)", "create trigger delete_from_b after update on a for each row delete from b where y = old.x + new.x", "update a set x = x + 1 where x in (2,4)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {0}, {3}, {5}, {6}, {8}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {1}, {3}, {7}, }, }, }, }, { Name: "trigger after update, update other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (0), (2), (4), (6), (8)", "insert into b values (0), (2), (4), (8)", "create trigger update_b after update on a for each row update b set y = old.x + new.x + 1 where y = old.x", "update a set x = x + 1 where x in (2, 4)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {0}, {3}, {5}, {6}, {8}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {0}, {6}, {8}, {10}, }, }, }, }, { Name: "trigger before update, insert into other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (1), (3), (5)", "create trigger insert_into_b before update on a for each row insert into b values (old.x + new.x + 1)", "update a set x = x + 1 where x in (1, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {2}, {4}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {4}, {8}, }, }, { Query: "update a set x = x + 1 where x = 5", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }, }}, }, }, }, }, { Name: "trigger before update, delete from other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (0), (2), (4), (6), (8)", "insert into b values (1), (3), (5), (7), (9)", "create trigger delete_from_b before update on a for each row delete from b where y = old.x + new.x", "update a set x = x + 1 where x in (2,4)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {0}, {3}, {5}, {6}, {8}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {1}, {3}, {7}, }, }, }, }, { Name: "trigger before update, update other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (0), (2), (4), (6), (8)", "insert into b values (0), (2), (4), (8)", "create trigger update_b before update on a for each row update b set y = old.x + new.x + 1 where y = old.x", "update a set x = x + 1 where x in (2, 4)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {0}, {3}, {5}, {6}, {8}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {0}, {6}, {8}, {10}, }, }, }, }, { Name: "trigger before update, set new value", SetUpScript: []string{ "create table a (x int primary key)", "insert into a values (1), (10)", "create trigger update_a before update on a for each row set new.x = new.x + old.x", "update a set x = x + 1", }, Query: "select x from a order by 1", Expected: []sql.Row{ {3}, {21}, }, }, { Name: "trigger before update, set new value to old value", SetUpScript: []string{ "create table a (x int primary key)", "insert into a values (1), (10)", "create trigger no_step_on_snek before update on a for each row set new.x = old.x", "update a set x = x + 1", }, Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {10}, }, }, { Name: "trigger before update, set new values, multiple cols", SetUpScript: []string{ "create table a (x int primary key, y int)", "insert into a values (1,3), (10,20)", "create trigger update_a before update on a for each row set new.x = new.x + old.y, new.y = new.y + old.x", "update a set x = x + 1, y = y + 1", }, Query: "select x, y from a order by 1", Expected: []sql.Row{ {5, 5}, {31, 31}, }, }, { Name: "trigger before update, set new values, multiple cols (2)", SetUpScript: []string{ "create table a (x int primary key, y int)", "insert into a values (1,3), (10,20)", "create trigger update_a before update on a for each row set new.x = new.x + new.y, new.y = new.y + old.y", "update a set x = x + 1, y = y + 1", }, Query: "select x, y from a order by 1", Expected: []sql.Row{ {6, 7}, {32, 41}, }, }, { Name: "trigger before update, with indexed update", SetUpScript: []string{ "create table a (x int primary key, y int, unique key (y))", "create table b (z int primary key)", "insert into a values (1,3), (10,20)", "create trigger insert_b before update on a for each row insert into b values (old.x * 10)", "update a set x = x + 1 where y = 20", }, Assertions: []ScriptTestAssertion{ { Query: "select x, y from a order by 1", Expected: []sql.Row{ {1, 3}, {11, 20}, }, }, { Query: "select z from b", Expected: []sql.Row{ {100}, }, }, }, }, { Name: "trigger before update, begin block with multiple set statements", SetUpScript: []string{ "CREATE TABLE test(pk BIGINT PRIMARY KEY, v1 BIGINT);", "INSERT INTO test VALUES (0,2),(1,3)", "CREATE TRIGGER tt BEFORE UPDATE ON test FOR EACH ROW BEGIN SET NEW.v1 = (OLD.v1 * 2) + NEW.v1; SET NEW.v1 = NEW.v1 * -10; END;", "UPDATE test SET v1 = v1 + 1;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test ORDER BY 1", Expected: []sql.Row{ {0, -70}, {1, -100}, }, }, }, }, { Name: "trigger before update with set clause inside if statement with '!' operator", SetUpScript: []string{ "CREATE TABLE test (stat_id INT);", "INSERT INTO test VALUES (-1), (1);", }, Assertions: []ScriptTestAssertion{ { Query: ` CREATE TRIGGER before_test_stat_update BEFORE UPDATE ON test FOR EACH ROW BEGIN IF !(new.stat_id < 0) THEN SET new.stat_id = new.stat_id * -1; END IF; END;`, Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "update test set stat_id=2 where stat_id=1;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "select * from test order by stat_id;", Expected: []sql.Row{{-2}, {-1}}, }, { Query: "update test set stat_id=-2 where stat_id=-1;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "select * from test;", Expected: []sql.Row{{-2}, {-2}}, }, }, }, { Name: "trigger before update with set clause inside if statement with 'NOT'", SetUpScript: []string{ "CREATE TABLE test (stat_id INT);", "INSERT INTO test VALUES (-1), (1);", }, Assertions: []ScriptTestAssertion{ { Query: ` CREATE TRIGGER before_test_stat_update BEFORE UPDATE ON test FOR EACH ROW BEGIN IF NOT(new.stat_id < 0) THEN SET new.stat_id = new.stat_id * -1; END IF; END;`, Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "update test set stat_id=2 where stat_id=1;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "select * from test order by stat_id;", Expected: []sql.Row{{-2}, {-1}}, }, { Query: "update test set stat_id=-2 where stat_id=-1;", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, }, { Query: "select * from test;", Expected: []sql.Row{{-2}, {-2}}, }, }, }, { Name: "trigger after delete, insert into other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (1), (3), (5)", "create trigger insert_into_b after delete on a for each row insert into b values (old.x + 1)", "delete from a where x in (1, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {2}, {4}, }, }, { Query: "delete from a where x = 5", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, }, }, { Name: "trigger after delete, delete from other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (0), (2), (4), (6), (8)", "insert into b values (0), (2), (4), (6), (8)", "create trigger delete_from_b after delete on a for each row delete from b where y = old.x", "delete from a where x in (2,4,6)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {0}, {8}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {0}, {8}, }, }, }, }, { Name: "trigger after delete, update other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (0), (2), (4), (6), (8)", "insert into b values (0), (2), (4), (6), (8)", "create trigger update_b after delete on a for each row update b set y = old.x + 1 where y = old.x", "delete from a where x in (2,4,6)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {0}, {8}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {0}, {3}, {5}, {7}, {8}, }, }, }, }, { Name: "trigger before delete, insert into other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (0), (2), (4), (6), (8)", "create trigger insert_into_b before delete on a for each row insert into b values (old.x + 1)", "delete from a where x in (2, 4, 6)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {0}, {8}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {3}, {5}, {7}, }, }, { Query: "delete from a where x = 0", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, }, }, { Name: "trigger before delete, delete from other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (0), (2), (4), (6), (8)", "insert into b values (1), (3), (5), (7), (9)", "create trigger delete_from_b before delete on a for each row delete from b where y = (old.x + 1)", "delete from a where x in (2, 4, 6)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {0}, {8}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {1}, {9}, }, }, }, }, { Name: "trigger before delete, update other table", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into a values (0), (2), (4), (6), (8)", "insert into b values (1), (3), (5), (7), (9)", "create trigger update_b before delete on a for each row update b set y = old.x where y = old.x + 1", "delete from a where x in (2, 4, 6)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {0}, {8}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {1}, {2}, {4}, {6}, {9}, }, }, }, }, { Name: "trigger before delete, delete with index", SetUpScript: []string{ "create table a (x int primary key, z int, unique key (z))", "create table b (y int primary key)", "insert into a values (0,1), (2,3), (4,5)", "create trigger insert_b before delete on a for each row insert into b values (old.x * 2)", "delete from a where z > 2", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {0}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {4}, {8}, }, }, }, }, { Name: "trigger before delete, update other table", SetUpScript: []string{ "create table a (i int primary key, j int)", "insert into a values (0,1), (2,3), (4,5)", "create table b (x int)", "insert into b values (0)", "create trigger trig before delete on a for each row begin update b set x = x + old.j; end;", "delete from a where true", }, Assertions: []ScriptTestAssertion{ { Query: "select * from a order by 1", Expected: []sql.Row{}, }, { Query: "select x from b order by 1", Expected: []sql.Row{ {9}, }, }, }, }, { Name: "single trigger before single target table delete from join", SetUpScript: []string{ "create table a (i int primary key, j int)", "insert into a values (0,1), (2,3), (4,5)", "create table b (i int primary key)", "insert into b values (1), (3), (5)", "create table c (x int)", "insert into c values (0)", "create trigger trig before delete on a for each row begin update c set x = x + 1; end;", }, Assertions: []ScriptTestAssertion{ { Query: "delete a from a inner join b on a.j=b.i;", ExpectedErrStr: "delete from with explicit target tables does not support triggers; retry with single table deletes", }, }, }, { Name: "multiple trigger before single target table delete from join", SetUpScript: []string{ "create table a (i int primary key, j int)", "insert into a values (0,1), (2,3), (4,5)", "create table b (i int primary key)", "insert into b values (1), (3), (5)", "create table c (x int)", "insert into c values (0)", "create trigger trig1 before delete on a for each row begin update c set x = x + 1; end;", "create trigger trig2 before delete on b for each row begin update c set x = x + 1; end;", }, Assertions: []ScriptTestAssertion{ { Query: "delete a from a inner join b on a.j=b.i where a.i >= 0;", ExpectedErrStr: "delete from with explicit target tables does not support triggers; retry with single table deletes", }, }, }, { Name: "multiple trigger before multiple target table delete from join", SetUpScript: []string{ "create table a (i int primary key, j int)", "insert into a values (0,1), (2,3), (4,5)", "create table b (i int primary key)", "insert into b values (1), (3), (5)", "create table c (x int)", "insert into c values (0)", "create trigger trig1 before delete on a for each row begin update c set x = x + 1; end;", "create trigger trig2 before delete on b for each row begin update c set x = x + 1; end;", }, Assertions: []ScriptTestAssertion{ { Query: "delete a, b from a inner join b on a.j=b.i where a.i >= 0;", ExpectedErrStr: "delete from with explicit target tables does not support triggers; retry with single table deletes", }, }, }, { Name: "triggers before and after insert", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create trigger a1 before insert on a for each row insert into b values (NEW.x * 7)", "create trigger a2 after insert on a for each row insert into b values (New.x * 11)", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (2), (3), (5)", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select x from a order by 1", Expected: []sql.Row{ {2}, {3}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {14}, {21}, {22}, {33}, {35}, {55}, }, }, }, }, { Name: "multiple triggers before insert", SetUpScript: []string{ "create table a (x int primary key)", "create trigger a1 before insert on a for each row set new.x = New.x + 1", "create trigger a2 before insert on a for each row set new.x = New.x * 2", "create trigger a3 before insert on a for each row set new.x = New.x - 5", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (3)", Expected: []sql.Row{ {types.NewOkResult(2)}, }, }, { Query: "select x from a order by 1", Expected: []sql.Row{ {-1}, {3}, }, }, }, }, { Name: "multiple triggers before insert, with precedes / follows", SetUpScript: []string{ "create table a (x int primary key)", "create trigger a1 before insert on a for each row set new.x = New.x + 1", "create trigger a2 before insert on a for each row precedes a1 set new.x = New.x * 2", "create trigger a3 before insert on a for each row precedes a2 set new.x = New.x - 5", "create trigger a4 before insert on a for each row follows a2 set new.x = New.x * 3", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (3)", Expected: []sql.Row{ {types.NewOkResult(2)}, }, }, { Query: "select x from a order by 1", Expected: []sql.Row{ {-23}, {-11}, }, }, }, }, { Name: "triggers before and after update", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create trigger a1 before update on a for each row insert into b values (old.x * 7)", "create trigger a2 after update on a for each row insert into b values (old.x * 11)", "insert into a values (2), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "update a set x = x * 2", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 3, Info: plan.UpdateInfo{ Matched: 3, Updated: 3, }, }}, }, }, { Query: "select x from a order by 1", Expected: []sql.Row{ {4}, {6}, {10}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {14}, {21}, {22}, {33}, {35}, {55}, }, }, }, }, { Name: "multiple triggers before and after update", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create trigger a1 before update on a for each row insert into b values (old.x * 7)", "create trigger a2 after update on a for each row insert into b values (old.x * 11)", "create trigger a3 before update on a for each row insert into b values (old.x * 13)", "create trigger a4 after update on a for each row insert into b values (old.x * 17)", "insert into a values (2), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "update a set x = x * 2", Expected: []sql.Row{ {types.OkResult{ RowsAffected: 3, Info: plan.UpdateInfo{ Matched: 3, Updated: 3, }, }}, }, }, { Query: "select x from a order by 1", Expected: []sql.Row{ {4}, {6}, {10}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {14}, {21}, {22}, {26}, {33}, {34}, {35}, {39}, {51}, {55}, {65}, {85}, }, }, }, }, { Name: "triggers before and after delete", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create trigger a1 before delete on a for each row insert into b values (old.x * 7)", "create trigger a2 after delete on a for each row insert into b values (old.x * 11)", "insert into a values (2), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "delete from a", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select x from a order by 1", Expected: []sql.Row{}, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {14}, {21}, {22}, {33}, {35}, {55}, }, }, }, }, { Name: "multiple triggers before and after delete", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create trigger a1 before delete on a for each row insert into b values (old.x * 7)", "create trigger a2 after delete on a for each row insert into b values (old.x * 11)", "create trigger a3 before delete on a for each row insert into b values (old.x * 13)", "create trigger a4 after delete on a for each row insert into b values (old.x * 17)", "insert into a values (2), (3), (5)", }, Assertions: []ScriptTestAssertion{ { Query: "delete from a", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select x from a order by 1", Expected: []sql.Row{}, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {14}, {21}, {22}, {26}, {33}, {34}, {35}, {39}, {51}, {55}, {65}, {85}, }, }, }, }, { Name: "multiple triggers before and after insert, with precedes / follows", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "insert into b values (1), (3)", "create trigger a1 before insert on a for each row set new.x = New.x + 1", "create trigger a2 before insert on a for each row precedes a1 set new.x = New.x * 2", "create trigger a3 before insert on a for each row precedes a2 set new.x = New.x - 5", "create trigger a4 before insert on a for each row follows a2 set new.x = New.x * 3", "create trigger a5 after insert on a for each row update b set y = y + 1 order by y asc", "create trigger a6 after insert on a for each row precedes a5 update b set y = y * 2 order by y asc", "create trigger a7 after insert on a for each row precedes a6 update b set y = y - 5 order by y asc", "create trigger a8 after insert on a for each row follows a6 update b set y = y * 3 order by y asc", }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (3)", Expected: []sql.Row{ {types.NewOkResult(2)}, }, }, { Query: "select x from a order by 1", Expected: []sql.Row{ {-23}, {-11}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {-167}, {-95}, }, }, }, }, { Name: "triggered update query which could project", SetUpScript: []string{ "create table trigger_on_update (id int primary key, first varchar(25), last varchar(25))", "create table is_dirty (id int primary key, is_dirty bool)", "insert into is_dirty values (1, false)", "insert into trigger_on_update values (1, 'george', 'smith')", `create trigger trigger_on_update_on_update before update on trigger_on_update for each row begin update is_dirty set is_dirty = true; end;`, }, Assertions: []ScriptTestAssertion{ { Query: "select id, is_dirty from is_dirty", Expected: []sql.Row{ {1, 0}, }, }, { Query: "update trigger_on_update set id = 1, first = 'george', last = 'smith' where id = 1", Expected: []sql.Row{ { types.OkResult{ RowsAffected: 0, Info: plan.UpdateInfo{ Matched: 1, Updated: 0, }, }, }, }, }, { Query: "select id, is_dirty from is_dirty", Expected: []sql.Row{ {1, 1}, }, }, }, }, { Name: "trigger before insert with subquery expressions", SetUpScript: []string{ "create table rn (id int primary key, upstream_edge_id int, downstream_edge_id int)", "create table sn (id int primary key, target_id int, source_id int)", ` create trigger rn_on_insert before insert on rn for each row begin if (select target_id from sn where id = NEW.upstream_edge_id) <> (select source_id from sn where id = NEW.downstream_edge_id) then set @myvar = concat('bro', 'ken'); SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @myvar; end if; end;`, }, Assertions: []ScriptTestAssertion{ { Query: "insert into rn values (1,1,1)", }, { Query: "select id from rn", Expected: []sql.Row{{1}}, }, }, }, { Name: "trigger with signal and user var", SetUpScript: []string{ "create table t1 (id int primary key)", "create table t2 (id int primary key)", ` create trigger trigger1 before insert on t1 for each row begin set @myvar = concat('bro', 'ken'); SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @myvar; end;`, }, Assertions: []ScriptTestAssertion{ { Query: "insert into t1 values (1)", ExpectedErrStr: "broken (errno 1644) (sqlstate 45000)", }, { Query: "select id from t1", Expected: []sql.Row{}, }, }, }, { Name: "trigger before insert, multiple triggers defined", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create table c (z int primary key)", "create trigger a1 before insert on a for each row insert into b values (new.x * 2)", "create trigger a2 before update on a for each row insert into b values (new.x * 3)", "create trigger a3 before delete on a for each row insert into b values (old.x * 5)", "create trigger b1 before insert on b for each row insert into c values (new.y * 7)", "create trigger b2 before update on b for each row insert into c values (new.y * 11)", "create trigger b3 before delete on b for each row insert into c values (old.y * 13)", "insert into a values (1), (2), (3)", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {2}, {3}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {2}, {4}, {6}, }, }, { Query: "select z from c order by 1", Expected: []sql.Row{ {14}, {28}, {42}, }, }, }, }, { Name: "trigger with signal", SetUpScript: []string{ "create table a (x int primary key)", "create table b (y int primary key)", "create table c (z int primary key)", "insert into c values (-1)", `create trigger trig_with_signal before insert on a for each row begin declare cond_name condition for sqlstate '45000'; if new.x = 5 then signal cond_name set message_text = 'trig err'; end if; insert into b values (new.x + 1); update c set z = new.x; end;`, }, Assertions: []ScriptTestAssertion{ { Query: "insert into a values (1), (3)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 2}}, }, }, { Query: "insert into a values (5)", ExpectedErrStr: "trig err (errno 1644) (sqlstate 45000)", }, { Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {3}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {2}, {4}, }, }, { Query: "select z from c order by 1", Expected: []sql.Row{ {3}, }, }, }, }, { Name: "show create triggers", SetUpScript: []string{ "create table a (x int primary key)", "create trigger a1 before insert on a for each row set new.x = new.x + 1", "create table b (y int primary key)", "create trigger b1 before insert on b for each row set new.y = new.y + 2", }, Assertions: []ScriptTestAssertion{ { Query: "show create trigger a1", Expected: []sql.Row{ { "a1", "", "create trigger a1 before insert on a for each row set new.x = new.x + 1", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), time.Unix(0, 0).UTC(), }, }, }, { Query: "show create trigger b1", Expected: []sql.Row{ { "b1", "", "create trigger b1 before insert on b for each row set new.y = new.y + 2", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), time.Unix(0, 0).UTC(), }, }, }, { Query: "show create trigger b2", ExpectedErr: sql.ErrTriggerDoesNotExist, }, }, }, { Name: "show triggers", SetUpScript: []string{ "create table abb (x int primary key)", "create table acc (y int primary key)", "create trigger t1 before insert on abb for each row set new.x = new.x + 1", "create trigger t2 before insert on abb for each row set new.x = new.x + 2", "create trigger t3 after insert on acc for each row insert into abb values (new.y)", "create trigger t4 before update on acc for each row set new.y = old.y + 2", }, Assertions: []ScriptTestAssertion{ { Query: "show triggers", Expected: []sql.Row{ { "t1", "INSERT", "abb", "set new.x = new.x + 1", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, { "t2", "INSERT", "abb", "set new.x = new.x + 2", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, { "t3", "INSERT", "acc", "insert into abb values (new.y)", "AFTER", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, { "t4", "UPDATE", "acc", "set new.y = old.y + 2", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, }, }, { Query: "show triggers from mydb", Expected: []sql.Row{ { "t1", "INSERT", "abb", "set new.x = new.x + 1", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, { "t2", "INSERT", "abb", "set new.x = new.x + 2", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, { "t3", "INSERT", "acc", "insert into abb values (new.y)", "AFTER", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, { "t4", "UPDATE", "acc", "set new.y = old.y + 2", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, }, }, { Query: "show triggers like '%cc'", Expected: []sql.Row{ { "t3", "INSERT", "acc", "insert into abb values (new.y)", "AFTER", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, { "t4", "UPDATE", "acc", "set new.y = old.y + 2", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, }, }, { Query: "show triggers where `event` = 'INSERT'", Expected: []sql.Row{ { "t1", "INSERT", "abb", "set new.x = new.x + 1", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, { "t2", "INSERT", "abb", "set new.x = new.x + 2", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, { "t3", "INSERT", "acc", "insert into abb values (new.y)", "AFTER", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, }, }, { Query: "show triggers where timing = 'AFTER'", Expected: []sql.Row{ { "t3", "INSERT", "acc", "insert into abb values (new.y)", "AFTER", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, }, }, { Query: "show triggers where timing = 'BEFORE' and `Table` like '%bb'", Expected: []sql.Row{ { "t1", "INSERT", "abb", "set new.x = new.x + 1", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, { "t2", "INSERT", "abb", "set new.x = new.x + 2", "BEFORE", time.Unix(0, 0).UTC(), "", "", sql.Collation_Default.CharacterSet().String(), sql.Collation_Default.String(), sql.Collation_Default.String(), }, }, }, }, }, { Name: "drop trigger", SetUpScript: []string{ "create table a (x int primary key)", "create trigger t1 before insert on a for each row set new.x = new.x * 1", "create trigger t2 before insert on a for each row follows t1 set new.x = new.x * 2", "create trigger t3 before insert on a for each row set new.x = new.x * 3", "create trigger t4 before insert on a for each row precedes t3 set new.x = new.x * 5", }, Assertions: []ScriptTestAssertion{ { Query: "drop trigger t1", ExpectedErr: sql.ErrTriggerCannotBeDropped, }, { Query: "drop trigger t3", ExpectedErr: sql.ErrTriggerCannotBeDropped, }, { Query: "drop trigger t4", Expected: []sql.Row{}, }, { Query: "drop trigger t3", Expected: []sql.Row{}, }, { Query: "drop trigger if exists t5", Expected: []sql.Row{}, }, { Query: "drop trigger t5", ExpectedErr: sql.ErrTriggerDoesNotExist, }, { Query: "select trigger_name from information_schema.triggers order by 1", Expected: []sql.Row{ {"t1"}, {"t2"}, }, }, { Query: "drop trigger if exists t2", Expected: []sql.Row{}, }, { Query: "select trigger_name from information_schema.triggers order by 1", Expected: []sql.Row{ {"t1"}, }, }, }, }, { Name: "drop table referenced in triggers", SetUpScript: []string{ "create table a (w int primary key)", "create table b (x int primary key)", "create table c (y int primary key)", "create table d (z int primary key)", "create trigger t1 before insert on a for each row set new.w = new.w", "create trigger t2 before insert on a for each row set new.w = new.w * 100", "create trigger t3 before insert on b for each row set new.x = new.x", "create trigger t4 before insert on b for each row set new.x = new.x * 100", "create trigger t5 before insert on c for each row set new.y = new.y", "create trigger t6 before insert on c for each row set new.y = new.y * 100", "create trigger t7 before insert on d for each row set new.z = new.z", "create trigger t8 before insert on d for each row set new.z = new.z * 100", }, Assertions: []ScriptTestAssertion{ { Query: "drop table a", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "select trigger_name from information_schema.triggers order by 1", Expected: []sql.Row{ {"t3"}, {"t4"}, {"t5"}, {"t6"}, {"t7"}, {"t8"}, }, }, { Query: "drop table if exists b, d, e", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "select trigger_name from information_schema.triggers order by 1", Expected: []sql.Row{ {"t5"}, {"t6"}, }, }, }, }, { Name: "drop table referenced in triggers with follows/precedes", SetUpScript: []string{ "create table a (x int primary key)", "create trigger t1 before insert on a for each row set new.x = new.x", "create trigger t2 before insert on a for each row follows t1 set new.x = new.x * 10", "create trigger t3 before insert on a for each row precedes t1 set new.x = new.x * 100", "create trigger t4 before insert on a for each row follows t3 set new.x = new.x * 1000", "create trigger t5 before insert on a for each row precedes t2 set new.x = new.x * 10000", "create trigger t6 before insert on a for each row follows t4 set new.x = new.x * 100000", "create trigger t7 before insert on a for each row precedes t1 set new.x = new.x * 1000000", "create trigger t8 before insert on a for each row follows t6 set new.x = new.x * 10000000", }, Assertions: []ScriptTestAssertion{ { Query: "drop table a", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show triggers", Expected: []sql.Row{}, }, }, }, { Name: "triggers with subquery expressions analyze", SetUpScript: []string{ "create table a (x int primary key)", "create trigger t1 before insert on a for each row begin if NEW.x in (select 2+2 from dual) then signal SQLSTATE '45000' SET MESSAGE_TEXT = 'String field contains invalid value, like empty string, ''none'', ''null'', ''n/a'', ''nan'' etc.'; end if; end;", }, Assertions: nil, }, { Name: "insert into common sequence table (https://github.com/dolthub/dolt/issues/2534)", SetUpScript: []string{ "create table mytable (id integer PRIMARY KEY DEFAULT 0, sometext text);", "create table sequence_table (max_id integer PRIMARY KEY);", "create trigger update_position_id before insert on mytable for each row begin set new.id = (select coalesce(max(max_id),1) from sequence_table); update sequence_table set max_id = max_id + 1; end;", "insert into sequence_table values (1);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into mytable () values ();", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "insert into mytable (sometext) values ('hello');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "insert into mytable values (10, 'goodbye');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from mytable order by id", Expected: []sql.Row{ {1, nil}, {2, "hello"}, {3, "goodbye"}, }, }, }, }, { Name: "insert into common sequence table workaround", SetUpScript: []string{ "create table mytable (id integer PRIMARY KEY DEFAULT 0, sometext text);", "create table sequence_table (max_id integer PRIMARY KEY);", `create trigger update_position_id before insert on mytable for each row begin if @max_id is null then set @max_id = (select coalesce(max(max_id),1) from sequence_table); end if; set new.id = @max_id; set @max_id = @max_id + 1; update sequence_table set max_id = @max_id; end;`, "insert into sequence_table values (1);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into mytable () values ();", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "insert into mytable (sometext) values ('hello');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "insert into mytable values (10, 'goodbye');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "insert into mytable () values (), ();", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "select * from mytable order by id", Expected: []sql.Row{ {1, nil}, {2, "hello"}, {3, "goodbye"}, {4, nil}, {5, nil}, }, }, }, }, { Name: "simple trigger with non-existent table in trigger body", SetUpScript: []string{ "create table a (x int primary key)", }, Assertions: []ScriptTestAssertion{ { Query: "create trigger insert_into_b after insert on a for each row insert into b values (new.x + 1)", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "insert into a values (1), (3), (5)", ExpectedErr: sql.ErrTableNotFound, }, { Query: "create table b (y int primary key)", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "insert into a values (1), (3), (5)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3}}, }, }, { Query: "select x from a order by 1", Expected: []sql.Row{ {1}, {3}, {5}, }, }, { Query: "select y from b order by 1", Expected: []sql.Row{ {2}, {4}, {6}, }, }, }, }, { Name: "insert, update, delete triggers with non-existent table in trigger body", SetUpScript: []string{ "CREATE TABLE film (film_id smallint unsigned NOT NULL AUTO_INCREMENT, title varchar(128) NOT NULL, description text, PRIMARY KEY (film_id))", "INSERT INTO `film` VALUES (1,'ACADEMY DINOSAUR','A Epic Drama in The Canadian Rockies'),(2,'ACE GOLDFINGER','An Astounding Epistle of a Database Administrator in Ancient China');", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TRIGGER ins_film AFTER INSERT ON film FOR EACH ROW BEGIN INSERT INTO film_text (film_id, title, description) VALUES (new.film_id, new.title, new.description); END;", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: `CREATE TRIGGER upd_film AFTER UPDATE ON film FOR EACH ROW BEGIN IF (old.title != new.title) OR (old.description != new.description) OR (old.film_id != new.film_id) THEN UPDATE film_text SET title=new.title, description=new.description, film_id=new.film_id WHERE film_id=old.film_id; END IF; END;`, Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CREATE TRIGGER del_film AFTER DELETE ON film FOR EACH ROW BEGIN DELETE FROM film_text WHERE film_id = old.film_id; END;", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "INSERT INTO `film` VALUES (3,'ADAPTATION HOLES','An Astounding Reflection in A Baloon Factory'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary in A Shark Tank')", ExpectedErr: sql.ErrTableNotFound, }, { Query: "UPDATE film SET title = 'THE ACADEMY DINOSAUR' WHERE title = 'ACADEMY DINOSAUR'", ExpectedErr: sql.ErrTableNotFound, }, { Query: "DELETE FROM film WHERE title = 'ACE GOLDFINGER'", ExpectedErr: sql.ErrTableNotFound, }, { Query: "CREATE TABLE film_text (film_id smallint NOT NULL, title varchar(255) NOT NULL, description text, PRIMARY KEY (film_id))", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SELECT COUNT(*) FROM film", Expected: []sql.Row{{2}}, }, { Query: "INSERT INTO `film` VALUES (3,'ADAPTATION HOLES','An Astounding Reflection in A Baloon Factory'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary in A Shark Tank')", Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 3}}}, }, { Query: "SELECT COUNT(*) FROM film", Expected: []sql.Row{{4}}, }, { Query: "SELECT COUNT(*) FROM film_text", Expected: []sql.Row{{2}}, }, { Query: "UPDATE film SET title = 'DIFFERENT MOVIE' WHERE title = 'ADAPTATION HOLES'", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 0, Info: plan.UpdateInfo{Matched: 1, Updated: 1, Warnings: 0}}}}, }, { Query: "SELECT COUNT(*) FROM film_text WHERE title = 'DIFFERENT MOVIE'", Expected: []sql.Row{{1}}, }, { Query: "DELETE FROM film WHERE title = 'DIFFERENT MOVIE'", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "SELECT COUNT(*) FROM film_text WHERE title = 'DIFFERENT MOVIE'", Expected: []sql.Row{{0}}, }, }, }, { Name: "non-existent procedure in trigger body", SetUpScript: []string{ "CREATE TABLE t0 (id INT PRIMARY KEY AUTO_INCREMENT, v1 INT, v2 TEXT);", "CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, v1 INT, v2 TEXT);", "INSERT INTO t0 VALUES (1, 2, 'abc'), (2, 3, 'def');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t0;", Expected: []sql.Row{{1, 2, "abc"}, {2, 3, "def"}}, }, { Query: `CREATE PROCEDURE add_entry(i INT, s TEXT) BEGIN IF i > 50 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'too big number'; END IF; INSERT INTO t0 (v1, v2) VALUES (i, s); END;`, Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CREATE TRIGGER trig AFTER INSERT ON t0 FOR EACH ROW BEGIN CALL back_up(NEW.v1, NEW.v2); END;", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "INSERT INTO t0 (v1, v2) VALUES (5, 'ggg');", ExpectedErr: sql.ErrStoredProcedureDoesNotExist, }, { Query: "CREATE PROCEDURE back_up(num INT, msg TEXT) INSERT INTO t1 (v1, v2) VALUES (num*2, msg);", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CALL add_entry(4, 'aaa');", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 1}}}, }, { Query: "SELECT * FROM t0;", Expected: []sql.Row{{1, 2, "abc"}, {2, 3, "def"}, {3, 4, "aaa"}}, }, { Query: "SELECT * FROM t1;", Expected: []sql.Row{{1, 8, "aaa"}}, }, { Query: "CALL add_entry(54, 'bbb');", ExpectedErrStr: "too big number (errno 1644) (sqlstate 45000)", }, }, }, }
var TypeWireTests = []TypeWireTest{ { Name: "TINYINT", SetUpScript: []string{ `CREATE TABLE test (pk TINYINT PRIMARY KEY, v1 TINYINT);`, `INSERT INTO test VALUES (-75, "-25"), (0, 0), (107.2, 0025), (107.5, 0025), (120, -120);`, `UPDATE test SET v1 = v1 - 1 WHERE pk < 0;`, `DELETE FROM test WHERE pk > "119";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"-75", "-26"}, {"0", "0"}, {"107", "25"}, {"108", "25"}}, {{"-26", "-75"}, {"0", "0"}, {"25", "107"}, {"25", "108"}}, {{"-52", "-74"}, {"0", "1"}, {"50", "108"}, {"50", "109"}}, }, }, { Name: "SMALLINT", SetUpScript: []string{ `CREATE TABLE test (pk SMALLINT PRIMARY KEY, v1 SMALLINT);`, `INSERT INTO test VALUES (-75.7, "-2531"), (-75, "-2531"), (0, 0), (2547.2, 03325), (2547.6, 03325), (9999, 9999);`, `UPDATE test SET v1 = v1 - 1 WHERE pk < 0;`, `DELETE FROM test WHERE pk >= "9999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"-76", "-2532"}, {"-75", "-2532"}, {"0", "0"}, {"2547", "3325"}, {"2548", "3325"}}, {{"-2532", "-76"}, {"-2532", "-75"}, {"0", "0"}, {"3325", "2547"}, {"3325", "2548"}}, {{"-5064", "-75"}, {"-5064", "-74"}, {"0", "1"}, {"6650", "2548"}, {"6650", "2549"}}, }, }, { Name: "MEDIUMINT", SetUpScript: []string{ `CREATE TABLE test (pk MEDIUMINT PRIMARY KEY, v1 MEDIUMINT);`, `INSERT INTO test VALUES (-75, "-2531"), (0, 0), (2547.2, 03325), (2547.7, 03325), (999999, 999999);`, `UPDATE test SET v1 = v1 - 1 WHERE pk < 0;`, `DELETE FROM test WHERE pk > "99999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"-75", "-2532"}, {"0", "0"}, {"2547", "3325"}, {"2548", "3325"}}, {{"-2532", "-75"}, {"0", "0"}, {"3325", "2547"}, {"3325", "2548"}}, {{"-5064", "-74"}, {"0", "1"}, {"6650", "2548"}, {"6650", "2549"}}, }, }, { Name: "INT", SetUpScript: []string{ `CREATE TABLE test (pk INT PRIMARY KEY, v1 INT);`, `INSERT INTO test VALUES (-75, "-2531"), (0, 0), (2547.2, 03325), (2547.8, 03325), (999999, 999999);`, `UPDATE test SET v1 = v1 - 1 WHERE pk < 0;`, `DELETE FROM test WHERE pk > "99999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"-75", "-2532"}, {"0", "0"}, {"2547", "3325"}, {"2548", "3325"}}, {{"-2532", "-75"}, {"0", "0"}, {"3325", "2547"}, {"3325", "2548"}}, {{"-5064", "-74"}, {"0", "1"}, {"6650", "2548"}, {"6650", "2549"}}, }, }, { Name: "BIGINT", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 BIGINT);`, `INSERT INTO test VALUES (-75, "-2531"), (0, 0), (2547.2, 03325), (2547.9, 03325), (999999, 999999);`, `UPDATE test SET v1 = v1 - 1 WHERE pk < 0;`, `DELETE FROM test WHERE pk > "99999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"-75", "-2532"}, {"0", "0"}, {"2547", "3325"}, {"2548", "3325"}}, {{"-2532", "-75"}, {"0", "0"}, {"3325", "2547"}, {"3325", "2548"}}, {{"-5064", "-74"}, {"0", "1"}, {"6650", "2548"}, {"6650", "2549"}}, }, }, { Name: "TINYINT UNSIGNED", SetUpScript: []string{ `CREATE TABLE test (pk TINYINT UNSIGNED PRIMARY KEY, v1 TINYINT UNSIGNED);`, `INSERT INTO test VALUES (0, 0), (25, "26"), (32.1, 0126), (42.8, 0126), (255, 255);`, `UPDATE test SET v1 = v1 - 1 WHERE pk > 0 AND pk < 30;`, `DELETE FROM test WHERE pk >= "255";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"0", "0"}, {"25", "25"}, {"32", "126"}, {"43", "126"}}, {{"0", "0"}, {"25", "25"}, {"126", "32"}, {"126", "43"}}, {{"0", "1"}, {"50", "26"}, {"252", "33"}, {"252", "44"}}, }, }, { Name: "SMALLINT UNSIGNED", SetUpScript: []string{ `CREATE TABLE test (pk SMALLINT UNSIGNED PRIMARY KEY, v1 SMALLINT UNSIGNED);`, `INSERT INTO test VALUES (0, 0), (25, "2531"), (2547.2, 03325), (2547.5, 03325), (9999, 9999);`, `UPDATE test SET v1 = v1 - 1 WHERE pk > 0 AND pk < 100;`, `DELETE FROM test WHERE pk >= "9999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"0", "0"}, {"25", "2530"}, {"2547", "3325"}, {"2548", "3325"}}, {{"0", "0"}, {"2530", "25"}, {"3325", "2547"}, {"3325", "2548"}}, {{"0", "1"}, {"5060", "26"}, {"6650", "2548"}, {"6650", "2549"}}, }, }, { Name: "MEDIUMINT UNSIGNED", SetUpScript: []string{ `CREATE TABLE test (pk MEDIUMINT UNSIGNED PRIMARY KEY, v1 MEDIUMINT UNSIGNED);`, `INSERT INTO test VALUES (75, "2531"), (0, 0), (2547.2, 03325), (2547.6, 03325), (999999, 999999);`, `UPDATE test SET v1 = v1 + 1 WHERE pk < 100;`, `DELETE FROM test WHERE pk > "99999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"0", "1"}, {"75", "2532"}, {"2547", "3325"}, {"2548", "3325"}}, {{"1", "0"}, {"2532", "75"}, {"3325", "2547"}, {"3325", "2548"}}, {{"2", "1"}, {"5064", "76"}, {"6650", "2548"}, {"6650", "2549"}}, }, }, { Name: "INT UNSIGNED", SetUpScript: []string{ `CREATE TABLE test (pk INT UNSIGNED PRIMARY KEY, v1 INT UNSIGNED);`, `INSERT INTO test VALUES (75, "2531"), (0, 0), (2547.2, 03325), (2547.7, 03325), (999999, 999999);`, `UPDATE test SET v1 = v1 + 1 WHERE pk < 100;`, `DELETE FROM test WHERE pk > "99999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"0", "1"}, {"75", "2532"}, {"2547", "3325"}, {"2548", "3325"}}, {{"1", "0"}, {"2532", "75"}, {"3325", "2547"}, {"3325", "2548"}}, {{"2", "1"}, {"5064", "76"}, {"6650", "2548"}, {"6650", "2549"}}, }, }, { Name: "BIGINT UNSIGNED", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 BIGINT UNSIGNED);`, `INSERT INTO test VALUES (75, "2531"), (0, 0), (2547.2, 03325), (2547.8, 03325), (999999, 999999);`, `UPDATE test SET v1 = v1 + 1 WHERE pk < 100;`, `DELETE FROM test WHERE pk > "99999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"0", "1"}, {"75", "2532"}, {"2547", "3325"}, {"2548", "3325"}}, {{"1", "0"}, {"2532", "75"}, {"3325", "2547"}, {"3325", "2548"}}, {{"2", "1"}, {"5064", "76"}, {"6650", "2548"}, {"6650", "2549"}}, }, }, { Name: "FLOAT", SetUpScript: []string{ `CREATE TABLE test (pk FLOAT PRIMARY KEY, v1 FLOAT);`, `INSERT INTO test VALUES (-75.11, "-2531"), (0, 0), ("2547.2", 03325), (999999, 999999);`, `UPDATE test SET v1 = v1 - 1 WHERE pk < 0;`, `DELETE FROM test WHERE pk > "99999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"-75.11", "-2532"}, {"0", "0"}, {"2547.2", "3325"}}, {{"-2532", "-75.11"}, {"0", "0"}, {"3325", "2547.2"}}, {{"-5064", "-74.11000061035156"}, {"0", "1"}, {"6650", "2548.199951171875"}}, }, }, { Name: "DOUBLE", SetUpScript: []string{ `CREATE TABLE test (pk DOUBLE PRIMARY KEY, v1 DOUBLE);`, `INSERT INTO test VALUES (-75.11, "-2531"), (0, 0), ("2547.2", 03325), (999999, 999999);`, `UPDATE test SET v1 = v1 - 1 WHERE pk < 0;`, `DELETE FROM test WHERE pk > "99999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"-75.11", "-2532"}, {"0", "0"}, {"2547.2", "3325"}}, {{"-2532", "-75.11"}, {"0", "0"}, {"3325", "2547.2"}}, {{"-5064", "-74.11"}, {"0", "1"}, {"6650", "2548.2"}}, }, }, { Name: "DECIMAL", SetUpScript: []string{ `CREATE TABLE test (pk DECIMAL(5,0) PRIMARY KEY, v1 DECIMAL(25,5));`, `INSERT INTO test VALUES (-75, "-2531.356"), (0, 0), (2547.2, 03325), (99999, 999999);`, `UPDATE test SET v1 = v1 - 1 WHERE pk < 0;`, `DELETE FROM test WHERE pk >= "99999";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1*2, pk+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"-75", "-2532.35600"}, {"0", "0.00000"}, {"2547", "3325.00000"}}, {{"-2532.35600", "-75"}, {"0.00000", "0"}, {"3325.00000", "2547"}}, {{"-5064.71200", "-74"}, {"0.00000", "1"}, {"6650.00000", "2548"}}, }, }, { Name: "BIT", SetUpScript: []string{ `CREATE TABLE test (pk BIT(55) PRIMARY KEY, v1 BIT(1), v2 BIT(24));`, `INSERT INTO test VALUES (75, 0, "21"), (0, 0, 0), (2547.2, 1, 03325), (999999, 1, 999999);`, `UPDATE test SET v2 = v2 - 1 WHERE pk > 0 AND pk < 100;`, `DELETE FROM test WHERE pk > 99999;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v2, v1, pk FROM test ORDER BY pk;`, `SELECT v1*1, pk/10, v2+1 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"\x00\x00\x00\x00\x00\x00\x00", "\x00", "\x00\x00\x00"}, {"\x00\x00\x00\x00\x00\x00K", "\x00", "\x0020"}, {"\x00\x00\x00\x00\x00\t\xf3", "�", "\x00\xfd"}}, {{"\x00\x00\x00", "\x00", "\x00\x00\x00\x00\x00\x00\x00"}, {"\x0020", "\x00", "\x00\x00\x00\x00\x00\x00K"}, {"\x00\xfd", "�", "\x00\x00\x00\x00\x00\t\xf3"}}, {{"0", "0.0000", "1"}, {"0", "7.5000", "12849"}, {"1", "254.7000", "3326"}}, }, }, { Name: "YEAR", SetUpScript: []string{ `CREATE TABLE test (pk YEAR PRIMARY KEY, v1 YEAR);`, `INSERT INTO test VALUES (1901, 1901), (1950, "1950"), (1979.2, 01986), (2122, 2122);`, `UPDATE test SET v1 = v1 + 1 WHERE pk < 1975;`, `DELETE FROM test WHERE pk > "2100";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT v1+3, pk+2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1901", "1902"}, {"1950", "1951"}, {"1979", "1986"}}, {{"1902", "1901"}, {"1951", "1950"}, {"1986", "1979"}}, {{"1905", "1903"}, {"1954", "1952"}, {"1989", "1981"}}, }, }, { Name: "TIMESTAMP", SetUpScript: []string{ `CREATE TABLE test (pk TIMESTAMP PRIMARY KEY, v1 TIMESTAMP);`, `INSERT INTO test VALUES ("1980-04-12 12:02:11", "1986-08-02 17:04:22"), ("1999-11-28 13:06:33", "2022-01-14 15:08:44"), ("2020-05-06 18:10:55", "1975-09-15 11:12:16");`, `UPDATE test SET v1 = "2000-01-01 00:00:00" WHERE pk < "1990-01-01 00:00:00";`, `DELETE FROM test WHERE pk > "2015-01-01 00:00:00";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v1 FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT DATE_ADD(TIMESTAMP('2022-10-26 13:14:15'), INTERVAL 1 DAY);`, `SELECT DATE_ADD('2022-10-26 13:14:15', INTERVAL 1 DAY);`, `SELECT DATE_ADD('2022-10-26', INTERVAL 1 SECOND);`, `SELECT DATE_ADD('2022-10-26', INTERVAL 1 MINUTE);`, `SELECT DATE_ADD('2022-10-26', INTERVAL 1 HOUR);`, }, Results: [][]sql.Row{ {{"1980-04-12 12:02:11", "2000-01-01 00:00:00"}, {"1999-11-28 13:06:33", "2022-01-14 15:08:44"}}, {{"1980-04-12 12:02:11", "2000-01-01 00:00:00"}, {"1999-11-28 13:06:33", "2022-01-14 15:08:44"}}, {{"2000-01-01 00:00:00", "1980-04-12 12:02:11"}, {"2022-01-14 15:08:44", "1999-11-28 13:06:33"}}, {{"2022-10-27 13:14:15"}}, {{"2022-10-27 13:14:15"}}, {{"2022-10-26 00:00:01"}}, {{"2022-10-26 00:01:00"}}, {{"2022-10-26 01:00:00"}}, }, }, { Name: "DATETIME", SetUpScript: []string{ `CREATE TABLE test (pk DATETIME PRIMARY KEY, v1 DATETIME);`, `INSERT INTO test VALUES ("1000-04-12 12:02:11", "1986-08-02 17:04:22"), ("1999-11-28 13:06:33", "2022-01-14 15:08:44"), ("5020-05-06 18:10:55", "1975-09-15 11:12:16");`, `UPDATE test SET v1 = "2000-01-01 00:00:00" WHERE pk < "1990-01-01 00:00:00";`, `DELETE FROM test WHERE pk > "5000-01-01 00:00:00";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v1 FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT DATE_ADD('2022-10-26 13:14:15', INTERVAL 1 DAY);`, `SELECT DATE_ADD('2022-10-26', INTERVAL 1 SECOND);`, `SELECT DATE_ADD('2022-10-26', INTERVAL 1 MINUTE);`, `SELECT DATE_ADD('2022-10-26', INTERVAL 1 HOUR);`, }, Results: [][]sql.Row{ {{"1000-04-12 12:02:11", "2000-01-01 00:00:00"}, {"1999-11-28 13:06:33", "2022-01-14 15:08:44"}}, {{"1000-04-12 12:02:11", "2000-01-01 00:00:00"}, {"1999-11-28 13:06:33", "2022-01-14 15:08:44"}}, {{"2000-01-01 00:00:00", "1000-04-12 12:02:11"}, {"2022-01-14 15:08:44", "1999-11-28 13:06:33"}}, {{"2022-10-27 13:14:15"}}, {{"2022-10-26 00:00:01"}}, {{"2022-10-26 00:01:00"}}, {{"2022-10-26 01:00:00"}}, }, }, { Name: "DATE", SetUpScript: []string{ `CREATE TABLE test (pk DATE PRIMARY KEY, v1 DATE);`, `INSERT INTO test VALUES ("1000-04-12", "1986-08-02"), ("1999-11-28", "2022-01-14"), ("5020-05-06", "1975-09-15");`, `UPDATE test SET v1 = "2000-01-01" WHERE pk < "1990-01-01";`, `DELETE FROM test WHERE pk > "5000-01-01";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v1 FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT DATE_ADD(DATE('2022-10-26'), INTERVAL 1 DAY);`, `SELECT DATE_ADD(DATE('2022-10-26'), INTERVAL 1 WEEK);`, `SELECT DATE_ADD(DATE('2022-10-26'), INTERVAL 1 MONTH);`, `SELECT DATE_ADD(DATE('2022-10-26'), INTERVAL 1 QUARTER);`, `SELECT DATE_ADD(DATE('2022-10-26'), INTERVAL 1 YEAR);`, }, Results: [][]sql.Row{ {{"1000-04-12", "2000-01-01"}, {"1999-11-28", "2022-01-14"}}, {{"1000-04-12", "2000-01-01"}, {"1999-11-28", "2022-01-14"}}, {{"2000-01-01", "1000-04-12"}, {"2022-01-14", "1999-11-28"}}, {{"2022-10-27"}}, {{"2022-11-02"}}, {{"2022-11-26"}}, {{"2023-01-26"}}, {{"2023-10-26"}}, }, }, { Name: "TIME", SetUpScript: []string{ `CREATE TABLE test (pk TIME PRIMARY KEY, v1 TIME);`, `INSERT INTO test VALUES ("-800:00:00", "-20:21:22"), ("00:00:00", "00:00:00"), ("10:26:57", "30:53:14"), ("700:23:51", "300:25:52");`, `UPDATE test SET v1 = "-120:12:20" WHERE pk < "00:00:00";`, `DELETE FROM test WHERE pk > "600:00:00";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v1 FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"-800:00:00", "-120:12:20"}, {"00:00:00", "00:00:00"}, {"10:26:57", "30:53:14"}}, {{"-800:00:00", "-120:12:20"}, {"00:00:00", "00:00:00"}, {"10:26:57", "30:53:14"}}, {{"-120:12:20", "-800:00:00"}, {"00:00:00", "00:00:00"}, {"30:53:14", "10:26:57"}}, }, }, { Name: "CHAR", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 CHAR(5), v2 CHAR(10));`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = "a-c" WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "a-c", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "a-c"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"a-cr", "2", "123"}, {"__2r", "3", "456"}}, }, }, { Name: "VARCHAR", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 VARCHAR(5), v2 VARCHAR(10));`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = CONCAT(v1, "x") WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, `SELECT DATE_ADD('2022-10-26 13:14:15', INTERVAL 1 DAY);`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "c-ax", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "c-ax"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"c-axr", "2", "123"}, {"__2r", "3", "456"}}, {{"2022-10-27 13:14:15"}}, }, }, { Name: "BINARY", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 BINARY(5), v2 BINARY(10));`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = "a-c" WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc\x00\x00", "def\x00\x00\x00\x00\x00\x00\x00"}, {"2", "a-c\x00\x00", "123\x00\x00\x00\x00\x00\x00\x00"}, {"3", "__2\x00\x00", "456\x00\x00\x00\x00\x00\x00\x00"}}, {{"1", "def\x00\x00\x00\x00\x00\x00\x00", "abc\x00\x00"}, {"2", "123\x00\x00\x00\x00\x00\x00\x00", "a-c\x00\x00"}, {"3", "456\x00\x00\x00\x00\x00\x00\x00", "__2\x00\x00"}}, {{"abc\x00\x00r", "1", "def\x00\x00\x00\x00\x00\x00\x00"}, {"a-c\x00\x00r", "2", "123\x00\x00\x00\x00\x00\x00\x00"}, {"__2\x00\x00r", "3", "456\x00\x00\x00\x00\x00\x00\x00"}}, }, }, { Name: "VARBINARY", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 VARBINARY(5), v2 VARBINARY(10));`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = CONCAT(v1, "x") WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "c-ax", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "c-ax"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"c-axr", "2", "123"}, {"__2r", "3", "456"}}, }, }, { Name: "TINYTEXT", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 TINYTEXT, v2 TINYTEXT);`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = CONCAT(v1, "x") WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "c-ax", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "c-ax"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"c-axr", "2", "123"}, {"__2r", "3", "456"}}, }, }, { Name: "TEXT", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 TEXT, v2 TEXT);`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = CONCAT(v1, "x") WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "c-ax", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "c-ax"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"c-axr", "2", "123"}, {"__2r", "3", "456"}}, }, }, { Name: "MEDIUMTEXT", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 MEDIUMTEXT, v2 MEDIUMTEXT);`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = CONCAT(v1, "x") WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "c-ax", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "c-ax"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"c-axr", "2", "123"}, {"__2r", "3", "456"}}, }, }, { Name: "LONGTEXT", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 LONGTEXT, v2 LONGTEXT);`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = CONCAT(v1, "x") WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "c-ax", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "c-ax"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"c-axr", "2", "123"}, {"__2r", "3", "456"}}, }, }, { Name: "TINYBLOB", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 TINYBLOB, v2 TINYBLOB);`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = CONCAT(v1, "x") WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "c-ax", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "c-ax"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"c-axr", "2", "123"}, {"__2r", "3", "456"}}, }, }, { Name: "BLOB", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 BLOB, v2 BLOB);`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = CONCAT(v1, "x") WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "c-ax", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "c-ax"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"c-axr", "2", "123"}, {"__2r", "3", "456"}}, }, }, { Name: "MEDIUMBLOB", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 MEDIUMBLOB, v2 MEDIUMBLOB);`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = CONCAT(v1, "x") WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "c-ax", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "c-ax"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"c-axr", "2", "123"}, {"__2r", "3", "456"}}, }, }, { Name: "LONGBLOB", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 LONGBLOB, v2 LONGBLOB);`, `INSERT INTO test VALUES (1, "abc", "def"), (2, "c-a", "123"), (3, "__2", 456), (4, "?hi?", "\\n");`, `UPDATE test SET v1 = CONCAT(v1, "x") WHERE pk = 2;`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v2, v1 FROM test ORDER BY pk;`, `SELECT CONCAT(v1, "r"), pk, v2 FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "abc", "def"}, {"2", "c-ax", "123"}, {"3", "__2", "456"}}, {{"1", "def", "abc"}, {"2", "123", "c-ax"}, {"3", "456", "__2"}}, {{"abcr", "1", "def"}, {"c-axr", "2", "123"}, {"__2r", "3", "456"}}, }, }, { Name: "ENUM", SetUpScript: []string{ `CREATE TABLE test (pk ENUM("a","b","c") PRIMARY KEY, v1 ENUM("x","y","z"));`, `INSERT INTO test VALUES (1, 1), ("b", "y"), (3, "z");`, `UPDATE test SET v1 = "x" WHERE pk = 2;`, `DELETE FROM test WHERE pk > 2;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v1 FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"a", "x"}, {"b", "x"}}, {{"a", "x"}, {"b", "x"}}, {{"x", "a"}, {"x", "b"}}, }, }, { Name: "SET", SetUpScript: []string{ `CREATE TABLE test (pk SET("a","b","c") PRIMARY KEY, v1 SET("w","x","y","z"));`, `INSERT INTO test VALUES (0, 1), ("b", "y"), ("b,c", "z,z"), ("a,c,b", 10);`, `UPDATE test SET v1 = "y,x,w" WHERE pk >= 4`, `DELETE FROM test WHERE pk > "b,c";`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v1 FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ {{"", "w"}, {"b", "y"}, {"b,c", "w,x,y"}}, {{"", "w"}, {"b", "y"}, {"b,c", "w,x,y"}}, {{"w", ""}, {"y", "b"}, {"w,x,y", "b,c"}}, }, }, { Name: "GEOMETRY", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 GEOMETRY);`, `INSERT INTO test VALUES (1, POINT(1, 2)), (2, LINESTRING(POINT(1, 2), POINT(3, 4))), (3, ST_GeomFromText('POLYGON((0 0,0 3,3 0,0 0),(1 1,1 2,2 1,1 1))'));`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v1 FROM test ORDER BY pk;`, `SELECT pk, ST_ASWKT(v1) FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ { {"1", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40})}, {"2", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40})}, {"3", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F})}, }, { {"1", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40})}, {"2", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40})}, {"3", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F})}, }, { {"1", "POINT(1 2)"}, {"2", "LINESTRING(1 2,3 4)"}, {"3", "POLYGON((0 0,0 3,3 0,0 0),(1 1,1 2,2 1,1 1))"}, }, }, }, { Name: "POINT", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 POINT);`, `INSERT INTO test VALUES (1, POINT(1, 2)), (2, POINT(3.4, 5.6)), (3, POINT(10, -20)), (4, POINT(1000, -1000));`, `DELETE FROM test WHERE pk = 4;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v1 FROM test ORDER BY pk;`, `SELECT pk, ST_ASWKT(v1) FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ { {"1", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40})}, {"2", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x0B, 0x40, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x16, 0x40})}, {"3", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0xC0})}, }, { {"1", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40})}, {"2", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x0B, 0x40, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x16, 0x40})}, {"3", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0xC0})}, }, { {"1", "POINT(1 2)"}, {"2", "POINT(3.4 5.6)"}, {"3", "POINT(10 -20)"}, }, }, }, { Name: "LINESTRING", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 LINESTRING);`, `INSERT INTO test VALUES (1, LINESTRING(POINT(1, 2), POINT(3, 4))), (2, LINESTRING(POINT(5, 6), POINT(7, 8)));`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v1 FROM test ORDER BY pk;`, `SELECT pk, ST_ASWKT(v1) FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ { {"1", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40})}, {"2", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40})}, }, { {"1", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40})}, {"2", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40})}, }, { {"1", "LINESTRING(1 2,3 4)"}, {"2", "LINESTRING(5 6,7 8)"}, }, }, }, { Name: "POLYGON", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 POLYGON);`, `INSERT INTO test VALUES (1, ST_GeomFromText('POLYGON((0 0,0 3,3 0,0 0),(1 1,1 2,2 1,1 1))'));`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT pk, v1 FROM test ORDER BY pk;`, `SELECT pk, ST_ASWKT(v1) FROM test ORDER BY pk;`, }, Results: [][]sql.Row{ { {"1", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F})}, }, { {"1", string([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F})}, }, { {"1", "POLYGON((0 0,0 3,3 0,0 0),(1 1,1 2,2 1,1 1))"}, }, }, }, { Name: "JSON", SetUpScript: []string{ `CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 JSON);`, `INSERT INTO test VALUES (1, '{"key1": {"key": "value"}}'), (2, '{"key1": "value1", "key2": "value2"}'), (3, '{"key1": {"key": [2,3]}}');`, `UPDATE test SET v1 = '["a", 1]' WHERE pk = 1;`, `DELETE FROM test WHERE pk = 3;`, }, Queries: []string{ `SELECT * FROM test ORDER BY pk;`, `SELECT v1, pk FROM test ORDER BY pk;`, `SELECT pk, JSON_ARRAYAGG(v1) FROM (SELECT * FROM test ORDER BY pk) as sub GROUP BY v1 ORDER BY pk;`, }, Results: [][]sql.Row{ {{"1", "[\"a\",1]"}, {"2", "{\"key1\":\"value1\",\"key2\":\"value2\"}"}}, {{"[\"a\",1]", "1"}, {"{\"key1\":\"value1\",\"key2\":\"value2\"}", "2"}}, {{"1", "[[\"a\",1]]"}, {"2", "[{\"key1\":\"value1\",\"key2\":\"value2\"}]"}}, }, }, }
TypeWireTests are used to ensure that types are properly represented over the wire (vs being directly returned from the engine).
var UpdateErrorScripts = []ScriptTest{ { Name: "try updating string that is too long", SetUpScript: []string{ "create table bad (s varchar(9))", "insert into bad values ('good')", }, Query: "update bad set s = '1234567890'", ExpectedErr: types.ErrLengthBeyondLimit, }, }
var UpdateErrorTests = []QueryErrorTest{ { Query: `UPDATE keyless INNER JOIN one_pk on keyless.c0 = one_pk.pk SET keyless.c0 = keyless.c0 + 1`, ExpectedErr: sql.ErrUnsupportedFeature, }, { Query: `UPDATE people set height_inches = null where height_inches < 100`, ExpectedErr: sql.ErrInsertIntoNonNullableProvidedNull, }, { Query: `UPDATE people SET height_inches = IF(SUM(height_inches) % 2 = 0, 42, height_inches)`, ExpectedErr: sql.ErrAggregationUnsupported, }, { Query: `UPDATE people SET height_inches = IF(SUM(*) % 2 = 0, 42, height_inches)`, ExpectedErr: sql.ErrStarUnsupported, }, { Query: `UPDATE people SET height_inches = IF(ROW_NUMBER() OVER() % 2 = 0, 42, height_inches)`, ExpectedErr: sql.ErrWindowUnsupported, }, }
var UpdateIgnoreScripts = []ScriptTest{ { Name: "UPDATE IGNORE with primary keys and indexes", SetUpScript: []string{ "CREATE TABLE pkTable(pk int, val int, primary key(pk, val))", "CREATE TABLE idxTable(pk int primary key, val int UNIQUE)", "INSERT INTO pkTable VALUES (1, 1), (2, 2), (3, 3)", "INSERT INTO idxTable VALUES (1, 1), (2, 2), (3, 3)", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE IGNORE pkTable set pk = pk + 1, val = val + 1", Expected: []sql.Row{{newUpdateResult(3, 1)}}, ExpectedWarning: mysql.ERDupEntry, }, { Query: "SELECT * FROM pkTable order by pk", Expected: []sql.Row{{1, 1}, {2, 2}, {4, 4}}, }, { Query: "UPDATE IGNORE idxTable set val = val + 1", Expected: []sql.Row{{newUpdateResult(3, 1)}}, ExpectedWarning: mysql.ERDupEntry, }, { Query: "SELECT * FROM idxTable order by pk", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 4}}, }, { Query: "UPDATE IGNORE pkTable set val = val + 1 where pk = 2", Expected: []sql.Row{{newUpdateResult(1, 1)}}, }, { Query: "SELECT * FROM pkTable order by pk", Expected: []sql.Row{{1, 1}, {2, 3}, {4, 4}}, }, { Query: "UPDATE IGNORE pkTable SET pk = NULL", Expected: []sql.Row{{newUpdateResult(3, 3)}}, ExpectedWarning: mysql.ERBadNullError, }, { Query: "SELECT * FROM pkTable order by pk", Expected: []sql.Row{{0, 1}, {0, 3}, {0, 4}}, }, { Query: "UPDATE IGNORE pkTable SET val = NULL", Expected: []sql.Row{{newUpdateResult(3, 1)}}, }, { Query: "SELECT * FROM pkTable order by pk", Expected: []sql.Row{{0, 0}, {0, 3}, {0, 4}}, }, { Query: "UPDATE IGNORE idxTable set pk = pk + 1, val = val + 1", Expected: []sql.Row{{newUpdateResult(3, 1)}}, ExpectedWarning: mysql.ERDupEntry, }, { Query: "SELECT * FROM idxTable order by pk", Expected: []sql.Row{{1, 1}, {2, 2}, {4, 5}}, }, }, }, { Name: "UPDATE IGNORE with type conversions", SetUpScript: []string{ "CREATE TABLE t1 (pk int primary key, v1 int, v2 int)", "INSERT INTO t1 VALUES (1, 1, 1)", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE IGNORE t1 SET v1 = 'dsddads'", Expected: []sql.Row{{newUpdateResult(1, 1)}}, ExpectedWarning: mysql.ERTruncatedWrongValueForField, }, { Query: "SELECT * FROM t1", Expected: []sql.Row{{1, 0, 1}}, }, { Query: "UPDATE IGNORE t1 SET pk = 'dasda', v2 = 'dsddads'", Expected: []sql.Row{{newUpdateResult(1, 1)}}, ExpectedWarning: mysql.ERTruncatedWrongValueForField, }, { Query: "SELECT * FROM t1", Expected: []sql.Row{{0, 0, 0}}, }, }, }, { Name: "UPDATE IGNORE with foreign keys", SetUpScript: []string{ "CREATE TABLE colors ( id INT NOT NULL, color VARCHAR(32) NOT NULL, PRIMARY KEY (id), INDEX color_index(color));", "CREATE TABLE objects (id INT NOT NULL, name VARCHAR(64) NOT NULL,color VARCHAR(32), PRIMARY KEY(id),FOREIGN KEY (color) REFERENCES colors(color))", "INSERT INTO colors (id,color) VALUES (1,'red'),(2,'green'),(3,'blue'),(4,'purple')", "INSERT INTO objects (id,name,color) VALUES (1,'truck','red'),(2,'ball','green'),(3,'shoe','blue')", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE IGNORE objects SET color = 'orange' where id = 2", Expected: []sql.Row{{newUpdateResult(1, 0)}}, ExpectedWarning: mysql.ErNoReferencedRow2, }, { Query: "SELECT * FROM objects ORDER BY id", Expected: []sql.Row{{1, "truck", "red"}, {2, "ball", "green"}, {3, "shoe", "blue"}}, }, }, }, { Name: "UPDATE IGNORE with check constraints", SetUpScript: []string{ "CREATE TABLE checksTable(pk int primary key)", "ALTER TABLE checksTable ADD CONSTRAINT mycx CHECK (pk < 5)", "INSERT INTO checksTable VALUES (1),(2),(3),(4)", }, Assertions: []ScriptTestAssertion{ { Query: "UPDATE IGNORE checksTable SET pk = pk + 1 where pk = 4", Expected: []sql.Row{{newUpdateResult(1, 0)}}, ExpectedWarning: mysql.ERUnknownError, }, { Query: "SELECT * from checksTable ORDER BY pk", Expected: []sql.Row{{1}, {2}, {3}, {4}}, }, }, }, }
var UpdateIgnoreTests = []WriteQueryTest{ { WriteQuery: "UPDATE IGNORE mytable SET i = 2 where i = 1", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 0)}}, SelectQuery: "SELECT * FROM mytable order by i", ExpectedSelect: []sql.Row{ sql.NewRow(1, "first row"), sql.NewRow(2, "second row"), sql.NewRow(3, "third row"), }, }, { WriteQuery: "UPDATE IGNORE mytable SET i = i+1 where i = 1", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 0)}}, SelectQuery: "SELECT * FROM mytable order by i", ExpectedSelect: []sql.Row{ sql.NewRow(1, "first row"), sql.NewRow(2, "second row"), sql.NewRow(3, "third row"), }, }, }
var UpdateTests = []WriteQueryTest{ { WriteQuery: "UPDATE mytable SET s = 'updated';", ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "updated"}, {int64(2), "updated"}, {int64(3), "updated"}}, }, { WriteQuery: "UPDATE mytable SET S = 'updated';", ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "updated"}, {int64(2), "updated"}, {int64(3), "updated"}}, }, { WriteQuery: "UPDATE mytable SET s = 'updated' WHERE i > 9999;", ExpectedWriteResult: []sql.Row{{newUpdateResult(0, 0)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}}, }, { WriteQuery: "UPDATE mytable SET s = 'updated' WHERE i = 1;", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "updated"}, {int64(2), "second row"}, {int64(3), "third row"}}, }, { WriteQuery: "UPDATE mytable SET s = 'updated' WHERE i <> 9999;", ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "updated"}, {int64(2), "updated"}, {int64(3), "updated"}}, }, { WriteQuery: "UPDATE floattable SET f32 = f32 + f32, f64 = f32 * f64 WHERE i = 2;", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM floattable WHERE i = 2;", ExpectedSelect: []sql.Row{{int64(2), float32(3.0), float64(4.5)}}, }, { WriteQuery: "UPDATE floattable SET f32 = 5, f32 = 4 WHERE i = 1;", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT f32 FROM floattable WHERE i = 1;", ExpectedSelect: []sql.Row{{float32(4.0)}}, }, { WriteQuery: "UPDATE mytable SET s = 'first row' WHERE i = 1;", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 0)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "third row"}}, }, { WriteQuery: "UPDATE niltable SET b = NULL WHERE f IS NULL;", ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 2)}}, SelectQuery: "SELECT i,b FROM niltable WHERE f IS NULL;", ExpectedSelect: []sql.Row{{int64(1), nil}, {int64(2), nil}, {int64(3), nil}}, }, { WriteQuery: "UPDATE mytable SET s = 'updated' ORDER BY i ASC LIMIT 2;", ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "updated"}, {int64(2), "updated"}, {int64(3), "third row"}}, }, { WriteQuery: "UPDATE mytable SET s = 'updated' ORDER BY i DESC LIMIT 2;", ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(2), "updated"}, {int64(3), "updated"}}, }, { WriteQuery: "UPDATE mytable SET s = 'updated' ORDER BY i LIMIT 1 OFFSET 1;", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(2), "updated"}, {int64(3), "third row"}}, }, { WriteQuery: "UPDATE mytable SET s = 'updated';", ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "updated"}, {int64(2), "updated"}, {int64(3), "updated"}}, }, { WriteQuery: "UPDATE mytable SET s = _binary 'updated' WHERE i = 3;", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM mytable;", ExpectedSelect: []sql.Row{{int64(1), "first row"}, {int64(2), "second row"}, {int64(3), "updated"}}, }, { WriteQuery: "UPDATE typestable SET ti = '2020-03-06 00:00:00';", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM typestable;", ExpectedSelect: []sql.Row{{ int64(1), int8(2), int16(3), int32(4), int64(5), uint8(6), uint16(7), uint32(8), uint64(9), float32(10), float64(11), sql.MustConvert(types.Timestamp.Convert("2020-03-06 00:00:00")), sql.MustConvert(types.Date.Convert("2019-12-31")), "fourteen", 0, nil, nil, uint64(1), uint64(0)}}, }, { WriteQuery: "UPDATE typestable SET ti = '2020-03-06 00:00:00', da = '2020-03-06';", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM typestable;", ExpectedSelect: []sql.Row{{ int64(1), int8(2), int16(3), int32(4), int64(5), uint8(6), uint16(7), uint32(8), uint64(9), float32(10), float64(11), sql.MustConvert(types.Timestamp.Convert("2020-03-06 00:00:00")), sql.MustConvert(types.Date.Convert("2020-03-06")), "fourteen", 0, nil, nil, uint64(1), uint64(0)}}, }, { WriteQuery: "UPDATE typestable SET da = '0000-00-00', ti = '0000-00-00 00:00:00';", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM typestable;", ExpectedSelect: []sql.Row{{ int64(1), int8(2), int16(3), int32(4), int64(5), uint8(6), uint16(7), uint32(8), uint64(9), float32(10), float64(11), types.Timestamp.Zero(), types.Date.Zero(), "fourteen", 0, nil, nil, uint64(1), uint64(0)}}, }, { WriteQuery: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 SET two_pk.c1 = two_pk.c1 + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(4, 4)}}, SelectQuery: "SELECT * FROM two_pk;", ExpectedSelect: []sql.Row{ sql.NewRow(0, 0, 1, 1, 2, 3, 4), sql.NewRow(0, 1, 11, 11, 12, 13, 14), sql.NewRow(1, 0, 21, 21, 22, 23, 24), sql.NewRow(1, 1, 31, 31, 32, 33, 34), }, }, { WriteQuery: "UPDATE mytable INNER JOIN one_pk ON mytable.i = one_pk.c5 SET mytable.i = mytable.i * 10", ExpectedWriteResult: []sql.Row{{newUpdateResult(0, 0)}}, SelectQuery: "SELECT * FROM mytable", ExpectedSelect: []sql.Row{ sql.NewRow(int64(1), "first row"), sql.NewRow(int64(2), "second row"), sql.NewRow(int64(3), "third row"), }, }, { WriteQuery: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 SET two_pk.c1 = two_pk.c1 + 1 WHERE one_pk.c5 < 10`, ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, SelectQuery: "SELECT * FROM two_pk;", ExpectedSelect: []sql.Row{ sql.NewRow(0, 0, 1, 1, 2, 3, 4), sql.NewRow(0, 1, 11, 11, 12, 13, 14), sql.NewRow(1, 0, 20, 21, 22, 23, 24), sql.NewRow(1, 1, 30, 31, 32, 33, 34), }, }, { WriteQuery: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 INNER JOIN othertable on othertable.i2 = two_pk.pk2 SET one_pk.c1 = one_pk.c1 + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, SelectQuery: "SELECT * FROM one_pk;", ExpectedSelect: []sql.Row{ sql.NewRow(0, 1, 1, 2, 3, 4), sql.NewRow(1, 11, 11, 12, 13, 14), sql.NewRow(2, 20, 21, 22, 23, 24), sql.NewRow(3, 30, 31, 32, 33, 34), }, }, { WriteQuery: `UPDATE one_pk INNER JOIN (SELECT * FROM two_pk order by pk1, pk2) as t2 on one_pk.pk = t2.pk1 SET one_pk.c1 = t2.c1 + 1 where one_pk.pk < 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM one_pk where pk < 1", ExpectedSelect: []sql.Row{ sql.NewRow(0, 1, 1, 2, 3, 4), }, }, { WriteQuery: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 SET one_pk.c1 = one_pk.c1 + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, SelectQuery: "SELECT * FROM one_pk;", ExpectedSelect: []sql.Row{ sql.NewRow(0, 1, 1, 2, 3, 4), sql.NewRow(1, 11, 11, 12, 13, 14), sql.NewRow(2, 20, 21, 22, 23, 24), sql.NewRow(3, 30, 31, 32, 33, 34), }, }, { WriteQuery: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 SET one_pk.c1 = one_pk.c1 + 1, one_pk.c2 = one_pk.c2 + 1 ORDER BY one_pk.pk`, ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, SelectQuery: "SELECT * FROM one_pk;", ExpectedSelect: []sql.Row{ sql.NewRow(0, 1, 2, 2, 3, 4), sql.NewRow(1, 11, 12, 12, 13, 14), sql.NewRow(2, 20, 21, 22, 23, 24), sql.NewRow(3, 30, 31, 32, 33, 34), }, }, { WriteQuery: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 SET one_pk.c1 = one_pk.c1 + 1, two_pk.c1 = two_pk.c2 + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(8, 6)}}, SelectQuery: "SELECT * FROM two_pk;", ExpectedSelect: []sql.Row{ sql.NewRow(0, 0, 2, 1, 2, 3, 4), sql.NewRow(0, 1, 12, 11, 12, 13, 14), sql.NewRow(1, 0, 22, 21, 22, 23, 24), sql.NewRow(1, 1, 32, 31, 32, 33, 34), }, }, { WriteQuery: `update mytable h join mytable on h.i = mytable.i and h.s <> mytable.s set h.i = mytable.i+1;`, ExpectedWriteResult: []sql.Row{{newUpdateResult(0, 0)}}, SelectQuery: "select * from mytable", ExpectedSelect: []sql.Row{{1, "first row"}, {2, "second row"}, {3, "third row"}}, }, { WriteQuery: `UPDATE othertable CROSS JOIN tabletest set othertable.i2 = othertable.i2 * 10`, ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, SelectQuery: "SELECT * FROM othertable order by i2", ExpectedSelect: []sql.Row{ sql.NewRow("third", 10), sql.NewRow("second", 20), sql.NewRow("first", 30), }, }, { WriteQuery: `UPDATE tabletest cross join tabletest as t2 set tabletest.i = tabletest.i * 10`, ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, SelectQuery: "SELECT * FROM tabletest order by i", ExpectedSelect: []sql.Row{ sql.NewRow(10, "first row"), sql.NewRow(20, "second row"), sql.NewRow(30, "third row"), }, }, { WriteQuery: `UPDATE othertable cross join tabletest set tabletest.i = tabletest.i * 10`, ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, SelectQuery: "SELECT * FROM tabletest order by i", ExpectedSelect: []sql.Row{ sql.NewRow(10, "first row"), sql.NewRow(20, "second row"), sql.NewRow(30, "third row"), }, }, { WriteQuery: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 INNER JOIN two_pk a1 on one_pk.pk = two_pk.pk2 SET two_pk.c1 = two_pk.c1 + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, SelectQuery: "SELECT * FROM two_pk order by pk1 ASC, pk2 ASC;", ExpectedSelect: []sql.Row{ sql.NewRow(0, 0, 1, 1, 2, 3, 4), sql.NewRow(0, 1, 10, 11, 12, 13, 14), sql.NewRow(1, 0, 20, 21, 22, 23, 24), sql.NewRow(1, 1, 31, 31, 32, 33, 34), }, }, { WriteQuery: `UPDATE othertable INNER JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET othertable.s2 = 'fourth'`, ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM othertable order by i2", ExpectedSelect: []sql.Row{ sql.NewRow("third", 1), sql.NewRow("second", 2), sql.NewRow("fourth", 3), }, }, { WriteQuery: `UPDATE tabletest cross join tabletest as t2 set t2.i = t2.i * 10`, ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, SelectQuery: "SELECT * FROM tabletest order by i", ExpectedSelect: []sql.Row{ sql.NewRow(10, "first row"), sql.NewRow(20, "second row"), sql.NewRow(30, "third row"), }, }, { WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET othertable.s2 = 'fourth'`, ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, SelectQuery: "SELECT * FROM othertable order by i2", ExpectedSelect: []sql.Row{ sql.NewRow("fourth", 1), sql.NewRow("fourth", 2), sql.NewRow("fourth", 3), }, }, { WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET tabletest.s = 'fourth row', tabletest.i = tabletest.i + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM tabletest order by i", ExpectedSelect: []sql.Row{ sql.NewRow(1, "first row"), sql.NewRow(2, "second row"), sql.NewRow(4, "fourth row"), }, }, { WriteQuery: `UPDATE othertable LEFT JOIN tabletest t3 on othertable.i2=3 and t3.i=3 SET t3.s = 'fourth row', t3.i = t3.i + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM tabletest order by i", ExpectedSelect: []sql.Row{ sql.NewRow(1, "first row"), sql.NewRow(2, "second row"), sql.NewRow(4, "fourth row"), }, }, { WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=3 and tabletest.i=3 LEFT JOIN one_pk on othertable.i2 = one_pk.pk SET one_pk.c1 = one_pk.c1 + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, SelectQuery: "SELECT * FROM one_pk order by pk", ExpectedSelect: []sql.Row{ sql.NewRow(0, 0, 1, 2, 3, 4), sql.NewRow(1, 11, 11, 12, 13, 14), sql.NewRow(2, 21, 21, 22, 23, 24), sql.NewRow(3, 31, 31, 32, 33, 34), }, }, { WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=3 and tabletest.i=3 LEFT JOIN one_pk on othertable.i2 = one_pk.pk SET one_pk.c1 = one_pk.c1 + 1 where one_pk.pk > 4`, ExpectedWriteResult: []sql.Row{{newUpdateResult(0, 0)}}, SelectQuery: "SELECT * FROM one_pk order by pk", ExpectedSelect: []sql.Row{ sql.NewRow(0, 0, 1, 2, 3, 4), sql.NewRow(1, 10, 11, 12, 13, 14), sql.NewRow(2, 20, 21, 22, 23, 24), sql.NewRow(3, 30, 31, 32, 33, 34), }, }, { WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=3 and tabletest.i=3 LEFT JOIN one_pk on othertable.i2 = 1 and one_pk.pk = 1 SET one_pk.c1 = one_pk.c1 + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM one_pk order by pk", ExpectedSelect: []sql.Row{ sql.NewRow(0, 0, 1, 2, 3, 4), sql.NewRow(1, 11, 11, 12, 13, 14), sql.NewRow(2, 20, 21, 22, 23, 24), sql.NewRow(3, 30, 31, 32, 33, 34), }, }, { WriteQuery: `UPDATE othertable RIGHT JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET othertable.s2 = 'fourth'`, ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM othertable order by i2", ExpectedSelect: []sql.Row{ sql.NewRow("third", 1), sql.NewRow("second", 2), sql.NewRow("fourth", 3), }, }, { WriteQuery: `UPDATE othertable RIGHT JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET othertable.i2 = othertable.i2 + 1`, ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM othertable order by i2", ExpectedSelect: []sql.Row{ sql.NewRow("third", 1), sql.NewRow("second", 2), sql.NewRow("first", 4), }, }, { WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=tabletest.i RIGHT JOIN one_pk on othertable.i2 = 1 and one_pk.pk = 1 SET tabletest.s = 'updated';`, ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "SELECT * FROM tabletest order by i", ExpectedSelect: []sql.Row{ sql.NewRow(1, "updated"), sql.NewRow(2, "second row"), sql.NewRow(3, "third row"), }, }, { WriteQuery: "with t (n) as (select (1) from dual) UPDATE mytable set s = concat('updated ', i) where i in (select n from t)", ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, SelectQuery: "select * from mytable order by i", ExpectedSelect: []sql.Row{ sql.NewRow(1, "updated 1"), sql.NewRow(2, "second row"), sql.NewRow(3, "third row"), }, }, { WriteQuery: "with recursive t (n) as (select (1) from dual union all select n + 1 from t where n < 2) UPDATE mytable set s = concat('updated ', i) where i in (select n from t)", ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, SelectQuery: "select * from mytable order by i", ExpectedSelect: []sql.Row{ sql.NewRow(1, "updated 1"), sql.NewRow(2, "updated 2"), sql.NewRow(3, "third row"), }, }, }
var UserPrivTests = []UserPrivilegeTest{ { Name: "Binlog replication privileges", SetUpScript: []string{ "CREATE USER user@localhost;", "CREATE USER 'replica-admin'@localhost;", "CREATE USER 'replica-client'@localhost;", "CREATE USER 'replica-reload'@localhost;", "GRANT REPLICATION_SLAVE_ADMIN ON *.* TO 'replica-admin'@localhost;", "GRANT REPLICATION CLIENT ON *.* to 'replica-client'@localhost;", "GRANT RELOAD ON *.* TO 'replica-reload'@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "user", Host: "localhost", Query: "START REPLICA", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-admin", Host: "localhost", Query: "START REPLICA", ExpectedErr: plan.ErrNoReplicationController, }, { User: "replica-client", Host: "localhost", Query: "START REPLICA", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-reload", Host: "localhost", Query: "START REPLICA", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "root", Host: "localhost", Query: "START REPLICA", ExpectedErr: plan.ErrNoReplicationController, }, { User: "user", Host: "localhost", Query: "STOP REPLICA", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-admin", Host: "localhost", Query: "STOP REPLICA", ExpectedErr: plan.ErrNoReplicationController, }, { User: "replica-client", Host: "localhost", Query: "STOP REPLICA", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-reload", Host: "localhost", Query: "STOP REPLICA", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "root", Host: "localhost", Query: "STOP REPLICA", ExpectedErr: plan.ErrNoReplicationController, }, { User: "user", Host: "localhost", Query: "RESET REPLICA", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-admin", Host: "localhost", Query: "RESET REPLICA", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-client", Host: "localhost", Query: "RESET REPLICA", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-reload", Host: "localhost", Query: "RESET REPLICA", ExpectedErr: plan.ErrNoReplicationController, }, { User: "root", Host: "localhost", Query: "RESET REPLICA", ExpectedErr: plan.ErrNoReplicationController, }, { User: "user", Host: "localhost", Query: "SHOW REPLICA STATUS;", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-admin", Host: "localhost", Query: "SHOW REPLICA STATUS;", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-client", Host: "localhost", Query: "SHOW REPLICA STATUS;", Expected: []sql.Row{}, }, { User: "replica-reload", Host: "localhost", Query: "SHOW REPLICA STATUS;", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "root", Host: "localhost", Query: "SHOW REPLICA STATUS;", Expected: []sql.Row{}, }, { User: "user", Host: "localhost", Query: "CHANGE REPLICATION SOURCE TO SOURCE_HOST='localhost';", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-admin", Host: "localhost", Query: "CHANGE REPLICATION SOURCE TO SOURCE_HOST='localhost';", ExpectedErr: plan.ErrNoReplicationController, }, { User: "replica-client", Host: "localhost", Query: "CHANGE REPLICATION SOURCE TO SOURCE_HOST='localhost';", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-reload", Host: "localhost", Query: "CHANGE REPLICATION SOURCE TO SOURCE_HOST='localhost';", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "root", Host: "localhost", Query: "CHANGE REPLICATION SOURCE TO SOURCE_HOST='localhost';", ExpectedErr: plan.ErrNoReplicationController, }, { User: "user", Host: "localhost", Query: "CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE=(db01.t1);", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-admin", Host: "localhost", Query: "CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE=(db01.t1);", ExpectedErr: plan.ErrNoReplicationController, }, { User: "replica-client", Host: "localhost", Query: "CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE=(db01.t1);", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-reload", Host: "localhost", Query: "CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE=(db01.t1);", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "root", Host: "localhost", Query: "CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE=(db01.t1);", ExpectedErr: plan.ErrNoReplicationController, }, }, }, { Name: "Basic database and table name visibility", SetUpScript: []string{ "CREATE TABLE mydb.test (pk BIGINT PRIMARY KEY);", "INSERT INTO mydb.test VALUES (1);", "CREATE USER tester@localhost;", "CREATE ROLE test_role;", "GRANT SELECT ON mydb.* TO test_role;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test;/*1*/", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test2;/*1*/", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "GRANT SELECT ON *.* TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test;/*2*/", Expected: []sql.Row{{1}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test2;/*2*/", ExpectedErr: sql.ErrTableNotFound, }, { User: "root", Host: "localhost", Query: "REVOKE SELECT ON *.* FROM tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test;/*3*/", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test2;/*3*/", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "GRANT SELECT ON mydb.* TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test;/*4*/", Expected: []sql.Row{{1}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test2;/*4*/", ExpectedErr: sql.ErrTableNotFound, }, { User: "root", Host: "localhost", Query: "REVOKE SELECT ON mydb.* FROM tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test;/*5*/", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test2;/*5*/", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "GRANT SELECT ON mydb.test TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test;/*6*/", Expected: []sql.Row{{1}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test2;/*6*/", ExpectedErr: sql.ErrTableAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "REVOKE SELECT ON mydb.test FROM tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test;/*7*/", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test2;/*7*/", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "GRANT SELECT ON mydb.test2 TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test;/*8*/", ExpectedErr: sql.ErrTableAccessDeniedForUser, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test2;/*8*/", ExpectedErr: sql.ErrTableNotFound, }, { User: "root", Host: "localhost", Query: "REVOKE SELECT ON mydb.test2 FROM tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test;/*9*/", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test2;/*9*/", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "GRANT test_role TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test;/*10*/", Expected: []sql.Row{{1}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM mydb.test2;/*10*/", ExpectedErr: sql.ErrTableNotFound, }, }, }, { Name: "Basic user creation", SetUpScript: []string{ "CREATE USER testuser@`127.0.0.1`;", }, Assertions: []UserPrivilegeTestAssertion{ { Query: "CREATE USER testuser@`127.0.0.1`;", ExpectedErr: sql.ErrUserCreationFailure, }, { Query: "CREATE USER IF NOT EXISTS testuser@`127.0.0.1`;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO mysql.user (Host, User) VALUES ('localhost', 'testuser2');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * FROM mysql.user WHERE User = 'root';", Expected: []sql.Row{ { "localhost", "root", uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(2), uint16(1), []byte(""), []byte(""), []byte(""), uint32(0), uint32(0), uint32(0), uint32(0), "mysql_native_password", "", uint16(1), time.Unix(1, 0).UTC(), nil, uint16(1), uint16(2), uint16(2), nil, nil, nil, nil, "", }, }, }, { Query: "SELECT Host, User FROM mysql.user;", Expected: []sql.Row{ {"localhost", "root"}, {"localhost", "testuser2"}, {"127.0.0.1", "testuser"}, }, }, }, }, { Name: "Dynamic privilege support", SetUpScript: []string{ "CREATE USER testuser@localhost;", "GRANT REPLICATION_SLAVE_ADMIN ON *.* TO testuser@localhost;", "GRANT CLONE_ADMIN ON *.* TO testuser@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { Query: "SELECT user, host from mysql.user", Expected: []sql.Row{ {"root", "localhost"}, {"testuser", "localhost"}, }, }, { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR testuser@localhost;", Expected: []sql.Row{ {"GRANT USAGE ON *.* TO `testuser`@`localhost`"}, {"GRANT CLONE_ADMIN, REPLICATION_SLAVE_ADMIN ON *.* TO `testuser`@`localhost`"}, }, }, { User: "root", Host: "localhost", Query: "GRANT REPLICATION_SLAVE_ADMIN ON mydb.* TO 'testuser'@'localhost';", ExpectedErr: sql.ErrGrantRevokeIllegalPrivilegeWithMessage, }, { User: "root", Host: "localhost", Query: "GRANT REPLICATION_SLAVE_ADMIN ON mydb.mytable TO 'testuser'@'localhost';", ExpectedErr: sql.ErrGrantRevokeIllegalPrivilegeWithMessage, }, { User: "root", Host: "localhost", Query: "REVOKE REPLICATION_SLAVE_ADMIN ON mydb.* FROM 'testuser'@'localhost';", ExpectedErr: sql.ErrGrantRevokeIllegalPrivilegeWithMessage, }, { User: "root", Host: "localhost", Query: "REVOKE REPLICATION_SLAVE_ADMIN ON mydb.mytable FROM 'testuser'@'localhost';", ExpectedErr: sql.ErrGrantRevokeIllegalPrivilegeWithMessage, }, }, }, { Name: "user creation no host", SetUpScript: []string{ "CREATE USER testuser;", }, Assertions: []UserPrivilegeTestAssertion{ { Query: "SELECT user, host from mysql.user", Expected: []sql.Row{ {"root", "localhost"}, {"testuser", "%"}, }, }, }, }, { Name: "grants at various scopes no host", SetUpScript: []string{ "CREATE USER tester;", "GRANT SELECT ON *.* to tester", "GRANT SELECT ON db.* to tester", "GRANT SELECT ON db.tbl to tester", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR tester@localhost;", Expected: []sql.Row{ {"GRANT SELECT ON *.* TO `tester`@`%`"}, {"GRANT SELECT ON `db`.* TO `tester`@`%`"}, {"GRANT SELECT ON `db`.`tbl` TO `tester`@`%`"}, }, }, }, }, { Name: "Valid users without privileges may use the dual table", SetUpScript: []string{ "CREATE USER tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "SELECT 1+2;", Expected: []sql.Row{{3}}, }, { User: "noexist", Host: "localhost", Query: "SELECT 1+2;", ExpectedErrStr: "Access denied for user 'noexist' (errno 1045) (sqlstate 28000)", }, }, }, { Name: "Basic SELECT and INSERT privilege checking", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY);", "INSERT INTO test VALUES (1), (2), (3);", "CREATE USER tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "INSERT INTO test VALUES (4);", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "GRANT INSERT ON *.* TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "INSERT INTO test VALUES (4);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "root", Host: "localhost", Query: "SELECT * FROM test;", Expected: []sql.Row{{1}, {2}, {3}, {4}}, }, { User: "root", Host: "localhost", Query: "GRANT SELECT ON *.* TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", Expected: []sql.Row{{1}, {2}, {3}, {4}}, }, }, }, { Name: "Database-level privileges exist", SetUpScript: []string{ "CREATE USER tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "GRANT SELECT, UPDATE, EXECUTE ON mydb.* TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "SELECT * FROM mysql.db;", Expected: []sql.Row{{"localhost", "mydb", "tester", uint16(2), uint16(1), uint16(2), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(2), uint16(1), uint16(1)}}, }, { User: "root", Host: "localhost", Query: "REVOKE UPDATE ON mydb.* FROM tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "SELECT * FROM mysql.db;", Expected: []sql.Row{{"localhost", "mydb", "tester", uint16(2), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(2), uint16(1), uint16(1)}}, }, { User: "root", Host: "localhost", Query: "UPDATE mysql.db SET Insert_priv = 'Y' WHERE User = 'tester';", Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, InsertID: 0, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, Warnings: 0, }, }}}, }, { User: "root", Host: "localhost", Query: "SELECT * FROM mysql.db;", Expected: []sql.Row{{"localhost", "mydb", "tester", uint16(2), uint16(2), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(1), uint16(2), uint16(1), uint16(1)}}, }, }, }, { Name: "Table-level privileges exist", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY);", "CREATE USER tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "GRANT SELECT, DELETE, DROP ON mydb.test TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "SELECT * FROM mysql.tables_priv;", Expected: []sql.Row{{"localhost", "mydb", "tester", "test", "", time.Unix(1, 0).UTC(), uint64(0b101001), uint64(0)}}, }, { User: "root", Host: "localhost", Query: "REVOKE DELETE ON mydb.test FROM tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "SELECT * FROM mysql.tables_priv;", Expected: []sql.Row{{"localhost", "mydb", "tester", "test", "", time.Unix(1, 0).UTC(), uint64(0b100001), uint64(0)}}, }, { User: "root", Host: "localhost", Query: "UPDATE mysql.tables_priv SET table_priv = 'References,Index' WHERE User = 'tester';", Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, InsertID: 0, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, Warnings: 0, }, }}}, }, { User: "root", Host: "localhost", Query: "SELECT * FROM mysql.tables_priv;", Expected: []sql.Row{{"localhost", "mydb", "tester", "test", "", time.Unix(1, 0).UTC(), uint64(0b110000000), uint64(0)}}, }, }, }, { Name: "Basic revoke SELECT privilege", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY);", "INSERT INTO test VALUES (1), (2), (3);", "CREATE USER tester@localhost;", "GRANT SELECT ON *.* TO tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", Expected: []sql.Row{{1}, {2}, {3}}, }, { User: "root", Host: "localhost", Query: "SELECT User, Host, Select_priv FROM mysql.user WHERE User = 'tester';", Expected: []sql.Row{{"tester", "localhost", uint16(2)}}, }, { User: "root", Host: "localhost", Query: "REVOKE SELECT ON *.* FROM tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "SELECT User, Host, Select_priv FROM mysql.user WHERE User = 'tester';", Expected: []sql.Row{{"tester", "localhost", uint16(1)}}, }, }, }, { Name: "Basic revoke all global static privileges", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY);", "INSERT INTO test VALUES (1), (2), (3);", "CREATE USER tester@localhost;", "GRANT ALL ON *.* TO tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "INSERT INTO test VALUES (4);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", Expected: []sql.Row{{1}, {2}, {3}, {4}}, }, { User: "root", Host: "localhost", Query: "SELECT User, Host, Select_priv, Insert_priv FROM mysql.user WHERE User = 'tester';", Expected: []sql.Row{{"tester", "localhost", uint16(2), uint16(2)}}, }, { User: "root", Host: "localhost", Query: "REVOKE ALL ON *.* FROM tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "tester", Host: "localhost", Query: "INSERT INTO test VALUES (5);", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "SELECT User, Host, Select_priv, Insert_priv FROM mysql.user WHERE User = 'tester';", Expected: []sql.Row{{"tester", "localhost", uint16(1), uint16(1)}}, }, }, }, { Name: "Basic role creation", SetUpScript: []string{ "CREATE ROLE test_role;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SELECT User, Host, account_locked FROM mysql.user WHERE User = 'test_role';", Expected: []sql.Row{{"test_role", "%", uint16(2)}}, }, }, }, { Name: "Grant Role with SELECT Privilege", SetUpScript: []string{ "SET @@GLOBAL.activate_all_roles_on_login = true;", "CREATE TABLE test (pk BIGINT PRIMARY KEY);", "INSERT INTO test VALUES (1), (2), (3);", "CREATE USER tester@localhost;", "CREATE ROLE test_role;", "GRANT SELECT ON *.* TO test_role;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "SELECT COUNT(*) FROM mysql.role_edges;", Expected: []sql.Row{{0}}, }, { User: "root", Host: "localhost", Query: "GRANT test_role TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "SELECT * FROM mysql.role_edges;", Expected: []sql.Row{{"%", "test_role", "localhost", "tester", uint16(1)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", Expected: []sql.Row{{1}, {2}, {3}}, }, { User: "root", Host: "localhost", Query: "SELECT User, Host, Select_priv FROM mysql.user WHERE User = 'tester';", Expected: []sql.Row{{"tester", "localhost", uint16(1)}}, }, }, }, { Name: "Revoke role currently granted to a user", SetUpScript: []string{ "SET @@GLOBAL.activate_all_roles_on_login = true;", "CREATE TABLE test (pk BIGINT PRIMARY KEY);", "INSERT INTO test VALUES (1), (2), (3);", "CREATE USER tester@localhost;", "CREATE ROLE test_role;", "GRANT SELECT ON *.* TO test_role;", "GRANT test_role TO tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", Expected: []sql.Row{{1}, {2}, {3}}, }, { User: "root", Host: "localhost", Query: "SELECT * FROM mysql.role_edges;", Expected: []sql.Row{{"%", "test_role", "localhost", "tester", uint16(1)}}, }, { User: "root", Host: "localhost", Query: "REVOKE test_role FROM tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "SELECT COUNT(*) FROM mysql.role_edges;", Expected: []sql.Row{{0}}, }, { User: "root", Host: "localhost", Query: "SELECT COUNT(*) FROM mysql.user WHERE User = 'test_role';", Expected: []sql.Row{{1}}, }, { User: "root", Host: "localhost", Query: "SELECT COUNT(*) FROM mysql.user WHERE User = 'tester';", Expected: []sql.Row{{1}}, }, }, }, { Name: "Drop role currently granted to a user", SetUpScript: []string{ "SET @@GLOBAL.activate_all_roles_on_login = true;", "CREATE TABLE test (pk BIGINT PRIMARY KEY);", "INSERT INTO test VALUES (1), (2), (3);", "CREATE USER tester@localhost;", "CREATE ROLE test_role;", "GRANT SELECT ON *.* TO test_role;", "GRANT test_role TO tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", Expected: []sql.Row{{1}, {2}, {3}}, }, { User: "root", Host: "localhost", Query: "SELECT * FROM mysql.role_edges;", Expected: []sql.Row{{"%", "test_role", "localhost", "tester", uint16(1)}}, }, { User: "root", Host: "localhost", Query: "DROP ROLE test_role;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM test;", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "root", Host: "localhost", Query: "SELECT COUNT(*) FROM mysql.role_edges;", Expected: []sql.Row{{0}}, }, { User: "root", Host: "localhost", Query: "SELECT COUNT(*) FROM mysql.user WHERE User = 'test_role';", Expected: []sql.Row{{0}}, }, { User: "root", Host: "localhost", Query: "SELECT COUNT(*) FROM mysql.user WHERE User = 'tester';", Expected: []sql.Row{{1}}, }, { User: "root", Host: "localhost", Query: "DROP ROLE test_role;", ExpectedErr: sql.ErrRoleDeletionFailure, }, { User: "root", Host: "localhost", Query: "DROP ROLE IF EXISTS test_role;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Drop user with role currently granted", SetUpScript: []string{ "SET @@GLOBAL.activate_all_roles_on_login = true;", "CREATE TABLE test (pk BIGINT PRIMARY KEY);", "INSERT INTO test VALUES (1), (2), (3);", "CREATE USER tester@localhost;", "CREATE ROLE test_role;", "GRANT SELECT ON *.* TO test_role;", "GRANT test_role TO tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SELECT * FROM mysql.role_edges;", Expected: []sql.Row{{"%", "test_role", "localhost", "tester", uint16(1)}}, }, { User: "root", Host: "localhost", Query: "DROP USER tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "SELECT COUNT(*) FROM mysql.role_edges;", Expected: []sql.Row{{0}}, }, { User: "root", Host: "localhost", Query: "SELECT COUNT(*) FROM mysql.user WHERE User = 'tester';", Expected: []sql.Row{{0}}, }, { User: "root", Host: "localhost", Query: "SELECT COUNT(*) FROM mysql.user WHERE User = 'test_role';", Expected: []sql.Row{{1}}, }, { User: "root", Host: "localhost", Query: "DROP USER tester@localhost;", ExpectedErr: sql.ErrUserDeletionFailure, }, { User: "root", Host: "localhost", Query: "DROP USER IF EXISTS tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Show grants on root account", Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SHOW GRANTS;", Expected: []sql.Row{{"GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, " + "FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, " + "EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, " + "ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO " + "`root`@`localhost` WITH GRANT OPTION"}}, }, }, }, { Name: "Show grants on a user from the root account", SetUpScript: []string{ "CREATE USER tester@localhost;", "GRANT SELECT ON *.* TO tester@localhost;", "CREATE ROLE test_role1;", "CREATE ROLE test_role2;", "GRANT INSERT ON *.* TO test_role1;", "GRANT REFERENCES ON *.* TO test_role2;", "GRANT test_role1 TO tester@localhost;", "GRANT test_role2 TO tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR tester@localhost;", Expected: []sql.Row{ {"GRANT SELECT ON *.* TO `tester`@`localhost`"}, {"GRANT `test_role1`@`%`, `test_role2`@`%` TO `tester`@`localhost`"}, }, }, { User: "root", Host: "localhost", Query: "GRANT UPDATE ON *.* TO tester@localhost WITH GRANT OPTION;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR tester@localhost;", Expected: []sql.Row{ {"GRANT SELECT, UPDATE ON *.* TO `tester`@`localhost` WITH GRANT OPTION"}, {"GRANT `test_role1`@`%`, `test_role2`@`%` TO `tester`@`localhost`"}, }, }, { User: "tester", Host: "localhost", Query: "SHOW GRANTS;", Expected: []sql.Row{ {"GRANT SELECT, UPDATE ON *.* TO `tester`@`localhost` WITH GRANT OPTION"}, {"GRANT `test_role1`@`%`, `test_role2`@`%` TO `tester`@`localhost`"}, }, }, }, }, { Name: "show user with no grants", SetUpScript: []string{ "CREATE USER tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR tester@localhost;", Expected: []sql.Row{ {"GRANT USAGE ON *.* TO `tester`@`localhost`"}, }, }, }, }, { Name: "show grants with multiple global grants", SetUpScript: []string{ "CREATE USER tester@localhost;", "GRANT SELECT ON *.* to tester@localhost", "GRANT INSERT ON *.* to tester@localhost", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR tester@localhost;", Expected: []sql.Row{ {"GRANT SELECT, INSERT ON *.* TO `tester`@`localhost`"}, }, }, }, }, { Name: "show grants at various scopes", SetUpScript: []string{ "CREATE USER tester@localhost;", "GRANT SELECT ON *.* to tester@localhost", "GRANT SELECT ON db.* to tester@localhost", "GRANT SELECT ON db.tbl to tester@localhost", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR tester@localhost;", Expected: []sql.Row{ {"GRANT SELECT ON *.* TO `tester`@`localhost`"}, {"GRANT SELECT ON `db`.* TO `tester`@`localhost`"}, {"GRANT SELECT ON `db`.`tbl` TO `tester`@`localhost`"}, }, }, }, }, { Name: "show grants at only some scopes", SetUpScript: []string{ "CREATE USER tester@localhost;", "GRANT SELECT ON *.* to tester@localhost", "GRANT SELECT ON db.tbl to tester@localhost", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR tester@localhost;", Expected: []sql.Row{ {"GRANT SELECT ON *.* TO `tester`@`localhost`"}, {"GRANT SELECT ON `db`.`tbl` TO `tester`@`localhost`"}, }, }, }, }, { Name: "show always shows global USAGE priv regardless of other privs", SetUpScript: []string{ "CREATE USER tester@localhost;", "GRANT SELECT ON db.* to tester@localhost", "GRANT INSERT ON db1.* to tester@localhost", "GRANT DELETE ON db2.* to tester@localhost", "GRANT SELECT ON db.tbl to tester@localhost", "GRANT INSERT ON db.tbl to tester@localhost", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR tester@localhost;", Expected: []sql.Row{ {"GRANT USAGE ON *.* TO `tester`@`localhost`"}, {"GRANT SELECT ON `db`.* TO `tester`@`localhost`"}, {"GRANT INSERT ON `db1`.* TO `tester`@`localhost`"}, {"GRANT DELETE ON `db2`.* TO `tester`@`localhost`"}, {"GRANT SELECT, INSERT ON `db`.`tbl` TO `tester`@`localhost`"}, }, }, }, }, { Name: "with grant option works at every scope", SetUpScript: []string{ "CREATE USER tester@localhost;", "GRANT SELECT ON *.* to tester@localhost WITH GRANT OPTION", "GRANT SELECT ON db.* to tester@localhost WITH GRANT OPTION", "GRANT SELECT ON db.tbl to tester@localhost WITH GRANT OPTION", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR tester@localhost;", Expected: []sql.Row{ {"GRANT SELECT ON *.* TO `tester`@`localhost` WITH GRANT OPTION"}, {"GRANT SELECT ON `db`.* TO `tester`@`localhost` WITH GRANT OPTION"}, {"GRANT SELECT ON `db`.`tbl` TO `tester`@`localhost` WITH GRANT OPTION"}, }, }, }, }, { Name: "adding with grant option applies to existing privileges", SetUpScript: []string{ "CREATE USER tester@localhost;", "GRANT SELECT ON *.* to tester@localhost", "GRANT INSERT ON *.* to tester@localhost WITH GRANT OPTION", "GRANT SELECT ON db.* to tester@localhost", "GRANT INSERT ON db.* to tester@localhost WITH GRANT OPTION", "GRANT SELECT ON db.tbl to tester@localhost", "GRANT INSERT ON db.tbl to tester@localhost WITH GRANT OPTION", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SHOW GRANTS FOR tester@localhost;", Expected: []sql.Row{ {"GRANT SELECT, INSERT ON *.* TO `tester`@`localhost` WITH GRANT OPTION"}, {"GRANT SELECT, INSERT ON `db`.* TO `tester`@`localhost` WITH GRANT OPTION"}, {"GRANT SELECT, INSERT ON `db`.`tbl` TO `tester`@`localhost` WITH GRANT OPTION"}, }, }, }, }, { Name: "SHOW DATABASES shows `mysql` database", SetUpScript: []string{ "CREATE USER testuser;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SELECT user FROM mysql.user;", Expected: []sql.Row{ {"root"}, {"testuser"}, }, }, { User: "root", Host: "localhost", Query: "SELECT USER();", Expected: []sql.Row{ {"root@localhost"}, }, }, { User: "root", Host: "localhost", Query: "SHOW DATABASES", Expected: []sql.Row{ {"information_schema"}, {"mydb"}, {"mysql"}, }, }, }, }, { Name: "Anonymous User", SetUpScript: []string{ "CREATE TABLE mydb.test (pk BIGINT PRIMARY KEY, v1 BIGINT);", "CREATE TABLE mydb.test2 (pk BIGINT PRIMARY KEY, v1 BIGINT);", "INSERT INTO mydb.test VALUES (0, 0), (1, 1);", "INSERT INTO mydb.test2 VALUES (0, 1), (1, 2);", "CREATE USER 'rand_user'@'localhost';", "CREATE USER ''@'%';", "GRANT SELECT ON mydb.test TO 'rand_user'@'localhost';", "GRANT SELECT ON mydb.test2 TO ''@'%';", }, Assertions: []UserPrivilegeTestAssertion{ { User: "rand_user", Host: "localhost", Query: "SELECT * FROM mydb.test;", Expected: []sql.Row{ {0, 0}, {1, 1}, }, }, { User: "rand_user", Host: "localhost", Query: "SELECT * FROM mydb.test2;", ExpectedErr: sql.ErrTableAccessDeniedForUser, }, { User: "rand_user", Host: "non_existent_host", Query: "SELECT * FROM mydb.test;", ExpectedErr: sql.ErrTableAccessDeniedForUser, }, { User: "rand_user", Host: "non_existent_host", Query: "SELECT * FROM mydb.test2;", Expected: []sql.Row{ {0, 1}, {1, 2}, }, }, { User: "non_existent_user", Host: "non_existent_host", Query: "SELECT * FROM mydb.test;", ExpectedErr: sql.ErrTableAccessDeniedForUser, }, { User: "non_existent_user", Host: "non_existent_host", Query: "SELECT * FROM mydb.test2;", Expected: []sql.Row{ {0, 1}, {1, 2}, }, }, { User: "", Host: "%", Query: "SELECT * FROM mydb.test;", ExpectedErr: sql.ErrTableAccessDeniedForUser, }, { User: "", Host: "%", Query: "SELECT * FROM mydb.test2;", Expected: []sql.Row{ {0, 1}, {1, 2}, }, }, }, }, { Name: "IPv4 Loopback == localhost", SetUpScript: []string{ "CREATE TABLE mydb.test (pk BIGINT PRIMARY KEY, v1 BIGINT);", "CREATE TABLE mydb.test2 (pk BIGINT PRIMARY KEY, v1 BIGINT);", "INSERT INTO mydb.test VALUES (0, 0), (1, 1);", "INSERT INTO mydb.test2 VALUES (0, 1), (1, 2);", "CREATE USER 'rand_user1'@'localhost';", "CREATE USER 'rand_user2'@'127.0.0.1';", "GRANT SELECT ON mydb.test TO 'rand_user1'@'localhost';", "GRANT SELECT ON mydb.test2 TO 'rand_user2'@'127.0.0.1';", }, Assertions: []UserPrivilegeTestAssertion{ { User: "rand_user1", Host: "localhost", Query: "SELECT * FROM mydb.test;", Expected: []sql.Row{ {0, 0}, {1, 1}, }, }, { User: "rand_user1", Host: "127.0.0.1", Query: "SELECT * FROM mydb.test;", Expected: []sql.Row{ {0, 0}, {1, 1}, }, }, { User: "rand_user1", Host: "54.244.85.252", Query: "SELECT * FROM mydb.test;", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, { User: "rand_user2", Host: "localhost", Query: "SELECT * FROM mydb.test2;", Expected: []sql.Row{ {0, 1}, {1, 2}, }, }, { User: "rand_user2", Host: "127.0.0.1", Query: "SELECT * FROM mydb.test2;", Expected: []sql.Row{ {0, 1}, {1, 2}, }, }, { User: "rand_user2", Host: "54.244.85.252", Query: "SELECT * FROM mydb.test2;", ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, }, }, }, { Name: "DROP USER without a host designation", SetUpScript: []string{ "CREATE USER admin;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SELECT user FROM mysql.user", Expected: []sql.Row{ {"root"}, {"admin"}, }, }, { User: "root", Host: "localhost", Query: "DROP USER admin;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "SELECT user FROM mysql.user", Expected: []sql.Row{ {"root"}, }, }, }, }, { Name: "information_schema.columns table 'privileges' column gets correct values", SetUpScript: []string{ "CREATE TABLE checks (a INTEGER PRIMARY KEY, b INTEGER, c VARCHAR(20))", "CREATE TABLE test (pk BIGINT PRIMARY KEY, c VARCHAR(20), p POINT default (POINT(1,1)))", "CREATE USER tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "SELECT count(*) FROM inFORmation_ScHeMa.columns where table_schema = 'mydb' and table_name = 'test';", Expected: []sql.Row{{0}}, }, { User: "root", Host: "localhost", Query: "GRANT INSERT ON mydb.test TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT column_name, privileges FROM information_schema.columns where table_schema = 'mydb' and table_name = 'test'", Expected: []sql.Row{{"pk", "insert"}, {"c", "insert"}, {"p", "insert"}}, }, { User: "root", Host: "localhost", Query: "GRANT SELECT ON mydb.* TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT column_name, privileges FROM information_schema.columns where table_schema = 'mydb' and table_name = 'test'", Expected: []sql.Row{{"pk", "insert,select"}, {"c", "insert,select"}, {"p", "insert,select"}}, }, { User: "root", Host: "localhost", Query: "GRANT UPDATE ON mydb.checks TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "select table_name, column_name, privileges from information_schema.columns where table_schema = 'mydb' and table_name = 'checks';", Expected: []sql.Row{{"checks", "a", "select,update"}, {"checks", "b", "select,update"}, {"checks", "c", "select,update"}}, }, { User: "tester", Host: "localhost", Query: "SELECT count(*) FROM information_schema.columns where table_schema = 'information_schema' and table_name = 'columns'", Expected: []sql.Row{{22}}, }, { User: "root", Host: "localhost", Query: "select table_name, column_name, privileges from information_schema.columns where table_schema = 'mydb' and table_name = 'checks';", Expected: []sql.Row{{"checks", "a", "insert,references,select,update"}, {"checks", "b", "insert,references,select,update"}, {"checks", "c", "insert,references,select,update"}}, }, }, }, { Name: "information_schema.column_statistics shows columns with privileges only", SetUpScript: []string{ "CREATE TABLE two (i int primary key, j int)", "INSERT INTO two VALUES (1, 4), (2, 5), (3, 6)", "CREATE TABLE one (f float)", "INSERT INTO one VALUES (1.25), (45.25), (7.5), (10.5)", "ANALYZE TABLE one", "ANALYZE TABLE two", "CREATE USER tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "GRANT SELECT ON mydb.one TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM information_schema.column_statistics where schema_name = 'mydb';", Expected: []sql.Row{{"mydb", "one", "f", types.JSONDocument{Val: map[string]interface{}{"buckets": []interface{}{[]interface{}{"1.25", "1.25", "0.25"}, []interface{}{"7.50", "7.50", "0.25"}, []interface{}{"10.50", "10.50", "0.25"}, []interface{}{"45.25", "45.25", "0.25"}}}}}}, }, { User: "root", Host: "localhost", Query: "GRANT SELECT ON mydb.two TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "SELECT * FROM information_schema.column_statistics where schema_name = 'mydb';", Expected: []sql.Row{{"mydb", "one", "f", types.JSONDocument{Val: map[string]interface{}{"buckets": []interface{}{[]interface{}{"1.25", "1.25", "0.25"}, []interface{}{"7.50", "7.50", "0.25"}, []interface{}{"10.50", "10.50", "0.25"}, []interface{}{"45.25", "45.25", "0.25"}}}}}, {"mydb", "two", "i", types.JSONDocument{Val: map[string]interface{}{"buckets": []interface{}{[]interface{}{"1.00", "1.00", "0.33"}, []interface{}{"2.00", "2.00", "0.33"}, []interface{}{"3.00", "3.00", "0.33"}}}}}, {"mydb", "two", "j", types.JSONDocument{Val: map[string]interface{}{"buckets": []interface{}{[]interface{}{"4.00", "4.00", "0.33"}, []interface{}{"5.00", "5.00", "0.33"}, []interface{}{"6.00", "6.00", "0.33"}}}}}}, }, }, }, { Name: "information_schema.statistics shows tables with privileges only", SetUpScript: []string{ "CREATE TABLE checks (a INTEGER PRIMARY KEY, b INTEGER, c VARCHAR(20))", "CREATE TABLE test (pk BIGINT PRIMARY KEY, c VARCHAR(20), p POINT default (POINT(1,1)))", "CREATE USER tester@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "SELECT count(*) FROM information_schema.statistics where table_schema = 'mydb';", Expected: []sql.Row{{0}}, }, { User: "root", Host: "localhost", Query: "GRANT INSERT ON mydb.checks TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "select table_name, column_name, index_name from information_schema.statistics where table_schema = 'mydb';", Expected: []sql.Row{{"checks", "a", "PRIMARY"}}, }, }, }, { Name: "basic tests on information_schema.SCHEMA_PRIVILEGES table", SetUpScript: []string{ "CREATE TABLE checks (a INTEGER PRIMARY KEY, b INTEGER, c VARCHAR(20))", "CREATE USER tester@localhost;", "CREATE USER admin@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "select * from information_schema.schema_privileges;", Expected: []sql.Row{}, }, { User: "root", Host: "localhost", Query: "GRANT INSERT, REFERENCES ON mydb.* TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "GRANT UPDATE, GRANT OPTION ON mydb.* TO admin@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "select * from information_schema.schema_privileges order by privilege_type, is_grantable;", Expected: []sql.Row{{"'tester'@'localhost'", "def", "mydb", "INSERT", "NO"}, {"'tester'@'localhost'", "def", "mydb", "REFERENCES", "NO"}, {"'admin'@'localhost'", "def", "mydb", "UPDATE", "YES"}}, }, { User: "tester", Host: "localhost", Query: "select * from information_schema.schema_privileges order by privilege_type, is_grantable;", Expected: []sql.Row{{"'tester'@'localhost'", "def", "mydb", "INSERT", "NO"}, {"'tester'@'localhost'", "def", "mydb", "REFERENCES", "NO"}}, }, { User: "admin", Host: "localhost", Query: "select * from information_schema.schema_privileges order by privilege_type, is_grantable;", Expected: []sql.Row{{"'admin'@'localhost'", "def", "mydb", "UPDATE", "YES"}}, }, { User: "root", Host: "localhost", Query: "GRANT SELECT ON mysql.* TO admin@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "admin", Host: "localhost", Query: "select * from information_schema.schema_privileges order by privilege_type, is_grantable;", Expected: []sql.Row{{"'tester'@'localhost'", "def", "mydb", "INSERT", "NO"}, {"'tester'@'localhost'", "def", "mydb", "REFERENCES", "NO"}, {"'admin'@'localhost'", "def", "mysql", "SELECT", "NO"}, {"'admin'@'localhost'", "def", "mydb", "UPDATE", "YES"}}, }, }, }, { Name: "basic tests on information_schema.TABLE_PRIVILEGES table", SetUpScript: []string{ "CREATE TABLE checks (a INTEGER PRIMARY KEY, b INTEGER, c VARCHAR(20))", "CREATE TABLE test (pk BIGINT PRIMARY KEY, c VARCHAR(20), p POINT default (POINT(1,1)))", "CREATE USER tester@localhost;", "CREATE USER admin@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "select * from information_schema.table_privileges;", Expected: []sql.Row{}, }, { User: "root", Host: "localhost", Query: "GRANT INSERT ON mydb.checks TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "GRANT UPDATE, GRANT OPTION ON mydb.test TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "root", Host: "localhost", Query: "select * from information_schema.table_privileges order by privilege_type, is_grantable;/*root*/", Expected: []sql.Row{{"'tester'@'localhost'", "def", "mydb", "checks", "INSERT", "NO"}, {"'tester'@'localhost'", "def", "mydb", "test", "UPDATE", "YES"}}, }, { User: "tester", Host: "localhost", Query: "select * from information_schema.table_privileges order by privilege_type, is_grantable;/*tester*/", Expected: []sql.Row{{"'tester'@'localhost'", "def", "mydb", "checks", "INSERT", "NO"}, {"'tester'@'localhost'", "def", "mydb", "test", "UPDATE", "YES"}}, }, { User: "admin", Host: "localhost", Query: "select * from information_schema.table_privileges order by privilege_type, is_grantable;/*admin1*/", Expected: []sql.Row{}, }, { User: "root", Host: "localhost", Query: "GRANT SELECT ON mysql.* TO admin@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "admin", Host: "localhost", Query: "select * from information_schema.table_privileges order by privilege_type, is_grantable;/*admin2*/", Expected: []sql.Row{{"'tester'@'localhost'", "def", "mydb", "checks", "INSERT", "NO"}, {"'tester'@'localhost'", "def", "mydb", "test", "UPDATE", "YES"}}, }, }, }, { Name: "basic tests on information_schema.USER_PRIVILEGES table", SetUpScript: []string{ "CREATE TABLE checks (a INTEGER PRIMARY KEY, b INTEGER, c VARCHAR(20))", "CREATE TABLE test (pk BIGINT PRIMARY KEY, c VARCHAR(20), p POINT default (POINT(1,1)))", "CREATE USER tester@localhost;", "CREATE USER admin@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "select * from information_schema.user_privileges order by privilege_type LIMIT 4;/*root*/", Expected: []sql.Row{{"'root'@'localhost'", "def", "ALTER", "YES"}, {"'root'@'localhost'", "def", "ALTER ROUTINE", "YES"}, {"'root'@'localhost'", "def", "CREATE", "YES"}, {"'root'@'localhost'", "def", "CREATE ROLE", "YES"}}, }, { User: "root", Host: "localhost", Query: "GRANT INSERT ON *.* TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "select * from information_schema.user_privileges order by privilege_type, is_grantable;/*tester1*/", Expected: []sql.Row{{"'tester'@'localhost'", "def", "INSERT", "NO"}}, }, { User: "root", Host: "localhost", Query: "GRANT UPDATE, GRANT OPTION ON *.* TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "select * from information_schema.user_privileges order by privilege_type, is_grantable;/*tester2*/", Expected: []sql.Row{{"'tester'@'localhost'", "def", "INSERT", "YES"}, {"'tester'@'localhost'", "def", "UPDATE", "YES"}}, }, { User: "admin", Host: "localhost", Query: "select * from information_schema.user_privileges order by privilege_type, is_grantable;/*admin*/", Expected: []sql.Row{}, }, }, }, { Name: "basic tests on information_schema.USER_ATTRIBUTES table", SetUpScript: []string{ "CREATE USER tester@localhost;", `CREATE USER admin@localhost ATTRIBUTE '{"fname": "Josh", "lname": "Scott"}';`, "GRANT UPDATE ON mysql.* TO admin@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "select * from information_schema.user_attributes order by user;/*root*/", Expected: []sql.Row{{"admin", "localhost", nil}, {"root", "localhost", nil}, {"tester", "localhost", nil}}, }, { User: "admin", Host: "localhost", Query: "select * from information_schema.user_attributes order by user;/*admin*/", Expected: []sql.Row{{"admin", "localhost", nil}, {"root", "localhost", nil}, {"tester", "localhost", nil}}, }, { User: "tester", Host: "localhost", Query: "select * from information_schema.user_attributes order by user;/*tester*/", Expected: []sql.Row{{"tester", "localhost", nil}}, }, }, }, { Name: "basic privilege tests on information_schema.ROUTINES and PARAMETERS tables", SetUpScript: []string{ "CREATE USER tester@localhost;", "CREATE PROCEDURE testabc(IN x DOUBLE, IN y FLOAT, OUT abc DECIMAL(5,1)) SELECT x*y INTO abc", }, Assertions: []UserPrivilegeTestAssertion{ { User: "tester", Host: "localhost", Query: "select count(*) from information_schema.routines where routine_name = 'testabc'/*tester1*/;", Expected: []sql.Row{{0}}, }, { User: "tester", Host: "localhost", Query: "select count(*) from information_schema.parameters where specific_name = 'testabc'/*tester1*/;", Expected: []sql.Row{{0}}, }, { User: "root", Host: "localhost", Query: "GRANT CREATE ROUTINE ON mydb.* TO tester@localhost;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester", Host: "localhost", Query: "select count(*) from information_schema.routines where routine_name = 'testabc';", Expected: []sql.Row{{1}}, }, { User: "tester", Host: "localhost", Query: "select count(*) from information_schema.parameters where specific_name = 'testabc';", Expected: []sql.Row{{3}}, }, }, }, }
UserPrivTests test the user and privilege systems. These tests always have the root account available, and the root account is used with any queries in the SetUpScript.
var VariableErrorTests = []QueryErrorTest{ { Query: "set @@does_not_exist = 100", ExpectedErr: sql.ErrUnknownSystemVariable, }, { Query: "set @myvar = bareword", ExpectedErr: sql.ErrColumnNotFound, }, { Query: "set @@sql_mode = true", ExpectedErr: sql.ErrInvalidSystemVariableValue, }, { Query: `set @@sql_mode = "NOT_AN_OPTION"`, ExpectedErr: sql.ErrInvalidSetValue, }, { Query: `set global core_file = true`, ExpectedErr: sql.ErrSystemVariableReadOnly, }, { Query: `set global require_row_format = on`, ExpectedErr: sql.ErrSystemVariableSessionOnly, }, { Query: `set session default_password_lifetime = 5`, ExpectedErr: sql.ErrSystemVariableGlobalOnly, }, { Query: `set @custom_var = default`, ExpectedErr: sql.ErrUserVariableNoDefault, }, { Query: `set session @@bulk_insert_buffer_size = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set global @@bulk_insert_buffer_size = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set session @@session.bulk_insert_buffer_size = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set session @@global.bulk_insert_buffer_size = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set global @@session.bulk_insert_buffer_size = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set global @@global.bulk_insert_buffer_size = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set session @myvar = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set global @myvar = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set @@session.@@bulk_insert_buffer_size = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set @@global.@@bulk_insert_buffer_size = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set @@session.@bulk_insert_buffer_size = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set @@global.@bulk_insert_buffer_size = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set @@session.@myvar = 5`, ExpectedErr: sql.ErrSyntaxError, }, { Query: `set @@global.@myvar = 5`, ExpectedErr: sql.ErrSyntaxError, }, }
var VariableQueries = []ScriptTest{ { Name: "use string name for foreign_key checks", SetUpScript: []string{}, Query: "select @@GLOBAL.unknown", ExpectedErr: sql.ErrUnknownSystemVariable, }, { Name: "use string name for foreign_key checks", SetUpScript: []string{}, Query: "set @@foreign_key_checks = off;", Expected: []sql.Row{{}}, }, { Name: "set system variables", SetUpScript: []string{ "set @@auto_increment_increment = 100, sql_select_limit = 1", }, Query: "SELECT @@auto_increment_increment, @@sql_select_limit", Expected: []sql.Row{ {100, 1}, }, }, { Name: "select join_complexity_limit", Query: "SELECT @@join_complexity_limit", Expected: []sql.Row{ {uint64(12)}, }, }, { Name: "set join_complexity_limit", SetUpScript: []string{ "set @@join_complexity_limit = 2", }, Query: "SELECT @@join_complexity_limit", Expected: []sql.Row{ {uint64(2)}, }, }, { Name: "@@server_id", Assertions: []ScriptTestAssertion{ { Query: "select @@server_id;", Expected: []sql.Row{{uint32(0)}}, }, { Query: "set @@server_id=123;", Expected: []sql.Row{{}}, }, { Query: "set @@GLOBAL.server_id=123;", Expected: []sql.Row{{}}, }, { Query: "set @@GLOBAL.server_id=0;", Expected: []sql.Row{{}}, }, }, }, { Name: "set system variables and user variables", SetUpScript: []string{ "SET @myvar = @@autocommit", "SET autocommit = @myvar", "SET @myvar2 = @myvar - 1, @myvar3 = @@autocommit - 1", }, Assertions: []ScriptTestAssertion{ { Query: "select @myvar, @@autocommit, @myvar2, @myvar3", Expected: []sql.Row{ {1, 1, 0, 0}, }, }, }, }, { Name: "set system variables mixed case", SetUpScript: []string{ "set @@auto_increment_INCREMENT = 100, sql_select_LIMIT = 1", }, Query: "SELECT @@auto_increment_increment, @@sql_select_limit", Expected: []sql.Row{ {100, 1}, }, }, { Name: "set system variable defaults", SetUpScript: []string{ "set @@auto_increment_increment = 100, sql_select_limit = 1", "set @@auto_increment_increment = default, sql_select_limit = default", }, Query: "SELECT @@auto_increment_increment, @@sql_select_limit", Expected: []sql.Row{ {1, math.MaxInt32}, }, }, { Name: "set system variable ON / OFF", SetUpScript: []string{ "set @@autocommit = ON, sql_mode = \"\"", }, Query: "SELECT @@autocommit, @@session.sql_mode", Expected: []sql.Row{ {1, ""}, }, }, { Name: "set system variable ON / OFF", SetUpScript: []string{ "set @@autocommit = ON, session sql_mode = \"\"", }, Query: "SELECT @@autocommit, @@session.sql_mode", Expected: []sql.Row{ {1, ""}, }, }, { Name: "set system variable sql_mode to ANSI for session", SetUpScript: []string{ "set SESSION sql_mode = 'ANSI'", }, Query: "SELECT @@session.sql_mode", Expected: []sql.Row{ {"ANSI"}, }, }, { Name: "set system variable true / false quoted", SetUpScript: []string{ `set @@autocommit = "true", default_table_encryption = "false"`, }, Query: "SELECT @@autocommit, @@session.default_table_encryption", Expected: []sql.Row{ {1, 0}, }, }, { Name: "set system variable true / false", SetUpScript: []string{ `set @@autocommit = true, default_table_encryption = false`, }, Query: "SELECT @@autocommit, @@session.default_table_encryption", Expected: []sql.Row{ {1, 0}, }, }, { Name: "set system variable with expressions", SetUpScript: []string{ `set lc_messages = '123', @@auto_increment_increment = 1`, `set lc_messages = concat(@@lc_messages, '456'), @@auto_increment_increment = @@auto_increment_increment + 3`, }, Query: "SELECT @@lc_messages, @@auto_increment_increment", Expected: []sql.Row{ {"123456", 4}, }, }, { Name: "set system variable to another system variable", SetUpScript: []string{ `set @@auto_increment_increment = 123`, `set @@sql_select_limit = @@auto_increment_increment`, }, Query: "SELECT @@sql_select_limit", Expected: []sql.Row{ {123}, }, }, { Name: "set names", SetUpScript: []string{ `set names utf8mb4`, }, Query: "SELECT @@character_set_client, @@character_set_connection, @@character_set_results", Expected: []sql.Row{ {"utf8mb4", "utf8mb4", "utf8mb4"}, }, }, { Name: "set names quoted", SetUpScript: []string{ `set NAMES "utf8mb3"`, }, Query: "SELECT @@character_set_client, @@character_set_connection, @@character_set_results", Expected: []sql.Row{ {"utf8mb3", "utf8mb3", "utf8mb3"}, }, }, { Name: "set character set", SetUpScript: []string{ `set character set utf8`, }, Query: "SELECT @@character_set_client, @@character_set_connection, @@character_set_results", Expected: []sql.Row{ {"utf8", "utf8mb4", "utf8"}, }, }, { Name: "set charset", SetUpScript: []string{ `set charset utf8`, }, Query: "SELECT @@character_set_client, @@character_set_connection, @@character_set_results", Expected: []sql.Row{ {"utf8", "utf8mb4", "utf8"}, }, }, { Name: "set charset quoted", SetUpScript: []string{ `set charset 'utf8'`, }, Query: "SELECT @@character_set_client, @@character_set_connection, @@character_set_results", Expected: []sql.Row{ {"utf8", "utf8mb4", "utf8"}, }, }, { Name: "set multiple variables including 'names'", SetUpScript: []string{ "set SESSION sql_mode = 'ANSI'", `SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')), time_zone='+00:00', NAMES utf8mb3 COLLATE utf8mb3_bin;`, }, Query: "SELECT @@sql_mode, @@time_zone, @@character_set_client, @@character_set_connection, @@character_set_results", Expected: []sql.Row{ {"NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI", "+00:00", "utf8mb3", "utf8mb3", "utf8mb3"}, }, }, { Name: "set multiple variables including 'charset'", SetUpScript: []string{ `SET sql_mode=ALLOW_INVALID_DATES, time_zone='+00:00', CHARSET 'utf8'`, }, Query: "SELECT @@sql_mode, @@time_zone, @@character_set_client, @@character_set_connection, @@character_set_results", Expected: []sql.Row{ {"ALLOW_INVALID_DATES", "+00:00", "utf8", "utf8mb4", "utf8"}, }, }, { Name: "set system variable to bareword", SetUpScript: []string{ `set @@sql_mode = ALLOW_INVALID_DATES`, }, Query: "SELECT @@sql_mode", Expected: []sql.Row{ {"ALLOW_INVALID_DATES"}, }, }, { Name: "set system variable to bareword, unqualified", SetUpScript: []string{ `set sql_mode = ALLOW_INVALID_DATES`, }, Query: "SELECT @@sql_mode", Expected: []sql.Row{ {"ALLOW_INVALID_DATES"}, }, }, { Name: "set sql_mode variable from mysqldump", SetUpScript: []string{ `SET sql_mode = 'STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_ENGINE_SUBSTITUTION'`, }, Query: "SELECT @@sql_mode", Expected: []sql.Row{ {"ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,STRICT_ALL_TABLES,STRICT_TRANS_TABLES,TRADITIONAL"}, }, }, { Name: "show variables renders enums after set", SetUpScript: []string{ `set @@sql_mode='ONLY_FULL_GROUP_BY';`, }, Assertions: []ScriptTestAssertion{ { Query: `SHOW VARIABLES LIKE '%sql_mode%'`, Expected: []sql.Row{ {"sql_mode", "ONLY_FULL_GROUP_BY"}, }, }, }, }, { Name: "set user var", SetUpScript: []string{ `set @myvar = "hello"`, }, Query: "SELECT @myvar", Expected: []sql.Row{ {"hello"}, }, }, { Name: "set user var, integer type", SetUpScript: []string{ `set @myvar = 123`, }, Query: "SELECT @myvar", Expected: []sql.Row{ {123}, }, }, { Name: "set user var, floating point", SetUpScript: []string{ `set @myvar = 123.4`, }, Query: "SELECT @myvar", Expected: []sql.Row{ {123.4}, }, }, { Name: "set user var and sys var in same statement", SetUpScript: []string{ `set @myvar = 123.4, @@auto_increment_increment = 1234`, }, Query: "SELECT @myvar, @@auto_increment_increment", Expected: []sql.Row{ {123.4, 1234}, }, }, { Name: "set sys var to user var", SetUpScript: []string{ `set @myvar = 1234`, `set auto_increment_increment = @myvar`, }, Query: "SELECT @myvar, @@auto_increment_increment", Expected: []sql.Row{ {1234, 1234}, }, }, { Name: "local is session", SetUpScript: []string{ `set @@LOCAL.cte_max_recursion_depth = 1234`, }, Query: "SELECT @@SESSION.cte_max_recursion_depth", Expected: []sql.Row{ {1234}, }, }, { Name: "user and system var with same name", SetUpScript: []string{ `set @cte_max_recursion_depth = 55`, `set cte_max_recursion_depth = 77`, }, Query: "SELECT @cte_max_recursion_depth, @@cte_max_recursion_depth", Expected: []sql.Row{ {55, 77}, }, }, { Name: "uninitialized user vars", Assertions: []ScriptTestAssertion{ { Query: "SELECT @doesNotExist;", Expected: []sql.Row{{nil}}, }, { Query: "SELECT @doesNotExist is NULL;", Expected: []sql.Row{{true}}, }, { Query: "SELECT @doesNotExist='';", Expected: []sql.Row{{nil}}, }, { Query: "SELECT @doesNotExist < 123;", Expected: []sql.Row{{nil}}, }, }, }, { Name: "eval string user var", SetUpScript: []string{ "set @stringVar = 'abc'", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT @stringVar='abc'", Expected: []sql.Row{{true}}, }, { Query: "SELECT @stringVar='abcd';", Expected: []sql.Row{{false}}, }, { Query: "SELECT @stringVar=123;", Expected: []sql.Row{{false}}, }, { Query: "SELECT @stringVar is null;", Expected: []sql.Row{{false}}, }, }, }, { Name: "set transaction", Assertions: []ScriptTestAssertion{ { Query: "set transaction isolation level serializable, read only", Expected: []sql.Row{{}}, }, { Query: "select @@transaction_isolation, @@transaction_read_only", Expected: []sql.Row{{"SERIALIZABLE", 1}}, }, { Query: "set transaction read write, isolation level read uncommitted", Expected: []sql.Row{{}}, }, { Query: "select @@transaction_isolation, @@transaction_read_only", Expected: []sql.Row{{"READ-UNCOMMITTED", 0}}, }, { Query: "set transaction isolation level read committed", Expected: []sql.Row{{}}, }, { Query: "select @@transaction_isolation", Expected: []sql.Row{{"READ-COMMITTED"}}, }, { Query: "set transaction isolation level repeatable read", Expected: []sql.Row{{}}, }, { Query: "select @@transaction_isolation", Expected: []sql.Row{{"REPEATABLE-READ"}}, }, { Query: "set session transaction isolation level serializable, read only", Expected: []sql.Row{{}}, }, { Query: "select @@transaction_isolation, @@transaction_read_only", Expected: []sql.Row{{"SERIALIZABLE", 1}}, }, { Query: "set global transaction read write, isolation level read uncommitted", Expected: []sql.Row{{}}, }, { Query: "select @@transaction_isolation, @@transaction_read_only", Expected: []sql.Row{{"SERIALIZABLE", 1}}, }, { Query: "select @@global.transaction_isolation, @@global.transaction_read_only", Expected: []sql.Row{{"READ-UNCOMMITTED", 0}}, }, }, }, }
var VersionedQueries = []QueryTest{ { Query: "SELECT * FROM myhistorytable AS OF '2019-01-01' AS foo ORDER BY i", Expected: []sql.Row{ {int64(1), "first row, 1"}, {int64(2), "second row, 1"}, {int64(3), "third row, 1"}, }, }, { Query: "SELECT * FROM myhistorytable AS OF '2019-01-02' foo ORDER BY i", Expected: []sql.Row{ {int64(1), "first row, 2"}, {int64(2), "second row, 2"}, {int64(3), "third row, 2"}, }, }, { Query: "SELECT * FROM myhistorytable AS OF GREATEST('2019-01-02','2019-01-01','') foo ORDER BY i", Expected: []sql.Row{ {int64(1), "first row, 2"}, {int64(2), "second row, 2"}, {int64(3), "third row, 2"}, }, }, { Query: "SELECT * FROM myhistorytable ORDER BY i", Expected: []sql.Row{ {int64(1), "first row, 3", "1"}, {int64(2), "second row, 3", "2"}, {int64(3), "third row, 3", "3"}, }, }, { Query: "SHOW TABLES AS OF '2019-01-02' LIKE 'myhistorytable'", Expected: []sql.Row{ {"myhistorytable"}, }, }, { Query: "SHOW TABLES FROM mydb AS OF '2019-01-02' LIKE 'myhistorytable'", Expected: []sql.Row{ {"myhistorytable"}, }, }, { Query: "SHOW CREATE TABLE myhistorytable as of '2019-01-02'", Expected: []sql.Row{ {"myhistorytable", "CREATE TABLE `myhistorytable` (\n" + " `i` bigint NOT NULL,\n" + " `s` text NOT NULL,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "SHOW CREATE TABLE myhistorytable as of '2019-01-03'", Expected: []sql.Row{ {"myhistorytable", "CREATE TABLE `myhistorytable` (\n" + " `i` bigint NOT NULL,\n" + " `s` text NOT NULL,\n" + " `c` text NOT NULL,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, }
var VersionedScripts = []ScriptTest{ { Name: "user var for AS OF expression", SetUpScript: []string{ "SET @rev1 = '2019-01-01', @rev2 = '2019-01-02'", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM myhistorytable AS OF @rev1 AS foo ORDER BY i", Expected: []sql.Row{ {int64(1), "first row, 1"}, {int64(2), "second row, 1"}, {int64(3), "third row, 1"}, }, }, { Query: "SELECT * FROM myhistorytable AS OF @rev2 AS foo ORDER BY i", Expected: []sql.Row{ {int64(1), "first row, 2"}, {int64(2), "second row, 2"}, {int64(3), "third row, 2"}, }, }, { Query: "SHOW TABLES AS OF @rev1 LIKE 'myhistorytable'", Expected: []sql.Row{ {"myhistorytable"}, }, }, { Query: "DESCRIBE myhistorytable AS OF '2019-01-02'", Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", "NULL", ""}, {"s", "text", "NO", "", "NULL", ""}, }, }, { Query: "DESCRIBE myhistorytable AS OF '2019-01-03'", Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", "NULL", ""}, {"s", "text", "NO", "", "NULL", ""}, {"c", "text", "NO", "", "NULL", ""}, }, }, }, }, }
var VersionedViewTests = []QueryTest{ { Query: "SELECT * FROM myview1 ORDER BY i", Expected: []sql.Row{ sql.NewRow(int64(1), "first row, 3", "1"), sql.NewRow(int64(2), "second row, 3", "2"), sql.NewRow(int64(3), "third row, 3", "3"), }, }, { Query: "SELECT t.* FROM myview1 AS t ORDER BY i", Expected: []sql.Row{ sql.NewRow(int64(1), "first row, 3", "1"), sql.NewRow(int64(2), "second row, 3", "2"), sql.NewRow(int64(3), "third row, 3", "3"), }, }, { Query: "SELECT t.i FROM myview1 AS t ORDER BY i", Expected: []sql.Row{ sql.NewRow(int64(1)), sql.NewRow(int64(2)), sql.NewRow(int64(3)), }, }, { Query: "SELECT * FROM myview1 AS OF '2019-01-01' ORDER BY i", Expected: []sql.Row{ sql.NewRow(int64(1), "first row, 1"), sql.NewRow(int64(2), "second row, 1"), sql.NewRow(int64(3), "third row, 1"), }, }, { Query: "SELECT * FROM myview2", Expected: []sql.Row{ sql.NewRow(int64(1), "first row, 3", "1"), }, }, { Query: "SELECT i FROM myview2", Expected: []sql.Row{ sql.NewRow(int64(1)), }, }, { Query: "SELECT myview2.i FROM myview2", Expected: []sql.Row{ sql.NewRow(int64(1)), }, }, { Query: "SELECT myview2.* FROM myview2", Expected: []sql.Row{ sql.NewRow(int64(1), "first row, 3", "1"), }, }, { Query: "SELECT t.* FROM myview2 as t", Expected: []sql.Row{ sql.NewRow(int64(1), "first row, 3", "1"), }, }, { Query: "SELECT t.i FROM myview2 as t", Expected: []sql.Row{ sql.NewRow(int64(1)), }, }, { Query: "SELECT * FROM myview2 AS OF '2019-01-01'", Expected: []sql.Row{ sql.NewRow(int64(1), "first row, 1"), }, }, { Query: "SELECT * FROM myview3 AS OF '2019-01-01'", Expected: []sql.Row{ {"1"}, {"2"}, {"3"}, {"first row, 1"}, {"second row, 1"}, {"third row, 1"}, }, }, { Query: "SELECT * FROM myview3 AS OF '2019-01-02'", Expected: []sql.Row{ {"1"}, {"2"}, {"3"}, {"first row, 2"}, {"second row, 2"}, {"third row, 2"}, }, }, { Query: "SELECT * FROM myview3 AS OF '2019-01-03'", Expected: []sql.Row{ {"1"}, {"2"}, {"3"}, {"first row, 3"}, {"second row, 3"}, {"third row, 3"}, }, }, { Query: "SELECT * FROM myview4 AS OF '2019-01-01'", Expected: []sql.Row{ {1, "first row, 1"}, }, }, { Query: "SELECT * FROM myview4 AS OF '2019-01-02'", Expected: []sql.Row{ {2, "second row, 2"}, }, }, { Query: "SELECT * FROM myview4 AS OF '2019-01-03'", Expected: []sql.Row{ {3, "third row, 3", "3"}, }, }, { Query: "SELECT * FROM myview5 AS OF '2019-01-01'", Expected: []sql.Row{ {1, "first row, 1"}, }, }, { Query: "SELECT * FROM myview5 AS OF '2019-01-02'", Expected: []sql.Row{ {2, "second row, 2"}, }, }, { Query: "SELECT * FROM myview5 AS OF '2019-01-03'", Expected: []sql.Row{ {3, "third row, 3", "3"}, }, }, { Query: "select * from information_schema.views where table_schema = 'mydb'", Expected: []sql.Row{ sql.NewRow("def", "mydb", "myview", "SELECT * FROM mytable", "NONE", "YES", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"), sql.NewRow("def", "mydb", "myview1", "SELECT * FROM myhistorytable", "NONE", "YES", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"), sql.NewRow("def", "mydb", "myview2", "SELECT * FROM myview1 WHERE i = 1", "NONE", "YES", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"), sql.NewRow("def", "mydb", "myview3", "SELECT i from myview1 union select s from myhistorytable", "NONE", "YES", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"), sql.NewRow("def", "mydb", "myview4", "SELECT * FROM myhistorytable where i in (select distinct cast(RIGHT(s, 1) as signed) from myhistorytable)", "NONE", "NO", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"), sql.NewRow("def", "mydb", "myview5", "SELECT * FROM (select * from myhistorytable where i in (select distinct cast(RIGHT(s, 1) as signed))) as sq", "NONE", "NO", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"), }, }, { Query: "select table_name from information_schema.tables where table_schema = 'mydb' and table_type = 'VIEW' order by 1", Expected: []sql.Row{ sql.NewRow("myview"), sql.NewRow("myview1"), sql.NewRow("myview2"), sql.NewRow("myview3"), sql.NewRow("myview4"), sql.NewRow("myview5"), }, }, }
var ViewScripts = []ScriptTest{ { Name: "check view with escaped strings", SetUpScript: []string{ `CREATE TABLE strs ( id int NOT NULL AUTO_INCREMENT, str varchar(15) NOT NULL, PRIMARY KEY (id));`, `CREATE VIEW quotes AS SELECT * FROM strs WHERE str IN ('joe''s', "jan's", 'mia\\''s', 'bob\'s' );`, `INSERT INTO strs VALUES (0,"joe's");`, `INSERT INTO strs VALUES (0,"mia\\'s");`, `INSERT INTO strs VALUES (0,"bob's");`, `INSERT INTO strs VALUES (0,"joe's");`, `INSERT INTO strs VALUES (0,"notInView");`, `INSERT INTO strs VALUES (0,"jan's");`, }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * from quotes order by id", Expected: []sql.Row{ {1, "joe's"}, {2, "mia\\'s"}, {3, "bob's"}, {4, "joe's"}, {6, "jan's"}}, }, }, }, }
var ViewTests = []QueryTest{ { Query: "SELECT * FROM myview ORDER BY i", Expected: []sql.Row{ sql.NewRow(int64(1), "first row"), sql.NewRow(int64(2), "second row"), sql.NewRow(int64(3), "third row"), }, }, { Query: "SELECT myview.* FROM myview ORDER BY i", Expected: []sql.Row{ sql.NewRow(int64(1), "first row"), sql.NewRow(int64(2), "second row"), sql.NewRow(int64(3), "third row"), }, }, { Query: "SELECT i FROM myview ORDER BY i", Expected: []sql.Row{ sql.NewRow(int64(1)), sql.NewRow(int64(2)), sql.NewRow(int64(3)), }, }, { Query: "SELECT t.* FROM myview AS t ORDER BY i", Expected: []sql.Row{ sql.NewRow(int64(1), "first row"), sql.NewRow(int64(2), "second row"), sql.NewRow(int64(3), "third row"), }, }, { Query: "SELECT t.i FROM myview AS t ORDER BY i", Expected: []sql.Row{ sql.NewRow(int64(1)), sql.NewRow(int64(2)), sql.NewRow(int64(3)), }, }, { Query: "SELECT * FROM myview2", Expected: []sql.Row{ sql.NewRow(int64(1), "first row"), }, }, { Query: "SELECT i FROM myview2", Expected: []sql.Row{ sql.NewRow(int64(1)), }, }, { Query: "SELECT myview2.i FROM myview2", Expected: []sql.Row{ sql.NewRow(int64(1)), }, }, { Query: "SELECT myview2.* FROM myview2", Expected: []sql.Row{ sql.NewRow(int64(1), "first row"), }, }, { Query: "SELECT t.* FROM myview2 as t", Expected: []sql.Row{ sql.NewRow(int64(1), "first row"), }, }, { Query: "SELECT t.i FROM myview2 as t", Expected: []sql.Row{ sql.NewRow(int64(1)), }, }, { Query: "select * from information_schema.views where table_schema = 'mydb' order by table_name", Expected: []sql.Row{ sql.NewRow("def", "mydb", "myview", "SELECT * FROM mytable", "NONE", "YES", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"), sql.NewRow("def", "mydb", "myview2", "SELECT * FROM myview WHERE i = 1", "NONE", "YES", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"), }, }, { Query: "select table_name from information_schema.tables where table_schema = 'mydb' and table_type = 'VIEW' order by 1", Expected: []sql.Row{ sql.NewRow("myview"), sql.NewRow("myview2"), }, }, }
Functions ¶
func MustParseTime ¶ added in v0.17.0
Types ¶
type CharsetCollationEngineTest ¶ added in v0.14.0
type CharsetCollationEngineTest struct { Name string SetUpScript []string Queries []CharsetCollationEngineTestQuery }
CharsetCollationEngineTest is used to test character sets.
type CharsetCollationEngineTestQuery ¶ added in v0.14.0
type CharsetCollationEngineTestQuery struct { Query string Expected []sql.Row Error bool ErrKind *errors.Kind }
CharsetCollationEngineTestQuery is a query within a CharsetCollationEngineTest. If `Error` is true but `ErrKind` is nil, then just tests that an error has occurred. If `ErrKind` is not nil, then tests that an error is returned and matches the stated kind (has higher precedence than the `Error` field). Only checks the `Expected` rows when both `Error` and `ErrKind` are nil.
type CharsetCollationWireTest ¶ added in v0.14.0
type CharsetCollationWireTest struct { Name string SetUpScript []string Queries []CharsetCollationWireTestQuery }
CharsetCollationWireTest is used to test character sets.
type CharsetCollationWireTestQuery ¶ added in v0.14.0
CharsetCollationWireTestQuery is a query within a CharsetCollationWireTest.
type CollationCoercionTest ¶ added in v0.15.0
type CollationCoercionTest struct { Parameters string Collation sql.CollationID Coercibility int64 Error bool }
CollationCoercionTest is used to test the resulting collation and coercion of a SQL expression
type GenericErrorQueryTest ¶
type GenericErrorQueryTest struct { Name string Query string Bindings map[string]sql.Expression }
GenericErrorQueryTest is a query test that is used to assert an error occurs for some query, without specifying what the error was.
type NoopPlaintextPlugin ¶ added in v0.14.0
type NoopPlaintextPlugin struct{}
NoopPlaintextPlugin is used to authenticate plaintext user plugins
type ParallelismTest ¶ added in v0.17.0
type QueryErrorTest ¶
type QueryErrorTest struct { Query string Bindings map[string]*query.BindVariable ExpectedErr *errors.Kind ExpectedErrStr string }
type QueryPlanTest ¶
type QuickPrivilegeTest ¶
type QuickPrivilegeTest struct { Queries []string Expected []sql.Row ExpectedErr *errors.Kind ExpectingErr bool }
QuickPrivilegeTest specifically tests privileges on a predefined user (tester@localhost) using predefined tables and databases. Every test here can easily be represented by a UserPrivilegeTest, however this is intended to test specific privileges at a large scale, meaning there may be thousands of these tests, and hence the test data should be as small as possible.
All queries will be run as a root user with full privileges (intended for setup), with the last query running as the testing user (tester@localhost). For example, the first query may grant a SELECT privilege, while the second query is the SELECT query. Of note, the current database as set by the context is retained when switching from the root user to the test user. This does not mean that the test user automatically gains access to the database, but this is used for any queries that (incorrectly) only work with the current database.
ExpectingErr should be set when an error is expected, and it does not matter what the error is so long that it is one of the errors related to privilege checking (meaning a failed INSERT due to a missing column is NOT caught). If ExpectingErr is set and an error is given to ExpectedErr, then it is enforced that the error matches. However, if ExpectingErr is set and ExpectedErr is nil, then any privilege checking error will match.
Expected makes a distinction between the nil value and the empty value. A nil value means that we do not care about the result, only that it did not error (unless one of the error-asserting fields are set). A non-nil value asserts that the returned value matches our Expected value. If the returned value is nil, then we make a special case to match the non-nil empty row with it, due to the aforementioned distinction.
Statements that are run before every test (the state that all tests start with): CREATE TABLE mydb.test (pk BIGINT PRIMARY KEY, v1 BIGINT); CREATE TABLE mydb.test2 (pk BIGINT PRIMARY KEY, v1 BIGINT); CREATE TABLE otherdb.test (pk BIGINT PRIMARY KEY, v1 BIGINT); CREATE TABLE otherdb.test2 (pk BIGINT PRIMARY KEY, v1 BIGINT); INSERT INTO mydb.test VALUES (0, 0), (1, 1); INSERT INTO mydb.test2 VALUES (0, 1), (1, 2); INSERT INTO otherdb.test VALUES (1, 1), (2, 2); INSERT INTO otherdb.test2 VALUES (1, 1), (2, 2);
type ScriptTest ¶
type ScriptTest struct { // Name of the script test Name string // The sql statements to execute as setup, in order. Results are not checked, but statements must not error. SetUpScript []string // The set of assertions to make after setup, in order Assertions []ScriptTestAssertion // For tests that make a single assertion, Query can be set for the single assertion Query string // For tests that make a single assertion, Expected can be set for the single assertion Expected []sql.Row // For tests that make a single assertion, ExpectedErr can be set for the expected error ExpectedErr *errors.Kind // For tests that make a single assertion, ExpectedIndexes can be set for the string representation of indexes that we expect to appear in the query plan ExpectedIndexes []string // SkipPrepared is true when we skip a test for prepared statements only SkipPrepared bool }
type ScriptTestAssertion ¶
type ScriptTestAssertion struct { Query string Expected []sql.Row ExpectedErr *errors.Kind // ExpectedErrStr should be set for tests that expect a specific error string this is not linked to a custom error. // In most cases, errors should be linked to a custom error, however there are exceptions where this is not possible, // such as the use of the SIGNAL statement. ExpectedErrStr string // ExpectedWarning contains the expected warning code when a query generates warnings but not errors. ExpectedWarning int // ExpectedWarningsCount is used to test the expected number of warnings generated by a query. // The ExpectedWarning field must be set for warning counts to be checked. ExpectedWarningsCount int // ExpectedWarningMessageSubstring is used to test the contents of warning messages generated by a // query. The ExpectedWarning field must be set for warning messages to be checked. ExpectedWarningMessageSubstring string // ExpectedColumns indicates the Name and Type of the columns expected; no other schema fields are tested. ExpectedColumns sql.Schema // The string representation of indexes that we expect to appear in the query plan ExpectedIndexes []string // SkipResultsCheck is used to skip assertions on expected Rows returned from a query. This should be used // sparingly, such as in cases where you only want to test warning messages. SkipResultsCheck bool // Skip is used to completely skip a test, not execute its query at all, and record it as a skipped test // in the test suite results. Skip bool // Bindings are variable mappings only used for prepared tests Bindings map[string]*querypb.BindVariable }
type ServerAuthenticationTest ¶
type ServerAuthenticationTest struct { Name string SetUpFunc func(ctx *sql.Context, t *testing.T, engine *sqle.Engine) SetUpScript []string Assertions []ServerAuthenticationTestAssertion }
ServerAuthenticationTest is used to define a test on the server authentication system. These tests always have the root account available, and the root account is used with any queries in the SetUpScript. The SetUpFunc is run before the SetUpScript.
type ServerAuthenticationTestAssertion ¶
type ServerAuthenticationTestAssertion struct { Username string Password string Query string ExpectedErr bool ExpectedErrKind *errors.Kind ExpectedErrStr string }
ServerAuthenticationTestAssertion is within a ServerAuthenticationTest to assert functionality.
type TransactionTest ¶
type TransactionTest struct { // Name of the script test Name string // The sql statements to execute as setup, in order. Results are not checked, but statements must not error. // Setup scripts are run as a distinct client separate from the client used in any assertions. SetUpScript []string // The set of assertions to make after setup, in order // The transaction test runner augments the ScriptTest runner by allowing embedding of a client string in a query // comment to name the client running the query, like so: // /* client a */ select * from myTable Assertions []ScriptTestAssertion }
TransactionTest is a script to test transaction correctness. It's similar to ScriptTest, but its assertions name clients that participate
type TypeWireTest ¶
TypeWireTest is used to ensure that types are properly represented over the wire (vs being directly returned from the engine).
type UserPrivilegeTest ¶
type UserPrivilegeTest struct { Name string SetUpScript []string Assertions []UserPrivilegeTestAssertion }
UserPrivilegeTest is used to define a test on the user and privilege systems. These tests always have the root account available, and the root account is used with any queries in the SetUpScript.
type UserPrivilegeTestAssertion ¶
type UserPrivilegeTestAssertion struct { User string Host string Query string Expected []sql.Row ExpectedErr *errors.Kind ExpectedErrStr string }
UserPrivilegeTestAssertion is within a UserPrivilegeTest to assert functionality.
type WriteQueryTest ¶
type WriteQueryTest struct { WriteQuery string ExpectedWriteResult []sql.Row SelectQuery string ExpectedSelect []sql.Row Bindings map[string]*query.BindVariable }
WriteQueryTest is a query test for INSERT, UPDATE, etc. statements. It has a query to run and a select query to validate the results.
Source Files ¶
- alter_table_queries.go
- ansi_quotes_queries.go
- blob_queries.go
- call_asof_queries.go
- charset_collation_engine.go
- charset_collation_wire.go
- check_scripts.go
- collation_coercion.go
- column_alias_queries.go
- convert_queries.go
- create_table_queries.go
- delete_queries.go
- derived_table_outer_scope_visibility_queries.go
- event_queries.go
- external_procedure_queries.go
- foreign_key_queries.go
- fulltext_queries.go
- generated_columns.go
- index_queries.go
- index_query_plans.go
- information_schema_queries.go
- insert_queries.go
- join_queries.go
- json_scripts.go
- json_table_queries.go
- load_queries.go
- mysql_db_queries.go
- null_range_tests.go
- order_by_group_by_queries.go
- ordinal_ddl_queries.go
- parallelism.go
- priv_auth_queries.go
- procedure_queries.go
- queries.go
- query_plans.go
- regex_queries.go
- replace_queries.go
- script_queries.go
- table_func_scripts.go
- transaction_queries.go
- trigger_queries.go
- type_wire_queries.go
- update_queries.go
- variable_queries.go
- view_queries.go