Re: Numeric multiplication overflow errors

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Numeric multiplication overflow errors
Date: 2021-07-01 01:00:22
Message-ID: CAApHDvrLJfW8dt2hZe7NmniBCgt3qeq2Xyzf9MZUc0gOH7AfcQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks for the updated patch

On Tue, 29 Jun 2021 at 22:29, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
> I'm not a fan of the *serialize() function names in numeric.c though
> (e.g., the name numeric_serialize() seems quite misleading for what it
> actually does). So rather than adding to those, I've kept the original
> names. In the context where they're used, those names seem more
> natural.

I've only looked at the numeric-agg-sumX2-overflow-v2.patch one and it
all looks mostly ok.

I kinda disagree with the send/recv naming since all you're using them
for is to serialise/deserialise the NumericVar. Functions named
*send() and recv() I more expect to return a bytea so they can be used
for a type's send/recv function. I just don't have the same
expectations for functions named serialize/deserialize. That's all
pretty special to aggregates with internal states.

One other thing I can think of to mention is that the recv function
fetches the digits with pq_getmsgint(buf, sizeof(NumericDigit))
whereas, the send function sends them with pq_sendint16(buf,
var->digits[i]). I understand you've just copied numeric_send/recv,
but I disagree with that too and think that both send functions should
be using pq_sendint. This would save having weird issues if someone
was to change the type of the NumericDigit. Perhaps that would cause
other problems, but I don't think it's a good idea to bake those
problems in any further.

I also wonder if numericvar_recv() really needs all the validation
code? We don't do any other validation during deserialisation. I see
the logic in doing this for a recv function since a client could send
us corrupt data e.g. during a binary copy. There are currently no
external factors to account for with serial/deserial.

I'm also fine for that patch to go in as-is. I'm just pointing out
what I noted down when looking over it. I'll let you choose if you
want to make any changes based on the above.

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gurjeet Singh 2021-07-01 01:11:19 Re: Automatic notification of top transaction IDs
Previous Message Thomas Munro 2021-07-01 00:59:27 Re: Use simplehash.h instead of dynahash in SMgr