Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f3deB-0002lf-HD for pgsql-general@arkaria.postgresql.org; Wed, 04 Apr 2018 08:19:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f3deA-0001DY-Bx for pgsql-general@arkaria.postgresql.org; Wed, 04 Apr 2018 08:19:58 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f3S7Z-000125-9K for pgsql-general@lists.postgresql.org; Tue, 03 Apr 2018 20:01:33 +0000 Received: from tme3c.com ([81.210.106.69]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f3S7V-00008h-8a for pgsql-general@lists.postgresql.org; Tue, 03 Apr 2018 20:01:30 +0000 To: pgsql-general@lists.postgresql.org From: Artur Formella Organization: TME Subject: Concurrent CTE Message-ID: Date: Tue, 3 Apr 2018 22:01:20 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-MailScanner-ID: B3B433292002.A7832 X-MailScanner: Found to be clean X-MailScanner-From: a.formella@tme3c.com X-Spam-Status: No List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello! We have a lot of big CTE (~40 statements, ~1000 lines) for very dynamic OLTP content and avg response time 50-300ms. Our setup has 96 threads (Intel Xeon Gold 6128), 256 GB RAM and 12 SSD (3 tablespaces). DB size < RAM. Simplifying the problem: WITH aa as (   SELECT * FROM table1 ), bb (   SELECT * FROM table2 ), cc (   SELECT * FROM table3 ), dd (   SELECT * FROM aa,bb ), ee (   SELECT * FROM aa,bb,cc ), ff (   SELECT * FROM ee,dd ), gg (   SELECT * FROM table4 ), hh (   SELECT * FROM aa ) SELECT * FROM gg,hh,ff /* primary statement */ Execution now: time--> Thread1: aa | bb | cc | dd | ee | ff | gg | hh | primary And the question: is it possible to achieve more concurrent execution plan to reduce the response time? For example: Thread1: aa | dd | ff | primary Thread2: bb | ee | gg Thread3: cc | -- | hh Table1, table2 and table3 are located on separate tablespaces and are independent. Partial results (aa,bb,cc,dd,ee) are quite big and slow (full text search, arrays, custom collations, function scans...). We consider resigning from the CTE and rewrite to RX Java but we are afraid of downloading partial results and sending it back with WHERE IN(...). Thanks! Artur Formella