@@ -1067,8 +1067,10 @@ func (m *Mutator) GetMetasByDBID(dbID int64) ([]structure.HashPair, error) {
10671067 return res , nil
10681068}
10691069
1070+ // foreign key info contain null and [] situations
1071+ var checkForeignKeyAttributesNil = `"fk_info":null`
1072+ var checkForeignKeyAttributesZero = `"fk_info":[]`
10701073var checkAttributesInOrder = []string {
1071- `"fk_info":null` ,
10721074 `"partition":null` ,
10731075 `"Lock":null` ,
10741076 `"tiflash_replica":null` ,
@@ -1082,8 +1084,19 @@ var checkAttributesInOrder = []string{
10821084// then it does not need to be loaded and this function will return false.
10831085// Otherwise, it will return true, indicating that the table info should be loaded.
10841086// Since attributes are checked in sequence, it's important to choose the order carefully.
1085- func isTableInfoMustLoad (json []byte , filterAttrs ... string ) bool {
1087+ // isCheckForeignKeyAttrsInOrder check foreign key or not, since fk_info contains two null situations.
1088+ func isTableInfoMustLoad (json []byte , isCheckForeignKeyAttrsInOrder bool , filterAttrs ... string ) bool {
10861089 idx := 0
1090+ if isCheckForeignKeyAttrsInOrder {
1091+ idx = bytes .Index (json , hack .Slice (checkForeignKeyAttributesNil ))
1092+ if idx == - 1 {
1093+ idx = bytes .Index (json , hack .Slice (checkForeignKeyAttributesZero ))
1094+ if idx == - 1 {
1095+ return true
1096+ }
1097+ }
1098+ json = json [idx :]
1099+ }
10871100 for _ , substr := range filterAttrs {
10881101 idx = bytes .Index (json , hack .Slice (substr ))
10891102 if idx == - 1 {
@@ -1097,7 +1110,7 @@ func isTableInfoMustLoad(json []byte, filterAttrs ...string) bool {
10971110// IsTableInfoMustLoad checks whether the table info needs to be loaded.
10981111// Exported for testing.
10991112func IsTableInfoMustLoad (json []byte ) bool {
1100- return isTableInfoMustLoad (json , checkAttributesInOrder ... )
1113+ return isTableInfoMustLoad (json , true , checkAttributesInOrder ... )
11011114}
11021115
11031116// NameExtractRegexp is exported for testing.
@@ -1142,7 +1155,7 @@ func (m *Mutator) GetAllNameToIDAndTheMustLoadedTableInfo(dbID int64) (map[strin
11421155
11431156 key := Unescape (nameLMatch [1 ])
11441157 res [strings .Clone (key )] = int64 (id )
1145- if isTableInfoMustLoad (value , checkAttributesInOrder ... ) {
1158+ if isTableInfoMustLoad (value , true , checkAttributesInOrder ... ) {
11461159 tbInfo := & model.TableInfo {}
11471160 err = json .Unmarshal (value , tbInfo )
11481161 if err != nil {
@@ -1171,7 +1184,7 @@ func GetTableInfoWithAttributes(m *Mutator, dbID int64, filterAttrs ...string) (
11711184 return nil
11721185 }
11731186
1174- if isTableInfoMustLoad (value , filterAttrs ... ) {
1187+ if isTableInfoMustLoad (value , false , filterAttrs ... ) {
11751188 tbInfo := & model.TableInfo {}
11761189 err := json .Unmarshal (value , tbInfo )
11771190 if err != nil {
0 commit comments