Skip to content

Commit 8f98c06

Browse files
authored
Merge pull request #1004 from dolthub/taylor/stats
Add tests for dolt_statistics
2 parents 9407941 + 24916bd commit 8f98c06

File tree

3 files changed

+132
-9
lines changed

3 files changed

+132
-9
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ require (
88
github.com/PuerkitoBio/goquery v1.8.1
99
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
1010
github.com/cockroachdb/errors v1.7.5
11-
github.com/dolthub/dolt/go v0.40.5-0.20241122201136-4ad19572a805
11+
github.com/dolthub/dolt/go v0.40.5-0.20241127004648-970994aac2fc
1212
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d
1313
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
1414
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662
15-
github.com/dolthub/go-mysql-server v0.18.2-0.20241122190136-dd8defd838e3
15+
github.com/dolthub/go-mysql-server v0.18.2-0.20241127000145-a1809677932e
1616
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
17-
github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0
17+
github.com/dolthub/vitess v0.0.0-20241126223332-cd8f828f26ac
1818
github.com/fatih/color v1.13.0
1919
github.com/goccy/go-json v0.10.2
2020
github.com/gogo/protobuf v1.3.2

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
214214
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
215215
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
216216
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
217-
github.com/dolthub/dolt/go v0.40.5-0.20241122201136-4ad19572a805 h1:89YAwmuEQ6B9tsQp6UAAKUSVrDD+w3GedW7V14d3RuU=
218-
github.com/dolthub/dolt/go v0.40.5-0.20241122201136-4ad19572a805/go.mod h1:ImVR1GtrJTVzmsnsJoDaZpLiVdLR+xXar7F2dur5oE8=
217+
github.com/dolthub/dolt/go v0.40.5-0.20241127004648-970994aac2fc h1:UAK+aIF4b1iWajiGttUusQAjLMQNHqAPpqG8eiG8BoU=
218+
github.com/dolthub/dolt/go v0.40.5-0.20241127004648-970994aac2fc/go.mod h1:P91iOmdLxfcAPaeUIEmmd1ghJnVr09QLC+CbFbSeMSw=
219219
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d h1:gO9+wrmNHXukPNCO1tpfCcXIdMlW/qppbUStfLvqz/U=
220220
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY=
221221
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=
224224
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
225225
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 h1:aC17hZD6iwzBwwfO5M+3oBT5E5gGRiQPdn+vzpDXqIA=
226226
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
227-
github.com/dolthub/go-mysql-server v0.18.2-0.20241122190136-dd8defd838e3 h1:bvSE64pO6euDX8j5hpml5qVVz9OXG3hVV9532bn+eZ0=
228-
github.com/dolthub/go-mysql-server v0.18.2-0.20241122190136-dd8defd838e3/go.mod h1:2mA/v84EOCe8TQIKR8TN8ZRIQSbOqThGQHyevGRmawU=
227+
github.com/dolthub/go-mysql-server v0.18.2-0.20241127000145-a1809677932e h1:2oysRPgywCpyW/h4m6DxYUpUsdZ+JkJXvC51TVr4sUE=
228+
github.com/dolthub/go-mysql-server v0.18.2-0.20241127000145-a1809677932e/go.mod h1:QdaXQKE8XFwM4P1yN14m2eydx4V2xyuqpQp4tmNoXzQ=
229229
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
230230
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
231231
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
@@ -238,8 +238,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4
238238
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
239239
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
240240
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
241-
github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0 h1:C8X4RkkWKcrJG6rG+MsdFINX2PhB7ObpbBvFcWsI8K8=
242-
github.com/dolthub/vitess v0.0.0-20241121221517-3e7b5ffc22b0/go.mod h1:alcJgfdyIhFaAiYyEmuDCFSLCzedz3KCaIclLoCUtJg=
241+
github.com/dolthub/vitess v0.0.0-20241126223332-cd8f828f26ac h1:A0U/OdIqdCkAV0by7MVBbnSyZBsa94ZjIZxx7PhjBW4=
242+
github.com/dolthub/vitess v0.0.0-20241126223332-cd8f828f26ac/go.mod h1:alcJgfdyIhFaAiYyEmuDCFSLCzedz3KCaIclLoCUtJg=
243243
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
244244
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
245245
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=

testing/go/dolt_tables_test.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,129 @@ func TestUserSpaceDoltTables(t *testing.T) {
17221722
},
17231723
},
17241724
},
1725+
{
1726+
Name: "dolt statistics",
1727+
SetUpScript: []string{
1728+
"CREATE TABLE horses (id int primary key, name varchar(10));",
1729+
"CREATE INDEX horses_name_idx ON horses(name);",
1730+
"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;",
1731+
},
1732+
Assertions: []ScriptTestAssertion{
1733+
{
1734+
Query: `ANALYZE horses;`,
1735+
Expected: []sql.Row{},
1736+
},
1737+
{
1738+
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`,
1739+
Expected: []sql.Row{
1740+
{"postgres", "horses", "horses_name_idx", 306, 1, "name", "Steve", 306},
1741+
{"postgres", "horses", "horses_name_idx", 167, 1, "name", "Steve", 167},
1742+
{"postgres", "horses", "horses_name_idx", 197, 1, "name", "Steve", 197},
1743+
{"postgres", "horses", "horses_name_idx", 320, 1, "name", "Steve", 320},
1744+
{"postgres", "horses", "horses_name_idx", 10, 1, "name", "Steve", 10},
1745+
{"postgres", "horses", "primary", 347, 347, "id", "347", 1},
1746+
{"postgres", "horses", "primary", 404, 404, "id", "751", 1},
1747+
{"postgres", "horses", "primary", 203, 203, "id", "954", 1},
1748+
{"postgres", "horses", "primary", 46, 46, "id", "1000", 1},
1749+
},
1750+
},
1751+
{
1752+
Query: `SELECT count(*) FROM dolt_statistics`,
1753+
Expected: []sql.Row{{9}},
1754+
},
1755+
{
1756+
Query: `SELECT count(*) FROM public.dolt_statistics`,
1757+
Expected: []sql.Row{{9}},
1758+
},
1759+
{
1760+
Query: `SELECT dolt_statistics.index_name FROM public.dolt_statistics GROUP BY index_name ORDER BY index_name`,
1761+
Expected: []sql.Row{{"horses_name_idx"}, {"primary"}},
1762+
},
1763+
{
1764+
Query: `SELECT name FROM other.dolt_statistics`,
1765+
ExpectedErr: "database schema not found",
1766+
},
1767+
{
1768+
Query: `CREATE SCHEMA newschema`,
1769+
Expected: []sql.Row{},
1770+
},
1771+
{
1772+
Query: "SET search_path = 'newschema'",
1773+
Expected: []sql.Row{},
1774+
},
1775+
{
1776+
Query: `SELECT count(*) FROM dolt_statistics`,
1777+
Expected: []sql.Row{{0}},
1778+
},
1779+
{
1780+
Query: "CREATE TABLE horses2 (id int primary key, name varchar(10));",
1781+
Expected: []sql.Row{},
1782+
},
1783+
{
1784+
Query: "CREATE INDEX horses2_name_idx ON horses2(name);",
1785+
Expected: []sql.Row{},
1786+
},
1787+
{
1788+
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;",
1789+
Expected: []sql.Row{},
1790+
},
1791+
{
1792+
Query: `ANALYZE horses2;`,
1793+
Expected: []sql.Row{},
1794+
},
1795+
{
1796+
Query: `SELECT dolt_statistics.index_name FROM dolt_statistics GROUP BY index_name ORDER BY index_name`,
1797+
Expected: []sql.Row{{"horses2_name_idx"}, {"primary"}},
1798+
},
1799+
{
1800+
Query: `SELECT dolt_statistics.index_name FROM newschema.dolt_statistics GROUP BY index_name ORDER BY index_name`,
1801+
Expected: []sql.Row{{"horses2_name_idx"}, {"primary"}},
1802+
},
1803+
{
1804+
Query: `SELECT dolt_statistics.index_name FROM public.dolt_statistics GROUP BY index_name ORDER BY index_name`,
1805+
Expected: []sql.Row{{"horses_name_idx"}, {"primary"}},
1806+
},
1807+
// Same table name, different schema
1808+
{
1809+
Query: "CREATE TABLE horses (id int primary key, name varchar(10));",
1810+
Expected: []sql.Row{},
1811+
},
1812+
{
1813+
Query: "CREATE INDEX horses3_name_idx ON horses(name);",
1814+
Expected: []sql.Row{},
1815+
},
1816+
{
1817+
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;",
1818+
Expected: []sql.Row{},
1819+
},
1820+
{
1821+
Query: `ANALYZE horses;`,
1822+
Expected: []sql.Row{},
1823+
},
1824+
{
1825+
Query: `SELECT table_name, index_name FROM dolt_statistics GROUP BY table_name, index_name ORDER BY table_name, index_name`,
1826+
Expected: []sql.Row{
1827+
{"horses", "horses3_name_idx"},
1828+
{"horses", "primary"},
1829+
{"horses2", "horses2_name_idx"},
1830+
{"horses2", "primary"},
1831+
},
1832+
},
1833+
{
1834+
Query: `SELECT table_name, index_name FROM newschema.dolt_statistics GROUP BY table_name, index_name ORDER BY table_name, index_name`,
1835+
Expected: []sql.Row{
1836+
{"horses", "horses3_name_idx"},
1837+
{"horses", "primary"},
1838+
{"horses2", "horses2_name_idx"},
1839+
{"horses2", "primary"},
1840+
},
1841+
},
1842+
{
1843+
Query: `SELECT table_name, index_name FROM public.dolt_statistics GROUP BY index_name ORDER BY index_name`,
1844+
Expected: []sql.Row{{"horses", "horses_name_idx"}, {"horses", "primary"}},
1845+
},
1846+
},
1847+
},
17251848
{
17261849
Name: "dolt tags",
17271850
SetUpScript: []string{

0 commit comments

Comments
 (0)