Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func runServer(ctx context.Context, cfg *servercfg.DoltgresConfig, dEnv *env.Dol

defer tempfiles.MovableTempFileProvider.Clean()

sql.SystemVariables.SetGlobal(sql.NewContext(ctx), dsess.DoltStatsEnabled, false)

err := dsess.InitPersistedSystemVars(dEnv)
if err != nil {
return nil, errors.Errorf("failed to load persisted system variables: %w", err)
Expand Down
255 changes: 128 additions & 127 deletions testing/go/dolt_tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1753,133 +1753,134 @@ 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, row_count`,
Expected: []sql.Row{
{"postgres", "horses", "horses_name_idx", 10, 1, "name", "Steve", 10},
{"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", 306, 1, "name", "Steve", 306},
{"postgres", "horses", "horses_name_idx", 320, 1, "name", "Steve", 320},
{"postgres", "horses", "primary", 46, 46, "id", "1000", 1},
{"postgres", "horses", "primary", 203, 203, "id", "954", 1},
{"postgres", "horses", "primary", 347, 347, "id", "347", 1},
{"postgres", "horses", "primary", 404, 404, "id", "751", 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{},
},
{
Skip: true, // https://github.com/dolthub/doltgresql/issues/1352
Query: `SELECT dolt_statistics.index_name FROM dolt_statistics GROUP BY index_name ORDER BY index_name`,
Expected: []sql.Row{{"horses2_name_idx"}, {"primary"}},
},
{
Skip: true, // https://github.com/dolthub/doltgresql/issues/1352
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`,
Skip: true, // TODO: seems to be flaky on CI, works locally no matter how many times it's run
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`,
Skip: true, // TODO: seems to be flaky on CI, works locally no matter how many times it's run
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"}},
},
},
},
//TODO: turn on statistics
//{
// 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, row_count`,
// Expected: []sql.Row{
// {"postgres", "horses", "horses_name_idx", 10, 1, "name", "Steve", 10},
// {"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", 306, 1, "name", "Steve", 306},
// {"postgres", "horses", "horses_name_idx", 320, 1, "name", "Steve", 320},
// {"postgres", "horses", "primary", 46, 46, "id", "1000", 1},
// {"postgres", "horses", "primary", 203, 203, "id", "954", 1},
// {"postgres", "horses", "primary", 347, 347, "id", "347", 1},
// {"postgres", "horses", "primary", 404, 404, "id", "751", 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{},
// },
// {
// Skip: true, // https://github.com/dolthub/doltgresql/issues/1352
// Query: `SELECT dolt_statistics.index_name FROM dolt_statistics GROUP BY index_name ORDER BY index_name`,
// Expected: []sql.Row{{"horses2_name_idx"}, {"primary"}},
// },
// {
// Skip: true, // https://github.com/dolthub/doltgresql/issues/1352
// 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`,
// Skip: true, // TODO: seems to be flaky on CI, works locally no matter how many times it's run
// 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`,
// Skip: true, // TODO: seems to be flaky on CI, works locally no matter how many times it's run
// 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 status",
SetUpScript: []string{
Expand Down