From 61959f6733f90432eb6db1f06f250597563378a7 Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Tue, 13 Aug 2024 10:04:45 -0400 Subject: [PATCH] VReplication: Improve table plan builder errors (#16588) Signed-off-by: Matt Lord --- .../vreplication/replicator_plan_test.go | 34 +++++++++---------- .../vreplication/table_plan_builder.go | 4 +-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/go/vt/vttablet/tabletmanager/vreplication/replicator_plan_test.go b/go/vt/vttablet/tabletmanager/vreplication/replicator_plan_test.go index 6c9f92128ac..d3971c3a397 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/replicator_plan_test.go +++ b/go/vt/vttablet/tabletmanager/vreplication/replicator_plan_test.go @@ -574,7 +574,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "bad query", }}, }, - err: "syntax error at position 4 near 'bad' in query: bad query", + err: "failed to build table replication plan for t1 table: syntax error at position 4 near 'bad' in query: bad query", }, { // not a select input: &binlogdatapb.Filter{ @@ -583,7 +583,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "update t1 set val = 1", }}, }, - err: "unsupported non-select statement in query: update t1 set val = 1", + err: "failed to build table replication plan for t1 table: unsupported non-select statement in query: update t1 set val = 1", }, { // no distinct input: &binlogdatapb.Filter{ @@ -592,7 +592,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select distinct c1 from t1", }}, }, - err: "unsupported distinct clause in query: select distinct c1 from t1", + err: "failed to build table replication plan for t1 table: unsupported distinct clause in query: select distinct c1 from t1", }, { // no ',' join input: &binlogdatapb.Filter{ @@ -601,7 +601,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select * from t1, t2", }}, }, - err: "unsupported multi-table usage in query: select * from t1, t2", + err: "failed to build table replication plan for t1 table: unsupported multi-table usage in query: select * from t1, t2", }, { // no join input: &binlogdatapb.Filter{ @@ -610,7 +610,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select * from t1 join t2", }}, }, - err: "unsupported from expression (*sqlparser.JoinTableExpr) in query: select * from t1 join t2", + err: "failed to build table replication plan for t1 table: unsupported from expression (*sqlparser.JoinTableExpr) in query: select * from t1 join t2", }, { // no subqueries input: &binlogdatapb.Filter{ @@ -619,7 +619,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select * from (select * from t2) as a", }}, }, - err: "unsupported from source (*sqlparser.DerivedTable) in query: select * from (select * from t2) as a", + err: "failed to build table replication plan for t1 table: unsupported from source (*sqlparser.DerivedTable) in query: select * from (select * from t2) as a", }, { // cannot combine '*' with other input: &binlogdatapb.Filter{ @@ -628,7 +628,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select *, c1 from t1", }}, }, - err: "unsupported mix of '*' and columns in query: select *, c1 from t1", + err: "failed to build table replication plan for t1 table: unsupported mix of '*' and columns in query: select *, c1 from t1", }, { // cannot combine '*' with other (different code path) input: &binlogdatapb.Filter{ @@ -637,7 +637,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select c1, * from t1", }}, }, - err: "invalid expression: * in query: select c1, * from t1", + err: "failed to build table replication plan for t1 table: invalid expression: * in query: select c1, * from t1", }, { // no distinct in func input: &binlogdatapb.Filter{ @@ -646,7 +646,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select hour(distinct c1) as a from t1", }}, }, - err: "syntax error at position 21 near 'distinct' in query: select hour(distinct c1) as a from t1", + err: "failed to build table replication plan for t1 table: syntax error at position 21 near 'distinct' in query: select hour(distinct c1) as a from t1", }, { // funcs need alias input: &binlogdatapb.Filter{ @@ -655,7 +655,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select hour(c1) from t1", }}, }, - err: "expression needs an alias: hour(c1) in query: select hour(c1) from t1", + err: "failed to build table replication plan for t1 table: expression needs an alias: hour(c1) in query: select hour(c1) from t1", }, { // only count(*) input: &binlogdatapb.Filter{ @@ -664,7 +664,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select count(c1) as c from t1", }}, }, - err: "only count(*) is supported: count(c1) in query: select count(c1) as c from t1", + err: "failed to build table replication plan for t1 table: only count(*) is supported: count(c1) in query: select count(c1) as c from t1", }, { // no sum(*) input: &binlogdatapb.Filter{ @@ -673,7 +673,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select sum(*) as c from t1", }}, }, - err: "syntax error at position 13 in query: select sum(*) as c from t1", + err: "failed to build table replication plan for t1 table: syntax error at position 13 in query: select sum(*) as c from t1", }, { // sum should have only one argument input: &binlogdatapb.Filter{ @@ -682,7 +682,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select sum(a, b) as c from t1", }}, }, - err: "syntax error at position 14 in query: select sum(a, b) as c from t1", + err: "failed to build table replication plan for t1 table: syntax error at position 14 in query: select sum(a, b) as c from t1", }, { // no complex expr in sum input: &binlogdatapb.Filter{ @@ -691,7 +691,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select sum(a + b) as c from t1", }}, }, - err: "unsupported non-column name in sum clause: sum(a + b) in query: select sum(a + b) as c from t1", + err: "failed to build table replication plan for t1 table: unsupported non-column name in sum clause: sum(a + b) in query: select sum(a + b) as c from t1", }, { // no complex expr in group by input: &binlogdatapb.Filter{ @@ -700,7 +700,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select a from t1 group by a + 1", }}, }, - err: "unsupported non-column name or alias in group by clause: a + 1 in query: select a from t1 group by a + 1", + err: "failed to build table replication plan for t1 table: unsupported non-column name or alias in group by clause: a + 1 in query: select a from t1 group by a + 1", }, { // group by does not reference alias input: &binlogdatapb.Filter{ @@ -709,7 +709,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select a as b from t1 group by a", }}, }, - err: "group by expression does not reference an alias in the select list: a in query: select a as b from t1 group by a", + err: "failed to build table replication plan for t1 table: group by expression does not reference an alias in the select list: a in query: select a as b from t1 group by a", }, { // cannot group by aggr input: &binlogdatapb.Filter{ @@ -718,7 +718,7 @@ func TestBuildPlayerPlan(t *testing.T) { Filter: "select count(*) as a from t1 group by a", }}, }, - err: "group by expression is not allowed to reference an aggregate expression: a in query: select count(*) as a from t1 group by a", + err: "failed to build table replication plan for t1 table: group by expression is not allowed to reference an aggregate expression: a in query: select count(*) as a from t1 group by a", }} PrimaryKeyInfos := map[string][]*ColumnInfo{ diff --git a/go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go b/go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go index 2e44fd49e9b..db774af1861 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go +++ b/go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go @@ -161,7 +161,7 @@ func buildReplicatorPlan(source *binlogdatapb.BinlogSource, colInfoMap map[strin } tablePlan, err := buildTablePlan(tableName, rule, colInfos, lastpk, stats, source, collationEnv, parser) if err != nil { - return nil, err + return nil, vterrors.Wrapf(err, "failed to build table replication plan for %s table", tableName) } if tablePlan == nil { // Table was excluded. @@ -598,7 +598,7 @@ func (tpb *tablePlanBuilder) analyzePK(cols []*ColumnInfo) error { // TODO(shlomi): at some point in the futue we want to make this check stricter. // We could be reading a generated column c1 which in turn selects some other column c2. // We will want t oensure that `c2` is found in select list... - return fmt.Errorf("primary key column %v not found in select list", col) + return fmt.Errorf("primary key column %v not found in table's select filter or the TableMap event within the GTID", col) } if cexpr.operation != opExpr { return fmt.Errorf("primary key column %v is not allowed to reference an aggregate expression", col)