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 6107785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:13:33+00:00 2026-05-23T14:13:33+00:00

MyModel.objects.all().order_by(‘-timestamp’) There is a unique key on timestamp and another column: `code` varchar(3) NOT

  • 0
MyModel.objects.all().order_by('-timestamp')

There is a unique key on timestamp and another column:

`code` varchar(3) NOT NULL,
`timestamp` date NOT NULL,
 UNIQUE KEY `exchangerate_currency_70883b95_uniq` (`code`,`timestamp`)

All I want is to obtain the latest row in the table.
The query achieves that but I am thinking of the future when it will grow to 100K rows.
Are there glaring performance problems with this query & schema ?

  • 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-23T14:13:34+00:00Added an answer on May 23, 2026 at 2:13 pm

    Without seeing your full query, and your schema, it’s impossible to do more than speculate.

    But… I believe the order of columns in a multi-column index in MySQL is important. This would mean that your index on (code,timestamp) is likely unusable for ordering by timestamp. If you changed the order to instead be (timestamp,code), it probably would be useable for ORDER BY timestamp, however it may hurt performance for other queries.

    If your usage requires an index for both, you may need to create a second index on just the timestamp column.

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

Sidebar

Related Questions

I cannot run ['abc'].append( MyModel.objects.all() ) since it generates exception 'NoneType' object is not
In django - is there a default timestamp field for all objects? That is,
I'm doing this query: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() I normally have an aggregate field in my model
I want to return a filtered version of queryset when MyModel.objects.all() method is invoked.
Is there any documentation about how django handles different ORM problems/errors for methods: MyModel.objects.get(name='myname')
is there a way to do the following in one Django query? MyModel.filter(attr=a).values('attr','fields','of','interest').annotate(count=Count('id')) MyModel.filter(attr=b).values('attr','fields','of','interest').annotate(count=Count('id'))
I have a model where because of a code bug, there are duplicate rows.
I'm trying to fetch all expired objects for a model in my Django application.
As described in another question , I have a set of Model objects and
I have this code in my model when the controller requests to get all

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.