Skip to content

Commit

Permalink
branch qualified analyze fix
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman committed Feb 11, 2025
1 parent fe72f62 commit 1be0f49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/enginetest/dolt_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (d *DoltHarness) NewEngine(t *testing.T) (enginetest.QueryEngine, error) {
bThreads := sql.NewBackgroundThreads()

ctxGen := func(ctx context.Context) (*sql.Context, error) {
return d.NewSession(), nil
return d.NewContextWithClient(sql.Client{Address: "localhost", User: "root"}), nil
}
statsPro := statspro.NewStatsCoord(doltProvider, ctxGen, sqlCtx.Session.GetLogger().Logger, bThreads, d.multiRepoEnv.GetEnv(d.multiRepoEnv.GetFirstDatabase()))
statsPro.SetTimers(int64(1*time.Nanosecond), int64(1*time.Second), int64(1*time.Second))
Expand Down
32 changes: 2 additions & 30 deletions go/libraries/doltcore/sqle/enginetest/stats_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ var StatBranchTests = []queries.ScriptTest{
{
Name: "multi branch stats",
SetUpScript: []string{
"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')",
"call dolt_commit('-Am', 'xy')",
Expand All @@ -602,10 +601,7 @@ var StatBranchTests = []queries.ScriptTest{
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call dolt_stats_restart()",
},
{
Query: "select sleep(.1)",
Query: "call dolt_stats_sync()",
},
{
Query: "select table_name, index_name, row_count from dolt_statistics",
Expand Down Expand Up @@ -640,7 +636,7 @@ var StatBranchTests = []queries.ScriptTest{
Query: "call dolt_commit('-am', 'cm')",
},
{
Query: "select sleep(.1)",
Query: "call dolt_stats_wait()",
},
{
Query: "select table_name, index_name, row_count from dolt_statistics as of 'feat'",
Expand All @@ -658,30 +654,6 @@ var StatBranchTests = []queries.ScriptTest{
{"xy", "y", uint64(6)},
},
},
{
Query: "call dolt_checkout('feat')",
},
{
Query: "call dolt_stats_stop()",
},
{
Query: "select sleep(.1)",
},
{
Query: "call dolt_stats_drop()",
},
{
Query: "select table_name, index_name, row_count from dolt_statistics as of 'feat'",
Expected: []sql.Row{},
},
{
// we dropped 'feat', not 'main'
Query: "select table_name, index_name, row_count from dolt_statistics as of 'main'",
Expected: []sql.Row{
{"xy", "primary", uint64(6)},
{"xy", "y", uint64(6)},
},
},
},
},
{
Expand Down
21 changes: 16 additions & 5 deletions go/libraries/doltcore/sqle/statspro/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,24 @@ func (sc *StatsCoord) GetTableStats(ctx *sql.Context, db string, table sql.Table

func (sc *StatsCoord) RefreshTableStats(ctx *sql.Context, table sql.Table, dbName string) error {
dSess := dsess.DSessFromSess(ctx.Session)
branch, err := dSess.GetBranch()
if err != nil {
return err
}

var branch string
if strings.Contains(dbName, "/") {
parts := strings.Split(dbName, "/")
if len(parts) == 2 {
dbName = parts[0]
branch = parts[1]
}
}
if branch == "" {
branch = "main"
branch, err := dSess.GetBranch()
if err != nil {
return err
}

if branch == "" {
branch = "main"
}
}

var sqlDb dsess.SqlDatabase
Expand Down

0 comments on commit 1be0f49

Please sign in to comment.