Skip to content

Commit 690400e

Browse files
authored
[no-release-notes] set log output option (#2867)
* [no-release-notes] set log output option * more logger output * fix formatters * cleanup
1 parent 2e57d42 commit 690400e

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

sql/analyzer/analyzer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package analyzer
1616

1717
import (
1818
"fmt"
19+
"io"
1920
"os"
2021
"reflect"
2122
"runtime/trace"
@@ -176,6 +177,10 @@ func (ab *Builder) RemoveAfterAllRule(id RuleId) *Builder {
176177

177178
var log = logrus.New()
178179

180+
func SetOutput(w io.Writer) {
181+
log.SetOutput(w)
182+
}
183+
179184
func init() {
180185
// TODO: give the option for debug analyzer logging format to match the global one
181186
log.SetFormatter(simpleLogFormatter{})

sql/analyzer/costed_index_scan.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func costedIndexScans(ctx *sql.Context, a *Analyzer, n sql.Node, qFlags *sql.Que
8282
}
8383
}
8484
if iat, ok := rt.UnderlyingTable().(sql.IndexAddressableTable); ok {
85-
return costedIndexLookup(ctx, n, a.Catalog, iat, rt, aliasName, filter.Expression, qFlags)
85+
return costedIndexLookup(ctx, n, a, iat, rt, aliasName, filter.Expression, qFlags)
8686
}
8787
return n, transform.SameTree, nil
8888
})
@@ -123,19 +123,24 @@ func indexSearchableLookup(n sql.Node, rt sql.TableNode, lookup sql.IndexLookup,
123123
return ret, transform.NewTree, nil
124124
}
125125

126-
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) {
126+
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) {
127127
indexes, err := iat.GetIndexes(ctx)
128128
if err != nil {
129129
return n, transform.SameTree, err
130130
}
131-
ita, _, filters, err := getCostedIndexScan(ctx, cat, rt, indexes, expression.SplitConjunction(oldFilter), qFlags)
131+
ita, stats, filters, err := getCostedIndexScan(ctx, a.Catalog, rt, indexes, expression.SplitConjunction(oldFilter), qFlags)
132132
if err != nil || ita == nil {
133133
return n, transform.SameTree, err
134134
}
135135
var ret sql.Node = ita
136136
if aliasName != "" {
137137
ret = plan.NewTableAlias(aliasName, ret)
138138
}
139+
140+
a.Log("new indexed table: %s/%s/%s", ita.Index().Database(), ita.Index().Table(), ita.Index().ID())
141+
a.Log("index stats cnt: %d", stats.RowCount())
142+
a.Log("index stats histogram: %s", stats.Histogram().DebugString())
143+
139144
// excluded from tree + not included in index scan => filter above scan
140145
if len(filters) > 0 {
141146
ret = plan.NewFilter(expression.JoinAnd(filters...), ret)

sql/analyzer/indexed_joins.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func recSchemaToGetFields(n sql.Node, sch sql.Schema) []sql.Expression {
136136

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

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

13651366
stats, _ := statsProv.GetStats(ctx, sql.NewStatQualifier(tn.Database().Name(), schemaName, tn.Name(), idx.SqlIdx().ID()), cols)
1366-
13671367
return &memo.IndexScan{
13681368
Table: ret,
13691369
Index: idx,

sql/memo/memo.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Memo struct {
4747
Ctx *sql.Context
4848
scope *plan.Scope
4949
scopeLen int
50+
Debug bool
5051

5152
TableProps *tableProps
5253
QFlags *sql.QueryFlags
@@ -320,6 +321,11 @@ func (m *Memo) memoizeIndexScan(grp *ExprGroup, ita *plan.IndexedTableAccess, al
320321
// group. This is distinct from memoizeIndexScan so that we can mark ITA groups
321322
// as done early.
322323
func (m *Memo) MemoizeStaticIndexAccess(grp *ExprGroup, aliasName string, idx *Index, ita *plan.IndexedTableAccess, filters []sql.Expression, stat sql.Statistic) {
324+
if m.Debug {
325+
m.Ctx.GetLogger().Debugf("new indexed table: %s/%s/%s", ita.Index().Database(), ita.Index().Table(), ita.Index().ID())
326+
m.Ctx.GetLogger().Debugf("index stats cnt: %d: ", stat.RowCount())
327+
m.Ctx.GetLogger().Debugf("index stats histogram: %s", stat.Histogram().DebugString())
328+
}
323329
if len(filters) > 0 {
324330
// set the indexed path as best. correct for cases where
325331
// indexScan is incompatible with best join operator

0 commit comments

Comments
 (0)