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 1oReMX-0006Ep-EC for pgsql-admin@arkaria.postgresql.org; Fri, 26 Aug 2022 18:47:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oReLX-0003W5-Ml for pgsql-admin@arkaria.postgresql.org; Fri, 26 Aug 2022 18:46:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oReLX-0003Vw-Az for pgsql-admin@lists.postgresql.org; Fri, 26 Aug 2022 18:46:23 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oReLQ-0005fi-Rc for pgsql-admin@lists.postgresql.org; Fri, 26 Aug 2022 18:46:22 +0000 Received: by mail-pl1-x631.google.com with SMTP id p18so2294707plr.8 for ; Fri, 26 Aug 2022 11:46:16 -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=J6JYG/uuuTsyQkhOhKU/f1grfPs53fGNBAKm9QFbuho=; b=MfGF08nJ+16n3gX3LzMzjzolIs+EHpdSo4gsC1jAHQaAprEL9SDzgr6rcBMXGE3io0 Y6Y8hqdxC4TEy9GoPd8OJG6BanTWbhKzi+gjgpUF+KQa/721TTUdYtH9HejyFbURmNGU ZiIn5HXjjw7iuYx7hNtYEQkxWPlYCGAhXXkR93c4VqwFfat5sZIv0ywqjekeqgGggT/A 4pAGBMrd93Vv7AH5PYGCNY4HlLv9QqJmbJwcITSp6mCb76SPSvFUliSEgZKNeIQ3lqYn 1ld2jSkVY7W9PxbUNJ/alcPe80rWu59ZpXMj+YmHV4AhDPgCGlJG1kHUwG/kcFWjcGEi oNKg== 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=J6JYG/uuuTsyQkhOhKU/f1grfPs53fGNBAKm9QFbuho=; b=FoGjkQ124sWx4c4Juz5A1PzOb5dxQ2jJwcHZhcUu/SA6kXsahYSp3c+Iz4UjTvkRRi SAbZpwKuSbmTOZy0D2WMkxPzFY/AW/AzDh7oMKT894u/h7WSvK57DtAYUf9O+jXoCUy6 pXuk4VJPXtQx26C5bAPyA/2XEPxviFotKM1xXJo8qR+EdUVi630+nKxYLVJkj32Awtwp 2fNgH4gzuqaW8MzwJbLSnr0w+8LaAGX0777n/4xuJ4QIDQzBgAAYWMZWNAuUKStA/NFk aTGjlgNXzeNGg57DKyWZIuUTTZ7dITMNqb3fiNIwxlodqrJtU2DqSu/Nz6/gHP0pmt6r sufw== X-Gm-Message-State: ACgBeo1Lc1Z5d82NKIzazPb/220Ya0mHe1gLh4fs4xuAPMan8udbwKeu +y6EUHErSxwAlK1eWIOi3l8= X-Google-Smtp-Source: AA6agR5T4vn1WZ3rEuflzw9zsZfipW2ls136JqMv10Q36xX5sNZpI5qPMUUOgnucV3/faJeFabxF8A== X-Received: by 2002:a17:90a:7805:b0:1fa:bdab:7d59 with SMTP id w5-20020a17090a780500b001fabdab7d59mr5561978pjk.37.1661539574850; Fri, 26 Aug 2022 11:46:14 -0700 (PDT) Received: from smtpclient.apple (2603-8001-3e43-3464-d909-4dad-fce0-0fb6.res6.spectrum.com. [2603:8001:3e43:3464:d909:4dad:fce0:fb6]) by smtp.gmail.com with ESMTPSA id y12-20020a17090322cc00b00172dd10f64fsm1918088plg.263.2022.08.26.11.46.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Aug 2022 11:46:14 -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: Fri, 26 Aug 2022 11:46:12 -0700 Message-Id: <738BC8F9-5F1E-4E8F-8EB9-DEE6EDAA740B@gmail.com> References: <01000182d27cd99e-5a38a3c8-7060-4969-a24b-cf879b9f5bf7-000000@email.amazonses.com> Cc: pgsql-admin In-Reply-To: <01000182d27cd99e-5a38a3c8-7060-4969-a24b-cf879b9f5bf7-000000@email.amazonses.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 Thank you, Doug and Malden for your inputs. 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(..) + interva= l '1' day=E2=80=9D What happens here is: My query has 2tables : A and B, both are having an inn= er join on company code and order date. We have A.Company_code, A.order_date= filter in the where condition which was having trun() previously but now I r= eplaced it with the command suggested by Doug. The company_code filter is wo= rking for both tables A and B, the query is searching only the partitions pa= rticular to that country code. However for order_date condition, the partiti= ons for A table are being utilized correctly I.e the query is searching dire= ctly in only one partition based on that date. But for table B, it is still s= earching all the partitions, it is not applying the where A.order_date condi= tion for B tables partitions while searching. I do not understand why the A.order_date filter is not being applied to tabl= e B where as A.company_code is being applied to both tables. Thanks and Regards, J. Teja Sri. > 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 st= atement forces it to trunc every row in the table. =20 >=20 > If you do order_date >=3D to_date(..) and order_date < to_date(..) + inter= val '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 wrot= e: >>=20 >> =EF=BB=BFHello Admin team, >>=20 >> We have a Postgres 13 server set up on Google Cloud. Recently we created p= artitions 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 colum= n as a filter in where condition : trunc(order_date) =3D to_date(=E2=80=9920= 22-04-01=E2=80=99,=E2=80=99YYYY-MM-DD=E2=80=99), the query scans all the par= titions 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 a= ll 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