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

Improve Performance of Contracts REST API Endpoints with High Entity Counts #10069

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

HarshSawarkar
Copy link
Contributor

Description:

The entity__id_type index is replaced with entity_type_id, and the getContract SQL query is rewritten to utilize the new index structure.

Related issue(s):

Fixes #9967

Notes for reviewer:

Check for the SQL query updated at contractController.js leveraging common table expression.
Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

…rewritten getContract Sql query to leverage it.

Signed-off-by: Harsh Sawarkar <[email protected]>
@HarshSawarkar HarshSawarkar requested a review from a team as a code owner January 8, 2025 09:26
@@ -0,0 +1,3 @@
DROP INDEX IF EXISTS entity__id_type;
Copy link
Collaborator

@xin-hedera xin-hedera Jan 13, 2025

Choose a reason for hiding this comment

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

the version should be V1.103.0 and for v2 schema, need to add the same migration with version V2.8.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@@ -234,13 +234,21 @@ const getContractByIdOrAddressContractEntityQuery = ({timestampConditions, times
*/
const getContractsQuery = (whereQuery, limitQuery, order) => {
return [
`select ${contractSelectFields}`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this changed to a more complicated, two CTEs + one main query SQL query? If it's not driven by perf analysis, please revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the CTE to first fetch the relevant contract IDs, which reduces the number of data rows the left join needs to process. However, since I haven't conducted a performance analysis to validate the change, I will revert it for now.

@xin-hedera
Copy link
Collaborator

The changes need to be vetted by running perf tests with large amount of data from production environment, we'll try to run such perf tests as early as we can.

…01.0__drop_entity__id_type_index.sql

Co-authored-by: Xin Li <[email protected]>
Signed-off-by: Harsh Vinod Sawarkar <[email protected]>
@HarshSawarkar
Copy link
Contributor Author

The changes need to be vetted by running perf tests with large amount of data from production environment, we'll try to run such perf tests as early as we can.

Sure, let me know if there's anything I can do to help.

HarshSawarkar and others added 5 commits January 14, 2025 14:10
…into chore-Some-contracts-REST-API-endpoints-show-large-slowdown-with-high-number-of-entities
…_id and rewritten getContract Sql query to leverage it."

This reverts commit 6c4e34b.
…rewritten getContract Sql query to leverage it.
…oof (hashgraph#10105)

Bumps [glob](https://github.com/isaacs/node-glob) from 11.0.0 to 11.0.1.
- [Changelog](https://github.com/isaacs/node-glob/blob/main/changelog.md)
- [Commits](isaacs/node-glob@v11.0.0...v11.0.1)

---
updated-dependencies:
- dependency-name: glob
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Harsh Sawarkar <[email protected]>
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

Successfully merging this pull request may close these issues.

Some contracts REST API endpoints show large slowdown with high number of entities
2 participants