From 87bf2f47fcfc415f801dba61b633d91980e6386b Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Mon, 23 Sep 2024 13:52:40 -0700 Subject: [PATCH 1/3] tests for unique indexes --- testing/go/index_test.go | 109 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/testing/go/index_test.go b/testing/go/index_test.go index 284d2f9a93..49d8659690 100644 --- a/testing/go/index_test.go +++ b/testing/go/index_test.go @@ -68,6 +68,29 @@ func TestBasicIndexing(t *testing.T) { }, }, }, + { + Name: "Unique Covering Index", + Focus: true, + SetUpScript: []string{ + "CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 BIGINT);", + "INSERT INTO test VALUES (13, 3), (11, 1), (15, 5), (12, 2), (14, 4);", + "CREATE unique INDEX v1_idx ON test(v1);", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "SELECT * FROM test WHERE v1 > 2 ORDER BY pk;", + Expected: []sql.Row{ + {13, 3}, + {14, 4}, + {15, 5}, + }, + }, + { + Query: "insert into test values (16, 3);", + ExpectedErr: "Duplicate entry '3' for key 'v1_idx'", + }, + }, + }, { Name: "Covering Composite Index", SetUpScript: []string{ @@ -346,6 +369,28 @@ func TestBasicIndexing(t *testing.T) { }, }, }, + { + Name: "Unique Non-Covering Index", + SetUpScript: []string{ + "CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT);", + "INSERT INTO test VALUES (13, 3, 23), (11, 1, 21), (15, 5, 25), (12, 2, 22), (14, 4, 24);", + "CREATE UNIQUE INDEX v1_idx ON test(v1);", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "SELECT * FROM test WHERE v1 > 2 ORDER BY pk;", + Expected: []sql.Row{ + {13, 3, 23}, + {14, 4, 24}, + {15, 5, 25}, + }, + }, + { + Query: "insert into test values (16, 3, 23);", + ExpectedErr: "Duplicate entry '3' for key 'v1_idx'", + }, + }, + }, { Name: "Non-Covering Composite Index", SetUpScript: []string{ @@ -423,6 +468,32 @@ func TestBasicIndexing(t *testing.T) { }, }, { + Name: "Unique Non-Covering Composite Index", + SetUpScript: []string{ + "CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 BIGINT, v2 BIGINT, v3 BIGINT);", + "INSERT INTO test VALUES (13, 3, 23, 33), (11, 1, 21, 31), (15, 5, 25, 35), (12, 2, 22, 32), (14, 4, 24, 34);", + "CREATE UNIQUE INDEX v1_idx ON test(v1, v2);", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "SELECT * FROM test WHERE v1 < 3 AND v2 = 21 ORDER BY pk;", + Expected: []sql.Row{ + {11, 1, 21, 31}, + }, + }, + { + Query: "SELECT * FROM test WHERE v1 <= 3 AND v2 < 23 ORDER BY pk;", + Expected: []sql.Row{ + {11, 1, 21, 31}, + {12, 2, 22, 32}, + }, + }, + { + Query: "insert into test values (16, 3, 23, 33);", + ExpectedErr: "Duplicate entry '3-23' for key 'v1_idx'", + }, + }, + }, { Name: "Keyless Index", SetUpScript: []string{ "CREATE TABLE test (v0 BIGINT, v1 BIGINT, v2 BIGINT);", @@ -468,6 +539,17 @@ func TestBasicIndexing(t *testing.T) { }, }, }, + { + Name: "keyless unique index", + SetUpScript: []string{ + "CREATE TABLE aTable (aColumn INT NULL, bColumn INT NULL, primary key (aColumn));", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "CREATE UNIQUE INDEX aIndex ON aTable (bColumn);", + }, + }, + }, { Name: "Keyless Composite Index", SetUpScript: []string{ @@ -544,6 +626,33 @@ func TestBasicIndexing(t *testing.T) { }, }, }, + { + Name: "Unique Keyless Composite Index", + SetUpScript: []string{ + "CREATE TABLE test (v0 BIGINT, v1 BIGINT, v2 BIGINT, v3 BIGINT);", + "INSERT INTO test VALUES (13, 3, 23, 33), (11, 1, 21, 31), (15, 5, 25, 35), (12, 2, 22, 32), (14, 4, 24, 34);", + "CREATE UNIQUE INDEX v1_idx ON test(v1, v2);", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "SELECT * FROM test WHERE v1 = 2 AND v2 < 23 ORDER BY v0;", + Expected: []sql.Row{ + {12, 2, 22, 32}, + }, + }, + { + Query: "SELECT * FROM test WHERE v1 <= 3 AND v2 < 23 ORDER BY v0;", + Expected: []sql.Row{ + {11, 1, 21, 31}, + {12, 2, 22, 32}, + }, + }, + { + Query: "insert into test values (16, 3, 23, 33);", + ExpectedErr: "Duplicate entry '3-23' for key 'v1_idx'", + }, + }, + }, { Name: "Indexed Join Covering Indexes", SetUpScript: []string{ From 16ba9408f69ea907ec86ac42c197835c787a937c Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Mon, 23 Sep 2024 14:00:00 -0700 Subject: [PATCH 2/3] Tidy up unique index tests --- testing/go/index_test.go | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/testing/go/index_test.go b/testing/go/index_test.go index 49d8659690..5dd4e3e344 100644 --- a/testing/go/index_test.go +++ b/testing/go/index_test.go @@ -69,8 +69,7 @@ func TestBasicIndexing(t *testing.T) { }, }, { - Name: "Unique Covering Index", - Focus: true, + Name: "Unique Covering Index", SetUpScript: []string{ "CREATE TABLE test (pk BIGINT PRIMARY KEY, v1 BIGINT);", "INSERT INTO test VALUES (13, 3), (11, 1), (15, 5), (12, 2), (14, 4);", @@ -87,7 +86,7 @@ func TestBasicIndexing(t *testing.T) { }, { Query: "insert into test values (16, 3);", - ExpectedErr: "Duplicate entry '3' for key 'v1_idx'", + ExpectedErr: "duplicate unique key given", }, }, }, @@ -387,7 +386,7 @@ func TestBasicIndexing(t *testing.T) { }, { Query: "insert into test values (16, 3, 23);", - ExpectedErr: "Duplicate entry '3' for key 'v1_idx'", + ExpectedErr: "duplicate unique key given", }, }, }, @@ -490,10 +489,11 @@ func TestBasicIndexing(t *testing.T) { }, { Query: "insert into test values (16, 3, 23, 33);", - ExpectedErr: "Duplicate entry '3-23' for key 'v1_idx'", + ExpectedErr: "duplicate unique key given", }, }, - }, { + }, + { Name: "Keyless Index", SetUpScript: []string{ "CREATE TABLE test (v0 BIGINT, v1 BIGINT, v2 BIGINT);", @@ -540,13 +540,30 @@ func TestBasicIndexing(t *testing.T) { }, }, { - Name: "keyless unique index", + Name: "Unique Keyless Index", SetUpScript: []string{ - "CREATE TABLE aTable (aColumn INT NULL, bColumn INT NULL, primary key (aColumn));", + "CREATE TABLE test (v0 BIGINT, v1 BIGINT, v2 BIGINT);", + "INSERT INTO test VALUES (13, 3, 23), (11, 1, 21), (15, 5, 25), (12, 2, 22), (14, 4, 24);", + "CREATE UNIQUE INDEX v1_idx ON test(v1);", }, Assertions: []ScriptTestAssertion{ { - Query: "CREATE UNIQUE INDEX aIndex ON aTable (bColumn);", + Query: "SELECT * FROM test WHERE v1 = 2 ORDER BY v0;", + Expected: []sql.Row{ + {12, 2, 22}, + }, + }, + { + Query: "SELECT * FROM test WHERE v1 > 2 ORDER BY v0;", + Expected: []sql.Row{ + {13, 3, 23}, + {14, 4, 24}, + {15, 5, 25}, + }, + }, + { + Query: "INSERT INTO test VALUES (16, 3, 23);", + ExpectedErr: "duplicate unique key given", }, }, }, @@ -649,7 +666,7 @@ func TestBasicIndexing(t *testing.T) { }, { Query: "insert into test values (16, 3, 23, 33);", - ExpectedErr: "Duplicate entry '3-23' for key 'v1_idx'", + ExpectedErr: "duplicate unique key given", }, }, }, From e19ae27577b78b8d8c0ae7c5964fc0b57b835ae9 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Mon, 23 Sep 2024 14:01:40 -0700 Subject: [PATCH 3/3] New dolt --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 6571b4f943..0bb33194ca 100644 --- a/go.mod +++ b/go.mod @@ -8,11 +8,11 @@ require ( github.com/PuerkitoBio/goquery v1.8.1 github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a github.com/cockroachdb/errors v1.7.5 - github.com/dolthub/dolt/go v0.40.5-0.20240919183209-28badac50053 + github.com/dolthub/dolt/go v0.40.5-0.20240923204958-bf8d3e8f4d04 github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 - github.com/dolthub/go-mysql-server v0.18.2-0.20240920224603-6f1a8518b048 + github.com/dolthub/go-mysql-server v0.18.2-0.20240923181307-5aacdb13e45a github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 github.com/dolthub/vitess v0.0.0-20240919225659-2ad81685e772 github.com/fatih/color v1.13.0 diff --git a/go.sum b/go.sum index 8374508b2f..49d90c1f41 100644 --- a/go.sum +++ b/go.sum @@ -214,8 +214,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/dolthub/dolt/go v0.40.5-0.20240919183209-28badac50053 h1:R0nHYkk/1a6BuDwcrGVhtJANqFmKmAfMGK0cUwo1/P0= -github.com/dolthub/dolt/go v0.40.5-0.20240919183209-28badac50053/go.mod h1:OkulohTdSGOFzq3YR3NxVxYLU4Z2GLUaYL8fb/f8cho= +github.com/dolthub/dolt/go v0.40.5-0.20240923204958-bf8d3e8f4d04 h1:snHOMQJOieEXdAOOM8icGhwp4p5IPLYPKyVKYZiPkQc= +github.com/dolthub/dolt/go v0.40.5-0.20240923204958-bf8d3e8f4d04/go.mod h1:1HBB+xUaDISZ6GrUmiiD//Ij5wExAAV1nPDpU4xPrmg= github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d h1:RZkQeYOrDrOWzCxaP2ttkvg4E2TM9n8lnEsIBLKjqkM= github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY= github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww= @@ -224,8 +224,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U= github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0= github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 h1:aC17hZD6iwzBwwfO5M+3oBT5E5gGRiQPdn+vzpDXqIA= github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168= -github.com/dolthub/go-mysql-server v0.18.2-0.20240920224603-6f1a8518b048 h1:cYdcm/bKRAupP51QfcWhelgDBNg1r36OKlAf7+meU4E= -github.com/dolthub/go-mysql-server v0.18.2-0.20240920224603-6f1a8518b048/go.mod h1:lGbU2bK+QNnlETdUjOOaE+UnlEUu31VaQOFKAFGyZN4= +github.com/dolthub/go-mysql-server v0.18.2-0.20240923181307-5aacdb13e45a h1:rpCmZj332eiBbzsHsq3Sj5AWzl3Q7szDObwI49UqA8Y= +github.com/dolthub/go-mysql-server v0.18.2-0.20240923181307-5aacdb13e45a/go.mod h1:lGbU2bK+QNnlETdUjOOaE+UnlEUu31VaQOFKAFGyZN4= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q= github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=