Skip to content

Commit

Permalink
bugfix: don't panic when missing schema information (#14787)
Browse files Browse the repository at this point in the history
  • Loading branch information
systay authored Dec 15, 2023
1 parent c2ff09f commit 7c9fec7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
25 changes: 24 additions & 1 deletion go/vt/vtgate/planbuilder/testdata/from_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4256,5 +4256,28 @@
"user.user",
"user.user_extra"
]
} }
}
},
{
"comment": "unexpanded columns are fine if we can push down into single route",
"query": "select x from (select t.*, 1 as x from unsharded t union select t.*, 1 as x from unsharded t) as x",
"plan": {
"QueryType": "SELECT",
"Original": "select x from (select t.*, 1 as x from unsharded t union select t.*, 1 as x from unsharded t) as x",
"Instructions": {
"OperatorType": "Route",
"Variant": "Unsharded",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"FieldQuery": "select x from (select t.*, 1 as x from unsharded as t where 1 != 1 union select t.*, 1 as x from unsharded as t where 1 != 1) as x where 1 != 1",
"Query": "select x from (select t.*, 1 as x from unsharded as t union select t.*, 1 as x from unsharded as t) as x",
"Table": "unsharded"
},
"TablesUsed": [
"main.unsharded"
]
}
}
]
5 changes: 5 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/unsupported_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,10 @@
"comment": "correlated subqueries in select expressions are unsupported",
"query": "SELECT (SELECT sum(user.name) FROM music LIMIT 1) FROM user",
"plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS"
},
{
"comment": "We need schema tracking to allow unexpanded columns inside UNION",
"query": "select x from (select t.*, 0 as x from user t union select t.*, 1 as x from user_extra t) AS t",
"plan": "VT09015: schema tracking required"
}
]
4 changes: 4 additions & 0 deletions go/vt/vtgate/semantics/derived_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func (dt *DerivedTable) dependencies(colName string, org originable) (dependenci
if !strings.EqualFold(name, colName) {
continue
}
if len(dt.recursive) == 0 {
// we have unexpanded columns and can't figure this out
return nil, ShardedError{Inner: vterrors.VT09015()}
}
recursiveDeps, qt := dt.recursive[i], dt.types[i]

return createCertain(directDeps, recursiveDeps, qt), nil
Expand Down

0 comments on commit 7c9fec7

Please sign in to comment.