@@ -177,6 +177,12 @@ func (is *infoSchema) TableByName(schema, table model.CIStr) (t table.Table, err
177
177
return nil , ErrTableNotExists .GenWithStackByArgs (schema , table )
178
178
}
179
179
180
+ // TableInfoByName implements InfoSchema.TableInfoByName
181
+ func (is * infoSchema ) TableInfoByName (schema , table model.CIStr ) (* model.TableInfo , error ) {
182
+ tbl , err := is .TableByName (schema , table )
183
+ return getTableInfo (tbl ), err
184
+ }
185
+
180
186
// TableIsView indicates whether the schema.table is a view.
181
187
func TableIsView (is InfoSchema , schema , table model.CIStr ) bool {
182
188
tbl , err := is .TableByName (schema , table )
@@ -240,6 +246,25 @@ func (is *infoSchema) TableByID(id int64) (val table.Table, ok bool) {
240
246
return slice [idx ], true
241
247
}
242
248
249
+ // TableInfoByID implements InfoSchema.TableInfoByID
250
+ func (is * infoSchema ) TableInfoByID (id int64 ) (* model.TableInfo , bool ) {
251
+ tbl , ok := is .TableByID (id )
252
+ return getTableInfo (tbl ), ok
253
+ }
254
+
255
+ // FindTableInfoByPartitionID implements InfoSchema.FindTableInfoByPartitionID
256
+ func (is * infoSchema ) FindTableInfoByPartitionID (
257
+ partitionID int64 ,
258
+ ) (* model.TableInfo , * model.DBInfo , * model.PartitionDefinition ) {
259
+ tbl , db , partDef := is .FindTableByPartitionID (partitionID )
260
+ return getTableInfo (tbl ), db , partDef
261
+ }
262
+
263
+ // SchemaTableInfos implements InfoSchema.FindTableInfoByPartitionID
264
+ func (is * infoSchema ) SchemaTableInfos (schema model.CIStr ) []* model.TableInfo {
265
+ return getTableInfoList (is .SchemaTables (schema ))
266
+ }
267
+
243
268
// allocByID returns the Allocators of a table.
244
269
func allocByID (is InfoSchema , id int64 ) (autoid.Allocators , bool ) {
245
270
tbl , ok := is .TableByID (id )
@@ -351,10 +376,10 @@ func init() {
351
376
Tables : infoSchemaTables ,
352
377
}
353
378
RegisterVirtualTable (infoSchemaDB , createInfoSchemaTable )
354
- util .GetSequenceByName = func (is context.InfoSchemaMetaVersion , schema , sequence model.CIStr ) (util.SequenceTable , error ) {
379
+ util .GetSequenceByName = func (is context.MetaOnlyInfoSchema , schema , sequence model.CIStr ) (util.SequenceTable , error ) {
355
380
return GetSequenceByName (is .(InfoSchema ), schema , sequence )
356
381
}
357
- mock .MockInfoschema = func (tbList []* model.TableInfo ) context.InfoSchemaMetaVersion {
382
+ mock .MockInfoschema = func (tbList []* model.TableInfo ) context.MetaOnlyInfoSchema {
358
383
return MockInfoSchema (tbList )
359
384
}
360
385
}
@@ -666,6 +691,26 @@ func (ts *SessionExtendedInfoSchema) TableByName(schema, table model.CIStr) (tab
666
691
return ts .InfoSchema .TableByName (schema , table )
667
692
}
668
693
694
+ // TableInfoByName implements InfoSchema.TableInfoByName
695
+ func (ts * SessionExtendedInfoSchema ) TableInfoByName (schema , table model.CIStr ) (* model.TableInfo , error ) {
696
+ tbl , err := ts .TableByName (schema , table )
697
+ return getTableInfo (tbl ), err
698
+ }
699
+
700
+ // TableInfoByID implements InfoSchema.TableInfoByID
701
+ func (ts * SessionExtendedInfoSchema ) TableInfoByID (id int64 ) (* model.TableInfo , bool ) {
702
+ tbl , ok := ts .TableByID (id )
703
+ return getTableInfo (tbl ), ok
704
+ }
705
+
706
+ // FindTableInfoByPartitionID implements InfoSchema.FindTableInfoByPartitionID
707
+ func (ts * SessionExtendedInfoSchema ) FindTableInfoByPartitionID (
708
+ partitionID int64 ,
709
+ ) (* model.TableInfo , * model.DBInfo , * model.PartitionDefinition ) {
710
+ tbl , db , partDef := ts .FindTableByPartitionID (partitionID )
711
+ return getTableInfo (tbl ), db , partDef
712
+ }
713
+
669
714
// TableByID implements InfoSchema.TableByID
670
715
func (ts * SessionExtendedInfoSchema ) TableByID (id int64 ) (table.Table , bool ) {
671
716
if ts .LocalTemporaryTables != nil {
@@ -739,3 +784,22 @@ func FindTableByTblOrPartID(is InfoSchema, id int64) (table.Table, *model.Partit
739
784
tbl , _ , partDef := is .FindTableByPartitionID (id )
740
785
return tbl , partDef
741
786
}
787
+
788
+ func getTableInfo (tbl table.Table ) * model.TableInfo {
789
+ if tbl == nil {
790
+ return nil
791
+ }
792
+ return tbl .Meta ()
793
+ }
794
+
795
+ func getTableInfoList (tables []table.Table ) []* model.TableInfo {
796
+ if tables == nil {
797
+ return nil
798
+ }
799
+
800
+ infoLost := make ([]* model.TableInfo , 0 , len (tables ))
801
+ for _ , tbl := range tables {
802
+ infoLost = append (infoLost , tbl .Meta ())
803
+ }
804
+ return infoLost
805
+ }
0 commit comments