Skip to content

Commit

Permalink
more logger output
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman committed Mar 3, 2025
1 parent ac81c13 commit 2ed4b57
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 9 additions & 3 deletions sql/analyzer/costed_index_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func costedIndexScans(ctx *sql.Context, a *Analyzer, n sql.Node, qFlags *sql.Que
}
}
if iat, ok := rt.UnderlyingTable().(sql.IndexAddressableTable); ok {
return costedIndexLookup(ctx, n, a.Catalog, iat, rt, aliasName, filter.Expression, qFlags)
return costedIndexLookup(ctx, n, a, iat, rt, aliasName, filter.Expression, qFlags)
}
return n, transform.SameTree, nil
})
Expand Down Expand Up @@ -123,19 +123,24 @@ func indexSearchableLookup(n sql.Node, rt sql.TableNode, lookup sql.IndexLookup,
return ret, transform.NewTree, nil
}

func costedIndexLookup(ctx *sql.Context, n sql.Node, cat sql.Catalog, iat sql.IndexAddressableTable, rt sql.TableNode, aliasName string, oldFilter sql.Expression, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) {
func costedIndexLookup(ctx *sql.Context, n sql.Node, a *Analyzer, iat sql.IndexAddressableTable, rt sql.TableNode, aliasName string, oldFilter sql.Expression, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) {
indexes, err := iat.GetIndexes(ctx)
if err != nil {
return n, transform.SameTree, err
}
ita, _, filters, err := getCostedIndexScan(ctx, cat, rt, indexes, expression.SplitConjunction(oldFilter), qFlags)
ita, stats, filters, err := getCostedIndexScan(ctx, a.Catalog, rt, indexes, expression.SplitConjunction(oldFilter), qFlags)
if err != nil || ita == nil {
return n, transform.SameTree, err
}
var ret sql.Node = ita
if aliasName != "" {
ret = plan.NewTableAlias(aliasName, ret)
}

a.Log("new indexed table: %s/%s/%s", ita.Index().Database(), ita.Index().Table(), ita.Index().ID())
a.Log("index stats cnt: ", stats.RowCount())

Check failure on line 141 in sql/analyzer/costed_index_scan.go

View workflow job for this annotation

GitHub Actions / test (macos-latest)

(*github.com/dolthub/go-mysql-server/sql/analyzer.Analyzer).Log call has arguments but no formatting directives

Check failure on line 141 in sql/analyzer/costed_index_scan.go

View workflow job for this annotation

GitHub Actions / test

(*github.com/dolthub/go-mysql-server/sql/analyzer.Analyzer).Log call has arguments but no formatting directives
a.Log("index stats histogram", stats.Histogram().DebugString())

Check failure on line 142 in sql/analyzer/costed_index_scan.go

View workflow job for this annotation

GitHub Actions / test (macos-latest)

(*github.com/dolthub/go-mysql-server/sql/analyzer.Analyzer).Log call has arguments but no formatting directives

Check failure on line 142 in sql/analyzer/costed_index_scan.go

View workflow job for this annotation

GitHub Actions / test

(*github.com/dolthub/go-mysql-server/sql/analyzer.Analyzer).Log call has arguments but no formatting directives

// excluded from tree + not included in index scan => filter above scan
if len(filters) > 0 {
ret = plan.NewFilter(expression.JoinAnd(filters...), ret)
Expand Down Expand Up @@ -1305,6 +1310,7 @@ func indexHasContentHashedFieldForFilter(filter *iScanLeaf, idx sql.Index, ordin
// by a statistic, returning the updated statistic, whether the filter was
// applicable, and the maximum prefix key (0 or 1 for a leaf).
func (c *indexCoster) costIndexScanLeaf(filter *iScanLeaf, s sql.Statistic, buckets []sql.HistogramBucket, ordinals map[string]int, idx sql.Index) ([]sql.HistogramBucket, *sql.FuncDepSet, bool, int, error) {
//todo use {underlyingTable}.{gf.Name}?
ord, ok := ordinals[strings.ToLower(filter.gf.Name())]
if !ok {
return nil, nil, false, 0, nil
Expand Down
2 changes: 1 addition & 1 deletion sql/analyzer/indexed_joins.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func recSchemaToGetFields(n sql.Node, sch sql.Schema) []sql.Expression {

func replanJoin(ctx *sql.Context, n *plan.JoinNode, a *Analyzer, scope *plan.Scope, qFlags *sql.QueryFlags) (ret sql.Node, err error) {
m := memo.NewMemo(ctx, a.Catalog, scope, len(scope.Schema()), a.Coster, qFlags)
m.Debug = a.Debug

defer func() {
if r := recover(); r != nil {
Expand Down Expand Up @@ -1363,7 +1364,6 @@ func makeIndexScan(ctx *sql.Context, statsProv sql.StatsProvider, tab plan.Table
}

stats, _ := statsProv.GetStats(ctx, sql.NewStatQualifier(tn.Database().Name(), schemaName, tn.Name(), idx.SqlIdx().ID()), cols)

return &memo.IndexScan{
Table: ret,
Index: idx,
Expand Down
6 changes: 6 additions & 0 deletions sql/memo/memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Memo struct {
Ctx *sql.Context
scope *plan.Scope
scopeLen int
Debug bool

TableProps *tableProps
QFlags *sql.QueryFlags
Expand Down Expand Up @@ -320,6 +321,11 @@ func (m *Memo) memoizeIndexScan(grp *ExprGroup, ita *plan.IndexedTableAccess, al
// group. This is distinct from memoizeIndexScan so that we can mark ITA groups
// as done early.
func (m *Memo) MemoizeStaticIndexAccess(grp *ExprGroup, aliasName string, idx *Index, ita *plan.IndexedTableAccess, filters []sql.Expression, stat sql.Statistic) {
if m.Debug {
m.Ctx.GetLogger().Debug("new indexed table: %s/%s/%s", ita.Index().Database(), ita.Index().Table(), ita.Index().ID())

Check failure on line 325 in sql/memo/memo.go

View workflow job for this annotation

GitHub Actions / test (macos-latest)

(*github.com/sirupsen/logrus.Entry).Debug call has possible Printf formatting directive %s

Check failure on line 325 in sql/memo/memo.go

View workflow job for this annotation

GitHub Actions / test

(*github.com/sirupsen/logrus.Entry).Debug call has possible Printf formatting directive %s
m.Ctx.GetLogger().Debug("index stats cnt: ", stat.RowCount())
m.Ctx.GetLogger().Debug("index stats histogram", stat.Histogram().DebugString())
}
if len(filters) > 0 {
// set the indexed path as best. correct for cases where
// indexScan is incompatible with best join operator
Expand Down

0 comments on commit 2ed4b57

Please sign in to comment.