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

Bump lyx #444

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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-20240111083355-38b940962fe3
github.com/pg-sharding/lyx v0.0.0-20240124084632-a9f5aa89a6ac
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.31.0
github.com/sevlyar/go-daemon v0.1.6
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ 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-20240111083355-38b940962fe3 h1:drqKxg58y9R3niC8T4wW6dqziPZnBosuAGC8X/eXLPc=
github.com/pg-sharding/lyx v0.0.0-20240111083355-38b940962fe3/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pg-sharding/lyx v0.0.0-20240119072404-3d559dba6aa8 h1:s8f0Vo257gQvwS++K9RMkxKrgxsdVAXTtc5wJkqHvmg=
github.com/pg-sharding/lyx v0.0.0-20240119072404-3d559dba6aa8/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pg-sharding/lyx v0.0.0-20240123215906-b049786c6ee2 h1:Pja7QaJpBcflHtTUbIEFl/ZGJrk2vOmX6arh1IJwoIU=
github.com/pg-sharding/lyx v0.0.0-20240123215906-b049786c6ee2/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pg-sharding/lyx v0.0.0-20240123223048-f4c8715e77ed h1:NNv0qFDlAFc9/crthqjFqUmYRW5SjGnvkxSiLx6hOwQ=
github.com/pg-sharding/lyx v0.0.0-20240123223048-f4c8715e77ed/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pg-sharding/lyx v0.0.0-20240124084632-a9f5aa89a6ac h1:iJcay9e0ibZYH1Bx/2tLHZsHYj5k5I480VOswOpfeGo=
github.com/pg-sharding/lyx v0.0.0-20240124084632-a9f5aa89a6ac/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
2 changes: 1 addition & 1 deletion router/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestFrontendSimple(t *testing.T) {

qr.EXPECT().Route(gomock.Any(), &lyx.Select{
TargetList: []lyx.Node{
&lyx.AExprConst{Value: "1"},
&lyx.AExprIConst{Value: 1},
},
Where: &lyx.AExprEmpty{},
}, gomock.Any()).Return(routingstate.ShardMatchState{
Expand Down
83 changes: 66 additions & 17 deletions router/qrouter/proxy_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ func NewRoutingMetadataContext(
}

// TODO : unit tests
func (meta *RoutingMetadataContext) RecordConstExpr(resolvedRelation RelationFQN, colname string, expr *lyx.AExprConst) {
func (meta *RoutingMetadataContext) RecordConstExpr(resolvedRelation RelationFQN, colname string, expr string) {
meta.rels[resolvedRelation] = append(meta.rels[resolvedRelation], colname)
if _, ok := meta.exprs[resolvedRelation]; !ok {
meta.exprs[resolvedRelation] = map[string]string{}
}
delete(meta.unparsed_columns, colname)
meta.exprs[resolvedRelation][colname] = expr.Value
meta.exprs[resolvedRelation][colname] = expr
}

// TODO : unit tests
Expand Down Expand Up @@ -192,14 +192,23 @@ func (qr *ProxyQrouter) RouteKeyWithRanges(ctx context.Context, expr lyx.Node, m
spqrlog.Zero.Debug().Str("key", string(meta.params[e.Number-1])).Str("hashed key", string(hashedKey)).Msg("applying hash function on key")

return qr.DeparseKeyWithRangesInternal(ctx, string(hashedKey), meta)
case *lyx.AExprConst:
case *lyx.AExprSConst:
hashedKey, err := hashfunction.ApplyHashFunction([]byte(e.Value), hf)
if err != nil {
return nil, err
}

spqrlog.Zero.Debug().Str("key", e.Value).Str("hashed key", string(hashedKey)).Msg("applying hash function on key")
return qr.DeparseKeyWithRangesInternal(ctx, string(hashedKey), meta)
case *lyx.AExprIConst:
val := fmt.Sprintf("%d", e.Value)
hashedKey, err := hashfunction.ApplyHashFunction([]byte(val), hf)
if err != nil {
return nil, err
}

spqrlog.Zero.Debug().Int("key", e.Value).Str("hashed key", string(hashedKey)).Msg("applying hash function on key")
return qr.DeparseKeyWithRangesInternal(ctx, string(hashedKey), meta)
default:
return nil, ComplexQuery
}
Expand All @@ -225,7 +234,24 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
switch rght := texpr.Right.(type) {
case *lyx.ParamRef:
// ignore
case *lyx.AExprConst:
case *lyx.AExprSConst:
alias, colname := lft.TableAlias, lft.ColName

if !meta.CheckColumnRls(colname) {
spqrlog.Zero.Debug().
Str("colname", colname).
Msg("skip column due no rule mathing")
continue
}

resolvedRelation, err := meta.ResolveRelationByAlias(alias)
if err == nil {
// TBD: postpone routing from here to root of parsing tree
meta.RecordConstExpr(resolvedRelation, colname, rght.Value)
} else {
meta.unparsed_columns[colname] = struct{}{}
}
case *lyx.AExprIConst:
alias, colname := lft.TableAlias, lft.ColName

if !meta.CheckColumnRls(colname) {
Expand All @@ -238,7 +264,8 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
resolvedRelation, err := meta.ResolveRelationByAlias(alias)
if err == nil {
// TBD: postpone routing from here to root of parsing tree
meta.RecordConstExpr(resolvedRelation, colname, rght)
// maybe expimely inefficient. Will be fixed in SPQR-2.0
meta.RecordConstExpr(resolvedRelation, colname, fmt.Sprintf("%d", rght.Value))
} else {
meta.unparsed_columns[colname] = struct{}{}
}
Expand All @@ -247,7 +274,7 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
if len(rght.List) != 0 {
expr := rght.List[0]
switch bexpr := expr.(type) {
case *lyx.AExprConst:
case *lyx.AExprSConst:
alias, colname := lft.TableAlias, lft.ColName

if !meta.CheckColumnRls(colname) {
Expand All @@ -260,7 +287,25 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
resolvedRelation, err := meta.ResolveRelationByAlias(alias)
if err == nil {
// TBD: postpone routing from here to root of parsing tree
meta.RecordConstExpr(resolvedRelation, colname, bexpr)
meta.RecordConstExpr(resolvedRelation, colname, bexpr.Value)
} else {
meta.unparsed_columns[colname] = struct{}{}
}
case *lyx.AExprIConst:
alias, colname := lft.TableAlias, lft.ColName

if !meta.CheckColumnRls(colname) {
spqrlog.Zero.Debug().
Str("colname", colname).
Msg("skip column due no rule mathing")
continue
}

resolvedRelation, err := meta.ResolveRelationByAlias(alias)
if err == nil {
// TBD: postpone routing from here to root of parsing tree
// maybe expimely inefficient. Will be fixed in SPQR-2.0
meta.RecordConstExpr(resolvedRelation, colname, fmt.Sprintf("%d", bexpr.Value))
} else {
meta.unparsed_columns[colname] = struct{}{}
}
Expand All @@ -280,7 +325,7 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
}
case *lyx.ColumnRef:
/* colref = colref case, skip */
case *lyx.AExprConst:
case *lyx.AExprIConst, *lyx.AExprSConst, *lyx.AExprBConst, *lyx.AExprNConst:
/* should not happend */
case *lyx.AExprEmpty:
/*skip*/
Expand Down Expand Up @@ -541,8 +586,6 @@ func (qr *ProxyQrouter) deparseShardingMapping(
Strs("statements", cols).
Msg("deparsed insert statement columns")

meta.ValuesLists = stmt.Values

meta.InsertStmtCols = cols
switch q := stmt.TableRef.(type) {
case *lyx.RangeVar:
Expand All @@ -552,12 +595,17 @@ func (qr *ProxyQrouter) deparseShardingMapping(
}

if selectStmt := stmt.SubSelect; selectStmt != nil {
spqrlog.Zero.Debug().Msg("routing insert stmt on select clause")
_ = qr.DeparseSelectStmt(ctx, selectStmt, meta)
/* try target list */
spqrlog.Zero.Debug().Msg("routing insert stmt on target list")
/* this target list for some insert (...) sharding column */
meta.TargetList = selectStmt.(*lyx.Select).TargetList
switch subS := selectStmt.(type) {
case *lyx.Select:
spqrlog.Zero.Debug().Msg("routing insert stmt on select clause")
_ = qr.DeparseSelectStmt(ctx, subS, meta)
/* try target list */
spqrlog.Zero.Debug().Msg("routing insert stmt on target list")
/* this target list for some insert (...) sharding column */
meta.TargetList = selectStmt.(*lyx.Select).TargetList
case *lyx.ValueClause:
meta.ValuesLists = subS.Values
}
}

return nil
Expand Down Expand Up @@ -778,9 +826,10 @@ func (qr *ProxyQrouter) routeWithRules(ctx context.Context, stmt lyx.Node, sph s
if e.Name == "current_schema" {
any_routable = true
}
case *lyx.AExprConst:
case *lyx.AExprIConst, *lyx.AExprSConst, *lyx.AExprNConst, *lyx.AExprBConst:
// ok
any_routable = true

case *lyx.ColumnRef:
/* Step 1.4.8.2 - SELECT current_schema special case */
if e.ColName == "current_schema" {
Expand Down
Loading