- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitc12d570
committed
Support arrays over domains.
Allowing arrays with a domain type as their element type was left un-donein the original domain patch, but not for any very good reason. Thisomission leads to such surprising results as array_agg() not working ona domain column, because the parser can't identify a suitable output typefor the polymorphic aggregate.In order to fix this, first clean up the APIs of coerce_to_domain() andsome internal functions in parse_coerce.c so that we consistently passaround a CoercionContext along with CoercionForm. Previously, we sometimespassed an "isExplicit" boolean flag instead, which is strictly lessinformation; and coerce_to_domain() didn't even get that, but instead hadto reverse-engineer isExplicit from CoercionForm. That's contrary to thedocumentation in primnodes.h that says that CoercionForm only affectsdisplay and not semantics. I don't think this change fixes any live bugs,but it makes things more consistent. The main reason for doing it thoughis that now build_coercion_expression() receives ccontext, which it needsin order to be able to recursively invoke coerce_to_target_type().Next, reimplement ArrayCoerceExpr so that the node does not directly knowany details of what has to be done to the individual array elements whileperforming the array coercion. Instead, the per-element processing isrepresented by a sub-expression whose input is a source array element andwhose output is a target array element. This simplifies life inparse_coerce.c, because it can build that sub-expression by a recursiveinvocation of coerce_to_target_type(). The executor now handles theper-element processing as a compiled expression instead of hard-wired code.The main advantage of this is that we can use a single ArrayCoerceExpr tohandle as many as three successive steps per element: base type conversion,typmod coercion, and domain constraint checking. The old code used twostacked ArrayCoerceExprs to handle type + typmod coercion, which was prettyinefficient, and adding yet another array deconstruction to do domainconstraint checking seemed very unappetizing.In the case where we just need a single, very simple coercion function,doing this straightforwardly leads to a noticeable increase in theper-array-element runtime cost. Hence, add an additional shortcut evalfuncin execExprInterp.c that skips unnecessary overhead for that specific formof expression. The runtime speed of simple cases is within 1% or so ofwhere it was before, while cases that previously required two levels ofarray processing are significantly faster.Finally, create an implicit array type for every domain type, as we do forbase types, enums, etc. Everything except the array-coercion case seemsto just work without further effort.Tom Lane, reviewed by Andrew DunstanDiscussion:https://postgr.es/m/9852.1499791473@sss.pgh.pa.us1 parent248e337 commitc12d570
File tree
28 files changed
+492
-264
lines changed- contrib/pg_stat_statements
- doc/src/sgml
- src
- backend
- catalog
- commands
- executor
- nodes
- optimizer
- path
- plan
- prep
- util
- parser
- rewrite
- utils
- adt
- fmgr
- include
- catalog
- executor
- nodes
- parser
- utils
- test/regress
- expected
- sql
28 files changed
+492
-264
lines changedLines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2630 | 2630 |
| |
2631 | 2631 |
| |
2632 | 2632 |
| |
| 2633 | + | |
2633 | 2634 |
| |
2634 | 2635 |
| |
2635 | 2636 |
| |
|
Lines changed: 2 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
10 | 10 |
| |
11 | 11 |
| |
12 | 12 |
| |
13 |
| - | |
14 |
| - | |
15 |
| - | |
| 13 | + | |
| 14 | + | |
16 | 15 |
| |
17 | 16 |
| |
18 | 17 |
| |
|
Lines changed: 6 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1738 | 1738 |
| |
1739 | 1739 |
| |
1740 | 1740 |
| |
1741 |
| - | |
1742 |
| - | |
1743 |
| - | |
| 1741 | + | |
1744 | 1742 |
| |
1745 | 1743 |
| |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
1746 | 1749 |
| |
1747 | 1750 |
| |
1748 | 1751 |
| |
|
Lines changed: 49 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
729 | 729 |
| |
730 | 730 |
| |
731 | 731 |
| |
| 732 | + | |
732 | 733 |
| |
733 | 734 |
| |
734 | 735 |
| |
| |||
757 | 758 |
| |
758 | 759 |
| |
759 | 760 |
| |
| 761 | + | |
760 | 762 |
| |
761 | 763 |
| |
762 | 764 |
| |
| |||
1027 | 1029 |
| |
1028 | 1030 |
| |
1029 | 1031 |
| |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
1030 | 1035 |
| |
1031 | 1036 |
| |
1032 | 1037 |
| |
| |||
1051 | 1056 |
| |
1052 | 1057 |
| |
1053 | 1058 |
| |
1054 |
| - | |
| 1059 | + | |
1055 | 1060 |
| |
1056 | 1061 |
| |
1057 | 1062 |
| |
| |||
1063 | 1068 |
| |
1064 | 1069 |
| |
1065 | 1070 |
| |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
1066 | 1113 |
| |
1067 | 1114 |
| |
1068 | 1115 |
| |
| |||
1139 | 1186 |
| |
1140 | 1187 |
| |
1141 | 1188 |
| |
| 1189 | + | |
1142 | 1190 |
| |
1143 | 1191 |
| |
1144 | 1192 |
| |
|
Lines changed: 33 additions & 25 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1225 | 1225 |
| |
1226 | 1226 |
| |
1227 | 1227 |
| |
| 1228 | + | |
1228 | 1229 |
| |
1229 | 1230 |
| |
1230 | 1231 |
| |
| |||
1234 | 1235 |
| |
1235 | 1236 |
| |
1236 | 1237 |
| |
1237 |
| - | |
1238 |
| - | |
1239 | 1238 |
| |
1240 |
| - | |
1241 |
| - | |
1242 |
| - | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
1243 | 1249 |
| |
1244 |
| - | |
1245 |
| - | |
1246 |
| - | |
| 1250 | + | |
| 1251 | + | |
1247 | 1252 |
| |
1248 |
| - | |
1249 |
| - | |
1250 |
| - | |
1251 |
| - | |
1252 |
| - | |
1253 |
| - | |
1254 |
| - | |
1255 |
| - | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
1256 | 1267 |
| |
1257 |
| - | |
1258 |
| - | |
1259 |
| - | |
1260 |
| - | |
1261 |
| - | |
1262 |
| - | |
1263 |
| - | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
1264 | 1271 |
| |
| 1272 | + | |
| 1273 | + | |
1265 | 1274 |
| |
1266 | 1275 |
| |
1267 | 1276 |
| |
1268 | 1277 |
| |
1269 | 1278 |
| |
1270 | 1279 |
| |
1271 |
| - | |
1272 |
| - | |
| 1280 | + | |
1273 | 1281 |
| |
1274 | 1282 |
| |
1275 | 1283 |
| |
|
Lines changed: 57 additions & 29 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
34 | 34 |
| |
35 | 35 |
| |
36 | 36 |
| |
37 |
| - | |
38 |
| - | |
39 |
| - | |
40 |
| - | |
| 37 | + | |
| 38 | + | |
41 | 39 |
| |
42 | 40 |
| |
43 | 41 |
| |
| |||
149 | 147 |
| |
150 | 148 |
| |
151 | 149 |
| |
| 150 | + | |
152 | 151 |
| |
153 | 152 |
| |
154 | 153 |
| |
| |||
184 | 183 |
| |
185 | 184 |
| |
186 | 185 |
| |
187 |
| - | |
188 |
| - | |
189 |
| - | |
190 |
| - | |
| 186 | + | |
| 187 | + | |
191 | 188 |
| |
192 | 189 |
| |
193 | 190 |
| |
| |||
230 | 227 |
| |
231 | 228 |
| |
232 | 229 |
| |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
233 | 237 |
| |
234 | 238 |
| |
235 | 239 |
| |
| |||
1275 | 1279 |
| |
1276 | 1280 |
| |
1277 | 1281 |
| |
1278 |
| - | |
| 1282 | + | |
1279 | 1283 |
| |
1280 | 1284 |
| |
1281 | 1285 |
| |
| |||
1811 | 1815 |
| |
1812 | 1816 |
| |
1813 | 1817 |
| |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
1814 | 1855 |
| |
1815 | 1856 |
| |
1816 | 1857 |
| |
| |||
2345 | 2386 |
| |
2346 | 2387 |
| |
2347 | 2388 |
| |
2348 |
| - | |
| 2389 | + | |
2349 | 2390 |
| |
2350 |
| - | |
2351 | 2391 |
| |
2352 |
| - | |
2353 | 2392 |
| |
2354 | 2393 |
| |
2355 | 2394 |
| |
| |||
2361 | 2400 |
| |
2362 | 2401 |
| |
2363 | 2402 |
| |
2364 |
| - | |
| 2403 | + | |
2365 | 2404 |
| |
2366 | 2405 |
| |
2367 | 2406 |
| |
| |||
2372 | 2411 |
| |
2373 | 2412 |
| |
2374 | 2413 |
| |
2375 |
| - | |
2376 |
| - | |
2377 |
| - | |
2378 |
| - | |
2379 |
| - | |
2380 |
| - | |
| 2414 | + | |
2381 | 2415 |
| |
2382 |
| - | |
2383 |
| - | |
2384 |
| - | |
2385 |
| - | |
2386 |
| - | |
2387 |
| - | |
2388 |
| - | |
2389 |
| - | |
2390 |
| - | |
2391 |
| - | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
2392 | 2420 |
| |
2393 | 2421 |
| |
2394 | 2422 |
| |
|
Lines changed: 1 addition & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1698 | 1698 |
| |
1699 | 1699 |
| |
1700 | 1700 |
| |
1701 |
| - | |
| 1701 | + | |
1702 | 1702 |
| |
1703 | 1703 |
| |
1704 | 1704 |
| |
1705 |
| - | |
1706 | 1705 |
| |
1707 | 1706 |
| |
1708 | 1707 |
| |
|
Lines changed: 1 addition & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
513 | 513 |
| |
514 | 514 |
| |
515 | 515 |
| |
516 |
| - | |
| 516 | + | |
517 | 517 |
| |
518 | 518 |
| |
519 | 519 |
| |
520 |
| - | |
521 | 520 |
| |
522 | 521 |
| |
523 | 522 |
| |
|
0 commit comments
Comments
(0)