-
Notifications
You must be signed in to change notification settings - Fork 9k
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
perf(core): Make execution queries faster #9817
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/cli/src/databases/migrations/common/1717498465932-RefactorExecutionIndices.ts
Outdated
Show resolved
Hide resolved
Thanks, from the story I was under the impression we only wanted to touch these, rather than all of them. |
packages/cli/src/databases/migrations/common/1717498465932-RefactorExecutionIndices.ts
Outdated
Show resolved
Hide resolved
packages/cli/src/databases/migrations/common/1717498465932-RefactorExecutionIndices.ts
Outdated
Show resolved
Hide resolved
packages/cli/src/databases/migrations/common/1717498465932-RefactorExecutionIndices.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple comments, mainly about the structure of the indexes
packages/cli/src/databases/migrations/common/1717498465932-RefactorExecutionIndices.ts
Outdated
Show resolved
Hide resolved
packages/cli/src/databases/migrations/common/1717498465932-RefactorExecutionIndices.ts
Outdated
Show resolved
Hide resolved
packages/cli/src/databases/migrations/common/1717498465932-RefactorExecutionIndices.ts
Outdated
Show resolved
Hide resolved
packages/cli/src/databases/migrations/common/1717498465932-RefactorExecutionIndices.ts
Outdated
Show resolved
Hide resolved
Find multiple executionsMethod: Sample TypeORM log:
Equivalent SQL query: SELECT COUNT(DISTINCT execution.id) AS cnt
FROM execution_entity execution
INNER JOIN workflow_entity workflow ON workflow.id = execution."workflowId"
WHERE execution."workflowId" IN (
'04OYwcQzYJdnjsdd', '2N1V33FP2dKlmTz7', '3SmuvtkVARLuQW6y', '4Zo1ABVbAXz8pdhh',
'6fVKKFKQBGAnvZ4a', '76hvMdsQBVBdnYNM', '8dlw8vap8tPkg50i', 'A2v6XntNlA19XTBu',
'BDp700hAdBGEcoaI', 'CTfQjEFQcW5G3fMr', 'CfLvzSSWLAZVKyFV', 'Dp4reGx2lxez7Vni',
'EZ1fmiFhp6lby6Jg', 'Hm90qPVAq25VzrdD', 'LECmidOfr7VfQ8I7', 'LLRzyiCFeC9vmDki',
'Ov4lOrsuNJqQQvgm', 'Penre9AUYUc0oCr7', 'QIJEUiWfX8fe1qXO', 'QR2GgBoUbcM3JuuX',
'QnrkjpyTEfofdqTM', 'Rtm65p8UI6lmhqKX', 'UQtas8whCecK4p2c', 'UU6i2lrPR5Aipx0N',
'VT6WW8eWyqitfy16', 'X59nkhZx5Q5QxUVa', 'XNfBTQYWfrXaKtIE', 'XYKSUGOlf4jPJJ43',
'YTxYdrPMwsxQHj93', 'ZprM1PsYwZO3IBWA', 'fxc5dTtFiI1dlzzA', 'gCjcQNUkC5kepysS',
'h9zGiCxSeIPZtUW2', 'hDpmfTPWQMttZrGc', 'heRTgosoRcMOYZfB', 'j9TAi7mwIOhP3dJd',
'jYBbm6ZOWX1DNMRP', 'lexlovNxCRXANfqP', 'lqJVl2vUAs4hHIiU', 'nJKtmhRIZ3lwBekg',
'nJKtmhRIZ3lwBekg', 'onPzjgFhmLPqkWXU', 'rVJSrrVsFVInO1Mf', 'reVGqrHPH1xjdC3q',
'w71QwtdB2bThj4ap', 'zr50K32bPqIzW0jA'
)
AND execution.status IN ('new', 'running')
AND execution."deletedAt" IS NULL;
Find waiting executionsMethod: Sample TypeORM log:
SQL query: SELECT id AS "ExecutionEntity_id", "waitTill" AS "ExecutionEntity_waitTill"
FROM execution_entity
WHERE ("waitTill" <= '2024-08-16 11:37:40.997' AND status != 'crashed')
AND "deletedAt" IS NULL
ORDER BY "waitTill" ASC;
Query to soft-delete executionsMethod: Sample TypeORM log:
SQL: UPDATE execution_entity
SET "deletedAt" = '2024-08-16 11:39:13.455'
WHERE "deletedAt" IS NULL
AND "status" NOT IN ('new', 'running', 'waiting')
AND "stoppedAt" <= '2024-08-02 11:39:13.442';
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice stuff 🎉 Just one very small comment. Feel free to ignore it
await schemaBuilder.createIndex('execution_entity', ['workflowId', 'startedAt']); | ||
await schemaBuilder.createIndex('execution_entity', ['waitTill', 'status', 'deletedAt']); | ||
await schemaBuilder.createIndex('execution_entity', ['stoppedAt', 'status', 'deletedAt']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these could be named explicitly as well, so the names would match for all different DBs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, since we'll be dropping MySQL, I think this is okay for now.
Test summaryRun details
Flakiness
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Cloud |
✅ All Cypress E2E specs passed |
Got released with |
https://linear.app/n8n/issue/PAY-1609