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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:23:58+00:00 2026-06-12T11:23:58+00:00

I have a table briefly structured like this: tn( id integer NOT NULL primary

  • 0

I have a table briefly structured like this:

tn( id integer NOT NULL primary key DEFAULT nextval('tn_sequence'),
                 create_dt TIMESTAMP NOT NULL DEFAULT NOW(),
                             ...............
                 deleted boolean );

create_dt is the timestamp when the row is inserted into the database.

deleted indicates that the row is or no longer useful.

And I have the following queries:

select * from tn where create_dt > ( NOW() - interval '150 seconds ) and deleted = FALSE;
select * from tn where create_dt < ( NOW() - interval '150 seconds ) and deleted = FALSE;

My question is how these query will slow down when the number of rows increase? For instance, when the number of rows exceeds 10K, 20K, or 100K, will it make a big impact on the speed? Is there any way I can optimize these queries? Note that every 5 seconds I will turn the column ‘deleted’ of rows which are older than 150 seconds into ‘TRUE’.

  • 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-06-12T11:23:59+00:00Added an answer on June 12, 2026 at 11:23 am

    The effect of table growth on performance will depend on the query plan chosen, available indexes, the selectivity of the query, and lots of other factors. EXPLAIN ANALYZE on the query might help. In short, if your query only selects a few rows and can use a simple b-tree index then it won’t usually slow down tons, only a little as the index grows. On the other hand queries using complex non-indexed conditions or returning lots of rows could perform very badly indeed.

    Your issue appears to mirror that in the question How should we handle rows which won’t be queried once they are old in PostgreSQL?

    The advice given there should apply:

    • Use a partial index with the condition WHERE (not deleted); or
    • partition on ‘deleted’ with constraint exclusion enabled.

    For example, you might:

    CREATE INDEX create_dt_when_not_deleted_idx 
    ON tn (create_dt)
    WHERE (NOT deleted);
    

    This includes only rows where deleted = 'f' (assuming deleted is `not null) in the index. This isn’t the same as having them gone from the table completely.

    • Nothing changes with full table sequential scans, the deleted='t' rows must still be scanned; and
    • There’s more I/O than if the deleted = 't' rows weren’t there because any given heap page is likely to contain a mix of deleted = 't' and deleted = 'f' rows.

    You can reduce the impact of the latter by CLUSTERing on an index that includes deleted. Again, this will have no effect on sequential scans. To help with sequential scans you would have to partition the table on deleted.

    Pg 9.2’s index only scans should (I think, haven’t tested) use the partial index. When an index only scan is possible the partial index should be as fast as an index on a table containing only the deleted = 'f' rows.

    Note that you’ll need to keep table and index bloat under control. Ensure autovaccum runs very frequently and use a current version of PostgreSQL that doesn’t need things like manually-managed free space map and has the latest, best-behaved autovacuum. I’d recommend 9.0 or above, preferably 9.1 or 9.2. Tune autovacuum to run aggressively.

    When tuning and testing performance – test your queries with EXPLAIN ANALYZE, don’t just guess.

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

Sidebar

Related Questions

I have table named A with column B defined int not null Primary Key
I have table as below personalInfo CREATE TABLE personalInfo(userid BIGINT AUTO_INCREMENT PRIMARY KEY) patentInfo
I have table and this table contain result column with some entries. I just
I have table with 300 000 records (MyISAM). I get record from this table
I have table with two columns (varchar from, varchar to). This table represents connections
i have few questions for SQL gurus in here ... Briefly this is ads
I want to be able to do something like this quickly: I have a
i have table (MEN) with 900,000 records. in this table i have field IP
I have table tblsale . In this table i have field called BillType ,
Briefly, I have a database table of events with start date and end date

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.