<div dir="ltr">(cross-post from postgres list)<br><div><div class="gmail_quote"><div dir="ltr"><div><div><div><div><div><div>Hey dear list,<br><br></div>I'd like to partition geographical (geometry) data with postgres mechanism.<br></div><div>(my usage is in fact related to pointcloud, but I use geometry as a work around)<br></div>From example I read on constraint, nothing should prevent it from working<br></div>Here is a self contained example, the planner doesn"t seems to use the constraint_exclusion mechanism, whatever the constraint<br><br></div>Thanks, <br></div>Cheers,<br></div>Rémi-C<br><div><div><div><div><div><div><br>------<br><br>CREATE SCHEMA IF NOT EXISTS test_partitionning;<br>SET search_path TO test_partitionning, public ;<br><br>DROP TABLE IF  EXISTS test_father CASCADE;<br>CREATE TABLE test_father  (<br>    gid SERIAL PRIMARY KEY<br>    , geom geometry<br>); <br><br>create table test_child_1 (<br>    check (geometry_overlaps(geom,ST_Expand(ST_MakePoint(10,10),10  ) ) )<br>    ,check ( geom&&ST_Expand(ST_MakePoint(10,10),10  ) )  <br>    , CHECK (ST_X(geom) BETWEEN 0 AND 20)<br>    , CHECK (ST_Y(geom) BETWEEN 0 AND 20)<br>    , CHECK (  ST_Intersects(geom, ST_Expand(ST_MakePoint(10,10),10  ))  )<br>) inherits (test_father);<br>--CREATE INDEX ON test_child_1 USING GIST(geom);<br><br>create table test_child_2 (<br>    check (geometry_overlaps(geom,ST_Expand(ST_MakePoint(30,10),10  ) ) )<br>    ,check ( geom&&ST_Expand(ST_MakePoint(30,10),10  ) ) <br>    , CHECK (ST_X(geom) BETWEEN 20 AND 40)<br>    , CHECK (ST_Y(geom) BETWEEN 0 AND 20)<br>    , CHECK (  ST_Intersects(geom, ST_Expand(ST_MakePoint(30,10),10  ))  )<br>    ) inherits (test_father);<br>--CREATE INDEX ON test_child_2 USING GIST(geom);<br><br><br>INSERT INTO test_child_1 (geom)<br>SELECT ST_MakePoint(s1/10.0+random(),s2/10.0+random())<br>FROM generate_series(1,90) AS s1, generate_series(1,90) AS s2;<br><br>INSERT INTO test_child_2 (geom)<br>SELECT ST_MakePoint(s1/10.0+random(),s2/10.0+random())<br>FROM generate_series(200,300) AS s1, generate_series(1,90) AS s2;<br><br><br>SHOW constraint_exclusion;<br>SET constraint_exclusion TO partition;<br><br><br>WITH area_of_interest AS (<br>    SELECT ST_Buffer(ST_MakePoint(5,5),1) as buf<br>)<br>SELECT *<br>FROM area_of_interest, test_father <br>WHERE  -- geom && buf <br>    ST_X(geom) BETWEEN ST_XMin(buf) AND ST_Xmax(buf)<br>    AND ST_Y(geom) BETWEEN ST_YMin(buf) AND ST_Ymax(buf) ;<br><br> <br>SELECT *<br>FROM  test_father , ST_Buffer(ST_MakePoint(5,5),1) as buf<br>WHERE  <br>    ST_X(geom) BETWEEN ST_XMin(buf) AND ST_Xmax(buf)<br>    AND ST_Y(geom) BETWEEN ST_YMin(buf) AND ST_Ymax(buf);<br>------<br></div></div></div></div></div></div></div>
</div><br></div></div>