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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:05:50+00:00 2026-06-12T09:05:50+00:00

Following on from my previous question on this topic, Postgres combining multiple Indexes :

  • 0

Following on from my previous question on this topic, Postgres combining multiple Indexes:

I have the following table on Postgres 9.2 (with postgis):

CREATE TABLE updates (
    update_id character varying(50) NOT NULL,
    coords geography(Point,4326) NOT NULL,
    user_id character varying(50) NOT NULL,
    created_at timestamp without time zone NOT NULL
);

And I am running following query on the table:

select * 
from updates 
where ST_DWithin(coords, ST_MakePoint(-126.4, 45.32)::geography, 30000) 
and user_id='3212312' 
order by created_at desc
limit 60

So given that, what Index should I use for (coords + user_id), GIST or BTree?

CREATE INDEX ix_coords_user_id ON updates USING GIST (coords, user_id);

OR

CREATE INDEX ix_coords_user_id ON updates (coords, user_id);

I was reading that BTree performs better than GIST, but am I forced to use GIST since I am using postgis geography field??

  • 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-12T09:05:51+00:00Added an answer on June 12, 2026 at 9:05 am

    You must use GiST if you want to use any index method other than the regular b-tree indexes (or hash indexes, but they shouldn’t really be used). PostGIS indexes require GiST.

    B-tree indexes can only be used for basic operations involving equality or ordering, like =, <, <=, >, >=, <>, BETWEEN and IN. While you can create a b-tree index on a geomtery object (point, region, etc) it can only actually be used for equality as ordering comparisons like > are generally meaningless for such objects. A GiST index is required to support more complex and general comparisons like “contains”, “intersects”, etc.

    You can use the btree_gist extension to enable b-tree indexing for GiST. It’s considerably slower than regular b-tree indexes, but allows you to create a multi-column index that contains both GiST-only types and regular types like text, integer, etc.


    In these situations you really need to use explain analyze (explain.depesz.com is useful for this) to examine how Pg uses various indexes and combinations of indexes that you create. Try different column orderings in multi-column indexes, and see whether two or more separate indexes are more effective.

    I strongly suspect that you’ll get the best results with the multicolumn GiST index in this case, but I’d try several different combinations of indexes and index column orderings to see.

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

Sidebar

Related Questions

I have the following code (from a previous question on this site) which retrieves
Okay, this is following on from my previous question reguarding performing a simple ajax
This problem follows on from a previous question . When I run the following
Following on from my previous question [link text][1] , I have a new problem.
Following on from this previous question: Linq query for EF 4.1 data with nested
Following on from a previous question , I am having trouble combining the Lazy<T>
Following on from my previous question about tables I am trying to create additional
I have the following code adapted from a previous question/answer: var str = $('title').text();
From a previous question , I have the following: So I have implemented a
Following on from a previous question about sub-selects, I have an SQL statement with

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.