Re: Slow Query - PostgreSQL 9.2

From: Saulo Merlo <smerlo50(at)outlook(dot)com>
To: Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Slow Query - PostgreSQL 9.2
Date: 2016-01-11 06:27:23
Message-ID: SNT147-W69E44DB2E0E512A8191242D3C90@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Vitaly,
Yep... gorfs.nodes is a view.
And the schema is: gorfs.inode_segments
So... CREATE INDEX index_name ON gorfs.inode_segments(st_ctime)
Is that correct? It would be "st_ctime"?
I've rewriten the query as well. Thank you for that!
Thank youLucas
> Date: Sun, 10 Jan 2016 21:23:01 -0800
> Subject: Re: [GENERAL] Slow Query - PostgreSQL 9.2
> From: vitaly(dot)burovoy(at)gmail(dot)com
> To: smerlo50(at)outlook(dot)com
> CC: pgsql-general(at)postgresql(dot)org
>
> On 1/10/16, Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com> wrote:
> > On 1/10/16, Saulo Merlo <smerlo50(at)outlook(dot)com> wrote:
> >> I've got a slow query.. I'd like to make it faster.. Make add an index?
> >> Query:
> >> SELECT
> >> <<overquoting>>
> >> FROM gorfs.nodes AS f
> >> <<overquoting>>
> >> WHERE f.file_data IS NOT NULL
> >> AND ((transaction_timestamp() AT TIME ZONE 'UTC') > (f.last_changed +
> >> '24
> >> months' :: INTERVAL)) LIMIT 100;
> >
> >> <<overquoting>>
> >> "Total runtime: 94989.208 ms"What could I do to make it faster? Thank
> >> you.
> >
> > At least you can add an index:
> > CREATE INDEX ON gorfs.nodes(last_changed)
> >
> > and rewrite part of WHERE clause to:
> > (f.last_changed < (transaction_timestamp() AT TIME ZONE 'UTC' - '24
> > months'::INTERVAL))
> >
> > It allows to decrease the slowest part of your query (sequence
> > scanning of a table, all 13.5M rows):
> >> -> Seq Scan on "inodes" "t" (cost=0.00..1411147.24 rows=13416537
> >> width=29) (actual time=94987.224..94987.224 rows=0 loops=1)
> >> Filter: ("timezone"('UTC'::"text", "transaction_timestamp"()) >
> >> (("st_ctime")::timestamp without time zone + '2 years'::interval))
> >
> > compare that time to the one in the topmost row of EXPLAIN:
> >> Limit (cost=1556.99..1336437.30 rows=100 width=186) (actual
> >> time=94987.261..94987.261 rows=0 loops=1)
>
> Hmm. It seems that gorfs.nodes is a view.
> So creating index should be something like (I have no idea that schema
> name for it):
> CREATE INDEX ON _schema_name_.inodes(st_ctime)
>
> --
> Best regards,
> Vitaly Burovoy
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paquier 2016-01-11 06:27:43 Re: Code of Conduct: Is it time?
Previous Message Oleg Bartunov 2016-01-11 06:13:32 Re: Code of Conduct: Is it time?