Skip to content

Commit fe3d154

Browse files
committed
Add tests for dolt_statistics
1 parent 9407941 commit fe3d154

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

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)