@@ -227,7 +227,7 @@ func (is *infoSchema) SchemaExists(schema pmodel.CIStr) bool {
227
227
return ok
228
228
}
229
229
230
- func (is * infoSchema ) TableByName (ctx stdctx.Context , schema , table pmodel.CIStr ) (t table.Table , err error ) {
230
+ func (is * infoSchema ) tableByNameWithoutConsideringState (ctx stdctx.Context , schema , table pmodel.CIStr ) (t table.Table , err error ) {
231
231
if tbNames , ok := is .schemaMap [schema .L ]; ok {
232
232
if t , ok = tbNames .tables [table .L ]; ok {
233
233
return
@@ -236,6 +236,27 @@ func (is *infoSchema) TableByName(ctx stdctx.Context, schema, table pmodel.CIStr
236
236
return nil , ErrTableNotExists .FastGenByArgs (schema , table )
237
237
}
238
238
239
+ // TableByName implements InfoSchema.TableByName
240
+ func (is * infoSchema ) TableByName (ctx stdctx.Context , schema , table pmodel.CIStr ) (t table.Table , err error ) {
241
+ t , err = is .tableByNameWithoutConsideringState (ctx , schema , table )
242
+ if err != nil {
243
+ return nil , err
244
+ }
245
+ if t .Meta ().State != model .StatePublic {
246
+ return nil , ErrTableNotExists .FastGenByArgs (schema , table )
247
+ }
248
+ return t , nil
249
+ }
250
+
251
+ // TableByFKInfo implements InfoSchema.TableByFKInfo
252
+ func (is * infoSchema ) TableByFKInfo (ctx stdctx.Context , info * model.ReferredFKInfo ) (t table.Table , err error ) {
253
+ t , err = is .tableByNameWithoutConsideringState (ctx , info .ChildSchema , info .ChildTable )
254
+ if err != nil {
255
+ return nil , err
256
+ }
257
+ return t , nil
258
+ }
259
+
239
260
// TableInfoByName implements InfoSchema.TableInfoByName
240
261
func (is * infoSchema ) TableInfoByName (schema , table pmodel.CIStr ) (* model.TableInfo , error ) {
241
262
tbl , err := is .TableByName (stdctx .Background (), schema , table )
@@ -262,7 +283,7 @@ func TableIsSequence(is InfoSchema, schema, table pmodel.CIStr) bool {
262
283
263
284
func (is * infoSchema ) TableExists (schema , table pmodel.CIStr ) bool {
264
285
if tbNames , ok := is .schemaMap [schema .L ]; ok {
265
- if _ , ok = tbNames .tables [table .L ]; ok {
286
+ if tbl , ok : = tbNames .tables [table .L ]; ok && tbl . Meta (). State == model . StatePublic {
266
287
return true
267
288
}
268
289
}
@@ -305,7 +326,12 @@ func (is *infoSchema) TableByID(_ stdctx.Context, id int64) (val table.Table, ok
305
326
if idx == - 1 {
306
327
return nil , false
307
328
}
308
- return slice [idx ], true
329
+
330
+ tbl := slice [idx ]
331
+ if tbl .Meta ().State != model .StatePublic {
332
+ return nil , false
333
+ }
334
+ return tbl , true
309
335
}
310
336
311
337
// TableInfoByID implements InfoSchema.TableInfoByID
@@ -330,6 +356,9 @@ func (is *infoSchema) SchemaTableInfos(ctx stdctx.Context, schema pmodel.CIStr)
330
356
}
331
357
tables := make ([]* model.TableInfo , 0 , len (schemaTables .tables ))
332
358
for _ , tbl := range schemaTables .tables {
359
+ if tbl .Meta ().State != model .StatePublic {
360
+ continue
361
+ }
333
362
tables = append (tables , tbl .Meta ())
334
363
}
335
364
return tables , nil
@@ -343,6 +372,9 @@ func (is *infoSchema) SchemaSimpleTableInfos(ctx stdctx.Context, schema pmodel.C
343
372
}
344
373
ret := make ([]* model.TableNameInfo , 0 , len (schemaTables .tables ))
345
374
for _ , t := range schemaTables .tables {
375
+ if t .Meta ().State != model .StatePublic {
376
+ continue
377
+ }
346
378
ret = append (ret , & model.TableNameInfo {
347
379
ID : t .Meta ().ID ,
348
380
Name : t .Meta ().Name ,
@@ -363,12 +395,17 @@ func (is *infoSchema) ListTablesWithSpecialAttribute(filter specialAttributeFilt
363
395
tblInfos , err := is .SchemaTableInfos (stdctx .Background (), dbName )
364
396
terror .Log (err )
365
397
for _ , tblInfo := range tblInfos {
398
+ if tblInfo .State != model .StatePublic {
399
+ continue
400
+ }
366
401
if ! filter (tblInfo ) {
367
402
continue
368
403
}
369
404
res .TableInfos = append (res .TableInfos , tblInfo )
370
405
}
371
- ret = append (ret , res )
406
+ if len (res .TableInfos ) > 0 {
407
+ ret = append (ret , res )
408
+ }
372
409
}
373
410
return ret
374
411
}
@@ -402,6 +439,9 @@ func (is *infoSchema) AllSchemaNames() (schemas []pmodel.CIStr) {
402
439
func (is * infoSchema ) FindTableByPartitionID (partitionID int64 ) (table.Table , * model.DBInfo , * model.PartitionDefinition ) {
403
440
for _ , v := range is .schemaMap {
404
441
for _ , tbl := range v .tables {
442
+ if tbl .Meta ().State != model .StatePublic {
443
+ continue
444
+ }
405
445
pi := tbl .Meta ().GetPartitionInfo ()
406
446
if pi == nil {
407
447
continue
@@ -681,6 +721,9 @@ func NewSessionTables() *SessionTables {
681
721
func (is * SessionTables ) TableByName (ctx stdctx.Context , schema , table pmodel.CIStr ) (table.Table , bool ) {
682
722
if tbNames , ok := is .schemaMap [schema .L ]; ok {
683
723
if t , ok := tbNames .tables [table .L ]; ok {
724
+ if t .Meta ().State != model .StatePublic {
725
+ return nil , false
726
+ }
684
727
return t , true
685
728
}
686
729
}
@@ -696,6 +739,9 @@ func (is *SessionTables) TableExists(schema, table pmodel.CIStr) (ok bool) {
696
739
// TableByID get table by table id
697
740
func (is * SessionTables ) TableByID (id int64 ) (tbl table.Table , ok bool ) {
698
741
tbl , ok = is .idx2table [id ]
742
+ if ok && tbl .Meta ().State != model .StatePublic {
743
+ return nil , false
744
+ }
699
745
return
700
746
}
701
747
@@ -790,12 +836,18 @@ type SessionExtendedInfoSchema struct {
790
836
func (ts * SessionExtendedInfoSchema ) TableByName (ctx stdctx.Context , schema , table pmodel.CIStr ) (table.Table , error ) {
791
837
if ts .LocalTemporaryTables != nil {
792
838
if tbl , ok := ts .LocalTemporaryTables .TableByName (ctx , schema , table ); ok {
839
+ if tbl .Meta ().State != model .StatePublic {
840
+ return nil , ErrTableNotExists .GenWithStackByArgs (schema , table )
841
+ }
793
842
return tbl , nil
794
843
}
795
844
}
796
845
797
846
if ts .MdlTables != nil {
798
847
if tbl , ok := ts .MdlTables .TableByName (ctx , schema , table ); ok {
848
+ if tbl .Meta ().State != model .StatePublic {
849
+ return nil , ErrTableNotExists .GenWithStackByArgs (schema , table )
850
+ }
799
851
return tbl , nil
800
852
}
801
853
}
@@ -831,12 +883,18 @@ func (ts *SessionExtendedInfoSchema) TableByID(ctx stdctx.Context, id int64) (ta
831
883
832
884
if ts .LocalTemporaryTables != nil {
833
885
if tbl , ok := ts .LocalTemporaryTables .TableByID (id ); ok {
886
+ if tbl .Meta ().State != model .StatePublic {
887
+ return nil , false
888
+ }
834
889
return tbl , true
835
890
}
836
891
}
837
892
838
893
if ts .MdlTables != nil {
839
894
if tbl , ok := ts .MdlTables .TableByID (id ); ok {
895
+ if tbl .Meta ().State != model .StatePublic {
896
+ return nil , false
897
+ }
840
898
return tbl , true
841
899
}
842
900
}
0 commit comments