Skip to content

Commit

Permalink
*: memory is not allocated first if the user does not use some inform…
Browse files Browse the repository at this point in the history
…ation from the table. (#50062) (#50166)

close #50077
  • Loading branch information
ti-chi-bot authored Feb 22, 2024
1 parent 99e2a21 commit 6915d3a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
35 changes: 15 additions & 20 deletions table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ type TableCommon struct {
// physicalTableID is a unique int64 to identify a physical table.
physicalTableID int64
Columns []*table.Column
PublicColumns []*table.Column
VisibleColumns []*table.Column
HiddenColumns []*table.Column
WritableColumns []*table.Column
FullHiddenColsAndVisibleColumns []*table.Column
publicColumns []*table.Column
visibleColumns []*table.Column
hiddenColumns []*table.Column
writableColumns []*table.Column
fullHiddenColsAndVisibleColumns []*table.Column
indices []table.Index
meta *model.TableInfo
allocs autoid.Allocators
Expand Down Expand Up @@ -192,11 +192,6 @@ func initTableCommon(t *TableCommon, tblInfo *model.TableInfo, physicalTableID i
t.allocs = allocs
t.meta = tblInfo
t.Columns = cols
t.PublicColumns = t.Cols()
t.VisibleColumns = t.VisibleCols()
t.HiddenColumns = t.HiddenCols()
t.WritableColumns = t.WritableCols()
t.FullHiddenColsAndVisibleColumns = t.FullHiddenColsAndVisibleCols()
t.recordPrefix = tablecodec.GenTableRecordPrefix(physicalTableID)
t.indexPrefix = tablecodec.GenTableIndexPrefix(physicalTableID)
if tblInfo.IsSequence() {
Expand Down Expand Up @@ -293,32 +288,32 @@ func (t *TableCommon) getCols(mode getColsMode) []*table.Column {

// Cols implements table.Table Cols interface.
func (t *TableCommon) Cols() []*table.Column {
if len(t.PublicColumns) > 0 {
return t.PublicColumns
if len(t.publicColumns) > 0 {
return t.publicColumns
}
return t.getCols(full)
}

// VisibleCols implements table.Table VisibleCols interface.
func (t *TableCommon) VisibleCols() []*table.Column {
if len(t.VisibleColumns) > 0 {
return t.VisibleColumns
if len(t.visibleColumns) > 0 {
return t.visibleColumns
}
return t.getCols(visible)
}

// HiddenCols implements table.Table HiddenCols interface.
func (t *TableCommon) HiddenCols() []*table.Column {
if len(t.HiddenColumns) > 0 {
return t.HiddenColumns
if len(t.hiddenColumns) > 0 {
return t.hiddenColumns
}
return t.getCols(hidden)
}

// WritableCols implements table WritableCols interface.
func (t *TableCommon) WritableCols() []*table.Column {
if len(t.WritableColumns) > 0 {
return t.WritableColumns
if len(t.writableColumns) > 0 {
return t.writableColumns
}
writableColumns := make([]*table.Column, 0, len(t.Columns))
for _, col := range t.Columns {
Expand All @@ -337,8 +332,8 @@ func (t *TableCommon) DeletableCols() []*table.Column {

// FullHiddenColsAndVisibleCols implements table FullHiddenColsAndVisibleCols interface.
func (t *TableCommon) FullHiddenColsAndVisibleCols() []*table.Column {
if len(t.FullHiddenColsAndVisibleColumns) > 0 {
return t.FullHiddenColsAndVisibleColumns
if len(t.fullHiddenColsAndVisibleColumns) > 0 {
return t.fullHiddenColsAndVisibleColumns
}

cols := make([]*table.Column, 0, len(t.Columns))
Expand Down
6 changes: 0 additions & 6 deletions table/tables/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,6 @@ func TestHiddenColumn(t *testing.T) {
colInfo[1].Hidden = true
colInfo[3].Hidden = true
colInfo[5].Hidden = true
tc := tb.(*tables.TableCommon)
// Reset related caches
tc.VisibleColumns = nil
tc.WritableColumns = nil
tc.HiddenColumns = nil
tc.FullHiddenColsAndVisibleColumns = nil

// Basic test
cols := tb.VisibleCols()
Expand Down
2 changes: 1 addition & 1 deletion tablecodec/tablecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ func decodeIntHandleInIndexValue(data []byte) kv.Handle {

// EncodeTableIndexPrefix encodes index prefix with tableID and idxID.
func EncodeTableIndexPrefix(tableID, idxID int64) kv.Key {
key := make([]byte, 0, prefixLen)
key := make([]byte, 0, prefixLen+idLen)
key = appendTableIndexPrefix(key, tableID)
key = codec.EncodeInt(key, idxID)
return key
Expand Down

0 comments on commit 6915d3a

Please sign in to comment.