summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChangBo Guo(gcb) <eric.guo@easystack.cn>2017-02-06 10:38:05 +0800
committerChangBo Guo(gcb) <eric.guo@easystack.cn>2017-02-06 23:24:35 +0800
commit9fb3c018fc16c8f5b781c119dd3c148ed7954db7 (patch)
tree616a323a837e5d329883416b7f2e40517da28112
parentfcc794f531777ed1b80962ad700a166bff8c47c6 (diff)
downloadoslo-db-9fb3c018fc16c8f5b781c119dd3c148ed7954db7.tar.gz
Explain paginate_query doesn't provide parameter offset
OFFSET is a terrible thing to use. It seems to work great when you first use it because your table is only a few hundred rows. six months later, everyone complains the app is incredibly slow - it's because the database is being killed doing linear scans through millions of rows because everyone's doing OFFSET. It not only causes slow and unusable applications but hurts everyone by adding tons of meaningless work to the DB load overall. This pagination function already does the "right" way, which is to order the rows and use WHERE criteria (See http://use-the-index-luke.com/no-offset). This commit add docstring to explain why don't need offset. Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: I6fdb094085d133c8910415efea2eb44225a66216
-rw-r--r--oslo_db/sqlalchemy/utils.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/oslo_db/sqlalchemy/utils.py b/oslo_db/sqlalchemy/utils.py
index 97a28c6..f3db1dc 100644
--- a/oslo_db/sqlalchemy/utils.py
+++ b/oslo_db/sqlalchemy/utils.py
@@ -155,6 +155,11 @@ def paginate_query(query, model, limit, sort_keys, marker=None,
marker, then the actual marker object must be fetched from the db and
passed in to us as marker.
+ The "offset" parameter is intentionally avoided. As offset requires a
+ full scan through the preceding results each time, criteria-based
+ pagination is preferred. See http://use-the-index-luke.com/no-offset
+ for further background.
+
:param query: the query object to which we should add paging/sorting
:param model: the ORM model class
:param limit: maximum number of items to return