Partitions and indexes

Lists: pgsql-general
From: Amitabh Kant <amitabhkant(at)gmail(dot)com>
To: PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Partitions and indexes
Date: 2011-02-23 07:22:00
Message-ID: AANLkTimgXVgCjuFxTWME66SgrGaDOTQ12iE=3fdkwgvy@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hello

If I have partitioned a table based on a foreign key in a manner where every
child table will only have data for single value of the foreign key, do I
need to create a index for the foreign key in the primary and/or child
tables? I am using version 8.4

With regards

Amitabh


From: Amitabh Kant <amitabhkant(at)gmail(dot)com>
To: Chetan Suttraway <chetan(dot)suttraway(at)enterprisedb(dot)com>
Cc: PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Partitions and indexes
Date: 2011-02-26 17:04:28
Message-ID: AANLkTim9nF0AHUpDdEjcjh43SgU_dV9foToyBYJz0SuN@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Fri, Feb 25, 2011 at 1:17 PM, Chetan Suttraway <
chetan(dot)suttraway(at)enterprisedb(dot)com> wrote:

>
>
> On Wed, Feb 23, 2011 at 12:52 PM, Amitabh Kant <amitabhkant(at)gmail(dot)com>wrote:
>
>> Hello
>>
>> If I have partitioned a table based on a foreign key in a manner where
>> every child table will only have data for single value of the foreign key,
>> do I need to create a index for the foreign key in the primary and/or child
>> tables? I am using version 8.4
>>
>> With regards
>>
>> Amitabh
>>
>>
>> Could you post a detailed set of queries?
>
>
> --
> Chetan Sutrave
> http://www.enterprisedb.com
>
>
A simplified representation would be:

Table T1
id int (PK)
name varchar
--
--

Table T2
id int (PK)
T1id int (FK to T1->id)
--
--

Now if I partition the table T2 based on field T1id, making sure that each
distinct T1id is provided its own child table

Table T2C1 (inherited from T2, T1id field only contains 1 for all rows)
Table T2C2 (inherited from T2, T1id field only contains 2 for all rows)
--
--

What I would like to know here is that do I need to add an index for T1id
field for either T2 or it's inherited tables (T2C1/T2C2 etc)?

Amitabh


From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
To: Amitabh Kant <amitabhkant(at)gmail(dot)com>
Cc: Chetan Suttraway <chetan(dot)suttraway(at)enterprisedb(dot)com>, PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Partitions and indexes
Date: 2011-02-26 18:01:18
Message-ID: 4258A398-A6E4-441A-83BB-F69E46B6A26E@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 26 Feb 2011, at 18:04, Amitabh Kant wrote:

> Now if I partition the table T2 based on field T1id, making sure that each distinct T1id is provided its own child table
>
> Table T2C1 (inherited from T2, T1id field only contains 1 for all rows)
> Table T2C2 (inherited from T2, T1id field only contains 2 for all rows)
> --
> --
>
> What I would like to know here is that do I need to add an index for T1id field for either T2 or it's inherited tables (T2C1/T2C2 etc)?

No. Either would be rather pointless. In the child tables all the values in that index would have the same exact value, which you don't need as constraint exclusion already pointed the planner to the right table. In the parent table there wouldn't be any data to index.

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.

!DSPAM:737,4d69400211732483184779!


From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Partitions and indexes
Date: 2011-02-26 18:22:38
Message-ID: 4D6944EE.6070208@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 02/26/11 10:01 AM, Alban Hertroys wrote:
> On 26 Feb 2011, at 18:04, Amitabh Kant wrote:
>
>> Now if I partition the table T2 based on field T1id, making sure that each distinct T1id is provided its own child table
>>
>> Table T2C1 (inherited from T2, T1id field only contains 1 for all rows)
>> Table T2C2 (inherited from T2, T1id field only contains 2 for all rows)
>> --
>> --
>>
>> What I would like to know here is that do I need to add an index for T1id field for either T2 or it's inherited tables (T2C1/T2C2 etc)?
> No. Either would be rather pointless. In the child tables all the values in that index would have the same exact value, which you don't need as constraint exclusion already pointed the planner to the right table. In the parent table there wouldn't be any data to index.

the whole idea of one table per row sounds rather odd and pointless to me.


From: Amitabh Kant <amitabhkant(at)gmail(dot)com>
To: John R Pierce <pierce(at)hogranch(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Partitions and indexes
Date: 2011-02-26 18:42:26
Message-ID: AANLkTimJQ6L91h-CVYZCX+gfLqoLAvzgWbL8i8LFK8h2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Sat, Feb 26, 2011 at 11:52 PM, John R Pierce <pierce(at)hogranch(dot)com> wrote:

> On 02/26/11 10:01 AM, Alban Hertroys wrote:
>
>> On 26 Feb 2011, at 18:04, Amitabh Kant wrote:
>>
>> Now if I partition the table T2 based on field T1id, making sure that
>>> each distinct T1id is provided its own child table
>>>
>>> Table T2C1 (inherited from T2, T1id field only contains 1 for all rows)
>>> Table T2C2 (inherited from T2, T1id field only contains 2 for all rows)
>>> --
>>> --
>>>
>>> What I would like to know here is that do I need to add an index for T1id
>>> field for either T2 or it's inherited tables (T2C1/T2C2 etc)?
>>>
>> No. Either would be rather pointless. In the child tables all the values
>> in that index would have the same exact value, which you don't need as
>> constraint exclusion already pointed the planner to the right table. In the
>> parent table there wouldn't be any data to index.
>>
>
> the whole idea of one table per row sounds rather odd and pointless to me.
>
> --
> 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
>

Not sure I am getting you correctly, but every table will have multiple rows
of data, but for every row in a given table, the value of the FK would be
the same.

Amitabh


From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Partitions and indexes
Date: 2011-02-26 19:00:07
Message-ID: 4D694DB7.8090602@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 02/26/11 10:42 AM, Amitabh Kant wrote:
> On Sat, Feb 26, 2011 at 11:52 PM, John R Pierce <pierce(at)hogranch(dot)com
> <mailto:pierce(at)hogranch(dot)com>> wrote:
>
> On 02/26/11 10:01 AM, Alban Hertroys wrote:
>
> On 26 Feb 2011, at 18:04, Amitabh Kant wrote:
>
> Now if I partition the table T2 based on field T1id,
> making sure that each distinct T1id is provided its own
> child table
>
> Table T2C1 (inherited from T2, T1id field only contains 1
> for all rows)
> Table T2C2 (inherited from T2, T1id field only contains 2
> for all rows)
> --
> --
>
> What I would like to know here is that do I need to add an
> index for T1id field for either T2 or it's inherited
> tables (T2C1/T2C2 etc)?
>
> No. Either would be rather pointless. In the child tables all
> the values in that index would have the same exact value,
> which you don't need as constraint exclusion already pointed
> the planner to the right table. In the parent table there
> wouldn't be any data to index.
>
>
> the whole idea of one table per row sounds rather odd and
> pointless to me.<http://www.postgresql.org/mailpref/pgsql-general>
>
>
> Not sure I am getting you correctly, but every table will have
> multiple rows of data, but for every row in a given table, the value
> of the FK would be the same.

ah, I misunderstood the original description.

you're not likely to query T2 by T1id, are you? Doing so would return
all of one of those inherited tables


From: Amitabh Kant <amitabhkant(at)gmail(dot)com>
To: John R Pierce <pierce(at)hogranch(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Partitions and indexes
Date: 2011-02-27 00:27:17
Message-ID: AANLkTik5X7rNABRpz_rGdK-uo-kv_HjWGavQfAUO0mVU@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Sun, Feb 27, 2011 at 12:30 AM, John R Pierce <pierce(at)hogranch(dot)com> wrote:

> On 02/26/11 10:42 AM, Amitabh Kant wrote:
>
>> On Sat, Feb 26, 2011 at 11:52 PM, John R Pierce <pierce(at)hogranch(dot)com<mailto:
>> pierce(at)hogranch(dot)com>> wrote:
>>
>> On 02/26/11 10:01 AM, Alban Hertroys wrote:
>>
>> On 26 Feb 2011, at 18:04, Amitabh Kant wrote:
>>
>> Now if I partition the table T2 based on field T1id,
>> making sure that each distinct T1id is provided its own
>> child table
>>
>> Table T2C1 (inherited from T2, T1id field only contains 1
>> for all rows)
>> Table T2C2 (inherited from T2, T1id field only contains 2
>> for all rows)
>> -- --
>>
>> What I would like to know here is that do I need to add an
>> index for T1id field for either T2 or it's inherited
>> tables (T2C1/T2C2 etc)?
>>
>> No. Either would be rather pointless. In the child tables all
>> the values in that index would have the same exact value,
>> which you don't need as constraint exclusion already pointed
>> the planner to the right table. In the parent table there
>> wouldn't be any data to index.
>>
>>
>> the whole idea of one table per row sounds rather odd and
>> pointless to me.<http://www.postgresql.org/mailpref/pgsql-general>
>>
>>
>>
>> Not sure I am getting you correctly, but every table will have multiple
>> rows of data, but for every row in a given table, the value of the FK would
>> be the same.
>>
>
> ah, I misunderstood the original description.
>
> you're not likely to query T2 by T1id, are you? Doing so would return all
> of one of those inherited tables
>
>
Almost all queries will have T1id as one of its parameter, although not the
only parameter.

Amitabh