Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pnh9y-0007EI-7q for pgsql-bugs@arkaria.postgresql.org; Sat, 15 Apr 2023 14:45:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pnh9x-00022P-3N for pgsql-bugs@arkaria.postgresql.org; Sat, 15 Apr 2023 14:45:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pnh9w-00022F-RO for pgsql-bugs@lists.postgresql.org; Sat, 15 Apr 2023 14:45:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pnh9u-0033wz-3K for pgsql-bugs@lists.postgresql.org; Sat, 15 Apr 2023 14:45:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 33FEjgr21701649; Sat, 15 Apr 2023 10:45:43 -0400 From: Tom Lane To: sf_postgresql@informationsoftworks.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17896: xmlagg exponentially slower than string_agg equivalent In-reply-to: <17896-f4bf54f99b6a3089@postgresql.org> References: <17896-f4bf54f99b6a3089@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Fri, 14 Apr 2023 15:12:59 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1701647.1681569942.1@sss.pgh.pa.us> Date: Sat, 15 Apr 2023 10:45:42 -0400 Message-ID: <1701648.1681569942@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > Also, while string_agg() seems to scale linearly (O(n)), xmlagg() seems to > scale somewhat steeper (O(n^2)?). Yeah, string_agg was optimized long ago to avoid repeat data copying, but xmlagg hasn't been. It looks like xmlagg doesn't make any direct use of libxml, which suggests that this wouldn't be terribly hard to fix if somebody were motivated to try. The xml type is a bit of a development backwater though ... regards, tom lane