Hi, Running ANALYZE on a file_fdw table with a DEFAULT marker in the input caused an assertion failure. Here is how to reproduce the issue:
---------------------------------------------------------------
printf 'DEFAULT\n' > /tmp/file_fdw_default.csv
Then run:
CREATE EXTENSION file_fdw;
CREATE SERVER fs FOREIGN DATA WRAPPER file_fdw;
CREATE FOREIGN TABLE ft (a integer DEFAULT 42)
SERVER fs
OPTIONS (filename '/tmp/file_fdw_default.csv',
format 'csv', "default" 'DEFAULT');
ANALYZE ft;
---------------------------------------------------------------
This causes the following assertion failure:
TRAP: failed Assert("econtext != NULL"), File: "copyfromparse.c",
Line: 1062, PID: 94428
Builds without assertions can also crash.
The issue occurs because the sampling code in file_fdw passes
a NULL ExprContext to NextCopyFrom(), which needs one to evaluate
column defaults.
Attached patch fixes this by providing an expression context for sampling.
This should be backpatched to v16, where DEFAULT marker support was
introduced.
Regards,
--
Fujii Masao
v1-0001-file_fdw-Fix-ANALYZE-crashes-with-DEFAULT-markers.patch
Description: Binary data
