Fix more issues with extended statistics on expressions When evaluating expressions (through make_build_data()) and building stats data for expressions (through build_expr_data()), both routines forgot that examine_expression() could return a NULL result, depending on the data generated by the typanalyze function assigned to a type. This would crash the server.
This commit includes some tests added to test_custom_types that are able to reproduce all these issues with two fancy typanalyze callbacks: - False result with a valid stats target, for the expression evaluation. - False result with a valid stats target on second call, for the stats data build. No typanalyze callback in core have the idea to do that, and I doubt that anything out there has the idea to do that. If they do, this switches the expression stats to fail gracefully instead of crashing, based on the combinations that are assumed as supported by the core code. This is a continuation of 3b7a6fa15720. Reported-by: Yuelin Wang <[email protected]> Author: Shihao Zhong <[email protected]> Author: Michael Paquier <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 14 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/b2ca62b1c069616302b5f9b4d1eb92cd628ea111 Modified Files -------------- src/backend/statistics/extended_stats.c | 48 ++++++++++++++++++---- src/test/modules/test_custom_types/README | 4 ++ .../expected/test_custom_types.out | 36 ++++++++++++++++ .../test_custom_types/sql/test_custom_types.sql | 28 +++++++++++++ .../test_custom_types/test_custom_types--1.0.sql | 16 ++++++++ .../modules/test_custom_types/test_custom_types.c | 37 +++++++++++++++++ 6 files changed, 161 insertions(+), 8 deletions(-)
