File: item_geofunc_relchecks.cc

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (237 lines) | stat: -rw-r--r-- 9,290 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* Copyright (c) 2014, 2025, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is designed to work with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have either included with
   the program or referenced in the documentation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#include <stddef.h>
#include <boost/concept/usage.hpp>
#include <boost/geometry/algorithms/equals.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <memory>
#include <set>
#include <utility>
#include <vector>

#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_sys.h"
#include "mysqld_error.h"
#include "sql/current_thd.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/types/spatial_reference_system.h"
#include "sql/derror.h"  // ER_THD
#include "sql/gis/geometries.h"
#include "sql/gis/relops.h"
#include "sql/gis/srid.h"
#include "sql/gis/wkb.h"
#include "sql/item.h"
#include "sql/item_cmpfunc.h"
#include "sql/item_func.h"
#include "sql/item_geofunc.h"
#include "sql/item_geofunc_internal.h"
#include "sql/spatial.h"
#include "sql/sql_class.h"  // THD
#include "sql/sql_error.h"
#include "sql/sql_exception_handler.h"
#include "sql/srs_fetcher.h"
#include "sql_string.h"

namespace boost {
namespace geometry {
namespace cs {
struct cartesian;
}  // namespace cs
}  // namespace geometry
}  // namespace boost

longlong Item_func_spatial_relation::val_int() {
  DBUG_TRACE;
  assert(fixed);

  String tmp_value1;
  String *res1 = args[0]->val_str(&tmp_value1);
  if (current_thd->is_error()) return error_int();
  if ((null_value = (res1 == nullptr || args[0]->null_value))) {
    assert(is_nullable());
    return 0;
  }
  String tmp_value2;
  String *res2 = args[1]->val_str(&tmp_value2);
  if (current_thd->is_error()) return error_int();
  if ((null_value = (res2 == nullptr || args[1]->null_value))) {
    assert(is_nullable());
    return 0;
  }

  if (res1 == nullptr || res2 == nullptr) {
    assert(false);
    my_error(ER_GIS_INVALID_DATA, MYF(0), func_name());
    return error_int();
  }

  const dd::Spatial_reference_system *srs1 = nullptr;
  const dd::Spatial_reference_system *srs2 = nullptr;
  std::unique_ptr<gis::Geometry> g1;
  std::unique_ptr<gis::Geometry> g2;
  std::unique_ptr<dd::cache::Dictionary_client::Auto_releaser> releaser(
      new dd::cache::Dictionary_client::Auto_releaser(
          current_thd->dd_client()));
  if (gis::parse_geometry(current_thd, func_name(), res1, &srs1, &g1) ||
      gis::parse_geometry(current_thd, func_name(), res2, &srs2, &g2)) {
    return error_int();
  }

  gis::srid_t srid1 = srs1 == nullptr ? 0 : srs1->id();
  gis::srid_t srid2 = srs2 == nullptr ? 0 : srs2->id();
  if (srid1 != srid2) {
    my_error(ER_GIS_DIFFERENT_SRIDS, MYF(0), func_name(), srid1, srid2);
    return error_int();
  }

  bool result;
  bool error = eval(srs1, g1.get(), g2.get(), &result, &null_value);

  if (error) return error_int();

  if (null_value) {
    assert(is_nullable());
    return 0;
  }

  return result;
}

bool Item_func_st_contains::eval(const dd::Spatial_reference_system *srs,
                                 const gis::Geometry *g1,
                                 const gis::Geometry *g2, bool *result,
                                 bool *null) {
  return gis::within(srs, g2, g1, func_name(), result, null);
}

bool Item_func_st_crosses::eval(const dd::Spatial_reference_system *srs,
                                const gis::Geometry *g1,
                                const gis::Geometry *g2, bool *result,
                                bool *null) {
  return gis::crosses(srs, g1, g2, func_name(), result, null);
}

bool Item_func_st_disjoint::eval(const dd::Spatial_reference_system *srs,
                                 const gis::Geometry *g1,
                                 const gis::Geometry *g2, bool *result,
                                 bool *null) {
  return gis::disjoint(srs, g1, g2, func_name(), result, null);
}

bool Item_func_st_equals::eval(const dd::Spatial_reference_system *srs,
                               const gis::Geometry *g1, const gis::Geometry *g2,
                               bool *result, bool *null) {
  return gis::equals(srs, g1, g2, func_name(), result, null);
}

bool Item_func_st_intersects::eval(const dd::Spatial_reference_system *srs,
                                   const gis::Geometry *g1,
                                   const gis::Geometry *g2, bool *result,
                                   bool *null) {
  return gis::intersects(srs, g1, g2, func_name(), result, null);
}

bool Item_func_mbrcontains::eval(const dd::Spatial_reference_system *srs,
                                 const gis::Geometry *g1,
                                 const gis::Geometry *g2, bool *result,
                                 bool *null) {
  return gis::mbr_within(srs, g2, g1, func_name(), result, null);
}

bool Item_func_mbrcoveredby::eval(const dd::Spatial_reference_system *srs,
                                  const gis::Geometry *g1,
                                  const gis::Geometry *g2, bool *result,
                                  bool *null) {
  return gis::mbr_covered_by(srs, g1, g2, func_name(), result, null);
}

bool Item_func_mbrcovers::eval(const dd::Spatial_reference_system *srs,
                               const gis::Geometry *g1, const gis::Geometry *g2,
                               bool *result, bool *null) {
  return gis::mbr_covered_by(srs, g2, g1, func_name(), result, null);
}

bool Item_func_mbrdisjoint::eval(const dd::Spatial_reference_system *srs,
                                 const gis::Geometry *g1,
                                 const gis::Geometry *g2, bool *result,
                                 bool *null) {
  return gis::mbr_disjoint(srs, g1, g2, func_name(), result, null);
}

bool Item_func_mbrequals::eval(const dd::Spatial_reference_system *srs,
                               const gis::Geometry *g1, const gis::Geometry *g2,
                               bool *result, bool *null) {
  return gis::mbr_equals(srs, g1, g2, func_name(), result, null);
}

bool Item_func_mbrintersects::eval(const dd::Spatial_reference_system *srs,
                                   const gis::Geometry *g1,
                                   const gis::Geometry *g2, bool *result,
                                   bool *null) {
  return gis::mbr_intersects(srs, g1, g2, func_name(), result, null);
}

bool Item_func_mbroverlaps::eval(const dd::Spatial_reference_system *srs,
                                 const gis::Geometry *g1,
                                 const gis::Geometry *g2, bool *result,
                                 bool *null) {
  return gis::mbr_overlaps(srs, g1, g2, func_name(), result, null);
}

bool Item_func_mbrtouches::eval(const dd::Spatial_reference_system *srs,
                                const gis::Geometry *g1,
                                const gis::Geometry *g2, bool *result,
                                bool *null) {
  return gis::mbr_touches(srs, g1, g2, func_name(), result, null);
}

bool Item_func_mbrwithin::eval(const dd::Spatial_reference_system *srs,
                               const gis::Geometry *g1, const gis::Geometry *g2,
                               bool *result, bool *null) {
  return gis::mbr_within(srs, g1, g2, func_name(), result, null);
}

bool Item_func_st_overlaps::eval(const dd::Spatial_reference_system *srs,
                                 const gis::Geometry *g1,
                                 const gis::Geometry *g2, bool *result,
                                 bool *null) {
  return gis::overlaps(srs, g1, g2, func_name(), result, null);
}

bool Item_func_st_touches::eval(const dd::Spatial_reference_system *srs,
                                const gis::Geometry *g1,
                                const gis::Geometry *g2, bool *result,
                                bool *null) {
  return gis::touches(srs, g1, g2, func_name(), result, null);
}

bool Item_func_st_within::eval(const dd::Spatial_reference_system *srs,
                               const gis::Geometry *g1, const gis::Geometry *g2,
                               bool *result, bool *null) {
  return gis::within(srs, g1, g2, func_name(), result, null);
}