Commit b716774
authored
fix: panic when JOIN condition type conversion fails (#23191)
### **User description**
## What type of PR is this?
- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring
## Which issue(s) this PR fixes:
issue matrixorigin/MO-Cloud#6733
## What this PR does / why we need it:
When a JOIN operation encounters a type mismatch (e.g., INT = VARCHAR),
the type conversion fails during evalJoinCondition(), leaving
HashmapBuilder.vecs in a partially initialized state. When Reset() is
called during cleanup, it attempts to free nil pointers, causing a
panic.
___
### **PR Type**
Bug fix, Tests
___
### **Description**
- Add nil pointer checks in `Reset()` and `Free()` methods to prevent
panics
- Introduce `cleanupPartiallyCreatedVecs()` helper to handle partial
initialization failures
- Call cleanup on errors in `evalJoinCondition()` to prevent memory
leaks
- Add comprehensive regression tests for nil pointer handling in
Reset/Free
- Add BVT test case for LEFT JOIN with type mismatch error handling
___
### Diagram Walkthrough
```mermaid
flowchart LR
A["evalJoinCondition<br/>encounters error"] -->|calls| B["cleanupPartiallyCreatedVecs"]
B -->|frees partial vecs| C["hb.vecs = nil"]
C -->|prevents nil deref| D["Reset/Free safe"]
E["Reset/Free methods"] -->|check nil| F["vecs[i] != nil"]
F -->|check nil| G["vecs[i][j] != nil"]
G -->|safe free| H["No panic"]
```
<details> <summary><h3> File Walkthrough</h3></summary>
<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Bug
fix</strong></td><td><table>
<tr>
<td>
<details>
<summary><strong>hashmap_util.go</strong><dd><code>Add nil pointer
safety checks and cleanup helper</code>
</dd></summary>
<hr>
pkg/sql/colexec/hashmap_util/hashmap_util.go
<ul><li>Add nil pointer checks in <code>Reset()</code> method for
<code>hb.vecs</code> and <br><code>hb.UniqueJoinKeys</code> arrays<br>
<li> Add nil pointer checks in <code>Free()</code> method for
<code>hb.UniqueJoinKeys</code> array<br> <li> Introduce new
<code>cleanupPartiallyCreatedVecs()</code> helper function to safely
<br>free partially initialized vectors<br> <li> Call
<code>cleanupPartiallyCreatedVecs()</code> in
<code>evalJoinCondition()</code> when errors <br>occur during vector
evaluation or duplication</ul>
</details>
</td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23191/files#diff-4e472814399bbb0cac40fbad6d42daabca4111e950bebe1a2f5c4dbf8560bd74">+32/-4</a>
</td>
</tr>
</table></td></tr><tr><td><strong>Tests</strong></td><td><table>
<tr>
<td>
<details>
<summary><strong>hashmap_util_test.go</strong><dd><code>Add
comprehensive nil pointer regression tests</code>
</dd></summary>
<hr>
pkg/sql/colexec/hashmap_util/hashmap_util_test.go
<ul><li>Add import for <code>vector</code> package<br> <li> Add
<code>TestResetWithNilPointers()</code> regression test for nil pointer
<br>handling in Reset with needDupVec=true<br> <li> Add
<code>TestResetWithMixedNilAndValidPointers()</code> test for mixed nil
and <br>valid vectors in Reset<br> <li> Add
<code>TestFreeWithNilPointers()</code> regression test for nil pointer
handling <br>in Free<br> <li> Add
<code>TestFreeWithMixedNilAndValidPointers()</code> test for mixed nil
and <br>valid vectors in Free</ul>
</details>
</td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23191/files#diff-dc62011f0bc0fcb2eb8d9fe366c82ba5265a34cb8efc810e5a21b450763e1320">+95/-0</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>join.test</strong><dd><code>Add BVT test for LEFT JOIN
type mismatch</code>
</dd></summary>
<hr>
test/distributed/cases/join/join.test
<ul><li>Add BVT test case for LEFT JOIN with type mismatch (INT =
VARCHAR)<br> <li> Test that type conversion error is returned instead of
causing panic<br> <li> Include table creation, data insertion, and error
validation</ul>
</details>
</td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23191/files#diff-c786ef775fdeba111970aafa87ec9dc5c1086e298fc7cd6f3ae01896a2586b8b">+13/-0</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>join.result</strong><dd><code>Update test results with
type mismatch error</code>
</dd></summary>
<hr>
test/distributed/cases/join/join.result
<ul><li>Update expected output for existing JOIN test (whitespace
formatting)<br> <li> Add expected error output for LEFT JOIN with type
mismatch test case<br> <li> Include test cleanup statements for new test
case</ul>
</details>
</td>
<td><a
href="https://github.com/matrixorigin/matrixone/pull/23191/files#diff-b989d5ea2130cdea874fcd458a930f745012401c8d4456f58ab1a51601e2106d">+11/-1</a>
</td>
</tr>
</table></td></tr></tr></tbody></table>
</details>
___1 parent 182f5b9 commit b716774
File tree
4 files changed
+151
-5
lines changed- pkg/sql/colexec/hashmap_util
- test/distributed/cases/join
4 files changed
+151
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
119 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
120 | 124 | | |
121 | 125 | | |
122 | 126 | | |
| |||
126 | 130 | | |
127 | 131 | | |
128 | 132 | | |
129 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
130 | 136 | | |
131 | 137 | | |
132 | 138 | | |
| |||
151 | 157 | | |
152 | 158 | | |
153 | 159 | | |
154 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
155 | 163 | | |
156 | 164 | | |
157 | 165 | | |
| |||
168 | 176 | | |
169 | 177 | | |
170 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
171 | 195 | | |
172 | 196 | | |
173 | 197 | | |
174 | 198 | | |
175 | 199 | | |
176 | 200 | | |
177 | 201 | | |
| 202 | + | |
| 203 | + | |
178 | 204 | | |
179 | 205 | | |
180 | 206 | | |
181 | 207 | | |
182 | 208 | | |
| 209 | + | |
| 210 | + | |
183 | 211 | | |
184 | 212 | | |
185 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
0 commit comments