diff --git a/ast/meta.go b/ast/meta.go index 9015087ea713d8e666df2df300a6768e2eb5bb2a..1f955127a9fb6a456180422e0d9af90e514ca208 100644 --- a/ast/meta.go +++ b/ast/meta.go @@ -279,7 +279,8 @@ func FindEQColsInWhere(node sqlparser.SQLNode) []*common.Column { err := sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) { switch node := node.(type) { // 对AST中所有节点进行扫描 - case *sqlparser.Subquery, *sqlparser.JoinTableExpr, *sqlparser.BinaryExpr, *sqlparser.OrExpr: + case *sqlparser.Subquery, *sqlparser.JoinTableExpr, *sqlparser.BinaryExpr, *sqlparser.OrExpr, + *sqlparser.CaseExpr, *sqlparser.FuncExpr: // 忽略子查询,join condition,数值计算,or condition return false, nil diff --git a/ast/meta_test.go b/ast/meta_test.go index 653491d16919b8fd2cd28c441b31ddcb517b1e9b..40f43e8b9cd076f8d3d5b3485e454b1ba0486863 100644 --- a/ast/meta_test.go +++ b/ast/meta_test.go @@ -87,6 +87,7 @@ func TestFindCondition(t *testing.T) { common.Log.Debug("Entering function: %s", common.GetFunctionName()) sqls := []string{ `SELECT * FROM film WHERE length % 20 = 4;`, + `select * from actor where actor_id = 1 order by if(first_name="PENELOPE", last_name, "") desc`, } for _, sql := range append(sqls, common.TestSQLs...) { fmt.Println(sql) diff --git a/common/testdata/TestPrintConfiguration.golden b/common/testdata/TestPrintConfiguration.golden index f856aafdf30f3048d26da8019e170627b7ed7350..ffb78414e2f38086a02d1d34247c9c9aa80a1a79 100644 --- a/common/testdata/TestPrintConfiguration.golden +++ b/common/testdata/TestPrintConfiguration.golden @@ -39,6 +39,7 @@ test-dsn: allow-old-passwords: false disable: false allow-online-as-test: true +disable-version-check: false drop-test-temporary: true cleanup-test-database: false only-syntax-check: false diff --git a/test/fixture/test_Check_the_default_config_of_the_changes.golden b/test/fixture/test_Check_the_default_config_of_the_changes.golden index 69232552ae207d68fe11223a5a4603051f87bc4b..b1bc2a440f7536553c9b0ce37764cb58e753e40b 100644 --- a/test/fixture/test_Check_the_default_config_of_the_changes.golden +++ b/test/fixture/test_Check_the_default_config_of_the_changes.golden @@ -39,6 +39,7 @@ test-dsn: allow-old-passwords: true disable: false allow-online-as-test: true +disable-version-check: false drop-test-temporary: false cleanup-test-database: true only-syntax-check: true diff --git a/test/fixture/test_Run_all_test_cases.golden b/test/fixture/test_Run_all_test_cases.golden index 173d337216f009b6a9a1c9eee48048c26f08b015..c2769d39ef2a8c367f636849f3c5724366c4469a 100644 --- a/test/fixture/test_Run_all_test_cases.golden +++ b/test/fixture/test_Run_all_test_cases.golden @@ -2455,7 +2455,7 @@ FROM | 1 | PRIMARY | *b* | NULL | eq\_ref | PRIMARY | PRIMARY | 2 | sakila.a.country\_id | 1 | ☠️ **100.00%** | O(log n) | NULL | | 2 | UNION | *b* | NULL | ALL | NULL | NULL | NULL | NULL | 109 | ☠️ **100.00%** | ☠️ **O(n)** | NULL | | 2 | UNION | *a* | NULL | ref | idx\_fk\_country\_id | idx\_fk\_country\_id | 2 | sakila.b.country\_id | 5 | ☠️ **100.00%** | O(log n) | NULL | -| 3 | UNION RESULT | ** | NULL | ALL | NULL | NULL | NULL | NULL | 0 | n% | ☠️ **O(n)** | Using temporary | +| 2 | UNION | *a* | NULL | ref | idx\_fk\_country\_id | idx\_fk\_country\_id | 2 | sakila.b.country\_id | 5 | ☠️ **100.00%** | O(log n) | NULL | @@ -2465,8 +2465,6 @@ FROM * **PRIMARY**: 最外层的select. -* **UNION RESULT**: UNION查询的结果集. - * **UNION**: UNION中的第二个或后面的SELECT查询, 不依赖于外部查询的结果集. #### Type信息解读 @@ -2477,10 +2475,6 @@ FROM * ☠️ **ALL**: 最坏的情况, 从头到尾全表扫描. -#### Extra信息解读 - -* ☠️ **Using temporary**: 表示MySQL在对查询结果排序时使用临时表. 常见于排序order by和分组查询group by. - ## 建议使用 AS 关键字显示声明一个别名 @@ -2537,7 +2531,7 @@ WHERE | 1 | PRIMARY | *a* | NULL | ref | idx\_fk\_country\_id | idx\_fk\_country\_id | 2 | sakila.b.country\_id | 5 | n% | O(log n) | Using where; Not exists | | 2 | UNION | *a* | NULL | ALL | NULL | NULL | NULL | NULL | 600 | ☠️ **100.00%** | ☠️ **O(n)** | NULL | | 2 | UNION | *b* | NULL | eq\_ref | PRIMARY | PRIMARY | 2 | sakila.a.country\_id | 1 | n% | O(log n) | Using where; Not exists | -| 3 | UNION RESULT | ** | NULL | ALL | NULL | NULL | NULL | NULL | 0 | n% | ☠️ **O(n)** | Using temporary | +| 2 | UNION | *b* | NULL | eq\_ref | PRIMARY | PRIMARY | 2 | sakila.a.country\_id | 1 | n% | O(log n) | Using where; Not exists | @@ -2547,8 +2541,6 @@ WHERE * **PRIMARY**: 最外层的select. -* **UNION RESULT**: UNION查询的结果集. - * **UNION**: UNION中的第二个或后面的SELECT查询, 不依赖于外部查询的结果集. #### Type信息解读 @@ -2565,8 +2557,6 @@ WHERE * **Using where**: WHERE条件用于筛选出与下一个表匹配的数据然后返回给客户端. 除非故意做的全表扫描, 否则连接类型是ALL或者是index, 且在Extra列的值中没有Using Where, 则该查询可能是有问题的. -* ☠️ **Using temporary**: 表示MySQL在对查询结果排序时使用临时表. 常见于排序order by和分组查询group by. - ## 为sakila库的city表添加索引 @@ -3827,7 +3817,7 @@ FROM | 1 | PRIMARY | *o* | NULL | eq\_ref | PRIMARY | PRIMARY | 2 | sakila.i.city\_id | 1 | ☠️ **100.00%** | O(log n) | NULL | | 2 | UNION | *o* | NULL | ALL | NULL | NULL | NULL | NULL | 109 | ☠️ **100.00%** | ☠️ **O(n)** | NULL | | 2 | UNION | *i* | NULL | eq\_ref | PRIMARY | PRIMARY | 2 | sakila.o.country\_id | 1 | ☠️ **100.00%** | O(log n) | NULL | -| 3 | UNION RESULT | ** | NULL | ALL | NULL | NULL | NULL | NULL | 0 | n% | ☠️ **O(n)** | Using temporary | +| 2 | UNION | *i* | NULL | eq\_ref | PRIMARY | PRIMARY | 2 | sakila.o.country\_id | 1 | ☠️ **100.00%** | O(log n) | NULL | @@ -3837,8 +3827,6 @@ FROM * **PRIMARY**: 最外层的select. -* **UNION RESULT**: UNION查询的结果集. - * **UNION**: UNION中的第二个或后面的SELECT查询, 不依赖于外部查询的结果集. #### Type信息解读 @@ -3847,10 +3835,6 @@ FROM * ☠️ **ALL**: 最坏的情况, 从头到尾全表扫描. -#### Extra信息解读 - -* ☠️ **Using temporary**: 表示MySQL在对查询结果排序时使用临时表. 常见于排序order by和分组查询group by. - ## 建议使用 AS 关键字显示声明一个别名 @@ -4001,7 +3985,7 @@ WHERE | 1 | PRIMARY | *o* | NULL | eq\_ref | PRIMARY | PRIMARY | 2 | sakila.i.city\_id | 1 | ☠️ **100.00%** | O(log n) | Using where; Not exists | | 2 | UNION | *o* | NULL | ALL | NULL | NULL | NULL | NULL | 109 | ☠️ **100.00%** | ☠️ **O(n)** | NULL | | 2 | UNION | *i* | NULL | eq\_ref | PRIMARY | PRIMARY | 2 | sakila.o.country\_id | 1 | ☠️ **100.00%** | O(log n) | Using where; Not exists | -| 3 | UNION RESULT | ** | NULL | ALL | NULL | NULL | NULL | NULL | 0 | n% | ☠️ **O(n)** | Using temporary | +| 2 | UNION | *i* | NULL | eq\_ref | PRIMARY | PRIMARY | 2 | sakila.o.country\_id | 1 | ☠️ **100.00%** | O(log n) | Using where; Not exists | @@ -4011,8 +3995,6 @@ WHERE * **PRIMARY**: 最外层的select. -* **UNION RESULT**: UNION查询的结果集. - * **UNION**: UNION中的第二个或后面的SELECT查询, 不依赖于外部查询的结果集. #### Type信息解读 @@ -4027,8 +4009,6 @@ WHERE * **Using where**: WHERE条件用于筛选出与下一个表匹配的数据然后返回给客户端. 除非故意做的全表扫描, 否则连接类型是ALL或者是index, 且在Extra列的值中没有Using Where, 则该查询可能是有问题的. -* ☠️ **Using temporary**: 表示MySQL在对查询结果排序时使用临时表. 常见于排序order by和分组查询group by. - ## 建议使用 AS 关键字显示声明一个别名 diff --git a/test/fixture/test_Run_default_printconfig_cases.golden b/test/fixture/test_Run_default_printconfig_cases.golden index 241b87549441fc583135d379f89ddf7db6064319..2e5334b38fe8cf0aefb2ba9e99fedf27f70eacb9 100644 --- a/test/fixture/test_Run_default_printconfig_cases.golden +++ b/test/fixture/test_Run_default_printconfig_cases.golden @@ -39,6 +39,7 @@ test-dsn: allow-old-passwords: false disable: false allow-online-as-test: false +disable-version-check: false drop-test-temporary: true cleanup-test-database: false only-syntax-check: false