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 1oT8gG-0002qn-E8 for pgsql-admin@arkaria.postgresql.org; Tue, 30 Aug 2022 21:21:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oT8gF-0001nr-9U for pgsql-admin@arkaria.postgresql.org; Tue, 30 Aug 2022 21:21:55 +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 1oT8gE-0001nh-Vt for pgsql-admin@lists.postgresql.org; Tue, 30 Aug 2022 21:21:54 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oT8gC-0006C0-Nx for pgsql-admin@lists.postgresql.org; Tue, 30 Aug 2022 21:21:53 +0000 Received: by mail-pl1-x634.google.com with SMTP id v5so6109870plo.9 for ; Tue, 30 Aug 2022 14:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc; bh=HPWryPM6r2tYIf/MNx4V8n7aoRFKYivIfEUx2egxMng=; b=YUco4s8HYlto0G3iSqoCmWwLwCHpJczVkI5w3v9cGhFqwM5gbNVeriyAky+y3n+8v/ d2e3+JtlpvED8jLNykFvUCTMhZGCQH1Xw5TX+qhfD8LSNLJIZp+HfK0dq1KmcEzd212s Q9mOM1ofCyt9ul1MrPEiu4ObyXLzKSFWIFg7aBd4sxFE3U3R1RzQB7I5Izn6+ws+KU0B 3Y3yKZnUPP8RfJ+3/yGCy7oy2Sq0rsqkUYyy3MJleBCnro6bGS4I6i1n6ycYCLNs1uD3 XFbyHj2F1WMzzec7qWolsxyi0eSYh5uyvevvTnHy5W3JwRcOGMaoL4N94xJgy3TNp+An RKbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc; bh=HPWryPM6r2tYIf/MNx4V8n7aoRFKYivIfEUx2egxMng=; b=N43pSmGUxiJTBRNRCBK7zoFdsPppXVBAdCAGY3tGnJUZrpqLJF0PB1yj/cT5DFfX6T 5hoKk34xUt/laNYGP8E7JLRmR1sKYK60WwCkj8EVjb6Nvv9QrGk4epRLVyFVv9RivScx V/CyAMgCg/pajcqv605B3RgRMb9bOqyX2O9Q3wgDzRhe9911RWYon/kkKrwY66nsOI/f 5DdD+AwHYENM9FQITuEmTrDArz5ngVupoTqpaIBxZboRyW8dMjFeQhE7PIyOIPHxjhx5 4NlM3uttF0udKXpfPchp4e5SyeymJwXgoSWXIyCX7tJJ3sGBh1TkmP8gCabmY7ob1Tl1 RahQ== X-Gm-Message-State: ACgBeo3Qp6gj3nDRd9x8eSCtm6X6Ngz74ub2ScBTr88oeZkEkxe8LgtM EpG9ZYyb73Nup55H+LLLD5U= X-Google-Smtp-Source: AA6agR5RqxtXlZg0cg1dYkAdX7S+uakdDodM54sMIqw+ECHTDS2r5216bsskCq0ebEkqLF2IxlDMSg== X-Received: by 2002:a17:90a:9309:b0:1fa:d28b:3751 with SMTP id p9-20020a17090a930900b001fad28b3751mr153953pjo.189.1661894511529; Tue, 30 Aug 2022 14:21:51 -0700 (PDT) Received: from smtpclient.apple ([4.42.177.235]) by smtp.gmail.com with ESMTPSA id z10-20020a62d10a000000b00537d0ed05ecsm9332824pfg.216.2022.08.30.14.21.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Aug 2022 14:21:51 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Teja Jakkidi Mime-Version: 1.0 (1.0) Subject: Re: Performance issue after creating partitions Date: Tue, 30 Aug 2022 14:21:50 -0700 Message-Id: <6F2BE85B-F6D0-4D4C-9DEA-EEE09D97B8EF@gmail.com> References: <738BC8F9-5F1E-4E8F-8EB9-DEE6EDAA740B@gmail.com> Cc: pgsql-admin In-Reply-To: <738BC8F9-5F1E-4E8F-8EB9-DEE6EDAA740B@gmail.com> To: Doug Reynolds , gogala.mladen@gmail.com X-Mailer: iPhone Mail (19G71) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Anyone ever encountered the below situation as what I am noticing with parti= tions? Thanks, Teja. J. > On Aug 26, 2022, at 11:46 AM, Teja Jakkidi wrot= e: >=20 > =EF=BB=BFThank you, Doug and Malden for your inputs. >=20 > As suggested by Doug I tried replacing the trunc() with below command: > =E2=80=9C order_date >=3D to_date(..) and order_date < to_date(..) + inter= val '1' day=E2=80=9D >=20 > What happens here is: My query has 2tables : A and B, both are having an i= nner join on company code and order date. We have A.Company_code, A.order_da= te filter in the where condition which was having trun() previously but now I= replaced it with the command suggested by Doug. The company_code filter is w= orking for both tables A and B, the query is searching only the partitions p= articular to that country code. However for order_date condition, the partit= ions for A table are being utilized correctly I.e the query is searching dir= ectly in only one partition based on that date. But for table B, it is still= searching all the partitions, it is not applying the where A.order_date con= dition for B tables partitions while searching. > I do not understand why the A.order_date filter is not being applied to ta= ble B where as A.company_code is being applied to both tables. >=20 > Thanks and Regards, > J. Teja Sri. >=20 >> On Aug 24, 2022, at 5:52 PM, Doug Reynolds wrote: >>=20 >> =EF=BB=BFYou need to change your query to not use the trunc. The TRUNC s= tatement forces it to trunc every row in the table. =20 >>=20 >> If you do order_date >=3D to_date(..) and order_date < to_date(..) + inte= rval '1' day, it will use the partition range to narrow down to the correct p= artition first. >>=20 >> Sent from my iPhone >>=20 >>>> On Aug 24, 2022, at 6:41 PM, Teja Jakkidi wr= ote: >>>=20 >>> =EF=BB=BFHello Admin team, >>>=20 >>> We have a Postgres 13 server set up on Google Cloud. Recently we created= partitions as below for the tables: >>> Range on =E2=80=98order_date=E2=80=99 column >>> List on =E2=80=98country_code=E2=80=99 column >>>=20 >>> Quarterly partitions for range. >>>=20 >>> Order date column is a time stamp column and when we are using this colu= mn as a filter in where condition : trunc(order_date) =3D to_date(=E2=80=992= 022-04-01=E2=80=99,=E2=80=99YYYY-MM-DD=E2=80=99), the query scans all the pa= rtitions dated back from the year 2000. So, instead of going to the 2022 Q2 p= artition directly, the query is scanning all the partitions. >>> But when we remove the trunc() function and just specify order_date =3D=E2= =80=982022-04-01 07:02:30=E2=80=99, this works as expected. It goes to the c= orrect partition directly and gets the data.=20 >>> Can Anyone help me on what=E2=80=99s happening in the first case and why= all the partitions are being scanned? >>> For the first case, when there is a non partition table, it is behaving w= ay better. >>>=20 >>> Thanks, >>> J. Teja. >>>=20 >>=20