Skip to content

Commit 7785e96

Browse files
committed
WL#8579 Spatial Reference Systems
Add a data dictionary table, objects and cache for spatial reference systems. Add geographic (2d) and projected (based on geographic 2d) spatial reference system definitions from the EPSG Geodetic Parameter Dataset, version 8.7. Issue a warning if the SRID refers to an undefined spatial reference system in functions MBRCONTAINS, MBRCOVEREDBY, MBRCOVERS, MBRDISJOINT, MBREQUALS, MBRINTERSECTS, MBROVERLAPS, MBRTOUCHES, MBRWITHIN, ST_AREA, ST_BUFFER, ST_CENTROID, ST_CONTAINS, ST_CONVEXHULL, ST_CROSSES, ST_DIFFERENCE, ST_DISJOINT, ST_DISTANCE, ST_ENVELOPE, ST_EQUALS, ST_INTERSECTION, ST_INTERSECTS, ST_ISSIMPLE, ST_LENGTH, ST_OVERLAPS, ST_SIMPLIFY, ST_SYMDIFFERENCE, ST_TOUCHES, ST_UNION and ST_WITHIN. Issue an error if the SRID refers to an undefined spatial reference system in functions ST_ISVALID, ST_MAKEENVELOPE and ST_VALIDATE.
1 parent 8335899 commit 7785e96

File tree

120 files changed

+23993
-2017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+23993
-2017
lines changed

client/upgrade/program.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "my_default.h"
2828
#include "check/mysqlcheck.h"
2929
#include "../scripts/mysql_fix_privilege_tables_sql.c"
30+
#include "../scripts/sql_commands_system_tables_data_fix.h"
3031
#include "../scripts/sql_commands_sys_schema.h"
3132

3233
#include "base/abstract_connection_program.h"
@@ -211,6 +212,11 @@ class Program : public Base::Abstract_connection_program
211212
return EXIT_UPGRADING_QUERIES_ERROR;
212213
}
213214

215+
if (this->run_commands_system_tables_data_fix() != 0)
216+
{
217+
return EXIT_UPGRADING_QUERIES_ERROR;
218+
}
219+
214220
if (this->m_upgrade_systables_only == false)
215221
{
216222
this->print_verbose_message("Checking system database.");
@@ -609,6 +615,42 @@ class Program : public Base::Abstract_connection_program
609615
return 0;
610616
}
611617

618+
/**
619+
Update system table data
620+
621+
@retval 0 Success
622+
@retval non-zero Error
623+
*/
624+
int run_commands_system_tables_data_fix()
625+
{
626+
const char **query_ptr;
627+
int result;
628+
629+
Mysql_query_runner runner(*this->m_query_runner);
630+
Instance_callback<int64, const Mysql_query_runner::Row&, Program>
631+
result_cb(this, &Program::result_callback);
632+
Instance_callback<int64, const Message_data&, Program>
633+
message_cb(this, &Program::fix_privilage_tables_error);
634+
635+
runner.add_result_callback(&result_cb);
636+
runner.add_message_callback(&message_cb);
637+
638+
this->print_verbose_message("Upgrading system table data.");
639+
640+
for (query_ptr= &mysql_system_tables_data_fix[0];
641+
*query_ptr != NULL;
642+
query_ptr++)
643+
{
644+
result= runner.run_query(*query_ptr);
645+
if (!this->m_ignore_errors && result != 0)
646+
{
647+
return result;
648+
}
649+
}
650+
651+
return 0;
652+
}
653+
612654
/**
613655
Update the sys schema
614656
*/

libmysqld/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ SET(LIBMYSQLD_BOOST_SOURCES
106106
../sql/debug_sync.cc
107107
../sql/handler.cc
108108
../sql/geometry_rtree.cc
109+
../sql/gis/srs/srs.cc
110+
../sql/gis/srs/wkt_parser.cc
109111
../sql/item_geofunc.cc
110112
../sql/item_geofunc_buffer.cc
111113
../sql/item_geofunc_internal.cc
@@ -161,6 +163,26 @@ IF(HAVE_UNDEF)
161163
COMPILE_FLAGS "-Wno-undef")
162164
ENDIF()
163165

166+
# Boost source compares signed and unsigned integer expressions
167+
MY_CHECK_CXX_COMPILER_FLAG("-Wsign-compare" HAVE_SIGN_COMPARE)
168+
IF(HAVE_SIGN_COMPARE)
169+
ADD_COMPILE_FLAGS(
170+
../sql/gis/srs/wkt_parser.cc
171+
COMPILE_FLAGS "-Wno-sign-compare"
172+
)
173+
ENDIF()
174+
175+
# Set -O1 on Solaris x86 to avoid exhausting virtual memory when
176+
# compiling
177+
IF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_SYSTEM_NAME MATCHES "SunOS")
178+
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "i386")
179+
ADD_COMPILE_FLAGS(
180+
../sql/gis/srs/wkt_parser.cc
181+
COMPILE_FLAGS "-O1"
182+
)
183+
ENDIF()
184+
ENDIF()
185+
164186
# Boost source use auto_ptr, deprecated in C++11
165187
MY_CHECK_CXX_COMPILER_FLAG("-Wdeprecated-declarations"
166188
HAVE_DEPRECATED_DECLARATIONS)

mysql-test/r/dd_schema_definition_ci.result

Lines changed: 261 additions & 261 deletions
Large diffs are not rendered by default.

mysql-test/r/dd_schema_definition_cs.result

Lines changed: 261 additions & 261 deletions
Large diffs are not rendered by default.

mysql-test/r/gis-precise.result

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,13 +1288,13 @@ ST_ISVALID(ST_GEOMFROMTEXT('GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(0 0)))')
12881288
#
12891289
SELECT ST_ASTEXT(ST_MAKEENVELOPE(ST_GEOMFROMTEXT('POINT(0 1)', 4236),
12901290
ST_GEOMFROMTEXT('POINT(0 0)', 0)));
1291-
ERROR HY000: Incorrect arguments to st_makeenvelope
1291+
ERROR HY000: Binary geometry function st_makeenvelope given two geometries of different srids: 4236 and 0, which should have been identical.
12921292
SELECT ST_ASTEXT(ST_MAKEENVELOPE(ST_GEOMFROMTEXT('POINT(0 1)', 1),
12931293
ST_GEOMFROMTEXT('POINT(0 0)', 0)));
1294-
ERROR HY000: Incorrect arguments to st_makeenvelope
1294+
ERROR HY000: Binary geometry function st_makeenvelope given two geometries of different srids: 1 and 0, which should have been identical.
12951295
SELECT ST_ASTEXT(ST_MAKEENVELOPE(ST_GEOMFROMTEXT('POINT(0 1)', 0),
12961296
ST_GEOMFROMTEXT('POINT(0 0)', 100)));
1297-
ERROR HY000: Incorrect arguments to st_makeenvelope
1297+
ERROR HY000: Binary geometry function st_makeenvelope given two geometries of different srids: 0 and 100, which should have been identical.
12981298
#
12991299
# Bug #20085563 ASSERTION `!NULL_VALUE && OPDONE && STR_VALUE_ARG->LENGTH() > 0' FAILED
13001300
#
@@ -1566,9 +1566,9 @@ result
15661566
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', -1));
15671567
ERROR 22003: SRID value is out of range in 'st_geomfromtext'
15681568
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 1));
1569-
ERROR HY000: Incorrect arguments to st_isvalid
1569+
ERROR SR001: Function st_isvalid is only defined for Cartesian spatial reference systems, but one of its arguments is in SRID 1, which has not been defined.
15701570
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 1000));
1571-
ERROR HY000: Incorrect arguments to st_isvalid
1571+
ERROR SR001: Function st_isvalid is only defined for Cartesian spatial reference systems, but one of its arguments is in SRID 1000, which has not been defined.
15721572
#
15731573
# Bug#20406850 WL#8034 : CRASH WITH ST_ISVAID() IN ITEM_FUNC_ISVALID::VAL_INT FUNCTION
15741574
#

mysql-test/r/gis.result

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,8 @@ FROM named_places
13321332
WHERE name = 'Goose Island';
13331333
ST_AsText(ST_Envelope(boundary))
13341334
POLYGON((59 13,67 13,67 18,59 18,59 13))
1335+
Warnings:
1336+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_envelope will be done in SRID 0.
13351337
# Conformance Item T15
13361338
SELECT ST_X(position)
13371339
FROM bridges
@@ -1362,6 +1364,8 @@ FROM road_segments
13621364
WHERE fid = 106;
13631365
ST_Length(centerline)
13641366
26
1367+
Warnings:
1368+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_length will be done in SRID 0.
13651369
# Conformance Item T22
13661370
SELECT ST_NumPoints(centerline)
13671371
FROM road_segments
@@ -1380,12 +1384,16 @@ FROM named_places
13801384
WHERE name = 'Goose Island';
13811385
ST_AsText(ST_Centroid(boundary))
13821386
POINT(63 15.5)
1387+
Warnings:
1388+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_centroid will be done in SRID 0.
13831389
# Conformance Item T26
13841390
SELECT ST_Area(boundary)
13851391
FROM named_places
13861392
WHERE name = 'Goose Island';
13871393
ST_Area(boundary)
13881394
40
1395+
Warnings:
1396+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_area will be done in SRID 0.
13891397
# Conformance Item T27
13901398
SELECT ST_AsText(ST_ExteriorRing(shore))
13911399
FROM lakes
@@ -1428,18 +1436,24 @@ FROM divided_routes
14281436
WHERE name = 'Route 75';
14291437
ST_Length(centerlines)
14301438
96
1439+
Warnings:
1440+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_length will be done in SRID 0.
14311441
# Conformance Item T34
14321442
SELECT ST_AsText(ST_Centroid(shores))
14331443
FROM ponds
14341444
WHERE fid = 120;
14351445
ST_AsText(ST_Centroid(shores))
14361446
POINT(25 42)
1447+
Warnings:
1448+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_centroid will be done in SRID 0.
14371449
# Conformance Item T36
14381450
SELECT ST_Area(shores)
14391451
FROM ponds
14401452
WHERE fid = 120;
14411453
ST_Area(shores)
14421454
8
1455+
Warnings:
1456+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_area will be done in SRID 0.
14431457
# Conformance Item T37
14441458
SELECT ST_Equals(boundary,
14451459
ST_PolyFromText('POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )',101))
@@ -1448,6 +1462,8 @@ WHERE name = 'Goose Island';
14481462
ST_Equals(boundary,
14491463
ST_PolyFromText('POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )',101))
14501464
1
1465+
Warnings:
1466+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_equals will be done in SRID 0.
14511467
SELECT ST_Equals(boundary,
14521468
ST_PolyFromText('POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )',1))
14531469
FROM named_places
@@ -1460,67 +1476,89 @@ WHERE divided_routes.name = 'Route 75'
14601476
AND named_places.name = 'Ashton';
14611477
ST_Disjoint(centerlines, boundary)
14621478
1
1479+
Warnings:
1480+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_disjoint will be done in SRID 0.
14631481
# Conformance Item T39
14641482
SELECT ST_Touches(centerline, shore)
14651483
FROM streams, lakes
14661484
WHERE streams.name = 'Cam Stream'
14671485
AND lakes.name = 'Blue Lake';
14681486
ST_Touches(centerline, shore)
14691487
1
1488+
Warnings:
1489+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_touches will be done in SRID 0.
14701490
# Conformance Item T42
14711491
SELECT ST_Crosses(road_segments.centerline, divided_routes.centerlines)
14721492
FROM road_segments, divided_routes
14731493
WHERE road_segments.fid = 102
14741494
AND divided_routes.name = 'Route 75';
14751495
ST_Crosses(road_segments.centerline, divided_routes.centerlines)
14761496
1
1497+
Warnings:
1498+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_crosses will be done in SRID 0.
14771499
# Conformance Item T43
14781500
SELECT ST_Intersects(road_segments.centerline, divided_routes.centerlines)
14791501
FROM road_segments, divided_routes
14801502
WHERE road_segments.fid = 102
14811503
AND divided_routes.name = 'Route 75';
14821504
ST_Intersects(road_segments.centerline, divided_routes.centerlines)
14831505
1
1506+
Warnings:
1507+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_intersects will be done in SRID 0.
14841508
# Conformance Item T44
14851509
SELECT ST_Contains(forests.boundary, named_places.boundary)
14861510
FROM forests, named_places
14871511
WHERE forests.name = 'Green Forest'
14881512
AND named_places.name = 'Ashton';
14891513
ST_Contains(forests.boundary, named_places.boundary)
14901514
0
1515+
Warnings:
1516+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_contains will be done in SRID 0.
14911517
# Conformance Item T46
14921518
SELECT ST_Distance(position, boundary)
14931519
FROM bridges, named_places
14941520
WHERE bridges.name = 'Cam Bridge'
14951521
AND named_places.name = 'Ashton';
14961522
ST_Distance(position, boundary)
14971523
12
1524+
Warnings:
1525+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_distance will be done in SRID 0.
14981526
# Conformance Item T48
14991527
SELECT ST_AsText(ST_Difference(named_places.boundary, forests.boundary))
15001528
FROM named_places, forests
15011529
WHERE named_places.name = 'Ashton'
15021530
AND forests.name = 'Green Forest';
15031531
ST_AsText(ST_Difference(named_places.boundary, forests.boundary))
15041532
POLYGON((84 42,84 48,62 48,56 34,84 42))
1533+
Warnings:
1534+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_difference will be done in SRID 0.
15051535
SELECT ST_AsText(ST_Union(shore, boundary))
15061536
FROM lakes, named_places
15071537
WHERE lakes.name = 'Blue Lake'
15081538
AND named_places.name = 'Goose Island';
15091539
ST_AsText(ST_Union(shore, boundary))
15101540
POLYGON((52 18,48 6,73 9,66 23,52 18))
1541+
Warnings:
1542+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_union will be done in SRID 0.
15111543
# Conformance Item T50
15121544
SELECT ST_AsText(ST_SymDifference(shore, boundary))
15131545
FROM lakes, named_places
15141546
WHERE lakes.name = 'Blue Lake'
15151547
AND named_places.name = 'Ashton';
15161548
ST_AsText(ST_SymDifference(shore, boundary))
15171549
MULTIPOLYGON(((52 18,48 6,73 9,66 23,52 18),(59 18,67 18,67 13,59 13,59 18)),((62 48,56 34,56 30,84 30,84 48,62 48)))
1550+
Warnings:
1551+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_symdifference will be done in SRID 0.
15181552
# Conformance Item T51
15191553
SELECT count(*)
15201554
FROM buildings, bridges
15211555
WHERE ST_Contains(ST_Buffer(bridges.position, 15.0), buildings.footprint) = 1;
15221556
count(*)
15231557
1
1558+
Warnings:
1559+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_buffer will be done in SRID 0.
1560+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_contains will be done in SRID 0.
1561+
Warning 3519 There's no spatial reference system with SRID 101. Calculations in function st_contains will be done in SRID 0.
15241562
DROP DATABASE gis_ogs;
15251563
#
15261564
# Bug#13362660 ASSERTION `FIELD_POS < FIELD_COUNT' FAILED. IN PROTOCOL_TEXT::STORE

mysql-test/r/transactional_acl_tables.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,7 @@ user MyISAM
17621762
Checking if update is needed.
17631763
Checking server version.
17641764
Running queries to upgrade MySQL server.
1765+
Upgrading system table data.
17651766
Checking system database.
17661767
mysql.column_stats OK
17671768
mysql.columns_priv OK

mysql-test/suite/gis/r/geohash_functions.result

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,3 +1769,30 @@ LINESTRING(POINT(1, 1))
17691769
ST_LongFromGeoHash(UpdateXML(1, NULL, NULL))
17701770
);
17711771
ERROR 22023: Invalid GIS data provided to function linestring.
1772+
#
1773+
# WL#8579 Spatial Reference Systems
1774+
#
1775+
# SRID 0 (should pass)
1776+
SELECT ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)', 0), 10);
1777+
ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)', 0), 10)
1778+
s000000000
1779+
# Projected SRS (should pass)
1780+
SELECT ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)', 2000), 10);
1781+
ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)', 2000), 10)
1782+
s000000000
1783+
# Geographic SRS (should pass)
1784+
SELECT ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)', 4326), 10);
1785+
ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)', 4326), 10)
1786+
s000000000
1787+
# Undefined SRS (should pass)
1788+
SELECT ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)', 19000000), 10);
1789+
ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)', 19000000), 10)
1790+
s000000000
1791+
# Unparseable SRS definition (should pass)
1792+
INSERT INTO mysql.st_spatial_reference_systems(id, catalog_id, name,
1793+
organization, organization_coordsys_id, definition, description)
1794+
VALUES (11111111, 1, 'TEST11111111', 'Foo', 11111111, 'FOOBAR', '');
1795+
SELECT ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)', 11111111), 10);
1796+
ST_GEOHASH(ST_GEOMFROMTEXT('POINT(0 0)', 11111111), 10)
1797+
s000000000
1798+
DELETE FROM mysql.st_spatial_reference_systems WHERE id = 11111111;

0 commit comments

Comments
 (0)