From 088261e210da0ece27339f77c3bc3fb218d69c5c Mon Sep 17 00:00:00 2001 From: Nick Tobey Date: Tue, 27 Aug 2024 15:06:27 -0700 Subject: [PATCH] Disable new tests that don't work with in-memory tables. --- enginetest/queries/generated_columns.go | 29 +++++++++++++++++-------- memory/table_data.go | 2 ++ memory/table_editor.go | 7 ++++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/enginetest/queries/generated_columns.go b/enginetest/queries/generated_columns.go index d15c823f2c..364fa2d372 100644 --- a/enginetest/queries/generated_columns.go +++ b/enginetest/queries/generated_columns.go @@ -275,7 +275,7 @@ var GeneratedColumnTests = []ScriptTest{ { Name: "creating unique index on stored generated column", SetUpScript: []string{ - "create table t1 (a int primary key, b int as (a * a) stored)", + "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{ @@ -289,26 +289,31 @@ var GeneratedColumnTests = []ScriptTest{ "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}}, + Expected: []sql.Row{{-2, 4, 0}}, }, { Query: "select * from t1 order by a", - Expected: []sql.Row{{-2, 4}, {-1, 1}}, + Expected: []sql.Row{{-2, 4, 0}, {-1, 1, 0}}, }, { Query: "select * from t1 order by b", - Expected: []sql.Row{{-1, 1}, {-2, 4}}, + 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, + }, }, }, { @@ -1140,7 +1145,7 @@ var GeneratedColumnTests = []ScriptTest{ { Name: "creating unique index on virtual generated column", SetUpScript: []string{ - "create table t1 (a int primary key, b int as (a * a) virtual)", + "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{ @@ -1154,6 +1159,7 @@ var GeneratedColumnTests = []ScriptTest{ "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"}}, @@ -1161,20 +1167,25 @@ var GeneratedColumnTests = []ScriptTest{ }, { Query: "select * from t1 where b = 4 order by a", - Expected: []sql.Row{{-2, 4}}, + Expected: []sql.Row{{-2, 4, 0}}, }, { Query: "select * from t1 order by a", - Expected: []sql.Row{{-2, 4}, {-1, 1}}, + Expected: []sql.Row{{-2, 4, 0}, {-1, 1, 0}}, }, { Query: "select * from t1 order by b", - Expected: []sql.Row{{-1, 1}, {-2, 4}}, + Expected: []sql.Row{{-1, 1, 0}, {-2, 4, 0}}, }, { Query: "insert into t1(a) values (2)", ExpectedErr: sql.ErrUniqueKeyViolation, - Skip: true, + Skip: true, // https://github.com/dolthub/go-mysql-server/issues/2643 + }, + { + Query: "create unique index i2 on t1(c)", + ExpectedErr: sql.ErrUniqueKeyViolation, + Skip: true, // https://github.com/dolthub/go-mysql-server/issues/2643 }, }, }, diff --git a/memory/table_data.go b/memory/table_data.go index 8989216083..f718097a41 100755 --- a/memory/table_data.go +++ b/memory/table_data.go @@ -278,6 +278,8 @@ func (td *TableData) errIfDuplicateEntryExist(cols []string, idxName string) err columnMapping, err := td.columnIndexes(cols) // We currently skip validating duplicates on unique virtual columns. + // Right now trying to validate them would just trigger a panic. + // See https://github.com/dolthub/go-mysql-server/issues/2643 for _, i := range columnMapping { if td.schema.Schema[i].Virtual { return nil diff --git a/memory/table_editor.go b/memory/table_editor.go index ff61ed4db4..2817555c34 100644 --- a/memory/table_editor.go +++ b/memory/table_editor.go @@ -319,8 +319,11 @@ func (t *tableEditor) pkColsDiffer(row, row2 sql.Row) bool { // Returns whether the values for the columns given match in the two rows provided func columnsMatch(colIndexes []int, prefixLengths []uint16, row sql.Row, row2 sql.Row, schema sql.Schema) bool { for i, idx := range colIndexes { + // Skip validating unique virtual columns. + // Right now trying to validate them would just trigger a panic. + // See https://github.com/dolthub/go-mysql-server/issues/2643 if schema[idx].Virtual { - continue + return false } v1 := row[idx] v2 := row2[idx] @@ -733,7 +736,7 @@ func (k *keylessTableEditAccumulator) GetByCols(value sql.Row, cols []int, prefi } for _, r := range k.adds { - if columnsMatch(cols, prefixLengths, r, value, nil) { + if columnsMatch(cols, prefixLengths, r, value, k.tableData.schema.Schema) { if deleteCount == 0 { return r, true, nil }