Skip to content

Commit 8aea741

Browse files
committed
Add tests for dolt_statistics
1 parent 3853635 commit 8aea741

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

testing/go/dolt_tables_test.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,132 @@ func TestUserSpaceDoltTables(t *testing.T) {
15761576
},
15771577
},
15781578
},
1579+
{
1580+
Name: "dolt statistics",
1581+
SetUpScript: []string{
1582+
"CREATE TABLE horses (id int primary key, name varchar(10));",
1583+
"CREATE INDEX horses_name_idx ON horses(name);",
1584+
"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;",
1585+
},
1586+
Assertions: []ScriptTestAssertion{
1587+
{
1588+
Query: `ANALYZE horses;`,
1589+
Expected: []sql.Row{},
1590+
},
1591+
{
1592+
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`,
1593+
Expected: []sql.Row{
1594+
{"postgres", "horses", "horses_name_idx", 306, 1, "name", "Steve", 306},
1595+
{"postgres", "horses", "horses_name_idx", 167, 1, "name", "Steve", 167},
1596+
{"postgres", "horses", "horses_name_idx", 197, 1, "name", "Steve", 197},
1597+
{"postgres", "horses", "horses_name_idx", 320, 1, "name", "Steve", 320},
1598+
{"postgres", "horses", "horses_name_idx", 10, 1, "name", "Steve", 10},
1599+
{"postgres", "horses", "primary", 347, 347, "id", "347", 1},
1600+
{"postgres", "horses", "primary", 404, 404, "id", "751", 1},
1601+
{"postgres", "horses", "primary", 203, 203, "id", "954", 1},
1602+
{"postgres", "horses", "primary", 46, 46, "id", "1000", 1},
1603+
},
1604+
},
1605+
{
1606+
Query: `SELECT count(*) FROM dolt_statistics`,
1607+
Expected: []sql.Row{{9}},
1608+
},
1609+
{
1610+
Query: `SELECT count(*) FROM public.dolt_statistics`,
1611+
Expected: []sql.Row{{9}},
1612+
},
1613+
{
1614+
Query: `SELECT dolt_statistics.index_name FROM public.dolt_statistics GROUP BY index_name ORDER BY index_name`,
1615+
Expected: []sql.Row{{"horses_name_idx"}, {"primary"}},
1616+
},
1617+
{
1618+
Query: `SELECT name FROM other.dolt_statistics`,
1619+
ExpectedErr: "database schema not found",
1620+
},
1621+
{
1622+
Query: `CREATE SCHEMA newschema`,
1623+
Expected: []sql.Row{},
1624+
},
1625+
{
1626+
Query: "SET search_path = 'newschema'",
1627+
Expected: []sql.Row{},
1628+
},
1629+
{
1630+
Query: `SELECT count(*) FROM dolt_statistics`,
1631+
Expected: []sql.Row{{0}},
1632+
},
1633+
{
1634+
Query: "CREATE TABLE horses2 (id int primary key, name varchar(10));",
1635+
Expected: []sql.Row{},
1636+
},
1637+
{
1638+
Query: "CREATE INDEX horses2_name_idx ON horses2(name);",
1639+
Expected: []sql.Row{},
1640+
},
1641+
{
1642+
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;",
1643+
Expected: []sql.Row{},
1644+
},
1645+
{
1646+
Query: `ANALYZE horses2;`,
1647+
Expected: []sql.Row{},
1648+
},
1649+
{
1650+
Query: `SELECT dolt_statistics.index_name FROM dolt_statistics GROUP BY index_name ORDER BY index_name`,
1651+
Expected: []sql.Row{{"horses2_name_idx"}, {"primary"}},
1652+
},
1653+
{
1654+
Query: `SELECT dolt_statistics.index_name FROM newschema.dolt_statistics GROUP BY index_name ORDER BY index_name`,
1655+
Expected: []sql.Row{{"horses2_name_idx"}, {"primary"}},
1656+
},
1657+
{
1658+
Query: `SELECT dolt_statistics.index_name FROM public.dolt_statistics GROUP BY index_name ORDER BY index_name`,
1659+
Expected: []sql.Row{{"horses_name_idx"}, {"primary"}},
1660+
},
1661+
// Same table name, different schema
1662+
{
1663+
Query: "CREATE TABLE horses (id int primary key, name varchar(10));",
1664+
Expected: []sql.Row{},
1665+
},
1666+
{
1667+
Query: "CREATE INDEX horses3_name_idx ON horses(name);",
1668+
Expected: []sql.Row{},
1669+
},
1670+
{
1671+
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;",
1672+
Expected: []sql.Row{},
1673+
},
1674+
{
1675+
Query: `ANALYZE horses;`,
1676+
Expected: []sql.Row{},
1677+
},
1678+
{
1679+
Skip: true, // TODO: dolt_statistics can't distinguish tables with the same name in different schemas
1680+
Query: `SELECT table_name, index_name FROM dolt_statistics GROUP BY index_name ORDER BY index_name`,
1681+
Expected: []sql.Row{
1682+
{"horses2", "horses2_name_idx"},
1683+
{"horses", "horses3_name_idx"},
1684+
{"horses2", "primary"},
1685+
{"horses", "primary"},
1686+
},
1687+
},
1688+
{
1689+
Skip: true, // TODO: dolt_statistics can't distinguish tables with the same name in different schemas
1690+
Query: `SELECT table_name, index_name FROM newschema.dolt_statistics GROUP BY index_name ORDER BY index_name`,
1691+
Expected: []sql.Row{
1692+
{"horses2", "horses2_name_idx"},
1693+
{"horses", "horses3_name_idx"},
1694+
{"horses2", "primary"},
1695+
{"horses", "primary"},
1696+
},
1697+
},
1698+
{
1699+
Skip: true, // TODO: dolt_statistics can't distinguish tables with the same name in different schemas
1700+
Query: `SELECT table_name, index_name FROM public.dolt_statistics GROUP BY index_name ORDER BY index_name`,
1701+
Expected: []sql.Row{{"horses", "horses_name_idx"}, {"horses", "primary"}},
1702+
},
1703+
},
1704+
},
15791705
{
15801706
Name: "dolt tags",
15811707
SetUpScript: []string{

0 commit comments

Comments
 (0)