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 1iZWkH-0005hi-6O for pgsql-general@arkaria.postgresql.org; Tue, 26 Nov 2019 09:02:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iZWkF-0000CQ-OE for pgsql-general@arkaria.postgresql.org; Tue, 26 Nov 2019 09:02:51 +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 1iZWkF-0000CI-DE for pgsql-general@lists.postgresql.org; Tue, 26 Nov 2019 09:02:51 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iZWkC-0004IJ-26 for pgsql-general@lists.postgresql.org; Tue, 26 Nov 2019 09:02:51 +0000 Received: by mail-wr1-x42d.google.com with SMTP id i12so21393558wrn.11 for ; Tue, 26 Nov 2019 01:02:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=n26.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=2TudJCzCkwJRTZnFLepbBnaR59orP30yGnftzUMmI9E=; b=BKQqGBsiSzrluZSRC1h88JnkvOiVeJtTDdjCOk+oGo9sgcT/X0oP/Jk1cnnf8AU+1N //JGYtL7UgCSxAt/eEX10Gmi8tuuGDsSgvrVBnAxLLKpOLU4TUnUDIg/dduR3ct1cAcC F9uvir3DmsBVOnBzgzGaXEBbJQm1BRgZuezVux6/QVrc7KhlmO7NGVgqWe7JdCaN3vgp quxggNn4SYp+pkj7KYtOjCHXqqQ0BcFFf8UN3z1OCpJdzvyJatzN9m9b6y27L5bPR2KM krwwwnTC/GR0tZIwsMwNRFY1OHCG3dXfv4DyBbdP69ANchVpnuiRnzgNL1ETbGcqAvXf pZsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=2TudJCzCkwJRTZnFLepbBnaR59orP30yGnftzUMmI9E=; b=SUzdhIlbHubmkCY2V3KwY1683+f3A2nByh+MqWG07pysTAgtm5Wk0IqXW+fKNIut+R s1PBtpm/Yw6THtY/zLOFeLuvDZ0+KEA3GWVUcnp88adx2xl2GJP0yYEleBhsDBGn3Z1l SiasG/ELhtLuvC41VaTD1CEQ8WP/VHepFMEUkJ/OY646z+z0XFKqBXn/CZXTf0cPl+ak KbT4XQOTYidWyWNhD+R7BEol/KZrQfyP1vnJbnpBqJQPROiijH98OmQN+SR9ACBwku/L 5gIeGTot57cRa+tAL47T/sYOs0H06uigvCWJdQ1IeX3ecQGqiNHV+ocvMC//NLBEZdrO Urpw== X-Gm-Message-State: APjAAAV3VLJZ4oYHzGEUW9b8Dbfm1SxtfwohufH1vaICjB4122yFpAHU wmk4Rn+AbsvQXtp+en+p4qkFIQ== X-Google-Smtp-Source: APXvYqy8bVX+DINtz9cDFwhTciO+55iY7ufUvyjYgFcuyAhGatc5ezc0lVM1YEjxA1isf2vVkREI7Q== X-Received: by 2002:a5d:6a4c:: with SMTP id t12mr27509079wrw.141.1574758966961; Tue, 26 Nov 2019 01:02:46 -0800 (PST) Received: from [10.4.23.52] ([62.96.137.138]) by smtp.gmail.com with ESMTPSA id d12sm12361182wrc.3.2019.11.26.01.02.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Nov 2019 01:02:46 -0800 (PST) From: Andrei Zhidenkov Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_810DD0C1-451A-4718-993C-0AF5C25D424E" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: Weird seqscan node plan Date: Tue, 26 Nov 2019 10:02:44 +0100 In-Reply-To: <154007751574734779@myt2-a7d7570d35ff.qloud-c.yandex.net> Cc: pgsql-general@lists.postgresql.org To: =?utf-8?B?0JjQs9C+0YDRjCDQktGL0YHQutC+0YDQutC+?= References: <154007751574734779@myt2-a7d7570d35ff.qloud-c.yandex.net> X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_810DD0C1-451A-4718-993C-0AF5C25D424E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 How many tables do you have in your query? If too many, in your case = =E2=80=9CGenetic Query Optiomiation=E2=80=9D might be used = (https://www.postgresql.org/docs/10/geqo-pg-intro.html = ). > On 26. Nov 2019, at 03:19, =D0=98=D0=B3=D0=BE=D1=80=D1=8C = =D0=92=D1=8B=D1=81=D0=BA=D0=BE=D1=80=D0=BA=D0=BE = wrote: >=20 > Hi all! > I'm confused by planner choice: seqscan but not index scan when index = scan cost is much cheaper. > 1st plan: https://explain.depesz.com/s/Cti#l8 > 2nd plan (with "set enable_seqscan =3D off"): = https://explain.depesz.com/s/qn0I#l8 >=20 > Look at 8th row: this nested loop decided to join the second node by = using seqscan (1st plan) when index is available (2nd plan). Index scan = is much cheaper (0.430 over 257.760).=20 >=20 > What am I missing? >=20 > And thanks for any reply! >=20 >=20 --Apple-Mail=_810DD0C1-451A-4718-993C-0AF5C25D424E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 How = many tables do you have in your query? If too many, in your case = =E2=80=9CGenetic Query Optiomiation=E2=80=9D might be used (https://www.postgresql.org/docs/10/geqo-pg-intro.html).

On 26. Nov 2019, at 03:19, =D0=98=D0=B3=D0=BE=D1=80=D1=8C = =D0=92=D1=8B=D1=81=D0=BA=D0=BE=D1=80=D0=BA=D0=BE <vyskorko.igor@yandex.ru> wrote:

Hi = all!
I'm confused by planner choice: seqscan but not index = scan when index scan cost is much cheaper.
1st plan: https://explain.depesz.com/s/Cti#l8
2nd = plan (with "set enable_seqscan =3D off"): https://explain.depesz.com/s/qn0I#l8

Look at 8th row: this nested loop decided to join the second = node by using seqscan (1st plan) when index is available (2nd plan). = Index scan is much cheaper (0.430 over 257.760).

What am I missing?

And thanks = for any reply!



= --Apple-Mail=_810DD0C1-451A-4718-993C-0AF5C25D424E--