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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:06:49+00:00 2026-06-13T00:06:49+00:00

In a PostgreSQL 9 database there is a table that contains a serial field

  • 0

In a PostgreSQL 9 database there is a table that contains a serial field X which is a PK (oid enabled), and other fields.

Using postgres’s pgadmin with that table – a query takes 30 seconds.

If I add a unique index on the same field X – same query in pgadmin takes 3 seconds.

PKs are implicitly indexes:
http://www.postgresql.org/docs/current/static/indexes-unique.html

So why does the explicit index make a difference?

Is this a pgadmin issue?

Do I need an explicit index for the PK field or not?

  • 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-13T00:06:50+00:00Added an answer on June 13, 2026 at 12:06 am

    No difference here (pg 9.1.2), I think it is an artifact (schema, case-insignificance?)

    DROP SCHEMA tmp CASCADE;
    CREATE SCHEMA tmp ;
    SET search_path=tmp;
    
    CREATE TABLE lutser
            ( id INTEGER NOT NULL PRIMARY KEY
            , val INTEGER NOT NULL
            );
    INSERT INTO lutser(id,val)
    SELECT g, g %31
    FROM generate_series(1,100000) g
            ;
    
    DELETE FROM lutser WHERE random() < .5;
    
    VACUUM ANALYZE lutser;
    
    EXPLAIN ANALYZE
    SELECT COUNT(*) FROM lutser
    WHERE id >= 1000 AND id < 2000
            ;
    
    CREATE INDEX lutser_id ON lutser(id);
    
    VACUUM ANALYZE lutser;
    
    EXPLAIN ANALYZE
    SELECT COUNT(*) FROM lutser
    WHERE id >= 1000 AND id < 2000
            ;
    

    Results:

    NOTICE:  drop cascades to table tmp.lutser
    DROP SCHEMA
    CREATE SCHEMA
    SET
    NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "lutser_pkey" for table "lutser"
    CREATE TABLE
    INSERT 0 100000
    DELETE 50051
    VACUUM
                                                              QUERY PLAN
    -------------------------------------------------------------------------------------------------------------------------------
     Aggregate  (cost=20.28..20.29 rows=1 width=0) (actual time=0.294..0.295 rows=1 loops=1)
       ->  Index Scan using lutser_pkey on lutser  (cost=0.00..19.03 rows=499 width=0) (actual time=0.015..0.216 rows=487 loops=1)
             Index Cond: ((id >= 1000) AND (id < 2000))
     Total runtime: 0.343 ms
    (4 rows)
    
    CREATE INDEX
    VACUUM
                                                             QUERY PLAN
    -----------------------------------------------------------------------------------------------------------------------------
     Aggregate  (cost=19.03..19.04 rows=1 width=0) (actual time=0.232..0.232 rows=1 loops=1)
       ->  Index Scan using lutser_id on lutser  (cost=0.00..17.79 rows=497 width=0) (actual time=0.033..0.185 rows=487 loops=1)
             Index Cond: ((id >= 1000) AND (id < 2000))
     Total runtime: 0.266 ms
    (4 rows)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apparently there is a database postgres that is created by default on each postgresql
I have a PostgreSql 9.04 database that contains a postgres implementation of the ASPNet
I have a postgres database with a table that contains rows I want to
I'm using PostgreSQL 9.1. My database is structured so that there is actual tables
Background In a PostgreSQL 9.0 database, there are various tables that have many-to-many relationships.
For Postgres is there any sort of command line utilities that allow a database
I have a postgresql database and am using it for a project which handles
I have a PostgreSQL database that contains traffic tickets written by a few jurisdictions.
I have a PostgreSQL database at work that is a single table of data.
I am using PostgreSQL database. Having a table named metadatavalue with structure is as

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.