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 1iUcES-0002fx-9i for pgsql-performance@arkaria.postgresql.org; Tue, 12 Nov 2019 19:53:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iUcER-00082M-0J for pgsql-performance@arkaria.postgresql.org; Tue, 12 Nov 2019 19:53:43 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUcEQ-00082F-Jn for pgsql-performance@lists.postgresql.org; Tue, 12 Nov 2019 19:53:42 +0000 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUcEN-0005Le-96 for pgsql-performance@lists.postgresql.org; Tue, 12 Nov 2019 19:53:41 +0000 Received: by mail-yb1-xb42.google.com with SMTP id g38so8098323ybe.11 for ; Tue, 12 Nov 2019 11:53:38 -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:in-reply-to:user-agent; bh=oci/BS9I3fn+D1xaJBfFGxUjb8s2RLVFCB+9lb968mg=; b=S8DhSdwaGuaLEIkqBDXjgZ7HWr7oTIvXgkMdBCw7FgCzyBXN8GAM6HU9od56slmgG6 vmMEkuqlZBc+ZAeXRwkrHXqOVoEOUqY+AfQOTrmKy8Z/jUb7F3u2p4Io7EbgVtwtGsV7 zJGE5JNg1dp1A33RYrBDKRsvA+1Mos5L2kB1bGO0sczmSCoQSKOCqVmDyVFhByzMmDGU OZwYroVXJdAZFQhGwGaiEyuz37S3ZAHTx3jzQmJu0x7aiwIQWe/eVLPJfV5zNvaSct+4 zQkjDnYkXMDY3FjTlW5ZOkSc5xF9DsNT3I5kIm6ww5P/mtddP/C4SKkbB0skhdcJQixN nqzQ== 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=oci/BS9I3fn+D1xaJBfFGxUjb8s2RLVFCB+9lb968mg=; b=CUwAJdIb4jOzq8m5IAg003YyFtfXK0rBm+FdoMXuxWNj0csfbnhowKTXMtY1/x02hj 8stt4LrIMkDp9cWB5nBeOz0gULf/Quk4l2XcAG6vcEDEFylDScAu/S7MOQWVmz1cPyTQ OFsEWgoFbFLLaXG64DURSnKD/LuQ8Rt87Fsxe+G1IZxpjAVooKF52CfoRA30BXoiddoq 3RM/JpuuWDg7vqiNlnzKpQcy0G7xjayUObH9oyJebr+BfjLIC9MbWLKkZUGchEc5nvMb YWc4CrzoAzePISMnk4Unz8/FfDNNrwVwA3HyOXtF73eD9cdIWuMmHExovdLewphR5/X8 inMw== X-Gm-Message-State: APjAAAUp4O1WBRD+wZBWaI622Bd/02rSP0phpL6EkBzM3X+xal/d9eAb PjeRqwD5Ie4XcaKkT6vZi77gZGhgVfw= X-Google-Smtp-Source: APXvYqxOckopk2qWmwYIGd/QQ3vRkZTjWxtq126LEEHMUWMvZLIAFjYe+YZlm40BSNJZVU5oOfRaJw== X-Received: by 2002:a25:4b85:: with SMTP id y127mr15722608yba.238.1573588417398; Tue, 12 Nov 2019 11:53:37 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id b204sm11033966ywe.106.2019.11.12.11.53.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Nov 2019 11:53:36 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id A4ACF800AA0; Tue, 12 Nov 2019 13:53:34 -0600 (CST) Date: Tue, 12 Nov 2019 13:53:34 -0600 From: Justin Pryzby To: Michael Lewis Cc: Marco Colli , pgsql-performance@lists.postgresql.org Subject: Re: Slow "not in array" operation Message-ID: <20191112195334.GP2923@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Nov 12, 2019 at 12:20:10PM -0700, Michael Lewis wrote: > It is very interesting to me that the optimizer chose a parallel sequential > scan rather than an index scan on either of your indexes that start > with project_id that also reference trashed_at. Maybe because of low correlation on any of those columns? https://wiki.postgresql.org/wiki/Slow_Query_Questions#Statistics:_n_distinct.2C_MCV.2C_histogram SELECT (SELECT sum(x) FROM unnest(most_common_freqs) x) frac_MCV, tablename, attname, inherited, null_frac, n_distinct, array_length(most_common_vals,1) n_mcv, array_length(histogram_bounds,1) n_hist, correlation FROM pg_stats WHERE tablename='subscriptions' AND attname IN ('project_id','tags') ORDER BY 1 DESC; Maybe clustering the table on project_id (and ANALYZEing) would help, but that might need to be done consistently. Michael previously suggested partitioning which, if done on project_id, would then no longer need to be specially CLUSTERed. Is the plan for the fast query the same as in August ? https://www.postgresql.org/message-id/CAFvCgN4UijKTYiOF61Tyd%2BgHvF_oqnMabatS9%2BDcX%2B_PK2SHRw%40mail.gmail.com Justin