Skip to content

Commit

Permalink
Add set operations processing (#639)
Browse files Browse the repository at this point in the history
* Bump lyx

* Add test for UNION routing

* Bump lyx again

* Add processing for set operations
  • Loading branch information
EinKrebs authored Apr 25, 2024
1 parent 0299c77 commit f19a1ac
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/lib/pq v1.10.9
github.com/libp2p/go-reuseport v0.4.0
github.com/opentracing/opentracing-go v1.2.0
github.com/pg-sharding/lyx v0.0.0-20240417111237-40a0e3320599
github.com/pg-sharding/lyx v0.0.0-20240425090312-06d7412dfba8
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.32.0
github.com/sevlyar/go-daemon v0.1.6
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pg-sharding/lyx v0.0.0-20240417111237-40a0e3320599 h1:CPMrNVoDZkPNjfqaPpPzCr1UN8LZmWw88NQ5aiZ+RrA=
github.com/pg-sharding/lyx v0.0.0-20240417111237-40a0e3320599/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pg-sharding/lyx v0.0.0-20240419111011-78b6979ac476 h1:PCRfnJMD8QawQoGqtpyNiN6MLRj9WN628dAWBL+zhTw=
github.com/pg-sharding/lyx v0.0.0-20240419111011-78b6979ac476/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pg-sharding/lyx v0.0.0-20240425090312-06d7412dfba8 h1:1+eQ40tGL8n/Xli/dBx9oW6ISU1NE2WGSnBDpNnRSiA=
github.com/pg-sharding/lyx v0.0.0-20240425090312-06d7412dfba8/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
22 changes: 21 additions & 1 deletion router/qrouter/proxy_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,17 @@ func (qr *ProxyQrouter) DeparseSelectStmt(ctx context.Context, selectStmt lyx.No
}
}

if s.LArg != nil {
if err := qr.DeparseSelectStmt(ctx, s.LArg, meta); err != nil {
return err
}
}
if s.RArg != nil {
if err := qr.DeparseSelectStmt(ctx, s.RArg, meta); err != nil {
return err
}
}

/* SELECT * FROM VALUES() ... */
case *lyx.ValueClause:
/* random route */
Expand Down Expand Up @@ -780,7 +791,7 @@ func (qr *ProxyQrouter) routeWithRules(ctx context.Context, stmt lyx.Node, sph s
/* We cannot route SQL stmt with no FROM clause provided, but there is still
* a few cases to consider
*/
if len(node.FromClause) == 0 {
if len(node.FromClause) == 0 && (node.LArg == nil || node.RArg == nil) {
/* Step 1.4.8: select a_expr is routable to any shard in case when a_expr is some type of
data-independent expr */

Expand Down Expand Up @@ -815,6 +826,15 @@ func (qr *ProxyQrouter) routeWithRules(ctx context.Context, stmt lyx.Node, sph s
if any_routable {
return routingstate.RandomMatchState{}, nil
}
} else if node.LArg != nil && node.RArg != nil {
err := qr.deparseShardingMapping(ctx, node.LArg, meta)
if err != nil {
return nil, err
}
err = qr.deparseShardingMapping(ctx, node.RArg, meta)
if err != nil {
return nil, err
}
} else {
// SELECT stmts, which
// would be routed with their WHERE clause
Expand Down
19 changes: 19 additions & 0 deletions router/qrouter/proxy_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,25 @@ func TestSingleShard(t *testing.T) {
},
err: nil,
},

{
query: "SELECT * FROM t WHERE i = 12 UNION ALL SELECT * FROM xxmixed WHERE i = 22;",
exp: routingstate.ShardMatchState{
Route: &routingstate.DataShardRoute{
Shkey: kr.ShardKey{
Name: "sh2",
},
Matchedkr: &kr.KeyRange{
ShardID: "sh2",
ID: "id2",
Distribution: distribution,
LowerBound: []byte("11"),
},
},
TargetSessionAttrs: "any",
},
err: nil,
},
} {
parserRes, err := lyx.Parse(tt.query)

Expand Down

0 comments on commit f19a1ac

Please sign in to comment.