Commit cc424a6
Fix for infinite recursion for CAST Convert to String to fail And DATETRUNC to fail during DnR (#4854)
sys._trunc_numeric_to_int4 / _int8 and _int2 variants causes infinite recursion and stack overflow when called during dump/restore for tables with CAST(DECIMAL AS INT).
The error Repro - #4851 , #4857
During dump/restore, babelfishpg_tsql.dump_restore is set to on, which activates the find_coercion_pathway_hook. This hook overrides PostgreSQL's standard cast resolution for numeric to
integer types, routing them through the Babelfish truncation functions (sys._trunc_numeric_to_int* ). These functions internally use CAST(trunc(arg) AS INT*), which triggers the same hook again leadind to infinite recursion.
For the datetrunc it fails because the sys schema isn't in search_path during DnR. The type datetime lives in sys schema without sys in the path, PG can't find it.
So changed datetime -> sys.datetime and similar for other
For the Issue with CONVERT-
The reasons-
substring(text, pattern) → picks substring(text, int) instead of (text, text) → tries to parse the regex as int.
regexp_replace-> picks (text,text,text,int) over (text,text,text,text) → tries to parse 'gi' as int.
col IN (CHAR,VARCHAR) → the IN-list array's common type is resolved to float8 instead of text
A better fix for these similar issues would be a C level fix in find_coercion_pathway . But this fix unblocks the problem with - #4826 (which crashes for table with datetrunc and CAST in computed column)'
Issues Resolved
BABEL-6813 and BABEL-6815
---------
Co-authored-by: Ayush-061 <ayushhx@amazon.com>1 parent 2fa7f2e commit cc424a6
12 files changed
Lines changed: 1546 additions & 26 deletions
File tree
- contrib
- babelfishpg_common/sql
- upgrades
- babelfishpg_tsql/sql
- upgrades
- test/JDBC
- expected
- input
- upgrade/latest
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
308 | | - | |
| 308 | + | |
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
| 337 | + | |
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
341 | | - | |
| 341 | + | |
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | | - | |
| 378 | + | |
379 | 379 | | |
380 | | - | |
| 380 | + | |
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
| |||
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
498 | | - | |
| 498 | + | |
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
| |||
2240 | 2240 | | |
2241 | 2241 | | |
2242 | 2242 | | |
2243 | | - | |
| 2243 | + | |
2244 | 2244 | | |
2245 | 2245 | | |
2246 | 2246 | | |
| |||
2254 | 2254 | | |
2255 | 2255 | | |
2256 | 2256 | | |
2257 | | - | |
| 2257 | + | |
2258 | 2258 | | |
2259 | 2259 | | |
2260 | 2260 | | |
2261 | | - | |
| 2261 | + | |
2262 | 2262 | | |
2263 | 2263 | | |
2264 | 2264 | | |
| |||
2342 | 2342 | | |
2343 | 2343 | | |
2344 | 2344 | | |
2345 | | - | |
| 2345 | + | |
2346 | 2346 | | |
2347 | 2347 | | |
2348 | 2348 | | |
| |||
2573 | 2573 | | |
2574 | 2574 | | |
2575 | 2575 | | |
2576 | | - | |
| 2576 | + | |
2577 | 2577 | | |
2578 | 2578 | | |
2579 | | - | |
| 2579 | + | |
2580 | 2580 | | |
2581 | 2581 | | |
2582 | 2582 | | |
| |||
2594 | 2594 | | |
2595 | 2595 | | |
2596 | 2596 | | |
2597 | | - | |
| 2597 | + | |
2598 | 2598 | | |
2599 | 2599 | | |
2600 | 2600 | | |
| |||
2611 | 2611 | | |
2612 | 2612 | | |
2613 | 2613 | | |
2614 | | - | |
| 2614 | + | |
2615 | 2615 | | |
2616 | 2616 | | |
2617 | 2617 | | |
| |||
10984 | 10984 | | |
10985 | 10985 | | |
10986 | 10986 | | |
10987 | | - | |
| 10987 | + | |
10988 | 10988 | | |
10989 | 10989 | | |
10990 | 10990 | | |
| |||
11059 | 11059 | | |
11060 | 11060 | | |
11061 | 11061 | | |
11062 | | - | |
| 11062 | + | |
11063 | 11063 | | |
11064 | 11064 | | |
11065 | 11065 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5120 | 5120 | | |
5121 | 5121 | | |
5122 | 5122 | | |
5123 | | - | |
| 5123 | + | |
5124 | 5124 | | |
5125 | | - | |
| 5125 | + | |
5126 | 5126 | | |
5127 | 5127 | | |
5128 | 5128 | | |
5129 | 5129 | | |
5130 | 5130 | | |
5131 | 5131 | | |
5132 | 5132 | | |
5133 | | - | |
| 5133 | + | |
5134 | 5134 | | |
5135 | 5135 | | |
5136 | 5136 | | |
| |||
0 commit comments