Optimizing Spatial Analysis •Fetching spatial data in internal format: •Fetching spatial data in WKT format: •Fetching spatial data in WKB format: CREATE TABLE geom2 (g GEOMETRY) SELECT g FROM geom; SELECT ST_AsText(g) FROM geom; SELECT ST_AsBinary(g) FROM geom; Fetching geometry values using internal format can be useful in table-to-table transfers: The  ST_AsText()  function converts a geometry from internal format to a WKT string. The  ST_AsBinary()  function converts a geometry from internal format to a  BLOB  containing the WKB value. For  MyISAM  and  InnoDB  tables, search operations in columns containing spatial data can be optimized using  SPATIAL  indexes. The most typical operations are: MySQL uses  R-Trees with quadratic splitting  for  SPATIAL  indexes on spatial columns. A  SPATIAL index is built using the minimum bounding rectangle (MBR) of a geometry. For most geometries, the MBR is a minimum rectangle that surrounds the geometries. For a horizontal or a vertical linestring, the MBR is a rectangle degenerated into the linestring. For a point, the MBR is a rectangle degenerated into the point. It is also possible to create normal indexes on spatial columns. In a non- SPATIAL  index, you must declare a prefix for any spatial column except for  POINT  columns. MyISAM  and  InnoDB  support both  SPATIAL  and non- SPATIAL  indexes. Other storage engines support non- SPATIAL  indexes, as described in Section 13.1.15, “CREATE INDEX Statement” . For  InnoDB  and  MyISAM  tables, MySQL can create spatial indexes using syntax similar to that for creating regular indexes, but using the  SPATIAL  keyword. Columns in spatial indexes must be declared  NOT NULL . The following examples demonstrate how to create spatial indexes: CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326); CREATE SPATIAL INDEX g ON geom (g); CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326); ALTER TABLE geom ADD SPATIAL INDEX(g); CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326, SPATIAL INDEX(g)); •With  CREATE INDEX : •With  ALTER TABLE : •With  CREATE TABLE : 2064 11.4.10 Creating Spatial Indexes 11.4.9 Optimizing Spatial Analysis •Region queries that search for all objects that overlap a given region •Point queries that search for all objects that contain a given point