Skip to content

Commit

Permalink
*: resort fields for reducing the memory allocated (pingcap#14270)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsqlu authored and sre-bot committed Jan 7, 2020
1 parent ae281e1 commit 11b9beb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
8 changes: 4 additions & 4 deletions expression/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ type baseBuiltinFunc struct {
tp *types.FieldType
pbCode tipb.ScalarFuncSig

childrenVectorizedOnce *sync.Once
childrenVectorized bool
childrenVectorized bool
childrenReversed bool

childrenReversedOnce *sync.Once
childrenReversed bool
childrenVectorizedOnce *sync.Once
childrenReversedOnce *sync.Once
}

func (b *baseBuiltinFunc) PbCode() tipb.ScalarFuncSig {
Expand Down
14 changes: 7 additions & 7 deletions expression/builtin_cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,57 +827,57 @@ func (s *testEvaluatorSuite) TestCastFuncSig(c *C) {
castToTimeCases2 := []struct {
before *Column
after types.Time
row chunk.MutRow
fsp int8
tp byte
row chunk.MutRow
}{
// cast real as Time(0).
{
&Column{RetType: types.NewFieldType(mysql.TypeDouble), Index: 0},
dt,
chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(float64(curTimeInt))}),
types.DefaultFsp,
mysql.TypeDate,
chunk.MutRowFromDatums([]types.Datum{types.NewFloat64Datum(float64(curTimeInt))}),
},
// cast decimal as Date.
{
&Column{RetType: types.NewFieldType(mysql.TypeNewDecimal), Index: 0},
dt,
chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromInt(curTimeInt))}),
types.DefaultFsp,
mysql.TypeDate,
chunk.MutRowFromDatums([]types.Datum{types.NewDecimalDatum(types.NewDecFromInt(curTimeInt))}),
},
// cast int as Datetime(6).
{
&Column{RetType: types.NewFieldType(mysql.TypeLonglong), Index: 0},
tm,
chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(curTimeInt)}),
types.MaxFsp,
mysql.TypeDatetime,
chunk.MutRowFromDatums([]types.Datum{types.NewIntDatum(curTimeInt)}),
},
// cast string as Datetime(6).
{
&Column{RetType: types.NewFieldType(mysql.TypeString), Index: 0},
tm,
chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum(curTimeString)}),
types.MaxFsp,
mysql.TypeDatetime,
chunk.MutRowFromDatums([]types.Datum{types.NewStringDatum(curTimeString)}),
},
// cast Duration as Date.
{
&Column{RetType: types.NewFieldType(mysql.TypeDuration), Index: 0},
dt,
chunk.MutRowFromDatums([]types.Datum{durationDatum}),
types.DefaultFsp,
mysql.TypeDate,
chunk.MutRowFromDatums([]types.Datum{durationDatum}),
},
// cast Time as Date.
{
&Column{RetType: types.NewFieldType(mysql.TypeDatetime), Index: 0},
dt,
chunk.MutRowFromDatums([]types.Datum{timeDatum}),
types.DefaultFsp,
mysql.TypeDate,
chunk.MutRowFromDatums([]types.Datum{timeDatum}),
},
}
for i, t := range castToTimeCases2 {
Expand Down
7 changes: 4 additions & 3 deletions expression/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,15 @@ type Column struct {

hashcode []byte

// InOperand indicates whether this column is the inner operand of column equal condition converted
// from `[not] in (subq)`.
InOperand bool
// VirtualExpr is used to save expression for virtual column
VirtualExpr Expression

OrigName string
IsHidden bool

// InOperand indicates whether this column is the inner operand of column equal condition converted
// from `[not] in (subq)`.
InOperand bool
}

// Equal implements Expression interface.
Expand Down
8 changes: 4 additions & 4 deletions planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,15 @@ type Insert struct {
Schema4OnDuplicate *expression.Schema
names4OnDuplicate types.NameSlice

GenCols InsertGeneratedColumns

SelectPlan PhysicalPlan

IsReplace bool

// NeedFillDefaultValue is true when expr in value list reference other column.
NeedFillDefaultValue bool

GenCols InsertGeneratedColumns

SelectPlan PhysicalPlan

AllAssignmentsAreConstant bool
}

Expand Down
4 changes: 2 additions & 2 deletions planner/core/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@ type PhysicalIndexMergeJoin struct {

// KeyOff2KeyOffOrderByIdx maps the offsets in join keys to the offsets in join keys order by index.
KeyOff2KeyOffOrderByIdx []int
// NeedOuterSort means whether outer rows should be sorted to build range.
NeedOuterSort bool
// CompareFuncs store the compare functions for outer join keys and inner join key.
CompareFuncs []expression.CompareFunc
// OuterCompareFuncs store the compare functions for outer join keys and outer join
// keys, it's for outer rows sort's convenience.
OuterCompareFuncs []expression.CompareFunc
// NeedOuterSort means whether outer rows should be sorted to build range.
NeedOuterSort bool
// Desc means whether inner child keep desc order.
Desc bool
}
Expand Down
6 changes: 3 additions & 3 deletions planner/memo/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ type Group struct {
FirstExpr map[Operand]*list.Element
Fingerprints map[string]*list.Element

Explored bool
SelfFingerprint string

ImplMap map[string]Implementation
Prop *property.LogicalProperty

EngineType EngineType

SelfFingerprint string
Explored bool

//hasBuiltKeyInfo indicates whether this group has called `BuildKeyInfo`.
// BuildKeyInfo is lazily called when a rule needs information of
// unique key or maxOneRow (in LogicalProp). For each Group, we only need
Expand Down
11 changes: 6 additions & 5 deletions planner/util/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ type AccessPath struct {
EqOrInCondCount int
IndexFilters []expression.Expression
TableFilters []expression.Expression
// IsTablePath indicates whether this path is table path.
IsTablePath bool
// Forced means this path is generated by `use/force index()`.
Forced bool
// PartialIndexPaths store all index access paths.
// If there are extra filters, store them in TableFilters.
PartialIndexPaths []*AccessPath

StoreType kv.StoreType

IsDNFCond bool

StoreType kv.StoreType
// IsTablePath indicates whether this path is table path.
IsTablePath bool
// Forced means this path is generated by `use/force index()`.
Forced bool
}

// SplitCorColAccessCondFromFilters move the necessary filter in the form of index_col = corrlated_col to access conditions.
Expand Down

0 comments on commit 11b9beb

Please sign in to comment.