Skip to content

Commit

Permalink
Add tests for dolt_statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed Nov 23, 2024
1 parent 3853635 commit 0ae2ff0
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions testing/go/dolt_tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,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 0ae2ff0

Please sign in to comment.