mariadb/mysql-test/include/gis_keys.inc

63 lines
1.9 KiB
PHP
Raw Normal View History

Bug #30825: Problems when putting a non-spatial index on a GIS column Fixed the usage of spatial data (and Point in specific) with non-spatial indexes. Several problems : - The length of the Point class was not updated to include the spatial reference system identifier. Fixed by increasing with 4 bytes. - The storage length of the spatial columns was not accounting for the length that is prepended to it. Fixed by treating the spatial data columns as blobs (and thus increasing the storage length) - When creating the key image for comparison in index read wrong key image was created (the one needed for and r-tree search, not the one for b-tree/other search). Fixed by treating the spatial data columns as blobs (and creating the correct kind of image based on the index type). mysql-test/r/bdb_gis.result: Bug #30825: bdb tests mysql-test/r/gis-rtree.result: Bug #30825: key length changed mysql-test/r/gis.result: Bug #30825: MyISAM tests mysql-test/r/innodb_gis.result: Bug #30825: InnoDB tests mysql-test/t/bdb_gis.test: Bug #30825: bdb tests mysql-test/t/gis.test: Bug #30825: MyISAM tests mysql-test/t/innodb_gis.test: Bug #30825: InnoDB tests sql/field.cc: Bug #30825: Removed Field_geom::get_key_image as Field_blog::get_key_image takes type parameter into consideration and is a superset of Field_geom::get_key_image() sql/field.h: Bug #30825: Removed Field_geom::get_key_image as Field_blog::get_key_image takes type parameter into consideration and is a superset of Field_geom::get_key_image() sql/sql_select.h: Bug #30825: Geometry data are a blob derivate sql/sql_table.cc: Bug #30825: Increased key length to accomodate for spatial reference system identifier (srid) sql/sql_yacc.yy: Bug #30825: Increased key length to accomodate for spatial reference system identifier (srid) sql/table.cc: Bug #30825: It stores a length for spatial data as well, so increase the storage length (as it's done for blobs). mysql-test/include/gis_keys.inc: Bug #30825: Test file for spatial data and non-spatial indexes
2007-10-10 15:26:02 +02:00
--source include/have_geometry.inc
#
# Spatial objects with keys
#
#
# Bug #30825: Problems when putting a non-spatial index on a GIS column
#
CREATE TABLE t1 (p POINT);
CREATE TABLE t2 (p POINT, INDEX(p));
INSERT INTO t1 VALUES (POINTFROMTEXT('POINT(1 2)'));
INSERT INTO t2 VALUES (POINTFROMTEXT('POINT(1 2)'));
# no index, returns 1 as expected
Bug #30825: Problems when putting a non-spatial index on a GIS column Fixed the usage of spatial data (and Point in specific) with non-spatial indexes. Several problems : - The length of the Point class was not updated to include the spatial reference system identifier. Fixed by increasing with 4 bytes. - The storage length of the spatial columns was not accounting for the length that is prepended to it. Fixed by treating the spatial data columns as blobs (and thus increasing the storage length) - When creating the key image for comparison in index read wrong key image was created (the one needed for and r-tree search, not the one for b-tree/other search). Fixed by treating the spatial data columns as blobs (and creating the correct kind of image based on the index type). mysql-test/r/bdb_gis.result: Bug #30825: bdb tests mysql-test/r/gis-rtree.result: Bug #30825: key length changed mysql-test/r/gis.result: Bug #30825: MyISAM tests mysql-test/r/innodb_gis.result: Bug #30825: InnoDB tests mysql-test/t/bdb_gis.test: Bug #30825: bdb tests mysql-test/t/gis.test: Bug #30825: MyISAM tests mysql-test/t/innodb_gis.test: Bug #30825: InnoDB tests sql/field.cc: Bug #30825: Removed Field_geom::get_key_image as Field_blog::get_key_image takes type parameter into consideration and is a superset of Field_geom::get_key_image() sql/field.h: Bug #30825: Removed Field_geom::get_key_image as Field_blog::get_key_image takes type parameter into consideration and is a superset of Field_geom::get_key_image() sql/sql_select.h: Bug #30825: Geometry data are a blob derivate sql/sql_table.cc: Bug #30825: Increased key length to accomodate for spatial reference system identifier (srid) sql/sql_yacc.yy: Bug #30825: Increased key length to accomodate for spatial reference system identifier (srid) sql/table.cc: Bug #30825: It stores a length for spatial data as well, so increase the storage length (as it's done for blobs). mysql-test/include/gis_keys.inc: Bug #30825: Test file for spatial data and non-spatial indexes
2007-10-10 15:26:02 +02:00
SELECT COUNT(*) FROM t1 WHERE p=POINTFROMTEXT('POINT(1 2)');
# with index, returns 1 as expected
# EXPLAIN shows that the index is not used though
# due to the "most rows covered anyway, so a scan is more effective" rule
Bug #30825: Problems when putting a non-spatial index on a GIS column Fixed the usage of spatial data (and Point in specific) with non-spatial indexes. Several problems : - The length of the Point class was not updated to include the spatial reference system identifier. Fixed by increasing with 4 bytes. - The storage length of the spatial columns was not accounting for the length that is prepended to it. Fixed by treating the spatial data columns as blobs (and thus increasing the storage length) - When creating the key image for comparison in index read wrong key image was created (the one needed for and r-tree search, not the one for b-tree/other search). Fixed by treating the spatial data columns as blobs (and creating the correct kind of image based on the index type). mysql-test/r/bdb_gis.result: Bug #30825: bdb tests mysql-test/r/gis-rtree.result: Bug #30825: key length changed mysql-test/r/gis.result: Bug #30825: MyISAM tests mysql-test/r/innodb_gis.result: Bug #30825: InnoDB tests mysql-test/t/bdb_gis.test: Bug #30825: bdb tests mysql-test/t/gis.test: Bug #30825: MyISAM tests mysql-test/t/innodb_gis.test: Bug #30825: InnoDB tests sql/field.cc: Bug #30825: Removed Field_geom::get_key_image as Field_blog::get_key_image takes type parameter into consideration and is a superset of Field_geom::get_key_image() sql/field.h: Bug #30825: Removed Field_geom::get_key_image as Field_blog::get_key_image takes type parameter into consideration and is a superset of Field_geom::get_key_image() sql/sql_select.h: Bug #30825: Geometry data are a blob derivate sql/sql_table.cc: Bug #30825: Increased key length to accomodate for spatial reference system identifier (srid) sql/sql_yacc.yy: Bug #30825: Increased key length to accomodate for spatial reference system identifier (srid) sql/table.cc: Bug #30825: It stores a length for spatial data as well, so increase the storage length (as it's done for blobs). mysql-test/include/gis_keys.inc: Bug #30825: Test file for spatial data and non-spatial indexes
2007-10-10 15:26:02 +02:00
EXPLAIN
SELECT COUNT(*) FROM t2 WHERE p=POINTFROMTEXT('POINT(1 2)');
SELECT COUNT(*) FROM t2 WHERE p=POINTFROMTEXT('POINT(1 2)');
# adding another row to the table so that
# the "most rows covered" rule doesn't kick in anymore
# now EXPLAIN shows the index used on the table
# and we're getting the wrong result again
Bug #30825: Problems when putting a non-spatial index on a GIS column Fixed the usage of spatial data (and Point in specific) with non-spatial indexes. Several problems : - The length of the Point class was not updated to include the spatial reference system identifier. Fixed by increasing with 4 bytes. - The storage length of the spatial columns was not accounting for the length that is prepended to it. Fixed by treating the spatial data columns as blobs (and thus increasing the storage length) - When creating the key image for comparison in index read wrong key image was created (the one needed for and r-tree search, not the one for b-tree/other search). Fixed by treating the spatial data columns as blobs (and creating the correct kind of image based on the index type). mysql-test/r/bdb_gis.result: Bug #30825: bdb tests mysql-test/r/gis-rtree.result: Bug #30825: key length changed mysql-test/r/gis.result: Bug #30825: MyISAM tests mysql-test/r/innodb_gis.result: Bug #30825: InnoDB tests mysql-test/t/bdb_gis.test: Bug #30825: bdb tests mysql-test/t/gis.test: Bug #30825: MyISAM tests mysql-test/t/innodb_gis.test: Bug #30825: InnoDB tests sql/field.cc: Bug #30825: Removed Field_geom::get_key_image as Field_blog::get_key_image takes type parameter into consideration and is a superset of Field_geom::get_key_image() sql/field.h: Bug #30825: Removed Field_geom::get_key_image as Field_blog::get_key_image takes type parameter into consideration and is a superset of Field_geom::get_key_image() sql/sql_select.h: Bug #30825: Geometry data are a blob derivate sql/sql_table.cc: Bug #30825: Increased key length to accomodate for spatial reference system identifier (srid) sql/sql_yacc.yy: Bug #30825: Increased key length to accomodate for spatial reference system identifier (srid) sql/table.cc: Bug #30825: It stores a length for spatial data as well, so increase the storage length (as it's done for blobs). mysql-test/include/gis_keys.inc: Bug #30825: Test file for spatial data and non-spatial indexes
2007-10-10 15:26:02 +02:00
INSERT INTO t1 VALUES (POINTFROMTEXT('POINT(1 2)'));
INSERT INTO t2 VALUES (POINTFROMTEXT('POINT(1 2)'));
EXPLAIN
SELECT COUNT(*) FROM t1 WHERE p=POINTFROMTEXT('POINT(1 2)');
SELECT COUNT(*) FROM t1 WHERE p=POINTFROMTEXT('POINT(1 2)');
EXPLAIN
SELECT COUNT(*) FROM t2 WHERE p=POINTFROMTEXT('POINT(1 2)');
SELECT COUNT(*) FROM t2 WHERE p=POINTFROMTEXT('POINT(1 2)');
EXPLAIN
SELECT COUNT(*) FROM t2 IGNORE INDEX(p) WHERE p=POINTFROMTEXT('POINT(1 2)');
SELECT COUNT(*) FROM t2 IGNORE INDEX(p) WHERE p=POINTFROMTEXT('POINT(1 2)');
DROP TABLE t1, t2;
--echo End of 5.0 tests
Fix for bug #58650 "Failing assertion: primary_key_no == -1 || primary_key_no == 0". Attempt to create InnoDB table with non-nullable column of geometry type having an unique key with length 12 on it and with some other candidate key led to server crash due to assertion failure in both non-debug and debug builds. The problem was that such a non-candidate key could have been sorted as the first key in table/.FRM, before any legit candidate keys. This resulted in assertion failure in InnoDB engine which assumes that primary key should either be the first key in table/.FRM or should not exist at all. The reason behind such an incorrect sorting was an wrong value of Create_field::key_length member for geometry field (which was set to its pack_length == 12) which confused code in mysql_prepare_create_table(), so it would skip marking such key as a key with partial segments. This patch fixes the problem by ensuring that this member gets the same value of Create_field::key_length member as for other blob fields (from which geometry field class is inherited), and as result unique keys on geometry fields are correctly marked as having partial segments. mysql-test/include/gis_keys.inc: Added test case for bug #58650 "Failing assertion: primary_key_no == -1 || primary_key_no == 0". mysql-test/r/gis.result: Added test case for bug #58650 "Failing assertion: primary_key_no == -1 || primary_key_no == 0". mysql-test/suite/innodb/r/innodb_gis.result: Added test case for bug #58650 "Failing assertion: primary_key_no == -1 || primary_key_no == 0". mysql-test/suite/innodb_plugin/r/innodb_gis.result: Added test case for bug #58650 "Failing assertion: primary_key_no == -1 || primary_key_no == 0". sql/field.cc: Changed Create_field::create_length_to_internal_length() to correctly set Create_field::key_length member for geometry fields. Similar to the blob types key_length for such fields should be the same as length and not field's packed length (which is always 12 for geometry). As result of this change code handling table creation now always correctly identifies btree/unique keys on geometry fields as partial keys, so such keys can't be erroneously treated as candidate keys and sorted in keys array in .FRM before legit candidate keys. This fixes bug #58650 "Failing assertion: primary_key_no == -1 || primary_key_no == 0" in which incorrect candidate key sorting led to assertion failure in InnoDB code.
2011-02-02 14:17:48 +01:00
--echo #
--echo # Test for bug #58650 "Failing assertion: primary_key_no == -1 ||
--echo # primary_key_no == 0".
--echo #
--disable_warnings
drop table if exists t1;
--enable_warnings
--echo # The minimal test case.
create table t1 (a int not null, b linestring not null, unique key b (b(12)), unique key a (a));
drop table t1;
--echo # The original test case.
create table t1 (a int not null, b linestring not null, unique key b (b(12)));
create unique index a on t1(a);
drop table t1;