Re: Remove dependence on integer wrapping - Mailing list pgsql-hackers

From Joseph Koshakow
Subject Re: Remove dependence on integer wrapping
Date
Msg-id CAAvxfHfeUmVMXU6883in2H-jJ+Vn2=mcSgVpsNDRTTK=OYDjoA@mail.gmail.com
Whole thread Raw
In response to Re: Remove dependence on integer wrapping  (jian he <jian.universality@gmail.com>)
Responses Re: Remove dependence on integer wrapping
List pgsql-hackers


On Wed, Jul 17, 2024 at 9:31 PM jian he <jian.universality@gmail.com> wrote:
>
> i think "INSERT INTO arroverflowtest(i[2147483647:2147483647]) VALUES ('{}');"
> means to insert one element (size) to a customized lower/upper bounds.

Ah, thank you, I mistakenly understood that as an array with size
2147483647, with the first 2147483646 elements NULL.

I've updated the first calculation (upper_bound + 1) to retrun an error
saying "array upper bound is too large: %d" when it overflows. This
will change some of the existing error messages, but is just as correct
and doesn't require us to check the source array. Is there backwards
compatibility guarantees on error messages or is that acceptable?


For the second calculation ((upper_bound + 1) - lower_bound), I've kept the
existing error of "array size exceeds the maximum allowed (%d)". The
only way for that to underflow is if the upper bound is very negative
and the lower bound is very positive. I'm not entirely sure how to
interpret this scenario, but it's consistent with similar scenarios.

    # INSERT INTO arroverflowtest(i[10:-999999]) VALUES ('{1,2,3}');
    ERROR:  array size exceeds the maximum allowed (134217727)

As a reminder:
- 0001 is reviewed.
- 0002 is reviewed and a bug fix.
- 0003 is currently under review and a bug fix.
- 0004 needs a review.

Thanks,
Joe Koshakow
Attachment

pgsql-hackers by date:

Previous
From: 김명준
Date:
Subject: Re: [ pg_ctl ] Review Request for Adding Pre-check User Script Feature
Next
From: torikoshia
Date:
Subject: Re: Add on_error and log_verbosity options to file_fdw