MCPcopy
hub / github.com/pingcap/tidb / NewRowDecoder

Function NewRowDecoder

pkg/executor/builder.go:5467–5517  ·  view source on GitHub ↗

NewRowDecoder creates a chunk decoder for new row format row value decode.

(ctx sessionctx.Context, schema *expression.Schema, tbl *model.TableInfo)

Source from the content-addressed store, hash-verified

5465
5466// NewRowDecoder creates a chunk decoder for new row format row value decode.
5467func NewRowDecoder(ctx sessionctx.Context, schema *expression.Schema, tbl *model.TableInfo) *rowcodec.ChunkDecoder {
5468 getColInfoByID := func(tbl *model.TableInfo, colID int64) *model.ColumnInfo {
5469 for _, col := range tbl.Columns {
5470 if col.ID == colID {
5471 return col
5472 }
5473 }
5474 return nil
5475 }
5476 var pkCols []int64
5477 reqCols := make([]rowcodec.ColInfo, len(schema.Columns))
5478 for i := range schema.Columns {
5479 idx, col := i, schema.Columns[i]
5480 isPK := (tbl.PKIsHandle && mysql.HasPriKeyFlag(col.RetType.GetFlag())) || col.ID == model.ExtraHandleID
5481 if isPK {
5482 pkCols = append(pkCols, col.ID)
5483 }
5484 isGeneratedCol := false
5485 if col.VirtualExpr != nil {
5486 isGeneratedCol = true
5487 }
5488 reqCols[idx] = rowcodec.ColInfo{
5489 ID: col.ID,
5490 VirtualGenCol: isGeneratedCol,
5491 Ft: col.RetType,
5492 }
5493 }
5494 if len(pkCols) == 0 {
5495 pkCols = tables.TryGetCommonPkColumnIds(tbl)
5496 if len(pkCols) == 0 {
5497 pkCols = []int64{-1}
5498 }
5499 }
5500 defVal := func(i int, chk *chunk.Chunk) error {
5501 if reqCols[i].ID < 0 {
5502 // model.ExtraHandleID, ExtraPhysTblID... etc
5503 // Don't set the default value for that column.
5504 chk.AppendNull(i)
5505 return nil
5506 }
5507
5508 ci := getColInfoByID(tbl, reqCols[i].ID)
5509 d, err := table.GetColOriginDefaultValue(ctx.GetExprCtx(), ci)
5510 if err != nil {
5511 return err
5512 }
5513 chk.AppendDatum(i, &d)
5514 return nil
5515 }
5516 return rowcodec.NewChunkDecoder(reqCols, pkCols, defVal, ctx.GetSessionVars().Location())
5517}
5518
5519func (b *executorBuilder) buildBatchPointGet(plan *plannercore.BatchPointGetPlan) exec.Executor {
5520 var err error

Callers 4

InitMethod · 0.70
buildMemTableReaderFunction · 0.70
getMemRowsIterMethod · 0.70
buildBatchPointGetMethod · 0.70

Calls 11

HasPriKeyFlagFunction · 0.92
TryGetCommonPkColumnIdsFunction · 0.92
GetColOriginDefaultValueFunction · 0.92
NewChunkDecoderFunction · 0.92
getColInfoByIDFunction · 0.85
AppendDatumMethod · 0.80
GetFlagMethod · 0.65
GetExprCtxMethod · 0.65
LocationMethod · 0.65
GetSessionVarsMethod · 0.65
AppendNullMethod · 0.45

Tested by

no test coverage detected