Skip to content

Conversation

@mhamza15
Copy link
Collaborator

@mhamza15 mhamza15 commented Jan 6, 2026

Description

Adds support for view routing rules. View routing rules can be applied in the same way as tables:

{
  "rules": [
    {
      "from_table": "my_view",
      "to_tables": ["target_ks.my_view"]
    }
  ]
}

When routing rules are being built in VTGate, the from_table is first checked to see if it's a view. If it is, it's added into the local VSchema in a new ViewRoutingRules field:

type VSchema struct {
    // ...

    RoutingRules map[string]*RoutingRule `json:"routing_rules"`

    ViewRoutingRules map[string]*ViewRoutingRule `json:"view_routing_rules"`

    // ...
}

A view routing rule is defined as:

type ViewRoutingRule struct {
    TargetKeyspace string
    TargetViewName string
}

At query time, views are rewritten into the target view's definition rather than the source view. For example, for this view:

create view user_view as select id, name from user

And this routing rule:

{
  "rules": [
    {
      "from_table": "user_view",
      "to_tables": ["target_ks.user_view"]
    }
  ]
}

The query:

select * from user_view

Would be rewritten into:

select * from (select col1, col2 from target_ks.user_view) as user_view

See the RFC for more information.

Related Issue(s)

Closes #19097

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

Deployment Notes

AI Disclosure

Adds support for view routing rules. View routing rules can be applied
in the same way as tables:

```json
{
  "rules": [
    {
      "from_table": "my_view",
      "to_tables": ["target_ks.my_view"]
    }
  ]
}
```

When routing rules are being built in VTGate, the `from_table` is first
checked to see if it's a view. If it is, it's adding into the local
VSchema in a new `ViewRoutingRules` field:

```go
type VSchema struct {
    // ...

    RoutingRules map[string]*RoutingRule `json:"routing_rules"`

    ViewRoutingRules map[string]*ViewRoutingRule `json:"view_routing_rules"`

    // ...
}
```

A view routing rule is defined as:

```go
type ViewRoutingRule struct {
    TargetKeyspace string
    TargetViewName string
}
```

At query time, views are rewritten into the target view's definition
rather than the source view. For example, for this view:

```sql
create view user_view as select id, name from user
```

And this routing rule:

```json
{
  "rules": [
    {
      "from_table": "user_view",
      "to_tables": ["target_ks.user_view"]
    }
  ]
}
```

The query:

```sql
select * from user_view
```

Would be rewritten into:

```sql
select * from (select col1, col2 from target_ks.user_view) as user_view
```

See the [RFC](vitessio#19097) for more
information.

Signed-off-by: Mohamed Hamza <[email protected]>
@github-actions github-actions bot added this to the v24.0.0 milestone Jan 6, 2026
@vitess-bot vitess-bot bot added NeedsWebsiteDocsUpdate What it says 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 Jan 6, 2026
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Jan 6, 2026

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.

@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 80.95238% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.88%. Comparing base (fa770f9) to head (ef0a54b).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtgate/vindexes/vschema.go 83.33% 5 Missing ⚠️
go/test/vschemawrapper/vschema_wrapper.go 66.66% 1 Missing ⚠️
go/vt/sqlparser/normalizer.go 80.00% 1 Missing ⚠️
go/vt/vtgate/executorcontext/vcursor_impl.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #19104   +/-   ##
=======================================
  Coverage   69.87%   69.88%           
=======================================
  Files        1613     1613           
  Lines      216002   216048   +46     
=======================================
+ Hits       150939   150981   +42     
- Misses      65063    65067    +4     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mhamza15 mhamza15 added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VReplication 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 Jan 12, 2026
@mhamza15 mhamza15 marked this pull request as ready for review January 12, 2026 19:33
@promptless
Copy link
Contributor

promptless bot commented Jan 12, 2026

📝 Documentation updates detected!

New suggestion: Add changelog entry for view routing rules

@promptless
Copy link
Contributor

promptless bot commented Jan 12, 2026

📝 Documentation updates detected!

New suggestion: Document view routing rules support

Signed-off-by: Mohamed Hamza <[email protected]>
mhamza15 added a commit to mhamza15/website that referenced this pull request Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: VReplication Type: Enhancement Logical improvement (somewhere between a bug and feature)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC: View routing rules

1 participant