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:
parent
885f582677
commit
4f8f829913
|
@ -392,7 +392,7 @@ func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interfac
|
||||||
} else if statement.dialect.URI().DBType == schemas.ORACLE {
|
} else if statement.dialect.URI().DBType == schemas.ORACLE {
|
||||||
sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE (%s) %s AND ROWNUM=1", tableName, joinStr, condSQL)
|
sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE (%s) %s AND ROWNUM=1", tableName, joinStr, condSQL)
|
||||||
} else {
|
} 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
|
args = condArgs
|
||||||
} else {
|
} else {
|
||||||
|
@ -401,7 +401,7 @@ func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interfac
|
||||||
} else if statement.dialect.URI().DBType == schemas.ORACLE {
|
} else if statement.dialect.URI().DBType == schemas.ORACLE {
|
||||||
sqlStr = fmt.Sprintf("SELECT * FROM %s %s WHERE ROWNUM=1", tableName, joinStr)
|
sqlStr = fmt.Sprintf("SELECT * FROM %s %s WHERE ROWNUM=1", tableName, joinStr)
|
||||||
} else {
|
} 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{}{}
|
args = []interface{}{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue