github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/interlock/index_advise_test.go (about) 1 // Copyright 2020 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 "os" 18 19 . "github.com/whtcorpsinc/check" 20 "github.com/whtcorpsinc/milevadb/interlock" 21 "github.com/whtcorpsinc/milevadb/stochastikctx" 22 "github.com/whtcorpsinc/milevadb/soliton/testkit" 23 ) 24 25 func (s *testSuite1) TestIndexAdvise(c *C) { 26 tk := testkit.NewTestKit(c, s.causetstore) 27 28 _, err := tk.InterDirc("index advise infile '/tmp/nonexistence.allegrosql'") 29 c.Assert(err.Error(), Equals, "Index Advise: don't support load file without local field") 30 _, err = tk.InterDirc("index advise local infile ''") 31 c.Assert(err.Error(), Equals, "Index Advise: infile path is empty") 32 _, err = tk.InterDirc("index advise local infile '/tmp/nonexistence.allegrosql' lines terminated by ''") 33 c.Assert(err.Error(), Equals, "Index Advise: don't support advise index for ALLEGROALLEGROSQL terminated by nil") 34 35 path := "/tmp/index_advise.allegrosql" 36 fp, err := os.Create(path) 37 c.Assert(err, IsNil) 38 c.Assert(fp, NotNil) 39 defer func() { 40 err = fp.Close() 41 c.Assert(err, IsNil) 42 err = os.Remove(path) 43 c.Assert(err, IsNil) 44 }() 45 46 _, err = fp.WriteString("\n" + 47 "select * from t;\n" + 48 "\n" + 49 "select * from t where a > 1;\n" + 50 "select a from t where a > 1 and a < 100;\n" + 51 "\n" + 52 "\n" + 53 "select a,b from t1,t2 where t1.a = t2.b;\n" + 54 "\n") 55 c.Assert(err, IsNil) 56 57 // TODO: Using "tastCase" to do more test when we finish the index advisor completely. 58 tk.MustInterDirc("index advise local infile '/tmp/index_advise.allegrosql' max_minutes 3 max_idxnum per_block 4 per_db 5") 59 ctx := tk.Se.(stochastikctx.Context) 60 ia, ok := ctx.Value(interlock.IndexAdviseVarKey).(*interlock.IndexAdviseInfo) 61 defer ctx.SetValue(interlock.IndexAdviseVarKey, nil) 62 c.Assert(ok, IsTrue) 63 c.Assert(ia.MaxMinutes, Equals, uint64(3)) 64 c.Assert(ia.MaxIndexNum.PerBlock, Equals, uint64(4)) 65 c.Assert(ia.MaxIndexNum.PerDB, Equals, uint64(5)) 66 67 }