Files
tidb/executor/union_scan_test.go

64 lines
3.1 KiB
Go

// Copyright 2016 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package executor_test
import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testleak"
)
func (s *testSuite) TestDirtyTransaction(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)
}()
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a int primary key, b int, index idx_b (b));")
tk.MustExec("insert t value (2, 3), (4, 8), (6, 8)")
tk.MustExec("begin")
tk.MustQuery("select * from t").Check(testkit.Rows("2 3", "4 8", "6 8"))
tk.MustExec("insert t values (1, 5), (3, 4), (7, 6)")
tk.MustQuery("select * from information_schema.columns")
tk.MustQuery("select * from t").Check(testkit.Rows("1 5", "2 3", "3 4", "4 8", "6 8", "7 6"))
tk.MustQuery("select * from t where a = 1").Check(testkit.Rows("1 5"))
tk.MustQuery("select * from t order by a desc").Check(testkit.Rows("7 6", "6 8", "4 8", "3 4", "2 3", "1 5"))
tk.MustQuery("select * from t order by b, a").Check(testkit.Rows("2 3", "3 4", "1 5", "7 6", "4 8", "6 8"))
tk.MustQuery("select * from t order by b desc, a desc").Check(testkit.Rows("6 8", "4 8", "7 6", "1 5", "3 4", "2 3"))
tk.MustQuery("select b from t where b = 8 order by b desc").Check(testkit.Rows("8", "8"))
// Delete a snapshot row and a dirty row.
tk.MustExec("delete from t where a = 2 or a = 3")
tk.MustQuery("select * from t").Check(testkit.Rows("1 5", "4 8", "6 8", "7 6"))
tk.MustQuery("select * from t order by a desc").Check(testkit.Rows("7 6", "6 8", "4 8", "1 5"))
tk.MustQuery("select * from t order by b, a").Check(testkit.Rows("1 5", "7 6", "4 8", "6 8"))
tk.MustQuery("select * from t order by b desc, a desc").Check(testkit.Rows("6 8", "4 8", "7 6", "1 5"))
// Add deleted row back.
tk.MustExec("insert t values (2, 3), (3, 4)")
tk.MustQuery("select * from t").Check(testkit.Rows("1 5", "2 3", "3 4", "4 8", "6 8", "7 6"))
tk.MustQuery("select * from t order by a desc").Check(testkit.Rows("7 6", "6 8", "4 8", "3 4", "2 3", "1 5"))
tk.MustQuery("select * from t order by b, a").Check(testkit.Rows("2 3", "3 4", "1 5", "7 6", "4 8", "6 8"))
tk.MustQuery("select * from t order by b desc, a desc").Check(testkit.Rows("6 8", "4 8", "7 6", "1 5", "3 4", "2 3"))
// Truncate Table
tk.MustExec("truncate table t")
tk.MustQuery("select * from t").Check(testkit.Rows())
tk.MustExec("insert t values (1, 2)")
tk.MustQuery("select * from t").Check(testkit.Rows("1 2"))
tk.MustExec("truncate table t")
tk.MustExec("insert t values (3, 4)")
tk.MustQuery("select * from t").Check(testkit.Rows("3 4"))
tk.Exec("abort")
}