Skip to content

Commit

Permalink
fix the bug that index scan rule chooses a wrong geo index (vesoft-in…
Browse files Browse the repository at this point in the history
  • Loading branch information
jievince authored Aug 14, 2024
1 parent c078c6c commit 40ee8ac
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
27 changes: 22 additions & 5 deletions src/graph/optimizer/rule/GeoPredicateIndexScanBaseRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ StatusOr<TransformResult> GeoPredicateIndexScanBaseRule::transform(
return TransformResult::noTransform();
}

const std::string& geoProp = static_cast<PropertyExpression*>(first)->prop();

if (!graph::ExpressionUtils::isEvaluableExpr(second, qctx)) {
return TransformResult::noTransform();
}
Expand All @@ -94,18 +96,33 @@ StatusOr<TransformResult> GeoPredicateIndexScanBaseRule::transform(

const auto& geog = secondVal.getGeography();

auto indexItem = indexItems.back();
const auto& fields = indexItem->get_fields();
if (fields.size() != 1) {
std::shared_ptr<nebula::meta::cpp2::IndexItem> geoIndexItem = nullptr;
for (auto& indexItem : indexItems) {
auto& fields = indexItem->get_fields();
if (fields.size() != 1) {
continue;
}
if (fields[0].get_type().get_type() != nebula::cpp2::PropertyType::GEOGRAPHY) {
continue;
}
if (fields[0].get_name() != geoProp) {
continue;
}
geoIndexItem = indexItem;
break;
}
if (!geoIndexItem) {
return TransformResult::noTransform();
}
const auto& fields = geoIndexItem->get_fields();
DCHECK_EQ(fields.size(), 1);
auto& geoField = fields.back();
auto& geoColumnTypeDef = geoField.get_type();
bool isPointColumn = geoColumnTypeDef.geo_shape_ref().has_value() &&
geoColumnTypeDef.geo_shape_ref().value() == meta::cpp2::GeoShape::POINT;

geo::RegionCoverParams rc;
const auto* indexParams = indexItem->get_index_params();
const auto* indexParams = geoIndexItem->get_index_params();
if (indexParams) {
if (indexParams->s2_max_level_ref().has_value()) {
rc.maxCellLevel_ = indexParams->s2_max_level_ref().value();
Expand Down Expand Up @@ -145,7 +162,7 @@ StatusOr<TransformResult> GeoPredicateIndexScanBaseRule::transform(
auto indexColumnHint = scanRange.toIndexColumnHint();
indexColumnHint.column_name_ref() = fieldName;
ictx.filter_ref() = condition->encode();
ictx.index_id_ref() = indexItem->get_index_id();
ictx.index_id_ref() = geoIndexItem->get_index_id();
ictx.column_hints_ref() = {indexColumnHint};
idxCtxs.emplace_back(std::move(ictx));
}
Expand Down
23 changes: 20 additions & 3 deletions tests/tck/features/geo/GeoBase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: Geo base
| collate | utf8_bin |
And having executed:
"""
CREATE TAG any_shape(geo geography);
CREATE TAG any_shape(geo geography, non_geo_prop int64);
CREATE TAG only_point(geo geography(point));
CREATE TAG only_linestring(geo geography(linestring));
CREATE TAG only_polygon(geo geography(polygon));
Expand All @@ -29,8 +29,9 @@ Feature: Geo base
DESC TAG any_shape;
"""
Then the result should be, in any order:
| Field | Type | Null | Default | Comment |
| "geo" | "geography" | "YES" | EMPTY | EMPTY |
| Field | Type | Null | Default | Comment |
| "geo" | "geography" | "YES" | EMPTY | EMPTY |
| "non_geo_prop" | "int64" | "YES" | EMPTY | EMPTY |
When executing query:
"""
DESC TAG only_point;
Expand Down Expand Up @@ -233,6 +234,11 @@ Feature: Geo base
CREATE TAG INDEX any_shape_geo_index ON any_shape(geo) with (s2_max_level=30, s2_max_cells=8) comment "test";
"""
Then the execution should be successful
When executing query:
"""
CREATE TAG INDEX non_geo_prop_index ON any_shape(non_geo_prop);
"""
Then the execution should be successful
When executing query:
"""
CREATE TAG INDEX only_point_geo_index ON only_point(geo) comment "test2";
Expand Down Expand Up @@ -268,6 +274,11 @@ Feature: Geo base
REBUILD TAG INDEX any_shape_geo_index;
"""
Then wait the job to finish
When submit a job:
"""
REBUILD TAG INDEX non_geo_prop_index;
"""
Then wait the job to finish
When submit a job:
"""
REBUILD TAG INDEX only_point_geo_index;
Expand Down Expand Up @@ -757,6 +768,12 @@ Feature: Geo base
"""
Then the execution should be successful
And wait 3 seconds
When executing query:
"""
DROP TAG INDEX non_geo_prop_index;
"""
Then the execution should be successful
And wait 3 seconds
When executing query and retrying it on failure every 6 seconds for 3 times:
"""
LOOKUP ON any_shape YIELD id(vertex) as id;
Expand Down

0 comments on commit 40ee8ac

Please sign in to comment.