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 1shHI2-00FeC9-2Y for pgsql-admin@arkaria.postgresql.org; Thu, 22 Aug 2024 23:32:26 +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 1shHI0-006e4Q-4A for pgsql-admin@arkaria.postgresql.org; Thu, 22 Aug 2024 23:32:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1shHHz-006e42-Nh for pgsql-admin@lists.postgresql.org; Thu, 22 Aug 2024 23:32:24 +0000 Received: from fout1-smtp.messagingengine.com ([103.168.172.144]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1shHHw-0011at-KD for pgsql-admin@lists.postgresql.org; Thu, 22 Aug 2024 23:32:23 +0000 Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 56C62138FFE3; Thu, 22 Aug 2024 19:32:20 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 22 Aug 2024 19:32:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= quadratum-braccas.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1724369540; x=1724455940; bh=CHkpjzhiW3 5JO4FbEJYMxMf8dw9T8D7tz7WpNfXjdA0=; b=SnTab+jHmlCA4+okCtq93F6YSa Q0J0j41KzqF9EQ4j4eirQGHk2Z0hMeYwzOCP+OjP2Nhy6B5gfETKiv65UEmVWZ39 5Gn3PDROsmkSQqel5IG22AXOU0BheUM72OKCE7VpnU7KdpxBF6BI7+dEH+J1UMB8 aX+ahQOzB36p9NMEzS0+uwLXmzGbB+n0W8rLIPKb1DInsGPQZBukgMt7sudI/p+4 K6Smue4n4dfzGHW8O+/WtHl+M1MPYoKUXvHO34H3e9MyP5B8KvK88v8t2IfZ7ILX UF9UcDt81hq1Jbc3Oaf7GK935g1vrVMiaDMmVijQUVTPVs4k3oa1D/avKpjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1724369540; x= 1724455940; bh=CHkpjzhiW35JO4FbEJYMxMf8dw9T8D7tz7WpNfXjdA0=; b=T 9sSQ5Hh6ljV9Nemp4MJLxMpd1hIh3v7eJl2MPt5nMzB+84NdnCuYt2bezcHi3PPD oL8tqPcWEJMJHgkE0CLl3t5edJ00lggzHTttDmLk2NY3xOLo3HpzHhxocwlThEZ+ ZUYrx7ewVj83JJp5+BIYRzY+puDKfrxIIzTrBitePcm4TqOj0/QjLDrTOlgFo8TQ fPa65MFP0LibqHdDgUlZhHbmFQ11i0qSL2y8aChPiHa85BZZw/RCK+9xQ/1Iz0Qr 9MJF11k1RzXmIX1IWCBqea1zUMMGKubdlEHG2UW1ob5l0OPAAW6rsUX9cMRcRGnN LgCUpLxueiOG0IGuNBIpg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvuddgvdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffhvfevfhgjtgfgsehtkeertddtvdej necuhfhrohhmpefusghosgcuoehssghosgesqhhurggurhgrthhumhdqsghrrggttggrsh drtghomheqnecuggftrfgrthhtvghrnheptdetgfdvhffhhfetjeekhfekuddtieevvdet leekudfgleeggeeileejvedtvddtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepshgsohgssehquhgrughrrghtuhhmqdgsrhgrtggtrghsrdgt ohhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hruhhirdguvghsohhushgrsehitghlohhuugdrtghomhdprhgtphhtthhopehpghhsqhhl qdgrughmihhnsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhope hssghosgesqhhurggurhgrthhumhdqsghrrggttggrshdrtghomh X-ME-Proxy: Feedback-ID: i374947ac:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 19:32:19 -0400 (EDT) Message-ID: Date: Thu, 22 Aug 2024 17:32:18 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: checking for a NULL date in a partitioned table kills performance From: Sbob To: Rui DeSousa Cc: "pgsql-performance@lists.postgresql.org" References: <1c1a23bc-fa35-4a45-8017-62791506d91b@quadratum-braccas.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/22/24 5:26 PM, Sbob wrote: > > On 8/22/24 5:06 PM, Rui DeSousa wrote: >> >>> On Aug 22, 2024, at 5:44 PM, Sbob wrote: >>> >>> All; >>> >>> I am running a select from a partitioned table. The table (and all >>> the partitions) have an index on contract_date like this: >>> CREATE INDEX on part_tab (contract_date) where contract_date > >>> '2022-01-01'::date >>> >>> The table (including all partitions) has 32million rows >>> The db server is an aurora postgresql instance with 128GB of ram and >>> 16 vcpu's >>> >>> The shared buffers is set to 90GB and effective_cache_size is also 90GB >>> I set default_statistics_target to 1000 and ram a vacuum analyze on >>> the table >>> >>> I am selecting a number of columns and specifying this where clause: >>> >>> WHERE ( >>>                      (contract_date IS NULL) >>>                      OR >>>                      (contract_date > '2022-01-01'::date) >>>               ) >>> >>> This takes 15 seconds to run and an explain says it's doing a table >>> scan on all partitions (the query is not specifying the partition key) >>> If I change the where clause to look like this: >>> >>> WHERE ( >>>                    (contract_date > '2022-01-01'::date) >>>               ) >>> >>> Then it performs index scans on all the partitions and runs in about >>> 600ms >>> >>> If i leave the where clause off entirely it performs table scans of >>> the partitions and takes approx 18 seconds to run >>> >>> I am trying to get the performance to less than 2sec, >>> I have tried adding indexes on the table and all partitions like this: >>> CREATE INDEX ON table (contract_date NULLS FIRST) ; >>> but the performance with the full where clause is the same: >>> >>> WHERE ( >>>                      (contract_date IS NULL) >>>                      OR >>>                      (contract_date > '2022-01-01'::date) >>>               ) >>> >>> runs in 15 seconds and scans all partitions >>> >>> I also tried indexes i=on the table and all partitions like this: >>> CREATE INDEX ON table (contract_date) WHERE contract_date IS NULL; >>> >>> but I get the same result, table scans on all partitions and it runs >>> in 15 seconds >>> >>> Any help or advice ? >>> >>> Thanks in advance >>> >>> >> What is contract_date and when will it be null? > > > it's a date data type and it allows NULL's not sure why, this is a > client's system > > 29 million of the 32 million rows in the table have NULL for contract_date