Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.0.X] Fixed #9136: Do slicing in Oracle with rownum instead of

row_number() for a speed improvement. Thanks, Guillaume Taglang.

Backport of [9235] from trunk.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3c5688d4e0fd3701a601bb4974879d93223db3fe 1 parent 36e90e5
Ian Kelly ikelly authored
Showing with 3 additions and 2 deletions.
  1. +3 −2 django/db/backends/oracle/
5 django/db/backends/oracle/
@@ -111,9 +111,10 @@ def as_sql(self, with_limits=True, with_col_aliases=False):
# Wrap the base query in an outer SELECT * with boundaries on
# the "_RN" column. This is the canonical way to emulate LIMIT
# and OFFSET on Oracle.
- sql = 'SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY 1) AS "_RN", "_SUB".* FROM (%s) "_SUB") WHERE "_RN" > %d' % (sql, self.low_mark)
+ high_where = ''
if self.high_mark is not None:
- sql = '%s AND "_RN" <= %d' % (sql, self.high_mark)
+ high_where = 'WHERE ROWNUM <= %d' % (self.high_mark,)
+ sql = 'SELECT * FROM (SELECT ROWNUM AS "_RN", "_SUB".* FROM (%s) "_SUB" %s) WHERE "_RN" > %d' % (sql, high_where, self.low_mark)
return sql, params
Please sign in to comment.
Something went wrong with that request. Please try again.