Skip to content

[feature][CGS][manager] optimize slow sql query in label manager by adding direct label id lookup #1041

Description

@v-kkhuang

Search before asking

  • I had searched in the issues and found no similar feature requirement.

Problem Description

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

The current implementation of getNodeRelationsByLabels method uses full label objects to query node relations, which can cause slow SQL queries when dealing with large datasets. The query performance is suboptimal due to complex label value comparisons.

Description

A short description of your feature

Add a new method getNodeRelationsByLabelIds that accepts label IDs directly instead of full label objects, optimizing the SQL query to use simple ID-based lookups with INNER JOINs.

Use case

Describe the use case of your feature request and the solution you'd like.

This optimization improves query performance significantly when:

  • Querying node relations for a large number of labels
  • The system has many service instances and labels
  • Frequent label-based lookups are required

The new method uses direct ID comparisons which are much faster than label value string comparisons.

Solutions

Describe alternatives you've considered.

  • Keep the existing method and optimize the SQL (rejected: requires extensive refactoring)
  • Add database indexes (rejected: adds maintenance overhead)
  • Add new method with ID-based lookup (accepted: clean and efficient)

Anything else

Additional context or screenshots about the feature request.

This change maintains backward compatibility by keeping the original getNodeRelationsByLabels method intact.

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions