Note: these pages are no longer maintainedNever the less, much of the information is still relevant.Beware, however, that some of the command syntax is from older versions, and thus may no longer work as expected. Also: external links, from external sources, inside these pages may no longer function. |
Recipe #10: |
|
2011 January 28 |
Previous Slide | Table of Contents | Next Slide |
A Spatial Index more or less
is like any other Index: i.e. the intended role of any Index is to
support really fast search of selected items within an huge
dataset.
Simply think of some huge textbook: searching some specific item by reading the whole book surely is painful, and may require a very long time. But you can actually look at the textbook's index, then simply jumping to the appropriate page(s). Any DB index plays exactly the same identical role. Anyway, searching Geometries falling within a given search frame isn't the same of searching a text string or a number: so a different Index type is required. i.e. a Spatial Index. |
Common misconceptions and misunderstandings “I have a table storing several zillion points disseminated all around the world:drawing a map was really painful and required a very long time. Then I found somewhere some useful hint, so I've created a Spatial Index on this table. And now my maps are drawn very quickly, as a general case. Anyway I'm strongly puzzled, because drawing a worldwide map still takes a very long time. Why the Spatial Index doesn't work on worldwide map ?” The answer is elementary simple: the Spatial Index can speed up processing only when a small selected portion of the dataset has to be retrieved. But when the whole (or a very large part of) dataset has to be retrieved, obviously the Spatial Index cannot give any speed benefit. To be pedantic, under such conditions using the Spatial Index introduces further slowness, because inquiring the R*Tree imposes a strong overhead. Conclusion: the Spatial Index isn't a magic wand. The Spatial Index basically is like a filter.
|
SQLite's R*Tree implementation details SQLite supports a first class R*Tree: anyway, some implementation details surely may seem strongly exotic for users accustomed to other different Spatial DBMS (such as PostGIS and so on).Any R*Tree on SQLite actually requires four strictly correlated tables:
|
SpatiaLite's support for R*Tree Any SpatiaLite Spatial Index fully relies on a corresponding SQLite R*Tree.Anyway SpatiaLite smoothly integrates the R*Tree, so to make table handling absolutely painless:
Accordingly to all this, using a Spatial Index requires performing a JOIN, and (may be) defining a sub-query. You can find lots of examples about Spatial Index usage on SpatiaLite into the Haute Cuisine section. |
SELECT CreateSpatialIndex('local_councils', 'geometry');
SELECT CreateSpatialIndex('populated_places', 'geometry'); |
SELECT DisableSpatialIndex('local_councils', 'geometry'); |
SpatiaLite supports a second alternitive Spatial
Index based on MBR-caching. This one simply is a historical legacy, so using MBR-caching is strongly discouraged. |
Previous Slide | Table of Contents | Next Slide |
Author: Alessandro Furieri a.furieri@lqt.it | |
This work is licensed under the Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license. | |
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. |