( ctx context.Context, sctx sessionctx.Context, schema pmodel.CIStr, tbl *model.TableInfo, priv mysql.PrivilegeType, )
| 1101 | } |
| 1102 | |
| 1103 | func (e *hugeMemTableRetriever) dataForColumnsInTable( |
| 1104 | ctx context.Context, |
| 1105 | sctx sessionctx.Context, |
| 1106 | schema pmodel.CIStr, |
| 1107 | tbl *model.TableInfo, |
| 1108 | priv mysql.PrivilegeType, |
| 1109 | ) { |
| 1110 | if tbl.IsView() { |
| 1111 | e.viewMu.Lock() |
| 1112 | _, ok := e.viewSchemaMap[tbl.ID] |
| 1113 | if !ok { |
| 1114 | var viewLogicalPlan base.Plan |
| 1115 | internalCtx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnOthers) |
| 1116 | // Build plan is not thread safe, there will be concurrency on sessionctx. |
| 1117 | if err := runWithSystemSession(internalCtx, sctx, func(s sessionctx.Context) error { |
| 1118 | is := sessiontxn.GetTxnManager(s).GetTxnInfoSchema() |
| 1119 | planBuilder, _ := plannercore.NewPlanBuilder(plannercore.PlanBuilderOptNoExecution{}).Init(s.GetPlanCtx(), is, hint.NewQBHintHandler(nil)) |
| 1120 | var err error |
| 1121 | viewLogicalPlan, err = planBuilder.BuildDataSourceFromView(ctx, schema, tbl, nil, nil) |
| 1122 | return errors.Trace(err) |
| 1123 | }); err != nil { |
| 1124 | sctx.GetSessionVars().StmtCtx.AppendWarning(err) |
| 1125 | e.viewMu.Unlock() |
| 1126 | return |
| 1127 | } |
| 1128 | e.viewSchemaMap[tbl.ID] = viewLogicalPlan.Schema() |
| 1129 | e.viewOutputNamesMap[tbl.ID] = viewLogicalPlan.OutputNames() |
| 1130 | } |
| 1131 | e.viewMu.Unlock() |
| 1132 | } |
| 1133 | |
| 1134 | cols, ordinalPos := e.extractor.ListColumns(tbl) |
| 1135 | for i, col := range cols { |
| 1136 | ft := &(col.FieldType) |
| 1137 | if tbl.IsView() { |
| 1138 | e.viewMu.RLock() |
| 1139 | if e.viewSchemaMap[tbl.ID] != nil { |
| 1140 | // If this is a view, replace the column with the view column. |
| 1141 | idx := expression.FindFieldNameIdxByColName(e.viewOutputNamesMap[tbl.ID], col.Name.L) |
| 1142 | if idx >= 0 { |
| 1143 | col1 := e.viewSchemaMap[tbl.ID].Columns[idx] |
| 1144 | ft = col1.GetType(sctx.GetExprCtx().GetEvalCtx()) |
| 1145 | } |
| 1146 | } |
| 1147 | e.viewMu.RUnlock() |
| 1148 | } |
| 1149 | |
| 1150 | var charMaxLen, charOctLen, numericPrecision, numericScale, datetimePrecision any |
| 1151 | colLen, decimal := ft.GetFlen(), ft.GetDecimal() |
| 1152 | defaultFlen, defaultDecimal := mysql.GetDefaultFieldLengthAndDecimal(ft.GetType()) |
| 1153 | if decimal == types.UnspecifiedLength { |
| 1154 | decimal = defaultDecimal |
| 1155 | } |
| 1156 | if colLen == types.UnspecifiedLength { |
| 1157 | colLen = defaultFlen |
| 1158 | } |
| 1159 | if ft.GetType() == mysql.TypeSet { |
| 1160 | // Example: In MySQL set('a','bc','def','ghij') has length 13, because |
no test coverage detected