Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lyGMI-0007SY-AD for pgsql-general@arkaria.postgresql.org; Tue, 29 Jun 2021 16:13:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lyGMH-0002V5-9D for pgsql-general@arkaria.postgresql.org; Tue, 29 Jun 2021 16:13:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lyGMG-0002Ux-Ut for pgsql-general@lists.postgresql.org; Tue, 29 Jun 2021 16:13:09 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lyGME-0007FS-Mt for pgsql-general@lists.postgresql.org; Tue, 29 Jun 2021 16:13:07 +0000 Received: by mail-oi1-x233.google.com with SMTP id u11so26902036oiv.1 for ; Tue, 29 Jun 2021 09:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=iLnejv9GrPQ35snLHbSmxgb7Eplb3D79cgDQNhN8wqE=; b=NSD2SWQSuwaqkuzgoQmrViN286J6XDyX4OLjMymakIdklvaEb6VF0hLF29Q7Ga78NM td4ISdQx4gxukb3g91XgALRvf4HFOkno4v6FGobhTZfyalibS7OsFdY4na6Pyp29J4tV aVXBGKDd7TtppG2ZQrweOrt+k8LYIOuxNr+yRamLRbGMHxBIYpKMR1dEcz7dKIN3spYa bzRLtZM3bCss6jN8ImnOTvZzbZ1p2+Q1s4R9zlI800dfAAAr8HP+BHvWDsZsUlwzFsmX lKKLYCQ+RzZoz775tnHWzIqveCkEzPr6pmv/52YeQIBu4Ivhk9rETLDYMMqJydwbkouJ Wd4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=iLnejv9GrPQ35snLHbSmxgb7Eplb3D79cgDQNhN8wqE=; b=kh8m6bYiLwZUF4OplVXZzVsASgdbZNSwuylds8UV562xWn2SJ9RBISSU+O0mWTXmkq L2zs8bfFTavTDSmr0vjJ3HF/1ZkzjqHvoV/K2lu7EGkLXjKvl3Ga+IBonKSJEteBYSSl dMrNS9bKeEG2iBYOme3BeAcGJxWxSCQ5CiKCG6zI642UEIweWPaNyeZN+ZlSvAQk1qtC saaMGpoQ9zxh9wVJPWK7cEZuBFt+0dBSwMXcMy/jD/CGgK2p0CPqK206bz5zJFospzfT Ai9bGAP6FPd5cEP5tZArlhKhSBmowPoXKqNRhrjatNPB2Yd0/dhbyzTk8+b9lsHV40Qm X6DA== X-Gm-Message-State: AOAM532XXWelia6YLxxjyajQ3CWu/Wo3e3ngwKiY7eENZf14Qw9Wsdg1 mF7si2nZ3HsAcptoZb/D+645hERNe+XrxA== X-Google-Smtp-Source: ABdhPJzf4MaFrhJFrTReL9Ha0GxXmNGimNF/8gw8jbKEiuENLKN0i3l4Jo4EQvnPscjVasfdKmB9PQ== X-Received: by 2002:a05:6808:1312:: with SMTP id y18mr19901094oiv.82.1624983185512; Tue, 29 Jun 2021 09:13:05 -0700 (PDT) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id a7sm3733791ooo.9.2021.06.29.09.13.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Jun 2021 09:13:05 -0700 (PDT) Subject: Re: Do table-level CHECK constraints affect the query optimizer? To: PostgreSQL General References: <5f718120-a286-71ca-3d31-7bad70f0194e@gmail.com> From: Ron Message-ID: <374d530d-ec98-f1ea-8d41-21e661aa9ab4@gmail.com> Date: Tue, 29 Jun 2021 11:13:03 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------2E5108C5264AE59918E9F777" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------2E5108C5264AE59918E9F777 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 6/29/21 10:41 AM, Michael Lewis wrote: > Are vacuum and analyze happening regularly on the live system? Yes.  There's a nightly cron job which vacuums those it thinks needs it (though it's INSERT-heavy), and ditto ANALYZE. Specifically, I ran ANALYZE on the prod table just before running the query. Also, the sampling rate on all tables in both prod and test is 60000 rows. > What's an example query that uses indexes on test and does not on live? SELECT COUNT(*) FROM sep_info_report_extract; On prod, there's a list of "Parallel Seq Scan on xxxx_partname" records in the EXPLAIN output, while the test system has a list of "Parallel Index Only Scan using ..._idx" records. (Yes, this is a simple COUNT(*) but it's *a simple reproducer*, which *demonstrates* the kind of problems we're having on *much more complex queries*.) > Does the live system show poor estimates when executing 'explain analyze > select...' and the test system show semi-accurate row estimates? They're within 2% of each other. > 50 million seems to be a fairly low row count to be partitioned. What > version is this on? As explained in the OP, each record has a (sometimes large) XML record; months can have up to 240GB.  Besides, partitioning makes for easy archiving. -- Angular momentum makes the world go 'round. --------------2E5108C5264AE59918E9F777 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 6/29/21 10:41 AM, Michael Lewis wrote:
Are vacuum and analyze happening regularly on the live system?

Yes.  There's a nightly cron job which vacuums those it thinks needs it (though it's INSERT-heavy), and ditto ANALYZE.

Specifically, I ran ANALYZE on the prod table just before running the query.

Also, the sampling rate on all tables in both prod and test is 60000 rows.

What's an example query that uses indexes on test and does not on live?

SELECT COUNT(*) FROM sep_info_report_extract;

On prod, there's a list of "Parallel Seq Scan on xxxx_partname" records in the EXPLAIN output, while the test system has a list of "Parallel Index Only Scan using ..._idx" records.

(Yes, this is a simple COUNT(*) but it's a simple reproducer, which demonstrates the kind of problems we're having on much more complex queries.)

Does the live system show poor estimates when executing 'explain analyze select...' and the test system show semi-accurate row estimates?

They're within 2% of each other.

50 million seems to be a fairly low row count to be partitioned. What version is this on?

As explained in the OP, each record has a (sometimes large) XML record; months can have up to 240GB.  Besides, partitioning makes for easy archiving.

--
Angular momentum makes the world go 'round.
--------------2E5108C5264AE59918E9F777--