- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit0da39aa
committed
Handle default NULL insertion a little better.
If a column is omitted in an INSERT, and there's no column default,the code in preptlist.c generates a NULL Const to be inserted.Furthermore, if the column is of a domain type, we wrap the Constin CoerceToDomain, so as to throw a run-time error if the domainhas a NOT NULL constraint. That's fine as far as it goes, butthere are two problems:1. We're being sloppy about the type/typmod that the Const islabeled with. It really should have the domain's base type/typmod,since it's the input to CoerceToDomain not the output. This canresult in coerce_to_domain inserting a useless length-coercionfunction (useless because it's being applied to a null). Thecoercion would typically get const-folded away later, but it'dbe better not to create it in the first place.2. We're not applying expression preprocessing (specifically,eval_const_expressions) to the resulting expression tree.The planner's primary expression-preprocessing pass already happened,so that means the length coercion step and CoerceToDomain node misspreprocessing altogether.This is at the least inefficient, since it means the length coercionand CoerceToDomain will actually be executed for each inserted row,though they could be const-folded away in most cases. Worse, itseems possible that missing preprocessing for the length coercioncould result in an invalid plan (for example, due to failing toperform default-function-argument insertion). I'm not aware ofany live bug of that sort with core datatypes, and it might beunreachable for extension types as well because of restrictions ofCREATE CAST, but I'm not entirely convinced that it's unreachable.Hence, it seems worth back-patching the fix (although I only wentback to v14, as the patch doesn't apply cleanly at all in v13).There are several places in the rewriter that are building nulldomain constants the same way as preptlist.c. While those arebefore the planner and hence don't have any reachable bug, they'restill applying a length coercion that will be const-folded awaylater, uselessly wasting cycles. Hence, make a utility routinethat all of these places can call to do it right.Making this code more careful about the typmod assigned to thegenerated NULL constant has visible but cosmetic effects on someof the plans shown in contrib/postgres_fdw's regression tests.Discussion:https://postgr.es/m/1865579.1738113656@sss.pgh.pa.usBackpatch-through: 141 parent6cddecd commit0da39aa
File tree
6 files changed
+92
-78
lines changed- contrib/postgres_fdw/expected
- src
- backend
- optimizer/prep
- parser
- rewrite
- include/parser
6 files changed
+92
-78
lines changedLines changed: 12 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4273 | 4273 |
| |
4274 | 4274 |
| |
4275 | 4275 |
| |
4276 |
| - | |
4277 |
| - | |
| 4276 | + | |
| 4277 | + | |
4278 | 4278 |
| |
4279 | 4279 |
| |
4280 | 4280 |
| |
4281 | 4281 |
| |
4282 |
| - | |
| 4282 | + | |
4283 | 4283 |
| |
4284 | 4284 |
| |
4285 | 4285 |
| |
| |||
4307 | 4307 |
| |
4308 | 4308 |
| |
4309 | 4309 |
| |
4310 |
| - | |
4311 |
| - | |
| 4310 | + | |
| 4311 | + | |
4312 | 4312 |
| |
4313 | 4313 |
| |
4314 | 4314 |
| |
4315 | 4315 |
| |
4316 |
| - | |
| 4316 | + | |
4317 | 4317 |
| |
4318 | 4318 |
| |
4319 | 4319 |
| |
| |||
4961 | 4961 |
| |
4962 | 4962 |
| |
4963 | 4963 |
| |
4964 |
| - | |
4965 |
| - | |
| 4964 | + | |
| 4965 | + | |
4966 | 4966 |
| |
4967 | 4967 |
| |
4968 | 4968 |
| |
4969 | 4969 |
| |
4970 |
| - | |
| 4970 | + | |
4971 | 4971 |
| |
4972 | 4972 |
| |
4973 | 4973 |
| |
| |||
6125 | 6125 |
| |
6126 | 6126 |
| |
6127 | 6127 |
| |
6128 |
| - | |
6129 |
| - | |
| 6128 | + | |
| 6129 | + | |
6130 | 6130 |
| |
6131 | 6131 |
| |
6132 | 6132 |
| |
6133 | 6133 |
| |
6134 | 6134 |
| |
6135 |
| - | |
| 6135 | + | |
6136 | 6136 |
| |
6137 | 6137 |
| |
6138 | 6138 |
| |
|
Lines changed: 14 additions & 20 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
46 | 46 |
| |
47 | 47 |
| |
48 | 48 |
| |
49 |
| - | |
| 49 | + | |
| 50 | + | |
50 | 51 |
| |
51 | 52 |
| |
52 | 53 |
| |
| |||
102 | 103 |
| |
103 | 104 |
| |
104 | 105 |
| |
105 |
| - | |
| 106 | + | |
106 | 107 |
| |
107 | 108 |
| |
108 | 109 |
| |
| |||
148 | 149 |
| |
149 | 150 |
| |
150 | 151 |
| |
151 |
| - | |
| 152 | + | |
| 153 | + | |
152 | 154 |
| |
153 | 155 |
| |
154 | 156 |
| |
| |||
376 | 378 |
| |
377 | 379 |
| |
378 | 380 |
| |
379 |
| - | |
| 381 | + | |
380 | 382 |
| |
381 | 383 |
| |
382 | 384 |
| |
| |||
430 | 432 |
| |
431 | 433 |
| |
432 | 434 |
| |
433 |
| - | |
434 |
| - | |
435 | 435 |
| |
436 | 436 |
| |
437 | 437 |
| |
438 | 438 |
| |
439 |
| - | |
440 |
| - | |
441 |
| - | |
442 |
| - | |
443 |
| - | |
444 |
| - | |
445 |
| - | |
446 |
| - | |
447 |
| - | |
448 |
| - | |
449 |
| - | |
450 |
| - | |
451 |
| - | |
452 |
| - | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
453 | 447 |
| |
454 | 448 |
| |
455 | 449 |
| |
|
Lines changed: 37 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1263 | 1263 |
| |
1264 | 1264 |
| |
1265 | 1265 |
| |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
1266 | 1303 |
| |
1267 | 1304 |
| |
1268 | 1305 |
| |
|
Lines changed: 10 additions & 32 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1008 | 1008 |
| |
1009 | 1009 |
| |
1010 | 1010 |
| |
1011 |
| - | |
1012 |
| - | |
1013 |
| - | |
1014 |
| - | |
1015 |
| - | |
1016 |
| - | |
1017 |
| - | |
1018 |
| - | |
1019 |
| - | |
1020 |
| - | |
1021 |
| - | |
1022 |
| - | |
1023 |
| - | |
1024 |
| - | |
1025 |
| - | |
1026 |
| - | |
1027 |
| - | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
1028 | 1016 |
| |
1029 | 1017 |
| |
1030 | 1018 |
| |
| |||
1572 | 1560 |
| |
1573 | 1561 |
| |
1574 | 1562 |
| |
1575 |
| - | |
1576 |
| - | |
1577 |
| - | |
1578 |
| - | |
1579 |
| - | |
1580 |
| - | |
1581 |
| - | |
1582 |
| - | |
1583 |
| - | |
1584 |
| - | |
1585 |
| - | |
1586 |
| - | |
1587 |
| - | |
1588 |
| - | |
1589 |
| - | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
1590 | 1568 |
| |
1591 | 1569 |
| |
1592 | 1570 |
| |
|
Lines changed: 16 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
22 | 22 |
| |
23 | 23 |
| |
24 | 24 |
| |
| 25 | + | |
25 | 26 |
| |
26 | 27 |
| |
27 | 28 |
| |
| |||
1802 | 1803 |
| |
1803 | 1804 |
| |
1804 | 1805 |
| |
1805 |
| - | |
1806 |
| - | |
1807 |
| - | |
1808 |
| - | |
1809 |
| - | |
1810 |
| - | |
1811 |
| - | |
1812 |
| - | |
1813 |
| - | |
1814 |
| - | |
1815 |
| - | |
1816 |
| - | |
1817 |
| - | |
1818 |
| - | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
1819 | 1821 |
| |
1820 | 1822 |
| |
1821 | 1823 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
63 | 63 |
| |
64 | 64 |
| |
65 | 65 |
| |
| 66 | + | |
| 67 | + | |
| 68 | + | |
66 | 69 |
| |
67 | 70 |
| |
68 | 71 |
| |
|
0 commit comments
Comments
(0)