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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:49:06+00:00 2026-06-10T10:49:06+00:00

I have a Postgres table with about 4.5 million rows. The columns are basically

  • 0

I have a Postgres table with about 4.5 million rows. The columns are basically just

low BIGINT,
high BIGINT,
data1,
data2, 
...

When you query this table, you have a long integer, and want to find the data corresponding to the range between low and high that includes that value. What would be the best way to index this table for fast lookups?

  • 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-10T10:49:06+00:00Added an answer on June 10, 2026 at 10:49 am

    A multi-column index with reversed sort order:

    CREATE INDEX tbl_low_high_idx on tbl(low, high DESC);
    

    This way, the index can be scanned forward to where low is high enough, then take all rows until high is too low – all in one scan. That’s the main reason why sort order is implemented for indexes to begin with: to combine different sort orders in a multi-column index with different order. Basically, a b-tree index can be traversed in both directions at practically the same speed, so ASC / DESC would hardly be needed for single-column indexes.


    You may also be interested in the new range types of PostgreSQL 9.2. Can be indexed with a GiST index like this:

    CREATE INDEX tbl_idx ON tbl USING gist (low_high);
    

    Should make a query of this form perform very fast:

    SELECT * FROM tbl WHERE my_value <@ low_high;
    

    <@ being the “element is contained by” operator.

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

Sidebar

Related Questions

I have a simple table in Postgres with a bit over 8 million rows.
I have a Postgres table with more than 8 million rows. Given the following
I have a table with approx 5 million rows which has a fk constraint
is is possible in postgres to have a trigger on CREATE TABLE that will
I have simple table creating script in Postgres 9.1. I need it to create
I'm working on rails application with postgres db.I have a table called merchant_review_votes where
Postgres 9.0.4 Rails 3.0.7 AR 3.0.7 pg 0.12.2 I have a table with 3
I have some tables that I'm joining in a query with Postgres (9). However,
I have a Postgres instance building a GIN index. It's looking at about 200,000
I have two Postgres databases. In one I have two tables, each with about

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.