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

Started by Ayoub Kazar19 days ago4 messageshackers
Jump to latest
#1Ayoub Kazar
kazarayoub2004@gmail.com

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

Attachments:

t254566_1
0001-file_fdw-Enforce-REJECT_LIMIT-during-ANALYZE.patchtext/x-patch; charset=UTF-8; name=0001-file_fdw-Enforce-REJECT_LIMIT-during-ANALYZE.patchDownload+11-1
#2Fujii Masao
masao.fujii@gmail.com
In reply to: Ayoub Kazar (#1)
Re: file_fdw: Fix ANALYZE does not enforce REJECT_LIMIT with on_error 'ignore'

On Thu, Nov 5, 2026 at 9:40 AM Ayoub Kazar <ayoub.kazar@data-bene.io> 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

#3Ayoub Kazar
kazarayoub2004@gmail.com
In reply to: Fujii Masao (#2)
Re: file_fdw: Fix ANALYZE does not enforce REJECT_LIMIT with on_error 'ignore'

On 05/11/2026 16:24, Fujii Masao wrote:

On Thu, Nov 5, 2026 at 9:40 AM Ayoub Kazar <ayoub.kazar@data-bene.io> 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

Attachments:

t254566_3
v2-0001-file_fdw-Document-why-ANALYZE-does-not-enforce-REJECT_LIMIT.patchtext/x-patch; charset=UTF-8; name=v2-0001-file_fdw-Document-why-ANALYZE-does-not-enforce-REJECT_LIMIT.patchDownload+8-1
#4Fujii Masao
masao.fujii@gmail.com
In reply to: Ayoub Kazar (#3)
Re: file_fdw: Fix ANALYZE does not enforce REJECT_LIMIT with on_error 'ignore'

On Fri, Nov 6, 2026 at 4:07 AM Ayoub Kazar <ayoub.kazar@data-bene.io> 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