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

Support CountWorkflowExecutions for SQL DB #3955

Merged
merged 1 commit into from
Feb 15, 2023

Conversation

rodrigozhou
Copy link
Collaborator

What changed?
Implement support for CountWorkflowExecutions for advanced visibility with SQL DB.

Why?
Advanced visibility with SQL DB.

How did you test it?
Enabled TestCountWorkflow functional test.

Potential risks
No risks.

Is hotfix candidate?
No.

@rodrigozhou rodrigozhou requested a review from a team as a code owner February 14, 2023 22:30
Comment on lines 1084 to 1087
if !s.isElasticsearchEnabled() {
s.T().Skip("This test is only for Elasticsearch")
}

Copy link
Member

Choose a reason for hiding this comment

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

👍

}

return fmt.Sprintf(
"SELECT COUNT(1) FROM executions_visibility WHERE %s",
Copy link
Member

Choose a reason for hiding this comment

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

Had to use ChatGPT to explain me what is COUNT(1) and why it is better than COUNT(*).

@rodrigozhou rodrigozhou merged commit 099cef3 into temporalio:master Feb 15, 2023
@rodrigozhou rodrigozhou deleted the sql-count-workflows branch February 15, 2023 00:59
queryArgs = append(queryArgs, namespaceID.String())

if len(queryString) > 0 {
whereClauses = append(whereClauses, fmt.Sprintf("(%s)", queryString))
Copy link
Member

Choose a reason for hiding this comment

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

Do we have sql injection risk here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It shouldn't. The query converter escape the user's input.

return fmt.Sprintf(
`SELECT COUNT(1)
FROM executions_visibility ev
LEFT JOIN custom_search_attributes
Copy link
Member

Choose a reason for hiding this comment

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

Is join here must have? PostgreSQL and SQLite were able to get away without join.

Copy link
Collaborator Author

@rodrigozhou rodrigozhou Feb 15, 2023

Choose a reason for hiding this comment

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

Yes, in MySQL, we have two tables (executions + custom search attributes), so we need the join. I'm assuming the input can be on any search attribute. If it's only on system search attribute, we can remove the join.

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.

3 participants