Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with the cases when type infer is not precise in Gremlin queries in GOpt #3802

Closed
BingqingLyu opened this issue May 15, 2024 · 1 comment
Assignees

Comments

@BingqingLyu
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

Currently, in gremlin queries, the type infer may not be precise (for the operators those are not in match()) in GOpt.
For example,

g.V().hasLabel("PERSON").out("KNOWS").count()

The query plan looks like (we focus on the types here, and omit most fields in the plan):

    operations: [                                                                                                                                                                                                                   [738/1968]
        PhysicalOpr {
            opr: Scan(
                Scan {
                    scan_opt: Vertex,
                    alias: None,
                    params: Some(
                        QueryParams {
                            tables: [
                                NameOrId {
                                    item: Some(
                                        Id(
                                            1,
                                        ),
                                    ),
                                },
                            ],
                            ...
                        },
                    ),
                    ...
                },
            ),
        },
        PhysicalOpr {
            opr: Edge(
                EdgeExpand {
                    v_tag: None,
                    direction: Out,
                    params: Some(
                        QueryParams {
                            tables: [
                                NameOrId {
                                    item: Some(
                                        Id(
                                            12,
                                        ),
                                    ),
                                },
                            ],
                            columns: [
                                NameOrId {
                                    item: Some(
                                        Name(
                                            "creationDate",
                                        ),
                                    ),
                                },
                            ],
                            is_all_columns: false,
                            limit: None,
                            predicate: None,
                            sample_ratio: 1.0,
                            extra: {},
                        },
                    ),
                    alias: None,
                    expand_opt: Edge,
                    is_optional: false,
                },
            ),
        },
        PhysicalOpr {
            opr: Vertex(
                GetV {
                    tag: None,
                    opt: End,
                    params: Some(
                        QueryParams {
                            tables: [
                                NameOrId {
                                    item: Some(
                                        Id(
                                            0,
                                        ),
                                    ),
                                },
                                NameOrId {
                                    item: Some(
                                        Id(
                                            1,
                                        ),
                                    ),
                                },
                                NameOrId {
                                    item: Some(
                                        Id(
                                            2,
                                        ),
                                    ),
                                },
                                NameOrId {
                                    item: Some(
                                        Id(
                                            3,
                                        ),
                                    ),
                                },
                                NameOrId {
                                    item: Some(
                                        Id(
                                            4,
                                        ),
                                    ),
                                },
                                NameOrId {
                                    item: Some(
                                        Id(
                                            5,
                                        ),
                                    ),
                                },
                                NameOrId {
                                    item: Some(
                                        Id(
                                            6,
                                        ),
                                    ),
                                },
                                NameOrId {
                                    item: Some(
                                        Id(
                                            7,
                                        ),
                                    ),
                                },
                            ],
                            columns: [],
                            is_all_columns: false,
                            limit: None,
                            predicate: None,
                            sample_ratio: 1.0,
                            extra: {},
                        },
                    ),
                    alias: None,
                },
            ),
        },

Here, the GetV's query params contains all vertex types, which will involve extra unnecessary computation in Runtime (to check if the expanded vertices satisfy the constraints in query param).

However, this seems common in Gremlin queries (users may not always query like g.V().hasLabel("PERSON").out("KNOWS").hasLabel("PERSON").count()). Try to optimize such cases.

@BingqingLyu BingqingLyu self-assigned this May 15, 2024
siyuan0322 pushed a commit that referenced this issue May 20, 2024
…n `GetV` has imprecise types (#3804)

<!--
Thanks for your contribution! please review
https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before
opening an issue.
-->

## What do these changes do?

<!-- Please give a short brief about these changes. -->

As titled. This pr:
1. Fix a bug in `ExpandGetVFusionRule`. For example, assume we have edge
types of `person-likes-comment`, `person-likes-post`,
`person-knows-person` in schema. Then in queries, if we want to expand
`person-likes-comment`, we would generate a
`Expand(likes)+GetV(comment)` (before this fix, we generate a
`Expand(likes)` only, which is a bug); And if we want to expand
`person-knows-person`, we simply generate a `Expand(knows)`.
2. Optimize cases when the types in GetV is imprecise, to avoid
unnecessary filtering in Runtime.

## Related issue number

<!-- Are there any issues opened that will be resolved by merging this
change? -->

Fixes #3732 #3802

---------

Co-authored-by: Xiaoli Zhou <yihe.zxl@alibaba-inc.com>
@siyuan0322
Copy link
Collaborator

fixed by #3804

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants