Hi,
it seems the usage of ST_Envelope(geom) might cause troubles after all,
and we probably don't want that enabled by default (ufff....)
I was playing with a China wide OSM download, and querying a small
area on Hong Kong, after running "vacuum analyze", and ensuring
the indexes are there, gives me the following:
osm=# \timing
Timing is on.
osm=# SELECT
"id","name",encode(ST_AsBinary(ST_Force_2D("geometry")),'base64') as
"geometry" FROM "import"."osm_roads" WHERE "geometry" &&
ST_GeomFromText('POLYGON ((12686441.96088916 2574141.200893554,
12686441.96088916 2575819.375869846, 12688531.453260839 2575819.375869846,
12688531.453260839 2574141.200893554, 12686441.96088916
2574141.200893554))', 3857);
Time: 1,649 ms
osm=# SELECT
"id","name",encode(ST_AsBinary(ST_Force_2D("geometry")),'base64') as
"geometry" FROM "import"."osm_roads" WHERE ST_envelope("geometry") &&
ST_GeomFromText('POLYGON ((12686441.96088916 2574141.200893554,
12686441.96088916 2575819.375869846, 12688531.453260839 2575819.375869846,
12688531.453260839 2574141.200893554, 12686441.96088916
2574141.200893554))', 3857);
Time: 1076,481 ms
That is, wrapping the geometry with ST_Envelope makes the query 500 times
slower... erk!
I looked into it, and it seems that for this database wrapping with
ST_Envelope makes the DB
use sequential search:
----------------------------------------------------------------------------------------------
Seq Scan on osm_roads (cost=0.00..122097.24 rows=229722 width=243)
Filter: (st_envelope(geometry) &&
'0103000020110F00000100000005000000A09ABF3E8D32684146E1B6999EA34341A09ABF3E8D326841CC801CB0E5A64341E01C816E92336841CC801CB0E5A64341E01C816E9233684146E1B6999EA34341A09ABF3E8D32684146E1B6999EA34341'::geometry)
(2 rows)
whilst without ST_Envelope around, it's a index search:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on osm_roads (cost=4.61..180.05 rows=42 width=243)
Recheck Cond: (geometry &&
'0103000020110F00000100000005000000A09ABF3E8D32684146E1B6999EA34341A09ABF3E8D326841CC801CB0E5A64341E01C816E92336841CC801CB0E5A64341E01C816E9233684146E1B6999EA34341A09ABF3E8D32684146E1B6999EA34341'::geometry)
-> Bitmap Index Scan on osm_roads_geom (cost=0.00..4.60 rows=42
width=0)
Index Cond: (geometry &&
'0103000020110F00000100000005000000A09ABF3E8D32684146E1B6999EA34341A09ABF3E8D326841CC801CB0E5A64341E01C816E92336841CC801CB0E5A64341E01C816E9233684146E1B6999EA34341A09ABF3E8D32684146E1B6999EA34341'::geometry)
(4 rows)
So... I guess we should flip the sys var the other way? Or make it into
a store parameter again (sigh)?
I believe road networks are going to be more popular/common than
datasets with huge polygons, that why I'm suggesting to turn it off
by default.
Cheers
Andrea
--
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information.
==
Ing. Andrea Aime
@geowolf
Technical Lead
GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549
http://www.geo-solutions.it
http://twitter.com/geosolutions_it
*AVVERTENZE AI SENSI DEL D.Lgs. 196/2003*
Le informazioni contenute in questo messaggio di posta elettronica e/o
nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il
loro utilizzo è consentito esclusivamente al destinatario del messaggio,
per le finalità indicate nel messaggio stesso. Qualora riceviate questo
messaggio senza esserne il destinatario, Vi preghiamo cortesemente di
darcene notizia via e-mail e di procedere alla distruzione del messaggio
stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso,
divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od
utilizzarlo per finalità diverse, costituisce comportamento contrario ai
principi dettati dal D.Lgs. 196/2003.
The information in this message and/or attachments, is intended solely for
the attention and use of the named addressee(s) and may be confidential or
proprietary in nature or covered by the provisions of privacy act
(Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection
Code).Any use not in accord with its purpose, any disclosure, reproduction,
copying, distribution, or either dissemination, either whole or partial, is
strictly forbidden except previous formal approval of the named
addressee(s). If you are not the intended recipient, please contact
immediately the sender by telephone, fax or e-mail and delete the
information in this message that has been received in error. The sender
does not give any warranty or accept liability as the content, accuracy or
completeness of sent messages and accepts no responsibility for changes
made after they were sent or for other risks which arise as a result of
e-mail transmission, viruses, etc.
-------------------------------------------------------
------------------------------------------------------------------------------
_______________________________________________
GeoTools-Devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel