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

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Perhaps it can be made quicker... This was VERY interesting… May 11, 2026 at 6:35 pm
  • Editorial Team
    Editorial Team added an answer I'm assuming this is Java. MartinodF's quick and dirty toString().substring… May 11, 2026 at 6:35 pm
  • Editorial Team
    Editorial Team added an answer See my comment above asking for clarification on what you… May 11, 2026 at 6:35 pm

Related Questions

I'm trying to work out the correct way to handle populating an array with
suppose that I have this RDBM table ( Entity-attribute-value_model ): col1: entityID col2: attributeName
There's no strongly typed View() method to return an ActionResult. So, suppose I have
Suppose I have the following (rather common) model Client invokes web service request ->
I have only recently started working with the MVC approach, so I suppose this

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.