Skip to content

Commit 71a0ece

Browse files
[release-17.0] Fix vtexplain not handling UNION queries with weight_string results correctly. (vitessio#16129) (vitessio#16155)
Signed-off-by: Arthur Schreiber <arthurschreiber@github.com> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com> Co-authored-by: Arthur Schreiber <arthurschreiber@github.com>
1 parent ce02a1e commit 71a0ece

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

go/vt/vtexplain/testdata/multi-output/selectsharded-output.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,9 @@ SELECT id FROM orders WHERE id IN (1, "1", 1)
207207
2 ks_sharded/40-80: select id from orders where id in (1, '1', 1) limit 10001
208208

209209
----------------------------------------------------------------------
210+
(SELECT user.id, user.name FROM user WHERE user.id = 1) UNION (SELECT user.id, user.name FROM user WHERE user.id = 2)
211+
212+
2 ks_sharded/-40: select distinct `user`.id, `user`.`name`, weight_string(`user`.id), weight_string(`user`.`name`) from `user` where `user`.id = 2 limit 10001 /* INT64 */
213+
2 ks_sharded/-40: select distinct `user`.id, `user`.`name`, weight_string(`user`.id), weight_string(`user`.`name`) from `user` where `user`.id = 1 limit 10001 /* INT64 */
214+
215+
----------------------------------------------------------------------

go/vt/vtexplain/testdata/selectsharded-queries.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ select id from user where not id in (select col from music where music.user_id =
3838

3939
SELECT user.id, user.name, name_info.info FROM user INNER JOIN music ON (user.id = music.user_id) LEFT OUTER JOIN name_info ON (user.name = name_info.name);
4040

41-
SELECT id FROM orders WHERE id IN (1, "1", 1)
41+
SELECT id FROM orders WHERE id IN (1, "1", 1);
42+
43+
(SELECT user.id, user.name FROM user WHERE user.id = 1) UNION (SELECT user.id, user.name FROM user WHERE user.id = 2);

go/vt/vtexplain/vtexplain_vttablet.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,15 @@ func inferColTypeFromExpr(node sqlparser.Expr, tableColumnMap map[sqlparser.Iden
842842
colTypes = append(colTypes, colType)
843843
}
844844
case sqlparser.Callable:
845-
// As a shortcut, functions are integral types
846-
colNames = append(colNames, sqlparser.String(node))
847-
colTypes = append(colTypes, querypb.Type_INT32)
845+
switch node := node.(type) {
846+
case *sqlparser.WeightStringFuncExpr:
847+
colNames = append(colNames, sqlparser.String(node))
848+
colTypes = append(colTypes, querypb.Type_BINARY)
849+
default:
850+
// As a shortcut, functions are integral types
851+
colNames = append(colNames, sqlparser.String(node))
852+
colTypes = append(colTypes, querypb.Type_INT32)
853+
}
848854
case *sqlparser.Literal:
849855
colNames = append(colNames, sqlparser.String(node))
850856
switch node.Type {

0 commit comments

Comments
 (0)