pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Kirkwood <markir@coretech.co.nz>
To: Josh Berkus <josh@agliodbs.com>
Cc: Daniel Ceregatti <vi@sh.nu>
Cc: pgsql-performance@postgresql.org
Subject: Re: What is the best way to do attribute/values?
Date: Wed, 25 Aug 2004 20:22:18 +1200
Message-ID: <412C4C3A.2030001@coretech.co.nz> (raw)
In-Reply-To: <200408241330.32484.josh@agliodbs.com>
References: <4124EB58.9040102@sh.nu>
	<200408241330.32484.josh@agliodbs.com>



Josh Berkus wrote:

> Things we've already tried to avoid going over old ground:
>
>1) increasing statistics;
>2) increasing sort_mem (to 256MB, which is overkill)
>3) testing on 8.0 beta, which does not affect the issue.
>
>At this point I'm looking for ideas.   Suggestions, anyone?
>
>  
>
with respect to query design:

consider instead of:

select
	pav1.person_id
from
	person_attributes_vertical pav1,
	person_attributes_vertical pav2
where
	pav1.attribute_id = 1
	and pav1.value_id in (2,3)
	and pav2.attribute_id = 2
	and pav2.value_id in (2,3)
	and pav1.person_id = pav2.person_id

try:

select
	pav1.person_id
from
	person_attributes_vertical pav1
where
	   (    pav1.attribute_id = 1
	    and pav1.value_id in (2,3))
	or (    pav1.attribute_id = 2
	    and pav1.value_id in (2,3))
	
I am gambling that the 'or's' might be less expensive than the multiple self joins (particularly in the more general cases!).

To make access work well you might want to have *several* concatenated indexes of 2 -> 4 attributes - to work around Pg inability to use more than 1 in a given query.
For this query indexing (attribute_id, value_id) is probably good.

Consider playing with 'random_page_cost' and maybe 'effective_cache_size' to encourage the planner to use 'em.

regards

Mark







view thread (9+ messages)  latest in thread

Message-ID: <412C4C3A.2030001@coretech.co.nz>
Permalink:  ../412C4C3A.2030001@coretech.co.nz/
Also on:    postgresql.org/message-id/412C4C3A.2030001@coretech.co.nz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: markir@coretech.co.nz, josh@agliodbs.com, vi@sh.nu
  Subject: Re: What is the best way to do attribute/values?
  In-Reply-To: <412C4C3A.2030001@coretech.co.nz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox