Skip to content

Commit

Permalink
Added processing for statements with subselect compared to const (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
EinKrebs authored Apr 18, 2024
1 parent 950bb8b commit 2a7ab74
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
10 changes: 7 additions & 3 deletions router/qrouter/proxy_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
default:
queue = append(queue, texpr.Left, texpr.Right)
}
case *lyx.Select:
if err := qr.DeparseSelectStmt(ctx, lft, meta); err != nil {
return err
}
default:
/* Consider there cases */
// if !(texpr.AExpr.Kind == pgquery.A_Expr_Kind_AEXPR_OP || texpr.Kind == pgquery.A_Expr_Kind_AEXPR_BETWEEN) {
Expand Down Expand Up @@ -701,7 +705,7 @@ func (qr *ProxyQrouter) routeWithRules(ctx context.Context, stmt lyx.Node, sph s

/*
* Step 1: traverse query tree and deparse mapping from
* columns to their values (either contant or expression).
* columns to their values (either constant or expression).
* Note that exact (routing) value of (sharding) column may not be
* known after this phase, as it can be Parse Step of Extended proto.
*/
Expand All @@ -713,7 +717,7 @@ func (qr *ProxyQrouter) routeWithRules(ctx context.Context, stmt lyx.Node, sph s
case *lyx.VariableSetStmt:
/* TBD: maybe skip all set stmts? */
/*
* SET x = y etc, do not dispatch any statement to shards, just process this in router
* SET x = y etc., do not dispatch any statement to shards, just process this in router
*/
return routingstate.RandomMatchState{}, nil

Expand Down Expand Up @@ -746,7 +750,7 @@ func (qr *ProxyQrouter) routeWithRules(ctx context.Context, stmt lyx.Node, sph s
/*
* Disallow to index on table which does not contain any sharding column
*/
// XXX: doit
// XXX: do it
return routingstate.MultiMatchState{}, nil

case *lyx.Alter, *lyx.Drop, *lyx.Truncate:
Expand Down
30 changes: 29 additions & 1 deletion router/qrouter/proxy_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TestCTE(t *testing.T) {
query: `
WITH xxxx AS (
SELECT * from t where i = 1
)
)
SELECT * from xxxx;
`,
err: nil,
Expand All @@ -292,6 +292,34 @@ func TestCTE(t *testing.T) {
TargetSessionAttrs: "any",
},
},
{
query: `
WITH xxxx AS (
SELECT * from t where i = 1
),
zzzz AS (
UPDATE t
SET a = 0
WHERE i = 1 AND (SELECT COUNT(*) FROM xxxx WHERE b = 0) = 1
)
SELECT * FROM xxxx;
`,
err: nil,
exp: routingstate.ShardMatchState{
Route: &routingstate.DataShardRoute{
Shkey: kr.ShardKey{
Name: "sh1",
},
Matchedkr: &kr.KeyRange{
ShardID: "sh1",
ID: "id1",
Distribution: distribution,
LowerBound: []byte("1"),
},
},
TargetSessionAttrs: "any",
},
},
} {
parserRes, err := lyx.Parse(tt.query)

Expand Down

0 comments on commit 2a7ab74

Please sign in to comment.