Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0Jqc-00GRsE-JT for pgsql-performance@arkaria.postgresql.org; Thu, 03 Apr 2025 12:39:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u0Jqb-006jvT-C1 for pgsql-performance@arkaria.postgresql.org; Thu, 03 Apr 2025 12:39:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0Jqb-006jvL-20 for pgsql-performance@lists.postgresql.org; Thu, 03 Apr 2025 12:39:05 +0000 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u0JqZ-002jcL-1G for pgsql-performance@lists.postgresql.org; Thu, 03 Apr 2025 12:39:04 +0000 Received: by mail-yb1-xb29.google.com with SMTP id 3f1490d57ef6-e6df32ad351so720008276.2 for ; Thu, 03 Apr 2025 05:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743683942; x=1744288742; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=u/B67RCQNFeho9tLvVkVS+31Zh6Kp1RD0HYfH98E66g=; b=hahaOL/5erJtvOtnj3FJZcwbH47L+RMxuG3MkKuDsahwG0hQ37a0qub1R1NhvLmn+T JpoRDIO9MGdlIaGOehO5H7dxDKWvgrnozImYH8srIliZuMPvC+XS4j/nlQNaQQHzmKf1 wXFOx3yzHrAf7ZcTI8HPicmxT74QsybU8zJTLaCNj6dgb1LCvlxTG15hjPgERY5LLhhh uAoRKD0nUyZlmcsjKLcNP7vs0O89pfzrbclCam4o5fKBh/H4JED1ScoRZfsMyZNpXEUZ vebUKoPI1c/TTPqYyjiOdcuo4AWD17rq36LKaePpnnQhC+/kcTpoWkD2eObCM7B5nNmB N1sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743683942; x=1744288742; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=u/B67RCQNFeho9tLvVkVS+31Zh6Kp1RD0HYfH98E66g=; b=dae3TAMIXD/4/OVG4w70rjl88y5Jd86GwLSFuHgW3NZGVd9TdqWorYMjuyuBechgih dwXA4RhxiUURKytreMHodp9TwULY3YivCUbT8pAIj0bo4lb96IAg16IvuNv4H7p5HpsW uG5XZ89UziTd6IDL1hS+wZsc96TnRnh4J9XQU8pI3Wjx/STxza5MCUzGgiMOf/oXtCh2 yW2ENFZkFcoK3TblF+2RZhDCKfByXLPcP+GMn85RuFrFoUBQh6wCG9gGJiorYkujFIpe f6GelAj+a9XjGiyzkc/cAcQtyZGWrxEajo4GwZ4DSdTMa62mLlIzcJirruksqN7jnzmU Kwpw== X-Forwarded-Encrypted: i=1; AJvYcCUq4a6ZMjtBotvu2YESiAnhf5FWRVlUNmmw5F0EJKnj/u0fujnrJ4aqTucX4qJ6aJ8WB6EpcLhEPwyonXzYkYa4dA==@lists.postgresql.org X-Gm-Message-State: AOJu0Yx2izYXlybk1jtB16UYfZbBrw2/uCTNVIcyhL/lkHc4mm1l3NHF OZANs5E/i0n6rndZPRDtF81LQ3QMqxXVBZ1riSquOhHlJ0fatJ2hsI9iyI9p5IY2ltVNYOHg8xO +NObImUcAY5watLKz7wFZKlFNP+c= X-Gm-Gg: ASbGncvM56AH+F8r5TZObFx6nHG9HY7wcoGNC3u9Tpb4xCPRdG4c8axgIQ72rx00rsf Idu3Ny2UAmTd1WuqPPKqip3bexTceTIJHGiRW7+peAynK+k0SosesuCf2g0ordGRLWFOy+M3MBs Cf30qhO89SjTB9R0HbxI3aKfSp1+U= X-Google-Smtp-Source: AGHT+IH4a2JYShO7HznW+NGD55AqmOBbddMT40CxkYEN1m93TjLqJ0f2niPlPJNkZW+zUtplvmKPvZwqkXxgRDN9QtA= X-Received: by 2002:a05:6902:1b86:b0:e60:a068:a14b with SMTP id 3f1490d57ef6-e6e0a0ffaadmr3899953276.4.1743683942118; Thu, 03 Apr 2025 05:39:02 -0700 (PDT) MIME-Version: 1.0 References: <20e77723-3c1c-44f5-ba02-442f170dd365@gmail.com> In-Reply-To: <20e77723-3c1c-44f5-ba02-442f170dd365@gmail.com> From: James Pang Date: Thu, 3 Apr 2025 20:38:49 +0800 X-Gm-Features: ATxdqUGKcPcdsJhWbqAOZMNKlqHiV8AfgAWuLOcgyMX_FrY4gqF0bHyxl_mFqSI Message-ID: Subject: Re: partition table optimizer join cost misestimation To: Andrei Lepikhov , pgsql-performance@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000f87d2e0631df0d2d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f87d2e0631df0d2d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Follow your suggestion to increase statistics_target (I increase target_statistic to 1000 for aa.mmm_id and cc.sss_id ,analyze tablea, tablec again), optimizer choose the good SQL plan. Thanks, James Andrei Lepikhov =E6=96=BC 2025=E5=B9=B44=E6=9C=883=E6= =97=A5=E9=80=B1=E5=9B=9B =E4=B8=8B=E5=8D=884:44=E5=AF=AB=E9=81=93=EF=BC=9A > On 4/3/25 10:04, James Pang wrote: > > one more comments, for vacuum/analyze, we enable autovacuum=3Don, that = may > > sometimes automatically analyze part of partition table directly. > I see some incoherence in data provided. The ranges of joining columns > intersects only partially: > > cc.sss_id: 5 100 001 101 - 7 999 999 601 > aa.mmm_id: 2 005 242 651 - 5 726 786 022 > > So, the intersection range 5100001101 - 5726786022 - is about 10% of the > whole range. > But I don't see it in the column statistics you provided. And Postgres > may do the same. > So, at first, I do recommend increasing default_statistics_target or > just statistics_target on partitioned tables only. For such big tables I > usually set it at least to the 2500. > Also, don't trust in autovacuum on partitioned table - to make an > analyse it needs to lock each partition which is highly unlikely to happe= n. > So, increase stat target, make ANALYZE tablea, tablec and let me know > what will happen. May be after the analyse statistics will be more > consistent. > > -- > regards, Andrei Lepikhov > --000000000000f87d2e0631df0d2d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
=C2=A0 Follow your suggestion to increase statistics_targe= t (I increase target_statistic to 1000 for=C2=A0 aa.mmm_id and cc.sss_id ,a= nalyze tablea, tablec again),=C2=A0 optimizer choose the good SQL plan.=C2= =A0

Thanks,

James=C2=A0

Andrei Lepikhov <lepihov@gmail.com> =E6=96=BC 2025=E5=B9=B44=E6=9C=883=E6=97=A5=E9= =80=B1=E5=9B=9B =E4=B8=8B=E5=8D=884:44=E5=AF=AB=E9=81=93=EF=BC=9A
=
On 4/3/25 10:04, James Pa= ng wrote:
> one more comments, for vacuum/analyze, we enable autovacuum=3Don, that= may
> sometimes automatically analyze part of partition table directly.
I see some incoherence in data provided. The ranges of joining columns
intersects only partially:

cc.sss_id: 5 100 001 101 - 7 999 999 601
aa.mmm_id: 2 005 242 651 - 5 726 786 022

So, the intersection range 5100001101 - 5726786022 - is about 10% of the whole range.
But I don't see it in the column statistics you provided. And Postgres =
may do the same.
So, at first, I do recommend increasing default_statistics_target or
just statistics_target on partitioned tables only. For such big tables I usually set it at least to the 2500.
Also, don't trust in autovacuum on partitioned table - to make an
analyse it needs to lock each partition which is highly unlikely to happen.=
So, increase stat target, make ANALYZE tablea, tablec and let me know
what will happen. May be after the analyse statistics will be more
consistent.

--
regards, Andrei Lepikhov
--000000000000f87d2e0631df0d2d--