pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Fred Habash <fmhabash@gmail.com>
Cc: pgsql-performance@lists.postgresql.org
Subject: Re: Simple Query Elapsed Time ~ 3 hrs Using Bitmap Index/Heap Scan
Date: Tue, 05 Jun 2018 10:42:22 -0400
Message-ID: <28448.1528209742@sss.pgh.pa.us> (raw)
In-Reply-To: <560c24f9-dced-94ae-8e14-fe9451246342@gmail.com>
References: <560c24f9-dced-94ae-8e14-fe9451246342@gmail.com>

Fred Habash <fmhabash@gmail.com> writes:
> Indexes:
>      "cl_pk"  PRIMARY KEY, btree (cl_id)
>      "cl_cnst_uk01"  UNIQUE CONSTRAINT, btree (cit_id, vclf_number, cl_value)
>      "cl_indx_fk01"  btree (cit_id)
>      "cl_indx_fk02"  btree (vclf_number)

This is pretty inefficient index design.  Your query is slow because the
only selective condition it has is on cl_value, but you have no index
that can be searched with cl_value as the leading condition.  Moreover,
you have two indexes that can be searched with cit_id as the leading
condition, which is just wasteful.  I'd try reorganizing the cl_cnst_uk01
index as (cl_value, vclf_number, cit_id) so that it can serve for
searches on cl_value, while still enforcing the same uniqueness condition.
This particular column ordering would also let your query use the
vclf_number constraint as a secondary search condition, which would
help even more.

There's relevant advice about index design in the manual,

https://www.postgresql.org/docs/current/static/indexes.html

(see 11.3 and 11.5 particularly)

			regards, tom lane




view thread (5+ messages)  latest in thread

Message-ID: <28448.1528209742@sss.pgh.pa.us>
Permalink:  ../28448.1528209742@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/28448.1528209742@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, fmhabash@gmail.com, pgsql-performance@lists.postgresql.org
  Subject: Re: Simple Query Elapsed Time ~ 3 hrs Using Bitmap Index/Heap Scan
  In-Reply-To: <28448.1528209742@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox