Skip to content

Commit

Permalink
fix can not show view data_type pingcap#22316
Browse files Browse the repository at this point in the history
  • Loading branch information
beihaiguaishou committed Jan 11, 2021
1 parent 809a375 commit a65d37d
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/pingcap/tidb/ddl/placement"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/domain/infosync"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/meta/autoid"
plannercore "github.com/pingcap/tidb/planner/core"
Expand All @@ -50,6 +51,7 @@ import (
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/hint"
"github.com/pingcap/tidb/util/pdapi"
"github.com/pingcap/tidb/util/set"
"github.com/pingcap/tidb/util/sqlexec"
Expand Down Expand Up @@ -542,20 +544,20 @@ func (e *memtableRetriever) setDataFromTables(ctx sessionctx.Context, schemas []
return nil
}

func (e *hugeMemTableRetriever) setDataForColumns(ctx sessionctx.Context) error {
checker := privilege.GetPrivilegeManager(ctx)
func (e *hugeMemTableRetriever) setDataForColumns(ctx context.Context, sctx sessionctx.Context) error {
checker := privilege.GetPrivilegeManager(sctx)
e.rows = e.rows[:0]
batch := 1024
for ; e.dbsIdx < len(e.dbs); e.dbsIdx++ {
schema := e.dbs[e.dbsIdx]
for e.tblIdx < len(schema.Tables) {
table := schema.Tables[e.tblIdx]
e.tblIdx++
if checker != nil && !checker.RequestVerification(ctx.GetSessionVars().ActiveRoles, schema.Name.L, table.Name.L, "", mysql.AllPrivMask) {
if checker != nil && !checker.RequestVerification(sctx.GetSessionVars().ActiveRoles, schema.Name.L, table.Name.L, "", mysql.AllPrivMask) {
continue
}

e.dataForColumnsInTable(schema, table)
e.dataForColumnsInTable(ctx, sctx, schema, table)
if len(e.rows) >= batch {
return nil
}
Expand All @@ -565,7 +567,27 @@ func (e *hugeMemTableRetriever) setDataForColumns(ctx sessionctx.Context) error
return nil
}

func (e *hugeMemTableRetriever) dataForColumnsInTable(schema *model.DBInfo, tbl *model.TableInfo) {
func (e *hugeMemTableRetriever) dataForColumnsInTable(ctx context.Context, sctx sessionctx.Context, schema *model.DBInfo, tbl *model.TableInfo) {
if tbl.IsView() {
// retrieve view columns info
planBuilder, _ := plannercore.NewPlanBuilder(sctx, infoschema.GetInfoSchema(sctx), &hint.BlockHintProcessor{})
if viewLogicalPlan, err := planBuilder.BuildDataSourceFromView(ctx, schema.Name, tbl); err == nil {
viewSchema := viewLogicalPlan.Schema()
viewOutputNames := viewLogicalPlan.OutputNames()
for _, col := range tbl.Columns {
idx := expression.FindFieldNameIdxByColName(viewOutputNames, col.Name.L)
if idx >= 0 {
col.FieldType = *viewSchema.Columns[idx].GetType()
}
if col.Tp == mysql.TypeVarString {
col.Tp = mysql.TypeVarchar
}
}
} else {
sctx.GetSessionVars().StmtCtx.AppendWarning(err)
return
}
}
for i, col := range tbl.Columns {
if col.Hidden {
continue
Expand Down Expand Up @@ -1891,7 +1913,7 @@ func (e *hugeMemTableRetriever) retrieve(ctx context.Context, sctx sessionctx.Co
var err error
switch e.table.Name.O {
case infoschema.TableColumns:
err = e.setDataForColumns(sctx)
err = e.setDataForColumns(ctx, sctx)
}
if err != nil {
return nil, err
Expand Down

0 comments on commit a65d37d

Please sign in to comment.