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 1fLBwM-0001DB-0O for pgsql-performance@arkaria.postgresql.org; Tue, 22 May 2018 18:23:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fLBwK-0008RJ-4O for pgsql-performance@arkaria.postgresql.org; Tue, 22 May 2018 18:23:16 +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 1fLBwJ-0008R9-OA for pgsql-performance@lists.postgresql.org; Tue, 22 May 2018 18:23:15 +0000 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fLBwG-0006Us-6n for pgsql-performance@postgresql.org; Tue, 22 May 2018 18:23:15 +0000 Received: by mail-it0-x244.google.com with SMTP id j186-v6so1149505ita.5 for ; Tue, 22 May 2018 11:23:11 -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=7vfMogthbPaZsdPodDaQ6y8Lf4I1519Kl4YB+kjH+Z4=; b=d01ZqTyI8zL3ipPBjyEMI5CpnLSQYM19FrI8FCgOkQCe+h53Zi16S24bSm7/f7P/+a SvPl8aBKDW6fpsxRspMgdshz2IodYFRpQzXSb39i3VbIyPfNDrPpNXyPf3CcsYIFUF0u MjtPPc/DE9RKsC+39t7EYktcPrQCP7kNsKZ/GsT1b0G/XxDVIJAkqyDUbrH6T9/W6nKJ DC8NxEa1fK31kP7JX4dUHVsrubSY03Dye6HlSIdnm+3OAJpbVpHuqroFN+wn2kXxZU3u 4cmeFehabSSYkBryVYu2GEthjoBukGiaIIe3Gkjoion1nhhu7dS8AuMgpSTgTBPhzDAP mW7w== 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=7vfMogthbPaZsdPodDaQ6y8Lf4I1519Kl4YB+kjH+Z4=; b=eJ6OGyNd5bKx+M8KIEekgjDuhBso5n/Ck4tiv/f3307JxJqSgaRBqccQ6mIIw8216O ZzrVDZVRLiGRH6Qd6mxw6PgHhFEvuCPgVPOJRhrvw7LSjU5uSNrnJ7kHAeF0tKDgFf/b UKSCxOOxYgr2vvBjZ/k5szGBAIz6ZDmJnA5QfV3aO2LXz11xQrQXMiPrq6n5xDdZsdk1 dkrtXr5DeL+pp4OClTSWM8q1EbbzU8dUDzuw0Lq3U+Ckmp3uJXmg8LYQizQs511PepUz gFm237TInk18xyCALGvbVgyJtePIeo5yYf72Tu8mRRqcNpvBIfOW5/jbSEzBAy+tsa5j y9RA== X-Gm-Message-State: ALKqPwfuPpTg8DODBZVYlbaHFWfE3/gS7mpPMSaGLw8RgXyPJiPJHQNb trbm24CbPLNUeRR+wj8tNap7BA== X-Google-Smtp-Source: AB8JxZqUL+SqKSmJWehje19mEDk1dlSICxBRNBT5i2YBTCeHz9y9teGmm8haZ1eRf+e7iMiTBcJgDQ== X-Received: by 2002:a24:5213:: with SMTP id d19-v6mr2260372itb.3.1527013389566; Tue, 22 May 2018 11:23:09 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 10-v6sm258131ite.28.2018.05.22.11.23.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 11:23:08 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id E1E1A801727; Tue, 22 May 2018 13:23:07 -0500 (CDT) Date: Tue, 22 May 2018 13:23:07 -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: <20180522182307.GA9330@telsasoft.com> References: <1526883356469-0.post@n3.nabble.com> <1526917693149-0.post@n3.nabble.com> <1526985179479-0.post@n3.nabble.com> <20180522103906.GF30060@telsasoft.com> <1526986304012-0.post@n3.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1526986304012-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 Tue, May 22, 2018 at 03:51:44AM -0700, pavan95 wrote: > Please find the output of explain(analyze,buffers) for the whole query in > the below link. > Seq Scan on res_users users (cost=750.92..1,836.69 rows=249 width=15) (actual time=3.962..17.544 rows=67 loops=1) Not sure but would you try creating an index on: res_users.res_employee_id > Seq Scan on res_users user1 (cost=0.00..58.03 rows=1,303 width=15) (actual time=0.002..0.002 rows=1 loops=1) Also the planner's estimate for table:res_users is off by 1300x..so you should probably vacuum analyze it then recheck. I don't think we know what version postgres you have, but last week's patch releases include a fix which may be relevant (reltuples including dead tuples). Also I don't know the definition of this table or its indices: tms_workflow_history ..but it looks like an additional or modified index or maybe clustering the table on existing index might help (active? is_final_approver?) Or maybe this should be 3 separate indices rather than composite index? Perhaps some of those could be BRIN indices, depending on postgres version Justin