dosubot[bot] commented on issue #2929: URL: https://github.com/apache/incubator-hugegraph/issues/2929#issuecomment-3714894172
<!-- Greeting --> Hi @guijinxin! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the incubator-hugegraph team. <!-- Answer --> HugeGraph enforces index requirements differently depending on how filters are expressed in Gremlin. When you use a top-level `has` step (like in your first query), HugeGraph's query optimizer tries to push the filter into the backend query. If the property (like `ep4`) is not indexed, it throws a `NoIndexException` to avoid a full scan. However, when you use `match` or nest filters inside traversals (like your second query), those filters are applied after data retrieval as in-memory predicates, so the index check is bypassed and no exception is thrown—even though the logic is the same. This difference is not documented as a feature, but is a result of how HugeGraph's query planner works: only filters directly following `g.E()`/`g.V()` are "hoisted" into the backend query and subject to index enforcement. Filters inside `match`, `and`, or similar steps are evaluated later, which is why you see inconsistent behavior between the two queries. Other graph databases like JanusGraph and TinkerPop do not enforce index requirements in the same way, which is why you get consistent results there. If you want consistent behavior and performance, it's best to ensure that properties you filter on (especially with range or secondary conditions) are indexed, or be aware that using `match`/nested traversals may bypass index checks and lead to full scans or unexpected results. This is a known area for optimization in HugeGraph, but as of 1.7.0, this is the expected behavior given the current query planner design. References: - [HugeGraph query optimization and index enforcement](https://github.com/apache/incubator-hugegraph/blob/a53af864b31f803780a1db31cb20d3d94d5d34fc/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStepStrategy.java) - [ConditionQuery and index checks](https://github.com/apache/incubator-hugegraph/blob/a53af864b31f803780a1db31cb20d3d94d5d34fc/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java) - [HugeGraph indexing discussion](https://github.com/apache/incubator-hugegraph/discussions/2739) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/2f3ea7c4-d73d-4136-8b32-6ddff3510b63?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2f3ea7c4-d73d-4136-8b32-6ddff3510b63?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2f3ea7c4-d73d-4136-8b32-6ddff3510b63?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2f3ea7c4-d73d-4136-8b32-6ddff3510b63?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2f3ea7c4-d73d-4136-8b32-6ddff3510b63?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2f3ea7c4-d73d-4136-8b32-6ddff3510b63?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2f3ea7c4-d73d-4136-8b32-6ddff3510b63?feedback_type=other)</sup> [](https://app.dosu.dev/e5e246fa-a522-4d8a-ab3c-e2588b5b501b/ask?utm_source=github) [](https://cursor.com/link/prompt?text=HugeGraph%20enforces%20index%20requirements%20differently%20depending%20on%20how%20filters%20are%20expressed%20in%20Gremlin.%20When%20you%20use%20a%20top-level%20%60has%60%20step%20%28like%20in%20your%20first%20query%29%2C%20HugeGraph%27s%20query%20optimizer%20tries%20to%20push%20the%20filter%20into%20the%20backend%20query.%20If%20the%20property%20%28like%20%60ep4%60%29%20is%20not%20indexed%2C%20it%20throws%20a%20%60NoIndexException%60%20to%20avoid%20a%20full%20scan.%20However%2C%20when%20you%20use%20%60match%60%20or%20nest%20filters%20inside%20traversals%20%28like%20your%20second%20query%29%2C%20those%20filters%20are%20applied%20after%20data%20retrieval%20as%20in-memory%20predicates%2C%20so%20the%20index%20check%20is%20bypassed%20and%20no%20except ion%20is%20thrown%E2%80%94even%20though%20the%20logic%20is%20the%20same.%0A%0AThis%20difference%20is%20not%20documented%20as%20a%20feature%2C%20but%20is%20a%20result%20of%20how%20HugeGraph%27s%20query%20planner%20works%3A%20only%20filters%20directly%20following%20%60g.E%28%29%60/%60g.V%28%29%60%20are%20%22hoisted%22%20into%20the%20backend%20query%20and%20subject%20to%20index%20enforcement.%20Filters%20inside%20%60match%60%2C%20%60and%60%2C%20or%20similar%20steps%20are%20evaluated%20later%2C%20which%20is%20why%20you%20see%20inconsistent%20behavior%20between%20the%20two%20queries.%20Other%20graph%20databases%20like%20JanusGraph%20and%20TinkerPop%20do%20not%20enforce%20index%20requirements%20in%20the%20same%20way%2C%20which%20is%20why%20you%20get%20consistent%20results%20there.%0A%0AIf%20you%20want%20consistent%20behavior%20and%20performance%2C%20it%27s%20best%20to%20ensure%20that%20properties%20you%20filter%20on%20%28especially%20with%20range%20or%20secondary%20conditions%29%20are%20i ndexed%2C%20or%20be%20aware%20that%20using%20%60match%60/nested%20traversals%20may%20bypass%20index%20checks%20and%20lead%20to%20full%20scans%20or%20unexpected%20results.%20This%20is%20a%20known%20area%20for%20optimization%20in%20HugeGraph%2C%20but%20as%20of%201.7.0%2C%20this%20is%20the%20expected%20behavior%20given%20the%20current%20query%20planner%20design.%0A%0AReferences%3A%0A-%20%5BHugeGraph%20query%20optimization%20and%20index%20enforcement%5D%28https%3A//github.com/apache/incubator-hugegraph/blob/a53af864b31f803780a1db31cb20d3d94d5d34fc/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStepStrategy.java%29%0A-%20%5BConditionQuery%20and%20index%20checks%5D%28https%3A//github.com/apache/incubator-hugegraph/blob/a53af864b31f803780a1db31cb20d3d94d5d34fc/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java%29%0A-%20%5BHugeGraph%20indexing%20discussion%5D%28https%3A//github.com/apache/incub ator-hugegraph/discussions/2739%29) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/incubator-hugegraph/issues/2929) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
