file_fdw: Fix ANALYZE does not enforce REJECT_LIMIT with on_error 'ignore'

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

file_fdw: Fix ANALYZE does not enforce REJECT_LIMIT with on_error 'ignore'

От:
Ayoub Kazar <ayoub.kazar@data-bene.io>
Дата:
Вложения:
Hi,

When a file_fdw table is configured with on_error 'ignore' and a 
reject_limit option,
SELECT queries properly abort with an ERROR once the number of bad rows 
exceeds the limit.
However, ANALYZE silently ignores reject_limit, skips all 
malformed rows, and finishes with a NOTICE.

Reproduce with this:

printf 'x\ny\n' > /tmp/fdw.csv

CREATE EXTENSION file_fdw;
CREATE SERVER fs FOREIGN DATA WRAPPER file_fdw;
CREATE FOREIGN TABLE ft_bad (a int) SERVER fs
  OPTIONS (filename '/tmp/fdw.csv', format 'csv',
         on_error 'ignore', reject_limit '1');

SELECT * FROM ft_bad;
ERROR:  skipped more than REJECT_LIMIT (1) rows due to data type 
incompatibility
CONTEXT:  COPY ft_bad, line 2, column a: "y"

ANALYZE ft_bad;
NOTICE:  2 rows were skipped due to data type incompatibility

The fix is straightforward, we just add the same 
cstate->opts.reject_limit check to
file_acquire_sample_rows(), just like we do for fileIterateForeignScan().

I thought about whether this is necessary at all or not (like it's not a 
crash or anything, just not intended behavior at the very least), i'm 
more into the first, thoughts ?


Regards,
Ayoub Kazar

Re: file_fdw: Fix ANALYZE does not enforce REJECT_LIMIT with on_error 'ignore'

От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Thu, Nov 5, 2026 at 9:40 AM Ayoub Kazar  wrote:
> However, ANALYZE silently ignores reject_limit, skips all
> malformed rows, and finishes with a NOTICE.

Personally, I'd prefer to keep this behavior. Statistics based on valid rows
are still useful even when the number of errors exceeds reject_limit.
Queries may still succeed, for example, when using LIMIT, whereas
aborting ANALYZE would leave the statistics outdated. So I think
ANALYZE should continue to ignore reject_limit. Thought?

If we agree, how about documenting this exception and adding a comment
in file_acquire_sample_rows() explaining why reject_limit is not enforced?

Regards,

-- 
Fujii Masao


Re: file_fdw: Fix ANALYZE does not enforce REJECT_LIMIT with on_error 'ignore'

От:
Ayoub Kazar <ayoub.kazar@data-bene.io>
Дата:
Вложения:
On 05/11/2026 16:24, Fujii Masao wrote:

> On Thu, Nov 5, 2026 at 9:40 AM Ayoub Kazar  wrote:
>> However, ANALYZE silently ignores reject_limit, skips all
>> malformed rows, and finishes with a NOTICE.
> Personally, I'd prefer to keep this behavior. Statistics based on valid rows
> are still useful even when the number of errors exceeds reject_limit.
> Queries may still succeed, for example, when using LIMIT, whereas
> aborting ANALYZE would leave the statistics outdated. So I think
> ANALYZE should continue to ignore reject_limit. Thought?
Yes, very reasonable.
The NOTICE itself also provides good info about what's going on, so 
that's okay.
>
> If we agree, how about documenting this exception and adding a comment
> in file_acquire_sample_rows() explaining why reject_limit is not enforced?
Attached is v2 documenting this in file-fdw.sgml and adding a comment in 
file_acquire_sample_rows().


Regards,
Ayoub Kazar

Re: file_fdw: Fix ANALYZE does not enforce REJECT_LIMIT with on_error 'ignore'

От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Fri, Nov 6, 2026 at 4:07 AM Ayoub Kazar  wrote:
> Attached is v2 documenting this in file-fdw.sgml and adding a comment in
> file_acquire_sample_rows().

Thanks for updating the patch! I've pushed it.

Regards,

-- 
Fujii Masao


FAQ