Re: database not using indexes

From: Silvio Brandani <silvio(dot)brandani(at)tech(dot)sdb(dot)it>
To: "Ruslan A(dot) Bondar" <fsat(at)list(dot)ru>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: database not using indexes
Date: 2011-11-09 17:06:11
Message-ID: 4EBAB303.2080307@tech.sdb.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Ok,

the problem was on a big table on query like this:

select outmessage0_.out_msg_id as out1_0_
from edi.out_messages outmessage0_, edi.transaction_set_partners
transactio1_
where outmessage0_.transaction_set_partner=transactio1_.trn_set_prtn_id
and outmessage0_.status_id='TOSND'
and transactio1_.legacy_sender_id='ALL'
and transactio1_.legacy_receiver_id='00004542'
and outmessage0_.transaction_set_id='INTERNAL_USE'
order by outmessage0_.out_msg_id

the existing indexes on status_id
CREATE INDEX out_msg_status_idex
ON edi.out_messages
USING btree
(status_id);

and transaction_set_partners

CREATE INDEX edi_out_messages_trn_set_prtn_id_fk_idx
ON edi.out_messages
USING btree
(transaction_set_partner);

where not used anyore.

I created the following one:

CREATE INDEX out_msg_status_trn_set_prtn_idx
ON edi.out_messages
USING btree
(status_id,transaction_set_partner);

and still the explain show a seq scan

then I inverted the fields and now it works:

CREATE INDEX out_msg_status_trn_set_prtn_idx2
ON edi.out_messages
USING btree
(transaction_set_partner,status_id);

I wonder why not use anymore the existing indexes.

regards

Il 09/11/2011 16.58, Ruslan A. Bondar ha scritto:
> Why have you decided it isn't using indexes?
> If index exists - postgres will use it.
> To write a script for this I need at least database version.
>
> On Wed, 09 Nov 2011 16:22:20 +0100
> Silvio Brandani<silvio(dot)brandani(at)tech(dot)sdb(dot)it> wrote:
>
>> Our database seems not using index anymore, please help with, is a
>> production database.
>>
>> is there a script to check missing index on foreign key ??
>>
>> thanks a lot
>>
>> ---
>>
>>
>>
>>
>>

---

Utilizziamo i dati personali che la riguardano esclusivamente per nostre finalità amministrative e contabili, anche quando li comunichiamo a terzi. Informazioni dettagliate, anche in ordine al Suo diritto di accesso e agli altri Suoi diritti, sono riportate alla pagina http://www.savinodelbene.com/privacy.html
Se avete ricevuto questo messaggio per errore Vi preghiamo di ritornarlo al mittente eliminandolo assieme agli eventuali allegati, ai sensi art. 616 codice penale http://www.savinodelbene.com/privacy/codice_penale_616.html
L'Azienda non si assume alcuna responsabilità giuridica qualora pervengano da questo indirizzo messaggi estranei all'attività lavorativa o contrari a norme.
--

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Geoffrey Myers 2011-11-09 19:23:45 Re: setting timezone
Previous Message Tom Lane 2011-11-09 16:47:40 Re: setting timezone