Skip site navigation (1) Skip section navigation (2)

Re: Inheritance, CREATE TABLE LIKE, and partitioned tables

From: elein <elein(at)varlena(dot)com>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Inheritance, CREATE TABLE LIKE, and partitioned tables
Date: 2006-06-26 20:27:03
Message-ID: 20060626202703.GW3541@varlena.com (view raw or flat)
Thread:
Lists: pgsql-hackers
On Mon, Jun 26, 2006 at 12:31:24PM -0400, Greg Stark wrote:
> 
> Currently analyze.c and tablecmds.c both have some very similar code to handle
> copying columns from "parent" tables. As long as they were just copying
> columns and in the case of tablecmds.c copying check constraints that wasn't
> really that bad an idea, the code is pretty simple.
> 
> However with partitioned tables it becomes important to copy more table
> attributes like foreign key constraints and hopefully one day indexes. And it
> would be awfully convenient to have CREATE TABLE LIKE have options to copy the
> same things that inherited tables get. And have exactly the same semantics.

People will turn around and immediately as for create table like without us
making the assumptions it wanted all of the extras that come with inheritance.
COPY is a copy of the table, not additional functionality.  The added flexibility
of adding only what is necessary makes more sense than going in to guess
what was added and removing it later if it is not needed.

This does not preclude adding a copy table like (with extras) though if you must.

> 
> So I'm suggesting refactoring the code from analyze.c and tablecmds.c into
> functions to copy the columns, constraints, indexes etc.
> 
> For example I see a functions like:
> 
> List *CopyTableColumns(relation source, List *target_schema)
> List *CopyTableCheckConstraints(relation source, List *target_schema)
> ...
> 
> To do this though might require some changes in the algorithm used for
> inherited tables. Currently it builds up the list of merged columns
> incrementally. I'm thinking it would be more natural to accumulate all the
> columns from parents and then remove duplicates in a single pass. I think it
> should be possible to maintain precisely the same semantics doing this though.

Be careful because the code may be taking into account multiple inheritance here.
I'm not sure about this. It should be looked at carefully.

> 
> I may be able to make AddInherits a consumer for these functions as well,
> though it would be a bit awkward since it would have to construct a fake list
> of ColumnDefs to act as the target schema. It would have the side effect of
> making the constraint comparison use change_varattnos_of_a_node and then
> compare the binary representations rather than decompiling the constraints to
> do the comparison. I'm not sure if that's the same semantics.
Again, be sure it is the same semantics before going that way.
> 
> To a certain degree I feel like this is just make-work. The existing code
> works fine and I can just happily keep additing functionality to both
> analyze.c and tablecmds.c. And it's possible we won't always want to have the
> two match.
> 
> Has anyone looked at applying the ADD INHERITS patch yet? Would it be more or
> less likely to be accepted if it were a bigger patch that refactored all this
> stuff like I'm talking about?
> 
> -- 
> greg
> 
---elein
elein(at)varlena(dot)com

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2006-06-26 20:43:10
Subject: Re: "Truncated" tuples for tuple hash tables
Previous:From: Simon RiggsDate: 2006-06-26 20:12:55
Subject: Re: [PATCHES] Non-transactional pg_class, try 2

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group