What a sleepless night investigating why BDR crashes when updating index on expression with Segmentation Fault error. I agree with akretschmer‘s comment on my previous post that replacing functional index with column index is not considered as a solution. So I take a closer look at function associated with the problematic expression index:
The function is defined in SQL language:
CREATE OR REPLACE FUNCTION mybdr.funcidx(a smallint, b integer, c smallint, d text)
RETURNS text AS
$BODY$
SELECT ($1+1)::text || '.' || '5' || (CASE WHEN $3=2::smallint THEN '1' ELSE '' END) || '.' || LPAD($2::text, 6, '0') || '/' || $4;
$BODY$
LANGUAGE sql IMMUTABLE STRICT;
Then I find out that by converting it to PLPGSQL language, no more BDR crashes:
CREATE OR REPLACE FUNCTION mybdr.funcidx(a smallint, b integer, c smallint, d text)
RETURNS text AS
$BODY$
BEGIN
RETURN (a+1)::text || '.' || '5' || (CASE WHEN c=2::smallint THEN '1' ELSE '' END) || '.' || LPAD(b::text, 6, '0') || '/' || d;
END;
$BODY$
LANGUAGE plpgsql IMMUTABLE STRICT;
Need a deep investigation on that.
