forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitbd3dadd
committed
Arrange to convert EXISTS subqueries that are equivalent to hashable IN
subqueries into the same thing you'd have gotten from IN (except always withunknownEqFalse = true, so as to get the proper semantics for an EXISTS).I believe this fixes the last case within CVS HEAD in which an EXISTS couldgive worse performance than an equivalent IN subquery.The tricky part of this is that if the upper query probes the EXISTS for onlya few rows, the hashing implementation can actually be worse than the default,and therefore we need to make a cost-based decision about which way to use.But at the time when the planner generates plans for subqueries, it doesn'treally know how many times the subquery will be executed. The least invasivesolution seems to be to generate both plans and postpone the choice untilexecution. Therefore, in a query that has been optimized this way, EXPLAINwill show two subplans for the EXISTS, of which only one will actually getexecuted.There is a lot more that could be done based on this infrastructure: inparticular it's interesting to consider switching to the hash plan if we startout using the non-hashed plan but find a lot more upper rows going by than weexpected. I have therefore left some minor inefficiencies in place, such asinitializing both subplans even though we will currently only use one.1 parent8875a16 commitbd3dadd
File tree
21 files changed
+854
-321
lines changed- src
- backend
- catalog
- executor
- nodes
- optimizer
- path
- plan
- util
- parser
- rewrite
- utils/adt
- include
- executor
- nodes
- optimizer
- rewrite
21 files changed
+854
-321
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
8 | 8 |
| |
9 | 9 |
| |
10 | 10 |
| |
11 |
| - | |
| 11 | + | |
12 | 12 |
| |
13 | 13 |
| |
14 | 14 |
| |
| |||
1464 | 1464 |
| |
1465 | 1465 |
| |
1466 | 1466 |
| |
1467 |
| - | |
| 1467 | + | |
1468 | 1468 |
| |
1469 | 1469 |
| |
1470 | 1470 |
| |
|
Lines changed: 14 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
8 | 8 |
| |
9 | 9 |
| |
10 | 10 |
| |
11 |
| - | |
| 11 | + | |
12 | 12 |
| |
13 | 13 |
| |
14 | 14 |
| |
| |||
3957 | 3957 |
| |
3958 | 3958 |
| |
3959 | 3959 |
| |
| 3960 | + | |
| 3961 | + | |
| 3962 | + | |
| 3963 | + | |
| 3964 | + | |
| 3965 | + | |
| 3966 | + | |
| 3967 | + | |
| 3968 | + | |
| 3969 | + | |
| 3970 | + | |
| 3971 | + | |
| 3972 | + | |
3960 | 3973 |
| |
3961 | 3974 |
| |
3962 | 3975 |
| |
|
Lines changed: 90 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
7 | 7 |
| |
8 | 8 |
| |
9 | 9 |
| |
10 |
| - | |
| 10 | + | |
11 | 11 |
| |
12 | 12 |
| |
13 | 13 |
| |
| |||
29 | 29 |
| |
30 | 30 |
| |
31 | 31 |
| |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
32 | 40 |
| |
33 | 41 |
| |
34 | 42 |
| |
| |||
45 | 53 |
| |
46 | 54 |
| |
47 | 55 |
| |
48 |
| - | |
| 56 | + | |
49 | 57 |
| |
50 | 58 |
| |
51 | 59 |
| |
| |||
1066 | 1074 |
| |
1067 | 1075 |
| |
1068 | 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 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + |
Lines changed: 19 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
15 | 15 |
| |
16 | 16 |
| |
17 | 17 |
| |
18 |
| - | |
| 18 | + | |
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
| |||
969 | 969 |
| |
970 | 970 |
| |
971 | 971 |
| |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
972 | 987 |
| |
973 | 988 |
| |
974 | 989 |
| |
| |||
3146 | 3161 |
| |
3147 | 3162 |
| |
3148 | 3163 |
| |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
3149 | 3167 |
| |
3150 | 3168 |
| |
3151 | 3169 |
| |
|
Lines changed: 14 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
18 | 18 |
| |
19 | 19 |
| |
20 | 20 |
| |
21 |
| - | |
| 21 | + | |
22 | 22 |
| |
23 | 23 |
| |
24 | 24 |
| |
| |||
314 | 314 |
| |
315 | 315 |
| |
316 | 316 |
| |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
317 | 327 |
| |
318 | 328 |
| |
319 | 329 |
| |
| |||
2098 | 2108 |
| |
2099 | 2109 |
| |
2100 | 2110 |
| |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
2101 | 2114 |
| |
2102 | 2115 |
| |
2103 | 2116 |
| |
|
Lines changed: 14 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
8 | 8 |
| |
9 | 9 |
| |
10 | 10 |
| |
11 |
| - | |
| 11 | + | |
12 | 12 |
| |
13 | 13 |
| |
14 | 14 |
| |
| |||
846 | 846 |
| |
847 | 847 |
| |
848 | 848 |
| |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
849 | 859 |
| |
850 | 860 |
| |
851 | 861 |
| |
| |||
2208 | 2218 |
| |
2209 | 2219 |
| |
2210 | 2220 |
| |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
2211 | 2224 |
| |
2212 | 2225 |
| |
2213 | 2226 |
| |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
8 | 8 |
| |
9 | 9 |
| |
10 | 10 |
| |
11 |
| - | |
| 11 | + | |
12 | 12 |
| |
13 | 13 |
| |
14 | 14 |
| |
| |||
680 | 680 |
| |
681 | 681 |
| |
682 | 682 |
| |
683 |
| - | |
| 683 | + | |
| 684 | + | |
684 | 685 |
| |
685 | 686 |
| |
686 | 687 |
| |
|
0 commit comments
Comments
(0)