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

feat(vet): Add default query parameters for explain queries #2543

Merged
merged 7 commits into from
Jul 31, 2023

Conversation

kyleconroy
Copy link
Collaborator

@kyleconroy kyleconroy commented Jul 29, 2023

Before this change, all parameters to a query would be set to NULL when explaining the query. For both PostgreSQL and MySQL, this caused the explain output to either error or return unhelpful results.

For MySQL, these NULL parameters would cause "Impossible WHERE clause" errors. For PostgreSQL, the EXPLAIN output would return plans without indexes.

The default parameters aren't complete and won't cover all cases. We're working on a fallback mechanism that would allow you to specify the explain parameters values directly. Stay tuned!

@kyleconroy kyleconroy marked this pull request as ready for review July 30, 2023 20:29
@kyleconroy kyleconroy changed the title feat(vet): add default query parameters for vet explain with MySQL feat(vet): Add default query parameters for explain queries Jul 30, 2023
case "float", "double":
return 0.1
case "date":
t := time.Time{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we just want the zero time values I think we can dispense with instantiating the Go structs and just use hardcoded strings (see bottom of this page: https://dev.mysql.com/doc/refman/8.1/en/date-and-time-types.html). I wasn't sure that the zero values would be the best choice though.

switch col.Type.Name {
case "any":
return nil
case "bool":
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no "bool" type for MySQL; it's just an alias for tinyint with 0/1 values (which my Println() testing bears out). But maybe I'm not thinking correctly about the possible ways the input col gets constructed, and we might see something come through this code path with col.Type.Name == "bool"?

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's an alias, but a cool columns will have that type at this stage. When you pass false to the MySQL driver, it converts it to a 0. I found this case somewhere in the tests.

internal/cmd/vet.go Outdated Show resolved Hide resolved
@kyleconroy kyleconroy merged commit a58e3a5 into main Jul 31, 2023
7 checks passed
@kyleconroy kyleconroy deleted the andrew/vet-explain-default-params branch July 31, 2023 15:21
This pull request was closed.
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.

2 participants