Re: Query RE: Optimising UUID Lookups

From: Maxim Boguk <maxim(dot)boguk(at)gmail(dot)com>
To: Roland Dunn <roland(dot)dunn(at)gmail(dot)com>
Cc: postgres performance list <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Query RE: Optimising UUID Lookups
Date: 2015-03-21 09:10:59
Message-ID: CAK-MWwSTNn67jSLkrJBLWMhPaY17Mcc0aLJzS-YVFzD3BRJRNA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Sat, Mar 21, 2015 at 6:01 AM, Roland Dunn <roland(dot)dunn(at)gmail(dot)com> wrote:

> Hi,
> Wonder if anyone can help.
>
> Have a lookup table where the primary key is a native uuid type
> (filled with uuid's of type 4), around 50m rows in size.
>
> Have a separate table, table A, similar size (around 50m rows).
> Primary key in table A is the standard integer, nextval, etc type
> primary key. Table A also has a uuid column. The uuid column in table
> A (native Postgres uuid type) has a "UNIQUE CONSTRAINT, btree (uuid)"
> constraint on the uuid column.
>
> Currently regularly running following set of queries:
> 1. Pull around 10,000 rows from lookup table.
> 2. Use uuid's from (1), to query table A.
>
> Query (2) above, is running slowly. Typically around 40-50 seconds to
> pull 8000-10,000 rows. - which is pretty slow. The table has various
> other columns: 4 text fields, couple of JSON fields, so each row in
> table A is fairly "fat" (if that's the correct expression).
>

​Hi Roland,

It's very likely that the query is IO-bound.
Usual single SATA drive can perform around 100 IOPS/s.
As a result to fetch randomly spread 10000 rows HDD must spent ~100second
which is pretty close to actual timings.

I suggest enable track_io_timing in postgresql.conf, and after use explain
(analyze, costs, buffers, timing) ​ instead of simple explain analyze. It
will help you see time spend on the IO operations.

If your load are actually IO-bound I could suggest 3 possible ways make
things better:
1)use good server grade ssd drive instead of hdd.
2)increase memory on the server so database could comfortable fit into the
RAM.
3)use raid10 raid with good raid controller and 6-12 SAS drives.

​The database could not retrieve rows faster than underlying ​file system
could fetch data from hdd.

--
Maxim Boguk
Senior Postgresql DBA
http://www.postgresql-consulting.ru/ <http://www.postgresql-consulting.com/>

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Roland Dunn 2015-03-21 10:34:23 Re: Query RE: Optimising UUID Lookups
Previous Message Josh Krupka 2015-03-21 07:39:48 Re: Performance issues