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 schema tracking support for UDFs #15705

Merged
merged 13 commits into from
Apr 15, 2024

Conversation

systay
Copy link
Collaborator

@systay systay commented Apr 12, 2024

Description

Adds the capability of vttablets to notice that aggregate UDFs have been added to a MySQL system.
We need to track these to do planning correctly.

Related Issue(s)

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

GuptaManan100 and others added 3 commits April 11, 2024 13:24
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Copy link
Contributor

vitess-bot bot commented Apr 12, 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 Apr 12, 2024
@github-actions github-actions bot added this to the v20.0.0 milestone Apr 12, 2024
@systay systay changed the title feat: get if udfs have changed and send it as part of the broadcast Track user defined aggregation functions for query planning Apr 12, 2024
@systay systay 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 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 Apr 12, 2024
@systay systay changed the title Track user defined aggregation functions for query planning Add schema tracking support for UDFs Apr 15, 2024
@harshit-gangal harshit-gangal marked this pull request as ready for review April 15, 2024 08:20
@harshit-gangal harshit-gangal added the release notes (needs details) This PR needs to be listed in the release notes in a dedicated section (deprecation notice, etc...) label Apr 15, 2024
@harshit-gangal
Copy link
Member

Website Documentation: vitessio/website#1726

@harshit-gangal harshit-gangal added NeedsIssue A linked issue is missing for this Pull Request and removed NeedsWebsiteDocsUpdate What it says labels Apr 15, 2024
systay and others added 10 commits April 15, 2024 11:28
Signed-off-by: Andres Taylor <andres@planetscale.com>
…gate functions

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
… vtgate enableUDFs flag to keep it disabled by default

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

Rest LGTM!

go/vt/vtgate/vindexes/vschema.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 65.60510% with 54 lines in your changes are missing coverage. Please review.

Project coverage is 68.37%. Comparing base (f118ba2) to head (66f0495).
Report is 1 commits behind head on main.

Files Patch % Lines
go/vt/vttablet/tabletserver/schema/db.go 46.51% 23 Missing ⚠️
go/vt/vttablet/tabletserver/query_executor.go 12.50% 14 Missing ⚠️
go/vt/vtgate/schema/tracker.go 82.05% 7 Missing ⚠️
go/vt/vtgate/vschema_manager.go 83.78% 6 Missing ⚠️
go/vt/vtgate/vtgate.go 0.00% 2 Missing ⚠️
go/vt/vttablet/tabletserver/schema/engine.go 87.50% 1 Missing ⚠️
go/vt/vttablet/tabletserver/tabletserver.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15705      +/-   ##
==========================================
- Coverage   68.40%   68.37%   -0.03%     
==========================================
  Files        1556     1556              
  Lines      195121   195247     +126     
==========================================
+ Hits       133479   133508      +29     
- Misses      61642    61739      +97     

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

@harshit-gangal harshit-gangal added Type: Bug Type: Regression and removed NeedsIssue A linked issue is missing for this Pull Request Type: Bug Type: Regression labels Apr 15, 2024
@harshit-gangal harshit-gangal merged commit 6b25965 into vitessio:main Apr 15, 2024
108 of 109 checks passed
@harshit-gangal harshit-gangal deleted the udf-schema-tracker branch April 15, 2024 12:20
@@ -989,6 +992,7 @@ enum SchemaTableType {
VIEWS = 0;
TABLES = 1;
ALL = 2;
UDF_AGGREGATE = 3;
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 allow only aggregate UDFs? The vtgate flag is just called --enable_udfs. Release notes also say "any UDFs".

Comment on lines +103 to +104
// TestUDFRFC will validate that UDFs are received through the rfc call.
func TestUDFRFC(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to read TestUDFRPC??

@@ -883,6 +883,9 @@ message RealtimeStats {

// view_schema_changed is to provide list of views that have schema changes detected by the tablet.
repeated string view_schema_changed = 8;

// udfs_changed is used to signal that the UDFs have changed on the tablet.
bool udfs_changed = 9;
Copy link
Member

Choose a reason for hiding this comment

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

For tables and views, we track changes as list of changed objects. Why is this a single bool?
Can you have multiple .so files and/or multiple UDFs loaded? I assume so. In which case, if any of them changes, this will be true, and we will reload all of them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For tables and views, the signal that a change has occurred is sent as the name of the table/view. Vtgate can then fetch the new definition for these objects when it wants that info. We did this so that the healtstream doesn't get weighed down with extra traffic that the vtgate might not be interested in - it can decide when to fetch the heavy data load.

For UDFs, the data load is the list and types of UDFs. The vtgate will simply reload the full list when something has changed. With this model, there is no need for the signal to specify what has changed.

Comment on lines +93 to +105
detectUdfChange = `SELECT name
FROM (
SELECT name FROM
mysql.func

UNION ALL

SELECT function_name
FROM %s.udfs
) _inner
GROUP BY name
HAVING COUNT(*) = 1
LIMIT 1
Copy link
Member

Choose a reason for hiding this comment

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

The way I'm reading this, we'll detect new or deleted UDFs, but not a change to the UDF definition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, we should also check the types


// copyUdfs copies user defined function to the udfs table.
copyUdfs = `INSERT INTO %s.udfs(FUNCTION_NAME, FUNCTION_RETURN_TYPE, FUNCTION_TYPE)
SELECT f.name, i.UDF_RETURN_TYPE, f.type FROM mysql.func f left join performance_schema.user_defined_functions i on f.name = i.udf_name
Copy link
Member

Choose a reason for hiding this comment

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

nit: I assume you use i as an alias for information_schema, so it makes sense to use p for performance_schema

Comment on lines +552 to +553
// GetFetchUDFsQuery gets the fetch query to retrieve all the UDFs.
func GetFetchUDFsQuery(parser *sqlparser.Parser) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

If we are fetching only aggregate UDFs, this func should be renamed to reflect that.

systay added a commit that referenced this pull request Jul 22, 2024
* cherry pick of 15705

* chore: boost integration

Signed-off-by: Andres Taylor <andres@planetscale.com>

---------

Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: Andres Taylor <andres@planetscale.com>
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.

4 participants