Skip to content

Commit

Permalink
Merge pull request #1004 from dolthub/taylor/stats
Browse files Browse the repository at this point in the history
Add tests for dolt_statistics
  • Loading branch information
tbantle22 authored Nov 27, 2024
2 parents 9407941 + 24916bd commit 8f98c06
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 9 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ 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.20241122201136-4ad19572a805
github.com/dolthub/dolt/go v0.40.5-0.20241127004648-970994aac2fc
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d
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.20241122190136-dd8defd838e3
github.com/dolthub/go-mysql-server v0.18.2-0.20241127000145-a1809677932e
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0
github.com/dolthub/vitess v0.0.0-20241126223332-cd8f828f26ac
github.com/fatih/color v1.13.0
github.com/goccy/go-json v0.10.2
github.com/gogo/protobuf v1.3.2
Expand Down
12 changes: 6 additions & 6 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.20241122201136-4ad19572a805 h1:89YAwmuEQ6B9tsQp6UAAKUSVrDD+w3GedW7V14d3RuU=
github.com/dolthub/dolt/go v0.40.5-0.20241122201136-4ad19572a805/go.mod h1:ImVR1GtrJTVzmsnsJoDaZpLiVdLR+xXar7F2dur5oE8=
github.com/dolthub/dolt/go v0.40.5-0.20241127004648-970994aac2fc h1:UAK+aIF4b1iWajiGttUusQAjLMQNHqAPpqG8eiG8BoU=
github.com/dolthub/dolt/go v0.40.5-0.20241127004648-970994aac2fc/go.mod h1:P91iOmdLxfcAPaeUIEmmd1ghJnVr09QLC+CbFbSeMSw=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d h1:gO9+wrmNHXukPNCO1tpfCcXIdMlW/qppbUStfLvqz/U=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d/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.20241122190136-dd8defd838e3 h1:bvSE64pO6euDX8j5hpml5qVVz9OXG3hVV9532bn+eZ0=
github.com/dolthub/go-mysql-server v0.18.2-0.20241122190136-dd8defd838e3/go.mod h1:2mA/v84EOCe8TQIKR8TN8ZRIQSbOqThGQHyevGRmawU=
github.com/dolthub/go-mysql-server v0.18.2-0.20241127000145-a1809677932e h1:2oysRPgywCpyW/h4m6DxYUpUsdZ+JkJXvC51TVr4sUE=
github.com/dolthub/go-mysql-server v0.18.2-0.20241127000145-a1809677932e/go.mod h1:QdaXQKE8XFwM4P1yN14m2eydx4V2xyuqpQp4tmNoXzQ=
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 All @@ -238,8 +238,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0 h1:C8X4RkkWKcrJG6rG+MsdFINX2PhB7ObpbBvFcWsI8K8=
github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0/go.mod h1:alcJgfdyIhFaAiYyEmuDCFSLCzedz3KCaIclLoCUtJg=
github.com/dolthub/vitess v0.0.0-20241126223332-cd8f828f26ac h1:A0U/OdIqdCkAV0by7MVBbnSyZBsa94ZjIZxx7PhjBW4=
github.com/dolthub/vitess v0.0.0-20241126223332-cd8f828f26ac/go.mod h1:alcJgfdyIhFaAiYyEmuDCFSLCzedz3KCaIclLoCUtJg=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down
123 changes: 123 additions & 0 deletions testing/go/dolt_tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,129 @@ func TestUserSpaceDoltTables(t *testing.T) {
},
},
},
{
Name: "dolt statistics",
SetUpScript: []string{
"CREATE TABLE horses (id int primary key, name varchar(10));",
"CREATE INDEX horses_name_idx ON horses(name);",
"insert into horses select x, 'Steve' from (with recursive inputs(x) as (select 1 union select x+1 from inputs where x < 1000) select * from inputs) dt;",
},
Assertions: []ScriptTestAssertion{
{
Query: `ANALYZE horses;`,
Expected: []sql.Row{},
},
{
Query: `SELECT database_name, table_name, index_name, row_count, distinct_count, columns, upper_bound, upper_bound_cnt FROM dolt_statistics ORDER BY index_name`,
Expected: []sql.Row{
{"postgres", "horses", "horses_name_idx", 306, 1, "name", "Steve", 306},
{"postgres", "horses", "horses_name_idx", 167, 1, "name", "Steve", 167},
{"postgres", "horses", "horses_name_idx", 197, 1, "name", "Steve", 197},
{"postgres", "horses", "horses_name_idx", 320, 1, "name", "Steve", 320},
{"postgres", "horses", "horses_name_idx", 10, 1, "name", "Steve", 10},
{"postgres", "horses", "primary", 347, 347, "id", "347", 1},
{"postgres", "horses", "primary", 404, 404, "id", "751", 1},
{"postgres", "horses", "primary", 203, 203, "id", "954", 1},
{"postgres", "horses", "primary", 46, 46, "id", "1000", 1},
},
},
{
Query: `SELECT count(*) FROM dolt_statistics`,
Expected: []sql.Row{{9}},
},
{
Query: `SELECT count(*) FROM public.dolt_statistics`,
Expected: []sql.Row{{9}},
},
{
Query: `SELECT dolt_statistics.index_name FROM public.dolt_statistics GROUP BY index_name ORDER BY index_name`,
Expected: []sql.Row{{"horses_name_idx"}, {"primary"}},
},
{
Query: `SELECT name FROM other.dolt_statistics`,
ExpectedErr: "database schema not found",
},
{
Query: `CREATE SCHEMA newschema`,
Expected: []sql.Row{},
},
{
Query: "SET search_path = 'newschema'",
Expected: []sql.Row{},
},
{
Query: `SELECT count(*) FROM dolt_statistics`,
Expected: []sql.Row{{0}},
},
{
Query: "CREATE TABLE horses2 (id int primary key, name varchar(10));",
Expected: []sql.Row{},
},
{
Query: "CREATE INDEX horses2_name_idx ON horses2(name);",
Expected: []sql.Row{},
},
{
Query: "insert into horses2 select x, 'Steve' from (with recursive inputs(x) as (select 1 union select x+1 from inputs where x < 1000) select * from inputs) dt;",
Expected: []sql.Row{},
},
{
Query: `ANALYZE horses2;`,
Expected: []sql.Row{},
},
{
Query: `SELECT dolt_statistics.index_name FROM dolt_statistics GROUP BY index_name ORDER BY index_name`,
Expected: []sql.Row{{"horses2_name_idx"}, {"primary"}},
},
{
Query: `SELECT dolt_statistics.index_name FROM newschema.dolt_statistics GROUP BY index_name ORDER BY index_name`,
Expected: []sql.Row{{"horses2_name_idx"}, {"primary"}},
},
{
Query: `SELECT dolt_statistics.index_name FROM public.dolt_statistics GROUP BY index_name ORDER BY index_name`,
Expected: []sql.Row{{"horses_name_idx"}, {"primary"}},
},
// Same table name, different schema
{
Query: "CREATE TABLE horses (id int primary key, name varchar(10));",
Expected: []sql.Row{},
},
{
Query: "CREATE INDEX horses3_name_idx ON horses(name);",
Expected: []sql.Row{},
},
{
Query: "insert into horses select x, 'Steve' from (with recursive inputs(x) as (select 1 union select x+1 from inputs where x < 1000) select * from inputs) dt;",
Expected: []sql.Row{},
},
{
Query: `ANALYZE horses;`,
Expected: []sql.Row{},
},
{
Query: `SELECT table_name, index_name FROM dolt_statistics GROUP BY table_name, index_name ORDER BY table_name, index_name`,
Expected: []sql.Row{
{"horses", "horses3_name_idx"},
{"horses", "primary"},
{"horses2", "horses2_name_idx"},
{"horses2", "primary"},
},
},
{
Query: `SELECT table_name, index_name FROM newschema.dolt_statistics GROUP BY table_name, index_name ORDER BY table_name, index_name`,
Expected: []sql.Row{
{"horses", "horses3_name_idx"},
{"horses", "primary"},
{"horses2", "horses2_name_idx"},
{"horses2", "primary"},
},
},
{
Query: `SELECT table_name, index_name FROM public.dolt_statistics GROUP BY index_name ORDER BY index_name`,
Expected: []sql.Row{{"horses", "horses_name_idx"}, {"horses", "primary"}},
},
},
},
{
Name: "dolt tags",
SetUpScript: []string{
Expand Down

0 comments on commit 8f98c06

Please sign in to comment.