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 1gIZv7-00040d-4n for pgsql-performance@arkaria.postgresql.org; Fri, 02 Nov 2018 13:55:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gIZv5-0002tK-CE for pgsql-performance@arkaria.postgresql.org; Fri, 02 Nov 2018 13:55:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gIZv5-0002t2-10 for pgsql-performance@lists.postgresql.org; Fri, 02 Nov 2018 13:55:27 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gIZv1-0005hq-JD for pgsql-performance@lists.postgresql.org; Fri, 02 Nov 2018 13:55:25 +0000 Received: by mail-wm1-x32e.google.com with SMTP id s10-v6so2061955wmc.5 for ; Fri, 02 Nov 2018 06:55:23 -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=UgOK4yLgITQRKtpqB+UjZbs3j51VmhuFaWfR68hrG3U=; b=2TysxK/SoJwvziN9co+QxAWjh1n3cuo4z+yXb/NgTVJ7RC3rZLltUhedDM0Bbmy9RL NkAB4F0cp9lDAVOYsPfLEtiV9UmGAqBpSC3DKhAuQWIKTe0ZgUDElXYML/RAGOxmvYEK jodk8X4MJC7MIZceTEFQ5RYJDrHqlGjkHd0UnT51FAUHnUuvNyQ67VHkiX/IAfdy5mh8 WWINaxBQyr4Dl1+lO+ayY9jvjZ/21igNYDPHXJ2naD0AyFR/qOCM8RWXtD72RMMgkPtD GKYViZkTUsB7aCpC9nfTcEcG7+OjWIvNORywvfgbVPvI/AKVxjzMCaxQ6kIyYPEq7WRW u66Q== 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=UgOK4yLgITQRKtpqB+UjZbs3j51VmhuFaWfR68hrG3U=; b=BRpqZ+r0e2lgajsB+IefstMowLhOb0Q1XwTNxEguKVtAXvUy8r+UDcdSartbB9D/BI 92eTsd4f5ih6J774qRCCRLn0ybCXKyYzmVixUB8Xvt1kk+wkKmuUSQvSBkRX4qSd7vnk onWvzdgjKwIUfwQlCKMIYjlhWywVvwCYrYK6c682nWSIY7/pHatV9CatYejmCUczoYNK pXnjU5G5SRB3iuzbMt/B+QInsISR+P73rH/o4J85Wd7Xz9GSsooPYu4YQwrgjRc3G89b yAgIqM8cW05dr2W3EOK7BpuGOfbgEDNyKlmT6EWbSxZucdIDb/yoi/4pEz1dgEUzRhmw IQkw== X-Gm-Message-State: AGRZ1gLE/TQeyypX7cSVjgzklXdG9Ev0rsxDlQVmW8WoIi5J7e4OOom2 UgwdRDdyPwZjdVXciaWVJY/arKB5I9+YdXXWD08pUxsNwPGvy1H5Gzj1+d2q1j/P1oueg0S+wHl ldn5Ev7RqyfZKzPHju+9WYciU6cyz4tT+/k0ugWp72ppU4LG+lOndwmWDL8erjiaRjCpjr8qC8z cNk0bm4XdlaaEa5k5WBW6jTbE2+Z4= X-Google-Smtp-Source: AJdET5dGVQJWZ6OjrPPB8DkYoFda4l/fzzdJHeC5i37nHCHZ1809wY26J1B8UfbeBb/vaFAVN/QcGg== X-Received: by 2002:a1c:1250:: with SMTP id 77-v6mr56885wms.70.1541166920987; Fri, 02 Nov 2018 06:55:20 -0700 (PDT) Received: from [10.137.2.19] (ip-86-49-245-152.net.upcbroadband.cz. [86.49.245.152]) by smtp.gmail.com with ESMTPSA id e6-v6sm36560239wrc.70.2018.11.02.06.55.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Nov 2018 06:55:20 -0700 (PDT) Subject: Re: Fwd: Query with high planning time compared to execution time To: Richard Lee , pgsql-performance@lists.postgresql.org References: From: Tomas Vondra Message-ID: <8db7abc2-9ddf-858c-e3db-af014cf2ccd9@2ndquadrant.com> Date: Fri, 2 Nov 2018 14:55:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 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 11/02/2018 10:36 AM, Richard Lee wrote: > Hi, > > I'm running a performance test for our application and encountered a > particular query with high planning time compared to the execution. > Please refer to attached explain.out for the explain analyze output. > > Formatted explain: https://explain.depesz.com/s/R834 > > The test was performed with Jmeter sending requests to the database, > query was generated by Hibernate which consists of a 133 table UNION. > Also attached are some diagnostic info (database version, database > settings, table definitions and maintenance related information). > > Due to the extremely large query text, I'm choosing to provide > information via attachments instead of pasting in the email body. > > Below are some additional OS information on the database server: > CPU: 8 > RAM: 24GB > Disk: SSD > OS: CentOS Linux release 7.4.1708 (Core) > > [root@kvrh7os202 ~]# uname -a > Linux kvrh7os202.comptel.com > 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018 x86_64 > x86_64 x86_64 GNU/Linux > [root@kvrh7os202 ~]# > > Things I tried: > 1. Setting random_page_cost = 1.1 and effective_io_concurrency = 200 - > no effect on planning time > 2. Create materialized view for big UNION query - planning time reduced > significantly but not a viable solution > Those changes likely affect the query costing and execution, but the number of plans to consider is probably not going to change much. So planning taking about the same time is kinda expected here. > What are my other options to improve the query planning time? > Can you do a bit of profiling, to determine which part of the query planning process is slow here? That is: 1) make sure you have the debug symbols installed 2) do `perf record` 3) run the benchmark for a while (a minute or so) 4) stop the perf record using Ctrl-C 5) generate a profile using `perf report` and share the result Possibly do the same thing with `perf record -g` to collect call-graph information, but that's probably going way larger. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services