Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcu7X-0006yx-09 for pgsql-performance@arkaria.postgresql.org; Fri, 28 Dec 2018 15:32:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gcu7T-00040r-V2 for pgsql-performance@arkaria.postgresql.org; Fri, 28 Dec 2018 15:32:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcu7T-00040k-Fo for pgsql-performance@lists.postgresql.org; Fri, 28 Dec 2018 15:32:15 +0000 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcu7L-00061s-PB for pgsql-performance@postgresql.org; Fri, 28 Dec 2018 15:32:14 +0000 Received: by mail-io1-xd42.google.com with SMTP id a2so4594712iok.7 for ; Fri, 28 Dec 2018 07:32:07 -0800 (PST) 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:content-transfer-encoding:in-reply-to :user-agent; bh=qkqHfaUxuAYwgSvYBvMciIY73mEU6VnsbAKTVHb8ULo=; b=qZmCwECyf5tpZFj6Nb8hsON7eUvX6iXfdBmxmnHCfUdDpfyyvbo7UyF3S6b912UT9h x8YcSC1YuQZPDb2YVl9snkk8yS67PT9BzzqEcqN8LzwzJH5YzmQE6Oqx20WRT4XUdsxS spVvCxkNFoC1Z95YG1mKsW6vlq+dPKM299+QNDhd1cA8xcDEa5EGewmk7r0scyr1wAwg dsNNEUidUtyjaRO3SE1IHiNsXpou1qDhf2Iob7YBP6roTABYvIqpwKODvqBP4xPtZVp+ F0jf2pO7pTzYy1C77QbN9GvCPjVDB8JEmFl55/HjTfE7zg4Oo9KSTUhZNseEur93kBew x0Vg== 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:content-transfer-encoding :in-reply-to:user-agent; bh=qkqHfaUxuAYwgSvYBvMciIY73mEU6VnsbAKTVHb8ULo=; b=h6WxPci9hy/CUdjSNLfO9S9W9apwIAFiPYGXRKF+NJ6SI+yqDLpAk7YgeZY4Jh6Cg3 0Tz9H99U/cjmyj0V8H1M93OtTnzw/b8gdgqAC814KVEcmyscNgBuWHBJO6k/1tY1PAly ATf2fr13hPcSJZ02CCnTQ0CVSFb1nzg7QEJqHx635NskDrJwl4wBvJFWGQjmExID7aRL 1sW/wKasbzjwQUg2W5jGE6MdBnsGkzBEvpycEJZp9NboRoeoPyN7t8+KvXSO+bLtGE3K AiOdzNqcOuehY35of3encrcU1/fgMXaGSFgw/z74f/LvIrnvqpfAS4GKIAVqck5h+LTB dTIQ== X-Gm-Message-State: AJcUukeuuMGjSHvBi8GXZtpbSTW7MAOzAflSqDsnezbmplllt1aZIOnx E01I7JIx7gFmhoBoLhTEuvgerQ== X-Google-Smtp-Source: ALg8bN5Qj0fVLAdYutOsPwz86VQRndmcGXYM0oxUpN/8aTqHEnsRnw4a03vjZWBJJlL7bj6VuzfGfA== X-Received: by 2002:a5e:a513:: with SMTP id 19mr19839198iog.151.1546011126738; Fri, 28 Dec 2018 07:32:06 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id g12sm18753839iok.38.2018.12.28.07.32.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Dec 2018 07:32:06 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 71B588054BB; Fri, 28 Dec 2018 09:32:05 -0600 (CST) Date: Fri, 28 Dec 2018 09:32:05 -0600 From: Justin Pryzby To: =?utf-8?B?bmVzbGnFn2Fo?= demirci Cc: pgsql-performance@postgresql.org Subject: Re: Query Performance Issue Message-ID: <20181228153205.GM30382@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Dec 27, 2018 at 10:25:47PM +0300, neslişah demirci wrote: > Have this explain analyze output : > > *https://explain.depesz.com/s/Pra8a * Row counts are being badly underestimated leading to nested loop joins: |Index Scan using product_content_recommendation_main2_recommended_content_id_idx on product_content_recommendation_main2 prm (cost=0.57..2,031.03 ROWS=345 width=8) (actual time=0.098..68.314 ROWS=3,347 loops=1) |Index Cond: (recommended_content_id = 3371132) |Filter: (version = 1) Apparently, recommended_content_id and version aren't independent condition, but postgres thinks they are. Would you send statistics about those tables ? MCVs, ndistinct, etc. https://wiki.postgresql.org/wiki/Slow_Query_Questions#Statistics:_n_distinct.2C_MCV.2C_histogram I think the solution is to upgrade (at least) to PG10 and CREATE STATISTICS (dependencies). https://www.postgresql.org/docs/10/catalog-pg-statistic-ext.html https://www.postgresql.org/docs/10/sql-createstatistics.html https://www.postgresql.org/docs/10/planner-stats.html#PLANNER-STATS-EXTENDED https://www.postgresql.org/docs/10/multivariate-statistics-examples.html Justin