Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman committed Feb 11, 2025
1 parent 40cdce0 commit d040cfa
Show file tree
Hide file tree
Showing 22 changed files with 252 additions and 413 deletions.
9 changes: 5 additions & 4 deletions go/cmd/dolt/commands/engine/sqlengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ package engine

import (
"context"
"os"
"strconv"
"strings"
"time"

gms "github.com/dolthub/go-mysql-server"
"github.com/dolthub/go-mysql-server/eventscheduler"
"github.com/dolthub/go-mysql-server/sql"
Expand All @@ -26,10 +31,6 @@ import (
_ "github.com/dolthub/go-mysql-server/sql/variables"
"github.com/dolthub/vitess/go/vt/sqlparser"
"github.com/sirupsen/logrus"
"os"
"strconv"
"strings"
"time"

"github.com/dolthub/dolt/go/cmd/dolt/cli"
"github.com/dolthub/dolt/go/libraries/doltcore/branch_control"
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/dolt/commands/sqlserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"crypto/tls"
"errors"
"fmt"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/statspro"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -56,6 +55,7 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/cluster"
_ "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/statspro"
"github.com/dolthub/dolt/go/libraries/doltcore/sqlserver"
"github.com/dolthub/dolt/go/libraries/events"
"github.com/dolthub/dolt/go/libraries/utils/config"
Expand Down
3 changes: 2 additions & 1 deletion go/libraries/doltcore/sqle/dprocedures/stats_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"

"github.com/dolthub/go-mysql-server/sql"
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
"strconv"

"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
)
Expand Down
7 changes: 1 addition & 6 deletions go/libraries/doltcore/sqle/enginetest/dolt_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package enginetest
import (
"context"
"fmt"
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
"os"
"runtime"
"sync"
Expand All @@ -35,6 +34,7 @@ import (

"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/statspro"
Expand Down Expand Up @@ -1453,11 +1453,6 @@ func TestStatBranchTests(t *testing.T) {
RunStatBranchTests(t, harness)
}

func TestStatsFunctions(t *testing.T) {
harness := newDoltEnginetestHarness(t)
RunStatsFunctionsTest(t, harness)
}

func TestDiffTableFunction(t *testing.T) {
harness := newDoltEnginetestHarness(t)
RunDiffTableFunctionTests(t, harness)
Expand Down
15 changes: 0 additions & 15 deletions go/libraries/doltcore/sqle/enginetest/dolt_engine_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1164,21 +1164,6 @@ func mustNewEngine(t *testing.T, h enginetest.Harness) enginetest.QueryEngine {
return e
}

func RunStatsFunctionsTest(t *testing.T, harness DoltEnginetestHarness) {
defer harness.Close()
for _, test := range StatProcTests {
t.Run(test.Name, func(t *testing.T) {
// reset engine so provider statistics are clean
harness = harness.NewHarness(t).WithConfigureStats(true)
harness.Setup(setup.MydbData)
harness.SkipSetupCommit()
e := mustNewEngine(t, harness)
defer e.Close()
enginetest.TestScriptWithEngine(t, e, harness, test)
})
}
}

func RunDiffTableFunctionTests(t *testing.T, harness DoltEnginetestHarness) {
for _, test := range DiffTableFunctionScriptTests {
t.Run(test.Name, func(t *testing.T) {
Expand Down
26 changes: 14 additions & 12 deletions go/libraries/doltcore/sqle/enginetest/dolt_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ package enginetest
import (
"context"
"fmt"
"runtime"
"strings"
"testing"
"time"

gms "github.com/dolthub/go-mysql-server"
"github.com/dolthub/go-mysql-server/enginetest"
"github.com/dolthub/go-mysql-server/enginetest/scriptgen/setup"
"github.com/dolthub/go-mysql-server/memory"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/mysql_db"
"github.com/dolthub/go-mysql-server/sql/rowexec"
"github.com/stretchr/testify/require"

"github.com/dolthub/dolt/go/libraries/doltcore/branch_control"
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
Expand All @@ -28,18 +42,6 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/writer"
"github.com/dolthub/dolt/go/libraries/utils/filesys"
"github.com/dolthub/dolt/go/store/types"
gms "github.com/dolthub/go-mysql-server"
"github.com/dolthub/go-mysql-server/enginetest"
"github.com/dolthub/go-mysql-server/enginetest/scriptgen/setup"
"github.com/dolthub/go-mysql-server/memory"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/mysql_db"
"github.com/dolthub/go-mysql-server/sql/rowexec"
"github.com/stretchr/testify/require"
"runtime"
"strings"
"testing"
"time"
)

type DoltHarness struct {
Expand Down
219 changes: 4 additions & 215 deletions go/libraries/doltcore/sqle/enginetest/stats_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ package enginetest

import (
"fmt"
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
"strings"

"github.com/dolthub/go-mysql-server/enginetest/queries"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/types"
"strings"

"github.com/dolthub/dolt/go/libraries/doltcore/schema"
)

// fillerVarchar pushes the tree into level 3
Expand Down Expand Up @@ -588,8 +590,6 @@ var StatBranchTests = []queries.ScriptTest{
{
Name: "multi branch stats",
SetUpScript: []string{
"set @@PERSIST.dolt_stats_auto_refresh_interval = 0;",
"set @@PERSIST.dolt_stats_auto_refresh_threshold = 0;",
"set @@PERSIST.dolt_stats_branches = 'main,feat';",
"CREATE table xy (x bigint primary key, y int, z varchar(500), key(y,z));",
"insert into xy values (0,0,'a'), (1,0,'a'), (2,0,'a'), (3,0,'a'), (4,1,'a'), (5,2,'a')",
Expand Down Expand Up @@ -701,214 +701,3 @@ var StatBranchTests = []queries.ScriptTest{
},
},
}

var StatProcTests = []queries.ScriptTest{
{
Name: "deleting stats removes information_schema access point",
SetUpScript: []string{
"CREATE table xy (x bigint primary key, y int, z varchar(500), key(y,z));",
"insert into xy values (0,0,0)",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "analyze table xy",
},
{
Query: "select count(*) from information_schema.column_statistics",
Expected: []sql.Row{{2}},
},
{
Query: "call dolt_stats_drop()",
},
{
Query: "select count(*) from information_schema.column_statistics",
Expected: []sql.Row{{0}},
},
},
},
{
Name: "restart empty stats panic",
SetUpScript: []string{
"CREATE table xy (x bigint primary key, y int, z varchar(500), key(y,z));",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "analyze table xy",
},
{
Query: "select count(*) from dolt_statistics",
Expected: []sql.Row{{0}},
},
{
Query: "set @@GLOBAL.dolt_stats_auto_refresh_threshold = 0",
Expected: []sql.Row{{}},
},
{
Query: "set @@GLOBAL.dolt_stats_auto_refresh_interval = 0",
Expected: []sql.Row{{}},
},
{
// don't panic
Query: "call dolt_stats_restart()",
},
{
Query: "select sleep(.1)",
},
{
Query: "insert into xy values (0,0,0)",
},
{
Query: "select sleep(.1)",
},
{
Query: "select count(*) from dolt_statistics",
Expected: []sql.Row{{2}},
},
},
},
{
Name: "basic start, status, stop loop",
SetUpScript: []string{
"CREATE table xy (x bigint primary key, y int, z varchar(500), key(y,z));",
"insert into xy values (0,0,'a'), (2,0,'a'), (4,1,'a'), (6,2,'a')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "select count(*) from dolt_statistics",
Expected: []sql.Row{{0}},
},
{
Query: "call dolt_stats_status()",
Expected: []sql.Row{{"no active stats thread"}},
},
// set refresh interval arbitrarily high to avoid updating when we restart
{
Query: "set @@PERSIST.dolt_stats_auto_refresh_interval = 100000;",
Expected: []sql.Row{{}},
},
{
Query: "set @@PERSIST.dolt_stats_auto_refresh_threshold = 0",
Expected: []sql.Row{{}},
},
{
Query: "call dolt_stats_restart()",
},
{
Query: "call dolt_stats_status()",
Expected: []sql.Row{{"restarted thread: mydb"}},
},
{
Query: "set @@PERSIST.dolt_stats_auto_refresh_interval = 0;",
Expected: []sql.Row{{}},
},
// new restart picks up 0-interval, will start refreshing immediately
{
Query: "call dolt_stats_restart()",
},
{
Query: "select sleep(.1)",
},
{
Query: "call dolt_stats_status()",
Expected: []sql.Row{{"refreshed mydb"}},
},
{
Query: "select count(*) from dolt_statistics",
Expected: []sql.Row{{2}},
},
// kill refresh thread
{
Query: "call dolt_stats_stop()",
},
{
Query: "call dolt_stats_status()",
Expected: []sql.Row{{"cancelled thread: mydb"}},
},
// insert without refresh thread will not update stats
{
Query: "insert into xy values (1,0,'a'), (3,0,'a'), (5,2,'a'), (7,1,'a')",
},
{
Query: "select sleep(.1)",
},
{
Query: "call dolt_stats_status()",
Expected: []sql.Row{{"cancelled thread: mydb"}},
},
// manual analyze will update stats
{
Query: "analyze table xy",
Expected: []sql.Row{{"xy", "analyze", "status", "OK"}},
},
{
Query: "call dolt_stats_status()",
Expected: []sql.Row{{"refreshed mydb"}},
},
{
Query: "select count(*) from dolt_statistics",
Expected: []sql.Row{{2}},
},
// kill refresh thread and delete stats ref
{
Query: "call dolt_stats_drop()",
},
{
Query: "call dolt_stats_status()",
Expected: []sql.Row{{"dropped"}},
},
{
Query: "select count(*) from dolt_statistics",
Expected: []sql.Row{{0}},
},
},
},
{
Name: "test purge",
SetUpScript: []string{
"set @@PERSIST.dolt_stats_auto_refresh_enabled = 0;",
"CREATE table xy (x bigint primary key, y int, z varchar(500), key(y,z));",
"insert into xy values (1, 1, 'a'), (2,1,'a'), (3,1,'a'), (4,2,'b'), (5,2,'b'), (6,3,'c');",
"analyze table xy",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "select count(*) as cnt from dolt_statistics group by table_name, index_name order by cnt",
Expected: []sql.Row{{1}, {1}},
},
{
Query: "call dolt_stats_purge()",
},
{
Query: "select count(*) from dolt_statistics;",
Expected: []sql.Row{{0}},
},
},
},
{
Name: "test prune",
SetUpScript: []string{
"set @@PERSIST.dolt_stats_auto_refresh_enabled = 0;",
"CREATE table xy (x bigint primary key, y int, z varchar(500), key(y,z));",
"insert into xy values (1, 1, 'a'), (2,1,'a'), (3,1,'a'), (4,2,'b'), (5,2,'b'), (6,3,'c');",
"analyze table xy",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "select count(*) as cnt from dolt_statistics group by table_name, index_name order by cnt",
Expected: []sql.Row{{1}, {1}},
},
{
Query: "call dolt_stats_prune()",
},
{
Query: "select count(*) from dolt_statistics;",
Expected: []sql.Row{{2}},
},
},
},
}

func mustNewStatQual(s string) sql.StatQualifier {
qual, _ := sql.NewQualifierFromString(s)
return qual
}
3 changes: 2 additions & 1 deletion go/libraries/doltcore/sqle/statspro/bucket_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package statspro
import (
"container/heap"
"context"
"sort"

"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/stats"
"sort"

"github.com/dolthub/dolt/go/store/prolly"
"github.com/dolthub/dolt/go/store/prolly/tree"
Expand Down
Loading

0 comments on commit d040cfa

Please sign in to comment.