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 1ngo4v-0006ez-Uh for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Apr 2022 13:39:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ngo4u-0006sr-OS for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Apr 2022 13:39:36 +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 1ngo4u-0006si-CU for pgsql-hackers@lists.postgresql.org; Tue, 19 Apr 2022 13:39:36 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ngo4p-0006Oi-Ue for pgsql-hackers@postgresql.org; Tue, 19 Apr 2022 13:39:35 +0000 Received: by mail-il1-x133.google.com with SMTP id y11so5057527ilp.4 for ; Tue, 19 Apr 2022 06:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Nb5/C7N4x5f/WNS68iyMUlrs+JG5rE4l0m1NsPUskow=; b=XIVRL9SIK3Z46Gui5czDCdpe1RvaNwRPo3bkA6Lp/L1gUyMNqHlp8q0hVVBuBlhlVm 0HQXmSNSJkyACpNwg5rJ8GqBajGuLjUPOjFftuLR1aZSjLhfv+eCW53aptO3TdAhZ5qy mNDTv9chWmBUPMCslheKXR7keyIKoKYC+jw8F2qfmc/lFYV877dtAP4F7Klr0bPjZNd5 fpNnHjr4JWOEPfZmuFtCSz3fmpDpCfM+ipO2oaY509gSfrAIpcL/Flcw3kvETyHKup6z glTBi4Gw3uk24QNiJPoytU6bzCsPxgMygIX+d+hpZ6q3qiCr+aGWpqWN69gMpvWVtZCH 2vRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Nb5/C7N4x5f/WNS68iyMUlrs+JG5rE4l0m1NsPUskow=; b=yQlfVVK2kvFBAznXiJQVK+T4/4NOvLyR0lsUbhK8kWYUu2sTPuRHBm906j1SKZu/Yj eTtBzj6oV70ZXTQwAU+C9mCqi6keYlR1YXMbF8hD7zU8jdjlYaRJjwzBkI0fhVqjxcxd iQiiqDCuMonUJMgSH5/wASZOzpnFcr6TboBEVwTPX9fcJ0fgxR29I5/zN0psa5CiHEwZ oxNHQ/9GHypG4/lRJH3NDnjhJk9z1MP1RXLBHCbXKzkN8EzqE8xR3FsKmMHbhDdIDUKy 5AYLiSZ8svBZq3wYiomqE/NsvHgrphZkwLSnB7QwwnvUZ/x2OAm8qsKt7Auyl6P9Iacr OjkA== X-Gm-Message-State: AOAM531Ib7YbakOCEvY4LPVgRqXtxzCfP+n9/ifsQ3T+XqPbh0PMJ7AG BG2JLvgbn1rQnH7zbJvpRM9YmP1Hv1r+yQ== X-Google-Smtp-Source: ABdhPJwx8q3Jkm1kEZvsLjZe8qH9eux4LWOpyY9UMCiKj20wnbCLcggLU3fYxLcU1q2s/9ZJmtabwQ== X-Received: by 2002:a05:6e02:e11:b0:2cc:3377:416 with SMTP id a17-20020a056e020e1100b002cc33770416mr3240991ilk.308.1650375569649; Tue, 19 Apr 2022 06:39:29 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id r4-20020a924404000000b002c9dc82ab11sm8978942ila.79.2022.04.19.06.39.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Apr 2022 06:39:29 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id A58E0800B67; Tue, 19 Apr 2022 08:39:28 -0500 (CDT) Date: Tue, 19 Apr 2022 08:39:28 -0500 From: Justin Pryzby To: Mats Taraldsvik Cc: pgsql-hackers@postgresql.org Subject: Re: Fwd: Declarative partitioning and partition pruning/check (+postgis) Message-ID: <20220419133928.GG26620@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Apr 19, 2022 at 02:39:12PM +0200, Mats Taraldsvik wrote: > I'm re-trying this email here, as there were no answers in the psql-general > list. Hope that's ok. (please cc me when answering as I'm not subscribed > (yet) ) -hackers is for development and bug reports, so this isn't the right place. If you had mailed on -performance, I would have responded there. > The first part, getting the rows into the "right" partition isn't > especially interesting: Reduce every geometry to a point, and use the x and > y coordinates separately in a range partition. This is possible with > PostgreSQL as it is a normal range partition on double. I agree that it's conceptually simple. Have you tried it ? ts=# CREATE TABLE t(a geometry) PARTITION BY RANGE(st_x(a)); ts=# CREATE TABLE t1 PARTITION OF t FOR VALUES FROM (1)to(2); ... > The second part is more interesting. Whenever the spatial index is > (implicitly or directly) used in a query, the partition pruning step > (during execution) checks the spatial index's root bounding box to > determine if the partition can be skipped. > > Is this possible to achieve in PostgreSQL? There is already a function in > PostGIS to get the spatial index root bounding box > (_postgis_index_extent(tbl regclass, col text)), but I think the real issue > is that the actual SQL query might not even call the index directly (SELECT > * FROM a WHERE ST_Intersects(mygeom, a.geom) - the ST_Intersects function > uses the index internally). For partition pruning to work, a query would have to include a WHERE clause which is sufficient to prune the partitions. If the table is partitioned by RANGE(st_x(col)), then the query would need to say "st_x(col) <= 11" (or similar). If st_x() is compared to a constant, then partition pruning can happen at planning time; if not, it might (since v11) happen at execution time. https://www.postgresql.org/docs/current/ddl-partitioning.html#DDL-PARTITION-PRUNING I doubt your queries would have the necesarily condition for this to do what you want. It would be easy to 1) try; and then 2) post a question with the necessary SQL to set up the test, and show what you've tried. -- Justin