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 1eypas-000362-VR for pgsql-general@arkaria.postgresql.org; Thu, 22 Mar 2018 02:04:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eypar-00073L-T3 for pgsql-general@arkaria.postgresql.org; Thu, 22 Mar 2018 02:04:41 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1eypar-00073C-Ke for pgsql-general@lists.postgresql.org; Thu, 22 Mar 2018 02:04:41 +0000 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eypao-0007Xj-DF for pgsql-general@lists.postgresql.org; Thu, 22 Mar 2018 02:04:41 +0000 Received: by mail-wr0-x232.google.com with SMTP id h2so7094684wre.12 for ; Wed, 21 Mar 2018 19:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=sfZP5dfgsvpXTb4aK2Rgu97yFCJB9gcjQ22t9XR/fIU=; b=egS3hiADhgDv98q/+iM6zBZRIHckPdT9Lo+Q92UNhmV9qrxuR7CoVSJHMKx9N1hOR9 7nk8ig8N8MgApZm1iCAbhSFjRBa7YriPiu97Amie5XkpkA1MO2N3Fch7QLswc+c6V1pB lHGYUpHfk9DgXv68HD11THgaD5t9w+2NXdceBePPe8ekxw5PVKoMb4mH2nNRgJlSdfKY sOxfVTAsHbWO6ETKDiiYPbH7Mb+IkVUrdfEYl/51S7HJOuR41cHmvEgXBBZ7bWsU0VCq 62c2Q4AaaDK17Mn/5mtPFbcypfsXyxFWRmgIVKbBTbJ2p7BaUOGwFqFvzkzhpcGXQ10q I6eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=sfZP5dfgsvpXTb4aK2Rgu97yFCJB9gcjQ22t9XR/fIU=; b=IUkVfj6CwY7U/1I0IHgIeUq+W7jcPat4Me9L/XMX/YGLHitQHPET3H2I5ymE+zSeGn C3X1kDpKMMUl41OjheLCx0NPHTtSuPgVlVMkyQd66ArJaXnI34mtg459ha7FSsUHxEkm zI/LB40QmPfiKnHSJZwCzqjz36ve1AKBaJD9T5Uajq39zE+/kI0HnXM28uY9nOz4nLcO fZd+I3A2soNnX/Tk7n1FXl53ZFAG1L8krjKL/rUj5AG01RUgo0oNnTAMAJM11Kc4ETiv z/oaQh0P3RDy1n/t0CsDJhzxal4V6xf2FErQQN7TLzZf8Thug25xYTDi/K+oJ566MxtH HiTw== X-Gm-Message-State: AElRT7EJ26qQKYbRkPcpKHsNBWms4465ebYKLcBBfED0ZKU+nX/h7w2P vC9F2DcsBJrLH9W6Gy4l9PC46dffphPB5A5/y/I3Uo78L/7NY6dwe6ugdFnQwL1b5BdWbo/ynPG s9LmsNL2wohh3OfOSMmhAW7fDZWei5IbfhhAkRdJQnsBFGJSLdkmsw7PZixokwgbQ3peQV8ndbE 5CgcMiXPbXpWOB+389 X-Google-Smtp-Source: AG47ELvjrfWDZGznrTc5o1cKQLIHePI2iuGUO1Xy5sUiYvVjhxMdw1B5PXVf1zN979Y0CJoV7LOFnQ== X-Received: by 10.223.134.47 with SMTP id 44mr10529243wrv.114.1521684275570; Wed, 21 Mar 2018 19:04:35 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id d4sm6089764wmh.42.2018.03.21.19.04.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Mar 2018 19:04:34 -0700 (PDT) Subject: Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on To: Alessandro Aste Cc: pgsql-general@lists.postgresql.org References: From: Tomas Vondra Message-ID: Date: Thu, 22 Mar 2018 03:04:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/21/2018 08:44 PM, Alessandro Aste wrote: > Thanks for your reply Tomas.  The query just got stuck for forever.  I > observed no CPU spikes, it is currently running and I see 89 of the CPU > idle. I'm using a relative powerfull machine (120 GB ram, 56 CPU).   > That doesn't really answer the question, I'm afraid. I suppose "89 of CPU" means that 89% idle in total, but 11% with 56 CPUs still means about 6 cores 100% busy. But maybe you meant something else? Is there something else running on the machine? If you look at "top" are the processes (the one you're connected to and the parallel workers) doing something on the CPU? > > Plain analyze as requested. :  > I don't see anything obviously broken with the query plan, and it's difficult to compare with the other plans because they are quite different. But there's one part of the plan interesting: Limit (cost=253523.56..253523.57 rows=1 width=176) -> Sort (cost=253523.56..253523.57 rows=1 width=176) Sort Key: c_2.gii_circuitid, c_1.id -> Nested Loop (cost=33190.89..253523.55 rows=1 width=176) Join Filter: (c_1.id = c.id) -> Nested Loop (cost=31724.87..31736.29 rows=1 ...) ... -> Gather (cost=1466.02..221787.23 rows=3 width=75) Workers Planned: 5 -> Hash Join (cost=466.02..220786.93 rows=1 ...) ... That is, there's a Gather on the inner side of a Nested Loop. I wonder if that might cause issues in case of under-estimate (in which case we'd be restarting the Gather many times) ... BTW one of the plans you sent earlier is incomplete, because it ends like this: -> Nested Loop (cost=42469.41..42480.82 rows=1 width=85) (...) Join Filter: (c.status = cst.id) Time: 3016.688 ms (00:03.017) That is, it's missing the part below the join. That being said, I'm not sure what's the issue here. Can you prepare a self-contained test case that we might use to reproduce the issue? For example by dumping the relevant part of the tables? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services