vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/queries/foundrows/found_rows_test.go (about) 1 /* 2 Copyright 2021 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package foundrows 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/require" 23 24 "vitess.io/vitess/go/test/endtoend/cluster" 25 "vitess.io/vitess/go/test/endtoend/utils" 26 ) 27 28 func TestFoundRows(t *testing.T) { 29 defer cluster.PanicHandler(t) 30 mcmp, err := utils.NewMySQLCompare(t, vtParams, mysqlParams) 31 require.NoError(t, err) 32 defer mcmp.Close() 33 34 _, _ = mcmp.ExecAndIgnore("delete from t2") 35 defer func() { 36 utils.Exec(t, mcmp.VtConn, "set workload = oltp") 37 _, _ = mcmp.ExecAndIgnore("delete from t2") 38 // queries against lookup tables do not need to be executed against MySQL 39 _, _ = utils.ExecAllowError(t, mcmp.VtConn, "delete from t2_id4_idx") 40 }() 41 42 mcmp.Exec("insert into t2(id3,id4) values(1,2), (2,2), (3,3), (4,3), (5,3)") 43 44 // Wait for schema tracking to run and mark t2 as authoritative before we try out the queries. 45 // Some of the queries depend on schema tracking to run successfully to be able to replace the StarExpr 46 // in the select clause with the definitive column list. 47 err = utils.WaitForAuthoritative(t, clusterInstance.VtgateProcess, keyspaceName, "t2") 48 require.NoError(t, err) 49 runTests := func(workload string) { 50 mcmp.AssertFoundRowsValue("select * from t2", workload, 5) 51 mcmp.AssertFoundRowsValue("select * from t2 order by id3 limit 2", workload, 2) 52 mcmp.AssertFoundRowsValue("select SQL_CALC_FOUND_ROWS * from t2 order by id3 limit 2", workload, 5) 53 mcmp.AssertFoundRowsValue("select SQL_CALC_FOUND_ROWS * from t2 where id3 = 4 order by id3 limit 2", workload, 1) 54 mcmp.AssertFoundRowsValue("select SQL_CALC_FOUND_ROWS * from t2 where id4 = 3 order by id3 limit 2", workload, 3) 55 mcmp.AssertFoundRowsValue("select SQL_CALC_FOUND_ROWS id4, count(id3) from t2 where id3 = 3 group by id4 limit 1", workload, 1) 56 } 57 58 runTests("oltp") 59 utils.Exec(t, mcmp.VtConn, "set workload = olap") 60 runTests("olap") 61 }