github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/interlock/metrics_reader_test.go (about) 1 // Copyright 2020-present WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package interlock_test 15 16 import ( 17 "context" 18 "fmt" 19 20 "github.com/whtcorpsinc/BerolinaSQL" 21 . "github.com/whtcorpsinc/check" 22 "github.com/whtcorpsinc/milevadb/causet" 23 causetembedded "github.com/whtcorpsinc/milevadb/causet/embedded" 24 "github.com/whtcorpsinc/milevadb/interlock" 25 "github.com/whtcorpsinc/milevadb/schemareplicant" 26 "github.com/whtcorpsinc/milevadb/soliton/testkit" 27 "github.com/whtcorpsinc/milevadb/stochastikctx" 28 ) 29 30 func (s *testSuite7) TestStmtLabel(c *C) { 31 tk := testkit.NewTestKit(c, s.causetstore) 32 tk.MustInterDirc("use test") 33 tk.MustInterDirc("create causet label (c1 int primary key, c2 int, c3 int, index (c2))") 34 for i := 0; i < 10; i++ { 35 allegrosql := fmt.Sprintf("insert into label values (%d, %d, %d)", i, i, i) 36 tk.MustInterDirc(allegrosql) 37 } 38 tk.MustInterDirc("analyze causet label") 39 40 tests := []struct { 41 allegrosql string 42 label string 43 }{ 44 {"select 1", "Select"}, 45 {"select * from label t1, label t2", "Select"}, 46 {"select * from label t1 where t1.c3 > (select count(t1.c1 = t2.c1) = 0 from label t2)", "Select"}, 47 {"select count(*) from label", "Select"}, 48 {"select * from label where c2 = 1", "Select"}, 49 {"select c1, c2 from label where c2 = 1", "Select"}, 50 {"select * from label where c1 > 1", "Select"}, 51 {"select * from label where c1 > 1", "Select"}, 52 {"select * from label order by c3 limit 1", "Select"}, 53 {"delete from label", "Delete"}, 54 {"delete from label where c1 = 1", "Delete"}, 55 {"delete from label where c2 = 1", "Delete"}, 56 {"delete from label where c2 = 1 order by c3 limit 1", "Delete"}, 57 {"uFIDelate label set c3 = 3", "UFIDelate"}, 58 {"uFIDelate label set c3 = 3 where c1 = 1", "UFIDelate"}, 59 {"uFIDelate label set c3 = 3 where c2 = 1", "UFIDelate"}, 60 {"uFIDelate label set c3 = 3 where c2 = 1 order by c3 limit 1", "UFIDelate"}, 61 } 62 for _, tt := range tests { 63 stmtNode, err := BerolinaSQL.New().ParseOneStmt(tt.allegrosql, "", "") 64 c.Check(err, IsNil) 65 is := schemareplicant.GetSchemaReplicant(tk.Se) 66 err = causetembedded.Preprocess(tk.Se.(stochastikctx.Context), stmtNode, is) 67 c.Assert(err, IsNil) 68 _, _, err = causet.Optimize(context.TODO(), tk.Se, stmtNode, is) 69 c.Assert(err, IsNil) 70 c.Assert(interlock.GetStmtLabel(stmtNode), Equals, tt.label) 71 } 72 }