postgis spatial index and HQL

6 messages Options
Embed this post
Permalink
Vincent Nouguier

postgis spatial index and HQL

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

Hello,

 

I use hibernatespatial with a Postgres/Postgis database.

I use the HQL interface to query the database.

When I set the hibernate show_sql property to true, I can see that the spatial index is not used as explained in the tutorial (example with Criteria).

 

            @Test

            public void testIndexSpatial() throws com.vividsolutions.jts.io.ParseException{

                        String hql = "SELECT COUNT(md) FROM MDMetadata md LEFT JOIN md.identifications as a0 LEFT JOIN a0.boundingPolygons as a1 WHERE intersects(a1.geometry, :g0) = true" ;

                        Query query = ((Session)getEntityManager().getDelegate()).createQuery(hql);

                        CustomType geometryType = new CustomType(GeometryUserType.class, null);

                        WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING_SINGLE), 4326));

                        query.setParameter("g0", reader.read("POLYGON((-180 -90,-180 90,180 90, 180 -90, -180 -90))"), geometryType);

 

                        Number result = (Number)query.uniqueResult();

                        System.out.println(result);

            }

 

 

Hibernate: select count(mdmetadata0_.id) as col_0_0_ from public.md_metadata mdmetadata0_ inner join public.mf_metadata mdmetadata0_1_ on mdmetadata0_.id=mdmetadata0_1_.id left outer join public.md_identification identifica1_ on mdmetadata0_.id=identifica1_.fk_md_metadata left outer join public.ex_boundingpolygon boundingpo2_ on identifica1_.id=boundingpo2_.fk_dataident where intersects(boundingpo2_.geom, ?)=true

 

I expected … where boundingpo2_.geom && ? AND intersects(boundingpo2_.geom, ?)=true

 

Any Idea ?

 

Thanks a lot.

 

Vincent


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen

Re: postgis spatial index and HQL

Reply Threaded More More options
Print post
Permalink
Hi Vincent,


On 13 May 2009, at 15:05, Nouguier, Vincent wrote:

>
> I use hibernatespatial with a Postgres/Postgis database.
>
> I use the HQL interface to query the database.
>
> When I set the hibernate show_sql property to true, I can see that  
> the spatial index is not used as explained in the tutorial (example  
> with Criteria).
>
>

That is true, except that this is no longer relevant for later  
versions of Postgis (>= 1.3). The Postgis documentation states that:  
"As of PostGIS 1.3.0, most of the Geometry Relationship Functions,  
with the notable exceptions of ST_Disjoint and ST_Relate, include  
implicit bounding box overlap operators." So using the '&&' operator  
has become superfluous.

Regards,

Karel
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Vincent Nouguier

Re: postgis spatial index and HQL

Reply Threaded More More options
Print post
Permalink
Ok, I am using Postgis 1.3.3.
When I explain the SQL request, I always see that a sequential scan is used.
I will check that my postgis is well configured, load it with lots of data and make other tests in the next days.

Thanks for your reply.
Vincent Nouguier

Re: postgis spatial index and HQL

Reply Threaded More More options
Print post
Permalink
Hi,

I loaded a database with 200.000 items, check that it is well configured.
I have the same behaviour, intersects() never use the overlap operator
According to what is described at http://www.bostongis.com/postgis_intersection_intersects.snippet, I tried to use ST_intersects and I could check that the spatial is really used and really speeds up my request (25% better)

Would it be possible to choose the spatial operator as a property in hibernate configuration ? Any other idea ?
Karel Maesen

Re: postgis spatial index and HQL

Reply Threaded More More options
Print post
Permalink
Hi,

On 11 Jun 2009, at 10:45, Vincent Nouguier wrote:

> I loaded a database with 200.000 items, check that it is well  
> configured.
> I have the same behaviour, intersects() never use the overlap operator
> According to what is described at
> http://www.bostongis.com/postgis_intersection_intersects.snippet
> http://www.bostongis.com/postgis_intersection_intersects.snippet ,  
> I tried
> to use ST_intersects and I could check that the spatial is really  
> used and
> really speeds up my request (25% better)

Thanks for this info. I understood the Postgis documentation  
differently, and so this was news to me.

>
> Would it be possible to choose the spatial operator as a property in
> hibernate configuration ? Any other idea ?

I was thinking of adding a new Postgis dialect that uses the newer  
ST_* functions instead of the older functions.

Regards,

Karel
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Vincent Nouguier

Re: postgis spatial index and HQL

Reply Threaded More More options
Print post
Permalink
Karel Maesen wrote:
...
I was thinking of adding a new Postgis dialect that uses the newer  
ST_* functions instead of the older functions.
It would be fine for me.
Is there a roadmap for hibernate-spatial ? When can I expect to get a new version including the new operators ? Will I have to get source code through SVN or will you make a postgis-1.0.M3 available ?

Regards,

Vincent