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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:27:45+00:00 2026-05-26T04:27:45+00:00

Disclaimer: I am newbie in database world I wonder: How do you solve the

  • 0

Disclaimer: I am newbie in database world

I wonder: How do you solve the problem of an always-growing table?

I mean, suppose I would like to know “the last added item”, then I do

SELECT * FROM planetHistory WHERE name=”earth” ORDER BY date DESC
LIMIT 1;

That seems to be a bad idea because it would take more and more time as table grows.
What come to my mind is to “prepare” the design of database for the usual future queries. For this example the database could include a table with a single field and a instance:

+-----------------+
|table "lastAdded"|
+-----------------+
|     3242        |
+-----------------+

That would store the last added, so before doing the insert I should read that field increment it by one and then write it.

It sound weird, but it seems worse for me to order 1 Terabyte of data “just to know which is the last” that’s weirder

  • 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-26T04:27:46+00:00Added an answer on May 26, 2026 at 4:27 am

    Ordering by an indexed column does this kind of optimization ‘under the hood’ for you.

    Let the DB designers worry about optimizing query logic, just make sure you utilize the tools they give you like INDEXes. It is their job to ensure queries, even over millions of records, are performant enough.

    Doing this kind of ‘optimization’ yourself may cause several other problems:

    1. Duplicated data which could get out of sync
    2. Unnecessary complexity, assuming there was no performance problem in the first place
    3. Make it harder to fix real performance problems when they arise because more complex, code/queries means it is harder to refactor/optimize

    Monitor your app/DB so that you can pro-actively address performance problems but don’t solve them before you know there is a problem. Especially when it comes to DBs, they are built to be as fast as possible; when they aren’t fast, it is usually because of something we do which is silly.

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

Sidebar

Related Questions

Disclaimer: Hello all Python masters and fans. I would like to thank everyone for
Disclaimer: I'm a rails newbie, so I apologize if I'm going at this problem
Disclaimer: I know there are better ways to track email open rates, which are
Disclaimer: this question is purely informational and does not represent an actual problem I'm
Standard newbie disclaimer: I'm new to IoC and am getting mixed signals. I'm looking
DISCLAIMER: The following code is not something I would ever use in a real
Disclaimer: I'm working on Euler Problem 9. I'm adding up some pretty large numbers,
DISCLAIMER : I am still a Rails/Cucumber newbie but I am trying to learn.
disclaimer: I must use a microsoft access database and I cannot connect my app
Disclaimer: I don't actually know anything about nether Oracle nor Java. The issue is

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.