exist方法sql语句优化 (#2075)

本地没有mssql和oracle,所以没法测试,但是,mysql 使用select 1 from TABLENAME where CONDITION limit 1可能更好

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2075
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: linbaozhong <linbaozhong@noreply.gitea.io>
Co-committed-by: linbaozhong <linbaozhong@noreply.gitea.io>
This commit is contained in:
linbaozhong 2021-12-01 13:54:47 +08:00 committed by Lunny Xiao
parent 885f582677
commit 4f8f829913
1 changed files with 2 additions and 2 deletions

View File

@ -392,7 +392,7 @@ func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interfac
} else if statement.dialect.URI().DBType == schemas.ORACLE {
sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE (%s) %s AND ROWNUM=1", tableName, joinStr, condSQL)
} else {
sqlStr = fmt.Sprintf("SELECT * FROM %s %s WHERE %s LIMIT 1", tableName, joinStr, condSQL)
sqlStr = fmt.Sprintf("SELECT 1 FROM %s %s WHERE %s LIMIT 1", tableName, joinStr, condSQL)
}
args = condArgs
} else {
@ -401,7 +401,7 @@ func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interfac
} else if statement.dialect.URI().DBType == schemas.ORACLE {
sqlStr = fmt.Sprintf("SELECT * FROM %s %s WHERE ROWNUM=1", tableName, joinStr)
} else {
sqlStr = fmt.Sprintf("SELECT * FROM %s %s LIMIT 1", tableName, joinStr)
sqlStr = fmt.Sprintf("SELECT 1 FROM %s %s LIMIT 1", tableName, joinStr)
}
args = []interface{}{}
}