Skip to content

Commit

Permalink
Merge pull request #739 from dolthub/zachmu/more-testing
Browse files Browse the repository at this point in the history
Tests for unique indexes
  • Loading branch information
zachmu authored Sep 23, 2024
2 parents 8a6b33b + e19ae27 commit 2841560
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
126 changes: 126 additions & 0 deletions testing/go/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ func TestBasicIndexing(t *testing.T) {
},
},
},
{
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);",
"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 unique key given",
},
},
},
{
Name: "Covering Composite Index",
SetUpScript: []string{
Expand Down Expand Up @@ -346,6 +368,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 unique key given",
},
},
},
{
Name: "Non-Covering Composite Index",
SetUpScript: []string{
Expand Down Expand Up @@ -422,6 +466,33 @@ 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 unique key given",
},
},
},
{
Name: "Keyless Index",
SetUpScript: []string{
Expand Down Expand Up @@ -468,6 +539,34 @@ func TestBasicIndexing(t *testing.T) {
},
},
},
{
Name: "Unique Keyless Index",
SetUpScript: []string{
"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: "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",
},
},
},
{
Name: "Keyless Composite Index",
SetUpScript: []string{
Expand Down Expand Up @@ -544,6 +643,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 unique key given",
},
},
},
{
Name: "Indexed Join Covering Indexes",
SetUpScript: []string{
Expand Down

0 comments on commit 2841560

Please sign in to comment.