Re: extend VacAttrStats to allow stavalues of different types

Lists: pgsql-patches
From: Jan Urbański <j(dot)urbanski(at)students(dot)mimuw(dot)edu(dot)pl>
To: Postgres - Patches <pgsql-patches(at)postgresql(dot)org>
Subject: extend VacAttrStats to allow stavalues of different types
Date: 2008-05-15 22:29:47
Message-ID: 482CB95B.5060009@students.mimuw.edu.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

Following the conclusion here:
http://archives.postgresql.org/pgsql-hackers/2008-05/msg00273.php
here's a patch that extends VacAttrStats to allow typanalyze functions
to store statistic values of different types than the underlying column.

The XXX comment can be taken into consideration or just dropped as
unimportant.

Cheers,
--
Jan Urbanski
GPG key ID: E583D7D2

ouden estin

Attachment Content-Type Size
vacattrstats-extend.diff text/plain 4.2 KB

From: Jan Urbański <j(dot)urbanski(at)students(dot)mimuw(dot)edu(dot)pl>
To: Postgres - Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: extend VacAttrStats to allow stavalues of different types
Date: 2008-05-15 22:48:16
Message-ID: 482CBDB0.7020901@students.mimuw.edu.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

Jan Urbański wrote:
> Following the conclusion here:
> http://archives.postgresql.org/pgsql-hackers/2008-05/msg00273.php
> here's a patch that extends VacAttrStats to allow typanalyze functions
> to store statistic values of different types than the underlying column.
>
> The XXX comment can be taken into consideration or just dropped as
> unimportant.

Doh, this time against HEAD, not my branch ...

--
Jan Urbanski
GPG key ID: E583D7D2

ouden estin

Attachment Content-Type Size
vacattrstats-expand-HEAD.diff text/plain 3.6 KB

From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: Jan Urbański <j(dot)urbanski(at)students(dot)mimuw(dot)edu(dot)pl>
Cc: "Postgres - Patches" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: extend VacAttrStats to allow stavalues of different types
Date: 2008-06-02 07:52:51
Message-ID: 4843A6D3.2040403@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

Jan Urbański wrote:
> Following the conclusion here:
> http://archives.postgresql.org/pgsql-hackers/2008-05/msg00273.php
> here's a patch that extends VacAttrStats to allow typanalyze functions
> to store statistic values of different types than the underlying column.

Looks good to me at first glance.

About this comment:

> + * XXX or maybe fall back on attrtype-> stuff when these are NULL? That way
> + * we won't break other people's custom typanalyze functions. Not sure if
> + * any exist, though.

I tried to google for a user defined data type with a custom typanalyze
function but didn't find anything, so I don't think it's an issue. It's
a bit nasty, though, because if one exists, it will compile and run just
fine, until you run ANALYZE. In general it's better to break an old API
obviously rather than silently, so that the old code doesn't even compile.

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


From: Jan Urbański <j(dot)urbanski(at)students(dot)mimuw(dot)edu(dot)pl>
To: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
Cc: Postgres - Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: extend VacAttrStats to allow stavalues of different types
Date: 2008-06-02 11:03:18
Message-ID: 4843D376.4020000@students.mimuw.edu.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

Heikki Linnakangas wrote:
> I tried to google for a user defined data type with a custom typanalyze
> function but didn't find anything, so I don't think it's an issue. It's
> a bit nasty, though, because if one exists, it will compile and run just
> fine, until you run ANALYZE. In general it's better to break an old API
> obviously rather than silently, so that the old code doesn't even compile.

I can't think of a way to make the compilation fail if your old
typanalyze function fails to set the extra VacAttrStats fields. As I see
it, there are three options:
1. fall back on the old behaviour at the price of code uglification
2. put an Assert after the OidFunctionCall that calls a typanalyze
function if it exists, so people will get a nicer error message when
they test their code
3. put an ereport(ERROR, ...) after the OidFunctionCall, so people will
get a nicer error message if they don't use --enable-cassert and they'll
avoid segfaulting the backend on an ANALYZE call.

I think I like 2. best, but I just thought that you could check if the
custom typanalyze routine did set the fields right after it's been
called, and if it didn't then set them for it and thus get 1. in an
arguably clean way. Only that encourages sloppy programming (not setting
the fields and relying on someone to set them).

--
Jan Urbanski
GPG key ID: E583D7D2

ouden estin


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
Cc: Jan Urbański <j(dot)urbanski(at)students(dot)mimuw(dot)edu(dot)pl>, "Postgres - Patches" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: extend VacAttrStats to allow stavalues of different types
Date: 2008-06-02 14:37:29
Message-ID: 18320.1212417449@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

"Heikki Linnakangas" <heikki(at)enterprisedb(dot)com> writes:
> Jan Urbaski wrote:
>> + * XXX or maybe fall back on attrtype-> stuff when these are NULL? That way
>> + * we won't break other people's custom typanalyze functions. Not sure if
>> + * any exist, though.

> I tried to google for a user defined data type with a custom typanalyze
> function but didn't find anything, so I don't think it's an issue.

Oh, it absolutely is an issue. PostGIS has them, if no one else does.

I think the correct solution is to initialize the fields to match the
column type before calling the typanalyze function. Then you don't
break compatibility for existing typanalyze functions. It's also less
code, since the standard typanalyze functions can rely on those preset
values.

regards, tom lane


From: Jan Urbański <j(dot)urbanski(at)students(dot)mimuw(dot)edu(dot)pl>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>, Postgres - Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: extend VacAttrStats to allow stavalues of different types
Date: 2008-06-02 15:58:48
Message-ID: 484418B8.6060004@students.mimuw.edu.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

Tom Lane wrote:
> I think the correct solution is to initialize the fields to match the
> column type before calling the typanalyze function. Then you don't
> break compatibility for existing typanalyze functions. It's also less
> code, since the standard typanalyze functions can rely on those preset
> values.

Right. Updated patch attached.

--
Jan Urbanski
GPG key ID: E583D7D2

ouden estin

Attachment Content-Type Size
extend-vacattrstats-2.diff text/plain 3.5 KB

From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: Jan Urbański <j(dot)urbanski(at)students(dot)mimuw(dot)edu(dot)pl>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Postgres - Patches" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: extend VacAttrStats to allow stavalues of different types
Date: 2008-07-01 10:33:24
Message-ID: 486A07F4.3070502@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

Jan Urbański wrote:
> Tom Lane wrote:
>> I think the correct solution is to initialize the fields to match the
>> column type before calling the typanalyze function. Then you don't
>> break compatibility for existing typanalyze functions. It's also less
>> code, since the standard typanalyze functions can rely on those preset
>> values.
>
> Right. Updated patch attached.

Thanks, committed.

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