modify limit offset implement #2188
No reviewers
Labels
No Label
backport/done
backport/v1
blocked
db
oracle
db
sqlserver
duplicate
feature
cache
frontport/done
frontport/main
invalid
kind
breaking
kind
bug
kind
build
kind
dependencies
kind
docs
kind
driver
kind
enhancement
kind
feature
kind
performance
kind
proposal
kind
question
kind
refactor
kind
testing
need
feedback
need
test
proposal:accepted
RaspBerry Pi
regression
skip-changelog
upstream
wip
wontfix
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: xorm/xorm#2188
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "FlyingOnion/xorm:master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Oracle and SQLServer specific: When
LIMIT OFFSET
function is needed, useOFFSET <offset> ROWS FETCH NEXT <limit> ROWS ONLY
to replace legacy subquery.SQLServer specific: When
ORDER BY
is not set andOFFSET FETCH
is set, setstatement.orderStr
to1
(ORDER BY 1
). See here.MySQL specific: When limit is 0 and offset > 0, use
LIMIT 9223372036854775807
($2^{63}-1$). See comments here.Test result:
@ -207,7 +207,7 @@ func (statement *Statement) writeLimitOffset(w builder.Writer) error {
_, err := fmt.Fprintf(w, " LIMIT %v OFFSET %v", *statement.LimitN, statement.Start)
return err
}
_, err := fmt.Fprintf(w, " LIMIT 0 OFFSET %v", statement.Start)
Should not use
LIMIT 0
here, MySQL will return 0 row(s).@lunny Is it able to merge?
Since it's a break change(some MSSQL version will not be supported), I have to do it carefully but the PR is ready.
This requires SQL Server 2012, maybe we can have a global variable to switch.
CI failure is related.
ORDER BY is mandatory to use OFFSET and FETCH clause.
Shall we add
ORDER BY 1
(order by the first column) ifstatement.HasOrderBy()
is false?@lunny
If there is a primary key, use primary key asc, otherwise the first column asc ?
How about to add an option to fall back to old method.
modify limit offset implementto WIP: modify limit offset implementSorry for late response. My computer got repaired, so the PR remains WIP.
Still working on it.
It's dialect-dependent (mostly used in SQLServer and Oracle) so maybe
func NewEngineWithParams
is a good place to set the option.39ac77bdc9
to3726353ad0
Hi @lunny
Could you grant me the permission to run tests? I'm not able to run it with my own runner because of poor network. I have tried several ways to deal with it but all failed.
Thank you very much.
OK now.
db29839631
to50ed5f6bca
f4cc1db4ba
to9ccf24b957
WIP: modify limit offset implementto modify limit offset implement@lunny
I finished the task and passed all unit tests, but these tests do not contain
NewEngineWithParams
orengine.SetParams
, so legacy cases are not tested at all.Should an extra job be added in
test-mssql
? Or open another issue?There are still two files conflicted?
bc896febff
to9b0829fb30
@lunny
In this case the unit test failed.
As you commented, it happened when
statement.writeSelect
removed parameterneedOrderBy
. TheORDER BY
clause is always added (iflen(statement.orderStr) > 0
), which is what a former commit did in my fork (it has been overwritten by merging upstream master).If we still keep
needOrderBy
, an error may occur when it's false with.Limit
and.Offset
in sqlserver.I suggest we remove
.OrderBy("`name`")
in the unit test. IMO the result of calling.OrderBy().Count()
should be left to the database itself to decide. ORM should not do extra pruning. The error message is also clear enough for developers to modify their code.Besides, it's of no use to use
ORDER BY
incount(*)
.@ -0,0 +1,55 @@
package statements
Please add copyright header.