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 1eyizS-0005Ie-UB for pgsql-general@arkaria.postgresql.org; Wed, 21 Mar 2018 19:01:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eyizR-0004IL-HG for pgsql-general@arkaria.postgresql.org; Wed, 21 Mar 2018 19:01:37 +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 1eyizR-0004IC-3q for pgsql-general@lists.postgresql.org; Wed, 21 Mar 2018 19:01:37 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eyizM-0005Va-Nf for pgsql-general@lists.postgresql.org; Wed, 21 Mar 2018 19:01:36 +0000 Received: by mail-wm0-x241.google.com with SMTP id 139so11833609wmn.2 for ; Wed, 21 Mar 2018 12:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=LAHjU27opN4hBYy8BMfwlFhDcj2NfpflKmxCi9xRlDE=; b=rIzePcv9cKn1XI0Sx2WKWLtdb6IsQ9bfNSf1GMh6dPqp5bY2qc9rObkzvqlwvIYvzW gOMpWMGSvGi1Ow3aiz9N0p5/D4U6KWKIR9M/ASELTnNuXg040xvxFzvtz+S13DARF7Bg 7Ta6vCrqKkBBt5BvAmMxXXkKTp0ngWq1GxwlUAKO0rVKb3gBefewd9LahRW3St39awB+ wL20g8x+H0C1QFYAx7+6JGKd+Ld5FeevjE0WNU6UXaHPB8fxrJb9oFVPmwD3PV2g82wi tPR0dzrcFPZaRQ5Gp9iMLvN1bOGiwnn5o7evWVqI4GPwIG3FerDmOmP6ZbJgUByi9/mj KBpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=LAHjU27opN4hBYy8BMfwlFhDcj2NfpflKmxCi9xRlDE=; b=np5e/3Ma8ec9QXkBjTprA65WZopPyHzTiLx1c/hdYqs7UUwpYl0fbOyuK7eqdwUujr R4Dl6O1OCY6uLiN0eJ1oXiGEpjXUxn6UhHH0TIZon+h3jMWjL+wr/Lca8Rn5kdJ5y4Wv GOn2ho61O3dcHxxA9xvFD0fPBNjltZWLJTv3lwUnyIc9fsaCWFKVPgANWqWtKPksat52 KkcUnL6VpfMZZNq0umCQJjVg0PT0V4efCtHDSOgG5d0GvqzeNzUnayGTLiSAKBf6Bd+N McMdKONRIWyRunvVkpz9naIpGiumFlnyf4aJxctRofOuNjNR+ZLPGoBlAjBDWpPsWJbw TrJw== X-Gm-Message-State: AElRT7HD3r752fHihD8T1kdyh4TzGNV2HgF77K++Vj4pD8MjXFgZgAOB 6HZVpEwJkCNuvJVeZPSF4hqsb9xN/XR+ml90WMl23jWNEmfsTl7M8qTecQhAgjVv/99lebEE17J bo9HyDSnFOQ8QbRWf36fBcK8p6CrZRSHYbokERs/m1BscTu1c2QqImsYRcFSZa3iX5l5Ov9aQcQ A8eESeRZy70ZKMSTZZ X-Google-Smtp-Source: AIpwx4/iHncooPN4GuAk/EM16Rq1y2wCBRRFUlgLv5Pp+YfYNStRdYb91u86oJ+XtOF3vlKI3bZ/Nw== X-Received: by 10.28.52.83 with SMTP id b80mr623622wma.90.1521658890122; Wed, 21 Mar 2018 12:01:30 -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 x128sm3375769wmg.20.2018.03.21.12.01.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Mar 2018 12:01:28 -0700 (PDT) Subject: Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on To: Alessandro Aste , pgsql-general@lists.postgresql.org References: From: Tomas Vondra Message-ID: Date: Wed, 21 Mar 2018 20:01:26 +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 05:09 PM, Alessandro Aste wrote: > Hi there, we are using postgresql 10.3 and we're facing an issue with a > query. The query (full query below)  completes only  when:  > > 1 - LIMIT 10 is removed > or > 2 -  show max_parallel_workers_per_gather  is set to 0, so parallel > processing is disabled. > > With  max_parallel_workers_per_gather   set to the default value (8) I'm > not even able to get the query plan. > > Notes:  > > * We're experiencing the issue in any server of ours but I've > reproduced the issue in a fresh restored database with full > vacuum/reindex of the tables. > * We didn't touch any parameter concering the parallel processing, > we're running the defaults:  > > > cmdstaging=# show max_parallel_workers_per_gather ; >  max_parallel_workers_per_gather > --------------------------------- >  8 > (1 row) > > cmdstaging=# show max_worker_processes ; >  max_worker_processes > ---------------------- >  8 > (1 row) > > cmdstaging=# show max_parallel_workers; >  max_parallel_workers > ---------------------- >  8 > (1 row) > > > > > The query completes only omitting the LIMIT clause or when I disable > parallel processing:  > >  id   | vendor_id | gaa |   pop_name    | pop_status | pop_location | > pop_provider_id | pop_provider |     pop_street      | pop_city | pop > _postal_code | pop_state | pop_country | pop_country_id > --------+-----------+-----+---------------+------------+--------------+-----------------+--------------+---------------------+----------+---- > -------------+-----------+-------------+---------------- >  684807 |     12346 |     | GTT/POP/LON1T | Active     | LON1T        |  >          12288 | Telehouse UK | 14 Coriander Avenue | London   | E14 >  2AA         |           | GB          |            219 > (1 row) > > Time: 4374.759 ms (00:04.375) > cmdstaging=# show max_parallel_workers_per_gather ; >  max_parallel_workers_per_gather > --------------------------------- >  0 > (1 row) > > Time: 0.097 ms > > > Otherwise it just keep running for forever.  > When you say "running forever" is it actually using CPU, or does it get stuck on something? > > This is the full query:  > > > SELECT * FROM ( > SELECT > seg.circuit_id AS id, > vendor_gtt_pop.vendor_id, > CASE WHEN vendor_gtt_pop.push_to_gaa = 1 THEN 'Y' END as gaa, > pop.gii_circuitid AS pop_name, > cst.label AS pop_status, > seg.a_company_name AS pop_location, > seg.vendor_id AS pop_provider_id, > seg.vendor_name AS pop_provider, > cs.address1 AS pop_street, > cs.city AS pop_city, > cs.postal_code AS pop_postal_code, > cs.state AS pop_state, > csc.code AS pop_country, > cs.country_id AS pop_country_id > FROM ( > SELECT c.gii_circuitid, max(so.id ) AS service_order_id > FROM service_order so > join circuit c on c.product_id=so.product_id > join master_service_order mso on mso.id =so.master_service_order_id > WHERE NOT (so.ordertype_id = 2 AND so.status <> 999) AND > NOT (so.ordertype_id = 3 AND so.status <> 999) AND > c.status >= 20 AND > c.status not in (160,999) AND > mso.client_id=11615 AND > c.service_description=28 AND > c.status!=160 > GROUP BY c.gii_circuitid > ) pop > JOIN service_order so ON so.id = pop.service_order_id > left JOIN client_site cs on cs.id =so.a_site_id > left JOIN country csc on csc.id =cs.country_id > JOIN circuit c ON so.product_id=c.product_id > JOIN circuit_status cst ON cst.id =c.status > JOIN ( > SELECT c.id AS circuit_id, sg.id AS segment_id, c.pop_support_vendor_id AS vendor_id, > v.name AS vendor_name, sg.a_company_name > FROM segment sg > JOIN circuit_layout cl ON cl.segment_id = sg.id AND cl.ordinal = 1 > JOIN circuit c ON c.id = cl.circuit_id > JOIN vendor v ON v.id = c.pop_support_vendor_id > ) seg ON seg.circuit_id = c.id > JOIN vendor_gtt_pop on vendor_gtt_pop.gtt_pop_id = seg.circuit_id > ) foo where vendor_id = 12346 AND (1=1) ORDER BY pop_name ASC,id LIMIT 10 > > > > Execution plan with  max_parallel_workers_per_gather =0 ,  > max_parallel_workers_per_gather =8 and no LIMIT clause :  > > We really need to see the execution plan that causes issues, i.e. max_parallel_workers_per_gather=8 with LIMIT clause. Plain explain (without analyze), at least. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services