Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always try to push block filter for 1.1 #15409

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions pkg/sql/plan/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const DefaultBlockMaxRows = 8192
const BlockNumForceOneCN = 200
const blockSelectivityThreshHold = 0.95
const highNDVcolumnThreshHold = 0.95
const blockNDVThreshHold = 100

// stats cache is small, no need to use LRU for now
type StatsCache struct {
Expand Down Expand Up @@ -528,13 +527,10 @@ func estimateFilterWeight(expr *plan.Expr, w float64) float64 {
}

// harsh estimate of block selectivity, will improve it in the future
func estimateFilterBlockSelectivity(ctx context.Context, expr *plan.Expr, tableDef *plan.TableDef, builder *QueryBuilder) float64 {
func estimateFilterBlockSelectivity(ctx context.Context, expr *plan.Expr, tableDef *plan.TableDef, tableCnt float64) float64 {
if !ExprIsZonemappable(ctx, expr) {
return 1
}
if expr.Selectivity < 0.01 {
return expr.Selectivity * 100
}
col := extractColRefInFilter(expr)
if col != nil {
switch GetSortOrder(tableDef, col.Name) {
Expand All @@ -546,10 +542,11 @@ func estimateFilterBlockSelectivity(ctx context.Context, expr *plan.Expr, tableD
return math.Min(expr.Selectivity*10, 0.5)
}
}
if getExprNdv(expr, builder) < blockNDVThreshHold {
if tableCnt > 10000 {
return 0.5
} else {
return 1
}
return 0.5
}

func rewriteFilterListByStats(ctx context.Context, nodeID int32, builder *QueryBuilder) {
Expand Down Expand Up @@ -979,7 +976,7 @@ func calcScanStats(node *plan.Node, builder *QueryBuilder) *plan.Stats {
var blockExprList []*plan.Expr
for i := range node.FilterList {
node.FilterList[i].Selectivity = estimateExprSelectivity(node.FilterList[i], builder)
currentBlockSel := estimateFilterBlockSelectivity(builder.GetContext(), node.FilterList[i], node.TableDef, builder)
currentBlockSel := estimateFilterBlockSelectivity(builder.GetContext(), node.FilterList[i], node.TableDef, stats.TableCnt)
if currentBlockSel < blockSelectivityThreshHold {
copyOfExpr := DeepCopyExpr(node.FilterList[i])
copyOfExpr.Selectivity = currentBlockSel
Expand Down
Loading