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

Move horizon planning to operators #11622

Merged
merged 8 commits into from
Nov 4, 2022
Merged

Conversation

frouioui
Copy link
Member

@frouioui frouioui commented Nov 2, 2022

Description

A refactoring that introduces a Horizon as a logical operator.

During query planning, we start by figuring out where we are going to send the queries. This is done by inspecting the FROM & WHERE clauses.

A horizon is what we call in the planner the stuff that is outside the FROM ... WHERE clause. If we are able to send the whole query to a single shard, we don't do much more planning - we simply add the rest of the clauses (projections, ordering, limit, aggregation and more) to the query and we are done.

If we can't delegate everything to MySQL, we do more planning, and this is what we call horizon planning.

This change moves the horizon into the operator tree, instead of having special handling of derived tables, unions and subqueries.

Related Issue(s)

#11626

Checklist

  • "Backport me!" label has been added if this change should be backported
  • Tests were added or are not required
  • Documentation was added or is not required

Deployment Notes

@vitess-bot
Copy link
Contributor

vitess-bot bot commented Nov 2, 2022

Review Checklist

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

General

  • Ensure that the Pull Request has a descriptive title.
  • If this is a change that users need to know about, please apply the release notes (needs details) label so that merging is blocked unless the summary release notes document is included.

If a new flag is being introduced:

  • Is it really necessary to add this flag?
  • Flag names should be clear and intuitive (as far as possible)
  • Help text should be descriptive.
  • Flag names should use dashes (-) as word separators rather than underscores (_).

If a workflow is added or modified:

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

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should include a link to an issue that describes the bug.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

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

@frouioui frouioui added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving labels Nov 2, 2022
Comment on lines 70 to +71
// Clone implements the Operator interface
func (a *ApplyJoin) Clone(inputs []Operator) Operator {
func (a *ApplyJoin) clone(inputs []Operator) Operator {
Copy link
Member Author

Choose a reason for hiding this comment

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

nit: we can also change the comment Clone -> clone

Signed-off-by: Andres Taylor <[email protected]>
Comment on lines +52 to +53
}
func planSingleShardRoute(statement sqlparser.SelectStatement, rb *Route, horizon *Horizon) (Operator, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

nit: new line :)

"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"
)

// Horizon is an operator we use until we decide how to handle the source to the horizon.
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure I fully understand this. We add the Horizon operator into the tree until we have decided how the rest of the tree will do horizon planning?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at the operator test data, it feels like it encapsulates each node in the tree.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. We need to do the physical route planning before we do the horizon planning

Comment on lines +17 to +20
// Package operators contains the operators used to plan queries.
/*
The operators go through a few phases while planning:
1. Logical
Copy link
Member Author

Choose a reason for hiding this comment

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

That's a nice write up

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll add info about horizons in the op tree as well

Copy link
Member Author

@frouioui frouioui left a comment

Choose a reason for hiding this comment

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

LGTM, can't approve as this is my PR.

@frouioui
Copy link
Member Author

frouioui commented Nov 3, 2022

We should update the Pull Request description.

@systay systay marked this pull request as ready for review November 3, 2022 14:38
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.

I like the changes!

@systay systay merged commit f541e96 into vitessio:main Nov 4, 2022
@systay systay deleted the operator-horizon branch November 4, 2022 09:59
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.

3 participants