Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: support pushing down predicates to memory tables in prepared mode (#40262) #42640

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
merge conflict
Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
  • Loading branch information
YangKeao committed Mar 28, 2023
commit 2b1de7e54e44b1188b3b23212b253aa011f19efb
3 changes: 0 additions & 3 deletions expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1429,8 +1429,6 @@ func PropagateType(evalType types.EvalType, args ...Expression) {
}
}
}
<<<<<<< HEAD
=======

// Args2Expressions4Test converts these values to an expression list.
// This conversion is incomplete, so only use for test.
Expand Down Expand Up @@ -1461,4 +1459,3 @@ func Args2Expressions4Test(args ...interface{}) []Expression {
}
return exprs
}
>>>>>>> 95f0dc547e9 (planner: support pushing down predicates to memory tables in prepared mode (#40262))
22 changes: 11 additions & 11 deletions planner/core/memtable_predicate_extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package core_test

import (
"context"
"fmt"
"regexp"
"sort"
"testing"
"time"

"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/planner"
Expand All @@ -34,6 +34,7 @@ import (
"github.com/pingcap/tidb/util/hint"
"github.com/pingcap/tidb/util/set"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

func getLogicalMemTable(t *testing.T, dom *domain.Domain, se session.Session, parser *parser.Parser, sql string) *plannercore.LogicalMemTable {
Expand Down Expand Up @@ -1748,7 +1749,8 @@ func TestTikvRegionStatusExtractor(t *testing.T) {
}

func TestExtractorInPreparedStmt(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
store, dom, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()
tk := testkit.NewTestKit(t, store)

var cases = []struct {
Expand Down Expand Up @@ -1803,6 +1805,7 @@ func TestExtractorInPreparedStmt(t *testing.T) {
prepared: "select * from information_schema.tidb_hot_regions_history where update_time>=?",
userVars: []interface{}{"cast('2019-10-10 10:10:10' as datetime)"},
params: []interface{}{func() types.Time {
tk.Session().GetSessionVars().StmtCtx.TimeZone = time.Local
tt, err := types.ParseTimestamp(tk.Session().GetSessionVars().StmtCtx, "2019-10-10 10:10:10")
require.NoError(t, err)
return tt
Expand Down Expand Up @@ -1832,26 +1835,23 @@ func TestExtractorInPreparedStmt(t *testing.T) {
tk.MustExec(setStmt)
stmt, err := parser.ParseOneStmt(exec, "", "")
require.NoError(t, err)
plan, _, err := planner.OptimizeExecStmt(context.Background(), tk.Session(), stmt.(*ast.ExecuteStmt), dom.InfoSchema())
plan, err := planner.OptimizeExecStmt(context.Background(), tk.Session(), stmt.(*ast.ExecuteStmt), dom.InfoSchema())
require.NoError(t, err)
extractor := plan.(*plannercore.Execute).Plan.(*plannercore.PhysicalMemTable).Extractor
extractor := plan.(*plannercore.PhysicalMemTable).Extractor
ca.checker(extractor)
}

// binary protocol
for _, ca := range cases {
id, _, _, err := tk.Session().PrepareStmt(ca.prepared)
require.NoError(t, err)
prepStmt, err := tk.Session().GetSessionVars().GetPreparedStmtByID(id)
require.NoError(t, err)
params := expression.Args2Expressions4Test(ca.params...)
execStmt := &ast.ExecuteStmt{
BinaryArgs: params,
PrepStmt: prepStmt,
BinaryArgs: types.MakeDatums(ca.params...),
ExecID: id,
}
plan, _, err := planner.OptimizeExecStmt(context.Background(), tk.Session(), execStmt, dom.InfoSchema())
plan, err := planner.OptimizeExecStmt(context.Background(), tk.Session(), execStmt, dom.InfoSchema())
require.NoError(t, err)
extractor := plan.(*plannercore.Execute).Plan.(*plannercore.PhysicalMemTable).Extractor
extractor := plan.(*plannercore.PhysicalMemTable).Extractor
ca.checker(extractor)
}
}