Skip to content

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

Merged
casionone merged 1 commit into
dev-2.0.0-webankfrom
dev-2.0.0-fix-slow-sql
Jun 2, 2026
Merged

[perf][CGS][manager] optimize slow sql query in label manager by adding direct label id lookup#1042
casionone merged 1 commit into
dev-2.0.0-webankfrom
dev-2.0.0-fix-slow-sql

Conversation

@v-kkhuang

Copy link
Copy Markdown

What is the purpose of the change

Background/Problem:
The current implementation of getNodeRelationsByLabels method in LabelManagerMapper 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 and full table scans.

Purpose of Change:
To address this performance issue, this PR adds a new method getNodeRelationsByLabelIds that accepts label IDs directly instead of full label objects. The new method uses optimized SQL with INNER JOINs and simple ID-based lookups.

Value/Impact:
After the change, query performance is significantly improved when querying node relations for large numbers of labels, reducing database load and improving system responsiveness.

Related issues/PRs

Related issues: close #1041
Related pr:none

Brief change log

  • Add getNodeRelationsByLabelIds method to LabelManagerMapper interface
  • Implement optimized SQL query using INNER JOINs in LabelManagerMapper.xml
  • Update DefaultLabelManagerPersistence to support new lookup method
  • Optimize query performance by using direct label ID comparisons instead of label value comparisons

Checklist

  • I have read the Contributing Guidelines on pull requests.
  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible
  • If this is a code change: I have written unit tests to fully verify the new behavior.

@v-kkhuang v-kkhuang added the enhancement New feature or request label Jun 1, 2026

@casionone casionone left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@casionone casionone merged commit 814447e into dev-2.0.0-webank Jun 2, 2026
18 of 22 checks passed
@v-kkhuang v-kkhuang deleted the dev-2.0.0-fix-slow-sql branch June 3, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants