Merge pull request #5538 from dolthub/james/spatial

spatial indexes on by default
This commit is contained in:
James Cor
2023-03-09 17:16:37 -08:00
committed by GitHub
6 changed files with 8 additions and 60 deletions

View File

@@ -16,20 +16,10 @@ package schema
import (
"fmt"
"os"
"sort"
"strings"
)
// EnableSpatialIndex enables the creation and use of spatial indexes
var EnableSpatialIndex = false
func init() {
if v := os.Getenv("DOLT_ENABLE_SPATIAL_INDEX"); v != "" {
EnableSpatialIndex = true
}
}
type IndexCollection interface {
// AddIndex adds the given index, overwriting any current indexes with the same name or columns.
// It does not perform any kind of checking, and is intended for schema modifications.
@@ -184,9 +174,6 @@ func (ixc *indexCollectionImpl) AddIndexByColTags(indexName string, tags []uint6
// validateColumnIndexable returns an error if the column given cannot be used in an index
func validateColumnIndexable(c Column) error {
if !EnableSpatialIndex && IsColSpatialType(c) {
return fmt.Errorf("cannot create an index over spatial type columns")
}
return nil
}

View File

@@ -343,25 +343,21 @@ func TestSpatialScriptsPrepared(t *testing.T) {
func TestSpatialIndexScripts(t *testing.T) {
skipOldFormat(t)
schema.EnableSpatialIndex = true
enginetest.TestSpatialIndexScripts(t, newDoltHarness(t))
}
func TestSpatialIndexScriptsPrepared(t *testing.T) {
skipOldFormat(t)
schema.EnableSpatialIndex = true
enginetest.TestSpatialIndexScriptsPrepared(t, newDoltHarness(t))
}
func TestSpatialIndexPlans(t *testing.T) {
skipOldFormat(t)
schema.EnableSpatialIndex = true
enginetest.TestSpatialIndexPlans(t, newDoltHarness(t))
}
func TestSpatialIndexPlansPrepared(t *testing.T) {
skipOldFormat(t)
schema.EnableSpatialIndex = true
enginetest.TestSpatialIndexPlansPrepared(t, newDoltHarness(t))
}

View File

@@ -1800,8 +1800,8 @@ func (t *AlterableDoltTable) CreateIndex(ctx *sql.Context, idx sql.IndexDef) err
if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil {
return err
}
if !schema.EnableSpatialIndex && idx.Constraint != sql.IndexConstraint_None && idx.Constraint != sql.IndexConstraint_Unique {
return fmt.Errorf("only the following types of index constraints are supported: none, unique")
if idx.Constraint != sql.IndexConstraint_None && idx.Constraint != sql.IndexConstraint_Unique && idx.Constraint != sql.IndexConstraint_Spatial {
return fmt.Errorf("only the following types of index constraints are supported: none, unique, spatial")
}
columns := make([]string, len(idx.Columns))
@@ -2176,8 +2176,8 @@ func (t *AlterableDoltTable) UpdateForeignKey(ctx *sql.Context, fkName string, s
// CreateIndexForForeignKey implements sql.ForeignKeyTable
func (t *AlterableDoltTable) CreateIndexForForeignKey(ctx *sql.Context, idx sql.IndexDef) error {
if !schema.EnableSpatialIndex && idx.Constraint != sql.IndexConstraint_None && idx.Constraint != sql.IndexConstraint_Unique {
return fmt.Errorf("only the following types of index constraints are supported: none, unique")
if idx.Constraint != sql.IndexConstraint_None && idx.Constraint != sql.IndexConstraint_Unique && idx.Constraint != sql.IndexConstraint_Spatial {
return fmt.Errorf("only the following types of index constraints are supported: none, unique, spatial")
}
columns := make([]string, len(idx.Columns))
for i, indexCol := range idx.Columns {

View File

@@ -257,8 +257,8 @@ func (t *TempTable) IndexedAccess(_ sql.IndexLookup) sql.IndexedTable {
}
func (t *TempTable) CreateIndex(ctx *sql.Context, idx sql.IndexDef) error {
if !schema.EnableSpatialIndex && idx.Constraint != sql.IndexConstraint_None && idx.Constraint != sql.IndexConstraint_Unique {
return fmt.Errorf("only the following types of index constraints are supported: none, unique")
if idx.Constraint != sql.IndexConstraint_None && idx.Constraint != sql.IndexConstraint_Unique && idx.Constraint != sql.IndexConstraint_Spatial {
return fmt.Errorf("only the following types of index constraints are supported: none, unique, spatial")
}
cols := make([]string, len(idx.Columns))
for i, c := range idx.Columns {

View File

@@ -10,23 +10,16 @@ teardown() {
teardown_common
}
@test "spatial-index: spatial indexes disabled" {
skip_nbf_not_dolt
run dolt sql -q "create table t (p point srid 0 not null, spatial index(p))"
[ "$status" -eq 1 ]
[[ "$output" =~ "only the following types of index constraints are supported" ]] || false
}
@test "spatial-index: spatial indexes enabled" {
skip_nbf_not_dolt
DOLT_ENABLE_SPATIAL_INDEX=1 run dolt sql -q "create table t (p point srid 0 not null, spatial index(p))"
run dolt sql -q "create table t (p point srid 0 not null, spatial index(p))"
[ "$status" -eq 0 ]
}
@test "spatial-index: not supported in old format" {
rm -rf .dolt
dolt init --old-format
DOLT_ENABLE_SPATIAL_INDEX=1 run dolt sql -q "create table t (p point srid 0 not null, spatial index(p))"
run dolt sql -q "create table t (p point srid 0 not null, spatial index(p))"
[ "$status" -eq 1 ]
[[ "$output" =~ "spatial indexes are only supported in storage format" ]] || false
}

View File

@@ -156,34 +156,6 @@ teardown() {
[[ "$output" =~ "can't use Spatial Types as Primary Key" ]] || false
}
@test "sql-spatial-types: prevent creating index on point type" {
dolt sql -q "create table point_tbl (p point)"
run dolt sql -q "create index idx on point_tbl (p)"
[ "$status" -eq 1 ]
[[ "$output" =~ "cannot create an index over spatial type columns" ]] || false
}
@test "sql-spatial-types: prevent creating index on linestring types" {
dolt sql -q "create table line_tbl (l linestring)"
run dolt sql -q "create index idx on line_tbl (l)"
[ "$status" -eq 1 ]
[[ "$output" =~ "cannot create an index over spatial type columns" ]] || false
}
@test "sql-spatial-types: prevent creating index on polygon types" {
dolt sql -q "create table poly_tbl (p polygon)"
run dolt sql -q "create index idx on poly_tbl (p)"
[ "$status" -eq 1 ]
[[ "$output" =~ "cannot create an index over spatial type columns" ]] || false
}
@test "sql-spatial-types: prevent creating index on geometry types" {
dolt sql -q "create table geom_tbl (g geometry)"
run dolt sql -q "create index idx on geom_tbl (g)"
[ "$status" -eq 1 ]
[[ "$output" =~ "cannot create an index over spatial type columns" ]] || false
}
@test "sql-spatial-types: allow index on non-spatial columns of spatial table" {
dolt sql -q "create table poly_tbl (a int, p polygon)"
dolt sql -q "create index idx on poly_tbl (a)"