- milestone: 2663467 --> 1,2 Dev Q
This test case taken from aggregates.sql, can be used to reproduce the crash which is an assertion failure on the datanode
create table varchar_tbl( f1 character varying(4) );
insert into varchar_tbl values('a'), ('ab'), ('abcd'), ('abcd');
select string_agg(distinct f1, ',' order by f1) from varchar_tbl;
It would cause a datanode crash
TRAP: FailedAssertion("!(AggCheckCallContext(fcinfo, ((void *)0)))", File: "varlena.c", Line: 3668)
The explain output is as follows
test=# explain verbose select string_agg(distinct f1, ',' order by f1) from varchar_tbl;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------
Data Node Scan on "__REMOTE_FQS_QUERY__" (cost=0.00..0.00 rows=0 width=0)
Output: (string_agg(DISTINCT (varchar_tbl.f1)::text, ','::text ORDER BY (varchar_tbl.f1)::text))
Node/s: data_node_1
Remote query: SELECT pg_catalog.string_agg_finalfn(string_agg(DISTINCT (f1)::text, ','::text ORDER BY (f1)::text)) AS string_agg FROM public.varchar_tbl
(4 rows)
Note the call to string_agg_finalfn in the remote query, which causes the assertion failure.
The plan generated in case of more than one datanodes is as follows which works correctly.
test=# explain verbose select string_agg(distinct f1, ',' order by f1) from varchar_tbl;
QUERY PLAN
--------------------------------------------------------------------------------------------------
Aggregate (cost=2.50..2.51 rows=1 width=20)
Output: string_agg(DISTINCT (varchar_tbl.f1)::text, ','::text ORDER BY (varchar_tbl.f1)::text)
-> Data Node Scan on varchar_tbl "_REMOTE_TABLE_QUERY_" (cost=0.00..0.00 rows=1000 width=20)
Output: varchar_tbl.f1
Node/s: data_node_1, data_node_2
Remote query: SELECT f1 FROM ONLY public.varchar_tbl WHERE true
(6 rows)