func getMatch(node sqlparser.BoolExpr, index *Index) (planID PlanID, values interface{}) { switch node := node.(type) { case *sqlparser.AndExpr: if planID, values = getMatch(node.Left, index); planID != SelectScatter { return planID, values } if planID, values = getMatch(node.Right, index); planID != SelectScatter { return planID, values } case *sqlparser.ParenBoolExpr: return getMatch(node.Expr, index) case *sqlparser.ComparisonExpr: switch node.Operator { case "=": if !nameMatch(node.Left, index.Column) { return SelectScatter, nil } if !sqlparser.IsValue(node.Right) { return SelectScatter, nil } val, err := sqlparser.AsInterface(node.Right) if err != nil { return SelectScatter, nil } if index.Type == ShardKey { planID = SelectSingleShardKey } else { planID = SelectSingleLookup } return planID, val case "in": if !nameMatch(node.Left, index.Column) { return SelectScatter, nil } if !sqlparser.IsSimpleTuple(node.Right) { return SelectScatter, nil } val, err := sqlparser.AsInterface(node.Right) if err != nil { return SelectScatter, nil } node.Right = sqlparser.ListArg("::_vals") if index.Type == ShardKey { planID = SelectMultiShardKey } else { planID = SelectMultiLookup } return planID, val } } return SelectScatter, nil }
func getMatch(node sqlparser.BoolExpr, col string) (planID PlanID, values interface{}) { switch node := node.(type) { case *sqlparser.AndExpr: if planID, values = getMatch(node.Left, col); planID != SelectScatter { return planID, values } if planID, values = getMatch(node.Right, col); planID != SelectScatter { return planID, values } case *sqlparser.ParenBoolExpr: return getMatch(node.Expr, col) case *sqlparser.ComparisonExpr: switch node.Operator { case "=": if !nameMatch(node.Left, col) { return SelectScatter, nil } if !sqlparser.IsValue(node.Right) { return SelectScatter, nil } val, err := asInterface(node.Right) if err != nil { return SelectScatter, nil } return SelectEqual, val case "in": if !nameMatch(node.Left, col) { return SelectScatter, nil } if !sqlparser.IsSimpleTuple(node.Right) { return SelectScatter, nil } val, err := asInterface(node.Right) if err != nil { return SelectScatter, nil } node.Right = sqlparser.ListArg("::" + ListVarName) return SelectIN, val } } return SelectScatter, nil }