提交 fedefa55 编写于 作者: martianzhang's avatar martianzhang

fix #226

  update table1 set a = ( select a from table2 where b=1 and c=2) and b=1 where d=2
  update table1 set a = ( select a from table2 where b=1 and c=2), b=1, c=2 where d=2

  replace test-cli percent number with n% for CI
上级 840a5cee
......@@ -1161,8 +1161,14 @@ func (q *Query4Audit) RuleUpdateSetAnd() Rule {
var rule = q.RuleOK()
switch s := q.Stmt.(type) {
case *sqlparser.Update:
if strings.Contains(sqlparser.String(s.Exprs), " and ") {
rule = HeuristicRules["RES.005"]
for _, c := range s.Exprs {
switch c.Expr.(type) {
case *sqlparser.Subquery:
default:
if strings.Contains(sqlparser.String(c), " and ") {
rule = HeuristicRules["RES.005"]
}
}
}
}
return rule
......
......@@ -792,10 +792,13 @@ func TestRuleUpdateSetAnd(t *testing.T) {
common.Log.Debug("Entering function: %s", common.GetFunctionName())
sqls := [][]string{
{
"update tbl set col = 1 and cl = 2 where col=3;",
"update tbl set col = 1 AND cl = 2 where col=3;",
"update table1 set a = ( select a from table2 where b=1 and c=2) and b=1 where d=2",
},
{
"update tbl set col = 1 ,cl = 2 where col=3;",
// https://github.com/XiaoMi/soar/issues/226
"update table1 set a = ( select a from table2 where b=1 and c=2), b=1, c=2 where d=2",
},
}
for _, sql := range sqls[0] {
......
......@@ -3,14 +3,14 @@
load test_helper
@test "Simple Query Optimizer" {
${SOAR_BIN_ENV} -query "select * from film where length > 120" | grep -v "散粒度" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
${SOAR_BIN_ENV} -query "select * from film where length > 120" | sed "s/ [0-9.]*%/ n%/g" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
echo "$output"
[ $status -eq 0 ]
}
@test "Run all test cases" {
${SOAR_BIN} -list-test-sqls | ${SOAR_BIN_ENV} | grep -v "散粒度" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
${SOAR_BIN} -list-test-sqls | ${SOAR_BIN_ENV} | sed "s/ [0-9.]*%/ n%/g" > ${BATS_TMP_DIRNAME}/${BATS_TEST_NAME}.golden
run golden_diff
echo "$output"
[ $status -eq 0 ]
......
......@@ -16,7 +16,7 @@ WHERE
| id | select\_type | table | partitions | type | possible_keys | key | key\_len | ref | rows | filtered | scalability | Extra |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | *film* | NULL | ALL | NULL | NULL | NULL | NULL | 1000 | 33.33% | ☠️ **O(n)** | Using where |
| 1 | SIMPLE | *film* | NULL | ALL | NULL | NULL | NULL | NULL | 1000 | n% | ☠️ **O(n)** | Using where |
......@@ -41,6 +41,7 @@ WHERE
* **Severity:** L2
* **Content:** 为列length添加索引,散粒度为: n%;
* **Case:** ALTER TABLE \`sakila\`.\`film\` add index \`idx\_length\` (\`length\`) ;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册