Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 203603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:23:36+00:00 2026-05-11T17:23:36+00:00

Suppose that I have the model Foo in GAE and this query: query =

  • 0

Suppose that I have the model Foo in GAE and this query:

query = Foo.all().order(‘-key‘)

I want to get the n-th record. What is the most efficient way to achieve that?

Will the solution break if the ordering property is not unique, such as the one below:

query = Foo.all().order(‘-color‘)

edit: n > 1000

edit 2: I want to develop a friendly paging mechanism that shows pages available (such as Page 1, Page 2, … Page 185) and requires a “?page=x” in the query string, instead of a “?bookmark=XXX”. When page = x, the query is to fetch the records beginning from the first record of that page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:23:36+00:00Added an answer on May 11, 2026 at 5:23 pm

    There is no efficient way to do this – in any DBMS. In every case, you have to at least read sequentially through the index records until you find the nth one, then look up the corresponding data record. This is more or less what fetch(count, offset) does in GAE, with the additional limitation of 1000 records.

    A better approach to this is to keep a ‘bookmark’, consisting of the value of the field you’re ordering on for the last entity you retrieved, and the entity’s key. Then, when you want to continue from where you left off, you can add the field’s value as the lower bound of an inequality query, and skip records until you match or exceed the last one you saw.

    If you want to provide ‘friendly’ page offsets to users, what you can do is to use memcache to store an association between a start offset and a bookmark (order_property, key) tuple. When you generate a page, insert or update the bookmark for the entity following the last one. When you fetch a page, use the bookmark if it exists, or generate it the hard way, by doing queries with offsets – potentially multiple queries if the offset is high enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been wondering, suppose I have a model with an attribute that in every
Suppose that you have two huge files (several GB) that you want to concatenate
Suppose that I have a Java program within an IDE (Eclipse in this case).
Suppose that I have a request handler that accepts an argument: key And let
Suppose that I have an integer variable in a class, and this variable may
I have a string vaguely like this: foo,bar,c;qual="baz,blurb",d;junk="quux,syzygy" that I want to split by
Suppose that i have a city that has many buildings. I want to create
Suppose I have this model: public class ViewModel { [Required] public string UserInput {
suppose that I have this RDBM table ( Entity-attribute-value_model ): col1: entityID col2: attributeName
Suppose you have an application that utilizes the domain-model pattern, DDD and lots of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.