-
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
infoschema: fill data length fields for tables #7657
Changes from 1 commit
b5c50a1
bb1fdf6
7256b06
2758da5
ed6b32e
1cf30ef
110298f
b79328c
9f4c25f
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 |
---|---|---|
|
@@ -1421,3 +1421,23 @@ func SetBinChsClnFlag(ft *FieldType) { | |
ft.Collate = charset.CollationBin | ||
ft.Flag |= mysql.BinaryFlag | ||
} | ||
|
||
// VarElemLen indicates this column is a variable length column. | ||
const VarElemLen = -1 | ||
|
||
// Length is the length of value for the type. | ||
func (ft *FieldType) Length() int { | ||
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. It's misleading because we already have a Flen field in FieldType. |
||
switch ft.Tp { | ||
case mysql.TypeFloat: | ||
return 4 | ||
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, | ||
mysql.TypeLonglong, mysql.TypeDouble, mysql.TypeYear, mysql.TypeDuration: | ||
return 8 | ||
case mysql.TypeDate, mysql.TypeDatetime, mysql.TypeTimestamp: | ||
return 16 | ||
case mysql.TypeNewDecimal: | ||
return MyDecimalStructSize | ||
default: | ||
return VarElemLen | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ import ( | |
"unsafe" | ||
|
||
"github.com/cznic/mathutil" | ||
"github.com/pingcap/tidb/mysql" | ||
"github.com/pingcap/tidb/types" | ||
) | ||
|
||
|
@@ -124,7 +123,7 @@ func (c *Codec) decodeColumn(buffer []byte, col *column, ordinal int) (remained | |
} | ||
|
||
// decode offsets. | ||
numFixedBytes := getFixedLen(c.colTypes[ordinal]) | ||
numFixedBytes := c.colTypes[ordinal].Length() | ||
numDataBytes := numFixedBytes * col.length | ||
if numFixedBytes == -1 { | ||
numOffsetBytes := (col.length + 1) * 4 | ||
|
@@ -163,25 +162,6 @@ func (c *Codec) bytesToI32Slice(b []byte) (i32s []int32) { | |
return i32s | ||
} | ||
|
||
// varElemLen indicates this column is a variable length column. | ||
const varElemLen = -1 | ||
|
||
func getFixedLen(colType *types.FieldType) int { | ||
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. This is the length in Chunk, but the length in the storage is different. 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. Yes, but we do not maintain the length for fixed length column. 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. I mean we should use a different function to estimate the average column size in the storage. |
||
switch colType.Tp { | ||
case mysql.TypeFloat: | ||
return 4 | ||
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, | ||
mysql.TypeLonglong, mysql.TypeDouble, mysql.TypeYear, mysql.TypeDuration: | ||
return 8 | ||
case mysql.TypeDate, mysql.TypeDatetime, mysql.TypeTimestamp: | ||
return 16 | ||
case mysql.TypeNewDecimal: | ||
return types.MyDecimalStructSize | ||
default: | ||
return varElemLen | ||
} | ||
} | ||
|
||
func init() { | ||
for i := 0; i < 128; i++ { | ||
allNotNullBitmap[i] = 0xFF | ||
|
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.
The current implementation doesn't do any RPC.
After this change, it may take too much time to execute if we have many tables.
And this may run frequently in some application.
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.
It does. You can take a look at
getRowCountAllTable
.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.
Oh, I see.
We can cache the result in case it is called too frequently, just like the way
GlobalVariableCache
does.