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 StatsPlanTest
- type TransactionTest
- type TypeWireTest
- type UserPrivilegeTest
- type UserPrivilegeTestAssertion
- type WriteQueryTest
Constants ¶
This section is empty.
Variables ¶
var AddColumnScripts = []ScriptTest{ { Name: "column at end with default", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable ADD COLUMN i2 INT COMMENT 'hello' default 42", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable", Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "UNI", nil, "", "", "column s"}, {"i2", "int", nil, "YES", "", "42", "", "", "hello"}, }, }, { Query: "SELECT * FROM mytable ORDER BY i;", Expected: []sql.Row{ sql.NewRow(int64(1), "first row", int32(42)), sql.NewRow(int64(2), "second row", int32(42)), sql.NewRow(int64(3), "third row", int32(42)), }, }, }, }, { Name: "in middle, no default", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable ADD COLUMN s2 TEXT COMMENT 'hello' AFTER i;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable", Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"s2", "text", "utf8mb4_0900_bin", "YES", "", nil, "", "", "hello"}, {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "UNI", nil, "", "", "column s"}, {"i2", "int", nil, "YES", "", "42", "", "", "hello"}, }, }, { Query: "SELECT * FROM mytable ORDER BY i;", Expected: []sql.Row{ sql.NewRow(int64(1), nil, "first row", int32(42)), sql.NewRow(int64(2), nil, "second row", int32(42)), sql.NewRow(int64(3), nil, "third row", int32(42)), }, }, { Query: "insert into mytable values (4, 's2', 'fourth row', 11);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "update mytable set s2 = 'updated s2' where i2 = 42;", Expected: []sql.Row{{types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}}, }, { Query: "SELECT * FROM mytable ORDER BY i;", Expected: []sql.Row{ sql.NewRow(int64(1), "updated s2", "first row", int32(42)), sql.NewRow(int64(2), "updated s2", "second row", int32(42)), sql.NewRow(int64(3), "updated s2", "third row", int32(42)), sql.NewRow(int64(4), "s2", "fourth row", int32(11)), }, }, }, }, { Name: "first with default", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable ADD COLUMN s3 VARCHAR(25) COMMENT 'hello' default 'yay' FIRST", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable", Expected: []sql.Row{ {"s3", "varchar(25)", "utf8mb4_0900_bin", "YES", "", "'yay'", "", "", "hello"}, {"i", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"s2", "text", "utf8mb4_0900_bin", "YES", "", nil, "", "", "hello"}, {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "UNI", nil, "", "", "column s"}, {"i2", "int", nil, "YES", "", "42", "", "", "hello"}, }, }, { Query: "SELECT * FROM mytable ORDER BY i;", Expected: []sql.Row{ sql.NewRow("yay", int64(1), "updated s2", "first row", int32(42)), sql.NewRow("yay", int64(2), "updated s2", "second row", int32(42)), sql.NewRow("yay", int64(3), "updated s2", "third row", int32(42)), sql.NewRow("yay", int64(4), "s2", "fourth row", int32(11)), }, }, }, }, { Name: "middle, no default, non null", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable ADD COLUMN s4 VARCHAR(1) not null after s3", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable", Expected: []sql.Row{ {"s3", "varchar(25)", "utf8mb4_0900_bin", "YES", "", "'yay'", "", "", "hello"}, {"s4", "varchar(1)", "utf8mb4_0900_bin", "NO", "", nil, "", "", ""}, {"i", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"s2", "text", "utf8mb4_0900_bin", "YES", "", nil, "", "", "hello"}, {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "UNI", nil, "", "", "column s"}, {"i2", "int", nil, "YES", "", "42", "", "", "hello"}, }, }, { Query: "SELECT * FROM mytable ORDER BY i;", Expected: []sql.Row{ sql.NewRow("yay", "", int64(1), "updated s2", "first row", int32(42)), sql.NewRow("yay", "", int64(2), "updated s2", "second row", int32(42)), sql.NewRow("yay", "", int64(3), "updated s2", "third row", int32(42)), sql.NewRow("yay", "", int64(4), "s2", "fourth row", int32(11)), }, }, }, }, { Name: "multiple in one statement", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable ADD COLUMN s5 VARCHAR(26), ADD COLUMN s6 VARCHAR(27)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable", Expected: []sql.Row{ {"s3", "varchar(25)", "utf8mb4_0900_bin", "YES", "", "'yay'", "", "", "hello"}, {"s4", "varchar(1)", "utf8mb4_0900_bin", "NO", "", nil, "", "", ""}, {"i", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"s2", "text", "utf8mb4_0900_bin", "YES", "", nil, "", "", "hello"}, {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "UNI", nil, "", "", "column s"}, {"i2", "int", nil, "YES", "", "42", "", "", "hello"}, {"s5", "varchar(26)", "utf8mb4_0900_bin", "YES", "", nil, "", "", ""}, {"s6", "varchar(27)", "utf8mb4_0900_bin", "YES", "", nil, "", "", ""}, }, }, { Query: "SELECT * FROM mytable ORDER BY i;", Expected: []sql.Row{ sql.NewRow("yay", "", int64(1), "updated s2", "first row", int32(42), nil, nil), sql.NewRow("yay", "", int64(2), "updated s2", "second row", int32(42), nil, nil), sql.NewRow("yay", "", int64(3), "updated s2", "third row", int32(42), nil, nil), sql.NewRow("yay", "", int64(4), "s2", "fourth row", int32(11), nil, nil), }, }, }, }, { Name: "error cases", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE not_exist ADD COLUMN i2 INT COMMENT 'hello'", ExpectedErr: sql.ErrTableNotFound, }, { Query: "ALTER TABLE mytable ADD COLUMN b BIGINT COMMENT 'ok' AFTER not_exist", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE mytable ADD COLUMN i BIGINT COMMENT 'ok'", ExpectedErr: sql.ErrColumnExists, }, { Query: "ALTER TABLE mytable ADD COLUMN b INT NOT NULL DEFAULT 'yes'", ExpectedErr: sql.ErrIncompatibleDefaultType, }, { Query: "ALTER TABLE mytable ADD COLUMN c int, add c int", ExpectedErr: sql.ErrColumnExists, }, }, }, }
var AddDropPrimaryKeyScripts = []ScriptTest{ { Name: "Add primary key", SetUpScript: []string{ "create table t1 (i int, j int)", "insert into t1 values (1,1), (1,2), (1,3)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 add primary key (i)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `i` int,\n" + " `j` int\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "alter table t1 add primary key (i, j)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `i` int NOT NULL,\n" + " `j` int NOT NULL,\n" + " PRIMARY KEY (`i`,`j`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "Drop primary key for table with multiple primary key columns", SetUpScript: []string{ "create table t1 (pk varchar(20), v varchar(20) default (concat(pk, '-foo')), primary key (pk, v))", "insert into t1 values ('a1', 'a2'), ('a2', 'a3'), ('a3', 'a4')", }, Assertions: []ScriptTestAssertion{ { Query: "select * from t1 order by pk", Expected: []sql.Row{ {"a1", "a2"}, {"a2", "a3"}, {"a3", "a4"}, }, }, { Query: "alter table t1 drop primary key", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "select * from t1 order by pk", Expected: []sql.Row{ {"a1", "a2"}, {"a2", "a3"}, {"a3", "a4"}, }, }, { Query: "insert into t1 values ('a1', 'a2')", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 order by pk", Expected: []sql.Row{ {"a1", "a2"}, {"a1", "a2"}, {"a2", "a3"}, {"a3", "a4"}, }, }, { Query: "alter table t1 add primary key (pk, v)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "delete from t1 where pk = 'a1' limit 1", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "alter table t1 add primary key (pk, v)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `pk` varchar(20) NOT NULL,\n" + " `v` varchar(20) NOT NULL DEFAULT (concat(`pk`,'-foo')),\n" + " PRIMARY KEY (`pk`,`v`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "alter table t1 drop primary key", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 add index myidx (v)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 add primary key (pk)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "insert into t1 values ('a4', 'a3')", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `pk` varchar(20) NOT NULL,\n" + " `v` varchar(20) NOT NULL DEFAULT (concat(`pk`,'-foo')),\n" + " PRIMARY KEY (`pk`),\n" + " KEY `myidx` (`v`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select * from t1 where v = 'a3' order by pk", Expected: []sql.Row{ {"a2", "a3"}, {"a4", "a3"}, }, }, { Query: "alter table t1 drop primary key", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "truncate t1", Expected: []sql.Row{{types.NewOkResult(4)}}, }, { Query: "alter table t1 drop index myidx", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 add primary key (pk, v)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "insert into t1 values ('a1', 'a2'), ('a2', 'a3'), ('a3', 'a4')", Expected: []sql.Row{{types.NewOkResult(3)}}, }, }, }, { Name: "Drop primary key for table with multiple primary key columns, add smaller primary key in same statement", SetUpScript: []string{ "create table t1 (pk varchar(20), v varchar(20) default (concat(pk, '-foo')), primary key (pk, v))", "insert into t1 values ('a1', 'a2'), ('a2', 'a3'), ('a3', 'a4')", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY (v)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO t1 (pk, v) values ('a100', 'a3')", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "alter table t1 drop primary key", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t1 ADD PRIMARY KEY (pk, v), DROP PRIMARY KEY", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `pk` varchar(20) NOT NULL,\n" + " `v` varchar(20) NOT NULL DEFAULT (concat(`pk`,'-foo'))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "No database selected", SetUpScript: []string{ "create database newdb", "create table newdb.tab1 (pk int, c1 int)", "ALTER TABLE newdb.tab1 ADD PRIMARY KEY (pk)", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE newdb.tab1", Expected: []sql.Row{{"tab1", "CREATE TABLE `tab1` (\n" + " `pk` int NOT NULL,\n" + " `c1` int,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "alter table newdb.tab1 drop primary key", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW CREATE TABLE newdb.tab1", Expected: []sql.Row{{"tab1", "CREATE TABLE `tab1` (\n" + " `pk` int NOT NULL,\n" + " `c1` int\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "Drop primary key auto increment", SetUpScript: []string{ "CREATE TABLE test(pk int AUTO_INCREMENT PRIMARY KEY, val int)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE test DROP PRIMARY KEY", ExpectedErr: sql.ErrWrongAutoKey, }, { Query: "ALTER TABLE test modify pk int", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW CREATE TABLE test", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n" + " `pk` int NOT NULL,\n" + " `val` int,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "ALTER TABLE test drop primary key", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW CREATE TABLE test", Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n" + " `pk` int NOT NULL,\n" + " `val` int\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "INSERT INTO test VALUES (1, 1), (NULL, 1)", ExpectedErr: sql.ErrInsertIntoNonNullableProvidedNull, }, { Query: "INSERT INTO test VALUES (2, 2), (3, 3)", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "SELECT * FROM test ORDER BY pk", Expected: []sql.Row{ {2, 2}, {3, 3}, }, }, }, }, { Name: "Drop auto-increment primary key with supporting unique index", SetUpScript: []string{ "create table t (id int primary key AUTO_INCREMENT, c1 varchar(255));", "insert into t (c1) values ('one');", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t DROP PRIMARY KEY;", ExpectedErr: sql.ErrWrongAutoKey, }, { Query: "ALTER TABLE t ADD UNIQUE KEY id (id);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t DROP PRIMARY KEY;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t;", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n" + " `id` int NOT NULL AUTO_INCREMENT,\n" + " `c1` varchar(255),\n" + " UNIQUE KEY `id` (`id`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t (c1) values('two');", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 2}}}, }, { Query: "select * from t;", Expected: []sql.Row{{1, "one"}, {2, "two"}}, }, }, }, { Name: "Drop auto-increment primary key with supporting non-unique index", SetUpScript: []string{ "create table t (id int primary key AUTO_INCREMENT, c1 varchar(255));", "insert into t (c1) values ('one');", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t DROP PRIMARY KEY;", ExpectedErr: sql.ErrWrongAutoKey, }, { Query: "ALTER TABLE t ADD KEY id (id);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t DROP PRIMARY KEY;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t;", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n" + " `id` int NOT NULL AUTO_INCREMENT,\n" + " `c1` varchar(255),\n" + " KEY `id` (`id`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t (c1) values('two');", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 2}}}, }, { Query: "select * from t;", Expected: []sql.Row{{1, "one"}, {2, "two"}}, }, }, }, { Name: "Drop multi-column, auto-increment primary key with supporting non-unique index", SetUpScript: []string{ "create table t (id1 int AUTO_INCREMENT, id2 int not null, c1 varchar(255), primary key (id1, id2));", "insert into t (id2, c1) values (-1, 'one');", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t DROP PRIMARY KEY;", ExpectedErr: sql.ErrWrongAutoKey, }, { Query: "ALTER TABLE t ADD KEY c1id1 (c1, id1);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t DROP PRIMARY KEY;", ExpectedErr: sql.ErrWrongAutoKey, }, { Query: "ALTER TABLE t ADD KEY id1c1 (id1, c1);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t DROP PRIMARY KEY;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "insert into t (id2, c1) values(-2, 'two');", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 2}}}, }, { Query: "select * from t;", Expected: []sql.Row{{1, -1, "one"}, {2, -2, "two"}}, }, { Query: "show create table t;", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n" + " `id1` int NOT NULL AUTO_INCREMENT,\n" + " `id2` int NOT NULL,\n" + " `c1` varchar(255),\n" + " KEY `c1id1` (`c1`,`id1`),\n" + " KEY `id1c1` (`id1`,`c1`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, }
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 AUTO_INCREMENT=4 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 AUTO_INCREMENT=4 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 NOT NULL AUTO_INCREMENT,\n" + " PRIMARY KEY (`i`),\n" + " UNIQUE KEY `j` (`j`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=4 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: "multi alter with invalid schemas", SetUpScript: []string{ "CREATE TABLE t(a int primary key)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add column b varchar(16383)", ExpectedErr: analyzererrors.ErrInvalidRowLength, }, { Query: "alter table t add column b varchar(16000), add column c varchar(16000)", ExpectedErr: analyzererrors.ErrInvalidRowLength, }, { Query: "alter table t add column b varchar(16000), add column c varchar(10)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "variety of alter column statements in a single statement", SetUpScript: []string{ "CREATE TABLE t32(pk BIGINT PRIMARY KEY, v1 int, v2 int, v3 int default (v1), toRename int)", `alter table t32 add column v4 int after pk, drop column v2, modify v1 varchar(100) not null, alter column v3 set default 100, rename column toRename to newName`, "CREATE TABLE t32_2(pk BIGINT PRIMARY KEY, v1 int, v2 int, v3 int)", `alter table t32_2 drop v1, add v1 int`, "CREATE TABLE t32_3(pk BIGINT PRIMARY KEY, v1 int, v2 int, v3 int)", `alter table t32_3 rename column v1 to v5, add v1 int`, }, Assertions: []ScriptTestAssertion{ { Query: "SHOW FULL COLUMNS FROM t32", Expected: []sql.Row{ {"pk", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"v4", "int", nil, "YES", "", nil, "", "", ""}, {"v1", "varchar(100)", "utf8mb4_0900_bin", "NO", "", nil, "", "", ""}, {"v3", "int", nil, "YES", "", "100", "", "", ""}, {"newName", "int", nil, "YES", "", nil, "", "", ""}, }, }, { Query: "SHOW FULL COLUMNS FROM t32_2", Expected: []sql.Row{ {"pk", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"v2", "int", nil, "YES", "", nil, "", "", ""}, {"v3", "int", nil, "YES", "", nil, "", "", ""}, {"v1", "int", nil, "YES", "", nil, "", "", ""}, }, }, { Query: "SHOW FULL COLUMNS FROM t32_3", Expected: []sql.Row{ {"pk", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"v5", "int", nil, "YES", "", nil, "", "", ""}, {"v2", "int", nil, "YES", "", nil, "", "", ""}, {"v3", "int", nil, "YES", "", nil, "", "", ""}, {"v1", "int", nil, "YES", "", nil, "", "", ""}, }, }, { Query: "alter table t32 add column vnew int, drop column vnew", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "alter table t32 rename column v3 to v5, drop column v5", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "alter table t32 rename column v3 to v5, drop column v3", ExpectedErr: sql.ErrTableColumnNotFound, }, }, }, { Name: "mix of alter column, add and drop constraints in one statement", 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: "SHOW FULL COLUMNS FROM t33", Expected: []sql.Row{ {"pk", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"v4", "int", nil, "YES", "", nil, "", "", ""}, {"v1", "int", nil, "YES", "", nil, "", "", ""}, }, }, { Query: "SELECT * FROM information_schema.CHECK_CONSTRAINTS", Expected: []sql.Row{ {"def", "mydb", "v1gt0", "(v1 > 0)"}, }, }, }, }, { 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(6), col2 varchar(1000), index idx1 (pk, col1));", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t alter column col2 DROP DEFAULT;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t;", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `pk` int NOT NULL,\n `col1` timestamp(6) DEFAULT CURRENT_TIMESTAMP(6),\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{{types.NewOkResult(0)}}, }, { Query: "show create table t;", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `pk` int NOT NULL,\n `col1` timestamp(6) DEFAULT CURRENT_TIMESTAMP(6),\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 check as part of alter block", SetUpScript: []string{ "create table t42 (i bigint primary key, j int, CONSTRAINT check1 CHECK (j < 12345), CONSTRAINT check2 CHECK (j > 0))", "ALTER TABLE t42 ADD COLUMN s varchar(20), drop check check1", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t42", Expected: []sql.Row{{"t42", "CREATE TABLE `t42` (\n" + " `i` bigint NOT NULL,\n" + " `j` int,\n" + " `s` varchar(20),\n" + " PRIMARY KEY (`i`),\n" + " CONSTRAINT `check2` CHECK ((`j` > 0))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "drop constraint as part of alter block", SetUpScript: []string{ "create table t42 (i bigint primary key, j int, CONSTRAINT check1 CHECK (j < 12345), CONSTRAINT check2 CHECK (j > 0))", "ALTER TABLE t42 ADD COLUMN s varchar(20), drop constraint check1", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t42", Expected: []sql.Row{{"t42", "CREATE TABLE `t42` (\n" + " `i` bigint NOT NULL,\n" + " `j` int,\n" + " `s` varchar(20),\n" + " PRIMARY KEY (`i`),\n" + " CONSTRAINT `check2` CHECK ((`j` > 0))\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", nil, ""}, {"val", "int", "YES", "", nil, ""}, }, }, { 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"}}, }, }, }, { Name: "ALTER TABLE ... ALTER ADD CHECK / DROP CHECK", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 BIGINT NOT NULL DEFAULT 88);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE test ADD CONSTRAINT cx CHECK (v1 < 100)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE test DROP CHECK cx, ADD CHECK (v1 < 50)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO test VALUES (1, 99)", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "INSERT INTO test VALUES (2, 2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, }, }, { Name: "ALTER TABLE AUTO INCREMENT no-ops on table with no original auto increment key", SetUpScript: []string{ "CREATE table test (pk int primary key)", "ALTER TABLE `test` auto_increment = 2;", "INSERT INTO test VALUES (1)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test", Expected: []sql.Row{{1}}, }, }, }, { Name: "ALTER TABLE MODIFY column with UNIQUE KEY", SetUpScript: []string{ "CREATE table test (pk int primary key, uk int unique)", "ALTER TABLE `test` MODIFY column uk int auto_increment", }, Assertions: []ScriptTestAssertion{ { Query: "describe test", Expected: []sql.Row{ {"pk", "int", "NO", "PRI", nil, ""}, {"uk", "int", "NO", "UNI", nil, "auto_increment"}, }, }, }, }, { Name: "ALTER TABLE MODIFY column making UNIQUE", SetUpScript: []string{ "CREATE table test (pk int primary key, uk int)", "ALTER TABLE `test` MODIFY column uk int unique", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO test VALUES (1, 1), (2, 1)", ExpectedErr: sql.ErrUniqueKeyViolation, }, }, }, { Name: "ALTER TABLE MODIFY column with KEY", SetUpScript: []string{ "CREATE table test (pk int primary key, mk int, index (mk))", "ALTER TABLE `test` MODIFY column mk int auto_increment", }, Assertions: []ScriptTestAssertion{ { Query: "describe test", Expected: []sql.Row{ {"pk", "int", "NO", "PRI", nil, ""}, {"mk", "int", "NO", "MUL", nil, "auto_increment"}, }, }, }, }, { Name: "ALTER TABLE AUTO INCREMENT no-ops on table with no original auto increment key", SetUpScript: []string{ "CREATE table test (pk int primary key)", "ALTER TABLE `test` auto_increment = 2;", "INSERT INTO test VALUES (1)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM test", Expected: []sql.Row{{1}}, }, }, }, { Name: "Identifier lengths", SetUpScript: []string{ "create table t1 (a int primary key, b int)", "create table parent (a int primary key)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 rename to abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl rename to t1", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 rename to abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "alter table t1 rename column a to abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 rename column abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl to a", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 rename column a to abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "alter table t1 add constraint abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl check (a > 0)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 add constraint abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm check (a > 0)", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "alter table t1 add constraint abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk0 foreign key(a) references parent(a)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 add constraint abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm foreign key(a) references parent(a)", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "alter table t1 add constraint abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk1 unique key(a)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 add constraint abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm unique key(a)", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "alter table t1 rename index abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk1 to abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk2", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 rename index abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk2 to abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "alter table t1 add column abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk2 int", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 add column abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm int", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "alter table t1 change column abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk2 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk3 int", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 change column abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk3 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm int", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "alter table t1 add index abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk3 (b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t1 add index abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm (b)", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "alter table t1 add column d int, add index abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm (b)", ExpectedErr: sql.ErrInvalidIdentifier, }, }, }, { Name: "Add a column with the same case-insensitive name", SetUpScript: []string{ "create table t1 (abc int primary key, def int)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 add column ABC int", ExpectedErr: sql.ErrColumnExists, }, }, }, { Name: "Prefix index with same columns as another index", SetUpScript: []string{ "CREATE table t (pk int primary key, col1 varchar(100));", "INSERT into t values (1, '100'), (2, '200');", "alter table t add unique index idx1 (col1);", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add index idx2 (col1(10));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t", Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n" + " `pk` int NOT NULL,\n" + " `col1` varchar(100),\n" + " PRIMARY KEY (`pk`),\n" + " UNIQUE KEY `idx1` (`col1`),\n" + " KEY `idx2` (`col1`(10))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "Index case-insensitivity", SetUpScript: []string{ "create table t1 (i int, KEY myIndex1 (`i`))", "create table t2 (i int, KEY myIndex2 (`i`))", "create table t3 (i int, KEY myIndex3 (`i`))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 drop index MYINDEX1;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show indexes from t1;", Expected: []sql.Row{}, }, { Query: "alter table t2 rename index myIndex2 to mySecondIndex;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show indexes from t2;", Expected: []sql.Row{{"t2", 1, "mySecondIndex", 1, "i", nil, 0, nil, nil, "YES", "BTREE", "", "", "YES", nil}}, }, { Query: "alter table t3 rename index MYiNDEX3 to anotherIndex;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show indexes from t3;", Expected: []sql.Row{{"t3", 1, "anotherIndex", 1, "i", nil, 0, nil, nil, "YES", "BTREE", "", "", "YES", nil}}, }, }, }, { Name: "alter column and rename table work within same transaction", SetUpScript: []string{ "create table t (i int)", }, Assertions: []ScriptTestAssertion{ { SkipResultsCheck: true, Query: "start transaction;", }, { SkipResultsCheck: true, Query: "alter table t change i j int", }, { SkipResultsCheck: true, Query: "rename table t to tt", }, { SkipResultsCheck: true, Query: "commit;", }, { Query: "select j from tt;", Expected: []sql.Row{}, }, }, }, }
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"}}, }, }, }, { 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{{types.NewOkResult(0)}}, }, { Query: `show tables;`, Expected: []sql.Row{{"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 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 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 tableWithComment (pk int) COMMENT "'"`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE tableWithComment", ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT=''''"}}, }, { 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`, }, { Query: "SELECT json_depth() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_merge_patch() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_overlaps() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_pretty() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_quote() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_schema_valid() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_schema_validation_report() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_search() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_storage_free() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_storage_size() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_type() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "SELECT json_valid() FROM dual;", ExpectedErr: sql.ErrInvalidArgumentNumber, }, { Query: "select * from othertable join foo.othertable on othertable.text = 'third'", ExpectedErr: sql.ErrUnknownColumn, }, { Query: "select * from foo.othertable join othertable on othertable.text = 'third'", ExpectedErr: sql.ErrUnknownColumn, }, { Query: "select * from mydb.othertable join foo.othertable on othertable.text = 'third'", ExpectedErr: sql.ErrUnknownColumn, }, { Query: "select * from foo.othertable join mydb.othertable on othertable.text = 'third'", ExpectedErr: sql.ErrUnknownColumn, }, }
var BrokenGeneratedColumnTests = []ScriptTest{ { Name: "update a virtual column with a trigger", SetUpScript: []string{ "create table t1 (a int primary key, b int, c int generated always as (a + b) virtual)", "create table t2 (a int primary key)", "create trigger t1insert before update on t1 for each row set new.c = 2", }, Assertions: []ScriptTestAssertion{ { Query: "insert into t1 (a, b) values (1, 2), (3, 4)", ExpectedErr: sql.ErrGeneratedColumnValue, }, }, }, }
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 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: "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: "SELECT json_table() FROM dual;", }, { Query: "SELECT json_value() FROM dual;", }, { Query: "SELECT 1 FROM DUAL WHERE (1, null) in ((1, null))", Expected: []sql.Row{}, }, { Query: "SELECT 1 FROM DUAL WHERE (0, null) = (0, null)", Expected: []sql.Row{}, }, { Query: "SELECT 1 FROM DUAL WHERE (null, null) = (select null, null from dual)", Expected: []sql.Row{}, }, { 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: "SELECT STR_TO_DATE('2013 32 Tuesday', '%X %V %W')", Expected: []sql.Row{{"2013-08-13"}}, }, { Query: `SELECT STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s %f') - (STR_TO_DATE('01,5,2013 09:30:17','%d,%m,%Y %h:%i:%s') - INTERVAL 1 SECOND)`, Expected: []sql.Row{{int64(1)}}, }, { 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 TABLE_NAME, IS_UPDATABLE from information_schema.views where table_schema = 'mydb'", Expected: []sql.Row{{"myview1", "YES"}, {"myview2", "YES"}, {"myview3", "NO"}, {"myview4", "NO"}, {"myview5", "YES"}}, }, { Query: "SELECT json_type(cast(cast('2001-01-01 12:34:56.123456' as time) as json));", Expected: []sql.Row{ {"TIME"}, }, }, { Query: "SELECT json_type(cast(cast('123abc' as binary) as json));", Expected: []sql.Row{ {"BLOB"}, }, }, { Query: `SELECT json_type(json_extract('{"a": 1e2}', '$.a'));`, Expected: []sql.Row{ {"DOUBLE"}, }, }, { Query: `SELECT json_type(json_extract(json_object("a", cast(10 as double)), "$.a"));`, Expected: []sql.Row{ {"DOUBLE"}, }, }, { Query: `SELECT json_type(json_extract(json_object("a", cast(10 as unsigned)), "$.a"));`, Expected: []sql.Row{ {"UNSIGNED INTEGER"}, }, }, { Query: `SELECT json_type(json_extract(json_object("a", cast(10 as signed)), "$.a"));`, Expected: []sql.Row{ {"INTEGER"}, }, }, { Query: `SELECT json_type(json_extract(json_object("a", cast(10 as decimal)), "$.a"));`, Expected: []sql.Row{ {"DECIMAL"}, }, }, }
BrokenQueries are queries that are known to be broken in the engine.
var BrokenScriptTests = []ScriptTest{ { 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", "", nil, ""}, {"v1", "int", "YES", "", nil, ""}, {"v2", "int", "NO", "PRI", nil, ""}, }, }, { 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", "", nil, ""}, {"v1", "int", "YES", "", nil, ""}, {"v2", "int", "NO", "PRI", nil, ""}, }, }, { 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", "", nil, ""}, {"v4", "int", "NO", "", nil, ""}, {"v5", "int", "NO", "", nil, ""}, {"v6", "int", "NO", "", nil, ""}, {"v7", "int", "NO", "", nil, ""}, }, }, }, }, { 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"}}, }, }, }, { Name: "TIMESTAMP type value should be converted from session TZ to UTC TZ to be stored", SetUpScript: []string{ "CREATE TABLE timezone_test (ts TIMESTAMP, dt DATETIME)", "INSERT INTO timezone_test VALUES ('2023-02-14 08:47', '2023-02-14 08:47');", }, Assertions: []ScriptTestAssertion{ { Query: "SET SESSION time_zone = '-05:00';", Expected: []sql.Row{{}}, }, { Query: "SELECT DATE_FORMAT(ts, '%H:%i:%s'), DATE_FORMAT(dt, '%H:%i:%s') from timezone_test;", Expected: []sql.Row{{"11:47:00", "08:47:00"}}, }, { Query: "SELECT UNIX_TIMESTAMP(ts), UNIX_TIMESTAMP(dt) from timezone_test;", Expected: []sql.Row{{float64(1676393220), float64(1676382420)}}, }, }, }, }
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: "SET validates character set and collation variables", Queries: []CharsetCollationEngineTestQuery{ { Query: "SET character_set_client = 'am_i_wrong';", ErrKind: sql.ErrCharSetUnknown, }, { Query: "SET character_set_connection = 'to_believe';", ErrKind: sql.ErrCharSetUnknown, }, { Query: "SET character_set_results = 'in_crusty_cheese';", ErrKind: sql.ErrCharSetUnknown, }, { Query: "SET collation_connection = 'is_it_wrong';", ErrKind: sql.ErrCollationUnknown, }, { Query: "SET collation_database = 'to_believe';", ErrKind: sql.ErrCollationUnknown, }, { Query: "SET collation_server = 'in_deez';", ErrKind: sql.ErrCollationUnknown, }, { Query: "SET NAMES things;", ErrKind: sql.ErrCharSetUnknown, }, }, }, { Name: "setting charset/collation sets the other", Queries: []CharsetCollationEngineTestQuery{ { Query: "select @@session.character_set_connection, @@session.collation_connection;", Expected: []sql.Row{ {"utf8mb4", "utf8mb4_0900_bin"}, }, }, { Query: "set @@session.character_set_connection = 'latin1';", Expected: []sql.Row{{}}, }, { Query: "select @@session.character_set_connection, @@session.collation_connection;", Expected: []sql.Row{ {"latin1", "latin1_swedish_ci"}, }, }, { Query: "set @@session.collation_connection = 'utf8mb4_0900_bin';", Expected: []sql.Row{{}}, }, { Query: "select @@session.character_set_connection, @@session.collation_connection;", Expected: []sql.Row{ {"utf8mb4", "utf8mb4_0900_bin"}, }, }, { Query: "select @@global.character_set_connection, @@global.collation_connection;", Expected: []sql.Row{ {"utf8mb4", "utf8mb4_0900_bin"}, }, }, { Query: "set @@global.character_set_connection = 'latin1';", Expected: []sql.Row{{}}, }, { Query: "select @@global.character_set_connection, @@global.collation_connection;", Expected: []sql.Row{ {"latin1", "latin1_swedish_ci"}, }, }, { Query: "set @@global.collation_connection = 'utf8mb4_0900_bin';", Expected: []sql.Row{{}}, }, { Query: "select @@global.character_set_connection, @@global.collation_connection;", Expected: []sql.Row{ {"utf8mb4", "utf8mb4_0900_bin"}, }, }, { Query: "select @@session.character_set_server, @@session.collation_server;", Expected: []sql.Row{ {"utf8mb4", "utf8mb4_0900_bin"}, }, }, { Query: "set @@session.character_set_server = 'latin1';", Expected: []sql.Row{{}}, }, { Query: "select @@session.character_set_server, @@session.collation_server;", Expected: []sql.Row{ {"latin1", "latin1_swedish_ci"}, }, }, { Query: "set @@session.collation_server = 'utf8mb4_0900_bin';", Expected: []sql.Row{{}}, }, { Query: "select @@session.character_set_server, @@session.collation_server;", Expected: []sql.Row{ {"utf8mb4", "utf8mb4_0900_bin"}, }, }, { Query: "select @@global.character_set_server, @@global.collation_server;", Expected: []sql.Row{ {"utf8mb4", "utf8mb4_0900_bin"}, }, }, { Query: "set @@global.character_set_server = 'latin1';", Expected: []sql.Row{{}}, }, { Query: "select @@global.character_set_server, @@global.collation_server;", Expected: []sql.Row{ {"latin1", "latin1_swedish_ci"}, }, }, { Query: "set @@global.collation_server = 'utf8mb4_0900_bin';", Expected: []sql.Row{{}}, }, { Query: "select @@global.character_set_server, @@global.collation_server;", Expected: []sql.Row{ {"utf8mb4", "utf8mb4_0900_bin"}, }, }, }, }, { 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: "SET validates character set and collation variables", Queries: []CharsetCollationWireTestQuery{ { Query: "SET character_set_client = 'does_not_exist';", Error: true, }, { Query: "SET character_set_connection = 'invalid_charset';", Error: true, }, { Query: "SET character_set_results = 'whoops';", Error: true, }, { Query: "SET collation_connection = 'cant_be';", Error: true, }, { Query: "SET collation_database = 'something_else';", Error: true, }, { Query: "SET collation_server = 'why_try';", Error: true, }, { Query: "SET NAMES outside_correct;", 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"}}, ExpectedCollations: []sql.CollationID{sql.Collation_binary}, }, { Query: "SET character_set_results = 'utf8mb4';", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test;", Expected: []sql.Row{{"hey"}}, ExpectedCollations: []sql.CollationID{sql.Collation_utf8mb4_0900_ai_ci}, }, { 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"}}, ExpectedCollations: []sql.CollationID{sql.Collation_utf32_general_ci}, }, { Query: "SET character_set_results = NULL;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT * FROM test;", Expected: []sql.Row{{"\x00h\x00e\x00y"}}, ExpectedCollations: []sql.CollationID{sql.Collation_utf16_general_ci}, }, }, }, { 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 ChecksOnInsertScripts = []ScriptTest{ { Name: "basic checks constraints violations on insert", SetUpScript: []string{ "CREATE TABLE t1 (a INTEGER PRIMARY KEY, b INTEGER, c varchar(20))", "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", "ALTER TABLE t1 ADD CONSTRAINT chk4 CHECK (upper(c) = c) ENFORCED", "ALTER TABLE t1 ADD CONSTRAINT chk5 CHECK (trim(c) = c) ENFORCED", "ALTER TABLE t1 ADD CONSTRAINT chk6 CHECK (trim(leading ' ' from c) = c) ENFORCED", "INSERT INTO t1 VALUES (1,1,'ABC')", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t1;", Expected: []sql.Row{{1, 1, "ABC"}}, }, { Query: "INSERT INTO t1 (a,b) VALUES (0,0)", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "INSERT INTO t1 (a,b) VALUES (0,1)", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "INSERT INTO t1 (a,b,c) VALUES (2,2,'abc')", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "INSERT INTO t1 (a,b,c) VALUES (2,2,'ABC ')", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "INSERT INTO t1 (a,b,c) VALUES (2,2,' ABC')", ExpectedErr: sql.ErrCheckConstraintViolated, }, }, }, { Name: "simple insert with check constraint", SetUpScript: []string{ "INSERT INTO t1 VALUES (2,2,'ABC')", "INSERT INTO t1 (a,b) VALUES (4,NULL)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t1;", Expected: []sql.Row{ {1, 1, "ABC"}, {2, 2, "ABC"}, {4, nil, nil}, }, }, }, }, { Name: "insert into table from table", SetUpScript: []string{ "CREATE TABLE t2 (a INTEGER PRIMARY KEY, b INTEGER)", "INSERT INTO t2 VALUES (2,2),(3,3)", "DELETE FROM t1", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO t1 (a,b) select a - 2, b - 1 from t2", ExpectedErr: sql.ErrCheckConstraintViolated, }, { Query: "INSERT INTO t1 (a,b) select a, b from t2", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "INSERT IGNORE INTO t1 VALUES (5,2, 'abc')", Expected: []sql.Row{{types.OkResult{RowsAffected: 0}}}, }, { Query: "SELECT count(*) FROM t1 where a = 5", Expected: []sql.Row{{0}}, }, { Query: "INSERT IGNORE INTO t1 VALUES (4,4, null), (5,2, 'abc')", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "SELECT count(*) FROM t1 where a = 5", Expected: []sql.Row{{0}}, }, { Query: "SELECT count(*) FROM t1 where a = 4", Expected: []sql.Row{{1}}, }, }, }, }
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);", "create table wz (w int, z 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);", "insert into wz values (0, 0), (1, 0), (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 w, min(z) as w, max(z) as w from wz group by w;", Expected: []sql.Row{{0, 0, 0}, {1, 0, 2}}, }, { Query: "select w, w from wz group by w;", Expected: []sql.Row{{0, 0}, {1, 1}}, }, { 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{ { 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}}, }, { 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, }, { 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}}, }, { Query: "select 1 as b, (select b group by b order by b) order by 1;", Expected: []sql.Row{{1, 1}}, }, }, }, }
var ColumnDefaultTests = []ScriptTest{ { Name: "update join ambiguous default", SetUpScript: []string{ "CREATE TABLE t1(name varchar(10) primary key, cnt int, hash varchar(100) NOT NULL DEFAULT (concat('id00',md5(name))))", "INSERT INTO t1 (name, cnt) VALUES ('one', 1), ('two', 2)", "create view t2 as SELECT name, cnt, hash from t1 where name in ('one', 'two')", }, Assertions: []ScriptTestAssertion{ { Query: "update t1 n inner join t2 m on n.name = m.name set n.cnt =m.cnt+1;", Expected: []sql.Row{{newUpdateResult(2, 2)}}, }, { Query: "select name, cnt from t1", Expected: []sql.Row{{"one", 2}, {"two", 3}}, }, }, }, { Name: "update join ambiguous generated column", SetUpScript: []string{ "CREATE TABLE t1 (x int primary key, y int generated always as (x + 1) virtual)", "INSERT INTO t1 (x) values (1), (2), (3)", "create view t2 as SELECT x, y from t1", }, Assertions: []ScriptTestAssertion{ { Query: "update t1 n inner join t2 m on n.y = m.y set n.x =n.y where n.x = 3;", Expected: []sql.Row{{newUpdateResult(1, 1)}}, }, { Query: "select * from t1", Expected: []sql.Row{{1, 2}, {2, 3}, {4, 5}}, }, }, }, { Name: "Standard default literal", SetUpScript: []string{ "CREATE TABLE t1(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT 2)", "INSERT INTO t1 (pk) VALUES (1), (2)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t1", Expected: []sql.Row{{1, 2}, {2, 2}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `pk` bigint NOT NULL,\n" + " `v1` bigint DEFAULT '2',\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "Default expression with function and referenced column", SetUpScript: []string{ "CREATE TABLE t2(pk BIGINT PRIMARY KEY, v1 SMALLINT DEFAULT (GREATEST(pk, 2)))", "INSERT INTO t2 (pk) VALUES (1), (2), (3)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t2", Expected: []sql.Row{{1, 2}, {2, 2}, {3, 3}}, }, { Query: "show create table t2", Expected: []sql.Row{{"t2", "CREATE TABLE `t2` (\n" + " `pk` bigint NOT NULL,\n" + " `v1` smallint DEFAULT (greatest(`pk`,2)),\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "Default expression converting to proper column type", SetUpScript: []string{ "CREATE TABLE t3(pk BIGINT PRIMARY KEY, v1 VARCHAR(20) DEFAULT (GREATEST(pk, 2)))", "INSERT INTO t3 (pk) VALUES (1), (2), (3)", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t3", Expected: []sql.Row{{1, "2"}, {2, "2"}, {3, "3"}}}, }, }, { Name: "Default literal of different type but implicitly converts", SetUpScript: []string{ "CREATE TABLE t4(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT '4')", "INSERT INTO t4 (pk) VALUES (1), (2)", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t4", Expected: []sql.Row{{1, 4}, {2, 4}}}, }, }, { Name: "Back reference to default literal", SetUpScript: []string{ "CREATE TABLE t5(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2), v2 BIGINT DEFAULT 7)", "INSERT INTO t5 (pk) VALUES (1), (2)", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t5", Expected: []sql.Row{{1, 7, 7}, {2, 7, 7}}}, }, }, { Name: "Forward reference to default literal", SetUpScript: []string{ "CREATE TABLE t6(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT 9, v2 BIGINT DEFAULT (v1))", "INSERT INTO t6 (pk) VALUES (1), (2)", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t6", Expected: []sql.Row{{1, 9, 9}, {2, 9, 9}}}, }, }, { Name: "Forward reference to default expression", SetUpScript: []string{ "CREATE TABLE t7(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (8), v2 BIGINT DEFAULT (v1))", "INSERT INTO t7 (pk) VALUES (1), (2)", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t7", Expected: []sql.Row{{1, 8, 8}, {2, 8, 8}}}, }, }, { Name: "Back reference to value", SetUpScript: []string{ "CREATE TABLE t8(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2 + 1), v2 BIGINT)", "INSERT INTO t8 (pk, v2) VALUES (1, 4), (2, 6)", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t8", Expected: []sql.Row{{1, 5, 4}, {2, 7, 6}}}, }, }, { Name: "TEXT expression", SetUpScript: []string{ "CREATE TABLE t9(pk BIGINT PRIMARY KEY, v1 LONGTEXT DEFAULT (77))", "INSERT INTO t9 (pk) VALUES (1), (2)", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t9", Expected: []sql.Row{{1, "77"}, {2, "77"}}}, }, }, { Name: "REPLACE INTO with default expression", SetUpScript: []string{ "CREATE TABLE t12(pk BIGINT PRIMARY KEY, v1 SMALLINT DEFAULT (GREATEST(pk, 2)))", "INSERT INTO t12 (pk) VALUES (1), (2)", "REPLACE INTO t12 (pk) VALUES (2), (3)", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t12", Expected: []sql.Row{{1, 2}, {2, 2}, {3, 3}}}, }, }, { Name: "Add column last default literal", SetUpScript: []string{ "CREATE TABLE t13(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT '4')", "INSERT INTO t13 (pk) VALUES (1), (2)", "ALTER TABLE t13 ADD COLUMN v2 BIGINT DEFAULT 5", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t13", Expected: []sql.Row{{1, 4, 5}, {2, 4, 5}}}, }, }, { Name: "Add column implicit last default expression", SetUpScript: []string{ "CREATE TABLE t14(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 1))", "INSERT INTO t14 (pk) VALUES (1), (2)", "ALTER TABLE t14 ADD COLUMN v2 BIGINT DEFAULT (v1 + 2)", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t14", Expected: []sql.Row{{1, 2, 4}, {2, 3, 5}}}, }, }, { Name: "Add column explicit last default expression", SetUpScript: []string{ "CREATE TABLE t15(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 1))", "INSERT INTO t15 (pk) VALUES (1), (2)", "ALTER TABLE t15 ADD COLUMN v2 BIGINT DEFAULT (v1 + 2) AFTER v1", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t15", Expected: []sql.Row{{1, 2, 4}, {2, 3, 5}}}, }, }, { Name: "Add column first default literal", SetUpScript: []string{ "CREATE TABLE t16(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT '4')", "INSERT INTO t16 (pk) VALUES (1), (2)", "ALTER TABLE t16 ADD COLUMN v2 BIGINT DEFAULT 5 FIRST", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t16", Expected: []sql.Row{{5, 1, 4}, {5, 2, 4}}}, }, }, { Name: "Add column first default expression", SetUpScript: []string{ "CREATE TABLE t17(pk BIGINT PRIMARY KEY, v1 BIGINT)", "INSERT INTO t17 VALUES (1, 3), (2, 4)", "ALTER TABLE t17 ADD COLUMN v2 BIGINT DEFAULT (v1 + 2) FIRST", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t17", Expected: []sql.Row{{5, 1, 3}, {6, 2, 4}}}, }, }, { Name: "Add column forward reference to default expression", SetUpScript: []string{ "CREATE TABLE t18(pk BIGINT DEFAULT (v1) PRIMARY KEY, v1 BIGINT)", "INSERT INTO t18 (v1) VALUES (1), (2)", "ALTER TABLE t18 ADD COLUMN v2 BIGINT DEFAULT (pk + 1) AFTER pk", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t18", Expected: []sql.Row{{1, 2, 1}, {2, 3, 2}}}, }, }, { Name: "Add column back reference to default literal", SetUpScript: []string{ "CREATE TABLE t19(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT 5)", "INSERT INTO t19 (pk) VALUES (1), (2)", "ALTER TABLE t19 ADD COLUMN v2 BIGINT DEFAULT (v1 - 1) AFTER pk", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t19", Expected: []sql.Row{{1, 4, 5}, {2, 4, 5}}}, }, }, { Name: "Add column first with existing defaults still functioning", SetUpScript: []string{ "CREATE TABLE t20(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 10))", "INSERT INTO t20 (pk) VALUES (1), (2)", "ALTER TABLE t20 ADD COLUMN v2 BIGINT DEFAULT (-pk) FIRST", "INSERT INTO t20 (pk) VALUES (3)", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t20", Expected: []sql.Row{{-1, 1, 11}, {-2, 2, 12}, {-3, 3, 13}}}, }, }, { Name: "Drop column referencing other column", SetUpScript: []string{ "CREATE TABLE t21(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2), v2 BIGINT)", }, Assertions: []ScriptTestAssertion{{ Query: "ALTER TABLE t21 DROP COLUMN v1", Expected: []sql.Row{{types.NewOkResult(0)}}}, }, }, { Name: "Modify column move first forward reference default literal", SetUpScript: []string{ "CREATE TABLE t22(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 2), v2 BIGINT DEFAULT (pk + 1))", "INSERT INTO t22 (pk) VALUES (1), (2)", "ALTER TABLE t22 MODIFY COLUMN v1 BIGINT DEFAULT (pk + 2) FIRST", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t22", Expected: []sql.Row{{3, 1, 2}, {4, 2, 3}}}, }, }, { Name: "Modify column move first add reference", SetUpScript: []string{ "CREATE TABLE t23(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (v1 + 1))", "INSERT INTO t23 (pk, v1) VALUES (1, 2), (2, 3)", "ALTER TABLE t23 MODIFY COLUMN v1 BIGINT DEFAULT (pk + 5) FIRST", "INSERT INTO t23 (pk) VALUES (3)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t23 order by 1", Expected: []sql.Row{ {2, 1, 3}, {3, 2, 4}, {8, 3, 9}, }, }, }, }, { Name: "Modify column move last being referenced", SetUpScript: []string{ "CREATE TABLE t24(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (v1 + 1))", "INSERT INTO t24 (pk, v1) VALUES (1, 2), (2, 3)", "ALTER TABLE t24 MODIFY COLUMN v1 BIGINT AFTER v2", "INSERT INTO t24 (pk, v1) VALUES (3, 4)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t24 order by 1", Expected: []sql.Row{ {1, 3, 2}, {2, 4, 3}, {3, 5, 4}, }, }, }, }, { Name: "Modify column move last add reference", SetUpScript: []string{ "CREATE TABLE t25(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (pk * 2))", "INSERT INTO t25 (pk, v1) VALUES (1, 2), (2, 3)", "ALTER TABLE t25 MODIFY COLUMN v1 BIGINT DEFAULT (-pk) AFTER v2", "INSERT INTO t25 (pk) VALUES (3)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t25", Expected: []sql.Row{ {1, 2, 2}, {2, 4, 3}, {3, 6, -3}, }, }, }, }, { Name: "Modify column no move add reference", SetUpScript: []string{ "CREATE TABLE t26(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (pk * 2))", "INSERT INTO t26 (pk, v1) VALUES (1, 2), (2, 3)", "ALTER TABLE t26 MODIFY COLUMN v1 BIGINT DEFAULT (-pk)", "INSERT INTO t26 (pk) VALUES (3)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t26", Expected: []sql.Row{ {1, 2, 2}, {2, 3, 4}, {3, -3, 6}, }, }, }, }, { Name: "Negative float literal", SetUpScript: []string{"CREATE TABLE t27(pk BIGINT PRIMARY KEY, v1 DOUBLE DEFAULT -1.1)"}, Assertions: []ScriptTestAssertion{ { Query: "DESCRIBE t27", Expected: []sql.Row{ {"pk", "bigint", "NO", "PRI", nil, ""}, {"v1", "double", "YES", "", "-1.1", ""}, }, }, }, }, { Name: "Column referenced with name change", SetUpScript: []string{ "CREATE TABLE t29(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (v1 + 1))", "INSERT INTO t29 (pk, v1) VALUES (1, 2)", "ALTER TABLE t29 RENAME COLUMN v1 to v1x", "INSERT INTO t29 (pk, v1x) VALUES (2, 3)", "ALTER TABLE t29 CHANGE COLUMN v1x v1y BIGINT", "INSERT INTO t29 (pk, v1y) VALUES (3, 4)", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t29 ORDER BY 1", Expected: []sql.Row{ {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, }, }, { Query: "SHOW CREATE TABLE t29", Expected: []sql.Row{{"t29", "CREATE TABLE `t29` (\n" + " `pk` bigint NOT NULL,\n" + " `v1y` bigint,\n" + " `v2` bigint DEFAULT ((`v1y` + 1)),\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "Add multiple columns same ALTER", SetUpScript: []string{ "CREATE TABLE t30(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT '4')", "INSERT INTO t30 (pk) VALUES (1), (2)", "ALTER TABLE t30 ADD COLUMN v2 BIGINT DEFAULT 5, ADD COLUMN V3 BIGINT DEFAULT 7", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT pk, v1, v2, V3 FROM t30", Expected: []sql.Row{ {1, 4, 5, 7}, {2, 4, 5, 7}, }, }, }, }, { Name: "Add non-nullable column without default #1", SetUpScript: []string{ "CREATE TABLE t31 (pk BIGINT PRIMARY KEY)", "INSERT INTO t31 VALUES (1), (2), (3)", "ALTER TABLE t31 ADD COLUMN v1 BIGINT NOT NULL", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t31", Expected: []sql.Row{{1, 0}, {2, 0}, {3, 0}}, }, }, }, { Name: "Add non-nullable column without default #2", SetUpScript: []string{ "CREATE TABLE t32 (pk BIGINT PRIMARY KEY)", "INSERT INTO t32 VALUES (1), (2), (3)", "ALTER TABLE t32 ADD COLUMN v1 VARCHAR(20) NOT NULL", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t32", Expected: []sql.Row{{1, ""}, {2, ""}, {3, ""}}, }, }, }, { Name: "Column defaults with functions", SetUpScript: []string{ "CREATE TABLE t33(pk varchar(100) DEFAULT (replace(UUID(), '-', '')), v1 timestamp(6) DEFAULT now(6), v2 varchar(100), primary key (pk))", "insert into t33 (v2) values ('abc')", "alter table t33 add column name varchar(100)", "alter table t33 rename column v1 to v1_new", "alter table t33 rename column name to name2", "alter table t33 drop column name2", "alter table t33 add column v3 datetime(6) default CURRENT_TIMESTAMP(6)", }, Assertions: []ScriptTestAssertion{ { Query: "desc t33", Expected: []sql.Row{ {"pk", "varchar(100)", "NO", "PRI", "(replace(uuid(), '-', ''))", "DEFAULT_GENERATED"}, {"v1_new", "timestamp(6)", "YES", "", "CURRENT_TIMESTAMP(6)", "DEFAULT_GENERATED"}, {"v2", "varchar(100)", "YES", "", nil, ""}, {"v3", "datetime(6)", "YES", "", "CURRENT_TIMESTAMP(6)", "DEFAULT_GENERATED"}, }, }, { Query: "alter table t33 add column v4 date default CURRENT_TIMESTAMP(6)", ExpectedErrStr: "only datetime/timestamp may declare default values of now()/current_timestamp() without surrounding parentheses", }, }, }, { Name: "Function expressions must be enclosed in parens", Assertions: []ScriptTestAssertion{ { Query: "create table t0 (v0 varchar(100) default repeat(\"_\", 99));", ExpectedErr: sql.ErrSyntaxError, }, }, }, { Name: "Column references must be enclosed in parens", Assertions: []ScriptTestAssertion{ { Query: "Create table t0 (c0 int, c1 int default c0);", ExpectedErr: sql.ErrSyntaxError, }, }, }, { Name: "Invalid literal for column type", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 INT UNSIGNED DEFAULT -1)", ExpectedErr: sql.ErrIncompatibleDefaultType, }, }, }, { Name: "Invalid literal for column type", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT 'hi')", ExpectedErr: sql.ErrIncompatibleDefaultType, }, }, }, { Name: "Expression contains invalid literal once implicitly converted", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 INT UNSIGNED DEFAULT '-1')", ExpectedErr: sql.ErrIncompatibleDefaultType, }, }, }, { Name: "Null literal is invalid for NOT NULL", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 BIGINT NOT NULL DEFAULT NULL)", ExpectedErr: sql.ErrIncompatibleDefaultType, }, }, }, { Name: "Back reference to expression", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v2), v2 BIGINT DEFAULT (9))", ExpectedErr: sql.ErrInvalidDefaultValueOrder, }, }, }, { Name: "BLOB types can define defaults with literals", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t997(pk BIGINT PRIMARY KEY, v1 BLOB DEFAULT 0x61)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO t997 VALUES(42, DEFAULT)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * from t997", Expected: []sql.Row{{42, []uint8{0x61}}}, }, { Query: "CREATE TABLE t998(pk BIGINT PRIMARY KEY, v1 TEXT DEFAULT 'hi')", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO t998 VALUES(1, DEFAULT)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * from t998", Expected: []sql.Row{{1, "hi"}}, }, { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 LONGTEXT DEFAULT 'hi')", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO t999 VALUES(10, DEFAULT)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * from t999", Expected: []sql.Row{{10, "hi"}}, }, { Query: "CREATE TABLE t34(pk INT PRIMARY KEY, v1 JSON)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t34 alter column v1 set default '{}'", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "INSERT INTO t34 VALUES(100, DEFAULT)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SELECT * from t34", Expected: []sql.Row{{100, "{}"}}, }, { Query: "ALTER TABLE t34 alter column v1 set default ('{}')", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CREATE TABLE t35(i int default 100, j JSON)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t35 alter column j set default '[]'", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t35 alter column j set default ('[]')", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Other types using NOW/CURRENT_TIMESTAMP literal", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT NOW())", ExpectedErr: sql.ErrColumnDefaultDatetimeOnlyFunc, }, { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 VARCHAR(20) DEFAULT CURRENT_TIMESTAMP())", ExpectedErr: sql.ErrColumnDefaultDatetimeOnlyFunc, }, { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 BIT(5) DEFAULT NOW())", ExpectedErr: sql.ErrColumnDefaultDatetimeOnlyFunc, }, { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 DATE DEFAULT CURRENT_TIMESTAMP())", ExpectedErr: sql.ErrColumnDefaultDatetimeOnlyFunc, }, }, }, { Name: "Unknown functions return an error", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (CUSTOMFUNC(1)))", ExpectedErr: sql.ErrFunctionNotFound, }, }, }, { Name: "Stored procedures are not valid in column default value expressions", SetUpScript: []string{"CREATE PROCEDURE testProc()\nBEGIN\n\tSELECT 42 FROM dual;\nEND;"}, Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (call testProc()))", ExpectedErr: sql.ErrSyntaxError, }, }, }, { Name: "Default expression references own column", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE t999(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (v1))", ExpectedErr: sql.ErrInvalidDefaultValueOrder, }, }, }, { Name: "Expression contains invalid literal, fails on insertion", SetUpScript: []string{"CREATE TABLE t1000(pk BIGINT PRIMARY KEY, v1 INT UNSIGNED DEFAULT (-1))"}, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO t1000 (pk) VALUES (1)", ExpectedErrStr: "4294967295 out of range for int unsigned", }, }, }, { Name: "Expression contains null on NOT NULL, fails on insertion", SetUpScript: []string{"CREATE TABLE t1001(pk BIGINT PRIMARY KEY, v1 BIGINT NOT NULL DEFAULT (NULL))"}, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO t1001 (pk) VALUES (1)", ExpectedErr: sql.ErrColumnDefaultReturnedNull, }, }, }, { Name: "Add column first back reference to expression", SetUpScript: []string{"CREATE TABLE t1002(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 1))"}, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t1002 ADD COLUMN v2 BIGINT DEFAULT (v1 + 2) FIRST", ExpectedErr: sql.ErrInvalidDefaultValueOrder, }, }, }, { Name: "Add column after back reference to expression", SetUpScript: []string{"CREATE TABLE t1003(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 1))"}, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t1003 ADD COLUMN v2 BIGINT DEFAULT (v1 + 2) AFTER pk", ExpectedErr: sql.ErrInvalidDefaultValueOrder, }, }, }, { Name: "Add column self reference", SetUpScript: []string{"CREATE TABLE t1004(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk + 1))"}, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t1004 ADD COLUMN v2 BIGINT DEFAULT (v2)", ExpectedErr: sql.ErrInvalidDefaultValueOrder, }, }, }, { Name: "Drop column referenced by other column", SetUpScript: []string{"CREATE TABLE t1005(pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT DEFAULT (v1))"}, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t1005 DROP COLUMN v1", ExpectedErr: sql.ErrDropColumnReferencedInDefault, }, }, }, { Name: "Modify column moving back creates back reference to expression", SetUpScript: []string{"CREATE TABLE t1006(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT (pk), v2 BIGINT DEFAULT (v1))"}, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t1006 MODIFY COLUMN v1 BIGINT DEFAULT (pk) AFTER v2", ExpectedErr: sql.ErrInvalidDefaultValueOrder, }, }, }, { Name: "Modify column moving forward creates back reference to expression", SetUpScript: []string{"CREATE TABLE t1007(pk BIGINT DEFAULT (v2) PRIMARY KEY, v1 BIGINT DEFAULT (pk), v2 BIGINT)"}, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t1007 MODIFY COLUMN v1 BIGINT DEFAULT (pk) FIRST", ExpectedErr: sql.ErrInvalidDefaultValueOrder, }, }, }, { Name: "column default normalization: int column rounds", SetUpScript: []string{ "create table t (i int default '1.999');", "insert into t values ();", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int DEFAULT '2'\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "describe t;", Expected: []sql.Row{ {"i", "int", "YES", "", "2", ""}, }, }, { Query: "select table_name, column_name, column_default from information_schema.columns where table_name = 't';", Expected: []sql.Row{ {"t", "i", "2"}, }, }, { Query: "select * from t;", Expected: []sql.Row{{2}}, }, }, }, { Name: "column default normalization: float column rounds", SetUpScript: []string{ "create table t (f float default '1.000000');", "insert into t values ();", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `f` float DEFAULT '1'\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "describe t;", Expected: []sql.Row{ {"f", "float", "YES", "", "1", ""}, }, }, { Query: "select table_name, column_name, column_default from information_schema.columns where table_name = 't';", Expected: []sql.Row{ {"t", "f", "1"}, }, }, { Query: "select * from t;", Expected: []sql.Row{{1.0}}, }, }, }, { Name: "column default normalization: double quotes", SetUpScript: []string{ "create table t (f float default \"1.23000\");", "insert into t values ();", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `f` float DEFAULT '1.23'\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "describe t;", Expected: []sql.Row{ {"f", "float", "YES", "", "1.23", ""}, }, }, { Query: "select table_name, column_name, column_default from information_schema.columns where table_name = 't';", Expected: []sql.Row{ {"t", "f", "1.23"}, }, }, { Query: "select * from t;", Expected: []sql.Row{{1.23}}, }, }, }, { Name: "column default normalization: expression string literal", SetUpScript: []string{ "create table t (f float default ('1.23000'));", "insert into t values ();", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `f` float DEFAULT ('1.23000')\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "describe t;", Expected: []sql.Row{ {"f", "float", "YES", "", "('1.23000')", "DEFAULT_GENERATED"}, }, }, { Query: "select table_name, column_name, column_default from information_schema.columns where table_name = 't';", Expected: []sql.Row{ {"t", "f", "'1.23000'"}, }, }, { Query: "select * from t;", Expected: []sql.Row{{1.23}}, }, }, }, { Name: "column default normalization: expression int literal", SetUpScript: []string{ "create table t (i int default (1));", "insert into t values ();", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int DEFAULT (1)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "describe t;", Expected: []sql.Row{ {"i", "int", "YES", "", "(1)", "DEFAULT_GENERATED"}, }, }, { Query: "select table_name, column_name, column_default from information_schema.columns where table_name = 't';", Expected: []sql.Row{ {"t", "i", "1"}, }, }, { Query: "select * from t;", Expected: []sql.Row{{1}}, }, }, }, }
var ComplexIndexQueries = []QueryTest{}/* 703 elements not displayed */
var ConvertTests = []struct { Field string Op string Operand string ExpCnt int }{}/* 200 elements not displayed */
var CreateCheckConstraintsScripts = []ScriptTest{ { Name: "simple check constraint check on ChecksSetup data", SetUpScript: []string{}, 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"}}, }, }, }, { Name: "unnamed constraint", SetUpScript: []string{ "ALTER TABLE checks ADD CONSTRAINT CHECK (b > 100)", }, Assertions: []ScriptTestAssertion{ { Query: `SELECT LENGTH(TC.CONSTRAINT_NAME) > 0 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' AND CC.CHECK_CLAUSE = '(b > 100)';`, Expected: []sql.Row{{true}}, }, }, }, { Name: "check statements in CREATE TABLE statements", SetUpScript: []string{ ` CREATE TABLE T2 ( CHECK (c1 = c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 INT CHECK (c3 < 100), CONSTRAINT c1_nonzero CHECK (c1 = 0), CHECK (C1 > C3) );`, }, Assertions: []ScriptTestAssertion{ { Query: `SELECT CC.CHECK_CLAUSE FROM information_schema.TABLE_CONSTRAINTS TC, information_schema.CHECK_CONSTRAINTS CC WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 't2' AND TC.TABLE_SCHEMA = CC.CONSTRAINT_SCHEMA AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME AND TC.CONSTRAINT_TYPE = 'CHECK';`, Expected: []sql.Row{{"(c1 = c2)"}, {"(c1 > 10)"}, {"(c2 > 0)"}, {"(c3 < 100)"}, {"(c1 = 0)"}, {"(C1 > C3)"}}, }, }, }, { Name: "error cases", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t3 ADD CONSTRAINT chk2 CHECK (c > 0)", ExpectedErr: sql.ErrTableNotFound, }, { Query: "ALTER TABLE checks ADD CONSTRAINT chk3 CHECK (d > 0)", ExpectedErr: sql.ErrColumnNotFound, }, { Query: ` CREATE TABLE t4 ( CHECK (c1 = c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), CHECK (c1 > c3) );`, ExpectedErr: sql.ErrColumnNotFound, }, }, }, { 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: sql.ErrCheckConstraintViolated, }, }, }, { 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 CreateDatabaseScripts = []ScriptTest{ { Name: "CREATE DATABASE and create table", Assertions: []ScriptTestAssertion{ { Query: "CREATE DATABASE testdb", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "USE testdb", Expected: []sql.Row{}, }, { Query: "SELECT DATABASE()", Expected: []sql.Row{{"testdb"}}, }, { Query: "CREATE TABLE test (pk int primary key)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW TABLES", Expected: []sql.Row{{"test"}}, }, }, }, { Name: "CREATE DATABASE IF NOT EXISTS", Assertions: []ScriptTestAssertion{ { Query: "CREATE DATABASE IF NOT EXISTS testdb2", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "USE testdb2", Expected: []sql.Row{}, }, { Query: "SELECT DATABASE()", Expected: []sql.Row{{"testdb2"}}, }, { Query: "CREATE TABLE test (pk int primary key)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW TABLES", Expected: []sql.Row{{"test"}}, }, }, }, { Name: "CREATE SCHEMA", Assertions: []ScriptTestAssertion{ { Query: "CREATE SCHEMA testdb3", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "USE testdb3", Expected: []sql.Row{}, }, { Query: "SELECT DATABASE()", Expected: []sql.Row{{"testdb3"}}, }, { Query: "CREATE TABLE test (pk int primary key)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW TABLES", Expected: []sql.Row{{"test"}}, }, }, }, { Name: "CREATE DATABASE error handling", Assertions: []ScriptTestAssertion{ { Query: "create database `abc/def`", ExpectedErr: sql.ErrInvalidDatabaseName, }, { Query: "CREATE DATABASE newtestdb CHARACTER SET utf8mb4 ENCRYPTION='N'", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SHOW WARNINGS /* 1 */", Expected: []sql.Row{{"Warning", 1235, "Setting CHARACTER SET, COLLATION and ENCRYPTION are not supported yet"}}, }, { Query: "CREATE DATABASE newtest1db DEFAULT COLLATE binary ENCRYPTION='Y'", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "SHOW WARNINGS /* 2 */", Expected: []sql.Row{ {"Warning", 1235, "Setting CHARACTER SET, COLLATION and ENCRYPTION are not supported yet"}, }, }, { Query: "CREATE DATABASE mydb", ExpectedErr: sql.ErrDatabaseExists, }, { Query: "CREATE DATABASE IF NOT EXISTS mydb", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "SHOW WARNINGS /* 3 */", Expected: []sql.Row{{"Note", 1007, "Can't create database mydb; database exists "}}, }, }, }, }
var CreateForeignKeyTests = []ScriptTest{ { Name: "basic create foreign key tests", SetUpScript: []string{ "CREATE TABLE parent(a INTEGER PRIMARY KEY, b INTEGER)", "ALTER TABLE parent ADD INDEX pb (b)", `CREATE TABLE child(c INTEGER PRIMARY KEY, d INTEGER, CONSTRAINT fk1 FOREIGN KEY (D) REFERENCES parent(B) ON DELETE CASCADE )`, "ALTER TABLE child ADD CONSTRAINT fk4 FOREIGN KEY (D) REFERENCES child(C)", "CREATE TABLE child2(e INTEGER PRIMARY KEY, f INTEGER)", "ALTER TABLE child2 ADD CONSTRAINT fk2 FOREIGN KEY (f) REFERENCES parent(b) ON DELETE RESTRICT", "ALTER TABLE child2 ADD CONSTRAINT fk3 FOREIGN KEY (f) REFERENCES child(d) ON UPDATE SET NULL", }, Assertions: []ScriptTestAssertion{ { Query: `SELECT RC.CONSTRAINT_NAME, RC.CONSTRAINT_SCHEMA, RC.TABLE_NAME, KCU.COLUMN_NAME, KCU.REFERENCED_TABLE_SCHEMA, KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME, RC.UPDATE_RULE, RC.DELETE_RULE FROM information_schema.REFERENTIAL_CONSTRAINTS RC, information_schema.KEY_COLUMN_USAGE KCU WHERE RC.TABLE_NAME = 'child' AND RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME AND RC.TABLE_NAME = KCU.TABLE_NAME AND RC.REFERENCED_TABLE_NAME = KCU.REFERENCED_TABLE_NAME;`, Expected: []sql.Row{ {"fk1", "mydb", "child", "d", "mydb", "parent", "b", "NO ACTION", "CASCADE"}, {"fk4", "mydb", "child", "d", "mydb", "child", "c", "NO ACTION", "NO ACTION"}, }, }, { Query: `SELECT RC.CONSTRAINT_NAME, RC.CONSTRAINT_SCHEMA, RC.TABLE_NAME, KCU.COLUMN_NAME, KCU.REFERENCED_TABLE_SCHEMA, KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME, RC.UPDATE_RULE, RC.DELETE_RULE FROM information_schema.REFERENTIAL_CONSTRAINTS RC, information_schema.KEY_COLUMN_USAGE KCU WHERE RC.TABLE_NAME = 'child2' AND RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME AND RC.TABLE_NAME = KCU.TABLE_NAME AND RC.REFERENCED_TABLE_NAME = KCU.REFERENCED_TABLE_NAME;`, Expected: []sql.Row{ {"fk2", "mydb", "child2", "f", "mydb", "parent", "b", "NO ACTION", "RESTRICT"}, {"fk3", "mydb", "child2", "f", "mydb", "child", "d", "SET NULL", "NO ACTION"}, }, }, }, }, { Name: "error cases", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child2 ADD CONSTRAINT fk3 FOREIGN KEY (f) REFERENCES dne(d) ON UPDATE SET NULL", ExpectedErr: sql.ErrTableNotFound, }, { Query: "ALTER TABLE dne ADD CONSTRAINT fk4 FOREIGN KEY (f) REFERENCES child(d) ON UPDATE SET NULL", ExpectedErr: sql.ErrTableNotFound, }, { Query: "ALTER TABLE child2 ADD CONSTRAINT fk5 FOREIGN KEY (f) REFERENCES child(dne) ON UPDATE SET NULL", ExpectedErr: sql.ErrTableColumnNotFound, }, }, }, { Name: "Add a column then immediately add a foreign key", SetUpScript: []string{ "CREATE TABLE parent3 (pk BIGINT PRIMARY KEY, v1 BIGINT, INDEX (v1))", "CREATE TABLE child3 (pk BIGINT PRIMARY KEY);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child3 ADD COLUMN v1 BIGINT NULL, ADD CONSTRAINT fk_child3 FOREIGN KEY (v1) REFERENCES parent3(v1);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "Do not validate foreign keys if FOREIGN_KEY_CHECKS is set to zero", Assertions: []ScriptTestAssertion{ { Query: "SET FOREIGN_KEY_CHECKS=0;", Expected: []sql.Row{{}}, }, { Query: "CREATE TABLE child4 (pk BIGINT PRIMARY KEY, CONSTRAINT fk_child4 FOREIGN KEY (pk) REFERENCES delayed_parent4 (pk))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "CREATE TABLE delayed_parent4 (pk BIGINT PRIMARY KEY)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, }
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 NOT NULL AUTO_INCREMENT,\n" + " `b` int NOT NULL,\n" + " PRIMARY KEY (`b`),\n" + " UNIQUE KEY `a` (`a`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=3 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 NOT NULL AUTO_INCREMENT,\n" + " `b` int NOT NULL,\n" + " PRIMARY KEY (`b`),\n" + " UNIQUE KEY `a` (`a`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=3 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, }, }, }, { Name: "table with auto_increment table option", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "create table t1 (i int) auto_increment=10;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{ {"t1", "CREATE TABLE `t1` (\n" + " `i` int\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t2 (i int auto_increment primary key) auto_increment=10;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t2", Expected: []sql.Row{ {"t2", "CREATE TABLE `t2` (\n" + " `i` int NOT NULL AUTO_INCREMENT,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into t2 values (null), (null), (null)", Expected: []sql.Row{{types.OkResult{RowsAffected: 3, InsertID: 10}}}, }, { Query: "select * from t2", Expected: []sql.Row{ {10}, {11}, {12}, }, }, }, }, }
var CreateTableInSubroutineTests = []ScriptTest{ { Name: "procedure contains CREATE TABLE AS", Assertions: []ScriptTestAssertion{ { Query: "CREATE PROCEDURE foo() CREATE TABLE bar AS SELECT 1;", Skip: true, }, { Query: "CALL foo();", Skip: true, }, { Query: "SELECT * from bar;", Expected: []sql.Row{{1}}, Skip: true, }, }, }, { Name: "event contains CREATE TABLE AS", Assertions: []ScriptTestAssertion{ { Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE TABLE bar AS SELECT 1;", }, }, }, { Name: "trigger contains CREATE TABLE AS", SetUpScript: []string{ "CREATE TABLE t (pk INT PRIMARY KEY);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN CREATE TABLE bar AS SELECT 1; END;", }, }, }, }
var CreateTableQueries = []WriteQueryTest{ { WriteQuery: `create table tableWithComment (pk int) COMMENT 'Table Comments Work!'`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE tableWithComment", ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT='Table Comments Work!'"}}, }, { WriteQuery: `create table tableWithComment (pk int) COMMENT='Table Comments=Still Work'`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE tableWithComment", ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT='Table Comments=Still Work'"}}, }, { WriteQuery: `create table tableWithComment (pk int) COMMENT "~!@ #$ %^ &* ()"`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE tableWithComment", ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT='~!@ #$ %^ &* ()'"}}, }, { 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{{"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{{"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(1),\n `b2` tinyint(1) 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{{"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{{"t1", "CREATE TABLE `t1` (\n `a` int NOT NULL,\n `b` text NOT NULL COMMENT 'comment',\n `c` tinyint(1),\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{{"t1", "CREATE TABLE `t1` (\n `a` int NOT NULL,\n `create_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(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{{"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{{"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.othertable`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: "SHOW CREATE TABLE t1", ExpectedSelect: []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{{"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{{"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{{"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{{"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{{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `j` int NOT NULL 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{{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `j` int NOT NULL 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{{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `j` int NOT NULL AUTO_INCREMENT,\n `k` int,\n PRIMARY KEY (`i`),\n UNIQUE KEY `j` (`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{{"t1", "CREATE TABLE `t1` (\n `i` int NOT NULL,\n `j` int NOT NULL AUTO_INCREMENT,\n `k` int,\n PRIMARY KEY (`i`),\n KEY `j` (`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{{"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{{"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 CURRENT_TIMESTAMP,\n `col8` bigint DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (`pk`)\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 `b1` (`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 `b1` (`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 `b1_2` (`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}}, }, { WriteQuery: `CREATE TABLE t1 (pk varchar(10) primary key collate binary)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `SHOW CREATE TABLE t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `pk` varbinary(10) NOT NULL,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (pk varchar(10) primary key charset binary)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `SHOW CREATE TABLE t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `pk` varbinary(10) NOT NULL,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (pk varchar(10) primary key character set binary)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `SHOW CREATE TABLE t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `pk` varbinary(10) NOT NULL,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (pk varchar(10) primary key charset binary collate binary)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `SHOW CREATE TABLE t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `pk` varbinary(10) NOT NULL,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { WriteQuery: `CREATE TABLE t1 (pk varchar(10) primary key character set binary collate binary)`, ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}}, SelectQuery: `SHOW CREATE TABLE t1`, ExpectedSelect: []sql.Row{{"t1", "CREATE TABLE `t1` (\n `pk` varbinary(10) NOT NULL,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }
var CreateTableScriptTests = []ScriptTest{ { Name: "display width for numeric types", SetUpScript: []string{ "CREATE TABLE numericDisplayWidthTest (pk int primary key, b boolean, ti tinyint, ti1 tinyint(1), ti2 tinyint(2), i1 int(1));", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW CREATE TABLE numericDisplayWidthTest;", Expected: []sql.Row{{"numericDisplayWidthTest", "CREATE TABLE `numericDisplayWidthTest` (\n `pk` int NOT NULL,\n `b` tinyint(1),\n `ti` tinyint,\n `ti1` tinyint(1),\n `ti2` tinyint,\n `i1` int,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "SHOW FULL FIELDS FROM numericDisplayWidthTest;", Expected: []sql.Row{ {"pk", "int", interface{}(nil), "NO", "PRI", nil, "", "", ""}, {"b", "tinyint(1)", interface{}(nil), "YES", "", nil, "", "", ""}, {"ti", "tinyint", interface{}(nil), "YES", "", nil, "", "", ""}, {"ti1", "tinyint(1)", interface{}(nil), "YES", "", nil, "", "", ""}, {"ti2", "tinyint", interface{}(nil), "YES", "", nil, "", "", ""}, {"i1", "int", interface{}(nil), "YES", "", nil, "", "", ""}, }, }, { Query: "CREATE TABLE errorTest(pk int primary key, ti tinyint(-1));", ExpectedErrStr: "syntax error at position 56 near 'tinyint'", }, }, }, { 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", }, { Query: "CREATE TABLE tt (pk int primary key, d datetime(3) default current_timestamp(6))", ExpectedErr: sql.ErrInvalidColumnDefaultValue, }, { Query: "CREATE TABLE tt (pk int primary key, d datetime(6) default current_timestamp(3))", ExpectedErr: sql.ErrInvalidColumnDefaultValue, }, { Query: "CREATE TABLE tt (pk int primary key, d datetime(6) default current_timestamp(6))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { 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)}}, }, { SkipResultCheckOnServerEngine: true, 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)}}, }, { SkipResultCheckOnServerEngine: true, 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)}}, }, { SkipResultCheckOnServerEngine: true, 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", }, }, }, { Name: "Identifier lengths", SetUpScript: []string{ "create table parent (a int primary key)", }, Assertions: []ScriptTestAssertion{ { Query: "create table abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl (a int primary key)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "create table abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm (a int primary key)", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "create table a (abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl int primary key)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "create table a (abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm int primary key)", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "create table b (a int primary key, constraint abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl check (a > 0))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "create table b (a int primary key, constraint abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm check (a > 0))", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "create table c (a int primary key, b int, key abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl (b))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "create table c (a int primary key, b int, key abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm (b))", ExpectedErr: sql.ErrInvalidIdentifier, }, { Query: "create table d (a int primary key, constraint abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl foreign key (a) references parent(a))", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "create table d (a int primary key, constraint abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm foreign key (a) references parent(a))", ExpectedErr: sql.ErrInvalidIdentifier, }, }, }, { Name: "case insensitive column name uniqueness", Assertions: []ScriptTestAssertion{ { Query: "create table t1 (abc int, abc int)", ExpectedErr: sql.ErrDuplicateColumn, }, { Query: "create table t2 (ABC int, ABC int)", ExpectedErr: sql.ErrDuplicateColumn, }, { Query: "create table t3 (a int, A int)", ExpectedErr: sql.ErrDuplicateColumn, }, { Query: "create table t4 (abc int, def int, Abc int)", ExpectedErr: sql.ErrDuplicateColumn, }, }, }, { Name: "valid character set and collation options", SetUpScript: []string{ "create table parent (a int primary key)", }, Assertions: []ScriptTestAssertion{ { Query: `CREATE TABLE t1 (pk varbinary(10) primary key collate utf8mb4_0900_bin)`, ExpectedErr: types.ErrBinaryCollation, }, { Query: `CREATE TABLE t1 (pk varbinary(10) primary key charset utf8mb4_0900_bin)`, ExpectedErr: types.ErrCharacterSetOnInvalidType, }, { Query: `CREATE TABLE t1 (pk varbinary(10) primary key character set utf8mb4)`, ExpectedErr: types.ErrCharacterSetOnInvalidType, }, { Query: `CREATE TABLE t1 (pk varbinary(10) primary key charset utf8mb4 collate utf8mb4_0900_bin)`, ExpectedErr: types.ErrCharacterSetOnInvalidType, }, { Query: `CREATE TABLE t1 (pk varbinary(10) primary key character set utf8mb4 collate utf8mb4_0900_bin)`, ExpectedErr: types.ErrCharacterSetOnInvalidType, }, { Query: `CREATE TABLE t1 (pk int primary key character set utf8mb4)`, ExpectedErr: types.ErrCharacterSetOnInvalidType, }, { Query: `create table t (i int, primary key(i)) charset=utf8mb4 collate=utf8mb3_esperanto_ci;`, ExpectedErrStr: "utf8mb4 is not a valid character set for utf8mb3_esperanto_ci", }, { Query: `create table t (i int, primary key(i)) charset=utf8mb4 collate=utf8mb4_esperanto_ci;`, Expected: []sql.Row{{types.NewOkResult(0)}}, }, }, }, { Name: "table charset options", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: `create table t1 (i int) charset latin1`, Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: `show create table t1`, Expected: []sql.Row{ {"t1", "CREATE TABLE `t1` (\n" + " `i` int\n" + ") ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci"}, }, }, { Query: `create table t2 (i int) character set latin1`, Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: `show create table t2`, Expected: []sql.Row{ {"t2", "CREATE TABLE `t2` (\n" + " `i` int\n" + ") ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci"}, }, }, { Query: `create table t3 (i int) charset binary`, Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: `show create table t3`, Expected: []sql.Row{ {"t3", "CREATE TABLE `t3` (\n" + " `i` int\n" + ") ENGINE=InnoDB DEFAULT CHARSET=binary COLLATE=binary"}, }, }, { Query: `create table t4 (i int) character set binary`, Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: `show create table t4`, Expected: []sql.Row{ {"t4", "CREATE TABLE `t4` (\n" + " `i` int\n" + ") ENGINE=InnoDB DEFAULT CHARSET=binary COLLATE=binary"}, }, }, }, }, { Name: "if not exists option blocks", SetUpScript: []string{ "create table t1 (i int, index (i));", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t1", Expected: []sql.Row{ {"t1", "CREATE TABLE `t1` (\n" + " `i` int,\n" + " KEY `i` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "create table if not exists t1 (i int, index (i));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{ {"t1", "CREATE TABLE `t1` (\n" + " `i` int,\n" + " KEY `i` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "create table if not exists t1 (i int, index notthesamename (i));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{ {"t1", "CREATE TABLE `t1` (\n" + " `i` int,\n" + " KEY `i` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "create table if not exists t1 (i int primary key, foreign key (i) references t1(i));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{ {"t1", "CREATE TABLE `t1` (\n" + " `i` int,\n" + " KEY `i` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, { Query: "create table if not exists t1 (i int, check (i > 10));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{ {"t1", "CREATE TABLE `t1` (\n" + " `i` int,\n" + " KEY `i` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", }, }, }, }, }, { Name: "create table with select preserves default", SetUpScript: []string{ "create table a (i int primary key, j int default 100);", "create table b (x int primary key, y int default 200);", "create table c (p int primary key, q int default 300, u int as (q));", }, Assertions: []ScriptTestAssertion{ { Query: "create table t1 select * from a;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t1;", Expected: []sql.Row{ {"t1", "CREATE TABLE `t1` (\n" + " `i` int NOT NULL,\n" + " `j` int DEFAULT '100'\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t2 select j from a;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t2;", Expected: []sql.Row{ {"t2", "CREATE TABLE `t2` (\n" + " `j` int DEFAULT '100'\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t3 select j as i from a;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t3;", Expected: []sql.Row{ {"t3", "CREATE TABLE `t3` (\n" + " `i` int DEFAULT '100'\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t4 select j + 1 from a;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t4;", Expected: []sql.Row{ {"t4", "CREATE TABLE `t4` (\n" + " `(a.j + 1)` bigint\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t5 select a.j from a;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t5;", Expected: []sql.Row{ {"t5", "CREATE TABLE `t5` (\n" + " `j` int DEFAULT '100'\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t6 select sqa.j from (select i, j from a) sqa;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t6;", Expected: []sql.Row{ {"t6", "CREATE TABLE `t6` (\n" + " `j` int DEFAULT '100'\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t7 select (select j from a) sq from dual;", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "show create table t7;", Expected: []sql.Row{ {"t7", "CREATE TABLE `t7` (\n" + " `sq` int\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t8 select * from (select * from a) a join (select * from b) b;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t8;", Expected: []sql.Row{ {"t8", "CREATE TABLE `t8` (\n" + " `i` int NOT NULL,\n" + " `j` int DEFAULT '100',\n" + " `x` int NOT NULL,\n" + " `y` int DEFAULT '200'\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: `create table t9 select * from json_table('[{"c1": 1}]', '$[*]' columns (c1 int path '$.c1' default '100' on empty)) as jt;`, Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "show create table t9;", Expected: []sql.Row{ {"t9", "CREATE TABLE `t9` (\n" + " `c1` int NOT NULL\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Skip: true, Query: `create table t10 (select j from a) union (select y from b);`, Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Skip: true, Query: "show create table t10;", Expected: []sql.Row{ {"t9", "CREATE TABLE `t9` (\n" + " `c1` int NOT NULL\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t11 select sum(j) over() as jj from a;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t11;", Expected: []sql.Row{ {"t11", "CREATE TABLE `t11` (\n" + " `jj` int NOT NULL\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t12 select j from a group by j;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t12;", Expected: []sql.Row{ {"t12", "CREATE TABLE `t12` (\n" + " `j` int DEFAULT '100'\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t13 select * from c;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t13;", Expected: []sql.Row{ {"t13", "CREATE TABLE `t13` (\n" + " `p` int NOT NULL,\n" + " `q` int DEFAULT '300',\n" + " `u` int\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, }, }, }
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 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}}, }, { Skip: true, 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{ { Skip: true, Query: "select 'foo' as foo, (select dt.b from (select 1 as a, foo as b) dt);", ExpectedErr: sql.ErrColumnNotFound, }, { Skip: true, 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, }, { 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 DisallowedCheckConstraintsScripts = []ScriptTest{ { Name: "error cases", SetUpScript: []string{ "CREATE TABLE t1 (a INTEGER PRIMARY KEY, b INTEGER)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (current_user = \"root@\")", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (user() = \"root@\")", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (now() > '2021')", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (current_date() > '2021')", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (uuid() > 'a')", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (database() = 'foo')", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (schema() = 'foo')", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (version() = 'foo')", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (last_insert_id() = 0)", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (rand() < .8)", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (row_count() = 0)", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (found_rows() = 0)", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (curdate() > '2021')", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (curtime() > '2021')", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (current_timestamp() > '2021')", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (connection_id() = 2)", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (get_lock('abc', 0) is null)", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (release_all_locks() is null)", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (release_lock('abc') is null)", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (is_free_lock('abc') is null)", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (is_used_lock('abc') is null)", ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK ((select count(*) from t1) = 0)", ExpectedErr: sql.ErrInvalidConstraintSubqueryNotSupported, }, { Query: ` CREATE TABLE t3 ( a int primary key CONSTRAINT chk2 CHECK (current_user = "root@") ) `, ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: ` CREATE TABLE t3 ( a int primary key, CHECK (current_user = "root@") ) `, ExpectedErr: sql.ErrInvalidConstraintFunctionNotSupported, }, { Query: ` CREATE TABLE t3 ( a int primary key CONSTRAINT chk2 CHECK (a = (select count(*) from t1)) ) `, ExpectedErr: sql.ErrInvalidConstraintSubqueryNotSupported, }, { Query: ` CREATE TABLE t3 ( a int primary key, CHECK (a = (select count(*) from t1)) ) `, ExpectedErr: sql.ErrInvalidConstraintSubqueryNotSupported, }, }, }, }
var DropCheckConstraintsScripts = []ScriptTest{ { Name: "basic drop check constraints", SetUpScript: []string{ "CREATE TABLE t1 (a INTEGER PRIMARY KEY, b INTEGER, c integer)", "ALTER TABLE t1 ADD CONSTRAINT chk1 CHECK (a > 0)", "ALTER TABLE t1 ADD CONSTRAINT chk2 CHECK (b > 0) NOT ENFORCED", "ALTER TABLE t1 ADD CONSTRAINT chk3 CHECK (c > 0)", "ALTER TABLE t1 DROP CONSTRAINT chk2", "ALTER TABLE t1 DROP CHECK chk1", }, 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 = 't1' AND TC.TABLE_SCHEMA = CC.CONSTRAINT_SCHEMA AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME AND TC.CONSTRAINT_TYPE = 'CHECK';`, Expected: []sql.Row{{"chk3", "(c > 0)", "YES"}}, }, }, }, { Name: "error cases", SetUpScript: []string{ "ALTER TABLE t1 DROP CHECK chk3", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t2 DROP CONSTRAINT chk2", ExpectedErr: sql.ErrTableNotFound, }, { Query: "ALTER TABLE t1 DROP CONSTRAINT dne", ExpectedErr: sql.ErrUnknownConstraint, }, }, }, }
var DropColumnKeylessTablesScripts = []ScriptTest{ { Name: "drop last column", SetUpScript: []string{ "create table t0 (i bigint, s varchar(20))", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t0 DROP COLUMN s", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM t0", Expected: []sql.Row{{"i", "bigint", nil, "YES", "", nil, "", "", ""}}, }, }, }, { Name: "drop first column", SetUpScript: []string{ "CREATE TABLE t1 (a int, b varchar(10), c bigint)", "insert into t1 values (1, 'abc', 2), (4, 'def', 5)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t1 DROP COLUMN a", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM t1", Expected: []sql.Row{ {"b", "varchar(10)", "utf8mb4_0900_bin", "YES", "", nil, "", "", ""}, {"c", "bigint", nil, "YES", "", nil, "", "", ""}, }, }, { Query: "SELECT * FROM t1 ORDER BY b", Expected: []sql.Row{ {"abc", 2}, {"def", 5}, }, }, }, }, { Name: "drop middle column", SetUpScript: []string{ "CREATE TABLE t2 (a int, b varchar(10), c bigint)", "insert into t2 values (1, 'abc', 2), (4, 'def', 5)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t2 DROP COLUMN b", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM t2", Expected: []sql.Row{ {"a", "int", nil, "YES", "", nil, "", "", ""}, {"c", "bigint", nil, "YES", "", nil, "", "", ""}, }, }, { Query: "SELECT * FROM t2 ORDER BY c", Expected: []sql.Row{ {1, 2}, {4, 5}, }, }, }, }, { Name: "error cases", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE not_exist DROP COLUMN s", ExpectedErr: sql.ErrTableNotFound, }, { Query: "ALTER TABLE t0 DROP COLUMN s", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "SELECT * FROM t2 ORDER BY c", Expected: []sql.Row{ {1, 2}, {4, 5}, }, }, }, }, }
var DropColumnScripts = []ScriptTest{ { Name: "drop last column", SetUpScript: []string{ "ALTER TABLE mytable DROP COLUMN s", }, Assertions: []ScriptTestAssertion{ { Query: "SHOW FULL COLUMNS FROM mytable", Expected: []sql.Row{{"i", "bigint", nil, "NO", "PRI", nil, "", "", ""}}, }, { Query: "select * from mytable order by i", Expected: []sql.Row{{1}, {2}, {3}}, }, }, }, { Name: "drop first column", SetUpScript: []string{ "CREATE TABLE t1 (a int, b varchar(10), c bigint, k bigint primary key)", "insert into t1 values (1, 'abc', 2, 3), (4, 'def', 5, 6)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t1 DROP COLUMN a", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM t1", Expected: []sql.Row{ {"b", "varchar(10)", "utf8mb4_0900_bin", "YES", "", nil, "", "", ""}, {"c", "bigint", nil, "YES", "", nil, "", "", ""}, {"k", "bigint", nil, "NO", "PRI", nil, "", "", ""}, }, }, { Query: "SELECT * FROM t1 ORDER BY b", Expected: []sql.Row{ {"abc", 2, 3}, {"def", 5, 6}, }, }, }, }, { Name: "drop middle column", SetUpScript: []string{ "CREATE TABLE t2 (a int, b varchar(10), c bigint, k bigint primary key)", "insert into t2 values (1, 'abc', 2, 3), (4, 'def', 5, 6)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t2 DROP COLUMN b", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM t2", Expected: []sql.Row{ {"a", "int", nil, "YES", "", nil, "", "", ""}, {"c", "bigint", nil, "YES", "", nil, "", "", ""}, {"k", "bigint", nil, "NO", "PRI", nil, "", "", ""}, }, }, { Query: "SELECT * FROM t2 ORDER BY c", Expected: []sql.Row{ {1, 2, 3}, {4, 5, 6}, }, }, }, }, { Name: "drop primary key column", SetUpScript: []string{ "CREATE TABLE t3 (a int primary key, b varchar(10), c bigint)", "insert into t3 values (1, 'abc', 2), (3, 'def', 4)", }, Assertions: []ScriptTestAssertion{ { Skip: true, Query: "ALTER TABLE t3 DROP COLUMN a", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Skip: true, Query: "SHOW FULL COLUMNS FROM t3", Expected: []sql.Row{ {"b", "varchar(10)", "utf8mb4_0900_bin", "YES", "", nil, "", "", ""}, {"c", "bigint", nil, "YES", "", nil, "", "", ""}, }, }, { Skip: true, Query: "SELECT * FROM t3 ORDER BY b", Expected: []sql.Row{ {"abc", 2}, {"def", 4}, }, }, }, }, { Name: "error cases", SetUpScript: []string{ "create table t4 (a int primary key, b int, c int default (b+10))", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE not_exist DROP COLUMN s", ExpectedErr: sql.ErrTableNotFound, }, { Query: "ALTER TABLE mytable DROP COLUMN s", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE t4 DROP COLUMN b", ExpectedErr: sql.ErrDropColumnReferencedInDefault, }, }, }, }
var DropDatabaseScripts = []ScriptTest{ { Name: "DROP DATABASE correctly works", Assertions: []ScriptTestAssertion{ { Query: "DROP DATABASE mydb", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "SELECT DATABASE()", Expected: []sql.Row{{nil}}, }, { Skip: true, Query: "SHOW TABLES", ExpectedErr: sql.ErrNoDatabaseSelected, }, }, }, { Name: "DROP DATABASE works on newly created databases.", SetUpScript: []string{ "CREATE DATABASE testdb", }, Assertions: []ScriptTestAssertion{ { Query: "USE testdb", Expected: []sql.Row{}, }, { Query: "DROP DATABASE testdb", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "USE testdb", ExpectedErr: sql.ErrDatabaseNotFound, }, }, }, { Name: "DROP DATABASE works on current database and sets current database to empty.", SetUpScript: []string{ "CREATE DATABASE testdb", "USE TESTdb", }, Assertions: []ScriptTestAssertion{ { Query: "DROP DATABASE TESTDB", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "SELECT DATABASE()", Expected: []sql.Row{{nil}}, }, { Query: "USE testdb", ExpectedErr: sql.ErrDatabaseNotFound, }, }, }, { Name: "DROP SCHEMA works on newly created databases.", SetUpScript: []string{ "CREATE SCHEMA testdb", }, Assertions: []ScriptTestAssertion{ { Query: "DROP SCHEMA TESTDB", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "USE testdb", ExpectedErr: sql.ErrDatabaseNotFound, }, }, }, { Name: "DROP DATABASE IF EXISTS correctly works.", SetUpScript: []string{ "DROP DATABASE mydb", "CREATE DATABASE testdb", }, Assertions: []ScriptTestAssertion{ { Query: "DROP DATABASE IF EXISTS mydb", Expected: []sql.Row{{types.OkResult{RowsAffected: 0}}}, }, { Query: "SHOW WARNINGS", Expected: []sql.Row{{"Note", 1008, "Can't drop database mydb; database doesn't exist "}}, }, { Query: "DROP DATABASE IF EXISTS testdb", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "SHOW WARNINGS", Expected: []sql.Row{}, }, { Query: "SELECT DATABASE()", Expected: []sql.Row{{nil}}, }, { Query: "USE testdb", ExpectedErr: sql.ErrDatabaseNotFound, }, { Query: "DROP DATABASE IF EXISTS testdb", Expected: []sql.Row{{types.OkResult{RowsAffected: 0}}}, }, { Query: "SHOW WARNINGS", Expected: []sql.Row{{"Note", 1008, "Can't drop database testdb; database doesn't exist "}}, }, }, }, }
var DropForeignKeyTests = []ScriptTest{ { Name: "basic drop foreign key tests", SetUpScript: []string{ "CREATE TABLE parent(a INTEGER PRIMARY KEY, b INTEGER)", "ALTER TABLE parent ADD INDEX pb (b)", `CREATE TABLE child(c INTEGER PRIMARY KEY, d INTEGER, CONSTRAINT fk1 FOREIGN KEY (D) REFERENCES parent(B) ON DELETE CASCADE )`, "CREATE TABLE child2(e INTEGER PRIMARY KEY, f INTEGER)", `ALTER TABLE child2 ADD CONSTRAINT fk2 FOREIGN KEY (f) REFERENCES parent(b) ON DELETE RESTRICT, ADD CONSTRAINT fk3 FOREIGN KEY (f) REFERENCES child(d) ON UPDATE SET NULL`, }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child2 DROP CONSTRAINT fk2", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: `SELECT RC.CONSTRAINT_NAME, RC.CONSTRAINT_SCHEMA, RC.TABLE_NAME, KCU.COLUMN_NAME, KCU.REFERENCED_TABLE_SCHEMA, KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME, RC.UPDATE_RULE, RC.DELETE_RULE FROM information_schema.REFERENTIAL_CONSTRAINTS RC, information_schema.KEY_COLUMN_USAGE KCU WHERE RC.TABLE_NAME = 'child2' AND RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME AND RC.TABLE_NAME = KCU.TABLE_NAME AND RC.REFERENCED_TABLE_NAME = KCU.REFERENCED_TABLE_NAME;`, Expected: []sql.Row{ {"fk3", "mydb", "child2", "f", "mydb", "child", "d", "SET NULL", "NO ACTION"}, }, }, { Query: "ALTER TABLE child2 DROP CONSTRAINT fk3", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: `SELECT RC.CONSTRAINT_NAME, RC.CONSTRAINT_SCHEMA, RC.TABLE_NAME, KCU.COLUMN_NAME, KCU.REFERENCED_TABLE_SCHEMA, KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME, RC.UPDATE_RULE, RC.DELETE_RULE FROM information_schema.REFERENTIAL_CONSTRAINTS RC, information_schema.KEY_COLUMN_USAGE KCU WHERE RC.TABLE_NAME = 'child2' AND RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME AND RC.TABLE_NAME = KCU.TABLE_NAME AND RC.REFERENCED_TABLE_NAME = KCU.REFERENCED_TABLE_NAME;`, Expected: []sql.Row{}, }, }, }, { Name: "error cases", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE child3 DROP CONSTRAINT dne", ExpectedErr: sql.ErrTableNotFound, }, { Query: "ALTER TABLE child2 DROP CONSTRAINT fk3", ExpectedErr: sql.ErrUnknownConstraint, }, { Query: "ALTER TABLE child2 DROP FOREIGN KEY fk3", ExpectedErr: sql.ErrForeignKeyNotFound, }, }, }, }
var ErrorQueries = []QueryErrorTest{}/* 129 elements not displayed */
var EventCreateInSubroutineTests = []ScriptTest{ { Name: "procedure must not contain CREATE EVENT", Assertions: []ScriptTestAssertion{ { Query: "CREATE PROCEDURE foo() CREATE EVENT bar ON SCHEDULE EVERY 1 YEAR DO SELECT 1;", ExpectedErrStr: "Recursion of EVENT DDL statements is forbidden when body is present", Skip: true, }, }, }, { Name: "event must not contain CREATE EVENT", Assertions: []ScriptTestAssertion{ { Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE EVENT bar ON SCHEDULE EVERY 1 YEAR DO SELECT 1;", ExpectedErrStr: "Recursion of EVENT DDL statements is forbidden when body is present", Skip: true, }, }, }, { Name: "trigger must not contain CREATE EVENT", SetUpScript: []string{ "CREATE TABLE t (pk INT PRIMARY KEY);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN CREATE EVENT bar ON SCHEDULE EVERY 1 YEAR DO SELECT 1; END", ExpectedErrStr: "Recursion of EVENT DDL statements is forbidden when body is present", Skip: true, }, }, }, }
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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "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 '38-01-16 12:2:3.' + 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 12:02:03", 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' + 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{}}}, ExpectedWarning: 1537, ExpectedWarningsCount: 1, ExpectedWarningMessageSubstring: "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{}}}, ExpectedWarning: 1305, ExpectedWarningsCount: 1, ExpectedWarningMessageSubstring: "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{}}}, ExpectedWarning: 1588, ExpectedWarningMessageSubstring: "Event execution time is in the past and ON COMPLETION NOT PRESERVE is set. The event was dropped immediately after creation.", ExpectedWarningsCount: 1, }, { 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{}}}, ExpectedWarning: 1544, ExpectedWarningMessageSubstring: "Event execution time is in the past. Event has been disabled", ExpectedWarningsCount: 1, }, { 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"}}, }, { Query: "CREATE EVENT myevent ON SCHEDULE AT CURRENT_TIMESTAMP ON COMPLETION PRESERVE DISABLE ON SLAVE DO INSERT INTO totals VALUES (100);", Expected: []sql.Row{{types.OkResult{}}}, ExpectedWarning: 1235, ExpectedWarningMessageSubstring: "DISABLE ON SLAVE status is not supported yet, used DISABLE status instead", ExpectedWarningsCount: 1, }, }, }, { 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{}}}, ExpectedWarning: 1544, ExpectedWarningsCount: 1, ExpectedWarningMessageSubstring: "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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "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: "SHOW CREATE EVENT my_event1;", Expected: []sql.Row{{"my_event1", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "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 RENAME TO newEventName;", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "SHOW CREATE EVENT newEventName;", Expected: []sql.Row{{"newEventName", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "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 `fk_named` (`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 `fk_named` (`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 `fk_name` (`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 `fk_name` (`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 `fk_name` (`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 `fk_name` (`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 autogenerated FK name", SetUpScript: []string{ `CREATE TABLE a_test (id INT PRIMARY KEY);`, `CREATE TABLE b_test( a_id INT, FOREIGN KEY (a_id) REFERENCES a_test (id) );`, }, Assertions: []ScriptTestAssertion{ { Query: "RENAME TABLE b_test TO c_test;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW CREATE TABLE c_test;", Expected: []sql.Row{{"c_test", "CREATE TABLE `c_test` (\n `a_id` int,\n KEY `a_id` (`a_id`),\n " + "CONSTRAINT `c_test_ibfk_1` FOREIGN KEY (`a_id`) REFERENCES `a_test` (`id`)\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: "DROP SELF REFERENCED TABLE", SetUpScript: []string{ "create table t ( i int primary key, j int, index(j), foreign key (j) references t(i));", }, Assertions: []ScriptTestAssertion{ { Query: "DROP TABLE t;", 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 `fk1` (`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: "SELECT * FROM parent order by v1;", Expected: []sql.Row{{1, 1, 1}, {2, 2, 2}}, }, { Query: "UPDATE parent SET v1 = 2 WHERE id = 1;", ExpectedErr: sql.ErrForeignKeyParentViolation, }, { Query: "SELECT * FROM parent order by v1;", Expected: []sql.Row{{1, 1, 1}, {2, 2, 2}}, }, { Query: "REPLACE INTO parent VALUES (1, 1, 2), (2, 2, 1);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, { Query: "SELECT * FROM parent order by v1;", Expected: []sql.Row{{1, 1, 1}, {2, 2, 2}}, }, { 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 order by v1;", 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: update", SetUpScript: []string{ "set foreign_key_checks=0;", "create table delayed_parent(pk int primary key);", "create table delayed_child(pk int primary key, foreign key(pk) references delayed_parent(pk));", "insert into delayed_parent values (10), (20);", "insert into delayed_child values (1), (20);", "set foreign_key_checks=1;", }, Assertions: []ScriptTestAssertion{ { Skip: true, Query: "update delayed_child set pk=1 where pk=1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 0, Info: plan.UpdateInfo{Matched: 1, Updated: 0}}}, }, }, { Query: "update delayed_child set pk=3 where pk=3;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 0, Info: plan.UpdateInfo{Matched: 0, Updated: 0}}}, }, }, { Query: "update delayed_child set pk=20 where pk=20;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 0, Info: plan.UpdateInfo{Matched: 1, Updated: 0}}}, }, }, { Query: "update delayed_child set pk=10 where pk=1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, }, }, { Name: "Delayed foreign key resolution: delete", SetUpScript: []string{ "set foreign_key_checks=0;", "create table delayed_parent(pk int primary key);", "create table delayed_child(pk int primary key, foreign key(pk) references delayed_parent(pk));", "insert into delayed_parent values (10), (20);", "insert into delayed_child values (1), (20);", "set foreign_key_checks=1;", }, Assertions: []ScriptTestAssertion{ { Query: "delete from delayed_child where false;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, }, { Query: "delete from delayed_child where pk = 20;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, { Query: "delete from delayed_child where pk = 1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, }, }, { Name: "Delayed foreign key resolution insert", 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 `fk_delayed` (`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 valid_fk", 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 `fk_delayed` (`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 `fk` (`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: "Self-referential foreign key is not case sensitive", SetUpScript: []string{ "create table t1 (i int primary key, J int, constraint fk1 foreign key (J) references t1(i));", "create table t2 (I int primary key, j int, constraint fk2 foreign key (j) references t2(I));", "create table t3 (i int primary key, j int, constraint fk3 foreign key (J) references t3(I));", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t1;", Expected: []sql.Row{ {"t1", "CREATE TABLE `t1` (\n" + " `i` int NOT NULL,\n `J` int,\n" + " PRIMARY KEY (`i`),\n" + " KEY `fk1` (`J`),\n" + " CONSTRAINT `fk1` FOREIGN KEY (`J`) REFERENCES `t1` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into t1 values (1, 1);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "insert into t1 values (2, 3);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, { Query: "show create table t2;", Expected: []sql.Row{ {"t2", "CREATE TABLE `t2` (\n" + " `I` int NOT NULL,\n" + " `j` int,\n" + " PRIMARY KEY (`I`),\n" + " KEY `fk2` (`j`),\n" + " CONSTRAINT `fk2` FOREIGN KEY (`j`) REFERENCES `t2` (`I`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into t2 values (1, 1);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "insert into t2 values (2, 3);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, { Query: "show create table t3;", Expected: []sql.Row{ {"t3", "CREATE TABLE `t3` (\n" + " `i` int NOT NULL,\n `j` int,\n" + " PRIMARY KEY (`i`),\n" + " KEY `fk3` (`j`),\n" + " CONSTRAINT `fk3` FOREIGN KEY (`j`) REFERENCES `t3` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into t3 values (1, 1);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "insert into t3 values (2, 3);", ExpectedErr: sql.ErrForeignKeyChildViolation, }, }, }, { 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 `fk1` (`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 `fk2` (`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 `fk3` (`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 `fk4` (`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 `fk4` (`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"}, }, }, }, }, { Name: "rename foreign key constraints", SetUpScript: []string{ "create table myparent (i int primary key)", "create table mychild (j int primary key)", "alter table mychild add constraint `myfk` foreign key (j) references myparent (i)", }, Assertions: []ScriptTestAssertion{ { Query: "show create table mychild;", Expected: []sql.Row{ {"mychild", "CREATE TABLE `mychild` (\n" + " `j` int NOT NULL,\n" + " PRIMARY KEY (`j`),\n" + " CONSTRAINT `myfk` FOREIGN KEY (`j`) REFERENCES `myparent` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table mychild rename constraint foreign key myfk to newfk;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table mychild;", Expected: []sql.Row{ {"mychild", "CREATE TABLE `mychild` (\n" + " `j` int NOT NULL,\n" + " PRIMARY KEY (`j`),\n" + " CONSTRAINT `newfk` FOREIGN KEY (`j`) REFERENCES `myparent` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table mychild rename constraint foreign key NeWfK to NewNewFk;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table mychild;", Expected: []sql.Row{ {"mychild", "CREATE TABLE `mychild` (\n" + " `j` int NOT NULL,\n" + " PRIMARY KEY (`j`),\n" + " CONSTRAINT `NewNewFk` FOREIGN KEY (`j`) REFERENCES `myparent` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, }, }, { Name: "rename check constraints", SetUpScript: []string{ "create table t (i int, constraint `mychk` check (i > 0))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t rename constraint check mychk to newchk;", ExpectedErr: sql.ErrUnsupportedFeature, }, { Query: "alter table t rename constraint mychk to newchk;", ExpectedErr: sql.ErrUnsupportedFeature, }, }, }, { Name: "foreign key naming", SetUpScript: []string{ "create table theparent (i int primary key);", "create table child1 (j int primary key);", "create table child2 (j int primary key);", "create table child3 (j int primary key);", "create table child4 (j int primary key);", "create table child5 (j int primary key);", "create table child6 (j int primary key);", "create table child7 (j int primary key);", }, Assertions: []ScriptTestAssertion{ { Query: "alter table child1 add foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "alter table child1 add foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "alter table child1 add foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table child1;", Expected: []sql.Row{ {"child1", "CREATE TABLE `child1` (\n" + " `j` int NOT NULL,\n" + " PRIMARY KEY (`j`),\n" + " CONSTRAINT `child1_ibfk_1` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`),\n" + " CONSTRAINT `child1_ibfk_2` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`),\n" + " CONSTRAINT `child1_ibfk_3` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table child2 add constraint `child2_ibfk_1` foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "alter table child2 add foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table child2;", Expected: []sql.Row{ {"child2", "CREATE TABLE `child2` (\n" + " `j` int NOT NULL,\n" + " PRIMARY KEY (`j`),\n" + " CONSTRAINT `child2_ibfk_1` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`),\n" + " CONSTRAINT `child2_ibfk_2` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table child2 add constraint `child2_ibfk_2` foreign key (j) references theparent (i);", ExpectedErr: sql.ErrForeignKeyDuplicateName, }, { Query: "alter table child3 add constraint `child3_ibfk_100` foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "alter table child3 add foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table child3;", Expected: []sql.Row{ {"child3", "CREATE TABLE `child3` (\n" + " `j` int NOT NULL,\n" + " PRIMARY KEY (`j`),\n" + " CONSTRAINT `child3_ibfk_100` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`),\n" + " CONSTRAINT `child3_ibfk_101` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table child4 add constraint `CHILD4_IBFK_1` foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "alter table child4 add foreign key (j) references theparent (i);", ExpectedErr: sql.ErrForeignKeyDuplicateName, }, { Query: "show create table child4;", Expected: []sql.Row{ {"child4", "CREATE TABLE `child4` (\n" + " `j` int NOT NULL,\n" + " PRIMARY KEY (`j`),\n" + " CONSTRAINT `CHILD4_IBFK_1` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table child5 add constraint `child5_ibfk_-2` foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "alter table child5 add foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "alter table child5 add foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "alter table child5 add foreign key (j) references theparent (i);", ExpectedErr: sql.ErrForeignKeyDuplicateName, }, { Query: "show create table child5;", Expected: []sql.Row{ {"child5", "CREATE TABLE `child5` (\n" + " `j` int NOT NULL,\n" + " PRIMARY KEY (`j`),\n" + " CONSTRAINT `child5_ibfk_-2` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`),\n" + " CONSTRAINT `child5_ibfk_0` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`),\n" + " CONSTRAINT `child5_ibfk_4294967295` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table child6 add constraint `` foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "alter table child6 add foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Skip: true, Query: "show create table child6;", Expected: []sql.Row{ {"child6", "CREATE TABLE `child6` (\n" + " `j` int NOT NULL,\n" + " PRIMARY KEY (`j`),\n" + " CONSTRAINT `child6_ibfk_1` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`),\n" + " CONSTRAINT `child6_ibfk_2` FOREIGN KEY (`j`) REFERENCES `theparent` (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table child1 add constraint `child7_ibfk_1` foreign key (j) references theparent (i);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "alter table child7 add foreign key (j) references theparent (i);", ExpectedErr: sql.ErrForeignKeyDuplicateName, }, }, }, { Name: "Naming automatically created FK indexes", SetUpScript: []string{ `CREATE TABLE child1 ( id int NOT NULL, v1 int DEFAULT NULL, v2 int DEFAULT NULL, PRIMARY KEY (id), KEY fk_name (v1), KEY (id, v1) );`, `CREATE TABLE parent1( a_id1 INT, a_id2 INT, a_id3 INT, CONSTRAINT fk_b_a FOREIGN KEY (a_id2, a_id3) REFERENCES child1 (id, v1) );`, `CREATE TABLE parent2 ( v1 int NOT NULL, v2 int NOT NULL, v3 int NOT NULL, v4 int NOT NULL, v5 int NOT NULL, PRIMARY KEY (v1), KEY fk1 (v4), KEY v2 (v5) );`, }, Assertions: []ScriptTestAssertion{ { Query: "SELECT TABLE_NAME, INDEX_NAME, COLUMN_NAME, SEQ_IN_INDEX FROM information_schema.STATISTICS WHERE TABLE_NAME='parent1' ORDER BY INDEX_NAME, SEQ_IN_INDEX;", Expected: []sql.Row{ {"parent1", "fk_b_a", "a_id2", 1}, {"parent1", "fk_b_a", "a_id3", 2}, }, }, { Query: "ALTER TABLE parent2 ADD CONSTRAINT `fk1` FOREIGN KEY (v2) REFERENCES child1(v1);", ExpectedErr: sql.ErrDuplicateKey, }, { Query: "ALTER TABLE parent2 ADD FOREIGN KEY (v2) REFERENCES child1(v1);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT TABLE_NAME, INDEX_NAME, COLUMN_NAME, SEQ_IN_INDEX FROM information_schema.STATISTICS WHERE TABLE_NAME='parent2' ORDER BY INDEX_NAME, SEQ_IN_INDEX;", Expected: []sql.Row{ {"parent2", "fk1", "v4", 1}, {"parent2", "PRIMARY", "v1", 1}, {"parent2", "v2", "v5", 1}, {"parent2", "v2_2", "v2", 1}, }, }, }, }, { Name: "partial foreign key update", SetUpScript: []string{ "create table parent1 (i int primary key);", "create table child1 (" + "i int primary key, " + "j int, " + "k int, " + "index(j), " + "index(k), " + "foreign key (j) references parent1 (i)," + "foreign key (k) references parent1 (i));", "insert into parent1 values (1);", "insert into child1 values (100, 1, 1);", "set foreign_key_checks = 0;", "insert into child1 values (101, 2, 2);", "set foreign_key_checks = 1;", }, Assertions: []ScriptTestAssertion{ { Query: "update child1 set j = 1 where i = 101;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { Query: "select * from child1", Expected: []sql.Row{ {100, 1, 1}, {101, 1, 2}, }, }, }, }, { Name: "multiple foreign key refs", SetUpScript: []string{ "create table parent1 (i int primary key);", "create table child1 (j int, k int, foreign key (j) references parent1(i) on delete cascade on update cascade, foreign key (k) references parent1 (i) on delete cascade on update cascade);", "insert into parent1 values (1), (2), (3);", "insert into child1 values (1, 2), (2, 3), (3, 1);", }, Assertions: []ScriptTestAssertion{ { Query: "select * from parent1;", Expected: []sql.Row{ {1}, {2}, {3}, }, }, { Query: "select * from child1 order by j, k;", Expected: []sql.Row{ {1, 2}, {2, 3}, {3, 1}, }, }, { Query: "update parent1 set i = 20 where i = 2;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { Query: "select * from parent1 order by i;", Expected: []sql.Row{ {1}, {3}, {20}, }, }, { Query: "select * from child1 order by j, k;", Expected: []sql.Row{ {1, 20}, {3, 1}, {20, 3}, }, }, { Query: "delete from parent1 where i = 1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, { Query: "select * from parent1;", Expected: []sql.Row{ {3}, {20}, }, }, { Query: "select * from child1 order by j, k;", Expected: []sql.Row{ {20, 3}, }, }, }, }, }
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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT pk, v1 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi"}}, }, { Query: "SELECT v1, v2 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: true, Expected: []sql.Row{{"ghi", "jkl"}}, }, { Query: "SELECT pk, v1, v2 FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT pk, v2 FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "jkl"}}, }, { Query: "SELECT v1 FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", CheckIndexedAccess: true, Expected: []sql.Row{{"ghi"}}, }, { Query: "SELECT v2 FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", CheckIndexedAccess: true, Expected: []sql.Row{{"jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl') = 0;", CheckIndexedAccess: false, 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;", CheckIndexedAccess: false, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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;", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(3), "mno", "mno"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno') OR pk = 1;", CheckIndexedAccess: false, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT uk, v1 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi"}}, }, { Query: "SELECT uk, v2, v1 FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "jkl", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: false, Expected: []sql.Row{{"ghi", "jkl"}}, }, { Query: "SELECT v1 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: false, Expected: []sql.Row{{"ghi"}}, }, { Query: "SELECT v2 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: false, Expected: []sql.Row{{"jkl"}}, }, { Query: "SELECT v2, v1 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: false, Expected: []sql.Row{{"jkl", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl');", CheckIndexedAccess: false, Expected: []sql.Row{{"ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: false, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", uint64(1), "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}}, }, { Query: "SELECT v2, uk2 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: true, Expected: []sql.Row{{"jkl", uint64(1)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), uint64(1), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", uint64(1), "jkl"}}, }, { Query: "SELECT v2, uk2 FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: true, Expected: []sql.Row{{"jkl", uint64(1)}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('rgb');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(1), "abc", nil}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('jkl');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), nil, "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST (NULL);", CheckIndexedAccess: true, Expected: []sql.Row{}, }, { Query: "SELECT pk, v1, v2, MATCH(v1, v2) AGAINST (NULL) FROM test;", CheckIndexedAccess: false, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v2, v1) AGAINST ('jkl') = 0;", CheckIndexedAccess: false, 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;", CheckIndexedAccess: false, Expected: []sql.Row{{uint64(3), "mno", "mno"}}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v1, v2) AGAINST ('GHI');", CheckIndexedAccess: true, Expected: []sql.Row{}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v2, v1) AGAINST ('JKL') = 0;", CheckIndexedAccess: false, 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;", CheckIndexedAccess: false, Expected: []sql.Row{}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v2, v1) AGAINST ('jkl') = 0;", CheckIndexedAccess: false, 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;", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(3), "mno", "mno"}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v1, v2) AGAINST ('GHI');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v2, v1) AGAINST ('JKL') = 0;", CheckIndexedAccess: false, 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;", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(2), "ghi", "jkl"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v1) AGAINST ('jkl mno');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(1), "abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2) AGAINST ('def');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(1), "abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v3) AGAINST ('ghi');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, ExpectedErr: sql.ErrColumnNotFound, }, { Query: "SELECT * FROM test WHERE MATCH(v2) AGAINST ('def');", CheckIndexedAccess: true, ExpectedErr: sql.ErrColumnNotFound, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v3) AGAINST ('ghi');", CheckIndexedAccess: true, ExpectedErr: sql.ErrColumnNotFound, }, { Query: "SELECT * FROM test WHERE MATCH(v1) AGAINST ('abc');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(1), "abc", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v3) AGAINST ('ghi');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, Expected: []sql.Row{{uint64(1), "abc"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v3) AGAINST ('ghi');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: false, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: true, 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');", CheckIndexedAccess: false, 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');", CheckIndexedAccess: false, Expected: []sql.Row{}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v1, v2) AGAINST ('abc');", CheckIndexedAccess: false, Expected: []sql.Row{{"abc", "def"}}, }, { Query: "SELECT * FROM test1 WHERE MATCH(v1, v2) AGAINST ('jkl');", CheckIndexedAccess: false, Expected: []sql.Row{{"ghi", "jkl"}}, }, { Query: "SELECT * FROM test2 WHERE MATCH(v1, v2) AGAINST ('jkl');", CheckIndexedAccess: false, 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');", CheckIndexedAccess: false, 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');", CheckIndexedAccess: false, Expected: []sql.Row{{"abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('def');", CheckIndexedAccess: false, Expected: []sql.Row{{"abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v2) AGAINST ('ghi');", CheckIndexedAccess: false, Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v3) AGAINST ('abc');", CheckIndexedAccess: false, Expected: []sql.Row{{"abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v3) AGAINST ('def');", CheckIndexedAccess: false, Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v1, v3) AGAINST ('ghi');", CheckIndexedAccess: false, Expected: []sql.Row{{"abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v3) AGAINST ('abc');", CheckIndexedAccess: false, Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v3) AGAINST ('def');", CheckIndexedAccess: false, Expected: []sql.Row{{"abc", "def", "ghi"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v2, v3) AGAINST ('ghi');", CheckIndexedAccess: false, 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.ErrDuplicateColumn, }, }, }, { Name: "References missing column", Assertions: []ScriptTestAssertion{ { Query: "CREATE TABLE test (v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v3));", ExpectedErr: sql.ErrKeyColumnDoesNotExist, }, }, }, { 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"}}, }, }, }, { Name: "Full-Text with default columns", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED NOT NULL DEFAULT '1', v1 VARCHAR(200) DEFAULT 'def', PRIMARY KEY(pk), FULLTEXT idx (v1));", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO test (v1) VALUES ('abc');", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "INSERT INTO test (pk, v1) VALUES (2, 'def');", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "SELECT * FROM test;", Expected: []sql.Row{{uint64(1), "abc"}, {uint64(2), "def"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1) AGAINST ('def');", Expected: []sql.Row{{uint64(2), "def"}}, }, }, }, { Name: "large tokens", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT UNSIGNED NOT NULL DEFAULT '1', v1 VARCHAR(200) DEFAULT 'def', PRIMARY KEY(pk), FULLTEXT idx (v1));", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO test (v1) VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1) AGAINST ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');", Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v1) AGAINST ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');", Expected: []sql.Row{}, }, { Query: "REPLACE INTO test (v1) VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "SELECT * FROM test;", Expected: []sql.Row{{uint64(1), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}}, }, { Query: "SELECT * FROM test WHERE MATCH(v1) AGAINST ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');", Expected: []sql.Row{}, }, { Query: "SELECT * FROM test WHERE MATCH(v1) AGAINST ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');", Expected: []sql.Row{}, }, }, }, }
var GeneratedColumnPlanTests = []QueryPlanTest{
{
Query: `select * from generated_stored_1 where b = 2 order by a`,
ExpectedPlan: "Sort(generated_stored_1.a:0!null ASC nullsFirst)\n" +
" └─ IndexedTableAccess(generated_stored_1)\n" +
" ├─ index: [generated_stored_1.b]\n" +
" ├─ static: [{[2, 2]}]\n" +
" ├─ colSet: (1,2)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: generated_stored_1\n" +
" └─ columns: [a b]\n" +
"",
ExpectedEstimates: "Sort(generated_stored_1.a ASC)\n" +
" └─ IndexedTableAccess(generated_stored_1)\n" +
" ├─ index: [generated_stored_1.b]\n" +
" ├─ filters: [{[2, 2]}]\n" +
" └─ columns: [a b]\n" +
"",
ExpectedAnalysis: "Sort(generated_stored_1.a ASC)\n" +
" └─ IndexedTableAccess(generated_stored_1)\n" +
" ├─ index: [generated_stored_1.b]\n" +
" ├─ filters: [{[2, 2]}]\n" +
" └─ columns: [a b]\n" +
"",
},
{
Query: `select * from generated_stored_2 where b = 2 and c = 3 order by a`,
ExpectedPlan: "Sort(generated_stored_2.a:0!null ASC nullsFirst)\n" +
" └─ IndexedTableAccess(generated_stored_2)\n" +
" ├─ index: [generated_stored_2.b,generated_stored_2.c]\n" +
" ├─ static: [{[2, 2], [3, 3]}]\n" +
" ├─ colSet: (1-3)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: generated_stored_2\n" +
" └─ columns: [a b c]\n" +
"",
ExpectedEstimates: "Sort(generated_stored_2.a ASC)\n" +
" └─ IndexedTableAccess(generated_stored_2)\n" +
" ├─ index: [generated_stored_2.b,generated_stored_2.c]\n" +
" ├─ filters: [{[2, 2], [3, 3]}]\n" +
" └─ columns: [a b c]\n" +
"",
ExpectedAnalysis: "Sort(generated_stored_2.a ASC)\n" +
" └─ IndexedTableAccess(generated_stored_2)\n" +
" ├─ index: [generated_stored_2.b,generated_stored_2.c]\n" +
" ├─ filters: [{[2, 2], [3, 3]}]\n" +
" └─ columns: [a b c]\n" +
"",
},
{
Query: `delete from generated_stored_2 where b = 3 and c = 4`,
ExpectedPlan: "Delete\n" +
" └─ IndexedTableAccess(generated_stored_2)\n" +
" ├─ index: [generated_stored_2.b,generated_stored_2.c]\n" +
" ├─ static: [{[3, 3], [4, 4]}]\n" +
" ├─ colSet: (1-3)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: generated_stored_2\n" +
" └─ columns: [a b c]\n" +
"",
},
{
Query: `update generated_stored_2 set a = 5, c = 10 where b = 2 and c = 3`,
ExpectedPlan: "Update\n" +
" └─ UpdateSource(SET generated_stored_2.a:0!null = 5 (tinyint),SET generated_stored_2.c:2 = 10 (tinyint),SET generated_stored_2.b:1 = parenthesized((generated_stored_2.a:0!null + 1 (tinyint))))\n" +
" └─ IndexedTableAccess(generated_stored_2)\n" +
" ├─ index: [generated_stored_2.b,generated_stored_2.c]\n" +
" ├─ static: [{[2, 2], [3, 3]}]\n" +
" ├─ colSet: (1-3)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: generated_stored_2\n" +
" └─ columns: [a b c]\n" +
"",
},
{
Query: `select * from generated_virtual_1 where c = 7`,
ExpectedPlan: "IndexedTableAccess(generated_virtual_1)\n" +
" ├─ index: [generated_virtual_1.c]\n" +
" ├─ static: [{[7, 7]}]\n" +
" ├─ colSet: (4-6)\n" +
" ├─ tableId: 2\n" +
" └─ VirtualColumnTable\n" +
" ├─ name: generated_virtual_1\n" +
" ├─ columns: [generated_virtual_1.a:0!null, generated_virtual_1.b:1, parenthesized((generated_virtual_1.a:0!null + generated_virtual_1.b:1))]\n" +
" └─ Table\n" +
" ├─ name: generated_virtual_1\n" +
" └─ columns: [a b c]\n" +
"",
ExpectedEstimates: "IndexedTableAccess(generated_virtual_1)\n" +
" ├─ index: [generated_virtual_1.c]\n" +
" └─ filters: [{[7, 7]}]\n" +
"",
ExpectedAnalysis: "IndexedTableAccess(generated_virtual_1)\n" +
" ├─ index: [generated_virtual_1.c]\n" +
" └─ filters: [{[7, 7]}]\n" +
"",
},
{
Query: `update generated_virtual_1 set b = 5 where c = 3`,
ExpectedPlan: "Update\n" +
" └─ UpdateSource(SET generated_virtual_1.b:1 = 5 (tinyint),SET generated_virtual_1.c:2 = parenthesized((generated_virtual_1.a:0!null + generated_virtual_1.b:1)))\n" +
" └─ IndexedTableAccess(generated_virtual_1)\n" +
" ├─ index: [generated_virtual_1.c]\n" +
" ├─ static: [{[3, 3]}]\n" +
" ├─ colSet: (4-6)\n" +
" ├─ tableId: 2\n" +
" └─ VirtualColumnTable\n" +
" ├─ name: generated_virtual_1\n" +
" ├─ columns: [generated_virtual_1.a:0!null, generated_virtual_1.b:1, parenthesized((generated_virtual_1.a:0!null + generated_virtual_1.b:1))]\n" +
" └─ Table\n" +
" ├─ name: generated_virtual_1\n" +
" └─ columns: [a b c]\n" +
"",
},
{
Query: `delete from generated_virtual_1 where c = 6`,
ExpectedPlan: "Delete\n" +
" └─ IndexedTableAccess(generated_virtual_1)\n" +
" ├─ index: [generated_virtual_1.c]\n" +
" ├─ static: [{[6, 6]}]\n" +
" ├─ colSet: (4-6)\n" +
" ├─ tableId: 2\n" +
" └─ VirtualColumnTable\n" +
" ├─ name: generated_virtual_1\n" +
" ├─ columns: [generated_virtual_1.a:0!null, generated_virtual_1.b:1, parenthesized((generated_virtual_1.a:0!null + generated_virtual_1.b:1))]\n" +
" └─ Table\n" +
" ├─ name: generated_virtual_1\n" +
" └─ columns: [a b c]\n" +
"",
},
{
Query: `select * from generated_virtual_keyless where v = 2`,
ExpectedPlan: "IndexedTableAccess(generated_virtual_keyless)\n" +
" ├─ index: [generated_virtual_keyless.v]\n" +
" ├─ static: [{[2, 2]}]\n" +
" ├─ colSet: (3,4)\n" +
" ├─ tableId: 2\n" +
" └─ VirtualColumnTable\n" +
" ├─ name: generated_virtual_keyless\n" +
" ├─ columns: [generated_virtual_keyless.j:0, parenthesized(json_unquote(json_extract(generated_virtual_keyless.j, '$.a')))]\n" +
" └─ Table\n" +
" ├─ name: generated_virtual_keyless\n" +
" └─ columns: [j v]\n" +
"",
ExpectedEstimates: "IndexedTableAccess(generated_virtual_keyless)\n" +
" ├─ index: [generated_virtual_keyless.v]\n" +
" └─ filters: [{[2, 2]}]\n" +
"",
ExpectedAnalysis: "IndexedTableAccess(generated_virtual_keyless)\n" +
" ├─ index: [generated_virtual_keyless.v]\n" +
" └─ filters: [{[2, 2]}]\n" +
"",
},
{
Query: `update generated_virtual_keyless set j = '{"a": 5}' where v = 2`,
ExpectedPlan: "Update\n" +
" └─ UpdateSource(SET generated_virtual_keyless.j:0 = {\"a\": 5} (longtext),SET generated_virtual_keyless.v:1 = parenthesized(json_unquote(json_extract(generated_virtual_keyless.j, '$.a'))))\n" +
" └─ IndexedTableAccess(generated_virtual_keyless)\n" +
" ├─ index: [generated_virtual_keyless.v]\n" +
" ├─ static: [{[2, 2]}]\n" +
" ├─ colSet: (3,4)\n" +
" ├─ tableId: 2\n" +
" └─ VirtualColumnTable\n" +
" ├─ name: generated_virtual_keyless\n" +
" ├─ columns: [generated_virtual_keyless.j:0, parenthesized(json_unquote(json_extract(generated_virtual_keyless.j, '$.a')))]\n" +
" └─ Table\n" +
" ├─ name: generated_virtual_keyless\n" +
" └─ columns: [j v]\n" +
"",
},
{
Query: `delete from generated_virtual_keyless where v = 5`,
ExpectedPlan: "Delete\n" +
" └─ IndexedTableAccess(generated_virtual_keyless)\n" +
" ├─ index: [generated_virtual_keyless.v]\n" +
" ├─ static: [{[5, 5]}]\n" +
" ├─ colSet: (3,4)\n" +
" ├─ tableId: 2\n" +
" └─ VirtualColumnTable\n" +
" ├─ name: generated_virtual_keyless\n" +
" ├─ columns: [generated_virtual_keyless.j:0, parenthesized(json_unquote(json_extract(generated_virtual_keyless.j, '$.a')))]\n" +
" └─ Table\n" +
" ├─ name: generated_virtual_keyless\n" +
" └─ columns: [j v]\n" +
"",
},
}
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}}, }, { Query: "insert into t1(a,b) values (4, DEFAULT)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 where b = 5 order by a", Expected: []sql.Row{{4, 5}}, }, { Query: "update t1 set b = b + 1", ExpectedErr: sql.ErrGeneratedColumnValue, }, { Query: "update t1 set a = 10 where a = 1", Expected: []sql.Row{{newUpdateResult(1, 1)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{2, 3}, {3, 4}, {4, 5}, {10, 11}}, }, { Query: "delete from t1 where b = 11", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{2, 3}, {3, 4}, {4, 5}}, }, }, }, { Name: "Add stored column first with literal", SetUpScript: []string{ "CREATE TABLE t16(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT '4')", "INSERT INTO t16 (pk) VALUES (1), (2)", "ALTER TABLE t16 ADD COLUMN v2 BIGINT AS (5) STORED FIRST", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t16", Expected: []sql.Row{{5, 1, 4}, {5, 2, 4}}}, }, }, { Name: "Add stored column first with expression", SetUpScript: []string{ "CREATE TABLE t17(pk BIGINT PRIMARY KEY, v1 BIGINT)", "INSERT INTO t17 VALUES (1, 3), (2, 4)", "ALTER TABLE t17 ADD COLUMN v2 BIGINT AS (v1 + 2) STORED FIRST", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t17", Expected: []sql.Row{{5, 1, 3}, {6, 2, 4}}}, }, }, { Name: "index on stored generated column", SetUpScript: []string{ "create table t1 (a int primary key, b int as (a + 1) stored)", }, Assertions: []ScriptTestAssertion{ { Query: "create index i1 on t1(b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { 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" + " KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t1(a) values (1), (2)", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, 2}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2}, {2, 3}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, 2}, {2, 3}}, }, { Query: "update t1 set a = 10 where a = 1", Expected: []sql.Row{{newUpdateResult(1, 1)}}, }, { Query: "select * from t1 where b = 11 order by a", Expected: []sql.Row{{10, 11}}, }, { Query: "delete from t1 where b = 11", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 where b = 3 order by a", Expected: []sql.Row{{2, 3}}, }, }, }, { Name: "creating index on stored generated column", SetUpScript: []string{ "create table t1 (a int primary key, b int as (a + 1) stored)", "insert into t1(a) values (1), (2)", }, Assertions: []ScriptTestAssertion{ { Query: "create index i1 on t1(b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { 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" + " KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, 2}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2}, {2, 3}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, 2}, {2, 3}}, }, }, }, { Name: "creating index on stored generated column with type conversion", SetUpScript: []string{ "create table t1 (a int primary key, b float generated always as (a + 1) stored)", "insert into t1(a) values (1), (2)", }, Assertions: []ScriptTestAssertion{ { Query: "create index i1 on t1(b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `a` int NOT NULL,\n" + " `b` float GENERATED ALWAYS AS ((`a` + 1)) STORED,\n" + " PRIMARY KEY (`a`),\n" + " KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, float64(2)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, float64(2)}, {2, float64(3)}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, float64(2)}, {2, float64(3)}}, }, }, }, { Name: "creating index on stored generated column within multi-alter statement", SetUpScript: []string{ "create table t1 (a int primary key, b int as (a + 1) stored)", "insert into t1(a) values (1), (2)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 add column c int as (b+1) stored, add index b1(b), add column d int as (b+2) stored", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { 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" + " `c` int GENERATED ALWAYS AS ((`b` + 1)) STORED,\n" + " `d` int GENERATED ALWAYS AS ((`b` + 2)) STORED,\n" + " PRIMARY KEY (`a`),\n" + " KEY `b1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, 2, 3, 4}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2, 3, 4}, {2, 3, 4, 5}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, 2, 3, 4}, {2, 3, 4, 5}}, }, }, }, { Name: "creating unique index on stored generated column", SetUpScript: []string{ "create table t1 (a int primary key, b int as (a * a) stored, c int as (0) stored)", "insert into t1(a) values (-1), (-2)", }, Assertions: []ScriptTestAssertion{ { Query: "create unique index i1 on t1(b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `a` int NOT NULL,\n" + " `b` int GENERATED ALWAYS AS ((`a` * `a`)) STORED,\n" + " `c` int GENERATED ALWAYS AS (0) STORED,\n" + " PRIMARY KEY (`a`),\n" + " UNIQUE KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select * from t1 where b = 4 order by a", Expected: []sql.Row{{-2, 4, 0}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{-2, 4, 0}, {-1, 1, 0}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{-1, 1, 0}, {-2, 4, 0}}, }, { Query: "insert into t1(a) values (2)", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "create unique index i2 on t1(c)", ExpectedErr: sql.ErrUniqueKeyViolation, }, }, }, { Name: "creating index on virtual generated column", SetUpScript: []string{ "create table t1 (a int primary key, b int as (a + 1) virtual)", "insert into t1(a) values (1), (2)", }, Assertions: []ScriptTestAssertion{ { Query: "create index i1 on t1(b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { 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)),\n" + " PRIMARY KEY (`a`),\n" + " KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, Skip: true, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, 2}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2}, {2, 3}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, 2}, {2, 3}}, }, }, }, { Name: "creating index on stored generated column with type conversion", SetUpScript: []string{ "create table t1 (a int primary key, b float generated always as (a + 1) stored)", "insert into t1(a) values (1), (2)", }, Assertions: []ScriptTestAssertion{ { Query: "create index i1 on t1(b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `a` int NOT NULL,\n" + " `b` float GENERATED ALWAYS AS ((`a` + 1)) STORED,\n" + " PRIMARY KEY (`a`),\n" + " KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, float64(2)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, float64(2)}, {2, float64(3)}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, float64(2)}, {2, float64(3)}}, }, }, }, { Name: "creating index on virtual generated column with type conversion", SetUpScript: []string{ "create table t1 (a int primary key, b float generated always as (a + 1))", "insert into t1(a) values (1), (2)", }, Assertions: []ScriptTestAssertion{ { Query: "create index i1 on t1(b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `a` int NOT NULL,\n" + " `b` float GENERATED ALWAYS AS ((`a` + 1)),\n" + " PRIMARY KEY (`a`),\n" + " KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, Skip: true, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, float64(2)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, float64(2)}, {2, float64(3)}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, float64(2)}, {2, float64(3)}}, }, }, }, { Name: "index on stored generated column and one non-generated column", SetUpScript: []string{ "create table t1 (a int primary key, b int as (a + 1) stored, c int)", }, Assertions: []ScriptTestAssertion{ { Query: "create index i1 on t1(b,c)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { 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" + " `c` int,\n" + " PRIMARY KEY (`a`),\n" + " KEY `i1` (`b`,`c`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t1(a,c) values (1,3)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 where b = 2 and c = 3 order by a", Expected: []sql.Row{{1, 2, 3}}, }, { Query: "insert into t1(a,c) values (2,4)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from t1 where b = 3 and c = 4", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2, 3}}, }, { Query: "update t1 set a = 5, c = 10 where b = 2 and c = 3", Expected: []sql.Row{{newUpdateResult(1, 1)}}, }, { Query: "select * from t1 where b = 6 and c = 10 order by a", Expected: []sql.Row{{5, 6, 10}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{5, 6, 10}}, }, }, }, { Name: "add new generated column", SetUpScript: []string{ "create table t1 (a int primary key, b int)", "insert into t1 values (1,2), (2,3), (3,4)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 add column c int as (a + b) stored", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2, 3}, {2, 3, 5}, {3, 4, 7}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `a` int NOT NULL,\n" + " `b` int,\n" + " `c` int GENERATED ALWAYS AS ((`a` + `b`)) STORED,\n" + " PRIMARY KEY (`a`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { Name: "stored generated column with spaces", SetUpScript: []string{ "create table tt (`col 1` int, `col 2` int);", }, Assertions: []ScriptTestAssertion{ { Query: "create table t (`col 1` int, `col 2` int, `col 3` int generated always as (`col 1` + `col 2` + pow(`col 1`, `col 2`)) stored);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `col 1` int,\n" + " `col 2` int,\n" + " `col 3` int GENERATED ALWAYS AS (((`col 1` + `col 2`) + power(`col 1`, `col 2`))) STORED\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into t (`col 1`, `col 2`) values (1, 2);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "select * from t", Expected: []sql.Row{ {1, 2, 4}, }, }, { Query: "alter table tt add column `col 3` int generated always as (`col 1` + `col 2` + pow(`col 1`, `col 2`)) stored;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table tt", Expected: []sql.Row{ {"tt", "CREATE TABLE `tt` (\n" + " `col 1` int,\n" + " `col 2` int,\n" + " `col 3` int GENERATED ALWAYS AS (((`col 1` + `col 2`) + power(`col 1`, `col 2`))) STORED\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into tt (`col 1`, `col 2`) values (1, 2);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "select * from tt", Expected: []sql.Row{ {1, 2, 4}, }, }, }, }, { Name: "virtual generated column with spaces", SetUpScript: []string{ "create table tt (`col 1` int, `col 2` int);", }, Assertions: []ScriptTestAssertion{ { Query: "create table t (`col 1` int, `col 2` int, `col 3` int generated always as (`col 1` + `col 2` + pow(`col 1`, `col 2`)) virtual);", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `col 1` int,\n" + " `col 2` int,\n" + " `col 3` int GENERATED ALWAYS AS (((`col 1` + `col 2`) + power(`col 1`, `col 2`)))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into t (`col 1`, `col 2`) values (1, 2);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "select * from t", Expected: []sql.Row{ {1, 2, 4}, }, }, { Query: "alter table tt add column `col 3` int generated always as (`col 1` + `col 2` + pow(`col 1`, `col 2`)) virtual;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table tt", Expected: []sql.Row{ {"tt", "CREATE TABLE `tt` (\n" + " `col 1` int,\n" + " `col 2` int,\n" + " `col 3` int GENERATED ALWAYS AS (((`col 1` + `col 2`) + power(`col 1`, `col 2`)))\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into tt (`col 1`, `col 2`) values (1, 2);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "select * from tt", Expected: []sql.Row{ {1, 2, 4}, }, }, }, }, { Name: "Add virtual column first with literal", SetUpScript: []string{ "CREATE TABLE t16(pk BIGINT PRIMARY KEY, v1 BIGINT DEFAULT '4')", "INSERT INTO t16 (pk) VALUES (1), (2)", "ALTER TABLE t16 ADD COLUMN v2 BIGINT AS (5) VIRTUAL FIRST", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t16", Expected: []sql.Row{{5, 1, 4}, {5, 2, 4}}}, }, }, { Name: "Add virtual column first with expression", SetUpScript: []string{ "CREATE TABLE t17(pk BIGINT PRIMARY KEY, v1 BIGINT)", "INSERT INTO t17 VALUES (1, 3), (2, 4)", "ALTER TABLE t17 ADD COLUMN v2 BIGINT AS (v1 + 2) VIRTUAL FIRST", }, Assertions: []ScriptTestAssertion{{ Query: "SELECT * FROM t17", Expected: []sql.Row{{5, 1, 3}, {6, 2, 4}}}, }, }, { Name: "virtual column inserts, updates, deletes", SetUpScript: []string{ "create table t1 (a int primary key, b int generated always as (a + 1) virtual)", }, Assertions: []ScriptTestAssertion{ { 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}}, }, { Query: "update t1 set a = 4 where a = 3", Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }}, }}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2}, {2, 3}, {4, 5}}, }, { Query: "delete from t1 where a = 2", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2}, {4, 5}}, }, { Query: "update t1 set b = b + 1", ExpectedErr: sql.ErrGeneratedColumnValue, }, }, }, { Name: "virtual column selects", SetUpScript: []string{ "create table t1 (a int primary key, b int generated always as (a + 1) virtual)", "create table t2 (c int primary key, d int generated always as (c - 1) virtual)", }, Assertions: []ScriptTestAssertion{ { 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}}, }, { Query: "insert into t2 (c) values (1), (2), (3)", Expected: []sql.Row{{types.NewOkResult(3)}}, }, { Query: "select * from t2 order by c", Expected: []sql.Row{{1, 0}, {2, 1}, {3, 2}}, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, 2}}, }, { Query: "select * from t2 where d = 2 order by c", Expected: []sql.Row{{3, 2}}, }, { Query: "select sum(b) from t1 where b > 2", Expected: []sql.Row{{7.0}}, }, { Query: "select sum(d) from t2 where d >= 1", Expected: []sql.Row{{3.0}}, }, { Query: "select a, (select b from t1 t1a where t1a.a = t1.a+1) from t1 order by a", Expected: []sql.Row{{1, 3}, {2, 4}, {3, nil}}, }, { Query: "select c, (select d from t2 t2a where t2a.c = t2.c+1) from t2 order by c", Expected: []sql.Row{{1, 1}, {2, 2}, {3, nil}}, }, { Query: "select * from t1 join t2 on a = c order by a", Expected: []sql.Row{{1, 2, 1, 0}, {2, 3, 2, 1}, {3, 4, 3, 2}}, }, { Query: "select * from t1 join t2 on a = d order by a", Expected: []sql.Row{{1, 2, 2, 1}, {2, 3, 3, 2}}, }, { Query: "select * from t1 join t2 on b = d order by a", Expected: []sql.Row{{1, 2, 3, 2}}, }, { Query: "select * from t1 join (select * from t2) as t3 on b = d order by a", Expected: []sql.Row{{1, 2, 3, 2}}, }, }, }, { Name: "virtual column in triggers", SetUpScript: []string{ "create table t1 (a int primary key, b int generated always as (a + 1) virtual)", "create table t2 (c int primary key, d int generated always as (c - 1) virtual)", }, Assertions: []ScriptTestAssertion{ { Query: "insert into t1 (a) values (1), (2), (3)", Expected: []sql.Row{{types.NewOkResult(3)}}, }, { Query: "insert into t2 (c) values (1), (2), (3)", Expected: []sql.Row{{types.NewOkResult(3)}}, }, { Query: "create trigger t1insert before insert on t1 for each row insert into t2 (c) values (new.b + 1)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "insert into t1 (a) values (4), (5)", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}}, }, { Query: "select * from t2 order by c", Expected: []sql.Row{{1, 0}, {2, 1}, {3, 2}, {6, 5}, {7, 6}}, }, }, }, { Name: "virtual column json extract", SetUpScript: []string{ "create table t1 (a int primary key, j json, b int generated always as (j->>'$.b') virtual)", }, Assertions: []ScriptTestAssertion{ { Query: `insert into t1 (a, j) values (1, '{"a": 1, "b": 2}'), (2, '{"a": 1}'), (3, '{"b": "300"}')`, Expected: []sql.Row{{types.NewOkResult(3)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{ {1, types.MustJSON(`{"a": 1, "b": 2}`), 2}, {2, types.MustJSON(`{"a": 1}`), nil}, {3, types.MustJSON(`{"b": "300"}`), 300}}, }, }, }, { Name: "virtual column with function", SetUpScript: []string{ "create table t1 (a varchar(255) primary key, b varchar(255), c varchar(512) generated always as (concat(a,b)) virtual)", }, Assertions: []ScriptTestAssertion{ { Query: `insert into t1 (a, b) values ('abc', '123'), ('def', null), ('ghi', '')`, Expected: []sql.Row{{types.NewOkResult(3)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{ {"abc", "123", "abc123"}, {"def", nil, nil}, {"ghi", "", "ghi"}, }, }, }, }, { Name: "physical columns added after virtual one", SetUpScript: []string{ "create table t (pk int primary key, col1 int as (pk + 1));", "insert into t (pk) values (1), (3)", "alter table t add index idx1 (col1, pk);", "alter table t add index idx2 (col1);", "alter table t add column col2 int;", "alter table t add column col3 int;", "insert into t (pk, col2, col3) values (2, 4, 5);", }, Assertions: []ScriptTestAssertion{ { Query: "select * from t order by pk", Expected: []sql.Row{ {1, 2, nil, nil}, {2, 3, 4, 5}, {3, 4, nil, nil}, }, }, { Query: "select * from t where col1 = 2", Expected: []sql.Row{ {1, 2, nil, nil}, }, }, { Query: "select * from t where col1 = 3 and pk = 2", Expected: []sql.Row{ {2, 3, 4, 5}, }, }, { Query: "select * from t where pk = 2", Expected: []sql.Row{ {2, 3, 4, 5}, }, }, }, }, { Name: "virtual column ordering", SetUpScript: []string{ "create table t1 (v1 int generated always as (2), a int, v2 int generated always as (a + v1), c int)", }, Assertions: []ScriptTestAssertion{ { Query: "insert into t1 (a, c) values (1,5), (3,7)", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "insert into t1 (c, a) values (5,6), (7,8)", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{ {2, 1, 3, 5}, {2, 3, 5, 7}, {2, 6, 8, 5}, {2, 8, 10, 7}, }, }, { Query: "update t1 set a = 4 where a = 3", Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, Info: plan.UpdateInfo{ Matched: 1, Updated: 1, }}, }}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{ {2, 1, 3, 5}, {2, 4, 6, 7}, {2, 6, 8, 5}, {2, 8, 10, 7}, }, }, { Query: "delete from t1 where v2 = 6", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{ {2, 1, 3, 5}, {2, 6, 8, 5}, {2, 8, 10, 7}, }, }, }, }, { Name: "adding a virtual column", SetUpScript: []string{ "create table t1 (a int primary key, b int)", }, Assertions: []ScriptTestAssertion{ { Query: "insert into t1 (a, b) values (1, 2), (3, 4)", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "alter table t1 add column c int generated always as (a + b) virtual", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2, 3}, {3, 4, 7}}, }, }, }, { Name: "creating index on virtual generated column", SetUpScript: []string{ "create table t1 (a int primary key, b int as (a + 1) virtual)", "insert into t1(a) values (1), (2)", }, Assertions: []ScriptTestAssertion{ { Query: "create index i1 on t1(b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { 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)),\n" + " PRIMARY KEY (`a`),\n" + " KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, Skip: true, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, 2}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2}, {2, 3}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, 2}, {2, 3}}, }, }, }, { Name: "virtual column index", SetUpScript: []string{ "create table t1 (a int primary key, b int, c int generated always as (a + b) virtual, index idx_c (c))", "insert into t1 (a, b) values (1, 2), (3, 4)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from t1 where c = 7", Expected: []sql.Row{{3, 4, 7}}, }, { Query: "select * from t1 where c = 8", Expected: []sql.Row{}, }, { Query: "update t1 set b = 5 where c = 3", Expected: []sql.Row{{newUpdateResult(1, 1)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{ {1, 5, 6}, {3, 4, 7}, }, }, { Query: "select * from t1 where c = 6", Expected: []sql.Row{ {1, 5, 6}, }, }, { Query: "delete from t1 where c = 6", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{ {3, 4, 7}, }, }, }, }, { Name: "virtual column index on a keyless table", SetUpScript: []string{ "create table t1 (j json, v int generated always as (j->>'$.a') virtual, index idx_v (v))", "insert into t1(j) values ('{\"a\": 1}'), ('{\"a\": 2}'), ('{\"b\": 3}')", }, Assertions: []ScriptTestAssertion{ { Query: "select * from t1 where v = 2", Expected: []sql.Row{{"{\"a\": 2}", 2}}, }, { Query: "update t1 set j = '{\"a\": 5}' where v = 2", Expected: []sql.Row{{newUpdateResult(1, 1)}}, }, { Query: "select * from t1 order by v", Expected: []sql.Row{ {"{\"b\": 3}", nil}, {"{\"a\": 1}", 1}, {"{\"a\": 5}", 5}}, }, { Query: "delete from t1 where v = 5", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 order by v", Expected: []sql.Row{ {"{\"b\": 3}", nil}, {"{\"a\": 1}", 1}, }, }, }, }, { Name: "creating index on virtual generated column with type conversion", SetUpScript: []string{ "create table t1 (a int primary key, b float generated always as (a + 1))", "insert into t1(a) values (1), (2)", }, Assertions: []ScriptTestAssertion{ { Query: "create index i1 on t1(b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `a` int NOT NULL,\n" + " `b` float GENERATED ALWAYS AS ((`a` + 1)),\n" + " PRIMARY KEY (`a`),\n" + " KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, Skip: true, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, float64(2)}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, float64(2)}, {2, float64(3)}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, float64(2)}, {2, float64(3)}}, }, }, }, { Name: "creating index on virtual generated column within multi-alter statement", SetUpScript: []string{ "create table t1 (a int primary key, b int as (a + 1) virtual)", "insert into t1(a) values (1), (2)", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t1 add column c int as (b+1) stored, add index b1(b), add column d int as (b+2) stored", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { 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)),\n" + " `c` int GENERATED ALWAYS AS ((`b` + 1)),\n" + " `d` int GENERATED ALWAYS AS ((`b` + 2)),\n" + " PRIMARY KEY (`a`),\n" + " KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, Skip: true, }, { Query: "select * from t1 where b = 2 order by a", Expected: []sql.Row{{1, 2, 3, 4}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2, 3, 4}, {2, 3, 4, 5}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{1, 2, 3, 4}, {2, 3, 4, 5}}, }, }, }, { Name: "creating unique index on virtual generated column", SetUpScript: []string{ "create table t1 (a int primary key, b int as (a * a) virtual, c int as (0) virtual)", "insert into t1(a) values (-1), (-2)", }, Assertions: []ScriptTestAssertion{ { Query: "create unique index i1 on t1(b)", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "show create table t1", Expected: []sql.Row{{"t1", "CREATE TABLE `t1` (\n" + " `a` int NOT NULL,\n" + " `b` int GENERATED ALWAYS AS ((`a` * `a`)),\n" + " `c` int GENERATED ALWAYS AS (0),\n" + " PRIMARY KEY (`a`),\n" + " KEY `i1` (`b`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, Skip: true, }, { Query: "select * from t1 where b = 4 order by a", Expected: []sql.Row{{-2, 4, 0}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{-2, 4, 0}, {-1, 1, 0}}, }, { Query: "select * from t1 order by b", Expected: []sql.Row{{-1, 1, 0}, {-2, 4, 0}}, }, { Query: "insert into t1(a) values (2)", ExpectedErr: sql.ErrUniqueKeyViolation, Skip: true, }, { Query: "create unique index i2 on t1(c)", ExpectedErr: sql.ErrUniqueKeyViolation, Skip: true, }, }, }, { Name: "illegal table definitions", SetUpScript: []string{ "create table t2 (a int generated always as (2), b int)", }, Assertions: []ScriptTestAssertion{ { Query: "create table t1 (a int generated always as (2), b int, primary key (a))", ExpectedErr: sql.ErrVirtualColumnPrimaryKey, }, { Query: "create table t1 (a int generated always as (2), b int, primary key (a, b))", ExpectedErr: sql.ErrVirtualColumnPrimaryKey, }, { Query: "alter table t2 add primary key (a)", ExpectedErr: sql.ErrVirtualColumnPrimaryKey, }, { Query: "alter table t2 add primary key (a, b)", ExpectedErr: sql.ErrVirtualColumnPrimaryKey, }, }, }, { Name: "generated columns in primary key", SetUpScript: []string{ "create table t2 (a int, b int generated always as (a + 2) stored, primary key (b))", "create table t3 (a int, b int generated always as (a + 2) stored, primary key (a, b))", }, Assertions: []ScriptTestAssertion{ { Query: "insert into t2 (a) values (1), (2)", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "select * from t2 order by a", Expected: []sql.Row{ {1, 3}, {2, 4}, }, }, { Query: "select * from t2 where b = 4", Expected: []sql.Row{ {2, 4}, }, }, { Query: "insert into t3 (a) values (1), (2)", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "select * from t3 order by a", Expected: []sql.Row{ {1, 3}, {2, 4}, }, }, { Query: "select * from t3 where a = 2 and b = 4", Expected: []sql.Row{ {2, 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}}, }, ExpectedWarningsCount: 1, 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}}, }, ExpectedWarningsCount: 1, 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)}}, ExpectedWarningsCount: 1, 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)}}, }, { 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)}}, ExpectedWarningsCount: 1, 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)}}, ExpectedWarningsCount: 2, ExpectedWarning: mysql.ERDupEntry, }, { Query: "SELECT * FROM keyless ORDER BY pk", Expected: []sql.Row{{1, 1}, {2, 2}, {3, 4}}, }, }, }, }
var ImdbPlanTests = []QueryPlanTest{}/* 113 elements not displayed */
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))", "insert into t values (-1, 'zzz');", }, 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);", "insert into t values (999, 'abcdefg');", }, Assertions: []ScriptTestAssertion{ { Query: "select i from t where b like 'abcd%';", Expected: []sql.Row{{999}}, }, { Query: "alter table t add 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 KEY `b` (`b`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "insert into t values (998, X'4242');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "alter table t drop index `b`;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { 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);", "insert into t values (999, 'xxx');", }, Assertions: []ScriptTestAssertion{ { Query: "select i from t where t like 'x%';", Expected: []sql.Row{{999}}, }, { Query: "alter table t add 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 KEY `t` (`t`(1))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "select i from t where t like 'x%';", Expected: []sql.Row{{999}}, }, { Query: "insert into t values (998, 'yy');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "alter table t drop index `t`;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { 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 `v1` (`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 `v1` (`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 `v1` (`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 `v1` (`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: "unique indexes on TEXT/BLOB columns with no prefix length (MariaDB compatibility)", SetUpScript: []string{ "create table t (pk int primary key, col1 text);", "create table j2 (pk int primary key, col1 varchar(100));", "insert into j2 values (1, '100'), (2, ' '), (3, '300');", }, Assertions: []ScriptTestAssertion{ { Query: "select @@strict_mysql_compatibility;", Expected: []sql.Row{{0}}, }, { Query: "alter table t add unique key k1(col1);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "insert into t values (4, ''), (5, ' '), (8, NULL), (-1, ' ');", Expected: []sql.Row{{types.NewOkResult(4)}}, }, { Query: "insert into t values (1, 'oneasdfasdf');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "insert into t values (2, 'oneasdfasdf');", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "select pk from t where col1='oneasdfasdf' and exists (select pk from j2 where j2.col1 <= t.col1);", Expected: []sql.Row{{1}}, CheckIndexedAccess: true, ExpectedIndexes: []string{"k1"}, }, { Skip: true, Query: "insert into t values (2, 'oneasdfasdf');", ExpectedErrStr: "duplicate unique key given: [oneasdfasdf]", }, { Query: "select col1 from t where col1='oneasdfasdf';", Expected: []sql.Row{{"oneasdfasdf"}}, CheckIndexedAccess: true, ExpectedIndexes: []string{"k1"}, }, { Query: "select * from t where col1 >= 'one';", ExpectedIndexes: []string{}, Expected: []sql.Row{{1, "oneasdfasdf"}}, }, { Query: "select * from t where col1 >= ' ' order by pk;", ExpectedIndexes: []string{"primary"}, Expected: []sql.Row{{-1, " "}, {1, "oneasdfasdf"}, {5, " "}}, }, { Query: "create table t2 (pk int primary key, col1 BLOB, unique key k1(col1));", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "select distinct j2.pk from j2 join t on t.col1 >= 'one';", ExpectedIndexes: []string{}, Expected: []sql.Row{{1}, {2}, {3}}, JoinTypes: []plan.JoinType{plan.JoinTypeInner}, }, { Query: "select /*+ LOOKUP_JOIN(t,j2) */ distinct j2.pk from j2 join t on t.col1 = ' ';", ExpectedIndexes: []string{"k1"}, Expected: []sql.Row{{1}, {2}, {3}}, JoinTypes: []plan.JoinType{plan.JoinTypeLookup}, }, { Query: "select /*+ LOOKUP_JOIN(t,j2) */ distinct j2.pk from j2 join t on t.col1 = j2.col1;", ExpectedIndexes: []string{"k1"}, Expected: []sql.Row{{2}}, JoinTypes: []plan.JoinType{plan.JoinTypeLookup}, }, { Query: "select /*+ LOOKUP_JOIN(t,j2) */ distinct j2.pk from j2 join t on t.col1 >= j2.col1;", ExpectedIndexes: []string{}, Expected: []sql.Row{{1}, {2}, {3}}, JoinTypes: []plan.JoinType{plan.JoinTypeInner}, }, { Query: "select /*+ MERGE_JOIN(t,j2) */ distinct j2.pk from j2 join t on t.col1 = j2.col1;", ExpectedIndexes: []string{"k1"}, Expected: []sql.Row{{2}}, JoinTypes: []plan.JoinType{plan.JoinTypeLookup}, }, { Query: "select /*+ MERGE_JOIN(t,j2) */ distinct j2.pk from j2 join t on t.col1 >= j2.col1;", ExpectedIndexes: []string{}, Expected: []sql.Row{{1}, {2}, {3}}, JoinTypes: []plan.JoinType{plan.JoinTypeInner}, }, { Query: "select t.col1 from t order by t.col1;", ExpectedIndexes: []string{}, Expected: []sql.Row{{nil}, {""}, {" "}, {" "}, {"oneasdfasdf"}}, }, { Query: "select col1 from t where concat(t.col1, ' ') = ' ';", ExpectedIndexes: []string{}, Expected: []sql.Row{{" "}}, }, { Query: "select col1 from t where t.col1 = POINT(42, 42);", ExpectedIndexes: []string{"k1"}, Expected: []sql.Row{}, }, { Query: "select col1 from t where t.col1 != 'oneasdfasdf';", ExpectedIndexes: []string{"k1"}, Expected: []sql.Row{{""}, {" "}, {" "}}, }, { Query: "select col1 from t where t.col1 is not null;", ExpectedIndexes: []string{"k1"}, Expected: []sql.Row{{""}, {" "}, {" "}, {"oneasdfasdf"}}, }, { Query: "select col1 from t where t.col1 <=> 'oneasdfasdf';", ExpectedIndexes: []string{"k1"}, Expected: []sql.Row{{"oneasdfasdf"}}, }, { Query: "select col1 from t where t.col1 is NULL", ExpectedIndexes: []string{"k1"}, Expected: []sql.Row{{nil}}, }, }, }, { Name: "unique indexes on multiple TEXT/BLOB columns with partial prefix lengths (MariaDB compatibility)", SetUpScript: []string{ "create table t (pk int primary key, col1 text, col2 text, constraint uk1 unique key(col1, col2(3)));", "insert into t value(1, 'one', 'one___'), (2, 'two', 'two___');", }, Assertions: []ScriptTestAssertion{ { Query: "select @@strict_mysql_compatibility;", Expected: []sql.Row{{0}}, }, { Query: "insert into t values (200, 'two', 'two___');", ExpectedErr: sql.ErrUniqueKeyViolation, }, { Query: "select col1, col2 from t where col1='one';", Expected: []sql.Row{{"one", "one___"}}, CheckIndexedAccess: true, ExpectedIndexes: []string{"uk1"}, }, { Query: "select * from t where col1 >= 'one';", ExpectedIndexes: []string{}, Expected: []sql.Row{{1, "one", "one___"}, {2, "two", "two___"}}, }, { Query: "select * from t where col2 >= 'one';", ExpectedIndexes: []string{}, Expected: []sql.Row{{1, "one", "one___"}, {2, "two", "two___"}}, }, { Query: "select count(*) from t where col1 >= ' ';", ExpectedIndexes: []string{}, Expected: []sql.Row{{2}}, }, { Query: "select count(*) from t where col2 >= ' ';", ExpectedIndexes: []string{}, Expected: []sql.Row{{2}}, }, { Query: "select * from t where col1 >= ' ' order by pk;", ExpectedIndexes: []string{"primary"}, Expected: []sql.Row{{1, "one", "one___"}, {2, "two", "two___"}}, }, { Query: "select * from t where col2 >= ' ' order by pk;", ExpectedIndexes: []string{"primary"}, Expected: []sql.Row{{1, "one", "one___"}, {2, "two", "two___"}}, }, }, }, { Name: "case-insensitive collations are restricted for unique indexes on TEXT columns with no prefix length", Assertions: []ScriptTestAssertion{ { Query: "create table t1 (pk int primary key, col1 TEXT collate utf8mb3_general_ci, unique key k1(col1));", ExpectedErr: sql.ErrCollationNotSupportedOnUniqueTextIndex, }, { Query: "create table t2 (pk int primary key, col1 TEXT collate utf8mb3_general_ci);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "alter table t2 add unique key k1(col1);", ExpectedErr: sql.ErrCollationNotSupportedOnUniqueTextIndex, }, }, }, { Name: "unique indexes on TEXT/BLOB columns with no prefix length (strict MySQL compatibility)", SetUpScript: []string{ "create table t (pk int primary key, col1 text);", }, Assertions: []ScriptTestAssertion{ { Query: "set @@strict_mysql_compatibility = true;", Expected: []sql.Row{{}}, }, { Query: "select @@strict_mysql_compatibility;", Expected: []sql.Row{{1}}, }, { Query: "alter table t add unique key k1(col1);", ExpectedErrStr: "blob/text column 'col1' used in key specification without a key length", }, { Query: "create table t2 (pk int primary key, col1 BLOB, unique key k1(col1));", ExpectedErrStr: "blob/text column 'col1' used in key specification without a key length", }, }, }, { 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: "multiple indexes over same set of columns", SetUpScript: []string{ "CREATE TABLE `t0` (`id` char(32) NOT NULL PRIMARY KEY, `col1` varchar(255) NOT NULL, `col2` varchar(255) NOT NULL);", "CREATE TABLE `t3` (`id` char(32) NOT NULL PRIMARY KEY, `col1` varchar(255) NOT NULL, `col2` varchar(255) NOT NULL);", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE t0 ADD CONSTRAINT unique_1 UNIQUE(col1, col2);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t0 ADD CONSTRAINT unique_2 UNIQUE(col1, col2);", Expected: []sql.Row{{types.NewOkResult(0)}}, ExpectedWarningsCount: 1, ExpectedWarning: 1831, ExpectedWarningMessageSubstring: "Duplicate index 'unique_2' defined on the table 'mydb.t0'", }, { Query: "SELECT kc.`constraint_name`, kc.`column_name`, kc.`referenced_table_name`, kc.`referenced_column_name` FROM information_schema.key_column_usage AS kc WHERE kc.table_schema = DATABASE() AND kc.table_name = 't0' ORDER BY kc.`ordinal_position`;", Expected: []sql.Row{ {"PRIMARY", "id", nil, nil}, {"unique_1", "col1", nil, nil}, {"unique_2", "col1", nil, nil}, {"unique_1", "col2", nil, nil}, {"unique_2", "col2", nil, nil}, }, }, { Query: "SHOW CREATE TABLE t0;", Expected: []sql.Row{{"t0", "CREATE TABLE `t0` (\n `id` char(32) NOT NULL,\n `col1` varchar(255) NOT NULL,\n `col2` varchar(255) NOT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `unique_1` (`col1`,`col2`),\n UNIQUE KEY `unique_2` (`col1`,`col2`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "CREATE TABLE `t2` (`id` char(32) NOT NULL PRIMARY KEY, `col1` varchar(255) NOT NULL, `col2` varchar(255) NOT NULL, UNIQUE KEY unique_1(col1, col2), UNIQUE KEY unique_2(col1, col2));", Expected: []sql.Row{{types.NewOkResult(0)}}, ExpectedWarningsCount: 1, ExpectedWarning: 1831, ExpectedWarningMessageSubstring: "Duplicate index 'unique_2' defined on the table 'mydb.t2'", }, { Query: "SELECT kc.`constraint_name`, kc.`column_name`, kc.`referenced_table_name`, kc.`referenced_column_name` FROM information_schema.key_column_usage AS kc WHERE kc.table_schema = DATABASE() AND kc.table_name = 't2' ORDER BY kc.`ordinal_position`;", Expected: []sql.Row{ {"PRIMARY", "id", nil, nil}, {"unique_1", "col1", nil, nil}, {"unique_2", "col1", nil, nil}, {"unique_1", "col2", nil, nil}, {"unique_2", "col2", nil, nil}, }, }, { Query: "SHOW CREATE TABLE t2;", Expected: []sql.Row{{"t2", "CREATE TABLE `t2` (\n `id` char(32) NOT NULL,\n `col1` varchar(255) NOT NULL,\n `col2` varchar(255) NOT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `unique_1` (`col1`,`col2`),\n UNIQUE KEY `unique_2` (`col1`,`col2`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "ALTER TABLE t2 ADD CONSTRAINT unique_3 UNIQUE(col1, col2);", Expected: []sql.Row{{types.NewOkResult(0)}}, ExpectedWarningsCount: 1, ExpectedWarning: 1831, ExpectedWarningMessageSubstring: "Duplicate index 'unique_3' defined on the table 'mydb.t2'", }, { Query: "SHOW CREATE TABLE t2;", Expected: []sql.Row{{"t2", "CREATE TABLE `t2` (\n `id` char(32) NOT NULL,\n `col1` varchar(255) NOT NULL,\n `col2` varchar(255) NOT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `unique_1` (`col1`,`col2`),\n UNIQUE KEY `unique_2` (`col1`,`col2`),\n UNIQUE KEY `unique_3` (`col1`,`col2`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, { Query: "ALTER TABLE t3 ADD CONSTRAINT UNIQUE(col1, col2);", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "ALTER TABLE t3 ADD CONSTRAINT UNIQUE(col1, col2);", Expected: []sql.Row{{types.NewOkResult(0)}}, ExpectedWarningsCount: 1, ExpectedWarning: 1831, ExpectedWarningMessageSubstring: "Duplicate index 'col1_2' defined on the table 'mydb.t3'", }, { Query: "SELECT kc.`constraint_name`, kc.`column_name`, kc.`referenced_table_name`, kc.`referenced_column_name` FROM information_schema.key_column_usage AS kc WHERE kc.table_schema = DATABASE() AND kc.table_name = 't3' ORDER BY kc.`ordinal_position`;", Expected: []sql.Row{ {"PRIMARY", "id", nil, nil}, {"col1", "col1", nil, nil}, {"col1_2", "col1", nil, nil}, {"col1", "col2", nil, nil}, {"col1_2", "col2", nil, nil}, }, }, { Query: "SHOW CREATE TABLE t3;", Expected: []sql.Row{{"t3", "CREATE TABLE `t3` (\n `id` char(32) NOT NULL,\n `col1` varchar(255) NOT NULL,\n `col2` varchar(255) NOT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `col1` (`col1`,`col2`),\n UNIQUE KEY `col1_2` (`col1`,`col2`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, }, }, }, { 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}, }, }, }, }, { Name: "secondary index errors", SetUpScript: []string{ "create table json_tbl (pk int primary key, i int, j json);", "create table idx_tbl (pk int primary key, j int, index(j));", }, Assertions: []ScriptTestAssertion{ { Query: "create index idx on json_tbl(j)", ExpectedErr: sql.ErrJSONIndex, }, { Query: "create index idx on json_tbl(i, j)", ExpectedErr: sql.ErrJSONIndex, }, { Query: "create index idx on json_tbl(j, i)", ExpectedErr: sql.ErrJSONIndex, }, { Query: "alter table idx_tbl modify column j json;", ExpectedErr: sql.ErrJSONIndex, }, { Query: "create table t1 (i int primary key, j json, index(j));", ExpectedErr: sql.ErrJSONIndex, }, { Query: "create table t2 (i int, j json, index(i, j));", ExpectedErr: sql.ErrJSONIndex, }, { Query: "create table t3 (i int, j json, index(j, i));", ExpectedErr: sql.ErrJSONIndex, }, { Query: "show tables;", Expected: []sql.Row{ {"json_tbl"}, {"idx_tbl"}, }, }, }, }, }
var InfoSchemaQueries = []QueryTest{ { Query: "SHOW PLUGINS", Expected: []sql.Row{}, }, { Query: "SHOW KEYS FROM `columns` FROM `information_schema`;", Expected: []sql.Row{}, }, { 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{ {"othertable"}, }, }, { Query: "SHOW TABLES LIKE '%table'", Expected: []sql.Row{ {"mytable"}, }, }, { Query: `SHOW COLUMNS FROM mytable`, Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", nil, ""}, {"s", "varchar(20)", "NO", "UNI", nil, ""}, }, }, { Query: `DESCRIBE mytable`, Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", nil, ""}, {"s", "varchar(20)", "NO", "UNI", nil, ""}, }, }, { Query: `DESC mytable`, Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", nil, ""}, {"s", "varchar(20)", "NO", "UNI", nil, ""}, }, }, { Query: `SHOW COLUMNS FROM mytable WHERE Field = 'i'`, Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", nil, ""}, }, }, { Query: `SHOW COLUMNS FROM mytable LIKE 'i'`, Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", nil, ""}, }, }, { Query: `SHOW FULL COLUMNS FROM mytable`, Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "UNI", nil, "", "", "column s"}, }, }, { Query: `SHOW FULL COLUMNS FROM mytable FROM mydb`, Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "UNI", nil, "", "", "column s"}, }, }, { Query: `SHOW FULL COLUMNS FROM othertable in foo`, Expected: []sql.Row{ {"text", "varchar(20)", "utf8mb4_0900_bin", "NO", "PRI", nil, "", "", ""}, {"number", "mediumint", nil, "YES", "", nil, "", "", ""}, }, }, { 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`, ExpectedColumns: sql.Schema{ &sql.Column{Name: "Table", Type: types.LongText}, &sql.Column{Name: "Non_unique", Type: types.Int32}, &sql.Column{Name: "Key_name", Type: types.LongText}, &sql.Column{Name: "Seq_in_index", Type: types.Uint32}, &sql.Column{Name: "Column_name", Type: types.LongText, Nullable: true}, &sql.Column{Name: "Collation", Type: types.LongText, Nullable: true}, &sql.Column{Name: "Cardinality", Type: types.Int64}, &sql.Column{Name: "Sub_part", Type: types.Int64, Nullable: true}, &sql.Column{Name: "Packed", Type: types.LongText, Nullable: true}, &sql.Column{Name: "Null", Type: types.LongText}, &sql.Column{Name: "Index_type", Type: types.LongText}, &sql.Column{Name: "Comment", Type: types.LongText}, &sql.Column{Name: "Index_comment", Type: types.LongText}, &sql.Column{Name: "Visible", Type: types.LongText}, &sql.Column{Name: "Expression", Type: types.LongText, Nullable: true}, }, 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 INDEXES FROM othertable FROM foo`, Expected: []sql.Row{ {"othertable", 0, "PRIMARY", 1, "text", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil}, }, }, { Query: `SHOW INDEXES FROM foo.othertable`, Expected: []sql.Row{ {"othertable", 0, "PRIMARY", 1, "text", 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 `fk1` (`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"}, }, ExpectedColumns: sql.Schema{ { Name: "Engine", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default), }, { Name: "Support", Type: types.MustCreateString(sqltypes.VarChar, 8, sql.Collation_Information_Schema_Default), }, { Name: "Comment", Type: types.MustCreateString(sqltypes.VarChar, 80, sql.Collation_Information_Schema_Default), }, { Name: "Transactions", Type: types.MustCreateString(sqltypes.VarChar, 3, sql.Collation_Information_Schema_Default), }, { Name: "XA", Type: types.MustCreateString(sqltypes.VarChar, 3, sql.Collation_Information_Schema_Default), }, { Name: "Savepoints", Type: types.MustCreateString(sqltypes.VarChar, 3, sql.Collation_Information_Schema_Default), }, }, }, { 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", "othertable", "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", "othertable", "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"}, }, ExpectedColumns: sql.Schema{ { Name: "ENGINE", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default), }, { Name: "SUPPORT", Type: types.MustCreateString(sqltypes.VarChar, 8, sql.Collation_Information_Schema_Default), }, { Name: "COMMENT", Type: types.MustCreateString(sqltypes.VarChar, 80, sql.Collation_Information_Schema_Default), }, { Name: "TRANSACTIONS", Type: types.MustCreateString(sqltypes.VarChar, 3, sql.Collation_Information_Schema_Default), }, { Name: "XA", Type: types.MustCreateString(sqltypes.VarChar, 3, sql.Collation_Information_Schema_Default), }, { Name: "SAVEPOINTS", Type: types.MustCreateString(sqltypes.VarChar, 3, sql.Collation_Information_Schema_Default), }, }, }, { 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", nil, ""}, {"a", "bigint", "YES", "MUL", nil, ""}, {"b", "varchar(20)", "YES", "", nil, ""}, }, }, { 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`, uint32(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`, uint32(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`, uint32(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`, uint32(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`, uint32(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`, uint32(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`, uint32(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`, uint32(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`, uint32(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`, uint32(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", "fk1", "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: "foreign key that references dropped table", SetUpScript: []string{ "create table parent(a int primary key, b int);", "create table child(c int primary key);", "alter table child add foreign key (c) references parent(a);", }, Assertions: []ScriptTestAssertion{ { Query: "select UNIQUE_CONSTRAINT_NAME from information_schema.referential_constraints where TABLE_NAME = 'child' and REFERENCED_TABLE_NAME = 'parent';", Expected: []sql.Row{{"PRIMARY"}}, }, { Query: "select REFERENCED_COLUMN_NAME from information_schema.key_column_usage where TABLE_NAME = 'child' and REFERENCED_TABLE_NAME = 'parent';", Expected: []sql.Row{{"a"}}, }, { Query: "set foreign_key_checks=0;", }, { Query: "drop table parent;", }, { Query: "insert into child values (1), (2);", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "select * from child;", Expected: []sql.Row{{1}, {2}}, }, { Query: "delete from child;", Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, }, { Query: "select * from child;", Expected: []sql.Row{}, }, { Query: "set foreign_key_checks=1;", }, { Query: "insert into child values (1), (2);", ExpectedErr: sql.ErrForeignKeyNotResolved, }, { Query: "select UNIQUE_CONSTRAINT_NAME from information_schema.referential_constraints where TABLE_NAME = 'child' and REFERENCED_TABLE_NAME = 'parent';", Expected: []sql.Row{{nil}}, }, { Query: "select REFERENCED_COLUMN_NAME from information_schema.key_column_usage where TABLE_NAME = 'child' and REFERENCED_TABLE_NAME = 'parent';", Expected: []sql.Row{{"a"}}, }, }, }, { 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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "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 order by routine_name", 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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "hi", "", "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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "hello", "", "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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "", "user@%", "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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "", "", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}, }, }, }, }, { Name: "information_schema.columns for view", SetUpScript: []string{ "USE foo", "drop table othertable", "CREATE TABLE t (i int primary key, j int default (uuid_to_bin(uuid())));", "CREATE VIEW v as select i + 1, j, j * 2, mod(i, j) from t;", "create table tt (ii int primary key, jj int default (pow(1, 2)));", "create view vv as select * from t join tt where i = ii;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'foo'", Expected: []sql.Row{ {"def", "foo", "t", "i", uint32(1), nil, "NO", "int", nil, nil, 10, 0, nil, nil, nil, "int", "PRI", "", "insert,references,select,update", "", "", nil}, {"def", "foo", "t", "j", uint32(2), "UUID_TO_BIN(uuid())", "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "DEFAULT_GENERATED", "insert,references,select,update", "", "", nil}, {"def", "foo", "tt", "ii", uint32(1), nil, "NO", "int", nil, nil, 10, 0, nil, nil, nil, "int", "PRI", "", "insert,references,select,update", "", "", nil}, {"def", "foo", "tt", "jj", uint32(2), "power(1, 2)", "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "DEFAULT_GENERATED", "insert,references,select,update", "", "", nil}, {"def", "foo", "v", "i + 1", uint32(1), nil, "NO", "bigint", nil, nil, 19, 0, nil, nil, nil, "bigint", "", "", "insert,references,select,update", "", "", nil}, {"def", "foo", "v", "j", uint32(2), "UUID_TO_BIN(uuid())", "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "DEFAULT_GENERATED", "insert,references,select,update", "", "", nil}, {"def", "foo", "v", "j * 2", uint32(3), nil, "YES", "bigint", nil, nil, 19, 0, nil, nil, nil, "bigint", "", "", "insert,references,select,update", "", "", nil}, {"def", "foo", "v", "mod(i, j)", uint32(4), nil, "YES", "decimal", nil, nil, 10, 0, nil, nil, nil, "decimal(10,0)", "", "", "insert,references,select,update", "", "", nil}, {"def", "foo", "vv", "i", uint32(1), nil, "NO", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "", "insert,references,select,update", "", "", nil}, {"def", "foo", "vv", "j", uint32(2), "UUID_TO_BIN(uuid())", "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "DEFAULT_GENERATED", "insert,references,select,update", "", "", nil}, {"def", "foo", "vv", "ii", uint32(3), nil, "NO", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "", "insert,references,select,update", "", "", nil}, {"def", "foo", "vv", "jj", uint32(4), "power(1, 2)", "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "DEFAULT_GENERATED", "insert,references,select,update", "", "", 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(1)", ""}, }, }, }, }, { 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 cardinality 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(6)), 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(6)", "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, 0, nil, nil, "", "", "", "", nil}, {"date_time", "datetime(6)", nil, nil, 6, 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, 6, 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", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "", "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"}, }, }, }, }, { Name: "information_schema.tables has table comments", SetUpScript: []string{ "create table t (i int primary key) comment 'this is a table comment';", }, Assertions: []ScriptTestAssertion{ { Query: "select table_comment from information_schema.tables where table_name = 't';", Expected: []sql.Row{ {"this is a table comment"}, }, }, }, }, { Name: "information_schema.columns in expression uses info schema collation", SetUpScript: []string{ "create table TEST (COL int);", }, Assertions: []ScriptTestAssertion{ { Query: "select table_schema, table_name, column_name table_comment from information_schema.columns where (table_name, column_name) in (('TEST', 'COL'));", Expected: []sql.Row{ {"mydb", "TEST", "COL"}, }, }, { Query: "select table_schema, table_name, column_name table_comment from information_schema.columns where (table_name, column_name) in (('test', 'col'));", Expected: []sql.Row{ {"mydb", "TEST", "COL"}, }, }, }, }, { Name: "test information_schema database", Assertions: []ScriptTestAssertion{ { Query: "show databases like 'information_schema';", Expected: []sql.Row{{"information_schema"}}, }, { Query: "create database information_schema;", ExpectedErr: sql.ErrDatabaseExists, }, { Query: "drop database information_schema;", ExpectedErrStr: "unable to drop database: information_schema", }, { Query: "show databases like 'information_schema';", Expected: []sql.Row{{"information_schema"}}, }, }, }, }
var InsertBrokenScripts = []ScriptTest{ { Name: "Test that INSERT IGNORE assigns the closest dataype correctly", Dialect: "mysql", 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}}, }, ExpectedWarningsCount: 1, ExpectedWarning: mysql.ERTruncatedWrongValueForField, }, }, }, { Name: "auto increment does not increment on error", SetUpScript: []string{ "create table auto1 (pk int primary key auto_increment);", "insert into auto1 values (null);", "create table auto2 (pk int primary key auto_increment, c int not null);", "insert into auto2 values (null, 1);", }, Assertions: []ScriptTestAssertion{ { Query: "show create table auto1;", Expected: []sql.Row{ {"auto1", "CREATE TABLE `auto1` (\n" + " `pk` int NOT NULL AUTO_INCREMENT,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into auto1 values (1);", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "show create table auto1;", Expected: []sql.Row{ {"auto1", "CREATE TABLE `auto1` (\n" + " `pk` int NOT NULL AUTO_INCREMENT,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into auto1 values (null);", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, InsertID: 2}}, }, }, { Query: "show create table auto1;", Expected: []sql.Row{ {"auto1", "CREATE TABLE `auto1` (\n" + " `pk` int NOT NULL AUTO_INCREMENT,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "select * from auto1;", Expected: []sql.Row{ {1}, {2}, }, }, { Query: "show create table auto2;", Expected: []sql.Row{ {"auto2", "CREATE TABLE `auto2` (\n" + " `pk` int NOT NULL AUTO_INCREMENT,\n" + " `c` int NOT NULL,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into auto2 values (null, null);", ExpectedErr: sql.ErrInsertIntoNonNullableProvidedNull, }, { Query: "show create table auto2;", Expected: []sql.Row{ {"auto2", "CREATE TABLE `auto2` (\n" + " `pk` int NOT NULL AUTO_INCREMENT,\n" + " `c` int NOT NULL,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "insert into auto2 values (null, 2);", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, InsertID: 2}}, }, }, { Query: "show create table auto2;", Expected: []sql.Row{ {"auto2", "CREATE TABLE `auto2` (\n" + " `pk` int NOT NULL AUTO_INCREMENT,\n" + " `c` int NOT NULL,\n" + " PRIMARY KEY (`pk`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "select * from auto2;", Expected: []sql.Row{ {1, 1}, {2, 2}, }, }, }, }, { Name: "INSERT INTO with ENUM NOT NULL", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY NOT NULL, v1 ENUM('a','b','c') NOT NULL);", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO test (pk) VALUES (1);", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t2;", Expected: []sql.Row{{1, "a"}}, }, }, }, }
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}}, }, ExpectedWarningsCount: 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}}, }, ExpectedWarningsCount: 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}}, }, ExpectedWarningsCount: 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}}, }, ExpectedWarningsCount: 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}}, }, ExpectedWarningsCount: 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}}, }, ExpectedWarningsCount: 1, 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}}, }, ExpectedWarningsCount: 1, 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: "issue 8611: insert ignore on enum type column", SetUpScript: []string{ "create table test_table (x int auto_increment primary key, y enum('hello','bye'))", }, Assertions: []ScriptTestAssertion{ { Query: "insert into test_table values (1, 'invalid'), (2, 'comparative politics'), (3, null)", ExpectedErr: types.ErrConvertingToEnum, }, { Query: "insert ignore into test_table values (1, 'invalid'), (2, 'bye'), (3, null)", Expected: []sql.Row{{types.OkResult{RowsAffected: 3}}}, }, { Query: "select * from test_table", Expected: []sql.Row{{1, ""}, {2, "bye"}, {3, 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}}, Dialect: "mysql", }, { WriteQuery: "INSERT INTO keyless () VALUES ();", ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}}, SelectQuery: "SELECT * FROM keyless WHERE c0 IS NULL;", ExpectedSelect: []sql.Row{{nil, nil}}, Dialect: "mysql", }, { 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)}}, Dialect: "mysql", }, { 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(65)}}, Dialect: "mysql", }, { 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)}}, Dialect: "mysql", }, { 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)}}, Dialect: "mysql", }, { 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"}}, Dialect: "mysql", }, { 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"}}, Dialect: "mysql", }, { 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"), "v1", "v2", }}, }, { 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"), "v1", "v2", }}, }, { SkipServerEngine: true, 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(""), "", "", }}, }, { SkipServerEngine: true, 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(""), "v1", "v2", }}, }, { SkipServerEngine: true, 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(""), "v1", "v2", }}, }, { 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) as len, concat('numrows: ', count(*)) from mytable group by 1 HAVING len > 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"}}, Dialect: "mysql", }, { WriteQuery: "INSERT INTO mytable (i,s) values (1, 'hi') AS dt(new_i,new_s) ON DUPLICATE KEY UPDATE s=new_s", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable WHERE i = 1", ExpectedSelect: []sql.Row{{int64(1), "hi"}}, Skip: true, }, { WriteQuery: "INSERT INTO mytable (i,s) values (1, 'hi') AS dt ON DUPLICATE KEY UPDATE mytable.s=dt.s", ExpectedWriteResult: []sql.Row{{types.NewOkResult(2)}}, SelectQuery: "SELECT * FROM mytable WHERE i = 1", ExpectedSelect: []sql.Row{{int64(1), "hir"}}, Skip: true, }, { 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"}}, Dialect: "mysql", }, { 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"}}, Dialect: "mysql", }, { 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"}}, Dialect: "mysql", }, { 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}, }, Dialect: "mysql", }, { WriteQuery: "INSERT INTO auto_increment_tbl values (0, 44)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 0}}}, SelectQuery: "SELECT * FROM auto_increment_tbl ORDER BY pk", ExpectedSelect: []sql.Row{ {1, 11}, {2, 22}, {3, 33}, {4, 44}, }, Dialect: "mysql", }, { WriteQuery: "INSERT INTO auto_increment_tbl values (5, 44)", ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 0}}}, 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}, }, Dialect: "mysql", }, { 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}, }, Dialect: "mysql", }, { 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.NewOkResult(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 7322: values expression is subquery", SetUpScript: []string{ "create table xy (x int auto_increment primary key, y varchar(50) not null)", "create table uv (u int auto_increment primary key, v varchar(50) not null, x_id int, constraint u_x_fk foreign key (x_id) references xy (x))", "insert into xy values (1,'admin'), (2, 'standard')", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO uv(v, x_id) VALUES ('test', (SELECT x FROM xy WHERE y = 'admin'));", Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 1}}}, }, { Query: "INSERT INTO uv(v, x_id) VALUES ('test', (SELECT x FROM xy WHERE x > 0));", ExpectedErr: sql.ErrExpectedSingleRow, }, { Query: "select * from uv", Expected: []sql.Row{{1, "test", 1}}, }, }, }, { Name: "issue 6675: on duplicate rearranged getfield indexes from select source", SetUpScript: []string{ "create table xy (x int primary key, y datetime)", "insert into xy values (0,'2023-09-16')", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO xy (y,x) select * from (select cast('2019-12-31T12:00:00Z' as date), 0) dt(a,b) ON DUPLICATE KEY UPDATE x=dt.b+1, y=dt.a", Expected: []sql.Row{{types.NewOkResult(2)}}, }, { Query: "select * from xy", Expected: []sql.Row{{1, time.Date(2019, time.December, 31, 0, 0, 0, 0, time.UTC)}}, }, }, }, { 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name = 'auto' AND table_schema = DATABASE()", Expected: []sql.Row{{uint64(9)}}, }, { Query: "insert into auto values (NULL,90)", Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, InsertID: 9, }}}, }, { 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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", Dialect: "mysql", 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: "sql_mode=NO_auto_value_ON_ZERO", Dialect: "mysql", SetUpScript: []string{ "set @old_sql_mode=@@sql_mode;", "set @@sql_mode='NO_auto_value_ON_ZERO';", "create table auto (i int auto_increment, index (i));", "create table auto_pk (i int auto_increment primary key);", }, Assertions: []ScriptTestAssertion{ { Query: "select auto_increment from information_schema.tables where table_name='auto' and table_schema=database()", Expected: []sql.Row{ {nil}, }, }, { Query: "insert into auto values (0), (0), (1-1)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, InsertID: 0}}, }, }, { Query: "select * from auto order by i", Expected: []sql.Row{ {0}, {0}, {0}, }, }, { Query: "select auto_increment from information_schema.tables where table_name='auto' and table_schema=database()", Expected: []sql.Row{ {nil}, }, }, { Query: "insert into auto values (1)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, InsertID: 0}}, }, }, { Query: "select auto_increment from information_schema.tables where table_name='auto' and table_schema=database()", Expected: []sql.Row{ {uint64(2)}, }, }, { Query: "select auto_increment from information_schema.tables where table_name='auto_pk' and table_schema=database()", Expected: []sql.Row{ {nil}, }, }, { Query: "insert into auto_pk values (0), (1), (NULL), ()", Expected: []sql.Row{ {types.OkResult{RowsAffected: 4, InsertID: 2}}, }, }, { Query: "select * from auto_pk", Expected: []sql.Row{ {0}, {1}, {2}, {3}, }, }, { Query: "select auto_increment from information_schema.tables where table_name='auto_pk' and table_schema=database()", Expected: []sql.Row{ {uint64(4)}, }, }, { SkipResultsCheck: true, Query: "set @@sql_mode=@old_sql_mode", }, }, }, { Name: "explicit DEFAULT", Dialect: "mysql", 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: "Explicit default with column reference", Dialect: "mysql", SetUpScript: []string{ "CREATE TABLE t1 (a int default 1, b int default (a+1));", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO t1 (a,b) values (1, DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "select * from t1 order by a", Expected: []sql.Row{{1, 2}}, }, { Query: "INSERT INTO t1 values (2, DEFAULT)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "select * from t1 where a = 2 order by a", Expected: []sql.Row{{2, 3}}, }, { Query: "INSERT INTO t1 (b,a) values (DEFAULT, 3)", Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, }, { Query: "select * from t1 where a = 3 order by a", Expected: []sql.Row{{3, 4}}, }, }, }, { Name: "Try INSERT IGNORE with primary key, non null, and single row violations", Dialect: "mysql", 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}}, }, ExpectedWarningsCount: 1, ExpectedWarning: mysql.ERDupEntry, }, { Query: "INSERT IGNORE INTO y VALUES (5, NULL)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, ExpectedWarningsCount: 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}}, }, ExpectedWarningsCount: 5, 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}}, }, ExpectedWarningsCount: 1, 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}}, }, ExpectedWarningsCount: 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}}, }, ExpectedWarningsCount: 1, ExpectedWarning: mysql.ERSubqueryNo1Row, }, { Query: "INSERT IGNORE INTO y VALUES (3, 8)", Expected: []sql.Row{ {types.OkResult{RowsAffected: 0}}, }, ExpectedWarningsCount: 1, 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`, Expected: []sql.Row{ {types.OkResult{RowsAffected: 4}}, }, }, { Query: "select * from a", Skip: true, Expected: []sql.Row{ {101}, {2}, {3}, }, }, }, }, { Name: "insert on duplicate key with incorrect row alias", SetUpScript: []string{ `create table a (i int primary key)`, }, Assertions: []ScriptTestAssertion{ { Query: `insert into a values (1) as new(c, d) on duplicate key update i = c`, ExpectedErr: sql.ErrColumnCountMismatch, }, }, }, { 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", Dialect: "mysql", 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", Dialect: "mysql", 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: "INSERT INTO ... SELECT with TEXT types", SetUpScript: []string{ "create table t1 (i int primary key, t text);", "insert into t1 values (1, '2001-01-01'), (2, 'badtime'), (3, '');", "create table t2 (d datetime);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into t2(d) select t from t1 where false;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "insert into t2(d) select t from t1 where i = 3;", ExpectedErrStr: "Incorrect datetime value: ''", }, { Query: "insert into t2(d) select t from t1 where i = 2;", ExpectedErrStr: "Incorrect datetime value: 'badtime'", }, { Query: "insert into t2(d) select t from t1 where i = 1;", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "select * from t2;", Expected: []sql.Row{ {time.Date(2001, time.January, 1, 0, 0, 0, 0, time.UTC)}, }, }, }, }, { Name: "Defaults with escaped strings", Dialect: "mysql", 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", Dialect: "mysql", 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, }, }, }, { Name: "INSERT IGNORE works with FK Violations", Dialect: "mysql", 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}}, }, ExpectedWarningsCount: 1, ExpectedWarning: mysql.ErNoReferencedRow2, }, }, }, { Name: "insert duplicate key doesn't prevent other updates", SetUpScript: []string{ "CREATE TABLE t1 (pk BIGINT PRIMARY KEY, v1 VARCHAR(3));", "INSERT INTO t1 VALUES (1, 'abc');", }, Assertions: []ScriptTestAssertion{ { Query: "select * from t1 order by pk", Expected: []sql.Row{{1, "abc"}}, }, { Query: "INSERT INTO t1 VALUES (1, 'abc');", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "INSERT INTO t1 VALUES (2, 'def');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "select * from t1 order by pk", Expected: []sql.Row{{1, "abc"}, {2, "def"}}, }, }, }, { Name: "insert duplicate key doesn't prevent other updates, autocommit off", SetUpScript: []string{ "CREATE TABLE t1 (pk BIGINT PRIMARY KEY, v1 VARCHAR(3));", "INSERT INTO t1 VALUES (1, 'abc');", "SET autocommit = 0;", }, Assertions: []ScriptTestAssertion{ { Query: "select * from t1 order by pk", Expected: []sql.Row{{1, "abc"}}, }, { Query: "INSERT INTO t1 VALUES (1, 'abc');", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "INSERT INTO t1 VALUES (2, 'def');", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "commit", SkipResultsCheck: true, }, { Query: "select * from t1 order by pk", Expected: []sql.Row{{1, "abc"}, {2, "def"}}, }, }, }, }
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" +
" ├─ thnts.IXUXU:30 IS NULL\n" +
" └─ LeftOuterMergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ yk2gw.id:0!null\n" +
" │ └─ thnts.IXUXU:30\n" +
" ├─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (1-30)\n" +
" │ ├─ tableId: 1\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" +
" └─ Project\n" +
" ├─ columns: [thnts.IXUXU:2]\n" +
" └─ IndexedTableAccess(THNTS)\n" +
" ├─ index: [THNTS.IXUXU]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (31-34)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: THNTS\n" +
" └─ columns: [id nfryn ixuxu fhcyt]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [yk2gw.id, yk2gw.FTQLQ]\n" +
" └─ Project\n" +
" ├─ columns: [YK2GW.id, YK2GW.FTQLQ, YK2GW.TUXML, YK2GW.PAEF5, YK2GW.RUCY4, YK2GW.TPNJ6, YK2GW.LBL53, YK2GW.NB3QS, YK2GW.EO7IV, YK2GW.MUHJF, YK2GW.FM34L, YK2GW.TY5RF, YK2GW.ZHTLH, YK2GW.NPB7W, YK2GW.SX3HH, YK2GW.ISBNF, YK2GW.YA7YB, YK2GW.C5YKB, YK2GW.QK7KT, YK2GW.FFGE6, YK2GW.FIIGJ, YK2GW.SH3NC, YK2GW.NTENA, YK2GW.M4AUB, YK2GW.X5AIR, YK2GW.SAB6M, YK2GW.G5QI5, YK2GW.ZVQVD, YK2GW.YKSSU, YK2GW.FHCYT]\n" +
" └─ Filter\n" +
" ├─ thnts.IXUXU IS NULL\n" +
" └─ LeftOuterMergeJoin (estimated cost=5077.210 rows=3122)\n" +
" ├─ cmp: (yk2gw.id = thnts.IXUXU)\n" +
" ├─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ └─ filters: [{[NULL, ∞)}]\n" +
" └─ Project\n" +
" ├─ columns: [thnts.IXUXU]\n" +
" └─ IndexedTableAccess(THNTS)\n" +
" ├─ index: [THNTS.IXUXU]\n" +
" └─ filters: [{[NULL, ∞)}]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [yk2gw.id, yk2gw.FTQLQ]\n" +
" └─ Project\n" +
" ├─ columns: [YK2GW.id, YK2GW.FTQLQ, YK2GW.TUXML, YK2GW.PAEF5, YK2GW.RUCY4, YK2GW.TPNJ6, YK2GW.LBL53, YK2GW.NB3QS, YK2GW.EO7IV, YK2GW.MUHJF, YK2GW.FM34L, YK2GW.TY5RF, YK2GW.ZHTLH, YK2GW.NPB7W, YK2GW.SX3HH, YK2GW.ISBNF, YK2GW.YA7YB, YK2GW.C5YKB, YK2GW.QK7KT, YK2GW.FFGE6, YK2GW.FIIGJ, YK2GW.SH3NC, YK2GW.NTENA, YK2GW.M4AUB, YK2GW.X5AIR, YK2GW.SAB6M, YK2GW.G5QI5, YK2GW.ZVQVD, YK2GW.YKSSU, YK2GW.FHCYT]\n" +
" └─ Filter\n" +
" ├─ thnts.IXUXU IS NULL\n" +
" └─ LeftOuterMergeJoin (estimated cost=5077.210 rows=3122) (actual rows=0 loops=1)\n" +
" ├─ cmp: (yk2gw.id = thnts.IXUXU)\n" +
" ├─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ └─ filters: [{[NULL, ∞)}]\n" +
" └─ Project\n" +
" ├─ columns: [thnts.IXUXU]\n" +
" └─ IndexedTableAccess(THNTS)\n" +
" ├─ index: [THNTS.IXUXU]\n" +
" └─ filters: [{[NULL, ∞)}]\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:4!null as id, pbmrx.TW55N:5!null as TEYBZ, pbmrx.ZH72S:6 as FB6N7]\n" +
" └─ LookupJoin\n" +
" ├─ NOT\n" +
" │ └─ pbmrx.ZH72S:6 IS NULL\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cl3dt\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (41-44)\n" +
" │ ├─ tableId: 4\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ TTDPM:2!null\n" +
" │ │ │ └─ 0 (bigint)\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 (bigint)\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\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ccefl\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (31-33)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id:0!null as id, nd.ZH72S:7 as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select COUNT(*) from HDDVB where UJ6XY = nd.id\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" +
" │ │ ├─ keys: [nd.id:0!null]\n" +
" │ │ ├─ colSet: (20-28)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HDDVB\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" +
" │ │ ├─ alias-string: select COUNT(*) from HDDVB where UJ6XY = nd.id\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" +
" │ │ ├─ keys: [nd.id:0!null]\n" +
" │ │ ├─ colSet: (20-28)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HDDVB\n" +
" │ │ └─ columns: [uj6xy]\n" +
" │ │ as WGBRL]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ ├─ static: [{(NULL, ∞)}]\n" +
" │ ├─ colSet: (1-17)\n" +
" │ ├─ tableId: 1\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(pbmrx)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ keys: [cl3dt.ZH72S:0]\n" +
" ├─ colSet: (45-61)\n" +
" ├─ tableId: 5\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n zh72s]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [pbmrx.id as id, pbmrx.TW55N as TEYBZ, pbmrx.ZH72S as FB6N7]\n" +
" └─ LookupJoin (estimated cost=405.900 rows=124)\n" +
" ├─ (NOT(pbmrx.ZH72S IS NULL))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cl3dt\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Filter\n" +
" │ ├─ ((TTDPM = 0) AND (FBSRS > 0))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ccefl.ZH72S as ZH72S, count(ccefl.zh72s) as JTOA7, min(ccefl.wgbrl) as TTDPM, sum(ccefl.wgbrl) as FBSRS]\n" +
" │ └─ Having((JTOA7 > 1))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(ccefl.zh72s), min(ccefl.wgbrl), sum(ccefl.wgbrl), ccefl.ZH72S, ccefl.ZH72S as ZH72S, count(ccefl.zh72s) as JTOA7, min(ccefl.wgbrl) as TTDPM, sum(ccefl.wgbrl) as FBSRS]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(COUNT(ccefl.ZH72S), MIN(ccefl.WGBRL), SUM(ccefl.WGBRL), ccefl.ZH72S)\n" +
" │ ├─ Grouping(ccefl.ZH72S)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ccefl\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (hddvb.UJ6XY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ ├─ index: [HDDVB.UJ6XY]\n" +
" │ │ ├─ columns: [uj6xy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as WGBRL]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (hddvb.UJ6XY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ ├─ index: [HDDVB.UJ6XY]\n" +
" │ │ ├─ columns: [uj6xy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as WGBRL]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ └─ filters: [{(NULL, ∞)}]\n" +
" └─ TableAlias(pbmrx)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ columns: [id tw55n zh72s]\n" +
" └─ keys: cl3dt.ZH72S\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [pbmrx.id as id, pbmrx.TW55N as TEYBZ, pbmrx.ZH72S as FB6N7]\n" +
" └─ LookupJoin (estimated cost=405.900 rows=124) (actual rows=0 loops=1)\n" +
" ├─ (NOT(pbmrx.ZH72S IS NULL))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cl3dt\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Filter\n" +
" │ ├─ ((TTDPM = 0) AND (FBSRS > 0))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ccefl.ZH72S as ZH72S, count(ccefl.zh72s) as JTOA7, min(ccefl.wgbrl) as TTDPM, sum(ccefl.wgbrl) as FBSRS]\n" +
" │ └─ Having((JTOA7 > 1))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(ccefl.zh72s), min(ccefl.wgbrl), sum(ccefl.wgbrl), ccefl.ZH72S, ccefl.ZH72S as ZH72S, count(ccefl.zh72s) as JTOA7, min(ccefl.wgbrl) as TTDPM, sum(ccefl.wgbrl) as FBSRS]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(COUNT(ccefl.ZH72S), MIN(ccefl.WGBRL), SUM(ccefl.WGBRL), ccefl.ZH72S)\n" +
" │ ├─ Grouping(ccefl.ZH72S)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ccefl\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (hddvb.UJ6XY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ ├─ index: [HDDVB.UJ6XY]\n" +
" │ │ ├─ columns: [uj6xy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as WGBRL]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (hddvb.UJ6XY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ ├─ index: [HDDVB.UJ6XY]\n" +
" │ │ ├─ columns: [uj6xy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as WGBRL]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ └─ filters: [{(NULL, ∞)}]\n" +
" └─ TableAlias(pbmrx)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ columns: [id tw55n zh72s]\n" +
" └─ keys: cl3dt.ZH72S\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" +
" │ │ │ │ ├─ alias-string: select NHMXW.SWCQV from WGSDC as NHMXW where NHMXW.id = ism.PRUV2\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" +
" │ │ │ │ ├─ keys: [ism.PRUV2:6]\n" +
" │ │ │ │ ├─ colSet: (10-19)\n" +
" │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: WGSDC\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" +
" │ │ │ │ ├─ alias-string: select nd.id from E2I7U as nd where nd.TW55N = (select NHMXW.FZXV5 from WGSDC as NHMXW where NHMXW.id = ism.PRUV2)\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [nd.id:9!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ nd.TW55N:12!null\n" +
" │ │ │ │ │ └─ Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ ├─ alias-string: select NHMXW.FZXV5 from WGSDC as NHMXW where NHMXW.id = ism.PRUV2\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" +
" │ │ │ │ │ ├─ keys: [ism.PRUV2:6]\n" +
" │ │ │ │ │ ├─ colSet: (37-46)\n" +
" │ │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: WGSDC\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" +
" │ │ │ │ ├─ colSet: (20-36)\n" +
" │ │ │ │ └─ tableId: 3\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" +
" │ │ │ ├─ alias-string: select nd.id from E2I7U as nd where nd.TW55N = (select NHMXW.DQYGV from WGSDC as NHMXW where NHMXW.id = ism.PRUV2)\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [nd.id:9!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ nd.TW55N:12!null\n" +
" │ │ │ │ └─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ ├─ alias-string: select NHMXW.DQYGV from WGSDC as NHMXW where NHMXW.id = ism.PRUV2\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" +
" │ │ │ │ ├─ keys: [ism.PRUV2:6]\n" +
" │ │ │ │ ├─ colSet: (64-73)\n" +
" │ │ │ │ ├─ tableId: 6\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: WGSDC\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" +
" │ │ │ ├─ colSet: (47-63)\n" +
" │ │ │ └─ tableId: 5\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" +
" │ ├─ alias-string: select TIZHK.id as FWATE from WGSDC as NHMXW join WRZVO as 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)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tizhk.id:19!null as FWATE]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [WGSDC.id:9!null, WGSDC.NOHHR:10!null, WGSDC.AVPYF:11!null, WGSDC.SYPKF:12!null, WGSDC.IDUT2:13!null, WGSDC.FZXV5:14, WGSDC.DQYGV:15, WGSDC.SWCQV:16!null, WGSDC.YKSSU:17, WGSDC.FHCYT:18, WRZVO.id:19!null, WRZVO.TVNW2:20, WRZVO.ZHITY:21, WRZVO.SYPKF:22, WRZVO.IDUT2:23, WRZVO.O6QJ3:24, WRZVO.NO2JA:25, WRZVO.YKSSU:26, WRZVO.FHCYT:27, WRZVO.QZ6VT:28]\n" +
" │ └─ Filter\n" +
" │ ├─ hddvb.PRUV2:29 IS NULL\n" +
" │ └─ LeftOuterHashJoinExcludeNulls\n" +
" │ ├─ Eq\n" +
" │ │ ├─ nhmxw.id:9!null\n" +
" │ │ └─ hddvb.PRUV2:29\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ tizhk.TVNW2:20\n" +
" │ │ │ │ │ └─ nhmxw.NOHHR:10!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ tizhk.ZHITY:21\n" +
" │ │ │ │ └─ nhmxw.AVPYF:11!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ tizhk.IDUT2:23\n" +
" │ │ │ └─ nhmxw.IDUT2:13!null\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ nhmxw.SWCQV:16!null\n" +
" │ │ │ │ └─ 0 (int)\n" +
" │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: WGSDC\n" +
" │ │ │ ├─ columns: [id nohhr avpyf sypkf idut2 fzxv5 dqygv swcqv ykssu fhcyt]\n" +
" │ │ │ ├─ colSet: (74-83)\n" +
" │ │ │ └─ tableId: 7\n" +
" │ │ └─ TableAlias(tizhk)\n" +
" │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ ├─ index: [WRZVO.SYPKF]\n" +
" │ │ ├─ keys: [nhmxw.SYPKF:12!null]\n" +
" │ │ ├─ colSet: (84-93)\n" +
" │ │ ├─ tableId: 8\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: WRZVO\n" +
" │ │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(nhmxw.id:9!null)\n" +
" │ ├─ right-key: TUPLE(hddvb.PRUV2:9)\n" +
" │ └─ IndexedTableAccess(HDDVB)\n" +
" │ ├─ index: [HDDVB.PRUV2]\n" +
" │ ├─ static: [{(NULL, ∞)}]\n" +
" │ ├─ colSet: (94-102)\n" +
" │ ├─ tableId: 9\n" +
" │ └─ Table\n" +
" │ ├─ name: HDDVB\n" +
" │ └─ columns: [pruv2]\n" +
" └─ TableAlias(ism)\n" +
" └─ ProcessTable\n" +
" └─ Table\n" +
" ├─ name: HDDVB\n" +
" └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
"",
ExpectedEstimates: "Filter\n" +
" ├─ (((NOT(ism.PRUV2 IS NULL)) AND ((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nhmxw.SWCQV]\n" +
" │ └─ Filter\n" +
" │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ └─ TableAlias(nhmxw)\n" +
" │ └─ IndexedTableAccess(WGSDC)\n" +
" │ ├─ index: [WGSDC.id]\n" +
" │ ├─ columns: [id swcqv]\n" +
" │ └─ keys: ism.PRUV2\n" +
" │ = 1) OR (((NOT(ism.FV24E IS NULL)) AND (NOT((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (nd.TW55N = Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nhmxw.FZXV5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ └─ TableAlias(nhmxw)\n" +
" │ │ └─ IndexedTableAccess(WGSDC)\n" +
" │ │ ├─ index: [WGSDC.id]\n" +
" │ │ ├─ columns: [id fzxv5]\n" +
" │ │ └─ keys: ism.PRUV2\n" +
" │ │ )\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ └─ name: E2I7U\n" +
" │ = ism.FV24E)))) OR ((NOT(ism.UJ6XY IS NULL)) AND (NOT((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (nd.TW55N = Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nhmxw.DQYGV]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ └─ TableAlias(nhmxw)\n" +
" │ │ └─ IndexedTableAccess(WGSDC)\n" +
" │ │ ├─ index: [WGSDC.id]\n" +
" │ │ ├─ columns: [id dqygv]\n" +
" │ │ └─ keys: ism.PRUV2\n" +
" │ │ )\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ └─ name: E2I7U\n" +
" │ = ism.UJ6XY))))))) OR ((NOT(ism.ETPQV IS NULL)) AND InSubquery\n" +
" │ ├─ left: ism.ETPQV\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tizhk.id as FWATE]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [WGSDC.id, WGSDC.NOHHR, WGSDC.AVPYF, WGSDC.SYPKF, WGSDC.IDUT2, WGSDC.FZXV5, WGSDC.DQYGV, WGSDC.SWCQV, WGSDC.YKSSU, WGSDC.FHCYT, WRZVO.id, WRZVO.TVNW2, WRZVO.ZHITY, WRZVO.SYPKF, WRZVO.IDUT2, WRZVO.O6QJ3, WRZVO.NO2JA, WRZVO.YKSSU, WRZVO.FHCYT, WRZVO.QZ6VT]\n" +
" │ └─ Filter\n" +
" │ ├─ hddvb.PRUV2 IS NULL\n" +
" │ └─ LeftOuterHashJoinExcludeNulls\n" +
" │ ├─ (nhmxw.id = hddvb.PRUV2)\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ (((tizhk.TVNW2 = nhmxw.NOHHR) AND (tizhk.ZHITY = nhmxw.AVPYF)) AND (tizhk.IDUT2 = nhmxw.IDUT2))\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (nhmxw.SWCQV = 0)\n" +
" │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ └─ name: WGSDC\n" +
" │ │ └─ TableAlias(tizhk)\n" +
" │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ ├─ index: [WRZVO.SYPKF]\n" +
" │ │ └─ keys: nhmxw.SYPKF\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (nhmxw.id)\n" +
" │ ├─ right-key: (hddvb.PRUV2)\n" +
" │ └─ IndexedTableAccess(HDDVB)\n" +
" │ ├─ index: [HDDVB.PRUV2]\n" +
" │ ├─ filters: [{(NULL, ∞)}]\n" +
" │ └─ columns: [pruv2]\n" +
" │ ))\n" +
" └─ TableAlias(ism)\n" +
" └─ Table\n" +
" └─ name: HDDVB\n" +
"",
ExpectedAnalysis: "Filter\n" +
" ├─ (((NOT(ism.PRUV2 IS NULL)) AND ((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nhmxw.SWCQV]\n" +
" │ └─ Filter\n" +
" │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ └─ TableAlias(nhmxw)\n" +
" │ └─ IndexedTableAccess(WGSDC)\n" +
" │ ├─ index: [WGSDC.id]\n" +
" │ ├─ columns: [id swcqv]\n" +
" │ └─ keys: ism.PRUV2\n" +
" │ = 1) OR (((NOT(ism.FV24E IS NULL)) AND (NOT((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (nd.TW55N = Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nhmxw.FZXV5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ └─ TableAlias(nhmxw)\n" +
" │ │ └─ IndexedTableAccess(WGSDC)\n" +
" │ │ ├─ index: [WGSDC.id]\n" +
" │ │ ├─ columns: [id fzxv5]\n" +
" │ │ └─ keys: ism.PRUV2\n" +
" │ │ )\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ └─ name: E2I7U\n" +
" │ = ism.FV24E)))) OR ((NOT(ism.UJ6XY IS NULL)) AND (NOT((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (nd.TW55N = Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nhmxw.DQYGV]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ └─ TableAlias(nhmxw)\n" +
" │ │ └─ IndexedTableAccess(WGSDC)\n" +
" │ │ ├─ index: [WGSDC.id]\n" +
" │ │ ├─ columns: [id dqygv]\n" +
" │ │ └─ keys: ism.PRUV2\n" +
" │ │ )\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ └─ name: E2I7U\n" +
" │ = ism.UJ6XY))))))) OR ((NOT(ism.ETPQV IS NULL)) AND InSubquery\n" +
" │ ├─ left: ism.ETPQV\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tizhk.id as FWATE]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [WGSDC.id, WGSDC.NOHHR, WGSDC.AVPYF, WGSDC.SYPKF, WGSDC.IDUT2, WGSDC.FZXV5, WGSDC.DQYGV, WGSDC.SWCQV, WGSDC.YKSSU, WGSDC.FHCYT, WRZVO.id, WRZVO.TVNW2, WRZVO.ZHITY, WRZVO.SYPKF, WRZVO.IDUT2, WRZVO.O6QJ3, WRZVO.NO2JA, WRZVO.YKSSU, WRZVO.FHCYT, WRZVO.QZ6VT]\n" +
" │ └─ Filter\n" +
" │ ├─ hddvb.PRUV2 IS NULL\n" +
" │ └─ LeftOuterHashJoinExcludeNulls\n" +
" │ ├─ (nhmxw.id = hddvb.PRUV2)\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ (((tizhk.TVNW2 = nhmxw.NOHHR) AND (tizhk.ZHITY = nhmxw.AVPYF)) AND (tizhk.IDUT2 = nhmxw.IDUT2))\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (nhmxw.SWCQV = 0)\n" +
" │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ └─ name: WGSDC\n" +
" │ │ └─ TableAlias(tizhk)\n" +
" │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ ├─ index: [WRZVO.SYPKF]\n" +
" │ │ └─ keys: nhmxw.SYPKF\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (nhmxw.id)\n" +
" │ ├─ right-key: (hddvb.PRUV2)\n" +
" │ └─ IndexedTableAccess(HDDVB)\n" +
" │ ├─ index: [HDDVB.PRUV2]\n" +
" │ ├─ filters: [{(NULL, ∞)}]\n" +
" │ └─ columns: [pruv2]\n" +
" │ ))\n" +
" └─ TableAlias(ism)\n" +
" └─ Table\n" +
" └─ name: HDDVB\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: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]\n" +
" └─ Project\n" +
" ├─ columns: [WRZVO.id:1!null, WRZVO.TVNW2:2, WRZVO.ZHITY:3, WRZVO.SYPKF:4, WRZVO.IDUT2:5, WRZVO.O6QJ3:6, WRZVO.NO2JA:7, WRZVO.YKSSU:8, WRZVO.FHCYT:9, WRZVO.QZ6VT:10]\n" +
" └─ Filter\n" +
" ├─ hddvb.ETPQV:11 IS NULL\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ tizhk.id:1!null\n" +
" │ │ └─ tizhk_1.id:0!null\n" +
" │ ├─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tizhk_1.id:17!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.BTXC5:62\n" +
" │ │ │ └─ tizhk_1.SYPKF:20\n" +
" │ │ └─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ ├─ TableAlias(j4jyp)\n" +
" │ │ │ │ │ │ └─ ProcessTable\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_1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ │ │ ├─ index: [WRZVO.TVNW2]\n" +
" │ │ │ │ │ ├─ keys: [j4jyp.ZH72S:7]\n" +
" │ │ │ │ │ ├─ colSet: (11-20)\n" +
" │ │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: WRZVO\n" +
" │ │ │ │ │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" │ │ │ │ └─ TableAlias(rhuzn)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ ├─ keys: [tizhk_1.ZHITY:19]\n" +
" │ │ │ │ ├─ colSet: (38-54)\n" +
" │ │ │ │ ├─ tableId: 4\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(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ ├─ keys: [j4jyp.id:0!null]\n" +
" │ │ │ ├─ colSet: (55-71)\n" +
" │ │ │ ├─ tableId: 5\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" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ keys: [mf.M22QN:47!null]\n" +
" │ │ ├─ colSet: (72-74)\n" +
" │ │ ├─ tableId: 6\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ └─ TableAlias(tizhk)\n" +
" │ └─ IndexedTableAccess(WRZVO)\n" +
" │ ├─ index: [WRZVO.id]\n" +
" │ ├─ keys: [tizhk_1.id:0!null]\n" +
" │ ├─ colSet: (1-10)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: WRZVO\n" +
" │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" └─ Project\n" +
" ├─ columns: [hddvb.ETPQV:5]\n" +
" └─ IndexedTableAccess(HDDVB)\n" +
" ├─ index: [HDDVB.ETPQV]\n" +
" ├─ keys: [tizhk.id:1!null]\n" +
" ├─ colSet: (75-83)\n" +
" ├─ tableId: 7\n" +
" └─ Table\n" +
" ├─ name: HDDVB\n" +
" └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [tizhk.id, tizhk.TVNW2, tizhk.ZHITY, tizhk.SYPKF, tizhk.IDUT2, tizhk.O6QJ3, tizhk.NO2JA, tizhk.YKSSU, tizhk.FHCYT, tizhk.QZ6VT]\n" +
" └─ Project\n" +
" ├─ columns: [WRZVO.id, WRZVO.TVNW2, WRZVO.ZHITY, WRZVO.SYPKF, WRZVO.IDUT2, WRZVO.O6QJ3, WRZVO.NO2JA, WRZVO.YKSSU, WRZVO.FHCYT, WRZVO.QZ6VT]\n" +
" └─ Filter\n" +
" ├─ hddvb.ETPQV IS NULL\n" +
" └─ LeftOuterLookupJoin (estimated cost=8316.400 rows=1389)\n" +
" ├─ LookupJoin (estimated cost=16833.300 rows=5101)\n" +
" │ ├─ (tizhk.id = tizhk_1.id)\n" +
" │ ├─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tizhk_1.id]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.BTXC5 = tizhk_1.SYPKF)\n" +
" │ │ └─ LookupJoin (estimated cost=19806.600 rows=6002)\n" +
" │ │ ├─ LookupJoin (estimated cost=18627.300 rows=6002)\n" +
" │ │ │ ├─ LookupJoin (estimated cost=15867.300 rows=4802)\n" +
" │ │ │ │ ├─ LookupJoin (estimated cost=14907.300 rows=4802)\n" +
" │ │ │ │ │ ├─ TableAlias(j4jyp)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ └─ name: E2I7U\n" +
" │ │ │ │ │ └─ TableAlias(tizhk_1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ │ │ ├─ index: [WRZVO.TVNW2]\n" +
" │ │ │ │ │ └─ keys: j4jyp.ZH72S\n" +
" │ │ │ │ └─ TableAlias(rhuzn)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ └─ keys: tizhk_1.ZHITY\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ └─ keys: j4jyp.id\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ keys: mf.M22QN\n" +
" │ └─ TableAlias(tizhk)\n" +
" │ └─ IndexedTableAccess(WRZVO)\n" +
" │ ├─ index: [WRZVO.id]\n" +
" │ └─ keys: tizhk_1.id\n" +
" └─ Project\n" +
" ├─ columns: [hddvb.ETPQV]\n" +
" └─ IndexedTableAccess(HDDVB)\n" +
" ├─ index: [HDDVB.ETPQV]\n" +
" └─ keys: tizhk.id\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [tizhk.id, tizhk.TVNW2, tizhk.ZHITY, tizhk.SYPKF, tizhk.IDUT2, tizhk.O6QJ3, tizhk.NO2JA, tizhk.YKSSU, tizhk.FHCYT, tizhk.QZ6VT]\n" +
" └─ Project\n" +
" ├─ columns: [WRZVO.id, WRZVO.TVNW2, WRZVO.ZHITY, WRZVO.SYPKF, WRZVO.IDUT2, WRZVO.O6QJ3, WRZVO.NO2JA, WRZVO.YKSSU, WRZVO.FHCYT, WRZVO.QZ6VT]\n" +
" └─ Filter\n" +
" ├─ hddvb.ETPQV IS NULL\n" +
" └─ LeftOuterLookupJoin (estimated cost=8316.400 rows=1389) (actual rows=0 loops=1)\n" +
" ├─ LookupJoin (estimated cost=16833.300 rows=5101) (actual rows=0 loops=1)\n" +
" │ ├─ (tizhk.id = tizhk_1.id)\n" +
" │ ├─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tizhk_1.id]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.BTXC5 = tizhk_1.SYPKF)\n" +
" │ │ └─ LookupJoin (estimated cost=19806.600 rows=6002) (actual rows=0 loops=1)\n" +
" │ │ ├─ LookupJoin (estimated cost=18627.300 rows=6002) (actual rows=0 loops=1)\n" +
" │ │ │ ├─ LookupJoin (estimated cost=15867.300 rows=4802) (actual rows=0 loops=1)\n" +
" │ │ │ │ ├─ LookupJoin (estimated cost=14907.300 rows=4802) (actual rows=0 loops=1)\n" +
" │ │ │ │ │ ├─ TableAlias(j4jyp)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ └─ name: E2I7U\n" +
" │ │ │ │ │ └─ TableAlias(tizhk_1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ │ │ ├─ index: [WRZVO.TVNW2]\n" +
" │ │ │ │ │ └─ keys: j4jyp.ZH72S\n" +
" │ │ │ │ └─ TableAlias(rhuzn)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ └─ keys: tizhk_1.ZHITY\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ └─ keys: j4jyp.id\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ keys: mf.M22QN\n" +
" │ └─ TableAlias(tizhk)\n" +
" │ └─ IndexedTableAccess(WRZVO)\n" +
" │ ├─ index: [WRZVO.id]\n" +
" │ └─ keys: tizhk_1.id\n" +
" └─ Project\n" +
" ├─ columns: [hddvb.ETPQV]\n" +
" └─ IndexedTableAccess(HDDVB)\n" +
" ├─ index: [HDDVB.ETPQV]\n" +
" └─ keys: tizhk.id\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: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]\n" +
" └─ Project\n" +
" ├─ columns: [WRZVO.id:1!null, WRZVO.TVNW2:2, WRZVO.ZHITY:3, WRZVO.SYPKF:4, WRZVO.IDUT2:5, WRZVO.O6QJ3:6, WRZVO.NO2JA:7, WRZVO.YKSSU:8, WRZVO.FHCYT:9, WRZVO.QZ6VT:10]\n" +
" └─ Filter\n" +
" ├─ hddvb.ETPQV:11 IS NULL\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ tizhk.id:1!null\n" +
" │ │ └─ tizhk_1.id:0!null\n" +
" │ ├─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tizhk_1.id:17!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.BTXC5:62\n" +
" │ │ │ └─ tizhk_1.SYPKF:20\n" +
" │ │ └─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ ├─ TableAlias(j4jyp)\n" +
" │ │ │ │ │ │ └─ ProcessTable\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_1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ │ │ ├─ index: [WRZVO.TVNW2]\n" +
" │ │ │ │ │ ├─ keys: [j4jyp.ZH72S:7]\n" +
" │ │ │ │ │ ├─ colSet: (11-20)\n" +
" │ │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: WRZVO\n" +
" │ │ │ │ │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" │ │ │ │ └─ TableAlias(rhuzn)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ ├─ keys: [tizhk_1.ZHITY:19]\n" +
" │ │ │ │ ├─ colSet: (38-54)\n" +
" │ │ │ │ ├─ tableId: 4\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(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ ├─ keys: [j4jyp.id:0!null]\n" +
" │ │ │ ├─ colSet: (55-71)\n" +
" │ │ │ ├─ tableId: 5\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" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ keys: [mf.M22QN:47!null]\n" +
" │ │ ├─ colSet: (72-74)\n" +
" │ │ ├─ tableId: 6\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ └─ TableAlias(tizhk)\n" +
" │ └─ IndexedTableAccess(WRZVO)\n" +
" │ ├─ index: [WRZVO.id]\n" +
" │ ├─ keys: [tizhk_1.id:0!null]\n" +
" │ ├─ colSet: (1-10)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: WRZVO\n" +
" │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" └─ Project\n" +
" ├─ columns: [hddvb.ETPQV:5]\n" +
" └─ IndexedTableAccess(HDDVB)\n" +
" ├─ index: [HDDVB.ETPQV]\n" +
" ├─ keys: [tizhk.id:1!null]\n" +
" ├─ colSet: (75-83)\n" +
" ├─ tableId: 7\n" +
" └─ Table\n" +
" ├─ name: HDDVB\n" +
" └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [tizhk.id, tizhk.TVNW2, tizhk.ZHITY, tizhk.SYPKF, tizhk.IDUT2, tizhk.O6QJ3, tizhk.NO2JA, tizhk.YKSSU, tizhk.FHCYT, tizhk.QZ6VT]\n" +
" └─ Project\n" +
" ├─ columns: [WRZVO.id, WRZVO.TVNW2, WRZVO.ZHITY, WRZVO.SYPKF, WRZVO.IDUT2, WRZVO.O6QJ3, WRZVO.NO2JA, WRZVO.YKSSU, WRZVO.FHCYT, WRZVO.QZ6VT]\n" +
" └─ Filter\n" +
" ├─ hddvb.ETPQV IS NULL\n" +
" └─ LeftOuterLookupJoin (estimated cost=8316.400 rows=1389)\n" +
" ├─ LookupJoin (estimated cost=16833.300 rows=5101)\n" +
" │ ├─ (tizhk.id = tizhk_1.id)\n" +
" │ ├─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tizhk_1.id]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.BTXC5 = tizhk_1.SYPKF)\n" +
" │ │ └─ LookupJoin (estimated cost=19806.600 rows=6002)\n" +
" │ │ ├─ LookupJoin (estimated cost=18627.300 rows=6002)\n" +
" │ │ │ ├─ LookupJoin (estimated cost=15867.300 rows=4802)\n" +
" │ │ │ │ ├─ LookupJoin (estimated cost=14907.300 rows=4802)\n" +
" │ │ │ │ │ ├─ TableAlias(j4jyp)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ └─ name: E2I7U\n" +
" │ │ │ │ │ └─ TableAlias(tizhk_1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ │ │ ├─ index: [WRZVO.TVNW2]\n" +
" │ │ │ │ │ └─ keys: j4jyp.ZH72S\n" +
" │ │ │ │ └─ TableAlias(rhuzn)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ └─ keys: tizhk_1.ZHITY\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ └─ keys: j4jyp.id\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ keys: mf.M22QN\n" +
" │ └─ TableAlias(tizhk)\n" +
" │ └─ IndexedTableAccess(WRZVO)\n" +
" │ ├─ index: [WRZVO.id]\n" +
" │ └─ keys: tizhk_1.id\n" +
" └─ Project\n" +
" ├─ columns: [hddvb.ETPQV]\n" +
" └─ IndexedTableAccess(HDDVB)\n" +
" ├─ index: [HDDVB.ETPQV]\n" +
" └─ keys: tizhk.id\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [tizhk.id, tizhk.TVNW2, tizhk.ZHITY, tizhk.SYPKF, tizhk.IDUT2, tizhk.O6QJ3, tizhk.NO2JA, tizhk.YKSSU, tizhk.FHCYT, tizhk.QZ6VT]\n" +
" └─ Project\n" +
" ├─ columns: [WRZVO.id, WRZVO.TVNW2, WRZVO.ZHITY, WRZVO.SYPKF, WRZVO.IDUT2, WRZVO.O6QJ3, WRZVO.NO2JA, WRZVO.YKSSU, WRZVO.FHCYT, WRZVO.QZ6VT]\n" +
" └─ Filter\n" +
" ├─ hddvb.ETPQV IS NULL\n" +
" └─ LeftOuterLookupJoin (estimated cost=8316.400 rows=1389) (actual rows=0 loops=1)\n" +
" ├─ LookupJoin (estimated cost=16833.300 rows=5101) (actual rows=0 loops=1)\n" +
" │ ├─ (tizhk.id = tizhk_1.id)\n" +
" │ ├─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tizhk_1.id]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.BTXC5 = tizhk_1.SYPKF)\n" +
" │ │ └─ LookupJoin (estimated cost=19806.600 rows=6002) (actual rows=0 loops=1)\n" +
" │ │ ├─ LookupJoin (estimated cost=18627.300 rows=6002) (actual rows=0 loops=1)\n" +
" │ │ │ ├─ LookupJoin (estimated cost=15867.300 rows=4802) (actual rows=0 loops=1)\n" +
" │ │ │ │ ├─ LookupJoin (estimated cost=14907.300 rows=4802) (actual rows=0 loops=1)\n" +
" │ │ │ │ │ ├─ TableAlias(j4jyp)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ └─ name: E2I7U\n" +
" │ │ │ │ │ └─ TableAlias(tizhk_1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ │ │ ├─ index: [WRZVO.TVNW2]\n" +
" │ │ │ │ │ └─ keys: j4jyp.ZH72S\n" +
" │ │ │ │ └─ TableAlias(rhuzn)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ └─ keys: tizhk_1.ZHITY\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ └─ keys: j4jyp.id\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ keys: mf.M22QN\n" +
" │ └─ TableAlias(tizhk)\n" +
" │ └─ IndexedTableAccess(WRZVO)\n" +
" │ ├─ index: [WRZVO.id]\n" +
" │ └─ keys: tizhk_1.id\n" +
" └─ Project\n" +
" ├─ columns: [hddvb.ETPQV]\n" +
" └─ IndexedTableAccess(HDDVB)\n" +
" ├─ index: [HDDVB.ETPQV]\n" +
" └─ keys: tizhk.id\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:4!null as id, pbmrx.TW55N:5!null as TEYBZ, pbmrx.ZH72S:6 as FB6N7]\n" +
" └─ LookupJoin\n" +
" ├─ NOT\n" +
" │ └─ pbmrx.ZH72S:6 IS NULL\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cl3dt\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (44-47)\n" +
" │ ├─ tableId: 4\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ BADTB:2!null\n" +
" │ │ │ └─ 0 (bigint)\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 (bigint)\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\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: wooj5\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (34-36)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id:0!null as id, nd.ZH72S:7 as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select COUNT(*) from FLQLP where LUEVY = nd.id\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" +
" │ │ ├─ keys: [nd.id:0!null]\n" +
" │ │ ├─ colSet: (20-31)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: FLQLP\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" +
" │ │ ├─ alias-string: select COUNT(*) from FLQLP where LUEVY = nd.id\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" +
" │ │ ├─ keys: [nd.id:0!null]\n" +
" │ │ ├─ colSet: (20-31)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: FLQLP\n" +
" │ │ └─ columns: [luevy]\n" +
" │ │ as LEA4J]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ ├─ static: [{(NULL, ∞)}]\n" +
" │ ├─ colSet: (1-17)\n" +
" │ ├─ tableId: 1\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(pbmrx)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ keys: [cl3dt.ZH72S:0]\n" +
" ├─ colSet: (48-64)\n" +
" ├─ tableId: 5\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n zh72s]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [pbmrx.id as id, pbmrx.TW55N as TEYBZ, pbmrx.ZH72S as FB6N7]\n" +
" └─ LookupJoin (estimated cost=405.900 rows=124)\n" +
" ├─ (NOT(pbmrx.ZH72S IS NULL))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cl3dt\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Filter\n" +
" │ ├─ ((BADTB = 0) AND (FLHXH > 0))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [wooj5.ZH72S as ZH72S, count(wooj5.zh72s) as JTOA7, min(wooj5.lea4j) as BADTB, sum(wooj5.lea4j) as FLHXH]\n" +
" │ └─ Having((JTOA7 > 1))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(wooj5.zh72s), min(wooj5.lea4j), sum(wooj5.lea4j), wooj5.ZH72S, wooj5.ZH72S as ZH72S, count(wooj5.zh72s) as JTOA7, min(wooj5.lea4j) as BADTB, sum(wooj5.lea4j) as FLHXH]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(COUNT(wooj5.ZH72S), MIN(wooj5.LEA4J), SUM(wooj5.LEA4J), wooj5.ZH72S)\n" +
" │ ├─ Grouping(wooj5.ZH72S)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: wooj5\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (flqlp.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ ├─ columns: [luevy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as LEA4J]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (flqlp.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ ├─ columns: [luevy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as LEA4J]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ └─ filters: [{(NULL, ∞)}]\n" +
" └─ TableAlias(pbmrx)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ columns: [id tw55n zh72s]\n" +
" └─ keys: cl3dt.ZH72S\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [pbmrx.id as id, pbmrx.TW55N as TEYBZ, pbmrx.ZH72S as FB6N7]\n" +
" └─ LookupJoin (estimated cost=405.900 rows=124) (actual rows=0 loops=1)\n" +
" ├─ (NOT(pbmrx.ZH72S IS NULL))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cl3dt\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Filter\n" +
" │ ├─ ((BADTB = 0) AND (FLHXH > 0))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [wooj5.ZH72S as ZH72S, count(wooj5.zh72s) as JTOA7, min(wooj5.lea4j) as BADTB, sum(wooj5.lea4j) as FLHXH]\n" +
" │ └─ Having((JTOA7 > 1))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(wooj5.zh72s), min(wooj5.lea4j), sum(wooj5.lea4j), wooj5.ZH72S, wooj5.ZH72S as ZH72S, count(wooj5.zh72s) as JTOA7, min(wooj5.lea4j) as BADTB, sum(wooj5.lea4j) as FLHXH]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(COUNT(wooj5.ZH72S), MIN(wooj5.LEA4J), SUM(wooj5.LEA4J), wooj5.ZH72S)\n" +
" │ ├─ Grouping(wooj5.ZH72S)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: wooj5\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (flqlp.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ ├─ columns: [luevy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as LEA4J]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (flqlp.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ ├─ columns: [luevy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as LEA4J]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ └─ filters: [{(NULL, ∞)}]\n" +
" └─ TableAlias(pbmrx)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ columns: [id tw55n zh72s]\n" +
" └─ keys: cl3dt.ZH72S\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:33!null as VCGT3, nd.TW55N:15!null as UWBAI, aac.BTXC5:30 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" +
" │ │ │ │ ├─ alias-string: select I7HCR.SWCQV from EPZU6 as I7HCR where I7HCR.id = ct.OCA7E\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" +
" │ │ │ │ ├─ keys: [ct.OCA7E:6]\n" +
" │ │ │ │ ├─ colSet: (38-45)\n" +
" │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: EPZU6\n" +
" │ │ │ │ └─ columns: [id swcqv]\n" +
" │ │ │ └─ 1 (tinyint)\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select nd.id from E2I7U as nd where nd.TW55N = (select I7HCR.FVUCX from EPZU6 as I7HCR where I7HCR.id = ct.OCA7E)\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [nd.id:37!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ nd.TW55N:40!null\n" +
" │ │ │ │ └─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ ├─ alias-string: select I7HCR.FVUCX from EPZU6 as I7HCR where I7HCR.id = ct.OCA7E\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" +
" │ │ │ │ ├─ keys: [ct.OCA7E:6]\n" +
" │ │ │ │ ├─ colSet: (63-70)\n" +
" │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: EPZU6\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" +
" │ │ │ ├─ colSet: (46-62)\n" +
" │ │ │ └─ tableId: 6\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" +
" │ ├─ alias-string: select uct.id as FDL23 from EPZU6 as I7HCR join OUBDL as 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)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [uct.id:45!null as FDL23]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [EPZU6.id:37!null, EPZU6.TOFPN:38!null, EPZU6.SJYN2:39!null, EPZU6.BTXC5:40!null, EPZU6.FVUCX:41!null, EPZU6.SWCQV:42!null, EPZU6.YKSSU:43, EPZU6.FHCYT:44, OUBDL.id:45!null, OUBDL.FTQLQ:46, OUBDL.ZH72S:47, OUBDL.SFJ6L:48, OUBDL.V5DPX:49, OUBDL.LJLUM:50, OUBDL.IDPK7:51, OUBDL.NO52D:52, OUBDL.ZRV3B:53, OUBDL.VYO5E:54, OUBDL.YKSSU:55, OUBDL.FHCYT:56, OUBDL.QZ6VT:57]\n" +
" │ └─ Filter\n" +
" │ ├─ flqlp.OCA7E:58 IS NULL\n" +
" │ └─ LeftOuterHashJoinExcludeNulls\n" +
" │ ├─ Eq\n" +
" │ │ ├─ i7hcr.id:37!null\n" +
" │ │ └─ flqlp.OCA7E:58\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ uct.ZH72S:47\n" +
" │ │ │ │ └─ i7hcr.SJYN2:39!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ uct.LJLUM:50\n" +
" │ │ │ └─ i7hcr.BTXC5:40!null\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ i7hcr.SWCQV:42!null\n" +
" │ │ │ │ └─ 0 (int)\n" +
" │ │ │ └─ TableAlias(i7hcr)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: EPZU6\n" +
" │ │ │ ├─ columns: [id tofpn sjyn2 btxc5 fvucx swcqv ykssu fhcyt]\n" +
" │ │ │ ├─ colSet: (71-78)\n" +
" │ │ │ └─ tableId: 8\n" +
" │ │ └─ TableAlias(uct)\n" +
" │ │ └─ IndexedTableAccess(OUBDL)\n" +
" │ │ ├─ index: [OUBDL.FTQLQ]\n" +
" │ │ ├─ keys: [i7hcr.TOFPN:38!null]\n" +
" │ │ ├─ colSet: (79-91)\n" +
" │ │ ├─ tableId: 9\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: OUBDL\n" +
" │ │ └─ columns: [id ftqlq zh72s sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e ykssu fhcyt qz6vt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(i7hcr.id:37!null)\n" +
" │ ├─ right-key: TUPLE(flqlp.OCA7E:37)\n" +
" │ └─ IndexedTableAccess(FLQLP)\n" +
" │ ├─ index: [FLQLP.OCA7E]\n" +
" │ ├─ static: [{(NULL, ∞)}]\n" +
" │ ├─ colSet: (92-103)\n" +
" │ ├─ tableId: 10\n" +
" │ └─ Table\n" +
" │ ├─ name: FLQLP\n" +
" │ └─ columns: [oca7e]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ ci.id:32!null\n" +
" │ └─ ct.FZ2R5:1!null\n" +
" ├─ LookupJoin\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ ct.LUEVY:2!null\n" +
" │ │ │ └─ nd.id:12!null\n" +
" │ │ ├─ TableAlias(ct)\n" +
" │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (1-12)\n" +
" │ │ │ ├─ tableId: 1\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: FLQLP\n" +
" │ │ │ └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (18-34)\n" +
" │ │ ├─ tableId: 3\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(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ ├─ keys: [ct.M22QN:3!null]\n" +
" │ ├─ colSet: (35-37)\n" +
" │ ├─ tableId: 4\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXBU\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" +
" └─ ProcessTable\n" +
" └─ Table\n" +
" ├─ name: JDLNA\n" +
" └─ columns: [id ftqlq fwwiq o3qxw fhcyt]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Filter\n" +
" ├─ (((NOT(ct.OCA7E IS NULL)) AND ((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [i7hcr.SWCQV]\n" +
" │ └─ Filter\n" +
" │ ├─ (i7hcr.id = ct.OCA7E)\n" +
" │ └─ TableAlias(i7hcr)\n" +
" │ └─ IndexedTableAccess(EPZU6)\n" +
" │ ├─ index: [EPZU6.id]\n" +
" │ ├─ columns: [id swcqv]\n" +
" │ └─ keys: ct.OCA7E\n" +
" │ = 1) OR (NOT((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (nd.TW55N = Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [i7hcr.FVUCX]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (i7hcr.id = ct.OCA7E)\n" +
" │ │ └─ TableAlias(i7hcr)\n" +
" │ │ └─ IndexedTableAccess(EPZU6)\n" +
" │ │ ├─ index: [EPZU6.id]\n" +
" │ │ ├─ columns: [id fvucx]\n" +
" │ │ └─ keys: ct.OCA7E\n" +
" │ │ )\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ └─ name: E2I7U\n" +
" │ = ct.LUEVY))))) OR ((NOT(ct.NRURT IS NULL)) AND InSubquery\n" +
" │ ├─ left: ct.NRURT\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [uct.id as FDL23]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [EPZU6.id, EPZU6.TOFPN, EPZU6.SJYN2, EPZU6.BTXC5, EPZU6.FVUCX, EPZU6.SWCQV, EPZU6.YKSSU, EPZU6.FHCYT, OUBDL.id, OUBDL.FTQLQ, OUBDL.ZH72S, OUBDL.SFJ6L, OUBDL.V5DPX, OUBDL.LJLUM, OUBDL.IDPK7, OUBDL.NO52D, OUBDL.ZRV3B, OUBDL.VYO5E, OUBDL.YKSSU, OUBDL.FHCYT, OUBDL.QZ6VT]\n" +
" │ └─ Filter\n" +
" │ ├─ flqlp.OCA7E IS NULL\n" +
" │ └─ LeftOuterHashJoinExcludeNulls\n" +
" │ ├─ (i7hcr.id = flqlp.OCA7E)\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ ((uct.ZH72S = i7hcr.SJYN2) AND (uct.LJLUM = i7hcr.BTXC5))\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (i7hcr.SWCQV = 0)\n" +
" │ │ │ └─ TableAlias(i7hcr)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ └─ name: EPZU6\n" +
" │ │ └─ TableAlias(uct)\n" +
" │ │ └─ IndexedTableAccess(OUBDL)\n" +
" │ │ ├─ index: [OUBDL.FTQLQ]\n" +
" │ │ └─ keys: i7hcr.TOFPN\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (i7hcr.id)\n" +
" │ ├─ right-key: (flqlp.OCA7E)\n" +
" │ └─ IndexedTableAccess(FLQLP)\n" +
" │ ├─ index: [FLQLP.OCA7E]\n" +
" │ ├─ filters: [{(NULL, ∞)}]\n" +
" │ └─ columns: [oca7e]\n" +
" │ ))\n" +
" └─ HashJoin (estimated cost=16273.620 rows=14781)\n" +
" ├─ (ci.id = ct.FZ2R5)\n" +
" ├─ LookupJoin (estimated cost=48777.300 rows=14781)\n" +
" │ ├─ MergeJoin (estimated cost=18957.040 rows=14781)\n" +
" │ │ ├─ cmp: (ct.LUEVY = nd.id)\n" +
" │ │ ├─ TableAlias(ct)\n" +
" │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ keys: ct.M22QN\n" +
" └─ HashLookup\n" +
" ├─ left-key: (ct.FZ2R5)\n" +
" ├─ right-key: (ci.id)\n" +
" └─ TableAlias(ci)\n" +
" └─ Table\n" +
" └─ name: JDLNA\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Filter\n" +
" ├─ (((NOT(ct.OCA7E IS NULL)) AND ((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [i7hcr.SWCQV]\n" +
" │ └─ Filter\n" +
" │ ├─ (i7hcr.id = ct.OCA7E)\n" +
" │ └─ TableAlias(i7hcr)\n" +
" │ └─ IndexedTableAccess(EPZU6)\n" +
" │ ├─ index: [EPZU6.id]\n" +
" │ ├─ columns: [id swcqv]\n" +
" │ └─ keys: ct.OCA7E\n" +
" │ = 1) OR (NOT((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (nd.TW55N = Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [i7hcr.FVUCX]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (i7hcr.id = ct.OCA7E)\n" +
" │ │ └─ TableAlias(i7hcr)\n" +
" │ │ └─ IndexedTableAccess(EPZU6)\n" +
" │ │ ├─ index: [EPZU6.id]\n" +
" │ │ ├─ columns: [id fvucx]\n" +
" │ │ └─ keys: ct.OCA7E\n" +
" │ │ )\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ └─ name: E2I7U\n" +
" │ = ct.LUEVY))))) OR ((NOT(ct.NRURT IS NULL)) AND InSubquery\n" +
" │ ├─ left: ct.NRURT\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [uct.id as FDL23]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [EPZU6.id, EPZU6.TOFPN, EPZU6.SJYN2, EPZU6.BTXC5, EPZU6.FVUCX, EPZU6.SWCQV, EPZU6.YKSSU, EPZU6.FHCYT, OUBDL.id, OUBDL.FTQLQ, OUBDL.ZH72S, OUBDL.SFJ6L, OUBDL.V5DPX, OUBDL.LJLUM, OUBDL.IDPK7, OUBDL.NO52D, OUBDL.ZRV3B, OUBDL.VYO5E, OUBDL.YKSSU, OUBDL.FHCYT, OUBDL.QZ6VT]\n" +
" │ └─ Filter\n" +
" │ ├─ flqlp.OCA7E IS NULL\n" +
" │ └─ LeftOuterHashJoinExcludeNulls\n" +
" │ ├─ (i7hcr.id = flqlp.OCA7E)\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ ((uct.ZH72S = i7hcr.SJYN2) AND (uct.LJLUM = i7hcr.BTXC5))\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (i7hcr.SWCQV = 0)\n" +
" │ │ │ └─ TableAlias(i7hcr)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ └─ name: EPZU6\n" +
" │ │ └─ TableAlias(uct)\n" +
" │ │ └─ IndexedTableAccess(OUBDL)\n" +
" │ │ ├─ index: [OUBDL.FTQLQ]\n" +
" │ │ └─ keys: i7hcr.TOFPN\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (i7hcr.id)\n" +
" │ ├─ right-key: (flqlp.OCA7E)\n" +
" │ └─ IndexedTableAccess(FLQLP)\n" +
" │ ├─ index: [FLQLP.OCA7E]\n" +
" │ ├─ filters: [{(NULL, ∞)}]\n" +
" │ └─ columns: [oca7e]\n" +
" │ ))\n" +
" └─ HashJoin (estimated cost=16273.620 rows=14781) (actual rows=0 loops=1)\n" +
" ├─ (ci.id = ct.FZ2R5)\n" +
" ├─ LookupJoin (estimated cost=48777.300 rows=14781) (actual rows=0 loops=1)\n" +
" │ ├─ MergeJoin (estimated cost=18957.040 rows=14781) (actual rows=0 loops=1)\n" +
" │ │ ├─ cmp: (ct.LUEVY = nd.id)\n" +
" │ │ ├─ TableAlias(ct)\n" +
" │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ keys: ct.M22QN\n" +
" └─ HashLookup\n" +
" ├─ left-key: (ct.FZ2R5)\n" +
" ├─ right-key: (ci.id)\n" +
" └─ TableAlias(ci)\n" +
" └─ Table\n" +
" └─ name: JDLNA\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" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fzwbd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (52)\n" +
" │ ├─ tableId: 6\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ylksy.id:0!null as FDL23]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ci.FTQLQ:6!null\n" +
" │ │ └─ ylksy.FTQLQ:1\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ Project\n" +
" │ │ │ ├─ columns: [OUBDL.id:1!null, OUBDL.FTQLQ:2, OUBDL.ZH72S:3, OUBDL.LJLUM:4, E2I7U.ZH72S:0]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ flqlp.NRURT:5 IS NULL\n" +
" │ │ │ └─ LeftOuterHashJoinExcludeNulls\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ylksy.id:1!null\n" +
" │ │ │ │ └─ flqlp.NRURT:5\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ ├─ columns: [zh72s]\n" +
" │ │ │ │ │ ├─ colSet: (19-35)\n" +
" │ │ │ │ │ └─ tableId: 3\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ ylksy.LJLUM LIKE '%|%'\n" +
" │ │ │ │ └─ TableAlias(ylksy)\n" +
" │ │ │ │ └─ IndexedTableAccess(OUBDL)\n" +
" │ │ │ │ ├─ index: [OUBDL.ZH72S]\n" +
" │ │ │ │ ├─ keys: [nd.ZH72S:0]\n" +
" │ │ │ │ ├─ colSet: (1-13)\n" +
" │ │ │ │ ├─ tableId: 1\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: OUBDL\n" +
" │ │ │ │ └─ columns: [id ftqlq zh72s ljlum]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(ylksy.id:1!null)\n" +
" │ │ │ ├─ right-key: TUPLE(flqlp.NRURT:0)\n" +
" │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ ├─ index: [FLQLP.NRURT]\n" +
" │ │ │ ├─ static: [{(NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (39-50)\n" +
" │ │ │ ├─ tableId: 5\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: FLQLP\n" +
" │ │ │ └─ columns: [nrurt]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ ├─ keys: [ylksy.LJLUM:3]\n" +
" │ │ ├─ colSet: (36-38)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [btxc5]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ylksy.FTQLQ:1)\n" +
" │ ├─ right-key: TUPLE(ci.FTQLQ:0!null)\n" +
" │ └─ TableAlias(ci)\n" +
" │ └─ Table\n" +
" │ ├─ name: JDLNA\n" +
" │ ├─ columns: [ftqlq]\n" +
" │ ├─ colSet: (14-18)\n" +
" │ └─ tableId: 2\n" +
" └─ TableAlias(uct)\n" +
" └─ IndexedTableAccess(OUBDL)\n" +
" ├─ index: [OUBDL.id]\n" +
" ├─ keys: [fzwbd.FDL23:0!null]\n" +
" ├─ colSet: (53-65)\n" +
" ├─ tableId: 7\n" +
" └─ Table\n" +
" ├─ name: OUBDL\n" +
" └─ columns: [id ftqlq zh72s sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e ykssu fhcyt qz6vt]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [uct.id, uct.FTQLQ, uct.ZH72S, uct.SFJ6L, uct.V5DPX, uct.LJLUM, uct.IDPK7, uct.NO52D, uct.ZRV3B, uct.VYO5E, uct.YKSSU, uct.FHCYT, uct.QZ6VT]\n" +
" └─ LookupJoin (estimated cost=330.000 rows=100)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fzwbd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ylksy.id as FDL23]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (ci.FTQLQ = ylksy.FTQLQ)\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ Project\n" +
" │ │ │ ├─ columns: [OUBDL.id, OUBDL.FTQLQ, OUBDL.ZH72S, OUBDL.LJLUM, E2I7U.ZH72S]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ flqlp.NRURT IS NULL\n" +
" │ │ │ └─ LeftOuterHashJoinExcludeNulls\n" +
" │ │ │ ├─ (ylksy.id = flqlp.NRURT)\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ └─ columns: [zh72s]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (NOT(ylksy.LJLUM LIKE '%|%'))\n" +
" │ │ │ │ └─ TableAlias(ylksy)\n" +
" │ │ │ │ └─ IndexedTableAccess(OUBDL)\n" +
" │ │ │ │ ├─ index: [OUBDL.ZH72S]\n" +
" │ │ │ │ ├─ columns: [id ftqlq zh72s ljlum]\n" +
" │ │ │ │ └─ keys: nd.ZH72S\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (ylksy.id)\n" +
" │ │ │ ├─ right-key: (flqlp.NRURT)\n" +
" │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ ├─ index: [FLQLP.NRURT]\n" +
" │ │ │ ├─ filters: [{(NULL, ∞)}]\n" +
" │ │ │ └─ columns: [nrurt]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ ├─ columns: [btxc5]\n" +
" │ │ └─ keys: ylksy.LJLUM\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (ylksy.FTQLQ)\n" +
" │ ├─ right-key: (ci.FTQLQ)\n" +
" │ └─ TableAlias(ci)\n" +
" │ └─ Table\n" +
" │ ├─ name: JDLNA\n" +
" │ └─ columns: [ftqlq]\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" +
" └─ keys: fzwbd.FDL23\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [uct.id, uct.FTQLQ, uct.ZH72S, uct.SFJ6L, uct.V5DPX, uct.LJLUM, uct.IDPK7, uct.NO52D, uct.ZRV3B, uct.VYO5E, uct.YKSSU, uct.FHCYT, uct.QZ6VT]\n" +
" └─ LookupJoin (estimated cost=330.000 rows=100) (actual rows=0 loops=1)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fzwbd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ylksy.id as FDL23]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (ci.FTQLQ = ylksy.FTQLQ)\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ Project\n" +
" │ │ │ ├─ columns: [OUBDL.id, OUBDL.FTQLQ, OUBDL.ZH72S, OUBDL.LJLUM, E2I7U.ZH72S]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ flqlp.NRURT IS NULL\n" +
" │ │ │ └─ LeftOuterHashJoinExcludeNulls\n" +
" │ │ │ ├─ (ylksy.id = flqlp.NRURT)\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ └─ columns: [zh72s]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (NOT(ylksy.LJLUM LIKE '%|%'))\n" +
" │ │ │ │ └─ TableAlias(ylksy)\n" +
" │ │ │ │ └─ IndexedTableAccess(OUBDL)\n" +
" │ │ │ │ ├─ index: [OUBDL.ZH72S]\n" +
" │ │ │ │ ├─ columns: [id ftqlq zh72s ljlum]\n" +
" │ │ │ │ └─ keys: nd.ZH72S\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (ylksy.id)\n" +
" │ │ │ ├─ right-key: (flqlp.NRURT)\n" +
" │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ ├─ index: [FLQLP.NRURT]\n" +
" │ │ │ ├─ filters: [{(NULL, ∞)}]\n" +
" │ │ │ └─ columns: [nrurt]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ ├─ columns: [btxc5]\n" +
" │ │ └─ keys: ylksy.LJLUM\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (ylksy.FTQLQ)\n" +
" │ ├─ right-key: (ci.FTQLQ)\n" +
" │ └─ TableAlias(ci)\n" +
" │ └─ Table\n" +
" │ ├─ name: JDLNA\n" +
" │ └─ columns: [ftqlq]\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" +
" └─ keys: fzwbd.FDL23\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:9!null as UWBAI, aac.BTXC5:11 as TPXBU, ct.V5DPX:5!null as V5DPX, ct.S3Q3Y:6!null as S3Q3Y, ct.ZRV3B:7!null as ZRV3B]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ tvtjs.id:14!null\n" +
" │ └─ ct.XMM6Q:4\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ ci.id:12!null\n" +
" │ │ └─ ct.FZ2R5:1!null\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ ct.LUEVY:2!null\n" +
" │ │ │ │ └─ nd.id:8!null\n" +
" │ │ │ ├─ TableAlias(ct)\n" +
" │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (1-12)\n" +
" │ │ │ │ ├─ tableId: 1\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: FLQLP\n" +
" │ │ │ │ └─ columns: [id fz2r5 luevy m22qn xmm6q v5dpx s3q3y zrv3b]\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (31-47)\n" +
" │ │ │ ├─ tableId: 4\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [id tw55n]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ keys: [ct.M22QN:3!null]\n" +
" │ │ ├─ colSet: (48-50)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(ct.FZ2R5:1!null)\n" +
" │ ├─ right-key: TUPLE(ci.id:0!null)\n" +
" │ └─ TableAlias(ci)\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: JDLNA\n" +
" │ └─ columns: [id ftqlq]\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 (int)\n" +
" └─ TableAlias(tvtjs)\n" +
" └─ ProcessTable\n" +
" └─ Table\n" +
" ├─ name: HU5A5\n" +
" └─ columns: [id swcqv]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [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]\n" +
" └─ HashJoin (estimated cost=15160.620 rows=14781)\n" +
" ├─ (tvtjs.id = ct.XMM6Q)\n" +
" ├─ HashJoin (estimated cost=16273.620 rows=14781)\n" +
" │ ├─ (ci.id = ct.FZ2R5)\n" +
" │ ├─ LookupJoin (estimated cost=48777.300 rows=14781)\n" +
" │ │ ├─ MergeJoin (estimated cost=18957.040 rows=14781)\n" +
" │ │ │ ├─ cmp: (ct.LUEVY = nd.id)\n" +
" │ │ │ ├─ TableAlias(ct)\n" +
" │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id fz2r5 luevy m22qn xmm6q v5dpx s3q3y zrv3b]\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id tw55n]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: ct.M22QN\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (ct.FZ2R5)\n" +
" │ ├─ right-key: (ci.id)\n" +
" │ └─ TableAlias(ci)\n" +
" │ └─ Table\n" +
" │ ├─ name: JDLNA\n" +
" │ └─ columns: [id ftqlq]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (ct.XMM6Q)\n" +
" ├─ right-key: (tvtjs.id)\n" +
" └─ Filter\n" +
" ├─ (tvtjs.SWCQV = 1)\n" +
" └─ TableAlias(tvtjs)\n" +
" └─ Table\n" +
" ├─ name: HU5A5\n" +
" └─ columns: [id swcqv]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [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]\n" +
" └─ HashJoin (estimated cost=15160.620 rows=14781) (actual rows=0 loops=1)\n" +
" ├─ (tvtjs.id = ct.XMM6Q)\n" +
" ├─ HashJoin (estimated cost=16273.620 rows=14781) (actual rows=0 loops=1)\n" +
" │ ├─ (ci.id = ct.FZ2R5)\n" +
" │ ├─ LookupJoin (estimated cost=48777.300 rows=14781) (actual rows=0 loops=1)\n" +
" │ │ ├─ MergeJoin (estimated cost=18957.040 rows=14781) (actual rows=0 loops=1)\n" +
" │ │ │ ├─ cmp: (ct.LUEVY = nd.id)\n" +
" │ │ │ ├─ TableAlias(ct)\n" +
" │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id fz2r5 luevy m22qn xmm6q v5dpx s3q3y zrv3b]\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id tw55n]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: ct.M22QN\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (ct.FZ2R5)\n" +
" │ ├─ right-key: (ci.id)\n" +
" │ └─ TableAlias(ci)\n" +
" │ └─ Table\n" +
" │ ├─ name: JDLNA\n" +
" │ └─ columns: [id ftqlq]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (ct.XMM6Q)\n" +
" ├─ right-key: (tvtjs.id)\n" +
" └─ Filter\n" +
" ├─ (tvtjs.SWCQV = 1)\n" +
" └─ TableAlias(tvtjs)\n" +
" └─ Table\n" +
" ├─ name: HU5A5\n" +
" └─ columns: [id swcqv]\n" +
"",
},
{
Query: `
SELECT
*
FROM
HU5A5
WHERE
id NOT IN
(
SELECT
XMM6Q
FROM
FLQLP
WHERE XMM6Q IS NOT NULL
)
AND
SWCQV = 0
`,
ExpectedPlan: "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" +
" ├─ flqlp.XMM6Q:13 IS NULL\n" +
" └─ LeftOuterMergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ hu5a5.id:0!null\n" +
" │ └─ flqlp.XMM6Q:13\n" +
" ├─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ hu5a5.SWCQV:10!null\n" +
" │ │ └─ 0 (int)\n" +
" │ └─ IndexedTableAccess(HU5A5)\n" +
" │ ├─ index: [HU5A5.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (1-13)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: HU5A5\n" +
" │ └─ columns: [id tofpn i3vta sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e swcqv ykssu fhcyt]\n" +
" └─ Project\n" +
" ├─ columns: [flqlp.XMM6Q:7]\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ flqlp.XMM6Q:7 IS NULL\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.XMM6Q]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (14-25)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: FLQLP\n" +
" └─ columns: [id fz2r5 luevy m22qn ove3e nrurt oca7e xmm6q v5dpx s3q3y zrv3b fhcyt]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [HU5A5.id, HU5A5.TOFPN, HU5A5.I3VTA, HU5A5.SFJ6L, HU5A5.V5DPX, HU5A5.LJLUM, HU5A5.IDPK7, HU5A5.NO52D, HU5A5.ZRV3B, HU5A5.VYO5E, HU5A5.SWCQV, HU5A5.YKSSU, HU5A5.FHCYT]\n" +
" └─ Filter\n" +
" ├─ flqlp.XMM6Q IS NULL\n" +
" └─ LeftOuterMergeJoin (estimated cost=9561.410 rows=206920)\n" +
" ├─ cmp: (hu5a5.id = flqlp.XMM6Q)\n" +
" ├─ Filter\n" +
" │ ├─ (hu5a5.SWCQV = 0)\n" +
" │ └─ IndexedTableAccess(HU5A5)\n" +
" │ ├─ index: [HU5A5.id]\n" +
" │ └─ filters: [{[NULL, ∞)}]\n" +
" └─ Project\n" +
" ├─ columns: [flqlp.XMM6Q]\n" +
" └─ Filter\n" +
" ├─ (NOT(flqlp.XMM6Q IS NULL))\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.XMM6Q]\n" +
" └─ filters: [{[NULL, ∞)}]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [HU5A5.id, HU5A5.TOFPN, HU5A5.I3VTA, HU5A5.SFJ6L, HU5A5.V5DPX, HU5A5.LJLUM, HU5A5.IDPK7, HU5A5.NO52D, HU5A5.ZRV3B, HU5A5.VYO5E, HU5A5.SWCQV, HU5A5.YKSSU, HU5A5.FHCYT]\n" +
" └─ Filter\n" +
" ├─ flqlp.XMM6Q IS NULL\n" +
" └─ LeftOuterMergeJoin (estimated cost=9561.410 rows=206920) (actual rows=0 loops=1)\n" +
" ├─ cmp: (hu5a5.id = flqlp.XMM6Q)\n" +
" ├─ Filter\n" +
" │ ├─ (hu5a5.SWCQV = 0)\n" +
" │ └─ IndexedTableAccess(HU5A5)\n" +
" │ ├─ index: [HU5A5.id]\n" +
" │ └─ filters: [{[NULL, ∞)}]\n" +
" └─ Project\n" +
" ├─ columns: [flqlp.XMM6Q]\n" +
" └─ Filter\n" +
" ├─ (NOT(flqlp.XMM6Q IS NULL))\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.XMM6Q]\n" +
" └─ filters: [{[NULL, ∞)}]\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:0!null as id, concat(nsplt.TW55N:18!null,FDNCN (longtext),lqncx.TW55N:16!null) as X37NA, concat(xlza5.TW55N:10!null,FDNCN (longtext),afjmd.TW55N:8!null) as THWCS, rn.HVHRZ:3!null as HVHRZ]\n" +
" └─ Filter\n" +
" ├─ Or\n" +
" │ ├─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ pv6r5.FFTBJ:13!null\n" +
" │ │ └─ zyutc.BRQP2:5!null\n" +
" │ └─ NOT\n" +
" │ └─ Eq\n" +
" │ ├─ pv6r5.NUMK2:14!null\n" +
" │ └─ 1 (int)\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ rn.WNUNU:1!null\n" +
" │ └─ pv6r5.id:11!null\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ rn.HHVLX:2!null\n" +
" │ │ └─ zyutc.id:4!null\n" +
" │ ├─ TableAlias(rn)\n" +
" │ │ └─ ProcessTable\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: QYWQD\n" +
" │ │ └─ columns: [id wnunu hhvlx hvhrz]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(rn.HHVLX:2!null)\n" +
" │ ├─ right-key: TUPLE(zyutc.id:0!null)\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ xlza5.id:9!null\n" +
" │ │ └─ zyutc.BRQP2:5!null\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ zyutc.FFTBJ:6!null\n" +
" │ │ │ └─ afjmd.id:7!null\n" +
" │ │ ├─ TableAlias(zyutc)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (17-26)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ TableAlias(afjmd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (78-94)\n" +
" │ │ ├─ tableId: 7\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(zyutc.BRQP2:5!null)\n" +
" │ ├─ right-key: TUPLE(xlza5.id:0!null)\n" +
" │ └─ TableAlias(xlza5)\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(rn.WNUNU:1!null)\n" +
" ├─ right-key: TUPLE(pv6r5.id:0!null)\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nsplt.id:17!null\n" +
" │ └─ pv6r5.BRQP2:12!null\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ pv6r5.FFTBJ:13!null\n" +
" │ │ └─ lqncx.id:15!null\n" +
" │ ├─ TableAlias(pv6r5)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (7-16)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2 fftbj numk2]\n" +
" │ └─ TableAlias(lqncx)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (44-60)\n" +
" │ ├─ tableId: 5\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(pv6r5.BRQP2:12!null)\n" +
" ├─ right-key: TUPLE(nsplt.id:0!null)\n" +
" └─ TableAlias(nsplt)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" ├─ columns: [id tw55n]\n" +
" ├─ colSet: (27-43)\n" +
" └─ tableId: 4\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [rn.id as id, concat(nsplt.TW55N,'FDNCN',lqncx.TW55N) as X37NA, concat(xlza5.TW55N,'FDNCN',afjmd.TW55N) as THWCS, rn.HVHRZ as HVHRZ]\n" +
" └─ Filter\n" +
" ├─ ((NOT((pv6r5.FFTBJ = zyutc.BRQP2))) OR (NOT((pv6r5.NUMK2 = 1))))\n" +
" └─ HashJoin (estimated cost=107544.840 rows=70692)\n" +
" ├─ (rn.WNUNU = pv6r5.id)\n" +
" ├─ HashJoin (estimated cost=107544.840 rows=70692)\n" +
" │ ├─ (rn.HHVLX = zyutc.id)\n" +
" │ ├─ TableAlias(rn)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: QYWQD\n" +
" │ │ └─ columns: [id wnunu hhvlx hvhrz]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (rn.HHVLX)\n" +
" │ ├─ right-key: (zyutc.id)\n" +
" │ └─ HashJoin\n" +
" │ ├─ (xlza5.id = zyutc.BRQP2)\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (zyutc.FFTBJ = afjmd.id)\n" +
" │ │ ├─ TableAlias(zyutc)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ TableAlias(afjmd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (zyutc.BRQP2)\n" +
" │ ├─ right-key: (xlza5.id)\n" +
" │ └─ TableAlias(xlza5)\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (rn.WNUNU)\n" +
" ├─ right-key: (pv6r5.id)\n" +
" └─ HashJoin\n" +
" ├─ (nsplt.id = pv6r5.BRQP2)\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: (pv6r5.FFTBJ = lqncx.id)\n" +
" │ ├─ TableAlias(pv6r5)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id brqp2 fftbj numk2]\n" +
" │ └─ TableAlias(lqncx)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (pv6r5.BRQP2)\n" +
" ├─ right-key: (nsplt.id)\n" +
" └─ TableAlias(nsplt)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [rn.id as id, concat(nsplt.TW55N,'FDNCN',lqncx.TW55N) as X37NA, concat(xlza5.TW55N,'FDNCN',afjmd.TW55N) as THWCS, rn.HVHRZ as HVHRZ]\n" +
" └─ Filter\n" +
" ├─ ((NOT((pv6r5.FFTBJ = zyutc.BRQP2))) OR (NOT((pv6r5.NUMK2 = 1))))\n" +
" └─ HashJoin (estimated cost=107544.840 rows=70692) (actual rows=0 loops=1)\n" +
" ├─ (rn.WNUNU = pv6r5.id)\n" +
" ├─ HashJoin (estimated cost=107544.840 rows=70692) (actual rows=0 loops=1)\n" +
" │ ├─ (rn.HHVLX = zyutc.id)\n" +
" │ ├─ TableAlias(rn)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: QYWQD\n" +
" │ │ └─ columns: [id wnunu hhvlx hvhrz]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (rn.HHVLX)\n" +
" │ ├─ right-key: (zyutc.id)\n" +
" │ └─ HashJoin\n" +
" │ ├─ (xlza5.id = zyutc.BRQP2)\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (zyutc.FFTBJ = afjmd.id)\n" +
" │ │ ├─ TableAlias(zyutc)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ TableAlias(afjmd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (zyutc.BRQP2)\n" +
" │ ├─ right-key: (xlza5.id)\n" +
" │ └─ TableAlias(xlza5)\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (rn.WNUNU)\n" +
" ├─ right-key: (pv6r5.id)\n" +
" └─ HashJoin\n" +
" ├─ (nsplt.id = pv6r5.BRQP2)\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: (pv6r5.FFTBJ = lqncx.id)\n" +
" │ ├─ TableAlias(pv6r5)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id brqp2 fftbj numk2]\n" +
" │ └─ TableAlias(lqncx)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (pv6r5.BRQP2)\n" +
" ├─ right-key: (nsplt.id)\n" +
" └─ TableAlias(nsplt)\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:5!null as DRIWM, concat(oe56m.TW55N:10!null,FDNCN (longtext),cgfrz.TW55N:12!null) as GRVSE, skpm6.id:0!null as JIEVY, concat(v5say.TW55N:14!null,FDNCN (longtext),fqthf.TW55N:4!null) as ENCM3, 1 (decimal(2,1)) as OHD3R]\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ rn.WNUNU:15!null IS NULL\n" +
" │ └─ rn.HHVLX:16!null IS NULL\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ Eq\n" +
" │ ├─ rn.HHVLX:16!null\n" +
" │ └─ skpm6.id:0!null\n" +
" ├─ HashJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ skpm6.BRQP2:1!null\n" +
" │ │ │ │ └─ sn.FFTBJ:7!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ v5say.id:13!null\n" +
" │ │ │ └─ skpm6.BRQP2:1!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ skpm6.BRQP2:1!null\n" +
" │ │ └─ cgfrz.id:11!null\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ skpm6.FFTBJ:2!null\n" +
" │ │ │ └─ fqthf.id:3!null\n" +
" │ │ ├─ TableAlias(skpm6)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (11-20)\n" +
" │ │ │ ├─ tableId: 2\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ TableAlias(fqthf)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (78-94)\n" +
" │ │ ├─ tableId: 7\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(skpm6.BRQP2:1!null, skpm6.BRQP2:1!null, skpm6.BRQP2:1!null)\n" +
" │ ├─ right-key: TUPLE(sn.FFTBJ:2!null, v5say.id:8!null, cgfrz.id:6!null)\n" +
" │ └─ HashJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cgfrz.id:11!null\n" +
" │ │ │ └─ sn.FFTBJ:7!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ sn.FFTBJ:7!null\n" +
" │ │ └─ v5say.id:13!null\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ sn.BRQP2:6!null\n" +
" │ │ │ └─ oe56m.id:9!null\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ sn.NUMK2:3!null\n" +
" │ │ │ │ └─ 1 (int)\n" +
" │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (1-10)\n" +
" │ │ │ ├─ tableId: 1\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj numk2]\n" +
" │ │ └─ TableAlias(oe56m)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (27-43)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(sn.FFTBJ:7!null, sn.FFTBJ:7!null)\n" +
" │ ├─ right-key: TUPLE(cgfrz.id:0!null, v5say.id:2!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ cgfrz.id:11!null\n" +
" │ │ └─ v5say.id:13!null\n" +
" │ ├─ TableAlias(cgfrz)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (44-60)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ TableAlias(v5say)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (61-77)\n" +
" │ ├─ tableId: 6\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ TableAlias(rn)\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.WNUNU]\n" +
" ├─ keys: [sn.id:5!null]\n" +
" ├─ colSet: (21-26)\n" +
" ├─ tableId: 3\n" +
" └─ Table\n" +
" ├─ name: QYWQD\n" +
" └─ columns: [wnunu hhvlx]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Filter\n" +
" ├─ (rn.WNUNU IS NULL AND rn.HHVLX IS NULL)\n" +
" └─ LeftOuterLookupJoin (estimated cost=48654.100 rows=15688)\n" +
" ├─ (rn.HHVLX = skpm6.id)\n" +
" ├─ HashJoin (estimated cost=42179.640 rows=12551)\n" +
" │ ├─ (((skpm6.BRQP2 = sn.FFTBJ) AND (v5say.id = skpm6.BRQP2)) AND (skpm6.BRQP2 = cgfrz.id))\n" +
" │ ├─ MergeJoin (estimated cost=15929.680 rows=11813)\n" +
" │ │ ├─ cmp: (skpm6.FFTBJ = fqthf.id)\n" +
" │ │ ├─ TableAlias(skpm6)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ TableAlias(fqthf)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (skpm6.BRQP2, skpm6.BRQP2, skpm6.BRQP2)\n" +
" │ ├─ right-key: (sn.FFTBJ, v5say.id, cgfrz.id)\n" +
" │ └─ HashJoin\n" +
" │ ├─ ((cgfrz.id = sn.FFTBJ) AND (sn.FFTBJ = v5say.id))\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (sn.BRQP2 = oe56m.id)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (sn.NUMK2 = 1)\n" +
" │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj numk2]\n" +
" │ │ └─ TableAlias(oe56m)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (sn.FFTBJ, sn.FFTBJ)\n" +
" │ ├─ right-key: (cgfrz.id, v5say.id)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (cgfrz.id = v5say.id)\n" +
" │ ├─ TableAlias(cgfrz)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ TableAlias(v5say)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ TableAlias(rn)\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.WNUNU]\n" +
" ├─ columns: [wnunu hhvlx]\n" +
" └─ keys: sn.id\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Filter\n" +
" ├─ (rn.WNUNU IS NULL AND rn.HHVLX IS NULL)\n" +
" └─ LeftOuterLookupJoin (estimated cost=48654.100 rows=15688) (actual rows=0 loops=1)\n" +
" ├─ (rn.HHVLX = skpm6.id)\n" +
" ├─ HashJoin (estimated cost=42179.640 rows=12551) (actual rows=0 loops=1)\n" +
" │ ├─ (((skpm6.BRQP2 = sn.FFTBJ) AND (v5say.id = skpm6.BRQP2)) AND (skpm6.BRQP2 = cgfrz.id))\n" +
" │ ├─ MergeJoin (estimated cost=15929.680 rows=11813) (actual rows=0 loops=1)\n" +
" │ │ ├─ cmp: (skpm6.FFTBJ = fqthf.id)\n" +
" │ │ ├─ TableAlias(skpm6)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ TableAlias(fqthf)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (skpm6.BRQP2, skpm6.BRQP2, skpm6.BRQP2)\n" +
" │ ├─ right-key: (sn.FFTBJ, v5say.id, cgfrz.id)\n" +
" │ └─ HashJoin\n" +
" │ ├─ ((cgfrz.id = sn.FFTBJ) AND (sn.FFTBJ = v5say.id))\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (sn.BRQP2 = oe56m.id)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (sn.NUMK2 = 1)\n" +
" │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj numk2]\n" +
" │ │ └─ TableAlias(oe56m)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (sn.FFTBJ, sn.FFTBJ)\n" +
" │ ├─ right-key: (cgfrz.id, v5say.id)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (cgfrz.id = v5say.id)\n" +
" │ ├─ TableAlias(cgfrz)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ └─ TableAlias(v5say)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ TableAlias(rn)\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.WNUNU]\n" +
" ├─ columns: [wnunu hhvlx]\n" +
" └─ keys: sn.id\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:0!null, tdrvg.FGG57:1!null, tdrvg.SSHPJ:2!null, tdrvg.SFJ6L:3!null]\n" +
" └─ Filter\n" +
" ├─ InSubquery\n" +
" │ ├─ left: tdrvg.id:0!null\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ alias-string: select (select id from TDRVG where SSHPJ = S7BYT.SSHPJ order by id asc limit 1) id from (select distinct S5KBM.SSHPJ as SSHPJ, S5KBM.SFJ6L as SFJ6L from TDRVG as S5KBM join E2I7U as nd on nd.FGG57 = S5KBM.FGG57) as S7BYT where S7BYT.SSHPJ not in (select SSHPJ from WE72E)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select id from TDRVG where SSHPJ = S7BYT.SSHPJ order by id asc limit 1\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tdrvg.id:8!null]\n" +
" │ │ └─ Sort(tdrvg.id:8!null ASC nullsFirst)\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ tdrvg.SSHPJ:9!null\n" +
" │ │ │ └─ s7byt.SSHPJ:5!null\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.SSHPJ]\n" +
" │ │ ├─ keys: [s7byt.SSHPJ:5!null]\n" +
" │ │ ├─ colSet: (36-40)\n" +
" │ │ ├─ tableId: 6\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TDRVG\n" +
" │ │ └─ columns: [id sshpj]\n" +
" │ │ as id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [s7byt.SSHPJ:5!null, s7byt.SFJ6L:6!null, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select id from TDRVG where SSHPJ = S7BYT.SSHPJ order by id asc limit 1\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tdrvg.id:7!null]\n" +
" │ │ └─ Sort(tdrvg.id:7!null ASC nullsFirst)\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ tdrvg.SSHPJ:8!null\n" +
" │ │ │ └─ s7byt.SSHPJ:5!null\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.SSHPJ]\n" +
" │ │ ├─ keys: [s7byt.SSHPJ:5!null]\n" +
" │ │ ├─ colSet: (36-40)\n" +
" │ │ ├─ tableId: 6\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TDRVG\n" +
" │ │ └─ columns: [id sshpj]\n" +
" │ │ as id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [s7byt.SSHPJ:5!null, s7byt.SFJ6L:6!null]\n" +
" │ └─ Filter\n" +
" │ ├─ we72e.SSHPJ:7!null IS NULL\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: s7byt\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (30,31)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [s5kbm.SSHPJ:7!null as SSHPJ, s5kbm.SFJ6L:8!null as SFJ6L]\n" +
" │ │ └─ LookupJoin\n" +
" │ │ ├─ TableAlias(nd)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ ├─ columns: [fgg57]\n" +
" │ │ │ ├─ colSet: (11-27)\n" +
" │ │ │ └─ tableId: 3\n" +
" │ │ └─ TableAlias(s5kbm)\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.FGG57]\n" +
" │ │ ├─ keys: [nd.FGG57:5]\n" +
" │ │ ├─ colSet: (6-10)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TDRVG\n" +
" │ │ └─ columns: [fgg57 sshpj sfj6l]\n" +
" │ └─ IndexedTableAccess(WE72E)\n" +
" │ ├─ index: [WE72E.SSHPJ]\n" +
" │ ├─ keys: [s7byt.SSHPJ:5!null]\n" +
" │ ├─ colSet: (32-35)\n" +
" │ ├─ tableId: 5\n" +
" │ └─ Table\n" +
" │ ├─ name: WE72E\n" +
" │ └─ columns: [sshpj]\n" +
" └─ ProcessTable\n" +
" └─ Table\n" +
" ├─ name: TDRVG\n" +
" └─ columns: [id fgg57 sshpj sfj6l zh72s]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [tdrvg.id, tdrvg.FGG57, tdrvg.SSHPJ, tdrvg.SFJ6L]\n" +
" └─ Filter\n" +
" ├─ InSubquery\n" +
" │ ├─ left: tdrvg.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tdrvg.id]\n" +
" │ │ └─ Sort(tdrvg.id ASC)\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (tdrvg.SSHPJ = s7byt.SSHPJ)\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.SSHPJ]\n" +
" │ │ ├─ columns: [id sshpj]\n" +
" │ │ └─ keys: s7byt.SSHPJ\n" +
" │ │ as id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [s7byt.SSHPJ, s7byt.SFJ6L, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tdrvg.id]\n" +
" │ │ └─ Sort(tdrvg.id ASC)\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (tdrvg.SSHPJ = s7byt.SSHPJ)\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.SSHPJ]\n" +
" │ │ ├─ columns: [id sshpj]\n" +
" │ │ └─ keys: s7byt.SSHPJ\n" +
" │ │ as id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [s7byt.SSHPJ, s7byt.SFJ6L]\n" +
" │ └─ Filter\n" +
" │ ├─ we72e.SSHPJ IS NULL\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: s7byt\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [s5kbm.SSHPJ as SSHPJ, s5kbm.SFJ6L as SFJ6L]\n" +
" │ │ └─ LookupJoin\n" +
" │ │ ├─ TableAlias(nd)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [fgg57]\n" +
" │ │ └─ TableAlias(s5kbm)\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.FGG57]\n" +
" │ │ ├─ columns: [fgg57 sshpj sfj6l]\n" +
" │ │ └─ keys: nd.FGG57\n" +
" │ └─ IndexedTableAccess(WE72E)\n" +
" │ ├─ index: [WE72E.SSHPJ]\n" +
" │ ├─ columns: [sshpj]\n" +
" │ └─ keys: s7byt.SSHPJ\n" +
" └─ Table\n" +
" └─ name: TDRVG\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [tdrvg.id, tdrvg.FGG57, tdrvg.SSHPJ, tdrvg.SFJ6L]\n" +
" └─ Filter\n" +
" ├─ InSubquery\n" +
" │ ├─ left: tdrvg.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tdrvg.id]\n" +
" │ │ └─ Sort(tdrvg.id ASC)\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (tdrvg.SSHPJ = s7byt.SSHPJ)\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.SSHPJ]\n" +
" │ │ ├─ columns: [id sshpj]\n" +
" │ │ └─ keys: s7byt.SSHPJ\n" +
" │ │ as id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [s7byt.SSHPJ, s7byt.SFJ6L, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tdrvg.id]\n" +
" │ │ └─ Sort(tdrvg.id ASC)\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (tdrvg.SSHPJ = s7byt.SSHPJ)\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.SSHPJ]\n" +
" │ │ ├─ columns: [id sshpj]\n" +
" │ │ └─ keys: s7byt.SSHPJ\n" +
" │ │ as id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [s7byt.SSHPJ, s7byt.SFJ6L]\n" +
" │ └─ Filter\n" +
" │ ├─ we72e.SSHPJ IS NULL\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: s7byt\n" +
" │ │ ├─ outerVisibility: true\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [s5kbm.SSHPJ as SSHPJ, s5kbm.SFJ6L as SFJ6L]\n" +
" │ │ └─ LookupJoin\n" +
" │ │ ├─ TableAlias(nd)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [fgg57]\n" +
" │ │ └─ TableAlias(s5kbm)\n" +
" │ │ └─ IndexedTableAccess(TDRVG)\n" +
" │ │ ├─ index: [TDRVG.FGG57]\n" +
" │ │ ├─ columns: [fgg57 sshpj sfj6l]\n" +
" │ │ └─ keys: nd.FGG57\n" +
" │ └─ IndexedTableAccess(WE72E)\n" +
" │ ├─ index: [WE72E.SSHPJ]\n" +
" │ ├─ columns: [sshpj]\n" +
" │ └─ keys: s7byt.SSHPJ\n" +
" └─ Table\n" +
" └─ name: TDRVG\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:4!null as id, pbmrx.TW55N:5!null as UYOGN, pbmrx.ZH72S:6 as H4JEA]\n" +
" └─ LookupJoin\n" +
" ├─ NOT\n" +
" │ └─ pbmrx.ZH72S:6 IS NULL\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cl3dt\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (40-43)\n" +
" │ ├─ tableId: 4\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ B4OVH:2!null\n" +
" │ │ │ └─ 0 (bigint)\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 (bigint)\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\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: tq57w\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (30-32)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id:0!null as id, nd.ZH72S:7 as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select COUNT(*) from AMYXQ where LUEVY = nd.id\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" +
" │ │ ├─ keys: [nd.id:0!null]\n" +
" │ │ ├─ colSet: (20-27)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: AMYXQ\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" +
" │ │ ├─ alias-string: select COUNT(*) from AMYXQ where LUEVY = nd.id\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" +
" │ │ ├─ keys: [nd.id:0!null]\n" +
" │ │ ├─ colSet: (20-27)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: AMYXQ\n" +
" │ │ └─ columns: [luevy]\n" +
" │ │ as TJ66D]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ ├─ static: [{(NULL, ∞)}]\n" +
" │ ├─ colSet: (1-17)\n" +
" │ ├─ tableId: 1\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(pbmrx)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ keys: [cl3dt.ZH72S:0]\n" +
" ├─ colSet: (44-60)\n" +
" ├─ tableId: 5\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n zh72s]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [pbmrx.id as id, pbmrx.TW55N as UYOGN, pbmrx.ZH72S as H4JEA]\n" +
" └─ LookupJoin (estimated cost=405.900 rows=124)\n" +
" ├─ (NOT(pbmrx.ZH72S IS NULL))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cl3dt\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Filter\n" +
" │ ├─ ((B4OVH = 0) AND (R5CKX > 0))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tq57w.ZH72S as ZH72S, count(tq57w.zh72s) as JTOA7, min(tq57w.tj66d) as B4OVH, sum(tq57w.tj66d) as R5CKX]\n" +
" │ └─ Having((JTOA7 > 1))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(tq57w.zh72s), min(tq57w.tj66d), sum(tq57w.tj66d), tq57w.ZH72S, tq57w.ZH72S as ZH72S, count(tq57w.zh72s) as JTOA7, min(tq57w.tj66d) as B4OVH, sum(tq57w.tj66d) as R5CKX]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(COUNT(tq57w.ZH72S), MIN(tq57w.TJ66D), SUM(tq57w.TJ66D), tq57w.ZH72S)\n" +
" │ ├─ Grouping(tq57w.ZH72S)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: tq57w\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (amyxq.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [luevy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as TJ66D]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (amyxq.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [luevy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as TJ66D]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ └─ filters: [{(NULL, ∞)}]\n" +
" └─ TableAlias(pbmrx)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ columns: [id tw55n zh72s]\n" +
" └─ keys: cl3dt.ZH72S\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [pbmrx.id as id, pbmrx.TW55N as UYOGN, pbmrx.ZH72S as H4JEA]\n" +
" └─ LookupJoin (estimated cost=405.900 rows=124) (actual rows=0 loops=1)\n" +
" ├─ (NOT(pbmrx.ZH72S IS NULL))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cl3dt\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Filter\n" +
" │ ├─ ((B4OVH = 0) AND (R5CKX > 0))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tq57w.ZH72S as ZH72S, count(tq57w.zh72s) as JTOA7, min(tq57w.tj66d) as B4OVH, sum(tq57w.tj66d) as R5CKX]\n" +
" │ └─ Having((JTOA7 > 1))\n" +
" │ └─ Project\n" +
" │ ├─ columns: [count(tq57w.zh72s), min(tq57w.tj66d), sum(tq57w.tj66d), tq57w.ZH72S, tq57w.ZH72S as ZH72S, count(tq57w.zh72s) as JTOA7, min(tq57w.tj66d) as B4OVH, sum(tq57w.tj66d) as R5CKX]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(COUNT(tq57w.ZH72S), MIN(tq57w.TJ66D), SUM(tq57w.TJ66D), tq57w.ZH72S)\n" +
" │ ├─ Grouping(tq57w.ZH72S)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: tq57w\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (amyxq.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [luevy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as TJ66D]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nd.id as id, nd.ZH72S as ZH72S, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [count(1) as COUNT(*)]\n" +
" │ │ └─ GroupBy\n" +
" │ │ ├─ SelectedExprs(COUNT(1))\n" +
" │ │ ├─ Grouping()\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (amyxq.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [luevy]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as TJ66D]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ └─ filters: [{(NULL, ∞)}]\n" +
" └─ TableAlias(pbmrx)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ columns: [id tw55n zh72s]\n" +
" └─ keys: cl3dt.ZH72S\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" +
" └─ 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: [SISUT.id:0!null, SISUT.T4IBQ:1, SISUT.ZH72S:2, SISUT.AMYXQ:3, SISUT.KTNZ2:4, SISUT.HIID2:5, SISUT.DN3OQ:6, SISUT.VVKNB:7, SISUT.SH7TP:8, SISUT.SRZZO:9, SISUT.QZ6VT:10]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ amyxq.KKGN5:11 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ ufc.id:0!null\n" +
" │ │ │ └─ amyxq.KKGN5:11\n" +
" │ │ ├─ TableAlias(ufc)\n" +
" │ │ │ └─ IndexedTableAccess(SISUT)\n" +
" │ │ │ ├─ index: [SISUT.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (1-11)\n" +
" │ │ │ ├─ tableId: 1\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SISUT\n" +
" │ │ │ └─ columns: [id t4ibq zh72s amyxq ktnz2 hiid2 dn3oq vvknb sh7tp srzzo qz6vt]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.KKGN5:7]\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.KKGN5]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (59-66)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: AMYXQ\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" +
" │ └─ ProcessTable\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" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ static: [{(NULL, ∞)}]\n" +
" ├─ colSet: (12-28)\n" +
" ├─ tableId: 2\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" +
"",
ExpectedEstimates: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ufc.id, ufc.T4IBQ, ufc.ZH72S, ufc.AMYXQ, ufc.KTNZ2, ufc.HIID2, ufc.DN3OQ, ufc.VVKNB, ufc.SH7TP, ufc.SRZZO, ufc.QZ6VT]\n" +
" └─ HashJoin (estimated cost=102847291.680 rows=9769906324)\n" +
" ├─ (nd.ZH72S = ufc.ZH72S)\n" +
" ├─ HashJoin (estimated cost=5195054.880 rows=5085844)\n" +
" │ ├─ (cla.FTQLQ = ufc.T4IBQ)\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [SISUT.id, SISUT.T4IBQ, SISUT.ZH72S, SISUT.AMYXQ, SISUT.KTNZ2, SISUT.HIID2, SISUT.DN3OQ, SISUT.VVKNB, SISUT.SH7TP, SISUT.SRZZO, SISUT.QZ6VT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ amyxq.KKGN5 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin (estimated cost=109840579.580 rows=5983347)\n" +
" │ │ ├─ cmp: (ufc.id = amyxq.KKGN5)\n" +
" │ │ ├─ TableAlias(ufc)\n" +
" │ │ │ └─ IndexedTableAccess(SISUT)\n" +
" │ │ │ ├─ index: [SISUT.id]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.KKGN5]\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.KKGN5]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (ufc.T4IBQ)\n" +
" │ ├─ right-key: (cla.FTQLQ)\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ Table\n" +
" │ └─ name: YK2GW\n" +
" └─ HashLookup\n" +
" ├─ left-key: (ufc.ZH72S)\n" +
" ├─ right-key: (nd.ZH72S)\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" └─ filters: [{(NULL, ∞)}]\n" +
"",
ExpectedAnalysis: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ufc.id, ufc.T4IBQ, ufc.ZH72S, ufc.AMYXQ, ufc.KTNZ2, ufc.HIID2, ufc.DN3OQ, ufc.VVKNB, ufc.SH7TP, ufc.SRZZO, ufc.QZ6VT]\n" +
" └─ HashJoin (estimated cost=102847291.680 rows=9769906324) (actual rows=0 loops=1)\n" +
" ├─ (nd.ZH72S = ufc.ZH72S)\n" +
" ├─ HashJoin (estimated cost=5195054.880 rows=5085844) (actual rows=0 loops=1)\n" +
" │ ├─ (cla.FTQLQ = ufc.T4IBQ)\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [SISUT.id, SISUT.T4IBQ, SISUT.ZH72S, SISUT.AMYXQ, SISUT.KTNZ2, SISUT.HIID2, SISUT.DN3OQ, SISUT.VVKNB, SISUT.SH7TP, SISUT.SRZZO, SISUT.QZ6VT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ amyxq.KKGN5 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin (estimated cost=109840579.580 rows=5983347) (actual rows=0 loops=1)\n" +
" │ │ ├─ cmp: (ufc.id = amyxq.KKGN5)\n" +
" │ │ ├─ TableAlias(ufc)\n" +
" │ │ │ └─ IndexedTableAccess(SISUT)\n" +
" │ │ │ ├─ index: [SISUT.id]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.KKGN5]\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.KKGN5]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (ufc.T4IBQ)\n" +
" │ ├─ right-key: (cla.FTQLQ)\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ Table\n" +
" │ └─ name: YK2GW\n" +
" └─ HashLookup\n" +
" ├─ left-key: (ufc.ZH72S)\n" +
" ├─ right-key: (nd.ZH72S)\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" └─ filters: [{(NULL, ∞)}]\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" +
" └─ 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: [SISUT.id:0!null, SISUT.T4IBQ:1, SISUT.ZH72S:2, SISUT.AMYXQ:3, SISUT.KTNZ2:4, SISUT.HIID2:5, SISUT.DN3OQ:6, SISUT.VVKNB:7, SISUT.SH7TP:8, SISUT.SRZZO:9, SISUT.QZ6VT:10]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ amyxq.KKGN5:11 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ ufc.id:0!null\n" +
" │ │ │ └─ amyxq.KKGN5:11\n" +
" │ │ ├─ TableAlias(ufc)\n" +
" │ │ │ └─ IndexedTableAccess(SISUT)\n" +
" │ │ │ ├─ index: [SISUT.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (1-11)\n" +
" │ │ │ ├─ tableId: 1\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SISUT\n" +
" │ │ │ └─ columns: [id t4ibq zh72s amyxq ktnz2 hiid2 dn3oq vvknb sh7tp srzzo qz6vt]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.KKGN5:7]\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.KKGN5]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (59-66)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: AMYXQ\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" +
" │ └─ ProcessTable\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" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ static: [{(NULL, ∞)}]\n" +
" ├─ colSet: (12-28)\n" +
" ├─ tableId: 2\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" +
"",
ExpectedEstimates: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ufc.id, ufc.T4IBQ, ufc.ZH72S, ufc.AMYXQ, ufc.KTNZ2, ufc.HIID2, ufc.DN3OQ, ufc.VVKNB, ufc.SH7TP, ufc.SRZZO, ufc.QZ6VT]\n" +
" └─ HashJoin (estimated cost=102847291.680 rows=9769906324)\n" +
" ├─ (nd.ZH72S = ufc.ZH72S)\n" +
" ├─ HashJoin (estimated cost=5195054.880 rows=5085844)\n" +
" │ ├─ (cla.FTQLQ = ufc.T4IBQ)\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [SISUT.id, SISUT.T4IBQ, SISUT.ZH72S, SISUT.AMYXQ, SISUT.KTNZ2, SISUT.HIID2, SISUT.DN3OQ, SISUT.VVKNB, SISUT.SH7TP, SISUT.SRZZO, SISUT.QZ6VT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ amyxq.KKGN5 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin (estimated cost=109840579.580 rows=5983347)\n" +
" │ │ ├─ cmp: (ufc.id = amyxq.KKGN5)\n" +
" │ │ ├─ TableAlias(ufc)\n" +
" │ │ │ └─ IndexedTableAccess(SISUT)\n" +
" │ │ │ ├─ index: [SISUT.id]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.KKGN5]\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.KKGN5]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (ufc.T4IBQ)\n" +
" │ ├─ right-key: (cla.FTQLQ)\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ Table\n" +
" │ └─ name: YK2GW\n" +
" └─ HashLookup\n" +
" ├─ left-key: (ufc.ZH72S)\n" +
" ├─ right-key: (nd.ZH72S)\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" └─ filters: [{(NULL, ∞)}]\n" +
"",
ExpectedAnalysis: "Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ufc.id, ufc.T4IBQ, ufc.ZH72S, ufc.AMYXQ, ufc.KTNZ2, ufc.HIID2, ufc.DN3OQ, ufc.VVKNB, ufc.SH7TP, ufc.SRZZO, ufc.QZ6VT]\n" +
" └─ HashJoin (estimated cost=102847291.680 rows=9769906324) (actual rows=0 loops=1)\n" +
" ├─ (nd.ZH72S = ufc.ZH72S)\n" +
" ├─ HashJoin (estimated cost=5195054.880 rows=5085844) (actual rows=0 loops=1)\n" +
" │ ├─ (cla.FTQLQ = ufc.T4IBQ)\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [SISUT.id, SISUT.T4IBQ, SISUT.ZH72S, SISUT.AMYXQ, SISUT.KTNZ2, SISUT.HIID2, SISUT.DN3OQ, SISUT.VVKNB, SISUT.SH7TP, SISUT.SRZZO, SISUT.QZ6VT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ amyxq.KKGN5 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin (estimated cost=109840579.580 rows=5983347) (actual rows=0 loops=1)\n" +
" │ │ ├─ cmp: (ufc.id = amyxq.KKGN5)\n" +
" │ │ ├─ TableAlias(ufc)\n" +
" │ │ │ └─ IndexedTableAccess(SISUT)\n" +
" │ │ │ ├─ index: [SISUT.id]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.KKGN5]\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.KKGN5]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (ufc.T4IBQ)\n" +
" │ ├─ right-key: (cla.FTQLQ)\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ Table\n" +
" │ └─ name: YK2GW\n" +
" └─ HashLookup\n" +
" ├─ left-key: (ufc.ZH72S)\n" +
" ├─ right-key: (nd.ZH72S)\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" └─ filters: [{(NULL, ∞)}]\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" +
" └─ Project\n" +
" ├─ columns: [FG26Y.id:0!null, FG26Y.T4IBQ:1, FG26Y.ner:2, FG26Y.ber:3, FG26Y.hr:4, FG26Y.mmr:5, FG26Y.QZ6VT:6, YK2GW.id:7!null, YK2GW.FTQLQ:8!null, YK2GW.TUXML:9, YK2GW.PAEF5:10, YK2GW.RUCY4:11, YK2GW.TPNJ6:12!null, YK2GW.LBL53:13, YK2GW.NB3QS:14, YK2GW.EO7IV:15, YK2GW.MUHJF:16, YK2GW.FM34L:17, YK2GW.TY5RF:18, YK2GW.ZHTLH:19, YK2GW.NPB7W:20, YK2GW.SX3HH:21, YK2GW.ISBNF:22, YK2GW.YA7YB:23, YK2GW.C5YKB:24, YK2GW.QK7KT:25, YK2GW.FFGE6:26, YK2GW.FIIGJ:27, YK2GW.SH3NC:28, YK2GW.NTENA:29, YK2GW.M4AUB:30, YK2GW.X5AIR:31, YK2GW.SAB6M:32, YK2GW.G5QI5:33, YK2GW.ZVQVD:34, YK2GW.YKSSU:35, YK2GW.FHCYT:36]\n" +
" └─ Filter\n" +
" ├─ szqwj.JOGI6:37 IS NULL\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ TableAlias(ums)\n" +
" │ │ └─ ProcessTable\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: FG26Y\n" +
" │ │ └─ columns: [id t4ibq ner ber hr mmr qz6vt]\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.FTQLQ]\n" +
" │ ├─ keys: [ums.T4IBQ:1]\n" +
" │ ├─ colSet: (8-37)\n" +
" │ ├─ tableId: 2\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" +
" └─ Project\n" +
" ├─ columns: [szqwj.JOGI6:4]\n" +
" └─ IndexedTableAccess(SZQWJ)\n" +
" ├─ index: [SZQWJ.JOGI6]\n" +
" ├─ keys: [ums.id:0!null]\n" +
" ├─ colSet: (38-42)\n" +
" ├─ tableId: 3\n" +
" └─ Table\n" +
" ├─ name: SZQWJ\n" +
" └─ columns: [id gxlub ch3fr d237e jogi6]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [ums.id, ums.T4IBQ, ums.ner, ums.ber, ums.hr, ums.mmr, ums.QZ6VT]\n" +
" └─ Project\n" +
" ├─ columns: [FG26Y.id, FG26Y.T4IBQ, FG26Y.ner, FG26Y.ber, FG26Y.hr, FG26Y.mmr, FG26Y.QZ6VT, YK2GW.id, YK2GW.FTQLQ, YK2GW.TUXML, YK2GW.PAEF5, YK2GW.RUCY4, YK2GW.TPNJ6, YK2GW.LBL53, YK2GW.NB3QS, YK2GW.EO7IV, YK2GW.MUHJF, YK2GW.FM34L, YK2GW.TY5RF, YK2GW.ZHTLH, YK2GW.NPB7W, YK2GW.SX3HH, YK2GW.ISBNF, YK2GW.YA7YB, YK2GW.C5YKB, YK2GW.QK7KT, YK2GW.FFGE6, YK2GW.FIIGJ, YK2GW.SH3NC, YK2GW.NTENA, YK2GW.M4AUB, YK2GW.X5AIR, YK2GW.SAB6M, YK2GW.G5QI5, YK2GW.ZVQVD, YK2GW.YKSSU, YK2GW.FHCYT]\n" +
" └─ Filter\n" +
" ├─ szqwj.JOGI6 IS NULL\n" +
" └─ LeftOuterLookupJoin (estimated cost=3899.000 rows=1251)\n" +
" ├─ LookupJoin (estimated cost=3303.300 rows=1001)\n" +
" │ ├─ TableAlias(ums)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: FG26Y\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.FTQLQ]\n" +
" │ └─ keys: ums.T4IBQ\n" +
" └─ Project\n" +
" ├─ columns: [szqwj.JOGI6]\n" +
" └─ IndexedTableAccess(SZQWJ)\n" +
" ├─ index: [SZQWJ.JOGI6]\n" +
" └─ keys: ums.id\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [ums.id, ums.T4IBQ, ums.ner, ums.ber, ums.hr, ums.mmr, ums.QZ6VT]\n" +
" └─ Project\n" +
" ├─ columns: [FG26Y.id, FG26Y.T4IBQ, FG26Y.ner, FG26Y.ber, FG26Y.hr, FG26Y.mmr, FG26Y.QZ6VT, YK2GW.id, YK2GW.FTQLQ, YK2GW.TUXML, YK2GW.PAEF5, YK2GW.RUCY4, YK2GW.TPNJ6, YK2GW.LBL53, YK2GW.NB3QS, YK2GW.EO7IV, YK2GW.MUHJF, YK2GW.FM34L, YK2GW.TY5RF, YK2GW.ZHTLH, YK2GW.NPB7W, YK2GW.SX3HH, YK2GW.ISBNF, YK2GW.YA7YB, YK2GW.C5YKB, YK2GW.QK7KT, YK2GW.FFGE6, YK2GW.FIIGJ, YK2GW.SH3NC, YK2GW.NTENA, YK2GW.M4AUB, YK2GW.X5AIR, YK2GW.SAB6M, YK2GW.G5QI5, YK2GW.ZVQVD, YK2GW.YKSSU, YK2GW.FHCYT]\n" +
" └─ Filter\n" +
" ├─ szqwj.JOGI6 IS NULL\n" +
" └─ LeftOuterLookupJoin (estimated cost=3899.000 rows=1251) (actual rows=0 loops=1)\n" +
" ├─ LookupJoin (estimated cost=3303.300 rows=1001) (actual rows=0 loops=1)\n" +
" │ ├─ TableAlias(ums)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: FG26Y\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.FTQLQ]\n" +
" │ └─ keys: ums.T4IBQ\n" +
" └─ Project\n" +
" ├─ columns: [szqwj.JOGI6]\n" +
" └─ IndexedTableAccess(SZQWJ)\n" +
" ├─ index: [SZQWJ.JOGI6]\n" +
" └─ keys: ums.id\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:0!null as id, cla.FTQLQ:42!null as T4IBQ, nd.TW55N:23!null as UWBAI, aac.BTXC5:18 as TPXBU, mf.FSDY2:10!null as FSDY2]\n" +
" └─ Filter\n" +
" ├─ Or\n" +
" │ ├─ AND\n" +
" │ │ ├─ NOT\n" +
" │ │ │ └─ mf.QQV4M:15 IS NULL\n" +
" │ │ └─ Or\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ ├─ alias-string: select TJ5D2.SWCQV from SZW6V as TJ5D2 where TJ5D2.id = mf.QQV4M\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [tj5d2.SWCQV:72!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ tj5d2.id:71!null\n" +
" │ │ │ │ │ └─ mf.QQV4M:15\n" +
" │ │ │ │ └─ TableAlias(tj5d2)\n" +
" │ │ │ │ └─ IndexedTableAccess(SZW6V)\n" +
" │ │ │ │ ├─ index: [SZW6V.id]\n" +
" │ │ │ │ ├─ keys: [mf.QQV4M:15]\n" +
" │ │ │ │ ├─ colSet: (72-79)\n" +
" │ │ │ │ ├─ tableId: 6\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: SZW6V\n" +
" │ │ │ │ └─ columns: [id swcqv]\n" +
" │ │ │ └─ 1 (tinyint)\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select nd.id from E2I7U as nd where nd.TW55N = (select TJ5D2.H4DMT from SZW6V as TJ5D2 where TJ5D2.id = mf.QQV4M)\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [nd.id:71!null]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ nd.TW55N:74!null\n" +
" │ │ │ │ └─ Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ ├─ alias-string: select TJ5D2.H4DMT from SZW6V as TJ5D2 where TJ5D2.id = mf.QQV4M\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [tj5d2.H4DMT:89!null]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ tj5d2.id:88!null\n" +
" │ │ │ │ │ └─ mf.QQV4M:15\n" +
" │ │ │ │ └─ TableAlias(tj5d2)\n" +
" │ │ │ │ └─ IndexedTableAccess(SZW6V)\n" +
" │ │ │ │ ├─ index: [SZW6V.id]\n" +
" │ │ │ │ ├─ keys: [mf.QQV4M:15]\n" +
" │ │ │ │ ├─ colSet: (97-104)\n" +
" │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: SZW6V\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" +
" │ │ │ ├─ colSet: (80-96)\n" +
" │ │ │ └─ tableId: 7\n" +
" │ │ └─ mf.LUEVY:2!null\n" +
" │ └─ AND\n" +
" │ ├─ NOT\n" +
" │ │ └─ mf.TEUJA:14 IS NULL\n" +
" │ └─ InSubquery\n" +
" │ ├─ left: mf.TEUJA:14\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ alias-string: select umf.id as ORB3K from SZW6V as TJ5D2 join NZKPM as 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)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [umf.id:79!null as ORB3K]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ umf.FGG57:81\n" +
" │ │ │ └─ tj5d2.V7UFH:73!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.SYPKF:87\n" +
" │ │ └─ tj5d2.SYPKF:74!null\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [SZW6V.id:71!null, SZW6V.T4IBQ:72!null, SZW6V.V7UFH:73!null, SZW6V.SYPKF:74!null, SZW6V.H4DMT:75!null, SZW6V.SWCQV:76!null, SZW6V.YKSSU:77, SZW6V.FHCYT:78]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ hgmq6.QQV4M:79 IS NULL\n" +
" │ │ └─ LeftOuterLookupJoin\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ tj5d2.SWCQV:76!null\n" +
" │ │ │ │ └─ 0 (int)\n" +
" │ │ │ └─ TableAlias(tj5d2)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SZW6V\n" +
" │ │ │ ├─ columns: [id t4ibq v7ufh sypkf h4dmt swcqv ykssu fhcyt]\n" +
" │ │ │ ├─ colSet: (105-112)\n" +
" │ │ │ └─ tableId: 9\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ NOT\n" +
" │ │ │ └─ hgmq6.QQV4M:71 IS NULL\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.QQV4M]\n" +
" │ │ ├─ keys: [tj5d2.id:71!null]\n" +
" │ │ ├─ colSet: (138-154)\n" +
" │ │ ├─ tableId: 11\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HGMQ6\n" +
" │ │ └─ columns: [qqv4m]\n" +
" │ └─ TableAlias(umf)\n" +
" │ └─ IndexedTableAccess(NZKPM)\n" +
" │ ├─ index: [NZKPM.T4IBQ]\n" +
" │ ├─ keys: [tj5d2.T4IBQ:72!null]\n" +
" │ ├─ colSet: (113-137)\n" +
" │ ├─ tableId: 10\n" +
" │ └─ Table\n" +
" │ ├─ name: NZKPM\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" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ bs.id:37!null\n" +
" │ └─ mf.GXLUB:1!null\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ nd.id:20!null\n" +
" │ │ └─ mf.LUEVY:2!null\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ mf.M22QN:3!null\n" +
" │ │ │ └─ aac.id:17!null\n" +
" │ │ ├─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (1-17)\n" +
" │ │ │ ├─ tableId: 1\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" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (69-71)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.LUEVY:2!null)\n" +
" │ ├─ right-key: TUPLE(nd.id:0!null)\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ ProcessTable\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(mf.GXLUB:1!null)\n" +
" ├─ right-key: TUPLE(bs.id:0!null)\n" +
" └─ MergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ bs.IXUXU:39\n" +
" │ └─ cla.id:41!null\n" +
" ├─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (18-21)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: THNTS\n" +
" │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" └─ TableAlias(cla)\n" +
" └─ IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (22-51)\n" +
" ├─ tableId: 3\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" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [mf.id as id, cla.FTQLQ as T4IBQ, nd.TW55N as UWBAI, aac.BTXC5 as TPXBU, mf.FSDY2 as FSDY2]\n" +
" └─ Filter\n" +
" ├─ (((NOT(mf.QQV4M IS NULL)) AND ((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tj5d2.SWCQV]\n" +
" │ └─ Filter\n" +
" │ ├─ (tj5d2.id = mf.QQV4M)\n" +
" │ └─ TableAlias(tj5d2)\n" +
" │ └─ IndexedTableAccess(SZW6V)\n" +
" │ ├─ index: [SZW6V.id]\n" +
" │ ├─ columns: [id swcqv]\n" +
" │ └─ keys: mf.QQV4M\n" +
" │ = 1) OR (NOT((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (nd.TW55N = Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tj5d2.H4DMT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (tj5d2.id = mf.QQV4M)\n" +
" │ │ └─ TableAlias(tj5d2)\n" +
" │ │ └─ IndexedTableAccess(SZW6V)\n" +
" │ │ ├─ index: [SZW6V.id]\n" +
" │ │ ├─ columns: [id h4dmt]\n" +
" │ │ └─ keys: mf.QQV4M\n" +
" │ │ )\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ └─ name: E2I7U\n" +
" │ = mf.LUEVY))))) OR ((NOT(mf.TEUJA IS NULL)) AND InSubquery\n" +
" │ ├─ left: mf.TEUJA\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [umf.id as ORB3K]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ ((umf.FGG57 = tj5d2.V7UFH) AND (umf.SYPKF = tj5d2.SYPKF))\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [SZW6V.id, SZW6V.T4IBQ, SZW6V.V7UFH, SZW6V.SYPKF, SZW6V.H4DMT, SZW6V.SWCQV, SZW6V.YKSSU, SZW6V.FHCYT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ hgmq6.QQV4M IS NULL\n" +
" │ │ └─ LeftOuterLookupJoin\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (tj5d2.SWCQV = 0)\n" +
" │ │ │ └─ TableAlias(tj5d2)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ └─ name: SZW6V\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (NOT(hgmq6.QQV4M IS NULL))\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.QQV4M]\n" +
" │ │ ├─ columns: [qqv4m]\n" +
" │ │ └─ keys: tj5d2.id\n" +
" │ └─ TableAlias(umf)\n" +
" │ └─ IndexedTableAccess(NZKPM)\n" +
" │ ├─ index: [NZKPM.T4IBQ]\n" +
" │ └─ keys: tj5d2.T4IBQ\n" +
" │ ))\n" +
" └─ HashJoin (estimated cost=529702.380 rows=511969)\n" +
" ├─ (bs.id = mf.GXLUB)\n" +
" ├─ HashJoin (estimated cost=533734.380 rows=511969)\n" +
" │ ├─ (nd.id = mf.LUEVY)\n" +
" │ ├─ MergeJoin (estimated cost=647314.050 rows=511969)\n" +
" │ │ ├─ cmp: (mf.M22QN = aac.id)\n" +
" │ │ ├─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (mf.LUEVY)\n" +
" │ ├─ right-key: (nd.id)\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ └─ name: E2I7U\n" +
" └─ HashLookup\n" +
" ├─ left-key: (mf.GXLUB)\n" +
" ├─ right-key: (bs.id)\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (bs.IXUXU = cla.id)\n" +
" ├─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ └─ filters: [{[NULL, ∞)}]\n" +
" └─ TableAlias(cla)\n" +
" └─ IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.id]\n" +
" └─ filters: [{[NULL, ∞)}]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [mf.id as id, cla.FTQLQ as T4IBQ, nd.TW55N as UWBAI, aac.BTXC5 as TPXBU, mf.FSDY2 as FSDY2]\n" +
" └─ Filter\n" +
" ├─ (((NOT(mf.QQV4M IS NULL)) AND ((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tj5d2.SWCQV]\n" +
" │ └─ Filter\n" +
" │ ├─ (tj5d2.id = mf.QQV4M)\n" +
" │ └─ TableAlias(tj5d2)\n" +
" │ └─ IndexedTableAccess(SZW6V)\n" +
" │ ├─ index: [SZW6V.id]\n" +
" │ ├─ columns: [id swcqv]\n" +
" │ └─ keys: mf.QQV4M\n" +
" │ = 1) OR (NOT((Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (nd.TW55N = Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tj5d2.H4DMT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (tj5d2.id = mf.QQV4M)\n" +
" │ │ └─ TableAlias(tj5d2)\n" +
" │ │ └─ IndexedTableAccess(SZW6V)\n" +
" │ │ ├─ index: [SZW6V.id]\n" +
" │ │ ├─ columns: [id h4dmt]\n" +
" │ │ └─ keys: mf.QQV4M\n" +
" │ │ )\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ └─ name: E2I7U\n" +
" │ = mf.LUEVY))))) OR ((NOT(mf.TEUJA IS NULL)) AND InSubquery\n" +
" │ ├─ left: mf.TEUJA\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [umf.id as ORB3K]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ ((umf.FGG57 = tj5d2.V7UFH) AND (umf.SYPKF = tj5d2.SYPKF))\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [SZW6V.id, SZW6V.T4IBQ, SZW6V.V7UFH, SZW6V.SYPKF, SZW6V.H4DMT, SZW6V.SWCQV, SZW6V.YKSSU, SZW6V.FHCYT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ hgmq6.QQV4M IS NULL\n" +
" │ │ └─ LeftOuterLookupJoin\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (tj5d2.SWCQV = 0)\n" +
" │ │ │ └─ TableAlias(tj5d2)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ └─ name: SZW6V\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (NOT(hgmq6.QQV4M IS NULL))\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.QQV4M]\n" +
" │ │ ├─ columns: [qqv4m]\n" +
" │ │ └─ keys: tj5d2.id\n" +
" │ └─ TableAlias(umf)\n" +
" │ └─ IndexedTableAccess(NZKPM)\n" +
" │ ├─ index: [NZKPM.T4IBQ]\n" +
" │ └─ keys: tj5d2.T4IBQ\n" +
" │ ))\n" +
" └─ HashJoin (estimated cost=529702.380 rows=511969) (actual rows=0 loops=1)\n" +
" ├─ (bs.id = mf.GXLUB)\n" +
" ├─ HashJoin (estimated cost=533734.380 rows=511969) (actual rows=0 loops=1)\n" +
" │ ├─ (nd.id = mf.LUEVY)\n" +
" │ ├─ MergeJoin (estimated cost=647314.050 rows=511969) (actual rows=0 loops=1)\n" +
" │ │ ├─ cmp: (mf.M22QN = aac.id)\n" +
" │ │ ├─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (mf.LUEVY)\n" +
" │ ├─ right-key: (nd.id)\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Table\n" +
" │ └─ name: E2I7U\n" +
" └─ HashLookup\n" +
" ├─ left-key: (mf.GXLUB)\n" +
" ├─ right-key: (bs.id)\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (bs.IXUXU = cla.id)\n" +
" ├─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ └─ filters: [{[NULL, ∞)}]\n" +
" └─ TableAlias(cla)\n" +
" └─ IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.id]\n" +
" └─ filters: [{[NULL, ∞)}]\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" +
" └─ 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: [NZKPM.id:0!null, NZKPM.T4IBQ:1, NZKPM.FGG57:2, NZKPM.SSHPJ:3, NZKPM.NLA6O:4, NZKPM.SFJ6L:5, NZKPM.TJPT7:6, NZKPM.ARN5P:7, NZKPM.SYPKF:8, NZKPM.IVFMK:9, NZKPM.IDE43:10, NZKPM.AZ6SP:11, NZKPM.FSDY2:12, NZKPM.XOSD4:13, NZKPM.HMW4H:14, NZKPM.S76OM:15, NZKPM.vaf:16, NZKPM.ZROH6:17, NZKPM.QCGTS:18, NZKPM.LNFM6:19, NZKPM.TVAWL:20, NZKPM.HDLCL:21, NZKPM.BHHW6:22, NZKPM.FHCYT:23, NZKPM.QZ6VT:24]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ hgmq6.TEUJA:25 IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ umf.id:0!null\n" +
" │ │ │ └─ hgmq6.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" +
" │ │ │ ├─ colSet: (1-25)\n" +
" │ │ │ ├─ tableId: 1\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NZKPM\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: [hgmq6.TEUJA:14]\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.TEUJA]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (73-89)\n" +
" │ │ ├─ tableId: 4\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(umf.T4IBQ:1)\n" +
" │ ├─ right-key: TUPLE(cla.FTQLQ:1!null)\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ ProcessTable\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" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.FGG57]\n" +
" ├─ static: [{(NULL, ∞)}]\n" +
" ├─ colSet: (26-42)\n" +
" ├─ tableId: 2\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" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [umf.id, umf.T4IBQ, umf.FGG57, umf.SSHPJ, umf.NLA6O, umf.SFJ6L, umf.TJPT7, umf.ARN5P, umf.SYPKF, umf.IVFMK, umf.IDE43, umf.AZ6SP, umf.FSDY2, umf.XOSD4, umf.HMW4H, umf.S76OM, umf.vaf, umf.ZROH6, umf.QCGTS, umf.LNFM6, umf.TVAWL, umf.HDLCL, umf.BHHW6, umf.FHCYT, umf.QZ6VT]\n" +
" └─ HashJoin (estimated cost=566371.320 rows=543966)\n" +
" ├─ (nd.FGG57 = umf.FGG57)\n" +
" ├─ HashJoin (estimated cost=562339.320 rows=543966)\n" +
" │ ├─ (cla.FTQLQ = umf.T4IBQ)\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [NZKPM.id, NZKPM.T4IBQ, NZKPM.FGG57, NZKPM.SSHPJ, NZKPM.NLA6O, NZKPM.SFJ6L, NZKPM.TJPT7, NZKPM.ARN5P, NZKPM.SYPKF, NZKPM.IVFMK, NZKPM.IDE43, NZKPM.AZ6SP, NZKPM.FSDY2, NZKPM.XOSD4, NZKPM.HMW4H, NZKPM.S76OM, NZKPM.vaf, NZKPM.ZROH6, NZKPM.QCGTS, NZKPM.LNFM6, NZKPM.TVAWL, NZKPM.HDLCL, NZKPM.BHHW6, NZKPM.FHCYT, NZKPM.QZ6VT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ hgmq6.TEUJA IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin (estimated cost=16645873.910 rows=639961)\n" +
" │ │ ├─ cmp: (umf.id = hgmq6.TEUJA)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (NOT((umf.ARN5P = 'N/A')))\n" +
" │ │ │ └─ TableAlias(umf)\n" +
" │ │ │ └─ IndexedTableAccess(NZKPM)\n" +
" │ │ │ ├─ index: [NZKPM.id]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [hgmq6.TEUJA]\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.TEUJA]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (umf.T4IBQ)\n" +
" │ ├─ right-key: (cla.FTQLQ)\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ Table\n" +
" │ └─ name: YK2GW\n" +
" └─ HashLookup\n" +
" ├─ left-key: (umf.FGG57)\n" +
" ├─ right-key: (nd.FGG57)\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.FGG57]\n" +
" └─ filters: [{(NULL, ∞)}]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [umf.id, umf.T4IBQ, umf.FGG57, umf.SSHPJ, umf.NLA6O, umf.SFJ6L, umf.TJPT7, umf.ARN5P, umf.SYPKF, umf.IVFMK, umf.IDE43, umf.AZ6SP, umf.FSDY2, umf.XOSD4, umf.HMW4H, umf.S76OM, umf.vaf, umf.ZROH6, umf.QCGTS, umf.LNFM6, umf.TVAWL, umf.HDLCL, umf.BHHW6, umf.FHCYT, umf.QZ6VT]\n" +
" └─ HashJoin (estimated cost=566371.320 rows=543966) (actual rows=0 loops=1)\n" +
" ├─ (nd.FGG57 = umf.FGG57)\n" +
" ├─ HashJoin (estimated cost=562339.320 rows=543966) (actual rows=0 loops=1)\n" +
" │ ├─ (cla.FTQLQ = umf.T4IBQ)\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [NZKPM.id, NZKPM.T4IBQ, NZKPM.FGG57, NZKPM.SSHPJ, NZKPM.NLA6O, NZKPM.SFJ6L, NZKPM.TJPT7, NZKPM.ARN5P, NZKPM.SYPKF, NZKPM.IVFMK, NZKPM.IDE43, NZKPM.AZ6SP, NZKPM.FSDY2, NZKPM.XOSD4, NZKPM.HMW4H, NZKPM.S76OM, NZKPM.vaf, NZKPM.ZROH6, NZKPM.QCGTS, NZKPM.LNFM6, NZKPM.TVAWL, NZKPM.HDLCL, NZKPM.BHHW6, NZKPM.FHCYT, NZKPM.QZ6VT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ hgmq6.TEUJA IS NULL\n" +
" │ │ └─ LeftOuterMergeJoin (estimated cost=16645873.910 rows=639961) (actual rows=0 loops=1)\n" +
" │ │ ├─ cmp: (umf.id = hgmq6.TEUJA)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (NOT((umf.ARN5P = 'N/A')))\n" +
" │ │ │ └─ TableAlias(umf)\n" +
" │ │ │ └─ IndexedTableAccess(NZKPM)\n" +
" │ │ │ ├─ index: [NZKPM.id]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [hgmq6.TEUJA]\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.TEUJA]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (umf.T4IBQ)\n" +
" │ ├─ right-key: (cla.FTQLQ)\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ Table\n" +
" │ └─ name: YK2GW\n" +
" └─ HashLookup\n" +
" ├─ left-key: (umf.FGG57)\n" +
" ├─ right-key: (nd.FGG57)\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.FGG57]\n" +
" └─ filters: [{(NULL, ∞)}]\n" +
"",
},
{
Query: `SELECT
HVHRZ
FROM
QYWQD
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [qywqd.HVHRZ:1!null]\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (1-6)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: QYWQD\n" +
" └─ columns: [id hvhrz]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [qywqd.HVHRZ]\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id hvhrz]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [qywqd.HVHRZ]\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id hvhrz]\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" +
" │ │ ├─ alias-string: select aac.BTXC5 from TPXBU as aac where aac.id = SL3S5.M22QN\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" +
" │ │ ├─ keys: [sl3s5.M22QN:63!null]\n" +
" │ │ ├─ colSet: (134-136)\n" +
" │ │ ├─ tableId: 12\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\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:37!null, cla.FTQLQ:38!null, cla.TUXML:39, cla.PAEF5:40, cla.RUCY4:41, cla.TPNJ6:42!null, cla.LBL53:43, cla.NB3QS:44, cla.EO7IV:45, cla.MUHJF:46, cla.FM34L:47, cla.TY5RF:48, cla.ZHTLH:49, cla.NPB7W:50, cla.SX3HH:51, cla.ISBNF:52, cla.YA7YB:53, cla.C5YKB:54, cla.QK7KT:55, cla.FFGE6:56, cla.FIIGJ:57, cla.SH3NC:58, cla.NTENA:59, cla.M4AUB:60, cla.X5AIR:61, cla.SAB6M:62, cla.G5QI5:63, cla.ZVQVD:64, cla.YKSSU:65, cla.FHCYT:66, bs.id:33!null, bs.NFRYN:34!null, bs.IXUXU:35, bs.FHCYT:36, mf.id:16!null, mf.GXLUB:17!null, mf.LUEVY:18!null, mf.M22QN:19!null, mf.TJPT7:20!null, mf.ARN5P:21!null, mf.XOSD4:22!null, mf.IDE43:23, mf.HMW4H:24, mf.ZBT6R:25, mf.FSDY2:26!null, mf.LT7K6:27, mf.SPPYD:28, mf.QCGTS:29, mf.TEUJA:30, mf.QQV4M:31, mf.FHCYT:32, 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, cla.FTQLQ:38!null as T4IBQ, sl3s5.TOFPN:1!null as DL754, sn.id:6!null as BDNYB, sl3s5.ADURZ:3!null as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select aac.BTXC5 from TPXBU as aac where aac.id = SL3S5.M22QN\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5:68]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.id:67!null\n" +
" │ │ │ └─ sl3s5.M22QN:2!null\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ keys: [sl3s5.M22QN:2!null]\n" +
" │ │ ├─ colSet: (134-136)\n" +
" │ │ ├─ tableId: 12\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as TPXBU, sl3s5.NO52D:4!null as NO52D, sl3s5.IDPK7:5!null as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ sn.BRQP2:7!null\n" +
" │ │ │ │ └─ mf.LUEVY:18!null\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ │ ├─ name: sl3s5\n" +
" │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ ├─ colSet: (124-129)\n" +
" │ │ │ │ │ ├─ tableId: 11\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" +
" │ │ │ │ │ └─ HashJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ ci.id:0!null\n" +
" │ │ │ │ │ │ └─ ct.FZ2R5:2!null\n" +
" │ │ │ │ │ ├─ TableAlias(ci)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ │ │ │ ├─ static: [{[SQ1, SQ1]}]\n" +
" │ │ │ │ │ │ ├─ colSet: (107-111)\n" +
" │ │ │ │ │ │ ├─ tableId: 9\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: JDLNA\n" +
" │ │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: TUPLE(ci.id:0!null)\n" +
" │ │ │ │ │ ├─ right-key: TUPLE(ct.FZ2R5:0!null)\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" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ ├─ ct.OVE3E:5!null\n" +
" │ │ │ │ │ │ │ └─ cec.id:8!null\n" +
" │ │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ ct.ZRV3B:5!null\n" +
" │ │ │ │ │ │ │ │ └─ = (longtext)\n" +
" │ │ │ │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ │ │ │ ├─ index: [FLQLP.OVE3E]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (95-106)\n" +
" │ │ │ │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: FLQLP\n" +
" │ │ │ │ │ │ │ └─ columns: [fz2r5 luevy m22qn ove3e s3q3y zrv3b]\n" +
" │ │ │ │ │ │ └─ TableAlias(cec)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ │ │ │ │ ├─ index: [SFEGG.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ ├─ colSet: (112-117)\n" +
" │ │ │ │ │ │ ├─ tableId: 10\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" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ ├─ colSet: (92-94)\n" +
" │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ └─ Distinct\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [mf.M22QN:3!null as M22QN, sn.id:0!null as BDNYB, mf.LUEVY:2!null as LUEVY]\n" +
" │ │ │ │ │ └─ LookupJoin\n" +
" │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ │ │ │ ├─ colSet: (79-88)\n" +
" │ │ │ │ │ │ └─ tableId: 6\n" +
" │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ │ ├─ keys: [sn.BRQP2:1!null]\n" +
" │ │ │ │ │ ├─ colSet: (62-78)\n" +
" │ │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ │ │ └─ columns: [luevy m22qn]\n" +
" │ │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ │ ├─ keys: [sl3s5.BDNYB:0!null]\n" +
" │ │ │ │ ├─ colSet: (52-61)\n" +
" │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ ├─ keys: [sl3s5.M22QN:2!null]\n" +
" │ │ │ ├─ colSet: (35-51)\n" +
" │ │ │ ├─ tableId: 3\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" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ ├─ keys: [mf.GXLUB:17!null]\n" +
" │ │ ├─ colSet: (31-34)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: THNTS\n" +
" │ │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ keys: [bs.IXUXU:35]\n" +
" │ ├─ colSet: (1-30)\n" +
" │ ├─ tableId: 1\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" +
" └─ 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" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq:6!null, vumuy.DL754:0!null, vumuy.BDNYB:1!null, vumuy.ADURZ:2!null, vumuy.TPXBU:3, vumuy.NO52D:4!null, vumuy.IDPK7:5!null]\n" +
" └─ CrossHashJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: vumuy\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (207-212)\n" +
" │ ├─ tableId: 21\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" +
" │ │ ├─ alias-string: select aac.BTXC5 from TPXBU as aac where aac.id = SL3S5.M22QN\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" +
" │ │ ├─ keys: [sl3s5.M22QN:12!null]\n" +
" │ │ ├─ colSet: (201-203)\n" +
" │ │ ├─ tableId: 20\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\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" +
" │ │ ├─ alias-string: select aac.BTXC5 from TPXBU as aac where aac.id = SL3S5.M22QN\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" +
" │ │ ├─ keys: [sl3s5.M22QN:2!null]\n" +
" │ │ ├─ colSet: (201-203)\n" +
" │ │ ├─ tableId: 20\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as TPXBU, sl3s5.NO52D:4!null as NO52D, sl3s5.IDPK7:5!null as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: sl3s5\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (192-197)\n" +
" │ │ ├─ tableId: 19\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sn.id:0!null as BDNYB, ci.FTQLQ:23!null as TOFPN, ct.M22QN:13!null as M22QN, cec.ADURZ:26!null as ADURZ, cec.NO52D:25!null as NO52D, ct.S3Q3Y:19!null as IDPK7]\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cec.id:24!null\n" +
" │ │ │ └─ ct.OVE3E:14!null\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ci.id:22!null\n" +
" │ │ │ │ └─ ct.FZ2R5:11!null\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ │ │ │ └─ ct.LUEVY:12!null\n" +
" │ │ │ │ ├─ sel: Eq\n" +
" │ │ │ │ │ ├─ ct.M22QN:13!null\n" +
" │ │ │ │ │ └─ Subquery\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ ├─ alias-string: select aac.id from TPXBU as aac where BTXC5 = 'WT'\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [aac.id:22!null]\n" +
" │ │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ │ ├─ static: [{[WT, WT]}]\n" +
" │ │ │ │ │ ├─ colSet: (172-174)\n" +
" │ │ │ │ │ ├─ tableId: 16\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: TPXBU\n" +
" │ │ │ │ │ └─ columns: [id btxc5]\n" +
" │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ ├─ colSet: (150-159)\n" +
" │ │ │ │ │ ├─ tableId: 14\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ ct.ZRV3B:10!null\n" +
" │ │ │ │ │ └─ = (longtext)\n" +
" │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (160-171)\n" +
" │ │ │ │ ├─ tableId: 15\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(ct.FZ2R5:11!null)\n" +
" │ │ │ ├─ right-key: TUPLE(ci.id:0!null)\n" +
" │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ ├─ static: [{[SQ1, SQ1]}]\n" +
" │ │ │ ├─ colSet: (175-179)\n" +
" │ │ │ ├─ tableId: 17\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: JDLNA\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(ct.OVE3E:14!null)\n" +
" │ │ ├─ right-key: TUPLE(cec.id:0!null)\n" +
" │ │ └─ TableAlias(cec)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ ├─ columns: [id no52d adurz]\n" +
" │ │ ├─ colSet: (180-185)\n" +
" │ │ └─ tableId: 18\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.id]\n" +
" │ ├─ keys: [sl3s5.BDNYB:0!null]\n" +
" │ ├─ colSet: (140-149)\n" +
" │ ├─ tableId: 13\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE()\n" +
" ├─ right-key: TUPLE()\n" +
" └─ SubqueryAlias\n" +
" ├─ name: aoev5\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (214)\n" +
" ├─ tableId: 23\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" +
"",
ExpectedEstimates: "Union all\n" +
" ├─ Project\n" +
" │ ├─ columns: [convert(T4IBQ, char) as T4IBQ, DL754, BDNYB, ADURZ, TPXBU, NO52D, IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.id, cla.FTQLQ, cla.TUXML, cla.PAEF5, cla.RUCY4, cla.TPNJ6, cla.LBL53, cla.NB3QS, cla.EO7IV, cla.MUHJF, cla.FM34L, cla.TY5RF, cla.ZHTLH, cla.NPB7W, cla.SX3HH, cla.ISBNF, cla.YA7YB, cla.C5YKB, cla.QK7KT, cla.FFGE6, cla.FIIGJ, cla.SH3NC, cla.NTENA, cla.M4AUB, cla.X5AIR, cla.SAB6M, cla.G5QI5, cla.ZVQVD, cla.YKSSU, cla.FHCYT, bs.id, bs.NFRYN, bs.IXUXU, bs.FHCYT, mf.id, mf.GXLUB, mf.LUEVY, mf.M22QN, mf.TJPT7, mf.ARN5P, mf.XOSD4, mf.IDE43, mf.HMW4H, mf.ZBT6R, mf.FSDY2, mf.LT7K6, mf.SPPYD, mf.QCGTS, mf.TEUJA, mf.QQV4M, mf.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, sl3s5.BDNYB, sl3s5.TOFPN, sl3s5.M22QN, sl3s5.ADURZ, sl3s5.NO52D, sl3s5.IDPK7, cla.FTQLQ as T4IBQ, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ (sn.BRQP2 = mf.LUEVY)\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ │ ├─ name: sl3s5\n" +
" │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [khjjo.BDNYB as BDNYB, ci.FTQLQ as TOFPN, ct.M22QN as M22QN, cec.ADURZ as ADURZ, cec.NO52D as NO52D, ct.S3Q3Y as IDPK7]\n" +
" │ │ │ │ │ └─ HashJoin\n" +
" │ │ │ │ │ ├─ (ci.id = ct.FZ2R5)\n" +
" │ │ │ │ │ ├─ TableAlias(ci)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ │ │ │ ├─ filters: [{[SQ1, SQ1]}]\n" +
" │ │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (ci.id)\n" +
" │ │ │ │ │ ├─ right-key: (ct.FZ2R5)\n" +
" │ │ │ │ │ └─ HashJoin\n" +
" │ │ │ │ │ ├─ ((ct.M22QN = khjjo.M22QN) AND (ct.LUEVY = khjjo.LUEVY))\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: (ct.OVE3E = cec.id)\n" +
" │ │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ │ ├─ (ct.ZRV3B = '=')\n" +
" │ │ │ │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ │ │ │ ├─ index: [FLQLP.OVE3E]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [fz2r5 luevy m22qn ove3e s3q3y zrv3b]\n" +
" │ │ │ │ │ │ └─ TableAlias(cec)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ │ │ │ │ ├─ index: [SFEGG.id]\n" +
" │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id no52d adurz]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (ct.M22QN, ct.LUEVY)\n" +
" │ │ │ │ │ ├─ right-key: (khjjo.M22QN, khjjo.LUEVY)\n" +
" │ │ │ │ │ └─ SubqueryAlias\n" +
" │ │ │ │ │ ├─ name: khjjo\n" +
" │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Distinct\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [mf.M22QN as M22QN, sn.id as BDNYB, mf.LUEVY as LUEVY]\n" +
" │ │ │ │ │ └─ LookupJoin\n" +
" │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ │ ├─ columns: [luevy m22qn]\n" +
" │ │ │ │ │ └─ keys: sn.BRQP2\n" +
" │ │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ │ └─ keys: sl3s5.BDNYB\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ └─ keys: mf.GXLUB\n" +
" │ └─ Filter\n" +
" │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ └─ keys: bs.IXUXU\n" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq as t4ibq, vumuy.DL754, vumuy.BDNYB, vumuy.ADURZ, vumuy.TPXBU, vumuy.NO52D, vumuy.IDPK7]\n" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq, vumuy.DL754, vumuy.BDNYB, vumuy.ADURZ, vumuy.TPXBU, vumuy.NO52D, vumuy.IDPK7]\n" +
" └─ CrossHashJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: vumuy\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, sl3s5.BDNYB, sl3s5.TOFPN, sl3s5.M22QN, sl3s5.ADURZ, sl3s5.NO52D, sl3s5.IDPK7, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: sl3s5\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sn.id as BDNYB, ci.FTQLQ as TOFPN, ct.M22QN as M22QN, cec.ADURZ as ADURZ, cec.NO52D as NO52D, ct.S3Q3Y as IDPK7]\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ (cec.id = ct.OVE3E)\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ (ci.id = ct.FZ2R5)\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (sn.BRQP2 = ct.LUEVY)\n" +
" │ │ │ │ ├─ sel: (ct.M22QN = Subquery\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [aac.id]\n" +
" │ │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ │ ├─ filters: [{[WT, WT]}]\n" +
" │ │ │ │ │ └─ columns: [id btxc5]\n" +
" │ │ │ │ │ )\n" +
" │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (ct.ZRV3B = '=')\n" +
" │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (ct.FZ2R5)\n" +
" │ │ │ ├─ right-key: (ci.id)\n" +
" │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ ├─ filters: [{[SQ1, SQ1]}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: (ct.OVE3E)\n" +
" │ │ ├─ right-key: (cec.id)\n" +
" │ │ └─ TableAlias(cec)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ └─ columns: [id no52d adurz]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.id]\n" +
" │ └─ keys: sl3s5.BDNYB\n" +
" └─ HashLookup\n" +
" ├─ left-key: ()\n" +
" ├─ right-key: ()\n" +
" └─ SubqueryAlias\n" +
" ├─ name: aoev5\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [temp_aoev5.t4ibq]\n" +
" └─ Values() as temp_AOEV5\n" +
" ├─ Row(\n" +
" │ '1')\n" +
" ├─ Row(\n" +
" │ '2')\n" +
" ├─ Row(\n" +
" │ '3')\n" +
" ├─ Row(\n" +
" │ '4')\n" +
" └─ Row(\n" +
" '5')\n" +
"",
ExpectedAnalysis: "Union all\n" +
" ├─ Project\n" +
" │ ├─ columns: [convert(T4IBQ, char) as T4IBQ, DL754, BDNYB, ADURZ, TPXBU, NO52D, IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.id, cla.FTQLQ, cla.TUXML, cla.PAEF5, cla.RUCY4, cla.TPNJ6, cla.LBL53, cla.NB3QS, cla.EO7IV, cla.MUHJF, cla.FM34L, cla.TY5RF, cla.ZHTLH, cla.NPB7W, cla.SX3HH, cla.ISBNF, cla.YA7YB, cla.C5YKB, cla.QK7KT, cla.FFGE6, cla.FIIGJ, cla.SH3NC, cla.NTENA, cla.M4AUB, cla.X5AIR, cla.SAB6M, cla.G5QI5, cla.ZVQVD, cla.YKSSU, cla.FHCYT, bs.id, bs.NFRYN, bs.IXUXU, bs.FHCYT, mf.id, mf.GXLUB, mf.LUEVY, mf.M22QN, mf.TJPT7, mf.ARN5P, mf.XOSD4, mf.IDE43, mf.HMW4H, mf.ZBT6R, mf.FSDY2, mf.LT7K6, mf.SPPYD, mf.QCGTS, mf.TEUJA, mf.QQV4M, mf.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, sl3s5.BDNYB, sl3s5.TOFPN, sl3s5.M22QN, sl3s5.ADURZ, sl3s5.NO52D, sl3s5.IDPK7, cla.FTQLQ as T4IBQ, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ (sn.BRQP2 = mf.LUEVY)\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ │ ├─ name: sl3s5\n" +
" │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [khjjo.BDNYB as BDNYB, ci.FTQLQ as TOFPN, ct.M22QN as M22QN, cec.ADURZ as ADURZ, cec.NO52D as NO52D, ct.S3Q3Y as IDPK7]\n" +
" │ │ │ │ │ └─ HashJoin\n" +
" │ │ │ │ │ ├─ (ci.id = ct.FZ2R5)\n" +
" │ │ │ │ │ ├─ TableAlias(ci)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ │ │ │ ├─ filters: [{[SQ1, SQ1]}]\n" +
" │ │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (ci.id)\n" +
" │ │ │ │ │ ├─ right-key: (ct.FZ2R5)\n" +
" │ │ │ │ │ └─ HashJoin\n" +
" │ │ │ │ │ ├─ ((ct.M22QN = khjjo.M22QN) AND (ct.LUEVY = khjjo.LUEVY))\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: (ct.OVE3E = cec.id)\n" +
" │ │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ │ ├─ (ct.ZRV3B = '=')\n" +
" │ │ │ │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ │ │ │ ├─ index: [FLQLP.OVE3E]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [fz2r5 luevy m22qn ove3e s3q3y zrv3b]\n" +
" │ │ │ │ │ │ └─ TableAlias(cec)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ │ │ │ │ ├─ index: [SFEGG.id]\n" +
" │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id no52d adurz]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (ct.M22QN, ct.LUEVY)\n" +
" │ │ │ │ │ ├─ right-key: (khjjo.M22QN, khjjo.LUEVY)\n" +
" │ │ │ │ │ └─ SubqueryAlias\n" +
" │ │ │ │ │ ├─ name: khjjo\n" +
" │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Distinct\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [mf.M22QN as M22QN, sn.id as BDNYB, mf.LUEVY as LUEVY]\n" +
" │ │ │ │ │ └─ LookupJoin\n" +
" │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ │ ├─ columns: [luevy m22qn]\n" +
" │ │ │ │ │ └─ keys: sn.BRQP2\n" +
" │ │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ │ └─ keys: sl3s5.BDNYB\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ └─ keys: mf.GXLUB\n" +
" │ └─ Filter\n" +
" │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ └─ keys: bs.IXUXU\n" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq as t4ibq, vumuy.DL754, vumuy.BDNYB, vumuy.ADURZ, vumuy.TPXBU, vumuy.NO52D, vumuy.IDPK7]\n" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq, vumuy.DL754, vumuy.BDNYB, vumuy.ADURZ, vumuy.TPXBU, vumuy.NO52D, vumuy.IDPK7]\n" +
" └─ CrossHashJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: vumuy\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, sl3s5.BDNYB, sl3s5.TOFPN, sl3s5.M22QN, sl3s5.ADURZ, sl3s5.NO52D, sl3s5.IDPK7, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: sl3s5\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sn.id as BDNYB, ci.FTQLQ as TOFPN, ct.M22QN as M22QN, cec.ADURZ as ADURZ, cec.NO52D as NO52D, ct.S3Q3Y as IDPK7]\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ (cec.id = ct.OVE3E)\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ (ci.id = ct.FZ2R5)\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (sn.BRQP2 = ct.LUEVY)\n" +
" │ │ │ │ ├─ sel: (ct.M22QN = Subquery\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [aac.id]\n" +
" │ │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ │ ├─ filters: [{[WT, WT]}]\n" +
" │ │ │ │ │ └─ columns: [id btxc5]\n" +
" │ │ │ │ │ )\n" +
" │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (ct.ZRV3B = '=')\n" +
" │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (ct.FZ2R5)\n" +
" │ │ │ ├─ right-key: (ci.id)\n" +
" │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ ├─ filters: [{[SQ1, SQ1]}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: (ct.OVE3E)\n" +
" │ │ ├─ right-key: (cec.id)\n" +
" │ │ └─ TableAlias(cec)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ └─ columns: [id no52d adurz]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.id]\n" +
" │ └─ keys: sl3s5.BDNYB\n" +
" └─ HashLookup\n" +
" ├─ left-key: ()\n" +
" ├─ right-key: ()\n" +
" └─ SubqueryAlias\n" +
" ├─ name: aoev5\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [temp_aoev5.t4ibq]\n" +
" └─ Values() as temp_AOEV5\n" +
" ├─ Row(\n" +
" │ '1')\n" +
" ├─ Row(\n" +
" │ '2')\n" +
" ├─ Row(\n" +
" │ '3')\n" +
" ├─ Row(\n" +
" │ '4')\n" +
" └─ Row(\n" +
" '5')\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" +
" │ │ ├─ alias-string: select aac.BTXC5 from TPXBU as aac where aac.id = SL3S5.M22QN\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" +
" │ │ ├─ keys: [sl3s5.M22QN:63!null]\n" +
" │ │ ├─ colSet: (134-136)\n" +
" │ │ ├─ tableId: 12\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\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:37!null, cla.FTQLQ:38!null, cla.TUXML:39, cla.PAEF5:40, cla.RUCY4:41, cla.TPNJ6:42!null, cla.LBL53:43, cla.NB3QS:44, cla.EO7IV:45, cla.MUHJF:46, cla.FM34L:47, cla.TY5RF:48, cla.ZHTLH:49, cla.NPB7W:50, cla.SX3HH:51, cla.ISBNF:52, cla.YA7YB:53, cla.C5YKB:54, cla.QK7KT:55, cla.FFGE6:56, cla.FIIGJ:57, cla.SH3NC:58, cla.NTENA:59, cla.M4AUB:60, cla.X5AIR:61, cla.SAB6M:62, cla.G5QI5:63, cla.ZVQVD:64, cla.YKSSU:65, cla.FHCYT:66, bs.id:33!null, bs.NFRYN:34!null, bs.IXUXU:35, bs.FHCYT:36, mf.id:16!null, mf.GXLUB:17!null, mf.LUEVY:18!null, mf.M22QN:19!null, mf.TJPT7:20!null, mf.ARN5P:21!null, mf.XOSD4:22!null, mf.IDE43:23, mf.HMW4H:24, mf.ZBT6R:25, mf.FSDY2:26!null, mf.LT7K6:27, mf.SPPYD:28, mf.QCGTS:29, mf.TEUJA:30, mf.QQV4M:31, mf.FHCYT:32, 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, cla.FTQLQ:38!null as T4IBQ, sl3s5.TOFPN:1!null as DL754, sn.id:6!null as BDNYB, sl3s5.ADURZ:3!null as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select aac.BTXC5 from TPXBU as aac where aac.id = SL3S5.M22QN\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5:68]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.id:67!null\n" +
" │ │ │ └─ sl3s5.M22QN:2!null\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ keys: [sl3s5.M22QN:2!null]\n" +
" │ │ ├─ colSet: (134-136)\n" +
" │ │ ├─ tableId: 12\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as TPXBU, sl3s5.NO52D:4!null as NO52D, sl3s5.IDPK7:5!null as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ sn.BRQP2:7!null\n" +
" │ │ │ │ └─ mf.LUEVY:18!null\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ │ ├─ name: sl3s5\n" +
" │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ ├─ colSet: (124-129)\n" +
" │ │ │ │ │ ├─ tableId: 11\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [khjjo.BDNYB:1!null as BDNYB, ci.FTQLQ:10!null as TOFPN, ct.M22QN:5!null as M22QN, cec.ADURZ:13!null as ADURZ, cec.NO52D:12!null as NO52D, ct.S3Q3Y:7!null as IDPK7]\n" +
" │ │ │ │ │ └─ LookupJoin\n" +
" │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ ct.LUEVY:4!null\n" +
" │ │ │ │ │ │ │ │ └─ khjjo.LUEVY:2!null\n" +
" │ │ │ │ │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ │ │ │ │ ├─ name: khjjo\n" +
" │ │ │ │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ │ │ │ ├─ colSet: (92-94)\n" +
" │ │ │ │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ │ │ │ └─ Distinct\n" +
" │ │ │ │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ │ │ │ ├─ columns: [mf.M22QN:3!null as M22QN, sn.id:0!null as BDNYB, mf.LUEVY:2!null as LUEVY]\n" +
" │ │ │ │ │ │ │ │ └─ LookupJoin\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ │ │ │ │ │ │ ├─ colSet: (79-88)\n" +
" │ │ │ │ │ │ │ │ │ └─ tableId: 6\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ │ │ │ │ ├─ keys: [sn.BRQP2:1!null]\n" +
" │ │ │ │ │ │ │ │ ├─ colSet: (62-78)\n" +
" │ │ │ │ │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ │ │ │ │ │ └─ columns: [luevy m22qn]\n" +
" │ │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ ct.ZRV3B:5!null\n" +
" │ │ │ │ │ │ │ │ └─ = (longtext)\n" +
" │ │ │ │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ │ │ │ ├─ index: [FLQLP.M22QN]\n" +
" │ │ │ │ │ │ │ ├─ keys: [khjjo.M22QN:0!null]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (95-106)\n" +
" │ │ │ │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: FLQLP\n" +
" │ │ │ │ │ │ │ └─ columns: [fz2r5 luevy m22qn ove3e s3q3y zrv3b]\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ │ │ ├─ ci.FTQLQ:1!null\n" +
" │ │ │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ │ │ │ ├─ index: [JDLNA.id]\n" +
" │ │ │ │ │ │ ├─ keys: [ct.FZ2R5:3!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (107-111)\n" +
" │ │ │ │ │ │ ├─ tableId: 9\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: JDLNA\n" +
" │ │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ │ └─ TableAlias(cec)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ │ │ │ ├─ index: [SFEGG.id]\n" +
" │ │ │ │ │ ├─ keys: [ct.OVE3E:6!null]\n" +
" │ │ │ │ │ ├─ colSet: (112-117)\n" +
" │ │ │ │ │ ├─ tableId: 10\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: SFEGG\n" +
" │ │ │ │ │ └─ columns: [id no52d adurz]\n" +
" │ │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ │ ├─ keys: [sl3s5.BDNYB:0!null]\n" +
" │ │ │ │ ├─ colSet: (52-61)\n" +
" │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ ├─ keys: [sl3s5.M22QN:2!null]\n" +
" │ │ │ ├─ colSet: (35-51)\n" +
" │ │ │ ├─ tableId: 3\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" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ ├─ keys: [mf.GXLUB:17!null]\n" +
" │ │ ├─ colSet: (31-34)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: THNTS\n" +
" │ │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" │ └─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ cla.FTQLQ:1!null\n" +
" │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ keys: [bs.IXUXU:35]\n" +
" │ ├─ colSet: (1-30)\n" +
" │ ├─ tableId: 1\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" +
" └─ 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" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq:6!null, vumuy.DL754:0!null, vumuy.BDNYB:1!null, vumuy.ADURZ:2!null, vumuy.TPXBU:3, vumuy.NO52D:4!null, vumuy.IDPK7:5!null]\n" +
" └─ CrossHashJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: vumuy\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (207-212)\n" +
" │ ├─ tableId: 21\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" +
" │ │ ├─ alias-string: select aac.BTXC5 from TPXBU as aac where aac.id = SL3S5.M22QN\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" +
" │ │ ├─ keys: [sl3s5.M22QN:12!null]\n" +
" │ │ ├─ colSet: (201-203)\n" +
" │ │ ├─ tableId: 20\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\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" +
" │ │ ├─ alias-string: select aac.BTXC5 from TPXBU as aac where aac.id = SL3S5.M22QN\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" +
" │ │ ├─ keys: [sl3s5.M22QN:2!null]\n" +
" │ │ ├─ colSet: (201-203)\n" +
" │ │ ├─ tableId: 20\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as TPXBU, sl3s5.NO52D:4!null as NO52D, sl3s5.IDPK7:5!null as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: sl3s5\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (192-197)\n" +
" │ │ ├─ tableId: 19\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sn.id:0!null as BDNYB, ci.FTQLQ:23!null as TOFPN, ct.M22QN:13!null as M22QN, cec.ADURZ:26!null as ADURZ, cec.NO52D:25!null as NO52D, ct.S3Q3Y:19!null as IDPK7]\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cec.id:24!null\n" +
" │ │ │ └─ ct.OVE3E:14!null\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ci.id:22!null\n" +
" │ │ │ │ └─ ct.FZ2R5:11!null\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ │ │ │ └─ ct.LUEVY:12!null\n" +
" │ │ │ │ ├─ sel: Eq\n" +
" │ │ │ │ │ ├─ ct.M22QN:13!null\n" +
" │ │ │ │ │ └─ Subquery\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ ├─ alias-string: select aac.id from TPXBU as aac where BTXC5 = 'WT'\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [aac.id:22!null]\n" +
" │ │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ │ ├─ static: [{[WT, WT]}]\n" +
" │ │ │ │ │ ├─ colSet: (172-174)\n" +
" │ │ │ │ │ ├─ tableId: 16\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: TPXBU\n" +
" │ │ │ │ │ └─ columns: [id btxc5]\n" +
" │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ ├─ colSet: (150-159)\n" +
" │ │ │ │ │ ├─ tableId: 14\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ ct.ZRV3B:10!null\n" +
" │ │ │ │ │ └─ = (longtext)\n" +
" │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (160-171)\n" +
" │ │ │ │ ├─ tableId: 15\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(ct.FZ2R5:11!null)\n" +
" │ │ │ ├─ right-key: TUPLE(ci.id:0!null)\n" +
" │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ ├─ static: [{[SQ1, SQ1]}]\n" +
" │ │ │ ├─ colSet: (175-179)\n" +
" │ │ │ ├─ tableId: 17\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: JDLNA\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(ct.OVE3E:14!null)\n" +
" │ │ ├─ right-key: TUPLE(cec.id:0!null)\n" +
" │ │ └─ TableAlias(cec)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ ├─ columns: [id no52d adurz]\n" +
" │ │ ├─ colSet: (180-185)\n" +
" │ │ └─ tableId: 18\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.id]\n" +
" │ ├─ keys: [sl3s5.BDNYB:0!null]\n" +
" │ ├─ colSet: (140-149)\n" +
" │ ├─ tableId: 13\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE()\n" +
" ├─ right-key: TUPLE()\n" +
" └─ SubqueryAlias\n" +
" ├─ name: aoev5\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (214)\n" +
" ├─ tableId: 23\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" +
"",
ExpectedEstimates: "Union all\n" +
" ├─ Project\n" +
" │ ├─ columns: [convert(T4IBQ, char) as T4IBQ, DL754, BDNYB, ADURZ, TPXBU, NO52D, IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.id, cla.FTQLQ, cla.TUXML, cla.PAEF5, cla.RUCY4, cla.TPNJ6, cla.LBL53, cla.NB3QS, cla.EO7IV, cla.MUHJF, cla.FM34L, cla.TY5RF, cla.ZHTLH, cla.NPB7W, cla.SX3HH, cla.ISBNF, cla.YA7YB, cla.C5YKB, cla.QK7KT, cla.FFGE6, cla.FIIGJ, cla.SH3NC, cla.NTENA, cla.M4AUB, cla.X5AIR, cla.SAB6M, cla.G5QI5, cla.ZVQVD, cla.YKSSU, cla.FHCYT, bs.id, bs.NFRYN, bs.IXUXU, bs.FHCYT, mf.id, mf.GXLUB, mf.LUEVY, mf.M22QN, mf.TJPT7, mf.ARN5P, mf.XOSD4, mf.IDE43, mf.HMW4H, mf.ZBT6R, mf.FSDY2, mf.LT7K6, mf.SPPYD, mf.QCGTS, mf.TEUJA, mf.QQV4M, mf.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, sl3s5.BDNYB, sl3s5.TOFPN, sl3s5.M22QN, sl3s5.ADURZ, sl3s5.NO52D, sl3s5.IDPK7, cla.FTQLQ as T4IBQ, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ (sn.BRQP2 = mf.LUEVY)\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ │ ├─ name: sl3s5\n" +
" │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [khjjo.BDNYB as BDNYB, ci.FTQLQ as TOFPN, ct.M22QN as M22QN, cec.ADURZ as ADURZ, cec.NO52D as NO52D, ct.S3Q3Y as IDPK7]\n" +
" │ │ │ │ │ └─ LookupJoin\n" +
" │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ │ ├─ (ct.LUEVY = khjjo.LUEVY)\n" +
" │ │ │ │ │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ │ │ │ │ ├─ name: khjjo\n" +
" │ │ │ │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ │ │ │ └─ Distinct\n" +
" │ │ │ │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ │ │ │ ├─ columns: [mf.M22QN as M22QN, sn.id as BDNYB, mf.LUEVY as LUEVY]\n" +
" │ │ │ │ │ │ │ │ └─ LookupJoin\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ │ │ │ │ ├─ columns: [luevy m22qn]\n" +
" │ │ │ │ │ │ │ │ └─ keys: sn.BRQP2\n" +
" │ │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ │ ├─ (ct.ZRV3B = '=')\n" +
" │ │ │ │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ │ │ │ ├─ index: [FLQLP.M22QN]\n" +
" │ │ │ │ │ │ │ ├─ columns: [fz2r5 luevy m22qn ove3e s3q3y zrv3b]\n" +
" │ │ │ │ │ │ │ └─ keys: khjjo.M22QN\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ (ci.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ │ │ │ ├─ index: [JDLNA.id]\n" +
" │ │ │ │ │ │ ├─ columns: [id ftqlq]\n" +
" │ │ │ │ │ │ └─ keys: ct.FZ2R5\n" +
" │ │ │ │ │ └─ TableAlias(cec)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ │ │ │ ├─ index: [SFEGG.id]\n" +
" │ │ │ │ │ ├─ columns: [id no52d adurz]\n" +
" │ │ │ │ │ └─ keys: ct.OVE3E\n" +
" │ │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ │ └─ keys: sl3s5.BDNYB\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ └─ keys: mf.GXLUB\n" +
" │ └─ Filter\n" +
" │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ └─ keys: bs.IXUXU\n" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq as t4ibq, vumuy.DL754, vumuy.BDNYB, vumuy.ADURZ, vumuy.TPXBU, vumuy.NO52D, vumuy.IDPK7]\n" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq, vumuy.DL754, vumuy.BDNYB, vumuy.ADURZ, vumuy.TPXBU, vumuy.NO52D, vumuy.IDPK7]\n" +
" └─ CrossHashJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: vumuy\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, sl3s5.BDNYB, sl3s5.TOFPN, sl3s5.M22QN, sl3s5.ADURZ, sl3s5.NO52D, sl3s5.IDPK7, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: sl3s5\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sn.id as BDNYB, ci.FTQLQ as TOFPN, ct.M22QN as M22QN, cec.ADURZ as ADURZ, cec.NO52D as NO52D, ct.S3Q3Y as IDPK7]\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ (cec.id = ct.OVE3E)\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ (ci.id = ct.FZ2R5)\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (sn.BRQP2 = ct.LUEVY)\n" +
" │ │ │ │ ├─ sel: (ct.M22QN = Subquery\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [aac.id]\n" +
" │ │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ │ ├─ filters: [{[WT, WT]}]\n" +
" │ │ │ │ │ └─ columns: [id btxc5]\n" +
" │ │ │ │ │ )\n" +
" │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (ct.ZRV3B = '=')\n" +
" │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (ct.FZ2R5)\n" +
" │ │ │ ├─ right-key: (ci.id)\n" +
" │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ ├─ filters: [{[SQ1, SQ1]}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: (ct.OVE3E)\n" +
" │ │ ├─ right-key: (cec.id)\n" +
" │ │ └─ TableAlias(cec)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ └─ columns: [id no52d adurz]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.id]\n" +
" │ └─ keys: sl3s5.BDNYB\n" +
" └─ HashLookup\n" +
" ├─ left-key: ()\n" +
" ├─ right-key: ()\n" +
" └─ SubqueryAlias\n" +
" ├─ name: aoev5\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [temp_aoev5.t4ibq]\n" +
" └─ Values() as temp_AOEV5\n" +
" ├─ Row(\n" +
" │ '1')\n" +
" ├─ Row(\n" +
" │ '2')\n" +
" ├─ Row(\n" +
" │ '3')\n" +
" ├─ Row(\n" +
" │ '4')\n" +
" └─ Row(\n" +
" '5')\n" +
"",
ExpectedAnalysis: "Union all\n" +
" ├─ Project\n" +
" │ ├─ columns: [convert(T4IBQ, char) as T4IBQ, DL754, BDNYB, ADURZ, TPXBU, NO52D, IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.id, cla.FTQLQ, cla.TUXML, cla.PAEF5, cla.RUCY4, cla.TPNJ6, cla.LBL53, cla.NB3QS, cla.EO7IV, cla.MUHJF, cla.FM34L, cla.TY5RF, cla.ZHTLH, cla.NPB7W, cla.SX3HH, cla.ISBNF, cla.YA7YB, cla.C5YKB, cla.QK7KT, cla.FFGE6, cla.FIIGJ, cla.SH3NC, cla.NTENA, cla.M4AUB, cla.X5AIR, cla.SAB6M, cla.G5QI5, cla.ZVQVD, cla.YKSSU, cla.FHCYT, bs.id, bs.NFRYN, bs.IXUXU, bs.FHCYT, mf.id, mf.GXLUB, mf.LUEVY, mf.M22QN, mf.TJPT7, mf.ARN5P, mf.XOSD4, mf.IDE43, mf.HMW4H, mf.ZBT6R, mf.FSDY2, mf.LT7K6, mf.SPPYD, mf.QCGTS, mf.TEUJA, mf.QQV4M, mf.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, sl3s5.BDNYB, sl3s5.TOFPN, sl3s5.M22QN, sl3s5.ADURZ, sl3s5.NO52D, sl3s5.IDPK7, cla.FTQLQ as T4IBQ, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ (sn.BRQP2 = mf.LUEVY)\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ │ ├─ name: sl3s5\n" +
" │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [khjjo.BDNYB as BDNYB, ci.FTQLQ as TOFPN, ct.M22QN as M22QN, cec.ADURZ as ADURZ, cec.NO52D as NO52D, ct.S3Q3Y as IDPK7]\n" +
" │ │ │ │ │ └─ LookupJoin\n" +
" │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ │ ├─ (ct.LUEVY = khjjo.LUEVY)\n" +
" │ │ │ │ │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ │ │ │ │ ├─ name: khjjo\n" +
" │ │ │ │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ │ │ │ └─ Distinct\n" +
" │ │ │ │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ │ │ │ ├─ columns: [mf.M22QN as M22QN, sn.id as BDNYB, mf.LUEVY as LUEVY]\n" +
" │ │ │ │ │ │ │ │ └─ LookupJoin\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ │ │ │ │ ├─ columns: [luevy m22qn]\n" +
" │ │ │ │ │ │ │ │ └─ keys: sn.BRQP2\n" +
" │ │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ │ ├─ (ct.ZRV3B = '=')\n" +
" │ │ │ │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ │ │ │ ├─ index: [FLQLP.M22QN]\n" +
" │ │ │ │ │ │ │ ├─ columns: [fz2r5 luevy m22qn ove3e s3q3y zrv3b]\n" +
" │ │ │ │ │ │ │ └─ keys: khjjo.M22QN\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ (ci.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ │ │ │ ├─ index: [JDLNA.id]\n" +
" │ │ │ │ │ │ ├─ columns: [id ftqlq]\n" +
" │ │ │ │ │ │ └─ keys: ct.FZ2R5\n" +
" │ │ │ │ │ └─ TableAlias(cec)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ │ │ │ ├─ index: [SFEGG.id]\n" +
" │ │ │ │ │ ├─ columns: [id no52d adurz]\n" +
" │ │ │ │ │ └─ keys: ct.OVE3E\n" +
" │ │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ │ └─ keys: sl3s5.BDNYB\n" +
" │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.M22QN]\n" +
" │ │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ └─ keys: mf.GXLUB\n" +
" │ └─ Filter\n" +
" │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ └─ keys: bs.IXUXU\n" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq as t4ibq, vumuy.DL754, vumuy.BDNYB, vumuy.ADURZ, vumuy.TPXBU, vumuy.NO52D, vumuy.IDPK7]\n" +
" └─ Project\n" +
" ├─ columns: [aoev5.t4ibq, vumuy.DL754, vumuy.BDNYB, vumuy.ADURZ, vumuy.TPXBU, vumuy.NO52D, vumuy.IDPK7]\n" +
" └─ CrossHashJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: vumuy\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, sl3s5.BDNYB, sl3s5.TOFPN, sl3s5.M22QN, sl3s5.ADURZ, sl3s5.NO52D, sl3s5.IDPK7, sl3s5.TOFPN as DL754, sn.id as BDNYB, sl3s5.ADURZ as ADURZ, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.BTXC5]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (aac.id = sl3s5.M22QN)\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ columns: [id btxc5]\n" +
" │ │ └─ keys: sl3s5.M22QN\n" +
" │ │ as TPXBU, sl3s5.NO52D as NO52D, sl3s5.IDPK7 as IDPK7]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: sl3s5\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sn.id as BDNYB, ci.FTQLQ as TOFPN, ct.M22QN as M22QN, cec.ADURZ as ADURZ, cec.NO52D as NO52D, ct.S3Q3Y as IDPK7]\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ (cec.id = ct.OVE3E)\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ (ci.id = ct.FZ2R5)\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (sn.BRQP2 = ct.LUEVY)\n" +
" │ │ │ │ ├─ sel: (ct.M22QN = Subquery\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [aac.id]\n" +
" │ │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ │ ├─ filters: [{[WT, WT]}]\n" +
" │ │ │ │ │ └─ columns: [id btxc5]\n" +
" │ │ │ │ │ )\n" +
" │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (ct.ZRV3B = '=')\n" +
" │ │ │ │ └─ TableAlias(ct)\n" +
" │ │ │ │ └─ IndexedTableAccess(FLQLP)\n" +
" │ │ │ │ ├─ index: [FLQLP.LUEVY]\n" +
" │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (ct.FZ2R5)\n" +
" │ │ │ ├─ right-key: (ci.id)\n" +
" │ │ │ └─ TableAlias(ci)\n" +
" │ │ │ └─ IndexedTableAccess(JDLNA)\n" +
" │ │ │ ├─ index: [JDLNA.FTQLQ]\n" +
" │ │ │ ├─ filters: [{[SQ1, SQ1]}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: (ct.OVE3E)\n" +
" │ │ ├─ right-key: (cec.id)\n" +
" │ │ └─ TableAlias(cec)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ └─ columns: [id no52d adurz]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.id]\n" +
" │ └─ keys: sl3s5.BDNYB\n" +
" └─ HashLookup\n" +
" ├─ left-key: ()\n" +
" ├─ right-key: ()\n" +
" └─ SubqueryAlias\n" +
" ├─ name: aoev5\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [temp_aoev5.t4ibq]\n" +
" └─ Values() as temp_AOEV5\n" +
" ├─ Row(\n" +
" │ '1')\n" +
" ├─ Row(\n" +
" │ '2')\n" +
" ├─ Row(\n" +
" │ '3')\n" +
" ├─ Row(\n" +
" │ '4')\n" +
" └─ Row(\n" +
" '5')\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" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [count(1) as COUNT(*)]\n" +
" └─ Project\n" +
" ├─ columns: [NOXN3.COUNT(1) as COUNT(1)]\n" +
" └─ table_count(NOXN3) as COUNT(1)\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [count(1) as COUNT(*)]\n" +
" └─ Project\n" +
" ├─ columns: [NOXN3.COUNT(1) 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:6!null, s7egw.DKCAJ:7!null, s7egw.KNG7T:8, s7egw.TW55N:9!null, s7egw.QRQXW:10!null, s7egw.ECXAJ:11!null, s7egw.FGG57:12, s7egw.ZH72S:13, s7egw.FSK67:14!null, s7egw.XQDYT:15!null, s7egw.TCE7A:16, s7egw.IWV2H:17, s7egw.HPCMS:18!null, s7egw.N5CC2:19, s7egw.FHCYT:20, s7egw.ETAQ7:21, s7egw.A75X7:22, tymvl.id:23!null, tymvl.DKCAJ:24!null, tymvl.KNG7T:25, tymvl.TW55N:26!null, tymvl.QRQXW:27!null, tymvl.ECXAJ:28!null, tymvl.FGG57:29, tymvl.ZH72S:30, tymvl.FSK67:31!null, tymvl.XQDYT:32!null, tymvl.TCE7A:33, tymvl.IWV2H:34, tymvl.HPCMS:35!null, tymvl.N5CC2:36, tymvl.FHCYT:37, tymvl.ETAQ7:38, tymvl.A75X7:39, 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" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: nb6pj\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (13-18)\n" +
" │ │ ├─ tableId: 2\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" +
" │ │ ├─ colSet: (1-10)\n" +
" │ │ └─ tableId: 1\n" +
" │ └─ TableAlias(s7egw)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ keys: [nb6pj.BRQP2:2!null]\n" +
" │ ├─ colSet: (19-35)\n" +
" │ ├─ tableId: 3\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(tymvl)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ keys: [nb6pj.FFTBJ:3!null]\n" +
" ├─ colSet: (36-52)\n" +
" ├─ tableId: 4\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" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [nb6pj.Y3IOU as Y3IOU, s7egw.TW55N as FJVD7, tymvl.TW55N as KBXXJ, nb6pj.NUMK2 as NUMK2, nb6pj.LETOE as LETOE]\n" +
" └─ Sort(nb6pj.Y3IOU as Y3IOU ASC)\n" +
" └─ Project\n" +
" ├─ columns: [nb6pj.Y3IOU, nb6pj.id, nb6pj.BRQP2, nb6pj.FFTBJ, nb6pj.NUMK2, nb6pj.LETOE, s7egw.id, s7egw.DKCAJ, s7egw.KNG7T, s7egw.TW55N, s7egw.QRQXW, s7egw.ECXAJ, s7egw.FGG57, s7egw.ZH72S, s7egw.FSK67, s7egw.XQDYT, s7egw.TCE7A, s7egw.IWV2H, s7egw.HPCMS, s7egw.N5CC2, s7egw.FHCYT, s7egw.ETAQ7, s7egw.A75X7, tymvl.id, tymvl.DKCAJ, tymvl.KNG7T, tymvl.TW55N, tymvl.QRQXW, tymvl.ECXAJ, tymvl.FGG57, tymvl.ZH72S, tymvl.FSK67, tymvl.XQDYT, tymvl.TCE7A, tymvl.IWV2H, tymvl.HPCMS, tymvl.N5CC2, tymvl.FHCYT, tymvl.ETAQ7, tymvl.A75X7, nb6pj.Y3IOU as Y3IOU, s7egw.TW55N as FJVD7, tymvl.TW55N as KBXXJ, nb6pj.NUMK2 as NUMK2, nb6pj.LETOE as LETOE]\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: nb6pj\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [row_number() over ( order by noxn3.id asc) as Y3IOU, noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE]\n" +
" │ │ └─ Sort(noxn3.id ASC)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [row_number() over ( order by noxn3.id asc), noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE, row_number() over ( order by noxn3.id asc) as Y3IOU]\n" +
" │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2 fftbj numk2 letoe]\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" +
" │ └─ keys: nb6pj.BRQP2\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" +
" └─ keys: nb6pj.FFTBJ\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [nb6pj.Y3IOU as Y3IOU, s7egw.TW55N as FJVD7, tymvl.TW55N as KBXXJ, nb6pj.NUMK2 as NUMK2, nb6pj.LETOE as LETOE]\n" +
" └─ Sort(nb6pj.Y3IOU as Y3IOU ASC)\n" +
" └─ Project\n" +
" ├─ columns: [nb6pj.Y3IOU, nb6pj.id, nb6pj.BRQP2, nb6pj.FFTBJ, nb6pj.NUMK2, nb6pj.LETOE, s7egw.id, s7egw.DKCAJ, s7egw.KNG7T, s7egw.TW55N, s7egw.QRQXW, s7egw.ECXAJ, s7egw.FGG57, s7egw.ZH72S, s7egw.FSK67, s7egw.XQDYT, s7egw.TCE7A, s7egw.IWV2H, s7egw.HPCMS, s7egw.N5CC2, s7egw.FHCYT, s7egw.ETAQ7, s7egw.A75X7, tymvl.id, tymvl.DKCAJ, tymvl.KNG7T, tymvl.TW55N, tymvl.QRQXW, tymvl.ECXAJ, tymvl.FGG57, tymvl.ZH72S, tymvl.FSK67, tymvl.XQDYT, tymvl.TCE7A, tymvl.IWV2H, tymvl.HPCMS, tymvl.N5CC2, tymvl.FHCYT, tymvl.ETAQ7, tymvl.A75X7, nb6pj.Y3IOU as Y3IOU, s7egw.TW55N as FJVD7, tymvl.TW55N as KBXXJ, nb6pj.NUMK2 as NUMK2, nb6pj.LETOE as LETOE]\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: nb6pj\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [row_number() over ( order by noxn3.id asc) as Y3IOU, noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE]\n" +
" │ │ └─ Sort(noxn3.id ASC)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [row_number() over ( order by noxn3.id asc), noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE, row_number() over ( order by noxn3.id asc) as Y3IOU]\n" +
" │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2 fftbj numk2 letoe]\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" +
" │ └─ keys: nb6pj.BRQP2\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" +
" └─ keys: nb6pj.FFTBJ\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" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nb6pj\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (13-18)\n" +
" │ ├─ tableId: 2\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ keys: [nb6pj.BRQP2:2!null]\n" +
" ├─ colSet: (19-35)\n" +
" ├─ tableId: 3\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" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [nd.TW55N as TW55N, nb6pj.Y3IOU as Y3IOU]\n" +
" └─ Sort(nd.TW55N as TW55N ASC, nb6pj.Y3IOU as Y3IOU ASC)\n" +
" └─ Project\n" +
" ├─ columns: [nb6pj.Y3IOU, nb6pj.id, nb6pj.BRQP2, nb6pj.FFTBJ, nb6pj.NUMK2, nb6pj.LETOE, nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nd.TW55N as TW55N, nb6pj.Y3IOU as Y3IOU]\n" +
" └─ LookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nb6pj\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [row_number() over ( order by noxn3.id asc) as Y3IOU, noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE]\n" +
" │ └─ Sort(noxn3.id ASC)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [row_number() over ( order by noxn3.id asc), noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE, row_number() over ( order by noxn3.id asc) as Y3IOU]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE)\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" +
" └─ keys: nb6pj.BRQP2\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [nd.TW55N as TW55N, nb6pj.Y3IOU as Y3IOU]\n" +
" └─ Sort(nd.TW55N as TW55N ASC, nb6pj.Y3IOU as Y3IOU ASC)\n" +
" └─ Project\n" +
" ├─ columns: [nb6pj.Y3IOU, nb6pj.id, nb6pj.BRQP2, nb6pj.FFTBJ, nb6pj.NUMK2, nb6pj.LETOE, nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nd.TW55N as TW55N, nb6pj.Y3IOU as Y3IOU]\n" +
" └─ LookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nb6pj\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [row_number() over ( order by noxn3.id asc) as Y3IOU, noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE]\n" +
" │ └─ Sort(noxn3.id ASC)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [row_number() over ( order by noxn3.id asc), noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE, row_number() over ( order by noxn3.id asc) as Y3IOU]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.NUMK2, noxn3.LETOE)\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" +
" └─ keys: nb6pj.BRQP2\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:2!null as KBXXJ, sn.NUMK2:3!null, sn.LETOE:4!null, sn.id:5!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, tymvl.TW55N:2!null, sn.NUMK2:3!null, sn.LETOE:4!null, sn.id:5!null, (row_number() over ( order by sn.id asc):0!null - 1 (tinyint)) as M6T2N, s7egw.TW55N:1!null as FJVD7, tymvl.TW55N:2!null as KBXXJ, sn.id:5!null as XLFIA]\n" +
" └─ Window\n" +
" ├─ row_number() over ( order by sn.id ASC)\n" +
" ├─ s7egw.TW55N:6!null\n" +
" ├─ tymvl.TW55N:8!null\n" +
" ├─ sn.NUMK2:3!null\n" +
" ├─ sn.LETOE:4!null\n" +
" ├─ sn.id:0!null\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ sn.FFTBJ:2!null\n" +
" │ └─ tymvl.id:7!null\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ sn.BRQP2:1!null\n" +
" │ │ └─ s7egw.id:5!null\n" +
" │ ├─ TableAlias(sn)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (1-10)\n" +
" │ │ ├─ tableId: 1\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2 fftbj numk2 letoe]\n" +
" │ └─ TableAlias(s7egw)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (11-27)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(sn.FFTBJ:2!null)\n" +
" ├─ right-key: TUPLE(tymvl.id:0!null)\n" +
" └─ TableAlias(tymvl)\n" +
" └─ ProcessTable\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [(row_number() over ( order by sn.id asc) - 1) as M6T2N, s7egw.TW55N as FJVD7, tymvl.TW55N as KBXXJ, sn.NUMK2, sn.LETOE, sn.id as XLFIA]\n" +
" └─ Sort((row_number() over ( order by sn.id asc) - 1) as M6T2N ASC)\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by sn.id asc), s7egw.TW55N, tymvl.TW55N, sn.NUMK2, sn.LETOE, sn.id, (row_number() over ( order by sn.id asc) - 1) as M6T2N, s7egw.TW55N as FJVD7, tymvl.TW55N as KBXXJ, sn.id as XLFIA]\n" +
" └─ Window(row_number() over ( order by sn.id ASC), s7egw.TW55N, tymvl.TW55N, sn.NUMK2, sn.LETOE, sn.id)\n" +
" └─ HashJoin\n" +
" ├─ (sn.FFTBJ = tymvl.id)\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: (sn.BRQP2 = s7egw.id)\n" +
" │ ├─ TableAlias(sn)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id brqp2 fftbj numk2 letoe]\n" +
" │ └─ TableAlias(s7egw)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (sn.FFTBJ)\n" +
" ├─ right-key: (tymvl.id)\n" +
" └─ TableAlias(tymvl)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [(row_number() over ( order by sn.id asc) - 1) as M6T2N, s7egw.TW55N as FJVD7, tymvl.TW55N as KBXXJ, sn.NUMK2, sn.LETOE, sn.id as XLFIA]\n" +
" └─ Sort((row_number() over ( order by sn.id asc) - 1) as M6T2N ASC)\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by sn.id asc), s7egw.TW55N, tymvl.TW55N, sn.NUMK2, sn.LETOE, sn.id, (row_number() over ( order by sn.id asc) - 1) as M6T2N, s7egw.TW55N as FJVD7, tymvl.TW55N as KBXXJ, sn.id as XLFIA]\n" +
" └─ Window(row_number() over ( order by sn.id ASC), s7egw.TW55N, tymvl.TW55N, sn.NUMK2, sn.LETOE, sn.id)\n" +
" └─ HashJoin\n" +
" ├─ (sn.FFTBJ = tymvl.id)\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: (sn.BRQP2 = s7egw.id)\n" +
" │ ├─ TableAlias(sn)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id brqp2 fftbj numk2 letoe]\n" +
" │ └─ TableAlias(s7egw)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (sn.FFTBJ)\n" +
" ├─ right-key: (tymvl.id)\n" +
" └─ TableAlias(tymvl)\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" +
" └─ ProcessTable\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [sn.id as FZZVR, (row_number() over ( order by sn.id asc) - 1) as M6T2N]\n" +
" └─ Window(row_number() over ( order by sn.id ASC), sn.id)\n" +
" └─ TableAlias(sn)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [sn.id as FZZVR, (row_number() over ( order by sn.id asc) - 1) as M6T2N]\n" +
" └─ Window(row_number() over ( order by sn.id ASC), sn.id)\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:7!null, il.LIILR:1, il.KSFXH:2, il.KLMAU:3, il.ecm:4]\n" +
" └─ Sort(nd.TW55N:7!null ASC nullsFirst)\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.DKCAJ:6!null\n" +
" │ └─ nt.id:8!null\n" +
" ├─ LookupJoin\n" +
" │ ├─ TableAlias(il)\n" +
" │ │ └─ ProcessTable\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: RLOHD\n" +
" │ │ └─ columns: [luevy liilr ksfxh klmau ecm]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ keys: [il.LUEVY:0!null]\n" +
" │ ├─ colSet: (9-25)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id dkcaj tw55n]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(nd.DKCAJ:6!null)\n" +
" ├─ right-key: TUPLE(nt.id:0!null)\n" +
" └─ TableAlias(nt)\n" +
" └─ IndexedTableAccess(F35MI)\n" +
" ├─ index: [F35MI.DZLIM]\n" +
" ├─ static: [{(NULL, SUZTA)}, {(SUZTA, ∞)}]\n" +
" ├─ colSet: (26-28)\n" +
" ├─ tableId: 3\n" +
" └─ Table\n" +
" ├─ name: F35MI\n" +
" └─ columns: [id dzlim]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [nd.TW55N, il.LIILR, il.KSFXH, il.KLMAU, il.ecm]\n" +
" └─ Sort(nd.TW55N ASC)\n" +
" └─ HashJoin\n" +
" ├─ (nd.DKCAJ = nt.id)\n" +
" ├─ LookupJoin\n" +
" │ ├─ TableAlias(il)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: RLOHD\n" +
" │ │ └─ columns: [luevy liilr ksfxh klmau ecm]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ columns: [id dkcaj tw55n]\n" +
" │ └─ keys: il.LUEVY\n" +
" └─ HashLookup\n" +
" ├─ left-key: (nd.DKCAJ)\n" +
" ├─ right-key: (nt.id)\n" +
" └─ TableAlias(nt)\n" +
" └─ IndexedTableAccess(F35MI)\n" +
" ├─ index: [F35MI.DZLIM]\n" +
" ├─ filters: [{(NULL, SUZTA)}, {(SUZTA, ∞)}]\n" +
" └─ columns: [id dzlim]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [nd.TW55N, il.LIILR, il.KSFXH, il.KLMAU, il.ecm]\n" +
" └─ Sort(nd.TW55N ASC)\n" +
" └─ HashJoin\n" +
" ├─ (nd.DKCAJ = nt.id)\n" +
" ├─ LookupJoin\n" +
" │ ├─ TableAlias(il)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: RLOHD\n" +
" │ │ └─ columns: [luevy liilr ksfxh klmau ecm]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ columns: [id dkcaj tw55n]\n" +
" │ └─ keys: il.LUEVY\n" +
" └─ HashLookup\n" +
" ├─ left-key: (nd.DKCAJ)\n" +
" ├─ right-key: (nt.id)\n" +
" └─ TableAlias(nt)\n" +
" └─ IndexedTableAccess(F35MI)\n" +
" ├─ index: [F35MI.DZLIM]\n" +
" ├─ filters: [{(NULL, SUZTA)}, {(SUZTA, ∞)}]\n" +
" └─ columns: [id dzlim]\n" +
"",
},
{
Query: `
SELECT
FTQLQ, TPNJ6
FROM YK2GW
WHERE FTQLQ IN ('SQ1')`,
ExpectedPlan: "IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.FTQLQ]\n" +
" ├─ static: [{[SQ1, SQ1]}]\n" +
" ├─ colSet: (1-30)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: YK2GW\n" +
" └─ columns: [ftqlq tpnj6]\n" +
"",
ExpectedEstimates: "IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.FTQLQ]\n" +
" ├─ filters: [{[SQ1, SQ1]}]\n" +
" └─ columns: [ftqlq tpnj6]\n" +
"",
ExpectedAnalysis: "IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.FTQLQ]\n" +
" ├─ filters: [{[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" +
" └─ LeftOuterLookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: athcu\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (63-68)\n" +
" │ ├─ tableId: 6\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" +
" │ │ ├─ alias-string: select nt.DZLIM from F35MI as nt where nt.id = nd.DKCAJ\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" +
" │ │ ├─ keys: [nd.DKCAJ:3!null]\n" +
" │ │ ├─ colSet: (59-61)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: F35MI\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" +
" │ │ ├─ alias-string: select nt.DZLIM from F35MI as nt where nt.id = nd.DKCAJ\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" +
" │ │ ├─ keys: [nd.DKCAJ:1!null]\n" +
" │ │ ├─ colSet: (59-61)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: F35MI\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" +
" │ │ ├─ colSet: (39-55)\n" +
" │ │ └─ tableId: 4\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE()\n" +
" │ ├─ right-key: TUPLE()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: tmdtp\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (37,38)\n" +
" │ ├─ tableId: 3\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" +
" │ │ ├─ colSet: (1-30)\n" +
" │ │ ├─ tableId: 1\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YK2GW\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (31-34)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: THNTS\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ TableAlias(fc)\n" +
" └─ IndexedTableAccess(AMYXQ)\n" +
" ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" ├─ keys: [athcu.B2TX3:0!null athcu.YYKXN:2!null]\n" +
" ├─ colSet: (69-76)\n" +
" ├─ tableId: 7\n" +
" └─ Table\n" +
" ├─ name: AMYXQ\n" +
" └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Sort(athcu.YYKXN ASC)\n" +
" └─ Project\n" +
" ├─ columns: [athcu.B2TX3, athcu.T4IBQ, athcu.YYKXN, athcu.TW55N, athcu.SOWRY, athcu.SJ5DU, fc.id, fc.GXLUB, fc.LUEVY, fc.XQDYT, fc.AMYXQ, fc.OZTQF, fc.Z35GY, fc.KKGN5, 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]\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: athcu\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tmdtp.B2TX3, tmdtp.T4IBQ, nd.id as YYKXN, nd.TW55N as TW55N, nd.FSK67 as SOWRY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nt.DZLIM]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (nt.id = nd.DKCAJ)\n" +
" │ │ └─ TableAlias(nt)\n" +
" │ │ └─ IndexedTableAccess(F35MI)\n" +
" │ │ ├─ index: [F35MI.id]\n" +
" │ │ ├─ columns: [id dzlim]\n" +
" │ │ └─ keys: nd.DKCAJ\n" +
" │ │ as SJ5DU]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tmdtp.B2TX3, tmdtp.T4IBQ, nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nd.id as YYKXN, nd.TW55N as TW55N, nd.FSK67 as SOWRY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nt.DZLIM]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (nt.id = nd.DKCAJ)\n" +
" │ │ └─ TableAlias(nt)\n" +
" │ │ └─ IndexedTableAccess(F35MI)\n" +
" │ │ ├─ index: [F35MI.id]\n" +
" │ │ ├─ columns: [id dzlim]\n" +
" │ │ └─ keys: nd.DKCAJ\n" +
" │ │ as SJ5DU]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ TableAlias(nd)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: E2I7U\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: ()\n" +
" │ ├─ right-key: ()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: tmdtp\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.id as B2TX3, cla.FTQLQ as T4IBQ]\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ ├─ Filter\n" +
" │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ TableAlias(fc)\n" +
" └─ IndexedTableAccess(AMYXQ)\n" +
" ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" ├─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
" └─ keys: athcu.B2TX3, athcu.YYKXN\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Sort(athcu.YYKXN ASC)\n" +
" └─ Project\n" +
" ├─ columns: [athcu.B2TX3, athcu.T4IBQ, athcu.YYKXN, athcu.TW55N, athcu.SOWRY, athcu.SJ5DU, fc.id, fc.GXLUB, fc.LUEVY, fc.XQDYT, fc.AMYXQ, fc.OZTQF, fc.Z35GY, fc.KKGN5, 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]\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: athcu\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tmdtp.B2TX3, tmdtp.T4IBQ, nd.id as YYKXN, nd.TW55N as TW55N, nd.FSK67 as SOWRY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nt.DZLIM]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (nt.id = nd.DKCAJ)\n" +
" │ │ └─ TableAlias(nt)\n" +
" │ │ └─ IndexedTableAccess(F35MI)\n" +
" │ │ ├─ index: [F35MI.id]\n" +
" │ │ ├─ columns: [id dzlim]\n" +
" │ │ └─ keys: nd.DKCAJ\n" +
" │ │ as SJ5DU]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tmdtp.B2TX3, tmdtp.T4IBQ, nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nd.id as YYKXN, nd.TW55N as TW55N, nd.FSK67 as SOWRY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nt.DZLIM]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (nt.id = nd.DKCAJ)\n" +
" │ │ └─ TableAlias(nt)\n" +
" │ │ └─ IndexedTableAccess(F35MI)\n" +
" │ │ ├─ index: [F35MI.id]\n" +
" │ │ ├─ columns: [id dzlim]\n" +
" │ │ └─ keys: nd.DKCAJ\n" +
" │ │ as SJ5DU]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ TableAlias(nd)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: E2I7U\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: ()\n" +
" │ ├─ right-key: ()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: tmdtp\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.id as B2TX3, cla.FTQLQ as T4IBQ]\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ ├─ Filter\n" +
" │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ TableAlias(fc)\n" +
" └─ IndexedTableAccess(AMYXQ)\n" +
" ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" ├─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
" └─ keys: athcu.B2TX3, athcu.YYKXN\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, xprw6.ECUWU:1!null\n" +
" └─ SubqueryAlias\n" +
" ├─ name: xprw6\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (214-218)\n" +
" ├─ tableId: 25\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.5 (decimal(2,1))\n" +
" │ └─ Eq\n" +
" │ ├─ nrfj3.YHYLK:6\n" +
" │ └─ 0 (bigint)\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, nrfj3.ECUWU:1!null, nrfj3.GSTQA:2!null\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nrfj3\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (201-207)\n" +
" ├─ tableId: 24\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" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (194-200)\n" +
" ├─ tableId: 22\n" +
" └─ Project\n" +
" ├─ columns: [bs.T4IBQ:1!null as T4IBQ, pa.DZLIM:6!null as ECUWU, pga.DZLIM:12!null as GSTQA, pog.B5OUF:10, fc.OZTQF:20!null, f26zw.YHYLK:24, nd.TW55N:16!null as TW55N]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ ms.D237E:4!null\n" +
" │ └─ 1 (int)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.HPCMS:17!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:15!null\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ms.GXLUB:2!null\n" +
" │ │ │ │ └─ bs.id:0!null\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: bs\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ ├─ colSet: (74,75)\n" +
" │ │ │ │ ├─ tableId: 9\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ T4IBQ:1!null\n" +
" │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [thnts.id:0!null, yk2gw.FTQLQ:3!null as T4IBQ]\n" +
" │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ thnts.IXUXU:1\n" +
" │ │ │ │ │ └─ yk2gw.id:2!null\n" +
" │ │ │ │ ├─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ ├─ colSet: (39-42)\n" +
" │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: THNTS\n" +
" │ │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (43-72)\n" +
" │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: YK2GW\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(bs.id:0!null)\n" +
" │ │ │ ├─ right-key: TUPLE(ms.GXLUB:0!null)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ HashJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ pog.XVSBH:9\n" +
" │ │ │ │ │ │ └─ pga.id:11!null\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ ├─ ms.CH3FR:3!null\n" +
" │ │ │ │ │ │ │ │ └─ pa.id:5!null\n" +
" │ │ │ │ │ │ │ ├─ TableAlias(ms)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(SZQWJ)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [SZQWJ.CH3FR]\n" +
" │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ ├─ colSet: (1-5)\n" +
" │ │ │ │ │ │ │ │ ├─ tableId: 1\n" +
" │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ ├─ name: SZQWJ\n" +
" │ │ │ │ │ │ │ │ └─ columns: [gxlub ch3fr d237e]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(pa)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ │ │ │ │ │ ├─ index: [XOAOP.id]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (6-8)\n" +
" │ │ │ │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: XOAOP\n" +
" │ │ │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ │ │ └─ TableAlias(pog)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(NPCYY)\n" +
" │ │ │ │ │ │ ├─ index: [NPCYY.CH3FR]\n" +
" │ │ │ │ │ │ ├─ keys: [pa.id:5!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (9-12)\n" +
" │ │ │ │ │ │ ├─ tableId: 3\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NPCYY\n" +
" │ │ │ │ │ │ └─ columns: [id ch3fr xvsbh b5ouf]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: TUPLE(pog.XVSBH:9)\n" +
" │ │ │ │ │ ├─ right-key: TUPLE(pga.id:0!null)\n" +
" │ │ │ │ │ └─ TableAlias(pga)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: PG27A\n" +
" │ │ │ │ │ ├─ columns: [id dzlim]\n" +
" │ │ │ │ │ ├─ colSet: (13-15)\n" +
" │ │ │ │ │ └─ tableId: 4\n" +
" │ │ │ │ └─ TableAlias(gz7z4)\n" +
" │ │ │ │ └─ IndexedTableAccess(FEIOE)\n" +
" │ │ │ │ ├─ index: [FEIOE.GMSGA]\n" +
" │ │ │ │ ├─ keys: [pog.id:7!null]\n" +
" │ │ │ │ ├─ colSet: (16-21)\n" +
" │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: FEIOE\n" +
" │ │ │ │ └─ columns: [luevy gmsga]\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ keys: [gz7z4.LUEVY:13!null]\n" +
" │ │ │ ├─ colSet: (22-38)\n" +
" │ │ │ ├─ tableId: 6\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [id tw55n hpcms]\n" +
" │ │ └─ TableAlias(fc)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" │ │ ├─ keys: [bs.id:0!null nd.id:15!null]\n" +
" │ │ ├─ colSet: (76-83)\n" +
" │ │ ├─ tableId: 10\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: AMYXQ\n" +
" │ │ └─ columns: [gxlub luevy oztqf]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(bs.T4IBQ:1!null, nd.id:15!null)\n" +
" │ ├─ right-key: TUPLE(f26zw.T4IBQ:0!null, f26zw.BRQP2:1!null)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: f26zw\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (183-186)\n" +
" │ ├─ tableId: 20\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" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: iq\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (168-172)\n" +
" │ │ │ ├─ tableId: 17\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" +
" │ │ │ └─ 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" +
" │ │ │ │ │ ├─ colSet: (105-134)\n" +
" │ │ │ │ │ ├─ tableId: 13\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: YK2GW\n" +
" │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (101-104)\n" +
" │ │ │ │ ├─ tableId: 12\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: THNTS\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(bs.id:2!null)\n" +
" │ │ │ ├─ right-key: TUPLE(mf.GXLUB:1!null)\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" +
" │ │ │ ├─ TableAlias(mf)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ │ ├─ columns: [id gxlub luevy fsdy2]\n" +
" │ │ │ │ ├─ colSet: (84-100)\n" +
" │ │ │ │ └─ tableId: 11\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" +
" │ │ │ └─ LookupJoin\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" +
" │ │ │ │ │ ├─ colSet: (135-151)\n" +
" │ │ │ │ │ ├─ tableId: 14\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ └─ columns: [id hpcms]\n" +
" │ │ │ │ └─ TableAlias(nma)\n" +
" │ │ │ │ └─ IndexedTableAccess(TNMXI)\n" +
" │ │ │ │ ├─ index: [TNMXI.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (152-154)\n" +
" │ │ │ │ ├─ tableId: 15\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: TNMXI\n" +
" │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ keys: [nd.id:8!null]\n" +
" │ │ │ ├─ colSet: (155-164)\n" +
" │ │ │ ├─ tableId: 16\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [brqp2]\n" +
" │ │ └─ TableAlias(w2mao)\n" +
" │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ ├─ keys: [iq.Z7CP5:2!null]\n" +
" │ │ ├─ colSet: (173-175)\n" +
" │ │ ├─ tableId: 18\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" +
" │ ├─ colSet: (176-181)\n" +
" │ └─ tableId: 19\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(nd.HPCMS:17!null)\n" +
" ├─ right-key: TUPLE(nma.id:0!null)\n" +
" └─ TableAlias(nma)\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" ├─ columns: [id]\n" +
" ├─ colSet: (187-189)\n" +
" └─ tableId: 21\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [xprw6.T4IBQ as T4IBQ, xprw6.ECUWU as ECUWU, sum(xprw6.b5ouf) as B5OUF, sum(xprw6.sp4si) as SP4SI]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(xprw6.B5OUF), SUM(xprw6.SP4SI), xprw6.T4IBQ, xprw6.ECUWU)\n" +
" ├─ Grouping(xprw6.T4IBQ, xprw6.ECUWU)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: xprw6\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [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]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(CASE WHEN ((nrfj3.OZTQF < 0.5) OR (nrfj3.YHYLK = 0)) THEN 1 ELSE 0 END), nrfj3.T4IBQ, nrfj3.ECUWU, nrfj3.GSTQA, nrfj3.B5OUF)\n" +
" ├─ Grouping(nrfj3.T4IBQ, nrfj3.ECUWU, nrfj3.GSTQA)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nrfj3\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ax7fv.T4IBQ, ax7fv.ECUWU, ax7fv.GSTQA, ax7fv.B5OUF, ax7fv.TW55N, ax7fv.OZTQF, ax7fv.YHYLK]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ax7fv\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [bs.T4IBQ as T4IBQ, pa.DZLIM as ECUWU, pga.DZLIM as GSTQA, pog.B5OUF, fc.OZTQF, f26zw.YHYLK, nd.TW55N as TW55N]\n" +
" └─ Filter\n" +
" ├─ (ms.D237E = 1)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (nd.HPCMS = nma.id)\n" +
" ├─ LeftOuterHashJoin\n" +
" │ ├─ ((f26zw.T4IBQ = bs.T4IBQ) AND (f26zw.BRQP2 = nd.id))\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ (ms.GXLUB = bs.id)\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: bs\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (T4IBQ HASH IN ('SQ1'))\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [thnts.id, yk2gw.FTQLQ as T4IBQ]\n" +
" │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (thnts.IXUXU = yk2gw.id)\n" +
" │ │ │ │ ├─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (bs.id)\n" +
" │ │ │ ├─ right-key: (ms.GXLUB)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ HashJoin\n" +
" │ │ │ │ │ ├─ (pog.XVSBH = pga.id)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: (ms.CH3FR = pa.id)\n" +
" │ │ │ │ │ │ │ ├─ TableAlias(ms)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(SZQWJ)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [SZQWJ.CH3FR]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [gxlub ch3fr d237e]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(pa)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ │ │ │ │ │ ├─ index: [XOAOP.id]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ │ │ └─ TableAlias(pog)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(NPCYY)\n" +
" │ │ │ │ │ │ ├─ index: [NPCYY.CH3FR]\n" +
" │ │ │ │ │ │ ├─ columns: [id ch3fr xvsbh b5ouf]\n" +
" │ │ │ │ │ │ └─ keys: pa.id\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (pog.XVSBH)\n" +
" │ │ │ │ │ ├─ right-key: (pga.id)\n" +
" │ │ │ │ │ └─ TableAlias(pga)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: PG27A\n" +
" │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ └─ TableAlias(gz7z4)\n" +
" │ │ │ │ └─ IndexedTableAccess(FEIOE)\n" +
" │ │ │ │ ├─ index: [FEIOE.GMSGA]\n" +
" │ │ │ │ ├─ columns: [luevy gmsga]\n" +
" │ │ │ │ └─ keys: pog.id\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ columns: [id tw55n hpcms]\n" +
" │ │ │ └─ keys: gz7z4.LUEVY\n" +
" │ │ └─ TableAlias(fc)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [gxlub luevy oztqf]\n" +
" │ │ └─ keys: bs.id, nd.id\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (bs.T4IBQ, nd.id)\n" +
" │ ├─ right-key: (f26zw.T4IBQ, f26zw.BRQP2)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: f26zw\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [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 (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'W6W24')) THEN 1 WHEN (((iq.FSDY2 IN ('SRARY', 'UBQWG')) AND (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'OG')) THEN 1 WHEN (((iq.FSDY2 IN ('SRARY', 'UBQWG')) AND (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'TSG')) THEN 0 ELSE NULL END as YHYLK]\n" +
" │ └─ LeftOuterHashJoin\n" +
" │ ├─ (w2mao.YH4XB = vc.id)\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: iq\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.BRQP2, mf.id as Z7CP5, mf.FSDY2, nma.DZLIM as IDWIO]\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ (mf.GXLUB = bs.id)\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (bs.id)\n" +
" │ │ │ ├─ right-key: (mf.GXLUB)\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ ((mf.LUEVY = nd.id) AND (mf.LUEVY = sn.BRQP2))\n" +
" │ │ │ ├─ TableAlias(mf)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ │ └─ columns: [id gxlub luevy fsdy2]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (mf.LUEVY, mf.LUEVY)\n" +
" │ │ │ ├─ right-key: (nd.id, sn.BRQP2)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (nd.HPCMS = nma.id)\n" +
" │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.HPCMS]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id hpcms]\n" +
" │ │ │ │ └─ TableAlias(nma)\n" +
" │ │ │ │ └─ IndexedTableAccess(TNMXI)\n" +
" │ │ │ │ ├─ index: [TNMXI.id]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [brqp2]\n" +
" │ │ │ └─ keys: nd.id\n" +
" │ │ └─ TableAlias(w2mao)\n" +
" │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ ├─ columns: [z7cp5 yh4xb]\n" +
" │ │ └─ keys: iq.Z7CP5\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (w2mao.YH4XB)\n" +
" │ ├─ right-key: (vc.id)\n" +
" │ └─ TableAlias(vc)\n" +
" │ └─ Table\n" +
" │ ├─ name: D34QP\n" +
" │ └─ columns: [id znp4p]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (nd.HPCMS)\n" +
" ├─ right-key: (nma.id)\n" +
" └─ TableAlias(nma)\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" └─ columns: [id]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [xprw6.T4IBQ as T4IBQ, xprw6.ECUWU as ECUWU, sum(xprw6.b5ouf) as B5OUF, sum(xprw6.sp4si) as SP4SI]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(xprw6.B5OUF), SUM(xprw6.SP4SI), xprw6.T4IBQ, xprw6.ECUWU)\n" +
" ├─ Grouping(xprw6.T4IBQ, xprw6.ECUWU)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: xprw6\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [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]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(CASE WHEN ((nrfj3.OZTQF < 0.5) OR (nrfj3.YHYLK = 0)) THEN 1 ELSE 0 END), nrfj3.T4IBQ, nrfj3.ECUWU, nrfj3.GSTQA, nrfj3.B5OUF)\n" +
" ├─ Grouping(nrfj3.T4IBQ, nrfj3.ECUWU, nrfj3.GSTQA)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nrfj3\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ax7fv.T4IBQ, ax7fv.ECUWU, ax7fv.GSTQA, ax7fv.B5OUF, ax7fv.TW55N, ax7fv.OZTQF, ax7fv.YHYLK]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ax7fv\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [bs.T4IBQ as T4IBQ, pa.DZLIM as ECUWU, pga.DZLIM as GSTQA, pog.B5OUF, fc.OZTQF, f26zw.YHYLK, nd.TW55N as TW55N]\n" +
" └─ Filter\n" +
" ├─ (ms.D237E = 1)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (nd.HPCMS = nma.id)\n" +
" ├─ LeftOuterHashJoin\n" +
" │ ├─ ((f26zw.T4IBQ = bs.T4IBQ) AND (f26zw.BRQP2 = nd.id))\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ (ms.GXLUB = bs.id)\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: bs\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (T4IBQ HASH IN ('SQ1'))\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [thnts.id, yk2gw.FTQLQ as T4IBQ]\n" +
" │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (thnts.IXUXU = yk2gw.id)\n" +
" │ │ │ │ ├─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (bs.id)\n" +
" │ │ │ ├─ right-key: (ms.GXLUB)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ HashJoin\n" +
" │ │ │ │ │ ├─ (pog.XVSBH = pga.id)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: (ms.CH3FR = pa.id)\n" +
" │ │ │ │ │ │ │ ├─ TableAlias(ms)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(SZQWJ)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [SZQWJ.CH3FR]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [gxlub ch3fr d237e]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(pa)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ │ │ │ │ │ ├─ index: [XOAOP.id]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ │ │ └─ TableAlias(pog)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(NPCYY)\n" +
" │ │ │ │ │ │ ├─ index: [NPCYY.CH3FR]\n" +
" │ │ │ │ │ │ ├─ columns: [id ch3fr xvsbh b5ouf]\n" +
" │ │ │ │ │ │ └─ keys: pa.id\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (pog.XVSBH)\n" +
" │ │ │ │ │ ├─ right-key: (pga.id)\n" +
" │ │ │ │ │ └─ TableAlias(pga)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: PG27A\n" +
" │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ └─ TableAlias(gz7z4)\n" +
" │ │ │ │ └─ IndexedTableAccess(FEIOE)\n" +
" │ │ │ │ ├─ index: [FEIOE.GMSGA]\n" +
" │ │ │ │ ├─ columns: [luevy gmsga]\n" +
" │ │ │ │ └─ keys: pog.id\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ columns: [id tw55n hpcms]\n" +
" │ │ │ └─ keys: gz7z4.LUEVY\n" +
" │ │ └─ TableAlias(fc)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [gxlub luevy oztqf]\n" +
" │ │ └─ keys: bs.id, nd.id\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (bs.T4IBQ, nd.id)\n" +
" │ ├─ right-key: (f26zw.T4IBQ, f26zw.BRQP2)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: f26zw\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [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 (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'W6W24')) THEN 1 WHEN (((iq.FSDY2 IN ('SRARY', 'UBQWG')) AND (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'OG')) THEN 1 WHEN (((iq.FSDY2 IN ('SRARY', 'UBQWG')) AND (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'TSG')) THEN 0 ELSE NULL END as YHYLK]\n" +
" │ └─ LeftOuterHashJoin\n" +
" │ ├─ (w2mao.YH4XB = vc.id)\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: iq\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.BRQP2, mf.id as Z7CP5, mf.FSDY2, nma.DZLIM as IDWIO]\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ (mf.GXLUB = bs.id)\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (bs.id)\n" +
" │ │ │ ├─ right-key: (mf.GXLUB)\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ ((mf.LUEVY = nd.id) AND (mf.LUEVY = sn.BRQP2))\n" +
" │ │ │ ├─ TableAlias(mf)\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ │ └─ columns: [id gxlub luevy fsdy2]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (mf.LUEVY, mf.LUEVY)\n" +
" │ │ │ ├─ right-key: (nd.id, sn.BRQP2)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (nd.HPCMS = nma.id)\n" +
" │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.HPCMS]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id hpcms]\n" +
" │ │ │ │ └─ TableAlias(nma)\n" +
" │ │ │ │ └─ IndexedTableAccess(TNMXI)\n" +
" │ │ │ │ ├─ index: [TNMXI.id]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [brqp2]\n" +
" │ │ │ └─ keys: nd.id\n" +
" │ │ └─ TableAlias(w2mao)\n" +
" │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ ├─ columns: [z7cp5 yh4xb]\n" +
" │ │ └─ keys: iq.Z7CP5\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (w2mao.YH4XB)\n" +
" │ ├─ right-key: (vc.id)\n" +
" │ └─ TableAlias(vc)\n" +
" │ └─ Table\n" +
" │ ├─ name: D34QP\n" +
" │ └─ columns: [id znp4p]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (nd.HPCMS)\n" +
" ├─ right-key: (nma.id)\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, xprw6.ECUWU:1!null\n" +
" └─ SubqueryAlias\n" +
" ├─ name: xprw6\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (214-218)\n" +
" ├─ tableId: 25\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.5 (decimal(2,1))\n" +
" │ └─ Eq\n" +
" │ ├─ nrfj3.YHYLK:6\n" +
" │ └─ 0 (bigint)\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, nrfj3.ECUWU:1!null, nrfj3.GSTQA:2!null\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nrfj3\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (201-207)\n" +
" ├─ tableId: 24\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" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (194-200)\n" +
" ├─ tableId: 22\n" +
" └─ Project\n" +
" ├─ columns: [bs.T4IBQ:1!null as T4IBQ, pa.DZLIM:6!null as ECUWU, pga.DZLIM:12!null as GSTQA, pog.B5OUF:10, fc.OZTQF:20!null, f26zw.YHYLK:24, nd.TW55N:16!null as TW55N]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ ms.D237E:4!null\n" +
" │ └─ 1 (int)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.HPCMS:17!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:15!null\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ ms.GXLUB:2!null\n" +
" │ │ │ │ └─ bs.id:0!null\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: bs\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ ├─ colSet: (74,75)\n" +
" │ │ │ │ ├─ tableId: 9\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ T4IBQ:1!null\n" +
" │ │ │ │ │ └─ TUPLE(SQ1 (longtext))\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [thnts.id:0!null, yk2gw.FTQLQ:3!null as T4IBQ]\n" +
" │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ thnts.IXUXU:1\n" +
" │ │ │ │ │ └─ yk2gw.id:2!null\n" +
" │ │ │ │ ├─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ ├─ colSet: (39-42)\n" +
" │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: THNTS\n" +
" │ │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (43-72)\n" +
" │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: YK2GW\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(bs.id:0!null)\n" +
" │ │ │ ├─ right-key: TUPLE(ms.GXLUB:0!null)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ HashJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ pog.XVSBH:9\n" +
" │ │ │ │ │ │ └─ pga.id:11!null\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ ├─ ms.CH3FR:3!null\n" +
" │ │ │ │ │ │ │ │ └─ pa.id:5!null\n" +
" │ │ │ │ │ │ │ ├─ TableAlias(ms)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(SZQWJ)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [SZQWJ.CH3FR]\n" +
" │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ ├─ colSet: (1-5)\n" +
" │ │ │ │ │ │ │ │ ├─ tableId: 1\n" +
" │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ ├─ name: SZQWJ\n" +
" │ │ │ │ │ │ │ │ └─ columns: [gxlub ch3fr d237e]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(pa)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ │ │ │ │ │ ├─ index: [XOAOP.id]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (6-8)\n" +
" │ │ │ │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: XOAOP\n" +
" │ │ │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ │ │ └─ TableAlias(pog)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(NPCYY)\n" +
" │ │ │ │ │ │ ├─ index: [NPCYY.CH3FR]\n" +
" │ │ │ │ │ │ ├─ keys: [pa.id:5!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (9-12)\n" +
" │ │ │ │ │ │ ├─ tableId: 3\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NPCYY\n" +
" │ │ │ │ │ │ └─ columns: [id ch3fr xvsbh b5ouf]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: TUPLE(pog.XVSBH:9)\n" +
" │ │ │ │ │ ├─ right-key: TUPLE(pga.id:0!null)\n" +
" │ │ │ │ │ └─ TableAlias(pga)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: PG27A\n" +
" │ │ │ │ │ ├─ columns: [id dzlim]\n" +
" │ │ │ │ │ ├─ colSet: (13-15)\n" +
" │ │ │ │ │ └─ tableId: 4\n" +
" │ │ │ │ └─ TableAlias(gz7z4)\n" +
" │ │ │ │ └─ IndexedTableAccess(FEIOE)\n" +
" │ │ │ │ ├─ index: [FEIOE.GMSGA]\n" +
" │ │ │ │ ├─ keys: [pog.id:7!null]\n" +
" │ │ │ │ ├─ colSet: (16-21)\n" +
" │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: FEIOE\n" +
" │ │ │ │ └─ columns: [luevy gmsga]\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ keys: [gz7z4.LUEVY:13!null]\n" +
" │ │ │ ├─ colSet: (22-38)\n" +
" │ │ │ ├─ tableId: 6\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [id tw55n hpcms]\n" +
" │ │ └─ TableAlias(fc)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" │ │ ├─ keys: [bs.id:0!null nd.id:15!null]\n" +
" │ │ ├─ colSet: (76-83)\n" +
" │ │ ├─ tableId: 10\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: AMYXQ\n" +
" │ │ └─ columns: [gxlub luevy oztqf]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(bs.T4IBQ:1!null, nd.id:15!null)\n" +
" │ ├─ right-key: TUPLE(f26zw.T4IBQ:0!null, f26zw.BRQP2:1!null)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: f26zw\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (183-186)\n" +
" │ ├─ tableId: 20\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" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: iq\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (168-172)\n" +
" │ │ │ ├─ tableId: 17\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [cla.FTQLQ:12!null as T4IBQ, sn.BRQP2:0!null, mf.id:5!null as Z7CP5, mf.FSDY2:8!null, nma.DZLIM:4!null as IDWIO]\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ mf.GXLUB:6!null\n" +
" │ │ │ │ └─ bs.id:9!null\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ mf.LUEVY:7!null\n" +
" │ │ │ │ │ └─ sn.BRQP2:0!null\n" +
" │ │ │ │ ├─ HashJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ sn.BRQP2:0!null\n" +
" │ │ │ │ │ │ └─ nd.id:1!null\n" +
" │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ ├─ columns: [brqp2]\n" +
" │ │ │ │ │ │ ├─ colSet: (155-164)\n" +
" │ │ │ │ │ │ └─ tableId: 16\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: TUPLE(sn.BRQP2:0!null)\n" +
" │ │ │ │ │ ├─ right-key: TUPLE(nd.id:0!null)\n" +
" │ │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ ├─ nd.HPCMS:2!null\n" +
" │ │ │ │ │ │ └─ nma.id:3!null\n" +
" │ │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ │ ├─ index: [E2I7U.HPCMS]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ ├─ colSet: (135-151)\n" +
" │ │ │ │ │ │ ├─ tableId: 14\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ │ └─ columns: [id hpcms]\n" +
" │ │ │ │ │ └─ TableAlias(nma)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(TNMXI)\n" +
" │ │ │ │ │ ├─ index: [TNMXI.id]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ ├─ colSet: (152-154)\n" +
" │ │ │ │ │ ├─ tableId: 15\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: TNMXI\n" +
" │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ ├─ keys: [nd.id:1!null]\n" +
" │ │ │ │ ├─ colSet: (84-100)\n" +
" │ │ │ │ ├─ tableId: 11\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ │ └─ columns: [id gxlub luevy fsdy2]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(mf.GXLUB:6!null)\n" +
" │ │ │ ├─ right-key: TUPLE(bs.id:0!null)\n" +
" │ │ │ └─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ bs.IXUXU:10\n" +
" │ │ │ │ └─ cla.id:11!null\n" +
" │ │ │ ├─ TableAlias(bs)\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (101-104)\n" +
" │ │ │ │ ├─ tableId: 12\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: THNTS\n" +
" │ │ │ │ └─ columns: [id ixuxu]\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" +
" │ │ │ ├─ colSet: (105-134)\n" +
" │ │ │ ├─ tableId: 13\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: YK2GW\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(w2mao)\n" +
" │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ ├─ keys: [iq.Z7CP5:2!null]\n" +
" │ │ ├─ colSet: (173-175)\n" +
" │ │ ├─ tableId: 18\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" +
" │ ├─ colSet: (176-181)\n" +
" │ └─ tableId: 19\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(nd.HPCMS:17!null)\n" +
" ├─ right-key: TUPLE(nma.id:0!null)\n" +
" └─ TableAlias(nma)\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" ├─ columns: [id]\n" +
" ├─ colSet: (187-189)\n" +
" └─ tableId: 21\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [xprw6.T4IBQ as T4IBQ, xprw6.ECUWU as ECUWU, sum(xprw6.b5ouf) as B5OUF, sum(xprw6.sp4si) as SP4SI]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(xprw6.B5OUF), SUM(xprw6.SP4SI), xprw6.T4IBQ, xprw6.ECUWU)\n" +
" ├─ Grouping(xprw6.T4IBQ, xprw6.ECUWU)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: xprw6\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [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]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(CASE WHEN ((nrfj3.OZTQF < 0.5) OR (nrfj3.YHYLK = 0)) THEN 1 ELSE 0 END), nrfj3.T4IBQ, nrfj3.ECUWU, nrfj3.GSTQA, nrfj3.B5OUF)\n" +
" ├─ Grouping(nrfj3.T4IBQ, nrfj3.ECUWU, nrfj3.GSTQA)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nrfj3\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ax7fv.T4IBQ, ax7fv.ECUWU, ax7fv.GSTQA, ax7fv.B5OUF, ax7fv.TW55N, ax7fv.OZTQF, ax7fv.YHYLK]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ax7fv\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [bs.T4IBQ as T4IBQ, pa.DZLIM as ECUWU, pga.DZLIM as GSTQA, pog.B5OUF, fc.OZTQF, f26zw.YHYLK, nd.TW55N as TW55N]\n" +
" └─ Filter\n" +
" ├─ (ms.D237E = 1)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (nd.HPCMS = nma.id)\n" +
" ├─ LeftOuterHashJoin\n" +
" │ ├─ ((f26zw.T4IBQ = bs.T4IBQ) AND (f26zw.BRQP2 = nd.id))\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ (ms.GXLUB = bs.id)\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: bs\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (T4IBQ HASH IN ('SQ1'))\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [thnts.id, yk2gw.FTQLQ as T4IBQ]\n" +
" │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (thnts.IXUXU = yk2gw.id)\n" +
" │ │ │ │ ├─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (bs.id)\n" +
" │ │ │ ├─ right-key: (ms.GXLUB)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ HashJoin\n" +
" │ │ │ │ │ ├─ (pog.XVSBH = pga.id)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: (ms.CH3FR = pa.id)\n" +
" │ │ │ │ │ │ │ ├─ TableAlias(ms)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(SZQWJ)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [SZQWJ.CH3FR]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [gxlub ch3fr d237e]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(pa)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ │ │ │ │ │ ├─ index: [XOAOP.id]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ │ │ └─ TableAlias(pog)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(NPCYY)\n" +
" │ │ │ │ │ │ ├─ index: [NPCYY.CH3FR]\n" +
" │ │ │ │ │ │ ├─ columns: [id ch3fr xvsbh b5ouf]\n" +
" │ │ │ │ │ │ └─ keys: pa.id\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (pog.XVSBH)\n" +
" │ │ │ │ │ ├─ right-key: (pga.id)\n" +
" │ │ │ │ │ └─ TableAlias(pga)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: PG27A\n" +
" │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ └─ TableAlias(gz7z4)\n" +
" │ │ │ │ └─ IndexedTableAccess(FEIOE)\n" +
" │ │ │ │ ├─ index: [FEIOE.GMSGA]\n" +
" │ │ │ │ ├─ columns: [luevy gmsga]\n" +
" │ │ │ │ └─ keys: pog.id\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ columns: [id tw55n hpcms]\n" +
" │ │ │ └─ keys: gz7z4.LUEVY\n" +
" │ │ └─ TableAlias(fc)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [gxlub luevy oztqf]\n" +
" │ │ └─ keys: bs.id, nd.id\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (bs.T4IBQ, nd.id)\n" +
" │ ├─ right-key: (f26zw.T4IBQ, f26zw.BRQP2)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: f26zw\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [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 (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'W6W24')) THEN 1 WHEN (((iq.FSDY2 IN ('SRARY', 'UBQWG')) AND (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'OG')) THEN 1 WHEN (((iq.FSDY2 IN ('SRARY', 'UBQWG')) AND (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'TSG')) THEN 0 ELSE NULL END as YHYLK]\n" +
" │ └─ LeftOuterHashJoin\n" +
" │ ├─ (w2mao.YH4XB = vc.id)\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: iq\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.BRQP2, mf.id as Z7CP5, mf.FSDY2, nma.DZLIM as IDWIO]\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ (mf.GXLUB = bs.id)\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ (mf.LUEVY = sn.BRQP2)\n" +
" │ │ │ │ ├─ HashJoin\n" +
" │ │ │ │ │ ├─ (sn.BRQP2 = nd.id)\n" +
" │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ └─ columns: [brqp2]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (sn.BRQP2)\n" +
" │ │ │ │ │ ├─ right-key: (nd.id)\n" +
" │ │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: (nd.HPCMS = nma.id)\n" +
" │ │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ │ ├─ index: [E2I7U.HPCMS]\n" +
" │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id hpcms]\n" +
" │ │ │ │ │ └─ TableAlias(nma)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(TNMXI)\n" +
" │ │ │ │ │ ├─ index: [TNMXI.id]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ ├─ columns: [id gxlub luevy fsdy2]\n" +
" │ │ │ │ └─ keys: nd.id\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (mf.GXLUB)\n" +
" │ │ │ ├─ right-key: (bs.id)\n" +
" │ │ │ └─ MergeJoin\n" +
" │ │ │ ├─ cmp: (bs.IXUXU = cla.id)\n" +
" │ │ │ ├─ TableAlias(bs)\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(w2mao)\n" +
" │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ ├─ columns: [z7cp5 yh4xb]\n" +
" │ │ └─ keys: iq.Z7CP5\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (w2mao.YH4XB)\n" +
" │ ├─ right-key: (vc.id)\n" +
" │ └─ TableAlias(vc)\n" +
" │ └─ Table\n" +
" │ ├─ name: D34QP\n" +
" │ └─ columns: [id znp4p]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (nd.HPCMS)\n" +
" ├─ right-key: (nma.id)\n" +
" └─ TableAlias(nma)\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" └─ columns: [id]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [xprw6.T4IBQ as T4IBQ, xprw6.ECUWU as ECUWU, sum(xprw6.b5ouf) as B5OUF, sum(xprw6.sp4si) as SP4SI]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(xprw6.B5OUF), SUM(xprw6.SP4SI), xprw6.T4IBQ, xprw6.ECUWU)\n" +
" ├─ Grouping(xprw6.T4IBQ, xprw6.ECUWU)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: xprw6\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [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]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(CASE WHEN ((nrfj3.OZTQF < 0.5) OR (nrfj3.YHYLK = 0)) THEN 1 ELSE 0 END), nrfj3.T4IBQ, nrfj3.ECUWU, nrfj3.GSTQA, nrfj3.B5OUF)\n" +
" ├─ Grouping(nrfj3.T4IBQ, nrfj3.ECUWU, nrfj3.GSTQA)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nrfj3\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ax7fv.T4IBQ, ax7fv.ECUWU, ax7fv.GSTQA, ax7fv.B5OUF, ax7fv.TW55N, ax7fv.OZTQF, ax7fv.YHYLK]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ax7fv\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [bs.T4IBQ as T4IBQ, pa.DZLIM as ECUWU, pga.DZLIM as GSTQA, pog.B5OUF, fc.OZTQF, f26zw.YHYLK, nd.TW55N as TW55N]\n" +
" └─ Filter\n" +
" ├─ (ms.D237E = 1)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (nd.HPCMS = nma.id)\n" +
" ├─ LeftOuterHashJoin\n" +
" │ ├─ ((f26zw.T4IBQ = bs.T4IBQ) AND (f26zw.BRQP2 = nd.id))\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ ├─ (ms.GXLUB = bs.id)\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: bs\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (T4IBQ HASH IN ('SQ1'))\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [thnts.id, yk2gw.FTQLQ as T4IBQ]\n" +
" │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (thnts.IXUXU = yk2gw.id)\n" +
" │ │ │ │ ├─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (bs.id)\n" +
" │ │ │ ├─ right-key: (ms.GXLUB)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ HashJoin\n" +
" │ │ │ │ │ ├─ (pog.XVSBH = pga.id)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: (ms.CH3FR = pa.id)\n" +
" │ │ │ │ │ │ │ ├─ TableAlias(ms)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(SZQWJ)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [SZQWJ.CH3FR]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [gxlub ch3fr d237e]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(pa)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ │ │ │ │ │ ├─ index: [XOAOP.id]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ │ │ └─ TableAlias(pog)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(NPCYY)\n" +
" │ │ │ │ │ │ ├─ index: [NPCYY.CH3FR]\n" +
" │ │ │ │ │ │ ├─ columns: [id ch3fr xvsbh b5ouf]\n" +
" │ │ │ │ │ │ └─ keys: pa.id\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (pog.XVSBH)\n" +
" │ │ │ │ │ ├─ right-key: (pga.id)\n" +
" │ │ │ │ │ └─ TableAlias(pga)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: PG27A\n" +
" │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ └─ TableAlias(gz7z4)\n" +
" │ │ │ │ └─ IndexedTableAccess(FEIOE)\n" +
" │ │ │ │ ├─ index: [FEIOE.GMSGA]\n" +
" │ │ │ │ ├─ columns: [luevy gmsga]\n" +
" │ │ │ │ └─ keys: pog.id\n" +
" │ │ │ └─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.id]\n" +
" │ │ │ ├─ columns: [id tw55n hpcms]\n" +
" │ │ │ └─ keys: gz7z4.LUEVY\n" +
" │ │ └─ TableAlias(fc)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [gxlub luevy oztqf]\n" +
" │ │ └─ keys: bs.id, nd.id\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (bs.T4IBQ, nd.id)\n" +
" │ ├─ right-key: (f26zw.T4IBQ, f26zw.BRQP2)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: f26zw\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [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 (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'W6W24')) THEN 1 WHEN (((iq.FSDY2 IN ('SRARY', 'UBQWG')) AND (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'OG')) THEN 1 WHEN (((iq.FSDY2 IN ('SRARY', 'UBQWG')) AND (NOT((vc.ZNP4P = 'L5Q44')))) AND (iq.IDWIO = 'TSG')) THEN 0 ELSE NULL END as YHYLK]\n" +
" │ └─ LeftOuterHashJoin\n" +
" │ ├─ (w2mao.YH4XB = vc.id)\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: iq\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.BRQP2, mf.id as Z7CP5, mf.FSDY2, nma.DZLIM as IDWIO]\n" +
" │ │ │ └─ HashJoin\n" +
" │ │ │ ├─ (mf.GXLUB = bs.id)\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ (mf.LUEVY = sn.BRQP2)\n" +
" │ │ │ │ ├─ HashJoin\n" +
" │ │ │ │ │ ├─ (sn.BRQP2 = nd.id)\n" +
" │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ └─ columns: [brqp2]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (sn.BRQP2)\n" +
" │ │ │ │ │ ├─ right-key: (nd.id)\n" +
" │ │ │ │ │ └─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: (nd.HPCMS = nma.id)\n" +
" │ │ │ │ │ ├─ TableAlias(nd)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ │ ├─ index: [E2I7U.HPCMS]\n" +
" │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id hpcms]\n" +
" │ │ │ │ │ └─ TableAlias(nma)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(TNMXI)\n" +
" │ │ │ │ │ ├─ index: [TNMXI.id]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id dzlim]\n" +
" │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ ├─ columns: [id gxlub luevy fsdy2]\n" +
" │ │ │ │ └─ keys: nd.id\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (mf.GXLUB)\n" +
" │ │ │ ├─ right-key: (bs.id)\n" +
" │ │ │ └─ MergeJoin\n" +
" │ │ │ ├─ cmp: (bs.IXUXU = cla.id)\n" +
" │ │ │ ├─ TableAlias(bs)\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(w2mao)\n" +
" │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ ├─ columns: [z7cp5 yh4xb]\n" +
" │ │ └─ keys: iq.Z7CP5\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (w2mao.YH4XB)\n" +
" │ ├─ right-key: (vc.id)\n" +
" │ └─ TableAlias(vc)\n" +
" │ └─ Table\n" +
" │ ├─ name: D34QP\n" +
" │ └─ columns: [id znp4p]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (nd.HPCMS)\n" +
" ├─ right-key: (nma.id)\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:0!null, xj2rd.WNUNU:1!null, xj2rd.HVHRZ:2!null, tusay.Y3IOU:3!null, tusay.XLFIA:4!null, tusay.Y3IOU:3!null as RWGEU]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ xj2rd.WNUNU:1!null\n" +
" │ └─ tusay.XLFIA:4!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: xj2rd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (10-12)\n" +
" │ ├─ tableId: 2\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" +
" │ ├─ colSet: (1-6)\n" +
" │ └─ tableId: 1\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(xj2rd.WNUNU:1!null)\n" +
" ├─ right-key: TUPLE(tusay.XLFIA:1!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: tusay\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (26,27)\n" +
" ├─ tableId: 4\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" +
" ├─ colSet: (13-22)\n" +
" └─ tableId: 3\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [tusay.Y3IOU as RWGEU]\n" +
" └─ Sort(xj2rd.Y46B2 ASC)\n" +
" └─ Project\n" +
" ├─ columns: [xj2rd.Y46B2, xj2rd.WNUNU, xj2rd.HVHRZ, tusay.Y3IOU, tusay.XLFIA, tusay.Y3IOU as RWGEU]\n" +
" └─ HashJoin\n" +
" ├─ (xj2rd.WNUNU = tusay.XLFIA)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: xj2rd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [qywqd.id as Y46B2, qywqd.WNUNU as WNUNU, qywqd.HVHRZ as HVHRZ]\n" +
" │ └─ Table\n" +
" │ ├─ name: QYWQD\n" +
" │ └─ columns: [id wnunu hvhrz]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (xj2rd.WNUNU)\n" +
" ├─ right-key: (tusay.XLFIA)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: tusay\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by noxn3.id asc) as Y3IOU, noxn3.id as XLFIA]\n" +
" └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [tusay.Y3IOU as RWGEU]\n" +
" └─ Sort(xj2rd.Y46B2 ASC)\n" +
" └─ Project\n" +
" ├─ columns: [xj2rd.Y46B2, xj2rd.WNUNU, xj2rd.HVHRZ, tusay.Y3IOU, tusay.XLFIA, tusay.Y3IOU as RWGEU]\n" +
" └─ HashJoin\n" +
" ├─ (xj2rd.WNUNU = tusay.XLFIA)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: xj2rd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [qywqd.id as Y46B2, qywqd.WNUNU as WNUNU, qywqd.HVHRZ as HVHRZ]\n" +
" │ └─ Table\n" +
" │ ├─ name: QYWQD\n" +
" │ └─ columns: [id wnunu hvhrz]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (xj2rd.WNUNU)\n" +
" ├─ right-key: (tusay.XLFIA)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: tusay\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by noxn3.id asc) as Y3IOU, noxn3.id as XLFIA]\n" +
" └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\n" +
"",
},
{
Query: `
SELECT
ECXAJ
FROM
E2I7U
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [e2i7u.ECXAJ:1!null]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id ecxaj]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [e2i7u.ECXAJ]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id ecxaj]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [e2i7u.ECXAJ]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id ecxaj]\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" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (33,34)\n" +
" ├─ tableId: 5\n" +
" └─ Project\n" +
" ├─ columns: [nd.T722E:0!null, fc.Z35GY:2!null]\n" +
" └─ Sort(nd.T722E:0!null ASC nullsFirst)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ nd.T722E:0!null\n" +
" │ └─ fc.ZPAIK:1!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (19)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id:0!null as T722E]\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ ├─ columns: [id]\n" +
" │ ├─ colSet: (1-17)\n" +
" │ └─ tableId: 1\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" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (31,32)\n" +
" ├─ tableId: 4\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" +
" ├─ colSet: (20-27)\n" +
" └─ tableId: 3\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [CASE WHEN (NOT(yzxyp.Z35GY IS NULL)) THEN yzxyp.Z35GY ELSE -1 END as FMSOH]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: yzxyp\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.T722E, fc.Z35GY]\n" +
" └─ Sort(nd.T722E ASC)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (nd.T722E = fc.ZPAIK)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id as T722E]\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (nd.T722E)\n" +
" ├─ right-key: (fc.ZPAIK)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: fc\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [amyxq.LUEVY as ZPAIK, max(amyxq.z35gy) as Z35GY]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(MAX(amyxq.Z35GY), amyxq.LUEVY)\n" +
" ├─ Grouping(amyxq.luevy)\n" +
" └─ Table\n" +
" ├─ name: AMYXQ\n" +
" └─ columns: [luevy z35gy]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [CASE WHEN (NOT(yzxyp.Z35GY IS NULL)) THEN yzxyp.Z35GY ELSE -1 END as FMSOH]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: yzxyp\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.T722E, fc.Z35GY]\n" +
" └─ Sort(nd.T722E ASC)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (nd.T722E = fc.ZPAIK)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id as T722E]\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (nd.T722E)\n" +
" ├─ right-key: (fc.ZPAIK)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: fc\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [amyxq.LUEVY as ZPAIK, max(amyxq.z35gy) as Z35GY]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(MAX(amyxq.Z35GY), amyxq.LUEVY)\n" +
" ├─ Grouping(amyxq.luevy)\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" +
" │ ├─ alias-string: select id from E2I7U where not id in (select LUEVY from AMYXQ)\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" +
" │ ├─ amyxq.LUEVY:35!null IS NULL\n" +
" │ └─ LeftOuterLookupJoin\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" +
" │ │ ├─ colSet: (18-34)\n" +
" │ │ └─ tableId: 2\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ ├─ keys: [e2i7u.id:18!null]\n" +
" │ ├─ colSet: (35-42)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Table\n" +
" │ ├─ name: AMYXQ\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" +
" │ ├─ alias-string: select id from E2I7U where not id in (select LUEVY from AMYXQ)\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" +
" │ ├─ amyxq.LUEVY:34!null IS NULL\n" +
" │ └─ LeftOuterLookupJoin\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" +
" │ │ ├─ colSet: (18-34)\n" +
" │ │ └─ tableId: 2\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ ├─ keys: [e2i7u.id:17!null]\n" +
" │ ├─ colSet: (35-42)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Table\n" +
" │ ├─ name: AMYXQ\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" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\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" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [CASE WHEN e2i7u.FGG57 IS NULL THEN 0 WHEN InSubquery\n" +
" │ ├─ left: e2i7u.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [E2I7U.id, E2I7U.DKCAJ, E2I7U.KNG7T, E2I7U.TW55N, E2I7U.QRQXW, E2I7U.ECXAJ, E2I7U.FGG57, E2I7U.ZH72S, E2I7U.FSK67, E2I7U.XQDYT, E2I7U.TCE7A, E2I7U.IWV2H, E2I7U.HPCMS, E2I7U.N5CC2, E2I7U.FHCYT, E2I7U.ETAQ7, E2I7U.A75X7]\n" +
" │ └─ Filter\n" +
" │ ├─ amyxq.LUEVY IS NULL\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ Table\n" +
" │ │ └─ name: E2I7U\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ ├─ columns: [luevy]\n" +
" │ └─ keys: e2i7u.id\n" +
" │ THEN 1 WHEN (e2i7u.FSK67 = 'z') THEN 2 WHEN (e2i7u.FSK67 = 'CRZ2X') THEN 0 ELSE 3 END as SZ6KK]\n" +
" └─ Project\n" +
" ├─ columns: [e2i7u.id, e2i7u.DKCAJ, e2i7u.KNG7T, e2i7u.TW55N, e2i7u.QRQXW, e2i7u.ECXAJ, e2i7u.FGG57, e2i7u.ZH72S, e2i7u.FSK67, e2i7u.XQDYT, e2i7u.TCE7A, e2i7u.IWV2H, e2i7u.HPCMS, e2i7u.N5CC2, e2i7u.FHCYT, e2i7u.ETAQ7, e2i7u.A75X7, CASE WHEN e2i7u.FGG57 IS NULL THEN 0 WHEN InSubquery\n" +
" │ ├─ left: e2i7u.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [E2I7U.id, E2I7U.DKCAJ, E2I7U.KNG7T, E2I7U.TW55N, E2I7U.QRQXW, E2I7U.ECXAJ, E2I7U.FGG57, E2I7U.ZH72S, E2I7U.FSK67, E2I7U.XQDYT, E2I7U.TCE7A, E2I7U.IWV2H, E2I7U.HPCMS, E2I7U.N5CC2, E2I7U.FHCYT, E2I7U.ETAQ7, E2I7U.A75X7]\n" +
" │ └─ Filter\n" +
" │ ├─ amyxq.LUEVY IS NULL\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ Table\n" +
" │ │ └─ name: E2I7U\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ ├─ columns: [luevy]\n" +
" │ └─ keys: e2i7u.id\n" +
" │ THEN 1 WHEN (e2i7u.FSK67 = 'z') THEN 2 WHEN (e2i7u.FSK67 = 'CRZ2X') THEN 0 ELSE 3 END as SZ6KK]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" └─ filters: [{[NULL, ∞)}]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [CASE WHEN e2i7u.FGG57 IS NULL THEN 0 WHEN InSubquery\n" +
" │ ├─ left: e2i7u.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [E2I7U.id, E2I7U.DKCAJ, E2I7U.KNG7T, E2I7U.TW55N, E2I7U.QRQXW, E2I7U.ECXAJ, E2I7U.FGG57, E2I7U.ZH72S, E2I7U.FSK67, E2I7U.XQDYT, E2I7U.TCE7A, E2I7U.IWV2H, E2I7U.HPCMS, E2I7U.N5CC2, E2I7U.FHCYT, E2I7U.ETAQ7, E2I7U.A75X7]\n" +
" │ └─ Filter\n" +
" │ ├─ amyxq.LUEVY IS NULL\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ Table\n" +
" │ │ └─ name: E2I7U\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ ├─ columns: [luevy]\n" +
" │ └─ keys: e2i7u.id\n" +
" │ THEN 1 WHEN (e2i7u.FSK67 = 'z') THEN 2 WHEN (e2i7u.FSK67 = 'CRZ2X') THEN 0 ELSE 3 END as SZ6KK]\n" +
" └─ Project\n" +
" ├─ columns: [e2i7u.id, e2i7u.DKCAJ, e2i7u.KNG7T, e2i7u.TW55N, e2i7u.QRQXW, e2i7u.ECXAJ, e2i7u.FGG57, e2i7u.ZH72S, e2i7u.FSK67, e2i7u.XQDYT, e2i7u.TCE7A, e2i7u.IWV2H, e2i7u.HPCMS, e2i7u.N5CC2, e2i7u.FHCYT, e2i7u.ETAQ7, e2i7u.A75X7, CASE WHEN e2i7u.FGG57 IS NULL THEN 0 WHEN InSubquery\n" +
" │ ├─ left: e2i7u.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [E2I7U.id, E2I7U.DKCAJ, E2I7U.KNG7T, E2I7U.TW55N, E2I7U.QRQXW, E2I7U.ECXAJ, E2I7U.FGG57, E2I7U.ZH72S, E2I7U.FSK67, E2I7U.XQDYT, E2I7U.TCE7A, E2I7U.IWV2H, E2I7U.HPCMS, E2I7U.N5CC2, E2I7U.FHCYT, E2I7U.ETAQ7, E2I7U.A75X7]\n" +
" │ └─ Filter\n" +
" │ ├─ amyxq.LUEVY IS NULL\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ Table\n" +
" │ │ └─ name: E2I7U\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ ├─ columns: [luevy]\n" +
" │ └─ keys: e2i7u.id\n" +
" │ THEN 1 WHEN (e2i7u.FSK67 = 'z') THEN 2 WHEN (e2i7u.FSK67 = 'CRZ2X') THEN 0 ELSE 3 END as SZ6KK]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" └─ filters: [{[NULL, ∞)}]\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: "Sort(ckele.M6T2N:4!null ASC nullsFirst)\n" +
" └─ 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" +
" └─ Project\n" +
" ├─ columns: [oxxei.T4IBQ:0!null, oxxei.BDNYB:1!null, oxxei.BTXC5:2, oxxei.Z7CP5:3!null, oxxei.vaf:4, oxxei.QCGTS:5, oxxei.SNY4H:6!null, e52ap.KUXQY:7!null, e52ap.BDNYB:8!null, e52ap.YHVEZ:9!null, e52ap.YAZ4X:10!null, ckele.LWQ6O:11!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" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ ckele.LWQ6O:11!null\n" +
" │ └─ oxxei.BDNYB:1!null\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ e52ap.BDNYB:8!null\n" +
" │ │ └─ oxxei.BDNYB:1!null\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: oxxei\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (126-132)\n" +
" │ │ ├─ tableId: 15\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.5 (decimal(2,1)) 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" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ vc.id:18!null\n" +
" │ │ │ └─ w2mao.YH4XB:17!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" +
" │ │ │ │ │ ├─ colSet: (1-30)\n" +
" │ │ │ │ │ ├─ tableId: 1\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: YK2GW\n" +
" │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (31-34)\n" +
" │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: THNTS\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: TUPLE(bs.id:2!null)\n" +
" │ │ │ ├─ right-key: TUPLE(mf.GXLUB:1!null)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ ├─ mf.LUEVY:6!null\n" +
" │ │ │ │ │ │ └─ sn.BRQP2:13!null\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" +
" │ │ │ │ │ │ ├─ colSet: (35-51)\n" +
" │ │ │ │ │ │ ├─ tableId: 3\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ │ │ │ └─ columns: [id gxlub luevy m22qn fsdy2 lt7k6 sppyd qcgts]\n" +
" │ │ │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ ├─ colSet: (52-61)\n" +
" │ │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ │ ├─ keys: [mf.M22QN:7!null]\n" +
" │ │ │ │ ├─ colSet: (62-64)\n" +
" │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: TPXBU\n" +
" │ │ │ │ └─ columns: [id btxc5]\n" +
" │ │ │ └─ TableAlias(w2mao)\n" +
" │ │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ │ ├─ keys: [mf.id:4!null]\n" +
" │ │ │ ├─ colSet: (65-67)\n" +
" │ │ │ ├─ tableId: 6\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SEQS3\n" +
" │ │ │ └─ columns: [z7cp5 yh4xb]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(w2mao.YH4XB:17!null)\n" +
" │ │ ├─ right-key: TUPLE(vc.id:0!null)\n" +
" │ │ └─ TableAlias(vc)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: D34QP\n" +
" │ │ ├─ columns: [id znp4p]\n" +
" │ │ ├─ colSet: (68-73)\n" +
" │ │ └─ tableId: 7\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(oxxei.BDNYB:1!null)\n" +
" │ ├─ right-key: TUPLE(e52ap.BDNYB:1!null)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: e52ap\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (133-136)\n" +
" │ ├─ tableId: 16\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.9 (decimal(2,1))\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.9 (decimal(2,1))\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" +
" │ └─ LeftOuterLookupJoin\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" +
" │ │ │ ├─ colSet: (88-97)\n" +
" │ │ │ ├─ tableId: 10\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\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" +
" │ │ ├─ colSet: (98-114)\n" +
" │ │ ├─ tableId: 11\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(nma)\n" +
" │ └─ IndexedTableAccess(TNMXI)\n" +
" │ ├─ index: [TNMXI.id]\n" +
" │ ├─ keys: [nd.HPCMS:22!null]\n" +
" │ ├─ colSet: (115-117)\n" +
" │ ├─ tableId: 12\n" +
" │ └─ Table\n" +
" │ ├─ name: TNMXI\n" +
" │ └─ columns: [id dzlim f3yue]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(oxxei.BDNYB:1!null)\n" +
" ├─ right-key: TUPLE(ckele.LWQ6O:0!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ckele\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (150,151)\n" +
" ├─ tableId: 18\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" +
" ├─ colSet: (137-146)\n" +
" └─ tableId: 17\n" +
"",
ExpectedEstimates: "Sort(ckele.M6T2N ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [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]\n" +
" └─ Project\n" +
" ├─ columns: [oxxei.T4IBQ, oxxei.BDNYB, oxxei.BTXC5, oxxei.Z7CP5, oxxei.vaf, oxxei.QCGTS, oxxei.SNY4H, e52ap.KUXQY, e52ap.BDNYB, e52ap.YHVEZ, e52ap.YAZ4X, ckele.LWQ6O, 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]\n" +
" └─ HashJoin\n" +
" ├─ (ckele.LWQ6O = oxxei.BDNYB)\n" +
" ├─ HashJoin\n" +
" │ ├─ (e52ap.BDNYB = oxxei.BDNYB)\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: oxxei\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, aac.BTXC5 as BTXC5, mf.id as Z7CP5, CASE WHEN (NOT(mf.LT7K6 IS NULL)) THEN mf.LT7K6 ELSE mf.SPPYD END as vaf, CASE WHEN (NOT(mf.QCGTS IS NULL)) THEN mf.QCGTS ELSE 0.5 END as QCGTS, CASE WHEN (vc.ZNP4P = 'L5Q44') THEN 1 ELSE 0 END as SNY4H]\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ (vc.id = w2mao.YH4XB)\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ (mf.GXLUB = bs.id)\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (bs.id)\n" +
" │ │ │ ├─ right-key: (mf.GXLUB)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: (mf.LUEVY = sn.BRQP2)\n" +
" │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ ├─ (mf.FSDY2 HASH IN ('SRARY', 'UBQWG'))\n" +
" │ │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id gxlub luevy m22qn fsdy2 lt7k6 sppyd qcgts]\n" +
" │ │ │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ │ ├─ columns: [id btxc5]\n" +
" │ │ │ │ └─ keys: mf.M22QN\n" +
" │ │ │ └─ TableAlias(w2mao)\n" +
" │ │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ │ ├─ columns: [z7cp5 yh4xb]\n" +
" │ │ │ └─ keys: mf.id\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: (w2mao.YH4XB)\n" +
" │ │ ├─ right-key: (vc.id)\n" +
" │ │ └─ TableAlias(vc)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: D34QP\n" +
" │ │ └─ columns: [id znp4p]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (oxxei.BDNYB)\n" +
" │ ├─ right-key: (e52ap.BDNYB)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: e52ap\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [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]\n" +
" │ └─ Sort(sn.id ASC)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nma.id, nma.DZLIM, nma.F3YUE, 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]\n" +
" │ └─ Filter\n" +
" │ ├─ (NOT((nma.DZLIM = 'Q5I4E')))\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: (sn.BRQP2 = nd.id)\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[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" +
" │ ├─ columns: [id dzlim f3yue]\n" +
" │ └─ keys: nd.HPCMS\n" +
" └─ HashLookup\n" +
" ├─ left-key: (oxxei.BDNYB)\n" +
" ├─ right-key: (ckele.LWQ6O)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ckele\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [noxn3.id as LWQ6O, row_number() over ( order by noxn3.id asc) as M6T2N]\n" +
" └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\n" +
"",
ExpectedAnalysis: "Sort(ckele.M6T2N ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [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]\n" +
" └─ Project\n" +
" ├─ columns: [oxxei.T4IBQ, oxxei.BDNYB, oxxei.BTXC5, oxxei.Z7CP5, oxxei.vaf, oxxei.QCGTS, oxxei.SNY4H, e52ap.KUXQY, e52ap.BDNYB, e52ap.YHVEZ, e52ap.YAZ4X, ckele.LWQ6O, 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]\n" +
" └─ HashJoin\n" +
" ├─ (ckele.LWQ6O = oxxei.BDNYB)\n" +
" ├─ HashJoin\n" +
" │ ├─ (e52ap.BDNYB = oxxei.BDNYB)\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: oxxei\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, aac.BTXC5 as BTXC5, mf.id as Z7CP5, CASE WHEN (NOT(mf.LT7K6 IS NULL)) THEN mf.LT7K6 ELSE mf.SPPYD END as vaf, CASE WHEN (NOT(mf.QCGTS IS NULL)) THEN mf.QCGTS ELSE 0.5 END as QCGTS, CASE WHEN (vc.ZNP4P = 'L5Q44') THEN 1 ELSE 0 END as SNY4H]\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ (vc.id = w2mao.YH4XB)\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ (mf.GXLUB = bs.id)\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (bs.id)\n" +
" │ │ │ ├─ right-key: (mf.GXLUB)\n" +
" │ │ │ └─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ ├─ cmp: (mf.LUEVY = sn.BRQP2)\n" +
" │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ ├─ (mf.FSDY2 HASH IN ('SRARY', 'UBQWG'))\n" +
" │ │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id gxlub luevy m22qn fsdy2 lt7k6 sppyd qcgts]\n" +
" │ │ │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ │ ├─ columns: [id btxc5]\n" +
" │ │ │ │ └─ keys: mf.M22QN\n" +
" │ │ │ └─ TableAlias(w2mao)\n" +
" │ │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ │ ├─ columns: [z7cp5 yh4xb]\n" +
" │ │ │ └─ keys: mf.id\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: (w2mao.YH4XB)\n" +
" │ │ ├─ right-key: (vc.id)\n" +
" │ │ └─ TableAlias(vc)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: D34QP\n" +
" │ │ └─ columns: [id znp4p]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (oxxei.BDNYB)\n" +
" │ ├─ right-key: (e52ap.BDNYB)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: e52ap\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [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]\n" +
" │ └─ Sort(sn.id ASC)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nma.id, nma.DZLIM, nma.F3YUE, 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]\n" +
" │ └─ Filter\n" +
" │ ├─ (NOT((nma.DZLIM = 'Q5I4E')))\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: (sn.BRQP2 = nd.id)\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[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" +
" │ ├─ columns: [id dzlim f3yue]\n" +
" │ └─ keys: nd.HPCMS\n" +
" └─ HashLookup\n" +
" ├─ left-key: (oxxei.BDNYB)\n" +
" ├─ right-key: (ckele.LWQ6O)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ckele\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [noxn3.id as LWQ6O, row_number() over ( order by noxn3.id asc) as M6T2N]\n" +
" └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\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: "Sort(ckele.M6T2N:4!null ASC nullsFirst)\n" +
" └─ 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" +
" └─ Project\n" +
" ├─ columns: [oxxei.T4IBQ:0!null, oxxei.BDNYB:1!null, oxxei.BTXC5:2, oxxei.Z7CP5:3!null, oxxei.vaf:4, oxxei.QCGTS:5, oxxei.SNY4H:6!null, e52ap.KUXQY:7!null, e52ap.BDNYB:8!null, e52ap.YHVEZ:9!null, e52ap.YAZ4X:10!null, ckele.LWQ6O:11!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" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ ckele.LWQ6O:11!null\n" +
" │ └─ oxxei.BDNYB:1!null\n" +
" ├─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ e52ap.BDNYB:8!null\n" +
" │ │ └─ oxxei.BDNYB:1!null\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: oxxei\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (126-132)\n" +
" │ │ ├─ tableId: 15\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [cla.FTQLQ:15!null as T4IBQ, sn.id:0!null as BDNYB, aac.BTXC5:13 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.5 (decimal(2,1)) 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" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ vc.id:18!null\n" +
" │ │ │ └─ w2mao.YH4XB:11!null\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ mf.GXLUB:3!null\n" +
" │ │ │ │ └─ bs.id:16!null\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (52-61)\n" +
" │ │ │ │ │ │ │ └─ tableId: 4\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" +
" │ │ │ │ │ │ ├─ keys: [sn.BRQP2:1!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (35-51)\n" +
" │ │ │ │ │ │ ├─ tableId: 3\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: HGMQ6\n" +
" │ │ │ │ │ │ └─ columns: [id gxlub luevy m22qn fsdy2 lt7k6 sppyd qcgts]\n" +
" │ │ │ │ │ └─ TableAlias(w2mao)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ │ │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ │ │ │ ├─ keys: [mf.id:2!null]\n" +
" │ │ │ │ │ ├─ colSet: (65-67)\n" +
" │ │ │ │ │ ├─ tableId: 6\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: SEQS3\n" +
" │ │ │ │ │ └─ columns: [z7cp5 yh4xb]\n" +
" │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ │ ├─ keys: [mf.M22QN:5!null]\n" +
" │ │ │ │ ├─ colSet: (62-64)\n" +
" │ │ │ │ ├─ tableId: 5\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:14!null\n" +
" │ │ │ │ └─ bs.IXUXU:17\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" +
" │ │ │ │ ├─ colSet: (1-30)\n" +
" │ │ │ │ ├─ tableId: 1\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: YK2GW\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (31-34)\n" +
" │ │ │ ├─ tableId: 2\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: TUPLE(w2mao.YH4XB:11!null)\n" +
" │ │ ├─ right-key: TUPLE(vc.id:0!null)\n" +
" │ │ └─ TableAlias(vc)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: D34QP\n" +
" │ │ ├─ columns: [id znp4p]\n" +
" │ │ ├─ colSet: (68-73)\n" +
" │ │ └─ tableId: 7\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(oxxei.BDNYB:1!null)\n" +
" │ ├─ right-key: TUPLE(e52ap.BDNYB:1!null)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: e52ap\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (133-136)\n" +
" │ ├─ tableId: 16\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.9 (decimal(2,1))\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.9 (decimal(2,1))\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" +
" │ └─ LeftOuterLookupJoin\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" +
" │ │ │ ├─ colSet: (88-97)\n" +
" │ │ │ ├─ tableId: 10\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\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" +
" │ │ ├─ colSet: (98-114)\n" +
" │ │ ├─ tableId: 11\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(nma)\n" +
" │ └─ IndexedTableAccess(TNMXI)\n" +
" │ ├─ index: [TNMXI.id]\n" +
" │ ├─ keys: [nd.HPCMS:22!null]\n" +
" │ ├─ colSet: (115-117)\n" +
" │ ├─ tableId: 12\n" +
" │ └─ Table\n" +
" │ ├─ name: TNMXI\n" +
" │ └─ columns: [id dzlim f3yue]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(oxxei.BDNYB:1!null)\n" +
" ├─ right-key: TUPLE(ckele.LWQ6O:0!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ckele\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (150,151)\n" +
" ├─ tableId: 18\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" +
" ├─ colSet: (137-146)\n" +
" └─ tableId: 17\n" +
"",
ExpectedEstimates: "Sort(ckele.M6T2N ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [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]\n" +
" └─ Project\n" +
" ├─ columns: [oxxei.T4IBQ, oxxei.BDNYB, oxxei.BTXC5, oxxei.Z7CP5, oxxei.vaf, oxxei.QCGTS, oxxei.SNY4H, e52ap.KUXQY, e52ap.BDNYB, e52ap.YHVEZ, e52ap.YAZ4X, ckele.LWQ6O, 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]\n" +
" └─ HashJoin\n" +
" ├─ (ckele.LWQ6O = oxxei.BDNYB)\n" +
" ├─ HashJoin\n" +
" │ ├─ (e52ap.BDNYB = oxxei.BDNYB)\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: oxxei\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, aac.BTXC5 as BTXC5, mf.id as Z7CP5, CASE WHEN (NOT(mf.LT7K6 IS NULL)) THEN mf.LT7K6 ELSE mf.SPPYD END as vaf, CASE WHEN (NOT(mf.QCGTS IS NULL)) THEN mf.QCGTS ELSE 0.5 END as QCGTS, CASE WHEN (vc.ZNP4P = 'L5Q44') THEN 1 ELSE 0 END as SNY4H]\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ (vc.id = w2mao.YH4XB)\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ (mf.GXLUB = bs.id)\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ (mf.FSDY2 HASH IN ('SRARY', 'UBQWG'))\n" +
" │ │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ │ │ ├─ columns: [id gxlub luevy m22qn fsdy2 lt7k6 sppyd qcgts]\n" +
" │ │ │ │ │ │ └─ keys: sn.BRQP2\n" +
" │ │ │ │ │ └─ TableAlias(w2mao)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ │ │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ │ │ │ ├─ columns: [z7cp5 yh4xb]\n" +
" │ │ │ │ │ └─ keys: mf.id\n" +
" │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ │ ├─ columns: [id btxc5]\n" +
" │ │ │ │ └─ keys: mf.M22QN\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (mf.GXLUB)\n" +
" │ │ │ ├─ right-key: (bs.id)\n" +
" │ │ │ └─ MergeJoin\n" +
" │ │ │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ │ │ ├─ Filter\n" +
" │ │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: (w2mao.YH4XB)\n" +
" │ │ ├─ right-key: (vc.id)\n" +
" │ │ └─ TableAlias(vc)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: D34QP\n" +
" │ │ └─ columns: [id znp4p]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (oxxei.BDNYB)\n" +
" │ ├─ right-key: (e52ap.BDNYB)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: e52ap\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [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]\n" +
" │ └─ Sort(sn.id ASC)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nma.id, nma.DZLIM, nma.F3YUE, 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]\n" +
" │ └─ Filter\n" +
" │ ├─ (NOT((nma.DZLIM = 'Q5I4E')))\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: (sn.BRQP2 = nd.id)\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[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" +
" │ ├─ columns: [id dzlim f3yue]\n" +
" │ └─ keys: nd.HPCMS\n" +
" └─ HashLookup\n" +
" ├─ left-key: (oxxei.BDNYB)\n" +
" ├─ right-key: (ckele.LWQ6O)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ckele\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [noxn3.id as LWQ6O, row_number() over ( order by noxn3.id asc) as M6T2N]\n" +
" └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\n" +
"",
ExpectedAnalysis: "Sort(ckele.M6T2N ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [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]\n" +
" └─ Project\n" +
" ├─ columns: [oxxei.T4IBQ, oxxei.BDNYB, oxxei.BTXC5, oxxei.Z7CP5, oxxei.vaf, oxxei.QCGTS, oxxei.SNY4H, e52ap.KUXQY, e52ap.BDNYB, e52ap.YHVEZ, e52ap.YAZ4X, ckele.LWQ6O, 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]\n" +
" └─ HashJoin\n" +
" ├─ (ckele.LWQ6O = oxxei.BDNYB)\n" +
" ├─ HashJoin\n" +
" │ ├─ (e52ap.BDNYB = oxxei.BDNYB)\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: oxxei\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, aac.BTXC5 as BTXC5, mf.id as Z7CP5, CASE WHEN (NOT(mf.LT7K6 IS NULL)) THEN mf.LT7K6 ELSE mf.SPPYD END as vaf, CASE WHEN (NOT(mf.QCGTS IS NULL)) THEN mf.QCGTS ELSE 0.5 END as QCGTS, CASE WHEN (vc.ZNP4P = 'L5Q44') THEN 1 ELSE 0 END as SNY4H]\n" +
" │ │ └─ HashJoin\n" +
" │ │ ├─ (vc.id = w2mao.YH4XB)\n" +
" │ │ ├─ HashJoin\n" +
" │ │ │ ├─ (mf.GXLUB = bs.id)\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ ├─ TableAlias(sn)\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ (mf.FSDY2 HASH IN ('SRARY', 'UBQWG'))\n" +
" │ │ │ │ │ │ └─ TableAlias(mf)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ │ │ │ ├─ columns: [id gxlub luevy m22qn fsdy2 lt7k6 sppyd qcgts]\n" +
" │ │ │ │ │ │ └─ keys: sn.BRQP2\n" +
" │ │ │ │ │ └─ TableAlias(w2mao)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(SEQS3)\n" +
" │ │ │ │ │ ├─ index: [SEQS3.Z7CP5]\n" +
" │ │ │ │ │ ├─ columns: [z7cp5 yh4xb]\n" +
" │ │ │ │ │ └─ keys: mf.id\n" +
" │ │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ │ ├─ columns: [id btxc5]\n" +
" │ │ │ │ └─ keys: mf.M22QN\n" +
" │ │ │ └─ HashLookup\n" +
" │ │ │ ├─ left-key: (mf.GXLUB)\n" +
" │ │ │ ├─ right-key: (bs.id)\n" +
" │ │ │ └─ MergeJoin\n" +
" │ │ │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ │ │ ├─ Filter\n" +
" │ │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ └─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ HashLookup\n" +
" │ │ ├─ left-key: (w2mao.YH4XB)\n" +
" │ │ ├─ right-key: (vc.id)\n" +
" │ │ └─ TableAlias(vc)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: D34QP\n" +
" │ │ └─ columns: [id znp4p]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (oxxei.BDNYB)\n" +
" │ ├─ right-key: (e52ap.BDNYB)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: e52ap\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [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]\n" +
" │ └─ Sort(sn.id ASC)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nma.id, nma.DZLIM, nma.F3YUE, 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]\n" +
" │ └─ Filter\n" +
" │ ├─ (NOT((nma.DZLIM = 'Q5I4E')))\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: (sn.BRQP2 = nd.id)\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[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" +
" │ ├─ columns: [id dzlim f3yue]\n" +
" │ └─ keys: nd.HPCMS\n" +
" └─ HashLookup\n" +
" ├─ left-key: (oxxei.BDNYB)\n" +
" ├─ right-key: (ckele.LWQ6O)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: ckele\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [noxn3.id as LWQ6O, row_number() over ( order by noxn3.id asc) as M6T2N]\n" +
" └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\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" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.QNI57\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (223,224)\n" +
" │ ├─ tableId: 27\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:10!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.TDEIU\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (225,226)\n" +
" │ ├─ tableId: 28\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\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:21!null, mf.LUEVY:22!null, mf.M22QN:23!null, aac.id:24!null, aac.BTXC5:25, aac.FHCYT:26, mf.FTQLQ:21!null as T4IBQ, CASE WHEN NOT\n" +
" │ └─ mjr3d.QNI57:9!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.QNI57\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (223,224)\n" +
" │ ├─ tableId: 27\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:10!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.TDEIU\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (225,226)\n" +
" │ ├─ tableId: 28\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\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]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ aac.id:24!null\n" +
" │ └─ mjr3d.M22QN:3!null\n" +
" ├─ HashJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ mf.LUEVY:22!null\n" +
" │ │ │ └─ sn.BRQP2:12!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ mf.M22QN:23!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" +
" │ │ │ │ │ ├─ alias-string: select JTEHG.id from NOXN3 as JTEHG where BRQP2 = MJR3D.BJUF2\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" +
" │ │ │ │ │ ├─ keys: [mjr3d.BJUF2:1!null]\n" +
" │ │ │ │ │ ├─ colSet: (132-141)\n" +
" │ │ │ │ │ ├─ tableId: 18\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: NOXN3\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" +
" │ │ │ │ ├─ alias-string: select XMAFZ.id from NOXN3 as XMAFZ where BRQP2 = MJR3D.FJDP5\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" +
" │ │ │ │ ├─ keys: [mjr3d.FJDP5:0!null]\n" +
" │ │ │ │ ├─ colSet: (142-151)\n" +
" │ │ │ │ ├─ tableId: 19\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\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" +
" │ │ │ ├─ alias-string: select XMAFZ.id from NOXN3 as XMAFZ where BRQP2 = MJR3D.BJUF2\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" +
" │ │ │ ├─ keys: [mjr3d.BJUF2:1!null]\n" +
" │ │ │ ├─ colSet: (152-161)\n" +
" │ │ │ ├─ tableId: 20\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: mjr3d\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (111-121)\n" +
" │ │ │ ├─ tableId: 16\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, TDEIU:10 as TDEIU]\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" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ ├─ colSet: (87-97)\n" +
" │ │ │ │ │ ├─ tableId: 10\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:0!null as FJDP5, cpmfe.id:12!null as BJUF2, cpmfe.TW55N:13!null as PSMU6, ism.M22QN:2!null as M22QN, g3yxs.GE5EL:8, g3yxs.F7A4Q:9, g3yxs.ESFVY:6!null, CASE WHEN IN\n" +
" │ │ │ │ │ │ ├─ left: g3yxs.SL76B:7!null\n" +
" │ │ │ │ │ │ └─ right: TUPLE(FO422 (longtext), SJ53H (longtext))\n" +
" │ │ │ │ │ │ THEN 0 (tinyint) WHEN IN\n" +
" │ │ │ │ │ │ ├─ left: g3yxs.SL76B:7!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:7!null\n" +
" │ │ │ │ │ │ └─ right: TUPLE(QJEXM (longtext), J6S7P (longtext), VT7FI (longtext))\n" +
" │ │ │ │ │ │ THEN 2 (tinyint) WHEN IN\n" +
" │ │ │ │ │ │ ├─ left: g3yxs.SL76B:7!null\n" +
" │ │ │ │ │ │ └─ right: TUPLE(Y62X7 (longtext))\n" +
" │ │ │ │ │ │ THEN 3 (tinyint) END as CC4AX, g3yxs.SL76B:7!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" +
" │ │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ yvhjz.BRQP2:19!null\n" +
" │ │ │ │ │ │ └─ ism.UJ6XY:1!null\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ yqif4.BRQP2:16!null\n" +
" │ │ │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ cpmfe.id:12!null\n" +
" │ │ │ │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ │ ├─ nhmxw.id:10!null\n" +
" │ │ │ │ │ │ │ │ │ └─ ism.PRUV2:4\n" +
" │ │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ ism.NZ4MQ:3!null\n" +
" │ │ │ │ │ │ │ │ │ │ └─ g3yxs.id:5!null\n" +
" │ │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ colSet: (15-23)\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ name: HDDVB\n" +
" │ │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ ├─ colSet: (24-31)\n" +
" │ │ │ │ │ │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ │ ├─ name: YYBCX\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:4)\n" +
" │ │ │ │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ │ │ │ ├─ columns: [id nohhr]\n" +
" │ │ │ │ │ │ │ │ ├─ colSet: (32-41)\n" +
" │ │ │ │ │ │ │ │ └─ tableId: 6\n" +
" │ │ │ │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ │ │ ├─ keys: [nhmxw.NOHHR:11!null]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (42-58)\n" +
" │ │ │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ │ │ └─ columns: [id tw55n zh72s]\n" +
" │ │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ │ ├─ keys: [ism.UJ6XY:1!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (59-68)\n" +
" │ │ │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ keys: [ism.FV24E:0!null]\n" +
" │ │ │ │ │ ├─ colSet: (69-78)\n" +
" │ │ │ │ │ ├─ tableId: 9\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" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ ├─ colSet: (87-97)\n" +
" │ │ │ │ ├─ tableId: 10\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:0!null as FJDP5, cpmfe.id:12!null as BJUF2, cpmfe.TW55N:13!null as PSMU6, ism.M22QN:2!null as M22QN, g3yxs.GE5EL:8, g3yxs.F7A4Q:9, g3yxs.ESFVY:6!null, CASE WHEN IN\n" +
" │ │ │ │ │ ├─ left: g3yxs.SL76B:7!null\n" +
" │ │ │ │ │ └─ right: TUPLE(FO422 (longtext), SJ53H (longtext))\n" +
" │ │ │ │ │ THEN 0 (tinyint) WHEN IN\n" +
" │ │ │ │ │ ├─ left: g3yxs.SL76B:7!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:7!null\n" +
" │ │ │ │ │ └─ right: TUPLE(QJEXM (longtext), J6S7P (longtext), VT7FI (longtext))\n" +
" │ │ │ │ │ THEN 2 (tinyint) WHEN IN\n" +
" │ │ │ │ │ ├─ left: g3yxs.SL76B:7!null\n" +
" │ │ │ │ │ └─ right: TUPLE(Y62X7 (longtext))\n" +
" │ │ │ │ │ THEN 3 (tinyint) END as CC4AX, g3yxs.SL76B:7!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" +
" │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ yvhjz.BRQP2:19!null\n" +
" │ │ │ │ │ └─ ism.UJ6XY:1!null\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ yqif4.BRQP2:16!null\n" +
" │ │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ │ ├─ cpmfe.id:12!null\n" +
" │ │ │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ nhmxw.id:10!null\n" +
" │ │ │ │ │ │ │ │ └─ ism.PRUV2:4\n" +
" │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ │ ├─ ism.NZ4MQ:3!null\n" +
" │ │ │ │ │ │ │ │ │ └─ g3yxs.id:5!null\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ ├─ colSet: (15-23)\n" +
" │ │ │ │ │ │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ │ ├─ name: HDDVB\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ ├─ colSet: (24-31)\n" +
" │ │ │ │ │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ ├─ name: YYBCX\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:4)\n" +
" │ │ │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ │ │ ├─ columns: [id nohhr]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (32-41)\n" +
" │ │ │ │ │ │ │ └─ tableId: 6\n" +
" │ │ │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ │ ├─ keys: [nhmxw.NOHHR:11!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (42-58)\n" +
" │ │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ │ └─ columns: [id tw55n zh72s]\n" +
" │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ keys: [ism.UJ6XY:1!null]\n" +
" │ │ │ │ │ ├─ colSet: (59-68)\n" +
" │ │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ keys: [ism.FV24E:0!null]\n" +
" │ │ │ │ ├─ colSet: (69-78)\n" +
" │ │ │ │ ├─ tableId: 9\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, convert\n" +
" │ │ │ │ ├─ type: char\n" +
" │ │ │ │ └─ jchir.TDEIU:10!null\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, NULL (null) as QNI57, jchir.TDEIU:10!null]\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: jchir\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (87-97)\n" +
" │ │ │ ├─ tableId: 10\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:0!null as FJDP5, cpmfe.id:12!null as BJUF2, cpmfe.TW55N:13!null as PSMU6, ism.M22QN:2!null as M22QN, g3yxs.GE5EL:8, g3yxs.F7A4Q:9, g3yxs.ESFVY:6!null, CASE WHEN IN\n" +
" │ │ │ │ ├─ left: g3yxs.SL76B:7!null\n" +
" │ │ │ │ └─ right: TUPLE(FO422 (longtext), SJ53H (longtext))\n" +
" │ │ │ │ THEN 0 (tinyint) WHEN IN\n" +
" │ │ │ │ ├─ left: g3yxs.SL76B:7!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:7!null\n" +
" │ │ │ │ └─ right: TUPLE(QJEXM (longtext), J6S7P (longtext), VT7FI (longtext))\n" +
" │ │ │ │ THEN 2 (tinyint) WHEN IN\n" +
" │ │ │ │ ├─ left: g3yxs.SL76B:7!null\n" +
" │ │ │ │ └─ right: TUPLE(Y62X7 (longtext))\n" +
" │ │ │ │ THEN 3 (tinyint) END as CC4AX, g3yxs.SL76B:7!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" +
" │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ yvhjz.BRQP2:19!null\n" +
" │ │ │ │ └─ ism.UJ6XY:1!null\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ yqif4.BRQP2:16!null\n" +
" │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ cpmfe.id:12!null\n" +
" │ │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ nhmxw.id:10!null\n" +
" │ │ │ │ │ │ │ └─ ism.PRUV2:4\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ ├─ ism.NZ4MQ:3!null\n" +
" │ │ │ │ │ │ │ │ └─ g3yxs.id:5!null\n" +
" │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ ├─ colSet: (15-23)\n" +
" │ │ │ │ │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ ├─ name: HDDVB\n" +
" │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (24-31)\n" +
" │ │ │ │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: YYBCX\n" +
" │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:4)\n" +
" │ │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ │ ├─ columns: [id nohhr]\n" +
" │ │ │ │ │ │ ├─ colSet: (32-41)\n" +
" │ │ │ │ │ │ └─ tableId: 6\n" +
" │ │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ ├─ keys: [nhmxw.NOHHR:11!null]\n" +
" │ │ │ │ │ ├─ colSet: (42-58)\n" +
" │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ └─ columns: [id tw55n zh72s]\n" +
" │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ keys: [ism.UJ6XY:1!null]\n" +
" │ │ │ │ ├─ colSet: (59-68)\n" +
" │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ keys: [ism.FV24E:0!null]\n" +
" │ │ │ ├─ colSet: (69-78)\n" +
" │ │ │ ├─ tableId: 9\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ ProcessTable\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)\n" +
" │ ├─ right-key: TUPLE(mf.LUEVY:1!null, mf.M22QN:2!null)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: mf\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (213-215)\n" +
" │ ├─ tableId: 24\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:4!null, mf.LUEVY:1!null, mf.M22QN:2!null]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ bs.id:5!null\n" +
" │ │ └─ mf.GXLUB:0!null\n" +
" │ ├─ TableAlias(mf)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HGMQ6\n" +
" │ │ ├─ columns: [gxlub luevy m22qn]\n" +
" │ │ ├─ colSet: (196-212)\n" +
" │ │ └─ tableId: 23\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.GXLUB:0!null)\n" +
" │ ├─ right-key: TUPLE(bs.id:2!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ cla.id:3!null\n" +
" │ │ └─ bs.IXUXU:6\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" +
" │ │ ├─ colSet: (162-191)\n" +
" │ │ ├─ tableId: 21\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YK2GW\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (192-195)\n" +
" │ ├─ tableId: 22\n" +
" │ └─ Table\n" +
" │ ├─ name: THNTS\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(mjr3d.M22QN:3!null)\n" +
" ├─ right-key: TUPLE(aac.id:0!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: aac\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (219-221)\n" +
" ├─ tableId: 26\n" +
" └─ Table\n" +
" ├─ name: TPXBU\n" +
" ├─ columns: [id btxc5 fhcyt]\n" +
" ├─ colSet: (216-218)\n" +
" └─ tableId: 25\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [mf.FTQLQ as T4IBQ, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, mjr3d.GE5EL as GE5EL, mjr3d.F7A4Q as F7A4Q, mjr3d.CC4AX as CC4AX, mjr3d.SL76B as SL76B, aac.BTXC5 as YEBDJ, mjr3d.PSMU6]\n" +
" └─ Project\n" +
" ├─ columns: [mjr3d.FJDP5, mjr3d.BJUF2, mjr3d.PSMU6, mjr3d.M22QN, mjr3d.GE5EL, mjr3d.F7A4Q, mjr3d.ESFVY, mjr3d.CC4AX, mjr3d.SL76B, mjr3d.QNI57, mjr3d.TDEIU, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, mf.FTQLQ, mf.LUEVY, mf.M22QN, aac.id, aac.BTXC5, aac.FHCYT, mf.FTQLQ as T4IBQ, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, mjr3d.GE5EL as GE5EL, mjr3d.F7A4Q as F7A4Q, mjr3d.CC4AX as CC4AX, mjr3d.SL76B as SL76B, aac.BTXC5 as YEBDJ]\n" +
" └─ HashJoin (estimated cost=427.500 rows=125)\n" +
" ├─ (aac.id = mjr3d.M22QN)\n" +
" ├─ HashJoin (estimated cost=427.500 rows=125)\n" +
" │ ├─ ((mf.LUEVY = sn.BRQP2) AND (mf.M22QN = mjr3d.M22QN))\n" +
" │ ├─ LeftOuterJoin (estimated cost=1193112.000 rows=125)\n" +
" │ │ ├─ ((((((NOT(mjr3d.QNI57 IS NULL)) AND (sn.id = mjr3d.QNI57)) AND mjr3d.BJUF2 IS NULL) OR (((NOT(mjr3d.QNI57 IS NULL)) AND (NOT(mjr3d.BJUF2 IS NULL))) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jtehg.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (jtehg.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ )) OR (((NOT(mjr3d.TDEIU IS NULL)) AND mjr3d.BJUF2 IS NULL) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.FJDP5)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.FJDP5\n" +
" │ │ │ )) OR (((NOT(mjr3d.TDEIU IS NULL)) AND (NOT(mjr3d.BJUF2 IS NULL))) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ ))\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: mjr3d\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Union distinct\n" +
" │ │ │ ├─ Project\n" +
" │ │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, convert(jchir.QNI57, char) as QNI57, TDEIU as TDEIU]\n" +
" │ │ │ │ └─ Union distinct\n" +
" │ │ │ │ ├─ Project\n" +
" │ │ │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, jchir.QNI57, convert(jchir.TDEIU, char) as TDEIU]\n" +
" │ │ │ │ │ └─ SubqueryAlias\n" +
" │ │ │ │ │ ├─ name: jchir\n" +
" │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ (((NOT(QNI57 IS NULL)) AND TDEIU IS NULL) OR (QNI57 IS NULL AND (NOT(TDEIU IS NULL))))\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [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]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ │ │ │ ├─ right-key: (nhmxw.id)\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" +
" │ │ │ │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ └─ keys: ism.FV24E\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, jchir.QNI57, convert(TDEIU, char) as TDEIU]\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, jchir.QNI57, NULL as TDEIU]\n" +
" │ │ │ │ └─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: jchir\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ ((NOT(QNI57 IS NULL)) AND (NOT(TDEIU IS NULL)))\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [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]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ right-key: (nhmxw.id)\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" +
" │ │ │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ keys: ism.FV24E\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, convert(QNI57, char) as QNI57, convert(jchir.TDEIU, char) as TDEIU]\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, NULL as QNI57, jchir.TDEIU]\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: jchir\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ ((NOT(QNI57 IS NULL)) AND (NOT(TDEIU IS NULL)))\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [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]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ │ ├─ right-key: (nhmxw.id)\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" +
" │ │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ keys: ism.FV24E\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: NOXN3\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (sn.BRQP2, mjr3d.M22QN)\n" +
" │ ├─ right-key: (mf.LUEVY, mf.M22QN)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: mf\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ, mf.LUEVY, mf.M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (bs.id = mf.GXLUB)\n" +
" │ ├─ TableAlias(mf)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HGMQ6\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (mf.GXLUB)\n" +
" │ ├─ right-key: (bs.id)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ ├─ Filter\n" +
" │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (mjr3d.M22QN)\n" +
" ├─ right-key: (aac.id)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: aac\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Table\n" +
" ├─ name: TPXBU\n" +
" └─ columns: [id btxc5 fhcyt]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [mf.FTQLQ as T4IBQ, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, mjr3d.GE5EL as GE5EL, mjr3d.F7A4Q as F7A4Q, mjr3d.CC4AX as CC4AX, mjr3d.SL76B as SL76B, aac.BTXC5 as YEBDJ, mjr3d.PSMU6]\n" +
" └─ Project\n" +
" ├─ columns: [mjr3d.FJDP5, mjr3d.BJUF2, mjr3d.PSMU6, mjr3d.M22QN, mjr3d.GE5EL, mjr3d.F7A4Q, mjr3d.ESFVY, mjr3d.CC4AX, mjr3d.SL76B, mjr3d.QNI57, mjr3d.TDEIU, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, mf.FTQLQ, mf.LUEVY, mf.M22QN, aac.id, aac.BTXC5, aac.FHCYT, mf.FTQLQ as T4IBQ, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, mjr3d.GE5EL as GE5EL, mjr3d.F7A4Q as F7A4Q, mjr3d.CC4AX as CC4AX, mjr3d.SL76B as SL76B, aac.BTXC5 as YEBDJ]\n" +
" └─ HashJoin (estimated cost=427.500 rows=125) (actual rows=0 loops=1)\n" +
" ├─ (aac.id = mjr3d.M22QN)\n" +
" ├─ HashJoin (estimated cost=427.500 rows=125) (actual rows=0 loops=1)\n" +
" │ ├─ ((mf.LUEVY = sn.BRQP2) AND (mf.M22QN = mjr3d.M22QN))\n" +
" │ ├─ LeftOuterJoin (estimated cost=1193112.000 rows=125) (actual rows=0 loops=1)\n" +
" │ │ ├─ ((((((NOT(mjr3d.QNI57 IS NULL)) AND (sn.id = mjr3d.QNI57)) AND mjr3d.BJUF2 IS NULL) OR (((NOT(mjr3d.QNI57 IS NULL)) AND (NOT(mjr3d.BJUF2 IS NULL))) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jtehg.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (jtehg.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ )) OR (((NOT(mjr3d.TDEIU IS NULL)) AND mjr3d.BJUF2 IS NULL) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.FJDP5)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.FJDP5\n" +
" │ │ │ )) OR (((NOT(mjr3d.TDEIU IS NULL)) AND (NOT(mjr3d.BJUF2 IS NULL))) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ ))\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: mjr3d\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Union distinct\n" +
" │ │ │ ├─ Project\n" +
" │ │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, convert(jchir.QNI57, char) as QNI57, TDEIU as TDEIU]\n" +
" │ │ │ │ └─ Union distinct\n" +
" │ │ │ │ ├─ Project\n" +
" │ │ │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, jchir.QNI57, convert(jchir.TDEIU, char) as TDEIU]\n" +
" │ │ │ │ │ └─ SubqueryAlias\n" +
" │ │ │ │ │ ├─ name: jchir\n" +
" │ │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ (((NOT(QNI57 IS NULL)) AND TDEIU IS NULL) OR (QNI57 IS NULL AND (NOT(TDEIU IS NULL))))\n" +
" │ │ │ │ │ └─ Project\n" +
" │ │ │ │ │ ├─ columns: [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]\n" +
" │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ │ │ │ ├─ right-key: (nhmxw.id)\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" +
" │ │ │ │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ └─ keys: ism.FV24E\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, jchir.QNI57, convert(TDEIU, char) as TDEIU]\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, jchir.QNI57, NULL as TDEIU]\n" +
" │ │ │ │ └─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: jchir\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ ((NOT(QNI57 IS NULL)) AND (NOT(TDEIU IS NULL)))\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [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]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ right-key: (nhmxw.id)\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" +
" │ │ │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ keys: ism.FV24E\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, convert(QNI57, char) as QNI57, convert(jchir.TDEIU, char) as TDEIU]\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jchir.FJDP5, jchir.BJUF2, jchir.PSMU6, jchir.M22QN, jchir.GE5EL, jchir.F7A4Q, jchir.ESFVY, jchir.CC4AX, jchir.SL76B, NULL as QNI57, jchir.TDEIU]\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: jchir\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ ((NOT(QNI57 IS NULL)) AND (NOT(TDEIU IS NULL)))\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [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]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [id esfvy sl76b ge5el f7a4q]\n" +
" │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ │ ├─ right-key: (nhmxw.id)\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" +
" │ │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ keys: ism.FV24E\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: NOXN3\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (sn.BRQP2, mjr3d.M22QN)\n" +
" │ ├─ right-key: (mf.LUEVY, mf.M22QN)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: mf\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ, mf.LUEVY, mf.M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (bs.id = mf.GXLUB)\n" +
" │ ├─ TableAlias(mf)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HGMQ6\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (mf.GXLUB)\n" +
" │ ├─ right-key: (bs.id)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ ├─ Filter\n" +
" │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (mjr3d.M22QN)\n" +
" ├─ right-key: (aac.id)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: aac\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Table\n" +
" ├─ name: TPXBU\n" +
" └─ columns: [id btxc5 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 /*+ 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" +
" └─ Project\n" +
" ├─ columns: [fs.T4IBQ:0!null, fs.M6T2N:1, fs.BTXC5:2, fs.TUV25:3]\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ zmspr.T4IBQ:4!null IS NULL\n" +
" │ │ │ └─ zmspr.M6T2N:5 IS NULL\n" +
" │ │ └─ zmspr.BTXC5:6 IS NULL\n" +
" │ └─ zmspr.TUV25:7 IS NULL\n" +
" └─ LeftOuterHashJoinExcludeNulls\n" +
" ├─ Eq\n" +
" │ ├─ TUPLE(fs.T4IBQ:0!null, fs.M6T2N:1, fs.BTXC5:2, fs.TUV25:3)\n" +
" │ └─ TUPLE(zmspr.T4IBQ:4!null, zmspr.M6T2N:5, zmspr.BTXC5:6, zmspr.TUV25:7)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (252-255)\n" +
" │ ├─ tableId: 36\n" +
" │ └─ Project\n" +
" │ ├─ columns: [rsa3y.T4IBQ:3!null as T4IBQ, jmhie.M6T2N:0 as M6T2N, jmhie.BTXC5:1 as BTXC5, jmhie.TUV25:2 as TUV25]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: jmhie\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (224-226)\n" +
" │ │ ├─ tableId: 28\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jqhrg.M6T2N:0, jqhrg.BTXC5:1, jqhrg.TUV25:4]\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: jqhrg\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (219-223)\n" +
" │ │ ├─ tableId: 26\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [CASE WHEN NOT\n" +
" │ │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ │ THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.QNI57\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" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (210,211)\n" +
" │ │ │ ├─ tableId: 24\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" +
" │ │ │ ├─ colSet: (1-10)\n" +
" │ │ │ └─ tableId: 1\n" +
" │ │ │ WHEN NOT\n" +
" │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ │ THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.TDEIU\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" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (212,213)\n" +
" │ │ │ ├─ tableId: 25\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" +
" │ │ │ ├─ colSet: (1-10)\n" +
" │ │ │ └─ tableId: 1\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" +
" │ │ │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.QNI57\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" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (210,211)\n" +
" │ │ │ ├─ tableId: 24\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" +
" │ │ │ ├─ colSet: (1-10)\n" +
" │ │ │ └─ tableId: 1\n" +
" │ │ │ WHEN NOT\n" +
" │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ │ THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.TDEIU\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" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (212,213)\n" +
" │ │ │ ├─ tableId: 25\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" +
" │ │ │ ├─ colSet: (1-10)\n" +
" │ │ │ └─ tableId: 1\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" +
" │ │ │ │ │ │ ├─ alias-string: select JTEHG.id from NOXN3 as JTEHG where BRQP2 = MJR3D.BJUF2\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" +
" │ │ │ │ │ │ ├─ keys: [mjr3d.BJUF2:1!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (180-189)\n" +
" │ │ │ │ │ │ ├─ tableId: 21\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NOXN3\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" +
" │ │ │ │ │ ├─ alias-string: select XMAFZ.id from NOXN3 as XMAFZ where BRQP2 = MJR3D.FJDP5\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" +
" │ │ │ │ │ ├─ keys: [mjr3d.FJDP5:0!null]\n" +
" │ │ │ │ │ ├─ colSet: (190-199)\n" +
" │ │ │ │ │ ├─ tableId: 22\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: NOXN3\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" +
" │ │ │ │ ├─ alias-string: select XMAFZ.id from NOXN3 as XMAFZ where BRQP2 = MJR3D.BJUF2\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" +
" │ │ │ │ ├─ keys: [mjr3d.BJUF2:1!null]\n" +
" │ │ │ │ ├─ colSet: (200-209)\n" +
" │ │ │ │ ├─ tableId: 23\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: mjr3d\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ ├─ colSet: (160-166)\n" +
" │ │ │ │ ├─ tableId: 18\n" +
" │ │ │ │ └─ Distinct\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [ism.FV24E:0!null as FJDP5, cpmfe.id:10!null as BJUF2, ism.M22QN:2!null as M22QN, g3yxs.TUV25:7 as TUV25, g3yxs.ESFVY:6!null as ESFVY, yqif4.id:12!null as QNI57, yvhjz.id:15!null as TDEIU]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Or\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ yqif4.id:12!null IS NULL\n" +
" │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ └─ yvhjz.id:15!null IS NULL\n" +
" │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ yvhjz.BRQP2:16!null\n" +
" │ │ │ │ │ └─ ism.UJ6XY:1!null\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ yqif4.BRQP2:13!null\n" +
" │ │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ │ ├─ cpmfe.id:10!null\n" +
" │ │ │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ nhmxw.id:8!null\n" +
" │ │ │ │ │ │ │ │ └─ ism.PRUV2:4\n" +
" │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ │ ├─ ism.NZ4MQ:3!null\n" +
" │ │ │ │ │ │ │ │ │ └─ g3yxs.id:5!null\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ ├─ colSet: (15-23)\n" +
" │ │ │ │ │ │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ │ ├─ name: HDDVB\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ │ │ └─ g3yxs.TUV25:2 IS NULL\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ ├─ colSet: (24-31)\n" +
" │ │ │ │ │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ ├─ name: YYBCX\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:4)\n" +
" │ │ │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ │ │ ├─ columns: [id nohhr]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (32-41)\n" +
" │ │ │ │ │ │ │ └─ tableId: 6\n" +
" │ │ │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ │ ├─ keys: [nhmxw.NOHHR:9!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (42-58)\n" +
" │ │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ │ └─ columns: [id zh72s]\n" +
" │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ keys: [ism.UJ6XY:1!null]\n" +
" │ │ │ │ │ ├─ colSet: (59-68)\n" +
" │ │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ keys: [ism.FV24E:0!null]\n" +
" │ │ │ │ ├─ colSet: (69-78)\n" +
" │ │ │ │ ├─ tableId: 9\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ ├─ keys: [mjr3d.M22QN:2!null]\n" +
" │ │ │ ├─ colSet: (167-169)\n" +
" │ │ │ ├─ tableId: 19\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: TPXBU\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" +
" │ │ ├─ colSet: (170-179)\n" +
" │ │ └─ tableId: 20\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE()\n" +
" │ ├─ right-key: TUPLE()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: rsa3y\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (227)\n" +
" │ ├─ tableId: 29\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [htkbs.T4IBQ:0!null]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: htkbs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (157-159)\n" +
" │ ├─ tableId: 16\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:1!null as T4IBQ, sn.id:7!null as BDNYB, mf.M22QN:6!null as M22QN]\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" +
" │ │ │ ├─ colSet: (114-143)\n" +
" │ │ │ ├─ tableId: 14\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: YK2GW\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (110-113)\n" +
" │ │ ├─ tableId: 13\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: THNTS\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(bs.id:2!null)\n" +
" │ ├─ right-key: TUPLE(mf.GXLUB:0!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ mf.LUEVY:5!null\n" +
" │ │ └─ sn.BRQP2:8!null\n" +
" │ ├─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (93-109)\n" +
" │ │ ├─ tableId: 12\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HGMQ6\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (144-153)\n" +
" │ ├─ tableId: 15\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(TUPLE(fs.T4IBQ:0!null, fs.M6T2N:1, fs.BTXC5:2, fs.TUV25:3))\n" +
" ├─ right-key: TUPLE(TUPLE(zmspr.T4IBQ:0!null, zmspr.M6T2N:1, zmspr.BTXC5:2, zmspr.TUV25:3))\n" +
" └─ SubqueryAlias\n" +
" ├─ name: zmspr\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (248-251)\n" +
" ├─ tableId: 34\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (236-238)\n" +
" │ ├─ tableId: 32\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:1!null as T4IBQ, sn.id:7!null as BDNYB, mf.M22QN:6!null as M22QN]\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" +
" │ │ │ ├─ colSet: (114-143)\n" +
" │ │ │ ├─ tableId: 14\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: YK2GW\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (110-113)\n" +
" │ │ ├─ tableId: 13\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: THNTS\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(bs.id:2!null)\n" +
" │ ├─ right-key: TUPLE(mf.GXLUB:0!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ mf.LUEVY:5!null\n" +
" │ │ └─ sn.BRQP2:8!null\n" +
" │ ├─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (93-109)\n" +
" │ │ ├─ tableId: 12\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HGMQ6\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (144-153)\n" +
" │ ├─ tableId: 15\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" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (239-243)\n" +
" ├─ tableId: 33\n" +
" └─ Project\n" +
" ├─ columns: [CASE WHEN NOT\n" +
" │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.QNI57\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (210,211)\n" +
" │ ├─ tableId: 24\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.TDEIU\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (212,213)\n" +
" │ ├─ tableId: 25\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\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" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.QNI57\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (210,211)\n" +
" │ ├─ tableId: 24\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.TDEIU\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (212,213)\n" +
" │ ├─ tableId: 25\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\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" +
" │ │ │ │ ├─ alias-string: select JTEHG.id from NOXN3 as JTEHG where BRQP2 = MJR3D.BJUF2\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" +
" │ │ │ │ ├─ keys: [mjr3d.BJUF2:1!null]\n" +
" │ │ │ │ ├─ colSet: (180-189)\n" +
" │ │ │ │ ├─ tableId: 21\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\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" +
" │ │ │ ├─ alias-string: select XMAFZ.id from NOXN3 as XMAFZ where BRQP2 = MJR3D.FJDP5\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" +
" │ │ │ ├─ keys: [mjr3d.FJDP5:0!null]\n" +
" │ │ │ ├─ colSet: (190-199)\n" +
" │ │ │ ├─ tableId: 22\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\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" +
" │ │ ├─ alias-string: select XMAFZ.id from NOXN3 as XMAFZ where BRQP2 = MJR3D.BJUF2\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" +
" │ │ ├─ keys: [mjr3d.BJUF2:1!null]\n" +
" │ │ ├─ colSet: (200-209)\n" +
" │ │ ├─ tableId: 23\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2]\n" +
" │ └─ NOT\n" +
" │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" ├─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: mjr3d\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (160-166)\n" +
" │ │ ├─ tableId: 18\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ism.FV24E:0!null as FJDP5, cpmfe.id:10!null as BJUF2, ism.M22QN:2!null as M22QN, g3yxs.TUV25:7 as TUV25, g3yxs.ESFVY:6!null as ESFVY, yqif4.id:12!null as QNI57, yvhjz.id:15!null as TDEIU]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ yqif4.id:12!null IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ yvhjz.id:15!null IS NULL\n" +
" │ │ └─ LeftOuterLookupJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ yvhjz.BRQP2:16!null\n" +
" │ │ │ └─ ism.UJ6XY:1!null\n" +
" │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ yqif4.BRQP2:13!null\n" +
" │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ cpmfe.id:10!null\n" +
" │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nhmxw.id:8!null\n" +
" │ │ │ │ │ │ └─ ism.PRUV2:4\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ ├─ ism.NZ4MQ:3!null\n" +
" │ │ │ │ │ │ │ └─ g3yxs.id:5!null\n" +
" │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (15-23)\n" +
" │ │ │ │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: HDDVB\n" +
" │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ └─ g3yxs.TUV25:2 IS NULL\n" +
" │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ ├─ colSet: (24-31)\n" +
" │ │ │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: YYBCX\n" +
" │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:4)\n" +
" │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ ├─ columns: [id nohhr]\n" +
" │ │ │ │ │ ├─ colSet: (32-41)\n" +
" │ │ │ │ │ └─ tableId: 6\n" +
" │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ ├─ keys: [nhmxw.NOHHR:9!null]\n" +
" │ │ │ │ ├─ colSet: (42-58)\n" +
" │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ └─ columns: [id zh72s]\n" +
" │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ keys: [ism.UJ6XY:1!null]\n" +
" │ │ │ ├─ colSet: (59-68)\n" +
" │ │ │ ├─ tableId: 8\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ TableAlias(yvhjz)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ ├─ keys: [ism.FV24E:0!null]\n" +
" │ │ ├─ colSet: (69-78)\n" +
" │ │ ├─ tableId: 9\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ ├─ keys: [mjr3d.M22QN:2!null]\n" +
" │ ├─ colSet: (167-169)\n" +
" │ ├─ tableId: 19\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXBU\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" +
" ├─ colSet: (170-179)\n" +
" └─ tableId: 20\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [fs.T4IBQ as T4IBQ, fs.M6T2N as M6T2N, fs.TUV25 as TUV25, fs.BTXC5 as YEBDJ]\n" +
" └─ Project\n" +
" ├─ columns: [fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25]\n" +
" └─ Filter\n" +
" ├─ (((zmspr.T4IBQ IS NULL AND zmspr.M6T2N IS NULL) AND zmspr.BTXC5 IS NULL) AND zmspr.TUV25 IS NULL)\n" +
" └─ LeftOuterHashJoinExcludeNulls (estimated cost=402.250 rows=125)\n" +
" ├─ ((fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25) = (zmspr.T4IBQ, zmspr.M6T2N, zmspr.BTXC5, zmspr.TUV25))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [rsa3y.T4IBQ as T4IBQ, jmhie.M6T2N as M6T2N, jmhie.BTXC5 as BTXC5, jmhie.TUV25 as TUV25]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: jmhie\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jqhrg.M6T2N, jqhrg.BTXC5, jqhrg.TUV25]\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: jqhrg\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [mjr3d.FJDP5, mjr3d.BJUF2, mjr3d.M22QN, mjr3d.TUV25, mjr3d.ESFVY, mjr3d.QNI57, mjr3d.TDEIU, aac.id, aac.BTXC5, aac.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" │ │ └─ LeftOuterJoin\n" +
" │ │ ├─ ((((((NOT(mjr3d.QNI57 IS NULL)) AND (sn.id = mjr3d.QNI57)) AND mjr3d.BJUF2 IS NULL) OR (((NOT(mjr3d.QNI57 IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jtehg.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (jtehg.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ ) AND (NOT(mjr3d.BJUF2 IS NULL)))) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.FJDP5)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.FJDP5\n" +
" │ │ │ ) AND mjr3d.BJUF2 IS NULL)) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ ) AND (NOT(mjr3d.BJUF2 IS NULL))))\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: mjr3d\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Distinct\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [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]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ │ │ ├─ (NOT(g3yxs.TUV25 IS NULL))\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ right-key: (nhmxw.id)\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 zh72s]\n" +
" │ │ │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ keys: ism.FV24E\n" +
" │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ └─ keys: mjr3d.M22QN\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: NOXN3\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: ()\n" +
" │ ├─ right-key: ()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: rsa3y\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [htkbs.T4IBQ]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: htkbs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, mf.M22QN as M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (bs.id = mf.GXLUB)\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (bs.id)\n" +
" │ ├─ right-key: (mf.GXLUB)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (mf.LUEVY = sn.BRQP2)\n" +
" │ ├─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id brqp2]\n" +
" └─ HashLookup\n" +
" ├─ left-key: ((fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25))\n" +
" ├─ right-key: ((zmspr.T4IBQ, zmspr.M6T2N, zmspr.BTXC5, zmspr.TUV25))\n" +
" └─ SubqueryAlias\n" +
" ├─ name: zmspr\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cld.T4IBQ as T4IBQ, p4pjz.M6T2N as M6T2N, p4pjz.BTXC5 as BTXC5, p4pjz.TUV25 as TUV25]\n" +
" └─ Filter\n" +
" ├─ (NOT(p4pjz.M6T2N IS NULL))\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ ((p4pjz.LWQ6O = cld.BDNYB) AND (p4pjz.NTOFG = cld.M22QN))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cld\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, mf.M22QN as M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (bs.id = mf.GXLUB)\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (bs.id)\n" +
" │ ├─ right-key: (mf.GXLUB)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (mf.LUEVY = sn.BRQP2)\n" +
" │ ├─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id brqp2]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (cld.BDNYB, cld.M22QN)\n" +
" ├─ right-key: (p4pjz.LWQ6O, p4pjz.NTOFG)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: p4pjz\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" └─ Project\n" +
" ├─ columns: [mjr3d.FJDP5, mjr3d.BJUF2, mjr3d.M22QN, mjr3d.TUV25, mjr3d.ESFVY, mjr3d.QNI57, mjr3d.TDEIU, aac.id, aac.BTXC5, aac.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" └─ LeftOuterJoin\n" +
" ├─ ((((((NOT(mjr3d.QNI57 IS NULL)) AND (sn.id = mjr3d.QNI57)) AND mjr3d.BJUF2 IS NULL) OR (((NOT(mjr3d.QNI57 IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [jtehg.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (jtehg.BRQP2 = mjr3d.BJUF2)\n" +
" │ └─ TableAlias(jtehg)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.BJUF2\n" +
" │ ) AND (NOT(mjr3d.BJUF2 IS NULL)))) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [xmafz.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (xmafz.BRQP2 = mjr3d.FJDP5)\n" +
" │ └─ TableAlias(xmafz)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.FJDP5\n" +
" │ ) AND mjr3d.BJUF2 IS NULL)) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [xmafz.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (xmafz.BRQP2 = mjr3d.BJUF2)\n" +
" │ └─ TableAlias(xmafz)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.BJUF2\n" +
" │ ) AND (NOT(mjr3d.BJUF2 IS NULL))))\n" +
" ├─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: mjr3d\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [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]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ └─ LeftOuterLookupJoin\n" +
" │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ (NOT(g3yxs.TUV25 IS NULL))\n" +
" │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ ├─ right-key: (nhmxw.id)\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 zh72s]\n" +
" │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ └─ TableAlias(yvhjz)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ keys: ism.FV24E\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ keys: mjr3d.M22QN\n" +
" └─ TableAlias(sn)\n" +
" └─ Table\n" +
" └─ name: NOXN3\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [fs.T4IBQ as T4IBQ, fs.M6T2N as M6T2N, fs.TUV25 as TUV25, fs.BTXC5 as YEBDJ]\n" +
" └─ Project\n" +
" ├─ columns: [fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25]\n" +
" └─ Filter\n" +
" ├─ (((zmspr.T4IBQ IS NULL AND zmspr.M6T2N IS NULL) AND zmspr.BTXC5 IS NULL) AND zmspr.TUV25 IS NULL)\n" +
" └─ LeftOuterHashJoinExcludeNulls (estimated cost=402.250 rows=125) (actual rows=0 loops=1)\n" +
" ├─ ((fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25) = (zmspr.T4IBQ, zmspr.M6T2N, zmspr.BTXC5, zmspr.TUV25))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [rsa3y.T4IBQ as T4IBQ, jmhie.M6T2N as M6T2N, jmhie.BTXC5 as BTXC5, jmhie.TUV25 as TUV25]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: jmhie\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jqhrg.M6T2N, jqhrg.BTXC5, jqhrg.TUV25]\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: jqhrg\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [mjr3d.FJDP5, mjr3d.BJUF2, mjr3d.M22QN, mjr3d.TUV25, mjr3d.ESFVY, mjr3d.QNI57, mjr3d.TDEIU, aac.id, aac.BTXC5, aac.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" │ │ └─ LeftOuterJoin\n" +
" │ │ ├─ ((((((NOT(mjr3d.QNI57 IS NULL)) AND (sn.id = mjr3d.QNI57)) AND mjr3d.BJUF2 IS NULL) OR (((NOT(mjr3d.QNI57 IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jtehg.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (jtehg.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ ) AND (NOT(mjr3d.BJUF2 IS NULL)))) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.FJDP5)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.FJDP5\n" +
" │ │ │ ) AND mjr3d.BJUF2 IS NULL)) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ ) AND (NOT(mjr3d.BJUF2 IS NULL))))\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: mjr3d\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Distinct\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [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]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ │ │ ├─ (NOT(g3yxs.TUV25 IS NULL))\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ right-key: (nhmxw.id)\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 zh72s]\n" +
" │ │ │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ keys: ism.FV24E\n" +
" │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ └─ keys: mjr3d.M22QN\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: NOXN3\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: ()\n" +
" │ ├─ right-key: ()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: rsa3y\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [htkbs.T4IBQ]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: htkbs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, mf.M22QN as M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (bs.id = mf.GXLUB)\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (bs.id)\n" +
" │ ├─ right-key: (mf.GXLUB)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (mf.LUEVY = sn.BRQP2)\n" +
" │ ├─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id brqp2]\n" +
" └─ HashLookup\n" +
" ├─ left-key: ((fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25))\n" +
" ├─ right-key: ((zmspr.T4IBQ, zmspr.M6T2N, zmspr.BTXC5, zmspr.TUV25))\n" +
" └─ SubqueryAlias\n" +
" ├─ name: zmspr\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cld.T4IBQ as T4IBQ, p4pjz.M6T2N as M6T2N, p4pjz.BTXC5 as BTXC5, p4pjz.TUV25 as TUV25]\n" +
" └─ Filter\n" +
" ├─ (NOT(p4pjz.M6T2N IS NULL))\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ ((p4pjz.LWQ6O = cld.BDNYB) AND (p4pjz.NTOFG = cld.M22QN))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cld\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, mf.M22QN as M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (bs.id = mf.GXLUB)\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (cla.id = bs.IXUXU)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ │ │ └─ TableAlias(cla)\n" +
" │ │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ │ ├─ index: [YK2GW.id]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (bs.id)\n" +
" │ ├─ right-key: (mf.GXLUB)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (mf.LUEVY = sn.BRQP2)\n" +
" │ ├─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ TableAlias(sn)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id brqp2]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (cld.BDNYB, cld.M22QN)\n" +
" ├─ right-key: (p4pjz.LWQ6O, p4pjz.NTOFG)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: p4pjz\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" └─ Project\n" +
" ├─ columns: [mjr3d.FJDP5, mjr3d.BJUF2, mjr3d.M22QN, mjr3d.TUV25, mjr3d.ESFVY, mjr3d.QNI57, mjr3d.TDEIU, aac.id, aac.BTXC5, aac.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" └─ LeftOuterJoin\n" +
" ├─ ((((((NOT(mjr3d.QNI57 IS NULL)) AND (sn.id = mjr3d.QNI57)) AND mjr3d.BJUF2 IS NULL) OR (((NOT(mjr3d.QNI57 IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [jtehg.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (jtehg.BRQP2 = mjr3d.BJUF2)\n" +
" │ └─ TableAlias(jtehg)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.BJUF2\n" +
" │ ) AND (NOT(mjr3d.BJUF2 IS NULL)))) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [xmafz.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (xmafz.BRQP2 = mjr3d.FJDP5)\n" +
" │ └─ TableAlias(xmafz)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.FJDP5\n" +
" │ ) AND mjr3d.BJUF2 IS NULL)) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [xmafz.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (xmafz.BRQP2 = mjr3d.BJUF2)\n" +
" │ └─ TableAlias(xmafz)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.BJUF2\n" +
" │ ) AND (NOT(mjr3d.BJUF2 IS NULL))))\n" +
" ├─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: mjr3d\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [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]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ └─ LeftOuterLookupJoin\n" +
" │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ (NOT(g3yxs.TUV25 IS NULL))\n" +
" │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ ├─ right-key: (nhmxw.id)\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 zh72s]\n" +
" │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ └─ TableAlias(yvhjz)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ keys: ism.FV24E\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ keys: mjr3d.M22QN\n" +
" └─ TableAlias(sn)\n" +
" └─ Table\n" +
" └─ name: NOXN3\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" +
" └─ Project\n" +
" ├─ columns: [fs.T4IBQ:0!null, fs.M6T2N:1, fs.BTXC5:2, fs.TUV25:3]\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ zmspr.T4IBQ:4!null IS NULL\n" +
" │ │ │ └─ zmspr.M6T2N:5 IS NULL\n" +
" │ │ └─ zmspr.BTXC5:6 IS NULL\n" +
" │ └─ zmspr.TUV25:7 IS NULL\n" +
" └─ LeftOuterHashJoinExcludeNulls\n" +
" ├─ Eq\n" +
" │ ├─ TUPLE(fs.T4IBQ:0!null, fs.M6T2N:1, fs.BTXC5:2, fs.TUV25:3)\n" +
" │ └─ TUPLE(zmspr.T4IBQ:4!null, zmspr.M6T2N:5, zmspr.BTXC5:6, zmspr.TUV25:7)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (252-255)\n" +
" │ ├─ tableId: 36\n" +
" │ └─ Project\n" +
" │ ├─ columns: [rsa3y.T4IBQ:3!null as T4IBQ, jmhie.M6T2N:0 as M6T2N, jmhie.BTXC5:1 as BTXC5, jmhie.TUV25:2 as TUV25]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: jmhie\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (224-226)\n" +
" │ │ ├─ tableId: 28\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jqhrg.M6T2N:0, jqhrg.BTXC5:1, jqhrg.TUV25:4]\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: jqhrg\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (219-223)\n" +
" │ │ ├─ tableId: 26\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [CASE WHEN NOT\n" +
" │ │ │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ │ │ THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.QNI57\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" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (210,211)\n" +
" │ │ │ ├─ tableId: 24\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" +
" │ │ │ ├─ colSet: (1-10)\n" +
" │ │ │ └─ tableId: 1\n" +
" │ │ │ WHEN NOT\n" +
" │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ │ THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.TDEIU\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" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (212,213)\n" +
" │ │ │ ├─ tableId: 25\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" +
" │ │ │ ├─ colSet: (1-10)\n" +
" │ │ │ └─ tableId: 1\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" +
" │ │ │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.QNI57\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" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (210,211)\n" +
" │ │ │ ├─ tableId: 24\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" +
" │ │ │ ├─ colSet: (1-10)\n" +
" │ │ │ └─ tableId: 1\n" +
" │ │ │ WHEN NOT\n" +
" │ │ │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ │ │ THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.TDEIU\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" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (212,213)\n" +
" │ │ │ ├─ tableId: 25\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" +
" │ │ │ ├─ colSet: (1-10)\n" +
" │ │ │ └─ tableId: 1\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" +
" │ │ │ │ │ │ ├─ alias-string: select JTEHG.id from NOXN3 as JTEHG where BRQP2 = MJR3D.BJUF2\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" +
" │ │ │ │ │ │ ├─ keys: [mjr3d.BJUF2:1!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (180-189)\n" +
" │ │ │ │ │ │ ├─ tableId: 21\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: NOXN3\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" +
" │ │ │ │ │ ├─ alias-string: select XMAFZ.id from NOXN3 as XMAFZ where BRQP2 = MJR3D.FJDP5\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" +
" │ │ │ │ │ ├─ keys: [mjr3d.FJDP5:0!null]\n" +
" │ │ │ │ │ ├─ colSet: (190-199)\n" +
" │ │ │ │ │ ├─ tableId: 22\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: NOXN3\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" +
" │ │ │ │ ├─ alias-string: select XMAFZ.id from NOXN3 as XMAFZ where BRQP2 = MJR3D.BJUF2\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" +
" │ │ │ │ ├─ keys: [mjr3d.BJUF2:1!null]\n" +
" │ │ │ │ ├─ colSet: (200-209)\n" +
" │ │ │ │ ├─ tableId: 23\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2]\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: mjr3d\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ ├─ colSet: (160-166)\n" +
" │ │ │ │ ├─ tableId: 18\n" +
" │ │ │ │ └─ Distinct\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [ism.FV24E:0!null as FJDP5, cpmfe.id:10!null as BJUF2, ism.M22QN:2!null as M22QN, g3yxs.TUV25:7 as TUV25, g3yxs.ESFVY:6!null as ESFVY, yqif4.id:12!null as QNI57, yvhjz.id:15!null as TDEIU]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Or\n" +
" │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ └─ yqif4.id:12!null IS NULL\n" +
" │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ └─ yvhjz.id:15!null IS NULL\n" +
" │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ yvhjz.BRQP2:16!null\n" +
" │ │ │ │ │ └─ ism.UJ6XY:1!null\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ yqif4.BRQP2:13!null\n" +
" │ │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ │ ├─ cpmfe.id:10!null\n" +
" │ │ │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ nhmxw.id:8!null\n" +
" │ │ │ │ │ │ │ │ └─ ism.PRUV2:4\n" +
" │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ │ │ ├─ ism.NZ4MQ:3!null\n" +
" │ │ │ │ │ │ │ │ │ └─ g3yxs.id:5!null\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ ├─ colSet: (15-23)\n" +
" │ │ │ │ │ │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ │ ├─ name: HDDVB\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ │ │ └─ g3yxs.TUV25:2 IS NULL\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ ├─ colSet: (24-31)\n" +
" │ │ │ │ │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ │ ├─ name: YYBCX\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:4)\n" +
" │ │ │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ │ │ ├─ columns: [id nohhr]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (32-41)\n" +
" │ │ │ │ │ │ │ └─ tableId: 6\n" +
" │ │ │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ │ │ ├─ keys: [nhmxw.NOHHR:9!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (42-58)\n" +
" │ │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ │ └─ columns: [id zh72s]\n" +
" │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ keys: [ism.UJ6XY:1!null]\n" +
" │ │ │ │ │ ├─ colSet: (59-68)\n" +
" │ │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ keys: [ism.FV24E:0!null]\n" +
" │ │ │ │ ├─ colSet: (69-78)\n" +
" │ │ │ │ ├─ tableId: 9\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ ├─ keys: [mjr3d.M22QN:2!null]\n" +
" │ │ │ ├─ colSet: (167-169)\n" +
" │ │ │ ├─ tableId: 19\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: TPXBU\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" +
" │ │ ├─ colSet: (170-179)\n" +
" │ │ └─ tableId: 20\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE()\n" +
" │ ├─ right-key: TUPLE()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: rsa3y\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (227)\n" +
" │ ├─ tableId: 29\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [htkbs.T4IBQ:0!null]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: htkbs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (157-159)\n" +
" │ ├─ tableId: 16\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:8!null as T4IBQ, sn.id:0!null as BDNYB, mf.M22QN:4!null as M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ bs.id:5!null\n" +
" │ │ └─ mf.GXLUB:2!null\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ ├─ colSet: (144-153)\n" +
" │ │ │ └─ tableId: 15\n" +
" │ │ └─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ keys: [sn.BRQP2:1!null]\n" +
" │ │ ├─ colSet: (93-109)\n" +
" │ │ ├─ tableId: 12\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HGMQ6\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.GXLUB:2!null)\n" +
" │ ├─ right-key: TUPLE(bs.id:0!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ bs.IXUXU:6\n" +
" │ │ └─ cla.id:7!null\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (110-113)\n" +
" │ │ ├─ tableId: 13\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: THNTS\n" +
" │ │ └─ columns: [id ixuxu]\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" +
" │ ├─ colSet: (114-143)\n" +
" │ ├─ tableId: 14\n" +
" │ └─ Table\n" +
" │ ├─ name: YK2GW\n" +
" │ └─ columns: [id ftqlq]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(TUPLE(fs.T4IBQ:0!null, fs.M6T2N:1, fs.BTXC5:2, fs.TUV25:3))\n" +
" ├─ right-key: TUPLE(TUPLE(zmspr.T4IBQ:0!null, zmspr.M6T2N:1, zmspr.BTXC5:2, zmspr.TUV25:3))\n" +
" └─ SubqueryAlias\n" +
" ├─ name: zmspr\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (248-251)\n" +
" ├─ tableId: 34\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (236-238)\n" +
" │ ├─ tableId: 32\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ:8!null as T4IBQ, sn.id:0!null as BDNYB, mf.M22QN:4!null as M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ bs.id:5!null\n" +
" │ │ └─ mf.GXLUB:2!null\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ ├─ colSet: (144-153)\n" +
" │ │ │ └─ tableId: 15\n" +
" │ │ └─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ keys: [sn.BRQP2:1!null]\n" +
" │ │ ├─ colSet: (93-109)\n" +
" │ │ ├─ tableId: 12\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: HGMQ6\n" +
" │ │ └─ columns: [gxlub luevy m22qn]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(mf.GXLUB:2!null)\n" +
" │ ├─ right-key: TUPLE(bs.id:0!null)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ bs.IXUXU:6\n" +
" │ │ └─ cla.id:7!null\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (110-113)\n" +
" │ │ ├─ tableId: 13\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: THNTS\n" +
" │ │ └─ columns: [id ixuxu]\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" +
" │ ├─ colSet: (114-143)\n" +
" │ ├─ tableId: 14\n" +
" │ └─ Table\n" +
" │ ├─ name: YK2GW\n" +
" │ └─ columns: [id ftqlq]\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" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (239-243)\n" +
" ├─ tableId: 33\n" +
" └─ Project\n" +
" ├─ columns: [CASE WHEN NOT\n" +
" │ └─ mjr3d.QNI57:5!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.QNI57\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (210,211)\n" +
" │ ├─ tableId: 24\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.TDEIU\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (212,213)\n" +
" │ ├─ tableId: 25\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\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" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.QNI57\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (210,211)\n" +
" │ ├─ tableId: 24\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\n" +
" │ WHEN NOT\n" +
" │ └─ mjr3d.TDEIU:6!null IS NULL\n" +
" │ THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select ei.M6T2N from FZFVD as ei where ei.id = MJR3D.TDEIU\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (212,213)\n" +
" │ ├─ tableId: 25\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\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" +
" │ │ │ │ ├─ alias-string: select JTEHG.id from NOXN3 as JTEHG where BRQP2 = MJR3D.BJUF2\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" +
" │ │ │ │ ├─ keys: [mjr3d.BJUF2:1!null]\n" +
" │ │ │ │ ├─ colSet: (180-189)\n" +
" │ │ │ │ ├─ tableId: 21\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\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" +
" │ │ │ ├─ alias-string: select XMAFZ.id from NOXN3 as XMAFZ where BRQP2 = MJR3D.FJDP5\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" +
" │ │ │ ├─ keys: [mjr3d.FJDP5:0!null]\n" +
" │ │ │ ├─ colSet: (190-199)\n" +
" │ │ │ ├─ tableId: 22\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\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" +
" │ │ ├─ alias-string: select XMAFZ.id from NOXN3 as XMAFZ where BRQP2 = MJR3D.BJUF2\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" +
" │ │ ├─ keys: [mjr3d.BJUF2:1!null]\n" +
" │ │ ├─ colSet: (200-209)\n" +
" │ │ ├─ tableId: 23\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2]\n" +
" │ └─ NOT\n" +
" │ └─ mjr3d.BJUF2:1!null IS NULL\n" +
" ├─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: mjr3d\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (160-166)\n" +
" │ │ ├─ tableId: 18\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [ism.FV24E:0!null as FJDP5, cpmfe.id:10!null as BJUF2, ism.M22QN:2!null as M22QN, g3yxs.TUV25:7 as TUV25, g3yxs.ESFVY:6!null as ESFVY, yqif4.id:12!null as QNI57, yvhjz.id:15!null as TDEIU]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ yqif4.id:12!null IS NULL\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ yvhjz.id:15!null IS NULL\n" +
" │ │ └─ LeftOuterLookupJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ yvhjz.BRQP2:16!null\n" +
" │ │ │ └─ ism.UJ6XY:1!null\n" +
" │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ Eq\n" +
" │ │ │ │ ├─ yqif4.BRQP2:13!null\n" +
" │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ cpmfe.id:10!null\n" +
" │ │ │ │ │ └─ ism.FV24E:0!null\n" +
" │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ nhmxw.id:8!null\n" +
" │ │ │ │ │ │ └─ ism.PRUV2:4\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ │ │ ├─ ism.NZ4MQ:3!null\n" +
" │ │ │ │ │ │ │ └─ g3yxs.id:5!null\n" +
" │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (15-23)\n" +
" │ │ │ │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: HDDVB\n" +
" │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ NOT\n" +
" │ │ │ │ │ │ │ └─ g3yxs.TUV25:2 IS NULL\n" +
" │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ ├─ colSet: (24-31)\n" +
" │ │ │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: YYBCX\n" +
" │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: TUPLE(ism.PRUV2:4)\n" +
" │ │ │ │ │ ├─ right-key: TUPLE(nhmxw.id:0!null)\n" +
" │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ ├─ columns: [id nohhr]\n" +
" │ │ │ │ │ ├─ colSet: (32-41)\n" +
" │ │ │ │ │ └─ tableId: 6\n" +
" │ │ │ │ └─ TableAlias(cpmfe)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ ├─ keys: [nhmxw.NOHHR:9!null]\n" +
" │ │ │ │ ├─ colSet: (42-58)\n" +
" │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ └─ columns: [id zh72s]\n" +
" │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ keys: [ism.UJ6XY:1!null]\n" +
" │ │ │ ├─ colSet: (59-68)\n" +
" │ │ │ ├─ tableId: 8\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ TableAlias(yvhjz)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ ├─ keys: [ism.FV24E:0!null]\n" +
" │ │ ├─ colSet: (69-78)\n" +
" │ │ ├─ tableId: 9\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2 fftbj]\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ ├─ keys: [mjr3d.M22QN:2!null]\n" +
" │ ├─ colSet: (167-169)\n" +
" │ ├─ tableId: 19\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXBU\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" +
" ├─ colSet: (170-179)\n" +
" └─ tableId: 20\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [fs.T4IBQ as T4IBQ, fs.M6T2N as M6T2N, fs.TUV25 as TUV25, fs.BTXC5 as YEBDJ]\n" +
" └─ Project\n" +
" ├─ columns: [fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25]\n" +
" └─ Filter\n" +
" ├─ (((zmspr.T4IBQ IS NULL AND zmspr.M6T2N IS NULL) AND zmspr.BTXC5 IS NULL) AND zmspr.TUV25 IS NULL)\n" +
" └─ LeftOuterHashJoinExcludeNulls (estimated cost=402.250 rows=125)\n" +
" ├─ ((fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25) = (zmspr.T4IBQ, zmspr.M6T2N, zmspr.BTXC5, zmspr.TUV25))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [rsa3y.T4IBQ as T4IBQ, jmhie.M6T2N as M6T2N, jmhie.BTXC5 as BTXC5, jmhie.TUV25 as TUV25]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: jmhie\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jqhrg.M6T2N, jqhrg.BTXC5, jqhrg.TUV25]\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: jqhrg\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [mjr3d.FJDP5, mjr3d.BJUF2, mjr3d.M22QN, mjr3d.TUV25, mjr3d.ESFVY, mjr3d.QNI57, mjr3d.TDEIU, aac.id, aac.BTXC5, aac.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" │ │ └─ LeftOuterJoin\n" +
" │ │ ├─ ((((((NOT(mjr3d.QNI57 IS NULL)) AND (sn.id = mjr3d.QNI57)) AND mjr3d.BJUF2 IS NULL) OR (((NOT(mjr3d.QNI57 IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jtehg.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (jtehg.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ ) AND (NOT(mjr3d.BJUF2 IS NULL)))) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.FJDP5)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.FJDP5\n" +
" │ │ │ ) AND mjr3d.BJUF2 IS NULL)) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ ) AND (NOT(mjr3d.BJUF2 IS NULL))))\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: mjr3d\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Distinct\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [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]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ │ │ ├─ (NOT(g3yxs.TUV25 IS NULL))\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ right-key: (nhmxw.id)\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 zh72s]\n" +
" │ │ │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ keys: ism.FV24E\n" +
" │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ └─ keys: mjr3d.M22QN\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: NOXN3\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: ()\n" +
" │ ├─ right-key: ()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: rsa3y\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [htkbs.T4IBQ]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: htkbs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, mf.M22QN as M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (bs.id = mf.GXLUB)\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ columns: [gxlub luevy m22qn]\n" +
" │ │ └─ keys: sn.BRQP2\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (mf.GXLUB)\n" +
" │ ├─ right-key: (bs.id)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (bs.IXUXU = cla.id)\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ Filter\n" +
" │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ftqlq]\n" +
" └─ HashLookup\n" +
" ├─ left-key: ((fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25))\n" +
" ├─ right-key: ((zmspr.T4IBQ, zmspr.M6T2N, zmspr.BTXC5, zmspr.TUV25))\n" +
" └─ SubqueryAlias\n" +
" ├─ name: zmspr\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cld.T4IBQ as T4IBQ, p4pjz.M6T2N as M6T2N, p4pjz.BTXC5 as BTXC5, p4pjz.TUV25 as TUV25]\n" +
" └─ Filter\n" +
" ├─ (NOT(p4pjz.M6T2N IS NULL))\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ ((p4pjz.LWQ6O = cld.BDNYB) AND (p4pjz.NTOFG = cld.M22QN))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cld\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, mf.M22QN as M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (bs.id = mf.GXLUB)\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ columns: [gxlub luevy m22qn]\n" +
" │ │ └─ keys: sn.BRQP2\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (mf.GXLUB)\n" +
" │ ├─ right-key: (bs.id)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (bs.IXUXU = cla.id)\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ Filter\n" +
" │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ftqlq]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (cld.BDNYB, cld.M22QN)\n" +
" ├─ right-key: (p4pjz.LWQ6O, p4pjz.NTOFG)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: p4pjz\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" └─ Project\n" +
" ├─ columns: [mjr3d.FJDP5, mjr3d.BJUF2, mjr3d.M22QN, mjr3d.TUV25, mjr3d.ESFVY, mjr3d.QNI57, mjr3d.TDEIU, aac.id, aac.BTXC5, aac.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" └─ LeftOuterJoin\n" +
" ├─ ((((((NOT(mjr3d.QNI57 IS NULL)) AND (sn.id = mjr3d.QNI57)) AND mjr3d.BJUF2 IS NULL) OR (((NOT(mjr3d.QNI57 IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [jtehg.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (jtehg.BRQP2 = mjr3d.BJUF2)\n" +
" │ └─ TableAlias(jtehg)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.BJUF2\n" +
" │ ) AND (NOT(mjr3d.BJUF2 IS NULL)))) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [xmafz.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (xmafz.BRQP2 = mjr3d.FJDP5)\n" +
" │ └─ TableAlias(xmafz)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.FJDP5\n" +
" │ ) AND mjr3d.BJUF2 IS NULL)) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [xmafz.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (xmafz.BRQP2 = mjr3d.BJUF2)\n" +
" │ └─ TableAlias(xmafz)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.BJUF2\n" +
" │ ) AND (NOT(mjr3d.BJUF2 IS NULL))))\n" +
" ├─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: mjr3d\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [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]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ └─ LeftOuterLookupJoin\n" +
" │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ (NOT(g3yxs.TUV25 IS NULL))\n" +
" │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ ├─ right-key: (nhmxw.id)\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 zh72s]\n" +
" │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ └─ TableAlias(yvhjz)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ keys: ism.FV24E\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ keys: mjr3d.M22QN\n" +
" └─ TableAlias(sn)\n" +
" └─ Table\n" +
" └─ name: NOXN3\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [fs.T4IBQ as T4IBQ, fs.M6T2N as M6T2N, fs.TUV25 as TUV25, fs.BTXC5 as YEBDJ]\n" +
" └─ Project\n" +
" ├─ columns: [fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25]\n" +
" └─ Filter\n" +
" ├─ (((zmspr.T4IBQ IS NULL AND zmspr.M6T2N IS NULL) AND zmspr.BTXC5 IS NULL) AND zmspr.TUV25 IS NULL)\n" +
" └─ LeftOuterHashJoinExcludeNulls (estimated cost=402.250 rows=125) (actual rows=0 loops=1)\n" +
" ├─ ((fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25) = (zmspr.T4IBQ, zmspr.M6T2N, zmspr.BTXC5, zmspr.TUV25))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: fs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [rsa3y.T4IBQ as T4IBQ, jmhie.M6T2N as M6T2N, jmhie.BTXC5 as BTXC5, jmhie.TUV25 as TUV25]\n" +
" │ └─ CrossHashJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: jmhie\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jqhrg.M6T2N, jqhrg.BTXC5, jqhrg.TUV25]\n" +
" │ │ └─ SubqueryAlias\n" +
" │ │ ├─ name: jqhrg\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [mjr3d.FJDP5, mjr3d.BJUF2, mjr3d.M22QN, mjr3d.TUV25, mjr3d.ESFVY, mjr3d.QNI57, mjr3d.TDEIU, aac.id, aac.BTXC5, aac.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [ei.M6T2N]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ │ │ └─ SubqueryAlias\n" +
" │ │ │ ├─ name: ei\n" +
" │ │ │ ├─ outerVisibility: true\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ │ │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id]\n" +
" │ │ │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" │ │ └─ LeftOuterJoin\n" +
" │ │ ├─ ((((((NOT(mjr3d.QNI57 IS NULL)) AND (sn.id = mjr3d.QNI57)) AND mjr3d.BJUF2 IS NULL) OR (((NOT(mjr3d.QNI57 IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [jtehg.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (jtehg.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(jtehg)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ ) AND (NOT(mjr3d.BJUF2 IS NULL)))) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.FJDP5)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.FJDP5\n" +
" │ │ │ ) AND mjr3d.BJUF2 IS NULL)) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ │ │ ├─ left: sn.id\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [xmafz.id]\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ (xmafz.BRQP2 = mjr3d.BJUF2)\n" +
" │ │ │ └─ TableAlias(xmafz)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ columns: [id brqp2]\n" +
" │ │ │ └─ keys: mjr3d.BJUF2\n" +
" │ │ │ ) AND (NOT(mjr3d.BJUF2 IS NULL))))\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: mjr3d\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ └─ Distinct\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [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]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ │ │ └─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ │ │ ├─ (NOT(g3yxs.TUV25 IS NULL))\n" +
" │ │ │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ │ │ ├─ right-key: (nhmxw.id)\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 zh72s]\n" +
" │ │ │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ │ │ └─ TableAlias(yvhjz)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ │ └─ keys: ism.FV24E\n" +
" │ │ │ └─ TableAlias(aac)\n" +
" │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ ├─ index: [TPXBU.id]\n" +
" │ │ │ └─ keys: mjr3d.M22QN\n" +
" │ │ └─ TableAlias(sn)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: NOXN3\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: ()\n" +
" │ ├─ right-key: ()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: rsa3y\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [htkbs.T4IBQ]\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: htkbs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, mf.M22QN as M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (bs.id = mf.GXLUB)\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ columns: [gxlub luevy m22qn]\n" +
" │ │ └─ keys: sn.BRQP2\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (mf.GXLUB)\n" +
" │ ├─ right-key: (bs.id)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (bs.IXUXU = cla.id)\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ Filter\n" +
" │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ftqlq]\n" +
" └─ HashLookup\n" +
" ├─ left-key: ((fs.T4IBQ, fs.M6T2N, fs.BTXC5, fs.TUV25))\n" +
" ├─ right-key: ((zmspr.T4IBQ, zmspr.M6T2N, zmspr.BTXC5, zmspr.TUV25))\n" +
" └─ SubqueryAlias\n" +
" ├─ name: zmspr\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cld.T4IBQ as T4IBQ, p4pjz.M6T2N as M6T2N, p4pjz.BTXC5 as BTXC5, p4pjz.TUV25 as TUV25]\n" +
" └─ Filter\n" +
" ├─ (NOT(p4pjz.M6T2N IS NULL))\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ ((p4pjz.LWQ6O = cld.BDNYB) AND (p4pjz.NTOFG = cld.M22QN))\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: cld\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [cla.FTQLQ as T4IBQ, sn.id as BDNYB, mf.M22QN as M22QN]\n" +
" │ └─ HashJoin\n" +
" │ ├─ (bs.id = mf.GXLUB)\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2]\n" +
" │ │ └─ TableAlias(mf)\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ ├─ columns: [gxlub luevy m22qn]\n" +
" │ │ └─ keys: sn.BRQP2\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (mf.GXLUB)\n" +
" │ ├─ right-key: (bs.id)\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (bs.IXUXU = cla.id)\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id ixuxu]\n" +
" │ └─ Filter\n" +
" │ ├─ (cla.FTQLQ HASH IN ('SQ1'))\n" +
" │ └─ TableAlias(cla)\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ftqlq]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (cld.BDNYB, cld.M22QN)\n" +
" ├─ right-key: (p4pjz.LWQ6O, p4pjz.NTOFG)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: p4pjz\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" └─ Project\n" +
" ├─ columns: [mjr3d.FJDP5, mjr3d.BJUF2, mjr3d.M22QN, mjr3d.TUV25, mjr3d.ESFVY, mjr3d.QNI57, mjr3d.TDEIU, aac.id, aac.BTXC5, aac.FHCYT, sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, CASE WHEN (NOT(mjr3d.QNI57 IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.QNI57)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ WHEN (NOT(mjr3d.TDEIU IS NULL)) THEN Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ei.M6T2N]\n" +
" │ └─ Filter\n" +
" │ ├─ (ei.id = mjr3d.TDEIU)\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: ei\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, (row_number() over ( order by noxn3.id asc) - 1) as M6T2N]\n" +
" │ └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id]\n" +
" │ END as M6T2N, aac.BTXC5 as BTXC5, aac.id as NTOFG, sn.id as LWQ6O, mjr3d.TUV25 as TUV25]\n" +
" └─ LeftOuterJoin\n" +
" ├─ ((((((NOT(mjr3d.QNI57 IS NULL)) AND (sn.id = mjr3d.QNI57)) AND mjr3d.BJUF2 IS NULL) OR (((NOT(mjr3d.QNI57 IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [jtehg.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (jtehg.BRQP2 = mjr3d.BJUF2)\n" +
" │ └─ TableAlias(jtehg)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.BJUF2\n" +
" │ ) AND (NOT(mjr3d.BJUF2 IS NULL)))) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [xmafz.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (xmafz.BRQP2 = mjr3d.FJDP5)\n" +
" │ └─ TableAlias(xmafz)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.FJDP5\n" +
" │ ) AND mjr3d.BJUF2 IS NULL)) OR (((NOT(mjr3d.TDEIU IS NULL)) AND InSubquery\n" +
" │ ├─ left: sn.id\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [xmafz.id]\n" +
" │ └─ Filter\n" +
" │ ├─ (xmafz.BRQP2 = mjr3d.BJUF2)\n" +
" │ └─ TableAlias(xmafz)\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.BRQP2]\n" +
" │ ├─ columns: [id brqp2]\n" +
" │ └─ keys: mjr3d.BJUF2\n" +
" │ ) AND (NOT(mjr3d.BJUF2 IS NULL))))\n" +
" ├─ LookupJoin\n" +
" │ ├─ SubqueryAlias\n" +
" │ │ ├─ name: mjr3d\n" +
" │ │ ├─ outerVisibility: false\n" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [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]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ ((NOT(yqif4.id IS NULL)) OR (NOT(yvhjz.id IS NULL)))\n" +
" │ │ └─ LeftOuterLookupJoin\n" +
" │ │ ├─ (yvhjz.BRQP2 = ism.UJ6XY)\n" +
" │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ (yqif4.BRQP2 = ism.FV24E)\n" +
" │ │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ │ ├─ (NOT((cpmfe.id = ism.FV24E)))\n" +
" │ │ │ │ ├─ LeftOuterHashJoin\n" +
" │ │ │ │ │ ├─ (nhmxw.id = ism.PRUV2)\n" +
" │ │ │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ │ │ ├─ cmp: (ism.NZ4MQ = g3yxs.id)\n" +
" │ │ │ │ │ │ ├─ TableAlias(ism)\n" +
" │ │ │ │ │ │ │ └─ IndexedTableAccess(HDDVB)\n" +
" │ │ │ │ │ │ │ ├─ index: [HDDVB.NZ4MQ]\n" +
" │ │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ │ └─ columns: [fv24e uj6xy m22qn nz4mq pruv2]\n" +
" │ │ │ │ │ │ └─ Filter\n" +
" │ │ │ │ │ │ ├─ (NOT(g3yxs.TUV25 IS NULL))\n" +
" │ │ │ │ │ │ └─ TableAlias(g3yxs)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(YYBCX)\n" +
" │ │ │ │ │ │ ├─ index: [YYBCX.id]\n" +
" │ │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ │ └─ columns: [id esfvy tuv25]\n" +
" │ │ │ │ │ └─ HashLookup\n" +
" │ │ │ │ │ ├─ left-key: (ism.PRUV2)\n" +
" │ │ │ │ │ ├─ right-key: (nhmxw.id)\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 zh72s]\n" +
" │ │ │ │ └─ keys: nhmxw.NOHHR\n" +
" │ │ │ └─ TableAlias(yqif4)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ │ └─ keys: ism.UJ6XY\n" +
" │ │ └─ TableAlias(yvhjz)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ ├─ columns: [id brqp2 fftbj]\n" +
" │ │ └─ keys: ism.FV24E\n" +
" │ └─ TableAlias(aac)\n" +
" │ └─ IndexedTableAccess(TPXBU)\n" +
" │ ├─ index: [TPXBU.id]\n" +
" │ └─ keys: mjr3d.M22QN\n" +
" └─ TableAlias(sn)\n" +
" └─ Table\n" +
" └─ name: NOXN3\n" +
"",
},
{
Query: `
SELECT
TW55N
FROM
E2I7U
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [e2i7u.TW55N:1!null]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [e2i7u.TW55N]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id tw55n]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [e2i7u.TW55N]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id tw55n]\n" +
"",
},
{
Query: `
SELECT
TW55N, FGG57
FROM
E2I7U
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [e2i7u.TW55N:1!null, e2i7u.FGG57:2]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n fgg57]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [e2i7u.TW55N, e2i7u.FGG57]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id tw55n fgg57]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [e2i7u.TW55N, e2i7u.FGG57]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id tw55n fgg57]\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" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [count(1) as COUNT(*)]\n" +
" └─ Project\n" +
" ├─ columns: [E2I7U.COUNT(1) as COUNT(1)]\n" +
" └─ table_count(E2I7U) as COUNT(1)\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [count(1) as COUNT(*)]\n" +
" └─ Project\n" +
" ├─ columns: [E2I7U.COUNT(1) 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" +
" └─ ProcessTable\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [(row_number() over ( order by e2i7u.id asc) - 1) as DICQO, e2i7u.TW55N]\n" +
" └─ Window(row_number() over ( order by e2i7u.id ASC), e2i7u.TW55N)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id tw55n]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [(row_number() over ( order by e2i7u.id asc) - 1) as DICQO, e2i7u.TW55N]\n" +
" └─ Window(row_number() over ( order by e2i7u.id ASC), e2i7u.TW55N)\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:0!null, xj2rd.HHVLX:1!null, xj2rd.HVHRZ:2!null, tusay.Y3IOU:3!null, tusay.XLFIA:4!null, tusay.Y3IOU:3!null as Q7H3X]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ xj2rd.HHVLX:1!null\n" +
" │ └─ tusay.XLFIA:4!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: xj2rd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (10-12)\n" +
" │ ├─ tableId: 2\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" +
" │ ├─ colSet: (1-6)\n" +
" │ └─ tableId: 1\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(xj2rd.HHVLX:1!null)\n" +
" ├─ right-key: TUPLE(tusay.XLFIA:1!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: tusay\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (26,27)\n" +
" ├─ tableId: 4\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" +
" ├─ colSet: (13-22)\n" +
" └─ tableId: 3\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [tusay.Y3IOU as Q7H3X]\n" +
" └─ Sort(xj2rd.Y46B2 ASC)\n" +
" └─ Project\n" +
" ├─ columns: [xj2rd.Y46B2, xj2rd.HHVLX, xj2rd.HVHRZ, tusay.Y3IOU, tusay.XLFIA, tusay.Y3IOU as Q7H3X]\n" +
" └─ HashJoin\n" +
" ├─ (xj2rd.HHVLX = tusay.XLFIA)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: xj2rd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [qywqd.id as Y46B2, qywqd.HHVLX as HHVLX, qywqd.HVHRZ as HVHRZ]\n" +
" │ └─ Table\n" +
" │ ├─ name: QYWQD\n" +
" │ └─ columns: [id hhvlx hvhrz]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (xj2rd.HHVLX)\n" +
" ├─ right-key: (tusay.XLFIA)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: tusay\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by noxn3.id asc) as Y3IOU, noxn3.id as XLFIA]\n" +
" └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [tusay.Y3IOU as Q7H3X]\n" +
" └─ Sort(xj2rd.Y46B2 ASC)\n" +
" └─ Project\n" +
" ├─ columns: [xj2rd.Y46B2, xj2rd.HHVLX, xj2rd.HVHRZ, tusay.Y3IOU, tusay.XLFIA, tusay.Y3IOU as Q7H3X]\n" +
" └─ HashJoin\n" +
" ├─ (xj2rd.HHVLX = tusay.XLFIA)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: xj2rd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [qywqd.id as Y46B2, qywqd.HHVLX as HHVLX, qywqd.HVHRZ as HVHRZ]\n" +
" │ └─ Table\n" +
" │ ├─ name: QYWQD\n" +
" │ └─ columns: [id hhvlx hvhrz]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (xj2rd.HHVLX)\n" +
" ├─ right-key: (tusay.XLFIA)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: tusay\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by noxn3.id asc) as Y3IOU, noxn3.id as XLFIA]\n" +
" └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id]\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" +
" └─ LeftOuterHashJoin\n" +
" ├─ Eq\n" +
" │ ├─ sn.BRQP2:1!null\n" +
" │ └─ i2gj5.LUEVY:2!null\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: sn\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (12,13)\n" +
" │ ├─ tableId: 2\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" +
" │ ├─ colSet: (1-10)\n" +
" │ ├─ tableId: 1\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:1!null)\n" +
" ├─ right-key: TUPLE(i2gj5.LUEVY:0!null)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: i2gj5\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (42,43)\n" +
" ├─ tableId: 7\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (33,34)\n" +
" │ ├─ tableId: 4\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" +
" │ ├─ colSet: (14-30)\n" +
" │ └─ tableId: 3\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" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (39,40)\n" +
" ├─ tableId: 6\n" +
" └─ Project\n" +
" ├─ columns: [tnmxi.id:0!null as MLECF, tnmxi.DZLIM:1!null]\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" ├─ columns: [id dzlim]\n" +
" ├─ colSet: (35-37)\n" +
" └─ tableId: 5\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [i2gj5.R2SR7]\n" +
" └─ Sort(sn.XLFIA ASC)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (sn.BRQP2 = i2gj5.LUEVY)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: sn\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id as XLFIA, noxn3.BRQP2]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.A7XO2, noxn3.KBO7R, noxn3.ECDKM, noxn3.NUMK2, noxn3.LETOE, noxn3.YKSSU, noxn3.FHCYT, noxn3.id as XLFIA]\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (sn.BRQP2)\n" +
" ├─ right-key: (i2gj5.LUEVY)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: i2gj5\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.LUEVY, CASE WHEN (nma.DZLIM = 'Q5I4E') THEN 1 ELSE 0 END as R2SR7]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (nd.HPCMS = nma.MLECF)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id as LUEVY, e2i7u.HPCMS as HPCMS]\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id hpcms]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (nd.HPCMS)\n" +
" ├─ right-key: (nma.MLECF)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nma\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [tnmxi.id as MLECF, tnmxi.DZLIM]\n" +
" └─ Table\n" +
" ├─ name: TNMXI\n" +
" └─ columns: [id dzlim]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [i2gj5.R2SR7]\n" +
" └─ Sort(sn.XLFIA ASC)\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (sn.BRQP2 = i2gj5.LUEVY)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: sn\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id as XLFIA, noxn3.BRQP2]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.A7XO2, noxn3.KBO7R, noxn3.ECDKM, noxn3.NUMK2, noxn3.LETOE, noxn3.YKSSU, noxn3.FHCYT, noxn3.id as XLFIA]\n" +
" │ └─ IndexedTableAccess(NOXN3)\n" +
" │ ├─ index: [NOXN3.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (sn.BRQP2)\n" +
" ├─ right-key: (i2gj5.LUEVY)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: i2gj5\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nd.LUEVY, CASE WHEN (nma.DZLIM = 'Q5I4E') THEN 1 ELSE 0 END as R2SR7]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (nd.HPCMS = nma.MLECF)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: nd\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [e2i7u.id as LUEVY, e2i7u.HPCMS as HPCMS]\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id hpcms]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (nd.HPCMS)\n" +
" ├─ right-key: (nma.MLECF)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: nma\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [tnmxi.id as MLECF, tnmxi.DZLIM]\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (13,14)\n" +
" │ ├─ tableId: 2\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" +
" │ ├─ colSet: (1-10)\n" +
" │ └─ tableId: 1\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" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (35,36)\n" +
" ├─ tableId: 4\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" +
" ├─ colSet: (15-31)\n" +
" └─ tableId: 3\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [qi2ie.DICQO as DICQO]\n" +
" └─ Sort(grrb6.XLFIA ASC)\n" +
" └─ Project\n" +
" ├─ columns: [grrb6.XLFIA, grrb6.AHMDT, qi2ie.DICQO, qi2ie.VIBZI, qi2ie.DICQO as DICQO]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (qi2ie.VIBZI = grrb6.AHMDT)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: grrb6\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id as XLFIA, noxn3.BRQP2 as AHMDT]\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (grrb6.AHMDT)\n" +
" ├─ right-key: (qi2ie.VIBZI)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: qi2ie\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by e2i7u.id asc) as DICQO, e2i7u.id as VIBZI]\n" +
" └─ Window(row_number() over ( order by e2i7u.id ASC), e2i7u.id)\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [qi2ie.DICQO as DICQO]\n" +
" └─ Sort(grrb6.XLFIA ASC)\n" +
" └─ Project\n" +
" ├─ columns: [grrb6.XLFIA, grrb6.AHMDT, qi2ie.DICQO, qi2ie.VIBZI, qi2ie.DICQO as DICQO]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (qi2ie.VIBZI = grrb6.AHMDT)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: grrb6\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [noxn3.id as XLFIA, noxn3.BRQP2 as AHMDT]\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id brqp2]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (grrb6.AHMDT)\n" +
" ├─ right-key: (qi2ie.VIBZI)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: qi2ie\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by e2i7u.id asc) as DICQO, e2i7u.id as VIBZI]\n" +
" └─ Window(row_number() over ( order by e2i7u.id ASC), e2i7u.id)\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: "Sort(cla.FTQLQ:0!null ASC nullsFirst)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ:1!null]\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" +
" │ └─ bs.IXUXU:0\n" +
" ├─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.IXUXU:2]\n" +
" │ └─ SemiLookupJoin\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [bs.id:0!null, bs.NFRYN:1!null, bs.IXUXU:2, bs.FHCYT:3]\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ bs.id:0!null\n" +
" │ │ │ └─ hgmq6.GXLUB:4!null\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.id]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (31-34)\n" +
" │ │ │ ├─ tableId: 2\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [hgmq6.GXLUB:1!null]\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.GXLUB]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (35-51)\n" +
" │ │ ├─ tableId: 3\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" +
" │ └─ Project\n" +
" │ ├─ columns: [amyxq.GXLUB:1!null]\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.GXLUB]\n" +
" │ ├─ keys: [bs.id:0!null]\n" +
" │ ├─ colSet: (52-59)\n" +
" │ ├─ tableId: 4\n" +
" │ └─ Table\n" +
" │ ├─ name: AMYXQ\n" +
" │ └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(bs.IXUXU:0)\n" +
" ├─ right-key: TUPLE(cla.id:0!null)\n" +
" └─ TableAlias(cla)\n" +
" └─ ProcessTable\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" +
"",
ExpectedEstimates: "Sort(cla.FTQLQ ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ]\n" +
" └─ Project\n" +
" ├─ columns: [cla.id, cla.FTQLQ, cla.TUXML, cla.PAEF5, cla.RUCY4, cla.TPNJ6, cla.LBL53, cla.NB3QS, cla.EO7IV, cla.MUHJF, cla.FM34L, cla.TY5RF, cla.ZHTLH, cla.NPB7W, cla.SX3HH, cla.ISBNF, cla.YA7YB, cla.C5YKB, cla.QK7KT, cla.FFGE6, cla.FIIGJ, cla.SH3NC, cla.NTENA, cla.M4AUB, cla.X5AIR, cla.SAB6M, cla.G5QI5, cla.ZVQVD, cla.YKSSU, cla.FHCYT]\n" +
" └─ HashJoin\n" +
" ├─ (cla.id = bs.IXUXU)\n" +
" ├─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.IXUXU]\n" +
" │ └─ SemiLookupJoin\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [bs.id, bs.NFRYN, bs.IXUXU, bs.FHCYT]\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: (bs.id = hgmq6.GXLUB)\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.id]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [hgmq6.GXLUB]\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.GXLUB]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [amyxq.GXLUB]\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.GXLUB]\n" +
" │ └─ keys: bs.id\n" +
" └─ HashLookup\n" +
" ├─ left-key: (bs.IXUXU)\n" +
" ├─ right-key: (cla.id)\n" +
" └─ TableAlias(cla)\n" +
" └─ Table\n" +
" └─ name: YK2GW\n" +
"",
ExpectedAnalysis: "Sort(cla.FTQLQ ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ]\n" +
" └─ Project\n" +
" ├─ columns: [cla.id, cla.FTQLQ, cla.TUXML, cla.PAEF5, cla.RUCY4, cla.TPNJ6, cla.LBL53, cla.NB3QS, cla.EO7IV, cla.MUHJF, cla.FM34L, cla.TY5RF, cla.ZHTLH, cla.NPB7W, cla.SX3HH, cla.ISBNF, cla.YA7YB, cla.C5YKB, cla.QK7KT, cla.FFGE6, cla.FIIGJ, cla.SH3NC, cla.NTENA, cla.M4AUB, cla.X5AIR, cla.SAB6M, cla.G5QI5, cla.ZVQVD, cla.YKSSU, cla.FHCYT]\n" +
" └─ HashJoin\n" +
" ├─ (cla.id = bs.IXUXU)\n" +
" ├─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.IXUXU]\n" +
" │ └─ SemiLookupJoin\n" +
" │ ├─ Project\n" +
" │ │ ├─ columns: [bs.id, bs.NFRYN, bs.IXUXU, bs.FHCYT]\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: (bs.id = hgmq6.GXLUB)\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.id]\n" +
" │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [hgmq6.GXLUB]\n" +
" │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ ├─ index: [HGMQ6.GXLUB]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [amyxq.GXLUB]\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.GXLUB]\n" +
" │ └─ keys: bs.id\n" +
" └─ HashLookup\n" +
" ├─ left-key: (bs.IXUXU)\n" +
" ├─ right-key: (cla.id)\n" +
" └─ TableAlias(cla)\n" +
" └─ Table\n" +
" └─ name: YK2GW\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: "Sort(cla.FTQLQ:0!null ASC nullsFirst)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ:4!null]\n" +
" └─ HashJoin\n" +
" ├─ Eq\n" +
" │ ├─ mf.GXLUB:0!null\n" +
" │ └─ bs.id:1!null\n" +
" ├─ TableAlias(mf)\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: HGMQ6\n" +
" │ └─ columns: [gxlub]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(mf.GXLUB:0!null)\n" +
" ├─ right-key: TUPLE(bs.id:0!null)\n" +
" └─ MergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ bs.IXUXU:2\n" +
" │ └─ cla.id:3!null\n" +
" ├─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (18-21)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: THNTS\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ TableAlias(cla)\n" +
" └─ IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (22-51)\n" +
" ├─ tableId: 3\n" +
" └─ Table\n" +
" ├─ name: YK2GW\n" +
" └─ columns: [id ftqlq]\n" +
"",
ExpectedEstimates: "Sort(cla.FTQLQ ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ]\n" +
" └─ HashJoin\n" +
" ├─ (mf.GXLUB = bs.id)\n" +
" ├─ TableAlias(mf)\n" +
" │ └─ Table\n" +
" │ ├─ name: HGMQ6\n" +
" │ └─ columns: [gxlub]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (mf.GXLUB)\n" +
" ├─ right-key: (bs.id)\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (bs.IXUXU = cla.id)\n" +
" ├─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ TableAlias(cla)\n" +
" └─ IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id ftqlq]\n" +
"",
ExpectedAnalysis: "Sort(cla.FTQLQ ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ]\n" +
" └─ HashJoin\n" +
" ├─ (mf.GXLUB = bs.id)\n" +
" ├─ TableAlias(mf)\n" +
" │ └─ Table\n" +
" │ ├─ name: HGMQ6\n" +
" │ └─ columns: [gxlub]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (mf.GXLUB)\n" +
" ├─ right-key: (bs.id)\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (bs.IXUXU = cla.id)\n" +
" ├─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id ixuxu]\n" +
" └─ TableAlias(cla)\n" +
" └─ IndexedTableAccess(YK2GW)\n" +
" ├─ index: [YK2GW.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id ftqlq]\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: "Sort(cla.FTQLQ:0!null ASC nullsFirst)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ:1!null]\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" +
" │ └─ bs.IXUXU:0\n" +
" ├─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.IXUXU:2]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.id:0!null, bs.NFRYN:1!null, bs.IXUXU:2, bs.FHCYT:3]\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ bs.id:0!null\n" +
" │ │ └─ amyxq.GXLUB:4!null\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (31-34)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: THNTS\n" +
" │ │ └─ columns: [id nfryn ixuxu fhcyt]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [amyxq.GXLUB:1!null]\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ ├─ colSet: (35-42)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Table\n" +
" │ ├─ name: AMYXQ\n" +
" │ └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(bs.IXUXU:0)\n" +
" ├─ right-key: TUPLE(cla.id:0!null)\n" +
" └─ TableAlias(cla)\n" +
" └─ ProcessTable\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" +
"",
ExpectedEstimates: "Sort(cla.FTQLQ ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ]\n" +
" └─ Project\n" +
" ├─ columns: [cla.id, cla.FTQLQ, cla.TUXML, cla.PAEF5, cla.RUCY4, cla.TPNJ6, cla.LBL53, cla.NB3QS, cla.EO7IV, cla.MUHJF, cla.FM34L, cla.TY5RF, cla.ZHTLH, cla.NPB7W, cla.SX3HH, cla.ISBNF, cla.YA7YB, cla.C5YKB, cla.QK7KT, cla.FFGE6, cla.FIIGJ, cla.SH3NC, cla.NTENA, cla.M4AUB, cla.X5AIR, cla.SAB6M, cla.G5QI5, cla.ZVQVD, cla.YKSSU, cla.FHCYT]\n" +
" └─ HashJoin\n" +
" ├─ (cla.id = bs.IXUXU)\n" +
" ├─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.IXUXU]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.id, bs.NFRYN, bs.IXUXU, bs.FHCYT]\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (bs.id = amyxq.GXLUB)\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [amyxq.GXLUB]\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" │ └─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (bs.IXUXU)\n" +
" ├─ right-key: (cla.id)\n" +
" └─ TableAlias(cla)\n" +
" └─ Table\n" +
" └─ name: YK2GW\n" +
"",
ExpectedAnalysis: "Sort(cla.FTQLQ ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [cla.FTQLQ]\n" +
" └─ Project\n" +
" ├─ columns: [cla.id, cla.FTQLQ, cla.TUXML, cla.PAEF5, cla.RUCY4, cla.TPNJ6, cla.LBL53, cla.NB3QS, cla.EO7IV, cla.MUHJF, cla.FM34L, cla.TY5RF, cla.ZHTLH, cla.NPB7W, cla.SX3HH, cla.ISBNF, cla.YA7YB, cla.C5YKB, cla.QK7KT, cla.FFGE6, cla.FIIGJ, cla.SH3NC, cla.NTENA, cla.M4AUB, cla.X5AIR, cla.SAB6M, cla.G5QI5, cla.ZVQVD, cla.YKSSU, cla.FHCYT]\n" +
" └─ HashJoin\n" +
" ├─ (cla.id = bs.IXUXU)\n" +
" ├─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.IXUXU]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [bs.id, bs.NFRYN, bs.IXUXU, bs.FHCYT]\n" +
" │ └─ MergeJoin\n" +
" │ ├─ cmp: (bs.id = amyxq.GXLUB)\n" +
" │ ├─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.id]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [amyxq.GXLUB]\n" +
" │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" │ └─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" └─ HashLookup\n" +
" ├─ left-key: (bs.IXUXU)\n" +
" ├─ right-key: (cla.id)\n" +
" └─ TableAlias(cla)\n" +
" └─ Table\n" +
" └─ name: YK2GW\n" +
"",
},
{
Query: `
SELECT
DISTINCT ci.FTQLQ
FROM FLQLP ct
INNER JOIN JDLNA ci
ON ct.FZ2R5 = ci.id
ORDER BY ci.FTQLQ`,
ExpectedPlan: "Sort(ci.FTQLQ:0!null ASC nullsFirst)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ci.FTQLQ:2!null]\n" +
" └─ MergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ ct.FZ2R5:0!null\n" +
" │ └─ ci.id:1!null\n" +
" ├─ TableAlias(ct)\n" +
" │ └─ IndexedTableAccess(FLQLP)\n" +
" │ ├─ index: [FLQLP.FZ2R5]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (1-12)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: FLQLP\n" +
" │ └─ columns: [fz2r5]\n" +
" └─ TableAlias(ci)\n" +
" └─ IndexedTableAccess(JDLNA)\n" +
" ├─ index: [JDLNA.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (13-17)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: JDLNA\n" +
" └─ columns: [id ftqlq]\n" +
"",
ExpectedEstimates: "Sort(ci.FTQLQ ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ci.FTQLQ]\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (ct.FZ2R5 = ci.id)\n" +
" ├─ TableAlias(ct)\n" +
" │ └─ IndexedTableAccess(FLQLP)\n" +
" │ ├─ index: [FLQLP.FZ2R5]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [fz2r5]\n" +
" └─ TableAlias(ci)\n" +
" └─ IndexedTableAccess(JDLNA)\n" +
" ├─ index: [JDLNA.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id ftqlq]\n" +
"",
ExpectedAnalysis: "Sort(ci.FTQLQ ASC)\n" +
" └─ Distinct\n" +
" └─ Project\n" +
" ├─ columns: [ci.FTQLQ]\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (ct.FZ2R5 = ci.id)\n" +
" ├─ TableAlias(ct)\n" +
" │ └─ IndexedTableAccess(FLQLP)\n" +
" │ ├─ index: [FLQLP.FZ2R5]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [fz2r5]\n" +
" └─ TableAlias(ci)\n" +
" └─ IndexedTableAccess(JDLNA)\n" +
" ├─ index: [JDLNA.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id ftqlq]\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (41-52)\n" +
" │ ├─ tableId: 4\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" +
" │ │ ├─ alias-string: select XQDYT from AMYXQ where LUEVY = nd.id limit 1\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" +
" │ │ ├─ keys: [nd.id:0!null]\n" +
" │ │ ├─ colSet: (29-36)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: AMYXQ\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" +
" │ │ ├─ alias-string: select XQDYT from AMYXQ where LUEVY = nd.id limit 1\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" +
" │ │ ├─ keys: [nd.id:0!null]\n" +
" │ │ ├─ colSet: (29-36)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: AMYXQ\n" +
" │ │ └─ columns: [luevy xqdyt]\n" +
" │ │ as I3L5A, nd.ETAQ7:15 as FUG6J, nd.A75X7:16 as NF5AM, nd.FSK67:8!null as FRCVC]\n" +
" │ └─ LeftOuterLookupJoin\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" +
" │ │ ├─ colSet: (1-17)\n" +
" │ │ └─ tableId: 1\n" +
" │ └─ TableAlias(nma)\n" +
" │ └─ IndexedTableAccess(TNMXI)\n" +
" │ ├─ index: [TNMXI.id]\n" +
" │ ├─ keys: [nd.HPCMS:12!null]\n" +
" │ ├─ colSet: (18-20)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: TNMXI\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" +
" └─ ProcessTable\n" +
" └─ Table\n" +
" ├─ name: XGSJM\n" +
" └─ columns: [id dzlim f3yue]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Sort(ypgda.LUEVY as LUEVY ASC)\n" +
" └─ Project\n" +
" ├─ columns: [ypgda.LUEVY, ypgda.TW55N, ypgda.IYDZV, ypgda.QRQXW, ypgda.CAECS, ypgda.CJLLY, ypgda.SHP7H, ypgda.HARAZ, ypgda.I3L5A, ypgda.FUG6J, ypgda.NF5AM, ypgda.FRCVC, ybbg5.id, ybbg5.DZLIM, ybbg5.F3YUE, 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]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (ypgda.I3L5A = ybbg5.id)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: ypgda\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [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, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.XQDYT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (amyxq.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [luevy xqdyt]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as I3L5A, nd.ETAQ7 as FUG6J, nd.A75X7 as NF5AM, nd.FSK67 as FRCVC]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nma.id, nma.DZLIM, nma.F3YUE, 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, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.XQDYT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (amyxq.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [luevy xqdyt]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as I3L5A, nd.ETAQ7 as FUG6J, nd.A75X7 as NF5AM, nd.FSK67 as FRCVC]\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ TableAlias(nd)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: E2I7U\n" +
" │ └─ TableAlias(nma)\n" +
" │ └─ IndexedTableAccess(TNMXI)\n" +
" │ ├─ index: [TNMXI.id]\n" +
" │ └─ keys: nd.HPCMS\n" +
" └─ HashLookup\n" +
" ├─ left-key: (ypgda.I3L5A)\n" +
" ├─ right-key: (ybbg5.id)\n" +
" └─ TableAlias(ybbg5)\n" +
" └─ Table\n" +
" ├─ name: XGSJM\n" +
" └─ columns: [id dzlim f3yue]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Sort(ypgda.LUEVY as LUEVY ASC)\n" +
" └─ Project\n" +
" ├─ columns: [ypgda.LUEVY, ypgda.TW55N, ypgda.IYDZV, ypgda.QRQXW, ypgda.CAECS, ypgda.CJLLY, ypgda.SHP7H, ypgda.HARAZ, ypgda.I3L5A, ypgda.FUG6J, ypgda.NF5AM, ypgda.FRCVC, ybbg5.id, ybbg5.DZLIM, ybbg5.F3YUE, 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]\n" +
" └─ LeftOuterHashJoin\n" +
" ├─ (ypgda.I3L5A = ybbg5.id)\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: ypgda\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [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, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.XQDYT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (amyxq.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [luevy xqdyt]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as I3L5A, nd.ETAQ7 as FUG6J, nd.A75X7 as NF5AM, nd.FSK67 as FRCVC]\n" +
" │ └─ Project\n" +
" │ ├─ columns: [nd.id, nd.DKCAJ, nd.KNG7T, nd.TW55N, nd.QRQXW, nd.ECXAJ, nd.FGG57, nd.ZH72S, nd.FSK67, nd.XQDYT, nd.TCE7A, nd.IWV2H, nd.HPCMS, nd.N5CC2, nd.FHCYT, nd.ETAQ7, nd.A75X7, nma.id, nma.DZLIM, nma.F3YUE, 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, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ └─ Limit(1)\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [amyxq.XQDYT]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (amyxq.LUEVY = nd.id)\n" +
" │ │ └─ IndexedTableAccess(AMYXQ)\n" +
" │ │ ├─ index: [AMYXQ.LUEVY]\n" +
" │ │ ├─ columns: [luevy xqdyt]\n" +
" │ │ └─ keys: nd.id\n" +
" │ │ as I3L5A, nd.ETAQ7 as FUG6J, nd.A75X7 as NF5AM, nd.FSK67 as FRCVC]\n" +
" │ └─ LeftOuterLookupJoin\n" +
" │ ├─ TableAlias(nd)\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: E2I7U\n" +
" │ └─ TableAlias(nma)\n" +
" │ └─ IndexedTableAccess(TNMXI)\n" +
" │ ├─ index: [TNMXI.id]\n" +
" │ └─ keys: nd.HPCMS\n" +
" └─ HashLookup\n" +
" ├─ left-key: (ypgda.I3L5A)\n" +
" ├─ right-key: (ybbg5.id)\n" +
" └─ TableAlias(ybbg5)\n" +
" └─ Table\n" +
" ├─ name: XGSJM\n" +
" └─ columns: [id dzlim f3yue]\n" +
"",
},
{
Query: `
SELECT LUEVY, F6NSZ FROM ARLV5`,
ExpectedPlan: "ProcessTable\n" +
" └─ Table\n" +
" ├─ name: ARLV5\n" +
" └─ columns: [luevy f6nsz]\n" +
"",
ExpectedEstimates: "Table\n" +
" ├─ name: ARLV5\n" +
" └─ columns: [luevy f6nsz]\n" +
"",
ExpectedAnalysis: "Table\n" +
" ├─ name: ARLV5\n" +
" └─ columns: [luevy f6nsz]\n" +
"",
},
{
Query: `
SELECT id, DZLIM FROM IIISV`,
ExpectedPlan: "ProcessTable\n" +
" └─ Table\n" +
" ├─ name: IIISV\n" +
" └─ columns: [id dzlim]\n" +
"",
ExpectedEstimates: "Table\n" +
" ├─ name: IIISV\n" +
" └─ columns: [id dzlim]\n" +
"",
ExpectedAnalysis: "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" +
" └─ LeftOuterLookupJoin\n" +
" ├─ LeftOuterLookupJoin\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" +
" │ │ │ ├─ colSet: (1-10)\n" +
" │ │ │ ├─ tableId: 1\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\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" +
" │ │ ├─ colSet: (11-27)\n" +
" │ │ ├─ tableId: 2\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(lsm32)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ keys: [sn.FFTBJ:2!null]\n" +
" │ ├─ colSet: (28-44)\n" +
" │ ├─ tableId: 3\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(it)\n" +
" └─ IndexedTableAccess(FEVH4)\n" +
" ├─ index: [FEVH4.id]\n" +
" ├─ keys: [sn.A7XO2:3]\n" +
" ├─ colSet: (45-47)\n" +
" ├─ tableId: 4\n" +
" └─ Table\n" +
" ├─ name: FEVH4\n" +
" └─ columns: [id dzlim f3yue]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Sort(sn.id ASC)\n" +
" └─ Project\n" +
" ├─ columns: [sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, tvqg4.id, tvqg4.DKCAJ, tvqg4.KNG7T, tvqg4.TW55N, tvqg4.QRQXW, tvqg4.ECXAJ, tvqg4.FGG57, tvqg4.ZH72S, tvqg4.FSK67, tvqg4.XQDYT, tvqg4.TCE7A, tvqg4.IWV2H, tvqg4.HPCMS, tvqg4.N5CC2, tvqg4.FHCYT, tvqg4.ETAQ7, tvqg4.A75X7, lsm32.id, lsm32.DKCAJ, lsm32.KNG7T, lsm32.TW55N, lsm32.QRQXW, lsm32.ECXAJ, lsm32.FGG57, lsm32.ZH72S, lsm32.FSK67, lsm32.XQDYT, lsm32.TCE7A, lsm32.IWV2H, lsm32.HPCMS, lsm32.N5CC2, lsm32.FHCYT, lsm32.ETAQ7, lsm32.A75X7, it.id, it.DZLIM, it.F3YUE, 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]\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ LeftOuterLookupJoin\n" +
" │ ├─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: (sn.BRQP2 = tvqg4.id)\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ TableAlias(tvqg4)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ TableAlias(lsm32)\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" +
" │ └─ keys: sn.FFTBJ\n" +
" └─ TableAlias(it)\n" +
" └─ IndexedTableAccess(FEVH4)\n" +
" ├─ index: [FEVH4.id]\n" +
" ├─ columns: [id dzlim f3yue]\n" +
" └─ keys: sn.A7XO2\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Sort(sn.id ASC)\n" +
" └─ Project\n" +
" ├─ columns: [sn.id, sn.BRQP2, sn.FFTBJ, sn.A7XO2, sn.KBO7R, sn.ECDKM, sn.NUMK2, sn.LETOE, sn.YKSSU, sn.FHCYT, tvqg4.id, tvqg4.DKCAJ, tvqg4.KNG7T, tvqg4.TW55N, tvqg4.QRQXW, tvqg4.ECXAJ, tvqg4.FGG57, tvqg4.ZH72S, tvqg4.FSK67, tvqg4.XQDYT, tvqg4.TCE7A, tvqg4.IWV2H, tvqg4.HPCMS, tvqg4.N5CC2, tvqg4.FHCYT, tvqg4.ETAQ7, tvqg4.A75X7, lsm32.id, lsm32.DKCAJ, lsm32.KNG7T, lsm32.TW55N, lsm32.QRQXW, lsm32.ECXAJ, lsm32.FGG57, lsm32.ZH72S, lsm32.FSK67, lsm32.XQDYT, lsm32.TCE7A, lsm32.IWV2H, lsm32.HPCMS, lsm32.N5CC2, lsm32.FHCYT, lsm32.ETAQ7, lsm32.A75X7, it.id, it.DZLIM, it.F3YUE, 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]\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ LeftOuterLookupJoin\n" +
" │ ├─ LeftOuterMergeJoin\n" +
" │ │ ├─ cmp: (sn.BRQP2 = tvqg4.id)\n" +
" │ │ ├─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ TableAlias(tvqg4)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [id dkcaj kng7t tw55n qrqxw ecxaj fgg57 zh72s fsk67 xqdyt tce7a iwv2h hpcms n5cc2 fhcyt etaq7 a75x7]\n" +
" │ └─ TableAlias(lsm32)\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" +
" │ └─ keys: sn.FFTBJ\n" +
" └─ TableAlias(it)\n" +
" └─ IndexedTableAccess(FEVH4)\n" +
" ├─ index: [FEVH4.id]\n" +
" ├─ columns: [id dzlim f3yue]\n" +
" └─ keys: sn.A7XO2\n" +
"",
},
{
Query: `
SELECT
KBO7R
FROM
NOXN3
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [noxn3.KBO7R:1!null]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (1-10)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id kbo7r]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [noxn3.KBO7R]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id kbo7r]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [noxn3.KBO7R]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id kbo7r]\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" +
" └─ LeftOuterLookupJoin\n" +
" ├─ LeftOuterLookupJoin\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ LeftOuterLookupJoin\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" +
" │ │ │ │ │ ├─ colSet: (1-6)\n" +
" │ │ │ │ │ ├─ tableId: 1\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: QYWQD\n" +
" │ │ │ │ │ └─ columns: [id wnunu hhvlx hvhrz ykssu fhcyt]\n" +
" │ │ │ │ └─ TableAlias(jgt2h)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (7-16)\n" +
" │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NOXN3\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ TableAlias(ayfcd)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ ├─ keys: [rn.HHVLX:2!null]\n" +
" │ │ │ ├─ colSet: (17-26)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ └─ TableAlias(sdllr)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.id]\n" +
" │ │ ├─ keys: [jgt2h.BRQP2:7!null]\n" +
" │ │ ├─ colSet: (27-43)\n" +
" │ │ ├─ tableId: 4\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(riiw6)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ keys: [jgt2h.FFTBJ:8!null]\n" +
" │ ├─ colSet: (44-60)\n" +
" │ ├─ tableId: 5\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(fa75y)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ keys: [ayfcd.FFTBJ:18!null]\n" +
" ├─ colSet: (61-77)\n" +
" ├─ tableId: 6\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" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Sort(rn.id ASC)\n" +
" └─ Project\n" +
" ├─ columns: [rn.id, rn.WNUNU, rn.HHVLX, rn.HVHRZ, rn.YKSSU, rn.FHCYT, jgt2h.id, jgt2h.BRQP2, jgt2h.FFTBJ, jgt2h.A7XO2, jgt2h.KBO7R, jgt2h.ECDKM, jgt2h.NUMK2, jgt2h.LETOE, jgt2h.YKSSU, jgt2h.FHCYT, ayfcd.id, ayfcd.BRQP2, ayfcd.FFTBJ, ayfcd.A7XO2, ayfcd.KBO7R, ayfcd.ECDKM, ayfcd.NUMK2, ayfcd.LETOE, ayfcd.YKSSU, ayfcd.FHCYT, sdllr.id, sdllr.DKCAJ, sdllr.KNG7T, sdllr.TW55N, sdllr.QRQXW, sdllr.ECXAJ, sdllr.FGG57, sdllr.ZH72S, sdllr.FSK67, sdllr.XQDYT, sdllr.TCE7A, sdllr.IWV2H, sdllr.HPCMS, sdllr.N5CC2, sdllr.FHCYT, sdllr.ETAQ7, sdllr.A75X7, riiw6.id, riiw6.DKCAJ, riiw6.KNG7T, riiw6.TW55N, riiw6.QRQXW, riiw6.ECXAJ, riiw6.FGG57, riiw6.ZH72S, riiw6.FSK67, riiw6.XQDYT, riiw6.TCE7A, riiw6.IWV2H, riiw6.HPCMS, riiw6.N5CC2, riiw6.FHCYT, riiw6.ETAQ7, riiw6.A75X7, fa75y.id, fa75y.DKCAJ, fa75y.KNG7T, fa75y.TW55N, fa75y.QRQXW, fa75y.ECXAJ, fa75y.FGG57, fa75y.ZH72S, fa75y.FSK67, fa75y.XQDYT, fa75y.TCE7A, fa75y.IWV2H, fa75y.HPCMS, fa75y.N5CC2, fa75y.FHCYT, fa75y.ETAQ7, fa75y.A75X7, 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]\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ LeftOuterLookupJoin\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ LeftOuterMergeJoin\n" +
" │ │ │ │ ├─ cmp: (rn.WNUNU = jgt2h.id)\n" +
" │ │ │ │ ├─ TableAlias(rn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(QYWQD)\n" +
" │ │ │ │ │ ├─ index: [QYWQD.WNUNU]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id wnunu hhvlx hvhrz ykssu fhcyt]\n" +
" │ │ │ │ └─ TableAlias(jgt2h)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ TableAlias(ayfcd)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ ├─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ keys: rn.HHVLX\n" +
" │ │ └─ TableAlias(sdllr)\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" +
" │ │ └─ keys: jgt2h.BRQP2\n" +
" │ └─ TableAlias(riiw6)\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" +
" │ └─ keys: jgt2h.FFTBJ\n" +
" └─ TableAlias(fa75y)\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" +
" └─ keys: ayfcd.FFTBJ\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [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]\n" +
" └─ Sort(rn.id ASC)\n" +
" └─ Project\n" +
" ├─ columns: [rn.id, rn.WNUNU, rn.HHVLX, rn.HVHRZ, rn.YKSSU, rn.FHCYT, jgt2h.id, jgt2h.BRQP2, jgt2h.FFTBJ, jgt2h.A7XO2, jgt2h.KBO7R, jgt2h.ECDKM, jgt2h.NUMK2, jgt2h.LETOE, jgt2h.YKSSU, jgt2h.FHCYT, ayfcd.id, ayfcd.BRQP2, ayfcd.FFTBJ, ayfcd.A7XO2, ayfcd.KBO7R, ayfcd.ECDKM, ayfcd.NUMK2, ayfcd.LETOE, ayfcd.YKSSU, ayfcd.FHCYT, sdllr.id, sdllr.DKCAJ, sdllr.KNG7T, sdllr.TW55N, sdllr.QRQXW, sdllr.ECXAJ, sdllr.FGG57, sdllr.ZH72S, sdllr.FSK67, sdllr.XQDYT, sdllr.TCE7A, sdllr.IWV2H, sdllr.HPCMS, sdllr.N5CC2, sdllr.FHCYT, sdllr.ETAQ7, sdllr.A75X7, riiw6.id, riiw6.DKCAJ, riiw6.KNG7T, riiw6.TW55N, riiw6.QRQXW, riiw6.ECXAJ, riiw6.FGG57, riiw6.ZH72S, riiw6.FSK67, riiw6.XQDYT, riiw6.TCE7A, riiw6.IWV2H, riiw6.HPCMS, riiw6.N5CC2, riiw6.FHCYT, riiw6.ETAQ7, riiw6.A75X7, fa75y.id, fa75y.DKCAJ, fa75y.KNG7T, fa75y.TW55N, fa75y.QRQXW, fa75y.ECXAJ, fa75y.FGG57, fa75y.ZH72S, fa75y.FSK67, fa75y.XQDYT, fa75y.TCE7A, fa75y.IWV2H, fa75y.HPCMS, fa75y.N5CC2, fa75y.FHCYT, fa75y.ETAQ7, fa75y.A75X7, 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]\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ LeftOuterLookupJoin\n" +
" │ ├─ LeftOuterLookupJoin\n" +
" │ │ ├─ LeftOuterLookupJoin\n" +
" │ │ │ ├─ LeftOuterMergeJoin\n" +
" │ │ │ │ ├─ cmp: (rn.WNUNU = jgt2h.id)\n" +
" │ │ │ │ ├─ TableAlias(rn)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(QYWQD)\n" +
" │ │ │ │ │ ├─ index: [QYWQD.WNUNU]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [id wnunu hhvlx hvhrz ykssu fhcyt]\n" +
" │ │ │ │ └─ TableAlias(jgt2h)\n" +
" │ │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ TableAlias(ayfcd)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.id]\n" +
" │ │ │ ├─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
" │ │ │ └─ keys: rn.HHVLX\n" +
" │ │ └─ TableAlias(sdllr)\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" +
" │ │ └─ keys: jgt2h.BRQP2\n" +
" │ └─ TableAlias(riiw6)\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" +
" │ └─ keys: jgt2h.FFTBJ\n" +
" └─ TableAlias(fa75y)\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" +
" └─ keys: ayfcd.FFTBJ\n" +
"",
},
{
Query: `
SELECT
QRQXW
FROM
E2I7U
ORDER BY id ASC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [e2i7u.QRQXW:1!null]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: E2I7U\n" +
" └─ columns: [id qrqxw]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [e2i7u.QRQXW]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id qrqxw]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [e2i7u.QRQXW]\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id qrqxw]\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" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (13-16)\n" +
" ├─ tableId: 2\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ noxn3.NUMK2:2!null\n" +
" │ └─ 4 (int)\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" +
" ├─ colSet: (1-10)\n" +
" └─ tableId: 1\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [sn.Y3IOU, sn.ECDKM]\n" +
" └─ Sort(sn.id ASC)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: sn\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Filter\n" +
" ├─ (noxn3.NUMK2 = 4)\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by noxn3.id asc) as Y3IOU, noxn3.id, noxn3.NUMK2, noxn3.ECDKM]\n" +
" └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id, noxn3.NUMK2, noxn3.ECDKM)\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id ecdkm numk2]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [sn.Y3IOU, sn.ECDKM]\n" +
" └─ Sort(sn.id ASC)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: sn\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Filter\n" +
" ├─ (noxn3.NUMK2 = 4)\n" +
" └─ Project\n" +
" ├─ columns: [row_number() over ( order by noxn3.id asc) as Y3IOU, noxn3.id, noxn3.NUMK2, noxn3.ECDKM]\n" +
" └─ Window(row_number() over ( order by noxn3.id ASC), noxn3.id, noxn3.NUMK2, noxn3.ECDKM)\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:2!null, noxn3.ECDKM:1]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (1-10)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id ecdkm numk2]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [noxn3.id, noxn3.NUMK2, noxn3.ECDKM]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id ecdkm numk2]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [noxn3.id, noxn3.NUMK2, noxn3.ECDKM]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id ecdkm numk2]\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 (int)\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 (int)\n" +
" │ THEN noxn3.ECDKM:5 ELSE 0 (tinyint) END as RGXLL]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (1-10)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: NOXN3\n" +
" └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [CASE WHEN (noxn3.NUMK2 = 2) THEN noxn3.ECDKM ELSE 0 END as RGXLL]\n" +
" └─ Project\n" +
" ├─ columns: [noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.A7XO2, noxn3.KBO7R, noxn3.ECDKM, noxn3.NUMK2, noxn3.LETOE, noxn3.YKSSU, noxn3.FHCYT, CASE WHEN (noxn3.NUMK2 = 2) THEN noxn3.ECDKM ELSE 0 END as RGXLL]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id brqp2 fftbj a7xo2 kbo7r ecdkm numk2 letoe ykssu fhcyt]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [CASE WHEN (noxn3.NUMK2 = 2) THEN noxn3.ECDKM ELSE 0 END as RGXLL]\n" +
" └─ Project\n" +
" ├─ columns: [noxn3.id, noxn3.BRQP2, noxn3.FFTBJ, noxn3.A7XO2, noxn3.KBO7R, noxn3.ECDKM, noxn3.NUMK2, noxn3.LETOE, noxn3.YKSSU, noxn3.FHCYT, CASE WHEN (noxn3.NUMK2 = 2) THEN noxn3.ECDKM ELSE 0 END as RGXLL]\n" +
" └─ IndexedTableAccess(NOXN3)\n" +
" ├─ index: [NOXN3.id]\n" +
" ├─ filters: [{[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:5!null as ECUWU, nd.TW55N:3!null]\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ TableAlias(qnrbh)\n" +
" │ │ └─ ProcessTable\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: JJGQT\n" +
" │ │ └─ columns: [ch3fr luevy]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ keys: [qnrbh.LUEVY:1!null]\n" +
" │ ├─ colSet: (4-20)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id tw55n]\n" +
" └─ TableAlias(pa)\n" +
" └─ IndexedTableAccess(XOAOP)\n" +
" ├─ index: [XOAOP.id]\n" +
" ├─ keys: [qnrbh.CH3FR:0!null]\n" +
" ├─ colSet: (21-23)\n" +
" ├─ tableId: 3\n" +
" └─ Table\n" +
" ├─ name: XOAOP\n" +
" └─ columns: [id dzlim]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [pa.DZLIM as ECUWU, nd.TW55N]\n" +
" └─ LookupJoin (estimated cost=19.800 rows=6)\n" +
" ├─ LookupJoin (estimated cost=19.800 rows=6)\n" +
" │ ├─ TableAlias(qnrbh)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: JJGQT\n" +
" │ │ └─ columns: [ch3fr luevy]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ columns: [id tw55n]\n" +
" │ └─ keys: qnrbh.LUEVY\n" +
" └─ TableAlias(pa)\n" +
" └─ IndexedTableAccess(XOAOP)\n" +
" ├─ index: [XOAOP.id]\n" +
" ├─ columns: [id dzlim]\n" +
" └─ keys: qnrbh.CH3FR\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [pa.DZLIM as ECUWU, nd.TW55N]\n" +
" └─ LookupJoin (estimated cost=19.800 rows=6) (actual rows=0 loops=1)\n" +
" ├─ LookupJoin (estimated cost=19.800 rows=6) (actual rows=0 loops=1)\n" +
" │ ├─ TableAlias(qnrbh)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: JJGQT\n" +
" │ │ └─ columns: [ch3fr luevy]\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.id]\n" +
" │ ├─ columns: [id tw55n]\n" +
" │ └─ keys: qnrbh.LUEVY\n" +
" └─ TableAlias(pa)\n" +
" └─ IndexedTableAccess(XOAOP)\n" +
" ├─ index: [XOAOP.id]\n" +
" ├─ columns: [id dzlim]\n" +
" └─ keys: qnrbh.CH3FR\n" +
"",
},
{
Query: `-- deletes
DELETE FROM QYWQD
WHERE id IN ('1','2','3')`,
ExpectedPlan: "Delete\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" ├─ colSet: (1-6)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: QYWQD\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: "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" +
" └─ ProcessTable\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: "Delete\n" +
" └─ IndexedTableAccess(QYWQD)\n" +
" ├─ index: [QYWQD.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" ├─ colSet: (1-6)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: QYWQD\n" +
" └─ columns: [id wnunu hhvlx hvhrz ykssu fhcyt]\n" +
"",
},
{
Query: `
DELETE FROM AMYXQ
WHERE LUEVY IN ('1', '2', '3')`,
ExpectedPlan: "Delete\n" +
" └─ IndexedTableAccess(AMYXQ)\n" +
" ├─ index: [AMYXQ.GXLUB,AMYXQ.LUEVY]\n" +
" ├─ static: [{[NULL, ∞), [1, 1]}, {[NULL, ∞), [2, 2]}, {[NULL, ∞), [3, 3]}]\n" +
" ├─ colSet: (1-8)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: AMYXQ\n" +
" └─ columns: [id gxlub luevy xqdyt amyxq oztqf z35gy kkgn5]\n" +
"",
},
{
Query: `
DELETE FROM HGMQ6
WHERE id IN ('1', '2', '3')`,
ExpectedPlan: "Delete\n" +
" └─ IndexedTableAccess(HGMQ6)\n" +
" ├─ index: [HGMQ6.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\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" +
"",
},
{
Query: `
DELETE FROM HDDVB
WHERE id IN ('1', '2', '3')`,
ExpectedPlan: "Delete\n" +
" └─ IndexedTableAccess(HDDVB)\n" +
" ├─ index: [HDDVB.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" ├─ colSet: (1-9)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: HDDVB\n" +
" └─ columns: [id fv24e uj6xy m22qn nz4mq etpqv pruv2 ykssu fhcyt]\n" +
"",
},
{
Query: `
DELETE FROM FLQLP
WHERE LUEVY IN ('1', '2', '3')`,
ExpectedPlan: "Delete\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.LUEVY]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" ├─ colSet: (1-12)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: FLQLP\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: "Delete\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" ├─ colSet: (1-12)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: FLQLP\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: "Delete\n" +
" └─ IndexedTableAccess(FLQLP)\n" +
" ├─ index: [FLQLP.id]\n" +
" ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" ├─ colSet: (1-12)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: FLQLP\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: "Update\n" +
" └─ UpdateSource(SET nd.KNG7T:2 = Subquery\n" +
" ├─ cacheable: false\n" +
" ├─ alias-string: select gn.id from WE72E as gn join TDRVG as ltnm on ltnm.SSHPJ = gn.SSHPJ where ltnm.FGG57 = nd.FGG57\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" +
" │ ├─ colSet: (18-21)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: WE72E\n" +
" │ └─ columns: [id sshpj]\n" +
" └─ TableAlias(ltnm)\n" +
" └─ IndexedTableAccess(TDRVG)\n" +
" ├─ index: [TDRVG.SSHPJ]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (22-26)\n" +
" ├─ tableId: 3\n" +
" └─ Table\n" +
" ├─ name: TDRVG\n" +
" └─ columns: [fgg57 sshpj]\n" +
" )\n" +
" └─ Filter\n" +
" ├─ NOT\n" +
" │ └─ nd.FGG57:6 IS NULL\n" +
" └─ TableAlias(nd)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.KNG7T]\n" +
" ├─ static: [{[NULL, NULL]}]\n" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\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: `
UPDATE S3FQX SET ADWYM = 0, FPUYA = 0`,
ExpectedPlan: "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" +
" │ └─ ProcessTable\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: "Insert(id, NFRYN, IXUXU, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ ├─ alias-string: select id from JMRQL where DZLIM = 'T4IBQ'\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jmrql.id:34!null]\n" +
" │ │ └─ IndexedTableAccess(JMRQL)\n" +
" │ │ ├─ index: [JMRQL.DZLIM]\n" +
" │ │ ├─ static: [{[T4IBQ, T4IBQ]}]\n" +
" │ │ ├─ colSet: (36-38)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: JMRQL\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" +
" │ │ ├─ alias-string: select id from JMRQL where DZLIM = 'T4IBQ'\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [jmrql.id:30!null]\n" +
" │ │ └─ IndexedTableAccess(JMRQL)\n" +
" │ │ ├─ index: [JMRQL.DZLIM]\n" +
" │ │ ├─ static: [{[T4IBQ, T4IBQ]}]\n" +
" │ │ ├─ colSet: (36-38)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: JMRQL\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as NFRYN, yk2gw.id:0!null as IXUXU, NULL (null) as FHCYT]\n" +
" │ └─ IndexedTableAccess(YK2GW)\n" +
" │ ├─ index: [YK2GW.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ ├─ colSet: (5-34)\n" +
" │ ├─ tableId: 2\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" +
" └─ 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: "Insert(id, WNUNU, HHVLX, HVHRZ, YKSSU, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (36-38)\n" +
" │ ├─ tableId: 5\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" +
" │ └─ LeftOuterLookupJoin\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 (int)\n" +
" │ │ │ └─ TableAlias(sn)\n" +
" │ │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ │ ├─ index: [NOXN3.FFTBJ]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (7-16)\n" +
" │ │ │ ├─ tableId: 2\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: NOXN3\n" +
" │ │ │ └─ columns: [id fftbj ecdkm numk2]\n" +
" │ │ └─ TableAlias(skpm6)\n" +
" │ │ └─ IndexedTableAccess(NOXN3)\n" +
" │ │ ├─ index: [NOXN3.BRQP2]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (17-26)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: NOXN3\n" +
" │ │ └─ columns: [id brqp2]\n" +
" │ └─ TableAlias(rn)\n" +
" │ └─ IndexedTableAccess(QYWQD)\n" +
" │ ├─ index: [QYWQD.WNUNU]\n" +
" │ ├─ keys: [sn.id:0!null]\n" +
" │ ├─ colSet: (27-32)\n" +
" │ ├─ tableId: 4\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" +
" │ ├─ alias-string: select FFTBJ from NOXN3 where id = NEW.WNUNU\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" +
" │ ├─ keys: [new.WNUNU:1!null]\n" +
" │ ├─ colSet: (13-22)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Table\n" +
" │ ├─ name: NOXN3\n" +
" │ └─ columns: [id fftbj]\n" +
" └─ Subquery\n" +
" ├─ cacheable: false\n" +
" ├─ alias-string: select BRQP2 from NOXN3 where id = NEW.HHVLX\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" +
" ├─ keys: [new.HHVLX:2!null]\n" +
" ├─ colSet: (23-32)\n" +
" ├─ tableId: 4\n" +
" └─ Table\n" +
" ├─ name: NOXN3\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: "Insert(id, QZ7E7, SSHPJ, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ └─ IndexedTableAccess(TDRVG)\n" +
" │ ├─ index: [TDRVG.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ ├─ colSet: (5-9)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: TDRVG\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" +
" │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ ├─ columns: [svaz4]\n" +
" │ ├─ colSet: (9,10)\n" +
" │ └─ tableId: 3\n" +
" └─ InSubquery\n" +
" ├─ left: new.SSHPJ:2!null\n" +
" └─ right: Subquery\n" +
" ├─ cacheable: false\n" +
" ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" └─ Table\n" +
" ├─ name: TPXHZ\n" +
" ├─ columns: [svaz4]\n" +
" ├─ colSet: (11,12)\n" +
" └─ tableId: 4\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: "Insert(id, GXLUB, LUEVY, XQDYT, AMYXQ, OZTQF, Z35GY, KKGN5)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ ├─ alias-string: select /*+ JOIN_ORDER(cla, bs) */ bs.id from THNTS as bs join YK2GW as cla on cla.id = bs.IXUXU where cla.FTQLQ = ufc.T4IBQ\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" +
" │ │ │ ├─ colSet: (45-74)\n" +
" │ │ │ ├─ tableId: 6\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: YK2GW\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (41-44)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: THNTS\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" +
" │ │ ├─ alias-string: select /*+ JOIN_ORDER(cla, bs) */ bs.id from THNTS as bs join YK2GW as cla on cla.id = bs.IXUXU where cla.FTQLQ = ufc.T4IBQ\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" +
" │ │ │ ├─ colSet: (45-74)\n" +
" │ │ │ ├─ tableId: 6\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: YK2GW\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ └─ TableAlias(bs)\n" +
" │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (41-44)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: THNTS\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" +
" │ └─ InnerJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ nd.ZH72S:18\n" +
" │ │ └─ ufc.ZH72S:2\n" +
" │ ├─ TableAlias(ufc)\n" +
" │ │ └─ IndexedTableAccess(SISUT)\n" +
" │ │ ├─ index: [SISUT.id]\n" +
" │ │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ │ ├─ colSet: (9-19)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SISUT\n" +
" │ │ └─ columns: [id t4ibq zh72s amyxq ktnz2 hiid2 dn3oq vvknb sh7tp srzzo qz6vt]\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" +
" │ │ ├─ colSet: (20-36)\n" +
" │ │ ├─ tableId: 3\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(ybbg5)\n" +
" │ └─ IndexedTableAccess(XGSJM)\n" +
" │ ├─ index: [XGSJM.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (37-39)\n" +
" │ ├─ tableId: 4\n" +
" │ └─ Table\n" +
" │ ├─ name: XGSJM\n" +
" │ └─ columns: [id dzlim f3yue]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select FGG57 from E2I7U where id = NEW.LUEVY\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" +
" │ ├─ keys: [new.LUEVY:2!null]\n" +
" │ ├─ colSet: (17-33)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\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: "Insert(id, GXLUB, CH3FR, D237E, JOGI6)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ ├─ alias-string: select bs.id from THNTS as bs join YK2GW as cla on cla.id = bs.IXUXU where cla.FTQLQ = ums.T4IBQ\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:12!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:15!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ bs.IXUXU:13\n" +
" │ │ │ └─ cla.id:14!null\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (14-17)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (18-47)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YK2GW\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ alias-string: select id from XOAOP where DZLIM = 'NER'\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:12!null]\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[NER, NER]}]\n" +
" │ │ ├─ colSet: (49-51)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.ner:2\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.ner:2\n" +
" │ │ └─ 0.5 (decimal(2,1))\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" +
" │ │ ├─ alias-string: select bs.id from THNTS as bs join YK2GW as cla on cla.id = bs.IXUXU where cla.FTQLQ = ums.T4IBQ\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:7!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:10!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ bs.IXUXU:8\n" +
" │ │ │ └─ cla.id:9!null\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (14-17)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (18-47)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YK2GW\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ alias-string: select id from XOAOP where DZLIM = 'NER'\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:7!null]\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[NER, NER]}]\n" +
" │ │ ├─ colSet: (49-51)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.ner:2\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.ner:2\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ TableAlias(ums)\n" +
" │ └─ IndexedTableAccess(FG26Y)\n" +
" │ ├─ index: [FG26Y.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ ├─ colSet: (6-12)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: FG26Y\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" +
" │ │ ├─ alias-string: select DZLIM from XOAOP where id = NEW.CH3FR\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" +
" │ │ ├─ keys: [new.CH3FR:2!null]\n" +
" │ │ ├─ colSet: (11-13)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\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: "Insert(id, GXLUB, CH3FR, D237E, JOGI6)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ ├─ alias-string: select bs.id from THNTS as bs join YK2GW as cla on cla.id = bs.IXUXU where cla.FTQLQ = ums.T4IBQ\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:12!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:15!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ bs.IXUXU:13\n" +
" │ │ │ └─ cla.id:14!null\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (14-17)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (18-47)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YK2GW\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ alias-string: select id from XOAOP where DZLIM = 'BER'\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:12!null]\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[BER, BER]}]\n" +
" │ │ ├─ colSet: (49-51)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.ber:3\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.ber:3\n" +
" │ │ └─ 0.5 (decimal(2,1))\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" +
" │ │ ├─ alias-string: select bs.id from THNTS as bs join YK2GW as cla on cla.id = bs.IXUXU where cla.FTQLQ = ums.T4IBQ\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:7!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:10!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ bs.IXUXU:8\n" +
" │ │ │ └─ cla.id:9!null\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (14-17)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (18-47)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YK2GW\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ alias-string: select id from XOAOP where DZLIM = 'BER'\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:7!null]\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[BER, BER]}]\n" +
" │ │ ├─ colSet: (49-51)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.ber:3\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.ber:3\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ TableAlias(ums)\n" +
" │ └─ IndexedTableAccess(FG26Y)\n" +
" │ ├─ index: [FG26Y.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ ├─ colSet: (6-12)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: FG26Y\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" +
" │ │ ├─ alias-string: select DZLIM from XOAOP where id = NEW.CH3FR\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" +
" │ │ ├─ keys: [new.CH3FR:2!null]\n" +
" │ │ ├─ colSet: (11-13)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\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: "Insert(id, GXLUB, CH3FR, D237E, JOGI6)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ ├─ alias-string: select bs.id from THNTS as bs join YK2GW as cla on cla.id = bs.IXUXU where cla.FTQLQ = ums.T4IBQ\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:12!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:15!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ bs.IXUXU:13\n" +
" │ │ │ └─ cla.id:14!null\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (14-17)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (18-47)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YK2GW\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ alias-string: select id from XOAOP where DZLIM = 'HR'\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:12!null]\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[HR, HR]}]\n" +
" │ │ ├─ colSet: (49-51)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.hr:4\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.hr:4\n" +
" │ │ └─ 0.5 (decimal(2,1))\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" +
" │ │ ├─ alias-string: select bs.id from THNTS as bs join YK2GW as cla on cla.id = bs.IXUXU where cla.FTQLQ = ums.T4IBQ\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:7!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:10!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ bs.IXUXU:8\n" +
" │ │ │ └─ cla.id:9!null\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (14-17)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (18-47)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YK2GW\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ alias-string: select id from XOAOP where DZLIM = 'HR'\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:7!null]\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[HR, HR]}]\n" +
" │ │ ├─ colSet: (49-51)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.hr:4\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.hr:4\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ TableAlias(ums)\n" +
" │ └─ IndexedTableAccess(FG26Y)\n" +
" │ ├─ index: [FG26Y.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ ├─ colSet: (6-12)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: FG26Y\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" +
" │ │ ├─ alias-string: select DZLIM from XOAOP where id = NEW.CH3FR\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" +
" │ │ ├─ keys: [new.CH3FR:2!null]\n" +
" │ │ ├─ colSet: (11-13)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\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: "Insert(id, GXLUB, CH3FR, D237E, JOGI6)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ ├─ alias-string: select bs.id from THNTS as bs join YK2GW as cla on cla.id = bs.IXUXU where cla.FTQLQ = ums.T4IBQ\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:12!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:15!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ bs.IXUXU:13\n" +
" │ │ │ └─ cla.id:14!null\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (14-17)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (18-47)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YK2GW\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ alias-string: select id from XOAOP where DZLIM = 'MMR'\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:12!null]\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[MMR, MMR]}]\n" +
" │ │ ├─ colSet: (49-51)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.mmr:5\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.mmr:5\n" +
" │ │ └─ 0.5 (decimal(2,1))\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" +
" │ │ ├─ alias-string: select bs.id from THNTS as bs join YK2GW as cla on cla.id = bs.IXUXU where cla.FTQLQ = ums.T4IBQ\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [bs.id:7!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ cla.FTQLQ:10!null\n" +
" │ │ │ └─ ums.T4IBQ:1\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ bs.IXUXU:8\n" +
" │ │ │ └─ cla.id:9!null\n" +
" │ │ ├─ TableAlias(bs)\n" +
" │ │ │ └─ IndexedTableAccess(THNTS)\n" +
" │ │ │ ├─ index: [THNTS.IXUXU]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (14-17)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: THNTS\n" +
" │ │ │ └─ columns: [id ixuxu]\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.id]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (18-47)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: YK2GW\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as GXLUB, Subquery\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ alias-string: select id from XOAOP where DZLIM = 'MMR'\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [xoaop.id:7!null]\n" +
" │ │ └─ IndexedTableAccess(XOAOP)\n" +
" │ │ ├─ index: [XOAOP.DZLIM]\n" +
" │ │ ├─ static: [{[MMR, MMR]}]\n" +
" │ │ ├─ colSet: (49-51)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\n" +
" │ │ └─ columns: [id dzlim]\n" +
" │ │ as CH3FR, CASE WHEN GreaterThan\n" +
" │ │ ├─ ums.mmr:5\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 1 (tinyint) WHEN LessThan\n" +
" │ │ ├─ ums.mmr:5\n" +
" │ │ └─ 0.5 (decimal(2,1))\n" +
" │ │ THEN 0 (tinyint) ELSE NULL (null) END as D237E, ums.id:0!null as JOGI6]\n" +
" │ └─ TableAlias(ums)\n" +
" │ └─ IndexedTableAccess(FG26Y)\n" +
" │ ├─ index: [FG26Y.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ ├─ colSet: (6-12)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: FG26Y\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" +
" │ │ ├─ alias-string: select DZLIM from XOAOP where id = NEW.CH3FR\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" +
" │ │ ├─ keys: [new.CH3FR:2!null]\n" +
" │ │ ├─ colSet: (11-13)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: XOAOP\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: "Insert(id, BTXC5, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (33)\n" +
" │ ├─ tableId: 4\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [umf.SYPKF:8 as BTXC5]\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ ├─ left: umf.SYPKF:8\n" +
" │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ ├─ alias-string: select BTXC5 from TPXBU where BTXC5 is not null\n" +
" │ │ │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ │ │ ├─ static: [{(NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (29-31)\n" +
" │ │ │ │ ├─ tableId: 3\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: TPXBU\n" +
" │ │ │ │ └─ columns: [btxc5]\n" +
" │ │ │ └─ NOT\n" +
" │ │ │ └─ umf.SYPKF:8 IS NULL\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ umf.SYPKF:8\n" +
" │ │ └─ N/A (longtext)\n" +
" │ └─ TableAlias(umf)\n" +
" │ └─ IndexedTableAccess(NZKPM)\n" +
" │ ├─ index: [NZKPM.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ ├─ colSet: (4-28)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: NZKPM\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" +
" ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" └─ Table\n" +
" ├─ name: TPXHZ\n" +
" ├─ columns: [svaz4]\n" +
" ├─ colSet: (7,8)\n" +
" └─ tableId: 3\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: "Insert(id, GXLUB, LUEVY, M22QN, TJPT7, ARN5P, XOSD4, IDE43, HMW4H, ZBT6R, FSDY2, LT7K6, SPPYD, QCGTS, TEUJA, QQV4M, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ ├─ alias-string: select nd_for_id_overridden.id from E2I7U as nd_for_id_overridden where nd_for_id_overridden.TW55N = TJ5D2.H4DMT\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" +
" │ │ ├─ keys: [tj5d2.H4DMT:29!null]\n" +
" │ │ ├─ colSet: (159-175)\n" +
" │ │ ├─ tableId: 9\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ │ ELSE Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select nd_for_id.id from E2I7U as nd_for_id where nd_for_id.FGG57 is not null and nd_for_id.FGG57 = umf.FGG57\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nd_for_id.id:84!null]\n" +
" │ │ └─ Filter\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" +
" │ │ ├─ colSet: (176-192)\n" +
" │ │ ├─ tableId: 10\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\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" +
" │ │ ├─ alias-string: select id from TPXBU where BTXC5 is null\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tpxbu.id:84!null]\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ ├─ static: [{[NULL, NULL]}]\n" +
" │ │ ├─ colSet: (194-196)\n" +
" │ │ ├─ tableId: 11\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ ELSE Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select aac.id from TPXBU as aac where aac.BTXC5 = umf.SYPKF\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" +
" │ │ ├─ keys: [umf.SYPKF:8]\n" +
" │ │ ├─ colSet: (197-199)\n" +
" │ │ ├─ tableId: 12\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\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: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, tj5d2.id:25!null, tj5d2.T4IBQ:26!null, tj5d2.V7UFH:27!null, tj5d2.SYPKF:28!null, tj5d2.H4DMT:29!null, tj5d2.SWCQV:30!null, tj5d2.YKSSU:31, tj5d2.FHCYT:32, 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, 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" +
" │ │ ├─ alias-string: select nd_for_id_overridden.id from E2I7U as nd_for_id_overridden where nd_for_id_overridden.TW55N = TJ5D2.H4DMT\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:29!null\n" +
" │ │ └─ TableAlias(nd_for_id_overridden)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ ├─ keys: [tj5d2.H4DMT:29!null]\n" +
" │ │ ├─ colSet: (159-175)\n" +
" │ │ ├─ tableId: 9\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ │ ELSE Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select nd_for_id.id from E2I7U as nd_for_id where nd_for_id.FGG57 is not null and nd_for_id.FGG57 = umf.FGG57\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [nd_for_id.id:67!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ nd_for_id.FGG57:68\n" +
" │ │ │ └─ umf.FGG57:2\n" +
" │ │ └─ TableAlias(nd_for_id)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.FGG57]\n" +
" │ │ ├─ static: [{(NULL, ∞)}]\n" +
" │ │ ├─ colSet: (176-192)\n" +
" │ │ ├─ tableId: 10\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\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" +
" │ │ ├─ alias-string: select id from TPXBU where BTXC5 is null\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [tpxbu.id:67!null]\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ ├─ static: [{[NULL, NULL]}]\n" +
" │ │ ├─ colSet: (194-196)\n" +
" │ │ ├─ tableId: 11\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ ELSE Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select aac.id from TPXBU as aac where aac.BTXC5 = umf.SYPKF\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [aac.id:67!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ aac.BTXC5:68\n" +
" │ │ │ └─ umf.SYPKF:8\n" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.BTXC5]\n" +
" │ │ ├─ keys: [umf.SYPKF:8]\n" +
" │ │ ├─ colSet: (197-199)\n" +
" │ │ ├─ tableId: 12\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\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" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LeftOuterJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ tj5d2.SWCQV:30!null\n" +
" │ │ │ │ │ │ │ └─ 0 (int)\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ tj5d2.T4IBQ:26!null\n" +
" │ │ │ │ │ │ └─ umf.T4IBQ:1\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ tj5d2.V7UFH:27!null\n" +
" │ │ │ │ │ └─ umf.FGG57:2\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ tj5d2.SYPKF:28!null\n" +
" │ │ │ │ └─ umf.SYPKF:8\n" +
" │ │ │ ├─ SubqueryAlias\n" +
" │ │ │ │ ├─ name: umf\n" +
" │ │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ │ ├─ isLateral: false\n" +
" │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ ├─ colSet: (90-114)\n" +
" │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ InSubquery\n" +
" │ │ │ │ │ │ │ ├─ left: nzkpm.T4IBQ:1\n" +
" │ │ │ │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ │ │ ├─ alias-string: select FTQLQ from YK2GW\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: YK2GW\n" +
" │ │ │ │ │ │ │ ├─ columns: [ftqlq]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (43-72)\n" +
" │ │ │ │ │ │ │ └─ tableId: 3\n" +
" │ │ │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ │ │ ├─ left: nzkpm.FGG57:2\n" +
" │ │ │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ │ │ ├─ cacheable: true\n" +
" │ │ │ │ │ │ ├─ alias-string: select FGG57 from E2I7U where FGG57 is not null\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ │ │ ├─ index: [E2I7U.FGG57]\n" +
" │ │ │ │ │ │ ├─ static: [{(NULL, ∞)}]\n" +
" │ │ │ │ │ │ ├─ colSet: (73-89)\n" +
" │ │ │ │ │ │ ├─ tableId: 4\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ │ └─ columns: [fgg57]\n" +
" │ │ │ │ │ └─ NOT\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ nzkpm.ARN5P:7\n" +
" │ │ │ │ │ └─ N/A (longtext)\n" +
" │ │ │ │ └─ IndexedTableAccess(NZKPM)\n" +
" │ │ │ │ ├─ index: [NZKPM.id]\n" +
" │ │ │ │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ │ │ │ ├─ colSet: (18-42)\n" +
" │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: NZKPM\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(tj5d2)\n" +
" │ │ │ └─ ProcessTable\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SZW6V\n" +
" │ │ │ └─ columns: [id t4ibq v7ufh sypkf h4dmt swcqv ykssu fhcyt]\n" +
" │ │ └─ TableAlias(cla)\n" +
" │ │ └─ IndexedTableAccess(YK2GW)\n" +
" │ │ ├─ index: [YK2GW.FTQLQ]\n" +
" │ │ ├─ keys: [umf.T4IBQ:1]\n" +
" │ │ ├─ colSet: (123-152)\n" +
" │ │ ├─ tableId: 7\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" +
" │ └─ TableAlias(bs)\n" +
" │ └─ IndexedTableAccess(THNTS)\n" +
" │ ├─ index: [THNTS.IXUXU]\n" +
" │ ├─ keys: [cla.id:33!null]\n" +
" │ ├─ colSet: (153-156)\n" +
" │ ├─ tableId: 8\n" +
" │ └─ Table\n" +
" │ ├─ name: THNTS\n" +
" │ └─ columns: [id nfryn ixuxu 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" +
" │ │ │ │ │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: TPXHZ\n" +
" │ │ │ │ │ ├─ columns: [svaz4]\n" +
" │ │ │ │ │ ├─ colSet: (35,36)\n" +
" │ │ │ │ │ └─ tableId: 3\n" +
" │ │ │ │ └─ InSubquery\n" +
" │ │ │ │ ├─ left: new.ARN5P:5!null\n" +
" │ │ │ │ └─ right: Subquery\n" +
" │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: TPXHZ\n" +
" │ │ │ │ ├─ columns: [svaz4]\n" +
" │ │ │ │ ├─ colSet: (37,38)\n" +
" │ │ │ │ └─ tableId: 4\n" +
" │ │ │ └─ InSubquery\n" +
" │ │ │ ├─ left: new.XOSD4:6!null\n" +
" │ │ │ └─ right: Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: TPXHZ\n" +
" │ │ │ ├─ columns: [svaz4]\n" +
" │ │ │ ├─ colSet: (39,40)\n" +
" │ │ │ └─ tableId: 5\n" +
" │ │ └─ InSubquery\n" +
" │ │ ├─ left: new.IDE43:7\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXHZ\n" +
" │ │ ├─ columns: [svaz4]\n" +
" │ │ ├─ colSet: (41,42)\n" +
" │ │ └─ tableId: 6\n" +
" │ └─ InSubquery\n" +
" │ ├─ left: new.HMW4H:8\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ ├─ columns: [svaz4]\n" +
" │ ├─ colSet: (43,44)\n" +
" │ └─ tableId: 7\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.5 (decimal(2,1))\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: "Insert(id, Z7CP5, YH4XB)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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:2!null as Z7CP5, vc.id:0!null as YH4XB]\n" +
" └─ InnerJoin\n" +
" ├─ c6pud.AZ6SP LIKE concat(concat('%',vc.TWMSR),'%')\n" +
" ├─ TableAlias(vc)\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: D34QP\n" +
" │ └─ columns: [id twmsr]\n" +
" └─ SubqueryAlias\n" +
" ├─ name: c6pud\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (48,49)\n" +
" ├─ tableId: 4\n" +
" └─ Project\n" +
" ├─ columns: [mf.id:2!null as id, umf.AZ6SP:1 as AZ6SP]\n" +
" └─ InnerJoin\n" +
" ├─ Eq\n" +
" │ ├─ umf.id:0!null\n" +
" │ └─ mf.TEUJA:3\n" +
" ├─ TableAlias(umf)\n" +
" │ └─ IndexedTableAccess(NZKPM)\n" +
" │ ├─ index: [NZKPM.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ ├─ colSet: (21-45)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Table\n" +
" │ ├─ name: NZKPM\n" +
" │ └─ columns: [id az6sp]\n" +
" └─ TableAlias(mf)\n" +
" └─ Table\n" +
" ├─ name: HGMQ6\n" +
" ├─ columns: [id teuja]\n" +
" ├─ colSet: (4-20)\n" +
" └─ tableId: 2\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: "Insert(id, FV24E, UJ6XY, M22QN, NZ4MQ, ETPQV, PRUV2, YKSSU, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (99-105)\n" +
" │ ├─ tableId: 9\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" +
" │ │ ├─ alias-string: select G3YXS.id from YYBCX as G3YXS where CONCAT(G3YXS.ESFVY, '(MI:', G3YXS.SL76B, ')') = TIZHK.IDUT2\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" +
" │ │ ├─ colSet: (88-95)\n" +
" │ │ └─ tableId: 8\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: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:57!null, rhuzn.DKCAJ:58!null, rhuzn.KNG7T:59, rhuzn.TW55N:60!null, rhuzn.QRQXW:61!null, rhuzn.ECXAJ:62!null, rhuzn.FGG57:63, rhuzn.ZH72S:64, rhuzn.FSK67:65!null, rhuzn.XQDYT:66!null, rhuzn.TCE7A:67, rhuzn.IWV2H:68, rhuzn.HPCMS:69!null, rhuzn.N5CC2:70, rhuzn.FHCYT:71, rhuzn.ETAQ7:72, rhuzn.A75X7:73, mf.id:37!null, mf.GXLUB:38!null, mf.LUEVY:39!null, mf.M22QN:40!null, mf.TJPT7:41!null, mf.ARN5P:42!null, mf.XOSD4:43!null, mf.IDE43:44, mf.HMW4H:45, mf.ZBT6R:46, mf.FSDY2:47!null, mf.LT7K6:48, mf.SPPYD:49, mf.QCGTS:50, mf.TEUJA:51, mf.QQV4M:52, mf.FHCYT:53, aac.id:54!null, aac.BTXC5:55, aac.FHCYT:56, tizhk.id:0!null as MU3KG, j4jyp.id:20!null as FV24E, rhuzn.id:57!null as UJ6XY, aac.id:54!null as M22QN, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select G3YXS.id from YYBCX as G3YXS where CONCAT(G3YXS.ESFVY, '(MI:', G3YXS.SL76B, ')') = TIZHK.IDUT2\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" +
" │ │ ├─ colSet: (88-95)\n" +
" │ │ └─ tableId: 8\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" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ LeftOuterJoin\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ nhmxw.SWCQV:17!null\n" +
" │ │ │ │ │ │ │ │ │ │ └─ 0 (int)\n" +
" │ │ │ │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ │ │ │ ├─ nhmxw.NOHHR:11!null\n" +
" │ │ │ │ │ │ │ │ │ └─ tizhk.TVNW2:1\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" +
" │ │ │ │ │ ├─ TableAlias(tizhk)\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ │ │ │ ├─ index: [WRZVO.id]\n" +
" │ │ │ │ │ │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ │ │ │ │ │ ├─ colSet: (10-19)\n" +
" │ │ │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: WRZVO\n" +
" │ │ │ │ │ │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" │ │ │ │ │ └─ TableAlias(nhmxw)\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: WGSDC\n" +
" │ │ │ │ │ ├─ columns: [id nohhr avpyf sypkf idut2 fzxv5 dqygv swcqv ykssu fhcyt]\n" +
" │ │ │ │ │ ├─ colSet: (20-29)\n" +
" │ │ │ │ │ └─ tableId: 3\n" +
" │ │ │ │ └─ TableAlias(j4jyp)\n" +
" │ │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ │ │ ├─ keys: [tizhk.TVNW2:1]\n" +
" │ │ │ │ ├─ colSet: (30-46)\n" +
" │ │ │ │ ├─ tableId: 4\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(mf)\n" +
" │ │ │ └─ IndexedTableAccess(HGMQ6)\n" +
" │ │ │ ├─ index: [HGMQ6.LUEVY]\n" +
" │ │ │ ├─ keys: [j4jyp.id:20!null]\n" +
" │ │ │ ├─ colSet: (64-80)\n" +
" │ │ │ ├─ tableId: 6\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" +
" │ │ └─ TableAlias(aac)\n" +
" │ │ └─ IndexedTableAccess(TPXBU)\n" +
" │ │ ├─ index: [TPXBU.id]\n" +
" │ │ ├─ keys: [mf.M22QN:40!null]\n" +
" │ │ ├─ colSet: (81-83)\n" +
" │ │ ├─ tableId: 7\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5 fhcyt]\n" +
" │ └─ TableAlias(rhuzn)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ ├─ keys: [tizhk.ZHITY:2]\n" +
" │ ├─ colSet: (47-63)\n" +
" │ ├─ tableId: 5\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" +
" └─ 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" +
" │ ├─ alias-string: select aac.id from TPXBU as aac where aac.BTXC5 = BPNW2.SYPKF\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" +
" │ ├─ keys: [bpnw2.SYPKF:3]\n" +
" │ ├─ colSet: (230-232)\n" +
" │ ├─ tableId: 18\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXBU\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" +
" │ ├─ alias-string: select aac.id from TPXBU as aac where aac.BTXC5 = BPNW2.SYPKF\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" +
" │ ├─ keys: [bpnw2.SYPKF:3]\n" +
" │ ├─ colSet: (230-232)\n" +
" │ ├─ tableId: 18\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXBU\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" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (219-226)\n" +
" ├─ tableId: 17\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" +
" │ ├─ alias-string: select overridden_nd_mutant.id from E2I7U as overridden_nd_mutant where overridden_nd_mutant.TW55N = NHMXW.FZXV5\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" +
" │ ├─ keys: [nhmxw.FZXV5:15]\n" +
" │ ├─ colSet: (170-186)\n" +
" │ ├─ tableId: 14\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\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" +
" │ ├─ alias-string: select overridden_QI2IEner.id from E2I7U as overridden_QI2IEner where overridden_QI2IEner.TW55N = NHMXW.DQYGV\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" +
" │ ├─ keys: [nhmxw.DQYGV:16]\n" +
" │ ├─ colSet: (188-204)\n" +
" │ ├─ tableId: 15\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id tw55n]\n" +
" │ ELSE rhuzn.id:37!null END as UJ6XY, tizhk.SYPKF:3 as SYPKF, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select G3YXS.id from YYBCX as G3YXS where CONCAT(G3YXS.ESFVY, '(MI:', G3YXS.SL76B, ')') = TIZHK.IDUT2\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" +
" │ ├─ colSet: (207-214)\n" +
" │ └─ tableId: 16\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" +
" │ ├─ alias-string: select overridden_nd_mutant.id from E2I7U as overridden_nd_mutant where overridden_nd_mutant.TW55N = NHMXW.FZXV5\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" +
" │ ├─ keys: [nhmxw.FZXV5:15]\n" +
" │ ├─ colSet: (170-186)\n" +
" │ ├─ tableId: 14\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\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" +
" │ ├─ alias-string: select overridden_QI2IEner.id from E2I7U as overridden_QI2IEner where overridden_QI2IEner.TW55N = NHMXW.DQYGV\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" +
" │ ├─ keys: [nhmxw.DQYGV:16]\n" +
" │ ├─ colSet: (188-204)\n" +
" │ ├─ tableId: 15\n" +
" │ └─ Table\n" +
" │ ├─ name: E2I7U\n" +
" │ └─ columns: [id tw55n]\n" +
" │ ELSE rhuzn.id:37!null END as UJ6XY, tizhk.SYPKF:3 as SYPKF, Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select G3YXS.id from YYBCX as G3YXS where CONCAT(G3YXS.ESFVY, '(MI:', G3YXS.SL76B, ')') = TIZHK.IDUT2\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" +
" │ ├─ colSet: (207-214)\n" +
" │ └─ tableId: 16\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" +
" └─ LeftOuterLookupJoin\n" +
" ├─ LeftOuterLookupJoin\n" +
" │ ├─ LeftOuterJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ nhmxw.SWCQV:17!null\n" +
" │ │ │ │ │ │ │ └─ 0 (int)\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ nhmxw.NOHHR:11!null\n" +
" │ │ │ │ │ │ └─ tizhk.TVNW2:1\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" +
" │ │ ├─ TableAlias(tizhk)\n" +
" │ │ │ └─ IndexedTableAccess(WRZVO)\n" +
" │ │ │ ├─ index: [WRZVO.id]\n" +
" │ │ │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ │ │ ├─ colSet: (115-124)\n" +
" │ │ │ ├─ tableId: 10\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: WRZVO\n" +
" │ │ │ └─ columns: [id tvnw2 zhity sypkf idut2 o6qj3 no2ja ykssu fhcyt qz6vt]\n" +
" │ │ └─ TableAlias(nhmxw)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: WGSDC\n" +
" │ │ ├─ columns: [id nohhr avpyf sypkf idut2 fzxv5 dqygv swcqv ykssu fhcyt]\n" +
" │ │ ├─ colSet: (125-134)\n" +
" │ │ └─ tableId: 11\n" +
" │ └─ TableAlias(j4jyp)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.ZH72S]\n" +
" │ ├─ keys: [tizhk.TVNW2:1]\n" +
" │ ├─ colSet: (135-151)\n" +
" │ ├─ tableId: 12\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(rhuzn)\n" +
" └─ IndexedTableAccess(E2I7U)\n" +
" ├─ index: [E2I7U.ZH72S]\n" +
" ├─ keys: [tizhk.ZHITY:2]\n" +
" ├─ colSet: (152-168)\n" +
" ├─ tableId: 13\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: "Insert(id, NO52D, VYO5E, DKCAJ, ADURZ, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ │ ├─ alias-string: select distinct NO52D, VYO5E, DKCAJ from SFEGG where VYO5E is not null\n" +
" │ │ │ └─ Distinct\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ sfegg.VYO5E:5 IS NULL\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SFEGG\n" +
" │ │ │ ├─ columns: [no52d vyo5e dkcaj]\n" +
" │ │ │ ├─ colSet: (60-65)\n" +
" │ │ │ └─ tableId: 8\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" +
" │ │ ├─ alias-string: select distinct NO52D, DKCAJ from SFEGG where VYO5E is null\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sfegg.NO52D:4!null, sfegg.DKCAJ:6!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ sfegg.VYO5E:5 IS NULL\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ ├─ columns: [no52d vyo5e dkcaj]\n" +
" │ │ ├─ colSet: (66-71)\n" +
" │ │ └─ tableId: 9\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: rs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (56-59)\n" +
" │ ├─ tableId: 7\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:7!null as DKCAJ, nt.DZLIM:8!null as F35MI]\n" +
" │ └─ HashJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ nt.id:7!null\n" +
" │ │ └─ nd.DKCAJ:4!null\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ Or\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ nk7fp.FVUCX:3!null IS NULL\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ nd.ZH72S:6\n" +
" │ │ │ │ └─ nk7fp.ZH72S:2\n" +
" │ │ │ └─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ nk7fp.FVUCX:3!null IS NULL\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ nd.TW55N:5!null\n" +
" │ │ │ └─ nk7fp.FVUCX:3!null\n" +
" │ │ ├─ SubqueryAlias\n" +
" │ │ │ ├─ name: nk7fp\n" +
" │ │ │ ├─ outerVisibility: false\n" +
" │ │ │ ├─ isLateral: false\n" +
" │ │ │ ├─ cacheable: true\n" +
" │ │ │ ├─ colSet: (28-31)\n" +
" │ │ │ ├─ tableId: 4\n" +
" │ │ │ └─ Distinct\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [uct.NO52D:4, uct.VYO5E:5, uct.ZH72S:2, i7hcr.FVUCX:9!null]\n" +
" │ │ │ └─ LeftOuterJoin\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ i7hcr.SWCQV:10!null\n" +
" │ │ │ │ │ │ │ └─ 0 (int)\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ i7hcr.TOFPN:6!null\n" +
" │ │ │ │ │ │ └─ uct.FTQLQ:1\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ i7hcr.SJYN2:7!null\n" +
" │ │ │ │ │ └─ uct.ZH72S:2\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ i7hcr.BTXC5:8!null\n" +
" │ │ │ │ └─ uct.LJLUM:3\n" +
" │ │ │ ├─ TableAlias(uct)\n" +
" │ │ │ │ └─ IndexedTableAccess(OUBDL)\n" +
" │ │ │ │ ├─ index: [OUBDL.id]\n" +
" │ │ │ │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ │ │ │ ├─ colSet: (7-19)\n" +
" │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: OUBDL\n" +
" │ │ │ │ └─ columns: [id ftqlq zh72s ljlum no52d vyo5e]\n" +
" │ │ │ └─ TableAlias(i7hcr)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: EPZU6\n" +
" │ │ │ ├─ columns: [tofpn sjyn2 btxc5 fvucx swcqv]\n" +
" │ │ │ ├─ colSet: (20-27)\n" +
" │ │ │ └─ tableId: 3\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ Concat\n" +
" │ │ ├─ TableAlias(nd)\n" +
" │ │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ │ ├─ keys: [nk7fp.FVUCX:3!null]\n" +
" │ │ │ ├─ colSet: (32-48)\n" +
" │ │ │ ├─ tableId: 5\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [dkcaj tw55n zh72s]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ ├─ keys: [nk7fp.ZH72S:2]\n" +
" │ │ ├─ colSet: (32-48)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [dkcaj tw55n zh72s]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(nd.DKCAJ:4!null)\n" +
" │ ├─ right-key: TUPLE(nt.id:0!null)\n" +
" │ └─ TableAlias(nt)\n" +
" │ └─ Table\n" +
" │ ├─ name: F35MI\n" +
" │ ├─ columns: [id dzlim]\n" +
" │ ├─ colSet: (49-51)\n" +
" │ └─ tableId: 6\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(Or\n" +
" │ ├─ InSubquery\n" +
" │ │ ├─ left: new.NO52D:1!null\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXHZ\n" +
" │ │ ├─ columns: [svaz4]\n" +
" │ │ ├─ colSet: (13,14)\n" +
" │ │ └─ tableId: 3\n" +
" │ └─ InSubquery\n" +
" │ ├─ left: new.VYO5E:2\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ ├─ columns: [svaz4]\n" +
" │ ├─ colSet: (15,16)\n" +
" │ └─ tableId: 4\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 (int)\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: "Insert(id, FZ2R5, LUEVY, M22QN, OVE3E, NRURT, OCA7E, XMM6Q, V5DPX, S3Q3Y, ZRV3B, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ ├─ alias-string: select aac.id from TPXBU as aac where aac.BTXC5 = PQSXB.BTXC5\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" +
" │ │ ├─ keys: [pqsxb.BTXC5:10]\n" +
" │ │ ├─ colSet: (123-125)\n" +
" │ │ ├─ tableId: 10\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\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" +
" │ │ ├─ alias-string: select aac.id from TPXBU as aac where aac.BTXC5 = PQSXB.BTXC5\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" +
" │ │ ├─ keys: [pqsxb.BTXC5:10]\n" +
" │ │ ├─ colSet: (123-125)\n" +
" │ │ ├─ tableId: 10\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\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" +
" │ └─ Filter\n" +
" │ ├─ NOT\n" +
" │ │ └─ pqsxb.OVE3E:1 IS NULL\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" +
" │ │ ├─ isLateral: false\n" +
" │ │ ├─ cacheable: true\n" +
" │ │ ├─ colSet: (91-102)\n" +
" │ │ ├─ tableId: 8\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select id from JDLNA where JDLNA.FTQLQ = uct.FTQLQ\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" +
" │ │ │ ├─ keys: [uct.FTQLQ:1]\n" +
" │ │ │ ├─ colSet: (34-38)\n" +
" │ │ │ ├─ tableId: 4\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: JDLNA\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ as FZ2R5, Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: 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 as nd where nd.ZH72S = uct.ZH72S limit 1) else (select nd.DKCAJ from E2I7U as nd where nd.TW55N = I7HCR.FVUCX) end)\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" +
" │ │ │ │ ├─ alias-string: select case when I7HCR.FVUCX is null then (select nd.DKCAJ from E2I7U as nd where nd.ZH72S = uct.ZH72S limit 1) else (select nd.DKCAJ from E2I7U as nd where nd.TW55N = I7HCR.FVUCX) end\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [CASE WHEN i7hcr.FVUCX:17!null IS NULL THEN Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ ├─ alias-string: select nd.DKCAJ from E2I7U as nd where nd.ZH72S = uct.ZH72S limit 1\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" +
" │ │ │ │ │ ├─ keys: [uct.ZH72S:2]\n" +
" │ │ │ │ │ ├─ colSet: (46-62)\n" +
" │ │ │ │ │ ├─ tableId: 6\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ └─ columns: [dkcaj zh72s]\n" +
" │ │ │ │ │ ELSE Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ ├─ alias-string: select nd.DKCAJ from E2I7U as nd where nd.TW55N = I7HCR.FVUCX\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" +
" │ │ │ │ │ ├─ keys: [i7hcr.FVUCX:17!null]\n" +
" │ │ │ │ │ ├─ colSet: (63-79)\n" +
" │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ └─ columns: [dkcaj tw55n]\n" +
" │ │ │ │ │ END as CASE\n" +
" │ │ │ │ │ WHEN I7HCR.FVUCX IS NULL\n" +
" │ │ │ │ │ THEN (SELECT nd.DKCAJ FROM E2I7U nd WHERE nd.ZH72S = uct.ZH72S LIMIT 1)\n" +
" │ │ │ │ │ ELSE\n" +
" │ │ │ │ │ (SELECT nd.DKCAJ FROM E2I7U nd WHERE nd.TW55N = I7HCR.FVUCX)\n" +
" │ │ │ │ │ END]\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [dual.:39!null]\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: \n" +
" │ │ │ │ ├─ columns: []\n" +
" │ │ │ │ ├─ colSet: ()\n" +
" │ │ │ │ └─ tableId: 0\n" +
" │ │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ │ ├─ index: [SFEGG.NO52D,SFEGG.VYO5E,SFEGG.DKCAJ]\n" +
" │ │ │ ├─ keys: [uct.NO52D:7]\n" +
" │ │ │ ├─ colSet: (40-45)\n" +
" │ │ │ ├─ tableId: 5\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SFEGG\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" +
" │ │ │ ├─ alias-string: select id from JDLNA where JDLNA.FTQLQ = uct.FTQLQ\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" +
" │ │ │ ├─ keys: [uct.FTQLQ:1]\n" +
" │ │ │ ├─ colSet: (34-38)\n" +
" │ │ │ ├─ tableId: 4\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: JDLNA\n" +
" │ │ │ └─ columns: [id ftqlq]\n" +
" │ │ │ as FZ2R5, Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: 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 as nd where nd.ZH72S = uct.ZH72S limit 1) else (select nd.DKCAJ from E2I7U as nd where nd.TW55N = I7HCR.FVUCX) end)\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" +
" │ │ │ │ ├─ alias-string: select case when I7HCR.FVUCX is null then (select nd.DKCAJ from E2I7U as nd where nd.ZH72S = uct.ZH72S limit 1) else (select nd.DKCAJ from E2I7U as nd where nd.TW55N = I7HCR.FVUCX) end\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [CASE WHEN i7hcr.FVUCX:17!null IS NULL THEN Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ ├─ alias-string: select nd.DKCAJ from E2I7U as nd where nd.ZH72S = uct.ZH72S limit 1\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" +
" │ │ │ │ │ ├─ keys: [uct.ZH72S:2]\n" +
" │ │ │ │ │ ├─ colSet: (46-62)\n" +
" │ │ │ │ │ ├─ tableId: 6\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ └─ columns: [dkcaj zh72s]\n" +
" │ │ │ │ │ ELSE Subquery\n" +
" │ │ │ │ │ ├─ cacheable: false\n" +
" │ │ │ │ │ ├─ alias-string: select nd.DKCAJ from E2I7U as nd where nd.TW55N = I7HCR.FVUCX\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" +
" │ │ │ │ │ ├─ keys: [i7hcr.FVUCX:17!null]\n" +
" │ │ │ │ │ ├─ colSet: (63-79)\n" +
" │ │ │ │ │ ├─ tableId: 7\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: E2I7U\n" +
" │ │ │ │ │ └─ columns: [dkcaj tw55n]\n" +
" │ │ │ │ │ END as CASE\n" +
" │ │ │ │ │ WHEN I7HCR.FVUCX IS NULL\n" +
" │ │ │ │ │ THEN (SELECT nd.DKCAJ FROM E2I7U nd WHERE nd.ZH72S = uct.ZH72S LIMIT 1)\n" +
" │ │ │ │ │ ELSE\n" +
" │ │ │ │ │ (SELECT nd.DKCAJ FROM E2I7U nd WHERE nd.TW55N = I7HCR.FVUCX)\n" +
" │ │ │ │ │ END]\n" +
" │ │ │ │ └─ Project\n" +
" │ │ │ │ ├─ columns: [dual.:27!null]\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: \n" +
" │ │ │ │ ├─ columns: []\n" +
" │ │ │ │ ├─ colSet: ()\n" +
" │ │ │ │ └─ tableId: 0\n" +
" │ │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ │ ├─ index: [SFEGG.NO52D,SFEGG.VYO5E,SFEGG.DKCAJ]\n" +
" │ │ │ ├─ keys: [uct.NO52D:7]\n" +
" │ │ │ ├─ colSet: (40-45)\n" +
" │ │ │ ├─ tableId: 5\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SFEGG\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" +
" │ │ └─ LeftOuterJoin\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ i7hcr.SWCQV:18!null\n" +
" │ │ │ │ │ │ └─ 0 (int)\n" +
" │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ ├─ i7hcr.TOFPN:14!null\n" +
" │ │ │ │ │ └─ uct.FTQLQ:1\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ i7hcr.SJYN2:15!null\n" +
" │ │ │ │ └─ uct.ZH72S:2\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ i7hcr.BTXC5:16!null\n" +
" │ │ │ └─ uct.LJLUM:5\n" +
" │ │ ├─ TableAlias(uct)\n" +
" │ │ │ └─ IndexedTableAccess(OUBDL)\n" +
" │ │ │ ├─ index: [OUBDL.id]\n" +
" │ │ │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ │ │ ├─ colSet: (13-25)\n" +
" │ │ │ ├─ tableId: 2\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: OUBDL\n" +
" │ │ │ └─ columns: [id ftqlq zh72s sfj6l v5dpx ljlum idpk7 no52d zrv3b vyo5e ykssu fhcyt qz6vt]\n" +
" │ │ └─ TableAlias(i7hcr)\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: EPZU6\n" +
" │ │ ├─ columns: [id tofpn sjyn2 btxc5 fvucx swcqv ykssu fhcyt]\n" +
" │ │ ├─ colSet: (26-33)\n" +
" │ │ └─ tableId: 3\n" +
" │ └─ TableAlias(nd)\n" +
" │ └─ Concat\n" +
" │ ├─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.ZH72S]\n" +
" │ │ ├─ keys: [pqsxb.K3B6V:9]\n" +
" │ │ ├─ colSet: (103-119)\n" +
" │ │ ├─ tableId: 9\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(nd)\n" +
" │ └─ IndexedTableAccess(E2I7U)\n" +
" │ ├─ index: [E2I7U.TW55N]\n" +
" │ ├─ keys: [pqsxb.H4DMT:11!null]\n" +
" │ ├─ colSet: (103-119)\n" +
" │ ├─ tableId: 9\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" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(InSubquery\n" +
" │ ├─ left: new.V5DPX:8!null\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ ├─ columns: [svaz4]\n" +
" │ ├─ colSet: (25,26)\n" +
" │ └─ tableId: 3\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: "Insert(id, NO52D, VYO5E, DKCAJ, ADURZ, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ │ ├─ alias-string: select distinct NO52D, VYO5E, DKCAJ from SFEGG where VYO5E is not null\n" +
" │ │ │ └─ Distinct\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ sfegg.VYO5E:5 IS NULL\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: SFEGG\n" +
" │ │ │ ├─ columns: [no52d vyo5e dkcaj]\n" +
" │ │ │ ├─ colSet: (48-53)\n" +
" │ │ │ └─ tableId: 6\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" +
" │ │ ├─ alias-string: select distinct NO52D, DKCAJ from SFEGG where VYO5E is null\n" +
" │ │ └─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [sfegg.NO52D:4!null, sfegg.DKCAJ:6!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ sfegg.VYO5E:5 IS NULL\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\n" +
" │ │ ├─ columns: [no52d vyo5e dkcaj]\n" +
" │ │ ├─ colSet: (54-59)\n" +
" │ │ └─ tableId: 7\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: rs\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (44-47)\n" +
" │ ├─ tableId: 5\n" +
" │ └─ Distinct\n" +
" │ └─ Project\n" +
" │ ├─ columns: [tvtjs.NO52D:2!null as NO52D, tvtjs.VYO5E:3 as VYO5E, nt.id:6!null as DKCAJ, nt.DZLIM:7!null as F35MI]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ TableAlias(tvtjs)\n" +
" │ │ │ └─ IndexedTableAccess(HU5A5)\n" +
" │ │ │ ├─ index: [HU5A5.id]\n" +
" │ │ │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ │ │ ├─ colSet: (7-19)\n" +
" │ │ │ ├─ tableId: 2\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: HU5A5\n" +
" │ │ │ └─ columns: [id i3vta no52d vyo5e]\n" +
" │ │ └─ TableAlias(nd)\n" +
" │ │ └─ IndexedTableAccess(E2I7U)\n" +
" │ │ ├─ index: [E2I7U.TW55N]\n" +
" │ │ ├─ keys: [tvtjs.I3VTA:1!null]\n" +
" │ │ ├─ colSet: (20-36)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [dkcaj tw55n]\n" +
" │ └─ TableAlias(nt)\n" +
" │ └─ IndexedTableAccess(F35MI)\n" +
" │ ├─ index: [F35MI.id]\n" +
" │ ├─ keys: [nd.DKCAJ:4!null]\n" +
" │ ├─ colSet: (37-39)\n" +
" │ ├─ tableId: 4\n" +
" │ └─ Table\n" +
" │ ├─ name: F35MI\n" +
" │ └─ columns: [id dzlim]\n" +
" └─ BEGIN .. END\n" +
" ├─ IF BLOCK\n" +
" │ └─ IF(Or\n" +
" │ ├─ InSubquery\n" +
" │ │ ├─ left: new.NO52D:1!null\n" +
" │ │ └─ right: Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXHZ\n" +
" │ │ ├─ columns: [svaz4]\n" +
" │ │ ├─ colSet: (13,14)\n" +
" │ │ └─ tableId: 3\n" +
" │ └─ InSubquery\n" +
" │ ├─ left: new.VYO5E:2\n" +
" │ └─ right: Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ ├─ columns: [svaz4]\n" +
" │ ├─ colSet: (15,16)\n" +
" │ └─ tableId: 4\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 (int)\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: "Insert(id, FZ2R5, LUEVY, M22QN, OVE3E, NRURT, OCA7E, XMM6Q, V5DPX, S3Q3Y, ZRV3B, FHCYT)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\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" +
" │ │ ├─ alias-string: select id from JDLNA where JDLNA.FTQLQ = TVTJS.TOFPN\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" +
" │ │ ├─ keys: [tvtjs.TOFPN:1!null]\n" +
" │ │ ├─ colSet: (27-31)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: JDLNA\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as FZ2R5, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select id from E2I7U where TW55N = TVTJS.I3VTA\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" +
" │ │ ├─ keys: [tvtjs.I3VTA:2!null]\n" +
" │ │ ├─ colSet: (33-49)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ │ as LUEVY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select id from TPXBU where BTXC5 = TVTJS.LJLUM\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" +
" │ │ ├─ keys: [tvtjs.LJLUM:5!null]\n" +
" │ │ ├─ colSet: (51-53)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as M22QN, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: 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 as nd where nd.TW55N = TVTJS.I3VTA)\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" +
" │ │ │ ├─ alias-string: select nd.DKCAJ from E2I7U as nd where nd.TW55N = TVTJS.I3VTA\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" +
" │ │ │ ├─ keys: [tvtjs.I3VTA:2!null]\n" +
" │ │ │ ├─ colSet: (61-77)\n" +
" │ │ │ ├─ tableId: 7\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [dkcaj tw55n]\n" +
" │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ ├─ index: [SFEGG.NO52D,SFEGG.VYO5E,SFEGG.DKCAJ]\n" +
" │ │ ├─ keys: [tvtjs.NO52D:7!null]\n" +
" │ │ ├─ colSet: (55-60)\n" +
" │ │ ├─ tableId: 6\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\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" +
" │ │ ├─ alias-string: select id from JDLNA where JDLNA.FTQLQ = TVTJS.TOFPN\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" +
" │ │ ├─ keys: [tvtjs.TOFPN:1!null]\n" +
" │ │ ├─ colSet: (27-31)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: JDLNA\n" +
" │ │ └─ columns: [id ftqlq]\n" +
" │ │ as FZ2R5, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select id from E2I7U where TW55N = TVTJS.I3VTA\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" +
" │ │ ├─ keys: [tvtjs.I3VTA:2!null]\n" +
" │ │ ├─ colSet: (33-49)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: E2I7U\n" +
" │ │ └─ columns: [id tw55n]\n" +
" │ │ as LUEVY, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: select id from TPXBU where BTXC5 = TVTJS.LJLUM\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" +
" │ │ ├─ keys: [tvtjs.LJLUM:5!null]\n" +
" │ │ ├─ colSet: (51-53)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: TPXBU\n" +
" │ │ └─ columns: [id btxc5]\n" +
" │ │ as M22QN, Subquery\n" +
" │ │ ├─ cacheable: false\n" +
" │ │ ├─ alias-string: 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 as nd where nd.TW55N = TVTJS.I3VTA)\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" +
" │ │ │ ├─ alias-string: select nd.DKCAJ from E2I7U as nd where nd.TW55N = TVTJS.I3VTA\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" +
" │ │ │ ├─ keys: [tvtjs.I3VTA:2!null]\n" +
" │ │ │ ├─ colSet: (61-77)\n" +
" │ │ │ ├─ tableId: 7\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: E2I7U\n" +
" │ │ │ └─ columns: [dkcaj tw55n]\n" +
" │ │ └─ IndexedTableAccess(SFEGG)\n" +
" │ │ ├─ index: [SFEGG.NO52D,SFEGG.VYO5E,SFEGG.DKCAJ]\n" +
" │ │ ├─ keys: [tvtjs.NO52D:7!null]\n" +
" │ │ ├─ colSet: (55-60)\n" +
" │ │ ├─ tableId: 6\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: SFEGG\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" +
" │ └─ TableAlias(tvtjs)\n" +
" │ └─ IndexedTableAccess(HU5A5)\n" +
" │ ├─ index: [HU5A5.id]\n" +
" │ ├─ static: [{[1, 1]}, {[2, 2]}, {[3, 3]}]\n" +
" │ ├─ colSet: (13-25)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: HU5A5\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" +
" │ ├─ alias-string: select SVAZ4 from TPXHZ\n" +
" │ └─ Table\n" +
" │ ├─ name: TPXHZ\n" +
" │ ├─ columns: [svaz4]\n" +
" │ ├─ colSet: (25,26)\n" +
" │ └─ tableId: 3\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" +
"",
},
}
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{}, }, { Query: "select * from othertable join foo.othertable on othertable.s2 = 'third'", Expected: []sql.Row{{"third", 1, "a", 4}, {"third", 1, "b", 2}, {"third", 1, "c", 0}}, }, { Query: "select * from othertable join foo.othertable on mydb.othertable.s2 = 'third'", Expected: []sql.Row{{"third", 1, "a", 4}, {"third", 1, "b", 2}, {"third", 1, "c", 0}}, }, { Query: "select * from othertable join foo.othertable on foo.othertable.text = 'a'", Expected: []sql.Row{{"third", 1, "a", 4}, {"second", 2, "a", 4}, {"first", 3, "a", 4}}, }, { Query: "select * from foo.othertable join othertable on othertable.s2 = 'third'", Expected: []sql.Row{{"a", 4, "third", 1}, {"b", 2, "third", 1}, {"c", 0, "third", 1}}, }, { Query: "select * from foo.othertable join othertable on mydb.othertable.s2 = 'third'", Expected: []sql.Row{{"a", 4, "third", 1}, {"b", 2, "third", 1}, {"c", 0, "third", 1}}, }, { Query: "select * from foo.othertable join othertable on foo.othertable.text = 'a'", Expected: []sql.Row{{"a", 4, "third", 1}, {"a", 4, "second", 2}, {"a", 4, "first", 3}}, }, { Query: "select * from mydb.othertable join foo.othertable on othertable.s2 = 'third'", Expected: []sql.Row{{"third", 1, "a", 4}, {"third", 1, "b", 2}, {"third", 1, "c", 0}}, }, { Query: "select * from mydb.othertable join foo.othertable on mydb.othertable.s2 = 'third'", Expected: []sql.Row{{"third", 1, "a", 4}, {"third", 1, "b", 2}, {"third", 1, "c", 0}}, }, { Query: "select * from mydb.othertable join foo.othertable on foo.othertable.text = 'a'", Expected: []sql.Row{{"third", 1, "a", 4}, {"second", 2, "a", 4}, {"first", 3, "a", 4}}, }, { Query: "select * from foo.othertable join mydb.othertable on othertable.s2 = 'third'", Expected: []sql.Row{{"a", 4, "third", 1}, {"b", 2, "third", 1}, {"c", 0, "third", 1}}, }, { Query: "select * from foo.othertable join mydb.othertable on mydb.othertable.s2 = 'third'", Expected: []sql.Row{{"a", 4, "third", 1}, {"b", 2, "third", 1}, {"c", 0, "third", 1}}, }, { Query: "select * from foo.othertable join mydb.othertable on foo.othertable.text = 'a'", Expected: []sql.Row{{"a", 4, "third", 1}, {"a", 4, "second", 2}, {"a", 4, "first", 3}}, }, }
var JoinScriptTests = []ScriptTest{ { Name: "Simple join query", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "select x from xy, uv join ab on x = a and u = -1;", ExpectedErr: sql.ErrColumnNotFound, }, }, }, { 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_type scripts", Assertions: []ScriptTestAssertion{ { Query: "select JSON_TYPE(CAST(1 AS JSON))", Expected: []sql.Row{ {"INTEGER"}, }, }, { Query: `select JSON_TYPE("1")`, Expected: []sql.Row{ {"INTEGER"}, }, }, { Query: `select JSON_TYPE(CAST("1" AS JSON))`, Expected: []sql.Row{ {"INTEGER"}, }, }, { Query: `select JSON_TYPE("\"1\"")`, Expected: []sql.Row{ {"STRING"}, }, }, { Query: `select JSON_TYPE(CAST("\"1\"" AS JSON))`, Expected: []sql.Row{ {"STRING"}, }, }, { Query: "select JSON_TYPE(CAST(321.4 AS JSON))", Expected: []sql.Row{ {"DECIMAL"}, }, }, { Query: `select JSON_TYPE("321.4")`, Expected: []sql.Row{ {"DOUBLE"}, }, }, { Query: `select JSON_TYPE(CAST("321.4" AS JSON))`, Expected: []sql.Row{ {"DOUBLE"}, }, }, { Query: `select JSON_TYPE("\"321.4\"")`, Expected: []sql.Row{ {"STRING"}, }, }, { Query: `select JSON_TYPE(CAST("\"321.4\"" AS JSON))`, Expected: []sql.Row{ {"STRING"}, }, }, { Query: "select JSON_TYPE(CAST(1e-1 AS JSON))", Expected: []sql.Row{ {"DOUBLE"}, }, }, { Query: `select JSON_TYPE("1e-1")`, Expected: []sql.Row{ {"DOUBLE"}, }, }, { Query: `select JSON_TYPE(CAST("1e-1" AS JSON))`, Expected: []sql.Row{ {"DOUBLE"}, }, }, { Query: "select JSON_TYPE(CAST(1.0e-1 AS JSON))", Expected: []sql.Row{ {"DOUBLE"}, }, }, { Query: `select JSON_TYPE("1.0e-1")`, Expected: []sql.Row{ {"DOUBLE"}, }, }, { Query: `select JSON_TYPE(CAST("1.0e-1" AS JSON))`, Expected: []sql.Row{ {"DOUBLE"}, }, }, }, }, { Name: "types survive round-trip into tables", SetUpScript: []string{ "CREATE TABLE xy (x bigint primary key, y JSON)", `INSERT INTO xy VALUES (0, CAST(CAST(1.2 AS DECIMAL) AS JSON));`, `INSERT INTO xy VALUES (1, CAST(CAST(1.2 AS DOUBLE) AS JSON));`, }, Assertions: []ScriptTestAssertion{ { Query: "select x, JSON_TYPE(y) from xy", Expected: []sql.Row{ {0, "DECIMAL"}, {1, "DOUBLE"}, }, }, }, }, { Name: "unsigned tinyint is still unsigned after round-trip into table", SetUpScript: []string{ "CREATE TABLE xy (x bigint primary key, y JSON, z tinyint unsigned)", `INSERT INTO xy VALUES (0, null, 0);`, `INSERT INTO xy select 1, CAST(z AS JSON), 1 from xy;`, }, Assertions: []ScriptTestAssertion{ { Query: "select JSON_TYPE(y) from xy where x = 1;", Expected: []sql.Row{ {"UNSIGNED INTEGER"}, }, }, }, }, { Name: "json_object preserves types", Assertions: []ScriptTestAssertion{ { Query: `select JSON_TYPE(JSON_EXTRACT(JSON_OBJECT('a', CAST(12.34 AS DECIMAL(4, 2))), "$.a"));`, Expected: []sql.Row{ {"DECIMAL"}, }, }, { Query: `select JSON_TYPE(JSON_EXTRACT(JSON_OBJECT('a', CAST(12 AS UNSIGNED)), "$.a"));`, Expected: []sql.Row{ {"UNSIGNED INTEGER"}, }, }, }, }, { Name: "json_value preserves types", Assertions: []ScriptTestAssertion{ { Query: `select json_value(cast(12.34 as decimal), '$', 'json')`, ExpectedErr: sql.ErrInvalidJSONArgument, }, { Query: `select json_type(json_value(cast(cast(12.34 as decimal) as json), '$', 'json'))`, Expected: []sql.Row{ {"DECIMAL"}, }, }, { Query: `select json_type(json_value(cast(cast(12 as unsigned) as json), '$', 'json'))`, Expected: []sql.Row{ {"UNSIGNED INTEGER"}, }, }, }, }, { Name: "json_value", SetUpScript: []string{ "CREATE TABLE xy (x bigint primary key, y JSON)", `INSERT INTO xy VALUES (0, CAST('["a", "b"]' AS JSON)), (1, CAST('["a", "b", "c", "d"]' AS JSON));`, `INSERT INTO xy VALUES (2, CAST('{"a": [{"b": 1}, {"c": 2}]}' AS JSON)), (3, CAST('{"a": {"b": ["c","d"]}}' AS JSON)), (4,NULL);`, }, Assertions: []ScriptTestAssertion{ { Query: `select json_value(y, '$.a', 'json') from xy`, Expected: []sql.Row{ {nil}, {nil}, {types.MustJSON("[{\"b\": 1}, {\"c\": 2}]")}, {types.MustJSON("{\"b\": [\"c\",\"d\"]}")}, {nil}, }, }, { Query: `select json_value(y, '$.a[0].b', 'signed') from xy where x = 2`, Expected: []sql.Row{ {int64(1)}, }, }, { Query: `select json_value(y, '$.a[0].b') from xy where x = 2`, Expected: []sql.Row{ {"1"}, }, }, }, }, { Name: "json_length", SetUpScript: []string{ "CREATE TABLE xy (x bigint primary key, y JSON)", `INSERT INTO xy VALUES (0, CAST('["a", "b"]' AS JSON)), (1, CAST('["a", "b", "c", "d"]' AS JSON));`, `INSERT INTO xy VALUES (2, CAST('{"a": [{"b": 1}, {"c": 2}]}' AS JSON)), (3, CAST('{"a": {"b": ["c","d"]}}' AS JSON)), (4,NULL);`, }, Assertions: []ScriptTestAssertion{ { Query: `select json_length(y) from xy`, Expected: []sql.Row{ {2}, {4}, {1}, {1}, {nil}, }, }, { Query: `select json_length(json_extract(x, "$.a")) from xy`, ExpectedErrStr: "invalid data type for JSON data in argument 1 to function json_extract; a JSON string or JSON type is required", }, { Query: `select json_length(json_extract(y, "$.a")) from xy`, Expected: []sql.Row{ {nil}, {nil}, {2}, {1}, {nil}, }, }, { Query: `select json_length(json_extract(y, "$.a.b")) from xy where x = 3`, Expected: []sql.Row{ {2}, }, }, { Query: `select json_length(y, "$.a.b") from xy where x = 3`, Expected: []sql.Row{ {2}, }, }, { Query: `select json_length(y, "$.a[0].b") from xy where x = 2`, Expected: []sql.Row{ {1}, }, }, }, }, { 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]sqlparser.Expr{ "v1": sqlparser.NewStrVal([]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'", }, }, }, { Name: "json type value compared with number type value", Assertions: []ScriptTestAssertion{ { Query: "SELECT JSON_EXTRACT('0.4', '$')", Expected: []sql.Row{{types.MustJSON(`0.4`)}}, }, { Query: "SELECT JSON_EXTRACT('0.4', '$') > 0;", Expected: []sql.Row{{true}}, }, { Query: "SELECT JSON_EXTRACT('0.4', '$') <= 0;", Expected: []sql.Row{{false}}, }, { Query: "SELECT JSON_EXTRACT('0.4', '$') = 0;", Expected: []sql.Row{{false}}, }, { Query: "SELECT JSON_EXTRACT('0.4', '$') = 0.4;", Expected: []sql.Row{{true}}, }, }, }, { Name: "json bools", SetUpScript: []string{ "create table t (j json);", "insert into t values ('{\"x\": true}'), ('{\"x\": false}');", }, Assertions: []ScriptTestAssertion{ { Query: "select j->'$.x' = true from t;", Expected: []sql.Row{ {true}, {false}, }, }, }, }, { Name: "json mutations don't modify objects that could be seen by other expressions", SetUpScript: []string{ "create table t (pk int primary key, col1 json);", "insert into t values (1, '{}');", }, Assertions: []ScriptTestAssertion{ { Query: "select pk, json_insert(col1, '$.x', 1), json_insert(col1, '$.y', 2) from t order by pk;", Expected: []sql.Row{ {1, types.MustJSON("{\"x\":1}"), types.MustJSON("{\"y\":2}")}, }, }, }, }, }
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", "", nil, ""}, {"c1", "bigint", "YES", "", nil, ""}, }, }, { Query: "SHOW COLUMNS FROM keyless", Expected: []sql.Row{ {"c0", "bigint", "YES", "", nil, ""}, {"c1", "bigint", "YES", "", nil, ""}, }, }, { Query: "SHOW FULL COLUMNS FROM keyless", Expected: []sql.Row{ {"c0", "bigint", nil, "YES", "", nil, "", "", ""}, {"c1", "bigint", nil, "YES", "", nil, "", "", ""}, }, }, { 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}, }, }, { 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}, }, }, { 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}, }, }, }, }, { Name: "multiple lateral joins with references to left tables", SetUpScript: []string{ "create table students (id int primary key, name varchar(50), major int);", "create table classes (id int primary key, name varchar(50), department int);", "create table grades (grade float, student int, class int, primary key(class, student));", "create table majors (id int, name varchar(50), department int, primary key(name, department));", "create table departments (id int primary key, name varchar(50));", `insert into students values (1, 'Elle', 4), (2, 'Latham', 2);`, `insert into classes values (1, 'Corporate Finance', 1), (2, 'ESG Studies', 1), (3, 'Late Bronze Age Collapse', 2), (4, 'Greek Mythology', 2);`, `insert into majors values (1, 'Roman Studies', 2), (2, 'Bronze Age Studies', 2), (3, 'Accounting', 1), (4, 'Finance', 1);`, `insert into departments values (1, 'Business'), (2, 'History');`, `insert into grades values (94, 1, 1), (97, 1, 2), (85, 2, 3), (92, 2, 4);`, }, Assertions: []ScriptTestAssertion{ { Query: ` select name, class.class_name, grade.max_grade from students, LATERAL ( select departments.id as did from majors join departments on majors.department = departments.id where majors.id = students.major ) dept, LATERAL ( select grade as max_grade, classes.id as cid from grades join classes on grades.class = classes.id where grades.student = students.id and classes.department = dept.did order by grade desc limit 1 ) grade, LATERAL ( select name as class_name from classes where grade.cid = classes.id ) class `, Expected: []sql.Row{ {"Elle", "ESG Studies", 97.0}, {"Latham", "Greek Mythology", 92.0}, }, }, }, }, { Name: "lateral join with subquery", SetUpScript: []string{ "create table xy (x int primary key, y int);", "create table uv (u int primary key, v int);", "insert into xy values (1, 0), (2, 1), (3, 2), (4, 3);", "insert into uv values (0, 0), (1, 1), (2, 2), (3, 3);", }, Assertions: []ScriptTestAssertion{ { Query: "select x, u from xy, lateral (select * from uv where y = u) uv;", Expected: []sql.Row{ {1, 0}, {2, 1}, {3, 2}, {4, 3}, }, }, }, }, }
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 './bad/doesnotexist.txt' INTO TABLE loadtable", ExpectedErr: sql.ErrLoadDataCannotOpen, }, }, }, { Name: "Load data with unknown columns throws an error", SetUpScript: []string{ "create table loadtable(pk int primary key, i int)", }, Assertions: []ScriptTestAssertion{ { Query: "LOAD DATA INFILE './testdata/test1.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"' (fake_col, pk, i)", ExpectedErr: sql.ErrUnknownColumn, }, { Query: "LOAD DATA INFILE './testdata/test1.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"' (pk, fake_col, i)", ExpectedErr: sql.ErrUnknownColumn, }, { Query: "LOAD DATA INFILE './testdata/test1.txt' INTO TABLE loadtable FIELDS ENCLOSED BY '\"' (pk, i, fake_col)", ExpectedErr: sql.ErrUnknownColumn, }, }, }, { 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.ErrUnexpectedSeparator, }, }, }, { 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.ErrUnexpectedSeparator, }, }, }, { 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"}, }, }, }, }, { Name: "LOAD DATA with set columns no projections", SetUpScript: []string{ "create table lt1(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt1 FIELDS TERMINATED BY '\t' SET i = '123'", "create table lt2(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt2 set i = '123', j = '456'", "create table lt3(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt3 set i = '123', j = '456', k = '789'", "create table lt4(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt4 set i = '123', i = '321'", "create table lt5(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt5 set j = concat(j, j)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from lt1 order by i, j, k", Expected: []sql.Row{ {"123", "def", "ghi"}, {"123", "mno", "pqr"}, }, }, { Query: "select * from lt2 order by i, j, k", Expected: []sql.Row{ {"123", "456", "ghi"}, {"123", "456", "pqr"}, }, }, { Query: "select * from lt3 order by i, j, k", Expected: []sql.Row{ {"123", "456", "789"}, {"123", "456", "789"}, }, }, { Query: "select * from lt4 order by i, j, k", Expected: []sql.Row{ {"321", "def", "ghi"}, {"321", "mno", "pqr"}, }, }, { Query: "select * from lt5 order by i, j, k", Expected: []sql.Row{ {"abc", "defdef", "ghi"}, {"jkl", "mnomno", "pqr"}, }, }, }, }, { Name: "LOAD DATA with set columns with projections", SetUpScript: []string{ "create table lt1(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt1 (i, j, k) set i = '123'", "create table lt2(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt2 (k, i, j) set i = '123'", "create table lt3(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt3 (j, k) set i = '123'", "create table lt4(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt4 (k, i) set i = '123'", }, Assertions: []ScriptTestAssertion{ { Query: "select * from lt1 order by i, j, k", Expected: []sql.Row{ {"123", "def", "ghi"}, {"123", "mno", "pqr"}, }, }, { Query: "select * from lt2 order by i, j, k", Expected: []sql.Row{ {"123", "ghi", "abc"}, {"123", "pqr", "jkl"}, }, }, { Query: "select * from lt3 order by i, j, k", Expected: []sql.Row{ {"123", "abc", "def"}, {"123", "jkl", "mno"}, }, }, { Query: "select * from lt4 order by i, j, k", Expected: []sql.Row{ {"123", nil, "abc"}, {"123", nil, "jkl"}, }, }, }, }, { Name: "LOAD DATA assign to static User Variables", SetUpScript: []string{ "set @i = '123';", "set @j = '456';", "set @k = '789';", "create table lt(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt set i = @i", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt set i = @i, j = @j", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt set i = @i, j = @j, k = @k", }, Assertions: []ScriptTestAssertion{ { Query: "select * from lt order by i, j, k", Expected: []sql.Row{ {"123", "456", "789"}, {"123", "456", "789"}, {"123", "456", "ghi"}, {"123", "456", "pqr"}, {"123", "def", "ghi"}, {"123", "mno", "pqr"}, }, }, }, }, { Name: "LOAD DATA assign to User Variables", SetUpScript: []string{ "create table lt1(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt1 (@i, j, k)", "create table lt2(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt2 (i, @j, k)", "create table lt3(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt3 (i, j, @k)", "create table lt4(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt4 (@ii, @jj, @kk)", "create table lt5(i text, j text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt5 (i, j, @trash1)", "create table lt6(j text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt6 (@trash2, j, @trash2)", }, Assertions: []ScriptTestAssertion{ { Query: "select * from lt1 order by i, j, k", Expected: []sql.Row{ {nil, "def", "ghi"}, {nil, "mno", "pqr"}, }, }, { Query: "select * from lt2 order by i, j, k", Expected: []sql.Row{ {"abc", nil, "ghi"}, {"jkl", nil, "pqr"}, }, }, { Query: "select * from lt3 order by i, j, k", Expected: []sql.Row{ {"abc", "def", nil}, {"jkl", "mno", nil}, }, }, { Query: "select @i, @j, @k", Expected: []sql.Row{ {"jkl", "mno", "pqr"}, }, }, { Query: "select * from lt4 order by i, j, k", Expected: []sql.Row{ {nil, nil, nil}, {nil, nil, nil}, }, }, { Query: "select @ii, @jj, @kk", Expected: []sql.Row{ {"jkl", "mno", "pqr"}, }, }, { Query: "select * from lt5 order by i, j", Expected: []sql.Row{ {"abc", "def"}, {"jkl", "mno"}, }, }, { Query: "select @trash1", Expected: []sql.Row{ {"pqr"}, }, }, { Query: "select * from lt6 order by j", Expected: []sql.Row{ {"def"}, {"mno"}, }, }, { Query: "select @trash2", Expected: []sql.Row{ {"pqr"}, }, }, }, }, { Name: "LOAD DATA with user vars and set expressions", SetUpScript: []string{ "create table lt1(i text, j text, k text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt1 (k, @j, i) set j = @j", "create table lt2(i text, j text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt2 (i, j, @k) set j = concat(@k, @k)", "create table lt3(i text, j text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt3 (i, @j, @k) set j = concat(@j, @k)", "create table lt4(i text, j text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt4 (i, j, @k) set j = concat(j, @k)", "create table lt5(i text, j text);", "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt5 (@i, @j) set i = @j, j = @i", }, Assertions: []ScriptTestAssertion{ { Query: "select * from lt1 order by i, j, k", Expected: []sql.Row{ {"ghi", "def", "abc"}, {"pqr", "mno", "jkl"}, }, }, { Query: "select * from lt2 order by i, j", Expected: []sql.Row{ {"abc", "ghighi"}, {"jkl", "pqrpqr"}, }, }, { Query: "select * from lt3 order by i, j", Expected: []sql.Row{ {"abc", "defghi"}, {"jkl", "mnopqr"}, }, }, { Query: "select * from lt4 order by i, j", Expected: []sql.Row{ {"abc", "defghi"}, {"jkl", "mnopqr"}, }, }, { Query: "select * from lt5 order by i, j", Expected: []sql.Row{ {"def", "abc"}, {"mno", "jkl"}, }, }, }, }, { Name: "LOAD DATA with set columns errors", SetUpScript: []string{ "create table lt(i text, j text, k text);", }, Assertions: []ScriptTestAssertion{ { Query: "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt set noti = '123'", ExpectedErr: sql.ErrColumnNotFound, }, }, }, { Name: "LOAD DATA with user var alias edge case", SetUpScript: []string{ "create table lt(i text, `@j` text, `@@k` text);", }, Assertions: []ScriptTestAssertion{ { Query: "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt(@@k)", ExpectedErrStr: "syntax error near '@@k'", }, { Skip: true, Query: "LOAD DATA INFILE './testdata/test9.txt' INTO TABLE lt(i, @j, `@@k`)", Expected: []sql.Row{ {"abc", "def", "ghi"}, {"jkl", "mno", "pqr"}, }, }, }, }, { Name: "LOAD DATA with column data larger than 64KB", SetUpScript: []string{ "create table t(id int primary key, lt longtext);", "load data infile './testdata/test10.txt' into table t fields terminated by ',' lines terminated by '\n';", }, Assertions: []ScriptTestAssertion{ { Query: "select id, length(lt) from t order by id", Expected: []sql.Row{ {1, 65535}, {2, 100000}, {3, 1000000}, }, }, }, }, }
var ModifyColumnScripts = []ScriptTest{ { Name: "column at end with default", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable MODIFY COLUMN i bigint NOT NULL COMMENT 'modified'", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable /* 1 */", Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "", "", "modified"}, {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "", nil, "", "", "column s"}, }, }, { Query: "ALTER TABLE mytable MODIFY COLUMN i TINYINT NOT NULL COMMENT 'yes' AFTER s", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable /* 2 */", Expected: []sql.Row{ {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "", nil, "", "", "column s"}, {"i", "tinyint", nil, "NO", "PRI", nil, "", "", "yes"}, }, }, { Query: "ALTER TABLE mytable MODIFY COLUMN i BIGINT NOT NULL COMMENT 'ok' FIRST", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable /* 3 */", Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "", "", "ok"}, {"s", "varchar(20)", "utf8mb4_0900_bin", "NO", "", nil, "", "", "column s"}, }, }, { Query: "ALTER TABLE mytable MODIFY COLUMN s VARCHAR(20) NULL COMMENT 'changed'", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable /* 4 */", Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "", "", "ok"}, {"s", "varchar(20)", "utf8mb4_0900_bin", "YES", "", nil, "", "", "changed"}, }, }, }, }, { Name: "auto increment attribute", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable MODIFY i BIGINT auto_increment", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable /* 1 */", Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "auto_increment", "", ""}, {"s", "varchar(20)", "utf8mb4_0900_bin", "YES", "", nil, "", "", "changed"}, }, }, { Query: "insert into mytable (s) values ('new row')", }, { Query: "ALTER TABLE mytable add column i2 bigint auto_increment", ExpectedErr: sql.ErrInvalidAutoIncCols, }, { Query: "alter table mytable add column i2 bigint", }, { Query: "ALTER TABLE mytable modify column i2 bigint auto_increment", ExpectedErr: sql.ErrInvalidAutoIncCols, }, { Query: "SHOW FULL COLUMNS FROM mytable /* 2 */", Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "auto_increment", "", ""}, {"s", "varchar(20)", "utf8mb4_0900_bin", "YES", "", nil, "", "", "changed"}, {"i2", "bigint", nil, "YES", "", nil, "", "", ""}, }, }, { Query: "ALTER TABLE mytable MODIFY COLUMN i BIGINT NOT NULL COMMENT 'ok' FIRST", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable /* 3 */", Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "", "", "ok"}, {"s", "varchar(20)", "utf8mb4_0900_bin", "YES", "", nil, "", "", "changed"}, {"i2", "bigint", nil, "YES", "", nil, "", "", ""}, }, }, { Query: "ALTER TABLE mytable MODIFY COLUMN s VARCHAR(20) NULL COMMENT 'changed'", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable /* 4 */", Expected: []sql.Row{ {"i", "bigint", nil, "NO", "PRI", nil, "", "", "ok"}, {"s", "varchar(20)", "utf8mb4_0900_bin", "YES", "", nil, "", "", "changed"}, {"i2", "bigint", nil, "YES", "", nil, "", "", ""}, }, }, }, }, { Name: "error cases", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable MODIFY not_exist BIGINT NOT NULL COMMENT 'ok' FIRST", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE mytable MODIFY i BIGINT NOT NULL COMMENT 'ok' AFTER not_exist", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE not_exist MODIFY COLUMN i INT NOT NULL COMMENT 'hello'", ExpectedErr: sql.ErrTableNotFound, }, { Query: "ALTER TABLE mytable ADD COLUMN b INT NOT NULL DEFAULT 'yes'", ExpectedErr: sql.ErrIncompatibleDefaultType, }, { Query: "ALTER TABLE mytable ADD COLUMN c int, add c int", ExpectedErr: sql.ErrColumnExists, }, }, }, }
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"}}, }, }, }, { Name: "test mysql database", Assertions: []ScriptTestAssertion{ { Query: "show databases like 'mysql';", Expected: []sql.Row{{"mysql"}}, }, { Query: "create database mysql;", ExpectedErr: sql.ErrDatabaseExists, }, { Query: "drop database mysql;", ExpectedErrStr: "unable to drop database: mysql", }, { Query: "show databases like 'mysql';", Expected: []sql.Row{{"mysql"}}, }, }, }, }
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 NumericErrorQueries = []ScriptTest{ { Name: "range key float fuzzer fail", SetUpScript: []string{ "create table float_pk (a int, b double, primary key(a,b))", "create table float_uk (a int, b double, primary key(a), unique key (b))", "create table float_nuk (a int, b double, primary key(a), key (b))", "insert into float_pk values (1, -4e+212)", "insert into float_uk values (1, -4e+212)", "insert into float_nuk values (1, -4e+212)", "create table decimal_pk (a int, b decimal(65,30), primary key(a,b))", "create table decimal_uk (a int, b decimal(65,30), primary key(a), unique key (b))", "create table decimal_nuk (a int, b decimal(65,30), primary key(a), key (b))", "insert into decimal_pk values (1, 9999999999999999999999999.9999999999999999999999999999999)", "insert into decimal_uk values (1, 9999999999999999999999999.9999999999999999999999999999999)", "insert into decimal_nuk values (1, 9999999999999999999999999.9999999999999999999999999999999)", "create table i8 (i tinyint primary key)", "create table i16 (i smallint primary key)", "create table i32 (i int primary key)", "create table i64 (i bigint primary key)", "create table ui8 (i tinyint unsigned primary key)", "create table ui16 (i smallint unsigned primary key)", "create table ui32 (i int unsigned primary key)", "create table ui64 (i bigint unsigned primary key)", "insert into i8 values (127)", "insert into i16 values (32767)", "insert into i32 values (2147483647)", "insert into i64 values (9223372036854775807)", "insert into ui8 values (255)", "insert into ui16 values (65535)", "insert into ui32 values (4294967295)", "insert into ui64 values (18446744073709551615)", }, Assertions: []ScriptTestAssertion{ { Query: "delete from float_pk where a = 1 and b = -4e+212", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from decimal_uk where b = 9999999999999999999999999.9999999999999999999999999999999", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from decimal_nuk where b = 9999999999999999999999999.9999999999999999999999999999999", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from decimal_pk where a = 1 and b = 9999999999999999999999999.9999999999999999999999999999999", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from i8 where i = 127", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from i16 where i = 32767", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from i32 where i = 2147483647", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from i64 where i = 9223372036854775807", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from ui8 where i = 255", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from ui16 where i = 65535", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from ui32 where i = 4294967295", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "delete from ui64 where i = 18446744073709551615", Expected: []sql.Row{{types.NewOkResult(1)}}, }, }, }, }
var OnUpdateExprScripts = []ScriptTest{ { Name: "error cases", SetUpScript: []string{ "create table t (i int, ts timestamp);", }, Assertions: []ScriptTestAssertion{ { Query: "create table tt (i int, j int on update (5))", ExpectedErrStr: "syntax error at position 42 near 'update'", }, { Query: "create table tt (i int, j int on update current_timestamp)", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "create table tt (i int, d date on update current_timestamp)", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "create table tt (i int, ts timestamp on update now(1))", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "create table tt (i int, ts timestamp(6) on update now(3))", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "create table tt (i int, ts timestamp(3) on update now(6))", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "create table tt (i int, ts timestamp on update current_timestamp(1))", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "create table tt (i int, ts timestamp on update current_timestamp(100))", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "create table tt (i int, ts timestamp on update localtime(1))", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "create table tt (i int, ts timestamp on update localtimestamp(1))", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "alter table t modify column ts timestamp on update (5)", ExpectedErrStr: "syntax error at position 53 near 'update'", }, { Query: "alter table t modify column t int on update current_timestamp", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "alter table t modify column t date on update current_timestamp", ExpectedErr: sql.ErrInvalidOnUpdate, }, { Query: "select current_timestamp(i) from t", ExpectedErrStr: "syntax error at position 27 near 'i'", }, }, }, { Name: "basic case", SetUpScript: []string{ "create table t (i int, ts timestamp default 0 on update current_timestamp);", "insert into t(i) values (1), (2), (3);", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from t order by i;", Expected: []sql.Row{ {1, ZeroTime}, {2, ZeroTime}, {3, ZeroTime}, }, }, { Query: "update t set i = 10 where i = 1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from t order by i;", Expected: []sql.Row{ {2, ZeroTime}, {3, ZeroTime}, {10, Dec15_1_30}, }, }, { Query: "update t set i = 100", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {100, Dec15_1_30}, {100, Dec15_1_30}, {100, Dec15_1_30}, }, }, { Query: "update t set ts = timestamp('2020-10-2')", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {100, Oct2Midnight}, {100, Oct2Midnight}, {100, Oct2Midnight}, }, }, }, }, { Name: "precision 3", SetUpScript: []string{ "create table t (i int, ts timestamp(3) default 0 on update current_timestamp(3));", "insert into t(i) values (1), (2), (3);", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp(3) DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP(3)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from t order by i;", Expected: []sql.Row{ {1, ZeroTime}, {2, ZeroTime}, {3, ZeroTime}, }, }, { Query: "update t set i = 10 where i = 1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from t order by i;", Expected: []sql.Row{ {2, ZeroTime}, {3, ZeroTime}, {10, Dec15_1_30}, }, }, { Query: "update t set i = 100", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {100, Dec15_1_30}, {100, Dec15_1_30}, {100, Dec15_1_30}, }, }, { Query: "update t set ts = timestamp('2020-10-2')", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {100, Oct2Midnight}, {100, Oct2Midnight}, {100, Oct2Midnight}, }, }, }, }, { Name: "precision 6", SetUpScript: []string{ "create table t (i int, ts timestamp(6) default 0 on update current_timestamp(6));", "insert into t(i) values (1), (2), (3);", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp(6) DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP(6)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from t order by i;", Expected: []sql.Row{ {1, ZeroTime}, {2, ZeroTime}, {3, ZeroTime}, }, }, { Query: "update t set i = 10 where i = 1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from t order by i;", Expected: []sql.Row{ {2, ZeroTime}, {3, ZeroTime}, {10, Dec15_1_30}, }, }, { Query: "update t set i = 100", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {100, Dec15_1_30}, {100, Dec15_1_30}, {100, Dec15_1_30}, }, }, { Query: "update t set ts = timestamp('2020-10-2')", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {100, Oct2Midnight}, {100, Oct2Midnight}, {100, Oct2Midnight}, }, }, }, }, { Name: "default time is current time", SetUpScript: []string{ "create table t (i int, ts timestamp default current_timestamp on update current_timestamp);", "insert into t(i) values (1), (2), (3);", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {1, Jan1Noon}, {2, Jan1Noon}, {3, Jan1Noon}, }, }, { Query: "update t set i = 10 where i = 1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {2, Jan1Noon}, {3, Jan1Noon}, {10, Dec15_1_30}, }, }, { Query: "update t set i = 100", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {100, Dec15_1_30}, {100, Dec15_1_30}, {100, Dec15_1_30}, }, }, { Query: "update t set ts = timestamp('2020-10-2')", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {100, Oct2Midnight}, {100, Oct2Midnight}, {100, Oct2Midnight}, }, }, }, }, { Name: "alter table", SetUpScript: []string{ "create table t (i int, ts timestamp);", "insert into t(i) values (1), (2), (3);", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table t modify column ts timestamp default 0 on update current_timestamp;", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {1, nil}, {2, nil}, {3, nil}, }, }, { Query: "update t set i = 10 where i = 1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {2, nil}, {3, nil}, {10, Dec15_1_30}, }, }, { Query: "update t set i = 100", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {100, Dec15_1_30}, {100, Dec15_1_30}, {100, Dec15_1_30}, }, }, { Query: "update t set ts = timestamp('2020-10-2')", Expected: []sql.Row{ {types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 3, Updated: 3}}}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {100, Oct2Midnight}, {100, Oct2Midnight}, {100, Oct2Midnight}, }, }, }, }, { Name: "multiple columns case", SetUpScript: []string{ "create table t (i int primary key, ts timestamp default 0 on update current_timestamp, dt datetime default 0 on update current_timestamp);", "insert into t(i) values (1), (2), (3);", }, Assertions: []ScriptTestAssertion{ { Query: "show create table t", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int NOT NULL,\n" + " `ts` timestamp DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP,\n" + " `dt` datetime DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP,\n" + " PRIMARY KEY (`i`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from t order by i;", Expected: []sql.Row{ {1, ZeroTime, ZeroTime}, {2, ZeroTime, ZeroTime}, {3, ZeroTime, ZeroTime}, }, }, { Query: "update t set i = 10 where i = 1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from t order by i;", Expected: []sql.Row{ {2, ZeroTime, ZeroTime}, {3, ZeroTime, ZeroTime}, {10, Dec15_1_30, Dec15_1_30}, }, }, { Query: "update t set ts = timestamp('2020-10-2') where i = 2", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from t order by i;", Expected: []sql.Row{ {2, Oct2Midnight, Dec15_1_30}, {3, ZeroTime, ZeroTime}, {10, Dec15_1_30, Dec15_1_30}, }, }, }, }, { Name: "before update trigger", SetUpScript: []string{ "create table t (i int primary key, ts timestamp default 0 on update current_timestamp, dt datetime default 0 on update current_timestamp);", "create trigger trig before update on t for each row set new.ts = timestamp('2020-10-2');", "insert into t(i) values (1), (2), (3);", }, Assertions: []ScriptTestAssertion{ { Query: "update t set i = 10 where i = 1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from t order by i;", Expected: []sql.Row{ {2, ZeroTime, ZeroTime}, {3, ZeroTime, ZeroTime}, {10, Oct2Midnight, Dec15_1_30}, }, }, }, }, { Name: "after update trigger", SetUpScript: []string{ "create table a (i int primary key);", "create table b (i int, ts timestamp default 0 on update current_timestamp, dt datetime default 0 on update current_timestamp);", "create trigger trig after update on a for each row update b set i = i + 1;", "insert into a values (0);", "insert into b(i) values (0);", }, Assertions: []ScriptTestAssertion{ { SkipResultCheckOnServerEngine: true, Query: "select * from b order by i;", Expected: []sql.Row{ {0, ZeroTime, ZeroTime}, }, }, { Query: "update a set i = 10;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { Query: "select * from b order by i;", Expected: []sql.Row{ {1, Dec15_1_30, Dec15_1_30}, }, }, }, }, { Name: "insert triggers", SetUpScript: []string{ "create table t (i int primary key);", "create table a (i int, ts timestamp default 0 on update current_timestamp, dt datetime default 0 on update current_timestamp);", "create table b (i int, ts timestamp default 0 on update current_timestamp, dt datetime default 0 on update current_timestamp);", "create trigger trigA after insert on t for each row update a set i = i + 1;", "create trigger trigB before insert on t for each row update b set i = i + 1;", "insert into a(i) values (0);", "insert into b(i) values (0);", }, Assertions: []ScriptTestAssertion{ { Query: "insert into t values (1);", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1}}, }, }, { Query: "select * from a order by i;", Expected: []sql.Row{ {1, Dec15_1_30, Dec15_1_30}, }, }, { Query: "select * from b order by i;", Expected: []sql.Row{ {1, Dec15_1_30, Dec15_1_30}, }, }, }, }, { Name: "foreign key tests", SetUpScript: []string{ "create table parent (i int primary key);", "create table child (i int primary key, ts timestamp default 0 on update current_timestamp, foreign key (i) references parent(i) on update cascade);", "insert into parent values (1);", "insert into child(i) values (1);", }, Assertions: []ScriptTestAssertion{ { Query: "update parent set i = 10;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { SkipResultCheckOnServerEngine: true, Query: "select * from child;", Expected: []sql.Row{ {10, ZeroTime}, }, }, }, }, { Name: "stored procedure tests", SetUpScript: []string{ "create table t (i int, ts timestamp default 0 on update current_timestamp);", "insert into t(i) values (0);", "create procedure p() update t set i = i + 1;", }, Assertions: []ScriptTestAssertion{ { SkipResultCheckOnServerEngine: true, Query: "call p();", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {1, Dec15_1_30}, }, }, }, }, { Name: "now() synonyms", SetUpScript: []string{ "create table t (i int, ts timestamp);", }, Assertions: []ScriptTestAssertion{ { Query: "create table t1 (i int, ts timestamp on update now())", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t1;", Expected: []sql.Row{ {"t1", "CREATE TABLE `t1` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t2 (i int, ts timestamp on update now(0))", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t2;", Expected: []sql.Row{ {"t2", "CREATE TABLE `t2` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t3 (i int, ts timestamp on update localtime)", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t3;", Expected: []sql.Row{ {"t3", "CREATE TABLE `t3` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t4 (i int, ts timestamp on update localtime())", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t4;", Expected: []sql.Row{ {"t4", "CREATE TABLE `t4` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t5 (i int, ts timestamp on update localtime(0))", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t5;", Expected: []sql.Row{ {"t5", "CREATE TABLE `t5` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t6 (i int, ts timestamp on update localtimestamp)", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t6;", Expected: []sql.Row{ {"t6", "CREATE TABLE `t6` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t7 (i int, ts timestamp on update localtimestamp())", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t7;", Expected: []sql.Row{ {"t7", "CREATE TABLE `t7` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "create table t8 (i int, ts timestamp on update localtimestamp(0))", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t8;", Expected: []sql.Row{ {"t8", "CREATE TABLE `t8` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table t modify column ts timestamp on update now()", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table t modify column ts timestamp on update now(0)", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table t modify column ts timestamp on update localtime", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table t modify column ts timestamp on update localtime()", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table t modify column ts timestamp on update localtime(0)", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table t modify column ts timestamp on update localtimestamp", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table t modify column ts timestamp on update localtimestamp()", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "alter table t modify column ts timestamp on update localtimestamp(0)", Expected: []sql.Row{ {types.NewOkResult(0)}, }, }, { Query: "show create table t;", Expected: []sql.Row{ {"t", "CREATE TABLE `t` (\n" + " `i` int,\n" + " `ts` timestamp ON UPDATE CURRENT_TIMESTAMP\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, }, }, }
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{ {"NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES"}, }, }, { Query: "select @@session.sql_mode", Expected: []sql.Row{ {"NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES"}, }, }, { 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{ {"NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES"}, }, }, { Query: "select @@session.sql_mode", Expected: []sql.Row{ {"NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES"}, }, }, { 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{}/* 422 elements not displayed */
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: "bind variable not provided: '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 with time type binding", SetUpScript: []string{ "create table t (d date, dt datetime, t time, ts timestamp);", "set @d = date('2001-02-03');", "set @dt = datetime('2001-02-03 12:34:56');", "set @t = time('12:34:56');", "set @ts = timestamp('2001-02-03 12:34:56');", "prepare s from 'select ?';", "prepare sd from 'insert into t(d) values(?)';", "prepare sdt from 'insert into t(dt) values(?)';", "prepare st from 'insert into t(t) values(?)';", "prepare sts from 'insert into t(ts) values(?)';", }, Assertions: []ScriptTestAssertion{ { Query: "execute s using @d;", Expected: []sql.Row{ {"2001-02-03"}, }, }, { Query: "execute s using @dt;", Expected: []sql.Row{ {time.Date(2001, time.February, 3, 12, 34, 56, 0, time.UTC)}, }, }, { Skip: true, Query: "execute s using @t;", Expected: []sql.Row{ {"12:34:56"}, }, }, { Query: "execute s using @ts;", Expected: []sql.Row{ {time.Date(2001, time.February, 3, 12, 34, 56, 0, time.UTC)}, }, }, { SkipResultCheckOnServerEngine: true, Query: "execute sd using @d;", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { SkipResultCheckOnServerEngine: true, Query: "execute sdt using @dt;", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Skip: true, SkipResultCheckOnServerEngine: true, Query: "execute st using @t;", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { SkipResultCheckOnServerEngine: true, Query: "execute sts using @ts;", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "select d, dt, ts from t", Expected: []sql.Row{ {time.Date(2001, time.February, 3, 0, 0, 0, 0, time.UTC), nil, nil}, {nil, time.Date(2001, time.February, 3, 12, 34, 56, 0, time.UTC), nil}, {nil, nil, time.Date(2001, time.February, 3, 12, 34, 56, 0, time.UTC)}, }, }, }, }, { Name: "prepare with decimal type binding", SetUpScript: []string{ "create table t (d decimal);", "set @d = cast(123.45 as Decimal(5,2));", "prepare s from 'select ?';", "prepare sd from 'insert into t values(?)';", }, Assertions: []ScriptTestAssertion{ { Skip: true, Query: "execute s using @d;", Expected: []sql.Row{ {"123.45"}, }, }, { Skip: true, SkipResultCheckOnServerEngine: true, Query: "execute sd using @d;", Expected: []sql.Row{ {"123.45"}, }, }, { Skip: true, Query: "select * from t", Expected: []sql.Row{ {"123.45"}, }, }, }, }, { 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: "bind variable not provided: 'v2'", }, { SkipResultCheckOnServerEngine: true, 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]sqlparser.Expr{ "v1": sqlparser.NewStrVal([]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"}}, }, }, }, { Name: "Call a procedure that needs subqueries resolved in an if condition", SetUpScript: []string{ `CREATE PROCEDURE populate_if_empty() BEGIN IF (SELECT 0) = 0 THEN SELECT 'hi'; END IF; END`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL populate_if_empty();", Expected: []sql.Row{{"hi"}}, }, }, }, }
var ProcedureCreateInSubroutineTests = []ScriptTest{ { Name: "procedure must not contain CREATE PROCEDURE", Assertions: []ScriptTestAssertion{ { Query: "CREATE PROCEDURE foo() CREATE PROCEDURE bar() SELECT 0;", ExpectedErrStr: "creating procedures in stored procedures is currently unsupported and will be added in a future release", }, }, }, { Name: "event must not contain CREATE PROCEDURE", Assertions: []ScriptTestAssertion{ { Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE PROCEDURE bar() SELECT 1;", ExpectedErrStr: "Can't create a PROCEDURE from within another stored routine", Skip: true, }, }, }, { Name: "trigger must not contain CREATE PROCEDURE", SetUpScript: []string{ "CREATE TABLE t (pk INT PRIMARY KEY);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN CREATE PROCEDURE bar() SELECT 1; END", ExpectedErrStr: "Can't create a PROCEDURE from within another stored routine", Skip: true, }, }, }, }
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{{types.OkResult{}}}, }, { Query: "CALL p1", ExpectedErr: sql.ErrStoredProcedureDoesNotExist, }, { Query: "DROP PROCEDURE IF EXISTS p2", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CALL p2", ExpectedErr: sql.ErrStoredProcedureDoesNotExist, }, { Query: "DROP PROCEDURE p3", ExpectedErr: sql.ErrStoredProcedureDoesNotExist, }, { Query: "DROP PROCEDURE IF EXISTS p4", Expected: []sql.Row{{types.OkResult{}}}, }, }, }, }
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.0, }, }, }, { 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), }, }, }, { SkipResultCheckOnServerEngine: true, 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"}, }, }, { SkipResultCheckOnServerEngine: true, 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"}, }, }, { SkipResultCheckOnServerEngine: true, 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{ { SkipResultCheckOnServerEngine: true, 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{ { SkipResultCheckOnServerEngine: true, 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{ { SkipResultCheckOnServerEngine: true, 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: "issue 7458: proc params as limit values", SetUpScript: []string{ "create table t (i int primary key);", "insert into t values (0), (1), (2), (3)", "CREATE PROCEDURE limited(the_limit int, the_offset bigint) SELECT * FROM t LIMIT the_limit OFFSET the_offset", "CREATE PROCEDURE limited_uns(the_limit int unsigned, the_offset bigint unsigned) SELECT * FROM t LIMIT the_limit OFFSET the_offset", }, Assertions: []ScriptTestAssertion{ { Query: "call limited(1,0)", Expected: []sql.Row{{0}}, }, { Query: "call limited(2,0)", Expected: []sql.Row{{0}, {1}}, }, { Query: "call limited(2,2)", Expected: []sql.Row{{2}, {3}}, }, { Query: "call limited_uns(2,2)", Expected: []sql.Row{{2}, {3}}, }, { Query: "CREATE PROCEDURE limited_inv(the_limit CHAR(3), the_offset INT) SELECT * FROM t LIMIT the_limit OFFSET the_offset", ExpectedErrStr: "the variable 'the_limit' has a non-integer based type: char(3)", }, { Query: "CREATE PROCEDURE limited_inv(the_limit float, the_offset INT) SELECT * FROM t LIMIT the_limit OFFSET the_offset", ExpectedErrStr: "the variable 'the_limit' has a non-integer based type: float", }, }, }, { 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: "SQLEXCEPTION declare handler", SetUpScript: []string{ `DROP TABLE IF EXISTS t1;`, `CREATE TABLE t1 (pk BIGINT PRIMARY KEY);`, `CREATE PROCEDURE eof() BEGIN DECLARE a, b INT DEFAULT 1; DECLARE cur1 CURSOR FOR SELECT * FROM t1; OPEN cur1; BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION SET a = 7; tloop: LOOP FETCH cur1 INTO b; IF a > 1000 THEN LEAVE tloop; END IF; END LOOP; END; CLOSE cur1; SELECT a; END;`, `CREATE PROCEDURE duplicate_key() BEGIN DECLARE a, b INT DEFAULT 1; BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION SET a = 7; INSERT INTO t1 values (0); END; SELECT a; END;`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL eof();", Expected: []sql.Row{}, }, { Query: "CALL duplicate_key();", Expected: []sql.Row{{1}}, }, { Query: "CALL duplicate_key();", Expected: []sql.Row{{7}}, }, }, }, { Name: "DECLARE CONTINUE HANDLER", SetUpScript: []string{ "CREATE TABLE t1(id CHAR(16) primary key, data INT)", "CREATE TABLE t2(i INT)", "CREATE TABLE t3(id CHAR(16) primary key, data INT)", `CREATE PROCEDURE curdemo() BEGIN DECLARE done INT DEFAULT FALSE; DECLARE a CHAR(16); DECLARE b, c INT; DECLARE cur1 CURSOR FOR SELECT id,data FROM t1; DECLARE cur2 CURSOR FOR SELECT i FROM t2; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN cur1; OPEN cur2; read_loop: LOOP FETCH cur1 INTO a, b; FETCH cur2 INTO c; IF done THEN LEAVE read_loop; END IF; IF b < c THEN INSERT INTO t3 VALUES (a,b); ELSE INSERT INTO t3 VALUES (a,c); END IF; END LOOP; CLOSE cur1; CLOSE cur2; SELECT "success"; END`, }, Assertions: []ScriptTestAssertion{ { Query: "CALL curdemo()", Expected: []sql.Row{{"success"}}, }, { Query: "SELECT * from t3", Expected: []sql.Row{}, }, { Query: "INSERT INTO t1 values ('a', 10), ('b', 20)", }, { Query: "INSERT INTO t2 values (15), (15)", }, { Query: "CALL curdemo()", Expected: []sql.Row{{"success"}}, }, { Query: "SELECT * from t3", Expected: []sql.Row{{"a", 10}, {"b", 15}}, }, }, }, { 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{ { SkipResultCheckOnServerEngine: true, 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: "Conditional expression where body has its own columns", SetUpScript: []string{ "CREATE TABLE test (id INT);", }, Assertions: []ScriptTestAssertion{ { Query: ` CREATE PROCEDURE populate(IN val INT) BEGIN IF (SELECT COUNT(*) FROM test where id = val) = 0 THEN INSERT INTO test (id) VALUES (val); END IF; END;`, Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CALL populate(1);", Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, }}}, SkipResultCheckOnServerEngine: true, }, { Query: "SELECT * FROM test;", Expected: []sql.Row{ {1}, }, }, }, }, { Name: "Nested subquery in conditional expression where body has its own columns", SetUpScript: []string{ "CREATE TABLE test (id INT);", }, Assertions: []ScriptTestAssertion{ { Query: ` CREATE PROCEDURE populate(IN val INT) BEGIN IF (SELECT COUNT(*) FROM test where (select t2.id from test t2 where t2.id = test.id) = val) = 0 THEN INSERT INTO test (id) VALUES (val); END IF; END;`, Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CALL populate(1);", Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, }}}, SkipResultCheckOnServerEngine: true, }, { Query: "SELECT * FROM test;", Expected: []sql.Row{ {1}, }, }, }, }, { Name: "Conditional expression with else doesn't have body columns in its scope", SetUpScript: []string{ "CREATE TABLE test (id INT);", }, Assertions: []ScriptTestAssertion{ { Query: ` CREATE PROCEDURE populate(IN val INT) BEGIN IF (SELECT COUNT(*) FROM test where id = val) = 0 THEN INSERT INTO test (id) VALUES (val); ELSE SELECT 0; END IF; END;`, Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "CALL populate(1);", Expected: []sql.Row{{types.OkResult{ RowsAffected: 1, }}}, SkipResultCheckOnServerEngine: true, }, { Query: "SELECT * FROM test;", Expected: []sql.Row{ {1}, }, }, }, }, { 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{}/* 1515 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 RenameColumnScripts = []ScriptTest{ { Name: "error cases", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable RENAME COLUMN i2 TO iX", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE mytable RENAME COLUMN i TO iX, RENAME COLUMN iX TO i2", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE mytable RENAME COLUMN i TO iX, RENAME COLUMN i TO i2", ExpectedErr: sql.ErrTableColumnNotFound, }, { Query: "ALTER TABLE mytable RENAME COLUMN i TO S", ExpectedErr: sql.ErrColumnExists, }, { Query: "ALTER TABLE mytable RENAME COLUMN i TO n, RENAME COLUMN s TO N", ExpectedErr: sql.ErrColumnExists, }, }, }, { Name: "simple rename column", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable RENAME COLUMN i TO i2, RENAME COLUMN s TO s2", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SHOW FULL COLUMNS FROM mytable", Expected: []sql.Row{ {"i2", "bigint", nil, "NO", "PRI", nil, "", "", ""}, {"s2", "varchar(20)", "utf8mb4_0900_bin", "NO", "UNI", nil, "", "", "column s"}, }, }, { Query: "select * from mytable order by i2 limit 1", Expected: []sql.Row{ {1, "first row"}, }, }, }, }, { Name: "rename column preserves table checks", SetUpScript: []string{ "ALTER TABLE mytable ADD CONSTRAINT test_check CHECK (i2 < 12345)", }, Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE mytable RENAME COLUMN i2 TO i3", ExpectedErr: sql.ErrCheckConstraintInvalidatedByColumnAlter, }, { Query: "ALTER TABLE mytable RENAME COLUMN s2 TO s3", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { 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 = 'mytable' AND TC.TABLE_SCHEMA = CC.CONSTRAINT_SCHEMA AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME AND TC.CONSTRAINT_TYPE = 'CHECK';`, Expected: []sql.Row{{"test_check", "(i2 < 12345)", "YES"}}, }, }, }, }
var RenameTableScripts = []ScriptTest{ { Name: "simple rename table", Assertions: []ScriptTestAssertion{ { Query: "RENAME TABLE mytable TO newTableName", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT COUNT(*) FROM mytable", ExpectedErr: sql.ErrTableNotFound, }, { Query: "SELECT COUNT(*) FROM newTableName", Expected: []sql.Row{{3}}, }, }, }, { Name: "rename multiple tables in one stmt", Assertions: []ScriptTestAssertion{ { Query: "RENAME TABLE othertable to othertable2, newTableName to mytable", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "SELECT COUNT(*) FROM othertable", ExpectedErr: sql.ErrTableNotFound, }, { Query: "SELECT COUNT(*) FROM newTableName", ExpectedErr: sql.ErrTableNotFound, }, { Query: "SELECT COUNT(*) FROM mytable", Expected: []sql.Row{{3}}, }, { Query: "SELECT COUNT(*) FROM othertable2", Expected: []sql.Row{{3}}, }, }, }, { Name: "error cases", Assertions: []ScriptTestAssertion{ { Query: "ALTER TABLE not_exist RENAME foo", ExpectedErr: sql.ErrTableNotFound, }, { Query: "ALTER TABLE emptytable RENAME niltable", ExpectedErr: sql.ErrTableAlreadyExists, }, }, }, }
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"), "v1", "v2", }}, }, { 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"), "v1", "v2", }}, }, { SkipServerEngine: true, 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(""), "", "", }}, }, { SkipServerEngine: true, 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(""), "", "", }}, }, { 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 RowLimitTests = []ScriptTest{ { Name: "row length limit", Assertions: []ScriptTestAssertion{ { Query: `create table two_col (pk smallint primary key, c1 VARCHAR(32700) NOT NULL, c2 VARCHAR(32700) NOT NULL) CHARACTER SET latin1;`, }, { Query: fmt.Sprintf("insert into two_col values (0, '%s', '%s')", longChar, longChar), }, { Query: "create table one_col (id int primary key, c1 VARCHAR(65486) NOT NULL) CHARACTER SET latin1;", }, { Query: fmt.Sprintf("insert into one_col values (0, '%s')", longChar), }, { Query: ` CREATE TABLE one_ref ( id smallint primary key, a VARCHAR(10000), b VARCHAR(10000), c VARCHAR(10000), d VARCHAR(10000), e VARCHAR(10000), f VARCHAR(10000), i TEXT ) character set latin1;`, }, { Query: fmt.Sprintf("insert into one_ref values (0,'%s', '%s','%s', '%s','%s', '%s','%s')", longChar[:10000], longChar[:10000], longChar[:10000], longChar[:10000], longChar[:10000], longChar[:10000], longChar[:6000]), }, }, }, { Name: "row length limit errors", SetUpScript: []string{ "create table t (id smallint primary key, a VARCHAR(5000), b VARCHAR(5000), c VARCHAR(5000))", }, Assertions: []ScriptTestAssertion{ { Query: "alter table t add column d VARCHAR(5000)", ExpectedErr: analyzererrors.ErrInvalidRowLength, }, { Query: "alter table t modify column c VARCHAR(7000)", ExpectedErr: analyzererrors.ErrInvalidRowLength, }, { Query: fmt.Sprintf("insert into t values (1, '%s', 'a', 'a')", longChar), ExpectedErr: types.ErrLengthBeyondLimit, }, { Query: "create table t1 (c1 VARCHAR(16883) NOT NULL)", ExpectedErr: analyzererrors.ErrInvalidRowLength, }, { Query: "create table t1 (c1 VARCHAR(65536) NOT NULL) CHARACTER SET latin1;", ExpectedErr: types.ErrLengthTooLarge, }, { Query: ` CREATE TABLE one_ref ( id int primary key, a VARCHAR(10000), b VARCHAR(10000), c VARCHAR(10000), d VARCHAR(10000), e VARCHAR(10000), f VARCHAR(10000), i VARCHAR(6000) ) character set latin1;`, ExpectedErr: analyzererrors.ErrInvalidRowLength, }, }, }, }
var SQLLogicJoinTests = []ScriptTest{ { Name: "joining on different types panics", SetUpScript: []string{ "CREATE TABLE foo (a INT, b INT, c FLOAT, d FLOAT);", "INSERT INTO foo VALUES (1, 1, 1, 1), (2, 2, 2, 2), (3, 3, 3, 3);", "CREATE TABLE bar (a INT, b FLOAT, c FLOAT, d INT);", "INSERT INTO bar VALUES (1, 1, 1, 1), (2, 2, 2, 2), (3, 3, 3, 3);", }, Assertions: []ScriptTestAssertion{ { Skip: true, Query: "SELECT * FROM foo JOIN bar ON max(foo.c) < 2", ExpectedErrStr: "invalid use of group function", }, { Query: "SELECT * FROM foo NATURAL JOIN bar", Expected: []sql.Row{ {1, 1, 1.0, 1.0}, {2, 2, 2.0, 2.0}, {3, 3, 3.0, 3.0}, }, }, { Query: "SELECT * FROM foo JOIN bar USING (b);", Expected: []sql.Row{ {1, 1, 1.0, 1.0, 1, 1.0, 1}, {2, 2, 2.0, 2.0, 2, 2.0, 2}, {3, 3, 3.0, 3.0, 3, 3.0, 3}, }, }, { Query: "SELECT * FROM foo JOIN bar USING (a, b);", Expected: []sql.Row{ {1, 1, 1.0, 1.0, 1.0, 1}, {2, 2, 2.0, 2.0, 2.0, 2}, {3, 3, 3.0, 3.0, 3.0, 3}, }, }, { Query: "SELECT * FROM foo JOIN bar USING (a, b, c);", Expected: []sql.Row{ {1, 1, 1.0, 1.0, 1}, {2, 2, 2.0, 2.0, 2}, {3, 3, 3.0, 3.0, 3}, }, }, { Query: "SELECT * FROM foo JOIN bar ON foo.b = bar.b;", Expected: []sql.Row{ {1, 1, 1.0, 1.0, 1, 1.0, 1.0, 1}, {2, 2, 2.0, 2.0, 2, 2.0, 2.0, 2}, {3, 3, 3.0, 3.0, 3, 3.0, 3.0, 3}, }, }, { Query: "SELECT * FROM foo JOIN bar ON foo.a = bar.a AND foo.b = bar.b;", Expected: []sql.Row{ {1, 1, 1.0, 1.0, 1, 1.0, 1.0, 1}, {2, 2, 2.0, 2.0, 2, 2.0, 2.0, 2}, {3, 3, 3.0, 3.0, 3, 3.0, 3.0, 3}, }, }, { Query: "SELECT * FROM foo, bar WHERE foo.b = bar.b;", Expected: []sql.Row{ {1, 1, 1.0, 1.0, 1, 1.0, 1.0, 1}, {2, 2, 2.0, 2.0, 2, 2.0, 2.0, 2}, {3, 3, 3.0, 3.0, 3, 3.0, 3.0, 3}, }, }, { Query: "SELECT * FROM foo, bar WHERE foo.a = bar.a AND foo.b = bar.b;", Expected: []sql.Row{ {1, 1, 1.0, 1.0, 1, 1.0, 1.0, 1}, {2, 2, 2.0, 2.0, 2, 2.0, 2.0, 2}, {3, 3, 3.0, 3.0, 3, 3.0, 3.0, 3}, }, }, }, }, { Name: "case insensitive join with using clause", SetUpScript: []string{ "CREATE TABLE str1 (a INT PRIMARY KEY, s TEXT COLLATE utf8mb4_0900_ai_ci);", "INSERT INTO str1 VALUES (1, 'a' COLLATE utf8mb4_0900_ai_ci), (2, 'A' COLLATE utf8mb4_0900_ai_ci), (3, 'c' COLLATE utf8mb4_0900_ai_ci), (4, 'D' COLLATE utf8mb4_0900_ai_ci);", "CREATE TABLE str2 (a INT PRIMARY KEY, s TEXT COLLATE utf8mb4_0900_ai_ci);", "INSERT INTO str2 VALUES (1, 'A' COLLATE utf8mb4_0900_ai_ci), (2, 'B' COLLATE utf8mb4_0900_ai_ci), (3, 'C' COLLATE utf8mb4_0900_ai_ci), (4, 'E' COLLATE utf8mb4_0900_ai_ci);", }, Assertions: []ScriptTestAssertion{ { Skip: true, Query: "SELECT s, str1.s, str2.s FROM str1 INNER JOIN str2 USING(s);", Expected: []sql.Row{ {"A", "A", "A"}, {"a", "a", "A"}, {"c", "c", "C"}, }, }, { Query: "SELECT s, str1.s, str2.s FROM str1 LEFT OUTER JOIN str2 USING(s)", Expected: []sql.Row{ {"a", "a", "A"}, {"A", "A", "A"}, {"c", "c", "C"}, {"D", "D", nil}, }, }, { Query: "SELECT s, str1.s, str2.s FROM str1 RIGHT OUTER JOIN str2 USING(s)", Expected: []sql.Row{ {"A", "A", "A"}, {"A", "a", "A"}, {"B", nil, "B"}, {"C", "c", "C"}, {"E", nil, "E"}, }, }, }, }, { Name: "values and rows", SetUpScript: []string{ "CREATE TABLE xy (x INT PRIMARY KEY, y INT)", }, Assertions: []ScriptTestAssertion{ { Query: "INSERT INTO xy (VALUES ROW(1, 1))", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, }, }, { Name: "using join", SetUpScript: []string{ "CREATE TABLE abcd (a INT, b INT, c INT, d INT);", "INSERT INTO abcd VALUES (1, 1, 1, 1), (2, 2, 2, 2);", "CREATE TABLE dxby (d INT, x INT, b INT, y INT);", "INSERT INTO dxby VALUES (2, 2, 2, 2), (3, 3, 3, 3);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT abcd.*, dxby.* FROM abcd INNER JOIN dxby USING (d, b);", Expected: []sql.Row{ {2, 2, 2, 2, 2, 2, 2, 2}, }, }, }, }, }
SQLLogicJoinTests is a list of all the logic tests that are run against the sql engine.
var SQLLogicSubqueryTests = []ScriptTest{ { Name: "exists, in, all, any subquery", SetUpScript: []string{ "CREATE TABLE c (c_id INT PRIMARY KEY, bill TEXT);", "CREATE TABLE o (o_id INT PRIMARY KEY, c_id INT, ship TEXT);", "INSERT INTO c VALUES (1, 'CA'), (2, 'TX'), (3, 'MA'), (4, 'TX'), (5, NULL), (6, 'FL');", "INSERT INTO o VALUES (10, 1, 'CA'), (20, 1, 'CA'), (30, 1, 'CA'), (40, 2, 'CA'), (50, 2, 'TX'), (60, 2, NULL), (70, 4, 'WY'), (80, 4, NULL), (90, 6, 'WA');", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM c WHERE EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {4, "TX"}, {6, "FL"}, }, }, { Query: "SELECT * FROM c WHERE NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {3, "MA"}, {5, nil}, }, }, { Query: "SELECT * FROM c WHERE EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) OR NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {3, "MA"}, {4, "TX"}, {5, nil}, {6, "FL"}, }, }, { Query: "SELECT * FROM c WHERE EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND c.bill='TX');", Expected: []sql.Row{ {2, "TX"}, {4, "TX"}, }, }, { Query: "SELECT * FROM c WHERE 'WY' IN (SELECT ship FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {4, "TX"}, }, }, { Query: "SELECT * FROM c WHERE 'WY' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) OR 'WA' IN (SELECT ship FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {4, "TX"}, {6, "FL"}, }, }, { Query: "SELECT * FROM c WHERE 'CA' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) AND 'TX' NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {1, "CA"}, }, }, { Query: "SELECT * FROM c WHERE bill IN (SELECT ship FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {1, "CA"}, {3, "MA"}, {5, nil}, }, }, { Query: "SELECT * FROM c WHERE bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {3, "MA"}, {5, nil}, {6, "FL"}, }, }, { Query: "SELECT * FROM c WHERE bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL);", Expected: []sql.Row{ {3, "MA"}, {4, "TX"}, {5, nil}, {6, "FL"}, }, }, { Query: "SELECT * FROM c WHERE bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NULL);", Expected: []sql.Row{ {1, "CA"}, {3, "MA"}, {5, nil}, {6, "FL"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {4, "TX"}, {6, "FL"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE bill < SOME(SELECT ship FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {4, "TX"}, {6, "FL"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE (bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL;", Expected: []sql.Row{ {2, "TX"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE (bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL;", Expected: []sql.Row{ {1, "CA"}, {3, "MA"}, {4, "TX"}, {5, nil}, {6, "FL"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {2, "TX"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE (bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL;", Expected: []sql.Row{ {4, "TX"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE (bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL;", Expected: []sql.Row{ {1, "CA"}, {3, "MA"}, {4, "TX"}, {5, nil}, {6, "FL"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE bill = ANY(SELECT ship FROM o);", Expected: []sql.Row{ {1, "CA"}, {3, "MA"}, {4, "TX"}, {5, nil}, {6, "FL"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE bill = ANY(SELECT ship FROM o) OR bill IS NULL;", Expected: []sql.Row{ {1, "CA"}, {3, "MA"}, {4, "TX"}, {5, nil}, }, }, { Query: "SELECT * FROM c WHERE (NULL IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL;", Expected: []sql.Row{ {3, "MA"}, {5, nil}, }, }, { Query: "SELECT * FROM c WHERE (NULL NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL;", Expected: []sql.Row{ {3, "MA"}, {5, nil}, }, }, { Query: "SELECT * FROM c WHERE (replace(bill, 'TX', 'WY') IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL;", Expected: []sql.Row{ {2, "TX"}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id) OR EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND ship='WY');", Expected: []sql.Row{ {1, "CA"}, {3, "MA"}, {4, "TX"}, {5, nil}, }, }, { Skip: true, Query: "SELECT * FROM c WHERE bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id) AND EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {1, "CA"}, }, }, { Query: "SELECT * FROM c WHERE (SELECT count(*) FROM o WHERE o.c_id=c.c_id) > 1;", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {4, "TX"}, }, }, { Query: "SELECT * FROM c WHERE (SELECT count(ship) FROM o WHERE o.c_id=c.c_id) > 1;", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, }, }, { Query: "SELECT c.c_id, o.o_id, o.ship FROM c INNER JOIN o ON o.ship = (SELECT min(o.ship) FROM o WHERE o.c_id=c.c_id) ORDER BY c.c_id, o.o_id, o.ship;", Expected: []sql.Row{ {1, 10, "CA"}, {1, 20, "CA"}, {1, 30, "CA"}, {1, 40, "CA"}, {2, 10, "CA"}, {2, 20, "CA"}, {2, 30, "CA"}, {2, 40, "CA"}, {4, 70, "WY"}, {6, 90, "WA"}, }, }, { Query: "SELECT c.c_id, o.o_id, o.ship FROM c INNER JOIN o ON c.c_id=o.c_id AND o.ship = (SELECT min(o.ship) FROM o WHERE o.c_id=c.c_id) ORDER BY c.c_id, o.o_id, o.ship;", Expected: []sql.Row{ {1, 10, "CA"}, {1, 20, "CA"}, {1, 30, "CA"}, {2, 40, "CA"}, {4, 70, "WY"}, {6, 90, "WA"}, }, }, { Query: "SELECT c.c_id, o.ship, count(*) FROM c INNER JOIN o ON c.c_id=o.c_id WHERE (SELECT count(*) FROM o AS o2 WHERE o2.ship = o.ship AND o2.c_id = o.c_id) > (SELECT count(*) FROM o AS o2 WHERE o2.ship = o.ship AND o2.c_id <> o.c_id) GROUP BY c.c_id, o.ship;", Expected: []sql.Row{ {1, "CA", 3}, {2, "TX", 1}, {4, "WY", 1}, {6, "WA", 1}, }, }, { Query: "SELECT * FROM c WHERE (SELECT count(*) FROM o WHERE o.c_id=c.c_id) > 1 AND (SELECT max(ship) FROM o WHERE o.c_id=c.c_id) = 'CA';", Expected: []sql.Row{ {1, "CA"}, }, }, { Query: "SELECT * FROM c WHERE (SELECT count(*) FROM o WHERE o.c_id=c.c_id) > 1 OR EXISTS(SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NULL);", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {4, "TX"}, }, }, { Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM c WHERE bill=(SELECT max(ship) FROM o WHERE c_id=c2.c_id AND c_id=c.c_id));", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, }, }, { Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM c WHERE bill=(SELECT min(ship) FROM o WHERE c_id=c2.c_id AND c_id=c.c_id));", Expected: []sql.Row{ {1, "CA"}, }, }, { Skip: true, Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM c WHERE bill=(SELECT coalesce(min(ship), bill) FROM o WHERE c_id=c2.c_id AND c_id=c.c_id));", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {3, "MA"}, {4, "TX"}, {5, nil}, {6, "FL"}, }, }, { Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM (SELECT c_id, coalesce(ship, bill) AS state FROM o WHERE c_id=c2.c_id) AS o WHERE state=bill);", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {4, "TX"}, }, }, { Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM (SELECT c_id, coalesce(ship, bill) AS state FROM o) AS o WHERE c_id = c2.c_id AND state = bill);", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {4, "TX"}, }, }, { Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM (SELECT c_id, ship AS state FROM o) AS o WHERE c_id = c2.c_id AND coalesce(state, bill) = bill);", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {4, "TX"}, }, }, { Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT c_id, ship FROM o WHERE c_id = c2.c_id AND coalesce(ship, bill) = bill);", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {4, "TX"}, }, }, { Query: "SELECT c_id, bill FROM c AS c2 WHERE EXISTS(SELECT * FROM (SELECT c_id, ship AS state FROM o) AS o WHERE c_id = c2.c_id AND coalesce(state, bill) = bill);", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {4, "TX"}, }, }, { Query: "SELECT * FROM c WHERE (SELECT ship FROM o WHERE o.c_id=c.c_id ORDER BY ship LIMIT 1) IS NOT NULL", Expected: []sql.Row{ {1, "CA"}, {6, "FL"}, }, }, { Query: "SELECT * FROM c WHERE (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL ORDER BY ship LIMIT 1)='CA' OR (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL ORDER BY ship LIMIT 1)='WY' ORDER BY c_id", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {4, "TX"}, }, }, { Query: "SELECT * FROM c WHERE (SELECT o_id FROM o WHERE o.c_id=c.c_id AND ship='WY')=4;", Expected: []sql.Row{}, }, { Query: "SELECT * FROM c WHERE c_id=(SELECT c_id FROM o WHERE ship='CA' AND c_id<>1 AND bill='TX');", Expected: []sql.Row{ {2, "TX"}, }, }, { Query: "SELECT * FROM c WHERE c_id=(SELECT c_id FROM o WHERE ship='WA' AND bill='FL')", Expected: []sql.Row{ {6, "FL"}, }, }, { Query: "SELECT * FROM c WHERE (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL AND (SELECT count(*) FROM o WHERE o.c_id=c.c_id)<=1)='WA';", Expected: []sql.Row{ {6, "FL"}, }, }, { Query: "SELECT c_id, EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, true}, {3, false}, {4, true}, {5, false}, {6, true}, }, }, { Query: "SELECT c_id, NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, false}, {3, true}, {4, false}, {5, true}, {6, false}, }, }, { Query: "SELECT c_id, EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) OR NOT EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, true}, {3, true}, {4, true}, {5, true}, {6, true}, }, }, { Query: "SELECT c_id, EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND c.bill='TX') FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, true}, {3, false}, {4, true}, {5, false}, {6, false}, }, }, { Query: "SELECT c_id, 'WY' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, nil}, {3, false}, {4, true}, {5, false}, {6, false}, }, }, { Query: "SELECT c_id, 'WY' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) OR 'WA' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, nil}, {3, false}, {4, true}, {5, false}, {6, true}, }, }, { Query: "SELECT c_id, 'CA' IN (SELECT ship FROM o WHERE o.c_id=c.c_id) AND 'TX' NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, false}, {3, false}, {4, nil}, {5, false}, {6, false}, }, }, { Query: "SELECT c_id, bill IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, true}, {3, false}, {4, nil}, {5, false}, {6, false}, }, }, { Skip: true, Query: "SELECT c_id, bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, 1}, {2, 0}, {3, 1}, {4, 0}, {5, true}, {6, 0}, }, }, { Query: "SELECT c_id, bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, false}, {3, true}, {4, nil}, {5, true}, {6, true}, }, }, { Query: "SELECT c_id, bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, false}, {3, true}, {4, true}, {5, true}, {6, true}, }, }, { Query: "SELECT c_id, bill NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NULL) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, nil}, {3, true}, {4, nil}, {5, true}, {6, true}, }, }, { Skip: true, Query: "SELECT c_id, bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, nil}, {3, false}, {4, true}, {5, false}, {6, true}, }, }, { Skip: true, Query: "SELECT c_id, (bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, true}, {3, false}, {4, false}, {5, false}, {6, false}, }, }, { Skip: true, Query: "SELECT c_id, (bill < ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, false}, {3, true}, {4, true}, {5, true}, {6, true}, }, }, { Skip: true, Query: "SELECT c_id, bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, true}, {3, false}, {4, nil}, {5, false}, {6, false}, }, }, { Skip: true, Query: "SELECT c_id, (bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, false}, {3, false}, {4, true}, {5, false}, {6, false}, }, }, { Skip: true, Query: "SELECT c_id, (bill > ANY(SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, true}, {3, true}, {4, false}, {5, true}, {6, true}, }, }, { Skip: true, Query: "SELECT c_id, bill = ANY(SELECT ship FROM o WHERE ship IS NOT NULL) FROM c;", Expected: []sql.Row{ {1, true}, {2, true}, {3, false}, {4, true}, {5, nil}, {6, false}, }, }, { Skip: true, Query: "SELECT c_id, bill = ANY(SELECT ship FROM o WHERE ship IS NOT NULL) OR bill IS NULL FROM c;", Expected: []sql.Row{ {1, true}, {2, true}, {3, false}, {4, true}, {5, true}, {6, false}, }, }, { Query: "SELECT c_id, (NULL IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, false}, {3, true}, {4, false}, {5, true}, {6, false}, }, }, { Query: "SELECT c_id, (NULL NOT IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NOT NULL FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, false}, {3, true}, {4, false}, {5, true}, {6, false}, }, }, { Query: "SELECT c_id, (replace(bill, 'TX', 'WY') IN (SELECT ship FROM o WHERE o.c_id=c.c_id)) IS NULL FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, false}, {2, true}, {3, false}, {4, false}, {5, false}, {6, false}, }, }, { Skip: true, Query: "SELECT c_id, bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id) OR EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND ship='WY') FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, false}, {3, true}, {4, true}, {5, true}, {6, false}, }, }, { Skip: true, Query: "SELECT c_id, bill = ALL(SELECT ship FROM o WHERE o.c_id=c.c_id) AND EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, false}, {3, false}, {4, false}, {5, false}, {6, false}, }, }, { Query: "SELECT * FROM c WHERE (SELECT min(ship) FROM o WHERE o.c_id=c.c_id) IN (SELECT ship FROM o WHERE o.c_id=c.c_id);", Expected: []sql.Row{ {1, "CA"}, {2, "TX"}, {4, "TX"}, {6, "FL"}, }, }, { Query: "SELECT c_id, (SELECT min(ship) FROM o WHERE o.c_id=c.c_id) IN (SELECT ship FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, true}, {3, false}, {4, true}, {5, false}, {6, true}, }, }, { Query: "SELECT max((SELECT count(*) FROM o WHERE o.c_id=c.c_id)) FROM c;", Expected: []sql.Row{ {3}, }, }, { Query: "SELECT c_id, (SELECT count(*) FROM o WHERE o.c_id=c.c_id) FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, 3}, {2, 3}, {3, 0}, {4, 2}, {5, 0}, {6, 1}, }, }, { Query: "SELECT s.st, (SELECT count(*) FROM c WHERE c.bill=s.st) + (SELECT count(*) FROM o WHERE o.ship=s.st) FROM (SELECT c.bill AS st FROM c UNION SELECT o.ship AS st FROM o) s ORDER BY s.st;", Expected: []sql.Row{ {nil, 0}, {"CA", 5}, {"FL", 1}, {"MA", 1}, {"TX", 3}, {"WA", 1}, {"WY", 1}, }, }, { Query: "SELECT c.c_id, o.ship, count(*) AS cust, (SELECT count(*) FROM o AS o2 WHERE o2.ship = o.ship AND o2.c_id <> c.c_id) AS other FROM c INNER JOIN o ON c.c_id=o.c_id GROUP BY c.c_id, o.ship;", Expected: []sql.Row{ {1, "CA", 3, 1}, {2, "CA", 1, 3}, {2, "TX", 1, 0}, {2, nil, 1, 0}, {4, "WY", 1, 0}, {4, nil, 1, 0}, {6, "WA", 1, 0}, }, }, { Query: "SELECT c.c_id, o.o_id, (SELECT max(CASE WHEN c2.bill > o2.ship THEN c2.bill ELSE o2.ship END) FROM c AS c2, o AS o2 WHERE c2.c_id=o2.c_id AND c2.c_id=c.c_id) FROM c LEFT JOIN o ON c.c_id=o.c_id ORDER BY c.c_id, o.o_id;", Expected: []sql.Row{ {1, 10, "CA"}, {1, 20, "CA"}, {1, 30, "CA"}, {2, 40, "TX"}, {2, 50, "TX"}, {2, 60, "TX"}, {3, nil, nil}, {4, 70, "WY"}, {4, 80, "WY"}, {5, nil, nil}, {6, 90, "WA"}, }, }, { Query: "SELECT c.c_id, (SELECT ship FROM o WHERE o.c_id=c.c_id ORDER BY ship LIMIT 1) IS NOT NULL FROM c ORDER BY c.c_id;", Expected: []sql.Row{ {1, true}, {2, false}, {3, false}, {4, false}, {5, false}, {6, true}, }, }, { Query: "SELECT c.c_id, (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL ORDER BY ship LIMIT 1)='CA' OR (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL ORDER BY ship LIMIT 1)='WY' FROM c ORDER BY c_id;", Expected: []sql.Row{ {1, true}, {2, true}, {3, nil}, {4, true}, {5, nil}, {6, false}, }, }, { Skip: true, Query: "SELECT * FROM (SELECT c_id AS c_c_id, bill FROM c) sq1, LATERAL (SELECT row_number() OVER () AS rownum FROM o WHERE c_id = c_c_id) sq2 ORDER BY c_c_id, bill, rownum;", Expected: []sql.Row{ {1, "CA", 1}, {1, "CA", 2}, {1, "CA", 3}, {2, "TX", 1}, {2, "TX", 2}, {2, "TX", 3}, {4, "TX", 1}, {4, "TX", 2}, {6, "FL", 1}, }, }, { Query: "SELECT * FROM (SELECT bill FROM c) sq1, LATERAL (SELECT row_number() OVER (PARTITION BY bill) AS rownum FROM o WHERE ship = bill) sq2 ORDER BY bill, rownum;", Expected: []sql.Row{ {"CA", 1}, {"CA", 2}, {"CA", 3}, {"CA", 4}, {"TX", 1}, {"TX", 1}, }, }, { Skip: true, Query: "SELECT (SELECT count(*) FROM o WHERE o.c_id=c.c_id) AS order_cnt, count(*) AS cust_cnt FROM c GROUP BY (SELECT count(*) FROM o WHERE o.c_id=c.c_id) ORDER BY (SELECT count(*) FROM o WHERE o.c_id=c.c_id) DESC;", Expected: []sql.Row{ {3, 2}, {2, 1}, {1, 1}, {0, 2}, }, }, { Query: "SELECT c_cnt, o_cnt, c_cnt + o_cnt AS total FROM (VALUES ROW((SELECT count(*) FROM c), (SELECT count(*) FROM o))) AS v(c_cnt, o_cnt) WHERE c_cnt > 0 AND o_cnt > 0;", Expected: []sql.Row{ {6, 9, 15}, }, }, { Query: "SELECT c.c_id, o.o_id FROM c INNER JOIN o ON c.c_id=o.c_id AND EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND ship IS NULL);", Expected: []sql.Row{ {2, 40}, {2, 50}, {2, 60}, {4, 70}, {4, 80}, }, }, }, }, { Name: "multiple nested subquery again", SetUpScript: []string{ "CREATE TABLE IF NOT EXISTS t_48638 (`key` INT NOT NULL, `value` INTEGER NOT NULL, PRIMARY KEY (`key`, `value`));", "INSERT INTO t_48638 values (1, 4);", "INSERT INTO t_48638 values (4, 3);", "INSERT INTO t_48638 values (3, 2);", "INSERT INTO t_48638 values (4, 1);", "INSERT INTO t_48638 values (1, 2);", "INSERT INTO t_48638 values (6, 5);", "INSERT INTO t_48638 values (7, 8);", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * FROM t_48638 WHERE `key` IN (WITH v AS (SELECT level1.`value` AS `value`, level1.`key`AS level1, level2.`key` AS level2, level3.`key` AS level3 FROM t_48638 AS level2 RIGHT JOIN (SELECT * FROM t_48638 WHERE `value` = 4) AS level1 ON level1.`value` = level2.`key` LEFT JOIN (SELECT * FROM t_48638) AS level3 ON level3.`key` = level2.`value` ) SELECT v.level1 FROM v WHERE v.level1 IS NOT NULL UNION ALL SELECT v.level2 FROM v WHERE v.level2 IS NOT NULL UNION ALL SELECT v.level3 FROM v WHERE v.level3 IS NOT NULL);", Expected: []sql.Row{ {1, 2}, {1, 4}, {3, 2}, {4, 1}, {4, 3}, }, }, }, }, }
SQLLogicSubqueryTests is a list of all the logic tests that are run against the sql engine.
var ScriptTests = []ScriptTest{}/* 174 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: "ALTER USER can change passwords", Assertions: []ServerAuthenticationTestAssertion{ { Username: "root", Password: "", Query: "CREATE TABLE mydb.test (pk BIGINT PRIMARY KEY);", ExpectedErr: false, }, { Username: "root", Password: "", Query: "CREATE USER `createUserUser`@`localhost` IDENTIFIED BY '';", ExpectedErr: false, }, { Username: "root", Password: "", Query: "GRANT CREATE USER ON *.* TO `createUserUser`@`localhost`;", ExpectedErr: false, }, { Username: "root", Password: "", Query: "CREATE USER `updateUser`@`localhost` IDENTIFIED BY '';", ExpectedErr: false, }, { Username: "root", Password: "", Query: "GRANT UPDATE ON mysql.* TO `updateUser`@`localhost`;", ExpectedErr: false, }, { Username: "root", Password: "", Query: "CREATE USER `user1`@`localhost` IDENTIFIED BY '';", ExpectedErr: false, }, { Username: "root", Password: "", Query: "GRANT SELECT ON *.* TO `user1`@`localhost`;", ExpectedErr: false, }, { Username: "root", Password: "", Query: "CREATE USER `user2`@`localhost` IDENTIFIED BY '';", ExpectedErr: false, }, { Username: "root", Password: "", Query: "GRANT SELECT ON *.* TO `user2`@`localhost`;", ExpectedErr: false, }, { Username: "root", Password: "", Query: "ALTER USER IF EXISTS nobody@localhost IDENTIFIED BY 'password';", ExpectedErr: false, }, { Username: "root", Password: "", Query: "ALTER USER nobody@localhost IDENTIFIED BY 'password';", ExpectedErr: true, ExpectedErrStr: "Error 1105 (HY000): Operation ALTER USER failed for 'nobody'@'localhost'", }, { Username: "root", Password: "", Query: "ALTER USER user2@localhost IDENTIFIED BY RANDOM PASSWORD;", ExpectedErr: true, ExpectedErrStr: "Error 1105 (HY000): random password generation is not currently supported; " + "you can request support at https://github.com/dolthub/dolt/issues/new", }, { Username: "root", Password: "", Query: "ALTER USER `user1`@`localhost` IDENTIFIED BY 'password1';", ExpectedErr: false, }, { Username: "user1", Password: "", Query: "SELECT * FROM mydb.test;", ExpectedErr: true, }, { Username: "user1", Password: "password1", Query: "SELECT * FROM mydb.test;", ExpectedErr: false, }, { Username: "createUserUser", Password: "", Query: "ALTER USER `user1`@`localhost` IDENTIFIED BY 'password2';", ExpectedErr: false, }, { Username: "user1", Password: "", Query: "SELECT * FROM mydb.test;", ExpectedErr: true, }, { Username: "user1", Password: "password2", Query: "SELECT * FROM mydb.test;", ExpectedErr: false, }, { Username: "updateUser", Password: "", Query: "ALTER USER `user2`@`localhost` IDENTIFIED BY 'password3';", ExpectedErr: false, }, { Username: "user2", Password: "", Query: "SELECT * FROM mydb.test;", ExpectedErr: true, }, { Username: "user2", Password: "password3", Query: "SELECT * FROM mydb.test;", ExpectedErr: false, }, { Username: "user1", Password: "password2", Query: "ALTER USER `user1`@`localhost` IDENTIFIED BY 'password4';", ExpectedErr: false, }, { Username: "user1", Password: "", Query: "SELECT * FROM mydb.test;", ExpectedErr: true, }, { Username: "user1", Password: "password4", Query: "SELECT * FROM mydb.test;", ExpectedErr: false, }, { Username: "user1", Password: "password2", Query: "ALTER USER `user2`@`localhost` IDENTIFIED BY 'password5';", ExpectedErr: true, }, }, }, { Name: "DROP USER reports correct string for missing address", Assertions: []ServerAuthenticationTestAssertion{ { Username: "root", Password: "", Query: "DROP USER xyz;", ExpectedErrStr: "Error 1105 (HY000): Operation DROP USER failed for 'xyz'@'%'", }, }, }, { Name: "CREATE USER with a random password is not supported", Assertions: []ServerAuthenticationTestAssertion{ { Username: "root", Password: "", Query: "CREATE USER foo1@localhost IDENTIFIED BY RANDOM PASSWORD;", ExpectedErr: true, ExpectedErrStr: "Error 1105 (HY000): random password generation is not currently supported; " + "you can request support at https://github.com/dolthub/dolt/issues/new", }, }, }, { 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;", ExpectedAuthPlugin: "mysql_native_password", }, { 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 explicitly with mysql_native_password plugin", 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;", ExpectedAuthPlugin: "mysql_native_password", }, { Username: "ranuse", Password: "what", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, { Username: "ranuse", Password: "", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, }, }, }, { Name: "Create User explicitly with caching_sha2_password plugin", SetUpScript: []string{ "CREATE USER testuser1@localhost IDENTIFIED WITH caching_sha2_password BY 'mypassword3';", "GRANT ALL ON *.* TO testuser1@localhost WITH GRANT OPTION;", "CREATE USER testuser2@localhost IDENTIFIED WITH caching_sha2_password;", "GRANT ALL ON *.* TO testuser2@localhost WITH GRANT OPTION;", }, Assertions: []ServerAuthenticationTestAssertion{ { Username: "testuser1", Password: "mypassword3", Query: "SELECT * FROM mysql.user;", ExpectedAuthPlugin: "caching_sha2_password", }, { Username: "testuser1", Password: "what", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, ExpectedErrStr: "Error 1045 (28000): Access denied for user 'testuser1'", }, { Username: "testuser1", Password: "", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, ExpectedErrStr: "Error 1045 (28000): Access denied for user 'testuser1'", }, { Username: "testuser2", Password: "wrong", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, ExpectedErrStr: "Error 1045 (28000): Access denied for user 'testuser2'", }, { Username: "testuser2", Password: "", Query: "SELECT * FROM mysql.user;", ExpectedErr: false, ExpectedAuthPlugin: "caching_sha2_password", }, }, }, { Name: "Migrate user from mysql_native_password to caching_sha2_password", SetUpScript: []string{ "CREATE USER testuser1@localhost IDENTIFIED WITH mysql_native_password BY 'mypassword3';", "GRANT ALL ON *.* TO testuser1@localhost WITH GRANT OPTION;", }, Assertions: []ServerAuthenticationTestAssertion{ { Username: "testuser1", Password: "mypassword3", Query: "SELECT * FROM mysql.user;", ExpectedAuthPlugin: "mysql_native_password", }, { Username: "root", Query: "ALTER USER testuser1@localhost IDENTIFIED WITH caching_sha2_password BY 'pass1';", }, { Username: "testuser1", Password: "pass1", Query: "SELECT * FROM mysql.user;", ExpectedAuthPlugin: "caching_sha2_password", }, { Username: "testuser1", Password: "wrong", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, ExpectedErrStr: "Error 1045 (28000): Access denied for user 'testuser1'", }, { Username: "root", Query: "ALTER USER testuser1@localhost IDENTIFIED WITH caching_sha2_password;", }, { Username: "testuser1", Password: "", Query: "SELECT * FROM mysql.user;", ExpectedAuthPlugin: "caching_sha2_password", }, { Username: "testuser1", Password: "wrong", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, ExpectedErrStr: "Error 1045 (28000): Access denied for user 'testuser1'", }, }, }, { 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.EngineAnalyzer().Catalog.MySQLDb.SetPlugins(plugins) }, Assertions: []ServerAuthenticationTestAssertion{ { Username: "test-user", Password: "what", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, ExpectedErrStr: "Error 1045 (28000): Access denied for user 'test-user'", }, { Username: "test-user", Password: "", Query: "SELECT * FROM mysql.user;", ExpectedErr: true, ExpectedErrStr: "Error 1045 (28000): Access denied for user 'test-user'", }, { Username: "test-user", Password: "right-password", Query: "SELECT * FROM mysql.user;", ExpectedAuthPlugin: "authentication_dolt_jwt", }, }, }, { Name: "Adding a Super User directly", SetUpFunc: func(ctx *sql.Context, t *testing.T, engine *sqle.Engine) { ed := engine.EngineAnalyzer().Catalog.MySQLDb.Editor() defer ed.Close() engine.EngineAnalyzer().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 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", nil, ""}, {"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", nil, ""}, {"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", nil, ""}, {"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", nil, ""}, {"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", nil, ""}, {"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", nil, ""}, {"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 bigint primary key)", "INSERT INTO t VALUES (1), (2), (3)", "ANALYZE TABLE t", }, Assertions: []ScriptTestAssertion{ { SkipResultCheckOnServerEngine: true, Query: "SELECT * FROM information_schema.column_statistics", Expected: []sql.Row{ {"mydb", "t", "i", stats.NewStatistic(3, 3, 0, 24, time.Now(), sql.NewStatQualifier("mydb", "", "t", "primary"), []string{"i"}, []sql.Type{types.Int64}, []sql.HistogramBucket{ stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{int64(1)}, nil, nil), stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{int64(2)}, nil, nil), stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{int64(3)}, nil, nil), }, sql.IndexClassDefault, nil), }, }, }, }, }, { Name: "analyze update/drop", SetUpScript: []string{ "CREATE TABLE t (i bigint primary key, j bigint, key(j))", "INSERT INTO t VALUES (1, 4), (2, 5), (3, 6)", }, Assertions: []ScriptTestAssertion{ { Query: "analyze table t update histogram on (i) using data '{\"row_count\": 40, \"distinct_count\": 40, \"null_count\": 1, \"buckets\": [{\"row_count\": 20, \"distinct_count\": 20, \"upper_bound\": [50], \"bound_count\": 1}, {\"row_count\": 20, \"distinct_count\": 20, \"upper_bound\": [80], \"bound_count\": 1}]}'", Expected: []sql.Row{{"t", "histogram", "status", "OK"}}, }, { SkipResultCheckOnServerEngine: true, Query: "SELECT * FROM information_schema.column_statistics", Expected: []sql.Row{ {"mydb", "t", "i", stats.NewStatistic(40, 40, 1, 0, time.Now(), sql.NewStatQualifier("mydb", "", "t", "primary"), []string{"i"}, []sql.Type{types.Int64}, []sql.HistogramBucket{ stats.NewHistogramBucket(20, 20, 0, 1, sql.Row{float64(50)}, nil, nil), stats.NewHistogramBucket(20, 20, 0, 1, sql.Row{float64(80)}, nil, nil), }, sql.IndexClassDefault, nil), }, }, }, { Query: "analyze table t drop histogram on (i)", Expected: []sql.Row{{"t", "histogram", "status", "OK"}}, }, { Query: "SELECT * FROM information_schema.column_statistics", Expected: []sql.Row{}, }, }, }, { Name: "analyze two int columns", SetUpScript: []string{ "CREATE TABLE t (i bigint primary key, j bigint, key(j))", "INSERT INTO t VALUES (1, 4), (2, 5), (3, 6)", "ANALYZE TABLE t", }, Assertions: []ScriptTestAssertion{ { SkipResultCheckOnServerEngine: true, Query: "SELECT * FROM information_schema.column_statistics", Expected: []sql.Row{ {"mydb", "t", "i", stats.NewStatistic(3, 3, 0, 48, time.Now(), sql.NewStatQualifier("mydb", "", "t", "primary"), []string{"i"}, []sql.Type{types.Int64}, []sql.HistogramBucket{ stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{int64(1)}, nil, []sql.Row{}), stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{int64(2)}, nil, []sql.Row{}), stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{int64(3)}, nil, []sql.Row{}), }, sql.IndexClassDefault, nil), }, {"mydb", "t", "j", stats.NewStatistic(3, 3, 0, 48, time.Now(), sql.NewStatQualifier("mydb", "", "t", "j"), []string{"j"}, []sql.Type{types.Int64}, []sql.HistogramBucket{ stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{int64(4)}, nil, []sql.Row{}), stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{int64(5)}, nil, []sql.Row{}), stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{int64(6)}, nil, []sql.Row{}), }, sql.IndexClassDefault, nil), }, }, }, }, }, { Name: "analyze float columns", SetUpScript: []string{ "CREATE TABLE t (i double primary key)", "INSERT INTO t VALUES (1.25), (45.25), (7.5), (10.5)", "ANALYZE TABLE t", }, Assertions: []ScriptTestAssertion{ { SkipResultCheckOnServerEngine: true, Query: "SELECT * FROM information_schema.column_statistics", Expected: []sql.Row{ {"mydb", "t", "i", stats.NewStatistic(4, 4, 0, 32, time.Now(), sql.NewStatQualifier("mydb", "", "t", "primary"), []string{"i"}, []sql.Type{types.Float64}, []sql.HistogramBucket{ stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{float64(1.25)}, nil, []sql.Row{}), stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{float64(7.5)}, nil, []sql.Row{}), stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{float64(10.5)}, nil, []sql.Row{}), stats.NewHistogramBucket(1, 1, 0, 1, sql.Row{float64(45.25)}, nil, []sql.Row{}), }, sql.IndexClassDefault, nil), }, }, }, }, }, { 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{}, }, }, }, { 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 StatsIndexTests = []ScriptTest{ { Name: "choose range over full prefix match", SetUpScript: []string{ "create table xy (x int, y int, z varchar(36) default(uuid()), w varchar(10), key (z), key (y,w), key(x,y))", "insert into xy (x,y,w) values (1, 1, 'a'), (2,1,'a'), (3,1,'b'),(4,2,'b'),(5,2,'c')", ` analyze table xy update histogram on (x,y) using data '{ "qualifier": { "database": "mydb", "table": "xy", "index": "xy" }, "types:":["bigint","bigint"], "columns":["x", "y"], "buckets": [ {"upper_bound": [1,1], "row_count": 1}, {"upper_bound": [2,1], "row_count": 1}, {"upper_bound": [3,1], "row_count": 1}, {"upper_bound": [4,2], "row_count": 1}, {"upper_bound": [5,2], "row_count": 1} ] }'`, `analyze table xy update histogram on (y,w) using data ' { "qualifier": { "database": "mydb", "table": "xy", "index": "yw" }, "types:":["bigint","varchar(10)"], "columns":["y", "w"], "buckets":[ {"upper_bound": [1,"a"], "row_count": 2}, {"upper_bound": [1,"b"], "row_count": 1}, {"upper_bound": [2,"b"], "row_count": 1}, {"upper_bound": [2,"c"], "row_count": 1} ] }'`, `analyze table xy update histogram on (z) using data ' { "qualifier": { "database": "mydb", "table": "xy", "index": "z" }, "types:":["varchar(36)"], "columns":["z"], "buckets":[ {"upper_bound": ["1"], "row_count": 1}, {"upper_bound": ["2"], "row_count": 1}, {"upper_bound": ["3"], "row_count": 1}, {"upper_bound": ["4"], "row_count": 1}, {"upper_bound": ["5"], "row_count": 1} ] }'`, }, Assertions: []ScriptTestAssertion{ { Query: "select * from xy where x > 4 and y = 1 and w = 'a'", Expected: []sql.Row{}, ExpectedIndexes: []string{"y"}, }, }, }, }
var SysbenchPlanTests = []QueryPlanTest{
{
Query: `select a.id, a.small_int_col from sbtest1 a, sbtest1 b where a.id = b.id limit 500`,
ExpectedPlan: "Limit(500)\n" +
" └─ Project\n" +
" ├─ columns: [a.id:0!null, a.small_int_col:1!null]\n" +
" └─ MergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ a.id:0!null\n" +
" │ └─ b.id:2!null\n" +
" ├─ TableAlias(a)\n" +
" │ └─ IndexedTableAccess(sbtest1)\n" +
" │ ├─ index: [sbtest1.id]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (1-24)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: sbtest1\n" +
" │ └─ columns: [id small_int_col]\n" +
" └─ TableAlias(b)\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.id]\n" +
" ├─ static: [{[NULL, ∞)}]\n" +
" ├─ colSet: (25-48)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: sbtest1\n" +
" └─ columns: [id]\n" +
"",
ExpectedEstimates: "Limit(500)\n" +
" └─ Project\n" +
" ├─ columns: [a.id, a.small_int_col]\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (a.id = b.id)\n" +
" ├─ TableAlias(a)\n" +
" │ └─ IndexedTableAccess(sbtest1)\n" +
" │ ├─ index: [sbtest1.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id small_int_col]\n" +
" └─ TableAlias(b)\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id]\n" +
"",
ExpectedAnalysis: "Limit(500)\n" +
" └─ Project\n" +
" ├─ columns: [a.id, a.small_int_col]\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (a.id = b.id)\n" +
" ├─ TableAlias(a)\n" +
" │ └─ IndexedTableAccess(sbtest1)\n" +
" │ ├─ index: [sbtest1.id]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [id small_int_col]\n" +
" └─ TableAlias(b)\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.id]\n" +
" ├─ filters: [{[NULL, ∞)}]\n" +
" └─ columns: [id]\n" +
"",
},
{
Query: `select a.id, a.small_int_col, b.id, b.int_col from sbtest1 a, sbtest2 b where a.id = b.int_col limit 500`,
ExpectedPlan: "Limit(500)\n" +
" └─ Project\n" +
" ├─ columns: [a.id:2!null, a.small_int_col:3!null, b.id:0!null, b.int_col:1!null]\n" +
" └─ LookupJoin\n" +
" ├─ TableAlias(b)\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: sbtest2\n" +
" │ └─ columns: [id int_col]\n" +
" └─ TableAlias(a)\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.id]\n" +
" ├─ keys: [b.int_col:1!null]\n" +
" ├─ colSet: (1-24)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: sbtest1\n" +
" └─ columns: [id small_int_col]\n" +
"",
ExpectedEstimates: "Limit(500)\n" +
" └─ Project\n" +
" ├─ columns: [a.id, a.small_int_col, b.id, b.int_col]\n" +
" └─ LookupJoin\n" +
" ├─ TableAlias(b)\n" +
" │ └─ Table\n" +
" │ ├─ name: sbtest2\n" +
" │ └─ columns: [id int_col]\n" +
" └─ TableAlias(a)\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.id]\n" +
" ├─ columns: [id small_int_col]\n" +
" └─ keys: b.int_col\n" +
"",
ExpectedAnalysis: "Limit(500)\n" +
" └─ Project\n" +
" ├─ columns: [a.id, a.small_int_col, b.id, b.int_col]\n" +
" └─ LookupJoin\n" +
" ├─ TableAlias(b)\n" +
" │ └─ Table\n" +
" │ ├─ name: sbtest2\n" +
" │ └─ columns: [id int_col]\n" +
" └─ TableAlias(a)\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.id]\n" +
" ├─ columns: [id small_int_col]\n" +
" └─ keys: b.int_col\n" +
"",
},
{
Query: `SELECT year_col, count(year_col), max(big_int_col), avg(small_int_col) FROM sbtest1 WHERE big_int_col > 0 GROUP BY set_col ORDER BY year_col`,
ExpectedPlan: "Project\n" +
" ├─ columns: [sbtest1.year_col:3!null, count(sbtest1.year_col):1!null as count(year_col), max(sbtest1.big_int_col):2!null as max(big_int_col), avg(sbtest1.small_int_col):0 as avg(small_int_col)]\n" +
" └─ Sort(sbtest1.year_col:3!null ASC nullsFirst)\n" +
" └─ GroupBy\n" +
" ├─ select: AVG(sbtest1.small_int_col:0!null), COUNT(sbtest1.year_col:3!null), MAX(sbtest1.big_int_col:1!null), sbtest1.year_col:3!null\n" +
" ├─ group: sbtest1.set_col:2!null\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.big_int_col]\n" +
" ├─ static: [{(0, ∞)}]\n" +
" ├─ colSet: (1-24)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: sbtest1\n" +
" └─ columns: [small_int_col big_int_col set_col year_col]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [sbtest1.year_col, count(sbtest1.year_col) as count(year_col), max(sbtest1.big_int_col) as max(big_int_col), avg(sbtest1.small_int_col) as avg(small_int_col)]\n" +
" └─ Sort(sbtest1.year_col ASC)\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(AVG(sbtest1.small_int_col), COUNT(sbtest1.year_col), MAX(sbtest1.big_int_col), sbtest1.year_col)\n" +
" ├─ Grouping(sbtest1.set_col)\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.big_int_col]\n" +
" ├─ filters: [{(0, ∞)}]\n" +
" └─ columns: [small_int_col big_int_col set_col year_col]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [sbtest1.year_col, count(sbtest1.year_col) as count(year_col), max(sbtest1.big_int_col) as max(big_int_col), avg(sbtest1.small_int_col) as avg(small_int_col)]\n" +
" └─ Sort(sbtest1.year_col ASC)\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(AVG(sbtest1.small_int_col), COUNT(sbtest1.year_col), MAX(sbtest1.big_int_col), sbtest1.year_col)\n" +
" ├─ Grouping(sbtest1.set_col)\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.big_int_col]\n" +
" ├─ filters: [{(0, ∞)}]\n" +
" └─ columns: [small_int_col big_int_col set_col year_col]\n" +
"",
},
{
Query: `SELECT count(id) FROM sbtest1 WHERE big_int_col > 0`,
ExpectedPlan: "Project\n" +
" ├─ columns: [count(sbtest1.id):0!null as count(id)]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(sbtest1.id:0!null)\n" +
" ├─ group: \n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.big_int_col]\n" +
" ├─ static: [{(0, ∞)}]\n" +
" ├─ colSet: (1-24)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: sbtest1\n" +
" └─ columns: [id big_int_col]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [count(sbtest1.id) as count(id)]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(sbtest1.id))\n" +
" ├─ Grouping()\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.big_int_col]\n" +
" ├─ filters: [{(0, ∞)}]\n" +
" └─ columns: [id big_int_col]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [count(sbtest1.id) as count(id)]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(sbtest1.id))\n" +
" ├─ Grouping()\n" +
" └─ IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.big_int_col]\n" +
" ├─ filters: [{(0, ∞)}]\n" +
" └─ columns: [id big_int_col]\n" +
"",
},
{
Query: `SELECT * FROM sbtest1 WHERE big_int_col > 0`,
ExpectedPlan: "IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.big_int_col]\n" +
" ├─ static: [{(0, ∞)}]\n" +
" ├─ colSet: (1-24)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: sbtest1\n" +
" └─ columns: [id tiny_int_col unsigned_tiny_int_col small_int_col unsigned_small_int_col medium_int_col unsigned_medium_int_col int_col unsigned_int_col big_int_col unsigned_big_int_col decimal_col float_col double_col bit_col char_col var_char_col enum_col set_col date_col time_col datetime_col timestamp_col year_col]\n" +
"",
ExpectedEstimates: "IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.big_int_col]\n" +
" ├─ filters: [{(0, ∞)}]\n" +
" └─ columns: [id tiny_int_col unsigned_tiny_int_col small_int_col unsigned_small_int_col medium_int_col unsigned_medium_int_col int_col unsigned_int_col big_int_col unsigned_big_int_col decimal_col float_col double_col bit_col char_col var_char_col enum_col set_col date_col time_col datetime_col timestamp_col year_col]\n" +
"",
ExpectedAnalysis: "IndexedTableAccess(sbtest1)\n" +
" ├─ index: [sbtest1.big_int_col]\n" +
" ├─ filters: [{(0, ∞)}]\n" +
" └─ columns: [id tiny_int_col unsigned_tiny_int_col small_int_col unsigned_small_int_col medium_int_col unsigned_medium_int_col int_col unsigned_int_col big_int_col unsigned_big_int_col decimal_col float_col double_col bit_col char_col var_char_col enum_col set_col date_col time_col datetime_col timestamp_col year_col]\n" +
"",
},
}
var TableFunctionScriptTests = []ScriptTest{ { SetUpScript: []string{ "create database if not exists mydb", "use mydb", "create table xy (x int primary key, y int)", "insert into xy values (0,1), (1,2), (2,3)", }, Query: "select y from table_func('z',2) join xy t on y = z", Expected: []sql.Row{{2}}, }, { Query: "select * from sequence_table('y',2) seq1 where y in (select SEQ2.x from table_func('x', 1) seq2)", Expected: []sql.Row{{1}}, }, { 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.ErrTableColumnNotFound, }, { 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 /*+ MERGE_JOIN(seq1,seq2) JOIN_ORDER(seq2,seq1) */ 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 /*+ LOOKUP_JOIN(seq1,seq2) JOIN_ORDER(seq2,seq1) */ 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{"x"}, }, { Query: "select /*+ MERGE_JOIN(seq1,seq2) JOIN_ORDER(seq2,seq1) */ * 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: "select /*+ LOOKUP_JOIN(seq1,seq2) */ * 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}}, }, { Name: "sequence_table allows point lookups", Query: "select * from sequence_table('x', 5) where x = 2", Expected: []sql.Row{{2}}, ExpectedIndexes: []string{"x"}, }, { Name: "sequence_table allows range lookups", Query: "select * from sequence_table('x', 5) where x >= 1 and x <= 3", Expected: []sql.Row{{1}, {2}, {3}}, ExpectedIndexes: []string{"x"}, }, { Name: "basic behavior of point_lookup_table", Query: "select seq.x from point_lookup_table('x', 5) seq", Expected: []sql.Row{{0}, {1}, {2}, {3}, {4}}, }, { Name: "point_lookup_table allows point lookups", Query: "select * from point_lookup_table('x', 5) where x = 2", Expected: []sql.Row{{2}}, ExpectedIndexes: []string{"x"}, }, { Name: "point_lookup_table disallows range lookups", Query: "select * from point_lookup_table('x', 5) where x >= 1 and x <= 3", Expected: []sql.Row{{1}, {2}, {3}}, ExpectedIndexes: []string{}, }, { Name: "point_lookup_table disallows merge join", Query: "select /*+ MERGE_JOIN(l,r) */ * from point_lookup_table('x', 5) l join point_lookup_table('y', 5) r where x = y", Expected: []sql.Row{{0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}}, JoinTypes: []plan.JoinType{plan.JoinTypeLookup}, ExpectedIndexes: []string{"y"}, }, }
var TpccPlanTests = []QueryPlanTest{
{
Query: `
-- cycle 1a
SELECT c_discount, c_last, c_credit, w_tax FROM customer2, warehouse2 WHERE w_id = 1 AND c_w_id = w_id AND c_d_id = 9 AND c_id = 2151`,
ExpectedPlan: "Project\n" +
" ├─ columns: [customer2.c_discount:7, customer2.c_last:5, customer2.c_credit:6, warehouse2.w_tax:1]\n" +
" └─ LookupJoin\n" +
" ├─ IndexedTableAccess(warehouse2)\n" +
" │ ├─ index: [warehouse2.w_id]\n" +
" │ ├─ static: [{[1, 1]}]\n" +
" │ ├─ colSet: (22-30)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: warehouse2\n" +
" │ └─ columns: [w_id w_tax]\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ customer2.c_d_id:1!null\n" +
" │ │ └─ 9 (tinyint)\n" +
" │ └─ Eq\n" +
" │ ├─ customer2.c_id:0!null\n" +
" │ └─ 2151 (int)\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_id]\n" +
" ├─ keys: [warehouse2.w_id:0!null 9 (tinyint) 2151 (int)]\n" +
" ├─ colSet: (1-21)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: customer2\n" +
" └─ columns: [c_id c_d_id c_w_id c_last c_credit c_discount]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [customer2.c_discount, customer2.c_last, customer2.c_credit, warehouse2.w_tax]\n" +
" └─ LookupJoin (estimated cost=3.300 rows=1)\n" +
" ├─ IndexedTableAccess(warehouse2)\n" +
" │ ├─ index: [warehouse2.w_id]\n" +
" │ ├─ filters: [{[1, 1]}]\n" +
" │ └─ columns: [w_id w_tax]\n" +
" └─ Filter\n" +
" ├─ ((customer2.c_d_id = 9) AND (customer2.c_id = 2151))\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_id]\n" +
" ├─ columns: [c_id c_d_id c_w_id c_last c_credit c_discount]\n" +
" └─ keys: warehouse2.w_id, 9, 2151\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [customer2.c_discount, customer2.c_last, customer2.c_credit, warehouse2.w_tax]\n" +
" └─ LookupJoin (estimated cost=3.300 rows=1) (actual rows=0 loops=1)\n" +
" ├─ IndexedTableAccess(warehouse2)\n" +
" │ ├─ index: [warehouse2.w_id]\n" +
" │ ├─ filters: [{[1, 1]}]\n" +
" │ └─ columns: [w_id w_tax]\n" +
" └─ Filter\n" +
" ├─ ((customer2.c_d_id = 9) AND (customer2.c_id = 2151))\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_id]\n" +
" ├─ columns: [c_id c_d_id c_w_id c_last c_credit c_discount]\n" +
" └─ keys: warehouse2.w_id, 9, 2151\n" +
"",
},
{
Query: `SELECT d_next_o_id, d_tax FROM district2 WHERE d_w_id = 1 AND d_id = 9 FOR UPDATE`,
ExpectedPlan: "Project\n" +
" ├─ columns: [district2.d_next_o_id:3, district2.d_tax:2]\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ static: [{[1, 1], [9, 9]}]\n" +
" ├─ colSet: (1-11)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: district2\n" +
" └─ columns: [d_id d_w_id d_tax d_next_o_id]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [district2.d_next_o_id, district2.d_tax]\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ filters: [{[1, 1], [9, 9]}]\n" +
" └─ columns: [d_id d_w_id d_tax d_next_o_id]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [district2.d_next_o_id, district2.d_tax]\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ filters: [{[1, 1], [9, 9]}]\n" +
" └─ columns: [d_id d_w_id d_tax d_next_o_id]\n" +
"",
},
{
Query: `UPDATE district2 SET d_next_o_id = 3002 WHERE d_id = 9 AND d_w_id= 1`,
ExpectedPlan: "Update\n" +
" └─ UpdateSource(SET district2.d_next_o_id:10 = 3002 (smallint))\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ static: [{[1, 1], [9, 9]}]\n" +
" ├─ colSet: (1-11)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: district2\n" +
" └─ columns: [d_id d_w_id d_name d_street_1 d_street_2 d_city d_state d_zip d_tax d_ytd d_next_o_id]\n" +
"",
},
{
Query: `INSERT INTO orders2 (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local) VALUES (3001,9,1,2151,NOW(),12,1)`,
ExpectedPlan: "Insert(o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: orders2\n" +
" │ └─ columns: [o_id o_d_id o_w_id o_c_id o_entry_d o_carrier_id o_ol_cnt o_all_local]\n" +
" └─ Project\n" +
" ├─ columns: [o_id:0!null, o_d_id:1!null, o_w_id:2!null, o_c_id:3, o_entry_d:4, , o_ol_cnt:5, o_all_local:6]\n" +
" └─ Values([3001 (smallint),9 (tinyint),1 (tinyint),2151 (smallint),NOW(),12 (tinyint),1 (tinyint)])\n" +
"",
},
{
Query: `INSERT INTO new_orders2 (no_o_id, no_d_id, no_w_id) VALUES (3001,9,1)`,
ExpectedPlan: "Insert(no_o_id, no_d_id, no_w_id)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: new_orders2\n" +
" │ └─ columns: [no_o_id no_d_id no_w_id]\n" +
" └─ Project\n" +
" ├─ columns: [no_o_id:0!null, no_d_id:1!null, no_w_id:2!null]\n" +
" └─ Values([3001 (smallint),9 (tinyint),1 (tinyint)])\n" +
"",
},
{
Query: `SELECT i_price, i_name, i_data FROM item2 WHERE i_id = 2532`,
ExpectedPlan: "Project\n" +
" ├─ columns: [item2.i_price:2, item2.i_name:1, item2.i_data:3]\n" +
" └─ IndexedTableAccess(item2)\n" +
" ├─ index: [item2.i_id]\n" +
" ├─ static: [{[2532, 2532]}]\n" +
" ├─ colSet: (1-5)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: item2\n" +
" └─ columns: [i_id i_name i_price i_data]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [item2.i_price, item2.i_name, item2.i_data]\n" +
" └─ IndexedTableAccess(item2)\n" +
" ├─ index: [item2.i_id]\n" +
" ├─ filters: [{[2532, 2532]}]\n" +
" └─ columns: [i_id i_name i_price i_data]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [item2.i_price, item2.i_name, item2.i_data]\n" +
" └─ IndexedTableAccess(item2)\n" +
" ├─ index: [item2.i_id]\n" +
" ├─ filters: [{[2532, 2532]}]\n" +
" └─ columns: [i_id i_name i_price i_data]\n" +
"",
},
{
Query: `SELECT s_quantity, s_data, s_dist_09 s_dist FROM stock2 WHERE s_i_id = 2532 AND s_w_id= 1 FOR UPDATE`,
ExpectedPlan: "Project\n" +
" ├─ columns: [stock2.s_quantity:2, stock2.s_data:4, stock2.s_dist_09:3 as s_dist]\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ static: [{[1, 1], [2532, 2532]}]\n" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: stock2\n" +
" └─ columns: [s_i_id s_w_id s_quantity s_dist_09 s_data]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [stock2.s_quantity, stock2.s_data, stock2.s_dist_09 as s_dist]\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ filters: [{[1, 1], [2532, 2532]}]\n" +
" └─ columns: [s_i_id s_w_id s_quantity s_dist_09 s_data]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [stock2.s_quantity, stock2.s_data, stock2.s_dist_09 as s_dist]\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ filters: [{[1, 1], [2532, 2532]}]\n" +
" └─ columns: [s_i_id s_w_id s_quantity s_dist_09 s_data]\n" +
"",
},
{
Query: `UPDATE stock2 SET s_quantity = 39 WHERE s_i_id = 2532 AND s_w_id= 1`,
ExpectedPlan: "Update\n" +
" └─ UpdateSource(SET stock2.s_quantity:2 = 39 (tinyint))\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ static: [{[1, 1], [2532, 2532]}]\n" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: stock2\n" +
" └─ columns: [s_i_id s_w_id s_quantity s_dist_01 s_dist_02 s_dist_03 s_dist_04 s_dist_05 s_dist_06 s_dist_07 s_dist_08 s_dist_09 s_dist_10 s_ytd s_order_cnt s_remote_cnt s_data]\n" +
"",
},
{
Query: `INSERT INTO order_line2 (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info) VALUES (
3001,9,1,1,2532,1,5,301,'kkkkkkkkkkkkkkkkkkkkkkkk')`,
ExpectedPlan: "Insert(ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: order_line2\n" +
" │ └─ columns: [ol_o_id ol_d_id ol_w_id ol_number ol_i_id ol_supply_w_id ol_delivery_d ol_quantity ol_amount ol_dist_info]\n" +
" └─ Project\n" +
" ├─ columns: [ol_o_id:0!null, ol_d_id:1!null, ol_w_id:2!null, ol_number:3!null, ol_i_id:4, ol_supply_w_id:5, , ol_quantity:6, ol_amount:7, ol_dist_info:8]\n" +
" └─ Values([3001 (smallint),9 (tinyint),1 (tinyint),1 (tinyint),2532 (smallint),1 (tinyint),5 (tinyint),301 (smallint),kkkkkkkkkkkkkkkkkkkkkkkk (longtext)])\n" +
"",
},
{
Query: `
-- cycle 1b
SELECT i_price, i_name, i_data FROM item2 WHERE i_id = 2532`,
ExpectedPlan: "Project\n" +
" ├─ columns: [item2.i_price:2, item2.i_name:1, item2.i_data:3]\n" +
" └─ IndexedTableAccess(item2)\n" +
" ├─ index: [item2.i_id]\n" +
" ├─ static: [{[2532, 2532]}]\n" +
" ├─ colSet: (1-5)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: item2\n" +
" └─ columns: [i_id i_name i_price i_data]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [item2.i_price, item2.i_name, item2.i_data]\n" +
" └─ IndexedTableAccess(item2)\n" +
" ├─ index: [item2.i_id]\n" +
" ├─ filters: [{[2532, 2532]}]\n" +
" └─ columns: [i_id i_name i_price i_data]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [item2.i_price, item2.i_name, item2.i_data]\n" +
" └─ IndexedTableAccess(item2)\n" +
" ├─ index: [item2.i_id]\n" +
" ├─ filters: [{[2532, 2532]}]\n" +
" └─ columns: [i_id i_name i_price i_data]\n" +
"",
},
{
Query: `SELECT s_quantity, s_data, s_dist_09 s_dist FROM stock2 WHERE s_i_id = 2532 AND s_w_id= 1 FOR UPDATE`,
ExpectedPlan: "Project\n" +
" ├─ columns: [stock2.s_quantity:2, stock2.s_data:4, stock2.s_dist_09:3 as s_dist]\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ static: [{[1, 1], [2532, 2532]}]\n" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: stock2\n" +
" └─ columns: [s_i_id s_w_id s_quantity s_dist_09 s_data]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [stock2.s_quantity, stock2.s_data, stock2.s_dist_09 as s_dist]\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ filters: [{[1, 1], [2532, 2532]}]\n" +
" └─ columns: [s_i_id s_w_id s_quantity s_dist_09 s_data]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [stock2.s_quantity, stock2.s_data, stock2.s_dist_09 as s_dist]\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ filters: [{[1, 1], [2532, 2532]}]\n" +
" └─ columns: [s_i_id s_w_id s_quantity s_dist_09 s_data]\n" +
"",
},
{
Query: `UPDATE stock2 SET s_quantity = 5 WHERE s_i_id = 64568 AND s_w_id= 1`,
ExpectedPlan: "Update\n" +
" └─ UpdateSource(SET stock2.s_quantity:2 = 5 (tinyint))\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ static: [{[1, 1], [64568, 64568]}]\n" +
" ├─ colSet: (1-17)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: stock2\n" +
" └─ columns: [s_i_id s_w_id s_quantity s_dist_01 s_dist_02 s_dist_03 s_dist_04 s_dist_05 s_dist_06 s_dist_07 s_dist_08 s_dist_09 s_dist_10 s_ytd s_order_cnt s_remote_cnt s_data]\n" +
"",
},
{
Query: `INSERT INTO order_line2 (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info) VALUES (
3001,9,1,11,64568,1,7,298,'oooooooooooooooooooooooo')`,
ExpectedPlan: "Insert(ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: order_line2\n" +
" │ └─ columns: [ol_o_id ol_d_id ol_w_id ol_number ol_i_id ol_supply_w_id ol_delivery_d ol_quantity ol_amount ol_dist_info]\n" +
" └─ Project\n" +
" ├─ columns: [ol_o_id:0!null, ol_d_id:1!null, ol_w_id:2!null, ol_number:3!null, ol_i_id:4, ol_supply_w_id:5, , ol_quantity:6, ol_amount:7, ol_dist_info:8]\n" +
" └─ Values([3001 (smallint),9 (tinyint),1 (tinyint),11 (tinyint),64568 (smallint unsigned),1 (tinyint),7 (tinyint),298 (smallint),oooooooooooooooooooooooo (longtext)])\n" +
"",
},
{
Query: `
-- cycle 2
UPDATE warehouse2 SET w_ytd = w_ytd + 1767 WHERE w_id = 1`,
ExpectedPlan: "Update\n" +
" └─ UpdateSource(SET warehouse2.w_ytd:8 = (warehouse2.w_ytd:8 + 1767 (smallint)))\n" +
" └─ IndexedTableAccess(warehouse2)\n" +
" ├─ index: [warehouse2.w_id]\n" +
" ├─ static: [{[1, 1]}]\n" +
" ├─ colSet: (1-9)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: warehouse2\n" +
" └─ columns: [w_id w_name w_street_1 w_street_2 w_city w_state w_zip w_tax w_ytd]\n" +
"",
},
{
Query: `SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name FROM warehouse2 WHERE w_id = 1`,
ExpectedPlan: "Project\n" +
" ├─ columns: [warehouse2.w_street_1:2, warehouse2.w_street_2:3, warehouse2.w_city:4, warehouse2.w_state:5, warehouse2.w_zip:6, warehouse2.w_name:1]\n" +
" └─ IndexedTableAccess(warehouse2)\n" +
" ├─ index: [warehouse2.w_id]\n" +
" ├─ static: [{[1, 1]}]\n" +
" ├─ colSet: (1-9)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: warehouse2\n" +
" └─ columns: [w_id w_name w_street_1 w_street_2 w_city w_state w_zip]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [warehouse2.w_street_1, warehouse2.w_street_2, warehouse2.w_city, warehouse2.w_state, warehouse2.w_zip, warehouse2.w_name]\n" +
" └─ IndexedTableAccess(warehouse2)\n" +
" ├─ index: [warehouse2.w_id]\n" +
" ├─ filters: [{[1, 1]}]\n" +
" └─ columns: [w_id w_name w_street_1 w_street_2 w_city w_state w_zip]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [warehouse2.w_street_1, warehouse2.w_street_2, warehouse2.w_city, warehouse2.w_state, warehouse2.w_zip, warehouse2.w_name]\n" +
" └─ IndexedTableAccess(warehouse2)\n" +
" ├─ index: [warehouse2.w_id]\n" +
" ├─ filters: [{[1, 1]}]\n" +
" └─ columns: [w_id w_name w_street_1 w_street_2 w_city w_state w_zip]\n" +
"",
},
{
Query: `UPDATE district2 SET d_ytd = d_ytd + 1767 WHERE d_w_id = 1 AND d_id= 8`,
ExpectedPlan: "Update\n" +
" └─ UpdateSource(SET district2.d_ytd:9 = (district2.d_ytd:9 + 1767 (smallint)))\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ static: [{[1, 1], [8, 8]}]\n" +
" ├─ colSet: (1-11)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: district2\n" +
" └─ columns: [d_id d_w_id d_name d_street_1 d_street_2 d_city d_state d_zip d_tax d_ytd d_next_o_id]\n" +
"",
},
{
Query: `SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name FROM district2 WHERE d_w_id = 1 AND d_id = 8`,
ExpectedPlan: "Project\n" +
" ├─ columns: [district2.d_street_1:3, district2.d_street_2:4, district2.d_city:5, district2.d_state:6, district2.d_zip:7, district2.d_name:2]\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ static: [{[1, 1], [8, 8]}]\n" +
" ├─ colSet: (1-11)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: district2\n" +
" └─ columns: [d_id d_w_id d_name d_street_1 d_street_2 d_city d_state d_zip]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [district2.d_street_1, district2.d_street_2, district2.d_city, district2.d_state, district2.d_zip, district2.d_name]\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ filters: [{[1, 1], [8, 8]}]\n" +
" └─ columns: [d_id d_w_id d_name d_street_1 d_street_2 d_city d_state d_zip]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [district2.d_street_1, district2.d_street_2, district2.d_city, district2.d_state, district2.d_zip, district2.d_name]\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ filters: [{[1, 1], [8, 8]}]\n" +
" └─ columns: [d_id d_w_id d_name d_street_1 d_street_2 d_city d_state d_zip]\n" +
"",
},
{
Query: `SELECT count(c_id) namecnt FROM customer2 WHERE c_w_id = 1 AND c_d_id= 5 AND c_last='ESEEINGABLE'`,
ExpectedPlan: "Project\n" +
" ├─ columns: [count(customer2.c_id):0!null as namecnt]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(customer2.c_id:0!null)\n" +
" ├─ group: \n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ static: [{[1, 1], [5, 5], [ESEEINGABLE, ESEEINGABLE], [NULL, ∞)}]\n" +
" ├─ colSet: (1-21)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: customer2\n" +
" └─ columns: [c_id c_d_id c_w_id c_last]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [count(customer2.c_id) as namecnt]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(customer2.c_id))\n" +
" ├─ Grouping()\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ filters: [{[1, 1], [5, 5], [ESEEINGABLE, ESEEINGABLE], [NULL, ∞)}]\n" +
" └─ columns: [c_id c_d_id c_w_id c_last]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [count(customer2.c_id) as namecnt]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(customer2.c_id))\n" +
" ├─ Grouping()\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ filters: [{[1, 1], [5, 5], [ESEEINGABLE, ESEEINGABLE], [NULL, ∞)}]\n" +
" └─ columns: [c_id c_d_id c_w_id c_last]\n" +
"",
},
{
Query: `SELECT c_id FROM customer2 WHERE c_w_id = 1 AND c_d_id= 5 AND c_last='ESEEINGABLE' ORDER BY c_first`,
ExpectedPlan: "Project\n" +
" ├─ columns: [customer2.c_id:0!null]\n" +
" └─ Sort(customer2.c_first:3 ASC nullsFirst)\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ static: [{[1, 1], [5, 5], [ESEEINGABLE, ESEEINGABLE], [NULL, ∞)}]\n" +
" ├─ colSet: (1-21)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: customer2\n" +
" └─ columns: [c_id c_d_id c_w_id c_first c_last]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [customer2.c_id]\n" +
" └─ Sort(customer2.c_first ASC)\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ filters: [{[1, 1], [5, 5], [ESEEINGABLE, ESEEINGABLE], [NULL, ∞)}]\n" +
" └─ columns: [c_id c_d_id c_w_id c_first c_last]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [customer2.c_id]\n" +
" └─ Sort(customer2.c_first ASC)\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ filters: [{[1, 1], [5, 5], [ESEEINGABLE, ESEEINGABLE], [NULL, ∞)}]\n" +
" └─ columns: [c_id c_d_id c_w_id c_first c_last]\n" +
"",
},
{
Query: `SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since FROM customer2 WHERE c_w_id = 1 AND c_d_id= 5 AND c_id=1838 FOR UPDATE`,
ExpectedPlan: "Project\n" +
" ├─ columns: [customer2.c_first:3, customer2.c_middle:4, customer2.c_last:5, customer2.c_street_1:6, customer2.c_street_2:7, customer2.c_city:8, customer2.c_state:9, customer2.c_zip:10, customer2.c_phone:11, customer2.c_credit:13, customer2.c_credit_lim:14, customer2.c_discount:15, customer2.c_balance:16, customer2.c_ytd_payment:17, customer2.c_since:12]\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_id]\n" +
" ├─ static: [{[1, 1], [5, 5], [1838, 1838]}]\n" +
" ├─ colSet: (1-21)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: customer2\n" +
" └─ columns: [c_id c_d_id c_w_id c_first c_middle c_last c_street_1 c_street_2 c_city c_state c_zip c_phone c_since c_credit c_credit_lim c_discount c_balance c_ytd_payment]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [customer2.c_first, customer2.c_middle, customer2.c_last, customer2.c_street_1, customer2.c_street_2, customer2.c_city, customer2.c_state, customer2.c_zip, customer2.c_phone, customer2.c_credit, customer2.c_credit_lim, customer2.c_discount, customer2.c_balance, customer2.c_ytd_payment, customer2.c_since]\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_id]\n" +
" ├─ filters: [{[1, 1], [5, 5], [1838, 1838]}]\n" +
" └─ columns: [c_id c_d_id c_w_id c_first c_middle c_last c_street_1 c_street_2 c_city c_state c_zip c_phone c_since c_credit c_credit_lim c_discount c_balance c_ytd_payment]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [customer2.c_first, customer2.c_middle, customer2.c_last, customer2.c_street_1, customer2.c_street_2, customer2.c_city, customer2.c_state, customer2.c_zip, customer2.c_phone, customer2.c_credit, customer2.c_credit_lim, customer2.c_discount, customer2.c_balance, customer2.c_ytd_payment, customer2.c_since]\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_id]\n" +
" ├─ filters: [{[1, 1], [5, 5], [1838, 1838]}]\n" +
" └─ columns: [c_id c_d_id c_w_id c_first c_middle c_last c_street_1 c_street_2 c_city c_state c_zip c_phone c_since c_credit c_credit_lim c_discount c_balance c_ytd_payment]\n" +
"",
},
{
Query: `UPDATE customer2 SET c_balance=-1777.000000, c_ytd_payment=1777.000000 WHERE c_w_id = 1 AND c_d_id=5 AND c_id=1838`,
ExpectedPlan: "Update\n" +
" └─ UpdateSource(SET customer2.c_balance:16 = -1777.000000,SET customer2.c_ytd_payment:17 = 1777 (decimal(10,6)))\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_id]\n" +
" ├─ static: [{[1, 1], [5, 5], [1838, 1838]}]\n" +
" ├─ colSet: (1-21)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: customer2\n" +
" └─ columns: [c_id c_d_id c_w_id c_first c_middle c_last c_street_1 c_street_2 c_city c_state c_zip c_phone c_since c_credit c_credit_lim c_discount c_balance c_ytd_payment c_payment_cnt c_delivery_cnt c_data]\n" +
"",
},
{
Query: `INSERT INTO history2 (h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) VALUES (5,1,1838,8,1,NOW(),1767,'name-rqojn name-dnvgs ')`,
ExpectedPlan: "Insert(h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data)\n" +
" ├─ InsertDestination\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: history2\n" +
" │ └─ columns: [h_c_id h_c_d_id h_c_w_id h_d_id h_w_id h_date h_amount h_data]\n" +
" └─ Project\n" +
" ├─ columns: [h_c_id:2, h_c_d_id:0, h_c_w_id:1, h_d_id:3, h_w_id:4, h_date:5, h_amount:6, h_data:7]\n" +
" └─ Values([5 (tinyint),1 (tinyint),1838 (smallint),8 (tinyint),1 (tinyint),NOW(),1767 (smallint),name-rqojn name-dnvgs (longtext)])\n" +
"",
},
{
Query: `
-- cycle 3
SELECT count(c_id) namecnt FROM customer2 WHERE c_w_id = 1 AND c_d_id= 1 AND c_last='PRIESEPRES'`,
ExpectedPlan: "Project\n" +
" ├─ columns: [count(customer2.c_id):0!null as namecnt]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(customer2.c_id:0!null)\n" +
" ├─ group: \n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ static: [{[1, 1], [1, 1], [PRIESEPRES, PRIESEPRES], [NULL, ∞)}]\n" +
" ├─ colSet: (1-21)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: customer2\n" +
" └─ columns: [c_id c_d_id c_w_id c_last]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [count(customer2.c_id) as namecnt]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(customer2.c_id))\n" +
" ├─ Grouping()\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ filters: [{[1, 1], [1, 1], [PRIESEPRES, PRIESEPRES], [NULL, ∞)}]\n" +
" └─ columns: [c_id c_d_id c_w_id c_last]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [count(customer2.c_id) as namecnt]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(customer2.c_id))\n" +
" ├─ Grouping()\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ filters: [{[1, 1], [1, 1], [PRIESEPRES, PRIESEPRES], [NULL, ∞)}]\n" +
" └─ columns: [c_id c_d_id c_w_id c_last]\n" +
"",
},
{
Query: `SELECT c_balance, c_first, c_middle, c_id FROM customer2 WHERE c_w_id = 1 AND c_d_id= 1 AND c_last='PRIESEPRES' ORDER BY c_first`,
ExpectedPlan: "Project\n" +
" ├─ columns: [customer2.c_balance:6, customer2.c_first:3, customer2.c_middle:4, customer2.c_id:0!null]\n" +
" └─ Sort(customer2.c_first:3 ASC nullsFirst)\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ static: [{[1, 1], [1, 1], [PRIESEPRES, PRIESEPRES], [NULL, ∞)}]\n" +
" ├─ colSet: (1-21)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: customer2\n" +
" └─ columns: [c_id c_d_id c_w_id c_first c_middle c_last c_balance]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [customer2.c_balance, customer2.c_first, customer2.c_middle, customer2.c_id]\n" +
" └─ Sort(customer2.c_first ASC)\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ filters: [{[1, 1], [1, 1], [PRIESEPRES, PRIESEPRES], [NULL, ∞)}]\n" +
" └─ columns: [c_id c_d_id c_w_id c_first c_middle c_last c_balance]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [customer2.c_balance, customer2.c_first, customer2.c_middle, customer2.c_id]\n" +
" └─ Sort(customer2.c_first ASC)\n" +
" └─ IndexedTableAccess(customer2)\n" +
" ├─ index: [customer2.c_w_id,customer2.c_d_id,customer2.c_last,customer2.c_first]\n" +
" ├─ filters: [{[1, 1], [1, 1], [PRIESEPRES, PRIESEPRES], [NULL, ∞)}]\n" +
" └─ columns: [c_id c_d_id c_w_id c_first c_middle c_last c_balance]\n" +
"",
},
{
Query: `SELECT o_id, o_carrier_id, o_entry_d FROM orders2 WHERE o_w_id = 1 AND o_d_id = 1 AND o_c_id = 355 ORDER BY o_id DESC`,
ExpectedPlan: "Project\n" +
" ├─ columns: [orders2.o_id:0!null, orders2.o_carrier_id:5, orders2.o_entry_d:4]\n" +
" └─ Sort(orders2.o_id:0!null DESC nullsFirst)\n" +
" └─ IndexedTableAccess(orders2)\n" +
" ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" ├─ static: [{[1, 1], [1, 1], [355, 355], [NULL, ∞)}]\n" +
" ├─ colSet: (1-8)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: orders2\n" +
" └─ columns: [o_id o_d_id o_w_id o_c_id o_entry_d o_carrier_id]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [orders2.o_id, orders2.o_carrier_id, orders2.o_entry_d]\n" +
" └─ Sort(orders2.o_id DESC)\n" +
" └─ IndexedTableAccess(orders2)\n" +
" ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" ├─ filters: [{[1, 1], [1, 1], [355, 355], [NULL, ∞)}]\n" +
" └─ columns: [o_id o_d_id o_w_id o_c_id o_entry_d o_carrier_id]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [orders2.o_id, orders2.o_carrier_id, orders2.o_entry_d]\n" +
" └─ Sort(orders2.o_id DESC)\n" +
" └─ IndexedTableAccess(orders2)\n" +
" ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" ├─ filters: [{[1, 1], [1, 1], [355, 355], [NULL, ∞)}]\n" +
" └─ columns: [o_id o_d_id o_w_id o_c_id o_entry_d o_carrier_id]\n" +
"",
},
{
Query: `SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d FROM order_line2 WHERE ol_w_id = 1 AND ol_d_id = 1 AND ol_o_id = 1`,
ExpectedPlan: "Project\n" +
" ├─ columns: [order_line2.ol_i_id:3, order_line2.ol_supply_w_id:4, order_line2.ol_quantity:6, order_line2.ol_amount:7, order_line2.ol_delivery_d:5]\n" +
" └─ IndexedTableAccess(order_line2)\n" +
" ├─ index: [order_line2.ol_w_id,order_line2.ol_d_id,order_line2.ol_o_id,order_line2.ol_number]\n" +
" ├─ static: [{[1, 1], [1, 1], [1, 1], [NULL, ∞)}]\n" +
" ├─ colSet: (1-10)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: order_line2\n" +
" └─ columns: [ol_o_id ol_d_id ol_w_id ol_i_id ol_supply_w_id ol_delivery_d ol_quantity ol_amount]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [order_line2.ol_i_id, order_line2.ol_supply_w_id, order_line2.ol_quantity, order_line2.ol_amount, order_line2.ol_delivery_d]\n" +
" └─ IndexedTableAccess(order_line2)\n" +
" ├─ index: [order_line2.ol_w_id,order_line2.ol_d_id,order_line2.ol_o_id,order_line2.ol_number]\n" +
" ├─ filters: [{[1, 1], [1, 1], [1, 1], [NULL, ∞)}]\n" +
" └─ columns: [ol_o_id ol_d_id ol_w_id ol_i_id ol_supply_w_id ol_delivery_d ol_quantity ol_amount]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [order_line2.ol_i_id, order_line2.ol_supply_w_id, order_line2.ol_quantity, order_line2.ol_amount, order_line2.ol_delivery_d]\n" +
" └─ IndexedTableAccess(order_line2)\n" +
" ├─ index: [order_line2.ol_w_id,order_line2.ol_d_id,order_line2.ol_o_id,order_line2.ol_number]\n" +
" ├─ filters: [{[1, 1], [1, 1], [1, 1], [NULL, ∞)}]\n" +
" └─ columns: [ol_o_id ol_d_id ol_w_id ol_i_id ol_supply_w_id ol_delivery_d ol_quantity ol_amount]\n" +
"",
},
{
Query: `
-- cycle 4
SELECT d_next_o_id FROM district2 WHERE d_id = 5 AND d_w_id= 1`,
ExpectedPlan: "Project\n" +
" ├─ columns: [district2.d_next_o_id:2]\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ static: [{[1, 1], [5, 5]}]\n" +
" ├─ colSet: (1-11)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: district2\n" +
" └─ columns: [d_id d_w_id d_next_o_id]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [district2.d_next_o_id]\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ filters: [{[1, 1], [5, 5]}]\n" +
" └─ columns: [d_id d_w_id d_next_o_id]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [district2.d_next_o_id]\n" +
" └─ IndexedTableAccess(district2)\n" +
" ├─ index: [district2.d_w_id,district2.d_id]\n" +
" ├─ filters: [{[1, 1], [5, 5]}]\n" +
" └─ columns: [d_id d_w_id d_next_o_id]\n" +
"",
},
{
Query: `SELECT COUNT(DISTINCT (s_i_id)) FROM order_line2, stock2 WHERE ol_w_id = 1 AND ol_d_id = 5 AND ol_o_id < 3003 AND ol_o_id >= 2983 AND s_w_id= 1 AND s_i_id=ol_i_id AND s_quantity < 18`,
ExpectedPlan: "Project\n" +
" ├─ columns: [countdistinct([stock2.s_i_id]):0!null as COUNT(DISTINCT (s_i_id))]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNTDISTINCT([stock2.s_i_id])\n" +
" ├─ group: \n" +
" └─ LookupJoin\n" +
" ├─ IndexedTableAccess(order_line2)\n" +
" │ ├─ index: [order_line2.ol_w_id,order_line2.ol_d_id,order_line2.ol_o_id,order_line2.ol_number]\n" +
" │ ├─ static: [{[1, 1], [5, 5], [2983, 3003), [NULL, ∞)}]\n" +
" │ ├─ colSet: (1-10)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: order_line2\n" +
" │ └─ columns: [ol_o_id ol_d_id ol_w_id ol_i_id]\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ stock2.s_w_id:1!null\n" +
" │ │ └─ 1 (smallint)\n" +
" │ └─ LessThan\n" +
" │ ├─ stock2.s_quantity:2\n" +
" │ └─ 18 (smallint)\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ keys: [1 (smallint) order_line2.ol_i_id:3]\n" +
" ├─ colSet: (11-27)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: stock2\n" +
" └─ columns: [s_i_id s_w_id s_quantity]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [countdistinct([stock2.s_i_id]) as COUNT(DISTINCT (s_i_id))]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNTDISTINCT([stock2.s_i_id]))\n" +
" ├─ Grouping()\n" +
" └─ LookupJoin\n" +
" ├─ IndexedTableAccess(order_line2)\n" +
" │ ├─ index: [order_line2.ol_w_id,order_line2.ol_d_id,order_line2.ol_o_id,order_line2.ol_number]\n" +
" │ ├─ filters: [{[1, 1], [5, 5], [2983, 3003), [NULL, ∞)}]\n" +
" │ └─ columns: [ol_o_id ol_d_id ol_w_id ol_i_id]\n" +
" └─ Filter\n" +
" ├─ ((stock2.s_w_id = 1) AND (stock2.s_quantity < 18))\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ columns: [s_i_id s_w_id s_quantity]\n" +
" └─ keys: 1, order_line2.ol_i_id\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [countdistinct([stock2.s_i_id]) as COUNT(DISTINCT (s_i_id))]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNTDISTINCT([stock2.s_i_id]))\n" +
" ├─ Grouping()\n" +
" └─ LookupJoin\n" +
" ├─ IndexedTableAccess(order_line2)\n" +
" │ ├─ index: [order_line2.ol_w_id,order_line2.ol_d_id,order_line2.ol_o_id,order_line2.ol_number]\n" +
" │ ├─ filters: [{[1, 1], [5, 5], [2983, 3003), [NULL, ∞)}]\n" +
" │ └─ columns: [ol_o_id ol_d_id ol_w_id ol_i_id]\n" +
" └─ Filter\n" +
" ├─ ((stock2.s_w_id = 1) AND (stock2.s_quantity < 18))\n" +
" └─ IndexedTableAccess(stock2)\n" +
" ├─ index: [stock2.s_w_id,stock2.s_i_id]\n" +
" ├─ columns: [s_i_id s_w_id s_quantity]\n" +
" └─ keys: 1, order_line2.ol_i_id\n" +
"",
},
{
Query: `
-- other
SELECT o_id, o_entry_d, COALESCE(o_carrier_id,0)
FROM orders2
WHERE
o_w_id = 1 AND
o_d_id = 3 AND
o_c_id = 20001 AND
o_id = (SELECT MAX(o_id) FROM orders2 WHERE o_w_id = 1 AND o_d_id = 3 AND o_c_id = 20001)`,
ExpectedPlan: "Project\n" +
" ├─ columns: [orders2.o_id:0!null, orders2.o_entry_d:4, coalesce(orders2.o_carrier_id:5,0 (tinyint)) as COALESCE(o_carrier_id,0)]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ orders2.o_id:0!null\n" +
" │ └─ Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ alias-string: select MAX(o_id) from orders2 where o_w_id = 1 and o_d_id = 3 and o_c_id = 20001\n" +
" │ └─ Project\n" +
" │ ├─ columns: [max(orders2.o_id):8!null as MAX(o_id)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: MAX(orders2.o_id:8!null)\n" +
" │ ├─ group: \n" +
" │ └─ IndexedTableAccess(orders2)\n" +
" │ ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" │ ├─ static: [{[1, 1], [3, 3], [20001, 20001], [NULL, ∞)}]\n" +
" │ ├─ colSet: (9-16)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: orders2\n" +
" │ └─ columns: [o_id o_d_id o_w_id o_c_id]\n" +
" └─ IndexedTableAccess(orders2)\n" +
" ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" ├─ static: [{[1, 1], [3, 3], [20001, 20001], [NULL, ∞)}]\n" +
" ├─ colSet: (1-8)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: orders2\n" +
" └─ columns: [o_id o_d_id o_w_id o_c_id o_entry_d o_carrier_id o_ol_cnt o_all_local]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [orders2.o_id, orders2.o_entry_d, coalesce(orders2.o_carrier_id,0) as COALESCE(o_carrier_id,0)]\n" +
" └─ Filter\n" +
" ├─ (orders2.o_id = Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [max(orders2.o_id) as MAX(o_id)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(MAX(orders2.o_id))\n" +
" │ ├─ Grouping()\n" +
" │ └─ IndexedTableAccess(orders2)\n" +
" │ ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" │ ├─ filters: [{[1, 1], [3, 3], [20001, 20001], [NULL, ∞)}]\n" +
" │ └─ columns: [o_id o_d_id o_w_id o_c_id]\n" +
" │ )\n" +
" └─ IndexedTableAccess(orders2)\n" +
" ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" └─ filters: [{[1, 1], [3, 3], [20001, 20001], [NULL, ∞)}]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [orders2.o_id, orders2.o_entry_d, coalesce(orders2.o_carrier_id,0) as COALESCE(o_carrier_id,0)]\n" +
" └─ Filter\n" +
" ├─ (orders2.o_id = Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [max(orders2.o_id) as MAX(o_id)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(MAX(orders2.o_id))\n" +
" │ ├─ Grouping()\n" +
" │ └─ IndexedTableAccess(orders2)\n" +
" │ ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" │ ├─ filters: [{[1, 1], [3, 3], [20001, 20001], [NULL, ∞)}]\n" +
" │ └─ columns: [o_id o_d_id o_w_id o_c_id]\n" +
" │ )\n" +
" └─ IndexedTableAccess(orders2)\n" +
" ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" └─ filters: [{[1, 1], [3, 3], [20001, 20001], [NULL, ∞)}]\n" +
"",
},
{
Query: `
select o_id, o.o_d_id
from
orders2 o,
(
select o_c_id, o_w_id, o_d_id, count(distinct o_id)
from orders2
where o_w_id=1 and o_id > 2100 and o_id < 11153
group by o_c_id,o_d_id,o_w_id
having count( distinct o_id) > 1
limit 1
) t
where
t.o_w_id=o.o_w_id and
t.o_d_id=o.o_d_id and
t.o_c_id=o.o_c_id
limit 1;`,
ExpectedPlan: "Limit(1)\n" +
" └─ Project\n" +
" ├─ columns: [o.o_id:4!null, o.o_d_id:5!null]\n" +
" └─ LookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: t\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (18-21)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Limit(1)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [orders2.o_c_id:1, orders2.o_w_id:2!null, orders2.o_d_id:3!null, countdistinct([orders2.o_id]):0!null as count(distinct o_id)]\n" +
" │ └─ Having\n" +
" │ ├─ GreaterThan\n" +
" │ │ ├─ countdistinct([orders2.o_id]):0!null\n" +
" │ │ └─ 1 (bigint)\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: COUNTDISTINCT([orders2.o_id]), orders2.o_c_id:3, orders2.o_w_id:2!null, orders2.o_d_id:1!null, orders2.o_id:0!null\n" +
" │ ├─ group: orders2.o_c_id:3, orders2.o_d_id:1!null, orders2.o_w_id:2!null\n" +
" │ └─ IndexedTableAccess(orders2)\n" +
" │ ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_id]\n" +
" │ ├─ static: [{[1, 1], [NULL, ∞), (2100, 11153)}]\n" +
" │ ├─ colSet: (9-16)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: orders2\n" +
" │ └─ columns: [o_id o_d_id o_w_id o_c_id o_entry_d o_carrier_id o_ol_cnt o_all_local]\n" +
" └─ TableAlias(o)\n" +
" └─ IndexedTableAccess(orders2)\n" +
" ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" ├─ keys: [t.o_w_id:1!null t.o_d_id:2!null t.o_c_id:0]\n" +
" ├─ colSet: (1-8)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: orders2\n" +
" └─ columns: [o_id o_d_id o_w_id o_c_id]\n" +
"",
ExpectedEstimates: "Limit(1)\n" +
" └─ Project\n" +
" ├─ columns: [o.o_id, o.o_d_id]\n" +
" └─ LookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: t\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Limit(1)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [orders2.o_c_id, orders2.o_w_id, orders2.o_d_id, countdistinct([orders2.o_id]) as count(distinct o_id)]\n" +
" │ └─ Having((countdistinct([orders2.o_id]) > 1))\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(COUNTDISTINCT([orders2.o_id]), orders2.o_c_id, orders2.o_w_id, orders2.o_d_id, orders2.o_id)\n" +
" │ ├─ Grouping(orders2.o_c_id, orders2.o_d_id, orders2.o_w_id)\n" +
" │ └─ IndexedTableAccess(orders2)\n" +
" │ ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_id]\n" +
" │ └─ filters: [{[1, 1], [NULL, ∞), (2100, 11153)}]\n" +
" └─ TableAlias(o)\n" +
" └─ IndexedTableAccess(orders2)\n" +
" ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" ├─ columns: [o_id o_d_id o_w_id o_c_id]\n" +
" └─ keys: t.o_w_id, t.o_d_id, t.o_c_id\n" +
"",
ExpectedAnalysis: "Limit(1)\n" +
" └─ Project\n" +
" ├─ columns: [o.o_id, o.o_d_id]\n" +
" └─ LookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: t\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Limit(1)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [orders2.o_c_id, orders2.o_w_id, orders2.o_d_id, countdistinct([orders2.o_id]) as count(distinct o_id)]\n" +
" │ └─ Having((countdistinct([orders2.o_id]) > 1))\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(COUNTDISTINCT([orders2.o_id]), orders2.o_c_id, orders2.o_w_id, orders2.o_d_id, orders2.o_id)\n" +
" │ ├─ Grouping(orders2.o_c_id, orders2.o_d_id, orders2.o_w_id)\n" +
" │ └─ IndexedTableAccess(orders2)\n" +
" │ ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_id]\n" +
" │ └─ filters: [{[1, 1], [NULL, ∞), (2100, 11153)}]\n" +
" └─ TableAlias(o)\n" +
" └─ IndexedTableAccess(orders2)\n" +
" ├─ index: [orders2.o_w_id,orders2.o_d_id,orders2.o_c_id,orders2.o_id]\n" +
" ├─ columns: [o_id o_d_id o_w_id o_c_id]\n" +
" └─ keys: t.o_w_id, t.o_d_id, t.o_c_id\n" +
"",
},
}
var TpcdsPlanTests = []QueryPlanTest{ { Query: ` -- start query 1 in stream 0 using template query1.tpl with customer_total_return as (select sr_customer_sk as ctr_customer_sk ,sr_store_sk as ctr_store_sk ,sum(SR_FEE) as ctr_total_return from store_returns ,date_dim where sr_returned_date_sk = d_date_sk and d_year =2000 group by sr_customer_sk ,sr_store_sk) select c_customer_id from customer_total_return ctr1 ,store ,customer where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 from customer_total_return ctr2 where ctr1.ctr_store_sk = ctr2.ctr_store_sk) and s_store_sk = ctr1.ctr_store_sk and s_state = 'TN' and ctr1.ctr_customer_sk = c_customer_sk order by c_customer_id limit 100;`, }, { Query: ` -- start query 2 in stream 0 using template query2.tpl with wscs as (select sold_date_sk ,sales_price from (select ws_sold_date_sk sold_date_sk ,ws_ext_sales_price sales_price from web_sales union all select cs_sold_date_sk sold_date_sk ,cs_ext_sales_price sales_price from catalog_sales) dt), wswscs as (select d_week_seq, sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales from wscs ,date_dim where d_date_sk = sold_date_sk group by d_week_seq) select d_week_seq1 ,round(sun_sales1/sun_sales2,2) ,round(mon_sales1/mon_sales2,2) ,round(tue_sales1/tue_sales2,2) ,round(wed_sales1/wed_sales2,2) ,round(thu_sales1/thu_sales2,2) ,round(fri_sales1/fri_sales2,2) ,round(sat_sales1/sat_sales2,2) from (select wswscs.d_week_seq d_week_seq1 ,sun_sales sun_sales1 ,mon_sales mon_sales1 ,tue_sales tue_sales1 ,wed_sales wed_sales1 ,thu_sales thu_sales1 ,fri_sales fri_sales1 ,sat_sales sat_sales1 from wswscs,date_dim where date_dim.d_week_seq = wswscs.d_week_seq and d_year = 1998) y, (select wswscs.d_week_seq d_week_seq2 ,sun_sales sun_sales2 ,mon_sales mon_sales2 ,tue_sales tue_sales2 ,wed_sales wed_sales2 ,thu_sales thu_sales2 ,fri_sales fri_sales2 ,sat_sales sat_sales2 from wswscs ,date_dim where date_dim.d_week_seq = wswscs.d_week_seq and d_year = 1998+1) z where d_week_seq1=d_week_seq2-53 order by d_week_seq1;`, }, { Query: ` -- start query 3 in stream 0 using template query3.tpl select dt.d_year ,item.i_brand_id brand_id ,item.i_brand brand ,sum(ss_sales_price) sum_agg from date_dim dt ,store_sales ,item where dt.d_date_sk = store_sales.ss_sold_date_sk and store_sales.ss_item_sk = item.i_item_sk and item.i_manufact_id = 816 and dt.d_moy=11 group by dt.d_year ,item.i_brand ,item.i_brand_id order by dt.d_year ,sum_agg desc ,brand_id limit 100;`, }, { Query: ` -- start query 4 in stream 0 using template query4.tpl with year_total as ( select c_customer_id customer_id ,c_first_name customer_first_name ,c_last_name customer_last_name ,c_preferred_cust_flag customer_preferred_cust_flag ,c_birth_country customer_birth_country ,c_login customer_login ,c_email_address customer_email_address ,d_year dyear ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total ,'s' sale_type from customer ,store_sales ,date_dim where c_customer_sk = ss_customer_sk and ss_sold_date_sk = d_date_sk group by c_customer_id ,c_first_name ,c_last_name ,c_preferred_cust_flag ,c_birth_country ,c_login ,c_email_address ,d_year union all select c_customer_id customer_id ,c_first_name customer_first_name ,c_last_name customer_last_name ,c_preferred_cust_flag customer_preferred_cust_flag ,c_birth_country customer_birth_country ,c_login customer_login ,c_email_address customer_email_address ,d_year dyear ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total ,'c' sale_type from customer ,catalog_sales ,date_dim where c_customer_sk = cs_bill_customer_sk and cs_sold_date_sk = d_date_sk group by c_customer_id ,c_first_name ,c_last_name ,c_preferred_cust_flag ,c_birth_country ,c_login ,c_email_address ,d_year union all select c_customer_id customer_id ,c_first_name customer_first_name ,c_last_name customer_last_name ,c_preferred_cust_flag customer_preferred_cust_flag ,c_birth_country customer_birth_country ,c_login customer_login ,c_email_address customer_email_address ,d_year dyear ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total ,'w' sale_type from customer ,web_sales ,date_dim where c_customer_sk = ws_bill_customer_sk and ws_sold_date_sk = d_date_sk group by c_customer_id ,c_first_name ,c_last_name ,c_preferred_cust_flag ,c_birth_country ,c_login ,c_email_address ,d_year ) select t_s_secyear.customer_id ,t_s_secyear.customer_first_name ,t_s_secyear.customer_last_name ,t_s_secyear.customer_birth_country from year_total t_s_firstyear ,year_total t_s_secyear ,year_total t_c_firstyear ,year_total t_c_secyear ,year_total t_w_firstyear ,year_total t_w_secyear where t_s_secyear.customer_id = t_s_firstyear.customer_id and t_s_firstyear.customer_id = t_c_secyear.customer_id and t_s_firstyear.customer_id = t_c_firstyear.customer_id and t_s_firstyear.customer_id = t_w_firstyear.customer_id and t_s_firstyear.customer_id = t_w_secyear.customer_id and t_s_firstyear.sale_type = 's' and t_c_firstyear.sale_type = 'c' and t_w_firstyear.sale_type = 'w' and t_s_secyear.sale_type = 's' and t_c_secyear.sale_type = 'c' and t_w_secyear.sale_type = 'w' and t_s_firstyear.dyear = 1999 and t_s_secyear.dyear = 1999+1 and t_c_firstyear.dyear = 1999 and t_c_secyear.dyear = 1999+1 and t_w_firstyear.dyear = 1999 and t_w_secyear.dyear = 1999+1 and t_s_firstyear.year_total > 0 and t_c_firstyear.year_total > 0 and t_w_firstyear.year_total > 0 and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end order by t_s_secyear.customer_id ,t_s_secyear.customer_first_name ,t_s_secyear.customer_last_name ,t_s_secyear.customer_birth_country limit 100;`, }, { Query: ` -- start query 5 in stream 0 using template query5.tpl with ssr as (select s_store_id, sum(sales_price) as sales, sum(profit) as profit, sum(return_amt) as returns, sum(net_loss) as profit_loss from ( select ss_store_sk as store_sk, ss_sold_date_sk as date_sk, ss_ext_sales_price as sales_price, ss_net_profit as profit, cast(0 as decimal(7,2)) as return_amt, cast(0 as decimal(7,2)) as net_loss from store_sales union all select sr_store_sk as store_sk, sr_returned_date_sk as date_sk, cast(0 as decimal(7,2)) as sales_price, cast(0 as decimal(7,2)) as profit, sr_return_amt as return_amt, sr_net_loss as net_loss from store_returns ) salesreturns, date_dim, store where date_sk = d_date_sk and d_date between cast('2000-08-19' as date) and (cast('2000-08-19' as date) + interval 14 day) and store_sk = s_store_sk group by s_store_id) , csr as (select cp_catalog_page_id, sum(sales_price) as sales, sum(profit) as profit, sum(return_amt) as returns, sum(net_loss) as profit_loss from ( select cs_catalog_page_sk as page_sk, cs_sold_date_sk as date_sk, cs_ext_sales_price as sales_price, cs_net_profit as profit, cast(0 as decimal(7,2)) as return_amt, cast(0 as decimal(7,2)) as net_loss from catalog_sales union all select cr_catalog_page_sk as page_sk, cr_returned_date_sk as date_sk, cast(0 as decimal(7,2)) as sales_price, cast(0 as decimal(7,2)) as profit, cr_return_amount as return_amt, cr_net_loss as net_loss from catalog_returns ) salesreturns, date_dim, catalog_page where date_sk = d_date_sk and d_date between cast('2000-08-19' as date) and (cast('2000-08-19' as date) + interval 14 day) and page_sk = cp_catalog_page_sk group by cp_catalog_page_id) , wsr as (select web_site_id, sum(sales_price) as sales, sum(profit) as profit, sum(return_amt) as returns, sum(net_loss) as profit_loss from ( select ws_web_site_sk as wsr_web_site_sk, ws_sold_date_sk as date_sk, ws_ext_sales_price as sales_price, ws_net_profit as profit, cast(0 as decimal(7,2)) as return_amt, cast(0 as decimal(7,2)) as net_loss from web_sales union all select ws_web_site_sk as wsr_web_site_sk, wr_returned_date_sk as date_sk, cast(0 as decimal(7,2)) as sales_price, cast(0 as decimal(7,2)) as profit, wr_return_amt as return_amt, wr_net_loss as net_loss from web_returns left outer join web_sales on ( wr_item_sk = ws_item_sk and wr_order_number = ws_order_number) ) salesreturns, date_dim, web_site where date_sk = d_date_sk and d_date between cast('2000-08-19' as date) and (cast('2000-08-19' as date) + interval 14 day) and wsr_web_site_sk = web_site_sk group by web_site_id) select channel , id , sum(sales) as sales , sum(returns) as returns , sum(profit) as profit from (select 'store channel' as channel , 'store' || s_store_id as id , sales , returns , (profit - profit_loss) as profit from ssr union all select 'catalog channel' as channel , 'catalog_page' || cp_catalog_page_id as id , sales , returns , (profit - profit_loss) as profit from csr union all select 'web channel' as channel , 'web_site' || web_site_id as id , sales , returns , (profit - profit_loss) as profit from wsr ) x group by rollup (channel, id) order by channel ,id limit 100;`, Skip: true, }, { Query: ` -- start query 6 in stream 0 using template query6.tpl select a.ca_state state, count(*) cnt from customer_address a ,customer c ,store_sales s ,date_dim d ,item i where a.ca_address_sk = c.c_current_addr_sk and c.c_customer_sk = s.ss_customer_sk and s.ss_sold_date_sk = d.d_date_sk and s.ss_item_sk = i.i_item_sk and d.d_month_seq = (select distinct (d_month_seq) from date_dim where d_year = 2002 and d_moy = 3 ) and i.i_current_price > 1.2 * (select avg(j.i_current_price) from item j where j.i_category = i.i_category) group by a.ca_state having count(*) >= 10 order by cnt, a.ca_state limit 100;`, }, { Query: ` -- start query 7 in stream 0 using template query7.tpl select i_item_id, avg(ss_quantity) agg1, avg(ss_list_price) agg2, avg(ss_coupon_amt) agg3, avg(ss_sales_price) agg4 from store_sales, customer_demographics, date_dim, item, promotion where ss_sold_date_sk = d_date_sk and ss_item_sk = i_item_sk and ss_cdemo_sk = cd_demo_sk and ss_promo_sk = p_promo_sk and cd_gender = 'F' and cd_marital_status = 'W' and cd_education_status = 'College' and (p_channel_email = 'N' or p_channel_event = 'N') and d_year = 2001 group by i_item_id order by i_item_id limit 100;`, }, { Query: ` -- start query 8 in stream 0 using template query8.tpl select s_store_name ,sum(ss_net_profit) from store_sales ,date_dim ,store, (select ca_zip from ( SELECT substr(ca_zip,1,5) ca_zip FROM customer_address WHERE substr(ca_zip,1,5) IN ( '47602','16704','35863','28577','83910','36201', '58412','48162','28055','41419','80332', '38607','77817','24891','16226','18410', '21231','59345','13918','51089','20317', '17167','54585','67881','78366','47770', '18360','51717','73108','14440','21800', '89338','45859','65501','34948','25973', '73219','25333','17291','10374','18829', '60736','82620','41351','52094','19326', '25214','54207','40936','21814','79077', '25178','75742','77454','30621','89193', '27369','41232','48567','83041','71948', '37119','68341','14073','16891','62878', '49130','19833','24286','27700','40979', '50412','81504','94835','84844','71954', '39503','57649','18434','24987','12350', '86379','27413','44529','98569','16515', '27287','24255','21094','16005','56436', '91110','68293','56455','54558','10298', '83647','32754','27052','51766','19444', '13869','45645','94791','57631','20712', '37788','41807','46507','21727','71836', '81070','50632','88086','63991','20244', '31655','51782','29818','63792','68605', '94898','36430','57025','20601','82080', '33869','22728','35834','29086','92645', '98584','98072','11652','78093','57553', '43830','71144','53565','18700','90209', '71256','38353','54364','28571','96560', '57839','56355','50679','45266','84680', '34306','34972','48530','30106','15371', '92380','84247','92292','68852','13338', '34594','82602','70073','98069','85066', '47289','11686','98862','26217','47529', '63294','51793','35926','24227','14196', '24594','32489','99060','49472','43432', '49211','14312','88137','47369','56877', '20534','81755','15794','12318','21060', '73134','41255','63073','81003','73873', '66057','51184','51195','45676','92696', '70450','90669','98338','25264','38919', '59226','58581','60298','17895','19489', '52301','80846','95464','68770','51634', '19988','18367','18421','11618','67975', '25494','41352','95430','15734','62585', '97173','33773','10425','75675','53535', '17879','41967','12197','67998','79658', '59130','72592','14851','43933','68101', '50636','25717','71286','24660','58058', '72991','95042','15543','33122','69280', '11912','59386','27642','65177','17672', '33467','64592','36335','54010','18767', '63193','42361','49254','33113','33159', '36479','59080','11855','81963','31016', '49140','29392','41836','32958','53163', '13844','73146','23952','65148','93498', '14530','46131','58454','13376','13378', '83986','12320','17193','59852','46081', '98533','52389','13086','68843','31013', '13261','60560','13443','45533','83583', '11489','58218','19753','22911','25115', '86709','27156','32669','13123','51933', '39214','41331','66943','14155','69998', '49101','70070','35076','14242','73021', '59494','15782','29752','37914','74686', '83086','34473','15751','81084','49230', '91894','60624','17819','28810','63180', '56224','39459','55233','75752','43639', '55349','86057','62361','50788','31830', '58062','18218','85761','60083','45484', '21204','90229','70041','41162','35390', '16364','39500','68908','26689','52868', '81335','40146','11340','61527','61794', '71997','30415','59004','29450','58117', '69952','33562','83833','27385','61860', '96435','48333','23065','32961','84919', '61997','99132','22815','56600','68730', '48017','95694','32919','88217','27116', '28239','58032','18884','16791','21343', '97462','18569','75660','15475') intersect select ca_zip from (SELECT substr(ca_zip,1,5) ca_zip,count(*) cnt FROM customer_address, customer WHERE ca_address_sk = c_current_addr_sk and c_preferred_cust_flag='Y' group by ca_zip having count(*) > 10)A1)A2) V1 where ss_store_sk = s_store_sk and ss_sold_date_sk = d_date_sk and d_qoy = 2 and d_year = 1998 and (substr(s_zip,1,2) = substr(V1.ca_zip,1,2)) group by s_store_name order by s_store_name limit 100;`, }, { Query: ` -- start query 9 in stream 0 using template query9.tpl select case when (select count(*) from store_sales where ss_quantity between 1 and 20) > 1071 then (select avg(ss_ext_tax) from store_sales where ss_quantity between 1 and 20) else (select avg(ss_net_paid_inc_tax) from store_sales where ss_quantity between 1 and 20) end bucket1 , case when (select count(*) from store_sales where ss_quantity between 21 and 40) > 39161 then (select avg(ss_ext_tax) from store_sales where ss_quantity between 21 and 40) else (select avg(ss_net_paid_inc_tax) from store_sales where ss_quantity between 21 and 40) end bucket2, case when (select count(*) from store_sales where ss_quantity between 41 and 60) > 29434 then (select avg(ss_ext_tax) from store_sales where ss_quantity between 41 and 60) else (select avg(ss_net_paid_inc_tax) from store_sales where ss_quantity between 41 and 60) end bucket3, case when (select count(*) from store_sales where ss_quantity between 61 and 80) > 6568 then (select avg(ss_ext_tax) from store_sales where ss_quantity between 61 and 80) else (select avg(ss_net_paid_inc_tax) from store_sales where ss_quantity between 61 and 80) end bucket4, case when (select count(*) from store_sales where ss_quantity between 81 and 100) > 21216 then (select avg(ss_ext_tax) from store_sales where ss_quantity between 81 and 100) else (select avg(ss_net_paid_inc_tax) from store_sales where ss_quantity between 81 and 100) end bucket5 from reason where r_reason_sk = 1 ;`, }, { Query: ` -- start query 10 in stream 0 using template query10.tpl select cd_gender, cd_marital_status, cd_education_status, count(*) cnt1, cd_purchase_estimate, count(*) cnt2, cd_credit_rating, count(*) cnt3, cd_dep_count, count(*) cnt4, cd_dep_employed_count, count(*) cnt5, cd_dep_college_count, count(*) cnt6 from customer c,customer_address ca,customer_demographics where c.c_current_addr_sk = ca.ca_address_sk and ca_county in ('Fairfield County','Campbell County','Washtenaw County','Escambia County','Cleburne County') and cd_demo_sk = c.c_current_cdemo_sk and exists (select * from store_sales,date_dim where c.c_customer_sk = ss_customer_sk and ss_sold_date_sk = d_date_sk and d_year = 2001 and d_moy between 3 and 3+3) and (exists (select * from web_sales,date_dim where c.c_customer_sk = ws_bill_customer_sk and ws_sold_date_sk = d_date_sk and d_year = 2001 and d_moy between 3 ANd 3+3) or exists (select * from catalog_sales,date_dim where c.c_customer_sk = cs_ship_customer_sk and cs_sold_date_sk = d_date_sk and d_year = 2001 and d_moy between 3 and 3+3)) group by cd_gender, cd_marital_status, cd_education_status, cd_purchase_estimate, cd_credit_rating, cd_dep_count, cd_dep_employed_count, cd_dep_college_count order by cd_gender, cd_marital_status, cd_education_status, cd_purchase_estimate, cd_credit_rating, cd_dep_count, cd_dep_employed_count, cd_dep_college_count limit 100;`, }, { Query: ` -- start query 11 in stream 0 using template query11.tpl with year_total as ( select c_customer_id customer_id ,c_first_name customer_first_name ,c_last_name customer_last_name ,c_preferred_cust_flag customer_preferred_cust_flag ,c_birth_country customer_birth_country ,c_login customer_login ,c_email_address customer_email_address ,d_year dyear ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total ,'s' sale_type from customer ,store_sales ,date_dim where c_customer_sk = ss_customer_sk and ss_sold_date_sk = d_date_sk group by c_customer_id ,c_first_name ,c_last_name ,c_preferred_cust_flag ,c_birth_country ,c_login ,c_email_address ,d_year union all select c_customer_id customer_id ,c_first_name customer_first_name ,c_last_name customer_last_name ,c_preferred_cust_flag customer_preferred_cust_flag ,c_birth_country customer_birth_country ,c_login customer_login ,c_email_address customer_email_address ,d_year dyear ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total ,'w' sale_type from customer ,web_sales ,date_dim where c_customer_sk = ws_bill_customer_sk and ws_sold_date_sk = d_date_sk group by c_customer_id ,c_first_name ,c_last_name ,c_preferred_cust_flag ,c_birth_country ,c_login ,c_email_address ,d_year ) select t_s_secyear.customer_id ,t_s_secyear.customer_first_name ,t_s_secyear.customer_last_name ,t_s_secyear.customer_email_address from year_total t_s_firstyear ,year_total t_s_secyear ,year_total t_w_firstyear ,year_total t_w_secyear where t_s_secyear.customer_id = t_s_firstyear.customer_id and t_s_firstyear.customer_id = t_w_secyear.customer_id and t_s_firstyear.customer_id = t_w_firstyear.customer_id and t_s_firstyear.sale_type = 's' and t_w_firstyear.sale_type = 'w' and t_s_secyear.sale_type = 's' and t_w_secyear.sale_type = 'w' and t_s_firstyear.dyear = 1998 and t_s_secyear.dyear = 1998+1 and t_w_firstyear.dyear = 1998 and t_w_secyear.dyear = 1998+1 and t_s_firstyear.year_total > 0 and t_w_firstyear.year_total > 0 and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end order by t_s_secyear.customer_id ,t_s_secyear.customer_first_name ,t_s_secyear.customer_last_name ,t_s_secyear.customer_email_address limit 100;`, }, { Skip: true, Query: ` -- start query 12 in stream 0 using template query12.tpl select i_item_id ,i_item_desc ,i_category ,i_class ,i_current_price ,sum(ws_ext_sales_price) as itemrevenue ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over (partition by i_class) as revenueratio from web_sales ,item ,date_dim where ws_item_sk = i_item_sk and i_category in ('Men', 'Books', 'Electronics') and ws_sold_date_sk = d_date_sk and d_date between cast('2001-06-15' as date) and (cast('2001-06-15' as date) + interval 30 day) group by i_item_id ,i_item_desc ,i_category ,i_class ,i_current_price order by i_category ,i_class ,i_item_id ,i_item_desc ,revenueratio limit 100;`, }, { Query: ` -- start query 13 in stream 0 using template query13.tpl select avg(ss_quantity) ,avg(ss_ext_sales_price) ,avg(ss_ext_wholesale_cost) ,sum(ss_ext_wholesale_cost) from store_sales ,store ,customer_demographics ,household_demographics ,customer_address ,date_dim where s_store_sk = ss_store_sk and ss_sold_date_sk = d_date_sk and d_year = 2001 and((ss_hdemo_sk=hd_demo_sk and cd_demo_sk = ss_cdemo_sk and cd_marital_status = 'M' and cd_education_status = 'College' and ss_sales_price between 100.00 and 150.00 and hd_dep_count = 3 )or (ss_hdemo_sk=hd_demo_sk and cd_demo_sk = ss_cdemo_sk and cd_marital_status = 'D' and cd_education_status = 'Primary' and ss_sales_price between 50.00 and 100.00 and hd_dep_count = 1 ) or (ss_hdemo_sk=hd_demo_sk and cd_demo_sk = ss_cdemo_sk and cd_marital_status = 'W' and cd_education_status = '2 yr Degree' and ss_sales_price between 150.00 and 200.00 and hd_dep_count = 1 )) and((ss_addr_sk = ca_address_sk and ca_country = 'United States' and ca_state in ('IL', 'TN', 'TX') and ss_net_profit between 100 and 200 ) or (ss_addr_sk = ca_address_sk and ca_country = 'United States' and ca_state in ('WY', 'OH', 'ID') and ss_net_profit between 150 and 300 ) or (ss_addr_sk = ca_address_sk and ca_country = 'United States' and ca_state in ('MS', 'SC', 'IA') and ss_net_profit between 50 and 250 )) ;`, }, { Query: ` -- start query 14 in stream 0 using template query14.tpl with cross_items as (select i_item_sk ss_item_sk from item, (select iss.i_brand_id brand_id ,iss.i_class_id class_id ,iss.i_category_id category_id from store_sales ,item iss ,date_dim d1 where ss_item_sk = iss.i_item_sk and ss_sold_date_sk = d1.d_date_sk and d1.d_year between 1999 AND 1999 + 2 intersect select ics.i_brand_id ,ics.i_class_id ,ics.i_category_id from catalog_sales ,item ics ,date_dim d2 where cs_item_sk = ics.i_item_sk and cs_sold_date_sk = d2.d_date_sk and d2.d_year between 1999 AND 1999 + 2 intersect select iws.i_brand_id ,iws.i_class_id ,iws.i_category_id from web_sales ,item iws ,date_dim d3 where ws_item_sk = iws.i_item_sk and ws_sold_date_sk = d3.d_date_sk and d3.d_year between 1999 AND 1999 + 2) where i_brand_id = brand_id and i_class_id = class_id and i_category_id = category_id ), avg_sales as (select avg(quantity*list_price) average_sales from (select ss_quantity quantity ,ss_list_price list_price from store_sales ,date_dim where ss_sold_date_sk = d_date_sk and d_year between 1999 and 1999 + 2 union all select cs_quantity quantity ,cs_list_price list_price from catalog_sales ,date_dim where cs_sold_date_sk = d_date_sk and d_year between 1999 and 1999 + 2 union all select ws_quantity quantity ,ws_list_price list_price from web_sales ,date_dim where ws_sold_date_sk = d_date_sk and d_year between 1999 and 1999 + 2) x) select channel, i_brand_id,i_class_id,i_category_id,sum(sales), sum(number_sales) from( select 'store' channel, i_brand_id,i_class_id ,i_category_id,sum(ss_quantity*ss_list_price) sales , count(*) number_sales from store_sales ,item ,date_dim where ss_item_sk in (select ss_item_sk from cross_items) and ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk and d_year = 1999+2 and d_moy = 11 group by i_brand_id,i_class_id,i_category_id having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) union all select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales from catalog_sales ,item ,date_dim where cs_item_sk in (select ss_item_sk from cross_items) and cs_item_sk = i_item_sk and cs_sold_date_sk = d_date_sk and d_year = 1999+2 and d_moy = 11 group by i_brand_id,i_class_id,i_category_id having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) union all select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales from web_sales ,item ,date_dim where ws_item_sk in (select ss_item_sk from cross_items) and ws_item_sk = i_item_sk and ws_sold_date_sk = d_date_sk and d_year = 1999+2 and d_moy = 11 group by i_brand_id,i_class_id,i_category_id having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) ) y group by rollup (channel, i_brand_id,i_class_id,i_category_id) order by channel,i_brand_id,i_class_id,i_category_id limit 100; with cross_items as (select i_item_sk ss_item_sk from item, (select iss.i_brand_id brand_id ,iss.i_class_id class_id ,iss.i_category_id category_id from store_sales ,item iss ,date_dim d1 where ss_item_sk = iss.i_item_sk and ss_sold_date_sk = d1.d_date_sk and d1.d_year between 1999 AND 1999 + 2 intersect select ics.i_brand_id ,ics.i_class_id ,ics.i_category_id from catalog_sales ,item ics ,date_dim d2 where cs_item_sk = ics.i_item_sk and cs_sold_date_sk = d2.d_date_sk and d2.d_year between 1999 AND 1999 + 2 intersect select iws.i_brand_id ,iws.i_class_id ,iws.i_category_id from web_sales ,item iws ,date_dim d3 where ws_item_sk = iws.i_item_sk and ws_sold_date_sk = d3.d_date_sk and d3.d_year between 1999 AND 1999 + 2) x where i_brand_id = brand_id and i_class_id = class_id and i_category_id = category_id ), avg_sales as (select avg(quantity*list_price) average_sales from (select ss_quantity quantity ,ss_list_price list_price from store_sales ,date_dim where ss_sold_date_sk = d_date_sk and d_year between 1999 and 1999 + 2 union all select cs_quantity quantity ,cs_list_price list_price from catalog_sales ,date_dim where cs_sold_date_sk = d_date_sk and d_year between 1999 and 1999 + 2 union all select ws_quantity quantity ,ws_list_price list_price from web_sales ,date_dim where ws_sold_date_sk = d_date_sk and d_year between 1999 and 1999 + 2) x) select this_year.channel ty_channel ,this_year.i_brand_id ty_brand ,this_year.i_class_id ty_class ,this_year.i_category_id ty_category ,this_year.sales ty_sales ,this_year.number_sales ty_number_sales ,last_year.channel ly_channel ,last_year.i_brand_id ly_brand ,last_year.i_class_id ly_class ,last_year.i_category_id ly_category ,last_year.sales ly_sales ,last_year.number_sales ly_number_sales from (select 'store' channel, i_brand_id,i_class_id,i_category_id ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales from store_sales ,item ,date_dim where ss_item_sk in (select ss_item_sk from cross_items) and ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk and d_week_seq = (select d_week_seq from date_dim where d_year = 1999 + 1 and d_moy = 12 and d_dom = 3) group by i_brand_id,i_class_id,i_category_id having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, (select 'store' channel, i_brand_id,i_class_id ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales from store_sales ,item ,date_dim where ss_item_sk in (select ss_item_sk from cross_items) and ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk and d_week_seq = (select d_week_seq from date_dim where d_year = 1999 and d_moy = 12 and d_dom = 3) group by i_brand_id,i_class_id,i_category_id having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year where this_year.i_brand_id= last_year.i_brand_id and this_year.i_class_id = last_year.i_class_id and this_year.i_category_id = last_year.i_category_id order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id limit 100;`, Skip: true, }, { Query: ` -- start query 15 in stream 0 using template query15.tpl select ca_zip ,sum(cs_sales_price) from catalog_sales ,customer ,customer_address ,date_dim where cs_bill_customer_sk = c_customer_sk and c_current_addr_sk = ca_address_sk and ( substr(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') or ca_state in ('CA','WA','GA') or cs_sales_price > 500) and cs_sold_date_sk = d_date_sk and d_qoy = 2 and d_year = 2001 group by ca_zip order by ca_zip limit 100;`, }, { Query: ` -- start query 16 in stream 0 using template query16.tpl select count(distinct cs_order_number) as "order count" ,sum(cs_ext_ship_cost) as "total shipping cost" ,sum(cs_net_profit) as "total net profit" from catalog_sales cs1 ,date_dim ,customer_address ,call_center where d_date between '2002-4-01' and (cast('2002-4-01' as date) + interval 60 day) and cs1.cs_ship_date_sk = d_date_sk and cs1.cs_ship_addr_sk = ca_address_sk and ca_state = 'PA' and cs1.cs_call_center_sk = cc_call_center_sk and cc_county in ('Williamson County','Williamson County','Williamson County','Williamson County', 'Williamson County' ) and exists (select * from catalog_sales cs2 where cs1.cs_order_number = cs2.cs_order_number and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) and not exists(select * from catalog_returns cr1 where cs1.cs_order_number = cr1.cr_order_number) order by count(distinct cs_order_number) limit 100;`, }, { Query: ` -- start query 17 in stream 0 using template query17.tpl select i_item_id ,i_item_desc ,s_state ,count(ss_quantity) as store_sales_quantitycount ,avg(ss_quantity) as store_sales_quantityave ,stddev_samp(ss_quantity) as store_sales_quantitystdev ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov ,count(sr_return_quantity) as store_returns_quantitycount ,avg(sr_return_quantity) as store_returns_quantityave ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov from store_sales ,store_returns ,catalog_sales ,date_dim d1 ,date_dim d2 ,date_dim d3 ,store ,item where d1.d_quarter_name = '2001Q1' and d1.d_date_sk = ss_sold_date_sk and i_item_sk = ss_item_sk and s_store_sk = ss_store_sk and ss_customer_sk = sr_customer_sk and ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number and sr_returned_date_sk = d2.d_date_sk and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') and sr_customer_sk = cs_bill_customer_sk and sr_item_sk = cs_item_sk and cs_sold_date_sk = d3.d_date_sk and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') group by i_item_id ,i_item_desc ,s_state order by i_item_id ,i_item_desc ,s_state limit 100;`, }, { Query: ` -- start query 18 in stream 0 using template query18.tpl select i_item_id, ca_country, ca_state, ca_county, avg( cast(cs_quantity as decimal(12,2))) agg1, avg( cast(cs_list_price as decimal(12,2))) agg2, avg( cast(cs_coupon_amt as decimal(12,2))) agg3, avg( cast(cs_sales_price as decimal(12,2))) agg4, avg( cast(cs_net_profit as decimal(12,2))) agg5, avg( cast(c_birth_year as decimal(12,2))) agg6, avg( cast(cd1.cd_dep_count as decimal(12,2))) agg7 from catalog_sales, customer_demographics cd1, customer_demographics cd2, customer, customer_address, date_dim, item where cs_sold_date_sk = d_date_sk and cs_item_sk = i_item_sk and cs_bill_cdemo_sk = cd1.cd_demo_sk and cs_bill_customer_sk = c_customer_sk and cd1.cd_gender = 'F' and cd1.cd_education_status = 'Primary' and c_current_cdemo_sk = cd2.cd_demo_sk and c_current_addr_sk = ca_address_sk and c_birth_month in (1,3,7,11,10,4) and d_year = 2001 and ca_state in ('AL','MO','TN' ,'GA','MT','IN','CA') group by rollup (i_item_id, ca_country, ca_state, ca_county) order by ca_country, ca_state, ca_county, i_item_id limit 100;`, Skip: true, }, { Query: ` -- start query 19 in stream 0 using template query19.tpl select i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, sum(ss_ext_sales_price) ext_price from date_dim, store_sales, item,customer,customer_address,store where d_date_sk = ss_sold_date_sk and ss_item_sk = i_item_sk and i_manager_id=14 and d_moy=11 and d_year=2002 and ss_customer_sk = c_customer_sk and c_current_addr_sk = ca_address_sk and substr(ca_zip,1,5) <> substr(s_zip,1,5) and ss_store_sk = s_store_sk group by i_brand ,i_brand_id ,i_manufact_id ,i_manufact order by ext_price desc ,i_brand ,i_brand_id ,i_manufact_id ,i_manufact limit 100 ;`, }, { Query: ` -- start query 20 in stream 0 using template query20.tpl select i_item_id ,i_item_desc ,i_category ,i_class ,i_current_price ,sum(cs_ext_sales_price) as itemrevenue ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over (partition by i_class) as revenueratio from catalog_sales ,item ,date_dim where cs_item_sk = i_item_sk and i_category in ('Books', 'Music', 'Sports') and cs_sold_date_sk = d_date_sk and d_date between cast('2002-06-18' as date) and (cast('2002-06-18' as date) + interval 30 day) group by i_item_id ,i_item_desc ,i_category ,i_class ,i_current_price order by i_category ,i_class ,i_item_id ,i_item_desc ,revenueratio limit 100;`, }, { Query: ` -- start query 21 in stream 0 using template query21.tpl select * from(select w_warehouse_name ,i_item_id ,sum(case when (cast(d_date as date) < cast ('1999-06-22' as date)) then inv_quantity_on_hand else 0 end) as inv_before ,sum(case when (cast(d_date as date) >= cast ('1999-06-22' as date)) then inv_quantity_on_hand else 0 end) as inv_after from inventory ,warehouse ,item ,date_dim where i_current_price between 0.99 and 1.49 and i_item_sk = inv_item_sk and inv_warehouse_sk = w_warehouse_sk and inv_date_sk = d_date_sk and d_date between (cast ('1999-06-22' as date) - interval 30 day) and (cast ('1999-06-22' as date) + interval 30 day) group by w_warehouse_name, i_item_id) x where (case when inv_before > 0 then inv_after / inv_before else null end) between 2.0/3.0 and 3.0/2.0 order by w_warehouse_name ,i_item_id limit 100;`, }, { Query: ` -- start query 22 in stream 0 using template query22.tpl select i_product_name ,i_brand ,i_class ,i_category ,avg(inv_quantity_on_hand) qoh from inventory ,date_dim ,item where inv_date_sk=d_date_sk and inv_item_sk=i_item_sk and d_month_seq between 1200 and 1200 + 11 group by rollup(i_product_name ,i_brand ,i_class ,i_category) order by qoh, i_product_name, i_brand, i_class, i_category limit 100;`, Skip: true, }, { Query: ` -- start query 23 in stream 0 using template query23.tpl with frequent_ss_items as (select substr(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt from store_sales ,date_dim ,item where ss_sold_date_sk = d_date_sk and ss_item_sk = i_item_sk and d_year in (2000,2000+1,2000+2,2000+3) group by substr(i_item_desc,1,30),i_item_sk,d_date having count(*) >4), max_store_sales as (select max(csales) tpcds_cmax from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales from store_sales ,customer ,date_dim where ss_customer_sk = c_customer_sk and ss_sold_date_sk = d_date_sk and d_year in (2000,2000+1,2000+2,2000+3) group by c_customer_sk)), best_ss_customer as (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales from store_sales ,customer where ss_customer_sk = c_customer_sk group by c_customer_sk having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select * from max_store_sales)) select sum(sales) from (select cs_quantity*cs_list_price sales from catalog_sales ,date_dim where d_year = 2000 and d_moy = 7 and cs_sold_date_sk = d_date_sk and cs_item_sk in (select item_sk from frequent_ss_items) and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) union all select ws_quantity*ws_list_price sales from web_sales ,date_dim where d_year = 2000 and d_moy = 7 and ws_sold_date_sk = d_date_sk and ws_item_sk in (select item_sk from frequent_ss_items) and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) limit 100; with frequent_ss_items as (select substr(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt from store_sales ,date_dim ,item where ss_sold_date_sk = d_date_sk and ss_item_sk = i_item_sk and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) group by substr(i_item_desc,1,30),i_item_sk,d_date having count(*) >4), max_store_sales as (select max(csales) tpcds_cmax from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales from store_sales ,customer ,date_dim where ss_customer_sk = c_customer_sk and ss_sold_date_sk = d_date_sk and d_year in (2000,2000+1,2000+2,2000+3) group by c_customer_sk)), best_ss_customer as (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales from store_sales ,customer where ss_customer_sk = c_customer_sk group by c_customer_sk having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select * from max_store_sales)) select c_last_name,c_first_name,sales from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales from catalog_sales ,customer ,date_dim where d_year = 2000 and d_moy = 7 and cs_sold_date_sk = d_date_sk and cs_item_sk in (select item_sk from frequent_ss_items) and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) and cs_bill_customer_sk = c_customer_sk group by c_last_name,c_first_name union all select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales from web_sales ,customer ,date_dim where d_year = 2000 and d_moy = 7 and ws_sold_date_sk = d_date_sk and ws_item_sk in (select item_sk from frequent_ss_items) and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) and ws_bill_customer_sk = c_customer_sk group by c_last_name,c_first_name) order by c_last_name,c_first_name,sales limit 100;`, }, { Query: ` -- start query 24 in stream 0 using template query24.tpl with ssales as (select c_last_name ,c_first_name ,s_store_name ,ca_state ,s_state ,i_color ,i_current_price ,i_manager_id ,i_units ,i_size ,sum(ss_net_paid) netpaid from store_sales ,store_returns ,store ,item ,customer ,customer_address where ss_ticket_number = sr_ticket_number and ss_item_sk = sr_item_sk and ss_customer_sk = c_customer_sk and ss_item_sk = i_item_sk and ss_store_sk = s_store_sk and c_current_addr_sk = ca_address_sk and c_birth_country <> upper(ca_country) and s_zip = ca_zip and s_market_id=5 group by c_last_name ,c_first_name ,s_store_name ,ca_state ,s_state ,i_color ,i_current_price ,i_manager_id ,i_units ,i_size) select c_last_name ,c_first_name ,s_store_name ,sum(netpaid) paid from ssales where i_color = 'aquamarine' group by c_last_name ,c_first_name ,s_store_name having sum(netpaid) > (select 0.05*avg(netpaid) from ssales) order by c_last_name ,c_first_name ,s_store_name ; with ssales as (select c_last_name ,c_first_name ,s_store_name ,ca_state ,s_state ,i_color ,i_current_price ,i_manager_id ,i_units ,i_size ,sum(ss_net_paid) netpaid from store_sales ,store_returns ,store ,item ,customer ,customer_address where ss_ticket_number = sr_ticket_number and ss_item_sk = sr_item_sk and ss_customer_sk = c_customer_sk and ss_item_sk = i_item_sk and ss_store_sk = s_store_sk and c_current_addr_sk = ca_address_sk and c_birth_country <> upper(ca_country) and s_zip = ca_zip and s_market_id = 5 group by c_last_name ,c_first_name ,s_store_name ,ca_state ,s_state ,i_color ,i_current_price ,i_manager_id ,i_units ,i_size) select c_last_name ,c_first_name ,s_store_name ,sum(netpaid) paid from ssales where i_color = 'seashell' group by c_last_name ,c_first_name ,s_store_name having sum(netpaid) > (select 0.05*avg(netpaid) from ssales) order by c_last_name ,c_first_name ,s_store_name ;`, }, { Query: ` -- start query 25 in stream 0 using template query25.tpl select i_item_id ,i_item_desc ,s_store_id ,s_store_name ,max(ss_net_profit) as store_sales_profit ,max(sr_net_loss) as store_returns_loss ,max(cs_net_profit) as catalog_sales_profit from store_sales ,store_returns ,catalog_sales ,date_dim d1 ,date_dim d2 ,date_dim d3 ,store ,item where d1.d_moy = 4 and d1.d_year = 1999 and d1.d_date_sk = ss_sold_date_sk and i_item_sk = ss_item_sk and s_store_sk = ss_store_sk and ss_customer_sk = sr_customer_sk and ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number and sr_returned_date_sk = d2.d_date_sk and d2.d_moy between 4 and 10 and d2.d_year = 1999 and sr_customer_sk = cs_bill_customer_sk and sr_item_sk = cs_item_sk and cs_sold_date_sk = d3.d_date_sk and d3.d_moy between 4 and 10 and d3.d_year = 1999 group by i_item_id ,i_item_desc ,s_store_id ,s_store_name order by i_item_id ,i_item_desc ,s_store_id ,s_store_name limit 100;`, }, { Query: ` -- start query 26 in stream 0 using template query26.tpl select i_item_id, avg(cs_quantity) agg1, avg(cs_list_price) agg2, avg(cs_coupon_amt) agg3, avg(cs_sales_price) agg4 from catalog_sales, customer_demographics, date_dim, item, promotion where cs_sold_date_sk = d_date_sk and cs_item_sk = i_item_sk and cs_bill_cdemo_sk = cd_demo_sk and cs_promo_sk = p_promo_sk and cd_gender = 'M' and cd_marital_status = 'W' and cd_education_status = 'Unknown' and (p_channel_email = 'N' or p_channel_event = 'N') and d_year = 2002 group by i_item_id order by i_item_id limit 100;`, }, { Query: ` -- start query 27 in stream 0 using template query27.tpl select i_item_id, s_state, grouping(s_state) g_state, avg(ss_quantity) agg1, avg(ss_list_price) agg2, avg(ss_coupon_amt) agg3, avg(ss_sales_price) agg4 from store_sales, customer_demographics, date_dim, store, item where ss_sold_date_sk = d_date_sk and ss_item_sk = i_item_sk and ss_store_sk = s_store_sk and ss_cdemo_sk = cd_demo_sk and cd_gender = 'M' and cd_marital_status = 'W' and cd_education_status = 'Secondary' and d_year = 1999 and s_state in ('TN','TN', 'TN', 'TN', 'TN', 'TN') group by rollup (i_item_id, s_state) order by i_item_id ,s_state limit 100;`, Skip: true, }, { Query: ` -- start query 28 in stream 0 using template query28.tpl select * from (select avg(ss_list_price) B1_LP ,count(ss_list_price) B1_CNT ,count(distinct ss_list_price) B1_CNTD from store_sales where ss_quantity between 0 and 5 and (ss_list_price between 107 and 107+10 or ss_coupon_amt between 1319 and 1319+1000 or ss_wholesale_cost between 60 and 60+20)) B1, (select avg(ss_list_price) B2_LP ,count(ss_list_price) B2_CNT ,count(distinct ss_list_price) B2_CNTD from store_sales where ss_quantity between 6 and 10 and (ss_list_price between 23 and 23+10 or ss_coupon_amt between 825 and 825+1000 or ss_wholesale_cost between 43 and 43+20)) B2, (select avg(ss_list_price) B3_LP ,count(ss_list_price) B3_CNT ,count(distinct ss_list_price) B3_CNTD from store_sales where ss_quantity between 11 and 15 and (ss_list_price between 74 and 74+10 or ss_coupon_amt between 4381 and 4381+1000 or ss_wholesale_cost between 57 and 57+20)) B3, (select avg(ss_list_price) B4_LP ,count(ss_list_price) B4_CNT ,count(distinct ss_list_price) B4_CNTD from store_sales where ss_quantity between 16 and 20 and (ss_list_price between 89 and 89+10 or ss_coupon_amt between 3117 and 3117+1000 or ss_wholesale_cost between 68 and 68+20)) B4, (select avg(ss_list_price) B5_LP ,count(ss_list_price) B5_CNT ,count(distinct ss_list_price) B5_CNTD from store_sales where ss_quantity between 21 and 25 and (ss_list_price between 58 and 58+10 or ss_coupon_amt between 9402 and 9402+1000 or ss_wholesale_cost between 38 and 38+20)) B5, (select avg(ss_list_price) B6_LP ,count(ss_list_price) B6_CNT ,count(distinct ss_list_price) B6_CNTD from store_sales where ss_quantity between 26 and 30 and (ss_list_price between 64 and 64+10 or ss_coupon_amt between 5792 and 5792+1000 or ss_wholesale_cost between 73 and 73+20)) B6 limit 100;`, }, { Query: ` -- start query 29 in stream 0 using template query29.tpl select i_item_id ,i_item_desc ,s_store_id ,s_store_name ,max(ss_quantity) as store_sales_quantity ,max(sr_return_quantity) as store_returns_quantity ,max(cs_quantity) as catalog_sales_quantity from store_sales ,store_returns ,catalog_sales ,date_dim d1 ,date_dim d2 ,date_dim d3 ,store ,item where d1.d_moy = 4 and d1.d_year = 1998 and d1.d_date_sk = ss_sold_date_sk and i_item_sk = ss_item_sk and s_store_sk = ss_store_sk and ss_customer_sk = sr_customer_sk and ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number and sr_returned_date_sk = d2.d_date_sk and d2.d_moy between 4 and 4 + 3 and d2.d_year = 1998 and sr_customer_sk = cs_bill_customer_sk and sr_item_sk = cs_item_sk and cs_sold_date_sk = d3.d_date_sk and d3.d_year in (1998,1998+1,1998+2) group by i_item_id ,i_item_desc ,s_store_id ,s_store_name order by i_item_id ,i_item_desc ,s_store_id ,s_store_name limit 100;`, }, { Query: ` -- start query 30 in stream 0 using template query30.tpl with customer_total_return as (select wr_returning_customer_sk as ctr_customer_sk ,ca_state as ctr_state, sum(wr_return_amt) as ctr_total_return from web_returns ,date_dim ,customer_address where wr_returned_date_sk = d_date_sk and d_year =2000 and wr_returning_addr_sk = ca_address_sk group by wr_returning_customer_sk ,ca_state) select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address ,c_last_review_date_sk,ctr_total_return from customer_total_return ctr1 ,customer_address ,customer where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 from customer_total_return ctr2 where ctr1.ctr_state = ctr2.ctr_state) and ca_address_sk = c_current_addr_sk and ca_state = 'AR' and ctr1.ctr_customer_sk = c_customer_sk order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address ,c_last_review_date_sk,ctr_total_return limit 100;`, }, { Query: ` -- start query 31 in stream 0 using template query31.tpl with ss as (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales from store_sales,date_dim,customer_address where ss_sold_date_sk = d_date_sk and ss_addr_sk=ca_address_sk group by ca_county,d_qoy, d_year), ws as (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales from web_sales,date_dim,customer_address where ws_sold_date_sk = d_date_sk and ws_bill_addr_sk=ca_address_sk group by ca_county,d_qoy, d_year) select ss1.ca_county ,ss1.d_year ,ws2.web_sales/ws1.web_sales web_q1_q2_increase ,ss2.store_sales/ss1.store_sales store_q1_q2_increase ,ws3.web_sales/ws2.web_sales web_q2_q3_increase ,ss3.store_sales/ss2.store_sales store_q2_q3_increase from ss ss1 ,ss ss2 ,ss ss3 ,ws ws1 ,ws ws2 ,ws ws3 where ss1.d_qoy = 1 and ss1.d_year = 1999 and ss1.ca_county = ss2.ca_county and ss2.d_qoy = 2 and ss2.d_year = 1999 and ss2.ca_county = ss3.ca_county and ss3.d_qoy = 3 and ss3.d_year = 1999 and ss1.ca_county = ws1.ca_county and ws1.d_qoy = 1 and ws1.d_year = 1999 and ws1.ca_county = ws2.ca_county and ws2.d_qoy = 2 and ws2.d_year = 1999 and ws1.ca_county = ws3.ca_county and ws3.d_qoy = 3 and ws3.d_year =1999 and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end order by store_q2_q3_increase;`, }, { Query: ` -- start query 32 in stream 0 using template query32.tpl select sum(cs_ext_discount_amt) as "excess discount amount" from catalog_sales ,item ,date_dim where i_manufact_id = 722 and i_item_sk = cs_item_sk and d_date between '2001-03-09' and (cast('2001-03-09' as date) + interval 90 day) and d_date_sk = cs_sold_date_sk and cs_ext_discount_amt > ( select 1.3 * avg(cs_ext_discount_amt) from catalog_sales ,date_dim where cs_item_sk = i_item_sk and d_date between '2001-03-09' and (cast('2001-03-09' as date) + interval 90 day) and d_date_sk = cs_sold_date_sk ) limit 100;`, }, { Query: ` -- start query 33 in stream 0 using template query33.tpl with ss as ( select i_manufact_id,sum(ss_ext_sales_price) total_sales from store_sales, date_dim, customer_address, item where i_manufact_id in (select i_manufact_id from item where i_category in ('Books')) and ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk and d_year = 2001 and d_moy = 3 and ss_addr_sk = ca_address_sk and ca_gmt_offset = -5 group by i_manufact_id), cs as ( select i_manufact_id,sum(cs_ext_sales_price) total_sales from catalog_sales, date_dim, customer_address, item where i_manufact_id in (select i_manufact_id from item where i_category in ('Books')) and cs_item_sk = i_item_sk and cs_sold_date_sk = d_date_sk and d_year = 2001 and d_moy = 3 and cs_bill_addr_sk = ca_address_sk and ca_gmt_offset = -5 group by i_manufact_id), ws as ( select i_manufact_id,sum(ws_ext_sales_price) total_sales from web_sales, date_dim, customer_address, item where i_manufact_id in (select i_manufact_id from item where i_category in ('Books')) and ws_item_sk = i_item_sk and ws_sold_date_sk = d_date_sk and d_year = 2001 and d_moy = 3 and ws_bill_addr_sk = ca_address_sk and ca_gmt_offset = -5 group by i_manufact_id) select i_manufact_id ,sum(total_sales) total_sales from (select * from ss union all select * from cs union all select * from ws) tmp1 group by i_manufact_id order by total_sales limit 100;`, }, { Query: ` -- start query 34 in stream 0 using template query34.tpl select c_last_name ,c_first_name ,c_salutation ,c_preferred_cust_flag ,ss_ticket_number ,cnt from (select ss_ticket_number ,ss_customer_sk ,count(*) cnt from store_sales,date_dim,store,household_demographics where store_sales.ss_sold_date_sk = date_dim.d_date_sk and store_sales.ss_store_sk = store.s_store_sk and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) and (household_demographics.hd_buy_potential = '1001-5000' or household_demographics.hd_buy_potential = '0-500') and household_demographics.hd_vehicle_count > 0 and (case when household_demographics.hd_vehicle_count > 0 then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end) > 1.2 and date_dim.d_year in (2000,2000+1,2000+2) and store.s_county in ('Williamson County','Williamson County','Williamson County','Williamson County', 'Williamson County','Williamson County','Williamson County','Williamson County') group by ss_ticket_number,ss_customer_sk) dn,customer where ss_customer_sk = c_customer_sk and cnt between 15 and 20 order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number;`, }, { Query: ` -- start query 35 in stream 0 using template query35.tpl select ca_state, cd_gender, cd_marital_status, cd_dep_count, count(*) cnt1, avg(cd_dep_count), stddev_samp(cd_dep_count), sum(cd_dep_count), cd_dep_employed_count, count(*) cnt2, avg(cd_dep_employed_count), stddev_samp(cd_dep_employed_count), sum(cd_dep_employed_count), cd_dep_college_count, count(*) cnt3, avg(cd_dep_college_count), stddev_samp(cd_dep_college_count), sum(cd_dep_college_count) from customer c,customer_address ca,customer_demographics where c.c_current_addr_sk = ca.ca_address_sk and cd_demo_sk = c.c_current_cdemo_sk and exists (select * from store_sales,date_dim where c.c_customer_sk = ss_customer_sk and ss_sold_date_sk = d_date_sk and d_year = 1999 and d_qoy < 4) and (exists (select * from web_sales,date_dim where c.c_customer_sk = ws_bill_customer_sk and ws_sold_date_sk = d_date_sk and d_year = 1999 and d_qoy < 4) or exists (select * from catalog_sales,date_dim where c.c_customer_sk = cs_ship_customer_sk and cs_sold_date_sk = d_date_sk and d_year = 1999 and d_qoy < 4)) group by ca_state, cd_gender, cd_marital_status, cd_dep_count, cd_dep_employed_count, cd_dep_college_count order by ca_state, cd_gender, cd_marital_status, cd_dep_count, cd_dep_employed_count, cd_dep_college_count limit 100;`, }, { Query: ` -- start query 36 in stream 0 using template query36.tpl select sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin ,i_category ,i_class ,grouping(i_category)+grouping(i_class) as lochierarchy ,rank() over ( partition by grouping(i_category)+grouping(i_class), case when grouping(i_class) = 0 then i_category end order by sum(ss_net_profit)/sum(ss_ext_sales_price) asc) as rank_within_parent from store_sales ,date_dim d1 ,item ,store where d1.d_year = 2000 and d1.d_date_sk = ss_sold_date_sk and i_item_sk = ss_item_sk and s_store_sk = ss_store_sk and s_state in ('TN','TN','TN','TN', 'TN','TN','TN','TN') group by rollup(i_category,i_class) order by lochierarchy desc ,case when lochierarchy = 0 then i_category end ,rank_within_parent limit 100;`, Skip: true, }, { Query: ` -- start query 37 in stream 0 using template query37.tpl select i_item_id ,i_item_desc ,i_current_price from item, inventory, date_dim, catalog_sales where i_current_price between 29 and 29 + 30 and inv_item_sk = i_item_sk and d_date_sk=inv_date_sk and d_date between cast('2002-03-29' as date) and (cast('2002-03-29' as date) + interval 60 day) and i_manufact_id in (705,742,777,944) and inv_quantity_on_hand between 100 and 500 and cs_item_sk = i_item_sk group by i_item_id,i_item_desc,i_current_price order by i_item_id limit 100;`, }, { Query: ` -- start query 38 in stream 0 using template query38.tpl select count(*) from ( select distinct c_last_name, c_first_name, d_date from store_sales, date_dim, customer where store_sales.ss_sold_date_sk = date_dim.d_date_sk and store_sales.ss_customer_sk = customer.c_customer_sk and d_month_seq between 1189 and 1189 + 11 intersect select distinct c_last_name, c_first_name, d_date from catalog_sales, date_dim, customer where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk and d_month_seq between 1189 and 1189 + 11 intersect select distinct c_last_name, c_first_name, d_date from web_sales, date_dim, customer where web_sales.ws_sold_date_sk = date_dim.d_date_sk and web_sales.ws_bill_customer_sk = customer.c_customer_sk and d_month_seq between 1189 and 1189 + 11 ) hot_cust limit 100;`, }, { Query: ` -- start query 39 in stream 0 using template query39.tpl with inv as (select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy ,stdev,mean, case mean when 0 then null else stdev/mean end cov from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean from inventory ,item ,warehouse ,date_dim where inv_item_sk = i_item_sk and inv_warehouse_sk = w_warehouse_sk and inv_date_sk = d_date_sk and d_year =2000 group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo where case mean when 0 then 0 else stdev/mean end > 1) select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov from inv inv1,inv inv2 where inv1.i_item_sk = inv2.i_item_sk and inv1.w_warehouse_sk = inv2.w_warehouse_sk and inv1.d_moy=1 and inv2.d_moy=1+1 order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov ,inv2.d_moy,inv2.mean, inv2.cov ; with inv as (select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy ,stdev,mean, case mean when 0 then null else stdev/mean end cov from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean from inventory ,item ,warehouse ,date_dim where inv_item_sk = i_item_sk and inv_warehouse_sk = w_warehouse_sk and inv_date_sk = d_date_sk and d_year =2000 group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo where case mean when 0 then 0 else stdev/mean end > 1) select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov from inv inv1,inv inv2 where inv1.i_item_sk = inv2.i_item_sk and inv1.w_warehouse_sk = inv2.w_warehouse_sk and inv1.d_moy=1 and inv2.d_moy=1+1 and inv1.cov > 1.5 order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov ,inv2.d_moy,inv2.mean, inv2.cov ;`, }, { Query: ` -- start query 40 in stream 0 using template query40.tpl select w_state ,i_item_id ,sum(case when (cast(d_date as date) < cast ('2001-05-02' as date)) then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before ,sum(case when (cast(d_date as date) >= cast ('2001-05-02' as date)) then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after from catalog_sales left outer join catalog_returns on (cs_order_number = cr_order_number and cs_item_sk = cr_item_sk) ,warehouse ,item ,date_dim where i_current_price between 0.99 and 1.49 and i_item_sk = cs_item_sk and cs_warehouse_sk = w_warehouse_sk and cs_sold_date_sk = d_date_sk and d_date between (cast ('2001-05-02' as date) - interval 30 day) and (cast ('2001-05-02' as date) + interval 30 day) group by w_state,i_item_id order by w_state,i_item_id limit 100;`, }, { Query: ` -- start query 41 in stream 0 using template query41.tpl select distinct(i_product_name) from item i1 where i_manufact_id between 704 and 704+40 and (select count(*) as item_cnt from item where (i_manufact = i1.i_manufact and ((i_category = 'Women' and (i_color = 'forest' or i_color = 'lime') and (i_units = 'Pallet' or i_units = 'Pound') and (i_size = 'economy' or i_size = 'small') ) or (i_category = 'Women' and (i_color = 'navy' or i_color = 'slate') and (i_units = 'Gross' or i_units = 'Bunch') and (i_size = 'extra large' or i_size = 'petite') ) or (i_category = 'Men' and (i_color = 'powder' or i_color = 'sky') and (i_units = 'Dozen' or i_units = 'Lb') and (i_size = 'N/A' or i_size = 'large') ) or (i_category = 'Men' and (i_color = 'maroon' or i_color = 'smoke') and (i_units = 'Ounce' or i_units = 'Case') and (i_size = 'economy' or i_size = 'small') ))) or (i_manufact = i1.i_manufact and ((i_category = 'Women' and (i_color = 'dark' or i_color = 'aquamarine') and (i_units = 'Ton' or i_units = 'Tbl') and (i_size = 'economy' or i_size = 'small') ) or (i_category = 'Women' and (i_color = 'frosted' or i_color = 'plum') and (i_units = 'Dram' or i_units = 'Box') and (i_size = 'extra large' or i_size = 'petite') ) or (i_category = 'Men' and (i_color = 'papaya' or i_color = 'peach') and (i_units = 'Bundle' or i_units = 'Carton') and (i_size = 'N/A' or i_size = 'large') ) or (i_category = 'Men' and (i_color = 'firebrick' or i_color = 'sienna') and (i_units = 'Cup' or i_units = 'Each') and (i_size = 'economy' or i_size = 'small') )))) > 0 order by i_product_name limit 100;`, }, { Query: ` -- start query 42 in stream 0 using template query42.tpl select dt.d_year ,item.i_category_id ,item.i_category ,sum(ss_ext_sales_price) from date_dim dt ,store_sales ,item where dt.d_date_sk = store_sales.ss_sold_date_sk and store_sales.ss_item_sk = item.i_item_sk and item.i_manager_id = 1 and dt.d_moy=11 and dt.d_year=1998 group by dt.d_year ,item.i_category_id ,item.i_category order by sum(ss_ext_sales_price) desc,dt.d_year ,item.i_category_id ,item.i_category limit 100 ;`, }, { Query: ` -- start query 43 in stream 0 using template query43.tpl select s_store_name, s_store_id, sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales from date_dim, store_sales, store where d_date_sk = ss_sold_date_sk and s_store_sk = ss_store_sk and s_gmt_offset = -5 and d_year = 2000 group by s_store_name, s_store_id order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales limit 100;`, }, { Query: ` -- start query 44 in stream 0 using template query44.tpl select asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing from(select * from (select item_sk,rank() over (order by rank_col asc) rnk from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col from store_sales ss1 where ss_store_sk = 4 group by ss_item_sk having avg(ss_net_profit) > 0.9*(select avg(ss_net_profit) rank_col from store_sales where ss_store_sk = 4 and ss_hdemo_sk is null group by ss_store_sk))V1)V11 where rnk < 11) asceding, (select * from (select item_sk,rank() over (order by rank_col desc) rnk from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col from store_sales ss1 where ss_store_sk = 4 group by ss_item_sk having avg(ss_net_profit) > 0.9*(select avg(ss_net_profit) rank_col from store_sales where ss_store_sk = 4 and ss_hdemo_sk is null group by ss_store_sk))V2)V21 where rnk < 11) descending, item i1, item i2 where asceding.rnk = descending.rnk and i1.i_item_sk=asceding.item_sk and i2.i_item_sk=descending.item_sk order by asceding.rnk limit 100;`, }, { Query: ` -- start query 45 in stream 0 using template query45.tpl select ca_zip, ca_city, sum(ws_sales_price) from web_sales, customer, customer_address, date_dim, item where ws_bill_customer_sk = c_customer_sk and c_current_addr_sk = ca_address_sk and ws_item_sk = i_item_sk and ( substr(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') or i_item_id in (select i_item_id from item where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) ) ) and ws_sold_date_sk = d_date_sk and d_qoy = 1 and d_year = 2000 group by ca_zip, ca_city order by ca_zip, ca_city limit 100;`, }, { Query: ` -- start query 46 in stream 0 using template query46.tpl select c_last_name ,c_first_name ,ca_city ,bought_city ,ss_ticket_number ,amt,profit from (select ss_ticket_number ,ss_customer_sk ,ca_city bought_city ,sum(ss_coupon_amt) amt ,sum(ss_net_profit) profit from store_sales,date_dim,store,household_demographics,customer_address where store_sales.ss_sold_date_sk = date_dim.d_date_sk and store_sales.ss_store_sk = store.s_store_sk and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk and store_sales.ss_addr_sk = customer_address.ca_address_sk and (household_demographics.hd_dep_count = 8 or household_demographics.hd_vehicle_count= 0) and date_dim.d_dow in (6,0) and date_dim.d_year in (2000,2000+1,2000+2) and store.s_city in ('Midway','Fairview','Fairview','Fairview','Fairview') group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr where ss_customer_sk = c_customer_sk and customer.c_current_addr_sk = current_addr.ca_address_sk and current_addr.ca_city <> bought_city order by c_last_name ,c_first_name ,ca_city ,bought_city ,ss_ticket_number limit 100;`, }, { Query: ` -- start query 47 in stream 0 using template query47.tpl with v1 as( select i_category, i_brand, s_store_name, s_company_name, d_year, d_moy, sum(ss_sales_price) sum_sales, avg(sum(ss_sales_price)) over (partition by i_category, i_brand, s_store_name, s_company_name, d_year) avg_monthly_sales, rank() over (partition by i_category, i_brand, s_store_name, s_company_name order by d_year, d_moy) rn from item, store_sales, date_dim, store where ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk and ss_store_sk = s_store_sk and ( d_year = 2000 or ( d_year = 2000-1 and d_moy =12) or ( d_year = 2000+1 and d_moy =1) ) group by i_category, i_brand, s_store_name, s_company_name, d_year, d_moy), v2 as( select v1.s_store_name, v1.s_company_name ,v1.d_year ,v1.avg_monthly_sales ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum from v1, v1 v1_lag, v1 v1_lead where v1.i_category = v1_lag.i_category and v1.i_category = v1_lead.i_category and v1.i_brand = v1_lag.i_brand and v1.i_brand = v1_lead.i_brand and v1.s_store_name = v1_lag.s_store_name and v1.s_store_name = v1_lead.s_store_name and v1.s_company_name = v1_lag.s_company_name and v1.s_company_name = v1_lead.s_company_name and v1.rn = v1_lag.rn + 1 and v1.rn = v1_lead.rn - 1) select * from v2 where d_year = 2000 and avg_monthly_sales > 0 and case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 order by sum_sales - avg_monthly_sales, nsum limit 100;`, }, { Query: ` -- start query 48 in stream 0 using template query48.tpl select sum (ss_quantity) from store_sales, store, customer_demographics, customer_address, date_dim where s_store_sk = ss_store_sk and ss_sold_date_sk = d_date_sk and d_year = 2001 and ( ( cd_demo_sk = ss_cdemo_sk and cd_marital_status = 'S' and cd_education_status = 'Secondary' and ss_sales_price between 100.00 and 150.00 ) or ( cd_demo_sk = ss_cdemo_sk and cd_marital_status = 'M' and cd_education_status = '2 yr Degree' and ss_sales_price between 50.00 and 100.00 ) or ( cd_demo_sk = ss_cdemo_sk and cd_marital_status = 'D' and cd_education_status = 'Advanced Degree' and ss_sales_price between 150.00 and 200.00 ) ) and ( ( ss_addr_sk = ca_address_sk and ca_country = 'United States' and ca_state in ('ND', 'NY', 'SD') and ss_net_profit between 0 and 2000 ) or (ss_addr_sk = ca_address_sk and ca_country = 'United States' and ca_state in ('MD', 'GA', 'KS') and ss_net_profit between 150 and 3000 ) or (ss_addr_sk = ca_address_sk and ca_country = 'United States' and ca_state in ('CO', 'MN', 'NC') and ss_net_profit between 50 and 25000 ) ) ;`, }, { Query: ` -- start query 49 in stream 0 using template query49.tpl select channel, item, return_ratio, return_rank, currency_rank from (select 'web' as channel ,web.item ,web.return_ratio ,web.return_rank ,web.currency_rank from ( select item ,return_ratio ,currency_ratio ,rank() over (order by return_ratio) as return_rank ,rank() over (order by currency_ratio) as currency_rank from ( select ws.ws_item_sk as item ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio from web_sales ws left outer join web_returns wr on (ws.ws_order_number = wr.wr_order_number and ws.ws_item_sk = wr.wr_item_sk) ,date_dim where wr.wr_return_amt > 10000 and ws.ws_net_profit > 1 and ws.ws_net_paid > 0 and ws.ws_quantity > 0 and ws_sold_date_sk = d_date_sk and d_year = 1998 and d_moy = 11 group by ws.ws_item_sk ) in_web ) web where ( web.return_rank <= 10 or web.currency_rank <= 10 ) union select 'catalog' as channel ,catalog.item ,catalog.return_ratio ,catalog.return_rank ,catalog.currency_rank from ( select item ,return_ratio ,currency_ratio ,rank() over (order by return_ratio) as return_rank ,rank() over (order by currency_ratio) as currency_rank from ( select cs.cs_item_sk as item ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio from catalog_sales cs left outer join catalog_returns cr on (cs.cs_order_number = cr.cr_order_number and cs.cs_item_sk = cr.cr_item_sk) ,date_dim where cr.cr_return_amount > 10000 and cs.cs_net_profit > 1 and cs.cs_net_paid > 0 and cs.cs_quantity > 0 and cs_sold_date_sk = d_date_sk and d_year = 1998 and d_moy = 11 group by cs.cs_item_sk ) in_cat ) catalog where ( catalog.return_rank <= 10 or catalog.currency_rank <=10 ) union select 'store' as channel ,store.item ,store.return_ratio ,store.return_rank ,store.currency_rank from ( select item ,return_ratio ,currency_ratio ,rank() over (order by return_ratio) as return_rank ,rank() over (order by currency_ratio) as currency_rank from ( select sts.ss_item_sk as item ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio from store_sales sts left outer join store_returns sr on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) ,date_dim where sr.sr_return_amt > 10000 and sts.ss_net_profit > 1 and sts.ss_net_paid > 0 and sts.ss_quantity > 0 and ss_sold_date_sk = d_date_sk and d_year = 1998 and d_moy = 11 group by sts.ss_item_sk ) in_store ) store where ( store.return_rank <= 10 or store.currency_rank <= 10 ) ) order by 1,4,5,2 limit 100;`, }, { Query: ` -- start query 50 in stream 0 using template query50.tpl select s_store_name ,s_company_id ,s_street_number ,s_street_name ,s_street_type ,s_suite_number ,s_city ,s_county ,s_state ,s_zip ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" from store_sales ,store_returns ,store ,date_dim d1 ,date_dim d2 where d2.d_year = 2001 and d2.d_moy = 8 and ss_ticket_number = sr_ticket_number and ss_item_sk = sr_item_sk and ss_sold_date_sk = d1.d_date_sk and sr_returned_date_sk = d2.d_date_sk and ss_customer_sk = sr_customer_sk and ss_store_sk = s_store_sk group by s_store_name ,s_company_id ,s_street_number ,s_street_name ,s_street_type ,s_suite_number ,s_city ,s_county ,s_state ,s_zip order by s_store_name ,s_company_id ,s_street_number ,s_street_name ,s_street_type ,s_suite_number ,s_city ,s_county ,s_state ,s_zip limit 100;`, }, { Query: ` -- start query 51 in stream 0 using template query51.tpl WITH web_v1 as ( select ws_item_sk item_sk, d_date, sum(sum(ws_sales_price)) over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales from web_sales ,date_dim where ws_sold_date_sk=d_date_sk and d_month_seq between 1212 and 1212+11 and ws_item_sk is not NULL group by ws_item_sk, d_date), store_v1 as ( select ss_item_sk item_sk, d_date, sum(sum(ss_sales_price)) over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales from store_sales ,date_dim where ss_sold_date_sk=d_date_sk and d_month_seq between 1212 and 1212+11 and ss_item_sk is not NULL group by ss_item_sk, d_date) select * from (select item_sk ,d_date ,web_sales ,store_sales ,max(web_sales) over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative ,max(store_sales) over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk ,case when web.d_date is not null then web.d_date else store.d_date end d_date ,web.cume_sales web_sales ,store.cume_sales store_sales from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk and web.d_date = store.d_date) )x )y where web_cumulative > store_cumulative order by item_sk ,d_date limit 100;`, }, { Query: ` -- start query 52 in stream 0 using template query52.tpl select dt.d_year ,item.i_brand_id brand_id ,item.i_brand brand ,sum(ss_ext_sales_price) ext_price from date_dim dt ,store_sales ,item where dt.d_date_sk = store_sales.ss_sold_date_sk and store_sales.ss_item_sk = item.i_item_sk and item.i_manager_id = 1 and dt.d_moy=12 and dt.d_year=2000 group by dt.d_year ,item.i_brand ,item.i_brand_id order by dt.d_year ,ext_price desc ,brand_id limit 100 ;`, }, { Query: ` -- start query 53 in stream 0 using template query53.tpl select * from (select i_manufact_id, sum(ss_sales_price) sum_sales, avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales from item, store_sales, date_dim, store where ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk and ss_store_sk = s_store_sk and d_month_seq in (1186,1186+1,1186+2,1186+3,1186+4,1186+5,1186+6,1186+7,1186+8,1186+9,1186+10,1186+11) and ((i_category in ('Books','Children','Electronics') and i_class in ('personal','portable','reference','self-help') and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', 'exportiunivamalg #9','scholaramalgamalg #9')) or(i_category in ('Women','Music','Men') and i_class in ('accessories','classical','fragrances','pants') and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', 'importoamalg #1'))) group by i_manufact_id, d_qoy ) tmp1 where case when avg_quarterly_sales > 0 then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales else null end > 0.1 order by avg_quarterly_sales, sum_sales, i_manufact_id limit 100;`, }, { Query: ` -- start query 54 in stream 0 using template query54.tpl with my_customers as ( select distinct c_customer_sk , c_current_addr_sk from ( select cs_sold_date_sk sold_date_sk, cs_bill_customer_sk customer_sk, cs_item_sk item_sk from catalog_sales union all select ws_sold_date_sk sold_date_sk, ws_bill_customer_sk customer_sk, ws_item_sk item_sk from web_sales ) cs_or_ws_sales, item, date_dim, customer where sold_date_sk = d_date_sk and item_sk = i_item_sk and i_category = 'Music' and i_class = 'country' and c_customer_sk = cs_or_ws_sales.customer_sk and d_moy = 1 and d_year = 1999 ) , my_revenue as ( select c_customer_sk, sum(ss_ext_sales_price) as revenue from my_customers, store_sales, customer_address, store, date_dim where c_current_addr_sk = ca_address_sk and ca_county = s_county and ca_state = s_state and ss_sold_date_sk = d_date_sk and c_customer_sk = ss_customer_sk and d_month_seq between (select distinct d_month_seq+1 from date_dim where d_year = 1999 and d_moy = 1) and (select distinct d_month_seq+3 from date_dim where d_year = 1999 and d_moy = 1) group by c_customer_sk ) , segments as (select cast((revenue/50) as int) as segment from my_revenue ) select segment, count(*) as num_customers, segment*50 as segment_base from segments group by segment order by segment, num_customers limit 100;`, }, { Query: ` -- start query 55 in stream 0 using template query55.tpl select i_brand_id brand_id, i_brand brand, sum(ss_ext_sales_price) ext_price from date_dim, store_sales, item where d_date_sk = ss_sold_date_sk and ss_item_sk = i_item_sk and i_manager_id=52 and d_moy=11 and d_year=2000 group by i_brand, i_brand_id order by ext_price desc, i_brand_id limit 100 ;`, }, { Query: ` -- start query 56 in stream 0 using template query56.tpl with ss as ( select i_item_id,sum(ss_ext_sales_price) total_sales from store_sales, date_dim, customer_address, item where i_item_id in (select i_item_id from item where i_color in ('powder','orchid','pink')) and ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk and d_year = 2000 and d_moy = 3 and ss_addr_sk = ca_address_sk and ca_gmt_offset = -6 group by i_item_id), cs as ( select i_item_id,sum(cs_ext_sales_price) total_sales from catalog_sales, date_dim, customer_address, item where i_item_id in (select i_item_id from item where i_color in ('powder','orchid','pink')) and cs_item_sk = i_item_sk and cs_sold_date_sk = d_date_sk and d_year = 2000 and d_moy = 3 and cs_bill_addr_sk = ca_address_sk and ca_gmt_offset = -6 group by i_item_id), ws as ( select i_item_id,sum(ws_ext_sales_price) total_sales from web_sales, date_dim, customer_address, item where i_item_id in (select i_item_id from item where i_color in ('powder','orchid','pink')) and ws_item_sk = i_item_sk and ws_sold_date_sk = d_date_sk and d_year = 2000 and d_moy = 3 and ws_bill_addr_sk = ca_address_sk and ca_gmt_offset = -6 group by i_item_id) select i_item_id ,sum(total_sales) total_sales from (select * from ss union all select * from cs union all select * from ws) tmp1 group by i_item_id order by total_sales, i_item_id limit 100;`, }, { Query: ` -- start query 57 in stream 0 using template query57.tpl with v1 as( select i_category, i_brand, cc_name, d_year, d_moy, sum(cs_sales_price) sum_sales, avg(sum(cs_sales_price)) over (partition by i_category, i_brand, cc_name, d_year) avg_monthly_sales, rank() over (partition by i_category, i_brand, cc_name order by d_year, d_moy) rn from item, catalog_sales, date_dim, call_center where cs_item_sk = i_item_sk and cs_sold_date_sk = d_date_sk and cc_call_center_sk= cs_call_center_sk and ( d_year = 2001 or ( d_year = 2001-1 and d_moy =12) or ( d_year = 2001+1 and d_moy =1) ) group by i_category, i_brand, cc_name , d_year, d_moy), v2 as( select v1.i_category, v1.i_brand, v1.cc_name ,v1.d_year ,v1.avg_monthly_sales ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum from v1, v1 v1_lag, v1 v1_lead where v1.i_category = v1_lag.i_category and v1.i_category = v1_lead.i_category and v1.i_brand = v1_lag.i_brand and v1.i_brand = v1_lead.i_brand and v1. cc_name = v1_lag. cc_name and v1. cc_name = v1_lead. cc_name and v1.rn = v1_lag.rn + 1 and v1.rn = v1_lead.rn - 1) select * from v2 where d_year = 2001 and avg_monthly_sales > 0 and case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 order by sum_sales - avg_monthly_sales, avg_monthly_sales limit 100;`, }, { Query: ` -- start query 58 in stream 0 using template query58.tpl with ss_items as (select i_item_id item_id ,sum(ss_ext_sales_price) ss_item_rev from store_sales ,item ,date_dim where ss_item_sk = i_item_sk and d_date in (select d_date from date_dim where d_week_seq = (select d_week_seq from date_dim where d_date = '2001-06-16')) and ss_sold_date_sk = d_date_sk group by i_item_id), cs_items as (select i_item_id item_id ,sum(cs_ext_sales_price) cs_item_rev from catalog_sales ,item ,date_dim where cs_item_sk = i_item_sk and d_date in (select d_date from date_dim where d_week_seq = (select d_week_seq from date_dim where d_date = '2001-06-16')) and cs_sold_date_sk = d_date_sk group by i_item_id), ws_items as (select i_item_id item_id ,sum(ws_ext_sales_price) ws_item_rev from web_sales ,item ,date_dim where ws_item_sk = i_item_sk and d_date in (select d_date from date_dim where d_week_seq =(select d_week_seq from date_dim where d_date = '2001-06-16')) and ws_sold_date_sk = d_date_sk group by i_item_id) select ss_items.item_id ,ss_item_rev ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev ,cs_item_rev ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev ,ws_item_rev ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average from ss_items,cs_items,ws_items where ss_items.item_id=cs_items.item_id and ss_items.item_id=ws_items.item_id and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev order by item_id ,ss_item_rev limit 100;`, }, { Query: ` -- start query 59 in stream 0 using template query59.tpl with wss as (select d_week_seq, ss_store_sk, sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales from store_sales,date_dim where d_date_sk = ss_sold_date_sk group by d_week_seq,ss_store_sk ) select s_store_name1,s_store_id1,d_week_seq1 ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 from (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 ,s_store_id s_store_id1,sun_sales sun_sales1 ,mon_sales mon_sales1,tue_sales tue_sales1 ,wed_sales wed_sales1,thu_sales thu_sales1 ,fri_sales fri_sales1,sat_sales sat_sales1 from wss,store,date_dim d where d.d_week_seq = wss.d_week_seq and ss_store_sk = s_store_sk and d_month_seq between 1195 and 1195 + 11) y, (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 ,s_store_id s_store_id2,sun_sales sun_sales2 ,mon_sales mon_sales2,tue_sales tue_sales2 ,wed_sales wed_sales2,thu_sales thu_sales2 ,fri_sales fri_sales2,sat_sales sat_sales2 from wss,store,date_dim d where d.d_week_seq = wss.d_week_seq and ss_store_sk = s_store_sk and d_month_seq between 1195+ 12 and 1195 + 23) x where s_store_id1=s_store_id2 and d_week_seq1=d_week_seq2-52 order by s_store_name1,s_store_id1,d_week_seq1 limit 100;`, }, { Query: ` -- start query 60 in stream 0 using template query60.tpl with ss as ( select i_item_id,sum(ss_ext_sales_price) total_sales from store_sales, date_dim, customer_address, item where i_item_id in (select i_item_id from item where i_category in ('Jewelry')) and ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk and d_year = 2000 and d_moy = 10 and ss_addr_sk = ca_address_sk and ca_gmt_offset = -5 group by i_item_id), cs as ( select i_item_id,sum(cs_ext_sales_price) total_sales from catalog_sales, date_dim, customer_address, item where i_item_id in (select i_item_id from item where i_category in ('Jewelry')) and cs_item_sk = i_item_sk and cs_sold_date_sk = d_date_sk and d_year = 2000 and d_moy = 10 and cs_bill_addr_sk = ca_address_sk and ca_gmt_offset = -5 group by i_item_id), ws as ( select i_item_id,sum(ws_ext_sales_price) total_sales from web_sales, date_dim, customer_address, item where i_item_id in (select i_item_id from item where i_category in ('Jewelry')) and ws_item_sk = i_item_sk and ws_sold_date_sk = d_date_sk and d_year = 2000 and d_moy = 10 and ws_bill_addr_sk = ca_address_sk and ca_gmt_offset = -5 group by i_item_id) select i_item_id ,sum(total_sales) total_sales from (select * from ss union all select * from cs union all select * from ws) tmp1 group by i_item_id order by i_item_id ,total_sales limit 100;`, }, { Query: ` -- start query 61 in stream 0 using template query61.tpl select promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 from (select sum(ss_ext_sales_price) promotions from store_sales ,store ,promotion ,date_dim ,customer ,customer_address ,item where ss_sold_date_sk = d_date_sk and ss_store_sk = s_store_sk and ss_promo_sk = p_promo_sk and ss_customer_sk= c_customer_sk and ca_address_sk = c_current_addr_sk and ss_item_sk = i_item_sk and ca_gmt_offset = -7 and i_category = 'Home' and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') and s_gmt_offset = -7 and d_year = 2000 and d_moy = 12) promotional_sales, (select sum(ss_ext_sales_price) total from store_sales ,store ,date_dim ,customer ,customer_address ,item where ss_sold_date_sk = d_date_sk and ss_store_sk = s_store_sk and ss_customer_sk= c_customer_sk and ca_address_sk = c_current_addr_sk and ss_item_sk = i_item_sk and ca_gmt_offset = -7 and i_category = 'Home' and s_gmt_offset = -7 and d_year = 2000 and d_moy = 12) all_sales order by promotions, total limit 100;`, }, { Query: ` -- start query 62 in stream 0 using template query62.tpl select substr(w_warehouse_name,1,20) ,sm_type ,web_name ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" from web_sales ,warehouse ,ship_mode ,web_site ,date_dim where d_month_seq between 1223 and 1223 + 11 and ws_ship_date_sk = d_date_sk and ws_warehouse_sk = w_warehouse_sk and ws_ship_mode_sk = sm_ship_mode_sk and ws_web_site_sk = web_site_sk group by substr(w_warehouse_name,1,20) ,sm_type ,web_name order by substr(w_warehouse_name,1,20) ,sm_type ,web_name limit 100;`, }, { Query: ` -- start query 63 in stream 0 using template query63.tpl select * from (select i_manager_id ,sum(ss_sales_price) sum_sales ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales from item ,store_sales ,date_dim ,store where ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk and ss_store_sk = s_store_sk and d_month_seq in (1222,1222+1,1222+2,1222+3,1222+4,1222+5,1222+6,1222+7,1222+8,1222+9,1222+10,1222+11) and (( i_category in ('Books','Children','Electronics') and i_class in ('personal','portable','reference','self-help') and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', 'exportiunivamalg #9','scholaramalgamalg #9')) or( i_category in ('Women','Music','Men') and i_class in ('accessories','classical','fragrances','pants') and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', 'importoamalg #1'))) group by i_manager_id, d_moy) tmp1 where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 order by i_manager_id ,avg_monthly_sales ,sum_sales limit 100;`, }, { Query: ` -- start query 64 in stream 0 using template query64.tpl with cs_ui as (select cs_item_sk ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund from catalog_sales ,catalog_returns where cs_item_sk = cr_item_sk and cs_order_number = cr_order_number group by cs_item_sk having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), cross_sales as (select i_product_name product_name ,i_item_sk item_sk ,s_store_name store_name ,s_zip store_zip ,ad1.ca_street_number b_street_number ,ad1.ca_street_name b_street_name ,ad1.ca_city b_city ,ad1.ca_zip b_zip ,ad2.ca_street_number c_street_number ,ad2.ca_street_name c_street_name ,ad2.ca_city c_city ,ad2.ca_zip c_zip ,d1.d_year as syear ,d2.d_year as fsyear ,d3.d_year s2year ,count(*) cnt ,sum(ss_wholesale_cost) s1 ,sum(ss_list_price) s2 ,sum(ss_coupon_amt) s3 FROM store_sales ,store_returns ,cs_ui ,date_dim d1 ,date_dim d2 ,date_dim d3 ,store ,customer ,customer_demographics cd1 ,customer_demographics cd2 ,promotion ,household_demographics hd1 ,household_demographics hd2 ,customer_address ad1 ,customer_address ad2 ,income_band ib1 ,income_band ib2 ,item WHERE ss_store_sk = s_store_sk AND ss_sold_date_sk = d1.d_date_sk AND ss_customer_sk = c_customer_sk AND ss_cdemo_sk= cd1.cd_demo_sk AND ss_hdemo_sk = hd1.hd_demo_sk AND ss_addr_sk = ad1.ca_address_sk and ss_item_sk = i_item_sk and ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number and ss_item_sk = cs_ui.cs_item_sk and c_current_cdemo_sk = cd2.cd_demo_sk AND c_current_hdemo_sk = hd2.hd_demo_sk AND c_current_addr_sk = ad2.ca_address_sk and c_first_sales_date_sk = d2.d_date_sk and c_first_shipto_date_sk = d3.d_date_sk and ss_promo_sk = p_promo_sk and hd1.hd_income_band_sk = ib1.ib_income_band_sk and hd2.hd_income_band_sk = ib2.ib_income_band_sk and cd1.cd_marital_status <> cd2.cd_marital_status and i_color in ('orange','lace','lawn','misty','blush','pink') and i_current_price between 48 and 48 + 10 and i_current_price between 48 + 1 and 48 + 15 group by i_product_name ,i_item_sk ,s_store_name ,s_zip ,ad1.ca_street_number ,ad1.ca_street_name ,ad1.ca_city ,ad1.ca_zip ,ad2.ca_street_number ,ad2.ca_street_name ,ad2.ca_city ,ad2.ca_zip ,d1.d_year ,d2.d_year ,d3.d_year ) select cs1.product_name ,cs1.store_name ,cs1.store_zip ,cs1.b_street_number ,cs1.b_street_name ,cs1.b_city ,cs1.b_zip ,cs1.c_street_number ,cs1.c_street_name ,cs1.c_city ,cs1.c_zip ,cs1.syear ,cs1.cnt ,cs1.s1 as s11 ,cs1.s2 as s21 ,cs1.s3 as s31 ,cs2.s1 as s12 ,cs2.s2 as s22 ,cs2.s3 as s32 ,cs2.syear ,cs2.cnt from cross_sales cs1,cross_sales cs2 where cs1.item_sk=cs2.item_sk and cs1.syear = 1999 and cs2.syear = 1999 + 1 and cs2.cnt <= cs1.cnt and cs1.store_name = cs2.store_name and cs1.store_zip = cs2.store_zip order by cs1.product_name ,cs1.store_name ,cs2.cnt ,cs1.s1 ,cs2.s1;`, }, { Query: ` -- start query 65 in stream 0 using template query65.tpl select s_store_name, i_item_desc, sc.revenue, i_current_price, i_wholesale_cost, i_brand from store, item, (select ss_store_sk, avg(revenue) as ave from (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue from store_sales, date_dim where ss_sold_date_sk = d_date_sk and d_month_seq between 1176 and 1176+11 group by ss_store_sk, ss_item_sk) sa group by ss_store_sk) sb, (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue from store_sales, date_dim where ss_sold_date_sk = d_date_sk and d_month_seq between 1176 and 1176+11 group by ss_store_sk, ss_item_sk) sc where sb.ss_store_sk = sc.ss_store_sk and sc.revenue <= 0.1 * sb.ave and s_store_sk = sc.ss_store_sk and i_item_sk = sc.ss_item_sk order by s_store_name, i_item_desc limit 100;`, }, { Query: ` -- start query 66 in stream 0 using template query66.tpl select w_warehouse_name ,w_warehouse_sq_ft ,w_city ,w_county ,w_state ,w_country ,ship_carriers ,year ,sum(jan_sales) as jan_sales ,sum(feb_sales) as feb_sales ,sum(mar_sales) as mar_sales ,sum(apr_sales) as apr_sales ,sum(may_sales) as may_sales ,sum(jun_sales) as jun_sales ,sum(jul_sales) as jul_sales ,sum(aug_sales) as aug_sales ,sum(sep_sales) as sep_sales ,sum(oct_sales) as oct_sales ,sum(nov_sales) as nov_sales ,sum(dec_sales) as dec_sales ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot ,sum(jan_net) as jan_net ,sum(feb_net) as feb_net ,sum(mar_net) as mar_net ,sum(apr_net) as apr_net ,sum(may_net) as may_net ,sum(jun_net) as jun_net ,sum(jul_net) as jul_net ,sum(aug_net) as aug_net ,sum(sep_net) as sep_net ,sum(oct_net) as oct_net ,sum(nov_net) as nov_net ,sum(dec_net) as dec_net from ( select w_warehouse_name ,w_warehouse_sq_ft ,w_city ,w_county ,w_state ,w_country ,'ORIENTAL' || ',' || 'BOXBUNDLES' as ship_carriers ,d_year as year ,sum(case when d_moy = 1 then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales ,sum(case when d_moy = 2 then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales ,sum(case when d_moy = 3 then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales ,sum(case when d_moy = 4 then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales ,sum(case when d_moy = 5 then ws_ext_sales_price* ws_quantity else 0 end) as may_sales ,sum(case when d_moy = 6 then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales ,sum(case when d_moy = 7 then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales ,sum(case when d_moy = 8 then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales ,sum(case when d_moy = 9 then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales ,sum(case when d_moy = 10 then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales ,sum(case when d_moy = 11 then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales ,sum(case when d_moy = 12 then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales ,sum(case when d_moy = 1 then ws_net_paid_inc_ship * ws_quantity else 0 end) as jan_net ,sum(case when d_moy = 2 then ws_net_paid_inc_ship * ws_quantity else 0 end) as feb_net ,sum(case when d_moy = 3 then ws_net_paid_inc_ship * ws_quantity else 0 end) as mar_net ,sum(case when d_moy = 4 then ws_net_paid_inc_ship * ws_quantity else 0 end) as apr_net ,sum(case when d_moy = 5 then ws_net_paid_inc_ship * ws_quantity else 0 end) as may_net ,sum(case when d_moy = 6 then ws_net_paid_inc_ship * ws_quantity else 0 end) as jun_net ,sum(case when d_moy = 7 then ws_net_paid_inc_ship * ws_quantity else 0 end) as jul_net ,sum(case when d_moy = 8 then ws_net_paid_inc_ship * ws_quantity else 0 end) as aug_net ,sum(case when d_moy = 9 then ws_net_paid_inc_ship * ws_quantity else 0 end) as sep_net ,sum(case when d_moy = 10 then ws_net_paid_inc_ship * ws_quantity else 0 end) as oct_net ,sum(case when d_moy = 11 then ws_net_paid_inc_ship * ws_quantity else 0 end) as nov_net ,sum(case when d_moy = 12 then ws_net_paid_inc_ship * ws_quantity else 0 end) as dec_net from web_sales ,warehouse ,date_dim ,time_dim ,ship_mode where ws_warehouse_sk = w_warehouse_sk and ws_sold_date_sk = d_date_sk and ws_sold_time_sk = t_time_sk and ws_ship_mode_sk = sm_ship_mode_sk and d_year = 2001 and t_time between 42970 and 42970+28800 and sm_carrier in ('ORIENTAL','BOXBUNDLES') group by w_warehouse_name ,w_warehouse_sq_ft ,w_city ,w_county ,w_state ,w_country ,d_year union all select w_warehouse_name ,w_warehouse_sq_ft ,w_city ,w_county ,w_state ,w_country ,'ORIENTAL' || ',' || 'BOXBUNDLES' as ship_carriers ,d_year as year ,sum(case when d_moy = 1 then cs_ext_list_price* cs_quantity else 0 end) as jan_sales ,sum(case when d_moy = 2 then cs_ext_list_price* cs_quantity else 0 end) as feb_sales ,sum(case when d_moy = 3 then cs_ext_list_price* cs_quantity else 0 end) as mar_sales ,sum(case when d_moy = 4 then cs_ext_list_price* cs_quantity else 0 end) as apr_sales ,sum(case when d_moy = 5 then cs_ext_list_price* cs_quantity else 0 end) as may_sales ,sum(case when d_moy = 6 then cs_ext_list_price* cs_quantity else 0 end) as jun_sales ,sum(case when d_moy = 7 then cs_ext_list_price* cs_quantity else 0 end) as jul_sales ,sum(case when d_moy = 8 then cs_ext_list_price* cs_quantity else 0 end) as aug_sales ,sum(case when d_moy = 9 then cs_ext_list_price* cs_quantity else 0 end) as sep_sales ,sum(case when d_moy = 10 then cs_ext_list_price* cs_quantity else 0 end) as oct_sales ,sum(case when d_moy = 11 then cs_ext_list_price* cs_quantity else 0 end) as nov_sales ,sum(case when d_moy = 12 then cs_ext_list_price* cs_quantity else 0 end) as dec_sales ,sum(case when d_moy = 1 then cs_net_paid * cs_quantity else 0 end) as jan_net ,sum(case when d_moy = 2 then cs_net_paid * cs_quantity else 0 end) as feb_net ,sum(case when d_moy = 3 then cs_net_paid * cs_quantity else 0 end) as mar_net ,sum(case when d_moy = 4 then cs_net_paid * cs_quantity else 0 end) as apr_net ,sum(case when d_moy = 5 then cs_net_paid * cs_quantity else 0 end) as may_net ,sum(case when d_moy = 6 then cs_net_paid * cs_quantity else 0 end) as jun_net ,sum(case when d_moy = 7 then cs_net_paid * cs_quantity else 0 end) as jul_net ,sum(case when d_moy = 8 then cs_net_paid * cs_quantity else 0 end) as aug_net ,sum(case when d_moy = 9 then cs_net_paid * cs_quantity else 0 end) as sep_net ,sum(case when d_moy = 10 then cs_net_paid * cs_quantity else 0 end) as oct_net ,sum(case when d_moy = 11 then cs_net_paid * cs_quantity else 0 end) as nov_net ,sum(case when d_moy = 12 then cs_net_paid * cs_quantity else 0 end) as dec_net from catalog_sales ,warehouse ,date_dim ,time_dim ,ship_mode where cs_warehouse_sk = w_warehouse_sk and cs_sold_date_sk = d_date_sk and cs_sold_time_sk = t_time_sk and cs_ship_mode_sk = sm_ship_mode_sk and d_year = 2001 and t_time between 42970 AND 42970+28800 and sm_carrier in ('ORIENTAL','BOXBUNDLES') group by w_warehouse_name ,w_warehouse_sq_ft ,w_city ,w_county ,w_state ,w_country ,d_year ) x group by w_warehouse_name ,w_warehouse_sq_ft ,w_city ,w_county ,w_state ,w_country ,ship_carriers ,year order by w_warehouse_name limit 100;`, }, { Query: ` -- start query 67 in stream 0 using template query67.tpl select * from (select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id ,sumsales ,rank() over (partition by i_category order by sumsales desc) rk from (select i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales from store_sales ,date_dim ,store ,item where ss_sold_date_sk=d_date_sk and ss_item_sk=i_item_sk and ss_store_sk = s_store_sk and d_month_seq between 1217 and 1217+11 group by rollup(i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id))dw1) dw2 where rk <= 100 order by i_category ,i_class ,i_brand ,i_product_name ,d_year ,d_qoy ,d_moy ,s_store_id ,sumsales ,rk limit 100;`, Skip: true, }, { Query: ` -- start query 68 in stream 0 using template query68.tpl select c_last_name ,c_first_name ,ca_city ,bought_city ,ss_ticket_number ,extended_price ,extended_tax ,list_price from (select ss_ticket_number ,ss_customer_sk ,ca_city bought_city ,sum(ss_ext_sales_price) extended_price ,sum(ss_ext_list_price) list_price ,sum(ss_ext_tax) extended_tax from store_sales ,date_dim ,store ,household_demographics ,customer_address where store_sales.ss_sold_date_sk = date_dim.d_date_sk and store_sales.ss_store_sk = store.s_store_sk and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk and store_sales.ss_addr_sk = customer_address.ca_address_sk and date_dim.d_dom between 1 and 2 and (household_demographics.hd_dep_count = 3 or household_demographics.hd_vehicle_count= 4) and date_dim.d_year in (1998,1998+1,1998+2) and store.s_city in ('Fairview','Midway') group by ss_ticket_number ,ss_customer_sk ,ss_addr_sk,ca_city) dn ,customer ,customer_address current_addr where ss_customer_sk = c_customer_sk and customer.c_current_addr_sk = current_addr.ca_address_sk and current_addr.ca_city <> bought_city order by c_last_name ,ss_ticket_number limit 100;`, }, { Query: ` -- start query 69 in stream 0 using template query69.tpl select cd_gender, cd_marital_status, cd_education_status, count(*) cnt1, cd_purchase_estimate, count(*) cnt2, cd_credit_rating, count(*) cnt3 from customer c,customer_address ca,customer_demographics where c.c_current_addr_sk = ca.ca_address_sk and ca_state in ('IL','TX','ME') and cd_demo_sk = c.c_current_cdemo_sk and exists (select * from store_sales,date_dim where c.c_customer_sk = ss_customer_sk and ss_sold_date_sk = d_date_sk and d_year = 2002 and d_moy between 1 and 1+2) and (not exists (select * from web_sales,date_dim where c.c_customer_sk = ws_bill_customer_sk and ws_sold_date_sk = d_date_sk and d_year = 2002 and d_moy between 1 and 1+2) and not exists (select * from catalog_sales,date_dim where c.c_customer_sk = cs_ship_customer_sk and cs_sold_date_sk = d_date_sk and d_year = 2002 and d_moy between 1 and 1+2)) group by cd_gender, cd_marital_status, cd_education_status, cd_purchase_estimate, cd_credit_rating order by cd_gender, cd_marital_status, cd_education_status, cd_purchase_estimate, cd_credit_rating limit 100;`, }, { Query: ` -- start query 70 in stream 0 using template query70.tpl select sum(ss_net_profit) as total_sum ,s_state ,s_county ,grouping(s_state)+grouping(s_county) as lochierarchy ,rank() over ( partition by grouping(s_state)+grouping(s_county), case when grouping(s_county) = 0 then s_state end order by sum(ss_net_profit) desc) as rank_within_parent from store_sales ,date_dim d1 ,store where d1.d_month_seq between 1220 and 1220+11 and d1.d_date_sk = ss_sold_date_sk and s_store_sk = ss_store_sk and s_state in ( select s_state from (select s_state as s_state, rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking from store_sales, store, date_dim where d_month_seq between 1220 and 1220+11 and d_date_sk = ss_sold_date_sk and s_store_sk = ss_store_sk group by s_state ) tmp1 where ranking <= 5 ) group by rollup(s_state,s_county) order by lochierarchy desc ,case when lochierarchy = 0 then s_state end ,rank_within_parent limit 100;`, Skip: true, }, { Query: ` -- start query 71 in stream 0 using template query71.tpl select i_brand_id brand_id, i_brand brand,t_hour,t_minute, sum(ext_price) ext_price from item, (select ws_ext_sales_price as ext_price, ws_sold_date_sk as sold_date_sk, ws_item_sk as sold_item_sk, ws_sold_time_sk as time_sk from web_sales,date_dim where d_date_sk = ws_sold_date_sk and d_moy=12 and d_year=2002 union all select cs_ext_sales_price as ext_price, cs_sold_date_sk as sold_date_sk, cs_item_sk as sold_item_sk, cs_sold_time_sk as time_sk from catalog_sales,date_dim where d_date_sk = cs_sold_date_sk and d_moy=12 and d_year=2002 union all select ss_ext_sales_price as ext_price, ss_sold_date_sk as sold_date_sk, ss_item_sk as sold_item_sk, ss_sold_time_sk as time_sk from store_sales,date_dim where d_date_sk = ss_sold_date_sk and d_moy=12 and d_year=2002 ) tmp,time_dim where sold_item_sk = i_item_sk and i_manager_id=1 and time_sk = t_time_sk and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') group by i_brand, i_brand_id,t_hour,t_minute order by ext_price desc, i_brand_id ;`, }, { Query: ` -- start query 72 in stream 0 using template query72.tpl select i_item_desc ,w_warehouse_name ,d1.d_week_seq ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo ,sum(case when p_promo_sk is not null then 1 else 0 end) promo ,count(*) total_cnt from catalog_sales join inventory on (cs_item_sk = inv_item_sk) join warehouse on (w_warehouse_sk=inv_warehouse_sk) join item on (i_item_sk = cs_item_sk) join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) join date_dim d2 on (inv_date_sk = d2.d_date_sk) join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) left outer join promotion on (cs_promo_sk=p_promo_sk) left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) where d1.d_week_seq = d2.d_week_seq and inv_quantity_on_hand < cs_quantity and d3.d_date > d1.d_date + 5 and hd_buy_potential = '1001-5000' and d1.d_year = 1998 and cd_marital_status = 'S' group by i_item_desc,w_warehouse_name,d1.d_week_seq order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq limit 100;`, }, { Query: ` -- start query 73 in stream 0 using template query73.tpl select c_last_name ,c_first_name ,c_salutation ,c_preferred_cust_flag ,ss_ticket_number ,cnt from (select ss_ticket_number ,ss_customer_sk ,count(*) cnt from store_sales,date_dim,store,household_demographics where store_sales.ss_sold_date_sk = date_dim.d_date_sk and store_sales.ss_store_sk = store.s_store_sk and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk and date_dim.d_dom between 1 and 2 and (household_demographics.hd_buy_potential = '1001-5000' or household_demographics.hd_buy_potential = '5001-10000') and household_demographics.hd_vehicle_count > 0 and case when household_demographics.hd_vehicle_count > 0 then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 and date_dim.d_year in (2000,2000+1,2000+2) and store.s_county in ('Williamson County','Williamson County','Williamson County','Williamson County') group by ss_ticket_number,ss_customer_sk) dj,customer where ss_customer_sk = c_customer_sk and cnt between 1 and 5 order by cnt desc, c_last_name asc;`, }, { Query: ` -- start query 74 in stream 0 using template query74.tpl with year_total as ( select c_customer_id customer_id ,c_first_name customer_first_name ,c_last_name customer_last_name ,d_year as year ,max(ss_net_paid) year_total ,'s' sale_type from customer ,store_sales ,date_dim where c_customer_sk = ss_customer_sk and ss_sold_date_sk = d_date_sk and d_year in (1999,1999+1) group by c_customer_id ,c_first_name ,c_last_name ,d_year union all select c_customer_id customer_id ,c_first_name customer_first_name ,c_last_name customer_last_name ,d_year as year ,max(ws_net_paid) year_total ,'w' sale_type from customer ,web_sales ,date_dim where c_customer_sk = ws_bill_customer_sk and ws_sold_date_sk = d_date_sk and d_year in (1999,1999+1) group by c_customer_id ,c_first_name ,c_last_name ,d_year ) select t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name from year_total t_s_firstyear ,year_total t_s_secyear ,year_total t_w_firstyear ,year_total t_w_secyear where t_s_secyear.customer_id = t_s_firstyear.customer_id and t_s_firstyear.customer_id = t_w_secyear.customer_id and t_s_firstyear.customer_id = t_w_firstyear.customer_id and t_s_firstyear.sale_type = 's' and t_w_firstyear.sale_type = 'w' and t_s_secyear.sale_type = 's' and t_w_secyear.sale_type = 'w' and t_s_firstyear.year = 1999 and t_s_secyear.year = 1999+1 and t_w_firstyear.year = 1999 and t_w_secyear.year = 1999+1 and t_s_firstyear.year_total > 0 and t_w_firstyear.year_total > 0 and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end order by 1,3,2 limit 100;`, }, { Query: ` -- start query 75 in stream 0 using template query75.tpl WITH all_sales AS ( SELECT d_year ,i_brand_id ,i_class_id ,i_category_id ,i_manufact_id ,SUM(sales_cnt) AS sales_cnt ,SUM(sales_amt) AS sales_amt FROM (SELECT d_year ,i_brand_id ,i_class_id ,i_category_id ,i_manufact_id ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk JOIN date_dim ON d_date_sk=cs_sold_date_sk LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number AND cs_item_sk=cr_item_sk) WHERE i_category='Sports' UNION SELECT d_year ,i_brand_id ,i_class_id ,i_category_id ,i_manufact_id ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt FROM store_sales JOIN item ON i_item_sk=ss_item_sk JOIN date_dim ON d_date_sk=ss_sold_date_sk LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number AND ss_item_sk=sr_item_sk) WHERE i_category='Sports' UNION SELECT d_year ,i_brand_id ,i_class_id ,i_category_id ,i_manufact_id ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt FROM web_sales JOIN item ON i_item_sk=ws_item_sk JOIN date_dim ON d_date_sk=ws_sold_date_sk LEFT JOIN web_returns ON (ws_order_number=wr_order_number AND ws_item_sk=wr_item_sk) WHERE i_category='Sports') sales_detail GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) SELECT prev_yr.d_year AS prev_year ,curr_yr.d_year AS year ,curr_yr.i_brand_id ,curr_yr.i_class_id ,curr_yr.i_category_id ,curr_yr.i_manufact_id ,prev_yr.sales_cnt AS prev_yr_cnt ,curr_yr.sales_cnt AS curr_yr_cnt ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff FROM all_sales curr_yr, all_sales prev_yr WHERE curr_yr.i_brand_id=prev_yr.i_brand_id AND curr_yr.i_class_id=prev_yr.i_class_id AND curr_yr.i_category_id=prev_yr.i_category_id AND curr_yr.i_manufact_id=prev_yr.i_manufact_id AND curr_yr.d_year=2002 AND prev_yr.d_year=2002-1 AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 ORDER BY sales_cnt_diff,sales_amt_diff limit 100;`, }, { Query: ` -- start query 76 in stream 0 using template query76.tpl select channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price FROM store_sales, item, date_dim WHERE ss_customer_sk IS NULL AND ss_sold_date_sk=d_date_sk AND ss_item_sk=i_item_sk UNION ALL SELECT 'web' as channel, 'ws_promo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price FROM web_sales, item, date_dim WHERE ws_promo_sk IS NULL AND ws_sold_date_sk=d_date_sk AND ws_item_sk=i_item_sk UNION ALL SELECT 'catalog' as channel, 'cs_bill_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price FROM catalog_sales, item, date_dim WHERE cs_bill_customer_sk IS NULL AND cs_sold_date_sk=d_date_sk AND cs_item_sk=i_item_sk) foo GROUP BY channel, col_name, d_year, d_qoy, i_category ORDER BY channel, col_name, d_year, d_qoy, i_category limit 100;`, }, { Query: ` -- start query 77 in stream 0 using template query77.tpl with ss as (select s_store_sk, sum(ss_ext_sales_price) as sales, sum(ss_net_profit) as profit from store_sales, date_dim, store where ss_sold_date_sk = d_date_sk and d_date between cast('2000-08-10' as date) and (cast('2000-08-10' as date) + interval 30 day) and ss_store_sk = s_store_sk group by s_store_sk) , sr as (select s_store_sk, sum(sr_return_amt) as returns, sum(sr_net_loss) as profit_loss from store_returns, date_dim, store where sr_returned_date_sk = d_date_sk and d_date between cast('2000-08-10' as date) and (cast('2000-08-10' as date) + interval 30 day) and sr_store_sk = s_store_sk group by s_store_sk), cs as (select cs_call_center_sk, sum(cs_ext_sales_price) as sales, sum(cs_net_profit) as profit from catalog_sales, date_dim where cs_sold_date_sk = d_date_sk and d_date between cast('2000-08-10' as date) and (cast('2000-08-10' as date) + interval 30 day) group by cs_call_center_sk ), cr as (select cr_call_center_sk, sum(cr_return_amount) as returns, sum(cr_net_loss) as profit_loss from catalog_returns, date_dim where cr_returned_date_sk = d_date_sk and d_date between cast('2000-08-10' as date) and (cast('2000-08-10' as date) + interval 30 day) group by cr_call_center_sk ), ws as ( select wp_web_page_sk, sum(ws_ext_sales_price) as sales, sum(ws_net_profit) as profit from web_sales, date_dim, web_page where ws_sold_date_sk = d_date_sk and d_date between cast('2000-08-10' as date) and (cast('2000-08-10' as date) + interval 30 day) and ws_web_page_sk = wp_web_page_sk group by wp_web_page_sk), wr as (select wp_web_page_sk, sum(wr_return_amt) as returns, sum(wr_net_loss) as profit_loss from web_returns, date_dim, web_page where wr_returned_date_sk = d_date_sk and d_date between cast('2000-08-10' as date) and (cast('2000-08-10' as date) + interval 30 day) and wr_web_page_sk = wp_web_page_sk group by wp_web_page_sk) select channel , id , sum(sales) as sales , sum(returns) as returns , sum(profit) as profit from (select 'store channel' as channel , ss.s_store_sk as id , sales , coalesce(returns, 0) as returns , (profit - coalesce(profit_loss,0)) as profit from ss left join sr on ss.s_store_sk = sr.s_store_sk union all select 'catalog channel' as channel , cs_call_center_sk as id , sales , returns , (profit - profit_loss) as profit from cs , cr union all select 'web channel' as channel , ws.wp_web_page_sk as id , sales , coalesce(returns, 0) returns , (profit - coalesce(profit_loss,0)) as profit from ws left join wr on ws.wp_web_page_sk = wr.wp_web_page_sk ) x group by rollup (channel, id) order by channel ,id limit 100;`, Skip: true, }, { Query: ` -- start query 78 in stream 0 using template query78.tpl with ws as (select d_year AS ws_sold_year, ws_item_sk, ws_bill_customer_sk ws_customer_sk, sum(ws_quantity) ws_qty, sum(ws_wholesale_cost) ws_wc, sum(ws_sales_price) ws_sp from web_sales left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk join date_dim on ws_sold_date_sk = d_date_sk where wr_order_number is null group by d_year, ws_item_sk, ws_bill_customer_sk ), cs as (select d_year AS cs_sold_year, cs_item_sk, cs_bill_customer_sk cs_customer_sk, sum(cs_quantity) cs_qty, sum(cs_wholesale_cost) cs_wc, sum(cs_sales_price) cs_sp from catalog_sales left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk join date_dim on cs_sold_date_sk = d_date_sk where cr_order_number is null group by d_year, cs_item_sk, cs_bill_customer_sk ), ss as (select d_year AS ss_sold_year, ss_item_sk, ss_customer_sk, sum(ss_quantity) ss_qty, sum(ss_wholesale_cost) ss_wc, sum(ss_sales_price) ss_sp from store_sales left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk join date_dim on ss_sold_date_sk = d_date_sk where sr_ticket_number is null group by d_year, ss_item_sk, ss_customer_sk ) select ss_customer_sk, round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price from ss left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1998 order by ss_customer_sk, ss_qty desc, ss_wc desc, ss_sp desc, other_chan_qty, other_chan_wholesale_cost, other_chan_sales_price, ratio limit 100;`, }, { Query: ` -- start query 79 in stream 0 using template query79.tpl select c_last_name,c_first_name,substr(s_city,1,30),ss_ticket_number,amt,profit from (select ss_ticket_number ,ss_customer_sk ,store.s_city ,sum(ss_coupon_amt) amt ,sum(ss_net_profit) profit from store_sales,date_dim,store,household_demographics where store_sales.ss_sold_date_sk = date_dim.d_date_sk and store_sales.ss_store_sk = store.s_store_sk and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk and (household_demographics.hd_dep_count = 7 or household_demographics.hd_vehicle_count > -1) and date_dim.d_dow = 1 and date_dim.d_year in (2000,2000+1,2000+2) and store.s_number_employees between 200 and 295 group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer where ss_customer_sk = c_customer_sk order by c_last_name,c_first_name,substr(s_city,1,30), profit limit 100;`, }, { Query: ` -- start query 80 in stream 0 using template query80.tpl with ssr as (select s_store_id as store_id, sum(ss_ext_sales_price) as sales, sum(coalesce(sr_return_amt, 0)) as returns, sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit from store_sales left outer join store_returns on (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), date_dim, store, item, promotion where ss_sold_date_sk = d_date_sk and d_date between cast('2002-08-14' as date) and (cast('2002-08-14' as date) + interval 30 day) and ss_store_sk = s_store_sk and ss_item_sk = i_item_sk and i_current_price > 50 and ss_promo_sk = p_promo_sk and p_channel_tv = 'N' group by s_store_id) , csr as (select cp_catalog_page_id as catalog_page_id, sum(cs_ext_sales_price) as sales, sum(coalesce(cr_return_amount, 0)) as returns, sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit from catalog_sales left outer join catalog_returns on (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), date_dim, catalog_page, item, promotion where cs_sold_date_sk = d_date_sk and d_date between cast('2002-08-14' as date) and (cast('2002-08-14' as date) + interval 30 day) and cs_catalog_page_sk = cp_catalog_page_sk and cs_item_sk = i_item_sk and i_current_price > 50 and cs_promo_sk = p_promo_sk and p_channel_tv = 'N' group by cp_catalog_page_id) , wsr as (select web_site_id, sum(ws_ext_sales_price) as sales, sum(coalesce(wr_return_amt, 0)) as returns, sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit from web_sales left outer join web_returns on (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), date_dim, web_site, item, promotion where ws_sold_date_sk = d_date_sk and d_date between cast('2002-08-14' as date) and (cast('2002-08-14' as date) + interval 30 day) and ws_web_site_sk = web_site_sk and ws_item_sk = i_item_sk and i_current_price > 50 and ws_promo_sk = p_promo_sk and p_channel_tv = 'N' group by web_site_id) select channel , id , sum(sales) as sales , sum(returns) as returns , sum(profit) as profit from (select 'store channel' as channel , 'store' || store_id as id , sales , returns , profit from ssr union all select 'catalog channel' as channel , 'catalog_page' || catalog_page_id as id , sales , returns , profit from csr union all select 'web channel' as channel , 'web_site' || web_site_id as id , sales , returns , profit from wsr ) x group by rollup (channel, id) order by channel ,id limit 100;`, Skip: true, }, { Query: ` -- start query 81 in stream 0 using template query81.tpl with customer_total_return as (select cr_returning_customer_sk as ctr_customer_sk ,ca_state as ctr_state, sum(cr_return_amt_inc_tax) as ctr_total_return from catalog_returns ,date_dim ,customer_address where cr_returned_date_sk = d_date_sk and d_year =2001 and cr_returning_addr_sk = ca_address_sk group by cr_returning_customer_sk ,ca_state ) select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset ,ca_location_type,ctr_total_return from customer_total_return ctr1 ,customer_address ,customer where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 from customer_total_return ctr2 where ctr1.ctr_state = ctr2.ctr_state) and ca_address_sk = c_current_addr_sk and ca_state = 'TN' and ctr1.ctr_customer_sk = c_customer_sk order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset ,ca_location_type,ctr_total_return limit 100;`, }, { Query: ` -- start query 82 in stream 0 using template query82.tpl select i_item_id ,i_item_desc ,i_current_price from item, inventory, date_dim, store_sales where i_current_price between 58 and 58+30 and inv_item_sk = i_item_sk and d_date_sk=inv_date_sk and d_date between cast('2001-01-13' as date) and (cast('2001-01-13' as date) + interval 60 day) and i_manufact_id in (259,559,580,485) and inv_quantity_on_hand between 100 and 500 and ss_item_sk = i_item_sk group by i_item_id,i_item_desc,i_current_price order by i_item_id limit 100;`, }, { Query: ` -- start query 83 in stream 0 using template query83.tpl with sr_items as (select i_item_id item_id, sum(sr_return_quantity) sr_item_qty from store_returns, item, date_dim where sr_item_sk = i_item_sk and d_date in (select d_date from date_dim where d_week_seq in (select d_week_seq from date_dim where d_date in ('2001-07-13','2001-09-10','2001-11-16'))) and sr_returned_date_sk = d_date_sk group by i_item_id), cr_items as (select i_item_id item_id, sum(cr_return_quantity) cr_item_qty from catalog_returns, item, date_dim where cr_item_sk = i_item_sk and d_date in (select d_date from date_dim where d_week_seq in (select d_week_seq from date_dim where d_date in ('2001-07-13','2001-09-10','2001-11-16'))) and cr_returned_date_sk = d_date_sk group by i_item_id), wr_items as (select i_item_id item_id, sum(wr_return_quantity) wr_item_qty from web_returns, item, date_dim where wr_item_sk = i_item_sk and d_date in (select d_date from date_dim where d_week_seq in (select d_week_seq from date_dim where d_date in ('2001-07-13','2001-09-10','2001-11-16'))) and wr_returned_date_sk = d_date_sk group by i_item_id) select sr_items.item_id ,sr_item_qty ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev ,cr_item_qty ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev ,wr_item_qty ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average from sr_items ,cr_items ,wr_items where sr_items.item_id=cr_items.item_id and sr_items.item_id=wr_items.item_id order by sr_items.item_id ,sr_item_qty limit 100;`, }, { Query: ` -- start query 84 in stream 0 using template query84.tpl select c_customer_id as customer_id , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername from customer ,customer_address ,customer_demographics ,household_demographics ,income_band ,store_returns where ca_city = 'Woodland' and c_current_addr_sk = ca_address_sk and ib_lower_bound >= 60306 and ib_upper_bound <= 60306 + 50000 and ib_income_band_sk = hd_income_band_sk and cd_demo_sk = c_current_cdemo_sk and hd_demo_sk = c_current_hdemo_sk and sr_cdemo_sk = cd_demo_sk order by c_customer_id limit 100;`, }, { Query: ` -- start query 85 in stream 0 using template query85.tpl select substr(r_reason_desc,1,20) ,avg(ws_quantity) ,avg(wr_refunded_cash) ,avg(wr_fee) from web_sales, web_returns, web_page, customer_demographics cd1, customer_demographics cd2, customer_address, date_dim, reason where ws_web_page_sk = wp_web_page_sk and ws_item_sk = wr_item_sk and ws_order_number = wr_order_number and ws_sold_date_sk = d_date_sk and d_year = 1998 and cd1.cd_demo_sk = wr_refunded_cdemo_sk and cd2.cd_demo_sk = wr_returning_cdemo_sk and ca_address_sk = wr_refunded_addr_sk and r_reason_sk = wr_reason_sk and ( ( cd1.cd_marital_status = 'D' and cd1.cd_marital_status = cd2.cd_marital_status and cd1.cd_education_status = 'Primary' and cd1.cd_education_status = cd2.cd_education_status and ws_sales_price between 100.00 and 150.00 ) or ( cd1.cd_marital_status = 'S' and cd1.cd_marital_status = cd2.cd_marital_status and cd1.cd_education_status = 'College' and cd1.cd_education_status = cd2.cd_education_status and ws_sales_price between 50.00 and 100.00 ) or ( cd1.cd_marital_status = 'U' and cd1.cd_marital_status = cd2.cd_marital_status and cd1.cd_education_status = 'Advanced Degree' and cd1.cd_education_status = cd2.cd_education_status and ws_sales_price between 150.00 and 200.00 ) ) and ( ( ca_country = 'United States' and ca_state in ('NC', 'TX', 'IA') and ws_net_profit between 100 and 200 ) or ( ca_country = 'United States' and ca_state in ('WI', 'WV', 'GA') and ws_net_profit between 150 and 300 ) or ( ca_country = 'United States' and ca_state in ('OK', 'VA', 'KY') and ws_net_profit between 50 and 250 ) ) group by r_reason_desc order by substr(r_reason_desc,1,20) ,avg(ws_quantity) ,avg(wr_refunded_cash) ,avg(wr_fee) limit 100;`, }, { Query: ` -- start query 86 in stream 0 using template query86.tpl select sum(ws_net_paid) as total_sum ,i_category ,i_class ,grouping(i_category)+grouping(i_class) as lochierarchy ,rank() over ( partition by grouping(i_category)+grouping(i_class), case when grouping(i_class) = 0 then i_category end order by sum(ws_net_paid) desc) as rank_within_parent from web_sales ,date_dim d1 ,item where d1.d_month_seq between 1186 and 1186+11 and d1.d_date_sk = ws_sold_date_sk and i_item_sk = ws_item_sk group by rollup(i_category,i_class) order by lochierarchy desc, case when lochierarchy = 0 then i_category end, rank_within_parent limit 100;`, Skip: true, }, { Query: ` -- start query 87 in stream 0 using template query87.tpl select count(*) from ((select distinct c_last_name, c_first_name, d_date from store_sales, date_dim, customer where store_sales.ss_sold_date_sk = date_dim.d_date_sk and store_sales.ss_customer_sk = customer.c_customer_sk and d_month_seq between 1202 and 1202+11) except (select distinct c_last_name, c_first_name, d_date from catalog_sales, date_dim, customer where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk and d_month_seq between 1202 and 1202+11) except (select distinct c_last_name, c_first_name, d_date from web_sales, date_dim, customer where web_sales.ws_sold_date_sk = date_dim.d_date_sk and web_sales.ws_bill_customer_sk = customer.c_customer_sk and d_month_seq between 1202 and 1202+11) ) cool_cust ;`, }, { Query: ` -- start query 88 in stream 0 using template query88.tpl select * from (select count(*) h8_30_to_9 from store_sales, household_demographics , time_dim, store where ss_sold_time_sk = time_dim.t_time_sk and ss_hdemo_sk = household_demographics.hd_demo_sk and ss_store_sk = s_store_sk and time_dim.t_hour = 8 and time_dim.t_minute >= 30 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) and store.s_store_name = 'ese') s1, (select count(*) h9_to_9_30 from store_sales, household_demographics , time_dim, store where ss_sold_time_sk = time_dim.t_time_sk and ss_hdemo_sk = household_demographics.hd_demo_sk and ss_store_sk = s_store_sk and time_dim.t_hour = 9 and time_dim.t_minute < 30 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) and store.s_store_name = 'ese') s2, (select count(*) h9_30_to_10 from store_sales, household_demographics , time_dim, store where ss_sold_time_sk = time_dim.t_time_sk and ss_hdemo_sk = household_demographics.hd_demo_sk and ss_store_sk = s_store_sk and time_dim.t_hour = 9 and time_dim.t_minute >= 30 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) and store.s_store_name = 'ese') s3, (select count(*) h10_to_10_30 from store_sales, household_demographics , time_dim, store where ss_sold_time_sk = time_dim.t_time_sk and ss_hdemo_sk = household_demographics.hd_demo_sk and ss_store_sk = s_store_sk and time_dim.t_hour = 10 and time_dim.t_minute < 30 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) and store.s_store_name = 'ese') s4, (select count(*) h10_30_to_11 from store_sales, household_demographics , time_dim, store where ss_sold_time_sk = time_dim.t_time_sk and ss_hdemo_sk = household_demographics.hd_demo_sk and ss_store_sk = s_store_sk and time_dim.t_hour = 10 and time_dim.t_minute >= 30 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) and store.s_store_name = 'ese') s5, (select count(*) h11_to_11_30 from store_sales, household_demographics , time_dim, store where ss_sold_time_sk = time_dim.t_time_sk and ss_hdemo_sk = household_demographics.hd_demo_sk and ss_store_sk = s_store_sk and time_dim.t_hour = 11 and time_dim.t_minute < 30 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) and store.s_store_name = 'ese') s6, (select count(*) h11_30_to_12 from store_sales, household_demographics , time_dim, store where ss_sold_time_sk = time_dim.t_time_sk and ss_hdemo_sk = household_demographics.hd_demo_sk and ss_store_sk = s_store_sk and time_dim.t_hour = 11 and time_dim.t_minute >= 30 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) and store.s_store_name = 'ese') s7, (select count(*) h12_to_12_30 from store_sales, household_demographics , time_dim, store where ss_sold_time_sk = time_dim.t_time_sk and ss_hdemo_sk = household_demographics.hd_demo_sk and ss_store_sk = s_store_sk and time_dim.t_hour = 12 and time_dim.t_minute < 30 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) and store.s_store_name = 'ese') s8 ;`, }, { Query: ` -- start query 89 in stream 0 using template query89.tpl select * from( select i_category, i_class, i_brand, s_store_name, s_company_name, d_moy, sum(ss_sales_price) sum_sales, avg(sum(ss_sales_price)) over (partition by i_category, i_brand, s_store_name, s_company_name) avg_monthly_sales from item, store_sales, date_dim, store where ss_item_sk = i_item_sk and ss_sold_date_sk = d_date_sk and ss_store_sk = s_store_sk and d_year in (2001) and ((i_category in ('Books','Children','Electronics') and i_class in ('history','school-uniforms','audio') ) or (i_category in ('Men','Sports','Shoes') and i_class in ('pants','tennis','womens') )) group by i_category, i_class, i_brand, s_store_name, s_company_name, d_moy) tmp1 where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 order by sum_sales - avg_monthly_sales, s_store_name limit 100;`, }, { Query: ` -- start query 90 in stream 0 using template query90.tpl select cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio from ( select count(*) amc from web_sales, household_demographics , time_dim, web_page where ws_sold_time_sk = time_dim.t_time_sk and ws_ship_hdemo_sk = household_demographics.hd_demo_sk and ws_web_page_sk = web_page.wp_web_page_sk and time_dim.t_hour between 12 and 12+1 and household_demographics.hd_dep_count = 6 and web_page.wp_char_count between 5000 and 5200) at, ( select count(*) pmc from web_sales, household_demographics , time_dim, web_page where ws_sold_time_sk = time_dim.t_time_sk and ws_ship_hdemo_sk = household_demographics.hd_demo_sk and ws_web_page_sk = web_page.wp_web_page_sk and time_dim.t_hour between 14 and 14+1 and household_demographics.hd_dep_count = 6 and web_page.wp_char_count between 5000 and 5200) pt order by am_pm_ratio limit 100;`, }, { Query: ` -- start query 91 in stream 0 using template query91.tpl select cc_call_center_id Call_Center, cc_name Call_Center_Name, cc_manager Manager, sum(cr_net_loss) Returns_Loss from call_center, catalog_returns, date_dim, customer, customer_address, customer_demographics, household_demographics where cr_call_center_sk = cc_call_center_sk and cr_returned_date_sk = d_date_sk and cr_returning_customer_sk= c_customer_sk and cd_demo_sk = c_current_cdemo_sk and hd_demo_sk = c_current_hdemo_sk and ca_address_sk = c_current_addr_sk and d_year = 2000 and d_moy = 12 and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) and hd_buy_potential like 'Unknown%' and ca_gmt_offset = -7 group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status order by sum(cr_net_loss) desc;`, }, { Query: ` -- start query 92 in stream 0 using template query92.tpl select sum(ws_ext_discount_amt) as "Excess Discount Amount" from web_sales ,item ,date_dim where i_manufact_id = 714 and i_item_sk = ws_item_sk and d_date between '2000-02-01' and (cast('2000-02-01' as date) + interval 90 day) and d_date_sk = ws_sold_date_sk and ws_ext_discount_amt > ( SELECT 1.3 * avg(ws_ext_discount_amt) FROM web_sales ,date_dim WHERE ws_item_sk = i_item_sk and d_date between '2000-02-01' and (cast('2000-02-01' as date) + interval 90 day) and d_date_sk = ws_sold_date_sk ) order by sum(ws_ext_discount_amt) limit 100;`, }, { Query: ` -- start query 93 in stream 0 using template query93.tpl select ss_customer_sk ,sum(act_sales) sumsales from (select ss_item_sk ,ss_ticket_number ,ss_customer_sk ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price else (ss_quantity*ss_sales_price) end act_sales from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk and sr_ticket_number = ss_ticket_number) ,reason where sr_reason_sk = r_reason_sk and r_reason_desc = 'reason 58') t group by ss_customer_sk order by sumsales, ss_customer_sk limit 100;`, }, { Query: ` -- start query 94 in stream 0 using template query94.tpl select count(distinct ws_order_number) as "order count" ,sum(ws_ext_ship_cost) as "total shipping cost" ,sum(ws_net_profit) as "total net profit" from web_sales ws1 ,date_dim ,customer_address ,web_site where d_date between '2002-5-01' and (cast('2002-5-01' as date) + interval 60 day) and ws1.ws_ship_date_sk = d_date_sk and ws1.ws_ship_addr_sk = ca_address_sk and ca_state = 'OK' and ws1.ws_web_site_sk = web_site_sk and web_company_name = 'pri' and exists (select * from web_sales ws2 where ws1.ws_order_number = ws2.ws_order_number and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) and not exists(select * from web_returns wr1 where ws1.ws_order_number = wr1.wr_order_number) order by count(distinct ws_order_number) limit 100;`, }, { Query: ` -- start query 95 in stream 0 using template query95.tpl with ws_wh as (select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 from web_sales ws1,web_sales ws2 where ws1.ws_order_number = ws2.ws_order_number and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) select count(distinct ws_order_number) as "order count" ,sum(ws_ext_ship_cost) as "total shipping cost" ,sum(ws_net_profit) as "total net profit" from web_sales ws1 ,date_dim ,customer_address ,web_site where d_date between '2001-4-01' and (cast('2001-4-01' as date) + interval 60 day) and ws1.ws_ship_date_sk = d_date_sk and ws1.ws_ship_addr_sk = ca_address_sk and ca_state = 'VA' and ws1.ws_web_site_sk = web_site_sk and web_company_name = 'pri' and ws1.ws_order_number in (select ws_order_number from ws_wh) and ws1.ws_order_number in (select wr_order_number from web_returns,ws_wh where wr_order_number = ws_wh.ws_order_number) order by count(distinct ws_order_number) limit 100;`, }, { Query: ` -- start query 96 in stream 0 using template query96.tpl select count(*) from store_sales ,household_demographics ,time_dim, store where ss_sold_time_sk = time_dim.t_time_sk and ss_hdemo_sk = household_demographics.hd_demo_sk and ss_store_sk = s_store_sk and time_dim.t_hour = 8 and time_dim.t_minute >= 30 and household_demographics.hd_dep_count = 0 and store.s_store_name = 'ese' order by count(*) limit 100;`, }, { Query: ` -- start query 97 in stream 0 using template query97.tpl with ssci as ( select ss_customer_sk customer_sk ,ss_item_sk item_sk from store_sales,date_dim where ss_sold_date_sk = d_date_sk and d_month_seq between 1199 and 1199 + 11 group by ss_customer_sk ,ss_item_sk), csci as( select cs_bill_customer_sk customer_sk ,cs_item_sk item_sk from catalog_sales,date_dim where cs_sold_date_sk = d_date_sk and d_month_seq between 1199 and 1199 + 11 group by cs_bill_customer_sk ,cs_item_sk) select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk and ssci.item_sk = csci.item_sk) limit 100;`, }, { Query: ` -- start query 98 in stream 0 using template query98.tpl select i_item_id ,i_item_desc ,i_category ,i_class ,i_current_price ,sum(ss_ext_sales_price) as itemrevenue ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over (partition by i_class) as revenueratio from store_sales ,item ,date_dim where ss_item_sk = i_item_sk and i_category in ('Men', 'Sports', 'Jewelry') and ss_sold_date_sk = d_date_sk and d_date between cast('1999-02-05' as date) and (cast('1999-02-05' as date) + interval 30 day) group by i_item_id ,i_item_desc ,i_category ,i_class ,i_current_price order by i_category ,i_class ,i_item_id ,i_item_desc ,revenueratio;`, }, { Query: ` -- start query 99 in stream 0 using template query99.tpl select substr(w_warehouse_name,1,20) ,sm_type ,cc_name ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" from catalog_sales ,warehouse ,ship_mode ,call_center ,date_dim where d_month_seq between 1194 and 1194 + 11 and cs_ship_date_sk = d_date_sk and cs_warehouse_sk = w_warehouse_sk and cs_ship_mode_sk = sm_ship_mode_sk and cs_call_center_sk = cc_call_center_sk group by substr(w_warehouse_name,1,20) ,sm_type ,cc_name order by substr(w_warehouse_name,1,20) ,sm_type ,cc_name limit 100;`, }, }
var TpchPlanTests = []QueryPlanTest{
{
Query: `
--(Q1)
select
l_returnflag,
l_linestatus,
sum(l_quantity) as sum_qty,
sum(l_extendedprice) as sum_base_price,
sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
avg(l_quantity) as avg_qty,
avg(l_extendedprice) as avg_price,
avg(l_discount) as avg_disc,
count(*) as count_order
from
lineitem
where
l_shipdate <= '1998-12-01' - interval '90' day
group by
l_returnflag,
l_linestatus
order by
l_returnflag,
l_linestatus;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [lineitem.l_returnflag:8!null, lineitem.l_linestatus:9!null, sum(lineitem.l_quantity):7!null as sum_qty, sum(lineitem.l_extendedprice):6!null as sum_base_price, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):5!null as sum_disc_price, sum(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))):4!null as sum_charge, avg(lineitem.l_quantity):2 as avg_qty, avg(lineitem.l_extendedprice):1 as avg_price, avg(lineitem.l_discount):0 as avg_disc, count(1):3!null as count_order]\n" +
" └─ Sort(lineitem.l_returnflag:8!null ASC nullsFirst, lineitem.l_linestatus:9!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [avg(lineitem.l_discount):0, avg(lineitem.l_extendedprice):1, avg(lineitem.l_quantity):2, count(1):3!null, sum(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))):4!null, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):5!null, sum(lineitem.l_extendedprice):6!null, sum(lineitem.l_quantity):7!null, lineitem.l_returnflag:8!null, lineitem.l_linestatus:9!null, sum(lineitem.l_quantity):7!null as sum_qty, sum(lineitem.l_extendedprice):6!null as sum_base_price, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):5!null as sum_disc_price, sum(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))):4!null as sum_charge, avg(lineitem.l_quantity):2 as avg_qty, avg(lineitem.l_extendedprice):1 as avg_price, avg(lineitem.l_discount):0 as avg_disc, count(1):3!null as count_order]\n" +
" └─ GroupBy\n" +
" ├─ select: AVG(lineitem.l_discount:2!null), AVG(lineitem.l_extendedprice:1!null), AVG(lineitem.l_quantity:0!null), COUNT(1 (bigint)), SUM(((lineitem.l_extendedprice:1!null * (1 (tinyint) - lineitem.l_discount:2!null)) * (1 (tinyint) + lineitem.l_tax:3!null))), SUM((lineitem.l_extendedprice:1!null * (1 (tinyint) - lineitem.l_discount:2!null))), SUM(lineitem.l_extendedprice:1!null), SUM(lineitem.l_quantity:0!null), lineitem.l_returnflag:4!null, lineitem.l_linestatus:5!null\n" +
" ├─ group: lineitem.l_returnflag:4!null, lineitem.l_linestatus:5!null\n" +
" └─ Filter\n" +
" ├─ LessThanOrEqual\n" +
" │ ├─ lineitem.l_shipdate:6!null\n" +
" │ └─ 1998-09-02 00:00:00 +0000 UTC (datetime)\n" +
" └─ ProcessTable\n" +
" └─ Table\n" +
" ├─ name: lineitem\n" +
" └─ columns: [l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [lineitem.l_returnflag, lineitem.l_linestatus, sum(lineitem.l_quantity) as sum_qty, sum(lineitem.l_extendedprice) as sum_base_price, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as sum_disc_price, sum(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))) as sum_charge, avg(lineitem.l_quantity) as avg_qty, avg(lineitem.l_extendedprice) as avg_price, avg(lineitem.l_discount) as avg_disc, count(1) as count_order]\n" +
" └─ Sort(lineitem.l_returnflag ASC, lineitem.l_linestatus ASC)\n" +
" └─ Project\n" +
" ├─ columns: [avg(lineitem.l_discount), avg(lineitem.l_extendedprice), avg(lineitem.l_quantity), count(1), sum(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))), sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))), sum(lineitem.l_extendedprice), sum(lineitem.l_quantity), lineitem.l_returnflag, lineitem.l_linestatus, sum(lineitem.l_quantity) as sum_qty, sum(lineitem.l_extendedprice) as sum_base_price, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as sum_disc_price, sum(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))) as sum_charge, avg(lineitem.l_quantity) as avg_qty, avg(lineitem.l_extendedprice) as avg_price, avg(lineitem.l_discount) as avg_disc, count(1) as count_order]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(AVG(lineitem.l_discount), AVG(lineitem.l_extendedprice), AVG(lineitem.l_quantity), COUNT(1), SUM(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))), SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), SUM(lineitem.l_extendedprice), SUM(lineitem.l_quantity), lineitem.l_returnflag, lineitem.l_linestatus)\n" +
" ├─ Grouping(lineitem.l_returnflag, lineitem.l_linestatus)\n" +
" └─ Filter\n" +
" ├─ (lineitem.l_shipdate <= 1998-09-02 00:00:00 +0000 UTC)\n" +
" └─ Table\n" +
" ├─ name: lineitem\n" +
" └─ columns: [l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [lineitem.l_returnflag, lineitem.l_linestatus, sum(lineitem.l_quantity) as sum_qty, sum(lineitem.l_extendedprice) as sum_base_price, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as sum_disc_price, sum(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))) as sum_charge, avg(lineitem.l_quantity) as avg_qty, avg(lineitem.l_extendedprice) as avg_price, avg(lineitem.l_discount) as avg_disc, count(1) as count_order]\n" +
" └─ Sort(lineitem.l_returnflag ASC, lineitem.l_linestatus ASC)\n" +
" └─ Project\n" +
" ├─ columns: [avg(lineitem.l_discount), avg(lineitem.l_extendedprice), avg(lineitem.l_quantity), count(1), sum(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))), sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))), sum(lineitem.l_extendedprice), sum(lineitem.l_quantity), lineitem.l_returnflag, lineitem.l_linestatus, sum(lineitem.l_quantity) as sum_qty, sum(lineitem.l_extendedprice) as sum_base_price, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as sum_disc_price, sum(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))) as sum_charge, avg(lineitem.l_quantity) as avg_qty, avg(lineitem.l_extendedprice) as avg_price, avg(lineitem.l_discount) as avg_disc, count(1) as count_order]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(AVG(lineitem.l_discount), AVG(lineitem.l_extendedprice), AVG(lineitem.l_quantity), COUNT(1), SUM(((lineitem.l_extendedprice * (1 - lineitem.l_discount)) * (1 + lineitem.l_tax))), SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), SUM(lineitem.l_extendedprice), SUM(lineitem.l_quantity), lineitem.l_returnflag, lineitem.l_linestatus)\n" +
" ├─ Grouping(lineitem.l_returnflag, lineitem.l_linestatus)\n" +
" └─ Filter\n" +
" ├─ (lineitem.l_shipdate <= 1998-09-02 00:00:00 +0000 UTC)\n" +
" └─ Table\n" +
" ├─ name: lineitem\n" +
" └─ columns: [l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate]\n" +
"",
},
{
Query: `
--(Q2)
select
s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
from
part,
supplier,
partsupp,
nation,
region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and p_size = 15
and p_type like '%BRASS'
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'EUROPE'
and ps_supplycost = (
select
min(ps_supplycost)
from
partsupp,
supplier,
nation,
region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'EUROPE'
)
order by
s_acctbal desc,
n_name,
s_name,
p_partkey;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [supplier.s_acctbal:19!null, supplier.s_name:15!null, nation.n_name:22!null, part.p_partkey:0!null, part.p_mfgr:2!null, supplier.s_address:16!null, supplier.s_phone:18!null, supplier.s_comment:20!null]\n" +
" └─ Sort(supplier.s_acctbal:19!null DESC nullsFirst, nation.n_name:22!null ASC nullsFirst, supplier.s_name:15!null ASC nullsFirst, part.p_partkey:0!null ASC nullsFirst)\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ partsupp.ps_supplycost:12!null\n" +
" │ └─ Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select min(ps_supplycost) from partsupp, supplier, nation, region where p_partkey = ps_partkey and s_suppkey = ps_suppkey and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'EUROPE'\n" +
" │ └─ Project\n" +
" │ ├─ columns: [min(partsupp.ps_supplycost):28!null as min(ps_supplycost)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: MIN(partsupp.ps_supplycost:30!null)\n" +
" │ ├─ group: \n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ part.p_partkey:0!null\n" +
" │ │ └─ partsupp.ps_partkey:28!null\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ Table\n" +
" │ │ │ │ ├─ name: partsupp\n" +
" │ │ │ │ ├─ columns: [ps_partkey ps_suppkey ps_supplycost]\n" +
" │ │ │ │ ├─ colSet: (29-33)\n" +
" │ │ │ │ └─ tableId: 6\n" +
" │ │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ │ ├─ keys: [partsupp.ps_suppkey:29!null]\n" +
" │ │ │ ├─ colSet: (34-40)\n" +
" │ │ │ ├─ tableId: 7\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: supplier\n" +
" │ │ │ └─ columns: [s_suppkey s_nationkey]\n" +
" │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ ├─ keys: [supplier.s_nationkey:32!null]\n" +
" │ │ ├─ colSet: (41-44)\n" +
" │ │ ├─ tableId: 8\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: nation\n" +
" │ │ └─ columns: [n_nationkey n_regionkey]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ region.r_name:29!null\n" +
" │ │ └─ EUROPE (longtext)\n" +
" │ └─ IndexedTableAccess(region)\n" +
" │ ├─ index: [region.R_REGIONKEY]\n" +
" │ ├─ keys: [nation.n_regionkey:34!null]\n" +
" │ ├─ colSet: (45-47)\n" +
" │ ├─ tableId: 9\n" +
" │ └─ Table\n" +
" │ ├─ name: region\n" +
" │ └─ columns: [r_regionkey r_name]\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ ├─ part.p_partkey:0!null\n" +
" │ │ │ │ └─ partsupp.ps_partkey:9!null\n" +
" │ │ │ ├─ Filter\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ ├─ part.p_size:5!null\n" +
" │ │ │ │ │ │ └─ 15 (int)\n" +
" │ │ │ │ │ └─ part.p_type LIKE '%BRASS'\n" +
" │ │ │ │ └─ IndexedTableAccess(part)\n" +
" │ │ │ │ ├─ index: [part.P_PARTKEY]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (1-9)\n" +
" │ │ │ │ ├─ tableId: 1\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: part\n" +
" │ │ │ │ └─ columns: [p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment]\n" +
" │ │ │ └─ IndexedTableAccess(partsupp)\n" +
" │ │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (17-21)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: partsupp\n" +
" │ │ │ └─ columns: [ps_partkey ps_suppkey ps_availqty ps_supplycost ps_comment]\n" +
" │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ ├─ keys: [partsupp.ps_suppkey:10!null]\n" +
" │ │ ├─ colSet: (10-16)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: supplier\n" +
" │ │ └─ columns: [s_suppkey s_name s_address s_nationkey s_phone s_acctbal s_comment]\n" +
" │ └─ IndexedTableAccess(nation)\n" +
" │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ ├─ keys: [supplier.s_nationkey:17!null]\n" +
" │ ├─ colSet: (22-25)\n" +
" │ ├─ tableId: 4\n" +
" │ └─ Table\n" +
" │ ├─ name: nation\n" +
" │ └─ columns: [n_nationkey n_name n_regionkey n_comment]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ region.r_name:1!null\n" +
" │ └─ EUROPE (longtext)\n" +
" └─ IndexedTableAccess(region)\n" +
" ├─ index: [region.R_REGIONKEY]\n" +
" ├─ keys: [nation.n_regionkey:23!null]\n" +
" ├─ colSet: (26-28)\n" +
" ├─ tableId: 5\n" +
" └─ Table\n" +
" ├─ name: region\n" +
" └─ columns: [r_regionkey r_name r_comment]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [supplier.s_acctbal, supplier.s_name, nation.n_name, part.p_partkey, part.p_mfgr, supplier.s_address, supplier.s_phone, supplier.s_comment]\n" +
" └─ Sort(supplier.s_acctbal DESC, nation.n_name ASC, supplier.s_name ASC, part.p_partkey ASC)\n" +
" └─ Filter\n" +
" ├─ (partsupp.ps_supplycost = Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [min(partsupp.ps_supplycost) as min(ps_supplycost)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(MIN(partsupp.ps_supplycost))\n" +
" │ ├─ Grouping()\n" +
" │ └─ Filter\n" +
" │ ├─ (part.p_partkey = partsupp.ps_partkey)\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ Table\n" +
" │ │ │ │ ├─ name: partsupp\n" +
" │ │ │ │ └─ columns: [ps_partkey ps_suppkey ps_supplycost]\n" +
" │ │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ │ ├─ columns: [s_suppkey s_nationkey]\n" +
" │ │ │ └─ keys: partsupp.ps_suppkey\n" +
" │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ ├─ columns: [n_nationkey n_regionkey]\n" +
" │ │ └─ keys: supplier.s_nationkey\n" +
" │ └─ Filter\n" +
" │ ├─ (region.r_name = 'EUROPE')\n" +
" │ └─ IndexedTableAccess(region)\n" +
" │ ├─ index: [region.R_REGIONKEY]\n" +
" │ ├─ columns: [r_regionkey r_name]\n" +
" │ └─ keys: nation.n_regionkey\n" +
" │ )\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: (part.p_partkey = partsupp.ps_partkey)\n" +
" │ │ │ ├─ Filter\n" +
" │ │ │ │ ├─ ((part.p_size = 15) AND part.p_type LIKE '%BRASS')\n" +
" │ │ │ │ └─ IndexedTableAccess(part)\n" +
" │ │ │ │ ├─ index: [part.P_PARTKEY]\n" +
" │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ IndexedTableAccess(partsupp)\n" +
" │ │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ │ └─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ └─ keys: partsupp.ps_suppkey\n" +
" │ └─ IndexedTableAccess(nation)\n" +
" │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ └─ keys: supplier.s_nationkey\n" +
" └─ Filter\n" +
" ├─ (region.r_name = 'EUROPE')\n" +
" └─ IndexedTableAccess(region)\n" +
" ├─ index: [region.R_REGIONKEY]\n" +
" └─ keys: nation.n_regionkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [supplier.s_acctbal, supplier.s_name, nation.n_name, part.p_partkey, part.p_mfgr, supplier.s_address, supplier.s_phone, supplier.s_comment]\n" +
" └─ Sort(supplier.s_acctbal DESC, nation.n_name ASC, supplier.s_name ASC, part.p_partkey ASC)\n" +
" └─ Filter\n" +
" ├─ (partsupp.ps_supplycost = Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [min(partsupp.ps_supplycost) as min(ps_supplycost)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(MIN(partsupp.ps_supplycost))\n" +
" │ ├─ Grouping()\n" +
" │ └─ Filter\n" +
" │ ├─ (part.p_partkey = partsupp.ps_partkey)\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ Table\n" +
" │ │ │ │ ├─ name: partsupp\n" +
" │ │ │ │ └─ columns: [ps_partkey ps_suppkey ps_supplycost]\n" +
" │ │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ │ ├─ columns: [s_suppkey s_nationkey]\n" +
" │ │ │ └─ keys: partsupp.ps_suppkey\n" +
" │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ ├─ columns: [n_nationkey n_regionkey]\n" +
" │ │ └─ keys: supplier.s_nationkey\n" +
" │ └─ Filter\n" +
" │ ├─ (region.r_name = 'EUROPE')\n" +
" │ └─ IndexedTableAccess(region)\n" +
" │ ├─ index: [region.R_REGIONKEY]\n" +
" │ ├─ columns: [r_regionkey r_name]\n" +
" │ └─ keys: nation.n_regionkey\n" +
" │ )\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ MergeJoin\n" +
" │ │ │ ├─ cmp: (part.p_partkey = partsupp.ps_partkey)\n" +
" │ │ │ ├─ Filter\n" +
" │ │ │ │ ├─ ((part.p_size = 15) AND part.p_type LIKE '%BRASS')\n" +
" │ │ │ │ └─ IndexedTableAccess(part)\n" +
" │ │ │ │ ├─ index: [part.P_PARTKEY]\n" +
" │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ IndexedTableAccess(partsupp)\n" +
" │ │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ │ └─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ └─ keys: partsupp.ps_suppkey\n" +
" │ └─ IndexedTableAccess(nation)\n" +
" │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ └─ keys: supplier.s_nationkey\n" +
" └─ Filter\n" +
" ├─ (region.r_name = 'EUROPE')\n" +
" └─ IndexedTableAccess(region)\n" +
" ├─ index: [region.R_REGIONKEY]\n" +
" └─ keys: nation.n_regionkey\n" +
"",
},
{
Query: `
--Q3
select
l_orderkey,
sum(l_extendedprice * (1 - l_discount)) as revenue,
o_orderdate,
o_shippriority
from
customer,
orders,
lineitem
where
c_mktsegment = 'BUILDING'
and c_custkey = o_custkey
and l_orderkey = o_orderkey
and o_orderdate < '1995-03-15'
and l_shipdate > '1995-03-15'
group by
l_orderkey,
o_orderdate,
o_shippriority
order by
revenue desc,
o_orderdate;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [lineitem.l_orderkey:1!null, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as revenue, orders.o_orderdate:2!null, orders.o_shippriority:3!null]\n" +
" └─ Sort(sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as revenue DESC nullsFirst, orders.o_orderdate:2!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null, lineitem.l_orderkey:1!null, orders.o_orderdate:2!null, orders.o_shippriority:3!null, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as revenue]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM((lineitem.l_extendedprice:5!null * (1 (tinyint) - lineitem.l_discount:6!null))), lineitem.l_orderkey:4!null, orders.o_orderdate:2!null, orders.o_shippriority:3!null\n" +
" ├─ group: lineitem.l_orderkey:4!null, orders.o_orderdate:2!null, orders.o_shippriority:3!null\n" +
" └─ LookupJoin\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ orders.o_orderkey:0!null\n" +
" │ │ └─ lineitem.l_orderkey:4!null\n" +
" │ ├─ Filter\n" +
" │ │ ├─ LessThan\n" +
" │ │ │ ├─ orders.o_orderdate:2!null\n" +
" │ │ │ └─ 1995-03-15 (longtext)\n" +
" │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (9-17)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: orders\n" +
" │ │ └─ columns: [o_orderkey o_custkey o_orderdate o_shippriority]\n" +
" │ └─ Filter\n" +
" │ ├─ GreaterThan\n" +
" │ │ ├─ lineitem.l_shipdate:3!null\n" +
" │ │ └─ 1995-03-15 (longtext)\n" +
" │ └─ IndexedTableAccess(lineitem)\n" +
" │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ ├─ colSet: (18-33)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_orderkey l_extendedprice l_discount l_shipdate]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ customer.c_mktsegment:1!null\n" +
" │ └─ BUILDING (longtext)\n" +
" └─ IndexedTableAccess(customer)\n" +
" ├─ index: [customer.C_CUSTKEY]\n" +
" ├─ keys: [orders.o_custkey:1!null]\n" +
" ├─ colSet: (1-8)\n" +
" ├─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: customer\n" +
" └─ columns: [c_custkey c_mktsegment]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [lineitem.l_orderkey, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue, orders.o_orderdate, orders.o_shippriority]\n" +
" └─ Sort(sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue DESC, orders.o_orderdate ASC)\n" +
" └─ Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))), lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority)\n" +
" ├─ Grouping(lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority)\n" +
" └─ LookupJoin\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: (orders.o_orderkey = lineitem.l_orderkey)\n" +
" │ ├─ Filter\n" +
" │ │ ├─ (orders.o_orderdate < '1995-03-15')\n" +
" │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [o_orderkey o_custkey o_orderdate o_shippriority]\n" +
" │ └─ Filter\n" +
" │ ├─ (lineitem.l_shipdate > '1995-03-15')\n" +
" │ └─ IndexedTableAccess(lineitem)\n" +
" │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ └─ columns: [l_orderkey l_extendedprice l_discount l_shipdate]\n" +
" └─ Filter\n" +
" ├─ (customer.c_mktsegment = 'BUILDING')\n" +
" └─ IndexedTableAccess(customer)\n" +
" ├─ index: [customer.C_CUSTKEY]\n" +
" ├─ columns: [c_custkey c_mktsegment]\n" +
" └─ keys: orders.o_custkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [lineitem.l_orderkey, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue, orders.o_orderdate, orders.o_shippriority]\n" +
" └─ Sort(sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue DESC, orders.o_orderdate ASC)\n" +
" └─ Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))), lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority)\n" +
" ├─ Grouping(lineitem.l_orderkey, orders.o_orderdate, orders.o_shippriority)\n" +
" └─ LookupJoin\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: (orders.o_orderkey = lineitem.l_orderkey)\n" +
" │ ├─ Filter\n" +
" │ │ ├─ (orders.o_orderdate < '1995-03-15')\n" +
" │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [o_orderkey o_custkey o_orderdate o_shippriority]\n" +
" │ └─ Filter\n" +
" │ ├─ (lineitem.l_shipdate > '1995-03-15')\n" +
" │ └─ IndexedTableAccess(lineitem)\n" +
" │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ └─ columns: [l_orderkey l_extendedprice l_discount l_shipdate]\n" +
" └─ Filter\n" +
" ├─ (customer.c_mktsegment = 'BUILDING')\n" +
" └─ IndexedTableAccess(customer)\n" +
" ├─ index: [customer.C_CUSTKEY]\n" +
" ├─ columns: [c_custkey c_mktsegment]\n" +
" └─ keys: orders.o_custkey\n" +
"",
},
{
Query: `
--Q4
select
o_orderpriority,
count(*) as order_count
from
orders
where
o_orderdate >= '1993-07-01'
and o_orderdate < '1993-07-01' + interval '3' month
and exists (
select
*
from
lineitem
where
l_orderkey = o_orderkey
and l_commitdate < l_receiptdate
)
group by
o_orderpriority
order by
o_orderpriority;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [orders.o_orderpriority:1!null, count(1):0!null as order_count]\n" +
" └─ Sort(orders.o_orderpriority:1!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [count(1):0!null, orders.o_orderpriority:1!null, count(1):0!null as order_count]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(1 (bigint)), orders.o_orderpriority:5!null\n" +
" ├─ group: orders.o_orderpriority:5!null\n" +
" └─ Project\n" +
" ├─ columns: [orders.O_ORDERKEY:0!null, orders.O_CUSTKEY:1!null, orders.O_ORDERSTATUS:2!null, orders.O_TOTALPRICE:3!null, orders.O_ORDERDATE:4!null, orders.O_ORDERPRIORITY:5!null, orders.O_CLERK:6!null, orders.O_SHIPPRIORITY:7!null, orders.O_COMMENT:8!null]\n" +
" └─ MergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ orders.o_orderkey:0!null\n" +
" │ └─ lineitem.l_orderkey:9!null\n" +
" ├─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ ├─ orders.o_orderdate:4!null\n" +
" │ │ │ └─ 1993-07-01 (longtext)\n" +
" │ │ └─ LessThan\n" +
" │ │ ├─ orders.o_orderdate:4!null\n" +
" │ │ └─ 1993-10-01 00:00:00 +0000 UTC (datetime)\n" +
" │ └─ IndexedTableAccess(orders)\n" +
" │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (1-9)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: orders\n" +
" │ └─ columns: [o_orderkey o_custkey o_orderstatus o_totalprice o_orderdate o_orderpriority o_clerk o_shippriority o_comment]\n" +
" └─ Project\n" +
" ├─ columns: [lineitem.l_orderkey:0!null]\n" +
" └─ Filter\n" +
" ├─ LessThan\n" +
" │ ├─ lineitem.l_commitdate:11!null\n" +
" │ └─ lineitem.l_receiptdate:12!null\n" +
" └─ IndexedTableAccess(lineitem)\n" +
" ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" ├─ colSet: (10-25)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: lineitem\n" +
" └─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [orders.o_orderpriority, count(1) as order_count]\n" +
" └─ Sort(orders.o_orderpriority ASC)\n" +
" └─ Project\n" +
" ├─ columns: [count(1), orders.o_orderpriority, count(1) as order_count]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(1), orders.o_orderpriority)\n" +
" ├─ Grouping(orders.o_orderpriority)\n" +
" └─ Project\n" +
" ├─ columns: [orders.O_ORDERKEY, orders.O_CUSTKEY, orders.O_ORDERSTATUS, orders.O_TOTALPRICE, orders.O_ORDERDATE, orders.O_ORDERPRIORITY, orders.O_CLERK, orders.O_SHIPPRIORITY, orders.O_COMMENT]\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (orders.o_orderkey = lineitem.l_orderkey)\n" +
" ├─ Filter\n" +
" │ ├─ ((orders.o_orderdate >= '1993-07-01') AND (orders.o_orderdate < 1993-10-01 00:00:00 +0000 UTC))\n" +
" │ └─ IndexedTableAccess(orders)\n" +
" │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ └─ filters: [{[NULL, ∞)}]\n" +
" └─ Project\n" +
" ├─ columns: [lineitem.l_orderkey]\n" +
" └─ Filter\n" +
" ├─ (lineitem.l_commitdate < lineitem.l_receiptdate)\n" +
" └─ IndexedTableAccess(lineitem)\n" +
" ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" └─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [orders.o_orderpriority, count(1) as order_count]\n" +
" └─ Sort(orders.o_orderpriority ASC)\n" +
" └─ Project\n" +
" ├─ columns: [count(1), orders.o_orderpriority, count(1) as order_count]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(1), orders.o_orderpriority)\n" +
" ├─ Grouping(orders.o_orderpriority)\n" +
" └─ Project\n" +
" ├─ columns: [orders.O_ORDERKEY, orders.O_CUSTKEY, orders.O_ORDERSTATUS, orders.O_TOTALPRICE, orders.O_ORDERDATE, orders.O_ORDERPRIORITY, orders.O_CLERK, orders.O_SHIPPRIORITY, orders.O_COMMENT]\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (orders.o_orderkey = lineitem.l_orderkey)\n" +
" ├─ Filter\n" +
" │ ├─ ((orders.o_orderdate >= '1993-07-01') AND (orders.o_orderdate < 1993-10-01 00:00:00 +0000 UTC))\n" +
" │ └─ IndexedTableAccess(orders)\n" +
" │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ └─ filters: [{[NULL, ∞)}]\n" +
" └─ Project\n" +
" ├─ columns: [lineitem.l_orderkey]\n" +
" └─ Filter\n" +
" ├─ (lineitem.l_commitdate < lineitem.l_receiptdate)\n" +
" └─ IndexedTableAccess(lineitem)\n" +
" ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" └─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
"",
},
{
Query: `
--Q5
select
n_name,
sum(l_extendedprice * (1 - l_discount)) as revenue
from
customer,
orders,
lineitem,
supplier,
nation,
region
where
c_custkey = o_custkey
and l_orderkey = o_orderkey
and l_suppkey = s_suppkey
and c_nationkey = s_nationkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
and o_orderdate >= '1994-01-01'
and o_orderdate < '1994-01-01' + interval '1' year
group by
n_name
order by
revenue desc;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [nation.n_name:1!null, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as revenue]\n" +
" └─ Sort(sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as revenue DESC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null, nation.n_name:1!null, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as revenue]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM((lineitem.l_extendedprice:12!null * (1 (tinyint) - lineitem.l_discount:13!null))), nation.n_name:6!null\n" +
" ├─ group: nation.n_name:6!null\n" +
" └─ LookupJoin\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ customer.c_nationkey:4!null\n" +
" │ │ └─ supplier.s_nationkey:15!null\n" +
" │ └─ Eq\n" +
" │ ├─ supplier.s_nationkey:15!null\n" +
" │ └─ nation.n_nationkey:5!null\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ │ │ │ │ ├─ orders.o_orderdate:2!null\n" +
" │ │ │ │ │ │ │ └─ 1994-01-01 (longtext)\n" +
" │ │ │ │ │ │ └─ LessThan\n" +
" │ │ │ │ │ │ ├─ orders.o_orderdate:2!null\n" +
" │ │ │ │ │ │ └─ 1995-01-01 00:00:00 +0000 UTC (datetime)\n" +
" │ │ │ │ │ └─ ProcessTable\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: orders\n" +
" │ │ │ │ │ └─ columns: [o_orderkey o_custkey o_orderdate]\n" +
" │ │ │ │ └─ IndexedTableAccess(customer)\n" +
" │ │ │ │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ │ │ │ ├─ keys: [orders.o_custkey:1!null]\n" +
" │ │ │ │ ├─ colSet: (1-8)\n" +
" │ │ │ │ ├─ tableId: 1\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: customer\n" +
" │ │ │ │ └─ columns: [c_custkey c_nationkey]\n" +
" │ │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ │ ├─ keys: [customer.c_nationkey:4!null]\n" +
" │ │ │ ├─ colSet: (41-44)\n" +
" │ │ │ ├─ tableId: 5\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: nation\n" +
" │ │ │ └─ columns: [n_nationkey n_name n_regionkey]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ region.r_name:1!null\n" +
" │ │ │ └─ ASIA (longtext)\n" +
" │ │ └─ IndexedTableAccess(region)\n" +
" │ │ ├─ index: [region.R_REGIONKEY]\n" +
" │ │ ├─ keys: [nation.n_regionkey:7!null]\n" +
" │ │ ├─ colSet: (45-47)\n" +
" │ │ ├─ tableId: 6\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: region\n" +
" │ │ └─ columns: [r_regionkey r_name]\n" +
" │ └─ IndexedTableAccess(lineitem)\n" +
" │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ ├─ keys: [orders.o_orderkey:0!null]\n" +
" │ ├─ colSet: (18-33)\n" +
" │ ├─ tableId: 3\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_orderkey l_suppkey l_extendedprice l_discount]\n" +
" └─ IndexedTableAccess(supplier)\n" +
" ├─ index: [supplier.S_SUPPKEY]\n" +
" ├─ keys: [lineitem.l_suppkey:11!null]\n" +
" ├─ colSet: (34-40)\n" +
" ├─ tableId: 4\n" +
" └─ Table\n" +
" ├─ name: supplier\n" +
" └─ columns: [s_suppkey s_nationkey]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [nation.n_name, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue]\n" +
" └─ Sort(sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue DESC)\n" +
" └─ Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))), nation.n_name, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), nation.n_name)\n" +
" ├─ Grouping(nation.n_name)\n" +
" └─ LookupJoin\n" +
" ├─ ((customer.c_nationkey = supplier.s_nationkey) AND (supplier.s_nationkey = nation.n_nationkey))\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ ((orders.o_orderdate >= '1994-01-01') AND (orders.o_orderdate < 1995-01-01 00:00:00 +0000 UTC))\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: orders\n" +
" │ │ │ │ │ └─ columns: [o_orderkey o_custkey o_orderdate]\n" +
" │ │ │ │ └─ IndexedTableAccess(customer)\n" +
" │ │ │ │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ │ │ │ ├─ columns: [c_custkey c_nationkey]\n" +
" │ │ │ │ └─ keys: orders.o_custkey\n" +
" │ │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ │ ├─ columns: [n_nationkey n_name n_regionkey]\n" +
" │ │ │ └─ keys: customer.c_nationkey\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (region.r_name = 'ASIA')\n" +
" │ │ └─ IndexedTableAccess(region)\n" +
" │ │ ├─ index: [region.R_REGIONKEY]\n" +
" │ │ ├─ columns: [r_regionkey r_name]\n" +
" │ │ └─ keys: nation.n_regionkey\n" +
" │ └─ IndexedTableAccess(lineitem)\n" +
" │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ ├─ columns: [l_orderkey l_suppkey l_extendedprice l_discount]\n" +
" │ └─ keys: orders.o_orderkey\n" +
" └─ IndexedTableAccess(supplier)\n" +
" ├─ index: [supplier.S_SUPPKEY]\n" +
" ├─ columns: [s_suppkey s_nationkey]\n" +
" └─ keys: lineitem.l_suppkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [nation.n_name, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue]\n" +
" └─ Sort(sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue DESC)\n" +
" └─ Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))), nation.n_name, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), nation.n_name)\n" +
" ├─ Grouping(nation.n_name)\n" +
" └─ LookupJoin\n" +
" ├─ ((customer.c_nationkey = supplier.s_nationkey) AND (supplier.s_nationkey = nation.n_nationkey))\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ ((orders.o_orderdate >= '1994-01-01') AND (orders.o_orderdate < 1995-01-01 00:00:00 +0000 UTC))\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: orders\n" +
" │ │ │ │ │ └─ columns: [o_orderkey o_custkey o_orderdate]\n" +
" │ │ │ │ └─ IndexedTableAccess(customer)\n" +
" │ │ │ │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ │ │ │ ├─ columns: [c_custkey c_nationkey]\n" +
" │ │ │ │ └─ keys: orders.o_custkey\n" +
" │ │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ │ ├─ columns: [n_nationkey n_name n_regionkey]\n" +
" │ │ │ └─ keys: customer.c_nationkey\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (region.r_name = 'ASIA')\n" +
" │ │ └─ IndexedTableAccess(region)\n" +
" │ │ ├─ index: [region.R_REGIONKEY]\n" +
" │ │ ├─ columns: [r_regionkey r_name]\n" +
" │ │ └─ keys: nation.n_regionkey\n" +
" │ └─ IndexedTableAccess(lineitem)\n" +
" │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ ├─ columns: [l_orderkey l_suppkey l_extendedprice l_discount]\n" +
" │ └─ keys: orders.o_orderkey\n" +
" └─ IndexedTableAccess(supplier)\n" +
" ├─ index: [supplier.S_SUPPKEY]\n" +
" ├─ columns: [s_suppkey s_nationkey]\n" +
" └─ keys: lineitem.l_suppkey\n" +
"",
},
{
Query: `
--Q6
select
sum(l_extendedprice * l_discount) as revenue
from
lineitem
where
l_shipdate >= '1994-01-01'
and l_shipdate < '1994-01-01' + interval '1' year
and l_discount between .06 - 0.01 and .06 + 0.01
and l_quantity < 24;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * lineitem.l_discount)):0!null as revenue]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM((lineitem.l_extendedprice:1!null * lineitem.l_discount:2!null))\n" +
" ├─ group: \n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ │ ├─ lineitem.l_shipdate:3!null\n" +
" │ │ │ │ └─ 1994-01-01 (longtext)\n" +
" │ │ │ └─ LessThan\n" +
" │ │ │ ├─ lineitem.l_shipdate:3!null\n" +
" │ │ │ └─ 1995-01-01 00:00:00 +0000 UTC (datetime)\n" +
" │ │ └─ AND\n" +
" │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ ├─ lineitem.l_discount:2!null\n" +
" │ │ │ └─ 0.05 (decimal(5,2))\n" +
" │ │ └─ LessThanOrEqual\n" +
" │ │ ├─ lineitem.l_discount:2!null\n" +
" │ │ └─ 0.07 (decimal(5,2))\n" +
" │ └─ LessThan\n" +
" │ ├─ lineitem.l_quantity:0!null\n" +
" │ └─ 24 (tinyint)\n" +
" └─ ProcessTable\n" +
" └─ Table\n" +
" ├─ name: lineitem\n" +
" └─ columns: [l_quantity l_extendedprice l_discount l_shipdate]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * lineitem.l_discount)) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * lineitem.l_discount)))\n" +
" ├─ Grouping()\n" +
" └─ Filter\n" +
" ├─ ((((lineitem.l_shipdate >= '1994-01-01') AND (lineitem.l_shipdate < 1995-01-01 00:00:00 +0000 UTC)) AND ((lineitem.l_discount >= 0.05) AND (lineitem.l_discount <= 0.07))) AND (lineitem.l_quantity < 24))\n" +
" └─ Table\n" +
" ├─ name: lineitem\n" +
" └─ columns: [l_quantity l_extendedprice l_discount l_shipdate]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * lineitem.l_discount)) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * lineitem.l_discount)))\n" +
" ├─ Grouping()\n" +
" └─ Filter\n" +
" ├─ ((((lineitem.l_shipdate >= '1994-01-01') AND (lineitem.l_shipdate < 1995-01-01 00:00:00 +0000 UTC)) AND ((lineitem.l_discount >= 0.05) AND (lineitem.l_discount <= 0.07))) AND (lineitem.l_quantity < 24))\n" +
" └─ Table\n" +
" ├─ name: lineitem\n" +
" └─ columns: [l_quantity l_extendedprice l_discount l_shipdate]\n" +
"",
},
{
Query: `
--Q7
select
supp_nation,
cust_nation,
l_year,
sum(volume) as revenue
from
(
select
n1.n_name as supp_nation,
n2.n_name as cust_nation,
extract(year from l_shipdate) as l_year,
l_extendedprice * (1 - l_discount) as volume
from
supplier,
lineitem,
orders,
customer,
nation n1,
nation n2
where
s_suppkey = l_suppkey
and o_orderkey = l_orderkey
and c_custkey = o_custkey
and s_nationkey = n1.n_nationkey
and c_nationkey = n2.n_nationkey
and (
(n1.n_name = 'FRANCE' and n2.n_name = 'GERMANY')
or (n1.n_name = 'GERMANY' and n2.n_name = 'FRANCE')
)
and l_shipdate between '1995-01-01' and '1996-12-31'
) as shipping
group by
supp_nation,
cust_nation,
l_year
order by
supp_nation,
cust_nation,
l_year;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [shipping.supp_nation:1!null, shipping.cust_nation:2!null, shipping.l_year:3!null, sum(shipping.volume):0!null as revenue]\n" +
" └─ Sort(shipping.supp_nation:1!null ASC nullsFirst, shipping.cust_nation:2!null ASC nullsFirst, shipping.l_year:3!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sum(shipping.volume):0!null, shipping.supp_nation:1!null, shipping.cust_nation:2!null, shipping.l_year:3!null, sum(shipping.volume):0!null as revenue]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(shipping.volume:3!null), shipping.supp_nation:0!null, shipping.cust_nation:1!null, shipping.l_year:2!null\n" +
" ├─ group: shipping.supp_nation:0!null, shipping.cust_nation:1!null, shipping.l_year:2!null\n" +
" └─ SubqueryAlias\n" +
" ├─ name: shipping\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (53-56)\n" +
" ├─ tableId: 7\n" +
" └─ Project\n" +
" ├─ columns: [n1.n_name:12!null as supp_nation, n2.n_name:14!null as cust_nation, extract('YEAR' from lineitem.l_shipdate) as l_year, (lineitem.l_extendedprice:2!null * (1 (tinyint) - lineitem.l_discount:3!null)) as volume]\n" +
" └─ Filter\n" +
" ├─ Or\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ n1.n_name:12!null\n" +
" │ │ │ └─ FRANCE (longtext)\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ n2.n_name:14!null\n" +
" │ │ └─ GERMANY (longtext)\n" +
" │ └─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ n1.n_name:12!null\n" +
" │ │ └─ GERMANY (longtext)\n" +
" │ └─ Eq\n" +
" │ ├─ n2.n_name:14!null\n" +
" │ └─ FRANCE (longtext)\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ lineitem.l_orderkey:0!null\n" +
" │ │ │ │ │ └─ orders.o_orderkey:5!null\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ │ │ │ │ ├─ lineitem.l_shipdate:4!null\n" +
" │ │ │ │ │ │ │ └─ 1995-01-01 (longtext)\n" +
" │ │ │ │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ │ │ │ ├─ lineitem.l_shipdate:4!null\n" +
" │ │ │ │ │ │ └─ 1996-12-31 (longtext)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ │ │ ├─ colSet: (8-23)\n" +
" │ │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: lineitem\n" +
" │ │ │ │ │ └─ columns: [l_orderkey l_suppkey l_extendedprice l_discount l_shipdate]\n" +
" │ │ │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (24-32)\n" +
" │ │ │ │ ├─ tableId: 3\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: orders\n" +
" │ │ │ │ └─ columns: [o_orderkey o_custkey]\n" +
" │ │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ │ ├─ keys: [lineitem.l_suppkey:1!null]\n" +
" │ │ │ ├─ colSet: (1-7)\n" +
" │ │ │ ├─ tableId: 1\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: supplier\n" +
" │ │ │ └─ columns: [s_suppkey s_nationkey]\n" +
" │ │ └─ IndexedTableAccess(customer)\n" +
" │ │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ │ ├─ keys: [orders.o_custkey:6!null]\n" +
" │ │ ├─ colSet: (33-40)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: customer\n" +
" │ │ └─ columns: [c_custkey c_nationkey]\n" +
" │ └─ TableAlias(n1)\n" +
" │ └─ IndexedTableAccess(nation)\n" +
" │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ ├─ keys: [supplier.s_nationkey:8!null]\n" +
" │ ├─ colSet: (41-44)\n" +
" │ ├─ tableId: 5\n" +
" │ └─ Table\n" +
" │ ├─ name: nation\n" +
" │ └─ columns: [n_nationkey n_name]\n" +
" └─ TableAlias(n2)\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ keys: [customer.c_nationkey:10!null]\n" +
" ├─ colSet: (45-48)\n" +
" ├─ tableId: 6\n" +
" └─ Table\n" +
" ├─ name: nation\n" +
" └─ columns: [n_nationkey n_name]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [shipping.supp_nation, shipping.cust_nation, shipping.l_year, sum(shipping.volume) as revenue]\n" +
" └─ Sort(shipping.supp_nation ASC, shipping.cust_nation ASC, shipping.l_year ASC)\n" +
" └─ Project\n" +
" ├─ columns: [sum(shipping.volume), shipping.supp_nation, shipping.cust_nation, shipping.l_year, sum(shipping.volume) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(shipping.volume), shipping.supp_nation, shipping.cust_nation, shipping.l_year)\n" +
" ├─ Grouping(shipping.supp_nation, shipping.cust_nation, shipping.l_year)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: shipping\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [n1.n_name as supp_nation, n2.n_name as cust_nation, extract('YEAR' from lineitem.l_shipdate) as l_year, (lineitem.l_extendedprice * (1 - lineitem.l_discount)) as volume]\n" +
" └─ Filter\n" +
" ├─ (((n1.n_name = 'FRANCE') AND (n2.n_name = 'GERMANY')) OR ((n1.n_name = 'GERMANY') AND (n2.n_name = 'FRANCE')))\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (lineitem.l_orderkey = orders.o_orderkey)\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ ((lineitem.l_shipdate >= '1995-01-01') AND (lineitem.l_shipdate <= '1996-12-31'))\n" +
" │ │ │ │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [l_orderkey l_suppkey l_extendedprice l_discount l_shipdate]\n" +
" │ │ │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [o_orderkey o_custkey]\n" +
" │ │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ │ ├─ columns: [s_suppkey s_nationkey]\n" +
" │ │ │ └─ keys: lineitem.l_suppkey\n" +
" │ │ └─ IndexedTableAccess(customer)\n" +
" │ │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ │ ├─ columns: [c_custkey c_nationkey]\n" +
" │ │ └─ keys: orders.o_custkey\n" +
" │ └─ TableAlias(n1)\n" +
" │ └─ IndexedTableAccess(nation)\n" +
" │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ ├─ columns: [n_nationkey n_name]\n" +
" │ └─ keys: supplier.s_nationkey\n" +
" └─ TableAlias(n2)\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ columns: [n_nationkey n_name]\n" +
" └─ keys: customer.c_nationkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [shipping.supp_nation, shipping.cust_nation, shipping.l_year, sum(shipping.volume) as revenue]\n" +
" └─ Sort(shipping.supp_nation ASC, shipping.cust_nation ASC, shipping.l_year ASC)\n" +
" └─ Project\n" +
" ├─ columns: [sum(shipping.volume), shipping.supp_nation, shipping.cust_nation, shipping.l_year, sum(shipping.volume) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(shipping.volume), shipping.supp_nation, shipping.cust_nation, shipping.l_year)\n" +
" ├─ Grouping(shipping.supp_nation, shipping.cust_nation, shipping.l_year)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: shipping\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [n1.n_name as supp_nation, n2.n_name as cust_nation, extract('YEAR' from lineitem.l_shipdate) as l_year, (lineitem.l_extendedprice * (1 - lineitem.l_discount)) as volume]\n" +
" └─ Filter\n" +
" ├─ (((n1.n_name = 'FRANCE') AND (n2.n_name = 'GERMANY')) OR ((n1.n_name = 'GERMANY') AND (n2.n_name = 'FRANCE')))\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (lineitem.l_orderkey = orders.o_orderkey)\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ ((lineitem.l_shipdate >= '1995-01-01') AND (lineitem.l_shipdate <= '1996-12-31'))\n" +
" │ │ │ │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ │ │ ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ │ │ └─ columns: [l_orderkey l_suppkey l_extendedprice l_discount l_shipdate]\n" +
" │ │ │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ │ └─ columns: [o_orderkey o_custkey]\n" +
" │ │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ │ ├─ columns: [s_suppkey s_nationkey]\n" +
" │ │ │ └─ keys: lineitem.l_suppkey\n" +
" │ │ └─ IndexedTableAccess(customer)\n" +
" │ │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ │ ├─ columns: [c_custkey c_nationkey]\n" +
" │ │ └─ keys: orders.o_custkey\n" +
" │ └─ TableAlias(n1)\n" +
" │ └─ IndexedTableAccess(nation)\n" +
" │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ ├─ columns: [n_nationkey n_name]\n" +
" │ └─ keys: supplier.s_nationkey\n" +
" └─ TableAlias(n2)\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ columns: [n_nationkey n_name]\n" +
" └─ keys: customer.c_nationkey\n" +
"",
},
{
Query: `
--Q8
select
o_year,
sum(case
when nation = 'BRAZIL' then volume
else 0
end) / sum(volume) as mkt_share
from
(
select
extract(year from o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) as volume,
n2.n_name as nation
from
part,
supplier,
lineitem,
orders,
customer,
nation n1,
nation n2,
region
where
p_partkey = l_partkey
and s_suppkey = l_suppkey
and l_orderkey = o_orderkey
and o_custkey = c_custkey
and c_nationkey = n1.n_nationkey
and n1.n_regionkey = r_regionkey
and r_name = 'AMERICA'
and s_nationkey = n2.n_nationkey
and o_orderdate between '1995-01-01' and '1996-12-31'
and p_type = 'ECONOMY ANODIZED STEEL'
) as all_nations
group by
o_year
order by
o_year;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [all_nations.o_year:2!null, (sum(case when (all_nations.nation = 'brazil') then all_nations.volume else 0 end):0!null / sum(all_nations.volume):1!null) as mkt_share]\n" +
" └─ Sort(all_nations.o_year:2!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sum(case when (all_nations.nation = 'brazil') then all_nations.volume else 0 end):0!null, sum(all_nations.volume):1!null, all_nations.o_year:2!null, (sum(case when (all_nations.nation = 'brazil') then all_nations.volume else 0 end):0!null / sum(all_nations.volume):1!null) as mkt_share]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(CASE WHEN Eq\n" +
" │ ├─ all_nations.nation:2!null\n" +
" │ └─ BRAZIL (longtext)\n" +
" │ THEN all_nations.volume:1!null ELSE 0 (tinyint) END), SUM(all_nations.volume:1!null), all_nations.o_year:0!null\n" +
" ├─ group: all_nations.o_year:0!null\n" +
" └─ SubqueryAlias\n" +
" ├─ name: all_nations\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (64-66)\n" +
" ├─ tableId: 9\n" +
" └─ Project\n" +
" ├─ columns: [extract('YEAR' from orders.o_orderdate) as o_year, (lineitem.l_extendedprice:12!null * (1 (tinyint) - lineitem.l_discount:13!null)) as volume, n2.n_name:19!null as nation]\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ │ │ │ │ │ │ ├─ orders.o_orderdate:2!null\n" +
" │ │ │ │ │ │ │ │ │ └─ 1995-01-01 (longtext)\n" +
" │ │ │ │ │ │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ │ │ │ │ │ ├─ orders.o_orderdate:2!null\n" +
" │ │ │ │ │ │ │ │ └─ 1996-12-31 (longtext)\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: orders\n" +
" │ │ │ │ │ │ │ ├─ columns: [o_orderkey o_custkey o_orderdate]\n" +
" │ │ │ │ │ │ │ ├─ colSet: (33-41)\n" +
" │ │ │ │ │ │ │ └─ tableId: 4\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(customer)\n" +
" │ │ │ │ │ │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ │ │ │ │ │ ├─ keys: [orders.o_custkey:1!null]\n" +
" │ │ │ │ │ │ ├─ colSet: (42-49)\n" +
" │ │ │ │ │ │ ├─ tableId: 5\n" +
" │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ ├─ name: customer\n" +
" │ │ │ │ │ │ └─ columns: [c_custkey c_nationkey]\n" +
" │ │ │ │ │ └─ TableAlias(n1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ │ │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ │ │ │ ├─ keys: [customer.c_nationkey:4!null]\n" +
" │ │ │ │ │ ├─ colSet: (50-53)\n" +
" │ │ │ │ │ ├─ tableId: 6\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: nation\n" +
" │ │ │ │ │ └─ columns: [n_nationkey n_regionkey]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ region.r_name:1!null\n" +
" │ │ │ │ │ └─ AMERICA (longtext)\n" +
" │ │ │ │ └─ IndexedTableAccess(region)\n" +
" │ │ │ │ ├─ index: [region.R_REGIONKEY]\n" +
" │ │ │ │ ├─ keys: [n1.n_regionkey:6!null]\n" +
" │ │ │ │ ├─ colSet: (58-60)\n" +
" │ │ │ │ ├─ tableId: 8\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: region\n" +
" │ │ │ │ └─ columns: [r_regionkey r_name]\n" +
" │ │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ ├─ keys: [orders.o_orderkey:0!null]\n" +
" │ │ │ ├─ colSet: (17-32)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: lineitem\n" +
" │ │ │ └─ columns: [l_orderkey l_partkey l_suppkey l_extendedprice l_discount]\n" +
" │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ ├─ keys: [lineitem.l_suppkey:11!null]\n" +
" │ │ ├─ colSet: (10-16)\n" +
" │ │ ├─ tableId: 2\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: supplier\n" +
" │ │ └─ columns: [s_suppkey s_nationkey]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ part.p_type:1!null\n" +
" │ │ └─ ECONOMY ANODIZED STEEL (longtext)\n" +
" │ └─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ ├─ keys: [lineitem.l_partkey:10!null]\n" +
" │ ├─ colSet: (1-9)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: part\n" +
" │ └─ columns: [p_partkey p_type]\n" +
" └─ TableAlias(n2)\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ keys: [supplier.s_nationkey:15!null]\n" +
" ├─ colSet: (54-57)\n" +
" ├─ tableId: 7\n" +
" └─ Table\n" +
" ├─ name: nation\n" +
" └─ columns: [n_nationkey n_name]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [all_nations.o_year, (sum(case when (all_nations.nation = 'brazil') then all_nations.volume else 0 end) / sum(all_nations.volume)) as mkt_share]\n" +
" └─ Sort(all_nations.o_year ASC)\n" +
" └─ Project\n" +
" ├─ columns: [sum(case when (all_nations.nation = 'brazil') then all_nations.volume else 0 end), sum(all_nations.volume), all_nations.o_year, (sum(case when (all_nations.nation = 'brazil') then all_nations.volume else 0 end) / sum(all_nations.volume)) as mkt_share]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(CASE WHEN (all_nations.nation = 'BRAZIL') THEN all_nations.volume ELSE 0 END), SUM(all_nations.volume), all_nations.o_year)\n" +
" ├─ Grouping(all_nations.o_year)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: all_nations\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [extract('YEAR' from orders.o_orderdate) as o_year, (lineitem.l_extendedprice * (1 - lineitem.l_discount)) as volume, n2.n_name as nation]\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ │ ├─ ((orders.o_orderdate >= '1995-01-01') AND (orders.o_orderdate <= '1996-12-31'))\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: orders\n" +
" │ │ │ │ │ │ │ └─ columns: [o_orderkey o_custkey o_orderdate]\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(customer)\n" +
" │ │ │ │ │ │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ │ │ │ │ │ ├─ columns: [c_custkey c_nationkey]\n" +
" │ │ │ │ │ │ └─ keys: orders.o_custkey\n" +
" │ │ │ │ │ └─ TableAlias(n1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ │ │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ │ │ │ ├─ columns: [n_nationkey n_regionkey]\n" +
" │ │ │ │ │ └─ keys: customer.c_nationkey\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (region.r_name = 'AMERICA')\n" +
" │ │ │ │ └─ IndexedTableAccess(region)\n" +
" │ │ │ │ ├─ index: [region.R_REGIONKEY]\n" +
" │ │ │ │ ├─ columns: [r_regionkey r_name]\n" +
" │ │ │ │ └─ keys: n1.n_regionkey\n" +
" │ │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ ├─ columns: [l_orderkey l_partkey l_suppkey l_extendedprice l_discount]\n" +
" │ │ │ └─ keys: orders.o_orderkey\n" +
" │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ ├─ columns: [s_suppkey s_nationkey]\n" +
" │ │ └─ keys: lineitem.l_suppkey\n" +
" │ └─ Filter\n" +
" │ ├─ (part.p_type = 'ECONOMY ANODIZED STEEL')\n" +
" │ └─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ ├─ columns: [p_partkey p_type]\n" +
" │ └─ keys: lineitem.l_partkey\n" +
" └─ TableAlias(n2)\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ columns: [n_nationkey n_name]\n" +
" └─ keys: supplier.s_nationkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [all_nations.o_year, (sum(case when (all_nations.nation = 'brazil') then all_nations.volume else 0 end) / sum(all_nations.volume)) as mkt_share]\n" +
" └─ Sort(all_nations.o_year ASC)\n" +
" └─ Project\n" +
" ├─ columns: [sum(case when (all_nations.nation = 'brazil') then all_nations.volume else 0 end), sum(all_nations.volume), all_nations.o_year, (sum(case when (all_nations.nation = 'brazil') then all_nations.volume else 0 end) / sum(all_nations.volume)) as mkt_share]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(CASE WHEN (all_nations.nation = 'BRAZIL') THEN all_nations.volume ELSE 0 END), SUM(all_nations.volume), all_nations.o_year)\n" +
" ├─ Grouping(all_nations.o_year)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: all_nations\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [extract('YEAR' from orders.o_orderdate) as o_year, (lineitem.l_extendedprice * (1 - lineitem.l_discount)) as volume, n2.n_name as nation]\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ ├─ LookupJoin\n" +
" │ │ │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ │ │ ├─ ((orders.o_orderdate >= '1995-01-01') AND (orders.o_orderdate <= '1996-12-31'))\n" +
" │ │ │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ │ │ ├─ name: orders\n" +
" │ │ │ │ │ │ │ └─ columns: [o_orderkey o_custkey o_orderdate]\n" +
" │ │ │ │ │ │ └─ IndexedTableAccess(customer)\n" +
" │ │ │ │ │ │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ │ │ │ │ │ ├─ columns: [c_custkey c_nationkey]\n" +
" │ │ │ │ │ │ └─ keys: orders.o_custkey\n" +
" │ │ │ │ │ └─ TableAlias(n1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ │ │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ │ │ │ ├─ columns: [n_nationkey n_regionkey]\n" +
" │ │ │ │ │ └─ keys: customer.c_nationkey\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (region.r_name = 'AMERICA')\n" +
" │ │ │ │ └─ IndexedTableAccess(region)\n" +
" │ │ │ │ ├─ index: [region.R_REGIONKEY]\n" +
" │ │ │ │ ├─ columns: [r_regionkey r_name]\n" +
" │ │ │ │ └─ keys: n1.n_regionkey\n" +
" │ │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ ├─ columns: [l_orderkey l_partkey l_suppkey l_extendedprice l_discount]\n" +
" │ │ │ └─ keys: orders.o_orderkey\n" +
" │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ ├─ columns: [s_suppkey s_nationkey]\n" +
" │ │ └─ keys: lineitem.l_suppkey\n" +
" │ └─ Filter\n" +
" │ ├─ (part.p_type = 'ECONOMY ANODIZED STEEL')\n" +
" │ └─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ ├─ columns: [p_partkey p_type]\n" +
" │ └─ keys: lineitem.l_partkey\n" +
" └─ TableAlias(n2)\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ columns: [n_nationkey n_name]\n" +
" └─ keys: supplier.s_nationkey\n" +
"",
},
{
Query: `
--Q9
select
nation,
o_year,
sum(amount) as sum_profit
from
(
select
n_name as nation,
extract(year from o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
from
part,
supplier,
lineitem,
partsupp,
orders,
nation
where
s_suppkey = l_suppkey
and ps_suppkey = l_suppkey
and ps_partkey = l_partkey
and p_partkey = l_partkey
and o_orderkey = l_orderkey
and s_nationkey = n_nationkey
and p_name like '%green%'
) as profit
group by
nation,
o_year
order by
nation,
o_year desc;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [profit.nation:1!null, profit.o_year:2!null, sum(profit.amount):0!null as sum_profit]\n" +
" └─ Sort(profit.nation:1!null ASC nullsFirst, profit.o_year:2!null DESC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sum(profit.amount):0!null, profit.nation:1!null, profit.o_year:2!null, sum(profit.amount):0!null as sum_profit]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(profit.amount:2!null), profit.nation:0!null, profit.o_year:1!null\n" +
" ├─ group: profit.nation:0!null, profit.o_year:1!null\n" +
" └─ SubqueryAlias\n" +
" ├─ name: profit\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (54-56)\n" +
" ├─ tableId: 7\n" +
" └─ Project\n" +
" ├─ columns: [nation.n_name:16!null as nation, extract('YEAR' from orders.o_orderdate) as o_year, ((lineitem.l_extendedprice:9!null * (1 (tinyint) - lineitem.l_discount:10!null)) - (partsupp.ps_supplycost:4!null * lineitem.l_quantity:8!null)) as amount]\n" +
" └─ LookupJoin\n" +
" ├─ HashJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ part.p_partkey:0!null\n" +
" │ │ │ │ │ └─ lineitem.l_partkey:6!null\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ partsupp.ps_suppkey:3!null\n" +
" │ │ │ │ └─ lineitem.l_suppkey:7!null\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ partsupp.ps_partkey:2!null\n" +
" │ │ │ └─ lineitem.l_partkey:6!null\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ supplier.s_suppkey:13!null\n" +
" │ │ └─ partsupp.ps_suppkey:3!null\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ part.p_partkey:0!null\n" +
" │ │ │ └─ partsupp.ps_partkey:2!null\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ part.p_name LIKE '%green%'\n" +
" │ │ │ └─ IndexedTableAccess(part)\n" +
" │ │ │ ├─ index: [part.P_PARTKEY]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (1-9)\n" +
" │ │ │ ├─ tableId: 1\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: part\n" +
" │ │ │ └─ columns: [p_partkey p_name]\n" +
" │ │ └─ IndexedTableAccess(partsupp)\n" +
" │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ ├─ colSet: (33-37)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: partsupp\n" +
" │ │ └─ columns: [ps_partkey ps_suppkey ps_supplycost]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: TUPLE(part.p_partkey:0!null, partsupp.ps_suppkey:3!null, partsupp.ps_partkey:2!null, partsupp.ps_suppkey:3!null)\n" +
" │ ├─ right-key: TUPLE(lineitem.l_partkey:1!null, lineitem.l_suppkey:2!null, lineitem.l_partkey:1!null, supplier.s_suppkey:8!null)\n" +
" │ └─ LookupJoin\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ lineitem.l_orderkey:5!null\n" +
" │ │ │ └─ orders.o_orderkey:11!null\n" +
" │ │ ├─ IndexedTableAccess(lineitem)\n" +
" │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (17-32)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: lineitem\n" +
" │ │ │ └─ columns: [l_orderkey l_partkey l_suppkey l_quantity l_extendedprice l_discount]\n" +
" │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (38-46)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: orders\n" +
" │ │ └─ columns: [o_orderkey o_orderdate]\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ ├─ keys: [lineitem.l_suppkey:7!null]\n" +
" │ ├─ colSet: (10-16)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: supplier\n" +
" │ └─ columns: [s_suppkey s_nationkey]\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ keys: [supplier.s_nationkey:14!null]\n" +
" ├─ colSet: (47-50)\n" +
" ├─ tableId: 6\n" +
" └─ Table\n" +
" ├─ name: nation\n" +
" └─ columns: [n_nationkey n_name]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [profit.nation, profit.o_year, sum(profit.amount) as sum_profit]\n" +
" └─ Sort(profit.nation ASC, profit.o_year DESC)\n" +
" └─ Project\n" +
" ├─ columns: [sum(profit.amount), profit.nation, profit.o_year, sum(profit.amount) as sum_profit]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(profit.amount), profit.nation, profit.o_year)\n" +
" ├─ Grouping(profit.nation, profit.o_year)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: profit\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nation.n_name as nation, extract('YEAR' from orders.o_orderdate) as o_year, ((lineitem.l_extendedprice * (1 - lineitem.l_discount)) - (partsupp.ps_supplycost * lineitem.l_quantity)) as amount]\n" +
" └─ LookupJoin\n" +
" ├─ HashJoin\n" +
" │ ├─ ((((part.p_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) AND (partsupp.ps_partkey = lineitem.l_partkey)) AND (supplier.s_suppkey = partsupp.ps_suppkey))\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (part.p_partkey = partsupp.ps_partkey)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ part.p_name LIKE '%green%'\n" +
" │ │ │ └─ IndexedTableAccess(part)\n" +
" │ │ │ ├─ index: [part.P_PARTKEY]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [p_partkey p_name]\n" +
" │ │ └─ IndexedTableAccess(partsupp)\n" +
" │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ └─ columns: [ps_partkey ps_suppkey ps_supplycost]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (part.p_partkey, partsupp.ps_suppkey, partsupp.ps_partkey, partsupp.ps_suppkey)\n" +
" │ ├─ right-key: (lineitem.l_partkey, lineitem.l_suppkey, lineitem.l_partkey, supplier.s_suppkey)\n" +
" │ └─ LookupJoin\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (lineitem.l_orderkey = orders.o_orderkey)\n" +
" │ │ ├─ IndexedTableAccess(lineitem)\n" +
" │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ └─ columns: [l_orderkey l_partkey l_suppkey l_quantity l_extendedprice l_discount]\n" +
" │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [o_orderkey o_orderdate]\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ ├─ columns: [s_suppkey s_nationkey]\n" +
" │ └─ keys: lineitem.l_suppkey\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ columns: [n_nationkey n_name]\n" +
" └─ keys: supplier.s_nationkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [profit.nation, profit.o_year, sum(profit.amount) as sum_profit]\n" +
" └─ Sort(profit.nation ASC, profit.o_year DESC)\n" +
" └─ Project\n" +
" ├─ columns: [sum(profit.amount), profit.nation, profit.o_year, sum(profit.amount) as sum_profit]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(profit.amount), profit.nation, profit.o_year)\n" +
" ├─ Grouping(profit.nation, profit.o_year)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: profit\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [nation.n_name as nation, extract('YEAR' from orders.o_orderdate) as o_year, ((lineitem.l_extendedprice * (1 - lineitem.l_discount)) - (partsupp.ps_supplycost * lineitem.l_quantity)) as amount]\n" +
" └─ LookupJoin\n" +
" ├─ HashJoin\n" +
" │ ├─ ((((part.p_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) AND (partsupp.ps_partkey = lineitem.l_partkey)) AND (supplier.s_suppkey = partsupp.ps_suppkey))\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (part.p_partkey = partsupp.ps_partkey)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ part.p_name LIKE '%green%'\n" +
" │ │ │ └─ IndexedTableAccess(part)\n" +
" │ │ │ ├─ index: [part.P_PARTKEY]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [p_partkey p_name]\n" +
" │ │ └─ IndexedTableAccess(partsupp)\n" +
" │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ └─ columns: [ps_partkey ps_suppkey ps_supplycost]\n" +
" │ └─ HashLookup\n" +
" │ ├─ left-key: (part.p_partkey, partsupp.ps_suppkey, partsupp.ps_partkey, partsupp.ps_suppkey)\n" +
" │ ├─ right-key: (lineitem.l_partkey, lineitem.l_suppkey, lineitem.l_partkey, supplier.s_suppkey)\n" +
" │ └─ LookupJoin\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (lineitem.l_orderkey = orders.o_orderkey)\n" +
" │ │ ├─ IndexedTableAccess(lineitem)\n" +
" │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ └─ columns: [l_orderkey l_partkey l_suppkey l_quantity l_extendedprice l_discount]\n" +
" │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ └─ columns: [o_orderkey o_orderdate]\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ ├─ columns: [s_suppkey s_nationkey]\n" +
" │ └─ keys: lineitem.l_suppkey\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ columns: [n_nationkey n_name]\n" +
" └─ keys: supplier.s_nationkey\n" +
"",
},
{
Query: `
--Q10
select
c_custkey,
c_name,
sum(l_extendedprice * (1 - l_discount)) as revenue,
c_acctbal,
n_name,
c_address,
c_phone,
c_comment
from
customer,
orders,
lineitem,
nation
where
c_custkey = o_custkey
and l_orderkey = o_orderkey
and o_orderdate >= '1993-10-01'
and o_orderdate < '1993-10-01' + interval '3' month
and l_returnflag = 'R'
and c_nationkey = n_nationkey
group by
c_custkey,
c_name,
c_acctbal,
c_phone,
n_name,
c_address,
c_comment
order by
revenue desc;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [customer.c_custkey:1!null, customer.c_name:2!null, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as revenue, customer.c_acctbal:3!null, nation.n_name:4!null, customer.c_address:5!null, customer.c_phone:6!null, customer.c_comment:7!null]\n" +
" └─ Sort(sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as revenue DESC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null, customer.c_custkey:1!null, customer.c_name:2!null, customer.c_acctbal:3!null, nation.n_name:4!null, customer.c_address:5!null, customer.c_phone:6!null, customer.c_comment:7!null, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as revenue]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM((lineitem.l_extendedprice:4!null * (1 (tinyint) - lineitem.l_discount:5!null))), customer.c_custkey:7!null, customer.c_name:8!null, customer.c_acctbal:12!null, nation.n_name:15!null, customer.c_address:9!null, customer.c_phone:11!null, customer.c_comment:13!null\n" +
" ├─ group: customer.c_custkey:7!null, customer.c_name:8!null, customer.c_acctbal:12!null, customer.c_phone:11!null, nation.n_name:15!null, customer.c_address:9!null, customer.c_comment:13!null\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ orders.o_orderkey:0!null\n" +
" │ │ │ └─ lineitem.l_orderkey:3!null\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ │ │ ├─ orders.o_orderdate:2!null\n" +
" │ │ │ │ │ └─ 1993-10-01 (longtext)\n" +
" │ │ │ │ └─ LessThan\n" +
" │ │ │ │ ├─ orders.o_orderdate:2!null\n" +
" │ │ │ │ └─ 1994-01-01 00:00:00 +0000 UTC (datetime)\n" +
" │ │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (9-17)\n" +
" │ │ │ ├─ tableId: 2\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: orders\n" +
" │ │ │ └─ columns: [o_orderkey o_custkey o_orderdate]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ lineitem.l_returnflag:3!null\n" +
" │ │ │ └─ R (longtext)\n" +
" │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ ├─ colSet: (18-33)\n" +
" │ │ ├─ tableId: 3\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: lineitem\n" +
" │ │ └─ columns: [l_orderkey l_extendedprice l_discount l_returnflag]\n" +
" │ └─ IndexedTableAccess(customer)\n" +
" │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ ├─ keys: [orders.o_custkey:1!null]\n" +
" │ ├─ colSet: (1-8)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: customer\n" +
" │ └─ columns: [c_custkey c_name c_address c_nationkey c_phone c_acctbal c_comment]\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ keys: [customer.c_nationkey:10!null]\n" +
" ├─ colSet: (34-37)\n" +
" ├─ tableId: 4\n" +
" └─ Table\n" +
" ├─ name: nation\n" +
" └─ columns: [n_nationkey n_name]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [customer.c_custkey, customer.c_name, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue, customer.c_acctbal, nation.n_name, customer.c_address, customer.c_phone, customer.c_comment]\n" +
" └─ Sort(sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue DESC)\n" +
" └─ Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))), customer.c_custkey, customer.c_name, customer.c_acctbal, nation.n_name, customer.c_address, customer.c_phone, customer.c_comment, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), customer.c_custkey, customer.c_name, customer.c_acctbal, nation.n_name, customer.c_address, customer.c_phone, customer.c_comment)\n" +
" ├─ Grouping(customer.c_custkey, customer.c_name, customer.c_acctbal, customer.c_phone, nation.n_name, customer.c_address, customer.c_comment)\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (orders.o_orderkey = lineitem.l_orderkey)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ ((orders.o_orderdate >= '1993-10-01') AND (orders.o_orderdate < 1994-01-01 00:00:00 +0000 UTC))\n" +
" │ │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [o_orderkey o_custkey o_orderdate]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (lineitem.l_returnflag = 'R')\n" +
" │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ └─ columns: [l_orderkey l_extendedprice l_discount l_returnflag]\n" +
" │ └─ IndexedTableAccess(customer)\n" +
" │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ ├─ columns: [c_custkey c_name c_address c_nationkey c_phone c_acctbal c_comment]\n" +
" │ └─ keys: orders.o_custkey\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ columns: [n_nationkey n_name]\n" +
" └─ keys: customer.c_nationkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [customer.c_custkey, customer.c_name, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue, customer.c_acctbal, nation.n_name, customer.c_address, customer.c_phone, customer.c_comment]\n" +
" └─ Sort(sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue DESC)\n" +
" └─ Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))), customer.c_custkey, customer.c_name, customer.c_acctbal, nation.n_name, customer.c_address, customer.c_phone, customer.c_comment, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), customer.c_custkey, customer.c_name, customer.c_acctbal, nation.n_name, customer.c_address, customer.c_phone, customer.c_comment)\n" +
" ├─ Grouping(customer.c_custkey, customer.c_name, customer.c_acctbal, customer.c_phone, nation.n_name, customer.c_address, customer.c_comment)\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ MergeJoin\n" +
" │ │ ├─ cmp: (orders.o_orderkey = lineitem.l_orderkey)\n" +
" │ │ ├─ Filter\n" +
" │ │ │ ├─ ((orders.o_orderdate >= '1993-10-01') AND (orders.o_orderdate < 1994-01-01 00:00:00 +0000 UTC))\n" +
" │ │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ columns: [o_orderkey o_custkey o_orderdate]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (lineitem.l_returnflag = 'R')\n" +
" │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ └─ columns: [l_orderkey l_extendedprice l_discount l_returnflag]\n" +
" │ └─ IndexedTableAccess(customer)\n" +
" │ ├─ index: [customer.C_CUSTKEY]\n" +
" │ ├─ columns: [c_custkey c_name c_address c_nationkey c_phone c_acctbal c_comment]\n" +
" │ └─ keys: orders.o_custkey\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ columns: [n_nationkey n_name]\n" +
" └─ keys: customer.c_nationkey\n" +
"",
},
{
Query: `
--Q11
select
ps_partkey,
sum(ps_supplycost * ps_availqty) as value
from
partsupp,
supplier,
nation
where
ps_suppkey = s_suppkey
and s_nationkey = n_nationkey
and n_name = 'GERMANY'
group by
ps_partkey having
sum(ps_supplycost * ps_availqty) > (
select
sum(ps_supplycost * ps_availqty) * 0.0001000000
from
partsupp,
supplier,
nation
where
ps_suppkey = s_suppkey
and s_nationkey = n_nationkey
and n_name = 'GERMANY'
)
order by
value desc;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [partsupp.ps_partkey:1!null, sum((partsupp.ps_supplycost * partsupp.ps_availqty)):0!null as value]\n" +
" └─ Sort(sum((partsupp.ps_supplycost * partsupp.ps_availqty)):0!null as value DESC nullsFirst)\n" +
" └─ Having\n" +
" ├─ GreaterThan\n" +
" │ ├─ sum((partsupp.ps_supplycost * partsupp.ps_availqty)):0!null\n" +
" │ └─ Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ alias-string: select sum(ps_supplycost * ps_availqty) * 0.0001000000 from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = 'GERMANY'\n" +
" │ └─ Project\n" +
" │ ├─ columns: [(sum((partsupp.ps_supplycost * partsupp.ps_availqty)):0!null * 0.0001 (decimal(11,10))) as sum(ps_supplycost * ps_availqty) * 0.0001000000]\n" +
" │ └─ LookupJoin\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ Table\n" +
" │ │ │ ├─ name: partsupp\n" +
" │ │ │ ├─ columns: [ps_suppkey]\n" +
" │ │ │ ├─ colSet: (19-23)\n" +
" │ │ │ └─ tableId: 4\n" +
" │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ ├─ keys: [partsupp.ps_suppkey:5!null]\n" +
" │ │ ├─ colSet: (24-30)\n" +
" │ │ ├─ tableId: 5\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: supplier\n" +
" │ │ └─ columns: [s_suppkey s_nationkey]\n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ nation.n_name:6!null\n" +
" │ │ └─ GERMANY (longtext)\n" +
" │ └─ IndexedTableAccess(nation)\n" +
" │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ ├─ keys: [supplier.s_nationkey:7!null]\n" +
" │ ├─ colSet: (31-34)\n" +
" │ ├─ tableId: 6\n" +
" │ └─ Table\n" +
" │ ├─ name: nation\n" +
" │ └─ columns: [n_nationkey n_name]\n" +
" └─ Project\n" +
" ├─ columns: [sum((partsupp.ps_supplycost * partsupp.ps_availqty)):0!null, partsupp.ps_partkey:1!null, partsupp.PS_SUPPLYCOST:2!null, partsupp.PS_AVAILQTY:3!null, sum((partsupp.ps_supplycost * partsupp.ps_availqty)):0!null as value]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM((partsupp.ps_supplycost:3!null * partsupp.ps_availqty:2!null)), partsupp.ps_partkey:0!null, partsupp.PS_SUPPLYCOST:3!null, partsupp.PS_AVAILQTY:2!null\n" +
" ├─ group: partsupp.ps_partkey:0!null\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ ProcessTable\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: partsupp\n" +
" │ │ └─ columns: [ps_partkey ps_suppkey ps_availqty ps_supplycost ps_comment]\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ ├─ keys: [partsupp.ps_suppkey:1!null]\n" +
" │ ├─ colSet: (6-12)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: supplier\n" +
" │ └─ columns: [s_suppkey s_name s_address s_nationkey s_phone s_acctbal s_comment]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ nation.n_name:1!null\n" +
" │ └─ GERMANY (longtext)\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ keys: [supplier.s_nationkey:8!null]\n" +
" ├─ colSet: (13-16)\n" +
" ├─ tableId: 3\n" +
" └─ Table\n" +
" ├─ name: nation\n" +
" └─ columns: [n_nationkey n_name n_regionkey n_comment]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [partsupp.ps_partkey, sum((partsupp.ps_supplycost * partsupp.ps_availqty)) as value]\n" +
" └─ Sort(sum((partsupp.ps_supplycost * partsupp.ps_availqty)) as value DESC)\n" +
" └─ Having((sum((partsupp.ps_supplycost * partsupp.ps_availqty)) > Subquery\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [(sum((partsupp.ps_supplycost * partsupp.ps_availqty)) * 0.0001000000) as sum(ps_supplycost * ps_availqty) * 0.0001000000]\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ Table\n" +
" │ │ ├─ name: partsupp\n" +
" │ │ └─ columns: [ps_suppkey]\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ ├─ columns: [s_suppkey s_nationkey]\n" +
" │ └─ keys: partsupp.ps_suppkey\n" +
" └─ Filter\n" +
" ├─ (nation.n_name = 'GERMANY')\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ columns: [n_nationkey n_name]\n" +
" └─ keys: supplier.s_nationkey\n" +
" ))\n" +
" └─ Project\n" +
" ├─ columns: [sum((partsupp.ps_supplycost * partsupp.ps_availqty)), partsupp.ps_partkey, partsupp.PS_SUPPLYCOST, partsupp.PS_AVAILQTY, sum((partsupp.ps_supplycost * partsupp.ps_availqty)) as value]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((partsupp.ps_supplycost * partsupp.ps_availqty)), partsupp.ps_partkey, partsupp.PS_SUPPLYCOST, partsupp.PS_AVAILQTY)\n" +
" ├─ Grouping(partsupp.ps_partkey)\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ Table\n" +
" │ │ └─ name: partsupp\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ └─ keys: partsupp.ps_suppkey\n" +
" └─ Filter\n" +
" ├─ (nation.n_name = 'GERMANY')\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" └─ keys: supplier.s_nationkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [partsupp.ps_partkey, sum((partsupp.ps_supplycost * partsupp.ps_availqty)) as value]\n" +
" └─ Sort(sum((partsupp.ps_supplycost * partsupp.ps_availqty)) as value DESC)\n" +
" └─ Having((sum((partsupp.ps_supplycost * partsupp.ps_availqty)) > Subquery\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [(sum((partsupp.ps_supplycost * partsupp.ps_availqty)) * 0.0001000000) as sum(ps_supplycost * ps_availqty) * 0.0001000000]\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ Table\n" +
" │ │ ├─ name: partsupp\n" +
" │ │ └─ columns: [ps_suppkey]\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ ├─ columns: [s_suppkey s_nationkey]\n" +
" │ └─ keys: partsupp.ps_suppkey\n" +
" └─ Filter\n" +
" ├─ (nation.n_name = 'GERMANY')\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ columns: [n_nationkey n_name]\n" +
" └─ keys: supplier.s_nationkey\n" +
" ))\n" +
" └─ Project\n" +
" ├─ columns: [sum((partsupp.ps_supplycost * partsupp.ps_availqty)), partsupp.ps_partkey, partsupp.PS_SUPPLYCOST, partsupp.PS_AVAILQTY, sum((partsupp.ps_supplycost * partsupp.ps_availqty)) as value]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((partsupp.ps_supplycost * partsupp.ps_availqty)), partsupp.ps_partkey, partsupp.PS_SUPPLYCOST, partsupp.PS_AVAILQTY)\n" +
" ├─ Grouping(partsupp.ps_partkey)\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ Table\n" +
" │ │ └─ name: partsupp\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ └─ keys: partsupp.ps_suppkey\n" +
" └─ Filter\n" +
" ├─ (nation.n_name = 'GERMANY')\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" └─ keys: supplier.s_nationkey\n" +
"",
},
{
Query: `
--Q12
select
l_shipmode,
sum(case
when o_orderpriority = '1-URGENT'
or o_orderpriority = '2-HIGH'
then 1
else 0
end) as high_line_count,
sum(case
when o_orderpriority <> '1-URGENT'
and o_orderpriority <> '2-HIGH'
then 1
else 0
end) as low_line_count
from
orders,
lineitem
where
o_orderkey = l_orderkey
and l_shipmode in ('MAIL', 'SHIP')
and l_commitdate < l_receiptdate
and l_shipdate < l_commitdate
and l_receiptdate >= '1994-01-01'
and l_receiptdate < '1994-01-01' + interval '1' year
group by
l_shipmode
order by
l_shipmode;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [lineitem.l_shipmode:2!null, sum(case when ((orders.o_orderpriority = '1-urgent') or (orders.o_orderpriority = '2-high')) then 1 else 0 end):1!null as high_line_count, sum(case when ((not((orders.o_orderpriority = '1-urgent'))) and (not((orders.o_orderpriority = '2-high')))) then 1 else 0 end):0!null as low_line_count]\n" +
" └─ Sort(lineitem.l_shipmode:2!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [sum(case when ((not((orders.o_orderpriority = '1-urgent'))) and (not((orders.o_orderpriority = '2-high')))) then 1 else 0 end):0!null, sum(case when ((orders.o_orderpriority = '1-urgent') or (orders.o_orderpriority = '2-high')) then 1 else 0 end):1!null, lineitem.l_shipmode:2!null, sum(case when ((orders.o_orderpriority = '1-urgent') or (orders.o_orderpriority = '2-high')) then 1 else 0 end):1!null as high_line_count, sum(case when ((not((orders.o_orderpriority = '1-urgent'))) and (not((orders.o_orderpriority = '2-high')))) then 1 else 0 end):0!null as low_line_count]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(CASE WHEN AND\n" +
" │ ├─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ orders.o_orderpriority:1!null\n" +
" │ │ └─ 1-URGENT (longtext)\n" +
" │ └─ NOT\n" +
" │ └─ Eq\n" +
" │ ├─ orders.o_orderpriority:1!null\n" +
" │ └─ 2-HIGH (longtext)\n" +
" │ THEN 1 (tinyint) ELSE 0 (tinyint) END), SUM(CASE WHEN Or\n" +
" │ ├─ Eq\n" +
" │ │ ├─ orders.o_orderpriority:1!null\n" +
" │ │ └─ 1-URGENT (longtext)\n" +
" │ └─ Eq\n" +
" │ ├─ orders.o_orderpriority:1!null\n" +
" │ └─ 2-HIGH (longtext)\n" +
" │ THEN 1 (tinyint) ELSE 0 (tinyint) END), lineitem.l_shipmode:6!null\n" +
" ├─ group: lineitem.l_shipmode:6!null\n" +
" └─ MergeJoin\n" +
" ├─ cmp: Eq\n" +
" │ ├─ orders.o_orderkey:0!null\n" +
" │ └─ lineitem.l_orderkey:2!null\n" +
" ├─ IndexedTableAccess(orders)\n" +
" │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (1-9)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: orders\n" +
" │ └─ columns: [o_orderkey o_orderpriority]\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ HashIn\n" +
" │ │ │ │ │ ├─ lineitem.l_shipmode:4!null\n" +
" │ │ │ │ │ └─ TUPLE(MAIL (longtext), SHIP (longtext))\n" +
" │ │ │ │ └─ LessThan\n" +
" │ │ │ │ ├─ lineitem.l_commitdate:2!null\n" +
" │ │ │ │ └─ lineitem.l_receiptdate:3!null\n" +
" │ │ │ └─ LessThan\n" +
" │ │ │ ├─ lineitem.l_shipdate:1!null\n" +
" │ │ │ └─ lineitem.l_commitdate:2!null\n" +
" │ │ └─ GreaterThanOrEqual\n" +
" │ │ ├─ lineitem.l_receiptdate:3!null\n" +
" │ │ └─ 1994-01-01 (longtext)\n" +
" │ └─ LessThan\n" +
" │ ├─ lineitem.l_receiptdate:3!null\n" +
" │ └─ 1995-01-01 00:00:00 +0000 UTC (datetime)\n" +
" └─ IndexedTableAccess(lineitem)\n" +
" ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" ├─ colSet: (10-25)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: lineitem\n" +
" └─ columns: [l_orderkey l_shipdate l_commitdate l_receiptdate l_shipmode]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [lineitem.l_shipmode, sum(case when ((orders.o_orderpriority = '1-urgent') or (orders.o_orderpriority = '2-high')) then 1 else 0 end) as high_line_count, sum(case when ((not((orders.o_orderpriority = '1-urgent'))) and (not((orders.o_orderpriority = '2-high')))) then 1 else 0 end) as low_line_count]\n" +
" └─ Sort(lineitem.l_shipmode ASC)\n" +
" └─ Project\n" +
" ├─ columns: [sum(case when ((not((orders.o_orderpriority = '1-urgent'))) and (not((orders.o_orderpriority = '2-high')))) then 1 else 0 end), sum(case when ((orders.o_orderpriority = '1-urgent') or (orders.o_orderpriority = '2-high')) then 1 else 0 end), lineitem.l_shipmode, sum(case when ((orders.o_orderpriority = '1-urgent') or (orders.o_orderpriority = '2-high')) then 1 else 0 end) as high_line_count, sum(case when ((not((orders.o_orderpriority = '1-urgent'))) and (not((orders.o_orderpriority = '2-high')))) then 1 else 0 end) as low_line_count]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(CASE WHEN ((NOT((orders.o_orderpriority = '1-URGENT'))) AND (NOT((orders.o_orderpriority = '2-HIGH')))) THEN 1 ELSE 0 END), SUM(CASE WHEN ((orders.o_orderpriority = '1-URGENT') OR (orders.o_orderpriority = '2-HIGH')) THEN 1 ELSE 0 END), lineitem.l_shipmode)\n" +
" ├─ Grouping(lineitem.l_shipmode)\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (orders.o_orderkey = lineitem.l_orderkey)\n" +
" ├─ IndexedTableAccess(orders)\n" +
" │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [o_orderkey o_orderpriority]\n" +
" └─ Filter\n" +
" ├─ (((((lineitem.l_shipmode HASH IN ('MAIL', 'SHIP')) AND (lineitem.l_commitdate < lineitem.l_receiptdate)) AND (lineitem.l_shipdate < lineitem.l_commitdate)) AND (lineitem.l_receiptdate >= '1994-01-01')) AND (lineitem.l_receiptdate < 1995-01-01 00:00:00 +0000 UTC))\n" +
" └─ IndexedTableAccess(lineitem)\n" +
" ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" └─ columns: [l_orderkey l_shipdate l_commitdate l_receiptdate l_shipmode]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [lineitem.l_shipmode, sum(case when ((orders.o_orderpriority = '1-urgent') or (orders.o_orderpriority = '2-high')) then 1 else 0 end) as high_line_count, sum(case when ((not((orders.o_orderpriority = '1-urgent'))) and (not((orders.o_orderpriority = '2-high')))) then 1 else 0 end) as low_line_count]\n" +
" └─ Sort(lineitem.l_shipmode ASC)\n" +
" └─ Project\n" +
" ├─ columns: [sum(case when ((not((orders.o_orderpriority = '1-urgent'))) and (not((orders.o_orderpriority = '2-high')))) then 1 else 0 end), sum(case when ((orders.o_orderpriority = '1-urgent') or (orders.o_orderpriority = '2-high')) then 1 else 0 end), lineitem.l_shipmode, sum(case when ((orders.o_orderpriority = '1-urgent') or (orders.o_orderpriority = '2-high')) then 1 else 0 end) as high_line_count, sum(case when ((not((orders.o_orderpriority = '1-urgent'))) and (not((orders.o_orderpriority = '2-high')))) then 1 else 0 end) as low_line_count]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(CASE WHEN ((NOT((orders.o_orderpriority = '1-URGENT'))) AND (NOT((orders.o_orderpriority = '2-HIGH')))) THEN 1 ELSE 0 END), SUM(CASE WHEN ((orders.o_orderpriority = '1-URGENT') OR (orders.o_orderpriority = '2-HIGH')) THEN 1 ELSE 0 END), lineitem.l_shipmode)\n" +
" ├─ Grouping(lineitem.l_shipmode)\n" +
" └─ MergeJoin\n" +
" ├─ cmp: (orders.o_orderkey = lineitem.l_orderkey)\n" +
" ├─ IndexedTableAccess(orders)\n" +
" │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ ├─ filters: [{[NULL, ∞)}]\n" +
" │ └─ columns: [o_orderkey o_orderpriority]\n" +
" └─ Filter\n" +
" ├─ (((((lineitem.l_shipmode HASH IN ('MAIL', 'SHIP')) AND (lineitem.l_commitdate < lineitem.l_receiptdate)) AND (lineitem.l_shipdate < lineitem.l_commitdate)) AND (lineitem.l_receiptdate >= '1994-01-01')) AND (lineitem.l_receiptdate < 1995-01-01 00:00:00 +0000 UTC))\n" +
" └─ IndexedTableAccess(lineitem)\n" +
" ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" ├─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" └─ columns: [l_orderkey l_shipdate l_commitdate l_receiptdate l_shipmode]\n" +
"",
},
{
Query: `
--Q13
select
c_count,
count(*) as custdist
from
(
select
c_custkey,
count(o_orderkey)
from
customer left outer join orders on
c_custkey = o_custkey
and o_comment not like '%special%requests%'
group by
c_custkey
) as c_orders (c_custkey, c_count)
group by
c_count
order by
custdist desc,
c_count desc;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [c_orders.c_count:1!null, count(1):0!null as custdist]\n" +
" └─ Sort(count(1):0!null as custdist DESC nullsFirst, c_orders.c_count:1!null DESC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [count(1):0!null, c_orders.c_count:1!null, count(1):0!null as custdist]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(1 (bigint)), c_orders.c_count:1!null\n" +
" ├─ group: c_orders.c_count:1!null\n" +
" └─ SubqueryAlias\n" +
" ├─ name: c_orders\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (19,20)\n" +
" ├─ tableId: 3\n" +
" └─ Project\n" +
" ├─ columns: [customer.c_custkey:1!null, count(orders.o_orderkey):0!null as count(o_orderkey)]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(orders.o_orderkey:1!null), customer.c_custkey:0!null\n" +
" ├─ group: customer.c_custkey:0!null\n" +
" └─ LeftOuterJoin\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ customer.c_custkey:0!null\n" +
" │ │ └─ orders.o_custkey:2!null\n" +
" │ └─ NOT\n" +
" │ └─ orders.o_comment LIKE '%special%requests%'\n" +
" ├─ Table\n" +
" │ ├─ name: customer\n" +
" │ ├─ columns: [c_custkey]\n" +
" │ ├─ colSet: (1-8)\n" +
" │ └─ tableId: 1\n" +
" └─ Table\n" +
" ├─ name: orders\n" +
" ├─ columns: [o_orderkey o_custkey o_comment]\n" +
" ├─ colSet: (9-17)\n" +
" └─ tableId: 2\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [c_orders.c_count, count(1) as custdist]\n" +
" └─ Sort(count(1) as custdist DESC, c_orders.c_count DESC)\n" +
" └─ Project\n" +
" ├─ columns: [count(1), c_orders.c_count, count(1) as custdist]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(1), c_orders.c_count)\n" +
" ├─ Grouping(c_orders.c_count)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: c_orders\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [customer.c_custkey, count(orders.o_orderkey) as count(o_orderkey)]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(orders.o_orderkey), customer.c_custkey)\n" +
" ├─ Grouping(customer.c_custkey)\n" +
" └─ LeftOuterJoin\n" +
" ├─ ((customer.c_custkey = orders.o_custkey) AND (NOT(orders.o_comment LIKE '%special%requests%')))\n" +
" ├─ Table\n" +
" │ ├─ name: customer\n" +
" │ └─ columns: [c_custkey]\n" +
" └─ Table\n" +
" ├─ name: orders\n" +
" └─ columns: [o_orderkey o_custkey o_comment]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [c_orders.c_count, count(1) as custdist]\n" +
" └─ Sort(count(1) as custdist DESC, c_orders.c_count DESC)\n" +
" └─ Project\n" +
" ├─ columns: [count(1), c_orders.c_count, count(1) as custdist]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(1), c_orders.c_count)\n" +
" ├─ Grouping(c_orders.c_count)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: c_orders\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [customer.c_custkey, count(orders.o_orderkey) as count(o_orderkey)]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(orders.o_orderkey), customer.c_custkey)\n" +
" ├─ Grouping(customer.c_custkey)\n" +
" └─ LeftOuterJoin\n" +
" ├─ ((customer.c_custkey = orders.o_custkey) AND (NOT(orders.o_comment LIKE '%special%requests%')))\n" +
" ├─ Table\n" +
" │ ├─ name: customer\n" +
" │ └─ columns: [c_custkey]\n" +
" └─ Table\n" +
" ├─ name: orders\n" +
" └─ columns: [o_orderkey o_custkey o_comment]\n" +
"",
},
{
Query: `
--Q14
select
100.00 * sum(case
when p_type like 'PROMO%'
then l_extendedprice * (1 - l_discount)
else 0
end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue
from
lineitem,
part
where
l_partkey = p_partkey
and l_shipdate >= '1995-09-01'
and l_shipdate < '1995-09-01' + interval '1' month;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [((100 (decimal(5,2)) * sum(case when part.p_type like 'promo%' then (lineitem.l_extendedprice * (1 - lineitem.l_discount)) else 0 end):1!null) / sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null) as promo_revenue]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM((lineitem.l_extendedprice:1!null * (1 (tinyint) - lineitem.l_discount:2!null))), SUM(CASE WHEN part.p_type LIKE 'PROMO%' THEN (lineitem.l_extendedprice:1!null * (1 (tinyint) - lineitem.l_discount:2!null)) ELSE 0 (tinyint) END)\n" +
" ├─ group: \n" +
" └─ LookupJoin\n" +
" ├─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ ├─ lineitem.l_shipdate:3!null\n" +
" │ │ │ └─ 1995-09-01 (longtext)\n" +
" │ │ └─ LessThan\n" +
" │ │ ├─ lineitem.l_shipdate:3!null\n" +
" │ │ └─ 1995-10-01 00:00:00 +0000 UTC (datetime)\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_partkey l_extendedprice l_discount l_shipdate]\n" +
" └─ IndexedTableAccess(part)\n" +
" ├─ index: [part.P_PARTKEY]\n" +
" ├─ keys: [lineitem.l_partkey:0!null]\n" +
" ├─ colSet: (17-25)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: part\n" +
" └─ columns: [p_partkey p_type]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [((100.00 * sum(case when part.p_type like 'promo%' then (lineitem.l_extendedprice * (1 - lineitem.l_discount)) else 0 end)) / sum((lineitem.l_extendedprice * (1 - lineitem.l_discount)))) as promo_revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), SUM(CASE WHEN part.p_type LIKE 'PROMO%' THEN (lineitem.l_extendedprice * (1 - lineitem.l_discount)) ELSE 0 END))\n" +
" ├─ Grouping()\n" +
" └─ LookupJoin\n" +
" ├─ Filter\n" +
" │ ├─ ((lineitem.l_shipdate >= '1995-09-01') AND (lineitem.l_shipdate < 1995-10-01 00:00:00 +0000 UTC))\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_partkey l_extendedprice l_discount l_shipdate]\n" +
" └─ IndexedTableAccess(part)\n" +
" ├─ index: [part.P_PARTKEY]\n" +
" ├─ columns: [p_partkey p_type]\n" +
" └─ keys: lineitem.l_partkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [((100.00 * sum(case when part.p_type like 'promo%' then (lineitem.l_extendedprice * (1 - lineitem.l_discount)) else 0 end)) / sum((lineitem.l_extendedprice * (1 - lineitem.l_discount)))) as promo_revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), SUM(CASE WHEN part.p_type LIKE 'PROMO%' THEN (lineitem.l_extendedprice * (1 - lineitem.l_discount)) ELSE 0 END))\n" +
" ├─ Grouping()\n" +
" └─ LookupJoin\n" +
" ├─ Filter\n" +
" │ ├─ ((lineitem.l_shipdate >= '1995-09-01') AND (lineitem.l_shipdate < 1995-10-01 00:00:00 +0000 UTC))\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_partkey l_extendedprice l_discount l_shipdate]\n" +
" └─ IndexedTableAccess(part)\n" +
" ├─ index: [part.P_PARTKEY]\n" +
" ├─ columns: [p_partkey p_type]\n" +
" └─ keys: lineitem.l_partkey\n" +
"",
},
{
Query: `
--Q15
with revenue0 (supplier_no, total_revenue) as (
select
l_suppkey,
sum(l_extendedprice * (1 - l_discount))
from
lineitem
where
l_shipdate >= '1996-01-01'
and l_shipdate < '1996-01-01' + interval '3' month
group by
l_suppkey)
select
s_suppkey,
s_name,
s_address,
s_phone,
total_revenue
from
supplier,
revenue0
where
s_suppkey = supplier_no
and total_revenue = (
select
max(total_revenue)
from
revenue0
)
order by
s_suppkey;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [supplier.s_suppkey:2!null, supplier.s_name:3!null, supplier.s_address:4!null, supplier.s_phone:6!null, revenue0.total_revenue:1!null]\n" +
" └─ Sort(supplier.s_suppkey:2!null ASC nullsFirst)\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ revenue0.total_revenue:1!null\n" +
" │ └─ Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ alias-string: select max(total_revenue) from revenue0\n" +
" │ └─ Project\n" +
" │ ├─ columns: [max(revenue0.total_revenue):9!null as max(total_revenue)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: MAX(revenue0.total_revenue:1!null)\n" +
" │ ├─ group: \n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: revenue0\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (18,19)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lineitem.l_suppkey:10!null, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):9!null as sum(l_extendedprice * (1 - l_discount))]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: SUM((lineitem.l_extendedprice:10!null * (1 (tinyint) - lineitem.l_discount:11!null))), lineitem.l_suppkey:9!null\n" +
" │ ├─ group: lineitem.l_suppkey:9!null\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ ├─ lineitem.l_shipdate:12!null\n" +
" │ │ │ └─ 1996-01-01 (longtext)\n" +
" │ │ └─ LessThan\n" +
" │ │ ├─ lineitem.l_shipdate:12!null\n" +
" │ │ └─ 1996-04-01 00:00:00 +0000 UTC (datetime)\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ ├─ columns: [l_suppkey l_extendedprice l_discount l_shipdate]\n" +
" │ ├─ colSet: (1-16)\n" +
" │ └─ tableId: 1\n" +
" └─ LookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: revenue0\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ colSet: (18,19)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lineitem.l_suppkey:1!null, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as sum(l_extendedprice * (1 - l_discount))]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: SUM((lineitem.l_extendedprice:1!null * (1 (tinyint) - lineitem.l_discount:2!null))), lineitem.l_suppkey:0!null\n" +
" │ ├─ group: lineitem.l_suppkey:0!null\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ ├─ lineitem.l_shipdate:3!null\n" +
" │ │ │ └─ 1996-01-01 (longtext)\n" +
" │ │ └─ LessThan\n" +
" │ │ ├─ lineitem.l_shipdate:3!null\n" +
" │ │ └─ 1996-04-01 00:00:00 +0000 UTC (datetime)\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ ├─ columns: [l_suppkey l_extendedprice l_discount l_shipdate]\n" +
" │ ├─ colSet: (1-16)\n" +
" │ └─ tableId: 1\n" +
" └─ IndexedTableAccess(supplier)\n" +
" ├─ index: [supplier.S_SUPPKEY]\n" +
" ├─ keys: [revenue0.supplier_no:0!null]\n" +
" ├─ colSet: (20-26)\n" +
" ├─ tableId: 4\n" +
" └─ Table\n" +
" ├─ name: supplier\n" +
" └─ columns: [s_suppkey s_name s_address s_nationkey s_phone s_acctbal s_comment]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [supplier.s_suppkey, supplier.s_name, supplier.s_address, supplier.s_phone, revenue0.total_revenue]\n" +
" └─ Sort(supplier.s_suppkey ASC)\n" +
" └─ Filter\n" +
" ├─ (revenue0.total_revenue = Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [max(revenue0.total_revenue) as max(total_revenue)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(MAX(revenue0.total_revenue))\n" +
" │ ├─ Grouping()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: revenue0\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lineitem.l_suppkey, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as sum(l_extendedprice * (1 - l_discount))]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), lineitem.l_suppkey)\n" +
" │ ├─ Grouping(lineitem.l_suppkey)\n" +
" │ └─ Filter\n" +
" │ ├─ ((lineitem.l_shipdate >= '1996-01-01') AND (lineitem.l_shipdate < 1996-04-01 00:00:00 +0000 UTC))\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_suppkey l_extendedprice l_discount l_shipdate]\n" +
" │ )\n" +
" └─ LookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: revenue0\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lineitem.l_suppkey, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as sum(l_extendedprice * (1 - l_discount))]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), lineitem.l_suppkey)\n" +
" │ ├─ Grouping(lineitem.l_suppkey)\n" +
" │ └─ Filter\n" +
" │ ├─ ((lineitem.l_shipdate >= '1996-01-01') AND (lineitem.l_shipdate < 1996-04-01 00:00:00 +0000 UTC))\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_suppkey l_extendedprice l_discount l_shipdate]\n" +
" └─ IndexedTableAccess(supplier)\n" +
" ├─ index: [supplier.S_SUPPKEY]\n" +
" └─ keys: revenue0.supplier_no\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [supplier.s_suppkey, supplier.s_name, supplier.s_address, supplier.s_phone, revenue0.total_revenue]\n" +
" └─ Sort(supplier.s_suppkey ASC)\n" +
" └─ Filter\n" +
" ├─ (revenue0.total_revenue = Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [max(revenue0.total_revenue) as max(total_revenue)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(MAX(revenue0.total_revenue))\n" +
" │ ├─ Grouping()\n" +
" │ └─ SubqueryAlias\n" +
" │ ├─ name: revenue0\n" +
" │ ├─ outerVisibility: true\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lineitem.l_suppkey, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as sum(l_extendedprice * (1 - l_discount))]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), lineitem.l_suppkey)\n" +
" │ ├─ Grouping(lineitem.l_suppkey)\n" +
" │ └─ Filter\n" +
" │ ├─ ((lineitem.l_shipdate >= '1996-01-01') AND (lineitem.l_shipdate < 1996-04-01 00:00:00 +0000 UTC))\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_suppkey l_extendedprice l_discount l_shipdate]\n" +
" │ )\n" +
" └─ LookupJoin\n" +
" ├─ SubqueryAlias\n" +
" │ ├─ name: revenue0\n" +
" │ ├─ outerVisibility: false\n" +
" │ ├─ isLateral: false\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [lineitem.l_suppkey, sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as sum(l_extendedprice * (1 - l_discount))]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))), lineitem.l_suppkey)\n" +
" │ ├─ Grouping(lineitem.l_suppkey)\n" +
" │ └─ Filter\n" +
" │ ├─ ((lineitem.l_shipdate >= '1996-01-01') AND (lineitem.l_shipdate < 1996-04-01 00:00:00 +0000 UTC))\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_suppkey l_extendedprice l_discount l_shipdate]\n" +
" └─ IndexedTableAccess(supplier)\n" +
" ├─ index: [supplier.S_SUPPKEY]\n" +
" └─ keys: revenue0.supplier_no\n" +
"",
},
{
Query: `
--Q16
select
p_brand,
p_type,
p_size,
count(distinct ps_suppkey) as supplier_cnt
from
partsupp,
part
where
p_partkey = ps_partkey
and p_brand <> 'Brand#45'
and p_type not like 'MEDIUM POLISHED%'
and p_size in (49, 14, 23, 45, 19, 3, 36, 9)
and ps_suppkey not in (
select
s_suppkey
from
supplier
where
s_comment like '%Customer%Complaints%'
)
group by
p_brand,
p_type,
p_size
order by
supplier_cnt desc,
p_brand,
p_type,
p_size;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [part.p_brand:1!null, part.p_type:2!null, part.p_size:3!null, countdistinct([partsupp.ps_suppkey]):0!null as supplier_cnt]\n" +
" └─ Sort(countdistinct([partsupp.ps_suppkey]):0!null as supplier_cnt DESC nullsFirst, part.p_brand:1!null ASC nullsFirst, part.p_type:2!null ASC nullsFirst, part.p_size:3!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [countdistinct([partsupp.ps_suppkey]):0!null, part.p_brand:1!null, part.p_type:2!null, part.p_size:3!null, countdistinct([partsupp.ps_suppkey]):0!null as supplier_cnt]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNTDISTINCT([partsupp.ps_suppkey]), part.p_brand:8!null, part.p_type:9!null, part.p_size:10!null\n" +
" ├─ group: part.p_brand:8!null, part.p_type:9!null, part.p_size:10!null\n" +
" └─ Project\n" +
" ├─ columns: [partsupp.PS_PARTKEY:0!null, partsupp.PS_SUPPKEY:1!null, partsupp.PS_AVAILQTY:2!null, partsupp.PS_SUPPLYCOST:3!null, partsupp.PS_COMMENT:4!null, part.P_PARTKEY:5!null, part.P_NAME:6!null, part.P_MFGR:7!null, part.P_BRAND:8!null, part.P_TYPE:9!null, part.P_SIZE:10!null, part.P_CONTAINER:11!null, part.P_RETAILPRICE:12!null, part.P_COMMENT:13!null]\n" +
" └─ Filter\n" +
" ├─ supplier.s_suppkey:14!null IS NULL\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: Eq\n" +
" │ │ ├─ partsupp.ps_partkey:0!null\n" +
" │ │ └─ part.p_partkey:5!null\n" +
" │ ├─ IndexedTableAccess(partsupp)\n" +
" │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ ├─ colSet: (1-5)\n" +
" │ │ ├─ tableId: 1\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: partsupp\n" +
" │ │ └─ columns: [ps_partkey ps_suppkey ps_availqty ps_supplycost ps_comment]\n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ NOT\n" +
" │ │ │ │ └─ Eq\n" +
" │ │ │ │ ├─ part.p_brand:3!null\n" +
" │ │ │ │ └─ Brand#45 (longtext)\n" +
" │ │ │ └─ Or\n" +
" │ │ │ ├─ LessThan\n" +
" │ │ │ │ ├─ part.p_type:4!null\n" +
" │ │ │ │ └─ MEDIUM POLISHED (longtext)\n" +
" │ │ │ └─ GreaterThan\n" +
" │ │ │ ├─ part.p_type:4!null\n" +
" │ │ │ └─ MEDIUM POLISHEDÿ (longtext)\n" +
" │ │ └─ HashIn\n" +
" │ │ ├─ part.p_size:5!null\n" +
" │ │ └─ TUPLE(49 (tinyint), 14 (tinyint), 23 (tinyint), 45 (tinyint), 19 (tinyint), 3 (tinyint), 36 (tinyint), 9 (tinyint))\n" +
" │ └─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ ├─ static: [{[NULL, ∞)}]\n" +
" │ ├─ colSet: (6-14)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: part\n" +
" │ └─ columns: [p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment]\n" +
" └─ Project\n" +
" ├─ columns: [supplier.s_suppkey:0!null]\n" +
" └─ Filter\n" +
" ├─ supplier.s_comment LIKE '%Customer%Complaints%'\n" +
" └─ IndexedTableAccess(supplier)\n" +
" ├─ index: [supplier.S_SUPPKEY]\n" +
" ├─ keys: [partsupp.ps_suppkey:1!null]\n" +
" ├─ colSet: (15-21)\n" +
" ├─ tableId: 3\n" +
" └─ Table\n" +
" ├─ name: supplier\n" +
" └─ columns: [s_suppkey s_name s_address s_nationkey s_phone s_acctbal s_comment]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [part.p_brand, part.p_type, part.p_size, countdistinct([partsupp.ps_suppkey]) as supplier_cnt]\n" +
" └─ Sort(countdistinct([partsupp.ps_suppkey]) as supplier_cnt DESC, part.p_brand ASC, part.p_type ASC, part.p_size ASC)\n" +
" └─ Project\n" +
" ├─ columns: [countdistinct([partsupp.ps_suppkey]), part.p_brand, part.p_type, part.p_size, countdistinct([partsupp.ps_suppkey]) as supplier_cnt]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNTDISTINCT([partsupp.ps_suppkey]), part.p_brand, part.p_type, part.p_size)\n" +
" ├─ Grouping(part.p_brand, part.p_type, part.p_size)\n" +
" └─ Project\n" +
" ├─ columns: [partsupp.PS_PARTKEY, partsupp.PS_SUPPKEY, partsupp.PS_AVAILQTY, partsupp.PS_SUPPLYCOST, partsupp.PS_COMMENT, part.P_PARTKEY, part.P_NAME, part.P_MFGR, part.P_BRAND, part.P_TYPE, part.P_SIZE, part.P_CONTAINER, part.P_RETAILPRICE, part.P_COMMENT]\n" +
" └─ Filter\n" +
" ├─ supplier.s_suppkey IS NULL\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: (partsupp.ps_partkey = part.p_partkey)\n" +
" │ ├─ IndexedTableAccess(partsupp)\n" +
" │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ └─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ └─ Filter\n" +
" │ ├─ (((NOT((part.p_brand = 'Brand#45'))) AND ((part.p_type < 'MEDIUM POLISHED') OR (part.p_type > 'MEDIUM POLISHEDÿ'))) AND (part.p_size HASH IN (49, 14, 23, 45, 19, 3, 36, 9)))\n" +
" │ └─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ └─ filters: [{[NULL, ∞)}]\n" +
" └─ Project\n" +
" ├─ columns: [supplier.s_suppkey]\n" +
" └─ Filter\n" +
" ├─ supplier.s_comment LIKE '%Customer%Complaints%'\n" +
" └─ IndexedTableAccess(supplier)\n" +
" ├─ index: [supplier.S_SUPPKEY]\n" +
" └─ keys: partsupp.ps_suppkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [part.p_brand, part.p_type, part.p_size, countdistinct([partsupp.ps_suppkey]) as supplier_cnt]\n" +
" └─ Sort(countdistinct([partsupp.ps_suppkey]) as supplier_cnt DESC, part.p_brand ASC, part.p_type ASC, part.p_size ASC)\n" +
" └─ Project\n" +
" ├─ columns: [countdistinct([partsupp.ps_suppkey]), part.p_brand, part.p_type, part.p_size, countdistinct([partsupp.ps_suppkey]) as supplier_cnt]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNTDISTINCT([partsupp.ps_suppkey]), part.p_brand, part.p_type, part.p_size)\n" +
" ├─ Grouping(part.p_brand, part.p_type, part.p_size)\n" +
" └─ Project\n" +
" ├─ columns: [partsupp.PS_PARTKEY, partsupp.PS_SUPPKEY, partsupp.PS_AVAILQTY, partsupp.PS_SUPPLYCOST, partsupp.PS_COMMENT, part.P_PARTKEY, part.P_NAME, part.P_MFGR, part.P_BRAND, part.P_TYPE, part.P_SIZE, part.P_CONTAINER, part.P_RETAILPRICE, part.P_COMMENT]\n" +
" └─ Filter\n" +
" ├─ supplier.s_suppkey IS NULL\n" +
" └─ LeftOuterLookupJoin\n" +
" ├─ MergeJoin\n" +
" │ ├─ cmp: (partsupp.ps_partkey = part.p_partkey)\n" +
" │ ├─ IndexedTableAccess(partsupp)\n" +
" │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ └─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ └─ Filter\n" +
" │ ├─ (((NOT((part.p_brand = 'Brand#45'))) AND ((part.p_type < 'MEDIUM POLISHED') OR (part.p_type > 'MEDIUM POLISHEDÿ'))) AND (part.p_size HASH IN (49, 14, 23, 45, 19, 3, 36, 9)))\n" +
" │ └─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ └─ filters: [{[NULL, ∞)}]\n" +
" └─ Project\n" +
" ├─ columns: [supplier.s_suppkey]\n" +
" └─ Filter\n" +
" ├─ supplier.s_comment LIKE '%Customer%Complaints%'\n" +
" └─ IndexedTableAccess(supplier)\n" +
" ├─ index: [supplier.S_SUPPKEY]\n" +
" └─ keys: partsupp.ps_suppkey\n" +
"",
},
{
Query: `
--Q17
select
sum(l_extendedprice) / 7.0 as avg_yearly
from
lineitem,
part
where
p_partkey = l_partkey
and p_brand = 'Brand#23'
and p_container = 'MED BOX'
and l_quantity < (
select
0.2 * avg(l_quantity)
from
lineitem
where
l_partkey = p_partkey
);`,
ExpectedPlan: "Project\n" +
" ├─ columns: [(sum(lineitem.l_extendedprice):0!null / 7 (decimal(2,1))) as avg_yearly]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(lineitem.l_extendedprice:5!null)\n" +
" ├─ group: \n" +
" └─ Filter\n" +
" ├─ LessThan\n" +
" │ ├─ lineitem.l_quantity:4!null\n" +
" │ └─ Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ ├─ alias-string: select 0.2 * avg(l_quantity) from lineitem where l_partkey = p_partkey\n" +
" │ └─ Project\n" +
" │ ├─ columns: [(0.2 (decimal(2,1)) * avg(lineitem.l_quantity):25) as 0.2 * avg(l_quantity)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: AVG(lineitem.l_quantity:26!null)\n" +
" │ ├─ group: \n" +
" │ └─ Filter\n" +
" │ ├─ Eq\n" +
" │ │ ├─ lineitem.l_partkey:25!null\n" +
" │ │ └─ part.p_partkey:16!null\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ ├─ columns: [l_partkey l_quantity]\n" +
" │ ├─ colSet: (26-41)\n" +
" │ └─ tableId: 3\n" +
" └─ LookupJoin\n" +
" ├─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
" └─ Filter\n" +
" ├─ AND\n" +
" │ ├─ Eq\n" +
" │ │ ├─ part.p_brand:3!null\n" +
" │ │ └─ Brand#23 (longtext)\n" +
" │ └─ Eq\n" +
" │ ├─ part.p_container:6!null\n" +
" │ └─ MED BOX (longtext)\n" +
" └─ IndexedTableAccess(part)\n" +
" ├─ index: [part.P_PARTKEY]\n" +
" ├─ keys: [lineitem.l_partkey:1!null]\n" +
" ├─ colSet: (17-25)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: part\n" +
" └─ columns: [p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [(sum(lineitem.l_extendedprice) / 7.0) as avg_yearly]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(lineitem.l_extendedprice))\n" +
" ├─ Grouping()\n" +
" └─ Filter\n" +
" ├─ (lineitem.l_quantity < Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [(0.2 * avg(lineitem.l_quantity)) as 0.2 * avg(l_quantity)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(AVG(lineitem.l_quantity))\n" +
" │ ├─ Grouping()\n" +
" │ └─ Filter\n" +
" │ ├─ (lineitem.l_partkey = part.p_partkey)\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_partkey l_quantity]\n" +
" │ )\n" +
" └─ LookupJoin\n" +
" ├─ Table\n" +
" │ └─ name: lineitem\n" +
" └─ Filter\n" +
" ├─ ((part.p_brand = 'Brand#23') AND (part.p_container = 'MED BOX'))\n" +
" └─ IndexedTableAccess(part)\n" +
" ├─ index: [part.P_PARTKEY]\n" +
" └─ keys: lineitem.l_partkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [(sum(lineitem.l_extendedprice) / 7.0) as avg_yearly]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(lineitem.l_extendedprice))\n" +
" ├─ Grouping()\n" +
" └─ Filter\n" +
" ├─ (lineitem.l_quantity < Subquery\n" +
" │ ├─ cacheable: false\n" +
" │ └─ Project\n" +
" │ ├─ columns: [(0.2 * avg(lineitem.l_quantity)) as 0.2 * avg(l_quantity)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(AVG(lineitem.l_quantity))\n" +
" │ ├─ Grouping()\n" +
" │ └─ Filter\n" +
" │ ├─ (lineitem.l_partkey = part.p_partkey)\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_partkey l_quantity]\n" +
" │ )\n" +
" └─ LookupJoin\n" +
" ├─ Table\n" +
" │ └─ name: lineitem\n" +
" └─ Filter\n" +
" ├─ ((part.p_brand = 'Brand#23') AND (part.p_container = 'MED BOX'))\n" +
" └─ IndexedTableAccess(part)\n" +
" ├─ index: [part.P_PARTKEY]\n" +
" └─ keys: lineitem.l_partkey\n" +
"",
},
{
Query: `
--Q18
select
c_name,
c_custkey,
o_orderkey,
o_orderdate,
o_totalprice,
sum(l_quantity)
from
customer,
orders,
lineitem
where
o_orderkey in (
select
l_orderkey
from
lineitem
group by
l_orderkey having
sum(l_quantity) > 300
)
and c_custkey = o_custkey
and o_orderkey = l_orderkey
group by
c_name,
c_custkey,
o_orderkey,
o_orderdate,
o_totalprice
order by
o_totalprice desc,
o_orderdate;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [customer.c_name:1!null, customer.c_custkey:2!null, orders.o_orderkey:3!null, orders.o_orderdate:4!null, orders.o_totalprice:5!null, sum(lineitem.l_quantity):0!null as sum(l_quantity)]\n" +
" └─ Sort(orders.o_totalprice:5!null DESC nullsFirst, orders.o_orderdate:4!null ASC nullsFirst)\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(lineitem.l_quantity:21!null), customer.c_name:1!null, customer.c_custkey:0!null, orders.o_orderkey:8!null, orders.o_orderdate:12!null, orders.o_totalprice:11!null\n" +
" ├─ group: customer.c_name:1!null, customer.c_custkey:0!null, orders.o_orderkey:8!null, orders.o_orderdate:12!null, orders.o_totalprice:11!null\n" +
" └─ SemiJoin\n" +
" ├─ Eq\n" +
" │ ├─ orders.o_orderkey:8!null\n" +
" │ └─ lineitem_1.l_orderkey:33!null\n" +
" ├─ InnerJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ orders.o_orderkey:8!null\n" +
" │ │ └─ lineitem.l_orderkey:17!null\n" +
" │ ├─ InnerJoin\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ customer.c_custkey:0!null\n" +
" │ │ │ └─ orders.o_custkey:9!null\n" +
" │ │ ├─ ProcessTable\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: customer\n" +
" │ │ │ └─ columns: [c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment]\n" +
" │ │ └─ ProcessTable\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: orders\n" +
" │ │ └─ columns: [o_orderkey o_custkey o_orderstatus o_totalprice o_orderdate o_orderpriority o_clerk o_shippriority o_comment]\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
" └─ Project\n" +
" ├─ columns: [lineitem_1.l_orderkey:1!null]\n" +
" └─ Having\n" +
" ├─ GreaterThan\n" +
" │ ├─ sum(lineitem.l_quantity):0!null\n" +
" │ └─ 300 (smallint)\n" +
" └─ GroupBy\n" +
" ├─ select: SUM(lineitem_1.l_quantity:4!null), lineitem_1.l_orderkey:0!null, lineitem_1.L_QUANTITY:4!null\n" +
" ├─ group: lineitem_1.l_orderkey:0!null\n" +
" └─ TableAlias(lineitem_1)\n" +
" └─ Table\n" +
" ├─ name: lineitem\n" +
" ├─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
" ├─ colSet: (34-49)\n" +
" └─ tableId: 4\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [customer.c_name, customer.c_custkey, orders.o_orderkey, orders.o_orderdate, orders.o_totalprice, sum(lineitem.l_quantity) as sum(l_quantity)]\n" +
" └─ Sort(orders.o_totalprice DESC, orders.o_orderdate ASC)\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(lineitem.l_quantity), customer.c_name, customer.c_custkey, orders.o_orderkey, orders.o_orderdate, orders.o_totalprice)\n" +
" ├─ Grouping(customer.c_name, customer.c_custkey, orders.o_orderkey, orders.o_orderdate, orders.o_totalprice)\n" +
" └─ SemiJoin\n" +
" ├─ (orders.o_orderkey = lineitem_1.l_orderkey)\n" +
" ├─ InnerJoin\n" +
" │ ├─ (orders.o_orderkey = lineitem.l_orderkey)\n" +
" │ ├─ InnerJoin\n" +
" │ │ ├─ (customer.c_custkey = orders.o_custkey)\n" +
" │ │ ├─ Table\n" +
" │ │ │ └─ name: customer\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: orders\n" +
" │ └─ Table\n" +
" │ └─ name: lineitem\n" +
" └─ Project\n" +
" ├─ columns: [lineitem_1.l_orderkey]\n" +
" └─ Having((sum(lineitem.l_quantity) > 300))\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(lineitem_1.l_quantity), lineitem_1.l_orderkey, lineitem_1.L_QUANTITY)\n" +
" ├─ Grouping(lineitem_1.l_orderkey)\n" +
" └─ TableAlias(lineitem_1)\n" +
" └─ Table\n" +
" └─ name: lineitem\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [customer.c_name, customer.c_custkey, orders.o_orderkey, orders.o_orderdate, orders.o_totalprice, sum(lineitem.l_quantity) as sum(l_quantity)]\n" +
" └─ Sort(orders.o_totalprice DESC, orders.o_orderdate ASC)\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(lineitem.l_quantity), customer.c_name, customer.c_custkey, orders.o_orderkey, orders.o_orderdate, orders.o_totalprice)\n" +
" ├─ Grouping(customer.c_name, customer.c_custkey, orders.o_orderkey, orders.o_orderdate, orders.o_totalprice)\n" +
" └─ SemiJoin\n" +
" ├─ (orders.o_orderkey = lineitem_1.l_orderkey)\n" +
" ├─ InnerJoin\n" +
" │ ├─ (orders.o_orderkey = lineitem.l_orderkey)\n" +
" │ ├─ InnerJoin\n" +
" │ │ ├─ (customer.c_custkey = orders.o_custkey)\n" +
" │ │ ├─ Table\n" +
" │ │ │ └─ name: customer\n" +
" │ │ └─ Table\n" +
" │ │ └─ name: orders\n" +
" │ └─ Table\n" +
" │ └─ name: lineitem\n" +
" └─ Project\n" +
" ├─ columns: [lineitem_1.l_orderkey]\n" +
" └─ Having((sum(lineitem.l_quantity) > 300))\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM(lineitem_1.l_quantity), lineitem_1.l_orderkey, lineitem_1.L_QUANTITY)\n" +
" ├─ Grouping(lineitem_1.l_orderkey)\n" +
" └─ TableAlias(lineitem_1)\n" +
" └─ Table\n" +
" └─ name: lineitem\n" +
"",
},
{
Query: `
--Q19
select
sum(l_extendedprice* (1 - l_discount)) as revenue
from
lineitem,
part
where
(
p_partkey = l_partkey
and p_brand = 'Brand#12'
and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
and l_quantity >= 1 and l_quantity <= 1 + 10
and p_size between 1 and 5
and l_shipmode in ('AIR', 'AIR REG')
and l_shipinstruct = 'DELIVER IN PERSON'
)
or
(
p_partkey = l_partkey
and p_brand = 'Brand#23'
and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
and l_quantity >= 10 and l_quantity <= 10 + 10
and p_size between 1 and 10
and l_shipmode in ('AIR', 'AIR REG')
and l_shipinstruct = 'DELIVER IN PERSON'
)
or
(
p_partkey = l_partkey
and p_brand = 'Brand#34'
and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
and l_quantity >= 20 and l_quantity <= 20 + 10
and p_size between 1 and 15
and l_shipmode in ('AIR', 'AIR REG')
and l_shipinstruct = 'DELIVER IN PERSON'
);`,
ExpectedPlan: "Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))):0!null as revenue]\n" +
" └─ GroupBy\n" +
" ├─ select: SUM((lineitem.l_extendedprice:2!null * (1 (tinyint) - lineitem.l_discount:3!null)))\n" +
" ├─ group: \n" +
" └─ LookupJoin\n" +
" ├─ Or\n" +
" │ ├─ Or\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ part.p_partkey:6!null\n" +
" │ │ │ │ │ │ │ │ │ │ └─ lineitem.l_partkey:0!null\n" +
" │ │ │ │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ │ │ │ ├─ part.p_brand:7!null\n" +
" │ │ │ │ │ │ │ │ │ └─ Brand#12 (longtext)\n" +
" │ │ │ │ │ │ │ │ └─ IN\n" +
" │ │ │ │ │ │ │ │ ├─ left: part.p_container:9!null\n" +
" │ │ │ │ │ │ │ │ └─ right: TUPLE(SM CASE (longtext), SM BOX (longtext), SM PACK (longtext), SM PKG (longtext))\n" +
" │ │ │ │ │ │ │ └─ GreaterThanOrEqual\n" +
" │ │ │ │ │ │ │ ├─ lineitem.l_quantity:1!null\n" +
" │ │ │ │ │ │ │ └─ 1 (tinyint)\n" +
" │ │ │ │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ │ │ │ ├─ lineitem.l_quantity:1!null\n" +
" │ │ │ │ │ │ └─ 11 (bigint)\n" +
" │ │ │ │ │ └─ AND\n" +
" │ │ │ │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ │ │ │ ├─ part.p_size:8!null\n" +
" │ │ │ │ │ │ └─ 1 (tinyint)\n" +
" │ │ │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ │ │ ├─ part.p_size:8!null\n" +
" │ │ │ │ │ └─ 5 (tinyint)\n" +
" │ │ │ │ └─ IN\n" +
" │ │ │ │ ├─ left: lineitem.l_shipmode:5!null\n" +
" │ │ │ │ └─ right: TUPLE(AIR (longtext), AIR REG (longtext))\n" +
" │ │ │ └─ Eq\n" +
" │ │ │ ├─ lineitem.l_shipinstruct:4!null\n" +
" │ │ │ └─ DELIVER IN PERSON (longtext)\n" +
" │ │ └─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ │ ├─ part.p_partkey:6!null\n" +
" │ │ │ │ │ │ │ │ │ └─ lineitem.l_partkey:0!null\n" +
" │ │ │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ part.p_brand:7!null\n" +
" │ │ │ │ │ │ │ │ └─ Brand#23 (longtext)\n" +
" │ │ │ │ │ │ │ └─ IN\n" +
" │ │ │ │ │ │ │ ├─ left: part.p_container:9!null\n" +
" │ │ │ │ │ │ │ └─ right: TUPLE(MED BAG (longtext), MED BOX (longtext), MED PKG (longtext), MED PACK (longtext))\n" +
" │ │ │ │ │ │ └─ GreaterThanOrEqual\n" +
" │ │ │ │ │ │ ├─ lineitem.l_quantity:1!null\n" +
" │ │ │ │ │ │ └─ 10 (tinyint)\n" +
" │ │ │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ │ │ ├─ lineitem.l_quantity:1!null\n" +
" │ │ │ │ │ └─ 20 (bigint)\n" +
" │ │ │ │ └─ AND\n" +
" │ │ │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ │ │ ├─ part.p_size:8!null\n" +
" │ │ │ │ │ └─ 1 (tinyint)\n" +
" │ │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ │ ├─ part.p_size:8!null\n" +
" │ │ │ │ └─ 10 (tinyint)\n" +
" │ │ │ └─ IN\n" +
" │ │ │ ├─ left: lineitem.l_shipmode:5!null\n" +
" │ │ │ └─ right: TUPLE(AIR (longtext), AIR REG (longtext))\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ lineitem.l_shipinstruct:4!null\n" +
" │ │ └─ DELIVER IN PERSON (longtext)\n" +
" │ └─ AND\n" +
" │ ├─ AND\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ │ ├─ part.p_partkey:6!null\n" +
" │ │ │ │ │ │ │ │ └─ lineitem.l_partkey:0!null\n" +
" │ │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ │ ├─ part.p_brand:7!null\n" +
" │ │ │ │ │ │ │ └─ Brand#34 (longtext)\n" +
" │ │ │ │ │ │ └─ IN\n" +
" │ │ │ │ │ │ ├─ left: part.p_container:9!null\n" +
" │ │ │ │ │ │ └─ right: TUPLE(LG CASE (longtext), LG BOX (longtext), LG PACK (longtext), LG PKG (longtext))\n" +
" │ │ │ │ │ └─ GreaterThanOrEqual\n" +
" │ │ │ │ │ ├─ lineitem.l_quantity:1!null\n" +
" │ │ │ │ │ └─ 20 (tinyint)\n" +
" │ │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ │ ├─ lineitem.l_quantity:1!null\n" +
" │ │ │ │ └─ 30 (bigint)\n" +
" │ │ │ └─ AND\n" +
" │ │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ │ ├─ part.p_size:8!null\n" +
" │ │ │ │ └─ 1 (tinyint)\n" +
" │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ ├─ part.p_size:8!null\n" +
" │ │ │ └─ 15 (tinyint)\n" +
" │ │ └─ IN\n" +
" │ │ ├─ left: lineitem.l_shipmode:5!null\n" +
" │ │ └─ right: TUPLE(AIR (longtext), AIR REG (longtext))\n" +
" │ └─ Eq\n" +
" │ ├─ lineitem.l_shipinstruct:4!null\n" +
" │ └─ DELIVER IN PERSON (longtext)\n" +
" ├─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_partkey l_quantity l_extendedprice l_discount l_shipinstruct l_shipmode]\n" +
" └─ Concat\n" +
" ├─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ ├─ keys: [lineitem.l_partkey:0!null]\n" +
" │ ├─ colSet: (17-25)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: part\n" +
" │ └─ columns: [p_partkey p_brand p_size p_container]\n" +
" └─ Concat\n" +
" ├─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ ├─ keys: [lineitem.l_partkey:0!null]\n" +
" │ ├─ colSet: (17-25)\n" +
" │ ├─ tableId: 2\n" +
" │ └─ Table\n" +
" │ ├─ name: part\n" +
" │ └─ columns: [p_partkey p_brand p_size p_container]\n" +
" └─ IndexedTableAccess(part)\n" +
" ├─ index: [part.P_PARTKEY]\n" +
" ├─ keys: [lineitem.l_partkey:0!null]\n" +
" ├─ colSet: (17-25)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: part\n" +
" └─ columns: [p_partkey p_brand p_size p_container]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))))\n" +
" ├─ Grouping()\n" +
" └─ LookupJoin\n" +
" ├─ ((((((((((part.p_partkey = lineitem.l_partkey) AND (part.p_brand = 'Brand#12')) AND (part.p_container IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG'))) AND (lineitem.l_quantity >= 1)) AND (lineitem.l_quantity <= 11)) AND ((part.p_size >= 1) AND (part.p_size <= 5))) AND (lineitem.l_shipmode IN ('AIR', 'AIR REG'))) AND (lineitem.l_shipinstruct = 'DELIVER IN PERSON')) OR ((((((((part.p_partkey = lineitem.l_partkey) AND (part.p_brand = 'Brand#23')) AND (part.p_container IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK'))) AND (lineitem.l_quantity >= 10)) AND (lineitem.l_quantity <= 20)) AND ((part.p_size >= 1) AND (part.p_size <= 10))) AND (lineitem.l_shipmode IN ('AIR', 'AIR REG'))) AND (lineitem.l_shipinstruct = 'DELIVER IN PERSON'))) OR ((((((((part.p_partkey = lineitem.l_partkey) AND (part.p_brand = 'Brand#34')) AND (part.p_container IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG'))) AND (lineitem.l_quantity >= 20)) AND (lineitem.l_quantity <= 30)) AND ((part.p_size >= 1) AND (part.p_size <= 15))) AND (lineitem.l_shipmode IN ('AIR', 'AIR REG'))) AND (lineitem.l_shipinstruct = 'DELIVER IN PERSON')))\n" +
" ├─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_partkey l_quantity l_extendedprice l_discount l_shipinstruct l_shipmode]\n" +
" └─ Concat\n" +
" ├─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ ├─ columns: [p_partkey p_brand p_size p_container]\n" +
" │ └─ keys: lineitem.l_partkey\n" +
" └─ Concat\n" +
" ├─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ ├─ columns: [p_partkey p_brand p_size p_container]\n" +
" │ └─ keys: lineitem.l_partkey\n" +
" └─ IndexedTableAccess(part)\n" +
" ├─ index: [part.P_PARTKEY]\n" +
" ├─ columns: [p_partkey p_brand p_size p_container]\n" +
" └─ keys: lineitem.l_partkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [sum((lineitem.l_extendedprice * (1 - lineitem.l_discount))) as revenue]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(SUM((lineitem.l_extendedprice * (1 - lineitem.l_discount))))\n" +
" ├─ Grouping()\n" +
" └─ LookupJoin\n" +
" ├─ ((((((((((part.p_partkey = lineitem.l_partkey) AND (part.p_brand = 'Brand#12')) AND (part.p_container IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG'))) AND (lineitem.l_quantity >= 1)) AND (lineitem.l_quantity <= 11)) AND ((part.p_size >= 1) AND (part.p_size <= 5))) AND (lineitem.l_shipmode IN ('AIR', 'AIR REG'))) AND (lineitem.l_shipinstruct = 'DELIVER IN PERSON')) OR ((((((((part.p_partkey = lineitem.l_partkey) AND (part.p_brand = 'Brand#23')) AND (part.p_container IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK'))) AND (lineitem.l_quantity >= 10)) AND (lineitem.l_quantity <= 20)) AND ((part.p_size >= 1) AND (part.p_size <= 10))) AND (lineitem.l_shipmode IN ('AIR', 'AIR REG'))) AND (lineitem.l_shipinstruct = 'DELIVER IN PERSON'))) OR ((((((((part.p_partkey = lineitem.l_partkey) AND (part.p_brand = 'Brand#34')) AND (part.p_container IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG'))) AND (lineitem.l_quantity >= 20)) AND (lineitem.l_quantity <= 30)) AND ((part.p_size >= 1) AND (part.p_size <= 15))) AND (lineitem.l_shipmode IN ('AIR', 'AIR REG'))) AND (lineitem.l_shipinstruct = 'DELIVER IN PERSON')))\n" +
" ├─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_partkey l_quantity l_extendedprice l_discount l_shipinstruct l_shipmode]\n" +
" └─ Concat\n" +
" ├─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ ├─ columns: [p_partkey p_brand p_size p_container]\n" +
" │ └─ keys: lineitem.l_partkey\n" +
" └─ Concat\n" +
" ├─ IndexedTableAccess(part)\n" +
" │ ├─ index: [part.P_PARTKEY]\n" +
" │ ├─ columns: [p_partkey p_brand p_size p_container]\n" +
" │ └─ keys: lineitem.l_partkey\n" +
" └─ IndexedTableAccess(part)\n" +
" ├─ index: [part.P_PARTKEY]\n" +
" ├─ columns: [p_partkey p_brand p_size p_container]\n" +
" └─ keys: lineitem.l_partkey\n" +
"",
},
{
Query: `
--Q20
select
s_name,
s_address
from
supplier,
nation
where
s_suppkey in (
select
ps_suppkey
from
partsupp
where
ps_partkey in (
select
p_partkey
from
part
where
p_name like 'forest%'
)
and ps_availqty > (
select
0.5 * sum(l_quantity)
from
lineitem
where
l_partkey = ps_partkey
and l_suppkey = ps_suppkey
and l_shipdate >= '1994-01-01'
and l_shipdate < '1994-01-01' + interval '1' year
)
)
and s_nationkey = n_nationkey
and n_name = 'CANADA'
order by
s_name;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [supplier.s_name:2!null, supplier.s_address:3!null]\n" +
" └─ Sort(supplier.s_name:2!null ASC nullsFirst)\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ Eq\n" +
" │ │ ├─ supplier.s_suppkey:1!null\n" +
" │ │ └─ partsupp.ps_suppkey:0!null\n" +
" │ ├─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [partsupp.ps_suppkey:1!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ GreaterThan\n" +
" │ │ │ ├─ partsupp.ps_availqty:2!null\n" +
" │ │ │ └─ Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ ├─ alias-string: select 0.5 * sum(l_quantity) from lineitem where l_partkey = ps_partkey and l_suppkey = ps_suppkey and l_shipdate >= '1994-01-01' and l_shipdate < '1994-01-01' + interval '1' year\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [(0.5 (decimal(2,1)) * sum(lineitem.l_quantity):5!null) as 0.5 * sum(l_quantity)]\n" +
" │ │ │ └─ GroupBy\n" +
" │ │ │ ├─ select: SUM(lineitem.l_quantity:7!null)\n" +
" │ │ │ ├─ group: \n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ │ │ ├─ lineitem.l_partkey:5!null\n" +
" │ │ │ │ │ │ │ └─ partsupp.ps_partkey:0!null\n" +
" │ │ │ │ │ │ └─ Eq\n" +
" │ │ │ │ │ │ ├─ lineitem.l_suppkey:6!null\n" +
" │ │ │ │ │ │ └─ partsupp.ps_suppkey:1!null\n" +
" │ │ │ │ │ └─ GreaterThanOrEqual\n" +
" │ │ │ │ │ ├─ lineitem.l_shipdate:8!null\n" +
" │ │ │ │ │ └─ 1994-01-01 (longtext)\n" +
" │ │ │ │ └─ LessThan\n" +
" │ │ │ │ ├─ lineitem.l_shipdate:8!null\n" +
" │ │ │ │ └─ 1995-01-01 00:00:00 +0000 UTC (datetime)\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: lineitem\n" +
" │ │ │ ├─ columns: [l_partkey l_suppkey l_quantity l_shipdate]\n" +
" │ │ │ ├─ colSet: (26-41)\n" +
" │ │ │ └─ tableId: 5\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [partsupp.PS_PARTKEY:0!null, partsupp.PS_SUPPKEY:1!null, partsupp.PS_AVAILQTY:2!null, partsupp.PS_SUPPLYCOST:3!null, partsupp.PS_COMMENT:4!null]\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: Eq\n" +
" │ │ │ ├─ partsupp.ps_partkey:0!null\n" +
" │ │ │ └─ part.p_partkey:5!null\n" +
" │ │ ├─ IndexedTableAccess(partsupp)\n" +
" │ │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ ├─ colSet: (12-16)\n" +
" │ │ │ ├─ tableId: 3\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: partsupp\n" +
" │ │ │ └─ columns: [ps_partkey ps_suppkey ps_availqty ps_supplycost ps_comment]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [part.p_partkey:0!null]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ AND\n" +
" │ │ │ ├─ AND\n" +
" │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ │ ├─ AND\n" +
" │ │ │ │ │ │ │ │ │ ├─ GreaterThanOrEqual\n" +
" │ │ │ │ │ │ │ │ │ │ ├─ part.p_name:1!null\n" +
" │ │ │ │ │ │ │ │ │ │ └─ forest (longtext)\n" +
" │ │ │ │ │ │ │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ │ │ │ │ │ │ ├─ part.p_name:1!null\n" +
" │ │ │ │ │ │ │ │ │ └─ forestÿ (longtext)\n" +
" │ │ │ │ │ │ │ │ └─ GreaterThanOrEqual\n" +
" │ │ │ │ │ │ │ │ ├─ part.p_name:1!null\n" +
" │ │ │ │ │ │ │ │ └─ forest (longtext)\n" +
" │ │ │ │ │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ │ │ │ │ ├─ part.p_name:1!null\n" +
" │ │ │ │ │ │ │ └─ forestÿ (longtext)\n" +
" │ │ │ │ │ │ └─ GreaterThanOrEqual\n" +
" │ │ │ │ │ │ ├─ part.p_name:1!null\n" +
" │ │ │ │ │ │ └─ forest (longtext)\n" +
" │ │ │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ │ │ ├─ part.p_name:1!null\n" +
" │ │ │ │ │ └─ forestÿ (longtext)\n" +
" │ │ │ │ └─ GreaterThanOrEqual\n" +
" │ │ │ │ ├─ part.p_name:1!null\n" +
" │ │ │ │ └─ forest (longtext)\n" +
" │ │ │ └─ LessThanOrEqual\n" +
" │ │ │ ├─ part.p_name:1!null\n" +
" │ │ │ └─ forestÿ (longtext)\n" +
" │ │ └─ IndexedTableAccess(part)\n" +
" │ │ ├─ index: [part.P_PARTKEY]\n" +
" │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ ├─ colSet: (17-25)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: part\n" +
" │ │ └─ columns: [p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment]\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ ├─ keys: [partsupp.ps_suppkey:0!null]\n" +
" │ ├─ colSet: (1-7)\n" +
" │ ├─ tableId: 1\n" +
" │ └─ Table\n" +
" │ ├─ name: supplier\n" +
" │ └─ columns: [s_suppkey s_name s_address s_nationkey s_phone s_acctbal s_comment]\n" +
" └─ Filter\n" +
" ├─ Eq\n" +
" │ ├─ nation.n_name:1!null\n" +
" │ └─ CANADA (longtext)\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" ├─ keys: [supplier.s_nationkey:4!null]\n" +
" ├─ colSet: (8-11)\n" +
" ├─ tableId: 2\n" +
" └─ Table\n" +
" ├─ name: nation\n" +
" └─ columns: [n_nationkey n_name n_regionkey n_comment]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [supplier.s_name, supplier.s_address]\n" +
" └─ Sort(supplier.s_name ASC)\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ (supplier.s_suppkey = partsupp.ps_suppkey)\n" +
" │ ├─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [partsupp.ps_suppkey]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (partsupp.ps_availqty > Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [(0.5 * sum(lineitem.l_quantity)) as 0.5 * sum(l_quantity)]\n" +
" │ │ │ └─ GroupBy\n" +
" │ │ │ ├─ SelectedExprs(SUM(lineitem.l_quantity))\n" +
" │ │ │ ├─ Grouping()\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ ((((lineitem.l_partkey = partsupp.ps_partkey) AND (lineitem.l_suppkey = partsupp.ps_suppkey)) AND (lineitem.l_shipdate >= '1994-01-01')) AND (lineitem.l_shipdate < 1995-01-01 00:00:00 +0000 UTC))\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: lineitem\n" +
" │ │ │ └─ columns: [l_partkey l_suppkey l_quantity l_shipdate]\n" +
" │ │ │ )\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [partsupp.PS_PARTKEY, partsupp.PS_SUPPKEY, partsupp.PS_AVAILQTY, partsupp.PS_SUPPLYCOST, partsupp.PS_COMMENT]\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: (partsupp.ps_partkey = part.p_partkey)\n" +
" │ │ ├─ IndexedTableAccess(partsupp)\n" +
" │ │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ │ └─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [part.p_partkey]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ ((((((((part.p_name >= 'forest') AND (part.p_name <= 'forestÿ')) AND (part.p_name >= 'forest')) AND (part.p_name <= 'forestÿ')) AND (part.p_name >= 'forest')) AND (part.p_name <= 'forestÿ')) AND (part.p_name >= 'forest')) AND (part.p_name <= 'forestÿ'))\n" +
" │ │ └─ IndexedTableAccess(part)\n" +
" │ │ ├─ index: [part.P_PARTKEY]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ └─ keys: partsupp.ps_suppkey\n" +
" └─ Filter\n" +
" ├─ (nation.n_name = 'CANADA')\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" └─ keys: supplier.s_nationkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [supplier.s_name, supplier.s_address]\n" +
" └─ Sort(supplier.s_name ASC)\n" +
" └─ LookupJoin\n" +
" ├─ LookupJoin\n" +
" │ ├─ (supplier.s_suppkey = partsupp.ps_suppkey)\n" +
" │ ├─ Distinct\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [partsupp.ps_suppkey]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (partsupp.ps_availqty > Subquery\n" +
" │ │ │ ├─ cacheable: false\n" +
" │ │ │ └─ Project\n" +
" │ │ │ ├─ columns: [(0.5 * sum(lineitem.l_quantity)) as 0.5 * sum(l_quantity)]\n" +
" │ │ │ └─ GroupBy\n" +
" │ │ │ ├─ SelectedExprs(SUM(lineitem.l_quantity))\n" +
" │ │ │ ├─ Grouping()\n" +
" │ │ │ └─ Filter\n" +
" │ │ │ ├─ ((((lineitem.l_partkey = partsupp.ps_partkey) AND (lineitem.l_suppkey = partsupp.ps_suppkey)) AND (lineitem.l_shipdate >= '1994-01-01')) AND (lineitem.l_shipdate < 1995-01-01 00:00:00 +0000 UTC))\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: lineitem\n" +
" │ │ │ └─ columns: [l_partkey l_suppkey l_quantity l_shipdate]\n" +
" │ │ │ )\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [partsupp.PS_PARTKEY, partsupp.PS_SUPPKEY, partsupp.PS_AVAILQTY, partsupp.PS_SUPPLYCOST, partsupp.PS_COMMENT]\n" +
" │ │ └─ MergeJoin\n" +
" │ │ ├─ cmp: (partsupp.ps_partkey = part.p_partkey)\n" +
" │ │ ├─ IndexedTableAccess(partsupp)\n" +
" │ │ │ ├─ index: [partsupp.PS_PARTKEY,partsupp.PS_SUPPKEY]\n" +
" │ │ │ └─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ └─ Project\n" +
" │ │ ├─ columns: [part.p_partkey]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ ((((((((part.p_name >= 'forest') AND (part.p_name <= 'forestÿ')) AND (part.p_name >= 'forest')) AND (part.p_name <= 'forestÿ')) AND (part.p_name >= 'forest')) AND (part.p_name <= 'forestÿ')) AND (part.p_name >= 'forest')) AND (part.p_name <= 'forestÿ'))\n" +
" │ │ └─ IndexedTableAccess(part)\n" +
" │ │ ├─ index: [part.P_PARTKEY]\n" +
" │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ └─ IndexedTableAccess(supplier)\n" +
" │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ └─ keys: partsupp.ps_suppkey\n" +
" └─ Filter\n" +
" ├─ (nation.n_name = 'CANADA')\n" +
" └─ IndexedTableAccess(nation)\n" +
" ├─ index: [nation.N_NATIONKEY]\n" +
" └─ keys: supplier.s_nationkey\n" +
"",
},
{
Query: `
--Q21
select
s_name,
count(*) as numwait
from
supplier,
lineitem l1,
orders,
nation
where
s_suppkey = l1.l_suppkey
and o_orderkey = l1.l_orderkey
and o_orderstatus = 'F'
and l1.l_receiptdate > l1.l_commitdate
and exists (
select
*
from
lineitem l2
where
l2.l_orderkey = l1.l_orderkey
and l2.l_suppkey <> l1.l_suppkey
)
and not exists (
select
*
from
lineitem l3
where
l3.l_orderkey = l1.l_orderkey
and l3.l_suppkey <> l1.l_suppkey
and l3.l_receiptdate > l3.l_commitdate
)
and s_nationkey = n_nationkey
and n_name = 'SAUDI ARABIA'
group by
s_name
order by
numwait desc,
s_name;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [supplier.s_name:1!null, count(1):0!null as numwait]\n" +
" └─ Sort(count(1):0!null as numwait DESC nullsFirst, supplier.s_name:1!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [count(1):0!null, supplier.s_name:1!null, count(1):0!null as numwait]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(1 (bigint)), supplier.s_name:26!null\n" +
" ├─ group: supplier.s_name:26!null\n" +
" └─ SemiLookupJoin\n" +
" ├─ NOT\n" +
" │ └─ Eq\n" +
" │ ├─ l2.l_suppkey:38!null\n" +
" │ └─ l1.l_suppkey:2!null\n" +
" ├─ AntiJoin\n" +
" │ ├─ AND\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ l3.l_orderkey:36!null\n" +
" │ │ │ └─ l1.l_orderkey:0!null\n" +
" │ │ └─ NOT\n" +
" │ │ └─ Eq\n" +
" │ │ ├─ l3.l_suppkey:38!null\n" +
" │ │ └─ l1.l_suppkey:2!null\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: Eq\n" +
" │ │ │ │ │ ├─ l1.l_orderkey:0!null\n" +
" │ │ │ │ │ └─ orders.o_orderkey:16!null\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ GreaterThan\n" +
" │ │ │ │ │ │ ├─ l1.l_receiptdate:12!null\n" +
" │ │ │ │ │ │ └─ l1.l_commitdate:11!null\n" +
" │ │ │ │ │ └─ TableAlias(l1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ │ │ ├─ static: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ │ │ ├─ colSet: (8-23)\n" +
" │ │ │ │ │ ├─ tableId: 2\n" +
" │ │ │ │ │ └─ Table\n" +
" │ │ │ │ │ ├─ name: lineitem\n" +
" │ │ │ │ │ └─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ Eq\n" +
" │ │ │ │ │ ├─ orders.o_orderstatus:2!null\n" +
" │ │ │ │ │ └─ F (longtext)\n" +
" │ │ │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ │ │ ├─ static: [{[NULL, ∞)}]\n" +
" │ │ │ │ ├─ colSet: (24-32)\n" +
" │ │ │ │ ├─ tableId: 3\n" +
" │ │ │ │ └─ Table\n" +
" │ │ │ │ ├─ name: orders\n" +
" │ │ │ │ └─ columns: [o_orderkey o_custkey o_orderstatus o_totalprice o_orderdate o_orderpriority o_clerk o_shippriority o_comment]\n" +
" │ │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ │ ├─ keys: [l1.l_suppkey:2!null]\n" +
" │ │ │ ├─ colSet: (1-7)\n" +
" │ │ │ ├─ tableId: 1\n" +
" │ │ │ └─ Table\n" +
" │ │ │ ├─ name: supplier\n" +
" │ │ │ └─ columns: [s_suppkey s_name s_address s_nationkey s_phone s_acctbal s_comment]\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ Eq\n" +
" │ │ │ ├─ nation.n_name:1!null\n" +
" │ │ │ └─ SAUDI ARABIA (longtext)\n" +
" │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ ├─ keys: [supplier.s_nationkey:28!null]\n" +
" │ │ ├─ colSet: (33-36)\n" +
" │ │ ├─ tableId: 4\n" +
" │ │ └─ Table\n" +
" │ │ ├─ name: nation\n" +
" │ │ └─ columns: [n_nationkey n_name n_regionkey n_comment]\n" +
" │ └─ Filter\n" +
" │ ├─ GreaterThan\n" +
" │ │ ├─ l3.l_receiptdate:12!null\n" +
" │ │ └─ l3.l_commitdate:11!null\n" +
" │ └─ TableAlias(l3)\n" +
" │ └─ ProcessTable\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
" └─ TableAlias(l2)\n" +
" └─ IndexedTableAccess(lineitem)\n" +
" ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" ├─ keys: [l1.l_orderkey:0!null]\n" +
" ├─ colSet: (37-52)\n" +
" ├─ tableId: 5\n" +
" └─ Table\n" +
" ├─ name: lineitem\n" +
" └─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [supplier.s_name, count(1) as numwait]\n" +
" └─ Sort(count(1) as numwait DESC, supplier.s_name ASC)\n" +
" └─ Project\n" +
" ├─ columns: [count(1), supplier.s_name, count(1) as numwait]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(1), supplier.s_name)\n" +
" ├─ Grouping(supplier.s_name)\n" +
" └─ SemiLookupJoin\n" +
" ├─ (NOT((l2.l_suppkey = l1.l_suppkey)))\n" +
" ├─ AntiJoin\n" +
" │ ├─ ((l3.l_orderkey = l1.l_orderkey) AND (NOT((l3.l_suppkey = l1.l_suppkey))))\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (l1.l_orderkey = orders.o_orderkey)\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ (l1.l_receiptdate > l1.l_commitdate)\n" +
" │ │ │ │ │ └─ TableAlias(l1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ │ │ └─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (orders.o_orderstatus = 'F')\n" +
" │ │ │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ │ └─ keys: l1.l_suppkey\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (nation.n_name = 'SAUDI ARABIA')\n" +
" │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ └─ keys: supplier.s_nationkey\n" +
" │ └─ Filter\n" +
" │ ├─ (l3.l_receiptdate > l3.l_commitdate)\n" +
" │ └─ TableAlias(l3)\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
" └─ TableAlias(l2)\n" +
" └─ IndexedTableAccess(lineitem)\n" +
" ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" ├─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
" └─ keys: l1.l_orderkey\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [supplier.s_name, count(1) as numwait]\n" +
" └─ Sort(count(1) as numwait DESC, supplier.s_name ASC)\n" +
" └─ Project\n" +
" ├─ columns: [count(1), supplier.s_name, count(1) as numwait]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(1), supplier.s_name)\n" +
" ├─ Grouping(supplier.s_name)\n" +
" └─ SemiLookupJoin\n" +
" ├─ (NOT((l2.l_suppkey = l1.l_suppkey)))\n" +
" ├─ AntiJoin\n" +
" │ ├─ ((l3.l_orderkey = l1.l_orderkey) AND (NOT((l3.l_suppkey = l1.l_suppkey))))\n" +
" │ ├─ LookupJoin\n" +
" │ │ ├─ LookupJoin\n" +
" │ │ │ ├─ MergeJoin\n" +
" │ │ │ │ ├─ cmp: (l1.l_orderkey = orders.o_orderkey)\n" +
" │ │ │ │ ├─ Filter\n" +
" │ │ │ │ │ ├─ (l1.l_receiptdate > l1.l_commitdate)\n" +
" │ │ │ │ │ └─ TableAlias(l1)\n" +
" │ │ │ │ │ └─ IndexedTableAccess(lineitem)\n" +
" │ │ │ │ │ ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" │ │ │ │ │ └─ filters: [{[NULL, ∞), [NULL, ∞)}]\n" +
" │ │ │ │ └─ Filter\n" +
" │ │ │ │ ├─ (orders.o_orderstatus = 'F')\n" +
" │ │ │ │ └─ IndexedTableAccess(orders)\n" +
" │ │ │ │ ├─ index: [orders.O_ORDERKEY]\n" +
" │ │ │ │ └─ filters: [{[NULL, ∞)}]\n" +
" │ │ │ └─ IndexedTableAccess(supplier)\n" +
" │ │ │ ├─ index: [supplier.S_SUPPKEY]\n" +
" │ │ │ └─ keys: l1.l_suppkey\n" +
" │ │ └─ Filter\n" +
" │ │ ├─ (nation.n_name = 'SAUDI ARABIA')\n" +
" │ │ └─ IndexedTableAccess(nation)\n" +
" │ │ ├─ index: [nation.N_NATIONKEY]\n" +
" │ │ └─ keys: supplier.s_nationkey\n" +
" │ └─ Filter\n" +
" │ ├─ (l3.l_receiptdate > l3.l_commitdate)\n" +
" │ └─ TableAlias(l3)\n" +
" │ └─ Table\n" +
" │ ├─ name: lineitem\n" +
" │ └─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
" └─ TableAlias(l2)\n" +
" └─ IndexedTableAccess(lineitem)\n" +
" ├─ index: [lineitem.L_ORDERKEY,lineitem.L_LINENUMBER]\n" +
" ├─ columns: [l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipdate l_commitdate l_receiptdate l_shipinstruct l_shipmode l_comment]\n" +
" └─ keys: l1.l_orderkey\n" +
"",
},
{
Query: `
--Q22
select
cntrycode,
count(*) as numcust,
sum(c_acctbal) as totacctbal
from
(
select
substring(c_phone from 1 for 2) as cntrycode,
c_acctbal
from
customer
where
substring(c_phone from 1 for 2) in
('13', '31', '23', '29', '30', '18', '17')
and c_acctbal > (
select
avg(c_acctbal)
from
customer
where
c_acctbal > 0.00
and substring(c_phone from 1 for 2) in
('13', '31', '23', '29', '30', '18', '17')
)
and not exists (
select
*
from
orders
where
o_custkey = c_custkey
)
) as custsale
group by
cntrycode
order by
cntrycode;`,
ExpectedPlan: "Project\n" +
" ├─ columns: [custsale.cntrycode:2!null, count(1):0!null as numcust, sum(custsale.c_acctbal):1!null as totacctbal]\n" +
" └─ Sort(custsale.cntrycode:2!null ASC nullsFirst)\n" +
" └─ Project\n" +
" ├─ columns: [count(1):0!null, sum(custsale.c_acctbal):1!null, custsale.cntrycode:2!null, count(1):0!null as numcust, sum(custsale.c_acctbal):1!null as totacctbal]\n" +
" └─ GroupBy\n" +
" ├─ select: COUNT(1 (bigint)), SUM(custsale.c_acctbal:1!null), custsale.cntrycode:0!null\n" +
" ├─ group: custsale.cntrycode:0!null\n" +
" └─ SubqueryAlias\n" +
" ├─ name: custsale\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" ├─ colSet: (28,29)\n" +
" ├─ tableId: 4\n" +
" └─ Project\n" +
" ├─ columns: [SUBSTRING(customer.c_phone, 1, 2) as cntrycode, customer.c_acctbal:5!null]\n" +
" └─ Filter\n" +
" ├─ GreaterThan\n" +
" │ ├─ customer.c_acctbal:5!null\n" +
" │ └─ Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ ├─ alias-string: select avg(c_acctbal) from customer where c_acctbal > 0.00 and substr(c_phone, 1, 2) in ('13', '31', '23', '29', '30', '18', '17')\n" +
" │ └─ Project\n" +
" │ ├─ columns: [avg(customer.c_acctbal):8 as avg(c_acctbal)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ select: AVG(customer.c_acctbal:9!null)\n" +
" │ ├─ group: \n" +
" │ └─ Filter\n" +
" │ ├─ AND\n" +
" │ │ ├─ GreaterThan\n" +
" │ │ │ ├─ customer.c_acctbal:9!null\n" +
" │ │ │ └─ 0 (decimal(15,2))\n" +
" │ │ └─ HashIn\n" +
" │ │ ├─ SUBSTRING(customer.c_phone, 1, 2)\n" +
" │ │ └─ TUPLE(13 (longtext), 31 (longtext), 23 (longtext), 29 (longtext), 30 (longtext), 18 (longtext), 17 (longtext))\n" +
" │ └─ Table\n" +
" │ ├─ name: customer\n" +
" │ ├─ columns: [c_phone c_acctbal]\n" +
" │ ├─ colSet: (9-16)\n" +
" │ └─ tableId: 2\n" +
" └─ Project\n" +
" ├─ columns: [customer.C_CUSTKEY:0!null, customer.C_NAME:1!null, customer.C_ADDRESS:2!null, customer.C_NATIONKEY:3!null, customer.C_PHONE:4!null, customer.C_ACCTBAL:5!null, customer.C_MKTSEGMENT:6!null, customer.C_COMMENT:7!null]\n" +
" └─ Filter\n" +
" ├─ orders.o_custkey:8!null IS NULL\n" +
" └─ LeftOuterHashJoinExcludeNulls\n" +
" ├─ Eq\n" +
" │ ├─ orders.o_custkey:8!null\n" +
" │ └─ customer.c_custkey:0!null\n" +
" ├─ Filter\n" +
" │ ├─ HashIn\n" +
" │ │ ├─ SUBSTRING(customer.c_phone, 1, 2)\n" +
" │ │ └─ TUPLE(13 (longtext), 31 (longtext), 23 (longtext), 29 (longtext), 30 (longtext), 18 (longtext), 17 (longtext))\n" +
" │ └─ Table\n" +
" │ ├─ name: customer\n" +
" │ ├─ columns: [c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment]\n" +
" │ ├─ colSet: (1-8)\n" +
" │ └─ tableId: 1\n" +
" └─ HashLookup\n" +
" ├─ left-key: TUPLE(customer.c_custkey:0!null)\n" +
" ├─ right-key: TUPLE(orders.o_custkey:0!null)\n" +
" └─ Project\n" +
" ├─ columns: [orders.o_custkey:1!null]\n" +
" └─ Table\n" +
" ├─ name: orders\n" +
" ├─ columns: [o_orderkey o_custkey o_orderstatus o_totalprice o_orderdate o_orderpriority o_clerk o_shippriority o_comment]\n" +
" ├─ colSet: (18-26)\n" +
" └─ tableId: 3\n" +
"",
ExpectedEstimates: "Project\n" +
" ├─ columns: [custsale.cntrycode, count(1) as numcust, sum(custsale.c_acctbal) as totacctbal]\n" +
" └─ Sort(custsale.cntrycode ASC)\n" +
" └─ Project\n" +
" ├─ columns: [count(1), sum(custsale.c_acctbal), custsale.cntrycode, count(1) as numcust, sum(custsale.c_acctbal) as totacctbal]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(1), SUM(custsale.c_acctbal), custsale.cntrycode)\n" +
" ├─ Grouping(custsale.cntrycode)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: custsale\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [SUBSTRING(customer.c_phone, 1, 2) as cntrycode, customer.c_acctbal]\n" +
" └─ Filter\n" +
" ├─ (customer.c_acctbal > Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [avg(customer.c_acctbal) as avg(c_acctbal)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(AVG(customer.c_acctbal))\n" +
" │ ├─ Grouping()\n" +
" │ └─ Filter\n" +
" │ ├─ ((customer.c_acctbal > 0.00) AND (SUBSTRING(customer.c_phone, 1, 2) HASH IN ('13', '31', '23', '29', '30', '18', '17')))\n" +
" │ └─ Table\n" +
" │ ├─ name: customer\n" +
" │ └─ columns: [c_phone c_acctbal]\n" +
" │ )\n" +
" └─ Project\n" +
" ├─ columns: [customer.C_CUSTKEY, customer.C_NAME, customer.C_ADDRESS, customer.C_NATIONKEY, customer.C_PHONE, customer.C_ACCTBAL, customer.C_MKTSEGMENT, customer.C_COMMENT]\n" +
" └─ Filter\n" +
" ├─ orders.o_custkey IS NULL\n" +
" └─ LeftOuterHashJoinExcludeNulls\n" +
" ├─ (orders.o_custkey = customer.c_custkey)\n" +
" ├─ Filter\n" +
" │ ├─ (SUBSTRING(customer.c_phone, 1, 2) HASH IN ('13', '31', '23', '29', '30', '18', '17'))\n" +
" │ └─ Table\n" +
" │ └─ name: customer\n" +
" └─ HashLookup\n" +
" ├─ left-key: (customer.c_custkey)\n" +
" ├─ right-key: (orders.o_custkey)\n" +
" └─ Project\n" +
" ├─ columns: [orders.o_custkey]\n" +
" └─ Table\n" +
" ├─ name: orders\n" +
" └─ columns: [o_orderkey o_custkey o_orderstatus o_totalprice o_orderdate o_orderpriority o_clerk o_shippriority o_comment]\n" +
"",
ExpectedAnalysis: "Project\n" +
" ├─ columns: [custsale.cntrycode, count(1) as numcust, sum(custsale.c_acctbal) as totacctbal]\n" +
" └─ Sort(custsale.cntrycode ASC)\n" +
" └─ Project\n" +
" ├─ columns: [count(1), sum(custsale.c_acctbal), custsale.cntrycode, count(1) as numcust, sum(custsale.c_acctbal) as totacctbal]\n" +
" └─ GroupBy\n" +
" ├─ SelectedExprs(COUNT(1), SUM(custsale.c_acctbal), custsale.cntrycode)\n" +
" ├─ Grouping(custsale.cntrycode)\n" +
" └─ SubqueryAlias\n" +
" ├─ name: custsale\n" +
" ├─ outerVisibility: false\n" +
" ├─ isLateral: false\n" +
" ├─ cacheable: true\n" +
" └─ Project\n" +
" ├─ columns: [SUBSTRING(customer.c_phone, 1, 2) as cntrycode, customer.c_acctbal]\n" +
" └─ Filter\n" +
" ├─ (customer.c_acctbal > Subquery\n" +
" │ ├─ cacheable: true\n" +
" │ └─ Project\n" +
" │ ├─ columns: [avg(customer.c_acctbal) as avg(c_acctbal)]\n" +
" │ └─ GroupBy\n" +
" │ ├─ SelectedExprs(AVG(customer.c_acctbal))\n" +
" │ ├─ Grouping()\n" +
" │ └─ Filter\n" +
" │ ├─ ((customer.c_acctbal > 0.00) AND (SUBSTRING(customer.c_phone, 1, 2) HASH IN ('13', '31', '23', '29', '30', '18', '17')))\n" +
" │ └─ Table\n" +
" │ ├─ name: customer\n" +
" │ └─ columns: [c_phone c_acctbal]\n" +
" │ )\n" +
" └─ Project\n" +
" ├─ columns: [customer.C_CUSTKEY, customer.C_NAME, customer.C_ADDRESS, customer.C_NATIONKEY, customer.C_PHONE, customer.C_ACCTBAL, customer.C_MKTSEGMENT, customer.C_COMMENT]\n" +
" └─ Filter\n" +
" ├─ orders.o_custkey IS NULL\n" +
" └─ LeftOuterHashJoinExcludeNulls\n" +
" ├─ (orders.o_custkey = customer.c_custkey)\n" +
" ├─ Filter\n" +
" │ ├─ (SUBSTRING(customer.c_phone, 1, 2) HASH IN ('13', '31', '23', '29', '30', '18', '17'))\n" +
" │ └─ Table\n" +
" │ └─ name: customer\n" +
" └─ HashLookup\n" +
" ├─ left-key: (customer.c_custkey)\n" +
" ├─ right-key: (orders.o_custkey)\n" +
" └─ Project\n" +
" ├─ columns: [orders.o_custkey]\n" +
" └─ Table\n" +
" ├─ name: orders\n" +
" └─ columns: [o_orderkey o_custkey o_orderstatus o_totalprice o_orderdate o_orderpriority o_clerk o_shippriority o_comment]\n" +
"",
},
}
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: 12}}}, }, { 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: 11}}}, }, { 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}}, }, }, }, { Name: "Insert error with auto commit off", SetUpScript: []string{ "create table t1 (pk int primary key, val int)", "insert into t1 values (0,0)", }, Assertions: []ScriptTestAssertion{ { Query: "/* client a */ set autocommit = off", SkipResultsCheck: true, }, { Query: "/* client b */ set autocommit = off", SkipResultsCheck: true, }, { Query: "/* client a */ insert into t1 values (1, 1)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ insert into t1 values (1, 2)", ExpectedErr: sql.ErrPrimaryKeyViolation, }, { Query: "/* client a */ insert into t1 values (2, 2)", Expected: []sql.Row{{types.NewOkResult(1)}}, }, { Query: "/* client a */ select * from t1 order by pk", Expected: []sql.Row{{0, 0}, {1, 1}, {2, 2}}, }, { Query: "/* client b */ select * from t1 order by pk", Expected: []sql.Row{{0, 0}}, }, { Query: "/* client a */ commit", SkipResultsCheck: true, }, { Query: "/* client b */ start transaction", SkipResultsCheck: true, }, { Query: "/* client b */ select * from t1 order by pk", Expected: []sql.Row{{0, 0}, {1, 1}, {2, 2}}, }, { Query: "/* client a */ select * from t1 order by pk", Expected: []sql.Row{{0, 0}, {1, 1}, {2, 2}}, }, }, }, }
var TriggerCreateInSubroutineTests = []ScriptTest{ { Name: "procedure must not contain CREATE TRIGGER", Assertions: []ScriptTestAssertion{ { Query: "CREATE PROCEDURE foo() CREATE PROCEDURE bar() SELECT 0;", ExpectedErrStr: "creating procedures in stored procedures is currently unsupported and will be added in a future release", }, }, }, { Name: "event must not contain CREATE TRIGGER", Assertions: []ScriptTestAssertion{ { Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE PROCEDURE bar() SELECT 1;", ExpectedErrStr: "Can't create a PROCEDURE from within another stored routine", Skip: true, }, }, }, { Name: "trigger must not contain CREATE TRIGGER", SetUpScript: []string{ "CREATE TABLE t (pk INT PRIMARY KEY);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN CREATE PROCEDURE bar() SELECT 1; END", ExpectedErrStr: "Can't create a PROCEDURE from within another stored routine", Skip: true, }, }, }, }
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, }, { Name: "prevent creating trigger over views", SetUpScript: []string{ "create table x (a int primary key, b int, c int)", "create view v as select * from x", }, Query: "create trigger trig before insert on v for each row set b = 1", ExpectedErr: sql.ErrExpectedTableFoundView, }, }
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: "nested triggers before insert before insert", 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 * 7);", "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: "nested triggers before insert after insert", 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 after insert on b for each row insert into c values (new.y * 7);", "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: "nested triggers after insert before insert", 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 after 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 * 7);", "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: "nested triggers after insert after insert", 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 after insert on a for each row insert into b values (new.x * 2);", "create trigger b1 after insert on b for each row insert into c values (new.y * 7);", "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: "nested triggers before delete before delete", 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 a values (1);", "insert into b values (10);", "insert into c values (100);", "create trigger a1 before delete on a for each row delete from b where y = (old.x * 10);", "create trigger b1 before delete on b for each row delete from c where z = (old.y * 10);", "delete from a where x = 1;", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a;", Expected: []sql.Row{}, }, { Query: "select y from b;", Expected: []sql.Row{}, }, { Query: "select z from c;", Expected: []sql.Row{}, }, }, }, { Name: "nested triggers before delete after delete", 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 a values (1);", "insert into b values (10);", "insert into c values (100);", "create trigger a1 before delete on a for each row delete from b where y = (old.x * 10);", "create trigger b1 after delete on b for each row delete from c where z = (old.y * 10);", "delete from a where x = 1;", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a;", Expected: []sql.Row{}, }, { Query: "select y from b;", Expected: []sql.Row{}, }, { Query: "select z from c;", Expected: []sql.Row{}, }, }, }, { Name: "nested triggers after delete before delete", 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 a values (1);", "insert into b values (10);", "insert into c values (100);", "create trigger a1 after delete on a for each row delete from b where y = (old.x * 10);", "create trigger b1 before delete on b for each row delete from c where z = (old.y * 10);", "delete from a where x = 1;", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a;", Expected: []sql.Row{}, }, { Query: "select y from b;", Expected: []sql.Row{}, }, { Query: "select z from c;", Expected: []sql.Row{}, }, }, }, { Name: "nested triggers after delete after delete", 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 a values (1);", "insert into b values (10);", "insert into c values (100);", "create trigger a1 after delete on a for each row delete from b where y = (old.x * 10);", "create trigger b1 after delete on b for each row delete from c where z = (old.y * 10);", "delete from a where x = 1;", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a;", Expected: []sql.Row{}, }, { Query: "select y from b;", Expected: []sql.Row{}, }, { Query: "select z from c;", Expected: []sql.Row{}, }, }, }, { Name: "nested triggers before update before update", 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 a values (1);", "insert into b values (2);", "insert into c values (3);", "create trigger a1 before update on a for each row update b set y = y + old.x + new.x;", "create trigger b1 before update on b for each row update c set z = z + old.y + new.y;", "update a set x = x + 1;", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a;", Expected: []sql.Row{ {2}, }, }, { Query: "select y from b;", Expected: []sql.Row{ {5}, }, }, { Query: "select z from c;", Expected: []sql.Row{ {10}, }, }, }, }, { Name: "nested triggers before update after update", 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 a values (1);", "insert into b values (2);", "insert into c values (3);", "create trigger a1 before update on a for each row update b set y = y + old.x + new.x;", "create trigger b1 after update on b for each row update c set z = z + old.y + new.y;", "update a set x = x + 1;", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a;", Expected: []sql.Row{ {2}, }, }, { Query: "select y from b;", Expected: []sql.Row{ {5}, }, }, { Query: "select z from c;", Expected: []sql.Row{ {10}, }, }, }, }, { Name: "nested triggers after update before update", 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 a values (1);", "insert into b values (2);", "insert into c values (3);", "create trigger a1 after update on a for each row update b set y = y + old.x + new.x;", "create trigger b1 before update on b for each row update c set z = z + old.y + new.y;", "update a set x = x + 1;", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a;", Expected: []sql.Row{ {2}, }, }, { Query: "select y from b;", Expected: []sql.Row{ {5}, }, }, { Query: "select z from c;", Expected: []sql.Row{ {10}, }, }, }, }, { Name: "nested triggers after update after update", 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 a values (1);", "insert into b values (2);", "insert into c values (3);", "create trigger a1 after update on a for each row update b set y = y + old.x + new.x;", "create trigger b1 after update on b for each row update c set z = z + old.y + new.y;", "update a set x = x + 1;", }, Assertions: []ScriptTestAssertion{ { Query: "select x from a;", Expected: []sql.Row{ {2}, }, }, { Query: "select y from b;", Expected: []sql.Row{ {5}, }, }, { Query: "select z from c;", Expected: []sql.Row{ {10}, }, }, }, }, { 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{{types.OkResult{}}}, }, { Query: "drop trigger t3", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "drop trigger if exists t5", Expected: []sql.Row{{types.OkResult{}}}, }, { 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{{types.OkResult{}}}, }, { 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: 0}}}, }, { 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{}}}, }, { SkipResultCheckOnServerEngine: true, 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)", }, }, }, { Name: "triggers with nested begin-end blocks", SetUpScript: []string{ "create table t (i int primary key);", ` create trigger trig before insert on t for each row begin declare x int; set x = new.i * 10; begin declare y int; set y = new.i + 10; set new.i = x + y; end; end; `, }, Assertions: []ScriptTestAssertion{ { Query: "insert into t values (1), (2), (3);", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {21}, {32}, {43}, }, }, }, }, { Name: "triggers with declare statements and select into", SetUpScript: []string{ "create table t (i int primary key);", "create trigger trig before insert on t for each row begin declare x int; select new.i + 10 into x; set new.i = x; end;", }, Assertions: []ScriptTestAssertion{ { Query: "insert into t values (1), (2), (3);", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {11}, {12}, {13}, }, }, }, }, { Name: "triggers with declare statements and set", SetUpScript: []string{ "create table t (i int primary key);", "create trigger trig before insert on t for each row begin declare x int; set x = new.i + 10; set new.i = x; end;", }, Assertions: []ScriptTestAssertion{ { Query: "insert into t values (1), (2), (3);", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {11}, {12}, {13}, }, }, }, }, { Name: "triggers with declare statements and insert", SetUpScript: []string{ "create table t (i int primary key);", "create table t2 (i int primary key);", ` create trigger trig before insert on t for each row begin declare x int; set x = new.i * 10; insert into t2 values (x); end; `, }, Assertions: []ScriptTestAssertion{ { Query: "insert into t values (1), (2), (3);", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {1}, {2}, {3}, }, }, { Query: "select * from t2;", Expected: []sql.Row{ {10}, {20}, {30}, }, }, }, }, { Name: "triggers with declare statements and update", SetUpScript: []string{ "create table t (i int primary key);", "create table t2 (i int primary key);", "insert into t2 values (1), (2), (3);", ` create trigger trig before insert on t for each row begin declare x int; set x = new.i * 10; update t2 set i = x where i = new.i; end; `, }, Assertions: []ScriptTestAssertion{ { Query: "insert into t values (1), (2), (3);", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {1}, {2}, {3}, }, }, { Query: "select * from t2;", Expected: []sql.Row{ {10}, {20}, {30}, }, }, }, }, { Name: "triggers with declare statements and delete", SetUpScript: []string{ "create table t (i int primary key);", "create table t2 (i int primary key);", "insert into t2 values (1), (2), (3);", ` create trigger trig before insert on t for each row begin declare x int; set x = new.i; delete from t2 where i = x; end; `, }, Assertions: []ScriptTestAssertion{ { Query: "insert into t values (1), (2), (3);", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {1}, {2}, {3}, }, }, { Query: "select * from t2;", Expected: []sql.Row{}, }, }, }, { Name: "triggers with declare statements and stored procedure", SetUpScript: []string{ "create table t (i int primary key);", "create table t2 (i int primary key);", ` create procedure proc(in i int) begin insert into t2 values (i); end; `, ` create trigger trig before insert on t for each row begin declare x int; set x = new.i + 10; call proc(x); end; `, }, Assertions: []ScriptTestAssertion{ { Query: "insert into t values (1), (2), (3);", Expected: []sql.Row{ {types.NewOkResult(3)}, }, }, { Query: "select * from t;", Expected: []sql.Row{ {1}, {2}, {3}, }, }, { Query: "select * from t2;", Expected: []sql.Row{ {11}, {12}, {13}, }, }, }, }, { Name: "triggers with multiple references to same table", SetUpScript: []string{ "create table t1 (i int);", "create table t2 (j int);", ` create trigger trig before insert on t1 for each row begin insert into t2 values (10 * new.i); insert into t2 values (20 * new.i); insert into t2 values (30 * new.i); update t2 set j = 100 * j; delete from t2 where j = 2000 * new.i; end; `, }, Assertions: []ScriptTestAssertion{ { Query: "insert into t1 values (1);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "select * from t1 order by i;", Expected: []sql.Row{ {1}, }, }, { Query: "select * from t2 order by j;", Expected: []sql.Row{ {1000}, {3000}, }, }, }, }, { Name: "double nested triggers referencing multiple tables", SetUpScript: []string{ "create table t (i int);", "create table tt (i int);", "create table t1 (id int primary key, t2_id int);", "create table t2 (id int primary key, t3_id int);", "create table t3 (id int primary key);", "insert into tt values (1), (2), (3);", "insert into t1 values (1, 2);", "insert into t2 values (2, 3);", "insert into t3 values (3);", ` create trigger trig1 after delete on t1 for each row begin insert into t values (old.id); insert into t values (old.t2_id); update tt set i = 10 * old.id where i = old.t2_id; delete from t2 where id = old.t2_id; end; `, ` create trigger trig2 after delete on t2 for each row begin insert into t values (old.id); insert into t values (old.t3_id); update tt set i = 10 * old.id where i = old.t3_id; delete from t3 where id = old.t3_id; end; `, }, Assertions: []ScriptTestAssertion{ { Query: "delete from t1 where id = 1;", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {1}, {2}, {2}, {3}, }, }, { Query: "select * from tt order by i;", Expected: []sql.Row{ {1}, {10}, {20}, }, }, { Query: "select * from t1;", Expected: []sql.Row{}, }, { Query: "select * from t2;", Expected: []sql.Row{}, }, { Query: "select * from t3;", Expected: []sql.Row{}, }, }, }, { Name: "triple nested delete triggers referencing multiple tables", SetUpScript: []string{ "create table t (i int);", "create table tt (i int);", "create table t1 (id int primary key, t2_id int);", "create table t2 (id int primary key, t3_id int);", "create table t3 (id int primary key);", "insert into tt values (1), (2), (3);", "insert into t1 values (1, 2);", "insert into t2 values (2, 3);", "insert into t3 values (3);", ` create trigger trig1 after delete on t1 for each row begin insert into t values (old.id); insert into t values (old.t2_id); update tt set i = 10 * old.t2_id where i = old.id; delete from t2 where id = old.t2_id; end; `, ` create trigger trig2 after delete on t2 for each row begin insert into t values (old.id); insert into t values (old.t3_id); update tt set i = 10 * old.t3_id where i = old.id; delete from t3 where id = old.t3_id; end; `, ` create trigger trig3 after delete on t3 for each row begin insert into t values (old.id); update tt set i = 9999 where i = old.id; end; `, }, Assertions: []ScriptTestAssertion{ { Query: "delete from t1 where id = 1;", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {1}, {2}, {2}, {3}, {3}, }, }, { Query: "select * from tt order by i;", Expected: []sql.Row{ {20}, {30}, {9999}, }, }, { Query: "select * from t1;", Expected: []sql.Row{}, }, { Query: "select * from t2;", Expected: []sql.Row{}, }, { Query: "select * from t3;", Expected: []sql.Row{}, }, }, }, { Name: "triple nested insert triggers referencing multiple tables", SetUpScript: []string{ "create table t (i int);", "create table tt (i int primary key, j int);", "create table ttt (i int primary key);", "create table t1 (i int primary key);", "create table t2 (i int primary key, j int);", "create table t3 (i int primary key, j int, k int);", "insert into tt values (1, 0), (2, 0), (3, 0);", "insert into ttt values (1), (2), (3);", ` create trigger trig1 after insert on t1 for each row begin insert into t values (new.i); update tt set j = 100 * new.i where i = new.i; delete from ttt where i = new.i; insert into t2 values (new.i + 1, 10 * new.i); end; `, ` create trigger trig2 after insert on t2 for each row begin insert into t values (new.i), (new.j); update tt set j = 100 * new.i where i = new.i; delete from ttt where i = new.i; insert into t3 values (new.i + 1, 10 * new.j, new.i + new.j); end; `, ` create trigger trig3 after insert on t3 for each row begin insert into t values (new.i), (new.j), (new.k); update tt set j = 100 * new.i where i = new.i; delete from ttt where i = new.i; end; `, }, Assertions: []ScriptTestAssertion{ { Query: "insert into t1 values (1);", Expected: []sql.Row{ {types.NewOkResult(1)}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {1}, {2}, {3}, {10}, {12}, {100}, }, }, { Query: "select * from tt order by i;", Expected: []sql.Row{ {1, 100}, {2, 200}, {3, 300}, }, }, { Query: "select * from ttt order by i;", Expected: []sql.Row{}, }, { Query: "select * from t1;", Expected: []sql.Row{ {1}, }, }, { Query: "select * from t2;", Expected: []sql.Row{ {2, 10}, }, }, { Query: "select * from t3;", Expected: []sql.Row{ {3, 100, 12}, }, }, }, }, { Name: "triple nested update triggers referencing multiple tables", SetUpScript: []string{ "create table t (i int);", "create table tt (i int primary key, j int);", "insert into tt values (1, 0), (2, 0), (3, 0);", "create table ttt (i int primary key);", "insert into ttt values (1), (2), (3);", "create table t1 (i int primary key);", "create table t2 (i int primary key, j int);", "create table t3 (i int primary key, j int, k int);", "insert into t1 values (1);", "insert into t2 values (1, 0);", "insert into t3 values (1, 0, 0);", ` create trigger trig1 after update on t1 for each row begin insert into t values (old.i), (new.i); update tt set j = 100 * new.i where i = new.i; delete from ttt where i = new.i; update t2 set j = 10 * new.i where i = old.i; end; `, ` create trigger trig2 after update on t2 for each row begin insert into t values (old.i), (old.j), (new.i), (new.j); update tt set j = 100 * new.i where i = new.i; delete from ttt where i = new.i; update t3 set j = 10 * new.i where i = old.i; update t3 set k = 100 * new.i where i = old.i; end; `, ` create trigger trig3 after update on t3 for each row begin insert into t values (old.i), (new.i), (old.j), (new.j), (old.k), (new.k); update tt set j = 100 * new.i where i = new.i; delete from ttt where i = new.i; end; `, }, Assertions: []ScriptTestAssertion{ { Query: "update t1 set i = 2 where i = 1;", Expected: []sql.Row{ {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}, }, }, { Query: "select * from t order by i;", Expected: []sql.Row{ {0}, {0}, {0}, {0}, {0}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {2}, {10}, {10}, {10}, {20}, {100}, }, }, { Query: "select * from tt order by i;", Expected: []sql.Row{ {1, 100}, {2, 200}, {3, 0}, }, }, { Query: "select * from ttt order by i;", Expected: []sql.Row{ {3}, }, }, { Query: "select * from t1;", Expected: []sql.Row{ {2}, }, }, { Query: "select * from t2;", Expected: []sql.Row{ {1, 20}, }, }, { Query: "select * from t3;", Expected: []sql.Row{ {1, 10, 100}, }, }, }, }, }
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)}}, ExpectedWarningsCount: 2, 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)}}, ExpectedWarningsCount: 2, 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)}}, ExpectedWarningsCount: 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)}}, ExpectedWarningsCount: 2, 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)}}, ExpectedWarningsCount: 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)}}, ExpectedWarningsCount: 2, 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)}}, ExpectedWarningsCount: 1, 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)}}, ExpectedWarningsCount: 1, 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, "", ""}}, }, { 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, "", ""}}, }, { SkipServerEngine: true, 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, "", ""}}, }, { 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(6, 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: `UPDATE IGNORE 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 IGNORE one_pk JOIN one_pk one_pk2 on one_pk.pk = one_pk2.pk SET one_pk.pk = 10`, ExpectedWriteResult: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 4, Updated: 1, Warnings: 0}}}}, SelectQuery: "SELECT * FROM one_pk;", ExpectedSelect: []sql.Row{ sql.NewRow(1, 10, 11, 12, 13, 14), sql.NewRow(2, 20, 21, 22, 23, 24), sql.NewRow(3, 30, 31, 32, 33, 34), sql.NewRow(10, 0, 1, 2, 3, 4), }, }, { 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: "Create user limits", Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "create user abcdefghijklmnopqrstuvwxyz0123456789@'localhost' identified by 'abc123';", ExpectedErr: sql.ErrUserNameTooLong, }, { User: "root", Host: "localhost", Query: "create user j@'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'" + " identified by 'abc123';", ExpectedErr: sql.ErrUserHostTooLong, }, }, }, { 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: "SHOW BINARY LOGS;", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-admin", Host: "localhost", Query: "SHOW BINARY LOGS;", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-client", Host: "localhost", Query: "SHOW BINARY LOGS;", Expected: []sql.Row{}, }, { User: "replica-reload", Host: "localhost", Query: "SHOW BINARY LOGS;", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "root", Host: "localhost", Query: "SHOW BINARY LOGS;", Expected: []sql.Row{}, }, { User: "user", Host: "localhost", Query: "SHOW BINARY LOG STATUS;", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-admin", Host: "localhost", Query: "SHOW BINARY LOG STATUS;", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "replica-client", Host: "localhost", Query: "SHOW BINARY LOG STATUS;", Expected: []sql.Row{}, }, { User: "replica-reload", Host: "localhost", Query: "SHOW BINARY LOG STATUS;", ExpectedErr: sql.ErrPrivilegeCheckFailed, }, { User: "root", Host: "localhost", Query: "SHOW BINARY LOG 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);", "CREATE TABLE mydb.invis (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: "WITH cte AS (SELECT * FROM mydb.test) SELECT * FROM cte;/*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: "WITH cte AS (SELECT * FROM mydb.test) SELECT * FROM cte;/*6*/", Expected: []sql.Row{{1}}, }, { User: "tester", Host: "localhost", Query: "WITH cte AS (SELECT * FROM mydb.test) SELECT * FROM cte JOIN mydb.invis t2 WHERE cte.pk = t2.pk;", ExpectedErr: sql.ErrTableAccessDeniedForUser, }, { User: "tester", Host: "localhost", Query: "WITH cte AS (SELECT * FROM mydb.test) SELECT * FROM cte JOIN mydb.test t2 WHERE cte.pk = t2.pk;", Expected: []sql.Row{{1, 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", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "", []byte(""), []byte(""), []byte(""), uint32(0), uint32(0), uint32(0), uint32(0), "mysql_native_password", "", "N", time.Unix(1, 0).UTC(), nil, "N", "Y", "Y", nil, nil, nil, nil, "", }, }, }, { Query: "SELECT Host, User, Plugin, length(authentication_string) > 0 FROM mysql.user order by User;", Expected: []sql.Row{ {"localhost", "root", "mysql_native_password", false}, {"127.0.0.1", "testuser", "mysql_native_password", false}, {"localhost", "testuser2", "caching_sha2_password", false}, }, }, }, }, { Name: "User creation with auth plugin specified: mysql_native_password", SetUpScript: []string{ "CREATE USER testuser1@`127.0.0.1` identified with mysql_native_password by 'pass1';", "CREATE USER testuser2@`127.0.0.1` identified with 'mysql_native_password';", }, Assertions: []UserPrivilegeTestAssertion{ { Query: "select user, host, plugin, authentication_string from mysql.user where user='testuser1';", Expected: []sql.Row{{"testuser1", "127.0.0.1", "mysql_native_password", "*22A99BA288DB55E8E230679259740873101CD636"}}, }, { Query: "select user, host, plugin, authentication_string from mysql.user where user='testuser2';", Expected: []sql.Row{{"testuser2", "127.0.0.1", "mysql_native_password", ""}}, }, }, }, { Name: "User creation with auth plugin specified: caching_sha2_password", SetUpScript: []string{ "CREATE USER testuser1@`127.0.0.1` identified with caching_sha2_password by 'pass1';", "CREATE USER testuser2@`127.0.0.1` identified with 'caching_sha2_password';", }, Assertions: []UserPrivilegeTestAssertion{ { Query: "select user, host, plugin, authentication_string like '$A$005$%' from mysql.user where user='testuser1';", Expected: []sql.Row{{"testuser1", "127.0.0.1", "caching_sha2_password", true}}, }, { Query: "select user, host, plugin, authentication_string from mysql.user where user='testuser2';", Expected: []sql.Row{{"testuser2", "127.0.0.1", "caching_sha2_password", ""}}, }, }, }, { Name: "Migrate a user from mysql_native_password to caching_sha2_password", SetUpScript: []string{ "CREATE USER testuser1@`127.0.0.1` identified with mysql_native_password by 'pass1';", }, Assertions: []UserPrivilegeTestAssertion{ { Query: "select user, host, plugin, authentication_string from mysql.user where user='testuser1';", Expected: []sql.Row{{"testuser1", "127.0.0.1", "mysql_native_password", "*22A99BA288DB55E8E230679259740873101CD636"}}, }, { Query: "ALTER USER testuser1@`127.0.0.1` IDENTIFIED WITH caching_sha2_password BY 'pass1';", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "select user, host, plugin, authentication_string like '$A$005$%' from mysql.user where user='testuser1';", Expected: []sql.Row{{"testuser1", "127.0.0.1", "caching_sha2_password", true}}, }, { Query: "ALTER USER testuser1@`127.0.0.1` IDENTIFIED WITH caching_sha2_password;", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { Query: "select user, host, plugin, authentication_string from mysql.user where user='testuser1';", Expected: []sql.Row{{"testuser1", "127.0.0.1", "caching_sha2_password", ""}}, }, }, }, { 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: "procedure grants and restrictions", SetUpScript: []string{ "CREATE USER granted@localhost", "GRANT EXECUTE ON mydb.* TO granted@localhost", "GRANT EXECUTE ON PROCEDURE mydb.memory_admin_only TO granted@localhost", "CREATE USER denied@localhost", "GRANT EXECUTE ON mydb.* TO denied@localhost", "CREATE USER targeted@localhost", "GRANT EXECUTE ON PROCEDURE mydb.memory_admin_only TO targeted@localhost", "CREATE USER noaccess@localhost", }, Assertions: []UserPrivilegeTestAssertion{ { User: "granted", Host: "localhost", Query: "CALL mydb.memory_admin_only(1,2)", Expected: []sql.Row{{3}}, }, { User: "denied", Host: "localhost", Query: "CALL mydb.memory_variadic_add(3,2)", Expected: []sql.Row{{5}}, }, { User: "denied", Host: "localhost", Query: "CALL mydb.memory_admin_only(1,2)", ExpectedErrStr: "command denied to user 'denied'@'localhost'", }, { User: "targeted", Host: "localhost", Query: "CALL mydb.memory_variadic_add(3,2)", ExpectedErrStr: "command denied to user 'targeted'@'localhost'", }, { User: "targeted", Host: "localhost", Query: "CALL mydb.memory_admin_only(7,2)", Expected: []sql.Row{{9}}, }, { User: "noaccess", Host: "localhost", Query: "CALL mydb.memory_variadic_add(3,2)", ExpectedErrStr: "Access denied for user 'noaccess'@'localhost' to database 'mydb'", }, { User: "noaccess", Host: "localhost", Query: "CALL mydb.memory_admin_only(1,2)", ExpectedErrStr: "Access denied for user 'noaccess'@'localhost' to database 'mydb'", }, }, }, { 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", "Y", "N", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Y", "N", "N"}}, }, { 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", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Y", "N", "N"}}, }, { 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", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "Y", "N", "N"}}, }, }, }, { 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(), "Select,Delete,Drop", ""}}, }, { 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(), "Select,Drop", ""}}, }, { 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(), "References,Index", ""}}, }, }, }, { Name: "GRANT Procedure and function privileges reflect in mysql.procs_priv", SetUpScript: []string{ "CREATE USER tester1@localhost;", "CREATE USER tester2@localhost;", "GRANT EXECUTE ON PROCEDURE mydb.proc1 TO tester1@localhost;", "GRANT GRANT OPTION ON PROCEDURE mydb.proc1 TO tester1@localhost;", "GRANT ALTER ROUTINE ON PROCEDURE mydb.proc2 TO tester1@localhost;", "GRANT GRANT OPTION ON PROCEDURE mydb.proc1 TO tester2@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SELECT Routine_name,Routine_type,proc_priv from mysql.procs_priv WHERE User = 'tester1'", Expected: []sql.Row{ {"proc1", "PROCEDURE", "Grant,Execute"}, {"proc2", "PROCEDURE", "Alter Routine"}, }, }, { User: "root", Host: "localhost", Query: "SELECT Routine_name,Routine_type,proc_priv from mysql.procs_priv WHERE User = 'tester2'", Expected: []sql.Row{{"proc1", "PROCEDURE", "Grant"}}, }, { User: "tester1", Host: "localhost", Query: "GRANT Execute ON PROCEDURE mydb.proc1 TO tester2@localhost", Expected: []sql.Row{{types.NewOkResult(0)}}, }, { User: "tester2", Host: "localhost", Query: "GRANT Execute ON PROCEDURE mydb.proc2 TO tester1@localhost", ExpectedErrStr: "command denied to user 'tester2'@'localhost'", }, }, }, { Name: "GRANT Procedure and function privileges reflect in mysql.procs_priv", SetUpScript: []string{ "CREATE USER tester1@localhost;", "CREATE USER tester2@localhost;", "GRANT EXECUTE ON PROCEDURE mydb.proc1 TO tester1@localhost;", "GRANT GRANT OPTION ON PROCEDURE mydb.proc1 TO tester1@localhost;", "GRANT ALTER ROUTINE ON PROCEDURE mydb.proc2 TO tester1@localhost;", "GRANT GRANT OPTION ON PROCEDURE mydb.proc2 TO tester2@localhost;", "GRANT EXECUTE ON PROCEDURE mydb.proc2 TO tester2@localhost;", "REVOKE EXECUTE ON PROCEDURE mydb.proc1 FROM tester1@localhost;", "REVOKE ALTER ROUTINE ON PROCEDURE mydb.proc2 FROM tester1@localhost;", "REVOKE ALTER ROUTINE ON PROCEDURE mydb.proc2 FROM tester2@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "SELECT Routine_name,Routine_type,proc_priv from mysql.procs_priv WHERE User = 'tester1'", Expected: []sql.Row{{"proc1", "PROCEDURE", "Grant"}}, }, { User: "root", Host: "localhost", Query: "SELECT Routine_name,Routine_type,proc_priv from mysql.procs_priv WHERE User = 'tester2'", Expected: []sql.Row{sql.Row{"proc2", "PROCEDURE", "Grant,Execute"}}, }, }, }, { Name: "GRANT function privileges errors", SetUpScript: []string{ "CREATE USER tester1@localhost;", }, Assertions: []UserPrivilegeTestAssertion{ { User: "root", Host: "localhost", Query: "GRANT GRANT OPTION ON FUNCTION mydb.func1 TO tester1@localhost;", ExpectedErrStr: "fine grain function permissions currently unsupported", }, { User: "root", Host: "localhost", Query: "GRANT EXECUTE ON FUNCTION mydb.func1 TO tester1@localhost;", ExpectedErrStr: "fine grain function permissions currently unsupported", }, { User: "root", Host: "localhost", Query: "GRANT ALTER ROUTINE ON FUNCTION mydb.func1 TO tester1@localhost;", ExpectedErrStr: "fine grain function permissions currently unsupported", }, }, }, { 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", "Y"}}, }, { 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", "N"}}, }, }, }, { 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", "Y", "Y"}}, }, { 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", "N", "N"}}, }, }, }, { 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", "%", "Y"}}, }, }, }, { 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", "N"}}, }, { 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", "N"}}, }, }, }, { 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", "N"}}, }, { 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", "N"}}, }, { 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", "N"}}, }, { 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;", ExpectedErrStr: "Access denied for user 'rand_user1' (errno 1045) (sqlstate 28000)", }, { 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;", ExpectedErrStr: "Access denied for user 'rand_user2' (errno 1045) (sqlstate 28000)", }, }, }, { 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 bigint primary key, j bigint, key(j))", "INSERT INTO two VALUES (1, 4), (2, 5), (3, 6)", "CREATE TABLE one (f double primary key)", "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 table_name, column_name FROM information_schema.column_statistics where schema_name = 'mydb';", Expected: []sql.Row{ {"one", "f"}, }, }, { 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 table_name, column_name FROM information_schema.column_statistics where schema_name = 'mydb';", Expected: []sql.Row{ {"one", "f"}, {"two", "i"}, {"two", "j"}, }, }, }, }, { 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}}, }, }, }, { Name: "information schema is queryable", SetUpScript: []string{ "CREATE DATABASE testdb;", "CREATE USER testadmin@'%';", "GRANT ALL ON testdb.* TO testadmin@'%';", }, Assertions: []UserPrivilegeTestAssertion{ { User: "testadmin", Host: "%", Query: "USE testdb;", Expected: []sql.Row{}, }, { User: "testadmin", Host: "%", Query: `SELECT SUM(found) FROM ((SELECT 1 as found FROM information_schema.tables) UNION (SELECT 1 as found FROM information_schema.events)) as all_found;`, Expected: []sql.Row{{1.0}}, }, { User: "testadmin", Host: "%", Query: `(SELECT 1 as found FROM information_schema.tables) UNION (SELECT 1 as found FROM information_schema.events);`, Expected: []sql.Row{{1}}, }, { User: "testadmin", Host: "%", Query: `SELECT SUM(found) FROM ((SELECT 1 as found FROM dual) UNION (SELECT 1 as found FROM dual)) as all_found;`, Expected: []sql.Row{{1.0}}, }, { User: "testadmin", Host: "%", Query: `SELECT SUM(found) FROM ((SELECT 1 as found FROM information_schema.tables WHERE table_schema = 'testdb') UNION ALL (SELECT 1 as found FROM information_schema.views WHERE table_schema = 'testdb' LIMIT 1) UNION ALL (SELECT 1 as found FROM information_schema.table_constraints WHERE table_schema = 'testdb' LIMIT 1) UNION ALL (SELECT 1 as found FROM information_schema.triggers WHERE event_object_schema = 'testdb' LIMIT 1) UNION ALL (SELECT 1 as found FROM information_schema.routines WHERE routine_schema = 'testdb' LIMIT 1) UNION ALL (SELECT 1 as found FROM information_schema.events WHERE event_schema = 'testdb' LIMIT 1)) as all_found;`, Expected: []sql.Row{{nil}}, }, }, }, { Name: "Test user creation with hashed password", SetUpScript: []string{ "CREATE USER 'lol'@'%' IDENTIFIED WITH mysql_native_password AS '*91D9861DFC07DD967611B8C96953474EF270AD5E';", }, Assertions: []UserPrivilegeTestAssertion{ { Query: "SELECT User, plugin, authentication_string FROM mysql.user WHERE User = 'lol';", Expected: []sql.Row{ { "lol", "mysql_native_password", "*91D9861DFC07DD967611B8C96953474EF270AD5E", }, }, }, }, }, }
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: "variable scope is included in returned column name when explicitly provided", Assertions: []ScriptTestAssertion{ { Query: "select @@max_allowed_packet;", Expected: []sql.Row{{1073741824}}, ExpectedColumns: sql.Schema{ { Name: "@@max_allowed_packet", Type: types.Uint64, }, }, }, { Query: "select @@session.max_allowed_packet;", Expected: []sql.Row{{1073741824}}, ExpectedColumns: sql.Schema{ { Name: "@@session.max_allowed_packet", Type: types.Uint64, }, }, }, { Query: "select @@global.max_allowed_packet;", Expected: []sql.Row{{1073741824}}, ExpectedColumns: sql.Schema{ { Name: "@@global.max_allowed_packet", Type: types.Uint64, }, }, }, { Query: "select @@GLoBAL.max_allowed_packet;", Expected: []sql.Row{{1073741824}}, ExpectedColumns: sql.Schema{ { Name: "@@GLoBAL.max_allowed_packet", Type: types.Uint64, }, }, }, }, }, { Name: "@@server_id", Assertions: []ScriptTestAssertion{ { Query: "select @@server_id;", Expected: []sql.Row{{uint32(1)}}, }, { 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 system variable to no_auto_create_user, which has been deprecated", SetUpScript: []string{ `set sql_mode = NO_AUTO_CREATE_USER`, }, Query: "SELECT @@sql_mode", Expected: []sql.Row{ {"NO_AUTO_CREATE_USER"}, }, }, { 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: "set sql_mode variable ignores empty strings", SetUpScript: []string{ `SET sql_mode = ',,,,STRICT_TRANS_TABLES,,,,,NO_AUTO_VALUE_ON_ZERO,,,,NO_ENGINE_SUBSTITUTION,,,,,,'`, }, Query: "SELECT @@sql_mode", Expected: []sql.Row{ {"NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES"}, }, }, { 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: "innodb autoinc lock mode", SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { Query: `select @@innodb_autoinc_lock_mode;`, Expected: []sql.Row{ {2}, }, }, { Query: `select @@global.innodb_autoinc_lock_mode;`, Expected: []sql.Row{ {2}, }, }, { Skip: true, Query: `select @@session.innodb_autoinc_lock_mode;`, ExpectedErr: sql.ErrSystemVariableGlobalOnly, }, { Query: `set @@innodb_autoinc_lock_mode = 1;`, ExpectedErr: sql.ErrSystemVariableReadOnly, }, }, }, { 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 VectorFunctionQueries = []ScriptTest{ { Name: "basic usage of VEC_DISTANCE without index", SetUpScript: []string{ "create table vectors (id int primary key, v json);", `insert into vectors values (1, '[3.0,4.0]'), (2, '[0.0,0.0]'), (3, '[1.0,-1.0]'), (4, '[-2.0,0.0]');`, }, Assertions: []ScriptTestAssertion{ { Query: "select VEC_DISTANCE('[10.0]', '[20.0]');", Expected: []sql.Row{{100.0}}, }, { Query: "select VEC_DISTANCE_L2_SQUARED('[1.0, 2.0]', '[5.0, 5.0]');", Expected: []sql.Row{{25.0}}, }, { Query: "select * from vectors order by VEC_DISTANCE('[0.0,0.0]', v)", Expected: []sql.Row{ {2, types.MustJSON(`[0.0, 0.0]`)}, {3, types.MustJSON(`[1.0, -1.0]`)}, {4, types.MustJSON(`[-2.0, 0.0]`)}, {1, types.MustJSON(`[3.0, 4.0]`)}, }, }, { Query: "select * from vectors order by VEC_DISTANCE_L2_SQUARED('[-2.0,0.0]', v)", Expected: []sql.Row{ {4, types.MustJSON(`[-2.0, 0.0]`)}, {2, types.MustJSON(`[0.0, 0.0]`)}, {3, types.MustJSON(`[1.0, -1.0]`)}, {1, types.MustJSON(`[3.0, 4.0]`)}, }, }, }, }, }
var VectorIndexQueries = []ScriptTest{ { Name: "basic vector index", SetUpScript: []string{ "create table vectors (id int primary key, v json);", `insert into vectors values (1, '[4.0,3.0]'), (2, '[0.0,0.0]'), (3, '[-1.0,1.0]'), (4, '[0.0,-2.0]');`, `create vector index v_idx on vectors(v);`, }, Assertions: []ScriptTestAssertion{ { Query: "show create table vectors", Expected: []sql.Row{ {"vectors", "CREATE TABLE `vectors` (\n `id` int NOT NULL,\n `v` json,\n PRIMARY KEY (`id`),\n VECTOR KEY `v_idx` (`v`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, }, }, { Query: "select * from vectors order by VEC_DISTANCE('[0.0,0.0]', v) limit 4", Expected: []sql.Row{ {2, types.MustJSON(`[0.0, 0.0]`)}, {3, types.MustJSON(`[-1.0, 1.0]`)}, {4, types.MustJSON(`[0.0, -2.0]`)}, {1, types.MustJSON(`[4.0, 3.0]`)}, }, ExpectedIndexes: []string{"v_idx"}, }, { Query: "select * from vectors order by VEC_DISTANCE('[0.0,0.0]', v)", Expected: []sql.Row{ {2, types.MustJSON(`[0.0, 0.0]`)}, {3, types.MustJSON(`[-1.0, 1.0]`)}, {4, types.MustJSON(`[0.0, -2.0]`)}, {1, types.MustJSON(`[4.0, 3.0]`)}, }, ExpectedIndexes: nil, }, { Query: "select * from vectors order by VEC_DISTANCE_L2_SQUARED('[0.0,-2.0]', v) limit 4", Expected: []sql.Row{ {4, types.MustJSON(`[0.0, -2.0]`)}, {2, types.MustJSON(`[0.0, 0.0]`)}, {3, types.MustJSON(`[-1.0, 1.0]`)}, {1, types.MustJSON(`[4.0, 3.0]`)}, }, ExpectedIndexes: []string{"v_idx"}, }, { Query: "select * from vectors order by v limit 4", Expected: []sql.Row{ {3, types.MustJSON(`[-1.0, 1.0]`)}, {4, types.MustJSON(`[0.0, -2.0]`)}, {2, types.MustJSON(`[0.0, 0.0]`)}, {1, types.MustJSON(`[4.0, 3.0]`)}, }, ExpectedIndexes: []string{}, }, }, }, }
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", nil, ""}, {"s", "text", "NO", "", nil, ""}, }, }, { Query: "DESCRIBE myhistorytable AS OF '2019-01-03'", Expected: []sql.Row{ {"i", "bigint", "NO", "PRI", nil, ""}, {"s", "text", "NO", "", nil, ""}, {"c", "text", "NO", "", nil, ""}, }, }, }, }, }
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 TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, VIEW_DEFINITION, CHECK_OPTION, DEFINER, SECURITY_TYPE, " + "CHARACTER_SET_CLIENT, COLLATION_CONNECTION from information_schema.views where table_schema = 'mydb'", Expected: []sql.Row{ sql.NewRow("def", "mydb", "myview1", "SELECT * FROM myhistorytable", "NONE", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"), sql.NewRow("def", "mydb", "myview2", "SELECT * FROM myview1 WHERE i = 1", "NONE", "root@localhost", "DEFINER", "utf8mb4", "utf8mb4_0900_bin"), sql.NewRow("def", "mydb", "myview3", "SELECT i from myview1 union select s from myhistorytable", "NONE", "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", "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", "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("myview1"), sql.NewRow("myview2"), sql.NewRow("myview3"), sql.NewRow("myview4"), sql.NewRow("myview5"), }, }, }
var ViewCreateInSubroutineTests = []ScriptTest{ { Name: "procedure contains CREATE VIEW AS", Assertions: []ScriptTestAssertion{ { Query: "CREATE PROCEDURE foo() CREATE VIEW bar AS SELECT 1;", Skip: true, }, { Query: "CALL foo();", Skip: true, }, { Query: "SELECT * from bar;", Expected: []sql.Row{{1}}, Skip: true, }, }, }, { Name: "event contains CREATE VIEW AS", Assertions: []ScriptTestAssertion{ { Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE VIEW bar AS SELECT 1;", }, }, }, { Name: "trigger contains CREATE VIEW AS", SetUpScript: []string{ "CREATE TABLE t (pk INT PRIMARY KEY);", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN CREATE TABLE bar AS SELECT 1; END;", }, }, }, }
var ViewScripts = []ScriptTest{ { Name: "multi database view", SetUpScript: []string{ "Create database base;", "Create table base.xy (x int primary key, y int);", "Insert into base.xy values (1, 2);", "Create database live;", "create view live.xy as select base.xy.x AS x, base.xy.y AS y from base.xy;", }, Assertions: []ScriptTestAssertion{ { Query: "SELECT database()", Expected: []sql.Row{{"mydb"}}, }, { Query: "SELECT * from live.xy;", Expected: []sql.Row{{1, 2}}, }, }, }, { Name: "view of join with projections", SetUpScript: []string{ ` CREATE TABLE tab1 ( pk int NOT NULL, col0 int, col1 float, col2 text, col3 int, col4 float, col5 text, PRIMARY KEY (pk), KEY idx_tab1_0 (col0), KEY idx_tab1_1 (col1), KEY idx_tab1_3 (col3), KEY idx_tab1_4 (col4) )`, "insert into tab1 values (6, 0, 52.14, 'jxmel', 22, 2.27, 'pzxbn')", }, Assertions: []ScriptTestAssertion{ { Query: "CREATE VIEW view_2_tab1_157 AS SELECT pk, col0 FROM tab1 WHERE NOT ((col0 IN (SELECT col3 FROM tab1 WHERE ((col0 IS NULL) OR col3 > 5 OR col3 <= 50 OR col1 < 83.11))) OR col0 > 75)", Expected: []sql.Row{{types.OkResult{}}}, }, { Query: "select pk, col0 from view_2_tab1_157", Expected: []sql.Row{{6, 0}}, }, }, }, { Name: "view with expression name", SetUpScript: []string{ `create view v as select 2+2`, }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * from v;", Expected: []sql.Row{{4}}, ExpectedColumns: sql.Schema{ { Name: "2+2", Type: types.Int64, }, }, }, }, }, { Name: "view with column names", SetUpScript: []string{ `CREATE TABLE xy (x int primary key, y int);`, `create view v_today(today) as select CURRENT_DATE()`, `CREATE VIEW xyv (u,v) AS SELECT * from xy;`, }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * from xyv;", Expected: []sql.Row{}, ExpectedColumns: sql.Schema{ { Name: "u", Type: types.Int32, }, { Name: "v", Type: types.Int32, }, }, }, { Query: "SELECT * from v_today;", ExpectedColumns: sql.Schema{ { Name: "today", Type: types.LongText, }, }, }, { Query: "CREATE VIEW xyv (u) AS SELECT * from xy;", ExpectedErr: sql.ErrInvalidColumnNumber, }, }, }, { Name: "view columns retain original case", SetUpScript: []string{ `CREATE TABLE strs ( id int NOT NULL AUTO_INCREMENT, str varchar(15) NOT NULL, PRIMARY KEY (id));`, `CREATE VIEW caseSensitive AS SELECT id as AbCdEfG FROM strs;`, }, Assertions: []ScriptTestAssertion{ { Query: "SELECT * from caseSensitive;", Expected: []sql.Row{}, ExpectedColumns: sql.Schema{ { Name: "AbCdEfG", Type: types.Int32, }, }, }, }, }, { 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"}}, }, }, }, { Name: "show view", SetUpScript: []string{ "create table xy (x int primary key, y int)", "create view v as select * from xy", }, Assertions: []ScriptTestAssertion{ { Query: "show keys from v", Expected: []sql.Row{}, }, { Query: "show index from v from mydb", Expected: []sql.Row{}, }, { Query: "show index from v where Column_name = 'x'", Expected: []sql.Row{}, }, }, }, { Name: "views with defaults", SetUpScript: []string{ "create table t (i int primary key, j int default 100);", "insert into t(i) values (1);", "create table tt (ii int primary key, jj int default (pow(11, 2)));", "insert into tt values (1, default), (3, 4);", "create view v as select * from t;", "create view v1 as select i, j + 10 as jj from t;", "create view vv as select i, ii, j, jj, i + ii + j + jj from t join tt where i = ii;", }, Assertions: []ScriptTestAssertion{ { Query: "show full columns from v;", Expected: []sql.Row{ {"i", "int", nil, "NO", "", nil, "", "", ""}, {"j", "int", nil, "YES", "", "100", "", "", ""}, }, }, { Query: "show columns from v;", Expected: []sql.Row{ {"i", "int", "NO", "", nil, ""}, {"j", "int", "YES", "", "100", ""}, }, }, { Query: "describe v;", Expected: []sql.Row{ {"i", "int", "NO", "", nil, ""}, {"j", "int", "YES", "", "100", ""}, }, }, { Query: "select * from v", Expected: []sql.Row{ {1, 100}, }, }, { Query: "show full columns from v1;", Expected: []sql.Row{ {"i", "int", nil, "NO", "", nil, "", "", ""}, {"jj", "bigint", nil, "YES", "", nil, "", "", ""}, }, }, { Query: "show columns from v1;", Expected: []sql.Row{ {"i", "int", "NO", "", nil, ""}, {"jj", "bigint", "YES", "", nil, ""}, }, }, { Query: "describe v1;", Expected: []sql.Row{ {"i", "int", "NO", "", nil, ""}, {"jj", "bigint", "YES", "", nil, ""}, }, }, { Query: "select * from v1", Expected: []sql.Row{ {1, 110}, }, }, { Query: "show full columns from vv;", Expected: []sql.Row{ {"i", "int", nil, "NO", "", nil, "", "", ""}, {"ii", "int", nil, "NO", "", nil, "", "", ""}, {"j", "int", nil, "YES", "", "100", "", "", ""}, {"jj", "int", nil, "YES", "", "(power(11, 2))", "DEFAULT_GENERATED", "", ""}, {"i + ii + j + jj", "bigint", nil, "YES", "", nil, "", "", ""}, }, }, { Query: "show columns from vv;", Expected: []sql.Row{ {"i", "int", "NO", "", nil, ""}, {"ii", "int", "NO", "", nil, ""}, {"j", "int", "YES", "", "100", ""}, {"jj", "int", "YES", "", "(power(11, 2))", "DEFAULT_GENERATED"}, {"i + ii + j + jj", "bigint", "YES", "", nil, ""}, }, }, { Query: "describe vv;", Expected: []sql.Row{ {"i", "int", "NO", "", nil, ""}, {"ii", "int", "NO", "", nil, ""}, {"j", "int", "YES", "", "100", ""}, {"jj", "int", "YES", "", "(power(11, 2))", "DEFAULT_GENERATED"}, {"i + ii + j + jj", "bigint", "YES", "", nil, ""}, }, }, { Query: "select * from vv", Expected: []sql.Row{ {1, 1, 100, 121, 223}, }, }, }, }, }
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
type CharsetCollationWireTestQuery struct { Query string Expected []sql.Row Error bool // ExpectedCollations is an optional field, and when populated the test framework will assert that // the MySQL field metadata has these expected collation IDs. ExpectedCollations []sql.CollationID }
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 QueryPlanTest ¶
type QueryTest ¶
type QueryTest struct { // Query is the query string to execute Query string // Expected is the expected result of the query Expected []sql.Row // ExpectedColumns is the set of expected column names for the query results, if specified. // Only the Name and Type matter of the columns are checked. ExpectedColumns sql.Schema // Bindings are the bind values for the query, if provided Bindings map[string]sqlparser.Expr // SkipPrepared indicates that the query should be skipped when testing prepared statements SkipPrepared bool // SkipServerEngine indicates that the query should be skipped when testing a server engine (as opposed to the // simpler in-place engine object) SkipServerEngine bool // Dialect is the supported dialect for this query, which must match the dialect of the harness if specified. // The query is skipped if the dialect doesn't match. Dialect string }
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 USER tester@localhost; 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 // For tests that perform join operations, JoinTypes can be set for the type of merge we expect to perform. JoinTypes []plan.JoinType // SkipPrepared is true when we skip a test for prepared statements only SkipPrepared bool // Dialect is the supported dialect for this script, which must match the dialect of the harness if specified. // The script is skipped if the dialect doesn't match. Dialect string }
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 // For tests that perform join operations, JoinTypes can be set for the type of merge we expect to perform. JoinTypes []plan.JoinType // NewSession instructs the test framework that this assertion requires a new session to be created before the // query is executed. This is generally only needed when a test script is testing functionality that invalidates // a session and prevents additional queries from being executed on the session. NewSession bool // 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 // SkipResultCheckOnServerEngine is used when the result of over the wire test does not match the result from the engine test. // It should be fixed in the future. SkipResultCheckOnServerEngine bool // Bindings are variable mappings only used for prepared tests Bindings map[string]sqlparser.Expr // CheckIndexedAccess indicates whether we should verify the query plan uses an index CheckIndexedAccess bool // Dialect is the supported dialect for this assertion, which must match the dialect of the harness if specified. // The assertion is skipped if the dialect doesn't match. Dialect string }
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 ExpectedAuthPlugin string }
ServerAuthenticationTestAssertion is within a ServerAuthenticationTest to assert functionality.
type StatsPlanTest ¶ added in v0.18.0
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 is the INSERT, UPDATE. etc. statement to execute WriteQuery string // ExpectedWriteResult is the expected result of the write query ExpectedWriteResult []sql.Row // SelectQuery is a SELECT query to run after successfully executing the WriteQuery SelectQuery string // ExpectedSelect is the expected result of the SelectQuery ExpectedSelect []sql.Row // Bindings are the set of values to bind to the query Bindings map[string]sqlparser.Expr // Skip indicates whether this test should be skipped Skip bool // SkipServerEngine indicates whether this test should be skipped when the test is being run against a running // server (as opposed to the simpler Engine-based tests) SkipServerEngine bool // Dialect is the supported dialect for this test, which must match the dialect of the harness if specified. // The script is skipped if the dialect doesn't match. Dialect string }
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
- column_default_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_column_plans.go
- generated_columns.go
- imdb_plans.go
- index_queries.go
- index_query_plans.go
- information_schema_queries.go
- insert_queries.go
- integration_plans.go
- join_queries.go
- json_scripts.go
- json_table_queries.go
- load_queries.go
- logic_test_scripts.go
- mysql_db_queries.go
- null_range_tests.go
- numeric_error_queries.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
- row_limit_queries.go
- script_queries.go
- stats_queries.go
- sysbench_plans.go
- table_func_scripts.go
- tpc_ds_plans.go
- tpcc_plans.go
- tpch_plans.go
- transaction_queries.go
- trigger_queries.go
- type_wire_queries.go
- update_queries.go
- variable_queries.go
- vector_function_queries.go
- vector_index_queries.go
- view_queries.go