-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add support for view routing rules #19104
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
base: main
Are you sure you want to change the base?
Conversation
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]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
Signed-off-by: Mohamed Hamza <[email protected]>
|
📝 Documentation updates detected! New suggestion: Add changelog entry for view routing rules |
|
📝 Documentation updates detected! New suggestion: Document view routing rules support |
Signed-off-by: Mohamed Hamza <[email protected]>
Implemented in vitessio/vitess#19104
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_tableis first checked to see if it's a view. If it is, it's added into the local VSchema in a newViewRoutingRulesfield:A view routing rule is defined as:
At query time, views are rewritten into the target view's definition rather than the source view. For example, for this view:
And this routing rule:
{ "rules": [ { "from_table": "user_view", "to_tables": ["target_ks.user_view"] } ] }The query:
Would be rewritten into:
See the RFC for more information.
Related Issue(s)
Closes #19097
Checklist
Deployment Notes
AI Disclosure