-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
planner: Expression memory trace #37624
Changes from 17 commits
e81d5b7
e74ed1a
b8a0eef
86d3737
387291d
de006c1
0b393e9
dc9788c
395a866
1127045
6ce3e6d
6d6a23a
aca5095
1fda13c
4a4cbe7
7b5c3d3
2aabdc8
bb3ddc3
df1b8da
bc04a4c
54cd08b
addf19b
bef720f
316b2d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ package expression | |
import ( | ||
"fmt" | ||
"strings" | ||
"unsafe" | ||
|
||
"github.com/pingcap/errors" | ||
"github.com/pingcap/tidb/parser/ast" | ||
|
@@ -191,6 +192,16 @@ func (col *CorrelatedColumn) resolveIndicesByVirtualExpr(_ *Schema) bool { | |
return true | ||
} | ||
|
||
// MemoryUsage return the memory usage of CorrelatedColumn | ||
func (col *CorrelatedColumn) MemoryUsage() (sum int64) { | ||
if col == nil { | ||
return | ||
} | ||
|
||
sum = col.Column.MemoryUsage() + int64(unsafe.Sizeof(col.Data)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to implement |
||
return sum | ||
} | ||
|
||
// Column represents a column. | ||
type Column struct { | ||
RetType *types.FieldType | ||
|
@@ -722,3 +733,20 @@ func GcColumnExprIsTidbShard(virtualExpr Expression) bool { | |
|
||
return true | ||
} | ||
|
||
const emptyColumnSize = int64(unsafe.Sizeof(Column{})) | ||
|
||
// MemoryUsage return the memory usage of Column | ||
func (col *Column) MemoryUsage() (sum int64) { | ||
if col == nil { | ||
return | ||
} | ||
|
||
sum = emptyColumnSize + col.RetType.MemoryUsage() + int64(cap(col.hashcode))*int64(unsafe.Sizeof(*new(byte))) + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
int64(len(col.OrigName)+len(col.charset)+len(col.collation)) | ||
|
||
if col.VirtualExpr != nil { | ||
sum += col.VirtualExpr.MemoryUsage() | ||
} | ||
return | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,3 +263,13 @@ func TestGcColumnExprIsTidbShard(t *testing.T) { | |
shardExpr := NewFunctionInternal(ctx, ast.TiDBShard, ft, col) | ||
require.True(t, GcColumnExprIsTidbShard(shardExpr)) | ||
} | ||
|
||
func TestColumnMemoryUsage(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about combining all these tests as one like |
||
c1 := &Column{OrigName: "Origin"} | ||
c2 := Column{OrigName: "OriginName"} | ||
|
||
require.Greater(t, c2.MemoryUsage(), c1.MemoryUsage()) | ||
|
||
c1 = nil | ||
require.Equal(t, c1.MemoryUsage(), int64(0)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can
childrenVectorizedOnce
andchildrenReversedOnce
be nil?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to define a const number for
Once
likeconst onceSize = int64(unsafe.Sizeof(Once{}))
instead of copying it here.