Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eF40Q-0006qC-Fk for pgsql-performance@arkaria.postgresql.org; Wed, 15 Nov 2017 20:09:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eF40Q-0001qJ-3I for pgsql-performance@arkaria.postgresql.org; Wed, 15 Nov 2017 20:09:54 +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 1eF3yO-0004Gw-M5 for pgsql-performance@postgresql.org; Wed, 15 Nov 2017 20:07:48 +0000 Received: from mail-wr0-x229.google.com ([2a00:1450:400c:c0c::229]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eF3yJ-0005uw-SZ for pgsql-performance@postgresql.org; Wed, 15 Nov 2017 20:07:47 +0000 Received: by mail-wr0-x229.google.com with SMTP id k61so21469150wrc.4 for ; Wed, 15 Nov 2017 12:07:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=V27asroaCJlO15gSgaC4sVWQV8Cy0BAck21xLmK6C6w=; b=VnRc82cfkSTifP5g8mgMGQkbKcTYEuV0LGwyjeZ3OSVTHo94mm/hoR6CGCgacfHYVt R6ej/ra0clLptVLHW8CmSSMFpTTJwKXDyupUO6v/z/yyiomeHJrQFk+6HHLsf+Z+MbWs Q5/t4WVMlJdV55JsxPVcOJNuyKUYIn5vMBHh+nqQhmvCZy22SJFi7m0emh14uyRZaMV3 D5bH2UqY245FQT0xwThckXV864QsW0RJpSk/4sdFLVTFLrQAIJfn6Oev27ya91/JqF9f h3lByF6l3TUBGOMC1E3ETdFH0VwjMWkiIYpi2nSBqum8wdp842nbOdPwIwp+Cm3TMCYO bO8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=V27asroaCJlO15gSgaC4sVWQV8Cy0BAck21xLmK6C6w=; b=PCzCtMsLw8ukfKAxnZtW5vr6S8HGaWQq28ucuzSpm3/S586JZT5yU9f1arCW5i0ymS QzAdPVr87ZBhVrH8ScLTD6SdZSdqABtSjUL3tqIUoNU+rDRDtCLV7rgsJhUF0iZAipLm /8wC1yGtS7q9WpAQo0yBRZrHvBY2J5312KHAnsN5QqeLGuxFTeukej+0eymDUfnxP0sl YMS9s+nLe50Bb9wVaLI+g3TYz/rTiDdPIyAuTt9MMrYg9pmeNt8V/gvCJyNM14lAuMlI TRuKfdGFPL8umA/ijJR5BLcL1x15ky70Y2hywcC8M/Rj3farGftvNwRvjFjFnt4AzNjU rs2w== X-Gm-Message-State: AJaThX7WJ2Jq0uRN3fCvFSNgMx55LW+jPR++HSE9P5alitBRQfh7gzTX 4SF4EWsLDooB6gvcFf/v/ItkDVG4xIEve9OvBZw= X-Google-Smtp-Source: AGs4zMZKJVoKIvuFz4wGGfVD6sL5X/tj/3Er4oBCuK0W6QqGfL9ed8555NHJb/qJhHaay+dj73lMBX+GvVs67Ln4ZIo= X-Received: by 10.223.170.214 with SMTP id i22mr15716272wrc.110.1510776462434; Wed, 15 Nov 2017 12:07:42 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.146.7 with HTTP; Wed, 15 Nov 2017 12:07:01 -0800 (PST) In-Reply-To: <31c10833-9d19-dfa5-1cab-43eaae097828@gusw.net> References: <31c10833-9d19-dfa5-1cab-43eaae097828@gusw.net> From: Pavel Stehule Date: Wed, 15 Nov 2017 21:07:01 +0100 Message-ID: Subject: Re: query performance issue To: Gunther Cc: "pgsql-performance@postgresql.org" Content-Type: multipart/alternative; boundary="94eb2c1cb93e60e83e055e0b0e3e" 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 --94eb2c1cb93e60e83e055e0b0e3e Content-Type: text/plain; charset="UTF-8" 2017-11-15 20:58 GMT+01:00 Gunther : > > On 11/15/2017 8:12, Pavel Stehule wrote: > > There is wrong plan due wrong estimation > > for this query you should to penalize nested loop > > set enable_nestloop to off; > > before evaluation of this query > > > You are not the only one with this issue. May I suggest to look at this > thread a little earlier this month. > > http://www.postgresql-archive.org/OLAP-reporting-queries- > fall-into-nested-loops-over-seq-scans-or-other-horrible- > planner-choices-tp5990160.html > > where this has been discussed in some length. > It is typical issue. The source of these problems are correlations between columns (it can be fixed partially by multicolumn statistics in PostgreSQL 10). Another problem is missing multi table statistics - PostgreSQL planner expects so any value from dictionary has same probability, what is not usually true. Some OLAP techniques like calendar tables has usually very bad impact on estimations with this results. Regards Pavel > regards, > -Gunther > > > --94eb2c1cb93e60e83e055e0b0e3e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


2017-11-15 20:58 GMT+01:00 Gunther <raj@gusw.net>:
=20 =20 =20

On 11/15/2017 8:12= , Pavel Stehule wrote:
There is wrong plan due wrong estimation

for this query you should to penalize nested loop

set enable_nestloop to off;

before evaluation of this query

You are not the only one with this issue. May I suggest to look at this thread a little earlier this month.

http://www.postgresql-archive.org/OLAP-reporting-queries-fall-= into-nested-loops-over-seq-scans-or-other-horrible-planner-choice= s-tp5990160.html

where this has been discussed in some length.

It is typical issue. The source of these problems are corr= elations between columns (it can be fixed partially by multicolumn statisti= cs in PostgreSQL 10). Another problem is missing multi table statistics - P= ostgreSQL planner expects so any value from dictionary has same probability= , what is not usually true. Some OLAP techniques like calendar tables has u= sually very bad impact on estimations with this results.

Regards

Pavel


regards,
-Gunther



--94eb2c1cb93e60e83e055e0b0e3e--