Skip to content

Commit

Permalink
bugfix #183
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfei1 committed Aug 2, 2016
1 parent 3f334a4 commit ab3961e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions core/hack/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hack

const (
Version = "2016-03-17 14:04:39 +0800 @358bd8f"
Compile = "2016-03-22 10:52:25 +0800 by go version go1.6 darwin/amd64"
Version = "2016-08-02 16:17:09 +0800 @3f334a4"
Compile = "2016-08-02 16:18:18 +0800 by go version go1.6 darwin/amd64"
)
19 changes: 9 additions & 10 deletions proxy/router/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ type Plan struct {
//the rows for insert or replace.
Rows map[int]sqlparser.Values

SubTableValueGroups map[int]sqlparser.ValTuple //按照tableIndex存放ValueExpr
InRightToReplace *sqlparser.ComparisonExpr //记录in的右边Expr,用来动态替换不同table in的值
RouteTableIndexs []int
RouteNodeIndexs []int
RewrittenSqls map[string][]string
SubTableValueGroups map[int]sqlparser.ValTuple //按照tableIndex存放ValueExpr
InRightToReplace *sqlparser.ComparisonExpr //记录in的右边Expr,用来动态替换不同table in的值
RouteTableIndexs []int
RouteNodeIndexs []int
RewrittenSqls map[string][]string
}

func (plan *Plan) notList(l []int) []int {
Expand Down Expand Up @@ -388,7 +388,8 @@ func (plan *Plan) getTableIndexByBoolExpr(node sqlparser.BoolExpr) ([]int, error
left := plan.getValueType(node.Left)
right := plan.getValueType(node.Right)
if left == EID_NODE && right == LIST_NODE {
plan.InRightToReplace=node
//save the node of in operation,will replace in
plan.InRightToReplace = node
return plan.getTableIndexs(node)
}
}
Expand All @@ -411,16 +412,14 @@ func (plan *Plan) getTableIndexsByTuple(valExpr sqlparser.ValExpr) ([]int, error
for _, n := range node {
//n.Format()
index, err := plan.getTableIndexByValue(n)

if err != nil {
return nil, err
}
valExprs := shardset[index]

if(valExprs==nil){
if valExprs == nil {
valExprs = make([]sqlparser.ValExpr, 0)
}
valExprs=append(valExprs,n)
valExprs = append(valExprs, n)
shardset[index] = valExprs
}
}
Expand Down
5 changes: 2 additions & 3 deletions proxy/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,12 @@ func (r *Router) rewriteSelectSql(plan *Plan, node *sqlparser.Select, tableIndex
newLimit = node.Limit
}

if(plan.InRightToReplace!=nil){
if plan.InRightToReplace != nil {
//assign corresponding values to different table index
plan.InRightToReplace.Right=plan.SubTableValueGroups[tableIndex]
plan.InRightToReplace.Right = plan.SubTableValueGroups[tableIndex]

}


buf.Fprintf("%v%v%v%v%v%s",
node.Where,
node.GroupBy,
Expand Down
6 changes: 3 additions & 3 deletions proxy/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ func checkPlan(t *testing.T, sql string, tableIndexs []int, nodeIndexs []int) {
t.Logf("rewritten_sql=%v", plan.RewrittenSqls)

}
func TestWhereInPartitionByTableIndex(t *testing.T){
func TestWhereInPartitionByTableIndex(t *testing.T) {
var sql string
//2016-03-06 13:37:26
sql = "select * from test1 where id in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22) "
checkPlan(t, sql,
[]int{0,1,2,3,4,5,6,7,8,9,10,11},
[]int{0,1,2},
[]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
[]int{0, 1, 2},
)
}

Expand Down

0 comments on commit ab3961e

Please sign in to comment.