diff options
author | Dobes Vandermeer <dvandermeer@roovy.com> | 2014-04-25 10:46:30 -0700 |
---|---|---|
committer | Dobes Vandermeer <dvandermeer@roovy.com> | 2014-04-25 10:46:30 -0700 |
commit | a218eaee2b426496f682922bb9558bc3e581e77e (patch) | |
tree | 30379a97e7d5cbb656ea1e1a4502c58fb0267df5 | |
parent | 262fef0b4ac2a8d14117662786d3af8e9a4424eb (diff) | |
download | sqlalchemy-a218eaee2b426496f682922bb9558bc3e581e77e.tar.gz |
Pull out offset/limit to a local variable to reduce the impact of the inefficient select._offset and select._limit operations.
-rw-r--r-- | lib/sqlalchemy/dialects/oracle/base.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index 8bacb885f..ace7d80ca 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -652,24 +652,26 @@ class OracleCompiler(compiler.SQLCompiler): # Wrap the middle select and add the hint limitselect = sql.select([c for c in select.c]) - if select._limit and self.dialect.optimize_limits: - limitselect = limitselect.prefix_with("/*+ FIRST_ROWS(%d) */" % select._limit) + limit = select._limit + if limit and self.dialect.optimize_limits: + limitselect = limitselect.prefix_with("/*+ FIRST_ROWS(%d) */" % limit) limitselect._oracle_visit = True limitselect._is_wrapper = True # If needed, add the limiting clause - if select._limit is not None: - max_row = select._limit - if select._offset is not None: - max_row += select._offset + offset = select._offset + if limit is not None: + max_row = limit + if offset is not None: + max_row += offset if not self.dialect.use_binds_for_limits: max_row = sql.literal_column("%d" % max_row) limitselect.append_whereclause( sql.literal_column("ROWNUM") <= max_row) # If needed, add the ora_rn, and wrap again with offset. - if select._offset is None: + if offset is None: limitselect._for_update_arg = select._for_update_arg select = limitselect else: @@ -683,7 +685,7 @@ class OracleCompiler(compiler.SQLCompiler): offsetselect._oracle_visit = True offsetselect._is_wrapper = True - offset_value = select._offset + offset_value = offset if not self.dialect.use_binds_for_limits: offset_value = sql.literal_column("%d" % offset_value) offsetselect.append_whereclause( |