I got a problem with a PL/PGsql stored procedure outputting an xml.Basically, the function, output as xml the result of a query.Query is fast enough but i observed the xmlconcat became slower and slower when the set of result became too big.This is a simplified content of the function.\[code\]CREATE OR REPLACE FUNCTION test_function (v_limit int) RETURNS xml AS$BODY$DECLARE v_rec record; v_xml xml; v_query text;BEGIN v_query := 'SELECT * FROM test_table LIMIT ' || v_limit; FOR v_rec IN EXECUTE v_query LOOP v_xml := xmlconcat(v_xml, xmlelement(name content, v_rec.content) ); END LOOP; RETURN v_xml ;END$BODY$ LANGUAGE 'plpgsql' SECURITY DEFINER ;\[/code\]The table test_table contains just a field named content of type text. The average length of content is 100 chars.The problem appears with a large amount of records to concat.Look at this explain analyzes. The time needed increase exponentially.\[code\]db=# explain analyze select test_function(500); QUERY PLAN-------------------------------------------------------------------------------------- Result (cost=0.00..0.26 rows=1 width=0) (actual time=42.890..42.893 rows=1 loops=1) Total runtime: 42.909 ms(2 rows)db=# explain analyze select test_function(1000); QUERY PLAN---------------------------------------------------------------------------------------- Result (cost=0.00..0.26 rows=1 width=0) (actual time=109.153..109.159 rows=1 loops=1) Total runtime: 109.178 ms(2 rows)db=# explain analyze select test_function(10000); QUERY PLAN------------------------------------------------------------------------------------------ Result (cost=0.00..0.26 rows=1 width=0) (actual time=8304.257..8304.277 rows=1 loops=1) Total runtime: 8304.298 ms(2 rows)\[/code\]The cost of the single query, without xmlconcat, is just 36ms for 10000 records.Any suggestion about improve the efficiency of xmlconcat?