Skip to content

Commit bb67a3b

Browse files
committed
fix null select yielding incorrect results
1 parent 03b6054 commit bb67a3b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

enginetest/queries/script_queries.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,60 @@ type ScriptTestAssertion struct {
121121
// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
122122
// the tests.
123123
var ScriptTests = []ScriptTest{
124+
{
125+
// https://github.com/dolthub/go-mysql-server/issues/3216
126+
Name: "UNION ALL with BLOB columns",
127+
SetUpScript: []string{
128+
"CREATE TABLE a(name VARCHAR(255), data BLOB)",
129+
"CREATE TABLE b(name VARCHAR(255), data BLOB)",
130+
"INSERT INTO a VALUES ('a-data', UNHEX('deadbeef'))",
131+
"INSERT INTO b VALUES ('b-nodata', NULL)",
132+
},
133+
Assertions: []ScriptTestAssertion{
134+
{
135+
Query: "SELECT name, data FROM a UNION ALL SELECT name, data FROM b",
136+
Expected: []sql.Row{
137+
{"a-data", []byte{0xde, 0xad, 0xbe, 0xef}},
138+
{"b-nodata", nil},
139+
},
140+
},
141+
{
142+
Query: "SELECT name, HEX(data) as data_hex FROM a UNION ALL SELECT name, HEX(data) as data_hex FROM b",
143+
Expected: []sql.Row{
144+
{"a-data", "DEADBEEF"},
145+
{"b-nodata", nil},
146+
},
147+
},
148+
{
149+
Query: "SELECT name, data FROM a UNION ALL SELECT name, NULL FROM b",
150+
Expected: []sql.Row{
151+
{"a-data", []byte{0xde, 0xad, 0xbe, 0xef}},
152+
{"b-nodata", nil},
153+
},
154+
},
155+
{
156+
Query: "SELECT name, HEX(data) as data_hex FROM a UNION ALL SELECT name, HEX(NULL) as data_hex FROM b",
157+
Expected: []sql.Row{
158+
{"a-data", "DEADBEEF"},
159+
{"b-nodata", nil},
160+
},
161+
},
162+
{
163+
Query: "SELECT name, data FROM a UNION ALL SELECT name, UNHEX('') FROM b",
164+
Expected: []sql.Row{
165+
{"a-data", []byte{0xde, 0xad, 0xbe, 0xef}},
166+
{"b-nodata", []byte{}},
167+
},
168+
},
169+
{
170+
Query: "SELECT name, HEX(data) as data_hex FROM a UNION ALL SELECT name, HEX(UNHEX('')) as data_hex FROM b",
171+
Expected: []sql.Row{
172+
{"a-data", "DEADBEEF"},
173+
{"b-nodata", ""},
174+
},
175+
},
176+
},
177+
},
124178
{
125179
// https://github.com/dolthub/dolt/issues/9836
126180
Skip: true,

sql/expression/convert.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func GetConvertToType(l, r sql.Type) string {
120120
}
121121

122122
if !types.IsNumber(l) || !types.IsNumber(r) {
123+
// Special handling for BLOB types - preserve binary data
124+
if types.IsBlobType(l) || types.IsBlobType(r) {
125+
return ConvertToBinary
126+
}
123127
return ConvertToChar
124128
}
125129

0 commit comments

Comments
 (0)