Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUzYK-0005h7-0x for pgsql-performance@arkaria.postgresql.org; Wed, 13 Nov 2019 20:47:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iUzYH-0002aa-9g for pgsql-performance@arkaria.postgresql.org; Wed, 13 Nov 2019 20:47:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUzYH-0002aT-0i for pgsql-performance@lists.postgresql.org; Wed, 13 Nov 2019 20:47:45 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUzYD-0001ya-M9 for pgsql-performance@lists.postgresql.org; Wed, 13 Nov 2019 20:47:44 +0000 Received: by mail-wr1-x442.google.com with SMTP id z10so3939045wrs.12 for ; Wed, 13 Nov 2019 12:47:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=CSbOCTAh9werGOb0DiFHGStTTcaK7p4u4bZJ4e7c2mA=; b=oJ+W+3ofOC9GzWALhPoqKB6Qz+GP4neUcRSykOQyj6mZ9eFU+T54YMErXvvvsY/ndS 4gSWT8VplDWPvI49P05wcFdMefOhI78ak2ptfbNJ3v1d1NSOf/3cGzklSDQp1f0AdRqu UvV8zLTrH2sk3DjB+8AXe3vJrY8//PQxpDDCbu0JtTfXZo9AnvAKZwcEp8mvl8WQvQeV 0aWtg5Pv2641HI9juOp9AtzWm9grHijEVZfuTR695GZwkoZwADySpN/SoeVWCipJiIU8 eYywUJPphSkVUg2Ebh81MIV8EvQExGXqtX9itmNqNtjd9U7kO51NrnhJhcVYzXsEOJF2 zriQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=CSbOCTAh9werGOb0DiFHGStTTcaK7p4u4bZJ4e7c2mA=; b=oOizgPGmsU3UV1nTLQf29e738MZZ2GZLYafyYYRYg+MQAjici0ffC+eljU5WGe/2oS BHsHPsZ1MhrpyFGYCQRzTswhuzfi9XNFhfVcJw04P7/EmwDZ4khLOBNzwGDxR/t3nqIK dHhSqyvsyJFsFf5E0cJbnbOJWQq8DJl+92i5GyUhvKcN2b7yIODGskhtg5xhxdA8YOld CU7+5jU1d/geHsfnEf342+mLgRw280FeWcDFDZoyp2A4X3gFVmlwJHwBRJw98oV4Coqk u7phls4P0fRT9U9G0I9fKpO/24/ou3wmH/HeEg3kXKqjD6cHYQRUwtZRq2abTg6mzIwR PA0A== X-Gm-Message-State: APjAAAXi9fy2VrcmtYh9tpJfgysBMn3ssm/l0yAmcVCbnFU+HgQDWLoO kXkJRFaYeNOgSv/wQucPs+eosqR8g9M= X-Google-Smtp-Source: APXvYqwxYsHwmmec0xqw7UKs9T/ijESl6iXXzB5lzVB3G1lFMzljBDNCHBvDkO+jUK6rdKm2BET0ZA== X-Received: by 2002:a05:6000:18c:: with SMTP id p12mr4590588wrx.154.1573678060116; Wed, 13 Nov 2019 12:47:40 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id b17sm4345121wru.36.2019.11.13.12.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 12:47:39 -0800 (PST) Date: Wed, 13 Nov 2019 21:47:37 +0100 From: Tomas Vondra To: =?utf-8?B?THXDrXM=?= Roberto Weck Cc: pgsql-performance@lists.postgresql.org Subject: Re: Parallel Query Message-ID: <20191113204737.l6uny3qdwl6a4u7m@development> References: <732b7303-8b60-2f33-7f00-3b0cd70a7c5b@siscobra.com.br> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <732b7303-8b60-2f33-7f00-3b0cd70a7c5b@siscobra.com.br> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Nov 13, 2019 at 05:16:44PM -0300, Luís Roberto Weck wrote: >Hi! > >Is there a reason query 3 can't use parallel workers? Using q1 and q2 >they seem very similar but can use up to 4 workers to run faster: > >q1: https://pastebin.com/ufkbSmfB >q2: https://pastebin.com/Yt32zRNX >q3: https://pastebin.com/dqh7yKPb > >The sort node on q3 takes almost 12 seconds, making the query run on >68  if I had set enough work_mem to make it all in memory. > Most likely because it'd be actually slower. The trouble is the aggregation does not actually reduce the cardinality, or at least the planner does not expect that - the Sort and GroupAggregate are expected to produce 3454539 rows. The last step of the aggregation has to receive and merge data from all workers, which is not exactly free, and if there is no reduction of cardinality it's likely cheaper to just do everything in a single process serially. How does the explain analyze output look like without the HAVING clause? Try setting parallel_setup_cost and parallel_tuple_cost to 0. That might trigger parallel query. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services