Query analyse

From: Elielson Fontanezi <ElielsonF(at)prodam(dot)sp(dot)gov(dot)br>
To: pgsql-sql <pgsql-sql(at)postgresql(dot)org>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Query analyse
Date: 2003-07-25 13:08:16
Message-ID: A799F7647794D311924A005004ACEA9709699779@cprodamibs249.prodam
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Good morning!

First of all, my envoronment is:
Linux netlab142.prodam 2.4.8-26mdk #1 Sun Sep 23 17:06:39 CEST 2001
i686 unknown
pg_ctl (PostgreSQL) 7.2.1

I would like some suggestions on how to speed up a query.

Both of the queries below are identical except that one of them use the
trunc function.

You can see that the TRUNC function rise hardly up the query response
time in the second query.
That shouldn´t be happen. Only because a trunc function?

What can I be in that case?
What does it happen?

Sure, there are indexes:

CREATE INDEX idx_proposta_2 ON proposta USING btree (in_situacao_proposta);
CREATE INDEX idx_proposta_4 ON proposta USING btree (nr_proponente);

And pa.nr_proponente is fk and op.nr_proponte is pk.

These are the queries:

1o. That is ok.

DEBUG: query: select
pa.nr_projeto,
pa.dc_denom_projeto,
pa.nr_proponente,
pa.dc_coordenador,
op.dc_proponente
from proposta pa
inner join orgao_proponente op
on (pa.nr_proponente = op.nr_proponente)
where pa.in_situacao_proposta <> 'E' ORDER BY 1 DESC;

DEBUG: QUERY STATISTICS
! system usage stats:
! 0.015904 elapsed 0.000000 user 0.020000 system sec
! [0.010000 user 0.020000 sys total]
! 0/0 [0/0] filesystem blocks in/out
! 143/42 [353/172] page faults/reclaims, 0 [0] swaps
! 0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent
! 0/0 [0/0] voluntary/involuntary context switches
! postgres usage stats:
! Shared blocks: 88 read, 0 written, buffer hit rate
= 89.19
%
! Local blocks: 0 read, 0 written, buffer hit rate
= 0.00%
! Direct blocks: 0 read, 0 written

2o. But I need to use the trunc function:

DEBUG: query: select
pa.nr_projeto,
pa.dc_denom_projeto,
pa.nr_proponente,
pa.dc_coordenador,
op.dc_proponente
from proposta pa
inner join orgao_proponente op
on (trunc(pa.nr_proponente/100000,0)*100000 = op.nr_proponente)
where pa.in_situacao_proposta <> 'E' ORDER BY 1 DESC;

DEBUG: QUERY STATISTICS
! system usage stats:
! 104.665005 elapsed 10.090000 user 0.420000 system sec
! [10.100000 user 0.420000 sys total]
! 0/0 [0/0] filesystem blocks in/out
! 141/50 [352/180] page faults/reclaims, 0 [0] swaps
! 0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent
! 0/0 [0/0] voluntary/involuntary context switches
! postgres usage stats:
! Shared blocks: 7408 read, 0 written, buffer hit rate
= 13.23
%
! Local blocks: 0 read, 0 written, buffer hit rate
= 0.00%
! Direct blocks: 0 read, 0 written

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Reuben D. Budiardja 2003-07-25 13:31:37 Re: Can I turn the case sensitive off
Previous Message Ron Johnson 2003-07-25 12:49:14 Re: Can I turn the case sensitive off

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-07-25 13:45:15 Re: Problem using Subselect results
Previous Message Peter Childs 2003-07-25 12:31:00 Re: [OT] Frontend recommendations