Skip to content

Commit

Permalink
Merge #42900
Browse files Browse the repository at this point in the history
42900: sql: Simplify and remove heuristic planner code r=andy-kimball a=andy-kimball

This PR is a series of commits that simplifies and removes code that was at one time needed by the heuristic planner (which is now gone).

Co-authored-by: Andrew Kimball <[email protected]>
  • Loading branch information
craig[bot] and andy-kimball committed Dec 5, 2019
2 parents 2fe2028 + fe6a1c4 commit e1c1a9a
Show file tree
Hide file tree
Showing 30 changed files with 129 additions and 1,756 deletions.
8 changes: 3 additions & 5 deletions pkg/sql/analyze_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,20 @@ import (
func (p *planner) analyzeExpr(
ctx context.Context,
raw tree.Expr,
sources sqlbase.MultiSourceInfo,
source *sqlbase.DataSourceInfo,
iVarHelper tree.IndexedVarHelper,
expectedType *types.T,
requireType bool,
typingContext string,
) (tree.TypedExpr, error) {
// Perform optional name resolution.
resolved := raw
if sources != nil {
if source != nil {
var err error
var hasStar bool
resolved, _, hasStar, err = p.resolveNames(raw, sources, iVarHelper)
resolved, _, err = p.resolveNames(raw, source, iVarHelper)
if err != nil {
return nil, err
}
p.curPlan.hasStar = p.curPlan.hasStar || hasStar
}

// Type check.
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/apply_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func newApplyJoinNode(
rightProps: rightProps,
rightCols: rightCols,
right: right,
columns: pred.info.SourceColumns,
columns: pred.cols,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func validateCheckExpr(
// Construct AST and then convert to a string, to avoid problems with escaping the check expression
tblref := tree.TableRef{TableID: int64(tableDesc.ID), As: tree.AliasClause{Alias: "t"}}
sel := &tree.SelectClause{
Exprs: sqlbase.ColumnsSelectors(tableDesc.Columns, false /* forUpdateOrDelete */),
Exprs: sqlbase.ColumnsSelectors(tableDesc.Columns),
From: tree.From{Tables: []tree.TableExpr{&tblref}},
Where: &tree.Where{Type: tree.AstWhere, Expr: &tree.NotExpr{Expr: expr}},
}
Expand Down
13 changes: 5 additions & 8 deletions pkg/sql/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,9 @@ func makeTableDescIfAs(
}

func dequalifyColumnRefs(
ctx context.Context, sources sqlbase.MultiSourceInfo, expr tree.Expr,
ctx context.Context, source *sqlbase.DataSourceInfo, expr tree.Expr,
) (tree.Expr, error) {
resolver := sqlbase.ColumnResolver{Sources: sources}
resolver := sqlbase.ColumnResolver{Source: source}
return tree.SimpleVisit(
expr,
func(expr tree.Expr) (recurse bool, newExpr tree.Expr, err error) {
Expand All @@ -960,9 +960,8 @@ func dequalifyColumnRefs(
if err != nil {
return false, nil, err
}
srcIdx := resolver.ResolverState.SrcIdx
colIdx := resolver.ResolverState.ColIdx
col := sources[srcIdx].SourceColumns[colIdx]
col := source.SourceColumns[colIdx]
return false, &tree.ColumnItem{ColumnName: tree.Name(col.Name)}, nil
}
}
Expand Down Expand Up @@ -1073,7 +1072,6 @@ func MakeTableDesc(
sourceInfo := sqlbase.NewSourceInfoForSingleTable(
n.Table, sqlbase.ResultColumnsFromColDescs(desc.Columns),
)
sources := sqlbase.MultiSourceInfo{sourceInfo}

for i := range desc.Columns {
col := &desc.Columns[i]
Expand All @@ -1083,7 +1081,7 @@ func MakeTableDesc(
return desc, err
}

expr, err = dequalifyColumnRefs(ctx, sources, expr)
expr, err = dequalifyColumnRefs(ctx, sourceInfo, expr)
if err != nil {
return desc, err
}
Expand Down Expand Up @@ -1593,9 +1591,8 @@ func MakeCheckConstraint(
sourceInfo := sqlbase.NewSourceInfoForSingleTable(
tableName, sqlbase.ResultColumnsFromColDescs(desc.TableDesc().AllNonDropColumns()),
)
sources := sqlbase.MultiSourceInfo{sourceInfo}

expr, err = dequalifyColumnRefs(ctx, sources, d.Expr)
expr, err = dequalifyColumnRefs(ctx, sourceInfo, d.Expr)
if err != nil {
return nil, err
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/sql/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ package sql

import "github.com/cockroachdb/cockroach/pkg/sql/sqlbase"

// For more detailed documentation on DataSourceInfos, see
// sqlbase/data_source.go.

// planDataSource contains the data source information for data
// produced by a planNode.
type planDataSource struct {
// info which describe the columns.
info *sqlbase.DataSourceInfo
// columns gives the result columns (always anonymous source).
columns sqlbase.ResultColumns

// plan which can be used to retrieve the data.
plan planNode
Expand Down
Loading

0 comments on commit e1c1a9a

Please sign in to comment.