Обсуждение: Raw constraint & pg_relcheck.rcsrc

Поиск
Список
Период
Сортировка

Raw constraint & pg_relcheck.rcsrc

От
"Hiroshi Inoue"
Дата:
Hi all,

I have a question.
As far as I see,constraints are stored into PG database ordinarily
as follows.
 1) RelationAddRawConstraints() converts each raw constaint     to bin form. 2) StoreRelCheck() converts the bin form
tosrc form and store     them into pg_relcheck tuples.
 

Is pg_relcheck.rcsrc equivalent to the original raw constraint ?

Regards.

Hiroshi Inoue
Inoue@tpf.co.jp


Re: Raw constraint & pg_relcheck.rcsrc

От
Tom Lane
Дата:
"Hiroshi Inoue" <Inoue@tpf.co.jp> writes:
> Is pg_relcheck.rcsrc equivalent to the original raw constraint ?

To the best of deparse_expression()'s ability, it should be.
I'm not real sure why we bother to store it, rather than deparsing
rcbin on-the-fly on demand...
        regards, tom lane


RE: Raw constraint & pg_relcheck.rcsrc

От
"Hiroshi Inoue"
Дата:
> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> 
> "Hiroshi Inoue" <Inoue@tpf.co.jp> writes:
> > Is pg_relcheck.rcsrc equivalent to the original raw constraint ?
> 
> To the best of deparse_expression()'s ability, it should be.
> I'm not real sure why we bother to store it, rather than deparsing
> rcbin on-the-fly on demand...
>

I'm looking at DefineRelation() in commands/creartinh.c.
In case of inheritance,constraints of super classes are
stored using their pg_relcheck.rcbin-s. It seems bad 
in case of multiple inheritance.  rcsrc-s may be available
instead.

Comments ?  

Regards.

Hiroshi Inoue
Inoue@tpf.co.jp


RE: Raw constraint & pg_relcheck.rcsrc

От
"Hiroshi Inoue"
Дата:
> -----Original Message-----
> From: Hiroshi Inoue [mailto:Inoue@tpf.co.jp]
> 
> > -----Original Message-----
> > From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> > 
> > "Hiroshi Inoue" <Inoue@tpf.co.jp> writes:
> > > Is pg_relcheck.rcsrc equivalent to the original raw constraint ?
> > 
> > To the best of deparse_expression()'s ability, it should be.
> > I'm not real sure why we bother to store it, rather than deparsing
> > rcbin on-the-fly on demand...
> >
> 
> I'm looking at DefineRelation() in commands/creartinh.c.
> In case of inheritance,constraints of super classes are
> stored using their pg_relcheck.rcbin-s. It seems bad 
> in case of multiple inheritance.  rcsrc-s may be available
> instead.
>

Oops,I've been completely off the point.
The raw expression of constraints seems to be really needed.

Is there any way to convert rcbin(cooked text format) to the
raw(pre-cooked) Node expression ? Or is there a way to
convert rcsrc to the pre-cooked Node expression ?
Or is there a way to convert rcsrc to the cooked expression ?

Here's a simple bug case.

=# create table p1 (id int4);
CREATE
=# create table p2 (dt text check (dt = 'a'));
CREATE
=# create table inh () inherits (p1,p2);
CREATE
=# \d inh         Table "inh"Attribute |  Type   | Modifier
-----------+---------+----------id        | integer |dt        | text    |
Constraint: (id = 'a'::text)

Regards.

Hiroshi Inoue
Inoue@tpf.co.jp


Re: Raw constraint & pg_relcheck.rcsrc

От
Tom Lane
Дата:
"Hiroshi Inoue" <Inoue@tpf.co.jp> writes:
> Is there any way to convert rcbin(cooked text format) to the
> raw(pre-cooked) Node expression?

No.

> Or is there a way to
> convert rcsrc to the pre-cooked Node expression ?
> Or is there a way to convert rcsrc to the cooked expression ?

I think what you'd have to do is take the parent's rcsrc and run it
through the parse and transform phases again, using the new child
table as the reference for attribute name resolution.  Thomas might
have a clearer idea than I do about the cleanest way to interface
to the parser for that.

Another possibility is to determine the mapping from parent columns
to child columns, and then walk through the (cooked) expression tree
and substitute varattno field values in Var nodes accordingly.  I'm
not certain that's sufficient, but if it is it'd be a fairly small
amount of code (in fact you might be able to just call the routines in
the rewriter that do similar things).
        regards, tom lane


RE: Raw constraint & pg_relcheck.rcsrc

От
"Hiroshi Inoue"
Дата:
> -----Original Message-----
> From: Tom Lane
> 
> "Hiroshi Inoue" <Inoue@tpf.co.jp> writes:
> > Is there any way to convert rcbin(cooked text format) to the
> > raw(pre-cooked) Node expression?
> 
> No.
> 
> > Or is there a way to
> > convert rcsrc to the pre-cooked Node expression ?
> > Or is there a way to convert rcsrc to the cooked expression ?
>

[snip]
> Another possibility is to determine the mapping from parent columns
> to child columns, and then walk through the (cooked) expression tree
> and substitute varattno field values in Var nodes accordingly.  I'm
> not certain that's sufficient, but if it is it'd be a fairly small
> amount of code (in fact you might be able to just call the routines in
> the rewriter that do similar things).
>

OK,I would try this way using expression_tree_walker() which I
used once in my trial for ALTER TABLE DROP COLUMN.

Thanks.

Hiroshi Inoue
Inoue@tpf.co.jp