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

expression: support vectorized bitmap operations for nulls in Column #12034

Merged
merged 8 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions util/chunk/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,17 @@ func (c *Column) CopyReconstruct(sel []int, dst *Column) *Column {
}
return dst
}

// MergeNulls merges these columns' null bitmaps.
// For a row, if any column of it is null, the result is null.
// It works like: if col1.IsNull || col2.IsNull || col3.IsNull.
// The user should ensure that all these columns have the same length, and
// data stored in these columns are fixed-length type.
func (c *Column) MergeNulls(cols ...*Column) {
for _, col := range cols {
for i := range c.nullBitmap {
// bit 0 is null, 1 is not null, so do AND operations here.
c.nullBitmap[i] &= col.nullBitmap[i]
}
}
}
50 changes: 50 additions & 0 deletions util/chunk/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,3 +885,53 @@ func BenchmarkTimeVec(b *testing.B) {
}
}
}

func genNullCols(n int) []*Column {
cols := make([]*Column, n)
for i := range cols {
cols[i] = NewColumn(types.NewFieldType(mysql.TypeLonglong), 1024)
cols[i].ResizeInt64(1024, false)
for j := 0; j < 1024; j++ {
if rand.Intn(10) < 5 {
cols[i].SetNull(j, true)
}
}
}
return cols
}

func (s *testChunkSuite) TestVectorizedNulls(c *check.C) {
for i := 0; i < 256; i++ {
cols := genNullCols(4)
lCol, rCol := cols[0], cols[1]
vecResult, rowResult := cols[2], cols[3]
vecResult.SetNulls(0, 1024, false)
rowResult.SetNulls(0, 1024, false)
vecResult.MergeNulls(lCol, rCol)
for i := 0; i < 1024; i++ {
rowResult.SetNull(i, lCol.IsNull(i) || rCol.IsNull(i))
}

for i := 0; i < 1024; i++ {
c.Assert(rowResult.IsNull(i), check.Equals, vecResult.IsNull(i))
}
}
}

func BenchmarkMergeNullsVectorized(b *testing.B) {
cols := genNullCols(3)
b.ResetTimer()
for i := 0; i < b.N; i++ {
cols[0].MergeNulls(cols[1:]...)
}
}

func BenchmarkMergeNullsNonVectorized(b *testing.B) {
cols := genNullCols(3)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; i < 1024; i++ {
cols[0].SetNull(i, cols[1].IsNull(i) || cols[2].IsNull(i))
}
}
}