From d4f9fa9a19565622c63ecd9b0ae495764d6f5a7f Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 17 Oct 2024 08:18:57 +0200 Subject: [PATCH 1/3] test: add warnings to planner tests Signed-off-by: Andres Taylor --- go/test/vschemawrapper/vschema_wrapper.go | 4 +- go/vt/vtgate/planbuilder/plan_test.go | 5 + .../planbuilder/testdata/aggr_cases.json | 186 ++++++++++++------ .../planbuilder/testdata/cte_cases.json | 18 +- .../ddl_cases_no_default_keyspace.json | 3 +- .../planbuilder/testdata/dml_cases.json | 3 +- .../planbuilder/testdata/filter_cases.json | 9 +- .../planbuilder/testdata/from_cases.json | 3 +- .../testdata/info_schema57_cases.json | 3 +- .../testdata/info_schema80_cases.json | 3 +- .../testdata/memory_sort_cases.json | 30 ++- .../planbuilder/testdata/oltp_cases.json | 6 +- .../testdata/postprocess_cases.json | 57 ++++-- .../planbuilder/testdata/select_cases.json | 30 ++- .../planbuilder/testdata/set_cases.json | 6 +- .../planbuilder/testdata/tpcc_cases.json | 12 +- .../planbuilder/testdata/tpch_cases.json | 39 ++-- .../planbuilder/testdata/union_cases.json | 21 +- .../testdata/unknown_schema_cases.json | 12 +- .../testdata/unsupported_cases.json | 18 +- 20 files changed, 314 insertions(+), 154 deletions(-) diff --git a/go/test/vschemawrapper/vschema_wrapper.go b/go/test/vschemawrapper/vschema_wrapper.go index a1b87f5569c..5255b73fc27 100644 --- a/go/test/vschemawrapper/vschema_wrapper.go +++ b/go/test/vschemawrapper/vschema_wrapper.go @@ -51,6 +51,7 @@ type VSchemaWrapper struct { EnableViews bool TestBuilder func(query string, vschema plancontext.VSchema, keyspace string) (*engine.Plan, error) Env *vtenv.Environment + Warning string } func (vw *VSchemaWrapper) GetPrepareData(stmtName string) *vtgatepb.PrepareData { @@ -132,7 +133,8 @@ func (vw *VSchemaWrapper) Environment() *vtenv.Environment { return vw.Env } -func (vw *VSchemaWrapper) PlannerWarning(_ string) { +func (vw *VSchemaWrapper) PlannerWarning(s string) { + vw.Warning = s } func (vw *VSchemaWrapper) ForeignKeyMode(keyspace string) (vschemapb.Keyspace_ForeignKeyMode, error) { diff --git a/go/vt/vtgate/planbuilder/plan_test.go b/go/vt/vtgate/planbuilder/plan_test.go index 9cf92a91ddf..f4d775a32be 100644 --- a/go/vt/vtgate/planbuilder/plan_test.go +++ b/go/vt/vtgate/planbuilder/plan_test.go @@ -665,6 +665,7 @@ type ( Query string `json:"query,omitempty"` Plan json.RawMessage `json:"plan,omitempty"` Skip bool `json:"skip,omitempty"` + Warning string `json:"warning,omitempty"` } ) @@ -688,6 +689,7 @@ func (s *planTestSuite) testFile(filename string, vschema *vschemawrapper.VSchem } vschema.Version = Gen4 out := getPlanOutput(tcase, vschema, render) + current.Warning = vschema.Warning // our expectation for the planner on the query is one of three // - produces same plan as expected @@ -710,6 +712,9 @@ func (s *planTestSuite) testFile(filename string, vschema *vschemawrapper.VSchem } else if tcase.Skip { t.Errorf("query is correct even though it is skipped:\n %s", tcase.Query) } + if tcase.Warning != current.Warning && !tcase.Skip { + t.Errorf("warning mismatch: expected: %s, got: %s", tcase.Warning, current.Warning) + } current.Plan = []byte(out) }) expected = append(expected, current) diff --git a/go/vt/vtgate/planbuilder/testdata/aggr_cases.json b/go/vt/vtgate/planbuilder/testdata/aggr_cases.json index 8b268e367dd..1229fb18908 100644 --- a/go/vt/vtgate/planbuilder/testdata/aggr_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/aggr_cases.json @@ -303,7 +303,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in group statement is ambiguous" }, { "comment": "scatter aggregate in a subquery", @@ -421,7 +422,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "count with distinct group by unique vindex", @@ -443,7 +445,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in group statement is ambiguous" }, { "comment": "count with distinct unique vindex", @@ -474,7 +477,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "count with distinct no unique vindex", @@ -506,7 +510,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "count with distinct no unique vindex and no group by", @@ -581,7 +586,8 @@ "TablesUsed": [ "user.music" ] - } + }, + "warning": "Column 'user_id' in group statement is ambiguous" }, { "comment": "count with distinct no unique vindex, count expression aliased", @@ -613,7 +619,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "using HAVING inside a derived table still produces viable plans", @@ -642,7 +649,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in group statement is ambiguous" }, { "comment": "sum with distinct no unique vindex", @@ -674,7 +682,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "min with distinct no unique vindex. distinct is ignored.", @@ -706,7 +715,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "order by count distinct", @@ -745,17 +755,20 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "scatter aggregate group by aggregate function - since we don't have authoratative columns for user, we can't be sure that the user isn't referring a column named b", "query": "select count(*) b from user group by b", - "plan": "VT03005: cannot group on 'count(*)'" + "plan": "VT03005: cannot group on 'count(*)'", + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "scatter aggregate group by aggregate function with column information", "query": "select count(*) b from authoritative group by b", - "plan": "VT03005: cannot group on 'b'" + "plan": "VT03005: cannot group on 'b'", + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "scatter aggregate multiple group by (columns)", @@ -787,7 +800,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "Aggregation with derived table", @@ -903,7 +917,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "group concat with a separator needing evaluation on vtgate", @@ -1091,7 +1106,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "scatter aggregate with jumbled order by columns", @@ -1123,7 +1139,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "scatter aggregate with jumbled group by and order by columns", @@ -1155,7 +1172,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "scatter aggregate with some descending order by cols", @@ -1187,12 +1205,14 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "invalid order by column numner for scatter", "query": "select col, count(*) from user group by col order by 5 limit 10", - "plan": "Unknown column '5' in 'order clause'" + "plan": "Unknown column '5' in 'order clause'", + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "aggregate with limit", @@ -1229,7 +1249,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "routing rules for aggregates", @@ -1251,7 +1272,8 @@ "TablesUsed": [ "main.unsharded" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "order by on a reference table", @@ -1273,7 +1295,8 @@ "TablesUsed": [ "user.ref" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "distinct and aggregate functions missing group by", @@ -1334,7 +1357,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "Group by invalid column number (code is duplicated from symab).", @@ -1456,7 +1480,8 @@ "user.user", "user.user_extra" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "optimize group by when using distinct with no aggregation", @@ -1488,7 +1513,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "do not use distinct when using only aggregates and no group by", @@ -1600,7 +1626,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "aggregate query with order by aggregate column along with NULL", @@ -1638,7 +1665,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "aggregate query with order by NULL", @@ -1669,7 +1697,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "join query on sharding key with group by a unique vindex with having clause.", @@ -1744,7 +1773,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in having clause is ambiguous" }, { "comment": "weight_string addition to group by", @@ -1887,7 +1917,8 @@ "user.user", "user.user_extra" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "Column and Literal equality filter on scatter aggregates", @@ -2205,7 +2236,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "We should be able to find grouping keys on ordered aggregates", @@ -2243,7 +2275,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "User defined aggregation expression being used in order by of a query that is single sharded", @@ -2269,7 +2302,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "user defined aggregation such that it can pushed to mysql in a scatter route", @@ -2291,7 +2325,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in group statement is ambiguous" }, { "comment": "distinct on text column with collation", @@ -2322,7 +2357,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "aggregation filtering by having on a route with no group by with non-unique vindex filter", @@ -2742,7 +2778,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "aggregation on top of semijoin", @@ -2833,7 +2870,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "group by column alias", @@ -2865,7 +2903,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "multiple distinct aggregations on the same column is allowed", @@ -2897,7 +2936,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "multiple distinct aggregations on the same column in different positions", @@ -2929,7 +2969,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "distinct aggregation will 3 table join query", @@ -3036,7 +3077,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in group statement is ambiguous" }, { "comment": "select count(distinct user_id, name) from unsharded", @@ -3153,7 +3195,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "find aggregation expression and use column offset in filter times two", @@ -3191,7 +3234,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "find aggregation expression and use column offset in filter times three", @@ -3229,7 +3273,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "having should be able to add new aggregation expressions in having", @@ -3267,7 +3312,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "select u.id from user u join user_extra ue on ue.id = u.id group by u.id having count(u.name) = 3", @@ -3794,7 +3840,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'val1' in group statement is ambiguous" }, { "comment": "Can't inline derived table when it has HAVING with aggregation function", @@ -4143,7 +4190,8 @@ "TablesUsed": [ "user.user_extra" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "aggregation, where and derived tables - we can push extremums", @@ -4181,7 +4229,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'foo' in group statement is ambiguous" }, { "comment": "aggregation, where and derived tables - we can't push aggregations that might need a second layer of aggregation", @@ -4219,7 +4268,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'foo' in group statement is ambiguous" }, { "comment": "Scatter order by is complex with aggregates in select", @@ -4258,7 +4308,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "scatter aggregate complex order by", @@ -4282,7 +4333,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "select expression does not directly depend on grouping expression", @@ -4314,7 +4366,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "inner join with scalar aggregation", @@ -4970,7 +5023,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "scatter aggregate with ambiguous aliases", @@ -5136,7 +5190,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "using a grouping column multiple times should be OK", @@ -5167,7 +5222,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "multiple count star and a count with 3 table join", @@ -5875,7 +5931,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'intcol' in group statement is ambiguous" }, { "comment": "ordering on top of aggregator without pushing the column down during the horizon phase", @@ -6021,7 +6078,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "aggregation on union", @@ -7174,7 +7232,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "col is a column on user, but the HAVING is referring to an alias", @@ -7219,7 +7278,8 @@ { "comment": "Aggregate UDFs can't be handled by vtgate", "query": "select id from t1 group by id having udf_aggr(foo) > 1 and sum(foo) = 10", - "plan": "VT12001: unsupported: Aggregate UDF 'udf_aggr(foo)' must be pushed down to MySQL" + "plan": "VT12001: unsupported: Aggregate UDF 'udf_aggr(foo)' must be pushed down to MySQL", + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "Valid to run since we can push down the aggregate function because of the grouping", @@ -7241,7 +7301,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in group statement is ambiguous" }, { "comment": "Valid to run since we can push down the aggregate function because it's unsharded", @@ -7289,7 +7350,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "Aggregation over a ORDER BY/LIMIT inside a derived table", diff --git a/go/vt/vtgate/planbuilder/testdata/cte_cases.json b/go/vt/vtgate/planbuilder/testdata/cte_cases.json index 016159806d7..4454c915280 100644 --- a/go/vt/vtgate/planbuilder/testdata/cte_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/cte_cases.json @@ -111,7 +111,8 @@ "user.user", "user.user_extra" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "with t as (select user.col as col, 32 from user join user_extra) select sum(col) from t", @@ -370,7 +371,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'val1' in group statement is ambiguous" }, { "comment": "with s as (select id from user having count(*) = 1) select * from s", @@ -484,7 +486,8 @@ "TablesUsed": [ "user.user_extra" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "with tt as (SELECT foo, max(baz) as bazo FROM (SELECT foo, baz FROM user) f GROUP BY foo) SELECT foo FROM tt WHERE bazo BETWEEN 100 AND 200", @@ -522,7 +525,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'foo' in group statement is ambiguous" }, { "comment": "with tt as (SELECT foo, count(baz) as bazo FROM (SELECT foo, baz FROM user) f GROUP BY foo) SELECT foo FROM tt WHERE bazo BETWEEN 100 AND 200", @@ -560,7 +564,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'foo' in group statement is ambiguous" }, { "comment": "with d as (select id, count(*) as a from user) select d.a from music join d on music.user_id = d.id group by 1", @@ -2454,7 +2459,8 @@ "main.dual", "user.user" ] - } + }, + "warning": "Column 'manager_id' in group statement is ambiguous" }, { "comment": "Query that can be merged, dual on the RHS of the UNION", diff --git a/go/vt/vtgate/planbuilder/testdata/ddl_cases_no_default_keyspace.json b/go/vt/vtgate/planbuilder/testdata/ddl_cases_no_default_keyspace.json index b62988b2e38..c053f4e79ae 100644 --- a/go/vt/vtgate/planbuilder/testdata/ddl_cases_no_default_keyspace.json +++ b/go/vt/vtgate/planbuilder/testdata/ddl_cases_no_default_keyspace.json @@ -477,7 +477,8 @@ "TablesUsed": [ "user.view_a" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "create view with Booleans and parenthesis", diff --git a/go/vt/vtgate/planbuilder/testdata/dml_cases.json b/go/vt/vtgate/planbuilder/testdata/dml_cases.json index b5d0fa8951f..66960bb54b2 100644 --- a/go/vt/vtgate/planbuilder/testdata/dml_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/dml_cases.json @@ -3764,7 +3764,8 @@ { "comment": "insert using select with more columns in select", "query": "insert into music(id, user_id) select id, count(user_id), sum(user_id) from user group by id", - "plan": "VT03006: column count does not match value count with the row" + "plan": "VT03006: column count does not match value count with the row", + "warning": "Column 'id' in group statement is ambiguous" }, { "comment": "insert using select with more columns in select after accounting for star column", diff --git a/go/vt/vtgate/planbuilder/testdata/filter_cases.json b/go/vt/vtgate/planbuilder/testdata/filter_cases.json index 3dc379b9aae..5ec2c6f1c32 100644 --- a/go/vt/vtgate/planbuilder/testdata/filter_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/filter_cases.json @@ -4077,7 +4077,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "HAVING predicates that use table columns are safe to rewrite if we can move them to the WHERE clause", @@ -4691,7 +4692,8 @@ "TablesUsed": [ "user.authoritative" ] - } + }, + "warning": "Column 'user_id' in order by statement is ambiguous" }, { "comment": "group by and having with authoritative table - removing keyspace from having", @@ -4717,6 +4719,7 @@ "TablesUsed": [ "user.authoritative" ] - } + }, + "warning": "Column 'user_id' in order by statement is ambiguous" } ] diff --git a/go/vt/vtgate/planbuilder/testdata/from_cases.json b/go/vt/vtgate/planbuilder/testdata/from_cases.json index 2e0fe429c1f..c6a2c1a2359 100644 --- a/go/vt/vtgate/planbuilder/testdata/from_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/from_cases.json @@ -4048,7 +4048,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col1' in group statement is ambiguous" }, { "comment": "join with USING construct", diff --git a/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json b/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json index 31246a2f40f..3b78935fa63 100644 --- a/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json @@ -325,7 +325,8 @@ } ] } - } + }, + "warning": "Column 'ordinal_position' in order by statement is ambiguous" }, { "comment": "rails query", diff --git a/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json b/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json index 9553210174c..798b0731dab 100644 --- a/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json @@ -325,7 +325,8 @@ } ] } - } + }, + "warning": "Column 'ordinal_position' in order by statement is ambiguous" }, { "comment": "rails query", diff --git a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.json b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.json index 060f073a366..93ed4eaf2d2 100644 --- a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.json @@ -36,7 +36,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "scatter aggregate order by references aggregate expression", @@ -75,7 +76,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "select a, b, count(*) k from user group by a order by b, a, k", @@ -114,7 +116,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "scatter aggregate with memory sort and limit", @@ -159,7 +162,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "scatter aggregate with memory sort and order by number", @@ -198,7 +202,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "scatter aggregate with memory sort and order by number, reuse weight_string\n# we have to use a meaningless construct to test this", @@ -236,7 +241,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "order by on a cross-shard derived table", @@ -279,7 +285,8 @@ "user.user", "user.user_extra" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "order by on a cross-shard query. Note: this happens only when an order by column is from the second table", @@ -537,7 +544,8 @@ "TablesUsed": [ "user_index" ] - } + }, + "warning": "Column 'range_start' in order by statement is ambiguous" }, { "comment": "unary expression", @@ -561,7 +569,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "unary expression in join query", @@ -630,7 +639,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'intcol' in order by statement is ambiguous" }, { "comment": "scatter order by with order by column not present", diff --git a/go/vt/vtgate/planbuilder/testdata/oltp_cases.json b/go/vt/vtgate/planbuilder/testdata/oltp_cases.json index 45f1ac8c618..1c043fe312a 100644 --- a/go/vt/vtgate/planbuilder/testdata/oltp_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/oltp_cases.json @@ -97,7 +97,8 @@ "TablesUsed": [ "main.sbtest1" ] - } + }, + "warning": "Column 'c' in order by statement is ambiguous" }, { "comment": "OLTP distinct range select", @@ -127,7 +128,8 @@ "TablesUsed": [ "main.sbtest30" ] - } + }, + "warning": "Column 'c' in order by statement is ambiguous" }, { "comment": "OLTP index udpate", diff --git a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json index 36f1472007d..bff4c92ca08 100644 --- a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json @@ -232,7 +232,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "ORDER BY works for select * from authoritative table", @@ -256,7 +257,8 @@ "TablesUsed": [ "user.authoritative" ] - } + }, + "warning": "Column 'user_id' in order by statement is ambiguous" }, { "comment": "Test that LIMIT can be pushed to the route even in the presence of an outer join", @@ -342,7 +344,8 @@ "TablesUsed": [ "user.authoritative" ] - } + }, + "warning": "Column 'col1' in order by statement is ambiguous" }, { "comment": "ORDER BY on scatter with text column", @@ -366,7 +369,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "ORDER BY on scatter with text column, qualified name TODO: can plan better", @@ -390,7 +394,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "ORDER BY on scatter with multiple text columns", @@ -414,12 +419,14 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'textcol2' in order by statement is ambiguous" }, { "comment": "ORDER BY invalid col number on scatter", "query": "select col from user order by 2", - "plan": "Unknown column '2' in 'order clause'" + "plan": "Unknown column '2' in 'order clause'", + "warning": "Column 'textcol2' in order by statement is ambiguous" }, { "comment": "ORDER BY column offset", @@ -511,7 +518,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "ORDER BY NULL for join", @@ -1152,7 +1160,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "LIMIT", @@ -1441,7 +1450,8 @@ "TablesUsed": [ "user.music" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "column alias for a table column in order by", @@ -1465,7 +1475,8 @@ "TablesUsed": [ "user.music" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "ordering on the left side of the join", @@ -1508,7 +1519,8 @@ "user.music", "user.user" ] - } + }, + "warning": "Column '`name`' in order by statement is ambiguous" }, { "comment": "aggregation and non-aggregations column without group by", @@ -1688,7 +1700,8 @@ "user.music", "user.user" ] - } + }, + "warning": "Column '`name`' in order by statement is ambiguous" }, { "comment": "order by with ambiguous column reference ; valid in MySQL", @@ -1712,7 +1725,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "Scatter order by and aggregation: order by column must reference column from select list", @@ -1751,7 +1765,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in group statement is ambiguous" }, { "comment": "Distinct with cross shard query", @@ -1947,7 +1962,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "Order by column number with collate", @@ -1995,7 +2011,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "Order by column number with collate", @@ -2163,7 +2180,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "distinct with order by having additional non-order by columns in the selection using aggregation engine", @@ -2194,7 +2212,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "distinct with order by having no overalap with the selection columns - using distinct engine", diff --git a/go/vt/vtgate/planbuilder/testdata/select_cases.json b/go/vt/vtgate/planbuilder/testdata/select_cases.json index bd41b2f93ec..4b2f1ad21f2 100644 --- a/go/vt/vtgate/planbuilder/testdata/select_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/select_cases.json @@ -818,7 +818,8 @@ "user.user", "user.user_extra" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "Jumbled references", @@ -1171,7 +1172,8 @@ "TablesUsed": [ "user.music" ] - } + }, + "warning": "Column 'user_id' in order by statement is ambiguous" }, { "comment": "sharded limit offset with arguments", @@ -1202,7 +1204,8 @@ "TablesUsed": [ "user.music" ] - } + }, + "warning": "Column 'user_id' in order by statement is ambiguous" }, { "comment": "Sharding Key Condition in Parenthesis", @@ -1332,7 +1335,8 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "Booleans and parenthesis", @@ -2184,17 +2188,20 @@ "TablesUsed": [ "user.music" ] - } + }, + "warning": "Column 'user_id' in having clause is ambiguous" }, { "comment": "sql_calc_found_rows in sub queries", "query": "select * from music where user_id IN (select sql_calc_found_rows * from music limit 10)", - "plan": "Incorrect usage/placement of 'SQL_CALC_FOUND_ROWS'" + "plan": "Incorrect usage/placement of 'SQL_CALC_FOUND_ROWS'", + "warning": "Column 'user_id' in having clause is ambiguous" }, { "comment": "sql_calc_found_rows in derived table", "query": "select sql_calc_found_rows * from (select sql_calc_found_rows * from music limit 10) t limit 1", - "plan": "Incorrect usage/placement of 'SQL_CALC_FOUND_ROWS'" + "plan": "Incorrect usage/placement of 'SQL_CALC_FOUND_ROWS'", + "warning": "Column 'user_id' in having clause is ambiguous" }, { "comment": "select from unsharded keyspace into dumpfile", @@ -3061,7 +3068,8 @@ "user.user", "user.user_extra" ] - } + }, + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "correlated subquery having dependencies on two tables", @@ -3517,7 +3525,8 @@ "user.user", "user.user_extra" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "yeah, it does not make sense, but it's valid", @@ -5068,7 +5077,8 @@ "user.user", "user.user_extra" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "SELECT music.id FROM (SELECT MAX(id) as maxt FROM music WHERE music.user_id = 5) other JOIN music ON other.maxt = music.id", diff --git a/go/vt/vtgate/planbuilder/testdata/set_cases.json b/go/vt/vtgate/planbuilder/testdata/set_cases.json index 58cb2fffa75..5b85562f373 100644 --- a/go/vt/vtgate/planbuilder/testdata/set_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/set_cases.json @@ -582,7 +582,8 @@ } ] } - } + }, + "warning": "converted 'next transaction' scope to 'session' scope" }, { "comment": "set vitess_metadata", @@ -604,6 +605,7 @@ } ] } - } + }, + "warning": "converted 'next transaction' scope to 'session' scope" } ] diff --git a/go/vt/vtgate/planbuilder/testdata/tpcc_cases.json b/go/vt/vtgate/planbuilder/testdata/tpcc_cases.json index f6072bcd9a5..a9e7597d950 100644 --- a/go/vt/vtgate/planbuilder/testdata/tpcc_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/tpcc_cases.json @@ -566,7 +566,8 @@ "TablesUsed": [ "main.customer1" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "TPC-C select unique customer1", @@ -618,7 +619,8 @@ "TablesUsed": [ "main.orders1" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "TPC-C select order_line1", @@ -670,7 +672,8 @@ "TablesUsed": [ "main.new_orders1" ] - } + }, + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "TPC-C delete new_orders1", @@ -957,7 +960,8 @@ "TablesUsed": [ "main.orders1" ] - } + }, + "warning": "Column 'o_w_id' in group statement is ambiguous" }, { "comment": "TPC-C delete order_line1", diff --git a/go/vt/vtgate/planbuilder/testdata/tpch_cases.json b/go/vt/vtgate/planbuilder/testdata/tpch_cases.json index 6b3f84d01d6..f402c74bdbf 100644 --- a/go/vt/vtgate/planbuilder/testdata/tpch_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/tpch_cases.json @@ -45,12 +45,14 @@ "TablesUsed": [ "main.lineitem" ] - } + }, + "warning": "Column 'l_linestatus' in order by statement is ambiguous" }, { "comment": "TPC-H query 2", "query": "select s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment from part, supplier, partsupp, nation, region where p_partkey = ps_partkey and s_suppkey = ps_suppkey and p_size = 15 and p_type like '%BRASS' and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'EUROPE' and ps_supplycost = ( select min(ps_supplycost) from partsupp, supplier, nation, region where p_partkey = ps_partkey and s_suppkey = ps_suppkey and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'EUROPE' ) order by s_acctbal desc, n_name, s_name, p_partkey limit 10", - "plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS" + "plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS", + "warning": "Column 'p_partkey' in order by statement is ambiguous" }, { "comment": "TPC-H query 3", @@ -181,7 +183,8 @@ "main.lineitem", "main.orders" ] - } + }, + "warning": "Column 'o_orderdate' in order by statement is ambiguous" }, { "comment": "TPC-H query 4", @@ -780,7 +783,8 @@ "main.orders", "main.supplier" ] - } + }, + "warning": "Column 'l_year' in order by statement is ambiguous" }, { "comment": "TPC-H query 8", @@ -1064,7 +1068,8 @@ "main.region", "main.supplier" ] - } + }, + "warning": "Column 'o_year' in order by statement is ambiguous" }, { "comment": "TPC-H query 9", @@ -1766,7 +1771,8 @@ "main.partsupp", "main.supplier" ] - } + }, + "warning": "Column 'ps_partkey' in group statement is ambiguous" }, { "comment": "TPC-H query 12", @@ -1962,7 +1968,8 @@ "main.customer", "main.orders" ] - } + }, + "warning": "Column 'c_count' in order by statement is ambiguous" }, { "comment": "TPC-H query 14", @@ -2092,7 +2099,8 @@ "main.revenue0", "main.supplier" ] - } + }, + "warning": "Column 's_suppkey' in order by statement is ambiguous" }, { "comment": "TPC-H query 16", @@ -2189,7 +2197,8 @@ "main.partsupp", "main.supplier" ] - } + }, + "warning": "Column 'p_size' in order by statement is ambiguous" }, { "comment": "TPC-H query 17", @@ -2357,7 +2366,8 @@ "main.lineitem", "main.orders" ] - } + }, + "warning": "Column 'o_orderdate' in order by statement is ambiguous" }, { "comment": "TPC-H query 19", @@ -2425,7 +2435,8 @@ { "comment": "TPC-H query 20", "query": "select s_name, s_address from supplier, nation where s_suppkey in ( select ps_suppkey from partsupp where ps_partkey in ( select p_partkey from part where p_name like 'forest%' ) and ps_availqty > ( select 0.5 * sum(l_quantity) from lineitem where l_partkey = ps_partkey and l_suppkey = ps_suppkey and l_shipdate >= date('1994-01-01') and l_shipdate < date('1994-01-01') + interval '1' year ) ) and s_nationkey = n_nationkey and n_name = 'CANADA' order by s_name", - "plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS" + "plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS", + "warning": "Column 's_name' in order by statement is ambiguous" }, { "comment": "TPC-H query 21", @@ -2587,11 +2598,13 @@ "main.orders", "main.supplier" ] - } + }, + "warning": "Column 's_name' in order by statement is ambiguous" }, { "comment": "TPC-H query 22", "query": "select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal from ( select substring(c_phone from 1 for 2) as cntrycode, c_acctbal from customer where substring(c_phone from 1 for 2) in ('13', '31', '23', '29', '30', '18', '17') and c_acctbal > ( select avg(c_acctbal) from customer where c_acctbal > 0.00 and substring(c_phone from 1 for 2) in ('13', '31', '23', '29', '30', '18', '17') ) and not exists ( select * from orders where o_custkey = c_custkey ) ) as custsale group by cntrycode order by cntrycode", - "plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS" + "plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS", + "warning": "Column 'cntrycode' in order by statement is ambiguous" } ] diff --git a/go/vt/vtgate/planbuilder/testdata/union_cases.json b/go/vt/vtgate/planbuilder/testdata/union_cases.json index 7feabb0a698..11ef8d9d186 100644 --- a/go/vt/vtgate/planbuilder/testdata/union_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/union_cases.json @@ -160,7 +160,8 @@ "user.music", "user.user" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "Union all", @@ -291,7 +292,8 @@ "user.music", "user.user" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "union all on scatter and single route", @@ -1052,27 +1054,32 @@ "TablesUsed": [ "user.user" ] - } + }, + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "ambiguous LIMIT", "query": "select id from user limit 1 union all select id from music limit 1", - "plan": "syntax error at position 34 near 'union'" + "plan": "syntax error at position 34 near 'union'", + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "ambiguous ORDER BY", "query": "select id from user order by id union all select id from music order by id desc", - "plan": "syntax error at position 38 near 'union'" + "plan": "syntax error at position 38 near 'union'", + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "different number of columns", "query": "select id, 42 from user where id = 1 union all select id from user where id = 5", - "plan": "The used SELECT statements have a different number of columns: 2, 1" + "plan": "The used SELECT statements have a different number of columns: 2, 1", + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "union with invalid order by clause with table qualifier", "query": "select id from user union select 3 order by user.id", - "plan": "Table `user` from one of the SELECTs cannot be used in global ORDER clause" + "plan": "Table `user` from one of the SELECTs cannot be used in global ORDER clause", + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "union with invalid order by clause with table qualifier", diff --git a/go/vt/vtgate/planbuilder/testdata/unknown_schema_cases.json b/go/vt/vtgate/planbuilder/testdata/unknown_schema_cases.json index df4459d9e0f..73a0e7357cc 100644 --- a/go/vt/vtgate/planbuilder/testdata/unknown_schema_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/unknown_schema_cases.json @@ -37,7 +37,8 @@ { "comment": "ORDER BY on select *", "query": "select *, col from user order by col", - "plan": "VT09015: schema tracking required" + "plan": "VT09015: schema tracking required", + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "ORDER BY on select multi t.*", @@ -47,17 +48,20 @@ { "comment": "ORDER BY on select multi *", "query": "select *, name, *, col from user order by col", - "plan": "VT09015: schema tracking required" + "plan": "VT09015: schema tracking required", + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "Group by column number, used with non-aliased expression (duplicated code)", "query": "select * from user group by 1", - "plan": "cannot use column offsets in group clause when using `*`" + "plan": "cannot use column offsets in group clause when using `*`", + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "create view with Cannot auto-resolve for cross-shard joins", "query": "create view user.view_a as select col from user join user_extra", - "plan": "Column 'col' in field list is ambiguous" + "plan": "Column 'col' in field list is ambiguous", + "warning": "Column 'col' in order by statement is ambiguous" }, { "comment": "unsharded insert, unqualified names and auto-inc combined", diff --git a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json index 9241cec595c..e769d016f8b 100644 --- a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json @@ -17,12 +17,14 @@ { "comment": "subqueries not supported in group by", "query": "select id from user group by id, (select id from user_extra)", - "plan": "VT12001: unsupported: subqueries in GROUP BY" + "plan": "VT12001: unsupported: subqueries in GROUP BY", + "warning": "Column 'id' in group statement is ambiguous" }, { "comment": "user defined functions used in having clause that needs evaluation on vtgate", "query": "select col1, udf_aggr( col2 ) r from user group by col1 having r >= 0.3", - "plan": "VT12001: unsupported: Aggregate UDF 'udf_aggr(col2)' must be pushed down to MySQL" + "plan": "VT12001: unsupported: Aggregate UDF 'udf_aggr(col2)' must be pushed down to MySQL", + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "update changes primary vindex column", @@ -32,7 +34,8 @@ { "comment": "subquery with an aggregation in order by that cannot be merged into a single route", "query": "select col, trim((select user_name from user where col = 'a')) val from user_extra where user_id = 3 group by col order by val", - "plan": "VT12001: unsupported: subquery with aggregation in order by" + "plan": "VT12001: unsupported: subquery with aggregation in order by", + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "update change in multicol vindex column", @@ -157,7 +160,8 @@ { "comment": "create view with sharded limit", "query": "create view user.view_a as select id from user order by id limit 10", - "plan": "VT12001: unsupported: Complex select queries are not supported in create or alter view statements" + "plan": "VT12001: unsupported: Complex select queries are not supported in create or alter view statements", + "warning": "Column 'id' in order by statement is ambiguous" }, { "comment": "create view with top level subquery in select", @@ -172,7 +176,8 @@ { "comment": "create view with sql_calc_found_rows with group by and having", "query": "create view user.view_a as select sql_calc_found_rows user_id, count(id) from music group by user_id having count(user_id) = 1 order by user_id limit 2", - "plan": "VT12001: unsupported: Complex select queries are not supported in create or alter view statements" + "plan": "VT12001: unsupported: Complex select queries are not supported in create or alter view statements", + "warning": "Column 'user_id' in having clause is ambiguous" }, { "comment": "create view with incompatible keyspaces", @@ -367,7 +372,8 @@ { "comment": "WITH ROLLUP not supported on sharded queries", "query": "select a, b, c, sum(d) from user group by a, b, c with rollup", - "plan": "VT12001: unsupported: GROUP BY WITH ROLLUP not supported for sharded queries" + "plan": "VT12001: unsupported: GROUP BY WITH ROLLUP not supported for sharded queries", + "warning": "Missing table info, so not binding to anything on the FROM clause" }, { "comment": "SOME/ANY/ALL comparison operator not supported for unsharded queries", From 2df14dbc522bd9e92936e3b286aa11bc76eb93b3 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 17 Oct 2024 08:43:33 +0200 Subject: [PATCH 2/3] feat: improve semantics warnings Store multiple warnings, and add error code to them. wip - uses of semantics not updated yet Signed-off-by: Andres Taylor --- go/vt/vtgate/semantics/analyzer.go | 9 +- go/vt/vtgate/semantics/early_rewriter.go | 21 +++- go/vt/vtgate/semantics/early_rewriter_test.go | 116 ++++++++++-------- go/vt/vtgate/semantics/semantic_table.go | 3 +- go/vt/vtgate/semantics/table_collector.go | 3 +- 5 files changed, 90 insertions(+), 62 deletions(-) diff --git a/go/vt/vtgate/semantics/analyzer.go b/go/vt/vtgate/semantics/analyzer.go index 0a9d2480d9b..5bc7a293bad 100644 --- a/go/vt/vtgate/semantics/analyzer.go +++ b/go/vt/vtgate/semantics/analyzer.go @@ -18,6 +18,7 @@ package semantics import ( "vitess.io/vitess/go/mysql/collations" + querypb "vitess.io/vitess/go/vt/proto/query" vschemapb "vitess.io/vitess/go/vt/proto/vschema" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vterrors" @@ -45,7 +46,7 @@ type analyzer struct { notSingleRouteErr error unshardedErr error - warning string + warnings []*querypb.QueryWarning canShortcut bool singleUnshardedKeyspace bool fullAnalysis bool @@ -140,7 +141,7 @@ func (a *analyzer) newSemTable( return &SemTable{ Tables: a.earlyTables.Tables, Comments: comments, - Warning: a.warning, + Warnings: a.warnings, Collation: coll, ExprTypes: map[sqlparser.Expr]evalengine.Type{}, NotSingleRouteErr: a.notSingleRouteErr, @@ -177,7 +178,7 @@ func (a *analyzer) newSemTable( Targets: a.binder.targets, NotSingleRouteErr: a.notSingleRouteErr, NotUnshardedErr: a.unshardedErr, - Warning: a.warning, + Warnings: a.warnings, Comments: comments, ColumnEqualities: map[columnName][]sqlparser.Expr{}, Collation: coll, @@ -227,7 +228,7 @@ func (a *analyzer) analyzeDown(cursor *sqlparser.Cursor) bool { return true } // log any warn in rewriting. - a.warning = a.rewriter.warning + a.warnings = a.rewriter.warnings a.noteQuerySignature(cursor.Node()) diff --git a/go/vt/vtgate/semantics/early_rewriter.go b/go/vt/vtgate/semantics/early_rewriter.go index 3e53ed0816a..c1687510f54 100644 --- a/go/vt/vtgate/semantics/early_rewriter.go +++ b/go/vt/vtgate/semantics/early_rewriter.go @@ -20,6 +20,8 @@ import ( "fmt" "strconv" + "vitess.io/vitess/go/mysql/sqlerror" + querypb "vitess.io/vitess/go/vt/proto/query" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vtenv" @@ -30,7 +32,7 @@ type earlyRewriter struct { binder *binder scoper *scoper clause string - warning string + warnings []*querypb.QueryWarning expandedColumns map[sqlparser.TableName][]*sqlparser.ColName env *vtenv.Environment aliasMapCache map[*sqlparser.Select]map[string]exprContainer @@ -450,6 +452,13 @@ func (r *earlyRewriter) handleGroupBy(parent sqlparser.SQLNode, iter iterator) e return nil } +func (r *earlyRewriter) addWarning(message string, code sqlerror.ErrorCode) { + r.warnings = append(r.warnings, &querypb.QueryWarning{ + Message: message, + Code: uint32(code), + }) +} + // rewriteHavingAndOrderBy rewrites columns in the ORDER BY and HAVING clauses to use aliases // from the SELECT expressions when applicable, following MySQL scoping rules: // - A column identifier without a table qualifier that matches an alias introduced @@ -483,7 +492,7 @@ func (r *earlyRewriter) rewriteAliasesInGroupBy(node sqlparser.Expr, sel *sqlpar isColumnOnTable, sure := r.isColumnOnTable(col, currentScope) if found && isColumnOnTable { - r.warning = fmt.Sprintf("Column '%s' in group statement is ambiguous", sqlparser.String(col)) + r.addWarning(fmt.Sprintf("Column '%s' in group statement is ambiguous", sqlparser.String(col)), sqlerror.ERNonUniq) } if isColumnOnTable && sure { @@ -491,7 +500,7 @@ func (r *earlyRewriter) rewriteAliasesInGroupBy(node sqlparser.Expr, sel *sqlpar } if !sure { - r.warning = "Missing table info, so not binding to anything on the FROM clause" + r.addWarning("Missing table info, so not binding to anything on the FROM clause", sqlerror.ERNotSupportedYet) } if item.ambiguous { @@ -553,7 +562,7 @@ func (r *earlyRewriter) rewriteAliasesInHaving(node sqlparser.Expr, sel *sqlpars isColumnOnTable, sure := r.isColumnOnTable(col, currentScope) if isColumnOnTable { if found && sure { - r.warning = fmt.Sprintf("Column '%s' in having clause is ambiguous", sqlparser.String(col)) + r.addWarning(fmt.Sprintf("Column '%s' in having clause is ambiguous", sqlparser.String(col)), sqlerror.ERNonUniq) } return } @@ -650,7 +659,7 @@ func (r *earlyRewriter) rewriteAliasesInOrderBy(node sqlparser.Expr, sel *sqlpar } isColumnOnTable, sure := r.isColumnOnTable(col, currentScope) if found && isColumnOnTable && sure { - r.warning = fmt.Sprintf("Column '%s' in order by statement is ambiguous", sqlparser.String(col)) + r.addWarning(fmt.Sprintf("Column '%s' in order by statement is ambiguous", sqlparser.String(col)), sqlerror.ERNonUniq) } topLevel := col == node @@ -660,7 +669,7 @@ func (r *earlyRewriter) rewriteAliasesInOrderBy(node sqlparser.Expr, sel *sqlpar } if !sure { - r.warning = "Missing table info, so not binding to anything on the FROM clause" + r.addWarning("Missing table info, so not binding to anything on the FROM clause", sqlerror.ERNotSupportedYet) } if item.ambiguous { diff --git a/go/vt/vtgate/semantics/early_rewriter_test.go b/go/vt/vtgate/semantics/early_rewriter_test.go index 1ec7786a46c..f1e02286bbc 100644 --- a/go/vt/vtgate/semantics/early_rewriter_test.go +++ b/go/vt/vtgate/semantics/early_rewriter_test.go @@ -24,7 +24,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "vitess.io/vitess/go/slice" "vitess.io/vitess/go/sqltypes" + querypb "vitess.io/vitess/go/vt/proto/query" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vtgate/vindexes" ) @@ -359,7 +361,7 @@ func TestGroupByColumnName(t *testing.T) { sql: "select t1.col1, sum(t2.id) as col1 from t1 join t2 group by col1", expSQL: "select t1.col1, sum(t2.id) as col1 from t1 join t2 group by col1", expDeps: TS0, - warning: "Column 'col1' in group statement is ambiguous", + warning: `code:1052 message:"Column 'col1' in group statement is ambiguous"`, }, { sql: "select t2.col2 as id, sum(t2.id) as x from t1 join t2 group by id", expSQL: "select t2.col2 as id, sum(t2.id) as x from t1 join t2 group by t2.col2", @@ -383,7 +385,12 @@ func TestGroupByColumnName(t *testing.T) { gb := selectStatement.GroupBy deps := st.RecursiveDeps(gb.Exprs[0]) assert.Equal(t, tcase.expDeps, deps) - assert.Equal(t, tcase.warning, st.Warning) + if tcase.warning == "" { + assert.Empty(t, st.Warnings) + } else { + assert.Equal(t, 1, len(st.Warnings)) + assert.Equal(t, tcase.warning, st.Warnings[0].String()) + } } else { require.EqualError(t, err, tcase.expErr) } @@ -538,12 +545,12 @@ func TestHavingColumnName(t *testing.T) { sql: "select id, sum(t1.foo) as foo from t1 having sum(foo) > 1", expSQL: "select id, sum(t1.foo) as foo from t1 having sum(foo) > 1", expDeps: TS0, - warning: "Column 'foo' in having clause is ambiguous", + warning: `code:1052 message:"Column 'foo' in having clause is ambiguous"`, }, { sql: "select id, sum(t1.foo) as foo from t1 having custom_udf(foo) > 1", expSQL: "select id, sum(t1.foo) as foo from t1 having custom_udf(foo) > 1", expDeps: TS0, - warning: "Column 'foo' in having clause is ambiguous", + warning: `code:1052 message:"Column 'foo' in having clause is ambiguous"`, }, { sql: "select id, custom_udf(t1.foo) as foo from t1 having foo > 1", expSQL: "select id, custom_udf(t1.foo) as foo from t1 having custom_udf(t1.foo) > 1", @@ -569,7 +576,7 @@ func TestHavingColumnName(t *testing.T) { sql: "select foo, count(*) foo from t1, emp group by foo having sum(sal) > 1000", expSQL: "select foo, count(*) as foo from t1, emp group by foo having sum(sal) > 1000", expDeps: TS1, - warning: "Column 'foo' in group statement is ambiguous", + warning: `code:1052 message:"Column 'foo' in group statement is ambiguous"`, }, { sql: "select foo as X, sal as foo from t1, emp having sum(X) > 1000", expSQL: "select foo as X, sal as foo from t1, emp having sum(t1.foo) > 1000", @@ -610,7 +617,12 @@ func TestHavingColumnName(t *testing.T) { require.NoError(t, err) assert.Equal(t, tcase.expSQL, sqlparser.String(selectStatement)) assert.Equal(t, tcase.expDeps, semTbl.RecursiveDeps(selectStatement.Having.Expr)) - assert.Equal(t, tcase.warning, semTbl.Warning, "warning") + if tcase.warning == "" { + assert.Empty(t, semTbl.Warnings) + } else { + assert.Equal(t, 1, len(semTbl.Warnings)) + assert.Equal(t, tcase.warning, semTbl.Warnings[0].String()) + } } else { require.EqualError(t, err, tcase.expErr) } @@ -661,11 +673,11 @@ func TestOrderByColumnName(t *testing.T) { schemaInfo := getSchemaWithKnownColumns() cDB := "db" tcases := []struct { - sql string - expSQL string - expErr string - warning string - deps TableSet + sql string + expSQL string + expErr string + warnings []string + deps TableSet }{{ sql: "select id, sum(foo) as sumOfFoo from t1 order by sumOfFoo", expSQL: "select id, sum(foo) as sumOfFoo from t1 order by sum(t1.foo) asc", @@ -682,48 +694,51 @@ func TestOrderByColumnName(t *testing.T) { sql: "select id, sum(foo) as sumOfFoo from t1 order by max(sumOfFoo)", expErr: "Invalid use of group function", }, { - sql: "select id, sum(foo) as foo from t1 order by foo + 1", - expSQL: "select id, sum(foo) as foo from t1 order by foo + 1 asc", - deps: TS0, - warning: "Column 'foo' in order by statement is ambiguous", - }, { - sql: "select id, sum(foo) as foo from t1 order by foo", - expSQL: "select id, sum(foo) as foo from t1 order by sum(t1.foo) asc", - deps: TS0, - warning: "Column 'foo' in order by statement is ambiguous", - }, { - sql: "select id, lower(min(foo)) as foo from t1 order by min(foo)", - expSQL: "select id, lower(min(foo)) as foo from t1 order by min(foo) asc", - deps: TS0, - warning: "Column 'foo' in order by statement is ambiguous", - }, { - sql: "select id, lower(min(foo)) as foo from t1 order by foo", - expSQL: "select id, lower(min(foo)) as foo from t1 order by lower(min(t1.foo)) asc", - deps: TS0, - warning: "Column 'foo' in order by statement is ambiguous", - }, { - sql: "select id, lower(min(foo)) as foo from t1 order by abs(foo)", - expSQL: "select id, lower(min(foo)) as foo from t1 order by abs(foo) asc", - deps: TS0, - warning: "Column 'foo' in order by statement is ambiguous", - }, { - sql: "select id, t1.bar as foo from t1 group by id order by min(foo)", - expSQL: "select id, t1.bar as foo from t1 group by id order by min(foo) asc", - deps: TS0, - warning: "Column 'foo' in order by statement is ambiguous", + sql: "select id, sum(foo) as foo from t1 order by foo + 1", + expSQL: "select id, sum(foo) as foo from t1 order by foo + 1 asc", + deps: TS0, + warnings: []string{`code:1052 message:"Column 'foo' in order by statement is ambiguous"`}, + }, { + sql: "select id, sum(foo) as foo from t1 order by foo", + expSQL: "select id, sum(foo) as foo from t1 order by sum(t1.foo) asc", + deps: TS0, + warnings: []string{`code:1052 message:"Column 'foo' in order by statement is ambiguous"`}, + }, { + sql: "select id, lower(min(foo)) as foo from t1 order by min(foo)", + expSQL: "select id, lower(min(foo)) as foo from t1 order by min(foo) asc", + deps: TS0, + warnings: []string{`code:1052 message:"Column 'foo' in order by statement is ambiguous"`}, + }, { + sql: "select id, lower(min(foo)) as foo from t1 order by foo", + expSQL: "select id, lower(min(foo)) as foo from t1 order by lower(min(t1.foo)) asc", + deps: TS0, + warnings: []string{`code:1052 message:"Column 'foo' in order by statement is ambiguous"`}, + }, { + sql: "select id, lower(min(foo)) as foo from t1 order by abs(foo)", + expSQL: "select id, lower(min(foo)) as foo from t1 order by abs(foo) asc", + deps: TS0, + warnings: []string{`code:1052 message:"Column 'foo' in order by statement is ambiguous"`}, + }, { + sql: "select id, t1.bar as foo from t1 group by id order by min(foo)", + expSQL: "select id, t1.bar as foo from t1 group by id order by min(foo) asc", + deps: TS0, + warnings: []string{ + `code:1052 message:"Column 'id' in group statement is ambiguous"`, + `code:1052 message:"Column 'foo' in order by statement is ambiguous"`, + }, }, { sql: "select id, bar as id, count(*) from t1 order by id", expErr: "Column 'id' in field list is ambiguous", }, { - sql: "select id, id, count(*) from t1 order by id", - expSQL: "select id, id, count(*) from t1 order by t1.id asc", - deps: TS0, - warning: "Column 'id' in order by statement is ambiguous", + sql: "select id, id, count(*) from t1 order by id", + expSQL: "select id, id, count(*) from t1 order by t1.id asc", + deps: TS0, + warnings: []string{`code:1052 message:"Column 'id' in order by statement is ambiguous"`}, }, { - sql: "select id, count(distinct foo) k from t1 group by id order by k", - expSQL: "select id, count(distinct foo) as k from t1 group by id order by count(distinct t1.foo) asc", - deps: TS0, - warning: "Column 'id' in group statement is ambiguous", + sql: "select id, count(distinct foo) k from t1 group by id order by k", + expSQL: "select id, count(distinct foo) as k from t1 group by id order by count(distinct t1.foo) asc", + deps: TS0, + warnings: []string{`code:1052 message:"Column 'id' in group statement is ambiguous"`}, }, { sql: "select user.id as foo from user union select col from user_extra order by foo", expSQL: "select `user`.id as foo from `user` union select col from user_extra order by foo asc", @@ -744,7 +759,10 @@ func TestOrderByColumnName(t *testing.T) { assert.Equal(t, tcase.expSQL, sqlparser.String(selectStatement)) orderByExpr := selectStatement.GetOrderBy()[0].Expr assert.Equal(t, tcase.deps, semTable.RecursiveDeps(orderByExpr)) - assert.Equal(t, tcase.warning, semTable.Warning) + warnings := slice.Map(semTable.Warnings, func(q *querypb.QueryWarning) string { + return q.String() + }) + assert.Equal(t, tcase.warnings, warnings) } else { require.EqualError(t, err, tcase.expErr) } diff --git a/go/vt/vtgate/semantics/semantic_table.go b/go/vt/vtgate/semantics/semantic_table.go index f9856a901a6..d0ac94d59b8 100644 --- a/go/vt/vtgate/semantics/semantic_table.go +++ b/go/vt/vtgate/semantics/semantic_table.go @@ -22,6 +22,7 @@ import ( "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/key" + querypb "vitess.io/vitess/go/vt/proto/query" topodatapb "vitess.io/vitess/go/vt/proto/topodata" vschemapb "vitess.io/vitess/go/vt/proto/vschema" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" @@ -102,7 +103,7 @@ type ( // Comments stores any comments of the /* vt+ */ type in the query Comments *sqlparser.ParsedComments // Warning stores any warnings generated during semantic analysis. - Warning string + Warnings []*querypb.QueryWarning // Collation represents the default collation for the query, usually inherited // from the connection's default collation. Collation collations.ID diff --git a/go/vt/vtgate/semantics/table_collector.go b/go/vt/vtgate/semantics/table_collector.go index 191d9c3b38e..f58e2cd05e9 100644 --- a/go/vt/vtgate/semantics/table_collector.go +++ b/go/vt/vtgate/semantics/table_collector.go @@ -19,9 +19,8 @@ package semantics import ( "fmt" - vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" - querypb "vitess.io/vitess/go/vt/proto/query" + vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/vtgate/evalengine" From 6e3329f2a03794d699d2197b9270dd28b0d6358d Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 17 Oct 2024 10:56:00 +0200 Subject: [PATCH 3/3] feat: use error codes for warnings and allow multiple warnings Signed-off-by: Andres Taylor --- go/mysql/sqlerror/constants.go | 1 + go/test/vschemawrapper/vschema_wrapper.go | 6 +- go/vt/vtgate/planbuilder/plan_test.go | 23 +- .../plancontext/planning_context.go | 2 +- .../plancontext/planning_context_test.go | 3 +- .../vtgate/planbuilder/plancontext/vschema.go | 2 +- go/vt/vtgate/planbuilder/select.go | 2 +- go/vt/vtgate/planbuilder/set.go | 8 +- .../planbuilder/testdata/aggr_cases.json | 291 ++++++++++++++---- .../planbuilder/testdata/cte_cases.json | 26 +- .../ddl_cases_no_default_keyspace.json | 4 +- .../planbuilder/testdata/dml_cases.json | 4 +- .../planbuilder/testdata/filter_cases.json | 14 +- .../planbuilder/testdata/from_cases.json | 4 +- .../testdata/info_schema57_cases.json | 4 +- .../testdata/info_schema80_cases.json | 4 +- .../testdata/memory_sort_cases.json | 45 ++- .../planbuilder/testdata/oltp_cases.json | 8 +- .../testdata/postprocess_cases.json | 82 +++-- .../planbuilder/testdata/select_cases.json | 46 ++- .../planbuilder/testdata/set_cases.json | 8 +- .../planbuilder/testdata/tpcc_cases.json | 19 +- .../planbuilder/testdata/tpch_cases.json | 83 ++++- .../planbuilder/testdata/union_cases.json | 28 +- .../testdata/unknown_schema_cases.json | 16 +- .../testdata/unsupported_cases.json | 30 +- go/vt/vtgate/semantics/early_rewriter.go | 8 + go/vt/vtgate/vcursor_impl.go | 10 +- 28 files changed, 603 insertions(+), 178 deletions(-) diff --git a/go/mysql/sqlerror/constants.go b/go/mysql/sqlerror/constants.go index da2351bf00d..758dc76f778 100644 --- a/go/mysql/sqlerror/constants.go +++ b/go/mysql/sqlerror/constants.go @@ -220,6 +220,7 @@ const ( ERWrongFKDef = ErrorCode(1239) ERKeyRefDoNotMatchTableRef = ErrorCode(1240) ERCyclicReference = ErrorCode(1245) + ERAutoConvert = ErrorCode(1246) ERIllegalReference = ErrorCode(1247) ERDerivedMustHaveAlias = ErrorCode(1248) ERTableNameNotAllowedHere = ErrorCode(1250) diff --git a/go/test/vschemawrapper/vschema_wrapper.go b/go/test/vschemawrapper/vschema_wrapper.go index 5255b73fc27..e0856f8195a 100644 --- a/go/test/vschemawrapper/vschema_wrapper.go +++ b/go/test/vschemawrapper/vschema_wrapper.go @@ -51,7 +51,7 @@ type VSchemaWrapper struct { EnableViews bool TestBuilder func(query string, vschema plancontext.VSchema, keyspace string) (*engine.Plan, error) Env *vtenv.Environment - Warning string + Warnings []*querypb.QueryWarning } func (vw *VSchemaWrapper) GetPrepareData(stmtName string) *vtgatepb.PrepareData { @@ -133,8 +133,8 @@ func (vw *VSchemaWrapper) Environment() *vtenv.Environment { return vw.Env } -func (vw *VSchemaWrapper) PlannerWarning(s string) { - vw.Warning = s +func (vw *VSchemaWrapper) PlannerWarnings(warnings ...*querypb.QueryWarning) { + vw.Warnings = warnings } func (vw *VSchemaWrapper) ForeignKeyMode(keyspace string) (vschemapb.Keyspace_ForeignKeyMode, error) { diff --git a/go/vt/vtgate/planbuilder/plan_test.go b/go/vt/vtgate/planbuilder/plan_test.go index f4d775a32be..70ff929b613 100644 --- a/go/vt/vtgate/planbuilder/plan_test.go +++ b/go/vt/vtgate/planbuilder/plan_test.go @@ -28,6 +28,11 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" + + "vitess.io/vitess/go/slice" + querypb "vitess.io/vitess/go/vt/proto/query" + "github.com/nsf/jsondiff" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -661,11 +666,11 @@ func createFkDefinition(childCols []string, parentTableName string, parentCols [ type ( planTest struct { - Comment string `json:"comment,omitempty"` - Query string `json:"query,omitempty"` - Plan json.RawMessage `json:"plan,omitempty"` - Skip bool `json:"skip,omitempty"` - Warning string `json:"warning,omitempty"` + Comment string `json:"comment,omitempty"` + Query string `json:"query,omitempty"` + Plan json.RawMessage `json:"plan,omitempty"` + Skip bool `json:"skip,omitempty"` + Warnings []string `json:"warnings,omitempty"` } ) @@ -689,7 +694,9 @@ func (s *planTestSuite) testFile(filename string, vschema *vschemawrapper.VSchem } vschema.Version = Gen4 out := getPlanOutput(tcase, vschema, render) - current.Warning = vschema.Warning + current.Warnings = slice.Map(vschema.Warnings, func(q *querypb.QueryWarning) string { + return q.String() + }) // our expectation for the planner on the query is one of three // - produces same plan as expected @@ -712,8 +719,8 @@ func (s *planTestSuite) testFile(filename string, vschema *vschemawrapper.VSchem } else if tcase.Skip { t.Errorf("query is correct even though it is skipped:\n %s", tcase.Query) } - if tcase.Warning != current.Warning && !tcase.Skip { - t.Errorf("warning mismatch: expected: %s, got: %s", tcase.Warning, current.Warning) + if !tcase.Skip { + assert.Equal(t, tcase.Warnings, current.Warnings) } current.Plan = []byte(out) }) diff --git a/go/vt/vtgate/planbuilder/plancontext/planning_context.go b/go/vt/vtgate/planbuilder/plancontext/planning_context.go index 607ca83aa31..484ee12eb68 100644 --- a/go/vt/vtgate/planbuilder/plancontext/planning_context.go +++ b/go/vt/vtgate/planbuilder/plancontext/planning_context.go @@ -101,7 +101,7 @@ func CreatePlanningContext(stmt sqlparser.Statement, } // record any warning as planner warning. - vschema.PlannerWarning(semTable.Warning) + vschema.PlannerWarnings(semTable.Warnings...) return &PlanningContext{ ReservedVars: reservedVars, diff --git a/go/vt/vtgate/planbuilder/plancontext/planning_context_test.go b/go/vt/vtgate/planbuilder/plancontext/planning_context_test.go index d7315f376b6..9c703b03542 100644 --- a/go/vt/vtgate/planbuilder/plancontext/planning_context_test.go +++ b/go/vt/vtgate/planbuilder/plancontext/planning_context_test.go @@ -290,8 +290,7 @@ func (v *vschema) WarnUnshardedOnly(format string, params ...any) { panic("implement me") } -func (v *vschema) PlannerWarning(message string) { - // TODO implement me +func (v *vschema) PlannerWarnings(...*querypb.QueryWarning) { panic("implement me") } diff --git a/go/vt/vtgate/planbuilder/plancontext/vschema.go b/go/vt/vtgate/planbuilder/plancontext/vschema.go index 6e92ad0d83b..e517ffb69ed 100644 --- a/go/vt/vtgate/planbuilder/plancontext/vschema.go +++ b/go/vt/vtgate/planbuilder/plancontext/vschema.go @@ -54,7 +54,7 @@ type VSchema interface { WarnUnshardedOnly(format string, params ...any) // PlannerWarning records warning created during planning. - PlannerWarning(message string) + PlannerWarnings(warnings ...*querypb.QueryWarning) // ForeignKeyMode returns the foreign_key flag value ForeignKeyMode(keyspace string) (vschemapb.Keyspace_ForeignKeyMode, error) diff --git a/go/vt/vtgate/planbuilder/select.go b/go/vt/vtgate/planbuilder/select.go index 9cc1c8efe06..b7d4b22c8e5 100644 --- a/go/vt/vtgate/planbuilder/select.go +++ b/go/vt/vtgate/planbuilder/select.go @@ -109,7 +109,7 @@ func gen4planSQLCalcFoundRows(vschema plancontext.VSchema, sel *sqlparser.Select return nil, err } // record any warning as planner warning. - vschema.PlannerWarning(semTable.Warning) + vschema.PlannerWarnings(semTable.Warnings...) plan, tablesUsed, err := buildSQLCalcFoundRowsPlan(query, sel, reservedVars, vschema) if err != nil { diff --git a/go/vt/vtgate/planbuilder/set.go b/go/vt/vtgate/planbuilder/set.go index 77f20be40f9..9c6afea5316 100644 --- a/go/vt/vtgate/planbuilder/set.go +++ b/go/vt/vtgate/planbuilder/set.go @@ -21,6 +21,9 @@ import ( "strconv" "strings" + "vitess.io/vitess/go/mysql/sqlerror" + querypb "vitess.io/vitess/go/vt/proto/query" + "vitess.io/vitess/go/vt/key" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/sysvars" @@ -92,7 +95,10 @@ func buildSetPlan(stmt *sqlparser.Set, vschema plancontext.VSchema) (*planResult // This is to keep the backward compatibility. // 'transaction_isolation' was added as a reserved connection system variable, so it used to change the setting at session level already. // logging warning now to - vschema.PlannerWarning("converted 'next transaction' scope to 'session' scope") + vschema.PlannerWarnings(&querypb.QueryWarning{ + Code: uint32(sqlerror.ERAutoConvert), + Message: "converted 'next transaction' scope to 'session' scope", + }) } case sqlparser.VitessMetadataScope: value, err := getValueFor(expr) diff --git a/go/vt/vtgate/planbuilder/testdata/aggr_cases.json b/go/vt/vtgate/planbuilder/testdata/aggr_cases.json index 1229fb18908..4e7383c72a6 100644 --- a/go/vt/vtgate/planbuilder/testdata/aggr_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/aggr_cases.json @@ -304,7 +304,9 @@ "user.user" ] }, - "warning": "Column 'id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"" + ] }, { "comment": "scatter aggregate in a subquery", @@ -423,7 +425,9 @@ "user.user" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"" + ] }, { "comment": "count with distinct group by unique vindex", @@ -446,7 +450,9 @@ "user.user" ] }, - "warning": "Column 'id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"" + ] }, { "comment": "count with distinct unique vindex", @@ -478,7 +484,9 @@ "user.user" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"" + ] }, { "comment": "count with distinct no unique vindex", @@ -511,7 +519,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "count with distinct no unique vindex and no group by", @@ -587,7 +598,10 @@ "user.music" ] }, - "warning": "Column 'user_id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"", + "code:1052 message:\"Column 'user_id' in group statement is ambiguous\"" + ] }, { "comment": "count with distinct no unique vindex, count expression aliased", @@ -620,7 +634,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "using HAVING inside a derived table still produces viable plans", @@ -650,7 +667,9 @@ "user.user" ] }, - "warning": "Column 'id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"" + ] }, { "comment": "sum with distinct no unique vindex", @@ -683,7 +702,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "min with distinct no unique vindex. distinct is ignored.", @@ -716,7 +738,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "order by count distinct", @@ -756,19 +781,28 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "scatter aggregate group by aggregate function - since we don't have authoratative columns for user, we can't be sure that the user isn't referring a column named b", "query": "select count(*) b from user group by b", "plan": "VT03005: cannot group on 'count(*)'", - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'b' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "scatter aggregate group by aggregate function with column information", "query": "select count(*) b from authoritative group by b", "plan": "VT03005: cannot group on 'b'", - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'b' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "scatter aggregate multiple group by (columns)", @@ -801,7 +835,11 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'a' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'b' in group statement is ambiguous\"" + ] }, { "comment": "Aggregation with derived table", @@ -918,7 +956,11 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'b' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'a' in group statement is ambiguous\"" + ] }, { "comment": "group concat with a separator needing evaluation on vtgate", @@ -1107,7 +1149,9 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "scatter aggregate with jumbled order by columns", @@ -1140,7 +1184,9 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "scatter aggregate with jumbled group by and order by columns", @@ -1173,7 +1219,9 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "scatter aggregate with some descending order by cols", @@ -1206,13 +1254,17 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "invalid order by column numner for scatter", "query": "select col, count(*) from user group by col order by 5 limit 10", "plan": "Unknown column '5' in 'order clause'", - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "aggregate with limit", @@ -1250,7 +1302,9 @@ "user.user" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"" + ] }, { "comment": "routing rules for aggregates", @@ -1273,7 +1327,10 @@ "main.unsharded" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "order by on a reference table", @@ -1296,7 +1353,9 @@ "user.ref" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "distinct and aggregate functions missing group by", @@ -1358,7 +1417,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'a' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "Group by invalid column number (code is duplicated from symab).", @@ -1481,7 +1543,9 @@ "user.user_extra" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"" + ] }, { "comment": "optimize group by when using distinct with no aggregation", @@ -1514,7 +1578,11 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'col2' in group statement is ambiguous\"" + ] }, { "comment": "do not use distinct when using only aggregates and no group by", @@ -1627,7 +1695,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "aggregate query with order by aggregate column along with NULL", @@ -1666,7 +1737,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "aggregate query with order by NULL", @@ -1698,7 +1772,9 @@ "user.user" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"" + ] }, { "comment": "join query on sharding key with group by a unique vindex with having clause.", @@ -1774,7 +1850,10 @@ "user.user" ] }, - "warning": "Column 'id' in having clause is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"", + "code:1052 message:\"Column 'id' in having clause is ambiguous\"" + ] }, { "comment": "weight_string addition to group by", @@ -1918,7 +1997,9 @@ "user.user_extra" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "Column and Literal equality filter on scatter aggregates", @@ -2237,7 +2318,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "We should be able to find grouping keys on ordered aggregates", @@ -2276,7 +2360,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col2' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "User defined aggregation expression being used in order by of a query that is single sharded", @@ -2303,7 +2390,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "user defined aggregation such that it can pushed to mysql in a scatter route", @@ -2326,7 +2416,9 @@ "user.user" ] }, - "warning": "Column 'id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"" + ] }, { "comment": "distinct on text column with collation", @@ -2358,7 +2450,9 @@ "user.user" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"" + ] }, { "comment": "aggregation filtering by having on a route with no group by with non-unique vindex filter", @@ -2779,7 +2873,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "aggregation on top of semijoin", @@ -2871,7 +2968,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'val2' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "group by column alias", @@ -2904,7 +3004,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'a' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "multiple distinct aggregations on the same column is allowed", @@ -2937,7 +3040,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'tcol1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "multiple distinct aggregations on the same column in different positions", @@ -2970,7 +3076,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'tcol1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "distinct aggregation will 3 table join query", @@ -3078,7 +3187,9 @@ "user.user" ] }, - "warning": "Column 'id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"" + ] }, { "comment": "select count(distinct user_id, name) from unsharded", @@ -3196,7 +3307,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'foo' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "find aggregation expression and use column offset in filter times two", @@ -3235,7 +3349,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'foo' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "find aggregation expression and use column offset in filter times three", @@ -3274,7 +3391,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'foo' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "having should be able to add new aggregation expressions in having", @@ -3313,7 +3433,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'foo' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "select u.id from user u join user_extra ue on ue.id = u.id group by u.id having count(u.name) = 3", @@ -3841,7 +3964,10 @@ "user.user" ] }, - "warning": "Column 'val1' in group statement is ambiguous" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'val1' in group statement is ambiguous\"" + ] }, { "comment": "Can't inline derived table when it has HAVING with aggregation function", @@ -4191,7 +4317,10 @@ "user.user_extra" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'flowId' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "aggregation, where and derived tables - we can push extremums", @@ -4230,7 +4359,9 @@ "user.user" ] }, - "warning": "Column 'foo' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'foo' in group statement is ambiguous\"" + ] }, { "comment": "aggregation, where and derived tables - we can't push aggregations that might need a second layer of aggregation", @@ -4269,7 +4400,9 @@ "user.user" ] }, - "warning": "Column 'foo' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'foo' in group statement is ambiguous\"" + ] }, { "comment": "Scatter order by is complex with aggregates in select", @@ -4309,7 +4442,10 @@ "user.user" ] }, - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"", + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "scatter aggregate complex order by", @@ -4334,7 +4470,10 @@ "user.user" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"", + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "select expression does not directly depend on grouping expression", @@ -4367,7 +4506,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'a' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "inner join with scalar aggregation", @@ -5024,7 +5166,12 @@ "user.user" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"", + "code:1052 message:\"Column 'val' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'id' in group statement is ambiguous\"" + ] }, { "comment": "scatter aggregate with ambiguous aliases", @@ -5191,7 +5338,9 @@ "user.user" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"" + ] }, { "comment": "using a grouping column multiple times should be OK", @@ -5223,7 +5372,9 @@ "user.user" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"" + ] }, { "comment": "multiple count star and a count with 3 table join", @@ -5932,7 +6083,9 @@ "user.user" ] }, - "warning": "Column 'intcol' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'intcol' in group statement is ambiguous\"" + ] }, { "comment": "ordering on top of aggregator without pushing the column down during the horizon phase", @@ -6079,7 +6232,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'foo' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "aggregation on union", @@ -7233,7 +7389,10 @@ "user.user" ] }, - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"", + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "col is a column on user, but the HAVING is referring to an alias", @@ -7279,7 +7438,10 @@ "comment": "Aggregate UDFs can't be handled by vtgate", "query": "select id from t1 group by id having udf_aggr(foo) > 1 and sum(foo) = 10", "plan": "VT12001: unsupported: Aggregate UDF 'udf_aggr(foo)' must be pushed down to MySQL", - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "Valid to run since we can push down the aggregate function because of the grouping", @@ -7302,7 +7464,9 @@ "user.user" ] }, - "warning": "Column 'id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"" + ] }, { "comment": "Valid to run since we can push down the aggregate function because it's unsharded", @@ -7351,7 +7515,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'bar' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "Aggregation over a ORDER BY/LIMIT inside a derived table", diff --git a/go/vt/vtgate/planbuilder/testdata/cte_cases.json b/go/vt/vtgate/planbuilder/testdata/cte_cases.json index 4454c915280..97296076c34 100644 --- a/go/vt/vtgate/planbuilder/testdata/cte_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/cte_cases.json @@ -112,7 +112,9 @@ "user.user_extra" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"" + ] }, { "comment": "with t as (select user.col as col, 32 from user join user_extra) select sum(col) from t", @@ -372,7 +374,10 @@ "user.user" ] }, - "warning": "Column 'val1' in group statement is ambiguous" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'val1' in group statement is ambiguous\"" + ] }, { "comment": "with s as (select id from user having count(*) = 1) select * from s", @@ -487,7 +492,10 @@ "user.user_extra" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'flowId' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "with tt as (SELECT foo, max(baz) as bazo FROM (SELECT foo, baz FROM user) f GROUP BY foo) SELECT foo FROM tt WHERE bazo BETWEEN 100 AND 200", @@ -526,7 +534,9 @@ "user.user" ] }, - "warning": "Column 'foo' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'foo' in group statement is ambiguous\"" + ] }, { "comment": "with tt as (SELECT foo, count(baz) as bazo FROM (SELECT foo, baz FROM user) f GROUP BY foo) SELECT foo FROM tt WHERE bazo BETWEEN 100 AND 200", @@ -565,7 +575,9 @@ "user.user" ] }, - "warning": "Column 'foo' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'foo' in group statement is ambiguous\"" + ] }, { "comment": "with d as (select id, count(*) as a from user) select d.a from music join d on music.user_id = d.id group by 1", @@ -2460,7 +2472,9 @@ "user.user" ] }, - "warning": "Column 'manager_id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'manager_id' in group statement is ambiguous\"" + ] }, { "comment": "Query that can be merged, dual on the RHS of the UNION", diff --git a/go/vt/vtgate/planbuilder/testdata/ddl_cases_no_default_keyspace.json b/go/vt/vtgate/planbuilder/testdata/ddl_cases_no_default_keyspace.json index c053f4e79ae..269817bf985 100644 --- a/go/vt/vtgate/planbuilder/testdata/ddl_cases_no_default_keyspace.json +++ b/go/vt/vtgate/planbuilder/testdata/ddl_cases_no_default_keyspace.json @@ -478,7 +478,9 @@ "user.view_a" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "create view with Booleans and parenthesis", diff --git a/go/vt/vtgate/planbuilder/testdata/dml_cases.json b/go/vt/vtgate/planbuilder/testdata/dml_cases.json index 66960bb54b2..577958d60e8 100644 --- a/go/vt/vtgate/planbuilder/testdata/dml_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/dml_cases.json @@ -3765,7 +3765,9 @@ "comment": "insert using select with more columns in select", "query": "insert into music(id, user_id) select id, count(user_id), sum(user_id) from user group by id", "plan": "VT03006: column count does not match value count with the row", - "warning": "Column 'id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"" + ] }, { "comment": "insert using select with more columns in select after accounting for star column", diff --git a/go/vt/vtgate/planbuilder/testdata/filter_cases.json b/go/vt/vtgate/planbuilder/testdata/filter_cases.json index 5ec2c6f1c32..8d85057551f 100644 --- a/go/vt/vtgate/planbuilder/testdata/filter_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/filter_cases.json @@ -4078,7 +4078,9 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "HAVING predicates that use table columns are safe to rewrite if we can move them to the WHERE clause", @@ -4693,7 +4695,9 @@ "user.authoritative" ] }, - "warning": "Column 'user_id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'user_id' in order by statement is ambiguous\"" + ] }, { "comment": "group by and having with authoritative table - removing keyspace from having", @@ -4720,6 +4724,10 @@ "user.authoritative" ] }, - "warning": "Column 'user_id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'user_id' in group statement is ambiguous\"", + "code:1052 message:\"Column 'user_id' in having clause is ambiguous\"", + "code:1052 message:\"Column 'user_id' in order by statement is ambiguous\"" + ] } ] diff --git a/go/vt/vtgate/planbuilder/testdata/from_cases.json b/go/vt/vtgate/planbuilder/testdata/from_cases.json index c6a2c1a2359..9018fb09788 100644 --- a/go/vt/vtgate/planbuilder/testdata/from_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/from_cases.json @@ -4049,7 +4049,9 @@ "user.user" ] }, - "warning": "Column 'col1' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"" + ] }, { "comment": "join with USING construct", diff --git a/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json b/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json index 3b78935fa63..ad74f22983c 100644 --- a/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json @@ -326,7 +326,9 @@ ] } }, - "warning": "Column 'ordinal_position' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'ordinal_position' in order by statement is ambiguous\"" + ] }, { "comment": "rails query", diff --git a/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json b/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json index 798b0731dab..d3999692a28 100644 --- a/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json @@ -326,7 +326,9 @@ ] } }, - "warning": "Column 'ordinal_position' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'ordinal_position' in order by statement is ambiguous\"" + ] }, { "comment": "rails query", diff --git a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.json b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.json index 93ed4eaf2d2..1411f29e192 100644 --- a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.json @@ -37,7 +37,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'a' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "scatter aggregate order by references aggregate expression", @@ -77,7 +80,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'a' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "select a, b, count(*) k from user group by a order by b, a, k", @@ -117,7 +123,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'a' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "scatter aggregate with memory sort and limit", @@ -163,7 +172,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'a' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "scatter aggregate with memory sort and order by number", @@ -203,7 +215,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'a' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "scatter aggregate with memory sort and order by number, reuse weight_string\n# we have to use a meaningless construct to test this", @@ -242,7 +257,9 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "order by on a cross-shard derived table", @@ -286,7 +303,9 @@ "user.user_extra" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "order by on a cross-shard query. Note: this happens only when an order by column is from the second table", @@ -545,7 +564,9 @@ "user_index" ] }, - "warning": "Column 'range_start' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'range_start' in order by statement is ambiguous\"" + ] }, { "comment": "unary expression", @@ -570,7 +591,9 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "unary expression in join query", @@ -640,7 +663,9 @@ "user.user" ] }, - "warning": "Column 'intcol' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'intcol' in order by statement is ambiguous\"" + ] }, { "comment": "scatter order by with order by column not present", diff --git a/go/vt/vtgate/planbuilder/testdata/oltp_cases.json b/go/vt/vtgate/planbuilder/testdata/oltp_cases.json index 1c043fe312a..830bf15df7e 100644 --- a/go/vt/vtgate/planbuilder/testdata/oltp_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/oltp_cases.json @@ -98,7 +98,9 @@ "main.sbtest1" ] }, - "warning": "Column 'c' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'c' in order by statement is ambiguous\"" + ] }, { "comment": "OLTP distinct range select", @@ -129,7 +131,9 @@ "main.sbtest30" ] }, - "warning": "Column 'c' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'c' in order by statement is ambiguous\"" + ] }, { "comment": "OLTP index udpate", diff --git a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json index bff4c92ca08..f6ea944f462 100644 --- a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json @@ -233,7 +233,9 @@ "user.user" ] }, - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "ORDER BY works for select * from authoritative table", @@ -258,7 +260,9 @@ "user.authoritative" ] }, - "warning": "Column 'user_id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'user_id' in order by statement is ambiguous\"" + ] }, { "comment": "Test that LIMIT can be pushed to the route even in the presence of an outer join", @@ -345,7 +349,9 @@ "user.authoritative" ] }, - "warning": "Column 'col1' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col1' in order by statement is ambiguous\"" + ] }, { "comment": "ORDER BY on scatter with text column", @@ -370,7 +376,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'textcol1' in order by statement is ambiguous\"" + ] }, { "comment": "ORDER BY on scatter with text column, qualified name TODO: can plan better", @@ -395,7 +404,10 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'textcol1' in order by statement is ambiguous\"" + ] }, { "comment": "ORDER BY on scatter with multiple text columns", @@ -420,13 +432,21 @@ "user.user" ] }, - "warning": "Column 'textcol2' in order by statement is ambiguous" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'textcol1' in order by statement is ambiguous\"", + "code:1052 message:\"Column 'textcol2' in order by statement is ambiguous\"" + ] }, { "comment": "ORDER BY invalid col number on scatter", "query": "select col from user order by 2", "plan": "Unknown column '2' in 'order clause'", - "warning": "Column 'textcol2' in order by statement is ambiguous" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'textcol1' in order by statement is ambiguous\"", + "code:1052 message:\"Column 'textcol2' in order by statement is ambiguous\"" + ] }, { "comment": "ORDER BY column offset", @@ -519,7 +539,9 @@ "user.user" ] }, - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "ORDER BY NULL for join", @@ -1161,7 +1183,9 @@ "user.user" ] }, - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "LIMIT", @@ -1451,7 +1475,9 @@ "user.music" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "column alias for a table column in order by", @@ -1476,7 +1502,9 @@ "user.music" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "ordering on the left side of the join", @@ -1520,7 +1548,9 @@ "user.user" ] }, - "warning": "Column '`name`' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column '`name`' in order by statement is ambiguous\"" + ] }, { "comment": "aggregation and non-aggregations column without group by", @@ -1701,7 +1731,9 @@ "user.user" ] }, - "warning": "Column '`name`' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column '`name`' in order by statement is ambiguous\"" + ] }, { "comment": "order by with ambiguous column reference ; valid in MySQL", @@ -1726,7 +1758,9 @@ "user.user" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "Scatter order by and aggregation: order by column must reference column from select list", @@ -1766,7 +1800,9 @@ "user.user" ] }, - "warning": "Column 'col' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"" + ] }, { "comment": "Distinct with cross shard query", @@ -1963,7 +1999,9 @@ "user.user" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "Order by column number with collate", @@ -2012,7 +2050,9 @@ "user.user" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "Order by column number with collate", @@ -2181,7 +2221,9 @@ "user.user" ] }, - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "distinct with order by having additional non-order by columns in the selection using aggregation engine", @@ -2213,7 +2255,9 @@ "user.user" ] }, - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "distinct with order by having no overalap with the selection columns - using distinct engine", diff --git a/go/vt/vtgate/planbuilder/testdata/select_cases.json b/go/vt/vtgate/planbuilder/testdata/select_cases.json index 4b2f1ad21f2..a20765c2df2 100644 --- a/go/vt/vtgate/planbuilder/testdata/select_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/select_cases.json @@ -819,7 +819,10 @@ "user.user_extra" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "Jumbled references", @@ -1173,7 +1176,9 @@ "user.music" ] }, - "warning": "Column 'user_id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'user_id' in order by statement is ambiguous\"" + ] }, { "comment": "sharded limit offset with arguments", @@ -1205,7 +1210,9 @@ "user.music" ] }, - "warning": "Column 'user_id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'user_id' in order by statement is ambiguous\"" + ] }, { "comment": "Sharding Key Condition in Parenthesis", @@ -1336,7 +1343,9 @@ "user.user" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "Booleans and parenthesis", @@ -2189,19 +2198,28 @@ "user.music" ] }, - "warning": "Column 'user_id' in having clause is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'user_id' in group statement is ambiguous\"", + "code:1052 message:\"Column 'user_id' in having clause is ambiguous\"" + ] }, { "comment": "sql_calc_found_rows in sub queries", "query": "select * from music where user_id IN (select sql_calc_found_rows * from music limit 10)", "plan": "Incorrect usage/placement of 'SQL_CALC_FOUND_ROWS'", - "warning": "Column 'user_id' in having clause is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'user_id' in group statement is ambiguous\"", + "code:1052 message:\"Column 'user_id' in having clause is ambiguous\"" + ] }, { "comment": "sql_calc_found_rows in derived table", "query": "select sql_calc_found_rows * from (select sql_calc_found_rows * from music limit 10) t limit 1", "plan": "Incorrect usage/placement of 'SQL_CALC_FOUND_ROWS'", - "warning": "Column 'user_id' in having clause is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'user_id' in group statement is ambiguous\"", + "code:1052 message:\"Column 'user_id' in having clause is ambiguous\"" + ] }, { "comment": "select from unsharded keyspace into dumpfile", @@ -3069,7 +3087,9 @@ "user.user_extra" ] }, - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "correlated subquery having dependencies on two tables", @@ -3526,7 +3546,9 @@ "user.user_extra" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "yeah, it does not make sense, but it's valid", @@ -5078,7 +5100,11 @@ "user.user_extra" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'req' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'id' in group statement is ambiguous\"" + ] }, { "comment": "SELECT music.id FROM (SELECT MAX(id) as maxt FROM music WHERE music.user_id = 5) other JOIN music ON other.maxt = music.id", diff --git a/go/vt/vtgate/planbuilder/testdata/set_cases.json b/go/vt/vtgate/planbuilder/testdata/set_cases.json index 5b85562f373..18b64ab89e7 100644 --- a/go/vt/vtgate/planbuilder/testdata/set_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/set_cases.json @@ -583,7 +583,9 @@ ] } }, - "warning": "converted 'next transaction' scope to 'session' scope" + "warnings": [ + "code:1246 message:\"converted 'next transaction' scope to 'session' scope\"" + ] }, { "comment": "set vitess_metadata", @@ -606,6 +608,8 @@ ] } }, - "warning": "converted 'next transaction' scope to 'session' scope" + "warnings": [ + "code:1246 message:\"converted 'next transaction' scope to 'session' scope\"" + ] } ] diff --git a/go/vt/vtgate/planbuilder/testdata/tpcc_cases.json b/go/vt/vtgate/planbuilder/testdata/tpcc_cases.json index a9e7597d950..c7ab8af918a 100644 --- a/go/vt/vtgate/planbuilder/testdata/tpcc_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/tpcc_cases.json @@ -567,7 +567,9 @@ "main.customer1" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "TPC-C select unique customer1", @@ -620,7 +622,9 @@ "main.orders1" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "TPC-C select order_line1", @@ -673,7 +677,9 @@ "main.new_orders1" ] }, - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "TPC-C delete new_orders1", @@ -961,7 +967,12 @@ "main.orders1" ] }, - "warning": "Column 'o_w_id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'o_c_id' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'o_d_id' in group statement is ambiguous\"", + "code:1052 message:\"Column 'o_w_id' in group statement is ambiguous\"" + ] }, { "comment": "TPC-C delete order_line1", diff --git a/go/vt/vtgate/planbuilder/testdata/tpch_cases.json b/go/vt/vtgate/planbuilder/testdata/tpch_cases.json index f402c74bdbf..d180ac70c82 100644 --- a/go/vt/vtgate/planbuilder/testdata/tpch_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/tpch_cases.json @@ -46,13 +46,23 @@ "main.lineitem" ] }, - "warning": "Column 'l_linestatus' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'l_returnflag' in group statement is ambiguous\"", + "code:1052 message:\"Column 'l_linestatus' in group statement is ambiguous\"", + "code:1052 message:\"Column 'l_returnflag' in order by statement is ambiguous\"", + "code:1052 message:\"Column 'l_linestatus' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 2", "query": "select s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment from part, supplier, partsupp, nation, region where p_partkey = ps_partkey and s_suppkey = ps_suppkey and p_size = 15 and p_type like '%BRASS' and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'EUROPE' and ps_supplycost = ( select min(ps_supplycost) from partsupp, supplier, nation, region where p_partkey = ps_partkey and s_suppkey = ps_suppkey and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'EUROPE' ) order by s_acctbal desc, n_name, s_name, p_partkey limit 10", "plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS", - "warning": "Column 'p_partkey' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 's_acctbal' in order by statement is ambiguous\"", + "code:1052 message:\"Column 'n_name' in order by statement is ambiguous\"", + "code:1052 message:\"Column 's_name' in order by statement is ambiguous\"", + "code:1052 message:\"Column 'p_partkey' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 3", @@ -184,7 +194,12 @@ "main.orders" ] }, - "warning": "Column 'o_orderdate' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'l_orderkey' in group statement is ambiguous\"", + "code:1052 message:\"Column 'o_orderdate' in group statement is ambiguous\"", + "code:1052 message:\"Column 'o_shippriority' in group statement is ambiguous\"", + "code:1052 message:\"Column 'o_orderdate' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 4", @@ -784,7 +799,14 @@ "main.supplier" ] }, - "warning": "Column 'l_year' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'supp_nation' in group statement is ambiguous\"", + "code:1052 message:\"Column 'cust_nation' in group statement is ambiguous\"", + "code:1052 message:\"Column 'l_year' in group statement is ambiguous\"", + "code:1052 message:\"Column 'supp_nation' in order by statement is ambiguous\"", + "code:1052 message:\"Column 'cust_nation' in order by statement is ambiguous\"", + "code:1052 message:\"Column 'l_year' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 8", @@ -1069,7 +1091,10 @@ "main.supplier" ] }, - "warning": "Column 'o_year' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'o_year' in group statement is ambiguous\"", + "code:1052 message:\"Column 'o_year' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 9", @@ -1772,7 +1797,9 @@ "main.supplier" ] }, - "warning": "Column 'ps_partkey' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'ps_partkey' in group statement is ambiguous\"" + ] }, { "comment": "TPC-H query 12", @@ -1969,7 +1996,11 @@ "main.orders" ] }, - "warning": "Column 'c_count' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'c_custkey' in group statement is ambiguous\"", + "code:1052 message:\"Column 'c_count' in group statement is ambiguous\"", + "code:1052 message:\"Column 'c_count' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 14", @@ -2100,7 +2131,9 @@ "main.supplier" ] }, - "warning": "Column 's_suppkey' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 's_suppkey' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 16", @@ -2198,7 +2231,14 @@ "main.supplier" ] }, - "warning": "Column 'p_size' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'p_brand' in group statement is ambiguous\"", + "code:1052 message:\"Column 'p_type' in group statement is ambiguous\"", + "code:1052 message:\"Column 'p_size' in group statement is ambiguous\"", + "code:1052 message:\"Column 'p_brand' in order by statement is ambiguous\"", + "code:1052 message:\"Column 'p_type' in order by statement is ambiguous\"", + "code:1052 message:\"Column 'p_size' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 17", @@ -2367,7 +2407,16 @@ "main.orders" ] }, - "warning": "Column 'o_orderdate' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'l_orderkey' in group statement is ambiguous\"", + "code:1052 message:\"Column 'c_name' in group statement is ambiguous\"", + "code:1052 message:\"Column 'c_custkey' in group statement is ambiguous\"", + "code:1052 message:\"Column 'o_orderkey' in group statement is ambiguous\"", + "code:1052 message:\"Column 'o_orderdate' in group statement is ambiguous\"", + "code:1052 message:\"Column 'o_totalprice' in group statement is ambiguous\"", + "code:1052 message:\"Column 'o_totalprice' in order by statement is ambiguous\"", + "code:1052 message:\"Column 'o_orderdate' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 19", @@ -2436,7 +2485,9 @@ "comment": "TPC-H query 20", "query": "select s_name, s_address from supplier, nation where s_suppkey in ( select ps_suppkey from partsupp where ps_partkey in ( select p_partkey from part where p_name like 'forest%' ) and ps_availqty > ( select 0.5 * sum(l_quantity) from lineitem where l_partkey = ps_partkey and l_suppkey = ps_suppkey and l_shipdate >= date('1994-01-01') and l_shipdate < date('1994-01-01') + interval '1' year ) ) and s_nationkey = n_nationkey and n_name = 'CANADA' order by s_name", "plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS", - "warning": "Column 's_name' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 's_name' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 21", @@ -2599,12 +2650,18 @@ "main.supplier" ] }, - "warning": "Column 's_name' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 's_name' in group statement is ambiguous\"", + "code:1052 message:\"Column 's_name' in order by statement is ambiguous\"" + ] }, { "comment": "TPC-H query 22", "query": "select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal from ( select substring(c_phone from 1 for 2) as cntrycode, c_acctbal from customer where substring(c_phone from 1 for 2) in ('13', '31', '23', '29', '30', '18', '17') and c_acctbal > ( select avg(c_acctbal) from customer where c_acctbal > 0.00 and substring(c_phone from 1 for 2) in ('13', '31', '23', '29', '30', '18', '17') ) and not exists ( select * from orders where o_custkey = c_custkey ) ) as custsale group by cntrycode order by cntrycode", "plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS", - "warning": "Column 'cntrycode' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'cntrycode' in group statement is ambiguous\"", + "code:1052 message:\"Column 'cntrycode' in order by statement is ambiguous\"" + ] } ] diff --git a/go/vt/vtgate/planbuilder/testdata/union_cases.json b/go/vt/vtgate/planbuilder/testdata/union_cases.json index 11ef8d9d186..f68b0764444 100644 --- a/go/vt/vtgate/planbuilder/testdata/union_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/union_cases.json @@ -161,7 +161,9 @@ "user.user" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "Union all", @@ -293,7 +295,9 @@ "user.user" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "union all on scatter and single route", @@ -1055,31 +1059,41 @@ "user.user" ] }, - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "ambiguous LIMIT", "query": "select id from user limit 1 union all select id from music limit 1", "plan": "syntax error at position 34 near 'union'", - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "ambiguous ORDER BY", "query": "select id from user order by id union all select id from music order by id desc", "plan": "syntax error at position 38 near 'union'", - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "different number of columns", "query": "select id, 42 from user where id = 1 union all select id from user where id = 5", "plan": "The used SELECT statements have a different number of columns: 2, 1", - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "union with invalid order by clause with table qualifier", "query": "select id from user union select 3 order by user.id", "plan": "Table `user` from one of the SELECTs cannot be used in global ORDER clause", - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "union with invalid order by clause with table qualifier", diff --git a/go/vt/vtgate/planbuilder/testdata/unknown_schema_cases.json b/go/vt/vtgate/planbuilder/testdata/unknown_schema_cases.json index 73a0e7357cc..a2ff3d67294 100644 --- a/go/vt/vtgate/planbuilder/testdata/unknown_schema_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/unknown_schema_cases.json @@ -38,7 +38,9 @@ "comment": "ORDER BY on select *", "query": "select *, col from user order by col", "plan": "VT09015: schema tracking required", - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "ORDER BY on select multi t.*", @@ -49,19 +51,25 @@ "comment": "ORDER BY on select multi *", "query": "select *, name, *, col from user order by col", "plan": "VT09015: schema tracking required", - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "Group by column number, used with non-aliased expression (duplicated code)", "query": "select * from user group by 1", "plan": "cannot use column offsets in group clause when using `*`", - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "create view with Cannot auto-resolve for cross-shard joins", "query": "create view user.view_a as select col from user join user_extra", "plan": "Column 'col' in field list is ambiguous", - "warning": "Column 'col' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'col' in order by statement is ambiguous\"" + ] }, { "comment": "unsharded insert, unqualified names and auto-inc combined", diff --git a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json index e769d016f8b..6da6827a6ab 100644 --- a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json @@ -18,13 +18,18 @@ "comment": "subqueries not supported in group by", "query": "select id from user group by id, (select id from user_extra)", "plan": "VT12001: unsupported: subqueries in GROUP BY", - "warning": "Column 'id' in group statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in group statement is ambiguous\"" + ] }, { "comment": "user defined functions used in having clause that needs evaluation on vtgate", "query": "select col1, udf_aggr( col2 ) r from user group by col1 having r >= 0.3", "plan": "VT12001: unsupported: Aggregate UDF 'udf_aggr(col2)' must be pushed down to MySQL", - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col1' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "update changes primary vindex column", @@ -35,7 +40,10 @@ "comment": "subquery with an aggregation in order by that cannot be merged into a single route", "query": "select col, trim((select user_name from user where col = 'a')) val from user_extra where user_id = 3 group by col order by val", "plan": "VT12001: unsupported: subquery with aggregation in order by", - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'col' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"" + ] }, { "comment": "update change in multicol vindex column", @@ -161,7 +169,9 @@ "comment": "create view with sharded limit", "query": "create view user.view_a as select id from user order by id limit 10", "plan": "VT12001: unsupported: Complex select queries are not supported in create or alter view statements", - "warning": "Column 'id' in order by statement is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'id' in order by statement is ambiguous\"" + ] }, { "comment": "create view with top level subquery in select", @@ -177,7 +187,10 @@ "comment": "create view with sql_calc_found_rows with group by and having", "query": "create view user.view_a as select sql_calc_found_rows user_id, count(id) from music group by user_id having count(user_id) = 1 order by user_id limit 2", "plan": "VT12001: unsupported: Complex select queries are not supported in create or alter view statements", - "warning": "Column 'user_id' in having clause is ambiguous" + "warnings": [ + "code:1052 message:\"Column 'user_id' in group statement is ambiguous\"", + "code:1052 message:\"Column 'user_id' in having clause is ambiguous\"" + ] }, { "comment": "create view with incompatible keyspaces", @@ -373,7 +386,12 @@ "comment": "WITH ROLLUP not supported on sharded queries", "query": "select a, b, c, sum(d) from user group by a, b, c with rollup", "plan": "VT12001: unsupported: GROUP BY WITH ROLLUP not supported for sharded queries", - "warning": "Missing table info, so not binding to anything on the FROM clause" + "warnings": [ + "code:1052 message:\"Column 'a' in group statement is ambiguous\"", + "code:1235 message:\"Missing table info, so not binding to anything on the FROM clause\"", + "code:1052 message:\"Column 'b' in group statement is ambiguous\"", + "code:1052 message:\"Column 'c' in group statement is ambiguous\"" + ] }, { "comment": "SOME/ANY/ALL comparison operator not supported for unsharded queries", diff --git a/go/vt/vtgate/semantics/early_rewriter.go b/go/vt/vtgate/semantics/early_rewriter.go index c1687510f54..e98b8f76842 100644 --- a/go/vt/vtgate/semantics/early_rewriter.go +++ b/go/vt/vtgate/semantics/early_rewriter.go @@ -18,6 +18,7 @@ package semantics import ( "fmt" + "slices" "strconv" "vitess.io/vitess/go/mysql/sqlerror" @@ -453,6 +454,13 @@ func (r *earlyRewriter) handleGroupBy(parent sqlparser.SQLNode, iter iterator) e } func (r *earlyRewriter) addWarning(message string, code sqlerror.ErrorCode) { + idx := slices.IndexFunc(r.warnings, func(q *querypb.QueryWarning) bool { + return q.Message == message && q.Code == uint32(code) + }) + if idx != -1 { + // warning already exists + return + } r.warnings = append(r.warnings, &querypb.QueryWarning{ Message: message, Code: uint32(code), diff --git a/go/vt/vtgate/vcursor_impl.go b/go/vt/vtgate/vcursor_impl.go index e9b1d3d7712..8f8222c5c8e 100644 --- a/go/vt/vtgate/vcursor_impl.go +++ b/go/vt/vtgate/vcursor_impl.go @@ -1148,14 +1148,8 @@ func (vc *vcursorImpl) WarnUnshardedOnly(format string, params ...any) { } // PlannerWarning implements the VCursor interface -func (vc *vcursorImpl) PlannerWarning(message string) { - if message == "" { - return - } - vc.warnings = append(vc.warnings, &querypb.QueryWarning{ - Code: uint32(sqlerror.ERNotSupportedYet), - Message: message, - }) +func (vc *vcursorImpl) PlannerWarnings(warnings ...*querypb.QueryWarning) { + vc.warnings = append(vc.warnings, warnings...) } // ForeignKeyMode implements the VCursor interface