@@ -31,6 +31,7 @@ import (
3131 "github.com/pingcap/tidb/pkg/kv"
3232 "github.com/pingcap/tidb/pkg/meta/model"
3333 "github.com/pingcap/tidb/pkg/parser/ast"
34+ "github.com/pingcap/tidb/pkg/parser/mysql"
3435 "github.com/pingcap/tidb/pkg/tablecodec"
3536 "github.com/pingcap/tidb/pkg/util/chunk"
3637 "github.com/stretchr/testify/require"
@@ -1609,26 +1610,28 @@ func TestColdDelete(t *testing.T) {
16091610// columns as varchar for the snapshot rows, so caching that layout would decode
16101611// every later row of the table with the wrong column types.
16111612func TestSnapshotLayoutNotCached (t * testing.T ) {
1612- dec := & decoder {cache : common .NewTableInfoProvider ()}
1613- msg := & canalJSONMessageWithTiDBExtension {
1614- JSONMessage : & JSONMessage {
1615- Schema : "test" ,
1616- Table : "t1" ,
1617- PKNames : []string {"id" },
1618- MySQLType : map [string ]string {
1619- "id" : "int" ,
1620- "val" : "varchar(32)" ,
1613+ newMsg := func (mysqlType map [string ]string ) * canalJSONMessageWithTiDBExtension {
1614+ return & canalJSONMessageWithTiDBExtension {
1615+ JSONMessage : & JSONMessage {
1616+ Schema : "test" ,
1617+ Table : "t1" ,
1618+ PKNames : []string {"id" },
1619+ MySQLType : mysqlType ,
16211620 },
1622- },
1623- Extensions : & tidbExtension { CommitTs : 100 },
1621+ Extensions : & tidbExtension { CommitTs : 100 },
1622+ }
16241623 }
1624+ dec := & decoder {cache : common .NewTableInfoProvider ()}
1625+ shared := dec .queryTableInfo (newMsg (map [string ]string {"id" : "int" , "val" : "enum('a','b')" }), true )
16251626
1626- built := dec .queryTableInfo (msg , false )
1627- require .NotNil (t , built )
1627+ built := dec .queryTableInfo (newMsg (map [string ]string {"id" : "int" , "val" : "varchar(32)" }), false )
1628+ require .NotSame (t , shared , built )
1629+ require .Equal (t , mysql .TypeEnum , shared .GetColumns ()[1 ].FieldType .GetType ())
1630+ require .Equal (t , mysql .TypeVarchar , built .GetColumns ()[1 ].FieldType .GetType ())
16281631 _ , cached := dec .cache .ReadAt ("test" , "t1" , 101 )
1629- require .Nil ( t , cached )
1632+ require .Same ( t , shared , cached )
16301633
1631- cachedInfo := dec .queryTableInfo (msg , true )
1634+ cachedInfo := dec .queryTableInfo (newMsg ( map [ string ] string { "id" : "int" , "val" : "varchar(32)" }) , true )
16321635 _ , cached = dec .cache .ReadAt ("test" , "t1" , 101 )
16331636 require .Same (t , cachedInfo , cached )
16341637}
0 commit comments