From: Mark Kirkwood <markir@coretech.co.nz>
To: Josh Berkus <josh@agliodbs.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: What is the best way to do attribute/values?
Date: Thu, 26 Aug 2004 16:51:50 +1200
Message-ID: <412D6C66.2070207@coretech.co.nz> (raw)
In-Reply-To: <200408250959.15946.josh@agliodbs.com>
References: <4124EB58.9040102@sh.nu>
<200408241330.32484.josh@agliodbs.com>
<412C4C3A.2030001@coretech.co.nz>
<200408250959.15946.josh@agliodbs.com>
Josh Berkus wrote:
>Mark, Tim,
>
>
>
>>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))
>>
>>
>
>Not the same query, sorry. Daniel's query yields all the person_id's which
>have criteria A AND criteria B. Yours gives all the person_id's which have
>criteria A OR criteria B.
>
>
>
Apologies, not thinking clearly enough there...
Maybe try out intersection :
select
pav1.person_id
from
person_attributes_vertical pav1
where
( pav1.attribute_id = 1
and pav1.value_id in (2,3))
intersect
select
pav1.person_id
from
person_attributes_vertical pav1
where ( pav1.attribute_id = 2
and pav1.value_id in (2,3))
In the advent that is unhelpful, I wonder about simplifying the
situation and investigating how
select
pav1.person_id
from
person_attributes_vertical pav1
where
pav1.attribute_id = 1
performs, compared to
select
pav1.person_id
from
person_attributes_vertical pav1
where
( pav1.attribute_id = 1
and pav1.value_id in (2,3))
If the first performs ok and the second does not, It may be possible to
get better times by doing some horrible re-writes :e.g:
select
pav1.person_id
from
person_attributes_vertical pav1
where
( pav1.attribute_id = 1
and pav1.value_id||null in (2,3))
etc.
regards
Mark
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
Subject: Re: What is the best way to do attribute/values?
In-Reply-To: <412D6C66.2070207@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