Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAdLx-0005PB-61 for pgsql-performance@arkaria.postgresql.org; Fri, 03 Nov 2017 14:53:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eAdLw-00030o-P5 for pgsql-performance@arkaria.postgresql.org; Fri, 03 Nov 2017 14:53: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.84_2) (envelope-from ) id 1eAdK1-0004br-5w for pgsql-performance@postgresql.org; Fri, 03 Nov 2017 14:51:49 +0000 Received: from gproxy1-pub.mail.unifiedlayer.com ([69.89.25.95] helo=outbound-ss-1812.hostmonster.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eAdJx-0008PH-MR for pgsql-performance@postgresql.org; Fri, 03 Nov 2017 14:51:48 +0000 Received: from CMOut01 (cmgw2 [10.0.90.82]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 53C5A175AA6 for ; Fri, 3 Nov 2017 08:51:38 -0600 (MDT) Received: from host214.hostmonster.com ([74.220.215.214]) by CMOut01 with id VSrZ1w0124e7MuJ01Srcu9; Fri, 03 Nov 2017 08:51:38 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=E7lA7DdVRVhKYBNJxJVZOg==:117 a=E7lA7DdVRVhKYBNJxJVZOg==:17 a=IkcTkHD0fZMA:10 a=sC3jslCIGhcA:10 a=nW0mvi2boGaoiqLW7dMA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gusw.net; s=default; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version :Date:Message-ID:References:To:Subject:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=16JCt1zJ36GEv7XOXOr53SoFqF1l4ozEqBUcK4e0WX4=; b=J4YCt8vEQkSarGl9Af02rcRZbM +IBYWUs4ry2ysr903nIuui2L13fWRTONAixkHl/fSz34pJTGmumH5BbKo/q4Lwrwp+3oJNqvrWEPA eDv9CwBlr185QudRIjyHMEq85; Received: from [191.7.145.23] (port=60611 helo=[192.168.9.4]) by host214.hostmonster.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.87) (envelope-from ) id 1eAdJl-001tVj-GY for pgsql-performance@postgresql.org; Fri, 03 Nov 2017 08:51:33 -0600 From: Gunther Subject: Re: Re: OLAP/reporting queries fall into nested loops over seq scans or other horrible planner choices To: pgsql-performance@postgresql.org References: <1509611428.3268.5.camel@cybertec.at> <1509701327868-0.post@n3.nabble.com> <9a76f13e-cdb1-1d8d-2178-67e6dcf169bc@gusw.net> Message-ID: <9ed2bdd0-7094-7e7f-d276-3647a10f635f@gusw.net> Date: Fri, 3 Nov 2017 10:51:31 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <9a76f13e-cdb1-1d8d-2178-67e6dcf169bc@gusw.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host214.hostmonster.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - gusw.net X-BWhitelist: no X-Source-IP: 191.7.145.23 X-Exim-ID: 1eAdJl-001tVj-GY X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.9.4]) [191.7.145.23]:60611 X-Source-Auth: gunther+pragmaticdata.com X-Email-Count: 3 X-Source-Cap: cHJhZ21hdDE7cHJhZ21hdDE7aG9zdDIxNC5ob3N0bW9uc3Rlci5jb20= X-Local-Domain: yes 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 Just throwing out some more innovative ideas. Materialized join tables, I have read somewhere. OK, difficult to keep consistent with transactions. Forget that. But, why not collect statistics on every join that is processed, even if the query is interrupted. Then as more and more plans are run, and interrupted for being too slow, statistics on the joins are collected and can inform the optimizer next time not to use that approach. Would work like magic for a user. User writes a query. It runs 3 minutes and as no result. User interrupts the query (THANKS PgSQL for allowing that, unlike Oracle!). Now the statistics has already been gathered. User reruns the query, not changing anything. Because the statistics on (some of) the joins has been gathered, at least with an initial sample, now the planner will likely choose a different plan. Say, now the results come in at 2 minutes and the user is satisfied. But still more complete statistics was collected. Now the user changes a few query parameters and runs the query again, or puts it into a more complex query. This time the planner has even more statistics and chooses an even better plan. And lo and behold now the results come in at 10 seconds! At no point did the user have to analyze the explain plan, come up with hints and tricks and nudges to the optimizer. And at no point did the user have to become DBA to run some outlandish PL/SQL procedures for which he does not have the license key or the special privileges. But until that is done, please put in the pg_hint_plan.c. Hints don't hurt. If you don't like them, don't use them., regards, -Gunther -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance