Skip to content

Commit 40ee8ac

Browse files
authored
fix the bug that index scan rule chooses a wrong geo index (#5922)
1 parent c078c6c commit 40ee8ac

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/graph/optimizer/rule/GeoPredicateIndexScanBaseRule.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ StatusOr<TransformResult> GeoPredicateIndexScanBaseRule::transform(
8383
return TransformResult::noTransform();
8484
}
8585

86+
const std::string& geoProp = static_cast<PropertyExpression*>(first)->prop();
87+
8688
if (!graph::ExpressionUtils::isEvaluableExpr(second, qctx)) {
8789
return TransformResult::noTransform();
8890
}
@@ -94,18 +96,33 @@ StatusOr<TransformResult> GeoPredicateIndexScanBaseRule::transform(
9496

9597
const auto& geog = secondVal.getGeography();
9698

97-
auto indexItem = indexItems.back();
98-
const auto& fields = indexItem->get_fields();
99-
if (fields.size() != 1) {
99+
std::shared_ptr<nebula::meta::cpp2::IndexItem> geoIndexItem = nullptr;
100+
for (auto& indexItem : indexItems) {
101+
auto& fields = indexItem->get_fields();
102+
if (fields.size() != 1) {
103+
continue;
104+
}
105+
if (fields[0].get_type().get_type() != nebula::cpp2::PropertyType::GEOGRAPHY) {
106+
continue;
107+
}
108+
if (fields[0].get_name() != geoProp) {
109+
continue;
110+
}
111+
geoIndexItem = indexItem;
112+
break;
113+
}
114+
if (!geoIndexItem) {
100115
return TransformResult::noTransform();
101116
}
117+
const auto& fields = geoIndexItem->get_fields();
118+
DCHECK_EQ(fields.size(), 1);
102119
auto& geoField = fields.back();
103120
auto& geoColumnTypeDef = geoField.get_type();
104121
bool isPointColumn = geoColumnTypeDef.geo_shape_ref().has_value() &&
105122
geoColumnTypeDef.geo_shape_ref().value() == meta::cpp2::GeoShape::POINT;
106123

107124
geo::RegionCoverParams rc;
108-
const auto* indexParams = indexItem->get_index_params();
125+
const auto* indexParams = geoIndexItem->get_index_params();
109126
if (indexParams) {
110127
if (indexParams->s2_max_level_ref().has_value()) {
111128
rc.maxCellLevel_ = indexParams->s2_max_level_ref().value();
@@ -145,7 +162,7 @@ StatusOr<TransformResult> GeoPredicateIndexScanBaseRule::transform(
145162
auto indexColumnHint = scanRange.toIndexColumnHint();
146163
indexColumnHint.column_name_ref() = fieldName;
147164
ictx.filter_ref() = condition->encode();
148-
ictx.index_id_ref() = indexItem->get_index_id();
165+
ictx.index_id_ref() = geoIndexItem->get_index_id();
149166
ictx.column_hints_ref() = {indexColumnHint};
150167
idxCtxs.emplace_back(std::move(ictx));
151168
}

tests/tck/features/geo/GeoBase.feature

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Feature: Geo base
1313
| collate | utf8_bin |
1414
And having executed:
1515
"""
16-
CREATE TAG any_shape(geo geography);
16+
CREATE TAG any_shape(geo geography, non_geo_prop int64);
1717
CREATE TAG only_point(geo geography(point));
1818
CREATE TAG only_linestring(geo geography(linestring));
1919
CREATE TAG only_polygon(geo geography(polygon));
@@ -29,8 +29,9 @@ Feature: Geo base
2929
DESC TAG any_shape;
3030
"""
3131
Then the result should be, in any order:
32-
| Field | Type | Null | Default | Comment |
33-
| "geo" | "geography" | "YES" | EMPTY | EMPTY |
32+
| Field | Type | Null | Default | Comment |
33+
| "geo" | "geography" | "YES" | EMPTY | EMPTY |
34+
| "non_geo_prop" | "int64" | "YES" | EMPTY | EMPTY |
3435
When executing query:
3536
"""
3637
DESC TAG only_point;
@@ -233,6 +234,11 @@ Feature: Geo base
233234
CREATE TAG INDEX any_shape_geo_index ON any_shape(geo) with (s2_max_level=30, s2_max_cells=8) comment "test";
234235
"""
235236
Then the execution should be successful
237+
When executing query:
238+
"""
239+
CREATE TAG INDEX non_geo_prop_index ON any_shape(non_geo_prop);
240+
"""
241+
Then the execution should be successful
236242
When executing query:
237243
"""
238244
CREATE TAG INDEX only_point_geo_index ON only_point(geo) comment "test2";
@@ -268,6 +274,11 @@ Feature: Geo base
268274
REBUILD TAG INDEX any_shape_geo_index;
269275
"""
270276
Then wait the job to finish
277+
When submit a job:
278+
"""
279+
REBUILD TAG INDEX non_geo_prop_index;
280+
"""
281+
Then wait the job to finish
271282
When submit a job:
272283
"""
273284
REBUILD TAG INDEX only_point_geo_index;
@@ -757,6 +768,12 @@ Feature: Geo base
757768
"""
758769
Then the execution should be successful
759770
And wait 3 seconds
771+
When executing query:
772+
"""
773+
DROP TAG INDEX non_geo_prop_index;
774+
"""
775+
Then the execution should be successful
776+
And wait 3 seconds
760777
When executing query and retrying it on failure every 6 seconds for 3 times:
761778
"""
762779
LOOKUP ON any_shape YIELD id(vertex) as id;

0 commit comments

Comments
 (0)