Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
  • Loading branch information
hawkingrei committed Jun 6, 2024
1 parent 9e6a1d6 commit 012c1c1
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions pkg/statistics/handle/storage/read_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package storage

import (
"fmt"
"strings"
"time"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -124,30 +125,19 @@ type BatchLoadMeta struct {
possibleColInfo *model.ColumnInfo
}

func generateHistPredict(conditions []BatchLoadMeta) string {
var sqlParts []string
template := "(table_id = '%s' and hist_id = '%s' and is_index = '%s')"

for _, cond := range conditions {
part := fmt.Sprintf(template, cond, cond.HistID, cond.IsIndex)
sqlParts = append(sqlParts, part)
}

return strings.Join(sqlParts, " or ")
}

// HistMetasFromStorage reads the meta info of the histogram from the storage.
func HistMetasFromStorage(sctx sessionctx.Context, items BatchLoadMeta) (*statistics.Histogram, *types.Datum, int64, int64, error) {
isIndex := 0
var tp *types.FieldType
if item.IsIndex {
isIndex = 1
tp = types.NewFieldType(mysql.TypeBlob)
} else {
tp = &possibleColInfo.FieldType
}
rows, _, err := util.ExecRows(sctx,
"select distinct_count, version, null_count, tot_col_size, stats_ver, correlation, flag, last_analyze_pos from mysql.stats_histograms where table_id = %? and hist_id = %? and is_index = %?",
item.TableID,
item.ID,
isIndex,
)
if err != nil {
return nil, nil, 0, 0, err
}
if len(rows) == 0 {
return nil, nil, 0, 0, nil
}
hist := statistics.NewHistogram(item.ID, rows[0].GetInt64(0), rows[0].GetInt64(2), rows[0].GetUint64(1), tp, chunk.InitialCapacity, rows[0].GetInt64(3))
hist.Correlation = rows[0].GetFloat64(5)
lastPos := rows[0].GetDatum(7, types.NewFieldType(mysql.TypeBlob))
return hist, &lastPos, rows[0].GetInt64(4), rows[0].GetInt64(6), nil

}

0 comments on commit 012c1c1

Please sign in to comment.