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 1ib48I-0002Lc-Bc for pgsql-bugs@arkaria.postgresql.org; Sat, 30 Nov 2019 14:54:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ib48H-0007tA-5i for pgsql-bugs@arkaria.postgresql.org; Sat, 30 Nov 2019 14:54:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ib48G-0007t3-Qf for pgsql-bugs@lists.postgresql.org; Sat, 30 Nov 2019 14:54:00 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ib48D-0005zP-Ak for pgsql-bugs@lists.postgresql.org; Sat, 30 Nov 2019 14:53:59 +0000 Received: by mail-wr1-x444.google.com with SMTP id z7so34997530wrl.13 for ; Sat, 30 Nov 2019 06:53:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=vNTzNMddTMiuutFdaOxbtWrmxccCsJwWfttRoFOsFBY=; b=gnVAWRMW/xPEka4ntClw5CyvslKV0chnXAcJEk9bq9lttCGayRGSAg5S/qX3pLBCZ1 LRVKRcl/HEtek5K+lBZqOePPHMaXMjRdb21loNt1s5MU8eC1t3X0MmeUZ4I6YIUdmtK4 B+hMuU5UgYlMJz5jD9h2BZ8Vj1rNICxyfHTOawZ10sg5+fF2UVydKkr6QKy+Uo8VkeDH 314rBrYYWv55l9PAp4YoduWPNad8Hbn+inGnOMjXKR1yp4WpPQ98J+O9pRZmNbXmFtDu AEEZSQ2/krJ/8gXRGXAXYa6CVdw+JLo+lhoHgk4ffg9NbDwH3ZWG0nO4I+v55E0Sl4As Onsw== 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:content-transfer-encoding :in-reply-to; bh=vNTzNMddTMiuutFdaOxbtWrmxccCsJwWfttRoFOsFBY=; b=dRYjPxhzKHJte929GS2GKXPIm4Z9h/a5KXOr4kKHHRndEUK1B54etoc40yNGPJ54hb s8TUyX3Wh+DBNyuBtC/4a3HLGVpe8TtBcTd0SwREzgGDQzhJiU9yVQN1VEis4kcvLw5K lHLu8chq5mWxQkEQBUQZN33xtTAxJ21X/5F7g+ZZxuzwuoeziu+crfwLmId9HyOSROlO w5e+QmoZRH+tW6bUzShpX3oDFbCoKG5UKxb6B86L57lcTvYP91byeba/ZhXr3UzToH7V LGt3VX/UjeakRHRjcZqsTkA7fdhHvPcaVLjc2j+yIIBp045PPc/hUpfeUrFVMGN5bIfd NH0A== X-Gm-Message-State: APjAAAXxAx6akBYZjEdyAwCno8/wUhsOmkfZtTf6/mX6Fj7gQ/39sJUo rt5Ynf4pLIAVN5Ft9QouIvBPSg== X-Google-Smtp-Source: APXvYqwPqJYL6tPm2FfevACs+hhzvt9qJZMvbZ9L7QxOaIrLYkmdXVTZGdYGDeIO5Sbw1ICj30olxQ== X-Received: by 2002:a5d:4692:: with SMTP id u18mr23888523wrq.206.1575125635820; Sat, 30 Nov 2019 06:53:55 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id u18sm4120165wrt.26.2019.11.30.06.53.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Nov 2019 06:53:55 -0800 (PST) Date: Sat, 30 Nov 2019 15:53:52 +0100 From: Tomas Vondra To: EffiSYS / Martin Querleu Cc: Pavel Stehule , PostgreSQL mailing lists Subject: Re: Strange query planner behavior Message-ID: <20191130145352.hhr4n45cdsyjkzr5@development> References: <798855a5-4abe-b1d0-68ab-f21966d2c3a1@effisys.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Nov 30, 2019 at 11:29:53AM +0100, EffiSYS / Martin Querleu wrote: >Hi Pavel > >Thanks for the fast reply >Our databases are VACUUMed everyday. I did it again but no difference > >Here are the query plans: > >EFT_MBON=# explain analyse select * from livraison where id_master = 10; > QUERY PLAN >-------------------------------------------------------------------------------------------------------------------------------------------- > Index Scan using pour_recherche_sous_livraison on livraison > (cost=0.03..15.04 rows=1 width=697) (actual time=0.017..0.017 rows=0 >loops=1) >   Index Cond: (id_master = 10) > Planning Time: 0.124 ms > Execution Time: 0.036 ms >(4 lignes) > >EFT_MBON=# explain analyse select * from livraison where id_master = >(select 10); >                                                      QUERY PLAN >----------------------------------------------------------------------------------------------------------------------- > Seq Scan on livraison  (cost=0.01..2888156.69 rows=1917632 width=697) >(actual time=1334.615..1334.615 rows=0 loops=1) >   Filter: (id_master = $0) >   Rows Removed by Filter: 1918196 >   InitPlan 1 (returns $0) >     ->  Result  (cost=0.00..0.01 rows=1 width=4) (actual >time=0.000..0.001 rows=1 loops=1) > Planning Time: 0.138 ms > Execution Time: 1334.642 ms >(7 lignes) > >Regarding the cost calculator the configuration is as follows: > >random_page_cost and seq_page_cost are identical since the data is >100% in RAM (both at 15.0, 3 times default) Ummm, what? Does this mean you have random_page_cost = 15 seq_page_cost = 15 Neither of that is 3 times the default value, though, so maybe I just don't understand correctly. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services