[CP] [GIS] fix gis index with high resolution

This commit is contained in:
helloamateur 2024-08-21 12:57:28 +00:00 committed by ob-robot
parent f7c92208af
commit a6cb5fe594
6 changed files with 239 additions and 32 deletions

View File

@ -63,6 +63,7 @@ int ObWkbToS2Visitor::MakeS2Point(T_IBIN *geo, S2Cell *&res)
LOG_WARN("failed to alloc s2cell", K(ret));
} else {
res = p;
bounder_.AddPoint(S2Point(latlng));
}
}
return ret;
@ -129,6 +130,7 @@ int ObWkbToS2Visitor::MakeProjS2Point(T_IBIN *geo, S2Cell *&res)
LOG_WARN("failed to alloc s2cell", K(ret));
} else {
res = p;
bounder_.AddPoint(point);
}
}
}
@ -149,6 +151,8 @@ int ObWkbToS2Visitor::MakeS2Polyline(T_IBIN *geo, S2Polyline *&res)
LOG_WARN("failed to add cell from point", K(ret));
} else if (OB_FAIL(vector_push_back<S2LatLng>(vertices, latlng))) {
LOG_WARN("failed to add vertice", K(ret));
} else {
bounder_.AddPoint(S2Point(latlng));
}
}
if (OB_SUCC(ret)) {
@ -178,6 +182,8 @@ int ObWkbToS2Visitor::MakeProjS2Polyline(T_IBIN *geo, S2Polyline *&res)
LOG_WARN("failed to add cell from point", K(ret));
} else if (OB_FAIL(vector_push_back<S2Point>(vertices, p))) {
LOG_WARN("failed to add vertice", K(ret));
} else {
bounder_.AddPoint(p);
}
}
@ -212,6 +218,8 @@ int ObWkbToS2Visitor::MakeS2Polygon(T_IBIN *geo, S2Polygon *&res)
LOG_WARN("failed to add cell from point", K(ret));
} else if (OB_FAIL(vector_push_back<S2Point>(vertices, tmp))) {
LOG_WARN("failed to add vertice", K(ret));
} else {
bounder_.AddPoint(tmp);
}
}
if (OB_SUCC(ret)) {
@ -240,6 +248,8 @@ int ObWkbToS2Visitor::MakeS2Polygon(T_IBIN *geo, S2Polygon *&res)
LOG_WARN("failed to add cell from point", K(ret));
} else if (OB_FAIL(vector_push_back<S2Point>(vertices, tmp))) {
LOG_WARN("failed to add vertice", K(ret));
} else {
bounder_.AddPoint(tmp);
}
}
if (OB_SUCC(ret)) {
@ -286,6 +296,8 @@ int ObWkbToS2Visitor::MakeProjS2Polygon(T_IBIN *geo, S2Polygon *&res)
LOG_WARN("failed to add cell from point", K(ret));
} else if (OB_FAIL(vector_push_back<S2Point>(vertices, tmp))) {
LOG_WARN("failed to add vertice", K(ret));
} else {
bounder_.AddPoint(tmp);
}
}
if (OB_SUCC(ret)) {
@ -313,6 +325,8 @@ int ObWkbToS2Visitor::MakeProjS2Polygon(T_IBIN *geo, S2Polygon *&res)
LOG_WARN("failed to add cell from point", K(ret));
} else if (OB_FAIL(vector_push_back<S2Point>(vertices, tmp))) {
LOG_WARN("failed to add vertice", K(ret));
} else {
bounder_.AddPoint(tmp);
}
}
if (OB_SUCC(ret)) {
@ -448,30 +462,23 @@ int64_t ObWkbToS2Visitor::get_cellids(ObS2Cellids &cells, bool is_query, bool ne
LOG_WARN("fail to push_back cellid", K(ret));
}
} else {
S2CellUnion cellids;
S2RegionCoverer coverer(options_);
uint32_t s2v_size = s2v_.size();
for (int i = 0; i < s2v_size; i++) {
S2CellUnion tmp = coverer.GetCovering(*s2v_[i]);
cellids = cellids.Union(tmp);
}
if (need_buffer) {
const int max_level_diff = 2;
cellids.Expand(distance, max_level_diff);
cell_union_.Expand(distance, max_level_diff);
}
if (s2v_size > 1) {
cellids.Normalize();
cell_union_.Normalize();
}
S2CellId prev_id = S2CellId::None();
for (int i = 0; OB_SUCC(ret) && i < cellids.size(); i++) {
if (OB_FAIL(cells.push_back(cellids[i].id()))) {
for (int i = 0; OB_SUCC(ret) && i < cell_union_.size(); i++) {
if (OB_FAIL(cells.push_back(cell_union_[i].id()))) {
LOG_WARN("fail to push_back cellid", K(ret));
}
if (OB_SUCC(ret) && is_query) {
int level = cellids[i].level();
int level = cell_union_[i].level();
while (OB_SUCC(ret) && (level -= options_.level_mod()) >= options_.min_level()) {
S2CellId ancestor_id = cellids[i].parent(level);
S2CellId ancestor_id = cell_union_[i].parent(level);
if (prev_id != S2CellId::None() && prev_id.level() > level &&
prev_id.parent(level) == ancestor_id) {
break;
@ -481,7 +488,7 @@ int64_t ObWkbToS2Visitor::get_cellids(ObS2Cellids &cells, bool is_query, bool ne
}
}
}
prev_id = cellids[i];
prev_id = cell_union_[i];
}
if (OB_SUCC(ret) && has_reset_ && OB_FAIL(cells.push_back(exceedsBoundsCellID))) {
LOG_WARN("fail to push_back cellid", K(ret));
@ -490,6 +497,63 @@ int64_t ObWkbToS2Visitor::get_cellids(ObS2Cellids &cells, bool is_query, bool ne
return ret;
}
bool ObWkbToS2Visitor::is_full_range_cell_union(S2CellUnion &cellids)
{
bool b_ret = false;
if (is_geog_) {
const uint8_t cell_faces = 6;
if (cellids.size() != cell_faces) {
// do nothing
} else {
uint8_t curr_faces = 0;
for (uint32_t i = 0; i < cellids.size(); i++) {
if (cellids[i].level() == 0) {
curr_faces++;
LOG_INFO("cell id", K(static_cast<uint64_t>(cellids[i].id())));
}
}
if (curr_faces == cell_faces) {
b_ret = true;
}
}
} else {
for (uint32_t i = 0; i < cellids.size() && !b_ret; i++) {
if (cellids[i].face() != 0) {
b_ret = true;
LOG_INFO("cell id", K(static_cast<uint64_t>(cellids[i].id())));
}
}
}
return b_ret;
}
int ObWkbToS2Visitor::get_s2_cell_union()
{
int ret = OB_SUCCESS;
if (!invalid_) {
S2RegionCoverer coverer(options_);
uint32_t s2v_size = s2v_.size();
for (int i = 0; i < s2v_size; i++) {
S2CellUnion tmp = coverer.GetCovering(*s2v_[i]);
cell_union_ = cell_union_.Union(tmp);
}
if (is_full_range_cell_union(cell_union_)) {
S2LatLng margin = S2LatLng::FromDegrees(0.00001, 0.00001);
S2LatLngRect rect = bounder_.GetBound().Expanded(margin);
cell_union_ = coverer.GetCovering(rect);
mbr_ = rect;
LOG_INFO("generate new mbr: ", K(rect.lo().ToStringInDegrees().c_str()), K(rect.hi().ToStringInDegrees().c_str()));
S2cells_.clear();
for (uint8_t i = 0; i < 4 && OB_SUCC(ret); i++) {
if (OB_FAIL(add_cell_from_point(rect.GetVertex(i)))) {
LOG_WARN("fail to push_back cellid", K(ret));
}
}
}
}
return ret;
}
int64_t ObWkbToS2Visitor::get_cellids_and_unrepeated_ancestors(ObS2Cellids &cells,
ObS2Cellids &ancestors,
bool need_buffer,
@ -501,8 +565,6 @@ int64_t ObWkbToS2Visitor::get_cellids_and_unrepeated_ancestors(ObS2Cellids &cell
LOG_WARN("fail to push_back cellid", K(ret));
}
} else {
S2CellUnion cellids;
S2RegionCoverer coverer(options_);
uint32_t s2v_size = s2v_.size();
hash::ObHashSet<uint64_t> cellid_set;
if (OB_FAIL(cellid_set.create(128, "CellidSet", "HashNode"))) {
@ -511,30 +573,26 @@ int64_t ObWkbToS2Visitor::get_cellids_and_unrepeated_ancestors(ObS2Cellids &cell
ret = OB_NOT_INIT;
LOG_WARN("fail to init cellid set", K(ret));
} else {
for (int i = 0; i < s2v_size && OB_SUCC(ret); i++) {
S2CellUnion tmp = coverer.GetCovering(*s2v_[i]);
cellids = cellids.Union(tmp);
}
if (need_buffer) {
const int max_level_diff = 2;
cellids.Expand(distance, max_level_diff);
cell_union_.Expand(distance, max_level_diff);
}
if (s2v_size > 1) {
cellids.Normalize();
cell_union_.Normalize();
}
S2CellId prev_id = S2CellId::None();
for (int i = 0; OB_SUCC(ret) && i < cellids.size(); i++) {
int hash_ret = cellid_set.exist_refactored(cellids[i].id());
for (int i = 0; OB_SUCC(ret) && i < cell_union_.size(); i++) {
int hash_ret = cellid_set.exist_refactored(cell_union_[i].id());
if (OB_HASH_NOT_EXIST == hash_ret) {
if (OB_FAIL(cellid_set.set_refactored(cellids[i].id()))) {
if (OB_FAIL(cellid_set.set_refactored(cell_union_[i].id()))) {
LOG_WARN("failed to add cellid into set", K(ret));
} else if (OB_FAIL(cells.push_back(cellids[i].id()))) {
} else if (OB_FAIL(cells.push_back(cell_union_[i].id()))) {
LOG_WARN("fail to push_back cellid", K(ret));
}
if (OB_SUCC(ret)) {
int level = cellids[i].level();
int level = cell_union_[i].level();
while (OB_SUCC(ret) && (level -= options_.level_mod()) >= options_.min_level()) {
S2CellId ancestor_id = cellids[i].parent(level);
S2CellId ancestor_id = cell_union_[i].parent(level);
if (prev_id != S2CellId::None() && prev_id.level() > level &&
prev_id.parent(level) == ancestor_id) {
break;
@ -556,7 +614,7 @@ int64_t ObWkbToS2Visitor::get_cellids_and_unrepeated_ancestors(ObS2Cellids &cell
ret = hash_ret;
LOG_WARN("fail to check if key exist", K(ret), K(i));
}
prev_id = cellids[i];
prev_id = cell_union_[i];
}
if (OB_SUCC(ret) && has_reset_ && OB_FAIL(cells.push_back(exceedsBoundsCellID))) {
LOG_WARN("fail to push_back cellid", K(ret));
@ -607,6 +665,9 @@ void ObWkbToS2Visitor::reset()
S2cells_.clear();
invalid_ = false;
has_reset_ = true;
cell_union_.Clear();
// reset to empty rectangle
bounder_.~S2LatLngRectBounder();
}
template <typename ElementType>

View File

@ -46,7 +46,9 @@ public:
options_(options),
is_geog_(is_geog),
invalid_(false),
has_reset_(false)
has_reset_(false),
cell_union_(),
bounder_()
{
mbr_ = S2LatLngRect::Empty();
}
@ -97,12 +99,14 @@ public:
int64_t get_mbr(S2LatLngRect &mbr, bool need_buffer, S1Angle distance);
bool is_invalid() { return invalid_; }
void reset();
int get_s2_cell_union();
private:
double stToUV(double s);
bool exceedsBounds(double x, double y);
S2Point MakeS2PointFromXy(double x, double y);
int add_cell_from_point(S2Point point);
int add_cell_from_point(S2LatLng point);
bool is_full_range_cell_union(S2CellUnion &cellids);
template <typename ElementType>
static int vector_push_back(std::vector<ElementType> &vector, ElementType &element);
static int vector_emplace_back(std::vector<std::unique_ptr<S2Loop>> &vector, S2Loop *element);
@ -117,6 +121,8 @@ private:
bool is_geog_;
bool invalid_;
bool has_reset_;
S2CellUnion cell_union_;
S2LatLngRectBounder bounder_;
DISALLOW_COPY_AND_ASSIGN(ObWkbToS2Visitor);
};

View File

@ -350,6 +350,8 @@ int64_t ObS2Adapter::init(const ObString &swkb, const ObSrsBoundsItem *bound)
geo_ = geo;
if (OB_FAIL(geo->do_visit(*visitor_))) {
LOG_WARN("fail to do_visit by ObWkbToS2Visitor", K(ret));
} else if (OB_FAIL(visitor_->get_s2_cell_union())) {
LOG_WARN("fail to get s2 cell union", K(ret));
} else if (visitor_->is_invalid()) {
// 1. get valid geo inside bounds
ObGeometry *corrected_geo = NULL;
@ -370,6 +372,8 @@ int64_t ObS2Adapter::init(const ObString &swkb, const ObSrsBoundsItem *bound)
// 3. do_visit again
if (OB_FAIL(corrected_geo->do_visit(*visitor_))) {
LOG_WARN("fail to do_visit by ObWkbToS2Visitor", K(ret));
} else if (OB_FAIL(visitor_->get_s2_cell_union())) {
LOG_WARN("fail to get s2 cell union", K(ret));
}
}
}

View File

@ -650,6 +650,7 @@ Outputs & filters:
(3747839314902384640,MIN,MIN ; 3747839314902384640,MAX,MAX), (3748120789879095296,MIN,MIN ; 3748120789879095296,MAX,MAX), (3751498489599623168,MIN,MIN
; 3751498489599623168,MAX,MAX), (3765009288481734656,MIN,MIN ; 3765009288481734656,MAX,MAX), (3819052484010180608,MIN,MIN ; 3819052484010180608,MAX,MAX),
(3746994889972252672,MIN,MIN ; 3746994889972252672,MAX,MAX), (3458764513820540928,MIN,MIN ; 3458764513820540928,MAX,MAX)
drop table geek_poi_7;
drop table if exists t1;
create table t1( g geometry );//
drop PROCEDURE IF EXISTS pro;//
@ -672,3 +673,105 @@ select getg(ST_SymDifference(point(1,0),point(1,6)));//
getg(ST_SymDifference(point(1,0),point(1,6)))
MULTIPOINT((1 0),(1 6))
drop table t1;
drop table if exists highway_621;
CREATE TABLE `highway_621` (
`id` int(32) NOT NULL auto_increment,
`the_geom` geometry NOT NULL /*!80003 SRID 4326 */,
PRIMARY KEY (`id`),
SPATIAL KEY `idx_the_geom_highway_6` (`the_geom`) BLOCK_SIZE 16384 LOCAL
);
insert into highway_621(the_geom) values(ST_GeomFromText('point(120.34904267189361 30.320965261625222)',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('point(120.34904267189360 30.320965261625222)',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('linestring(120.34904267189360 30.320965261625222, 120.34904267189361 30.320965261625222)',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('linestring(120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013)',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('linestring(120.34904267189360 30.320965261625222, 120.34904267189360 30.320800629134425)',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('MULTIPOLYGON (((110.34904267189361 30.320965261625222, 110.35812237862895 30.321118189268013, 110.35812237865006 30.32111818926693, 110.35460911503478 30.32080062911392, 110.3546091159729 30.320800629134425, 110.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOLYGON(((120.31599964855097 30.243634005580816,120.3160009095347 30.243635469782166,120.31600747846684 30.24364742764055,120.31601121779788 30.243660263421923,120.31601198353063 30.243673482839302,120.31599964855097 30.243634005580816)),((120.3160009095347 30.243635469782166,120.31600747846684 30.24364742764055,120.31601121779788 30.243660263421923,120.31601198353063 30.243673482839302,120.31601159806742 30.24367573874217,120.3160009095347 30.243635469782166))),POLYGON((120.31599964855097 30.243634005580816,120.3160009095347 30.243635469782166,120.31600747846684 30.24364742764055,120.31601121779788 30.243660263421923,120.31601198353063 30.243673482839302,120.31599964855097 30.243634005580816)),LINESTRING(120.31599964855097 30.243634005580816,120.3160009095347 30.243635469782166),MULTIPOINT(120.31599964855097 30.243634005580816,120.3160009095347 30.243635469782166,120.31600747846684 30.24364742764055),point(120.31599964855097 30.243634005580816))',4326, 'axis-order=long-lat'));
explain select id, st_astext(the_geom) from highway_621 where ST_Intersects(the_geom, ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'));
Query Plan
==============================================================================
|ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)|
------------------------------------------------------------------------------
|0 |TABLE FULL SCAN|highway_621(idx_the_geom_highway_6)|12 |2947 |
==============================================================================
Outputs & filters:
-------------------------------------
0 - output([highway_621.id], [st_astext(highway_621.the_geom)]), filter([ST_Intersects(highway_621.the_geom, ST_GeomFromText('MULTIPOLYGON (((120.34904267189361
30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729
30.320800629134425, 120.34904267189361 30.320965261625222)))', 4326, 'axis-order=long-lat'))])
access([highway_621.id], [highway_621.the_geom]), partitions(p0)
is_index_back=true, is_global_index=false, filter_before_indexback[false],
range_key([highway_621.__cellid_17], [highway_621.__mbr_17], [highway_621.id]), range(3768553615552151552,MIN,MIN ; 3768553615552151552,MAX,MAX),
(3768553615485042688,MIN,MIN ; 3768553615485042688,MAX,MAX), (3768553614679736320,MIN,MIN ; 3768553614679736320,MAX,MAX), (3768553611458510848,MIN,MIN ;
3768553611458510848,MAX,MAX), (3768553615753478144,MIN,MIN ; 3768553615753478144,MAX,MAX), (3768553632933347328,MIN,MIN ; 3768553632933347328,MAX,MAX),
(3768553839091777536,MIN,MIN ; 3768553839091777536,MAX,MAX), (3768553014458056704,MIN,MIN ; 3768553014458056704,MAX,MAX), (3768549715923173376,MIN,MIN ;
3768549715923173376,MAX,MAX), (3768545317876662272,MIN,MIN ; 3768545317876662272,MAX,MAX), (3768598094434795520,MIN,MIN ; 3768598094434795520,MAX,MAX),
(3768668463178973184,MIN,MIN ; 3768668463178973184,MAX,MAX), (3768386988202262528,MIN,MIN ; 3768386988202262528,MAX,MAX), (3769512888109105152,MIN,MIN ;
3769512888109105152,MAX,MAX), (3765009288481734656,MIN,MIN ; 3765009288481734656,MAX,MAX), (3819052484010180608,MIN,MIN ; 3819052484010180608,MAX,MAX),
(3746994889972252672,MIN,MIN ; 3746994889972252672,MAX,MAX), (3458764513820540928,MIN,MIN ; 3458764513820540928,MAX,MAX), (3768553615686369280,MIN,MIN ;
3768553615686369280,MAX,MAX), (3768553615870918656,MIN,MIN ; 3768553615870918656,MAX,MAX), (3768553615820587008,MIN,MIN ; 3768553615820587008,MAX,MAX),
(3768553616021913600,MIN,MIN ; 3768553616021913600,MAX,MAX), (3768553616827219968,MIN,MIN ; 3768553616827219968,MAX,MAX), (3768553620048445440,MIN,MIN ;
3768553620048445440,MAX,MAX), (3768553615954804736,MIN,MIN ; 3768553615954804736,MAX,MAX), (3768553615938027520,MIN,MIN ; 3768553615938027520,MAX,MAX),
(3768553615971581952,MIN,MIN ; 3768553615971581952,MAX,MAX), (3768553616642670592,MIN,MIN ; 3768553616642670592,MAX,MAX), (3768553616625893376,MIN,MIN ;
3768553616625893376,MAX,MAX), (3768553616558784512,MIN,MIN ; 3768553616558784512,MAX,MAX), (3768553616760111104,MIN,MIN ; 3768553616760111104,MAX,MAX),
(3768553616776888320,MIN,MIN ; 3768553616776888320,MAX,MAX), (3768553616894328832,MIN,MIN ; 3768553616894328832,MAX,MAX), (3768553617095655424,MIN,MIN ;
3768553617095655424,MAX,MAX), (3768553617028546560,MIN,MIN ; 3768553617028546560,MAX,MAX), (3768553617045323776,MIN,MIN ; 3768553617045323776,MAX,MAX),
(3768553622263037952,MIN,MIN ; 3768553622263037952,MAX,MAX), (3768553622464364544,MIN,MIN ; 3768553622464364544,MAX,MAX), (3768553623269670912,MIN,MIN ;
3768553623269670912,MAX,MAX), (3768553622258843648,MIN,MIN ; 3768553622258843648,MAX,MAX), (3768553622246260736,MIN,MIN ; 3768553622246260736,MAX,MAX),
(3768553622397255680,MIN,MIN ; 3768553622397255680,MAX,MAX), (3768553622531473408,MIN,MIN ; 3768553622531473408,MAX,MAX), (3768553622665691136,MIN,MIN ;
3768553622665691136,MAX,MAX), (3768553622799908864,MIN,MIN ; 3768553622799908864,MAX,MAX), (3768553623001235456,MIN,MIN ; 3768553623001235456,MAX,MAX),
(3768553623202562048,MIN,MIN ; 3768553623202562048,MAX,MAX), (3768553623252893696,MIN,MIN ; 3768553623252893696,MAX,MAX), (3768553643201003520,MIN,MIN ;
3768553643201003520,MAX,MAX), (3768553643402330112,MIN,MIN ; 3768553643402330112,MAX,MAX), (3768553642597023744,MIN,MIN ; 3768553642597023744,MAX,MAX),
(3768553645818249216,MIN,MIN ; 3768553645818249216,MAX,MAX), (3768553650113216512,MIN,MIN ; 3768553650113216512,MAX,MAX), (3768553643808129024,MIN,MIN ;
3768553643808129024,MAX,MAX), (3768553643809177600,MIN,MIN ; 3768553643809177600,MAX,MAX), (3768553643821760512,MIN,MIN ; 3768553643821760512,MAX,MAX),
(3768553643872092160,MIN,MIN ; 3768553643872092160,MAX,MAX), (3768553643939201024,MIN,MIN ; 3768553643939201024,MAX,MAX), (3768553644744507392,MIN,MIN ;
3768553644744507392,MAX,MAX), (3768553615585705985,MIN,MIN ; 3768553615619260415,MAX,MAX), (3768553615619260417,MIN,MIN ; 3768553615652814847,MAX,MAX),
(3768553615854141441,MIN,MIN ; 3768553615862530047,MAX,MAX), (3768553615879307265,MIN,MIN ; 3768553615887695871,MAX,MAX), (3768553615887695873,MIN,MIN ;
3768553615921250303,MAX,MAX), (3768553615946416129,MIN,MIN ; 3768553615954804735,MAX,MAX), (3768553615954804737,MIN,MIN ; 3768553615963193343,MAX,MAX),
(3768553615979970561,MIN,MIN ; 3768553615988359167,MAX,MAX), (3768553615988359169,MIN,MIN ; 3768553616021913599,MAX,MAX), (3768553616021913601,MIN,MIN ;
3768553616156131327,MAX,MAX), (3768553616642670593,MIN,MIN ; 3768553616651059199,MAX,MAX), (3768553616651059201,MIN,MIN ; 3768553616659447807,MAX,MAX),
(3768553616659447809,MIN,MIN ; 3768553616693002239,MAX,MAX), (3768553616693002241,MIN,MIN ; 3768553616726556671,MAX,MAX), (3768553616785276929,MIN,MIN ;
3768553616793665535,MAX,MAX), (3768553616793665537,MIN,MIN ; 3768553616827219967,MAX,MAX), (3768553616827219969,MIN,MIN ; 3768553616860774399,MAX,MAX),
(3768553616927883265,MIN,MIN ; 3768553616961437695,MAX,MAX), (3768553616961437697,MIN,MIN ; 3768553616994992127,MAX,MAX), (3768553616994992129,MIN,MIN ;
3768553617028546559,MAX,MAX), (3768553617036935169,MIN,MIN ; 3768553617045323775,MAX,MAX), (3768553622195929089,MIN,MIN ; 3768553622229483519,MAX,MAX),
(3768553622260940801,MIN,MIN ; 3768553622263037951,MAX,MAX), (3768553622263037953,MIN,MIN ; 3768553622296592383,MAX,MAX), (3768553622296592385,MIN,MIN ;
3768553622330146815,MAX,MAX), (3768553622430810113,MIN,MIN ; 3768553622464364543,MAX,MAX), (3768553622464364545,MIN,MIN ; 3768553622497918975,MAX,MAX),
(3768553622565027841,MIN,MIN ; 3768553622598582271,MAX,MAX), (3768553622598582273,MIN,MIN ; 3768553622632136703,MAX,MAX), (3768553622632136705,MIN,MIN ;
3768553622665691135,MAX,MAX), (3768553622766354433,MIN,MIN ; 3768553622799908863,MAX,MAX), (3768553623001235457,MIN,MIN ; 3768553623135453183,MAX,MAX),
(3768553623135453185,MIN,MIN ; 3768553623169007615,MAX,MAX), (3768553623169007617,MIN,MIN ; 3768553623202562047,MAX,MAX), (3768553623202562049,MIN,MIN ;
3768553623236116479,MAX,MAX), (3768553623244505089,MIN,MIN ; 3768553623252893695,MAX,MAX), (3768553643167449089,MIN,MIN ; 3768553643201003519,MAX,MAX),
(3768553643201003521,MIN,MIN ; 3768553643234557951,MAX,MAX), (3768553643536547841,MIN,MIN ; 3768553643670765567,MAX,MAX), (3768553643807604737,MIN,MIN ;
3768553643808129023,MAX,MAX), (3768553643830149121,MIN,MIN ; 3768553643838537727,MAX,MAX)
select id, st_astext(the_geom) from highway_621 where ST_Intersects(the_geom, ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'));
id st_astext(the_geom)
1 POINT(30.320965261625222 120.34904267189361)
3 LINESTRING(30.320965261625222 120.3490426718936,30.320965261625222 120.34904267189361)
4 LINESTRING(30.320965261625222 120.34904267189361,30.321118189268013 120.35612237862895)
5 LINESTRING(30.320965261625222 120.3490426718936,30.320800629134425 120.3490426718936)
6 MULTIPOLYGON(((30.320965261625222 120.34904267189361,30.321118189268013 120.35612237862895,30.32111818926693 120.35612237865006,30.32080062911392 120.35460911503478,30.320800629134425 120.3546091159729,30.320965261625222 120.34904267189361)))
select id, st_astext(the_geom) from highway_621 where _ST_covers(ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'), the_geom);
id st_astext(the_geom)
1 POINT(30.320965261625222 120.34904267189361)
4 LINESTRING(30.320965261625222 120.34904267189361,30.321118189268013 120.35612237862895)
select id, st_astext(the_geom) from highway_621 ignore index(idx_the_geom_highway_6) where ST_Intersects(the_geom, ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'));
id st_astext(the_geom)
1 POINT(30.320965261625222 120.34904267189361)
3 LINESTRING(30.320965261625222 120.3490426718936,30.320965261625222 120.34904267189361)
4 LINESTRING(30.320965261625222 120.34904267189361,30.321118189268013 120.35612237862895)
5 LINESTRING(30.320965261625222 120.3490426718936,30.320800629134425 120.3490426718936)
6 MULTIPOLYGON(((30.320965261625222 120.34904267189361,30.321118189268013 120.35612237862895,30.32111818926693 120.35612237865006,30.32080062911392 120.35460911503478,30.320800629134425 120.3546091159729,30.320965261625222 120.34904267189361)))
select id, st_astext(the_geom) from highway_621 ignore index(idx_the_geom_highway_6) where _ST_covers(ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'), the_geom);
id st_astext(the_geom)
1 POINT(30.320965261625222 120.34904267189361)
4 LINESTRING(30.320965261625222 120.34904267189361,30.321118189268013 120.35612237862895)
select id, st_astext(the_geom) from highway_621 where ST_Intersects(the_geom, ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222))),POLYGON ((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)),multipoint(120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693),point(120.31601198353063 30.243673482839302))',4326, 'axis-order=long-lat'));
id st_astext(the_geom)
1 POINT(30.320965261625222 120.34904267189361)
2 POINT(30.320965261625222 120.3490426718936)
3 LINESTRING(30.320965261625222 120.3490426718936,30.320965261625222 120.34904267189361)
4 LINESTRING(30.320965261625222 120.34904267189361,30.321118189268013 120.35612237862895)
5 LINESTRING(30.320965261625222 120.3490426718936,30.320800629134425 120.3490426718936)
6 MULTIPOLYGON(((30.320965261625222 120.34904267189361,30.321118189268013 120.35612237862895,30.32111818926693 120.35612237865006,30.32080062911392 120.35460911503478,30.320800629134425 120.3546091159729,30.320965261625222 120.34904267189361)))
8 GEOMETRYCOLLECTION(MULTIPOLYGON(((30.243634005580816 120.31599964855097,30.243635469782166 120.3160009095347,30.24364742764055 120.31600747846684,30.243660263421923 120.31601121779788,30.243673482839302 120.31601198353063,30.243634005580816 120.31599964855097)),((30.243635469782166 120.3160009095347,30.24364742764055 120.31600747846684,30.243660263421923 120.31601121779788,30.243673482839302 120.31601198353063,30.24367573874217 120.31601159806742,30.243635469782166 120.3160009095347))),POLYGON((30.243634005580816 120.31599964855097,30.243635469782166 120.3160009095347,30.24364742764055 120.31600747846684,30.243660263421923 120.31601121779788,30.243673482839302 120.31601198353063,30.243634005580816 120.31599964855097)),LINESTRING(30.243634005580816 120.31599964855097,30.243635469782166 120.3160009095347),MULTIPOINT((30.243634005580816 120.31599964855097),(30.243635469782166 120.3160009095347),(30.24364742764055 120.31600747846684)),POINT(30.243634005580816 120.31599964855097))
drop table highway_621;

View File

@ -418,6 +418,9 @@ call dbms_stats.gather_table_stats('test','geek_poi_7');
--enable_result_log
explain SELECT p.p_id,0 as distance FROM geek_poi_7 as p WHERE p.geohash_code like 'ws0emp%' and p.p_delete_time = 0 AND ST_Contains(p.geog_poi,_ST_GeogFromText('POINT(113.42416381835938 23.11138916015625)'));
drop table geek_poi_7;
--disable_warnings
drop table if exists t1;
--enable_warnings
delimiter //;
@ -443,3 +446,30 @@ select getg(ST_SymDifference(point(1,0),point(1,6)));//
delimiter ;//
drop table t1;
--disable_warnings
drop table if exists highway_621;
--enable_warnings
CREATE TABLE `highway_621` (
`id` int(32) NOT NULL auto_increment,
`the_geom` geometry NOT NULL /*!80003 SRID 4326 */,
PRIMARY KEY (`id`),
SPATIAL KEY `idx_the_geom_highway_6` (`the_geom`) BLOCK_SIZE 16384 LOCAL
);
insert into highway_621(the_geom) values(ST_GeomFromText('point(120.34904267189361 30.320965261625222)',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('point(120.34904267189360 30.320965261625222)',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('linestring(120.34904267189360 30.320965261625222, 120.34904267189361 30.320965261625222)',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('linestring(120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013)',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('linestring(120.34904267189360 30.320965261625222, 120.34904267189360 30.320800629134425)',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('MULTIPOLYGON (((110.34904267189361 30.320965261625222, 110.35812237862895 30.321118189268013, 110.35812237865006 30.32111818926693, 110.35460911503478 30.32080062911392, 110.3546091159729 30.320800629134425, 110.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'));
insert into highway_621(the_geom) values(ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOLYGON(((120.31599964855097 30.243634005580816,120.3160009095347 30.243635469782166,120.31600747846684 30.24364742764055,120.31601121779788 30.243660263421923,120.31601198353063 30.243673482839302,120.31599964855097 30.243634005580816)),((120.3160009095347 30.243635469782166,120.31600747846684 30.24364742764055,120.31601121779788 30.243660263421923,120.31601198353063 30.243673482839302,120.31601159806742 30.24367573874217,120.3160009095347 30.243635469782166))),POLYGON((120.31599964855097 30.243634005580816,120.3160009095347 30.243635469782166,120.31600747846684 30.24364742764055,120.31601121779788 30.243660263421923,120.31601198353063 30.243673482839302,120.31599964855097 30.243634005580816)),LINESTRING(120.31599964855097 30.243634005580816,120.3160009095347 30.243635469782166),MULTIPOINT(120.31599964855097 30.243634005580816,120.3160009095347 30.243635469782166,120.31600747846684 30.24364742764055),point(120.31599964855097 30.243634005580816))',4326, 'axis-order=long-lat'));
explain select id, st_astext(the_geom) from highway_621 where ST_Intersects(the_geom, ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'));
select id, st_astext(the_geom) from highway_621 where ST_Intersects(the_geom, ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'));
select id, st_astext(the_geom) from highway_621 where _ST_covers(ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'), the_geom);
select id, st_astext(the_geom) from highway_621 ignore index(idx_the_geom_highway_6) where ST_Intersects(the_geom, ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'));
select id, st_astext(the_geom) from highway_621 ignore index(idx_the_geom_highway_6) where _ST_covers(ST_GeomFromText('MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)))',4326, 'axis-order=long-lat'), the_geom);
select id, st_astext(the_geom) from highway_621 where ST_Intersects(the_geom, ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOLYGON (((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222))),POLYGON ((120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693, 120.35460911503478 30.32080062911392, 120.3546091159729 30.320800629134425, 120.34904267189361 30.320965261625222)),multipoint(120.34904267189361 30.320965261625222, 120.35612237862895 30.321118189268013, 120.35612237865006 30.32111818926693),point(120.31601198353063 30.243673482839302))',4326, 'axis-order=long-lat'));
drop table highway_621;

View File

@ -236,8 +236,11 @@ void printCellid(ObS2Cellids &cells) {
S2CellId tmp(it);
std::cout << "F" << tmp.face();
std::cout << "/L" << tmp.level() << "/";
for (int level = 1; level <= tmp.level(); level++) {
std::cout << tmp.child_position(level);
for (int level = 1; level <= tmp.level() && !tmp.is_leaf(); level++) {
std::cout << tmp.child_position(level);
}
if (tmp.is_leaf()) {
std::cout << tmp.id();
}
std::cout << std::endl;
}