Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Blueprint Geo Spatial index #21070

Merged
merged 1 commit into from
Sep 7, 2017
Merged

[5.5] Blueprint Geo Spatial index #21070

merged 1 commit into from
Sep 7, 2017

Conversation

antonkomarev
Copy link
Contributor

@antonkomarev antonkomarev commented Sep 7, 2017

This PR continues #21056 and introduces spatial indexes in your migrations with the spatialIndex blueprint method.

Note: At this moment I've implemented only MySQL grammar SPATIAL INDEX support.

$table->spatialIndex('column_name');
// or
$table->point('column_name')->spatialIndex();

Example:

public function up()
{
    Schema::table('conferences', function (Blueprint $table) {
        $table->increments('id');
        $table->point('coordinates')->spatialIndex();
    });
}

You can drop it using default $table->dropIndex('column_name') command.

MySQL

Note about spatial indexes from the MySQL documentation:

For MyISAM and (as of MySQL 5.7.5) InnoDB 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.

MySQL SPATIAL INDEX creates an R-tree index. For storage engines that support nonspatial indexing of spatial columns, the engine creates a B-tree index. A B-tree index on spatial values is useful for exact-value lookups, but not for range scans.

  • Available only for MyISAM and InnoDB tables. Specifying SPATIAL INDEX for other storage engines results in an error.
  • Indexed columns must be NOT NULL.
  • Column prefix lengths are prohibited. The full width of each column is indexed.

PostgreSQL

Accordingly to PostGIS Spatial Indexing article:

The USING GIST clause tells PostgreSQL to use the generic index structure (GIST) when building the index. This is important because the default index type is the B-Ttree. B-Tree indices are not lossy (inexact) in the way a GIST index can be. This means that while the GIST index only indexes the bounding box of the geometry, the B-Tree must index the entire geometry, which can often be larger than the index can cope with. If you receive an error that looks like ERROR: index row requires 11340 bytes, maximum size is 8191 when creating your index, you have likely neglected to add the USING GIST clause.

@taylorotwell taylorotwell merged commit d4169a5 into laravel:5.5 Sep 7, 2017
@antonkomarev antonkomarev deleted the feature/mysql-spatial-data-index branch September 7, 2017 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants