MCPcopy Create free account
hub / github.com/pingcap/tidb / TestBuildDeleteSQL

Function TestBuildDeleteSQL

pkg/ttl/sqlbuilder/sql_test.go:865–932  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

863}
864
865func TestBuildDeleteSQL(t *testing.T) {
866 t1 := &cache.PhysicalTable{
867 Schema: pmodel.NewCIStr("test"),
868 TableInfo: &model.TableInfo{
869 Name: pmodel.NewCIStr("t1"),
870 },
871 KeyColumns: []*model.ColumnInfo{
872 {Name: pmodel.NewCIStr("id"), FieldType: *types.NewFieldType(mysql.TypeInt24)},
873 },
874 TimeColumn: &model.ColumnInfo{
875 Name: pmodel.NewCIStr("time"),
876 FieldType: *types.NewFieldType(mysql.TypeDatetime),
877 },
878 }
879
880 t2 := &cache.PhysicalTable{
881 Schema: pmodel.NewCIStr("test2"),
882 TableInfo: &model.TableInfo{
883 Name: pmodel.NewCIStr("t2"),
884 },
885 KeyColumns: []*model.ColumnInfo{
886 {Name: pmodel.NewCIStr("a"), FieldType: *types.NewFieldType(mysql.TypeInt24)},
887 {Name: pmodel.NewCIStr("b"), FieldType: *types.NewFieldType(mysql.TypeVarchar)},
888 },
889 TimeColumn: &model.ColumnInfo{
890 Name: pmodel.NewCIStr("time"),
891 FieldType: *types.NewFieldType(mysql.TypeDatetime),
892 },
893 }
894
895 cases := []struct {
896 tbl *cache.PhysicalTable
897 expire time.Time
898 rows [][]types.Datum
899 sql string
900 }{
901 {
902 tbl: t1,
903 expire: time.UnixMilli(0).In(time.UTC),
904 rows: [][]types.Datum{d(1)},
905 sql: "DELETE LOW_PRIORITY FROM `test`.`t1` WHERE `id` IN (1) AND `time` < FROM_UNIXTIME(0) LIMIT 1",
906 },
907 {
908 tbl: t1,
909 expire: time.UnixMilli(0).In(time.UTC),
910 rows: [][]types.Datum{d(2), d(3), d(4)},
911 sql: "DELETE LOW_PRIORITY FROM `test`.`t1` WHERE `id` IN (2, 3, 4) AND `time` < FROM_UNIXTIME(0) LIMIT 3",
912 },
913 {
914 tbl: t2,
915 expire: time.UnixMilli(0).In(time.UTC),
916 rows: [][]types.Datum{d(1, "a")},
917 sql: "DELETE LOW_PRIORITY FROM `test2`.`t2` WHERE (`a`, `b`) IN ((1, 'a')) AND `time` < FROM_UNIXTIME(0) LIMIT 1",
918 },
919 {
920 tbl: t2,
921 expire: time.UnixMilli(0).In(time.UTC),
922 rows: [][]types.Datum{d(1, "a"), d(2, "b")},

Callers

nothing calls this directly

Calls 5

NewFieldTypeFunction · 0.92
BuildDeleteSQLFunction · 0.92
dFunction · 0.85
InMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…