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

Add basic vector support for MySQL 9.x #16464

Merged
merged 4 commits into from
Jul 24, 2024

Conversation

dbussink
Copy link
Contributor

This adds the basic type support for the new MySQL 9.0 vector type. See also #16463

Related Issue(s)

Fixes #16463

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Copy link
Contributor

vitess-bot bot commented Jul 23, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Jul 23, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Jul 23, 2024
@@ -8638,6 +8644,7 @@ non_reserved_keyword:
| VARIABLES
| VARIANCE %prec FUNCTION_CALL_NON_KEYWORD
| VCPU
| VECTOR
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This follows how the new VECTOR type works in MySQL 9.0. It's not a reserved keyword, which means that for example using a column named vector that is not escaped in a SELECT vector FROM t1 still works.

This also means that the backwards compatibility here is guaranteed, since no working query today would break with this change.

| VECTOR length_opt
{
$$ = &ColumnType{Type: string($1), Length: $2}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the new column type definition that is possible with VECTOR. We can add it safely here to the parser, since even if we can parse it here, the underlying MySQL will then error with a syntax error. That is the same behavior as today regardless, since if we have non-properly parsed DDL, we already pass it down as a best effort to MySQL anyway.

So a syntax error today that the user sees already comes from MySQL and that doesn't change. In general also, our Vitess parser is more lax than MySQL itself. It's reverse engineered from MySQL and in case of doubt we always opt for accepting a bit more than MySQL would if we can't easily seem to match its behavior. That way we don't block valid queries and invalid queries are tried but then throw a syntax error regardless from MySQL itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: in some places we use ParseStrictDDL(), such as in ApplySchema or in schemadiff, in which case we validate the syntax before attempting to apply in MySQL. But since the new syntax is more permissive, that's generally OK.

If a user were to try creating a table with vector columns via ApplySchema and on MySQL 8.0, the behavior would be somewhat different - instead of failing at the ApplySchema level, it would fail in MySQL.

This is a slight change of behavior because normally, if you apply 10 changes in one ApplySchema, and one of them has a syntax error, we fail all 10 before even making contact with MySQL. Now, we would pass all 10 into MySQL, some changes will apply, then the vector one would fail. This is still acceptable IMHO, but noting a change of behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

This could be updated later, once the capabilities code knows about vector?

@dbussink dbussink added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jul 23, 2024
Copy link

codecov bot commented Jul 23, 2024

Codecov Report

Attention: Patch coverage is 12.50000% with 35 lines in your changes missing coverage. Please review.

Project coverage is 68.63%. Comparing base (be8f9f4) to head (42f2313).

Files Patch % Lines
go/vt/vtgate/evalengine/compiler_asm_push.go 0.00% 19 Missing ⚠️
go/mysql/binlog_event_rbr.go 33.33% 2 Missing ⚠️
go/vt/sqlparser/ast_funcs.go 0.00% 2 Missing ⚠️
go/vt/vitessdriver/rows.go 33.33% 2 Missing ⚠️
go/vt/vtgate/evalengine/eval.go 0.00% 2 Missing ⚠️
go/vt/vtgate/evalengine/eval_bytes.go 0.00% 2 Missing ⚠️
go/vt/vtgate/evalengine/expr_bvar.go 0.00% 2 Missing ⚠️
go/vt/vtgate/evalengine/expr_column.go 0.00% 2 Missing ⚠️
go/vt/vtgate/engine/aggregations.go 0.00% 1 Missing ⚠️
go/vt/vtgate/evalengine/expr_compare.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16464      +/-   ##
==========================================
- Coverage   68.65%   68.63%   -0.02%     
==========================================
  Files        1550     1550              
  Lines      199412   199443      +31     
==========================================
- Hits       136900   136889      -11     
- Misses      62512    62554      +42     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dbussink
Copy link
Contributor Author

CI caught actually a good case here specifically for what we're trying to do here! I also added the type to the JDBC driver 😄.

| VECTOR length_opt
{
$$ = &ColumnType{Type: string($1), Length: $2}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: in some places we use ParseStrictDDL(), such as in ApplySchema or in schemadiff, in which case we validate the syntax before attempting to apply in MySQL. But since the new syntax is more permissive, that's generally OK.

If a user were to try creating a table with vector columns via ApplySchema and on MySQL 8.0, the behavior would be somewhat different - instead of failing at the ApplySchema level, it would fail in MySQL.

This is a slight change of behavior because normally, if you apply 10 changes in one ApplySchema, and one of them has a syntax error, we fail all 10 before even making contact with MySQL. Now, we would pass all 10 into MySQL, some changes will apply, then the vector one would fail. This is still acceptable IMHO, but noting a change of behavior.

Copy link
Collaborator

@vmg vmg left a comment

Choose a reason for hiding this comment

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

Needs rebase because of conflict.

@dbussink dbussink force-pushed the vector-support branch 2 times, most recently from 4302481 to df2d659 Compare July 24, 2024 08:46
@dbussink dbussink merged commit 134a7dc into vitessio:main Jul 24, 2024
132 checks passed
@dbussink dbussink deleted the vector-support branch July 24, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Add upstream MySQL 9.0 vector type to Vitess
4 participants