CREATE TABLE LIKE INCLUDING INDEXES support

Lists: pgsql-hackerspgsql-patches
From: NikhilS <nikkhils(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Auto creation of Partitions
Date: 2007-03-06 11:57:50
Message-ID: d3c4af540703060357i2e69828ah772bbba0e54f1e2b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

This is to get feedback to meet the following TODO:

- Simplify ability to create partitioned tables

This would allow creation of partitioned tables without requiring
creation of rules for INSERT/UPDATE/DELETE, and constraints for rapid
partition selection. Options could include range and hash partition
selection.

There was some discussion on the pgsql mailing lists, which lead to the
above TODO:
http://archives.postgresql.org/pgsql-hackers/2006-09/msg00189.php
http://archives.postgresql.org/pgsql-hackers/2006-08/msg01874.php

We can have the following syntax to support auto creation of partitions in
Postgresql:

CREATE TABLE tabname (
...
...
) PARTITION BY
HASH(expr)
| RANGE(expr)
| LIST(expr)
[PARTITIONS num_partitions] /* will apply to HASH only for now*/
[PARTITION partition_name CHECK(...),
PARTITION partition_name CHECK(...)
...
];

Here "expr" will be one of the column names as specified for the master
table. Once we finalize the syntax, the above statement would end up
carrying out the following activities (disclaimer: we might add or remove
some activities based on the discussion here).

i ) Create master table.
ii) Create children tables based on the number of partitions specified and
make them inherit from the master table.
iii) Auto generate rules (or triggers?) using the checks mentioned for the
partitions, to handle INSERTs/DELETEs/UPDATEs to navigate them to the
appropriate child. Note that checks specified directly on the master table
will get inherited automatically.
iv) Based on the PRIMARY, UNIQUE, REFERENCES information specified, pass it
on to the children tables.
v) If possible add CHECK (false) to the master table to avoid any activity
on it.

Some questions remain as to:

1) Whether we should use triggers/rules for step number (iii) above. Maybe
rules is the way to go.
2) What other attributes (access permissions e.g.) of the master along with
the ones specified in (iv) should be passed on to the children.
3) Some implementation specific issue e.g. whether SPI_execute would be a
good way of creating these rules.

Comments appreciated,
Regards,
Nikhils
EnterpriseDB http://www.enterprisedb.com


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: NikhilS <nikkhils(at)gmail(dot)com>
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 12:40:02
Message-ID: 200703061340.02770.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS wrote:
> iv) Based on the PRIMARY, UNIQUE, REFERENCES information specified,
> pass it on to the children tables.

How will you maintain a primary key in such a table, considering that
indexes can't span multiple tables?

> 1) Whether we should use triggers/rules for step number (iii) above.
> Maybe rules is the way to go.

Since this would basically be a case of the updatable rules problem, you
should review those discussions in the past to check whether the issues
mentioned there don't interfere with that plan.

> 2) What other attributes (access permissions e.g.) of the master
> along with the ones specified in (iv) should be passed on to the
> children.

Moreover, how are later changes of those attributes propagated?

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 13:01:41
Message-ID: d3c4af540703060501r4f5463ccle75bc61ab6c7f9ec@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 3/6/07, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
>
> NikhilS wrote:
> > iv) Based on the PRIMARY, UNIQUE, REFERENCES information specified,
> > pass it on to the children tables.
>
> How will you maintain a primary key in such a table, considering that
> indexes can't span multiple tables?

We will not (I know its a hard thing to do :) ), the intention is to use
this information from the parent and make it a property of the child table.
This will avoid the step for the user having to manually specify CREATE
INDEX and the likes on all the children tables one-by-one.

> 1) Whether we should use triggers/rules for step number (iii) above.
> > Maybe rules is the way to go.
>
> Since this would basically be a case of the updatable rules problem, you
> should review those discussions in the past to check whether the issues
> mentioned there don't interfere with that plan.

The rules mentioned here will be to specify that all the
inserts/updates/deletes should go into proper children tables instead of the
parent. I do not see the updateable rules problem with regards to this, but
will check out the archives for discussion on this related to partitioning.

> 2) What other attributes (access permissions e.g.) of the master
> > along with the ones specified in (iv) should be passed on to the
> > children.
>
> Moreover, how are later changes of those attributes propagated?

Once created, this will be a normal inheritance relationship between the
tables and all the existing commands will apply to both the parent and the
child.

The basic idea here is to automate as many things as possible at partition
creation time. The user is free to make additional changes to the involved
tables later too.

Regards,
Nikhils

--
EnterpriseDB http://www.enterprisedb.com


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "NikhilS" <nikkhils(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 13:57:56
Message-ID: 87fy8ibhjv.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"NikhilS" <nikkhils(at)gmail(dot)com> writes:

>the intention is to use this information from the parent and make it a
>property of the child table. This will avoid the step for the user having to
>manually specify CREATE INDEX and the likes on all the children tables
>one-by-one.

Missed the start of this thread. A while back I had intended to add WITH
INDEXES to CREATE TABLE LIKE. That would let you create a tale LIKE parent
WITH CONSTRAINTS WITH INDEXES and get pretty much a perfect table ready for
adding to the inheritance structure.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Gregory Stark" <stark(at)enterprisedb(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 14:11:41
Message-ID: d3c4af540703060611i51125ef9y4e07db37dfb5b8d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 3/6/07, Gregory Stark <stark(at)enterprisedb(dot)com> wrote:
>
> "NikhilS" <nikkhils(at)gmail(dot)com> writes:
>
> >the intention is to use this information from the parent and make it a
> >property of the child table. This will avoid the step for the user having
> to
> >manually specify CREATE INDEX and the likes on all the children tables
> >one-by-one.
>
> Missed the start of this thread. A while back I had intended to add WITH
> INDEXES to CREATE TABLE LIKE. That would let you create a tale LIKE parent
> WITH CONSTRAINTS WITH INDEXES and get pretty much a perfect table ready
> for
> adding to the inheritance structure.

Yeah, this one aims to do pretty much the above as part of the auto creation
of the inheritance-based partitions.

Regards,
Nikhils

--
> Gregory Stark
> EnterpriseDB http://www.enterprisedb.com
>

--
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Gregory Stark" <stark(at)enterprisedb(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 14:13:58
Message-ID: d3c4af540703060613r355897b7ya24aec168bf109eb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On 3/6/07, NikhilS <nikkhils(at)gmail(dot)com> wrote:
>
> Hi,
>
> On 3/6/07, Gregory Stark <stark(at)enterprisedb(dot)com> wrote:
> >
> > "NikhilS" <nikkhils(at)gmail(dot)com> writes:
> >
> > >the intention is to use this information from the parent and make it a
> > >property of the child table. This will avoid the step for the user
> > having to
> > >manually specify CREATE INDEX and the likes on all the children tables
> > >one-by-one.
> >
> > Missed the start of this thread. A while back I had intended to add WITH
> > INDEXES to CREATE TABLE LIKE. That would let you create a tale LIKE
> > parent
> > WITH CONSTRAINTS WITH INDEXES and get pretty much a perfect table ready
> > for
> > adding to the inheritance structure.
>
>
> Yeah, this one aims to do pretty much the above as part of the auto
> creation of the inheritance-based partitions.
>

And to add, maybe if there is consensus/demand for the WITH INDEXES idea
mentioned above too, I could work on it as well.

Regards,
Nikhils

Regards,
> Nikhils
>
>
> --
> > Gregory Stark
> > EnterpriseDB http://www.enterprisedb.com
> >
>
>
>
> --
> EnterpriseDB http://www.enterprisedb.com
>

--
EnterpriseDB http://www.enterprisedb.com


From: Shane Ambler <pgsql(at)Sheeky(dot)Biz>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 16:13:39
Message-ID: 45ED9333.6070209@Sheeky.Biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS wrote:
> Hi,
>
> On 3/6/07, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
>>
>> NikhilS wrote:
>> > iv) Based on the PRIMARY, UNIQUE, REFERENCES information specified,
>> > pass it on to the children tables.
>>
>> How will you maintain a primary key in such a table, considering that
>> indexes can't span multiple tables?
>
>
> We will not (I know its a hard thing to do :) ), the intention is to use
> this information from the parent and make it a property of the child table.
> This will avoid the step for the user having to manually specify CREATE
> INDEX and the likes on all the children tables one-by-one.

I think a way can be devised to maintain the primary key and unique
constraints.
If a search is done on the parent table, the planner knows to rewrite
the query as a union (or union all) of all child tables that relate to
the where clause, or all child tables if the where clause is not on the
column/s used to partition, then this concept should be able to be
converted to indexes as well, so that when a primary or unique index
from a child table is inserted to, then each of the related child
indexes is consulted to ensure uniqueness.
This would only apply if the partitioning was not done by the primary or
unique column.

>> 1) Whether we should use triggers/rules for step number (iii) above.
>> > Maybe rules is the way to go.
>>
>> Since this would basically be a case of the updatable rules problem, you
>> should review those discussions in the past to check whether the issues
>> mentioned there don't interfere with that plan.
>
> The rules mentioned here will be to specify that all the
> inserts/updates/deletes should go into proper children tables instead of
> the
> parent. I do not see the updateable rules problem with regards to this, but
> will check out the archives for discussion on this related to partitioning.
>

I would think that a trigger would be a better choice as I see the need
(or at least the possibility) for more than just a rewrite. When a value
is inserted that is outside of a condition currently covered by an
existing child table then a new child will need to be spawned to contain
the new data.

So say we partition by year and month of a date column? As new dates are
added new child tables would be created each month. Or is this beyond
the current plan and left to manual creation?

Will ALTER TABLE be extended to handle partitions? This will allow
partitioning existing tables (maybe without blocking access?) and allow
things like ALTER TABLE mytable ADD PARTITION (mydate within 200703)
and ALTER TABLE mytable DROP PARTITION (mydate within 199912) or would
dropping be covered by DELETE FROM mytable where mydate <= 199912 ?

Could such a syntax be devised for date columns? (month of mydate) or
similar to auto create partitions based on the year and month of a date
column? or will we just do CHECK(mydatecol >= 1/3/07 and mydatecol <=
31/3/07) for each month of data? Also (day of mydatecol) to partition
based on year and day of year.

Another syntax possibility - range(myserialcol of 500000) where new
child tables are created every 500000 rows?

Maybe I'm looking at auto-maintenance which is beyond any current planning?

--

Shane Ambler
pgSQL(at)Sheeky(dot)Biz

Get Sheeky @ http://Sheeky.Biz


From: Chris Browne <cbbrowne(at)acm(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 17:01:02
Message-ID: 60abyqux0x.fsf@dba2.int.libertyrms.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

peter_e(at)gmx(dot)net (Peter Eisentraut) writes:
> NikhilS wrote:
>> iv) Based on the PRIMARY, UNIQUE, REFERENCES information specified,
>> pass it on to the children tables.
>
> How will you maintain a primary key in such a table, considering that
> indexes can't span multiple tables?

On the one hand, I seem to recall seeing "multiple-table-spanning
indices" being on the TODO list.

On the other, it may be that this sort of partitioning is only usable
for scenarios where it is only needful to maintain uniqueness on a
partition-by-partition basis.

>> 1) Whether we should use triggers/rules for step number (iii) above.
>> Maybe rules is the way to go.
>
> Since this would basically be a case of the updatable rules problem, you
> should review those discussions in the past to check whether the issues
> mentioned there don't interfere with that plan.
>
>> 2) What other attributes (access permissions e.g.) of the master
>> along with the ones specified in (iv) should be passed on to the
>> children.
>
> Moreover, how are later changes of those attributes propagated?

I hear rumour of there being a more comprehensive proposal on this in
the works...
--
(reverse (concatenate 'string "ofni.secnanifxunil" "@" "enworbbc"))
http://linuxfinances.info/info/finances.html
Rules of the Evil Overlord #189. "I will never tell the hero "Yes I
was the one who did it, but you'll never be able to prove it to that
incompetent old fool." Chances are, that incompetent old fool is
standing behind the curtain." <http://www.eviloverlord.com/>


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Shane Ambler <pgsql(at)Sheeky(dot)Biz>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 17:43:19
Message-ID: 20070306174319.GA11202@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Wed, Mar 07, 2007 at 02:43:39AM +1030, Shane Ambler wrote:
> I think a way can be devised to maintain the primary key and unique
> constraints.
> If a search is done on the parent table, the planner knows to rewrite
> the query as a union (or union all) of all child tables that relate to
> the where clause, or all child tables if the where clause is not on the
> column/s used to partition, then this concept should be able to be
> converted to indexes as well, so that when a primary or unique index
> from a child table is inserted to, then each of the related child
> indexes is consulted to ensure uniqueness.

But that's where it breaks down: you not only need to check that the
row you're inserting is unique, you need to make sure that other people
trying to insert the same value see it.

After all, a unique index does contain multiple instances of any
particular value, it's just that the DB has verified that none of these
are visible to the same transaction. If there is a collision a lock is
taken that waits until the colliding insert commits or rejects.

With b-tree it's easy, every value can only appear in one place, so
it's a very simple lock. The reason why GiST doesn't support unique
indexes is due to the fact that any particular value could appear in
many places, so to stop concurrent inserts you need to lock *every*
page in the tree that another backend might want to insert the record.

I fear this will also be a problem for indexes over multiple tables, you
will need to lock the page in every index that some other DB might want
to insert the value into. All while avoiding deadlocks.

I think the problems are related. If you can solve it for multiple
tables, you can solve it for GiST indexes also.

> This would only apply if the partitioning was not done by the primary or
> unique column.

That's the easy case, no problem there.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Shane Ambler <pgsql(at)Sheeky(dot)Biz>, NikhilS <nikkhils(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 18:27:03
Message-ID: 45EDB277.3050703@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Martijn van Oosterhout wrote:
> On Wed, Mar 07, 2007 at 02:43:39AM +1030, Shane Ambler wrote:
>> I think a way can be devised to maintain the primary key and unique
>> constraints.
>> If a search is done on the parent table, the planner knows to rewrite
>> the query as a union (or union all) of all child tables that relate to
>> the where clause, or all child tables if the where clause is not on the
>> column/s used to partition, then this concept should be able to be
>> converted to indexes as well, so that when a primary or unique index
>> from a child table is inserted to, then each of the related child
>> indexes is consulted to ensure uniqueness.
>
> But that's where it breaks down: you not only need to check that the
> row you're inserting is unique, you need to make sure that other people
> trying to insert the same value see it.

This sounds like what is really needed is a way to lock a certain
condition, namely the existance or non-existance of a record with
certain values in certain fields. This would not only help this case,
it would also help RI triggers, because those wouldn't have to acquire
a share lock on the referenced rows anymore.

As you pointed out, this would also make unique GiST indices possible

No real idea how to do this, though :-(

greetings, Florian Pfluge


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 18:35:19
Message-ID: 200703061935.19848.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS wrote:
> We will not (I know its a hard thing to do :) ), the intention is to
> use this information from the parent and make it a property of the
> child table. This will avoid the step for the user having to manually
> specify CREATE INDEX and the likes on all the children tables
> one-by-one.

But when I say

CREATE TABLE ( a int PRIMARY KEY, ... ) PARTITION blah ...

then I expect that the primary key will be enforced across all
partitions. We currently sidestep that issue by not offering seemingly
transparent partitioning. But if you are planning to offer that, the
unique index issue needs to be solved, and I see nothing in your plan
about that.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 18:44:25
Message-ID: 7004.1173206665@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> But when I say
> CREATE TABLE ( a int PRIMARY KEY, ... ) PARTITION blah ...
> then I expect that the primary key will be enforced across all
> partitions. We currently sidestep that issue by not offering seemingly
> transparent partitioning. But if you are planning to offer that, the
> unique index issue needs to be solved, and I see nothing in your plan
> about that.

Agreed, it needs to Just Work. I think it'd still be useful though
if we only support auto-partitioning on the primary key, and that
restriction avoids the indexing problem.

regards, tom lane


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, Shane Ambler <pgsql(at)sheeky(dot)biz>, NikhilS <nikkhils(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 18:44:31
Message-ID: 200703061044.31936.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Florian,

> This sounds like what is really needed is a way to lock a certain
> condition, namely the existance or non-existance of a record with
> certain values in certain fields. This would not only help this case,
> it would also help RI triggers, because those wouldn't have to acquire
> a share lock on the referenced rows anymore.

That's called "predicate locking" and it's very, very hard to do.

--
Josh Berkus
PostgreSQL @ Sun
San Francisco


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, NikhilS <nikkhils(at)gmail(dot)com>
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 19:04:41
Message-ID: 200703061104.42094.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

> Agreed, it needs to Just Work. I think it'd still be useful though
> if we only support auto-partitioning on the primary key, and that
> restriction avoids the indexing problem.

+1

--
Josh Berkus
PostgreSQL @ Sun
San Francisco


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, NikhilS <nikkhils(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 20:34:53
Message-ID: 45EDD06D.6010307@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
>
>> But when I say
>> CREATE TABLE ( a int PRIMARY KEY, ... ) PARTITION blah ...
>> then I expect that the primary key will be enforced across all
>> partitions. We currently sidestep that issue by not offering seemingly
>> transparent partitioning. But if you are planning to offer that, the
>> unique index issue needs to be solved, and I see nothing in your plan
>> about that.
>>
>
> Agreed, it needs to Just Work. I think it'd still be useful though
> if we only support auto-partitioning on the primary key, and that
> restriction avoids the indexing problem.
>
>

Maybe. The most obvious use for automatic partitioning that I can think
of would be based in the value of a timestamptz field rather than any
PK. Of course I tend to work more in the OLTP field than in DW type
apps, where other considerations might apply.

cheers

andrew


From: "Joris Dobbelsteen" <Joris(at)familiedobbelsteen(dot)nl>
To: "Josh Berkus" <josh(at)agliodbs(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Cc: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>, "Martijn van Oosterhout" <kleptog(at)svana(dot)org>, "Shane Ambler" <pgsql(at)sheeky(dot)biz>, "NikhilS" <nikkhils(at)gmail(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Subject: Re: Auto creation of Partitions
Date: 2007-03-06 21:54:50
Message-ID: 73427AD314CC364C8DF0FFF9C4D693FF0379BE@nehemiah.joris2k.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

>-----Original Message-----
>From: pgsql-hackers-owner(at)postgresql(dot)org
>[mailto:pgsql-hackers-owner(at)postgresql(dot)org] On Behalf Of Josh Berkus
>Sent: dinsdag 6 maart 2007 19:45
>To: pgsql-hackers(at)postgresql(dot)org
>Cc: Florian G. Pflug; Martijn van Oosterhout; Shane Ambler;
>NikhilS; Peter Eisentraut
>Subject: Re: [HACKERS] Auto creation of Partitions
>
>Florian,
>
>> This sounds like what is really needed is a way to lock a certain
>> condition, namely the existance or non-existance of a record with
>> certain values in certain fields. This would not only help
>this case,
>> it would also help RI triggers, because those wouldn't have
>to acquire
>> a share lock on the referenced rows anymore.
>
>That's called "predicate locking" and it's very, very hard to do.

That's definitely not needed.

Rather something good such that we can finally enforce RI ourselves in
the general case. This is currently not possible to do easily, except in
C code. This means we need to look at all the rows that exists, but are
normally be invisible to our view of the database. Still I'm not sure
about all cases, as the MVCC model is quite tricky and I'm not sure
whether my idea's about it are valid.

The basic idea is that you need to guarentee the constraint for the
'single underlaying model' (with everything visible) and for your view
(under your visibility rules). I believe, but are not certain, that
under these conditions any (valid) snapshot will obey the desired
constraints.

- Joris Dobbelsteen


From: Trevor Hardcastle <chizu(at)spicious(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Subject: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-03-07 03:06:29
Message-ID: 45EE2C35.6020908@spicious.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Greetings all,

I wrote this patch about a week ago to introduce myself to coding on
PostgreSQL. I wasn't entirely sure what the 'INCLUDING INDEXES' option
was meant to do, so I held off submitting it until I could get around to
asking about that and tweaking the documentation to reflect the patch.
By useful coincidence the thread "Auto creation of Partitions" had this
post in it, which made the intent of the option clear enough for me to
go ahead and see what people think of this.

Gregory Stark wrote:
> "NikhilS" <nikkhils(at)gmail(dot)com> writes:
>
>
>> the intention is to use this information from the parent and make it a
>> property of the child table. This will avoid the step for the user having to
>> manually specify CREATE INDEX and the likes on all the children tables
>> one-by-one.
>>
>
> Missed the start of this thread. A while back I had intended to add WITH
> INDEXES to CREATE TABLE LIKE. That would let you create a tale LIKE parent
> WITH CONSTRAINTS WITH INDEXES and get pretty much a perfect table ready for
> adding to the inheritance structure.
>
>
>
So, that's what this patch does. When a table is created with 'CREATE
TABLE ... LIKE parent INCLUDING INDEXES' this iterates over the parent
table indexes looking for constraint indexes, and alters the
CreateStmtContext to include equivalent indexes on the child table.

This is probably a somewhat naive implementation, being a first attempt.
I wasn't sure what sort of lock to place on the parent indexes or what
tablespace the new indexes should be created in. Any help improving it
would be appreciated.

Thank you,
-Trevor Hardcastle

Attachment Content-Type Size
like_including_indexes.patch text/plain 8.6 KB

From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Shane Ambler" <pgsql(at)sheeky(dot)biz>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 06:40:39
Message-ID: d3c4af540703062240y16f4753ambba23d0113690fd7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi Shane,

Maybe I'm looking at auto-maintenance which is beyond any current planning?

Many of your suggestions are useful, but auto-maintenance will be beyond the
current plan.

Regards,
Nikhils

EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 06:44:49
Message-ID: d3c4af540703062244m2a2d5579r828f3c5c4d1648dd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 3/7/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > But when I say
> > CREATE TABLE ( a int PRIMARY KEY, ... ) PARTITION blah ...
> > then I expect that the primary key will be enforced across all
> > partitions. We currently sidestep that issue by not offering seemingly
> > transparent partitioning. But if you are planning to offer that, the
> > unique index issue needs to be solved, and I see nothing in your plan
> > about that.
>
> Agreed, it needs to Just Work. I think it'd still be useful though
> if we only support auto-partitioning on the primary key, and that
> restriction avoids the indexing problem.
>
> regards, tom lane
>

Sure, but as Chris mentioned earlier, wouldn't it be useful to maintain
uniqueness on a
partition-by-partition basis too?

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, NikhilS <nikkhils(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 07:20:19
Message-ID: 45EE67B3.7020101@kaltenbrunner.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Dunstan wrote:
> Tom Lane wrote:
>> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
>>
>>> But when I say
>>> CREATE TABLE ( a int PRIMARY KEY, ... ) PARTITION blah ...
>>> then I expect that the primary key will be enforced across all
>>> partitions. We currently sidestep that issue by not offering
>>> seemingly transparent partitioning. But if you are planning to offer
>>> that, the unique index issue needs to be solved, and I see nothing in
>>> your plan about that.
>>>
>>
>> Agreed, it needs to Just Work. I think it'd still be useful though
>> if we only support auto-partitioning on the primary key, and that
>> restriction avoids the indexing problem.
>>
>>
>
> Maybe. The most obvious use for automatic partitioning that I can think
> of would be based in the value of a timestamptz field rather than any
> PK. Of course I tend to work more in the OLTP field than in DW type
> apps, where other considerations might apply.

I second that - partitioning on some kind of timestamp field is a common
usecase here too ...

Stefan


From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, NikhilS <nikkhils(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 07:49:53
Message-ID: 45EE6EA1.7010607@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

>
>>
>> Maybe. The most obvious use for automatic partitioning that I can
>> think of would be based in the value of a timestamptz field rather
>> than any PK. Of course I tend to work more in the OLTP field than in
>> DW type apps, where other considerations might apply.
>
> I second that - partitioning on some kind of timestamp field is a
> common usecase here too ...
Partitioning period needs to work. It doesn't matter what the user
chooses as their partition key. Timestamp is an obvious
choice but there are others such as serial where you just partition
every million rows (for example) to keep things manageable.

Joshua D. Drake

>
>
> Stefan
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 09:01:21
Message-ID: 200703071001.21875.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Am Mittwoch, 7. März 2007 07:44 schrieb NikhilS:
> Sure, but as Chris mentioned earlier, wouldn't it be useful to maintain
> uniqueness on a
> partition-by-partition basis too?

Many things might be useful, but the aim of the "table partitioning" venture
is believed to be the provision of a transparent interface to the existing
do-it-yourself partitioning facilities. Therefore, the logical definition of
a table must continue to work unchanged (or alternatively, the use of the
feature must be prohibited if that cannot be guaranteed in a particular
case). Other features such as uniqueness on a partition basis might also be
useful but you can do that today and you don't need partitioning for that.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "NikhilS" <nikkhils(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 10:26:40
Message-ID: 1173263201.3760.2278.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Tue, 2007-03-06 at 18:31 +0530, NikhilS wrote:

> On 3/6/07, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> NikhilS wrote:
> > iv) Based on the PRIMARY, UNIQUE, REFERENCES information
> specified,
> > pass it on to the children tables.
>
> How will you maintain a primary key in such a table,
> considering that
> indexes can't span multiple tables?
>
> We will not (I know its a hard thing to do :) ), the intention is to
> use this information from the parent and make it a property of the
> child table. This will avoid the step for the user having to manually
> specify CREATE INDEX and the likes on all the children tables
> one-by-one.

If you know that the constraints on each of the tables is distinct, then
building a UNIQUE index on each of the partitions is sufficient to prove
that all rows in the combined partitioned table are distinct also.

The hard part there is checking that the partition constraints are
distinct. If the partition constraints are added one at a time, you can
use the predicate testing logic to compare the to-be-added partition's
constraint against each of the already added constraints. That becomes
an O(N) problem.

What is really needed is a data structure that allows range partitions
to be accessed more efficiently. This could make adding partitions and
deciding in which partition a specific value goes an O(logN) operation.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 11:52:57
Message-ID: d3c4af540703070352k4bd631deyd328050f60678430@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

If you know that the constraints on each of the tables is distinct, then
> building a UNIQUE index on each of the partitions is sufficient to prove
> that all rows in the combined partitioned table are distinct also.
>
> The hard part there is checking that the partition constraints are
> distinct. If the partition constraints are added one at a time, you can
> use the predicate testing logic to compare the to-be-added partition's
> constraint against each of the already added constraints. That becomes
> an O(N) problem.
>
> What is really needed is a data structure that allows range partitions
> to be accessed more efficiently. This could make adding partitions and
> deciding in which partition a specific value goes an O(logN) operation.

If the unique constraint is supposed to be on a column which is NOT being
used for the partitioning, then all the above becomes much more difficult.
While partitioning, the additional onus on the user is to specify
non-conflicting CHECKs for the range/list partitions.

Regards,
Nikhils

--
> Simon Riggs
> EnterpriseDB http://www.enterprisedb.com
>
>
>

--
EnterpriseDB http://www.enterprisedb.com


From: "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>
To: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Cc: "NikhilS" <nikkhils(at)gmail(dot)com>
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 13:34:16
Message-ID: E1539E0ED7043848906A8FF995BDA57901D42CF3@m0143.s-mxs.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


> > iv) Based on the PRIMARY, UNIQUE, REFERENCES information specified,
> > pass it on to the children tables.
>
> How will you maintain a primary key in such a table,
> considering that indexes can't span multiple tables?

Many partitioning schemes have (or can be made to have) only one
possible target partition for the primary key. Thus if you create
separate unique indexes on each partition the problem is solved.
For a first version I opt, that it is sufficient to disallow creation of
a unique index on the master, when the constraints (on columns of this
index) do not nail down a specific partition for each row (e.g. a hash
or a range on one of the index columns that does not overlap).
Later, global index, or indexes with separate partitioning rules can be
implemented, that cover the other cases.

Andreas


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 14:29:48
Message-ID: d3c4af540703070629s7f475700n34990ef0438112ee@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 3/7/07, Zeugswetter Andreas ADI SD <ZeugswetterA(at)spardat(dot)at> wrote:
>
>
> > > iv) Based on the PRIMARY, UNIQUE, REFERENCES information specified,
> > > pass it on to the children tables.
> >
> > How will you maintain a primary key in such a table,
> > considering that indexes can't span multiple tables?
>
> Many partitioning schemes have (or can be made to have) only one
> possible target partition for the primary key. Thus if you create
> separate unique indexes on each partition the problem is solved.
> For a first version I opt, that it is sufficient to disallow creation of
> a unique index on the master, when the constraints (on columns of this
> index) do not nail down a specific partition for each row (e.g. a hash
> or a range on one of the index columns that does not overlap).
> Later, global index, or indexes with separate partitioning rules can be
> implemented, that cover the other cases.
>
> Andreas
>

Yes, I agree. For version 1, UNIQUE/PRIMARY indexes will cascade down to the
child table, only if the indexed column is present as part of the
partitioning rule.

Regards,
Nikhils

--
EnterpriseDB http://www.enterprisedb.com


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Zeugswetter Andreas ADI SD <ZeugswetterA(at)spardat(dot)at>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 14:58:32
Message-ID: 20070307145832.GA21435@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

I am wondering if we can implement unique indexes across several tables
(inheritance hierarchy) not by using a single, big index covering all
the tables, but rather by inserting a dummy entry into each partition's
unique index. This dummy entry would have an expanded CTID which would
include the tableoid, so it's possible to check it (albeit there is a
problem in that we may require the opening of another heap to do the
actual checking). These dummy entries could be removed by bulkcleanup
as soon as the inserting transaction is no longer running, to avoid
bloating the index too much. All said dummy index entries would be
located at either the rightmost or the leftmost leaf, or close to it, so
another idea is to have future inserters reuse the entry for a different
key.

The obvious problem with this is, naturally, the excess I/O that extra
index traversing causes. The not so obvious ones are locking,
deadlocking and the opening of other heaps and indexes while you do the
insertion, which may be too expensive. On the other hand, maybe this
idea is easier to implement than full-fledged cross-table indexes, so we
could have richer partitioning earlier than when somebody finally bites
the bullet and implements cross-table indexes.

Or maybe this is just a dumb idea, but I had to let it out anyway :-)

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: "Luke Lonergan" <llonergan(at)greenplum(dot)com>
To: "Simon Riggs" <simon(at)2ndquadrant(dot)com>, "NikhilS" <nikkhils(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 15:23:40
Message-ID: C214432C.28B7C%llonergan@greenplum.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Simon,

On 3/7/07 5:26 AM, "Simon Riggs" <simon(at)2ndquadrant(dot)com> wrote:

> What is really needed is a data structure that allows range partitions
> to be accessed more efficiently. This could make adding partitions and
> deciding in which partition a specific value goes an O(logN) operation.

I think we need to re-evaluate the inheritance mechanism for partitioning
and implement something much closer to the storage layer, similar to Oracle.

Having the constraint exclusion occur in the planner is not flexible enough
to allow more advanced solutions.

- Luke


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "Luke Lonergan" <llonergan(at)greenplum(dot)com>
Cc: "NikhilS" <nikkhils(at)gmail(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 15:52:22
Message-ID: 1173282743.3760.2418.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Wed, 2007-03-07 at 10:23 -0500, Luke Lonergan wrote:
> Simon,
>
> On 3/7/07 5:26 AM, "Simon Riggs" <simon(at)2ndquadrant(dot)com> wrote:
>
> > What is really needed is a data structure that allows range partitions
> > to be accessed more efficiently. This could make adding partitions and
> > deciding in which partition a specific value goes an O(logN) operation.
>
> I think we need to re-evaluate the inheritance mechanism for partitioning
> and implement something much closer to the storage layer, similar to Oracle.

Oracle's implementation is fairly close to ours, actually. Each
partition is a segment. SQLServer's is fairly low level.

> Having the constraint exclusion occur in the planner is not flexible enough
> to allow more advanced solutions.

It depends what those advanced solutions are. I definitely want to be
able to do run-time exclusion, push down merge joins and parallelism,
but I also think that being able to index only the first 3 partitions is
a useful feature too.

ISTM that making the Append node responsible for exclusion might be a
way to go with this, but various ways are possible, I'm sure. The trick
is to find one that does everything you need and that will take some
deeper analysis.

However you do it, you'll still need a way of deciding which partitions
to include/exclude that doesn't involve a sequential scan of all
partition constraints. So my comments about a different index structure
are still going to be relevant, wherever that lives/executes.

I'm not doing anything in this area personally for 8.3 though.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>
To: "Luke Lonergan" <llonergan(at)greenplum(dot)com>, "Simon Riggs" <simon(at)2ndquadrant(dot)com>, "NikhilS" <nikkhils(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 16:45:51
Message-ID: E1539E0ED7043848906A8FF995BDA57901D42D80@m0143.s-mxs.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


> > What is really needed is a data structure that allows range
partitions
> > to be accessed more efficiently. This could make adding partitions
and
> > deciding in which partition a specific value goes an O(logN)
operation.
>
> I think we need to re-evaluate the inheritance mechanism for
> partitioning and implement something much closer to the
> storage layer, similar to Oracle.
>
> Having the constraint exclusion occur in the planner is not
> flexible enough to allow more advanced solutions.

Whoa, do you have anything to back that up ?
You would need to elaborate what you actually mean, but I think it is
moot.
Sure, the constraint technique can be further extended (e.g. during
runtime), but imho the approach is very good.

Andreas


From: "Joris Dobbelsteen" <Joris(at)familiedobbelsteen(dot)nl>
To: "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>, "NikhilS" <nikkhils(at)gmail(dot)com>
Cc: "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-07 20:13:40
Message-ID: 73427AD314CC364C8DF0FFF9C4D693FF0379C6@nehemiah.joris2k.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

>-----Original Message-----
>From: pgsql-hackers-owner(at)postgresql(dot)org
>[mailto:pgsql-hackers-owner(at)postgresql(dot)org] On Behalf Of Alvaro Herrera
>Sent: woensdag 7 maart 2007 15:59
>To: NikhilS
>Cc: Zeugswetter Andreas ADI SD; Peter Eisentraut;
>pgsql-hackers(at)postgresql(dot)org
>Subject: Re: [HACKERS] Auto creation of Partitions
>
>I am wondering if we can implement unique indexes across
>several tables (inheritance hierarchy) not by using a single,
>big index covering all the tables, but rather by inserting a
>dummy entry into each partition's unique index.

I think that one big index is much better in this case. You are already
replicating the data and need a lot of work when updating the partition
structure (e.g. removing one).

[snip]

Rather:
If we have the partition relations (aka partition), then we can define a
unique index on it. This guarentees that there is at most one tuple with
the same value (for the specified columns) for every individual
partition.

Now for the inserts.
We already guarentee that is unique within the partition it lives. So we
must insert it first.
Next its to check the other partitions (in order!) for existence of a
row with a similar context. Of course we require full visibility of the
data.
We do the insert first, as this ensures other will find it. The order is
also important, otherwise there can be situations where we can't
guarentee the constraint.

Updates are exactly the same.
Deletes are trivial.

Perhaps you can do it without an index, but this is nothing different
than for a normal table.

- Joris Dobbelsteen


From: "Luke Lonergan" <llonergan(at)greenplum(dot)com>
To: "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>, "Simon Riggs" <simon(at)2ndquadrant(dot)com>, "NikhilS" <nikkhils(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 03:32:14
Message-ID: C214EDEE.28C47%llonergan@greenplum.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andreas,

On 3/7/07 11:45 AM, "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>
wrote:

> Whoa, do you have anything to back that up ?

Sure - when we start to consider designs that implement advanced data
management features, we run into problems with the architecture of
"tables->tables->tables...". Here are some examples:
1 - people think of partitions as a logical building block for tables, they
would like to move partitions around underneath a table without the table
definition being involved. In the current implementation, there are
explicit linkages between the table definition and the child tables -
imagine an "ALTER TABLE foo_parent ADD COLUMN" and how it would need to
cascade to 1,000 child tables and you get the beginning of it - this
connection should not exist.

2 - INSERT/UPDATE/DELETE processing through the SQL rewrite layer (rules) is
terribly slow and gets slower as you add more partitions. If done closer to
the storage layer, this can be done in ways that use access methods shared
with other storage entities, e.g. Indices, and the code path would flow more
naturally.

3 - Parallel query can be accomplished more easily by separating scans
across relations split among tablespaces. This is more natural than trying
to parallelize APPEND nodes within existing plans

> You would need to elaborate what you actually mean, but I think it is
> moot.
> Sure, the constraint technique can be further extended (e.g. during
> runtime), but imho the approach is very good.

Well, it's being used and that's good, but it needs to be better IMO and I
think that before we go too far down the current path we should consider the
alternatives more carefully.

- Luke


From: Jim Nasby <decibel(at)decibel(dot)org>
To: Shane Ambler <pgsql(at)Sheeky(dot)Biz>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 04:07:42
Message-ID: 939623FB-0790-4AF5-9734-E94C9BDE4AB5@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mar 6, 2007, at 9:13 AM, Shane Ambler wrote:
> NikhilS wrote:
>> On 3/6/07, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
>>> 1) Whether we should use triggers/rules for step number (iii) above.
>>> > Maybe rules is the way to go.
>>>
>>> Since this would basically be a case of the updatable rules
>>> problem, you
>>> should review those discussions in the past to check whether the
>>> issues
>>> mentioned there don't interfere with that plan.
>> The rules mentioned here will be to specify that all the
>> inserts/updates/deletes should go into proper children tables
>> instead of the
>> parent. I do not see the updateable rules problem with regards to
>> this, but
>> will check out the archives for discussion on this related to
>> partitioning.
>
> I would think that a trigger would be a better choice as I see the
> need (or at least the possibility) for more than just a rewrite.
> When a value is inserted that is outside of a condition currently
> covered by an existing child table then a new child will need to be
> spawned to contain the new data.

There's no reason a new child has to be spawned, and I don't think
that having a DML statement 'automagically' generating DDL is such a
hot idea, either.

Also, there's nothing inherently wrong with having an 'overflow
partition' (to use Oracle syntax) that holds values that don't fall
in the range of any other tables. The obvious place to do that with
our partitioning is in the parent table.

There are 2 other reasons to favor triggers though:

1) People (Josh Drake comes to mind) have found that if you get over
a tiny number of partitions, the performance of rules is abysmal.

2) I believe it should be possible to construct an update trigger
that allows you to perform updates that will place the row in
question into a new partition. While I can see cases for simply
disallowing updates to the partitioning key, I think there are also
times when being able to do that would be very useful.

> Will ALTER TABLE be extended to handle partitions? This will allow
> partitioning existing tables (maybe without blocking access?) and
> allow things like ALTER TABLE mytable ADD PARTITION (mydate within
> 200703)
> and ALTER TABLE mytable DROP PARTITION (mydate within 199912) or
> would dropping be covered by DELETE FROM mytable where mydate <=
> 199912 ?

I think it'd be great to make adding and removing partitions as
simple as ALTER TABLE. I don't think that DELETE should be the
mechanism to drop a partition, though. Again, DML statements
shouldn't be performing DDL.

> Could such a syntax be devised for date columns? (month of mydate)
> or similar to auto create partitions based on the year and month of
> a date column? or will we just do CHECK(mydatecol >= 1/3/07 and
> mydatecol <= 31/3/07) for each month of data? Also (day of
> mydatecol) to partition based on year and day of year.
>
> Another syntax possibility - range(myserialcol of 500000) where new
> child tables are created every 500000 rows?
>
> Maybe I'm looking at auto-maintenance which is beyond any current
> planning?

I don't think it's worth it to burden the database with auto-creating
time partitions; it's easy enough to setup a cron job to handle it.

It might be more useful to have the database handle things like
partitioning on a SERIAL column, though I agree with Nikhils that
this should wait.

Does any other database support 'automagic' partition creation? I
know Oracle 9i doesn't... not sure about 10g or DB2 or MSSQL...
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Jim Nasby <decibel(at)decibel(dot)org>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 04:17:38
Message-ID: 65391829-366B-4A65-9E54-903D7C7195A9@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mar 6, 2007, at 4:57 AM, NikhilS wrote:
> iv) Based on the PRIMARY, UNIQUE, REFERENCES information specified,
> pass it on to the children tables.

Since we want to eventually support 'global' indexes, I think we need
to be really careful here. There's actually 3 possible cases:

1) Index* should be global (spanning multiple tables)
2) Index* should be inherited by all partitions as they're created
3) Index* should exist only on the parent table

* Note that there's really no reason this has to be limit to indexes;
it could certainly apply to constraints, or even triggers.

IIRC, Oracle has a special syntax for global indexes; any other index
defined on a partitioned table is picked up *by newly created
partitions*. If you want to add indexes to existing partitions, you
have to explicitly add it to each partition.

I'd like to eventually see us supporting all 3 options. I'm not sure
how much we want to clutter the grammar, though.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Jim Nasby <decibel(at)decibel(dot)org>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: "NikhilS" <nikkhils(at)gmail(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 04:27:03
Message-ID: 3304D747-FD0D-486B-894B-700DE210D772@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mar 7, 2007, at 3:26 AM, Simon Riggs wrote:
> If you know that the constraints on each of the tables is distinct,
> then
> building a UNIQUE index on each of the partitions is sufficient to
> prove
> that all rows in the combined partitioned table are distinct also.
>
> The hard part there is checking that the partition constraints are
> distinct. If the partition constraints are added one at a time, you
> can
> use the predicate testing logic to compare the to-be-added partition's
> constraint against each of the already added constraints. That becomes
> an O(N) problem.
>
> What is really needed is a data structure that allows range partitions
> to be accessed more efficiently. This could make adding partitions and
> deciding in which partition a specific value goes an O(logN)
> operation.

Directing data to child tables with triggers pretty much necessitates
having some way to codify what partition a particular row belongs in.
IE: for partitioning by month, you'll see things like naming the
partition tables "parent_table_name_$YEAR_$MONTH", so the
'partitioning function' takes a date or timestamp and then returns
what partition it belongs to. Perhaps there is some way to use that
mapping to drive the selection of what partitions could contain a
given value?

One possibility would be to require 3 functions for a partitioned
table: one accepts the partitioning key and tells you what partition
it's in, one that tells you what the minimum partitioning key for a
partition would be, and one that tells you what the maximum would be.
If the user supplied those 3 functions, I think it would be possibly
to automatically generate code for the triggers and check
constraints. The min/max partition key functions might allow you to
more efficiently do partition elimination, too.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: NikhilS <nikkhils(at)gmail(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>, "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 08:09:54
Message-ID: d3c4af540703080009o14edb846v512c98fabce6b0d1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

Maybe, the dummy entry could be extended to contain the bounds (max/min) for
each of the other involved partitions and they could be updated each time a
DML happens across the partitions. That ways, an update to a particular
partition needs to lock out the others, examine the dummy entries in its own
index and follow it up with dummy entries update into other partitions if
the need be.

Ofcourse as you have mentioned all of this so needs to be done after a
careful think on the locking/deadlocking etc issues.

Regards,
Nikhils

On 3/7/07, Alvaro Herrera <alvherre(at)commandprompt(dot)com> wrote:
>
> I am wondering if we can implement unique indexes across several tables
> (inheritance hierarchy) not by using a single, big index covering all
> the tables, but rather by inserting a dummy entry into each partition's
> unique index. This dummy entry would have an expanded CTID which would
> include the tableoid, so it's possible to check it (albeit there is a
> problem in that we may require the opening of another heap to do the
> actual checking). These dummy entries could be removed by bulkcleanup
> as soon as the inserting transaction is no longer running, to avoid
> bloating the index too much. All said dummy index entries would be
> located at either the rightmost or the leftmost leaf, or close to it, so
> another idea is to have future inserters reuse the entry for a different
> key.
>
> The obvious problem with this is, naturally, the excess I/O that extra
> index traversing causes. The not so obvious ones are locking,
> deadlocking and the opening of other heaps and indexes while you do the
> insertion, which may be too expensive. On the other hand, maybe this
> idea is easier to implement than full-fledged cross-table indexes, so we
> could have richer partitioning earlier than when somebody finally bites
> the bullet and implements cross-table indexes.
>
> Or maybe this is just a dumb idea, but I had to let it out anyway :-)
>
> --
> Alvaro Herrera
> http://www.CommandPrompt.com/
> The PostgreSQL Company - Command Prompt, Inc.
>

--
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Jim Nasby" <decibel(at)decibel(dot)org>
Cc: "Shane Ambler" <pgsql(at)sheeky(dot)biz>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 08:22:27
Message-ID: d3c4af540703080022l1cd34e7fo5e6712391bec0839@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> There are 2 other reasons to favor triggers though:
>
> 1) People (Josh Drake comes to mind) have found that if you get over
> a tiny number of partitions, the performance of rules is abysmal.
>
> 2) I believe it should be possible to construct an update trigger
> that allows you to perform updates that will place the row in
> question into a new partition. While I can see cases for simply
> disallowing updates to the partitioning key, I think there are also
> times when being able to do that would be very useful.

The consensus seems to be veering towards triggers.

>
> I think it'd be great to make adding and removing partitions as
> simple as ALTER TABLE. I don't think that DELETE should be the
> mechanism to drop a partition, though. Again, DML statements
> shouldn't be performing DDL.

Since partition is inheritance-based, a simple DROP or "NO INHERIT" will do
the job to deal with the partition. Do we want to reinvent additional syntax
when these are around and are documented?

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "Luke Lonergan" <llonergan(at)greenplum(dot)com>
Cc: "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>, "NikhilS" <nikkhils(at)gmail(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 08:45:43
Message-ID: 1173343544.3641.47.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Wed, 2007-03-07 at 22:32 -0500, Luke Lonergan wrote:
> Andreas,
>
> On 3/7/07 11:45 AM, "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>
> wrote:
>
> > Whoa, do you have anything to back that up ?
>
> Sure - when we start to consider designs that implement advanced data
> management features, we run into problems with the architecture of
> "tables->tables->tables...". Here are some examples:
> 1 - people think of partitions as a logical building block for tables, they
> would like to move partitions around underneath a table without the table
> definition being involved. In the current implementation, there are
> explicit linkages between the table definition and the child tables -
> imagine an "ALTER TABLE foo_parent ADD COLUMN" and how it would need to
> cascade to 1,000 child tables and you get the beginning of it - this
> connection should not exist.

The inheritance can work at multiple levels, so its up to you how you
manage things. If you want to add a column to only the newest tables,
you just add a new mid-level table, add the new column only to that and
then make all new partitions inherit from that table rather than the
main table. So I don't see the objection here, I see a benefit.

> 2 - INSERT/UPDATE/DELETE processing through the SQL rewrite layer (rules) is
> terribly slow and gets slower as you add more partitions. If done closer to
> the storage layer, this can be done in ways that use access methods shared
> with other storage entities, e.g. Indices, and the code path would flow more
> naturally.

That bit is just syntactic sugar and unnecessary, for most applications,
in my experience - especially because it doesn't work with COPY.

People do seem to want it, so as I said upthread, we need a way of
speeding up the selection of the appropriate partition, so we can get
this to work for individual INSERTs.

This needs substantial improvement, but I don't see this challenging the
partition == table assumption.

> 3 - Parallel query can be accomplished more easily by separating scans
> across relations split among tablespaces. This is more natural than trying
> to parallelize APPEND nodes within existing plans

Tables-> Partitions -> Tablespaces

Changing Partitions from Tables to SomethingElse won't increase the
current capability to define the disk layout for concurrent I/O.

Parallel Query needs to be planner-aware, so if we change partitions
from being tables, then we'd need to reintroduce them to the planner.
APPEND is clearly not the only thing that's needed for parallel query.

Note to Nikhil: Make sure the new syntax doesn't prevent partitions from
being placed upon multiple tablespaces in some manner, at CREATE TABLE
time.

> > You would need to elaborate what you actually mean, but I think it is
> > moot.
> > Sure, the constraint technique can be further extended (e.g. during
> > runtime), but imho the approach is very good.
>
> Well, it's being used and that's good, but it needs to be better IMO and I
> think that before we go too far down the current path we should consider the
> alternatives more carefully.

I'm happy to reconsider things, but we need to do that with some clear
analysis of what doesn't work yet and how best to implement that.

None of what's been mentioned requires us to reconsider the
Partition == Table assumption. There were other ways considered, but
they didn't win out in the analysis, for documented reasons.

If there are benefits to having partitions act like tables, then maybe
we can make them behave differently in just those circumstances. Pack
animals behave differently in a group, so why not tables, if need be?
But when is that exactly?

There is a ton of work to make partitioning the elegant beast we'd like
it to be, but that seems like extension only, not rip and replace.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "Jim Nasby" <decibel(at)decibel(dot)org>
Cc: "NikhilS" <nikkhils(at)gmail(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 08:47:32
Message-ID: 1173343653.3641.49.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Wed, 2007-03-07 at 21:27 -0700, Jim Nasby wrote:
> On Mar 7, 2007, at 3:26 AM, Simon Riggs wrote:
> > If you know that the constraints on each of the tables is distinct,
> > then
> > building a UNIQUE index on each of the partitions is sufficient to
> > prove
> > that all rows in the combined partitioned table are distinct also.
> >
> > The hard part there is checking that the partition constraints are
> > distinct. If the partition constraints are added one at a time, you
> > can
> > use the predicate testing logic to compare the to-be-added partition's
> > constraint against each of the already added constraints. That becomes
> > an O(N) problem.
> >
> > What is really needed is a data structure that allows range partitions
> > to be accessed more efficiently. This could make adding partitions and
> > deciding in which partition a specific value goes an O(logN)
> > operation.
>
> Directing data to child tables with triggers pretty much necessitates
> having some way to codify what partition a particular row belongs in.
> IE: for partitioning by month, you'll see things like naming the
> partition tables "parent_table_name_$YEAR_$MONTH", so the
> 'partitioning function' takes a date or timestamp and then returns
> what partition it belongs to. Perhaps there is some way to use that
> mapping to drive the selection of what partitions could contain a
> given value?
>
> One possibility would be to require 3 functions for a partitioned
> table: one accepts the partitioning key and tells you what partition
> it's in, one that tells you what the minimum partitioning key for a
> partition would be, and one that tells you what the maximum would be.
> If the user supplied those 3 functions, I think it would be possibly
> to automatically generate code for the triggers and check
> constraints. The min/max partition key functions might allow you to
> more efficiently do partition elimination, too.

ISTM this is a good idea.

SQLServer uses partitioning functions and I like that approach. It makes
it much easier to do partition-wise joins between tables that share
partitioning functions.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Jim Nasby" <decibel(at)decibel(dot)org>
Cc: "Simon Riggs" <simon(at)2ndquadrant(dot)com>, "NikhilS" <nikkhils(at)gmail(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 10:12:30
Message-ID: 87wt1s6o35.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"Jim Nasby" <decibel(at)decibel(dot)org> writes:

> One possibility would be to require 3 functions for a partitioned table: one
> accepts the partitioning key and tells you what partition it's in, one that
> tells you what the minimum partitioning key for a partition would be, and one
> that tells you what the maximum would be. If the user supplied those 3
> functions, I think it would be possibly to automatically generate code for the
> triggers and check constraints. The min/max partition key functions might
> allow you to more efficiently do partition elimination, too.

But then it would be harder to tell whether a clause implied a given
partition. That is, if you have a partition constraint of "col OP const" then
we can test whether a query clause of "col OP2 const2" implies that constraint
when planning (or actually whether it implies it's false to exclude the
partition). If you have a constraint like "P1(const)" it'll be pretty hard to
do much with that.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com


From: "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>
To: "Jim Nasby" <decibel(at)decibel(dot)org>, "Simon Riggs" <simon(at)2ndquadrant(dot)com>
Cc: "NikhilS" <nikkhils(at)gmail(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 10:22:08
Message-ID: E1539E0ED7043848906A8FF995BDA57901D42E34@m0143.s-mxs.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

> > The hard part there is checking that the partition constraints are
> > distinct. If the partition constraints are added one at a time, you
> > can use the predicate testing logic to compare the to-be-added
> > partition's constraint against each of the already added
constraints.
> > That becomes an O(N) problem.

Yes, we could preevaluate that check (per index) in the DDL phase and
keep the info in a flag.
Also interesting info is if there is an order the partitions can be read
in to satisfy a particular order by.

> > What is really needed is a data structure that allows range
partitions
> > to be accessed more efficiently. This could make adding partitions
and
> > deciding in which partition a specific value goes an O(logN)
> > operation.

I do not really see a problem with O(N) since typical N currently range
from 10 to 200.
N = 1000 is already good for a >= 10 TB table.
If a 10 GB partition were too large we should imho invest more in the
advanced indexing methods that are currently beeing developed.

> Directing data to child tables with triggers pretty much
> necessitates having some way to codify what partition a
> particular row belongs in.
> IE: for partitioning by month, you'll see things like naming
> the partition tables "parent_table_name_$YEAR_$MONTH", so the
> 'partitioning function' takes a date or timestamp and then
> returns what partition it belongs to. Perhaps there is some
> way to use that mapping to drive the selection of what
> partitions could contain a given value?

You put it in the first partition that has matching constraints.

> One possibility would be to require 3 functions for a partitioned
> table: one accepts the partitioning key and tells you what
> partition it's in, one that tells you what the minimum
> partitioning key for a partition would be, and one that tells
> you what the maximum would be.
> If the user supplied those 3 functions, I think it would be
> possibly to automatically generate code for the triggers and
> check constraints. The min/max partition key functions might
> allow you to more efficiently do partition elimination, too.

I can see this as a good optional addition, but it can only be optional
else it would pretty much limit the methods that can be used for
partitioning. e.g. hash, modulo do not have a min,max per partition.

Andreas


From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Jim Nasby <decibel(at)decibel(dot)org>, Shane Ambler <pgsql(at)sheeky(dot)biz>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 18:44:20
Message-ID: 20070308184419.GU24979@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Thu, Mar 08, 2007 at 01:52:27PM +0530, NikhilS wrote:
> >I think it'd be great to make adding and removing partitions as
> >simple as ALTER TABLE. I don't think that DELETE should be the
> >mechanism to drop a partition, though. Again, DML statements
> >shouldn't be performing DDL.
>
>
> Since partition is inheritance-based, a simple DROP or "NO INHERIT" will do
> the job to deal with the partition. Do we want to reinvent additional syntax
> when these are around and are documented?

Well, if the syntax for adding a new partition eventually ends up as
ALTER TABLE ADD PARTITION, then it would make more sense that you remove
a partition via ALTER TABLE DROP PARTITION.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: Jim Nasby <decibel(at)decibel(dot)org>, Simon Riggs <simon(at)2ndquadrant(dot)com>, NikhilS <nikkhils(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 18:51:19
Message-ID: 20070308185119.GV24979@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Thu, Mar 08, 2007 at 10:12:30AM +0000, Gregory Stark wrote:
> "Jim Nasby" <decibel(at)decibel(dot)org> writes:
>
> > One possibility would be to require 3 functions for a partitioned table: one
> > accepts the partitioning key and tells you what partition it's in, one that
> > tells you what the minimum partitioning key for a partition would be, and one
> > that tells you what the maximum would be. If the user supplied those 3
> > functions, I think it would be possibly to automatically generate code for the
> > triggers and check constraints. The min/max partition key functions might
> > allow you to more efficiently do partition elimination, too.
>
> But then it would be harder to tell whether a clause implied a given
> partition. That is, if you have a partition constraint of "col OP const" then
> we can test whether a query clause of "col OP2 const2" implies that constraint
> when planning (or actually whether it implies it's false to exclude the
> partition). If you have a constraint like "P1(const)" it'll be pretty hard to
> do much with that.

Well, you could tell what partition 'const' was in; I would think that
plus knowledge about OP2 would allow you to decide what partitions you
need to look at.

There's also nothing to prevent us from also adding the constraints and
using constraint exclusion as well. In fact, I think we'd want to have
the constraints just so we know that a given partition only contains the
data we want it to.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 18:54:57
Message-ID: 20070308185457.GW24979@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

One other thought... a lot of this discussion seems to parallel the
debate from a while ago about whether SERIAL should act like a macro
(ie: it just sets everything up and users are free to monkey under the
hood afterwards), or whether it should be it's own 'closed-box'
construct.

Currently, we seem to be leaning towards partition management being a
'macro', with child tables very exposed, etc. I don't know if that's
good or bad, but it's probably worth some thought.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Shane Ambler <pgsql(at)Sheeky(dot)Biz>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Luke Lonergan <llonergan(at)greenplum(dot)com>, Zeugswetter Andreas ADI SD <ZeugswetterA(at)spardat(dot)at>, NikhilS <nikkhils(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 20:10:29
Message-ID: 45F06DB5.1010207@Sheeky.Biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


> Note to Nikhil: Make sure the new syntax doesn't prevent partitions from
> being placed upon multiple tablespaces in some manner, at CREATE TABLE
> time.

What if the syntax was something like -

CREATE TABLE tabname (
...
...
) PARTITION BY
HASH(expr)
| RANGE(expr)
| LIST(expr)
[PARTITIONS num_partitions] /* will apply to HASH only for now*/
[PARTITION partition_name CHECK(...) [USING TABLESPACE tblspcname],
PARTITION partition_name CHECK(...) [USING TABLESPACE tblspcname]
...
];

And (if we use the ALTER TABLE to add partitions)

ALTER TABLE tabname
ADD PARTITION partition_name CHECK(...)
[USING TABLESPACE tblspcname];

Of course ALTER TABLE childtable SET TABLESPACE tblspcname; should not
cause any probs.

--

Shane Ambler
pgSQL(at)Sheeky(dot)Biz

Get Sheeky @ http://Sheeky.Biz


From: Shane Ambler <pgsql(at)Sheeky(dot)Biz>
To: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, Jim Nasby <decibel(at)decibel(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-08 22:01:10
Message-ID: 45F087A6.3010107@Sheeky.Biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Jim C. Nasby wrote:
> On Thu, Mar 08, 2007 at 01:52:27PM +0530, NikhilS wrote:
>>> I think it'd be great to make adding and removing partitions as
>>> simple as ALTER TABLE. I don't think that DELETE should be the
>>> mechanism to drop a partition, though. Again, DML statements
>>> shouldn't be performing DDL.
>>
>> Since partition is inheritance-based, a simple DROP or "NO INHERIT" will do
>> the job to deal with the partition. Do we want to reinvent additional syntax
>> when these are around and are documented?
>
> Well, if the syntax for adding a new partition eventually ends up as
> ALTER TABLE ADD PARTITION, then it would make more sense that you remove
> a partition via ALTER TABLE DROP PARTITION.

This follows on from the suggestion I made - taken along the lines of
the subject "auto creation of partitions" where I suggested the syntax
of partition check(month of mydatecol) and have a new partition created
as data was entered. With this scenario dropping the partition when it
was empty would complement the creation of a new partition as needed.

Given that there seems to be no real support of going with "auto
maintenance" were new partitions are added as needed, then the auto
dropping of empty partitions would also not apply.

Leaving us with only specific add partition / drop partition commands.
And have the parent table pick up rows not matching any partition check
criteria.

--

Shane Ambler
pgSQL(at)Sheeky(dot)Biz

Get Sheeky @ http://Sheeky.Biz


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Shane Ambler" <pgsql(at)sheeky(dot)biz>
Cc: "Simon Riggs" <simon(at)2ndquadrant(dot)com>, "Luke Lonergan" <llonergan(at)greenplum(dot)com>, "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-09 06:18:34
Message-ID: d3c4af540703082218k1bf6a0ecw784bfb023eaab8b5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 3/9/07, Shane Ambler <pgsql(at)sheeky(dot)biz> wrote:
>
>
> > Note to Nikhil: Make sure the new syntax doesn't prevent partitions from
> > being placed upon multiple tablespaces in some manner, at CREATE TABLE
> > time.
>
> What if the syntax was something like -
>
> CREATE TABLE tabname (
> ...
> ...
> ) PARTITION BY
> HASH(expr)
> | RANGE(expr)
> | LIST(expr)
> [PARTITIONS num_partitions] /* will apply to HASH only for now*/
> [PARTITION partition_name CHECK(...) [USING TABLESPACE tblspcname],
> PARTITION partition_name CHECK(...) [USING TABLESPACE tblspcname]
> ...
> ];
>
>
> And (if we use the ALTER TABLE to add partitions)
>
> ALTER TABLE tabname
> ADD PARTITION partition_name CHECK(...)
> [USING TABLESPACE tblspcname];
>
>
We could as well drop the USING part.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Shane Ambler" <pgsql(at)sheeky(dot)biz>
Cc: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "Jim Nasby" <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-09 06:23:04
Message-ID: d3c4af540703082223m6d987ca1vc9f95902e9c52393@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> This follows on from the suggestion I made - taken along the lines of
> the subject "auto creation of partitions" where I suggested the syntax
> of partition check(month of mydatecol) and have a new partition created
> as data was entered. With this scenario dropping the partition when it
> was empty would complement the creation of a new partition as needed.
>
> Given that there seems to be no real support of going with "auto
> maintenance" were new partitions are added as needed, then the auto
> dropping of empty partitions would also not apply.
>
> Leaving us with only specific add partition / drop partition commands.
> And have the parent table pick up rows not matching any partition check
> criteria.

I was thinking along the lines of what Jim had suggested earlier regarding
overflow partition. Instead of dumping unmatched rows to the master table,
we could put them into a default "DUMP/DUMB" partition.

Given that Simon wants to do away with having the master table APPENDed in
the planning phase, this would be better.

Regards,
Nikhils

--
>
> Shane Ambler
> pgSQL(at)Sheeky(dot)Biz
>
> Get Sheeky @ http://Sheeky.Biz
>

--
EnterpriseDB http://www.enterprisedb.com


From: "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>
To: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "NikhilS" <nikkhils(at)gmail(dot)com>
Cc: "Jim Nasby" <decibel(at)decibel(dot)org>, "Shane Ambler" <pgsql(at)sheeky(dot)biz>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-09 09:31:27
Message-ID: E1539E0ED7043848906A8FF995BDA57901D42FD2@m0143.s-mxs.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


> > Since partition is inheritance-based, a simple DROP or "NO
> INHERIT"
> > will do the job to deal with the partition. Do we want to reinvent
> > additional syntax when these are around and are documented?
>
> Well, if the syntax for adding a new partition eventually
> ends up as ALTER TABLE ADD PARTITION, then it would make more
> sense that you remove a partition via ALTER TABLE DROP PARTITION.

But DROP PARTITION usually moves the data from this partition to other
partitions,
so it is something different.

Andreas


From: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
To: "NikhilS" <nikkhils(at)gmail(dot)com>
Cc: "Shane Ambler" <pgsql(at)sheeky(dot)biz>, "Luke Lonergan" <llonergan(at)greenplum(dot)com>, "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-09 11:17:38
Message-ID: 1173439059.3641.197.camel@silverbirch.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Fri, 2007-03-09 at 11:48 +0530, NikhilS wrote:
> Hi,
>
> On 3/9/07, Shane Ambler <pgsql(at)sheeky(dot)biz> wrote:
>
> > Note to Nikhil: Make sure the new syntax doesn't prevent
> partitions from
> > being placed upon multiple tablespaces in some manner, at
> CREATE TABLE
> > time.
>
> What if the syntax was something like -
>
> CREATE TABLE tabname (
> ...
> ...
> ) PARTITION BY
> HASH(expr)
> | RANGE(expr)
> | LIST(expr)
> [PARTITIONS num_partitions] /* will apply to HASH only for
> now*/
> [PARTITION partition_name CHECK(...) [USING TABLESPACE
> tblspcname],
> PARTITION partition_name CHECK(...) [USING TABLESPACE
> tblspcname]
> ...
> ];
>
>
> And (if we use the ALTER TABLE to add partitions)
>
> ALTER TABLE tabname
> ADD PARTITION partition_name CHECK(...)
> [USING TABLESPACE tblspcname];
>
>
>
> We could as well drop the USING part.

Why would we support HASH partitions?
If you did, the full syntax for hash clusters should be supported.

If we do the CHECK clauses like that then we still have don't have a
guaranteed non-overlap between partitions. It would be easier to use
Oracle syntax and then construct the CHECK clauses from that.

Also, the syntax needs to be fairly complex to allow for a mixture of
modes, e.g. range and list partitioning. That is currently possible
today and the syntax for doing that is IMHO much simpler than the Oracle
"simple" way of specifying it.

An alternative is to provide a partitioning function which decides which
partition each values goes into.

PARTITION FUNCTION which_partition(date_col)

The partition function must return an unsigned integer > 0, which would
correspond to particular partitions. Partitions would be numbered 1..N,
and named tablename_partM where 1 <= M <= N.

The input and contents of the partition function would be up to the
user. e.g.

CREATE FUNCTION range_partition(date date_col)
{
if (date_col < D1)
return 1;
else if (date_col < D2)
return 2;
else if (date_col < D3)
return 3;

return 4;
}

Doing it this way would allow us to easily join two tables based upon a
common partition function.

In time, I would suggest we support both ways: declarative and
functional.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Simon Riggs" <simon(at)2ndquadrant(dot)com>
Cc: "Shane Ambler" <pgsql(at)sheeky(dot)biz>, "Luke Lonergan" <llonergan(at)greenplum(dot)com>, "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-09 11:55:01
Message-ID: d3c4af540703090355y89178e2y314c0de0728527f9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> Why would we support HASH partitions?
> If you did, the full syntax for hash clusters should be supported.

In MySQL, Oracle, the syntax for HASH partitions seems to be similar to the
one mentioned. I do not know much about hash clusters though.

If we do the CHECK clauses like that then we still have don't have a
> guaranteed non-overlap between partitions. It would be easier to use
> Oracle syntax and then construct the CHECK clauses from that.

Again Oracle, MySQL use "VALUES LESS THAN (expr)" format for RANGE
partitions. So you mean that they end up creating ranges like "MININT -
Range1", "Range1+1 - Range2" etc for each of the partitions?

I think Postgres users are used to the CHECK clauses and I still feel that
the onus of distinct partitions lies on the partition creator.

Also, the syntax needs to be fairly complex to allow for a mixture of
> modes, e.g. range and list partitioning. That is currently possible
> today and the syntax for doing that is IMHO much simpler than the Oracle
> "simple" way of specifying it.

Subpartitioning is not being targeted right now, but could be put on the
TODO list for further enhancements.

An alternative is to provide a partitioning function which decides which
> partition each values goes into.
>
> PARTITION FUNCTION which_partition(date_col)
>
> The partition function must return an unsigned integer > 0, which would
> correspond to particular partitions. Partitions would be numbered 1..N,
> and named tablename_partM where 1 <= M <= N.
>
> The input and contents of the partition function would be up to the
> user. e.g.
>
> CREATE FUNCTION range_partition(date date_col)
> {
> if (date_col < D1)
> return 1;
> else if (date_col < D2)
> return 2;
> else if (date_col < D3)
> return 3;
>
> return 4;
> }
>
> Doing it this way would allow us to easily join two tables based upon a
> common partition function.
>
> In time, I would suggest we support both ways: declarative and
> functional.

Till now, we are going the declarative way.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: Jim Nasby <jim(at)nasby(dot)net>
To: Zeugswetter Andreas ADI SD <ZeugswetterA(at)spardat(dot)at>
Cc: "NikhilS" <nikkhils(at)gmail(dot)com>, "Shane Ambler" <pgsql(at)sheeky(dot)biz>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Auto creation of Partitions
Date: 2007-03-09 21:41:10
Message-ID: DC6300EF-8866-43FE-89EC-A0EAA1EB2943@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mar 9, 2007, at 3:31 AM, Zeugswetter Andreas ADI SD wrote:
>>> Since partition is inheritance-based, a simple DROP or "NO
>> INHERIT"
>>> will do the job to deal with the partition. Do we want to reinvent
>>> additional syntax when these are around and are documented?
>>
>> Well, if the syntax for adding a new partition eventually
>> ends up as ALTER TABLE ADD PARTITION, then it would make more
>> sense that you remove a partition via ALTER TABLE DROP PARTITION.
>
> But DROP PARTITION usually moves the data from this partition to other
> partitions,
> so it is something different.

It does? IIRC every partitioning system I've seen DROP PARTITION
drops the data as well. It's up to you to move it somewhere else if
you want to keep it.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Hannu Krosing <hannu(at)skype(dot)net>
To: Jim Nasby <jim(at)nasby(dot)net>
Cc: Zeugswetter Andreas ADI SD <ZeugswetterA(at)spardat(dot)at>, NikhilS <nikkhils(at)gmail(dot)com>, Shane Ambler <pgsql(at)sheeky(dot)biz>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-09 22:16:20
Message-ID: 1173478581.3243.1.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Ühel kenal päeval, R, 2007-03-09 kell 15:41, kirjutas Jim Nasby:
> On Mar 9, 2007, at 3:31 AM, Zeugswetter Andreas ADI SD wrote:
> >>> Since partition is inheritance-based, a simple DROP or "NO
> >> INHERIT"
> >>> will do the job to deal with the partition. Do we want to reinvent
> >>> additional syntax when these are around and are documented?
> >>
> >> Well, if the syntax for adding a new partition eventually
> >> ends up as ALTER TABLE ADD PARTITION, then it would make more
> >> sense that you remove a partition via ALTER TABLE DROP PARTITION.
> >
> > But DROP PARTITION usually moves the data from this partition to other
> > partitions,
> > so it is something different.
>
> It does? IIRC every partitioning system I've seen DROP PARTITION
> drops the data as well. It's up to you to move it somewhere else if
> you want to keep it.

Will this proposed DROP PARTITION just disassociate the table from the
master, or will it actually drop the partitions table from the whole
database ?

--
----------------
Hannu Krosing
Database Architect
Skype Technologies OÜ
Akadeemia tee 21 F, Tallinn, 12618, Estonia

Skype me: callto:hkrosing
Get Skype for free: http://www.skype.com


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: NikhilS <nikkhils(at)gmail(dot)com>, "Shane Ambler" <pgsql(at)sheeky(dot)biz>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "Jim Nasby" <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Subject: Re: Auto creation of Partitions
Date: 2007-03-10 04:44:28
Message-ID: 200703092344.29335.xzilla@users.sourceforge.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Friday 09 March 2007 01:23, NikhilS wrote:
> Hi,
>
> > This follows on from the suggestion I made - taken along the lines of
> > the subject "auto creation of partitions" where I suggested the syntax
> > of partition check(month of mydatecol) and have a new partition created
> > as data was entered. With this scenario dropping the partition when it
> > was empty would complement the creation of a new partition as needed.
> >
> > Given that there seems to be no real support of going with "auto
> > maintenance" were new partitions are added as needed, then the auto
> > dropping of empty partitions would also not apply.
> >
> > Leaving us with only specific add partition / drop partition commands.
> > And have the parent table pick up rows not matching any partition check
> > criteria.
>
> I was thinking along the lines of what Jim had suggested earlier regarding
> overflow partition. Instead of dumping unmatched rows to the master table,
> we could put them into a default "DUMP/DUMB" partition.
>

I'm quite content dumping unmatched rows into the master table. This makes it
very easy to scan partitioned tables for busted partition setups. Having a
DUMP tables seems only different semantically, so why learn new semantics?

> Given that Simon wants to do away with having the master table APPENDed in
> the planning phase, this would be better.
>

ISTM you're trading appending the master table for appending the DUMP
partition, which afaict would give you no gain.

--
Robert Treat
Build A Brighter LAMP :: Linux Apache {middleware} PostgreSQL


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)skype(dot)net>
Cc: "Jim Nasby" <jim(at)nasby(dot)net>, "Zeugswetter Andreas ADI SD" <ZeugswetterA(at)spardat(dot)at>, "Shane Ambler" <pgsql(at)sheeky(dot)biz>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Auto creation of Partitions
Date: 2007-03-10 04:58:55
Message-ID: d3c4af540703092058j5c288cb3y6b61bddea53a1bfa@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 3/10/07, Hannu Krosing <hannu(at)skype(dot)net> wrote:
>
> Ühel kenal päeval, R, 2007-03-09 kell 15:41, kirjutas Jim Nasby:
> > On Mar 9, 2007, at 3:31 AM, Zeugswetter Andreas ADI SD wrote:
> > >>> Since partition is inheritance-based, a simple DROP or "NO
> > >> INHERIT"
> > >>> will do the job to deal with the partition. Do we want to reinvent
> > >>> additional syntax when these are around and are documented?
> > >>
> > >> Well, if the syntax for adding a new partition eventually
> > >> ends up as ALTER TABLE ADD PARTITION, then it would make more
> > >> sense that you remove a partition via ALTER TABLE DROP PARTITION.
> > >
> > > But DROP PARTITION usually moves the data from this partition to other
> > > partitions,
> > > so it is something different.
> >
> > It does? IIRC every partitioning system I've seen DROP PARTITION
> > drops the data as well. It's up to you to move it somewhere else if
> > you want to keep it.
>
> Will this proposed DROP PARTITION just disassociate the table from the
> master, or will it actually drop the partitions table from the whole
> database ?

Thats why I would prefer the existing mechanism, there a DROP on the child
removes it and a NO INHERIT disassociates it. There might be situations
where we would want to just disassociate and not drop.

Regards,
Nikhils

--
> ----------------
> Hannu Krosing
> Database Architect
> Skype Technologies OÜ
> Akadeemia tee 21 F, Tallinn, 12618, Estonia
>
> Skype me: callto:hkrosing
> Get Skype for free: http://www.skype.com
>
>
>

--
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Robert Treat" <xzilla(at)users(dot)sourceforge(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, "Shane Ambler" <pgsql(at)sheeky(dot)biz>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "Jim Nasby" <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Subject: Re: Auto creation of Partitions
Date: 2007-03-10 05:13:12
Message-ID: d3c4af540703092113o3acbe35bo1809765869b52983@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> > Given that Simon wants to do away with having the master table APPENDed
> in
> > the planning phase, this would be better.
> >
>
> ISTM you're trading appending the master table for appending the DUMP
> partition, which afaict would give you no gain.

If there are entries in the master table, I think it would get appended for
all queries regardless of whether we need to examine its contents or not.
Segregating dump data into a partition will avoid that.

I have seen examples in some other databases wherein a partition specifies a
range of "someval - MAXINT" for instance, to catch such cases.

That again means that the onus is on the partition creator most of the
times..
Regards,
Nikhils

> --
> Robert Treat
> Build A Brighter LAMP :: Linux Apache {middleware} PostgreSQL
>

--
EnterpriseDB http://www.enterprisedb.com


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, "Shane Ambler" <pgsql(at)sheeky(dot)biz>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, "Jim Nasby" <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Subject: Re: Auto creation of Partitions
Date: 2007-03-12 15:13:51
Message-ID: 200703121113.51752.xzilla@users.sourceforge.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Saturday 10 March 2007 00:13, NikhilS wrote:
> Hi,
>
> > > Given that Simon wants to do away with having the master table APPENDed
> >
> > in
> >
> > > the planning phase, this would be better.
> >
> > ISTM you're trading appending the master table for appending the DUMP
> > partition, which afaict would give you no gain.
>
> If there are entries in the master table, I think it would get appended for
> all queries regardless of whether we need to examine its contents or not.
> Segregating dump data into a partition will avoid that.
>
> I have seen examples in some other databases wherein a partition specifies
> a range of "someval - MAXINT" for instance, to catch such cases.
>
> That again means that the onus is on the partition creator most of the
> times..

*shrug*... we can do that now in pgsql

--
Robert Treat
Build A Brighter LAMP :: Linux Apache {middleware} PostgreSQL


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Trevor Hardcastle <chizu(at)spicious(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-02 23:06:11
Message-ID: 200704022306.l32N6Bg16850@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------

Trevor Hardcastle wrote:
> Greetings all,
>
> I wrote this patch about a week ago to introduce myself to coding on
> PostgreSQL. I wasn't entirely sure what the 'INCLUDING INDEXES' option
> was meant to do, so I held off submitting it until I could get around to
> asking about that and tweaking the documentation to reflect the patch.
> By useful coincidence the thread "Auto creation of Partitions" had this
> post in it, which made the intent of the option clear enough for me to
> go ahead and see what people think of this.
>
> Gregory Stark wrote:
> > "NikhilS" <nikkhils(at)gmail(dot)com> writes:
> >
> >
> >> the intention is to use this information from the parent and make it a
> >> property of the child table. This will avoid the step for the user having to
> >> manually specify CREATE INDEX and the likes on all the children tables
> >> one-by-one.
> >>
> >
> > Missed the start of this thread. A while back I had intended to add WITH
> > INDEXES to CREATE TABLE LIKE. That would let you create a tale LIKE parent
> > WITH CONSTRAINTS WITH INDEXES and get pretty much a perfect table ready for
> > adding to the inheritance structure.
> >
> >
> >
> So, that's what this patch does. When a table is created with 'CREATE
> TABLE ... LIKE parent INCLUDING INDEXES' this iterates over the parent
> table indexes looking for constraint indexes, and alters the
> CreateStmtContext to include equivalent indexes on the child table.
>
> This is probably a somewhat naive implementation, being a first attempt.
> I wasn't sure what sort of lock to place on the parent indexes or what
> tablespace the new indexes should be created in. Any help improving it
> would be appreciated.
>
> Thank you,
> -Trevor Hardcastle
>

> Index: src/backend/parser/analyze.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/backend/parser/analyze.c,v
> retrieving revision 1.361
> diff -c -r1.361 analyze.c
> *** src/backend/parser/analyze.c 20 Feb 2007 17:32:16 -0000 1.361
> --- src/backend/parser/analyze.c 7 Mar 2007 01:43:12 -0000
> ***************
> *** 14,19 ****
> --- 14,20 ----
> #include "postgres.h"
>
> #include "access/heapam.h"
> + #include "access/genam.h"
> #include "catalog/heap.h"
> #include "catalog/index.h"
> #include "catalog/namespace.h"
> ***************
> *** 40,45 ****
> --- 41,47 ----
> #include "utils/acl.h"
> #include "utils/builtins.h"
> #include "utils/lsyscache.h"
> + #include "utils/relcache.h"
> #include "utils/syscache.h"
>
>
> ***************
> *** 1345,1355 ****
> }
> }
>
> - if (including_indexes)
> - ereport(ERROR,
> - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> - errmsg("LIKE INCLUDING INDEXES is not implemented")));
> -
> /*
> * Insert the copied attributes into the cxt for the new table
> * definition.
> --- 1347,1352 ----
> ***************
> *** 1448,1453 ****
> --- 1445,1519 ----
> }
>
> /*
> + * Clone constraint indexes if requested.
> + */
> + if (including_indexes && relation->rd_rel->relhasindex)
> + {
> + List *parent_index_list = RelationGetIndexList(relation);
> + ListCell *parent_index_scan;
> +
> + foreach(parent_index_scan, parent_index_list)
> + {
> + Oid parent_index_oid = lfirst_oid(parent_index_scan);
> + Relation parent_index;
> +
> + parent_index = index_open(parent_index_oid, AccessShareLock);
> +
> + /*
> + * Create new unique or primary key indexes on the child.
> + */
> + if (parent_index->rd_index->indisunique || parent_index->rd_index->indisprimary)
> + {
> + IndexInfo *parent_index_info;
> + Constraint *n = makeNode(Constraint);
> + AttrNumber parent_attno;
> +
> + parent_index_info = BuildIndexInfo(parent_index);
> +
> + if (parent_index->rd_index->indisprimary)
> + {
> + n->contype = CONSTR_PRIMARY;
> + }
> + else
> + {
> + n->contype = CONSTR_UNIQUE;
> + }
> + /* Let DefineIndex name it */
> + n->name = NULL;
> + n->raw_expr = NULL;
> + n->cooked_expr = NULL;
> +
> + /*
> + * Search through the possible index keys, and append
> + * the names of simple columns to the new index key list.
> + */
> + for (parent_attno = 1; parent_attno <= parent_index->rd_att->natts;
> + parent_attno++)
> + {
> + Form_pg_attribute attribute = parent_index->rd_att->attrs[parent_attno - 1];
> + char *attributeName = NameStr(attribute->attname);
> +
> + /*
> + * Ignore dropped columns in the parent.
> + */
> + if (!attribute->attisdropped)
> + n->keys = lappend(n->keys,
> + makeString(attributeName));
> + }
> +
> + /* Add the new index constraint to the create context */
> + cxt->ixconstraints = lappend(cxt->ixconstraints, n);
> +
> + ereport(NOTICE,
> + (errmsg("Index \"%s\" cloned.",
> + RelationGetRelationName(parent_index))));
> + }
> +
> + relation_close(parent_index, AccessShareLock);
> + }
> + }
> +
> + /*
> * Close the parent rel, but keep our AccessShareLock on it until xact
> * commit. That will prevent someone else from deleting or ALTERing the
> * parent before the child is committed.
> Index: doc/src/sgml/ref/create_table.sgml
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v
> retrieving revision 1.107
> diff -c -r1.107 create_table.sgml
> *** doc/src/sgml/ref/create_table.sgml 1 Feb 2007 00:28:18 -0000 1.107
> --- doc/src/sgml/ref/create_table.sgml 7 Mar 2007 01:43:13 -0000
> ***************
> *** 23,29 ****
> CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> ( [
> { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
> | <replaceable>table_constraint</replaceable>
> ! | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS } ] ... }
> [, ... ]
> ] )
> [ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
> --- 23,29 ----
> CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> ( [
> { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
> | <replaceable>table_constraint</replaceable>
> ! | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES } ] ... }
> [, ... ]
> ] )
> [ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
> ***************
> *** 237,243 ****
> </varlistentry>
>
> <varlistentry>
> ! <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS } ]</literal></term>
> <listitem>
> <para>
> The <literal>LIKE</literal> clause specifies a table from which
> --- 237,243 ----
> </varlistentry>
>
> <varlistentry>
> ! <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING | INDEXES } { DEFAULTS | CONSTRAINTS } ]</literal></term>
> <listitem>
> <para>
> The <literal>LIKE</literal> clause specifies a table from which
> ***************
> *** 260,269 ****
> <para>
> Not-null constraints are always copied to the new table.
> <literal>CHECK</literal> constraints will only be copied if
> ! <literal>INCLUDING CONSTRAINTS</literal> is specified; other types of
> ! constraints will never be copied. Also, no distinction is made between
> ! column constraints and table constraints &mdash; when constraints are
> ! requested, all check constraints are copied.
> </para>
> <para>
> Note also that unlike <literal>INHERITS</literal>, copied columns and
> --- 260,271 ----
> <para>
> Not-null constraints are always copied to the new table.
> <literal>CHECK</literal> constraints will only be copied if
> ! <literal>INCLUDING CONSTRAINTS</literal> is specified. UNIQUE and
> ! PRIMARY KEY constraints will only be copied if
> ! <literal>INCLUDING INDEXES</literal> is specified. Also, no
> ! distinction is made between column constraints and table constraints
> ! &mdash; when constraints are requested, all check constraints are
> ! copied.
> </para>
> <para>
> Note also that unlike <literal>INHERITS</literal>, copied columns and
> Index: src/test/regress/sql/inherit.sql
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/test/regress/sql/inherit.sql,v
> retrieving revision 1.10
> diff -c -r1.10 inherit.sql
> *** src/test/regress/sql/inherit.sql 27 Jun 2006 03:43:20 -0000 1.10
> --- src/test/regress/sql/inherit.sql 7 Mar 2007 01:43:13 -0000
> ***************
> *** 155,160 ****
> --- 155,164 ----
> INSERT INTO inhg VALUES ('x', 'foo', 'y'); /* fails due to constraint */
> SELECT * FROM inhg; /* Two records with three columns in order x=x, xx=text, y=y */
> DROP TABLE inhg;
> + CREATE TABLE inhg (x text, LIKE inhx INCLUDING INDEXES, y text); /* Copies indexes */
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds */
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Fails -- Unique constraints are copied */
> + DROP TABLE inhg;
>
>
> -- Test changing the type of inherited columns
> Index: src/test/regress/expected/inherit.out
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/test/regress/expected/inherit.out,v
> retrieving revision 1.20
> diff -c -r1.20 inherit.out
> *** src/test/regress/expected/inherit.out 27 Jun 2006 03:43:20 -0000 1.20
> --- src/test/regress/expected/inherit.out 7 Mar 2007 01:43:14 -0000
> ***************
> *** 633,638 ****
> --- 633,645 ----
> (2 rows)
>
> DROP TABLE inhg;
> + CREATE TABLE inhg (x text, LIKE inhx INCLUDING INDEXES, y text); /* Copies indexes */
> + NOTICE: Index "inhx_pkey" cloned.
> + NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "inhg_pkey" for table "inhg"
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds */
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Fails -- Unique constraints are copied */
> + ERROR: duplicate key violates unique constraint "inhg_pkey"
> + DROP TABLE inhg;
> -- Test changing the type of inherited columns
> insert into d values('test','one','two','three');
> alter table a alter column aa type integer using bit_length(aa);

>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Trevor Hardcastle <chizu(at)spicious(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-05 03:08:15
Message-ID: 200704050308.l3538FF06436@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Uh, shouldn't CREATE TABLE LIKE INCLUDING CONSTRAINTS already be including
any indexes in the parent table?

---------------------------------------------------------------------------

Trevor Hardcastle wrote:
> Greetings all,
>
> I wrote this patch about a week ago to introduce myself to coding on
> PostgreSQL. I wasn't entirely sure what the 'INCLUDING INDEXES' option
> was meant to do, so I held off submitting it until I could get around to
> asking about that and tweaking the documentation to reflect the patch.
> By useful coincidence the thread "Auto creation of Partitions" had this
> post in it, which made the intent of the option clear enough for me to
> go ahead and see what people think of this.
>
> Gregory Stark wrote:
> > "NikhilS" <nikkhils(at)gmail(dot)com> writes:
> >
> >
> >> the intention is to use this information from the parent and make it a
> >> property of the child table. This will avoid the step for the user having to
> >> manually specify CREATE INDEX and the likes on all the children tables
> >> one-by-one.
> >>
> >
> > Missed the start of this thread. A while back I had intended to add WITH
> > INDEXES to CREATE TABLE LIKE. That would let you create a tale LIKE parent
> > WITH CONSTRAINTS WITH INDEXES and get pretty much a perfect table ready for
> > adding to the inheritance structure.
> >
> >
> >
> So, that's what this patch does. When a table is created with 'CREATE
> TABLE ... LIKE parent INCLUDING INDEXES' this iterates over the parent
> table indexes looking for constraint indexes, and alters the
> CreateStmtContext to include equivalent indexes on the child table.
>
> This is probably a somewhat naive implementation, being a first attempt.
> I wasn't sure what sort of lock to place on the parent indexes or what
> tablespace the new indexes should be created in. Any help improving it
> would be appreciated.
>
> Thank you,
> -Trevor Hardcastle
>

> Index: src/backend/parser/analyze.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/backend/parser/analyze.c,v
> retrieving revision 1.361
> diff -c -r1.361 analyze.c
> *** src/backend/parser/analyze.c 20 Feb 2007 17:32:16 -0000 1.361
> --- src/backend/parser/analyze.c 7 Mar 2007 01:43:12 -0000
> ***************
> *** 14,19 ****
> --- 14,20 ----
> #include "postgres.h"
>
> #include "access/heapam.h"
> + #include "access/genam.h"
> #include "catalog/heap.h"
> #include "catalog/index.h"
> #include "catalog/namespace.h"
> ***************
> *** 40,45 ****
> --- 41,47 ----
> #include "utils/acl.h"
> #include "utils/builtins.h"
> #include "utils/lsyscache.h"
> + #include "utils/relcache.h"
> #include "utils/syscache.h"
>
>
> ***************
> *** 1345,1355 ****
> }
> }
>
> - if (including_indexes)
> - ereport(ERROR,
> - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> - errmsg("LIKE INCLUDING INDEXES is not implemented")));
> -
> /*
> * Insert the copied attributes into the cxt for the new table
> * definition.
> --- 1347,1352 ----
> ***************
> *** 1448,1453 ****
> --- 1445,1519 ----
> }
>
> /*
> + * Clone constraint indexes if requested.
> + */
> + if (including_indexes && relation->rd_rel->relhasindex)
> + {
> + List *parent_index_list = RelationGetIndexList(relation);
> + ListCell *parent_index_scan;
> +
> + foreach(parent_index_scan, parent_index_list)
> + {
> + Oid parent_index_oid = lfirst_oid(parent_index_scan);
> + Relation parent_index;
> +
> + parent_index = index_open(parent_index_oid, AccessShareLock);
> +
> + /*
> + * Create new unique or primary key indexes on the child.
> + */
> + if (parent_index->rd_index->indisunique || parent_index->rd_index->indisprimary)
> + {
> + IndexInfo *parent_index_info;
> + Constraint *n = makeNode(Constraint);
> + AttrNumber parent_attno;
> +
> + parent_index_info = BuildIndexInfo(parent_index);
> +
> + if (parent_index->rd_index->indisprimary)
> + {
> + n->contype = CONSTR_PRIMARY;
> + }
> + else
> + {
> + n->contype = CONSTR_UNIQUE;
> + }
> + /* Let DefineIndex name it */
> + n->name = NULL;
> + n->raw_expr = NULL;
> + n->cooked_expr = NULL;
> +
> + /*
> + * Search through the possible index keys, and append
> + * the names of simple columns to the new index key list.
> + */
> + for (parent_attno = 1; parent_attno <= parent_index->rd_att->natts;
> + parent_attno++)
> + {
> + Form_pg_attribute attribute = parent_index->rd_att->attrs[parent_attno - 1];
> + char *attributeName = NameStr(attribute->attname);
> +
> + /*
> + * Ignore dropped columns in the parent.
> + */
> + if (!attribute->attisdropped)
> + n->keys = lappend(n->keys,
> + makeString(attributeName));
> + }
> +
> + /* Add the new index constraint to the create context */
> + cxt->ixconstraints = lappend(cxt->ixconstraints, n);
> +
> + ereport(NOTICE,
> + (errmsg("Index \"%s\" cloned.",
> + RelationGetRelationName(parent_index))));
> + }
> +
> + relation_close(parent_index, AccessShareLock);
> + }
> + }
> +
> + /*
> * Close the parent rel, but keep our AccessShareLock on it until xact
> * commit. That will prevent someone else from deleting or ALTERing the
> * parent before the child is committed.
> Index: doc/src/sgml/ref/create_table.sgml
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v
> retrieving revision 1.107
> diff -c -r1.107 create_table.sgml
> *** doc/src/sgml/ref/create_table.sgml 1 Feb 2007 00:28:18 -0000 1.107
> --- doc/src/sgml/ref/create_table.sgml 7 Mar 2007 01:43:13 -0000
> ***************
> *** 23,29 ****
> CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> ( [
> { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
> | <replaceable>table_constraint</replaceable>
> ! | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS } ] ... }
> [, ... ]
> ] )
> [ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
> --- 23,29 ----
> CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> ( [
> { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
> | <replaceable>table_constraint</replaceable>
> ! | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES } ] ... }
> [, ... ]
> ] )
> [ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
> ***************
> *** 237,243 ****
> </varlistentry>
>
> <varlistentry>
> ! <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS } ]</literal></term>
> <listitem>
> <para>
> The <literal>LIKE</literal> clause specifies a table from which
> --- 237,243 ----
> </varlistentry>
>
> <varlistentry>
> ! <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING | INDEXES } { DEFAULTS | CONSTRAINTS } ]</literal></term>
> <listitem>
> <para>
> The <literal>LIKE</literal> clause specifies a table from which
> ***************
> *** 260,269 ****
> <para>
> Not-null constraints are always copied to the new table.
> <literal>CHECK</literal> constraints will only be copied if
> ! <literal>INCLUDING CONSTRAINTS</literal> is specified; other types of
> ! constraints will never be copied. Also, no distinction is made between
> ! column constraints and table constraints &mdash; when constraints are
> ! requested, all check constraints are copied.
> </para>
> <para>
> Note also that unlike <literal>INHERITS</literal>, copied columns and
> --- 260,271 ----
> <para>
> Not-null constraints are always copied to the new table.
> <literal>CHECK</literal> constraints will only be copied if
> ! <literal>INCLUDING CONSTRAINTS</literal> is specified. UNIQUE and
> ! PRIMARY KEY constraints will only be copied if
> ! <literal>INCLUDING INDEXES</literal> is specified. Also, no
> ! distinction is made between column constraints and table constraints
> ! &mdash; when constraints are requested, all check constraints are
> ! copied.
> </para>
> <para>
> Note also that unlike <literal>INHERITS</literal>, copied columns and
> Index: src/test/regress/sql/inherit.sql
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/test/regress/sql/inherit.sql,v
> retrieving revision 1.10
> diff -c -r1.10 inherit.sql
> *** src/test/regress/sql/inherit.sql 27 Jun 2006 03:43:20 -0000 1.10
> --- src/test/regress/sql/inherit.sql 7 Mar 2007 01:43:13 -0000
> ***************
> *** 155,160 ****
> --- 155,164 ----
> INSERT INTO inhg VALUES ('x', 'foo', 'y'); /* fails due to constraint */
> SELECT * FROM inhg; /* Two records with three columns in order x=x, xx=text, y=y */
> DROP TABLE inhg;
> + CREATE TABLE inhg (x text, LIKE inhx INCLUDING INDEXES, y text); /* Copies indexes */
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds */
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Fails -- Unique constraints are copied */
> + DROP TABLE inhg;
>
>
> -- Test changing the type of inherited columns
> Index: src/test/regress/expected/inherit.out
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/test/regress/expected/inherit.out,v
> retrieving revision 1.20
> diff -c -r1.20 inherit.out
> *** src/test/regress/expected/inherit.out 27 Jun 2006 03:43:20 -0000 1.20
> --- src/test/regress/expected/inherit.out 7 Mar 2007 01:43:14 -0000
> ***************
> *** 633,638 ****
> --- 633,645 ----
> (2 rows)
>
> DROP TABLE inhg;
> + CREATE TABLE inhg (x text, LIKE inhx INCLUDING INDEXES, y text); /* Copies indexes */
> + NOTICE: Index "inhx_pkey" cloned.
> + NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "inhg_pkey" for table "inhg"
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds */
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Fails -- Unique constraints are copied */
> + ERROR: duplicate key violates unique constraint "inhg_pkey"
> + DROP TABLE inhg;
> -- Test changing the type of inherited columns
> insert into d values('test','one','two','three');
> alter table a alter column aa type integer using bit_length(aa);

>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Trevor Hardcastle" <chizu(at)spicious(dot)com>, <pgsql-patches(at)postgresql(dot)org>
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-05 03:25:52
Message-ID: 87mz1njydb.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"Bruce Momjian" <bruce(at)momjian(dot)us> writes:

> Uh, shouldn't CREATE TABLE LIKE INCLUDING CONSTRAINTS already be including
> any indexes in the parent table?

You could argue it should for unique indexes since our unique indexes are how
we implement unique constraints. But I see no particular reason to expect it
to copy random other indexes. At least its name doesn't lead one to expect it
to.

I also thought it was sort of strange to have a command that otherwise is just
copying definitions suddenly start building whole new objects. I think I was
thinking it would be a long slow operation but I suppose creating an empty
index isn't really noticeably slow. It could print a NOTICE similar to what's
printed when you create a primary key or unique constraint.

It does mean that users would be unable to create a partition, load data, then
build indexes. Perhaps it would be nice to have an ALTER TABLE foo LIKE bar
INCLUDING CONSTRAINTS as well.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-05 14:23:03
Message-ID: 200704051423.l35EN3h22492@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Gregory Stark wrote:
> "Bruce Momjian" <bruce(at)momjian(dot)us> writes:
>
> > Uh, shouldn't CREATE TABLE LIKE INCLUDING CONSTRAINTS already be including
> > any indexes in the parent table?
>
> You could argue it should for unique indexes since our unique indexes are how
> we implement unique constraints. But I see no particular reason to expect it
> to copy random other indexes. At least its name doesn't lead one to expect it
> to.
>
> I also thought it was sort of strange to have a command that otherwise is just
> copying definitions suddenly start building whole new objects. I think I was
> thinking it would be a long slow operation but I suppose creating an empty
> index isn't really noticeably slow. It could print a NOTICE similar to what's
> printed when you create a primary key or unique constraint.
>
> It does mean that users would be unable to create a partition, load data, then
> build indexes. Perhaps it would be nice to have an ALTER TABLE foo LIKE bar
> INCLUDING CONSTRAINTS as well.

The patch already _only_ does constraint(unique) indexes:

> So, that's what this patch does. When a table is created with 'CREATE
> TABLE ... LIKE parent INCLUDING INDEXES' this iterates over the parent
> table indexes looking for constraint indexes, and alters the
> CreateStmtContext to include equivalent indexes on the child table.

so I am just suggesting it do that always for INCLUDING CONSTRAINTS,
with a notice as you suggest.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Trevor Hardcastle <chizu(at)spicious(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-10 01:22:24
Message-ID: 200704100122.l3A1MPk18120@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Added to TODO:

o Have WITH CONSTRAINTS also create constraint indexes
http://archives.postgresql.org/pgsql-patches/2007-04/msg00149.php

---------------------------------------------------------------------------

Trevor Hardcastle wrote:
> Greetings all,
>
> I wrote this patch about a week ago to introduce myself to coding on
> PostgreSQL. I wasn't entirely sure what the 'INCLUDING INDEXES' option
> was meant to do, so I held off submitting it until I could get around to
> asking about that and tweaking the documentation to reflect the patch.
> By useful coincidence the thread "Auto creation of Partitions" had this
> post in it, which made the intent of the option clear enough for me to
> go ahead and see what people think of this.
>
> Gregory Stark wrote:
> > "NikhilS" <nikkhils(at)gmail(dot)com> writes:
> >
> >
> >> the intention is to use this information from the parent and make it a
> >> property of the child table. This will avoid the step for the user having to
> >> manually specify CREATE INDEX and the likes on all the children tables
> >> one-by-one.
> >>
> >
> > Missed the start of this thread. A while back I had intended to add WITH
> > INDEXES to CREATE TABLE LIKE. That would let you create a tale LIKE parent
> > WITH CONSTRAINTS WITH INDEXES and get pretty much a perfect table ready for
> > adding to the inheritance structure.
> >
> >
> >
> So, that's what this patch does. When a table is created with 'CREATE
> TABLE ... LIKE parent INCLUDING INDEXES' this iterates over the parent
> table indexes looking for constraint indexes, and alters the
> CreateStmtContext to include equivalent indexes on the child table.
>
> This is probably a somewhat naive implementation, being a first attempt.
> I wasn't sure what sort of lock to place on the parent indexes or what
> tablespace the new indexes should be created in. Any help improving it
> would be appreciated.
>
> Thank you,
> -Trevor Hardcastle
>

> Index: src/backend/parser/analyze.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/backend/parser/analyze.c,v
> retrieving revision 1.361
> diff -c -r1.361 analyze.c
> *** src/backend/parser/analyze.c 20 Feb 2007 17:32:16 -0000 1.361
> --- src/backend/parser/analyze.c 7 Mar 2007 01:43:12 -0000
> ***************
> *** 14,19 ****
> --- 14,20 ----
> #include "postgres.h"
>
> #include "access/heapam.h"
> + #include "access/genam.h"
> #include "catalog/heap.h"
> #include "catalog/index.h"
> #include "catalog/namespace.h"
> ***************
> *** 40,45 ****
> --- 41,47 ----
> #include "utils/acl.h"
> #include "utils/builtins.h"
> #include "utils/lsyscache.h"
> + #include "utils/relcache.h"
> #include "utils/syscache.h"
>
>
> ***************
> *** 1345,1355 ****
> }
> }
>
> - if (including_indexes)
> - ereport(ERROR,
> - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> - errmsg("LIKE INCLUDING INDEXES is not implemented")));
> -
> /*
> * Insert the copied attributes into the cxt for the new table
> * definition.
> --- 1347,1352 ----
> ***************
> *** 1448,1453 ****
> --- 1445,1519 ----
> }
>
> /*
> + * Clone constraint indexes if requested.
> + */
> + if (including_indexes && relation->rd_rel->relhasindex)
> + {
> + List *parent_index_list = RelationGetIndexList(relation);
> + ListCell *parent_index_scan;
> +
> + foreach(parent_index_scan, parent_index_list)
> + {
> + Oid parent_index_oid = lfirst_oid(parent_index_scan);
> + Relation parent_index;
> +
> + parent_index = index_open(parent_index_oid, AccessShareLock);
> +
> + /*
> + * Create new unique or primary key indexes on the child.
> + */
> + if (parent_index->rd_index->indisunique || parent_index->rd_index->indisprimary)
> + {
> + IndexInfo *parent_index_info;
> + Constraint *n = makeNode(Constraint);
> + AttrNumber parent_attno;
> +
> + parent_index_info = BuildIndexInfo(parent_index);
> +
> + if (parent_index->rd_index->indisprimary)
> + {
> + n->contype = CONSTR_PRIMARY;
> + }
> + else
> + {
> + n->contype = CONSTR_UNIQUE;
> + }
> + /* Let DefineIndex name it */
> + n->name = NULL;
> + n->raw_expr = NULL;
> + n->cooked_expr = NULL;
> +
> + /*
> + * Search through the possible index keys, and append
> + * the names of simple columns to the new index key list.
> + */
> + for (parent_attno = 1; parent_attno <= parent_index->rd_att->natts;
> + parent_attno++)
> + {
> + Form_pg_attribute attribute = parent_index->rd_att->attrs[parent_attno - 1];
> + char *attributeName = NameStr(attribute->attname);
> +
> + /*
> + * Ignore dropped columns in the parent.
> + */
> + if (!attribute->attisdropped)
> + n->keys = lappend(n->keys,
> + makeString(attributeName));
> + }
> +
> + /* Add the new index constraint to the create context */
> + cxt->ixconstraints = lappend(cxt->ixconstraints, n);
> +
> + ereport(NOTICE,
> + (errmsg("Index \"%s\" cloned.",
> + RelationGetRelationName(parent_index))));
> + }
> +
> + relation_close(parent_index, AccessShareLock);
> + }
> + }
> +
> + /*
> * Close the parent rel, but keep our AccessShareLock on it until xact
> * commit. That will prevent someone else from deleting or ALTERing the
> * parent before the child is committed.
> Index: doc/src/sgml/ref/create_table.sgml
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v
> retrieving revision 1.107
> diff -c -r1.107 create_table.sgml
> *** doc/src/sgml/ref/create_table.sgml 1 Feb 2007 00:28:18 -0000 1.107
> --- doc/src/sgml/ref/create_table.sgml 7 Mar 2007 01:43:13 -0000
> ***************
> *** 23,29 ****
> CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> ( [
> { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
> | <replaceable>table_constraint</replaceable>
> ! | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS } ] ... }
> [, ... ]
> ] )
> [ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
> --- 23,29 ----
> CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> ( [
> { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
> | <replaceable>table_constraint</replaceable>
> ! | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | INDEXES } ] ... }
> [, ... ]
> ] )
> [ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
> ***************
> *** 237,243 ****
> </varlistentry>
>
> <varlistentry>
> ! <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS } ]</literal></term>
> <listitem>
> <para>
> The <literal>LIKE</literal> clause specifies a table from which
> --- 237,243 ----
> </varlistentry>
>
> <varlistentry>
> ! <term><literal>LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING | INDEXES } { DEFAULTS | CONSTRAINTS } ]</literal></term>
> <listitem>
> <para>
> The <literal>LIKE</literal> clause specifies a table from which
> ***************
> *** 260,269 ****
> <para>
> Not-null constraints are always copied to the new table.
> <literal>CHECK</literal> constraints will only be copied if
> ! <literal>INCLUDING CONSTRAINTS</literal> is specified; other types of
> ! constraints will never be copied. Also, no distinction is made between
> ! column constraints and table constraints &mdash; when constraints are
> ! requested, all check constraints are copied.
> </para>
> <para>
> Note also that unlike <literal>INHERITS</literal>, copied columns and
> --- 260,271 ----
> <para>
> Not-null constraints are always copied to the new table.
> <literal>CHECK</literal> constraints will only be copied if
> ! <literal>INCLUDING CONSTRAINTS</literal> is specified. UNIQUE and
> ! PRIMARY KEY constraints will only be copied if
> ! <literal>INCLUDING INDEXES</literal> is specified. Also, no
> ! distinction is made between column constraints and table constraints
> ! &mdash; when constraints are requested, all check constraints are
> ! copied.
> </para>
> <para>
> Note also that unlike <literal>INHERITS</literal>, copied columns and
> Index: src/test/regress/sql/inherit.sql
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/test/regress/sql/inherit.sql,v
> retrieving revision 1.10
> diff -c -r1.10 inherit.sql
> *** src/test/regress/sql/inherit.sql 27 Jun 2006 03:43:20 -0000 1.10
> --- src/test/regress/sql/inherit.sql 7 Mar 2007 01:43:13 -0000
> ***************
> *** 155,160 ****
> --- 155,164 ----
> INSERT INTO inhg VALUES ('x', 'foo', 'y'); /* fails due to constraint */
> SELECT * FROM inhg; /* Two records with three columns in order x=x, xx=text, y=y */
> DROP TABLE inhg;
> + CREATE TABLE inhg (x text, LIKE inhx INCLUDING INDEXES, y text); /* Copies indexes */
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds */
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Fails -- Unique constraints are copied */
> + DROP TABLE inhg;
>
>
> -- Test changing the type of inherited columns
> Index: src/test/regress/expected/inherit.out
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/test/regress/expected/inherit.out,v
> retrieving revision 1.20
> diff -c -r1.20 inherit.out
> *** src/test/regress/expected/inherit.out 27 Jun 2006 03:43:20 -0000 1.20
> --- src/test/regress/expected/inherit.out 7 Mar 2007 01:43:14 -0000
> ***************
> *** 633,638 ****
> --- 633,645 ----
> (2 rows)
>
> DROP TABLE inhg;
> + CREATE TABLE inhg (x text, LIKE inhx INCLUDING INDEXES, y text); /* Copies indexes */
> + NOTICE: Index "inhx_pkey" cloned.
> + NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "inhg_pkey" for table "inhg"
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds */
> + INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Fails -- Unique constraints are copied */
> + ERROR: duplicate key violates unique constraint "inhg_pkey"
> + DROP TABLE inhg;
> -- Test changing the type of inherited columns
> insert into d values('test','one','two','three');
> alter table a alter column aa type integer using bit_length(aa);

>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-10 08:20:16
Message-ID: d3c4af540704100120nd3a061ej11bd3f18f95b4596@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 4/10/07, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>
>
> Added to TODO:
>
> o Have WITH CONSTRAINTS also create constraint indexes
>
> http://archives.postgresql.org/pgsql-patches/2007-04/msg00149.php

Trevor's patch does add unique/primary indexes. This would mean that we have
to remove the syntax support for "INCLUDING INDEXES" and just add code to
the existing WITH CONSTRAINTs code path from his patch.

Is there something else and hence we have the above TODO?

Regards,
Nikhils

--
EnterpriseDB http://www.enterprisedb.com


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-11 21:10:01
Message-ID: 200704112110.l3BLA1c22875@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS wrote:
> Hi,
>
> On 4/10/07, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> >
> >
> > Added to TODO:
> >
> > o Have WITH CONSTRAINTS also create constraint indexes
> >
> > http://archives.postgresql.org/pgsql-patches/2007-04/msg00149.php
>
>
> Trevor's patch does add unique/primary indexes. This would mean that we have
> to remove the syntax support for "INCLUDING INDEXES" and just add code to
> the existing WITH CONSTRAINTs code path from his patch.

That is all that is required.

> Is there something else and hence we have the above TODO?

If someone wants to work on this item and submit it, we can review it
for 8.3, but if not, it waits until 8.4.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Trevor Hardcastle <chizu(at)spicious(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-12 17:56:09
Message-ID: 461E72B9.6070507@spicious.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian wrote:
> NikhilS wrote:
>
>> Hi,
>>
>> On 4/10/07, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>>
>>> Added to TODO:
>>>
>>> o Have WITH CONSTRAINTS also create constraint indexes
>>>
>>> http://archives.postgresql.org/pgsql-patches/2007-04/msg00149.php
>>>
>> Trevor's patch does add unique/primary indexes. This would mean that we have
>> to remove the syntax support for "INCLUDING INDEXES" and just add code to
>> the existing WITH CONSTRAINTs code path from his patch.
>>
>
> That is all that is required.
>
>
>> Is there something else and hence we have the above TODO?
>>
>
> If someone wants to work on this item and submit it, we can review it
> for 8.3, but if not, it waits until 8.4.
>
>
I've updated my patch to merge the INDEXES behavior implemented into the
CONSTRAINTS option, and restore the current error triggered when you try
to use the INDEXES option. Attached is the updated patch.

I didn't remove the INDEXES syntax, just undocumented it again and put
the error it raised back in. It seems like an implementation of copying
all of the indexes could still use that syntax.

Thank you for all the comments,
-Trevor Hardcastle

Attachment Content-Type Size
like_including_indexes-2.patch text/plain 8.6 KB

From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Trevor Hardcastle" <chizu(at)spicious(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-13 05:51:56
Message-ID: d3c4af540704122251i7997cbb4h75d33e5ef8303376@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi Trevor,

> +
> + parent_index_info =
> BuildIndexInfo(parent_index);

The above is not used anywhere else in the code and seems redundant.

>
> +
> + ereport(NOTICE,
> + (errmsg("Index
> \"%s\" cloned.",
> +
> RelationGetRelationName(parent_index))));

DefineIndex will give out a message anyways for unique/primary keys. The
above seems additional to it.

Regards,
Nikhils

--
EnterpriseDB http://www.enterprisedb.com


From: Trevor Hardcastle <chizu(at)spicious(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-13 16:42:51
Message-ID: 461FB30B.3020907@spicious.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS wrote:
> Hi Trevor,
>
>
> +
> + parent_index_info =
> BuildIndexInfo(parent_index);
>
>
> The above is not used anywhere else in the code and seems redundant.
Yep, pulled that out.
>
> +
> + ereport(NOTICE,
> +
> (errmsg("Index \"%s\" cloned.",
> +
> RelationGetRelationName(parent_index))));
>
>
> DefineIndex will give out a message anyways for unique/primary keys.
> The above seems additional to it.
The original reason for this was the support for copying all indexes,
but it doesn't make much sense now. I've pulled it too.

Thanks for pointing those out. An updated patch is attached.

-Trevor Hardcastle

Attachment Content-Type Size
like_including_indexes-3.patch text/plain 8.4 KB

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Trevor Hardcastle <chizu(at)spicious(dot)com>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-27 01:12:08
Message-ID: 200704270112.l3R1C9522574@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------

Trevor Hardcastle wrote:
> NikhilS wrote:
> > Hi Trevor,
> >
> >
> > +
> > + parent_index_info =
> > BuildIndexInfo(parent_index);
> >
> >
> > The above is not used anywhere else in the code and seems redundant.
> Yep, pulled that out.
> >
> > +
> > + ereport(NOTICE,
> > +
> > (errmsg("Index \"%s\" cloned.",
> > +
> > RelationGetRelationName(parent_index))));
> >
> >
> > DefineIndex will give out a message anyways for unique/primary keys.
> > The above seems additional to it.
> The original reason for this was the support for copying all indexes,
> but it doesn't make much sense now. I've pulled it too.
>
> Thanks for pointing those out. An updated patch is attached.
>
> -Trevor Hardcastle
>

> Index: src/backend/parser/analyze.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/backend/parser/analyze.c,v
> retrieving revision 1.362
> diff -c -r1.362 analyze.c
> *** src/backend/parser/analyze.c 13 Mar 2007 00:33:41 -0000 1.362
> --- src/backend/parser/analyze.c 13 Apr 2007 16:41:46 -0000
> ***************
> *** 28,33 ****
> --- 28,34 ----
> #include "postgres.h"
>
> #include "access/heapam.h"
> + #include "access/genam.h"
> #include "catalog/heap.h"
> #include "catalog/index.h"
> #include "catalog/namespace.h"
> ***************
> *** 54,59 ****
> --- 55,61 ----
> #include "utils/acl.h"
> #include "utils/builtins.h"
> #include "utils/lsyscache.h"
> + #include "utils/relcache.h"
> #include "utils/syscache.h"
>
>
> ***************
> *** 1331,1338 ****
> }
>
> /*
> ! * Copy CHECK constraints if requested, being careful to adjust
> ! * attribute numbers
> */
> if (including_constraints && tupleDesc->constr)
> {
> --- 1333,1340 ----
> }
>
> /*
> ! * Copy CHECK based constraints if requested, being careful to adjust
> ! * attribute numbers. Also duplicate unique index constraints.
> */
> if (including_constraints && tupleDesc->constr)
> {
> ***************
> *** 1355,1360 ****
> --- 1357,1424 ----
> n->indexspace = NULL;
> cxt->ckconstraints = lappend(cxt->ckconstraints, (Node *) n);
> }
> +
> + /*
> + * Clone constraint indexes if any exist.
> + */
> + if (relation->rd_rel->relhasindex)
> + {
> + List *parent_index_list = RelationGetIndexList(relation);
> + ListCell *parent_index_scan;
> +
> + foreach(parent_index_scan, parent_index_list)
> + {
> + Oid parent_index_oid = lfirst_oid(parent_index_scan);
> + Relation parent_index;
> +
> + parent_index = index_open(parent_index_oid, AccessShareLock);
> +
> + /*
> + * Create new unique or primary key indexes on the child.
> + */
> + if (parent_index->rd_index->indisunique || parent_index->rd_index->indisprimary)
> + {
> + Constraint *n = makeNode(Constraint);
> + AttrNumber parent_attno;
> +
> + if (parent_index->rd_index->indisprimary)
> + {
> + n->contype = CONSTR_PRIMARY;
> + }
> + else
> + {
> + n->contype = CONSTR_UNIQUE;
> + }
> + /* Let DefineIndex name it */
> + n->name = NULL;
> + n->raw_expr = NULL;
> + n->cooked_expr = NULL;
> +
> + /*
> + * Search through the possible index keys, and append
> + * the names of simple columns to the new index key list.
> + */
> + for (parent_attno = 1; parent_attno <= parent_index->rd_att->natts;
> + parent_attno++)
> + {
> + Form_pg_attribute attribute = parent_index->rd_att->attrs[parent_attno - 1];
> + char *attributeName = NameStr(attribute->attname);
> +
> + /*
> + * Ignore dropped columns in the parent.
> + */
> + if (!attribute->attisdropped)
> + n->keys = lappend(n->keys,
> + makeString(attributeName));
> + }
> +
> + /* Add the new index constraint to the create context */
> + cxt->ixconstraints = lappend(cxt->ixconstraints, n);
> + }
> +
> + relation_close(parent_index, AccessShareLock);
> + }
> + }
> }
>
> /*
> Index: src/test/regress/sql/inherit.sql
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/test/regress/sql/inherit.sql,v
> retrieving revision 1.10
> diff -c -r1.10 inherit.sql
> *** src/test/regress/sql/inherit.sql 27 Jun 2006 03:43:20 -0000 1.10
> --- src/test/regress/sql/inherit.sql 13 Apr 2007 16:41:46 -0000
> ***************
> *** 151,160 ****
> DROP TABLE inhg;
> CREATE TABLE inhg (x text, LIKE inhx INCLUDING CONSTRAINTS, y text); /* Copies constraints */
> INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds */
> ! INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds -- Unique constraints not copied */
> INSERT INTO inhg VALUES ('x', 'foo', 'y'); /* fails due to constraint */
> SELECT * FROM inhg; /* Two records with three columns in order x=x, xx=text, y=y */
> DROP TABLE inhg;
>
>
> -- Test changing the type of inherited columns
> --- 151,161 ----
> DROP TABLE inhg;
> CREATE TABLE inhg (x text, LIKE inhx INCLUDING CONSTRAINTS, y text); /* Copies constraints */
> INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds */
> ! INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Fails -- Unique constraints copied */
> INSERT INTO inhg VALUES ('x', 'foo', 'y'); /* fails due to constraint */
> SELECT * FROM inhg; /* Two records with three columns in order x=x, xx=text, y=y */
> DROP TABLE inhg;
> + CREATE TABLE inhg (x text, LIKE inhx INCLUDING INDEXES, y text); /* Unimplemented */
>
>
> -- Test changing the type of inherited columns
> Index: src/test/regress/expected/inherit.out
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/test/regress/expected/inherit.out,v
> retrieving revision 1.20
> diff -c -r1.20 inherit.out
> *** src/test/regress/expected/inherit.out 27 Jun 2006 03:43:20 -0000 1.20
> --- src/test/regress/expected/inherit.out 13 Apr 2007 16:41:46 -0000
> ***************
> *** 621,638 ****
> INSERT INTO inhg VALUES ('foo');
> DROP TABLE inhg;
> CREATE TABLE inhg (x text, LIKE inhx INCLUDING CONSTRAINTS, y text); /* Copies constraints */
> INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds */
> ! INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds -- Unique constraints not copied */
> INSERT INTO inhg VALUES ('x', 'foo', 'y'); /* fails due to constraint */
> ERROR: new row for relation "inhg" violates check constraint "foo"
> SELECT * FROM inhg; /* Two records with three columns in order x=x, xx=text, y=y */
> x | xx | y
> ---+------+---
> x | text | y
> ! x | text | y
> ! (2 rows)
>
> DROP TABLE inhg;
> -- Test changing the type of inherited columns
> insert into d values('test','one','two','three');
> alter table a alter column aa type integer using bit_length(aa);
> --- 621,641 ----
> INSERT INTO inhg VALUES ('foo');
> DROP TABLE inhg;
> CREATE TABLE inhg (x text, LIKE inhx INCLUDING CONSTRAINTS, y text); /* Copies constraints */
> + NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "inhg_pkey" for table "inhg"
> INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Succeeds */
> ! INSERT INTO inhg VALUES ('x', 'text', 'y'); /* Fails -- Unique constraints copied */
> ! ERROR: duplicate key violates unique constraint "inhg_pkey"
> INSERT INTO inhg VALUES ('x', 'foo', 'y'); /* fails due to constraint */
> ERROR: new row for relation "inhg" violates check constraint "foo"
> SELECT * FROM inhg; /* Two records with three columns in order x=x, xx=text, y=y */
> x | xx | y
> ---+------+---
> x | text | y
> ! (1 row)
>
> DROP TABLE inhg;
> + CREATE TABLE inhg (x text, LIKE inhx INCLUDING INDEXES, y text); /* Unimplemented */
> + ERROR: LIKE INCLUDING INDEXES is not implemented
> -- Test changing the type of inherited columns
> insert into d values('test','one','two','three');
> alter table a alter column aa type integer using bit_length(aa);
> Index: doc/src/sgml/ref/create_table.sgml
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v
> retrieving revision 1.107
> diff -c -r1.107 create_table.sgml
> *** doc/src/sgml/ref/create_table.sgml 1 Feb 2007 00:28:18 -0000 1.107
> --- doc/src/sgml/ref/create_table.sgml 13 Apr 2007 16:41:46 -0000
> ***************
> *** 259,269 ****
> </para>
> <para>
> Not-null constraints are always copied to the new table.
> ! <literal>CHECK</literal> constraints will only be copied if
> ! <literal>INCLUDING CONSTRAINTS</literal> is specified; other types of
> ! constraints will never be copied. Also, no distinction is made between
> ! column constraints and table constraints &mdash; when constraints are
> ! requested, all check constraints are copied.
> </para>
> <para>
> Note also that unlike <literal>INHERITS</literal>, copied columns and
> --- 259,268 ----
> </para>
> <para>
> Not-null constraints are always copied to the new table.
> ! <literal>CHECK, UNIQUE, and PRIMARY KEY</literal> constraints will only
> ! be copied if <literal>INCLUDING CONSTRAINTS</literal> is specified. Also,
> ! no distinction is made between column constraints and table constraints
> ! &mdash; when constraints are requested, all check constraints are copied.
> </para>
> <para>
> Note also that unlike <literal>INHERITS</literal>, copied columns and

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Neil Conway <neilc(at)samurai(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Trevor Hardcastle <chizu(at)spicious(dot)com>, NikhilS <nikkhils(at)gmail(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-04-27 22:59:10
Message-ID: 1177714750.6440.160.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

This patch needs more work. How carefully did you test it?

* the patch failed to copy index constraints if there was not also at
least one CHECK constraint defined on the table

* the patch is broken for expressional indexes, and silently omits
copying the predicate that may be associated with an index. It also
doesn't copy the index's amoptions (WITH clause), or the NULLS
FIRST/etc. options that may be associated with any of the index's
columns.

In other words, copying column names does not suffice to duplicate the
index constraint. Perhaps the right fix is to implement support for
INCLUDING INDEXES, and then use that code to copy the definition of any
constraint indexes in INCLUDING INDEXES?

* should we copy invalid indexes? I suppose there's nothing wrong with
copying them...

* we should probably hold the AccessShareLock on copied indexes till end
of xact, per the comments at the end of transformInhRelation()

* index_open() should be matched with index_close(), not
relation_close(). (In the current implementation, index_close() and
relation_close() happen to be identical, so it still worked.)

I've attached a revised version of the patch, but I didn't fix the
second or third bullets in the list.

-Neil

Attachment Content-Type Size
including_constraints_idx-2.patch text/x-patch 10.0 KB

From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Neil Conway" <neilc(at)samurai(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-02 11:39:16
Message-ID: d3c4af540705020439l68c99a8fya22b30959fb196d9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi Neil,

>
> * the patch is broken for expressional indexes, and silently omits
> copying the predicate that may be associated with an index. It also
> doesn't copy the index's amoptions (WITH clause), or the NULLS
> FIRST/etc. options that may be associated with any of the index's
> columns.

Since this patch is only supposed to copy unique/primary indexes, I dont
think we will ever have predicates associated to such indexes?

Regards,
Nikhils

--
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-03 05:24:45
Message-ID: 25321.1178169885@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS <nikkhils(at)gmail(dot)com> writes:
> Hi Neil,
>> * the patch is broken for expressional indexes, and silently omits
>> copying the predicate that may be associated with an index.

> Since this patch is only supposed to copy unique/primary indexes, I dont
> think we will ever have predicates associated to such indexes?

Huh? I would expect a clause "INCLUDING INDEXES" to mean copying *all*
indexes. A clause "INCLUDING CONSTRAINTS" would reasonably act as you
suggest, ie copy only indexes derived from SQL constraint clauses.

regards, tom lane


From: Neil Conway <neilc(at)samurai(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-03 05:49:39
Message-ID: 1178171379.11049.2.camel@goldbach
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Wed, 2007-02-05 at 17:09 +0530, NikhilS wrote:
> Since this patch is only supposed to copy unique/primary indexes, I
> dont think we will ever have predicates associated to such indexes?

Nope:

neilc=# create table t1 (a int, b int);
CREATE TABLE
neilc=# create unique index t1_a_idx on t1 ((a + b)) where (a > 5);
CREATE INDEX

-Neil


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-03 05:59:52
Message-ID: d3c4af540705022259w588a76a3rdbd43897290553ae@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 5/3/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> NikhilS <nikkhils(at)gmail(dot)com> writes:
> > Hi Neil,
> >> * the patch is broken for expressional indexes, and silently omits
> >> copying the predicate that may be associated with an index.
>
> > Since this patch is only supposed to copy unique/primary indexes, I dont
> > think we will ever have predicates associated to such indexes?
>
> Huh? I would expect a clause "INCLUDING INDEXES" to mean copying *all*
> indexes. A clause "INCLUDING CONSTRAINTS" would reasonably act as you
> suggest, ie copy only indexes derived from SQL constraint clauses.

But this patch is not for the "INCLUDING INDEXES" case. As mentioned by
Bruce earlier in this thread, this patch is for the following TODO:

o Have WITH CONSTRAINTS also create constraint indexes
http://archives.postgresql.org/pgsql-patches/2007-04/msg00149.php

Regards,
Nikhils

regards, tom lane
>

--
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-03 06:32:20
Message-ID: 28107.1178173940@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS <nikkhils(at)gmail(dot)com> writes:
> But this patch is not for the "INCLUDING INDEXES" case.

Pardon me for being misled by the thread title :-(

regards, tom lane


From: Neil Conway <neilc(at)samurai(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Trevor Hardcastle <chizu(at)spicious(dot)com>, NikhilS <nikkhils(at)gmail(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-15 02:58:35
Message-ID: 1179197915.6047.49.camel@goldbach
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Fri, 2007-27-04 at 18:59 -0400, Neil Conway wrote:
> This patch needs more work.

Has a revised version of this patch been submitted?

-Neil


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Neil Conway" <neilc(at)samurai(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-17 13:09:15
Message-ID: d3c4af540705170609n21911a2ja9314d4db9d230d3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

>
> Nope:
>
> neilc=# create table t1 (a int, b int);
> CREATE TABLE
> neilc=# create unique index t1_a_idx on t1 ((a + b)) where (a > 5);
> CREATE INDEX

I just now realized that even though we allow the above. We do not allow:

pg=# create table t1 (a int, b int, unique(a+b));

nor the where clause syntax.

Any specific reason for this behaviour?

If we want to pass such kinds of expr, predicate based constraints via the
"LIKE .. INCLUDING CONSTRAINTS" statements, transformIndexConstraints as
well as the Constraint structure might need modifications.

Regards,
Nikhils

--
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-17 14:31:59
Message-ID: 25508.1179412319@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS <nikkhils(at)gmail(dot)com> writes:
> I just now realized that even though we allow the above. We do not allow:

> pg=# create table t1 (a int, b int, unique(a+b));

> Any specific reason for this behaviour?

It'd be contrary to SQL spec. The UNIQUE constraint takes a list of
column names, full stop.

regards, tom lane


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "NikhilS" <nikkhils(at)gmail(dot)com>, "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, <pgsql-patches(at)postgresql(dot)org>
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-17 18:38:39
Message-ID: 87y7jnpa6o.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> NikhilS <nikkhils(at)gmail(dot)com> writes:
>> I just now realized that even though we allow the above. We do not allow:
>
>> pg=# create table t1 (a int, b int, unique(a+b));
>
>> Any specific reason for this behaviour?
>
> It'd be contrary to SQL spec. The UNIQUE constraint takes a list of
> column names, full stop.

Does the SQL spec actually specify what happens if you provide an
non-compliant table definition like this?

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: "NikhilS" <nikkhils(at)gmail(dot)com>, "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-17 20:04:32
Message-ID: 12473.1179432272@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Gregory Stark <stark(at)enterprisedb(dot)com> writes:
> "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>> It'd be contrary to SQL spec. The UNIQUE constraint takes a list of
>> column names, full stop.

> Does the SQL spec actually specify what happens if you provide an
> non-compliant table definition like this?

It does not. We could accept expressions there, and pray that the SQL
committee never extends the spec syntax in a direction incompatible with
that. That seems like a pretty risky thing to do though.

[ thinks... ] I think actually the prior discussions about this have
suggested importing our CREATE INDEX argument-list syntax into the
UNIQUE/PRIMARY KEY syntax, lock stock and barrel. Between the optional
opclass and sort direction and the slightly klugy requirement to
parenthesize expressions, that seemed clearly at huge risk of putting us
behind the compatibility eight-ball. You could make an argument that
the only plausible way that the committee would extend the syntax would
be to allow plain expressions instead of column names, and thus that
allowing that but not our other extensions would be safe. You might be
right about that ... or not. The fact that the committee still hasn't
made this seemingly-obvious extension makes me wonder if they have plans
we don't know about. There are certainly a ton of bells and whistles
in SQL2003 that're far less useful than this would be.

In any case there will always be features in CREATE INDEX that we
daren't drop into the standard constraint syntax, so the argument
for importing just this one seems a bit weak.

BTW, has anyone checked to see if Oracle and/or DB2 allow expressions
here? I think it's unlikely the committee would do anything to break
the standards compliance of those guys, so we might be safe in following
their lead if there is one.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gregory Stark <stark(at)enterprisedb(dot)com>, "NikhilS" <nikkhils(at)gmail(dot)com>, "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-17 20:40:07
Message-ID: 12804.1179434407@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

I wrote:
> Gregory Stark <stark(at)enterprisedb(dot)com> writes:
>> Does the SQL spec actually specify what happens if you provide an
>> non-compliant table definition like this?

> It does not. We could accept expressions there, and pray that the SQL
> committee never extends the spec syntax in a direction incompatible with
> that. That seems like a pretty risky thing to do though.

[ remembering previous discussions more clearly... ] Actually there
is a concrete problem here: unique constraints are supposed to be
represented in the information_schema views, and there is no
spec-compliant way to do that for a constraint on something other than
a column. We'd have to guess at what the SQL committee would do about
that, and the odds of guessing exactly right don't seem encouraging.

regards, tom lane


From: Neil Conway <neilc(at)samurai(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Trevor Hardcastle <chizu(at)spicious(dot)com>, NikhilS <nikkhils(at)gmail(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-18 00:36:28
Message-ID: 1179448588.16480.60.camel@goldbach
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, 2007-14-05 at 22:58 -0400, Neil Conway wrote:
> Has a revised version of this patch been submitted?

In the absence of a revised patch, I can finish the feature myself, but
I won't get the free cycles until after PGCon. I can commit to getting
it done before the end of May, or else we can just push this to 8.4.

-Neil


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: Trevor Hardcastle <chizu(at)spicious(dot)com>, NikhilS <nikkhils(at)gmail(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-18 00:43:25
Message-ID: 200705180043.l4I0hPl23019@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Neil Conway wrote:
> On Mon, 2007-14-05 at 22:58 -0400, Neil Conway wrote:
> > Has a revised version of this patch been submitted?
>
> In the absence of a revised patch, I can finish the feature myself, but
> I won't get the free cycles until after PGCon. I can commit to getting
> it done before the end of May, or else we can just push this to 8.4.

We will keep it in the queue then. We can always push it for 8.4 if it
if we are near beta.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Gregory Stark" <stark(at)enterprisedb(dot)com>, "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-18 07:26:06
Message-ID: d3c4af540705180026o3921849cicc17c02fcc593ec@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> [ remembering previous discussions more clearly... ] Actually there
> is a concrete problem here: unique constraints are supposed to be
> represented in the information_schema views, and there is no
> spec-compliant way to do that for a constraint on something other than
> a column. We'd have to guess at what the SQL committee would do about
> that, and the odds of guessing exactly right don't seem encouraging.

Considering that a unique index is a unique constraint, then isn't allowing
expressional unique indexes contradictory to the above?

It seems that "CREATE UNIQUE INDEX" currently does not pass isconstraint as
true to DefineIndex, otherwise index_create() would have cribbed with:

"constraints cannot have index expressions" error.

Since this patch is going to consider creating unique/primary indexes
assuming them to be constraints, IMHO we should be uniform about unique
constraints semantics.

That might mean that we only support expressionless, non-predicate indexes
via "INCLUDING CONSTRAINTS"?

Regards,
Nikhils

--
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: "Gregory Stark" <stark(at)enterprisedb(dot)com>, "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-18 14:45:01
Message-ID: 26695.1179499501@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS <nikkhils(at)gmail(dot)com> writes:
>> [ remembering previous discussions more clearly... ] Actually there
>> is a concrete problem here: unique constraints are supposed to be
>> represented in the information_schema views, and there is no
>> spec-compliant way to do that for a constraint on something other than
>> a column. We'd have to guess at what the SQL committee would do about
>> that, and the odds of guessing exactly right don't seem encouraging.

> Considering that a unique index is a unique constraint,

No, it isn't. You are confusing definition and implementation. The
spec requires us to do X, Y, and Z in response to the unique-constraint
syntax. It says nothing about what CREATE INDEX does.

> Since this patch is going to consider creating unique/primary indexes
> assuming them to be constraints,

If it does that it will be rejected. There is a difference here and
that difference has to be maintained.

The correct way to think about this is that a pg_constraint entry of
type "unique" or "primary key" has an associated index that is part of
its implementation (and therefore has an "internal" dependency on the
constraint). But they are far from being the same thing.

regression=# create table foo (f1 int unique);
NOTICE: CREATE TABLE / UNIQUE will create implicit index "foo_f1_key" for table "foo"
CREATE TABLE
regression=# drop index foo_f1_key;
ERROR: cannot drop index foo_f1_key because constraint foo_f1_key on table foo requires it
HINT: You can drop constraint foo_f1_key on table foo instead.
regression=# alter table foo drop constraint foo_f1_key;
ALTER TABLE
regression=#

regards, tom lane


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Gregory Stark" <stark(at)enterprisedb(dot)com>, "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-20 06:34:37
Message-ID: d3c4af540705192334m208fb311ubccbe77fdf899db7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> > Since this patch is going to consider creating unique/primary indexes
> > assuming them to be constraints,
>
> If it does that it will be rejected. There is a difference here and
> that difference has to be maintained.
>
> The correct way to think about this is that a pg_constraint entry of
> type "unique" or "primary key" has an associated index that is part of
> its implementation (and therefore has an "internal" dependency on the
> constraint). But they are far from being the same thing.

Thanks Tom, I understand the difference now. I have a working patch and will
send it to Neil for review tommorrow.

Regards,
Nikhils

--
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Neil Conway" <neilc(at)samurai(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-21 06:53:42
Message-ID: d3c4af540705202353l1b39a64eo6572e8bbc1531323@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi Neil,

On 5/18/07, Neil Conway <neilc(at)samurai(dot)com> wrote:
>
> On Mon, 2007-14-05 at 22:58 -0400, Neil Conway wrote:
> > Has a revised version of this patch been submitted?
>
> In the absence of a revised patch, I can finish the feature myself, but
> I won't get the free cycles until after PGCon. I can commit to getting
> it done before the end of May, or else we can just push this to 8.4.

I had spent some time on this earlier so decided to complete and send the
patch to you for review. This patch supports copying of expressions,
predicates, opclass, amorder, reloptions etc. The test case also contains
some more additions with this patch. Please let me know if there are any
issues.

Also, if this patch is acceptable, I think the mechanism provided here can
be used to support "INCLUDING INDEXES" case easily too.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com

Attachment Content-Type Size
including_constraints_v3.0.patch text/x-patch 37.0 KB

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Neil Conway <neilc(at)samurai(dot)com>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-22 15:36:34
Message-ID: 200705221536.l4MFaY922439@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------

NikhilS wrote:
> Hi Neil,
>
> On 5/18/07, Neil Conway <neilc(at)samurai(dot)com> wrote:
> >
> > On Mon, 2007-14-05 at 22:58 -0400, Neil Conway wrote:
> > > Has a revised version of this patch been submitted?
> >
> > In the absence of a revised patch, I can finish the feature myself, but
> > I won't get the free cycles until after PGCon. I can commit to getting
> > it done before the end of May, or else we can just push this to 8.4.
>
>
> I had spent some time on this earlier so decided to complete and send the
> patch to you for review. This patch supports copying of expressions,
> predicates, opclass, amorder, reloptions etc. The test case also contains
> some more additions with this patch. Please let me know if there are any
> issues.
>
> Also, if this patch is acceptable, I think the mechanism provided here can
> be used to support "INCLUDING INDEXES" case easily too.
>
> Regards,
> Nikhils
> --
> EnterpriseDB http://www.enterprisedb.com

[ Attachment, skipping... ]

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, Neil Conway <neilc(at)samurai(dot)com>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-22 15:48:38
Message-ID: 20070522154838.GC11032@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian escribió:
>
> Your patch has been added to the PostgreSQL unapplied patches list at:
>
> http://momjian.postgresql.org/cgi-bin/pgpatches
>
> It will be applied as soon as one of the PostgreSQL committers reviews
> and approves it.

I noticed that this patch uses names for some things (for example it
gets the name of the access method), and then builds a IndexStmt which
contains the name. I don't think this is a good idea. I think what
should happen here is that the function to build indexes should be split
in two: one to resolve the names and fill a structure with Oids of
things, and another to get that structure and actually build the index
or constraint. For example look into how GrantStmt is turned into
InternalGrant, and the stuff in aclchk.c to work with that.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Neil Conway" <neilc(at)samurai(dot)com>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-23 06:15:41
Message-ID: d3c4af540705222315m300efa83u77e61720e80f17f3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

>
> I noticed that this patch uses names for some things (for example it
> gets the name of the access method), and then builds a IndexStmt which
> contains the name. I don't think this is a good idea. I think what
> should happen here is that the function to build indexes should be split
> in two: one to resolve the names and fill a structure with Oids of
> things, and another to get that structure and actually build the index
> or constraint. For example look into how GrantStmt is turned into
> InternalGrant, and the stuff in aclchk.c to work with that.

The index creation happens after the new table (which is LIKE the parent)
has been created, by appending the cxt.alist information to "extras_after".
The entry point for the index creation is thus via ProcessUtility which
expects an IndexStmt structure. That is why the current patch does all the
Oid to name mapping exercise to populate the relevant fields in IndexStmt
some of which are char pointers. The internal DefineIndex function also
expects most of the fields to be in IndexStmt like format.

If we want to follow the above suggestion, as I understand it, we might have
to devise a new structure to contain Oids and make ProcessUtility accept a
new nodeTag. We will also not be able to use existing Index definition
functions and this will lead to more coding IMHO. Do we want to go down this
path? Or is there something else that has been suggested above and that I am
missing completely?

Please let me know.
Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Neil Conway" <neilc(at)samurai(dot)com>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-23 06:53:21
Message-ID: d3c4af540705222353s7e1a7f28r262d63b038aa629a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> The index creation happens after the new table (which is LIKE the parent)
> has been created, by appending the cxt.alist information to
> "extras_after". The entry point for the index creation is thus via
> ProcessUtility which expects an IndexStmt structure. That is why the current
> patch does all the Oid to name mapping exercise to populate the relevant
> fields in IndexStmt some of which are char pointers. The internal
> DefineIndex function also expects most of the fields to be in IndexStmt like
> format.
>
> If we want to follow the above suggestion, as I understand it, we might
> have to devise a new structure to contain Oids and make ProcessUtility
> accept a new nodeTag. We will also not be able to use existing Index
> definition functions and this will lead to more coding IMHO. Do we want to
> go down this path? Or is there something else that has been suggested above
> and that I am missing completely?

OTOH, we can populate a new structure with the relevant Oids, IndexInfo
information from parent relation indexes and call index_create directly
from within ProcessUtility. Guess, it should be cleaner than the current
approach.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Neil Conway" <neilc(at)samurai(dot)com>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-23 10:54:29
Message-ID: d3c4af540705230354h7daf10ebhce40186b1f87abf9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 5/23/07, NikhilS <nikkhils(at)gmail(dot)com> wrote:
>
> Hi,
>
> > The index creation happens after the new table (which is LIKE the
> > parent) has been created, by appending the cxt.alist information to
> > "extras_after". The entry point for the index creation is thus via
> > ProcessUtility which expects an IndexStmt structure. That is why the current
> > patch does all the Oid to name mapping exercise to populate the relevant
> > fields in IndexStmt some of which are char pointers. The internal
> > DefineIndex function also expects most of the fields to be in IndexStmt like
> > format.
> >
> > If we want to follow the above suggestion, as I understand it, we might
> > have to devise a new structure to contain Oids and make ProcessUtility
> > accept a new nodeTag. We will also not be able to use existing Index
> > definition functions and this will lead to more coding IMHO. Do we want to
> > go down this path? Or is there something else that has been suggested above
> > and that I am missing completely?
>
>
> OTOH, we can populate a new structure with the relevant Oids, IndexInfo
> information from parent relation indexes and call index_create directly
> from within ProcessUtility. Guess, it should be cleaner than the current
> approach.
>
Sorry for the barrage of emails. But as I looked closely at the current
patch there are only 2 fields (accessMethod and tableSpace) in IndexStmt
structure that we populate by doing the conversion from OIDs to name. For
the other fields, the current transformations will remain.

If so, I think we can introduce 2 Oid fields in the IndexStmt structure and
store the Oids there. In DefineIndex we can use these Oids if they are not
invalid.

IMHO, all this is less work and the bulk of the changes remain localized in
mostly one or two functions as in the current patch.

Comments?

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Neil Conway <neilc(at)samurai(dot)com>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-23 13:40:39
Message-ID: 20070523134039.GB4642@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS escribió:

> Sorry for the barrage of emails. But as I looked closely at the current
> patch there are only 2 fields (accessMethod and tableSpace) in IndexStmt
> structure that we populate by doing the conversion from OIDs to name. For
> the other fields, the current transformations will remain.
>
> If so, I think we can introduce 2 Oid fields in the IndexStmt structure and
> store the Oids there. In DefineIndex we can use these Oids if they are not
> invalid.

Sounds reasonable. This is what we do for example in VacuumStmt. Make
sure that the OIDs are set to Invalid in the parser.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Neil Conway" <neilc(at)samurai(dot)com>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-23 13:59:12
Message-ID: 19919.1179928752@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS <nikkhils(at)gmail(dot)com> writes:
> If so, I think we can introduce 2 Oid fields in the IndexStmt structure and
> store the Oids there. In DefineIndex we can use these Oids if they are not
> invalid.

I think this is just make-work that causes the patch to complicate parts
of the system it didn't need to touch. The original suggestion was to
actively refactor existing code, which might or might not have been
worthwhile. But this isn't an appropriate substitute --- it's just
making the API uglier for no particular benefit.

regards, tom lane


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Neil Conway" <neilc(at)samurai(dot)com>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-23 14:08:33
Message-ID: d3c4af540705230708r942c8a5qe0e4596b23009910@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 5/23/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> NikhilS <nikkhils(at)gmail(dot)com> writes:
> > If so, I think we can introduce 2 Oid fields in the IndexStmt structure
> and
> > store the Oids there. In DefineIndex we can use these Oids if they are
> not
> > invalid.
>
> I think this is just make-work that causes the patch to complicate parts
> of the system it didn't need to touch. The original suggestion was to
> actively refactor existing code, which might or might not have been
> worthwhile. But this isn't an appropriate substitute --- it's just
> making the API uglier for no particular benefit.

I agree this will unnecessary add arguments to the DefineIndex API. If we
stick to the patch's earlier way of converting the Oid to names for just
these 2 arguments, we can avoid this IMO.

Considering that we will be generating this information from existing valid
index information, I think converting the Oids to names is safe enough.
Alvaro, do you think we should stick to the existing patch mechanism then
considering that it avoids polluting the API?

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Neil Conway <neilc(at)samurai(dot)com>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-23 14:24:42
Message-ID: 20070523142442.GL4642@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS escribió:

> On 5/23/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >
> >NikhilS <nikkhils(at)gmail(dot)com> writes:
> >> If so, I think we can introduce 2 Oid fields in the IndexStmt
> >> structure and store the Oids there. In DefineIndex we can use these
> >> Oids if they are not invalid.
> >
> >I think this is just make-work that causes the patch to complicate parts
> >of the system it didn't need to touch. The original suggestion was to
> >actively refactor existing code, which might or might not have been
> >worthwhile. But this isn't an appropriate substitute --- it's just
> >making the API uglier for no particular benefit.
>
> I agree this will unnecessary add arguments to the DefineIndex API. If we
> stick to the patch's earlier way of converting the Oid to names for just
> these 2 arguments, we can avoid this IMO.
>
> Considering that we will be generating this information from existing valid
> index information, I think converting the Oids to names is safe enough.
> Alvaro, do you think we should stick to the existing patch mechanism then
> considering that it avoids polluting the API?

Not sure. Is it possible that the schema is renamed while the operation
is being executed? If it's not then this not a problem at all so the
existing patch is fine.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Neil Conway <neilc(at)samurai(dot)com>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-23 14:38:53
Message-ID: 20472.1179931133@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> Not sure. Is it possible that the schema is renamed while the operation
> is being executed? If it's not then this not a problem at all so the
> existing patch is fine.

There are hazards of that type in CREATE TABLE right now; it's hardly
fair to hold LIKE INCLUDING INDEXES to a higher standard.

regards, tom lane


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Neil Conway" <neilc(at)samurai(dot)com>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-23 14:39:20
Message-ID: d3c4af540705230739t1dd4f401jaac86e1c35d8a9ba@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> I agree this will unnecessary add arguments to the DefineIndex API. If we
> > stick to the patch's earlier way of converting the Oid to names for just
> > these 2 arguments, we can avoid this IMO.
> >
> > Considering that we will be generating this information from existing
> valid
> > index information, I think converting the Oids to names is safe enough.
> > Alvaro, do you think we should stick to the existing patch mechanism
> then
> > considering that it avoids polluting the API?
>
> Not sure. Is it possible that the schema is renamed while the operation
> is being executed? If it's not then this not a problem at all so the
> existing patch is fine.

I doubt if accessMethod name will change. The tableSpace name can change,
but the possibility is no worse to doing a [CREATE TABLE table_name ...
TABLESPACE tablespace]. So this should be reasonably ok.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Neil Conway <neilc(at)samurai(dot)com>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-29 00:35:34
Message-ID: 200705290035.l4T0ZYR21072@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


OK, so the patch is ready to be applied?

---------------------------------------------------------------------------

NikhilS wrote:
> Hi,
>
> > I agree this will unnecessary add arguments to the DefineIndex API. If we
> > > stick to the patch's earlier way of converting the Oid to names for just
> > > these 2 arguments, we can avoid this IMO.
> > >
> > > Considering that we will be generating this information from existing
> > valid
> > > index information, I think converting the Oids to names is safe enough.
> > > Alvaro, do you think we should stick to the existing patch mechanism
> > then
> > > considering that it avoids polluting the API?
> >
> > Not sure. Is it possible that the schema is renamed while the operation
> > is being executed? If it's not then this not a problem at all so the
> > existing patch is fine.
>
>
> I doubt if accessMethod name will change. The tableSpace name can change,
> but the possibility is no worse to doing a [CREATE TABLE table_name ...
> TABLESPACE tablespace]. So this should be reasonably ok.
>
> Regards,
> Nikhils
> --
> EnterpriseDB http://www.enterprisedb.com

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Neil Conway <neilc(at)samurai(dot)com>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-05-29 02:30:38
Message-ID: 24583.1180405838@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> OK, so the patch is ready to be applied?

Neil's still reviewing it, last I heard.

regards, tom lane


From: Neil Conway <neilc(at)samurai(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-06-02 20:59:38
Message-ID: 1180817978.5297.17.camel@goldbach
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, 2007-21-05 at 12:23 +0530, NikhilS wrote:
> I had spent some time on this earlier so decided to complete and send
> the patch to you for review. This patch supports copying of
> expressions, predicates, opclass, amorder, reloptions etc. The test
> case also contains some more additions with this patch. Please let me
> know if there are any issues.

Attached is a revised version of this patch. Note that this pattern is
always unsafe:

ht_am = SearchSysCache(AMOID, ...);
if (!HeapTupleIsValid(ht_am))
elog(ERROR, "...");
amrec = (Form_pg_am) GETSTRUCT(ht_am);
index->accessMethod = NameStr(amrec->amname);

/* ... */
ReleaseSysCache(ht_am);

return index;

Before calling ReleaseSysCache(), all the data you need from the
syscache entry needs to be deep-copied to allow subsequent access, but
NameStr() doesn't do a deep-copy. Adding "-DFORCE_CATCACHE_RELEASE" is a
useful way to catch these kinds of problems (I wonder if this is worth
adding to the default CFLAGS when assertions are enabled?)

I also made a bunch of editorial changes, including moving the
varattnos_map_schema() call out of the loop in transformInhRelation().

BTW, comments like "This function is based on code from ruleutils.c"
would be helpful for reviewers (whether in the patch itself or just in
the email containing the patch).

There's still a few things I need to fix in the patch, but I'll apply a
revised version of the attached patch to HEAD tomorrow, barring any
objections.

-Neil

Attachment Content-Type Size
including_constraints_v3.2.patch text/x-patch 38.1 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-06-02 21:43:34
Message-ID: 27546.1180820614@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Neil Conway <neilc(at)samurai(dot)com> writes:
> Attached is a revised version of this patch.

This still seems to fundamentally misunderstand the difference between
an index and a constraint. IMHO it should not be examining pg_index
(or specifically, the index Relations) at all.

regards, tom lane


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Neil Conway" <neilc(at)samurai(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-06-03 13:57:15
Message-ID: d3c4af540706030657g49bda0bft3a05c02a1f72524d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 6/3/07, Neil Conway <neilc(at)samurai(dot)com> wrote:
>
> On Mon, 2007-21-05 at 12:23 +0530, NikhilS wrote:
> > I had spent some time on this earlier so decided to complete and send
> > the patch to you for review. This patch supports copying of
> > expressions, predicates, opclass, amorder, reloptions etc. The test
> > case also contains some more additions with this patch. Please let me
> > know if there are any issues.
>
> Attached is a revised version of this patch. Note that this pattern is
> always unsafe:
>
> ht_am = SearchSysCache(AMOID, ...);
> if (!HeapTupleIsValid(ht_am))
> elog(ERROR, "...");
> amrec = (Form_pg_am) GETSTRUCT(ht_am);
> index->accessMethod = NameStr(amrec->amname);
>
> /* ... */
> ReleaseSysCache(ht_am);
>
> return index;
>
> Before calling ReleaseSysCache(), all the data you need from the
> syscache entry needs to be deep-copied to allow subsequent access, but
> NameStr() doesn't do a deep-copy. Adding "-DFORCE_CATCACHE_RELEASE" is a
> useful way to catch these kinds of problems (I wonder if this is worth
> adding to the default CFLAGS when assertions are enabled?)

I should have delved deep into the NameStr functionality myself for this. I
too agree that adding the flag makes sense when assertions are enabled.

I also made a bunch of editorial changes, including moving the
> varattnos_map_schema() call out of the loop in transformInhRelation().
>
> BTW, comments like "This function is based on code from ruleutils.c"
> would be helpful for reviewers (whether in the patch itself or just in
> the email containing the patch).

Yes I had this in mind but somehow forgot to mention this when I posted the
patch. I had done some changes in ruleutils.c specificly to take cognizance
of this fact.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-06-03 14:02:58
Message-ID: d3c4af540706030702o47fd9745i67f13f78e689d7a8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

On 6/3/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Neil Conway <neilc(at)samurai(dot)com> writes:
> > Attached is a revised version of this patch.
>
> This still seems to fundamentally misunderstand the difference between
> an index and a constraint. IMHO it should not be examining pg_index
> (or specifically, the index Relations) at all.

But as you had mentioned earlier, if we look at index entries as part of the
implementation of "unique" or "primary key" pg_constraint entries, then
examining pg_index is required, right?

Anyways, this patch and the functionality introduced herein will be useful
in the "CREATE .. INCLUDING INDEXES" case too.

Regards,
Nikhils

--
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-06-03 14:48:21
Message-ID: 19542.1180882101@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

NikhilS <nikkhils(at)gmail(dot)com> writes:
> On 6/3/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> This still seems to fundamentally misunderstand the difference between
>> an index and a constraint. IMHO it should not be examining pg_index
>> (or specifically, the index Relations) at all.

> Anyways, this patch and the functionality introduced herein will be useful
> in the "CREATE .. INCLUDING INDEXES" case too.

No doubt. But those are different features and we shouldn't confuse
'em; in particular not put behavior into the INCLUDING CONSTRAINTS case
that shouldn't be there.

regards, tom lane


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Neil Conway" <neilc(at)samurai(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-06-05 09:20:23
Message-ID: d3c4af540706050220k23972cb0l8f9eac6736757e47@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> Anyways, this patch and the functionality introduced herein will be useful
> > in the "CREATE .. INCLUDING INDEXES" case too.
>
> No doubt. But those are different features and we shouldn't confuse
> 'em; in particular not put behavior into the INCLUDING CONSTRAINTS case
> that shouldn't be there.
>

PFA, a patch which provides the "CREATE .. INCLUDING INDEXES" functionality.
This patch uses the same functionality introduced by the earlier patches in
this thread albeit for the "INCLUDING INDEXES" case.

For ease of review, this patch is based on the latest version which was
posted by Neil.
Please let me know if there are any issues.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com

Attachment Content-Type Size
including_indexes_v1.0.patch text/x-patch 33.5 KB

From: Neil Conway <neilc(at)samurai(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-10 05:57:22
Message-ID: 1184047042.8180.10.camel@goldbach
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Tue, 2007-05-06 at 14:50 +0530, NikhilS wrote:
> PFA, a patch which provides the "CREATE .. INCLUDING INDEXES"
> functionality. This patch uses the same functionality introduced by
> the earlier patches in this thread albeit for the "INCLUDING INDEXES"
> case.

Attached is a revised version of this patch. Sorry for taking so long to
make progress on this: my new job been keeping my busy, and I've
recently been ill.

This version updates the patch to CVS HEAD and has various fixes and
refactoring, including proper docs. I refactored get_opclass_name() into
lsyscache.c, but then realized that this means that lsyscache.c will
depend on commands/indexcmds.c (for GetDefaultOpClass()), which is
arguably improper, so I'm tempted to revert and just duplicate the
syscache lookups in both ruleutils.c and parse_utilcmd.c

Nikhil: why are both "options" and "inhreloptions" necessary in
IndexStmt? Won't at least one be NULL?

BTW, I notice that include/defrem.h contains declarations for several
different, marginally-related .c files (indexcmds.c, functioncmds.c,
operatorcmds.c, aggregatecmds.c, opclasscmds.c, define.c). I'm inclined
to separate these declarations into separate header files; any
objections to doing that?

-Neil

Attachment Content-Type Size
including_indexes_v3.1.patch text/x-patch 43.7 KB

From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Neil Conway" <neilc(at)samurai(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-10 07:23:13
Message-ID: d3c4af540707100023te49748bi323b1d7ee5674e38@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

This version updates the patch to CVS HEAD and has various fixes and
> refactoring, including proper docs. I refactored get_opclass_name() into
> lsyscache.c, but then realized that this means that lsyscache.c will
> depend on commands/indexcmds.c (for GetDefaultOpClass()), which is
> arguably improper, so I'm tempted to revert and just duplicate the
> syscache lookups in both ruleutils.c and parse_utilcmd.c

Yes, I too would vote for duplicating the lookups for the sake of
simplicity.

Nikhil: why are both "options" and "inhreloptions" necessary in
> IndexStmt? Won't at least one be NULL?

Yes, in the CREATE..LIKE case, options will be NULL and in the normal
CREATE..INDEX case inhreloptions will be NULL. Note that options is a List
of DefElem entries, whereas inhreloptions is a char pointer.

The challenge was with converting the stored reloptions belonging to the
parent index into some form which could be consumed by
transformRelOptions(). It was difficult to convert it into a list of DefElem
entries and hence I had to introduce inhreloptions.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-10 21:38:53
Message-ID: 200707102138.l6ALcrI19028@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Neil Conway wrote:
> On Tue, 2007-05-06 at 14:50 +0530, NikhilS wrote:
> > PFA, a patch which provides the "CREATE .. INCLUDING INDEXES"
> > functionality. This patch uses the same functionality introduced by
> > the earlier patches in this thread albeit for the "INCLUDING INDEXES"
> > case.
>
> Attached is a revised version of this patch. Sorry for taking so long to
> make progress on this: my new job been keeping my busy, and I've
> recently been ill.

Illness only counts as an excuse if you _don't_ recover. If you
recover, you weren't sick enough. ;-) LOL

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: "Jaime Casanova" <systemguards(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Neil Conway" <neilc(at)samurai(dot)com>, NikhilS <nikkhils(at)gmail(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-11 05:15:28
Message-ID: c2d9e70e0707102215s1e4617d7le4495104b039ec34@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On 7/10/07, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Neil Conway wrote:
> > Attached is a revised version of this patch. Sorry for taking so long to
> > make progress on this: my new job been keeping my busy, and I've
> > recently been ill.
>
> Illness only counts as an excuse if you _don't_ recover. If you
> recover, you weren't sick enough. ;-) LOL
>

uh! that sounds like my boss talking!

--
regards,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
Richard Cook


From: Neil Conway <neilc(at)samurai(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-16 07:46:39
Message-ID: 1184571999.11492.23.camel@goldbach
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Tue, 2007-10-07 at 12:53 +0530, NikhilS wrote:
> Yes, in the CREATE..LIKE case, options will be NULL and in the normal
> CREATE..INDEX case inhreloptions will be NULL. Note that options is a
> List of DefElem entries, whereas inhreloptions is a char pointer.

Hmm, right -- ugly. I'll just stick with your approach.

BTW, I notice a problem with the patch as implemented:

# create table abc (a int, b int);
CREATE TABLE
# create index abc_a_idx on abc using hash (a);
CREATE INDEX
# create index abc_a_idx2 on abc (a);
CREATE INDEX
# create table abc2 (like abc including indexes);
CREATE TABLE
# \d abc2
Table "public.abc2"
Column | Type | Modifiers
--------+---------+-----------
a | integer |
b | integer |
Indexes:
"abc2_a_key" hash (a)

This occurs because transformIndexConstraints() eliminates "duplicate"
indexes from the index list by looking for two indexes with equal()
column lists. This makes some sense for the normal CREATE TABLE case,
but the above behavior is certainly objectionable -- when the access
method differs it is merely surprising, but when partial indexes are
involved it is surely a bug.

One way to fix this would be to check for duplicates by comparing all
the fields of the two IndexStmts, *except* the index name and "is PK?"
status. But that's ugly -- it seems much cleaner to keep index
definitions arising from LIKE ... INCLUDING INDEXES in a separate list
from the indexes derived from constraints.

Attached is a revised patch that does that. Barring any objections, I'll
apply this to HEAD tomorrow.

-Neil

Attachment Content-Type Size
including_indexes_v5.patch text/x-patch 39.9 KB

From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Neil Conway" <neilc(at)samurai(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-16 08:58:32
Message-ID: d3c4af540707160158r7069b30cs52da5f002a2ff673@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> Attached is a revised patch that does that. Barring any objections, I'll
> apply this to HEAD tomorrow.
>

A minor correction below in your patch:

--- src/include/commands/defrem.h 16 Jul 2007 05:19:43 -0000
*************** extern void DefineIndex(RangeVar *heapRe
*** 26,31 ****
--- 26,32 ----
List *options,
+ char *inhreloptions,

Guess you want to use "src_options" here to be uniform with usages
elsewhere that you have replaced. You suppose "src_options" is much
more readable than "inhreloptions" or "inh_idxoptions"? Your call :).

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: Neil Conway <neilc(at)samurai(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-16 10:08:52
Message-ID: 1184580532.29879.3.camel@goldbach
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, 2007-16-07 at 14:28 +0530, NikhilS wrote:
> Guess you want to use "src_options" here to be uniform with usages
> elsewhere that you have replaced.

Thanks, good catch.

> You suppose "src_options" is much more readable than "inhreloptions"
> or "inh_idxoptions"? Your call :).

Yeah, I'm not necessarily sure that it is. "inhreloptions" made me think
of table inheritance, whereas LIKE in general is more of a "source" =>
"target" copying operation. But I'm not convinced about src_options,
either ... suggestions/comments welcome.

-Neil


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Neil Conway" <neilc(at)samurai(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Trevor Hardcastle" <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-16 10:20:09
Message-ID: d3c4af540707160320j6b71ab89v25591c9e7ab7d4d9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

> > You suppose "src_options" is much more readable than "inhreloptions"
> > or "inh_idxoptions"? Your call :).
>
> Yeah, I'm not necessarily sure that it is. "inhreloptions" made me think
> of table inheritance, whereas LIKE in general is more of a "source" =>
> "target" copying operation. But I'm not convinced about src_options,
> either ... suggestions/comments welcome.
>

I agree, since its a LIKE operation and not inheritance as such, how about
"src_idxoptions", just to make the reference to the source index
clearer? To reiterate its a minor nitpick really from my side and can
be ignored too.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: Neil Conway <neilc(at)samurai(dot)com>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Trevor Hardcastle <chizu(at)spicious(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-17 05:03:40
Message-ID: 1184648620.6187.2.camel@goldbach
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

I've applied the latest version of the patch to HEAD. Thanks for the
patches, Nikhil and Trevor -- we can take a look at improving INCLUDING
CONSTRAINTS for 8.4.

On Mon, 2007-16-07 at 15:50 +0530, NikhilS wrote:
> I agree, since its a LIKE operation and not inheritance as such, how about
> "src_idxoptions", just to make the reference to the source index
> clearer?

I decided to keep it as "src_options", but we can always change it
later.

-Neil


From: Tatsuo Ishii <ishii(at)sraoss(dot)co(dot)jp>
To: neilc(at)samurai(dot)com
Cc: nikkhils(at)gmail(dot)com, tgl(at)sss(dot)pgh(dot)pa(dot)us, bruce(at)momjian(dot)us, chizu(at)spicious(dot)com, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-20 03:03:02
Message-ID: 20070720.120302.59658074.t-ishii@sraoss.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Can someone enligten me what the usecase for CREATE TABLE LIKE at this
moment is?

I read the doc and followed the discssion in this thread in
pgsql-patches list but it was hard for me to figure out.
--
Tatsuo Ishii
SRA OSS, Inc. Japan

> I've applied the latest version of the patch to HEAD. Thanks for the
> patches, Nikhil and Trevor -- we can take a look at improving INCLUDING
> CONSTRAINTS for 8.4.
>
> On Mon, 2007-16-07 at 15:50 +0530, NikhilS wrote:
> > I agree, since its a LIKE operation and not inheritance as such, how about
> > "src_idxoptions", just to make the reference to the source index
> > clearer?
>
> I decided to keep it as "src_options", but we can always change it
> later.
>
> -Neil
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Tatsuo Ishii" <ishii(at)sraoss(dot)co(dot)jp>
Cc: <neilc(at)samurai(dot)com>, <nikkhils(at)gmail(dot)com>, <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <bruce(at)momjian(dot)us>, <chizu(at)spicious(dot)com>, <pgsql-patches(at)postgresql(dot)org>
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-20 11:40:46
Message-ID: 87644f9ubl.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"Tatsuo Ishii" <ishii(at)sraoss(dot)co(dot)jp> writes:

> Can someone enligten me what the usecase for CREATE TABLE LIKE at this
> moment is?

One of the main use cases I envision is wanting to create new partitions
suitable for being added to a partitioned table.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com


From: "Jim C(dot) Nasby" <decibel(at)decibel(dot)org>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: Tatsuo Ishii <ishii(at)sraoss(dot)co(dot)jp>, neilc(at)samurai(dot)com, nikkhils(at)gmail(dot)com, tgl(at)sss(dot)pgh(dot)pa(dot)us, bruce(at)momjian(dot)us, chizu(at)spicious(dot)com, pgsql-patches(at)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-20 21:01:29
Message-ID: 20070720210129.GE39272@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Fri, Jul 20, 2007 at 12:40:46PM +0100, Gregory Stark wrote:
> "Tatsuo Ishii" <ishii(at)sraoss(dot)co(dot)jp> writes:
>
> > Can someone enligten me what the usecase for CREATE TABLE LIKE at this
> > moment is?
>
> One of the main use cases I envision is wanting to create new partitions
> suitable for being added to a partitioned table.

Except that's normally done with CREATE TABLE INHERITS, which seems
cleaner to me. I think the patch would be more useful if it added
support for INHERITS, but I don't object to it as-is.
--
Jim Nasby decibel(at)decibel(dot)org
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Jim C(dot) Nasby" <decibel(at)decibel(dot)org>
Cc: "Tatsuo Ishii" <ishii(at)sraoss(dot)co(dot)jp>, <neilc(at)samurai(dot)com>, <nikkhils(at)gmail(dot)com>, <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <bruce(at)momjian(dot)us>, <chizu(at)spicious(dot)com>, <pgsql-patches(at)postgresql(dot)org>
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support
Date: 2007-07-21 09:54:17
Message-ID: 87lkda6q0m.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


"Jim C. Nasby" <decibel(at)decibel(dot)org> writes:

> On Fri, Jul 20, 2007 at 12:40:46PM +0100, Gregory Stark wrote:
>
>> One of the main use cases I envision is wanting to create new partitions
>> suitable for being added to a partitioned table.
>
> Except that's normally done with CREATE TABLE INHERITS, which seems
> cleaner to me. I think the patch would be more useful if it added
> support for INHERITS, but I don't object to it as-is.

Well there are two different approaches to creating a new partition. For some
use cases you want to create a new empty partition directly in the table and
start using it right away. For other use cases you want to create a table into
which you need to load data, possibly even massage the data with updates and
deletes or additional inserts, then add the partition with the data all ready
directly into the master table.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com