Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPXOs-0003PM-Iz for pgsql-performance@arkaria.postgresql.org; Mon, 26 Jun 2017 17:02:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dPXOs-00020Y-2Z for pgsql-performance@arkaria.postgresql.org; Mon, 26 Jun 2017 17:02:10 +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.84_2) (envelope-from ) id 1dPXOr-00020O-J7 for pgsql-performance@postgresql.org; Mon, 26 Jun 2017 17:02:09 +0000 Received: from vapor.isi.edu ([128.9.64.64]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dPXOn-0001xg-HY for pgsql-performance@postgresql.org; Mon, 26 Jun 2017 17:02:08 +0000 Received: from moraine.isi.edu (moraine.isi.edu [128.9.64.90]) by vapor.isi.edu (8.13.8/8.13.8) with ESMTP id v5QH1RkK004473; Mon, 26 Jun 2017 10:01:27 -0700 (PDT) Date: Mon, 26 Jun 2017 10:01:20 -0700 From: Karl Czajkowski To: Chris Wilson Cc: pgsql-performance@postgresql.org, george.saklatvala@cantabcapital.com Subject: Re: Fwd: Slow query from ~7M rows, joined to two tables of ~100 rows each Message-ID: <20170626170120.GB27236@moraine.isi.edu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ISI-4-43-8-MailScanner: Found to be clean X-MailScanner-From: karlcz@isi.edu List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On Jun 26, Chris Wilson modulated: > ... > In your case, the equivalent hack would be to compile the small > dimension tables into big CASE statements I suppose... > > > Nice idea! I tried this but unfortunately it made the query 16 seconds > slower (up to 22 seconds) instead of faster. Other possible rewrites to try instead of joins: -- replace the case statement with a scalar subquery -- replace the case statement with a stored procedure wrapping that scalar subquery and declare the procedure as STABLE or even IMMUTABLE These are shots in the dark, but seem easy enough to experiment with and might behave differently if the query planner realizes it can cache results for repeated use of the same ~100 input values. Karl -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance