Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLjOm-0003J0-Qb for pgsql-performance@arkaria.postgresql.org; Thu, 24 May 2018 06:06:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fLjOi-00035Q-BH for pgsql-performance@arkaria.postgresql.org; Thu, 24 May 2018 06:06:48 +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 1fLjOi-00035G-42 for pgsql-performance@lists.postgresql.org; Thu, 24 May 2018 06:06:48 +0000 Received: from mail-it0-x235.google.com ([2607:f8b0:4001:c0b::235]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fLjOd-0004nj-ST for pgsql-performance@postgresql.org; Thu, 24 May 2018 06:06:47 +0000 Received: by mail-it0-x235.google.com with SMTP id q4-v6so925231ite.3 for ; Wed, 23 May 2018 23:06:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=O86WSBNDePeKd4skXdN5tPszCFdQNmQyIVyOndrrTwQ=; b=Fh8h5m9d2wYs0pTzZDC0aF+03jTOsd1ohuUYAqPct3J08pL0HFNAwpn6m+xxGqImvo xPa98nvM8IvynoALIgp+Umh7sqLsrgPx226Gye/Tsa2A6+l8nWcGhF+VXH01QQtYyCXx moqCsXFB7g1l1bI4t6gOFTSnCLTw1Pzphl3CPYh30f381R2WgImxPy1xmG71c0SjTTVz Mw+akLjFW0X0wXPLV5ydEKJhuGY2o8K+IEu/XYL2Ua/4XJwRlaEA2a9FRX7ffbCa+UzS +PuJ+wuMIjNuxlaF6bIGyHp4Fj2bcy0gL2fs+7bkeEgUpTKp04VnLmwPKtzvDLRSqnS0 HUbA== 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:in-reply-to:user-agent; bh=O86WSBNDePeKd4skXdN5tPszCFdQNmQyIVyOndrrTwQ=; b=j2z9yK3sHadDub+tl8t2fhp+8qEo+9An1AOj4mDI5XydLf+RAKNn/BpIZK0Uaqo+LZ 6ANHzDiVIAEeobYn939AmODUs1bgSezHiIbT0Ak9YNgR6kr2FerMMrI+tu3ndh4OeRVa X3fJ7QKLr/8Texy7SZ92rSumyS7UMKtrzxJFj/5zMQeFjm6MHuwB4IZbf7UgJd8Pqoib 4u1JnvKf65Je3PCoIdVmOZC7eJetlB2+6JQLSUmGE9rl8GTfmGcvmuxLnLI+DrCQoqKh wliL2J9/95SaTTahgRVYd27ZNFe0FkpSiQuUOWBWNKj1AJnwGve2dI8/4qfknaWtJoZ1 nvnA== X-Gm-Message-State: ALKqPweXyP0+ykw/zbu8kPx7s/uk06Yc3Et07yUhIlcCyMB4077ftP6m QpS0G3WcfotrvEnapEs2BvDjyg== X-Google-Smtp-Source: AB8JxZqFppdwEj6cBf50gv+DWqynh6O5ZTtwKtPyaF7PQklrRJRN8nQig7sU9lLLPNwV+3bPFZW2CA== X-Received: by 2002:a24:5091:: with SMTP id m139-v6mr7904746itb.50.1527142001664; Wed, 23 May 2018 23:06:41 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id r67-v6sm11023726iod.27.2018.05.23.23.06.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 23:06:41 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 2A7928019C8; Thu, 24 May 2018 01:06:40 -0500 (CDT) Date: Thu, 24 May 2018 01:06:40 -0500 From: Justin Pryzby To: pavan95 Cc: pgsql-performance@postgresql.org Subject: Re: Help me in reducing the CPU cost for the high cost query below, as it is hitting production seriously!! Message-ID: <20180524060639.GQ30060@telsasoft.com> References: <1526985179479-0.post@n3.nabble.com> <20180522103906.GF30060@telsasoft.com> <1526986304012-0.post@n3.nabble.com> <20180522182307.GA9330@telsasoft.com> <1527058866609-0.post@n3.nabble.com> <20180523134322.GK30060@telsasoft.com> <1527084198212-0.post@n3.nabble.com> <20180523200132.GL30060@telsasoft.com> <1527139242201-0.post@n3.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1527139242201-0.post@n3.nabble.com> User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, May 23, 2018 at 10:20:42PM -0700, pavan95 wrote: > Hi Justin, > > Please find the below explain plan link. > > Link: https://explain.depesz.com/s/owE That's explain analyze but explain(analyze,buffers) is better. Is this on a completely different server than the previous plans ? This rowcount misestimate appears to be a significant part of the problem: Merge Join (cost=228.77..992.11 ROWS=20 width=22) (actual time=4.353..12.439 ROWS=343 loops=1) Merge Cond: (history_2.timesheet_id = header_2.id) You could look at the available stats for that table's column in pg_stats. Is there an "most common values" list? Maybe you need to ALTER TABLE .. SET STATISTICS 999 (or some increased value) and re-analyze ? You can see these are also taking large component of the query time: Bitmap Index Scan on ts_detail_release_no_idx (cost=0.00..33.86 rows=1,259 width=0) (actual time=0.304..0.304 rows=1,331 LOOPS=327) Index Cond: ((release_no)::text = 'paid_time_off'::text) ... Bitmap Index Scan on ts_detail_release_no_idx (cost=0.00..33.86 rows=1,259 width=0) (actual time=0.304..0.304 rows=1,331 LOOPS=343) Index Cond: ((release_no)::text = 'paid_time_off'::text) I wonder whether it would help to CREATE INDEX ON tms_timesheet_details(timesheet_header_id) WHERE ((release_no)::text = 'paid_time_off'::text); In addition to the other settings I asked about, it might be interesting to SHOW effective_io_concurrency; You're at the point where I can't reasonably contribute much more. Justin