Re: Help optimize view

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: <pgsql-performance(at)postgresql(dot)org>,"Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Kevin Grittner" <Kgrittn(dot)CCAP(dot)Courts(at)wicourts(dot)gov>, "Mike Relyea" <Mike(dot)Relyea(at)xerox(dot)com>
Subject: Re: Help optimize view
Date: 2007-08-13 22:37:33
Message-ID: 46C096DD.EE98.0025.0@wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

>>> On Mon, Aug 13, 2007 at 4:25 PM, in message
<46C0860D(dot)EE98(dot)0025(dot)0(at)wicourts(dot)gov>, "Kevin Grittner"
<Kevin(dot)Grittner(at)wicourts(dot)gov> wrote:
>>>> On Mon, Aug 13, 2007 at 4:00 PM, in message
> <1806D1F73FCB7F439F2C842EE0627B18065F7A86(at)USA0300MS01(dot)na(dot)xerox(dot)net>, "Relyea,
> Mike" <Mike(dot)Relyea(at)xerox(dot)com> wrote:
>
>> From what Tom
>> says, it sounds like if I want the data returned faster I'm likely to
>> have to get beefier hardware.
>
> That's not what he suggested. If you introduce redundancy in a controlled
> fashion, you could have a single table with an index to more quickly get you
> to the desired set of data. That can be maintained on an ongoing basis
> (possibly using triggers) or could be materialized periodically or prior to
> running a series of reports or queries.
>
> Such redundancies violate the normalization rules which are generally used
> in database design, but some denormalization is often needed for acceptable
> performance.

One last thought regarding your table structure -- I noticed you were often
joining on column names ending in "ID" and selecting using column names
ending in "Name", where the values for the name columns were only a few
characters long. It is not always a good idea to create a meaningless ID
number for a primary key if you have a meaningful value (or combination of
values) which would uniquely identify a row.

If you were able to use the columns in your search criteria as keys, you
would have them in the Measurements table without creating any troublesome
redundancy. You could then add Measurements indexes on these columns, and
your query might run in under a second.

The down side of meaningful keys (oft cited by proponents of the technique)
is that if you decide that everything with an AnalysisModuleName" name of
'NMF' should now be named 'NMX', you would have to update all rows which
contain the old value. To be able to do this safely and reliably, you would
want to use DOMAIN definitions rigorously. If you link through meaningless
ID numbers (and what would be the point of changing those?) you can change
'NMF' to 'NMX' in one place, and everything would reflect the new value,
since it would always join to one place for those characters.

-Kevin

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Josh Berkus 2007-08-13 23:08:02 Re: [HACKERS] Proposal: Pluggable Optimizer Interface
Previous Message Tom Lane 2007-08-13 22:24:27 Re: [HACKERS] Proposal: Pluggable Optimizer Interface