Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-04-30 9f2ef60949ced4fab4d077a7e1c6d913f3620c9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
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
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
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
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
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
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
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
set enable_material = off;
set enable_memoize = off;
set geqo = off;
set from_collapse_limit = 16;
set jit = off;
set join_collapse_limit = 16;
set pg_hint_plan.collect_all_hints = on;
set pg_hint_plan.force_innerrel_update_table = on;
/*+Set(enable_indexscan on)*/
explain (costs false)
        select /*+IndexOnlyScan(t0)*/ t0.c0 from tab0 t0
        join tab3 t3 on t0.c0 = t3.c3
    union all
        select /*+IndexScan(t0)*/ t1.c1 from tab1 t1
        join tab4 t0 on t1.c1 = t0.c4
;
                        QUERY PLAN
-----------------------------------------------------------
 Gather
   Workers Planned: 1
   Single Copy: true
   ->  Parallel Append
         ->  Merge Join
               Merge Cond: (t0.c4 = t1.c1)
               ->  Index Scan using idx4 on tab4 t0
               ->  Sort
                     Sort Key: t1.c1
                     ->  Seq Scan on tab1 t1
         ->  Merge Join
               Merge Cond: (t0_1.c0 = t3.c3)
               ->  Index Only Scan using idx0 on tab0 t0_1
               ->  Sort
                     Sort Key: t3.c3
                     ->  Seq Scan on tab3 t3
(16 rows)
 
/*+Set(enable_indexscan on)*/
explain (costs false)
        select /*+IndexOnlyScan(t0)*/ t0.c0 from tab0 t0
        join tab3 t3 on t0.c0 = t3.c3
    union all
        select /*+IndexScan(t0)*/ t1.c1 from tab1 t1
        join tab4 t0 on t1.c1 = t0.c4
    union all
        select t5.c5 from tab5 t5
        join tab6 t6 on t5.c5 = t6.c6
;
                        QUERY PLAN
-----------------------------------------------------------
 Gather
   Workers Planned: 1
   Single Copy: true
   ->  Parallel Append
         ->  Merge Join
               Merge Cond: (t0.c4 = t1.c1)
               ->  Index Scan using idx4 on tab4 t0
               ->  Sort
                     Sort Key: t1.c1
                     ->  Seq Scan on tab1 t1
         ->  Merge Join
               Merge Cond: (t5.c5 = t6.c6)
               ->  Index Only Scan using idx5 on tab5 t5
               ->  Sort
                     Sort Key: t6.c6
                     ->  Seq Scan on tab6 t6
         ->  Merge Join
               Merge Cond: (t0_1.c0 = t3.c3)
               ->  Index Only Scan using idx0 on tab0 t0_1
               ->  Sort
                     Sort Key: t3.c3
                     ->  Seq Scan on tab3 t3
(22 rows)
 
/*+Set(enable_indexscan on) Set(enable_indexscan on) Set(enable_indexscan on)
    Set(aaa on) IndexScan(t0)
*/
explain (costs false)
        select /*+IndexOnlyScan(t0)*/ t0.c0 from tab0 t0
        join tab3 t3 on t0.c0 = t3.c3
    union all
        select /*+IndexScan(t0) Set(bbb on)*/ t1.c1 from tab1 t1
        join tab4 t0 on t1.c1 = t0.c4
    union all
        select /*+IndexOnlyScan(t6) Set(ccc on)*/ t5.c5 from tab5 t5
        join tab6 t6 on t5.c5 = t6.c6
;
INFO:  unrecognized configuration parameter "aaa"
INFO:  unrecognized configuration parameter "bbb"
INFO:  unrecognized configuration parameter "ccc"
                        QUERY PLAN
-----------------------------------------------------------
 Gather
   Workers Planned: 1
   Single Copy: true
   ->  Parallel Append
         ->  Merge Join
               Merge Cond: (t0.c4 = t1.c1)
               ->  Index Scan using idx4 on tab4 t0
               ->  Sort
                     Sort Key: t1.c1
                     ->  Seq Scan on tab1 t1
         ->  Merge Join
               Merge Cond: (t6.c6 = t5.c5)
               ->  Index Only Scan using idx6 on tab6 t6
               ->  Sort
                     Sort Key: t5.c5
                     ->  Seq Scan on tab5 t5
         ->  Merge Join
               Merge Cond: (t0_1.c0 = t3.c3)
               ->  Index Only Scan using idx0 on tab0 t0_1
               ->  Sort
                     Sort Key: t3.c3
                     ->  Seq Scan on tab3 t3
(22 rows)
 
/*+Set(enable_indexscan on)
   BitmapScan(t5)
*/
explain (costs false)
        select /*+IndexOnlyScan(t0)*/ t0.c0 from tab0 t0
        join tab3 t3 on t0.c0 = t3.c3
    union all
        select /*+IndexScan(t0)*/ t1.c1 from tab1 t1
        join tab4 t0 on t1.c1 = t0.c4
    union all
        select t5.c5 from tab5 t5
        join tab6 t6 on t5.c5 = t6.c6
;
                        QUERY PLAN
-----------------------------------------------------------
 Gather
   Workers Planned: 1
   Single Copy: true
   ->  Parallel Append
         ->  Nested Loop
               ->  Seq Scan on tab6 t6
               ->  Bitmap Heap Scan on tab5 t5
                     Recheck Cond: (c5 = t6.c6)
                     ->  Bitmap Index Scan on idx5
                           Index Cond: (c5 = t6.c6)
         ->  Merge Join
               Merge Cond: (t0.c4 = t1.c1)
               ->  Index Scan using idx4 on tab4 t0
               ->  Sort
                     Sort Key: t1.c1
                     ->  Seq Scan on tab1 t1
         ->  Merge Join
               Merge Cond: (t0_1.c0 = t3.c3)
               ->  Index Only Scan using idx0 on tab0 t0_1
               ->  Sort
                     Sort Key: t3.c3
                     ->  Seq Scan on tab3 t3
(22 rows)
 
/*+Set(enable_indexscan on)
   Set(enable_mergejoin off)
*/
/*!BitmapScan(t5)
*/
explain (costs false)
        select /*+IndexOnlyScan(t0)*/ t0.c0 from tab0 t0
        join tab3 t3 on t0.c0 = t3.c3
    union all
        select /*+IndexScan(t0)*/ t1.c1 from tab1 t1
        join tab4 t0 on t1.c1 = t0.c4
    union all
        select t5.c5 from tab5 t5
        join tab6 t6 on t5.c5 = t6.c6
    union all
        select t0.c8 from tab8 t0
        join tab9 t9 on t0.c8 = t9.c9
;
                        QUERY PLAN
-----------------------------------------------------------
 Gather
   Workers Planned: 1
   Single Copy: true
   ->  Parallel Append
         ->  Nested Loop
               ->  Seq Scan on tab6 t6
               ->  Bitmap Heap Scan on tab5 t5
                     Recheck Cond: (c5 = t6.c6)
                     ->  Bitmap Index Scan on idx5
                           Index Cond: (c5 = t6.c6)
         ->  Hash Join
               Hash Cond: (t0.c4 = t1.c1)
               ->  Index Scan using idx4 on tab4 t0
               ->  Hash
                     ->  Seq Scan on tab1 t1
         ->  Hash Join
               Hash Cond: (t0_1.c8 = t9.c9)
               ->  Index Scan using idx8 on tab8 t0_1
               ->  Hash
                     ->  Seq Scan on tab9 t9
         ->  Hash Join
               Hash Cond: (t0_2.c0 = t3.c3)
               ->  Index Only Scan using idx0 on tab0 t0_2
               ->  Hash
                     ->  Seq Scan on tab3 t3
(25 rows)
 
/*+ IndexScan(t0)(70,80)
    Set(enable_mergejoin off)
*/
explain (costs false)
        select t0.c0 from tab0 t0
        join tab3 t3 on t0.c0 = t3.c3
    union all
        select t1.c1 from tab1 t1
        join tab4 t0 on t1.c1 = t0.c4
    union all
        select t5.c5 from tab5 t5
        join tab6 t6 on t5.c5 = t6.c6
;
                      QUERY PLAN
------------------------------------------------------
 Gather
   Workers Planned: 1
   Single Copy: true
   ->  Parallel Append
         ->  Hash Join
               Hash Cond: (t0.c4 = t1.c1)
               ->  Index Scan using idx4 on tab4 t0
               ->  Hash
                     ->  Seq Scan on tab1 t1
         ->  Hash Join
               Hash Cond: (t0_1.c0 = t3.c3)
               ->  Index Scan using idx0 on tab0 t0_1
               ->  Hash
                     ->  Seq Scan on tab3 t3
         ->  Hash Join
               Hash Cond: (t5.c5 = t6.c6)
               ->  Seq Scan on tab5 t5
               ->  Hash
                     ->  Seq Scan on tab6 t6
(19 rows)
 
/*+Set(enable_indexscan on)*/
explain (costs false)
        select /*+IndexOnlyScan(t0 idx0)*/ t0.c0 from tab0 t0
        join tab3 t3 on t0.c0 = t3.c3
    union all
        select /*+IndexScan(t0 idx4)*/ t1.c1 from tab1 t1
        join tab4 t0 on t1.c1 = t0.c4
;
                        QUERY PLAN
-----------------------------------------------------------
 Gather
   Workers Planned: 1
   Single Copy: true
   ->  Parallel Append
         ->  Merge Join
               Merge Cond: (t0.c4 = t1.c1)
               ->  Index Scan using idx4 on tab4 t0
               ->  Sort
                     Sort Key: t1.c1
                     ->  Seq Scan on tab1 t1
         ->  Merge Join
               Merge Cond: (t0_1.c0 = t3.c3)
               ->  Index Only Scan using idx0 on tab0 t0_1
               ->  Sort
                     Sort Key: t3.c3
                     ->  Seq Scan on tab3 t3
(16 rows)
 
/*+Set(enable_indexscan on)*/
explain (costs false)
select /*+MergeJoin(t0 t3)*/ t0.c0 from tab0 t0
join tab3 t3 on t0.c0 = t3.c3
;
                 QUERY PLAN
---------------------------------------------
 Merge Join
   Merge Cond: (t0.c0 = t3.c3)
   ->  Index Only Scan using idx0 on tab0 t0
   ->  Sort
         Sort Key: t3.c3
         ->  Seq Scan on tab3 t3
(6 rows)
 
/*+Set(enable_indexscan on)*/
explain (costs false)
        select /*+NestLoop(t0 t3)*/ t0.c0 from tab0 t0
        join tab3 t3 on t0.c0 = t3.c3
    union all
        select /*+MergeJoin(t1 t0)*/ t1.c1 from tab1 t1
        join tab4 t0 on t1.c1 = t0.c4
;
                       QUERY PLAN
---------------------------------------------------------
 Gather
   Workers Planned: 1
   Single Copy: true
   ->  Parallel Append
         ->  Nested Loop
               ->  Seq Scan on tab0 t0
               ->  Index Only Scan using idx3 on tab3 t3
                     Index Cond: (c3 = t0.c0)
         ->  Merge Join
               Merge Cond: (t1.c1 = t0_1.c4)
               ->  Index Only Scan using idx1 on tab1 t1
               ->  Sort
                     Sort Key: t0_1.c4
                     ->  Seq Scan on tab4 t0_1
(14 rows)
 
/*+Set(enable_indexscan on)*/
explain (costs false)
select /*+IndexOnlyScan(t0)*/ t0.c0,
    (
        select /*+IndexScan(t0)*/ max(t0.c1)
        from tab1 t0
    )
    as tmp1
from tab0 t0
;
                            QUERY PLAN
-------------------------------------------------------------------
 Index Only Scan using idx0 on tab0 t0
   InitPlan 2 (returns $1)
     ->  Result
           InitPlan 1 (returns $0)
             ->  Limit
                   ->  Index Scan Backward using idx1 on tab1 t0_1
                         Index Cond: (c1 IS NOT NULL)
(7 rows)
 
/*+Set(enable_indexscan on)*/
explain (costs false)
select /*+IndexOnlyScan(t0)*/ t0.c0,
    coalesce (
        (
            select /*+IndexScan(t0)*/ max(t0.c1)
            from tab1 t0
            where t0.c1 < 0
        )
        , 888
    )
    as tmp2
from tab0 t0
;
                             QUERY PLAN
---------------------------------------------------------------------
 Index Only Scan using idx0 on tab0 t0
   InitPlan 2 (returns $1)
     ->  Result
           InitPlan 1 (returns $0)
             ->  Limit
                   ->  Index Scan Backward using idx1 on tab1 t0_1
                         Index Cond: ((c1 IS NOT NULL) AND (c1 < 0))
(7 rows)
 
/*+Set(enable_indexscan on)*/
explain (costs false)
select /*+IndexOnlyScan(t0)*/ t0.c0
from tab0 t0
where t0.c0 in
    (
        select /*+IndexScan(t0)*/ t0.c1
        from tab1 t0
    )
;
                      QUERY PLAN
------------------------------------------------------
 Hash Join
   Hash Cond: (t0.c0 = t0_1.c1)
   ->  Index Only Scan using idx0 on tab0 t0
   ->  Hash
         ->  HashAggregate
               Group Key: t0_1.c1
               ->  Index Scan using idx1 on tab1 t0_1
(7 rows)
 
/*+Set(enable_indexscan on)*/
explain (costs false)
insert into tab19 (c19)
select /*+IndexOnlyScan(t0)*/ t0.c0
from tab0 t0
where t0.c0 in
    (
        select /*+IndexScan(t0)*/ t0.c1
        from tab1 t0
    )
;
                         QUERY PLAN
------------------------------------------------------------
 Insert on tab19
   ->  Hash Join
         Hash Cond: (t0.c0 = t0_1.c1)
         ->  Index Only Scan using idx0 on tab0 t0
         ->  Hash
               ->  HashAggregate
                     Group Key: t0_1.c1
                     ->  Index Scan using idx1 on tab1 t0_1
(8 rows)
 
/*+Set(enable_indexscan on)*/
explain (costs false)
select /*+IndexOnlyScan(t0)*/ t0.c0
from tab0 t0
where exists
    (
        select /*+IndexScan(t1)*/ t1.c1
        from tab1 t1
        where t1.c1 = t0.c0
    )
;
                     QUERY PLAN
----------------------------------------------------
 Hash Join
   Hash Cond: (t0.c0 = t1.c1)
   ->  Index Only Scan using idx0 on tab0 t0
   ->  Hash
         ->  HashAggregate
               Group Key: t1.c1
               ->  Index Scan using idx1 on tab1 t1
(7 rows)
 
/*+Set(enable_indexscan on)*/
explain (costs false)
select /*+IndexOnlyScan(t0)*/ t0.c0
from tab0 t0
where exists
    (
        select /*+IndexScan(t0)*/ t0.c1
        from tab1 t0
        where t0.c1 = 777
    )
;
                 QUERY PLAN
---------------------------------------------
 Result
   One-Time Filter: $0
   InitPlan 1 (returns $0)
     ->  Index Scan using idx1 on tab1 t0_1
           Index Cond: (c1 = 777)
   ->  Index Only Scan using idx0 on tab0 t0
(6 rows)
 
-------------------------------------------------------ForceOrder()
/*+
    ForceOrder()
 */
explain (costs false)
with sub_query as
(
    select t0.c0 from tab0 t0
    join tab1 t1 on t0.c0 = t1.c1
    join tab2 t2 on t1.c1 = t2.c2
    join tab3 t3 on t2.c2 = t3.c3
    join tab4 t4 on t3.c3 = t4.c4
    join tab5 t5 on t4.c4 = t5.c5
    join tab6 t6 on t5.c5 = t6.c6
    join tab7 t7 on t6.c6 = t7.c7
    join tab8 t8 on t7.c7 = t8.c8
    join tab9 t9 on t8.c8 = t9.c9
    join tab10 t10 on t9.c9 = t10.c10
    join tab11 t11 on t10.c10 = t11.c11
)
select * from sub_query
;
                                               QUERY PLAN
---------------------------------------------------------------------------------------------------------
 Nested Loop
   ->  Nested Loop
         ->  Nested Loop
               ->  Nested Loop
                     ->  Nested Loop
                           ->  Nested Loop
                                 ->  Nested Loop
                                       ->  Nested Loop
                                             ->  Nested Loop
                                                   ->  Nested Loop
                                                         ->  Nested Loop
                                                               ->  Seq Scan on tab0 t0
                                                               ->  Index Only Scan using idx1 on tab1 t1
                                                                     Index Cond: (c1 = t0.c0)
                                                         ->  Index Only Scan using idx2 on tab2 t2
                                                               Index Cond: (c2 = t0.c0)
                                                   ->  Index Only Scan using idx3 on tab3 t3
                                                         Index Cond: (c3 = t0.c0)
                                             ->  Index Only Scan using idx4 on tab4 t4
                                                   Index Cond: (c4 = t0.c0)
                                       ->  Index Only Scan using idx5 on tab5 t5
                                             Index Cond: (c5 = t0.c0)
                                 ->  Index Only Scan using idx6 on tab6 t6
                                       Index Cond: (c6 = t0.c0)
                           ->  Index Only Scan using idx7 on tab7 t7
                                 Index Cond: (c7 = t0.c0)
                     ->  Index Only Scan using idx8 on tab8 t8
                           Index Cond: (c8 = t0.c0)
               ->  Index Only Scan using idx9 on tab9 t9
                     Index Cond: (c9 = t0.c0)
         ->  Index Only Scan using idx10 on tab10 t10
               Index Cond: (c10 = t0.c0)
   ->  Index Only Scan using idx11 on tab11 t11
         Index Cond: (c11 = t0.c0)
(34 rows)
 
/*! ForceOrder() */
explain (costs false)
select * from tab0 t0
where exists
    (
        select t13.c13 from tab13 t13
        where t13.c13 in
        (
            select t14.c14 from tab14 t14
--          where 1=1
            where t14.c14 not in
            (
                select t1.c1 from tab1 t1
                join tab2 t2 on t1.c1 = t2.c2
                join tab3 t3 on t2.c2 = t3.c3
                join tab4 t4 on t3.c3 = t4.c4
                join tab5 t5 on t4.c4 = t5.c5
                join tab6 t6 on t5.c5 = t6.c6
                join tab7 t7 on t6.c6 = t7.c7
                join tab8 t8 on t7.c7 = t8.c8
                join tab9 t9 on t8.c8 = t9.c9
                join tab10 t10 on t9.c9 = t10.c10
                join tab11 t11 on t10.c10 = t11.c11
                join tab12 t12 on t11.c11 = t12.c12
            )
        )
    )
    or t0.c0 = any
    (
        select t1.c1 from tab1 t1
        join tab2 t2 on t1.c1 = t2.c2
        join tab3 t3 on t2.c2 = t3.c3
        join tab4 t4 on t3.c3 = t4.c4
        join tab5 t5 on t4.c4 = t5.c5
        join tab6 t6 on t5.c5 = t6.c6
        join tab7 t7 on t6.c6 = t7.c7
        join tab8 t8 on t7.c7 = t8.c8
        join tab9 t9 on t8.c8 = t9.c9
        join tab10 t10 on t9.c9 = t10.c10
        join tab11 t11 on t10.c10 = t11.c11
        join tab12 t12 on t11.c11 = t12.c12
    )
;;
                                                    QUERY PLAN
------------------------------------------------------------------------------------------------------------------
 Seq Scan on tab0 t0
   Filter: ($6 OR (SubPlan 3))
   InitPlan 2 (returns $6)
     ->  Nested Loop Semi Join
           ->  Seq Scan on tab13 t13
           ->  Index Only Scan using idx14 on tab14 t14
                 Index Cond: (c14 = t13.c13)
                 Filter: (NOT (SubPlan 1))
                 SubPlan 1
                   ->  Nested Loop
                         ->  Nested Loop
                               ->  Nested Loop
                                     ->  Nested Loop
                                           ->  Nested Loop
                                                 Join Filter: (t1.c1 = t8.c8)
                                                 ->  Nested Loop
                                                       Join Filter: (t1.c1 = t7.c7)
                                                       ->  Nested Loop
                                                             Join Filter: (t1.c1 = t6.c6)
                                                             ->  Nested Loop
                                                                   Join Filter: (t1.c1 = t5.c5)
                                                                   ->  Nested Loop
                                                                         Join Filter: (t1.c1 = t4.c4)
                                                                         ->  Nested Loop
                                                                               Join Filter: (t1.c1 = t3.c3)
                                                                               ->  Nested Loop
                                                                                     Join Filter: (t1.c1 = t2.c2)
                                                                                     ->  Seq Scan on tab1 t1
                                                                                     ->  Seq Scan on tab2 t2
                                                                               ->  Seq Scan on tab3 t3
                                                                         ->  Seq Scan on tab4 t4
                                                                   ->  Seq Scan on tab5 t5
                                                             ->  Seq Scan on tab6 t6
                                                       ->  Seq Scan on tab7 t7
                                                 ->  Seq Scan on tab8 t8
                                           ->  Index Only Scan using idx9 on tab9 t9
                                                 Index Cond: (c9 = t1.c1)
                                     ->  Index Only Scan using idx10 on tab10 t10
                                           Index Cond: (c10 = t1.c1)
                               ->  Index Only Scan using idx11 on tab11 t11
                                     Index Cond: (c11 = t1.c1)
                         ->  Index Only Scan using idx12 on tab12 t12
                               Index Cond: (c12 = t1.c1)
   SubPlan 3
     ->  Nested Loop
           ->  Nested Loop
                 ->  Nested Loop
                       ->  Nested Loop
                             ->  Nested Loop
                                   Join Filter: (t1_1.c1 = t8_1.c8)
                                   ->  Nested Loop
                                         Join Filter: (t1_1.c1 = t7_1.c7)
                                         ->  Nested Loop
                                               Join Filter: (t1_1.c1 = t6_1.c6)
                                               ->  Nested Loop
                                                     Join Filter: (t1_1.c1 = t5_1.c5)
                                                     ->  Nested Loop
                                                           Join Filter: (t1_1.c1 = t4_1.c4)
                                                           ->  Nested Loop
                                                                 Join Filter: (t1_1.c1 = t3_1.c3)
                                                                 ->  Nested Loop
                                                                       Join Filter: (t1_1.c1 = t2_1.c2)
                                                                       ->  Seq Scan on tab1 t1_1
                                                                       ->  Seq Scan on tab2 t2_1
                                                                 ->  Seq Scan on tab3 t3_1
                                                           ->  Seq Scan on tab4 t4_1
                                                     ->  Seq Scan on tab5 t5_1
                                               ->  Seq Scan on tab6 t6_1
                                         ->  Seq Scan on tab7 t7_1
                                   ->  Seq Scan on tab8 t8_1
                             ->  Index Only Scan using idx9 on tab9 t9_1
                                   Index Cond: (c9 = t1_1.c1)
                       ->  Index Only Scan using idx10 on tab10 t10_1
                             Index Cond: (c10 = t1_1.c1)
                 ->  Index Only Scan using idx11 on tab11 t11_1
                       Index Cond: (c11 = t1_1.c1)
           ->  Index Only Scan using idx12 on tab12 t12_1
                 Index Cond: (c12 = t1_1.c1)
(78 rows)
 
/*! ForceOrder() */
explain (costs false)
select t1.c1 from tab1 t1
join tab2 t2 on t1.c1 = t2.c2
join tab3 t3 on t2.c2 = t3.c3
join tab4 t4 on t3.c3 = t4.c4
;
                       QUERY PLAN
---------------------------------------------------------
 Nested Loop
   ->  Nested Loop
         ->  Nested Loop
               ->  Seq Scan on tab1 t1
               ->  Index Only Scan using idx2 on tab2 t2
                     Index Cond: (c2 = t1.c1)
         ->  Index Only Scan using idx3 on tab3 t3
               Index Cond: (c3 = t1.c1)
   ->  Index Only Scan using idx4 on tab4 t4
         Index Cond: (c4 = t1.c1)
(10 rows)
 
/*! ForceOrder() */
explain (costs false)
select t1.c1
from tab1 t1, tab2 t2, tab3 t3, tab4 t4, tab5 t5, tab6 t6, tab7 t7, tab8 t8, tab9 t9, tab10 t10, tab11 t11, tab12 t12
where t1.c1 = t2.c2 and t2.c2 = t3.c3 and t3.c3 = t4.c4 and t4.c4 = t5.c5 and t5.c5 = t6.c6
    and t6.c6 = t7.c7 and t7.c7 = t8.c8 and t8.c8 = t9.c9 and t9.c9 = t10.c10
    and t10.c10 = t11.c11 and t11.c11 = t12.c12
;
                                               QUERY PLAN
---------------------------------------------------------------------------------------------------------
 Nested Loop
   ->  Nested Loop
         ->  Nested Loop
               ->  Nested Loop
                     ->  Nested Loop
                           ->  Nested Loop
                                 ->  Nested Loop
                                       ->  Nested Loop
                                             ->  Nested Loop
                                                   ->  Nested Loop
                                                         ->  Nested Loop
                                                               ->  Seq Scan on tab1 t1
                                                               ->  Index Only Scan using idx2 on tab2 t2
                                                                     Index Cond: (c2 = t1.c1)
                                                         ->  Index Only Scan using idx3 on tab3 t3
                                                               Index Cond: (c3 = t1.c1)
                                                   ->  Index Only Scan using idx4 on tab4 t4
                                                         Index Cond: (c4 = t1.c1)
                                             ->  Index Only Scan using idx5 on tab5 t5
                                                   Index Cond: (c5 = t1.c1)
                                       ->  Index Only Scan using idx6 on tab6 t6
                                             Index Cond: (c6 = t1.c1)
                                 ->  Index Only Scan using idx7 on tab7 t7
                                       Index Cond: (c7 = t1.c1)
                           ->  Index Only Scan using idx8 on tab8 t8
                                 Index Cond: (c8 = t1.c1)
                     ->  Index Only Scan using idx9 on tab9 t9
                           Index Cond: (c9 = t1.c1)
               ->  Index Only Scan using idx10 on tab10 t10
                     Index Cond: (c10 = t1.c1)
         ->  Index Only Scan using idx11 on tab11 t11
               Index Cond: (c11 = t1.c1)
   ->  Index Only Scan using idx12 on tab12 t12
         Index Cond: (c12 = t1.c1)
(34 rows)
 
/*! ForceOrder() */
explain (costs false)
select t0.c0
from tab0 t0, tab1 t1, tab2 t2, tab3 t3, tab4 t4, tab5 t5, tab6 t6, tab7 t7, tab8 t8, tab9 t9, tab10 t10, tab11 t11, tab12 t12, tab13 t13, tab14 t14
where t0.c0 = t1.c1 and t1.c1 = t2.c2 and t2.c2 = t3.c3 and t3.c3 = t4.c4 and t4.c4 = t5.c5 and t5.c5 = t6.c6
    and t6.c6 = t7.c7 and t7.c7 = t8.c8 and t8.c8 = t9.c9 and t9.c9 = t10.c10
    and t10.c10 = t11.c11 and t11.c11 = t12.c12 and t12.c12 = t13.c13 and t13.c13 = t14.c14
;
                                                        QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
 Nested Loop
   ->  Nested Loop
         ->  Nested Loop
               ->  Nested Loop
                     ->  Nested Loop
                           ->  Nested Loop
                                 ->  Nested Loop
                                       ->  Nested Loop
                                             ->  Nested Loop
                                                   ->  Nested Loop
                                                         ->  Nested Loop
                                                               ->  Nested Loop
                                                                     ->  Nested Loop
                                                                           ->  Nested Loop
                                                                                 ->  Seq Scan on tab0 t0
                                                                                 ->  Index Only Scan using idx1 on tab1 t1
                                                                                       Index Cond: (c1 = t0.c0)
                                                                           ->  Index Only Scan using idx2 on tab2 t2
                                                                                 Index Cond: (c2 = t0.c0)
                                                                     ->  Index Only Scan using idx3 on tab3 t3
                                                                           Index Cond: (c3 = t0.c0)
                                                               ->  Index Only Scan using idx4 on tab4 t4
                                                                     Index Cond: (c4 = t0.c0)
                                                         ->  Index Only Scan using idx5 on tab5 t5
                                                               Index Cond: (c5 = t0.c0)
                                                   ->  Index Only Scan using idx6 on tab6 t6
                                                         Index Cond: (c6 = t0.c0)
                                             ->  Index Only Scan using idx7 on tab7 t7
                                                   Index Cond: (c7 = t0.c0)
                                       ->  Index Only Scan using idx8 on tab8 t8
                                             Index Cond: (c8 = t0.c0)
                                 ->  Index Only Scan using idx9 on tab9 t9
                                       Index Cond: (c9 = t0.c0)
                           ->  Index Only Scan using idx10 on tab10 t10
                                 Index Cond: (c10 = t0.c0)
                     ->  Index Only Scan using idx11 on tab11 t11
                           Index Cond: (c11 = t0.c0)
               ->  Index Only Scan using idx12 on tab12 t12
                     Index Cond: (c12 = t0.c0)
         ->  Index Only Scan using idx13 on tab13 t13
               Index Cond: (c13 = t0.c0)
   ->  Index Only Scan using idx14 on tab14 t14
         Index Cond: (c14 = t0.c0)
(43 rows)
 
/*! ForceOrder() */
explain (costs false)
select
    t0.c0,
    (select min(t1.c1) from tab1 t1
            join tab2 t2 on t1.c1 = t2.c2
            join tab3 t3 on t2.c2 = t3.c3
            join tab4 t4 on t3.c3 = t4.c4
            join tab5 t5 on t4.c4 = t5.c5
        )
    as cc2
from tab0 t0
;
                                 QUERY PLAN
-----------------------------------------------------------------------------
 Seq Scan on tab0 t0
   InitPlan 1 (returns $4)
     ->  Aggregate
           ->  Nested Loop
                 ->  Nested Loop
                       ->  Nested Loop
                             ->  Nested Loop
                                   ->  Seq Scan on tab1 t1
                                   ->  Index Only Scan using idx2 on tab2 t2
                                         Index Cond: (c2 = t1.c1)
                             ->  Index Only Scan using idx3 on tab3 t3
                                   Index Cond: (c3 = t1.c1)
                       ->  Index Only Scan using idx4 on tab4 t4
                             Index Cond: (c4 = t1.c1)
                 ->  Index Only Scan using idx5 on tab5 t5
                       Index Cond: (c5 = t1.c1)
(16 rows)
 
/*! ForceOrder() */
explain (costs false)
select t1.c1,
    case
        when exists (
            select 1 from tab3 t3
            where t3.c3 = t1.c1
        ) then 10
        else 0
    end
    +
    case
        when exists (
            select 1 from tab2 t2
            where t2.c2 = t1.c1
        ) then 1
        else 0
    end
        as cc2
from tab0 t0
join tab1 t1 on t1.c1 = t0.c0
where t1.c1 >= 5
;
                    QUERY PLAN
--------------------------------------------------
 Nested Loop
   ->  Seq Scan on tab0 t0
   ->  Index Only Scan using idx1 on tab1 t1
         Index Cond: ((c1 = t0.c0) AND (c1 >= 5))
   SubPlan 2
     ->  Seq Scan on tab3 t3
   SubPlan 4
     ->  Seq Scan on tab2 t2
(8 rows)
 
/*! ForceOrder() */
explain (costs false)
select t1.c1,
    case
        when exists (
            select 1 from tab3 t3
            where t3.c3 = t1.c1
        ) then 10
        else 0
    end
    +
    case
        when exists (
            select 1 from tab2 t2
            where t2.c2 = t1.c1
        ) then 1
        else 0
    end
    -
    case
        when exists (
            select 1 from tab4 t4
            where t4.c4 = t1.c1
            and t4.c4 in
                (
                    select t5.c5 from tab5 t5
                    join tab6 t6 on t6.c6 = t5.c5
                )
        ) then 7
        else 0
    end
        as cc2
from tab0 t0
join tab1 t1 on t1.c1 = t0.c0
where t1.c1 >= 5
;
                        QUERY PLAN
-----------------------------------------------------------
 Nested Loop
   ->  Seq Scan on tab0 t0
   ->  Index Only Scan using idx1 on tab1 t1
         Index Cond: ((c1 = t0.c0) AND (c1 >= 5))
   SubPlan 2
     ->  Seq Scan on tab3 t3
   SubPlan 4
     ->  Seq Scan on tab2 t2
   SubPlan 6
     ->  Nested Loop Semi Join
           ->  Seq Scan on tab4 t4
           ->  Nested Loop
                 Join Filter: (t4.c4 = t6.c6)
                 ->  Index Only Scan using idx5 on tab5 t5
                       Index Cond: (c5 = t4.c4)
                 ->  Index Only Scan using idx6 on tab6 t6
                       Index Cond: (c6 = t5.c5)
(17 rows)
 
/*! ForceOrder() */
explain (costs false)
select t0.c0 from tab0 t0
join tab3 t3 on t0.c0 = t3.c3
join tab2 t2 on t0.c0 = t2.c2
join tab1 t1 on t0.c0 = t1.c1
;
                       QUERY PLAN
---------------------------------------------------------
 Nested Loop
   ->  Nested Loop
         ->  Nested Loop
               ->  Seq Scan on tab0 t0
               ->  Index Only Scan using idx3 on tab3 t3
                     Index Cond: (c3 = t0.c0)
         ->  Index Only Scan using idx2 on tab2 t2
               Index Cond: (c2 = t0.c0)
   ->  Index Only Scan using idx1 on tab1 t1
         Index Cond: (c1 = t0.c0)
(10 rows)
 
/*! ForceOrder() */
explain (costs false)
select t0.c0
from tab0 t0, tab1 t1, tab2 t2, tab3 t3
where t0.c0 = t1.c1 and t1.c1 = t2.c2 and t2.c2 = t3.c3
;
                       QUERY PLAN
---------------------------------------------------------
 Nested Loop
   ->  Nested Loop
         ->  Nested Loop
               ->  Seq Scan on tab0 t0
               ->  Index Only Scan using idx1 on tab1 t1
                     Index Cond: (c1 = t0.c0)
         ->  Index Only Scan using idx2 on tab2 t2
               Index Cond: (c2 = t0.c0)
   ->  Index Only Scan using idx3 on tab3 t3
         Index Cond: (c3 = t0.c0)
(10 rows)
 
/*! ForceOrder() */
explain (costs false)
select t0.c0
from tab1 t1, tab3 t3, tab2 t2, tab0 t0
where t0.c0 = t1.c1 and t1.c1 = t2.c2 and t2.c2 = t3.c3
;
                       QUERY PLAN
---------------------------------------------------------
 Nested Loop
   ->  Nested Loop
         ->  Nested Loop
               ->  Seq Scan on tab1 t1
               ->  Index Only Scan using idx3 on tab3 t3
                     Index Cond: (c3 = t1.c1)
         ->  Index Only Scan using idx2 on tab2 t2
               Index Cond: (c2 = t1.c1)
   ->  Index Only Scan using idx0 on tab0 t0
         Index Cond: (c0 = t1.c1)
(10 rows)
 
/*! ForceOrder() */
explain (costs false)
select t0.c0
from tab0 t0, tab1 t1
join tab2 t2 on t1.c1 = t2.c2
join tab3 t3 on t2.c2 = t3.c3
where t0.c0 = t1.c1
;
                       QUERY PLAN
---------------------------------------------------------
 Nested Loop
   Join Filter: (t0.c0 = t1.c1)
   ->  Seq Scan on tab0 t0
   ->  Nested Loop
         ->  Nested Loop
               ->  Seq Scan on tab1 t1
               ->  Index Only Scan using idx2 on tab2 t2
                     Index Cond: (c2 = t1.c1)
         ->  Index Only Scan using idx3 on tab3 t3
               Index Cond: (c3 = t1.c1)
(10 rows)
 
/*! ForceOrder() */
explain (costs false)
    select t0.c0 from tab0 t0
    join tab2 t2 on t0.c0 = t2.c2
    join tab1 t1 on t0.c0 = t1.c1
    join tab3 t3 on t2.c2 = t3.c3
union all
    select t0.c0 from tab0 t0
    join tab3 t3 on t0.c0 = t3.c3
    join tab1 t1 on t0.c0 = t1.c1
    join tab2 t2 on t0.c0 = t2.c2
;
                              QUERY PLAN
-----------------------------------------------------------------------
 Gather
   Workers Planned: 1
   Single Copy: true
   ->  Parallel Append
         ->  Nested Loop
               ->  Nested Loop
                     ->  Nested Loop
                           ->  Seq Scan on tab0 t0
                           ->  Index Only Scan using idx3 on tab3 t3
                                 Index Cond: (c3 = t0.c0)
                     ->  Index Only Scan using idx1 on tab1 t1
                           Index Cond: (c1 = t0.c0)
               ->  Index Only Scan using idx2 on tab2 t2
                     Index Cond: (c2 = t0.c0)
         ->  Nested Loop
               ->  Nested Loop
                     ->  Nested Loop
                           ->  Seq Scan on tab0 t0_1
                           ->  Index Only Scan using idx2 on tab2 t2_1
                                 Index Cond: (c2 = t0_1.c0)
                     ->  Index Only Scan using idx1 on tab1 t1_1
                           Index Cond: (c1 = t0_1.c0)
               ->  Index Only Scan using idx3 on tab3 t3_1
                     Index Cond: (c3 = t0_1.c0)
(24 rows)
 
/*! ForceOrder() */
explain (costs false)
select t0.c0
from tab1 t1,
    tab3 t3,
    tab0 t0
        join tab2 t2 on t2.c2 = t0.c0
where t0.c0 = t1.c1 and t1.c1 = t3.c3
;
                    QUERY PLAN
---------------------------------------------------
 Nested Loop
   Join Filter: (t1.c1 = t2.c2)
   ->  Nested Loop
         ->  Seq Scan on tab1 t1
         ->  Index Only Scan using idx3 on tab3 t3
               Index Cond: (c3 = t1.c1)
   ->  Nested Loop
         ->  Seq Scan on tab0 t0
         ->  Index Only Scan using idx2 on tab2 t2
               Index Cond: (c2 = t0.c0)
(10 rows)
 
/*! ForceOrder() */
explain (costs false)
select t0.c0
from tab1 t1,
    tab3 t3
        join tab4 t4 on t4.c4 = t3.c3,
    tab0 t0
        join tab2 t2 on t2.c2 = t0.c0
where t0.c0 = t1.c1 and t1.c1 = t3.c3
;
                       QUERY PLAN
---------------------------------------------------------
 Nested Loop
   Join Filter: (t1.c1 = t2.c2)
   ->  Nested Loop
         Join Filter: (t1.c1 = t4.c4)
         ->  Seq Scan on tab1 t1
         ->  Nested Loop
               ->  Seq Scan on tab3 t3
               ->  Index Only Scan using idx4 on tab4 t4
                     Index Cond: (c4 = t3.c3)
   ->  Nested Loop
         ->  Seq Scan on tab0 t0
         ->  Index Only Scan using idx2 on tab2 t2
               Index Cond: (c2 = t0.c0)
(13 rows)
 
/*! ForceOrder() */
explain (costs false)
select 1 from tab4 t4
where t4.c4 = 5
and t4.c4 in
    (
        select t5.c5 from tab5 t5
        join tab6 t6 on t6.c6 = t5.c5
    )
;
                 QUERY PLAN
---------------------------------------------
 Nested Loop Semi Join
   ->  Bitmap Heap Scan on tab4 t4
         Recheck Cond: (c4 = 5)
         ->  Bitmap Index Scan on idx4
               Index Cond: (c4 = 5)
   ->  Nested Loop
         ->  Bitmap Heap Scan on tab5 t5
               Recheck Cond: (c5 = 5)
               ->  Bitmap Index Scan on idx5
                     Index Cond: (c5 = 5)
         ->  Bitmap Heap Scan on tab6 t6
               Recheck Cond: (c6 = 5)
               ->  Bitmap Index Scan on idx6
                     Index Cond: (c6 = 5)
(14 rows)
 
/*! ForceOrder() */
explain (costs false)
select t0.c0 from tab0 t0
join tab1 t1 on t0.c0 = t1.c1
join tab2 t2 on t1.c1 = t2.c2
join tab3 t3 on t2.c2 = t3.c3
join tab11 t11 on t0.c0 = t11.c11
join tab12 t12 on t0.c0 = t12.c12
;
                             QUERY PLAN
---------------------------------------------------------------------
 Nested Loop
   ->  Nested Loop
         ->  Nested Loop
               ->  Nested Loop
                     ->  Nested Loop
                           ->  Seq Scan on tab0 t0
                           ->  Index Only Scan using idx1 on tab1 t1
                                 Index Cond: (c1 = t0.c0)
                     ->  Index Only Scan using idx2 on tab2 t2
                           Index Cond: (c2 = t0.c0)
               ->  Index Only Scan using idx3 on tab3 t3
                     Index Cond: (c3 = t0.c0)
         ->  Index Only Scan using idx11 on tab11 t11
               Index Cond: (c11 = t0.c0)
   ->  Index Only Scan using idx12 on tab12 t12
         Index Cond: (c12 = t0.c0)
(16 rows)
 
/*! ForceOrder() */
explain (costs false)
update tab2 t2
set c2 = t4.c4
from tab0 t0
inner join tab4 t4 on t0.c0 = t4.c4
where t2.c2 = t0.c0
;
                     QUERY PLAN
----------------------------------------------------
 Update on tab2 t2
   ->  Nested Loop
         Join Filter: (t2.c2 = t0.c0)
         ->  Seq Scan on tab2 t2
         ->  Nested Loop
               ->  Seq Scan on tab0 t0
               ->  Index Scan using idx4 on tab4 t4
                     Index Cond: (c4 = t0.c0)
(8 rows)
 
/*! ForceOrder() */
explain (costs false)
delete from tab2
where c2 in
    (
        select t2.c2
        from tab4 t4, tab2 t2
        where t2.c2 = t4.c4
    )
;
                        QUERY PLAN
----------------------------------------------------------
 Delete on tab2
   ->  Nested Loop Semi Join
         ->  Seq Scan on tab2
         ->  Nested Loop
               Join Filter: (tab2.c2 = t2.c2)
               ->  Index Scan using idx4 on tab4 t4
                     Index Cond: (c4 = tab2.c2)
               ->  Index Scan using idx2 on tab2 t2
                     Index Cond: (c2 = t4.c4)
(9 rows)
 
-------------------------------------------------------stand
--stand_query_001
/*! ForceOrder() */
explain (costs false)
        DELETE
          FROM pLastDate2
         WHERE pLastDate2.ctid IN (
        SELECT ld.ctid
          FROM pRest2 r
        INNER JOIN pLastDate2 ld
                ON ld.ResourceID = r.ResourceID AND ld.FundID = r.FundID AND ld.SPID = 2109098
         WHERE r.SPID = 2109098)
;
                                                                                     QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Delete on plastdate2
   ->  Nested Loop
         ->  HashAggregate
               Group Key: ld.ctid
               ->  Nested Loop
                     ->  Index Scan using prest2_xpktrest on prest2 r
                           Index Cond: ((spid)::numeric = '2109098'::numeric)
                     ->  Index Scan using plastdate2_xpkplastdate2 on plastdate2 ld
                           Index Cond: (((spid)::numeric = '2109098'::numeric) AND ((resourceid)::numeric = (r.resourceid)::numeric) AND ((fundid)::numeric = (r.fundid)::numeric))
         ->  Tid Scan on plastdate2
               TID Cond: (ctid = ld.ctid)
(11 rows)
 
--stand_query_002
/*! ForceOrder() */
explain (costs false)
          UPDATE pRest2 tab__update
             SET Rest = Rest.Rest + r.Rest
                ,RestBs = Rest.RestBs + r.RestBs
                ,LastDate = CASE WHEN (abs(Rest.TurnDeb) + abs(Rest.TurnCre) > 0) THEN '2010-08-31 00:00:00' ELSE r.LastDate END
            FROM pRest2 Rest
          INNER JOIN pLastDate2 pl
                  ON pl.SPID = 2109098 AND pl.ResourceID = Rest.ResourceID AND pl.FundID = Rest.FundID
          INNER JOIN tRest r
                  ON r.AccountingType = 1 AND r.Date = pl.LastDate AND r.ResourceID = Rest.ResourceID AND r.FundID = Rest.FundID AND r.InstitutionID = 2000
           WHERE tab__update.ctid = Rest.ctid AND (Rest.SPID = 2109098)
;
                                                                                                QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Update on prest2 tab__update
   ->  Nested Loop
         ->  Nested Loop
               ->  Nested Loop
                     ->  Index Scan using prest2_xpktrest on prest2 rest
                           Index Cond: ((spid)::numeric = '2109098'::numeric)
                     ->  Index Scan using plastdate2_xpkplastdate2 on plastdate2 pl
                           Index Cond: (((spid)::numeric = '2109098'::numeric) AND ((resourceid)::numeric = (rest.resourceid)::numeric) AND ((fundid)::numeric = (rest.fundid)::numeric))
               ->  Index Scan using trest_xie6trest on trest r
                     Index Cond: (((accountingtype)::integer = 1) AND ((institutionid)::numeric = '2000'::numeric) AND ((date)::timestamp without time zone = (pl.lastdate)::timestamp without time zone))
                     Filter: (((pl.resourceid)::numeric = (resourceid)::numeric) AND ((pl.fundid)::numeric = (fundid)::numeric))
         ->  Tid Scan on prest2 tab__update
               TID Cond: (ctid = rest.ctid)
(13 rows)
 
--stand_query_003
/*! ForceOrder() */
explain (costs false)
        INSERT INTO tMMRegAnalytics
        (
            MMRegID,
            MMAnalyticsID
        )
        SELECT r.MMRegID,
               d.MMAnalyticsID
          FROM pMMRegisterID r, pMMAnalyticMassInsert a, pMMAnalyticDeal2 d, pMMAnalyticMassInsert a2
         WHERE r.SPID = 2109098 AND a.SPID = r.SPID AND a.LinkID = r.LinkID AND d.SPID = a.SPID AND d.MMAnalyticsTypeID = a.MMAnalyticsTypeID AND d.AnalyticsObjectID = a.AnalyticsObjectID
            AND a.SPID = a2.SPID AND a.LinkID = a2.LinkID
;
                                                                                                    QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on tmmreganalytics
   ->  Nested Loop
         ->  Nested Loop
               ->  Nested Loop
                     ->  Bitmap Heap Scan on pmmregisterid r
                           Recheck Cond: ((spid)::numeric = '2109098'::numeric)
                           ->  Bitmap Index Scan on pmmregisterid_xpkpmmregisterid
                                 Index Cond: ((spid)::numeric = '2109098'::numeric)
                     ->  Index Scan using pmmanalyticmassinsert_xpkpmmanalyticmassinsert on pmmanalyticmassinsert a
                           Index Cond: (((spid)::numeric = '2109098'::numeric) AND ((linkid)::numeric = (r.linkid)::numeric))
               ->  Index Scan using pmmanalyticdeal2_xpkpmmanalyticdeal2 on pmmanalyticdeal2 d
                     Index Cond: (((spid)::numeric = '2109098'::numeric) AND ((mmanalyticstypeid)::numeric = (a.mmanalyticstypeid)::numeric) AND ((analyticsobjectid)::numeric = (a.analyticsobjectid)::numeric))
         ->  Index Only Scan using pmmanalyticmassinsert_xpkpmmanalyticmassinsert on pmmanalyticmassinsert a2
               Index Cond: ((spid = '2109098'::numeric) AND (linkid = (a.linkid)::numeric))
(14 rows)
 
--stand_query_004
/*! ForceOrder() */
explain (costs false)
            INSERT INTO pFX_TermRegister
            (
                SPID,
                ObjectID,
                MMRegID,
                Value,
                LiabType,
                CurrencyID
            )
            SELECT 2109098,
                   p.ObjectID,
                   r.MMRegID,
                   r.Value,
                   a1.AnalyticsObjectID,
                   a2.AnalyticsObjectID
              FROM pFX_TermDealParam p
            INNER JOIN tMMReg r
                    ON r.ObjectID = p.ObjectID AND r.ObjectTypeID = 1 AND r.Date = '2010-08-31 00:00:00' AND r.MMRegTypeID = 21
             INNER JOIN tMMRegAnalytics ra1
                    ON ra1.MMRegID = r.MMRegID
            INNER JOIN tMMAnalytics a1
                    ON a1.MMAnalyticsID = ra1.MMAnalyticsID AND a1.MMAnalyticsTypeID = 24
            INNER JOIN tMMRegAnalytics ra2
                    ON ra2.MMRegID = r.MMRegID
            INNER JOIN tMMAnalytics a2
                    ON a2.MMAnalyticsID = ra2.MMAnalyticsID AND a2.MMAnalyticsTypeID = 2
            INNER JOIN tMMReg rr
                    ON rr.ObjectID = p.ObjectID AND rr.ObjectTypeID = 1 AND rr.Date = '2010-08-31 00:00:00' AND rr.MMRegTypeID = 22
             WHERE p.SPID = 2109098
;
                                                                                                                QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on pfx_termregister
   ->  Nested Loop
         Join Filter: ((r.objectid)::numeric = (rr.objectid)::numeric)
         ->  Nested Loop
               ->  Nested Loop
                     ->  Nested Loop
                           ->  Nested Loop
                                 ->  Nested Loop
                                       Join Filter: ((p.objectid)::numeric = (r.objectid)::numeric)
                                       ->  Index Only Scan using pfx_termdealparam_xpkpfx_termdealparam on pfx_termdealparam p
                                             Index Cond: (spid = '2109098'::numeric)
                                       ->  Index Scan using tmmreg_xie1tmmreg on tmmreg r
                                             Index Cond: (((date)::timestamp without time zone = 'Tue Aug 31 00:00:00 2010'::timestamp without time zone) AND ((mmregtypeid)::numeric = '21'::numeric) AND ((objecttypeid)::integer = 1))
                                 ->  Bitmap Heap Scan on tmmreganalytics ra1
                                       Recheck Cond: ((mmregid)::numeric = (r.mmregid)::numeric)
                                       ->  Bitmap Index Scan on tmmreganalytics_xpktmmreganalytics
                                             Index Cond: ((mmregid)::numeric = (r.mmregid)::numeric)
                           ->  Index Scan using tmmanalytics_xpktmmanalytics on tmmanalytics a1
                                 Index Cond: ((mmanalyticsid)::numeric = (ra1.mmanalyticsid)::numeric)
                                 Filter: ((mmanalyticstypeid)::numeric = '24'::numeric)
                     ->  Index Only Scan using tmmreganalytics_xpktmmreganalytics on tmmreganalytics ra2
                           Index Cond: (mmregid = (ra1.mmregid)::numeric)
               ->  Index Scan using tmmanalytics_xpktmmanalytics on tmmanalytics a2
                     Index Cond: ((mmanalyticsid)::numeric = (ra2.mmanalyticsid)::numeric)
                     Filter: ((mmanalyticstypeid)::numeric = '2'::numeric)
         ->  Index Scan using tmmreg_xie1tmmreg on tmmreg rr
               Index Cond: (((date)::timestamp without time zone = 'Tue Aug 31 00:00:00 2010'::timestamp without time zone) AND ((mmregtypeid)::numeric = '22'::numeric) AND ((objecttypeid)::integer = 1))
(27 rows)
 
--stand_query_005
/*! ForceOrder() */
explain (costs false)
        UPDATE pDPT_Accrual_AdvLucre tab__update
           SET PrcDate = opc.AdvOnDate
          FROM pDealID_Mark m, pDPT_Accrual_AdvLucre al, pDPT_Accrual_AdvAc opc
         WHERE tab__update.ctid = al.ctid AND (m.spid = 111 AND al.SPID = m.spid AND al.TemplateNumber = 222 AND al.ObjectID = m.DealID AND opc.SPID = al.SPID AND opc.ObjectID = al.ObjectID AND opc.TemplateNumber = al.TemplateNumber AND opc.AdvOnDate = (
        SELECT max(opc2.AdvOnDate)
          FROM pDPT_Accrual_AdvAc opc2
         WHERE opc2.SPID = al.SPID AND opc2.ObjectID = opc.ObjectID AND opc2.TemplateNumber = al.TemplateNumber AND opc2.AdvOnDate <= m.DateBegin))
;
                                                                                                                              QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Update on pdpt_accrual_advlucre tab__update
   ->  Nested Loop
         Join Filter: (((al.objectid)::numeric = (opc.objectid)::numeric) AND ((SubPlan 2) = (opc.advondate)::timestamp without time zone))
         ->  Nested Loop
               Join Filter: ((m.dealid)::numeric = (al.objectid)::numeric)
               ->  Nested Loop
+                     ->  Index Scan using pdealid_mark_xie0pdealid_mark on pdealid_mark m
+                           Index Cond: ((spid)::numeric = '111'::numeric)
+                     ->  Seq Scan on pdpt_accrual_advlucre tab__update
+               ->  Tid Scan on pdpt_accrual_advlucre al
+                     TID Cond: (ctid = tab__update.ctid)
+                     Filter: (((spid)::numeric = '111'::numeric) AND ((templatenumber)::numeric = '222'::numeric))
+         ->  Index Scan using pdpt_accrual_advac_xak1pdpt_accrual_advac on pdpt_accrual_advac opc
+               Index Cond: (((spid)::numeric = '111'::numeric) AND ((templatenumber)::numeric = '222'::numeric) AND ((objectid)::numeric = (m.dealid)::numeric))
+         SubPlan 2
+           ->  Result
+                 InitPlan 1 (returns $4)
+                   ->  Limit
+                         ->  Index Only Scan Backward using pdpt_accrual_advac_xpkpdpt_accrual_advac on pdpt_accrual_advac opc2
+                               Index Cond: ((spid = (al.spid)::numeric) AND (objectid = (opc.objectid)::numeric) AND (templatenumber = (al.templatenumber)::numeric) AND (advondate IS NOT NULL) AND (advondate <= (m.datebegin)::timestamp without time zone))
+(20 rows)
 
--stand_query_006
/*! ForceOrder() */
explain (costs false)
    UPDATE pObject2 tab__update
         SET ErrorCode = o.RetCode
        FROM pTmp_DocumentBuffer o
      INNER JOIN pObject2 ob3
              ON ob3.SPID = 2109098 AND ob3.ObjectID = o.ObjectID
      INNER JOIN pObject2 ob4
              ON ob4.SPID = 2109098 AND ob4.ObjectID = o.ObjectID
      INNER JOIN pObject2 ob
              ON ob.SPID = 2109098 AND ob.ObjectID = o.ObjectID
       WHERE tab__update.ctid = ob.ctid AND (o.RetCode > 0 AND o.RetCode <> 25103)
;
                                                               QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------
 Update on pobject2 tab__update
   ->  Nested Loop
         ->  Nested Loop
               Join Filter: ((ob3.objectid)::numeric = (ob.objectid)::numeric)
               ->  Nested Loop
                     Join Filter: ((ob3.objectid)::numeric = (ob4.objectid)::numeric)
                     ->  Nested Loop
                           ->  Seq Scan on ptmp_documentbuffer o
                                 Filter: (((retcode)::numeric > '0'::numeric) AND ((retcode)::numeric <> '25103'::numeric))
                           ->  Index Scan using pobject2_xie1pobject2 on pobject2 ob3
                                 Index Cond: (((spid)::numeric = '2109098'::numeric) AND ((objectid)::numeric = (o.objectid)::numeric))
                     ->  Index Scan using pobject2_xie1pobject2 on pobject2 ob4
                           Index Cond: (((spid)::numeric = '2109098'::numeric) AND ((objectid)::numeric = (o.objectid)::numeric))
               ->  Index Scan using pobject2_xie1pobject2 on pobject2 ob
                     Index Cond: (((spid)::numeric = '2109098'::numeric) AND ((objectid)::numeric = (o.objectid)::numeric))
         ->  Tid Scan on pobject2 tab__update
               TID Cond: (ctid = ob.ctid)
(17 rows)
 
--zip_00240.sql
explain (costs false)
          INSERT INTO pObject
          (
              SPID,
              ObjectID,
              InstrumentID,
              ActionID,
              Date,
              OperDate,
              PlanDate
          )
          SELECT /*+ IndexScan(a tactionperiod_xie1tactionperiod)
                     IndexScan(dm tdocmark_xpktdocmark)
                     IndexScan(pl tactionplan_xak1tactionplan)
                     IndexScan(p5 ptblcursor5_xpkptblcursor5)
                     IndexScan(ob tobject_xak2tobject)
                     IndexScan(p tprotocol_xpktprotocol)
                     IndexScan(t ttransition_xpkttransition)
                     IndexScan(os toperset_xak1toperset) */
                 /*! ForceOrder() */
                 777/*var__SPID_CONSTANT*/,
                 pl.ObjectID,
                 888/*var_InstrumentID*/,
                 999/*var_ActionID*/,
                 max(pl.FactDate),
                 coalesce(nullif('20000101'/*var_locOperDate*/, '19000101'), '20200101'/*var_locDate*/)::dsoperday,
                 max(pl.PlanDate)
            FROM tActionPeriod a, tDocMark dm, tActionPlan pl, pTblCursor5 p5, tObject ob, tProtocol p, tTransition t, tOperSet os
           WHERE a.NodeID = 999/*var_ActionID*/ AND dm.SPID = 777/*var__SPID_CONSTANT*/ AND dm.Type = 555/*var_MarkType*/ AND ob.ID = dm.ID AND ob.InstrumentID = 888/*var_InstrumentID*/ AND p.ProtocolID = ob.CurrProtocolID AND t.TransitionID = p.TransitionID AND os.ParentID = t.TargetStateID AND os.ChildID = 999/*var_ActionID*/ AND pl.ObjectID = dm.ID AND pl.OperDate = '20200101'/*var_locDate*/
           AND EXISTS(          SELECT /*+ IndexScan(pr tperiod_xie1tperiod) */
                 1
            FROM tPeriod pr
           WHERE pr.SchemePeriodID = a.SchemePeriodID AND (pr.PeriodAlgorithm <> 5 OR pr.PeriodType <> 1))
           AND NOT EXISTS(          SELECT /*+ IndexScan(p pobject_xpkpobject) */
                 1
            FROM pObject p
           WHERE p.SPID = 777/*var__SPID_CONSTANT*/ AND p.ObjectID = pl.ObjectID) AND p5.SPID = 777/*var__SPID_CONSTANT*/ AND p5.Type = 131 AND pl.ActionPeriodID = a.ActionPeriodID AND pl.BranchID = p5.ID AND pl.ObjectID = ob.ID AND pl.BranchID = ob.BranchID AND ob.InstrumentID = 888/*var_InstrumentID*/
           AND NOT EXISTS(          SELECT /*+ IndexScan(e perrorobject_xpkperrorobject) */
                 1
            FROM pErrorObject e
           WHERE e.SPID = 777/*var__SPID_CONSTANT*/ AND e.ObjectID = pl.ObjectID AND e.InstrumentID = 888/*var_InstrumentID*/ AND e.NodeID = 999/*var_ActionID*/)
          GROUP BY
            pl.ObjectID ORDER BY pl.ObjectID
;
                                                                                           QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on pobject
   ->  Subquery Scan on "*SELECT*"
         ->  GroupAggregate
               Group Key: pl.objectid
               ->  Nested Loop Anti Join
                     Join Filter: ((e.objectid)::numeric = (pl.objectid)::numeric)
                     ->  Nested Loop Anti Join
                           ->  Nested Loop Semi Join
                                 ->  Nested Loop
                                       ->  Nested Loop
                                             ->  Nested Loop
                                                   ->  Nested Loop
                                                         Join Filter: ((dm.id)::numeric = (ob.id)::numeric)
                                                         ->  Nested Loop
                                                               ->  Nested Loop
                                                                     ->  Nested Loop
                                                                           ->  Index Scan using tdocmark_xpktdocmark on tdocmark dm
                                                                                 Index Cond: (((spid)::numeric = '777'::numeric) AND ((type)::integer = 555))
                                                                           ->  Index Scan using tactionperiod_xie1tactionperiod on tactionperiod a
                                                                                 Index Cond: ((nodeid)::numeric = '999'::numeric)
                                                                     ->  Index Scan using tactionplan_xak1tactionplan on tactionplan pl
                                                                           Index Cond: (((objectid)::numeric = (dm.id)::numeric) AND ((actionperiodid)::numeric = (a.actionperiodid)::numeric))
                                                                           Filter: ((operdate)::timestamp without time zone = 'Wed Jan 01 00:00:00 2020'::timestamp without time zone)
                                                               ->  Index Scan using ptblcursor5_xpkptblcursor5 on ptblcursor5 p5
                                                                     Index Cond: (((spid)::numeric = '777'::numeric) AND ((type)::smallint = 131) AND ((id)::numeric = (pl.branchid)::numeric))
                                                         ->  Index Scan using tobject_xak2tobject on tobject ob
                                                               Index Cond: (((instrumentid)::numeric = '888'::numeric) AND ((id)::numeric = (pl.objectid)::numeric))
                                                               Filter: ((pl.branchid)::numeric = (branchid)::numeric)
                                                   ->  Index Scan using tprotocol_xpktprotocol on tprotocol p
                                                         Index Cond: ((protocolid)::numeric = (ob.currprotocolid)::numeric)
                                             ->  Index Scan using ttransition_xpkttransition on ttransition t
                                                   Index Cond: ((transitionid)::numeric = (p.transitionid)::numeric)
                                       ->  Index Scan using toperset_xak1toperset on toperset os
                                             Index Cond: (((parentid)::numeric = (t.targetstateid)::numeric) AND ((childid)::numeric = '999'::numeric))
                                 ->  Index Scan using tperiod_xie1tperiod on tperiod pr
                                       Index Cond: ((schemeperiodid)::numeric = (a.schemeperiodid)::numeric)
                                       Filter: (((periodalgorithm)::numeric <> '5'::numeric) OR ((periodtype)::integer <> 1))
                           ->  Index Scan using pobject_xpkpobject on pobject p_1
                                 Index Cond: (((spid)::numeric = '777'::numeric) AND ((objectid)::numeric = (pl.objectid)::numeric))
                     ->  Index Scan using perrorobject_xpkperrorobject on perrorobject e
                           Index Cond: (((spid)::numeric = '777'::numeric) AND ((instrumentid)::numeric = '888'::numeric) AND ((nodeid)::numeric = '999'::numeric))
(41 rows)
 
--badhint_query
explain (costs false)
INSERT INTO pAPI_PrmD_IDList
      (
          SPID,
          AccountID,
          AccountNumber,
          PrmDID,
          LinkID
      )
      SELECT /*+ IndexScan(p prko_prmd_accidlist_xpkprko_prmd_accidlist)
                 IndexScan(dt tdealtransact_xie9tdealtransact) */
             /*! ForceOrder() */
             239710,
             p.AccountID,
             p.AccountNumber,
             dt.DealTransactID,
             p.FoundedAccID
        FROM pRKO_PrmD_AccIDList p
      INNER JOIN tDealTransact dt
              ON dt.ResourceID = p.FoundedAccID AND dt.Date BETWEEN '19000101 00:00:00' AND '20100831 00:00:00' AND dt.TransactType = 5 AND (1 = 2 OR (1 <> 2 AND dt.Confirmed = 1)) AND (2000 = 0 OR dt.InstitutionID = 2000)
       WHERE p.SPID = 239710 AND p.FoundedAccID BETWEEN 1 AND 1501
       UNION ALL
      SELECT /*+ IndexScan(p prko_prmd_accidlist_xpkprko_prmd_accidlist)
                 IndexScan(dt tdealtransact_xie14tdealtransact) */
             /*! ForceOrder() */
             239710,
             p.AccountID,
             p.AccountNumber,
             dt.DealTransactID,
             p.FoundedAccID
        FROM pRKO_PrmD_AccIDList p
      INNER JOIN tDealTransact dt
              ON dt.ResourcePsvID = p.FoundedAccID AND dt.Date BETWEEN '19000101 00:00:00' AND '20100831 00:00:00' AND dt.TransactType = 5 AND dt.ResourcePsvID <> dt.ResourceID AND (1 = 2 OR (1 <> 2 AND dt.Confirmed = 1)) AND (2000 = 0 OR dt.InstitutionID = 2000)
       WHERE p.SPID = 239710 AND p.FoundedAccID BETWEEN 1 AND 1501
;
                                                                                                                                                    QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on papi_prmd_idlist
   ->  Result
         ->  Append
               ->  Subquery Scan on "*SELECT* 1"
                     ->  Nested Loop
                           ->  Index Scan using prko_prmd_accidlist_xpkprko_prmd_accidlist on prko_prmd_accidlist p
                                 Index Cond: (((spid)::numeric = '239710'::numeric) AND ((foundedaccid)::numeric >= '1'::numeric) AND ((foundedaccid)::numeric <= '1501'::numeric))
                           ->  Index Scan using tdealtransact_xie9tdealtransact on tdealtransact dt
                                 Index Cond: (((resourceid)::numeric = (p.foundedaccid)::numeric) AND ((date)::timestamp without time zone >= 'Mon Jan 01 00:00:00 1900'::timestamp without time zone) AND ((date)::timestamp without time zone <= 'Tue Aug 31 00:00:00 2010'::timestamp without time zone))
                                 Filter: (((transacttype)::smallint = 5) AND ((confirmed)::smallint = 1) AND ((institutionid)::numeric = '2000'::numeric))
               ->  Subquery Scan on "*SELECT* 2"
                     ->  Nested Loop
                           ->  Index Scan using prko_prmd_accidlist_xpkprko_prmd_accidlist on prko_prmd_accidlist p_1
                                 Index Cond: (((spid)::numeric = '239710'::numeric) AND ((foundedaccid)::numeric >= '1'::numeric) AND ((foundedaccid)::numeric <= '1501'::numeric))
                           ->  Index Scan using tdealtransact_xie14tdealtransact on tdealtransact dt_1
                                 Index Cond: (((resourcepsvid)::numeric = (p_1.foundedaccid)::numeric) AND ((date)::timestamp without time zone >= 'Mon Jan 01 00:00:00 1900'::timestamp without time zone) AND ((date)::timestamp without time zone <= 'Tue Aug 31 00:00:00 2010'::timestamp without time zone))
                                 Filter: (((resourcepsvid)::numeric <> (resourceid)::numeric) AND ((transacttype)::smallint = 5) AND ((confirmed)::smallint = 1) AND ((institutionid)::numeric = '2000'::numeric))
(17 rows)
 
--badforce_query
explain (costs false)
UPDATE /*+ IndexScan(m pdealid_mark_xie0pdealid_mark)
               IndexScan(al pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre)
               IndexScan(opc pdpt_accrual_advac_xpkpdpt_accrual_advac) */
           /*! ForceOrder() */
           pDPT_Accrual_AdvLucre tab__update
       SET PrcDate = opc.AdvOnDate
      FROM pDealID_Mark m, pDPT_Accrual_AdvLucre al, pDPT_Accrual_AdvAc opc
     WHERE tab__update.ctid = al.ctid AND (m.spid = 999 AND al.SPID = m.spid AND al.TemplateNumber = 888 AND al.ObjectID = m.DealID AND opc.SPID = al.SPID AND opc.ObjectID = al.ObjectID AND opc.TemplateNumber = al.TemplateNumber AND opc.AdvOnDate = (    SELECT /*+ IndexScan(opc2 pdpt_accrual_advac_xpkpdpt_accrual_advac) */
           max(opc2.AdvOnDate)
      FROM pDPT_Accrual_AdvAc opc2
     WHERE opc2.SPID = al.SPID AND opc2.ObjectID = opc.ObjectID AND opc2.TemplateNumber = al.TemplateNumber AND opc2.AdvOnDate <= m.DateBegin))
;
                                                                                                                                                                             QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Update on pdpt_accrual_advlucre tab__update
   ->  Nested Loop
         Join Filter: (((al.objectid)::numeric = (opc.objectid)::numeric) AND ((SubPlan 2) = (opc.advondate)::timestamp without time zone))
         ->  Nested Loop
               Join Filter: (tab__update.ctid = al.ctid)
               ->  Nested Loop
                     ->  Index Scan using pdealid_mark_xie0pdealid_mark on pdealid_mark m
                           Index Cond: ((spid)::numeric = '999'::numeric)
                     ->  Seq Scan on pdpt_accrual_advlucre tab__update
               ->  Index Scan using pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre on pdpt_accrual_advlucre al
                     Index Cond: (((spid)::numeric = '999'::numeric) AND ((objectid)::numeric = (m.dealid)::numeric) AND ((templatenumber)::numeric = '888'::numeric))
+         ->  Index Scan using pdpt_accrual_advac_xpkpdpt_accrual_advac on pdpt_accrual_advac opc
+               Index Cond: (((spid)::numeric = '999'::numeric) AND ((objectid)::numeric = (m.dealid)::numeric) AND ((templatenumber)::numeric = '888'::numeric))
+         SubPlan 2
+           ->  Result
+                 InitPlan 1 (returns $4)
+                   ->  Limit
+                         ->  Index Scan Backward using pdpt_accrual_advac_xpkpdpt_accrual_advac on pdpt_accrual_advac opc2
+                               Index Cond: (((spid)::numeric = (al.spid)::numeric) AND ((objectid)::numeric = (opc.objectid)::numeric) AND ((templatenumber)::numeric = (al.templatenumber)::numeric) AND ((advondate)::timestamp without time zone IS NOT NULL) AND ((advondate)::timestamp without time zone <= (m.datebegin)::timestamp without time zone))
(19 rows)
 
--113_skype.sql
explain (costs off)
INSERT INTO pAPI_SM_LinkedProtocol
      (
          SPID,
          RelationType,
          ProtocolID,
          ObjectID,
          ObjectTypeID,
          FinOperID
      )
      SELECT /*+ IndexScan(pr tprotocolrelation_xie1tprotocolrelation)
                 IndexScan(p tprotocol_xpktprotocol)
                 IndexScan(o tobject_xpktobject) */
             /*! ForceOrder() */
             999,
             1,
             pr.ParentID,
             o.ID,
             o.ObjectTypeID,
             o.InstrumentID
        FROM tProtocolRelation pr
      INNER JOIN tProtocol p
              ON p.ProtocolID = pr.ParentID
      INNER JOIN tObject o
              ON o.ObjectID = p.ObjectID
       WHERE pr.ChildID = 888
       UNION ALL
      SELECT /*+ IndexScan(pr tprotocolrelation_xpktprotocolrelation)
                 IndexScan(p tprotocol_xpktprotocol)
                 IndexScan(o tobject_xpktobject) */
             /*! ForceOrder() */
             999,
             2,
             pr.ChildID,
             o.ID,
             o.ObjectTypeID,
             o.InstrumentID
        FROM tProtocolRelation pr
      INNER JOIN tProtocol p
              ON p.ProtocolID = pr.ChildID
      INNER JOIN tObject o
              ON o.ObjectID = p.ObjectID
       WHERE pr.ParentID = 888
;
                                                      QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------
 Insert on papi_sm_linkedprotocol
   ->  Result
         ->  Append
               ->  Subquery Scan on "*SELECT* 1"
                     ->  Nested Loop
                           ->  Nested Loop
                                 ->  Index Scan using tprotocolrelation_xie1tprotocolrelation on tprotocolrelation pr
                                       Index Cond: ((childid)::numeric = '888'::numeric)
                                 ->  Index Scan using tprotocol_xpktprotocol on tprotocol p
                                       Index Cond: ((protocolid)::numeric = (pr.parentid)::numeric)
                           ->  Index Scan using tobject_xpktobject on tobject o
                                 Index Cond: ((objectid)::numeric = (p.objectid)::numeric)
               ->  Subquery Scan on "*SELECT* 2"
                     ->  Nested Loop
                           ->  Nested Loop
                                 ->  Index Scan using tprotocolrelation_xpktprotocolrelation on tprotocolrelation pr_1
                                       Index Cond: ((parentid)::numeric = '888'::numeric)
                                 ->  Index Scan using tprotocol_xpktprotocol on tprotocol p_1
                                       Index Cond: ((protocolid)::numeric = (pr_1.childid)::numeric)
                           ->  Index Scan using tobject_xpktobject on tobject o_1
                                 Index Cond: ((objectid)::numeric = (p_1.objectid)::numeric)
(21 rows)
 
--116_skype.sql
explain (costs off)
    INSERT INTO pDPT_Accrual_AdvBase
    (
        SPID,
        ObjectID,
        BaseValue,
        Tax,
        AdvTax,
        Qty,
        RefQty,
        TemplateNumber,
        BeginDate,
        EndDate,
        ProtocolID
    )
    SELECT /*+ IndexScan(o papi_accrual_object_xpkpapi_accrual_object)
               IndexScan(oap pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre)
               IndexScan(od papi_accrual_date_xpkpapi_accrual_date) */
           /*! ForceOrder() */
           999,
           oap.ObjectID,
           oap.Value,
           oap.Prcnt,
           oap.AdvTax,
           0,
           0,
           888,
           oap.BeginDate,
           oap.EndDate,
           oap.ProtocolID
      FROM pAPI_Accrual_Object o, pDPT_Accrual_AdvLucre oap, pAPI_Accrual_Date od
     WHERE o.SPID = 999 AND oap.SPID = o.SPID AND oap.ObjectID = o.ObjectID AND od.SPID = oap.SPID AND od.ObjectID = oap.ObjectID AND od.TemplateNumber = 888 AND oap.BeginDate >= od.BeginDate AND oap.EndDate <= od.EndDate
    ;
                                                                                                                                QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on pdpt_accrual_advbase
   ->  Nested Loop
         Join Filter: (((oap.begindate)::timestamp without time zone >= (od.begindate)::timestamp without time zone) AND ((oap.enddate)::timestamp without time zone <= (od.enddate)::timestamp without time zone) AND ((oap.objectid)::numeric = (od.objectid)::numeric))
         ->  Nested Loop
               Join Filter: ((o.objectid)::numeric = (oap.objectid)::numeric)
               ->  Index Scan using papi_accrual_object_xpkpapi_accrual_object on papi_accrual_object o
                     Index Cond: ((spid)::numeric = '999'::numeric)
               ->  Index Scan using pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre on pdpt_accrual_advlucre oap
                     Index Cond: ((spid)::numeric = '999'::numeric)
         ->  Index Scan using papi_accrual_date_xpkpapi_accrual_date on papi_accrual_date od
               Index Cond: (((spid)::numeric = '999'::numeric) AND ((templatenumber)::numeric = '888'::numeric))
(11 rows)
 
--115_skype.sql
explain (costs off)
        INSERT INTO pTmp_DocumentBuffer
        (
            QtyDeb,
            FundID,
            DealProtocolID,
            InstrumentID,
            ObjectID,
            GroupID,
            OperTemplateID,
            DealID,
            Comment,
            QtyPsv,
            FundPsvID
        )
        SELECT /*+ IndexScan(oqp pqtyobjectmember_xpkpqtyobjectmember)
                   IndexScan(ot palltemplate_xie2palltemplate)
                   IndexScan(dp paccr_object_cprotocol_xpkpaccr_object_cprotocol)
                   IndexScan(otd palltemplatedoc_xie2palltemplatedoc)
                   IndexScan(pd pdocumenttemplate_xpkpdocumenttemplate) */
               /*! ForceOrder() */
               coalesce(sum(oqp.Const * oqp.Mult1 * oqp.Mult2 * oqp.Mult3 * oqp.Mult4 * oqp.Mult5 / oqp.Div1 / oqp.Div2 / oqp.Div3 / oqp.Div4 / oqp.Div5)),
               coalesce(max(oqp.FundID), 0) AS "oqpFundID",
               dp.CurrProtocolID,
               222,
               oqp.ObjectID AS "oqpObjectID",
               oqp.ObjectID,
               oqp.OperTemplateID AS "pdOperTemplateID",
               (1 - sign(55)) * oqp.ObjectID,
               max(ot.Number) AS "otNumber",
               0,
               0
          FROM pQtyObjectMember oqp, pAllTemplate ot, pACCR_Object_CProtocol dp, pAllTemplateDoc otd, pDocumentTemplate pd
         WHERE oqp.SPID = CAST(999 AS int) AND oqp.PartNumber = 1 AND oqp.Div1 <> 0 AND oqp.Div2 <> 0 AND oqp.Div3 <> 0 AND oqp.Div4 <> 0 AND oqp.Div5 <> 0 AND dp.SPID = CAST(oqp.spid AS numeric (15, 0)) AND dp.ObjectID = oqp.ObjectID AND dp.FinOperID = 222 AND ot.SPID = CAST(oqp.spid AS numeric (15, 0)) AND ot.OperTemplateID = oqp.OperTemplateID AND otd.SPID = CAST(oqp.spid AS numeric (15, 0)) AND otd.OperTemplateID = oqp.OperTemplateID AND otd.Priority = CAST(333 AS smallint) AND pd.SPID = CAST(oqp.spid AS numeric (15, 0)) AND pd.OperTemplateID = oqp.OperTemplateID AND ((ot.Security = 0) OR (EXISTS(        SELECT /*+ IndexScan(oa papi_accrual_objaccount_xie4papi_accrual_objaccount) */
               1
          FROM pAPI_Accrual_ObjAccount oa
         WHERE oa.SPID = CAST(oqp.spid AS numeric (15, 0)) AND oa.ObjectID = oqp.ObjectID AND oa.CrnID = ot.Security)))
        GROUP BY
          oqp.ObjectID,
          oqp.OperTemplateID,
          dp.CurrProtocolID ORDER BY "oqpObjectID", "otNumber"
;
                                                                                                                                                                      QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on ptmp_documentbuffer
   ->  Subquery Scan on "*SELECT*"
         ->  Incremental Sort
               Sort Key: oqp.objectid, (max((ot.number)::bpchar))
               Presorted Key: oqp.objectid
               ->  GroupAggregate
                     Group Key: oqp.objectid, oqp.opertemplateid, dp.currprotocolid
                     ->  Incremental Sort
                           Sort Key: oqp.objectid, oqp.opertemplateid, dp.currprotocolid
                           Presorted Key: oqp.objectid, oqp.opertemplateid
                           ->  Nested Loop
                                 Join Filter: ((dp.spid)::numeric = (pd.spid)::numeric)
                                 ->  Nested Loop
                                       Join Filter: ((dp.spid)::numeric = (otd.spid)::numeric)
                                       ->  Nested Loop
                                             Join Filter: ((oqp.objectid)::numeric = (dp.objectid)::numeric)
                                             ->  Nested Loop
                                                   ->  Index Scan using pqtyobjectmember_xpkpqtyobjectmember on pqtyobjectmember oqp
                                                         Index Cond: (((spid)::integer = 999) AND ((partnumber)::integer = 1))
                                                         Filter: (((div1)::double precision <> '0'::double precision) AND ((div2)::double precision <> '0'::double precision) AND ((div3)::double precision <> '0'::double precision) AND ((div4)::double precision <> '0'::double precision) AND ((div5)::double precision <> '0'::double precision))
                                                   ->  Index Scan using palltemplate_xie2palltemplate on palltemplate ot
                                                         Index Cond: (((spid)::numeric = (oqp.spid)::numeric(15,0)) AND ((opertemplateid)::numeric = (oqp.opertemplateid)::numeric))
                                                         Filter: (((security)::numeric = '0'::numeric) OR (SubPlan 1))
                                                         SubPlan 1
                                                           ->  Index Scan using papi_accrual_objaccount_xie4papi_accrual_objaccount on papi_accrual_objaccount oa
                                                                 Index Cond: (((spid)::numeric = (oqp.spid)::numeric(15,0)) AND ((objectid)::numeric = (oqp.objectid)::numeric) AND ((crnid)::numeric = (ot.security)::numeric))
                                             ->  Index Scan using paccr_object_cprotocol_xpkpaccr_object_cprotocol on paccr_object_cprotocol dp
                                                   Index Cond: (((spid)::numeric = (ot.spid)::numeric) AND ((finoperid)::numeric = '222'::numeric))
                                       ->  Index Scan using palltemplatedoc_xie2palltemplatedoc on palltemplatedoc otd
                                             Index Cond: (((spid)::numeric = (ot.spid)::numeric) AND ((opertemplateid)::numeric = (ot.opertemplateid)::numeric))
                                             Filter: ((priority)::smallint = '333'::smallint)
                                 ->  Index Scan using pdocumenttemplate_xpkpdocumenttemplate on pdocumenttemplate pd
                                       Index Cond: (((spid)::numeric = (ot.spid)::numeric) AND ((opertemplateid)::numeric = (ot.opertemplateid)::numeric))
(33 rows)
 
--zip_08859.sql
explain (costs off)
    INSERT INTO pAPI_CAcc_LetterAuthority
    (
        SPID,
        CurrentAccountID,
        LetterAuthorityID,
        Kind,
        BranchID,
        BranchBrief,
        AuthorID,
        AuthorBrief,
        AuthorName,
        Number,
        DateCreation,
        OwnerID,
        OwnerKind,
        OwnerBrief,
        OwnerName,
        OwnerICardID,
        OwnerICardTypeBrief,
        OwnerICardRegNumber,
        OwnerICardRegSeries,
        AgentID,
        AgentBrief,
        AgentName,
        AgentICardID,
        AgentICardTypeBrief,
        AgentICardRegNumber,
        AgentICardRegSeries,
        DateOper,
        DateStart,
        TermDay,
        TermMonth,
        DateEnd,
        Status,
        Comment,
        FinOperID,
        StateID,
        StateBrief,
        StateName
    )
    SELECT /*+ IndexScan(r ptdpt_jr_xpkptdpt_jr)
               IndexScan(l papi_jrel_findlist_xpkpapi_jrel_findlist)
               IndexScan(d papi_juraldoc_findlist_xpkpapi_juraldoc_findlist)
               IndexScan(f tdpt_finoper_sync_xpktdpt_finoper_sync)
               IndexScan(s papi_sm_currentstate_xpkpapi_sm_currentstate)
               IndexScan(pb tdpt_partc_sync_xpktdpt_partc_sync)
               IndexScan(pi tdpt_partc_sync_xpktdpt_partc_sync)
               IndexScan(pp tdpt_partc_sync_xpktdpt_partc_sync)
               IndexScan(lp papi_prs_icard_xie1papi_prs_icard)
               IndexScan(pc tdpt_partc_sync_xpktdpt_partc_sync)
               IndexScan(lc papi_prs_icard_xpkpapi_prs_icard) */
           /*! ForceOrder() */
           777/*var__SPID_CONSTANT*/,
           888,
           d.JRDocID,
           CASE WHEN coalesce(999, 0) > 0 THEN 999 ELSE CASE WHEN d.BranchID = d.AuthorID THEN 1 ELSE 2 END END,
           d.BranchID,
           pb.Brief,
           d.AuthorID,
           coalesce(pI.Brief, ''),
           coalesce(CASE WHEN pI.PropType = 0 THEN ltrim(rtrim(concat(ltrim(rtrim(concat(ltrim(rtrim(pI.Name)), ' ', pI.Name1))), ' ', pI.Name2))) ELSE pI.Name END, ''),
           coalesce(d.OriginalNumber, ''),
           d.DateCreation,
           d.OwnerID,
           pp.PropType,
           pp.Brief,
           CASE WHEN pp.PropType = 0 THEN concat(ltrim(rtrim(pp.Name)), ' ', ltrim(rtrim(pp.Name1)), ' ', ltrim(rtrim(pp.Name2))) ELSE ltrim(rtrim(pp.Name)) END,
           lp.ICardID,
           coalesce(lp.DocType, ''),
           coalesce(lp.RegNumber, ''),
           coalesce(lp.RegSeries, ''),
           d.AgentID,
           pc.Brief,
           CASE WHEN pc.PropType = 0 THEN concat(ltrim(rtrim(pc.Name)), ' ', ltrim(rtrim(pc.Name1)), ' ', ltrim(rtrim(pc.Name2))) ELSE ltrim(rtrim(pc.Name)) END,
           d.AgentICardID,
           coalesce(lc.DocType, ''),
           coalesce(lc.RegNumber, ''),
           coalesce(lc.RegSeries, ''),
           d.DateOper,
           d.DateAccount,
           d.PeriodDay,
           d.PeriodMonth,
           d.DateClose,
           CASE WHEN lower(l.Status)::DSBRIEFNAME = 'inactive' THEN 0 WHEN lower(l.Status)::DSBRIEFNAME = 'active' THEN 1 WHEN lower(l.Status)::DSBRIEFNAME = 'closed' THEN 2 WHEN lower(l.Status)::DSBRIEFNAME = 'cancelled' THEN 3 ELSE 0 END,
           d.Comment,
           f.FinOperID,
           s.StateID,
           s.Brief,
           s.Name
      FROM pTDpt_JR r
    INNER JOIN pAPI_JRel_FindList l
            ON l.SPID = 123/*var__SPID_CONSTANT*/ AND l.JRelID = r.JRelID
    INNER JOIN pAPI_JuralDoc_FindList d
            ON d.SPID = 777/*var__SPID_CONSTANT*/ AND d.JRDocID = l.JRDocID
    INNER JOIN tDPT_FinOper_Sync f
            ON f.FinOperID = d.FinOperID
    INNER JOIN pAPI_SM_CurrentState s
            ON s.SPID = 777/*var__SPID_CONSTANT*/ AND s.ID = r.JRelID
    LEFT OUTER JOIN tDPT_Partc_Sync pb
            ON pb.ParticipantID = d.BranchID
    LEFT OUTER JOIN tDPT_Partc_Sync pi
            ON pi.ParticipantID = d.AuthorID
    LEFT OUTER JOIN tDPT_Partc_Sync pp
            ON pp.ParticipantID = d.OwnerID
    LEFT OUTER JOIN pAPI_Prs_ICard lp
            ON lp.SPID = 777/*var__SPID_CONSTANT*/ AND lp.PersonID = d.OwnerID AND lp.FlMain = 1 AND lp.FlDead = 0
    LEFT OUTER JOIN tDPT_Partc_Sync pc
            ON pc.ParticipantID = d.AgentID
    LEFT OUTER JOIN pAPI_Prs_ICard lc
            ON lc.SPID = 777/*var__SPID_CONSTANT*/ AND lc.ICardID = d.AgentICardID AND lc.PersonID = d.AgentID
     WHERE r.SPID = 777/*var__SPID_CONSTANT*/ AND (((111 IN (0, d.FinOperID)) AND (1 = 1)) OR ((1 = 1) AND (d.FinOperID IN (333, 444))))
     UNION ALL
    SELECT /*+ IndexScan(r ptdpt_jr_xpkptdpt_jr)
               IndexScan(l tdptlegalclientlink_xpktdptlegalclientlink)
               IndexScan(d papi_juraldoc_findlist_xpkpapi_juraldoc_findlist)
               IndexScan(f tdpt_finoper_sync_xpktdpt_finoper_sync)
               IndexScan(pb tdpt_partc_sync_xpktdpt_partc_sync)
               IndexScan(s papi_sm_currentstate_xpkpapi_sm_currentstate)
               IndexScan(pi tdpt_partc_sync_xpktdpt_partc_sync)
               IndexScan(pp tdpt_partc_sync_xpktdpt_partc_sync)
               IndexScan(lp papi_prs_icard_xie1papi_prs_icard)
               IndexScan(pc tdpt_partc_sync_xpktdpt_partc_sync)
               IndexScan(lc papi_prs_icard_xpkpapi_prs_icard) */
           /*! ForceOrder() */
           777/*var__SPID_CONSTANT*/,
           555,
           d.JRDocID,
           CASE WHEN coalesce(999, 0) > 0 THEN 999 ELSE CASE WHEN d.BranchID = d.AuthorID THEN 1 ELSE 2 END END,
           d.BranchID,
           pb.Brief,
           d.AuthorID,
           coalesce(pI.Brief, ''),
           coalesce(CASE WHEN pI.PropType = 0 THEN ltrim(rtrim(concat(ltrim(rtrim(concat(ltrim(rtrim(pI.Name)), ' ', pI.Name1))), ' ', pI.Name2))) ELSE pI.Name END, ''),
           coalesce(d.OriginalNumber, ''),
           d.DateCreation,
           d.OwnerID,
           pp.PropType,
           pp.Brief,
           CASE WHEN pp.PropType = 0 THEN concat(ltrim(rtrim(pp.Name)), ' ', ltrim(rtrim(pp.Name1)), ' ', ltrim(rtrim(pp.Name2))) ELSE ltrim(rtrim(pp.Name)) END,
           coalesce(lp.ICardID, 0),
           coalesce(lp.DocType, ''),
           coalesce(lp.RegNumber, ''),
           coalesce(lp.RegSeries, ''),
           d.AgentID,
           pc.Brief,
           CASE WHEN pc.PropType = 0 THEN concat(ltrim(rtrim(pc.Name)), ' ', ltrim(rtrim(pc.Name1)), ' ', ltrim(rtrim(pc.Name2))) ELSE ltrim(rtrim(pc.Name)) END,
           d.AgentICardID,
           coalesce(lc.DocType, ''),
           coalesce(lc.RegNumber, ''),
           coalesce(lc.RegSeries, ''),
           d.DateOper,
           d.DateAccount,
           777::bigint,
           d.PeriodMonth,
           d.DateClose,
           CASE WHEN l.Status = 2 THEN 1 WHEN l.Status = 3 THEN 2 WHEN l.Status = 4 THEN 3 ELSE 0 END,
           d.Comment,
           f.FinOperID,
           s.StateID,
           s.Brief,
           s.Name
      FROM pTDpt_JR r
    INNER JOIN tDPTLegalClientLink l
            ON l.DPTLegalClientLinkID = r.JRelID
    INNER JOIN pAPI_JuralDoc_FindList d
            ON d.SPID = 777/*var__SPID_CONSTANT*/ AND d.JRDocID = l.LegalBaseID
    INNER JOIN tDPT_FinOper_Sync f
            ON f.FinOperID = d.FinOperID
    INNER JOIN tDPT_Partc_Sync pb
            ON pb.ParticipantID = d.BranchID
    INNER JOIN pAPI_SM_CurrentState s
            ON s.SPID = 777/*var__SPID_CONSTANT*/ AND s.ID = r.JRelID
    LEFT OUTER JOIN tDPT_Partc_Sync pi
            ON pi.ParticipantID = d.AuthorID
    LEFT OUTER JOIN tDPT_Partc_Sync pp
            ON pp.ParticipantID = d.OwnerID
    LEFT OUTER JOIN pAPI_Prs_ICard lp
            ON lp.SPID = 777/*var__SPID_CONSTANT*/ AND lp.PersonID = d.OwnerID AND lp.FlMain = 1 AND lp.FlDead = 0
    LEFT OUTER JOIN tDPT_Partc_Sync pc
            ON pc.ParticipantID = d.AgentID
    LEFT OUTER JOIN pAPI_Prs_ICard lc
            ON lc.SPID = 777/*var__SPID_CONSTANT*/ AND lc.ICardID = d.AgentICardID AND lc.PersonID = d.AgentID
     WHERE r.SPID = 777/*var__SPID_CONSTANT*/ AND (((111 IN (0, d.FinOperID)) ) OR ((1 = 1) AND (d.FinOperID IN (333, 444))))
;
                                                                                         QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on papi_cacc_letterauthority
   ->  Subquery Scan on "*SELECT*"
         ->  Append
               ->  Subquery Scan on "*SELECT* 1"
                     ->  Nested Loop Left Join
                           Join Filter: (((lc.icardid)::numeric = (d.agenticardid)::numeric) AND ((lc.personid)::numeric = (d.agentid)::numeric))
                           ->  Nested Loop Left Join
                                 ->  Nested Loop Left Join
                                       Join Filter: ((lp.personid)::numeric = (d.ownerid)::numeric)
                                       ->  Nested Loop Left Join
                                             ->  Nested Loop Left Join
                                                   ->  Nested Loop Left Join
                                                         ->  Nested Loop
                                                               Join Filter: ((l.jrelid)::numeric = (s.id)::numeric)
                                                               ->  Nested Loop
                                                                     ->  Nested Loop
                                                                           Join Filter: ((l.jrdocid)::numeric = (d.jrdocid)::numeric)
                                                                           ->  Nested Loop
                                                                                 ->  Index Scan using ptdpt_jr_xpkptdpt_jr on ptdpt_jr r
                                                                                       Index Cond: ((spid)::numeric = '777'::numeric)
                                                                                 ->  Index Scan using papi_jrel_findlist_xpkpapi_jrel_findlist on papi_jrel_findlist l
                                                                                       Index Cond: (((spid)::numeric = '123'::numeric) AND ((jrelid)::numeric = (r.jrelid)::numeric))
                                                                           ->  Index Scan using papi_juraldoc_findlist_xpkpapi_juraldoc_findlist on papi_juraldoc_findlist d
                                                                                 Index Cond: ((spid)::numeric = '777'::numeric)
                                                                                 Filter: (('111'::numeric = (finoperid)::numeric) OR ((finoperid)::numeric = ANY ('{333,444}'::numeric[])))
                                                                     ->  Index Scan using tdpt_finoper_sync_xpktdpt_finoper_sync on tdpt_finoper_sync f
                                                                           Index Cond: ((finoperid)::numeric = (d.finoperid)::numeric)
                                                               ->  Index Scan using papi_sm_currentstate_xpkpapi_sm_currentstate on papi_sm_currentstate s
                                                                     Index Cond: (((spid)::numeric = '777'::numeric) AND ((id)::numeric = (r.jrelid)::numeric))
                                                         ->  Index Scan using tdpt_partc_sync_xpktdpt_partc_sync on tdpt_partc_sync pb
                                                               Index Cond: ((participantid)::numeric = (d.branchid)::numeric)
                                                   ->  Index Scan using tdpt_partc_sync_xpktdpt_partc_sync on tdpt_partc_sync pi
                                                         Index Cond: ((participantid)::numeric = (d.authorid)::numeric)
                                             ->  Index Scan using tdpt_partc_sync_xpktdpt_partc_sync on tdpt_partc_sync pp
                                                   Index Cond: ((participantid)::numeric = (d.ownerid)::numeric)
                                       ->  Index Scan using papi_prs_icard_xie1papi_prs_icard on papi_prs_icard lp
                                             Index Cond: ((spid)::numeric = '777'::numeric)
                                             Filter: (((flmain)::smallint = 1) AND ((fldead)::smallint = 0))
                                 ->  Index Scan using tdpt_partc_sync_xpktdpt_partc_sync on tdpt_partc_sync pc
                                       Index Cond: ((participantid)::numeric = (d.agentid)::numeric)
                           ->  Index Scan using papi_prs_icard_xpkpapi_prs_icard on papi_prs_icard lc
                                 Index Cond: ((spid)::numeric = '777'::numeric)
               ->  Nested Loop Left Join
                     Join Filter: (((lc_1.icardid)::numeric = (d_1.agenticardid)::numeric) AND ((lc_1.personid)::numeric = (d_1.agentid)::numeric))
                     ->  Nested Loop Left Join
                           ->  Nested Loop Left Join
                                 Join Filter: ((lp_1.personid)::numeric = (d_1.ownerid)::numeric)
                                 ->  Nested Loop Left Join
                                       ->  Nested Loop Left Join
                                             ->  Nested Loop
                                                   ->  Nested Loop
                                                         ->  Nested Loop
                                                               ->  Nested Loop
                                                                     ->  Nested Loop
                                                                           ->  Index Scan using ptdpt_jr_xpkptdpt_jr on ptdpt_jr r_1
                                                                                 Index Cond: ((spid)::numeric = '777'::numeric)
                                                                           ->  Index Scan using tdptlegalclientlink_xpktdptlegalclientlink on tdptlegalclientlink l_1
                                                                                 Index Cond: ((dptlegalclientlinkid)::numeric = (r_1.jrelid)::numeric)
                                                                     ->  Index Scan using papi_juraldoc_findlist_xpkpapi_juraldoc_findlist on papi_juraldoc_findlist d_1
                                                                           Index Cond: (((spid)::numeric = '777'::numeric) AND ((jrdocid)::numeric = (l_1.legalbaseid)::numeric))
                                                                           Filter: (('111'::numeric = (finoperid)::numeric) OR ((finoperid)::numeric = ANY ('{333,444}'::numeric[])))
                                                               ->  Index Scan using tdpt_finoper_sync_xpktdpt_finoper_sync on tdpt_finoper_sync f_1
                                                                     Index Cond: ((finoperid)::numeric = (d_1.finoperid)::numeric)
                                                         ->  Index Scan using tdpt_partc_sync_xpktdpt_partc_sync on tdpt_partc_sync pb_1
                                                               Index Cond: ((participantid)::numeric = (d_1.branchid)::numeric)
                                                   ->  Index Scan using papi_sm_currentstate_xpkpapi_sm_currentstate on papi_sm_currentstate s_1
                                                         Index Cond: (((spid)::numeric = '777'::numeric) AND ((id)::numeric = (l_1.dptlegalclientlinkid)::numeric))
                                             ->  Index Scan using tdpt_partc_sync_xpktdpt_partc_sync on tdpt_partc_sync pi_1
                                                   Index Cond: ((participantid)::numeric = (d_1.authorid)::numeric)
                                       ->  Index Scan using tdpt_partc_sync_xpktdpt_partc_sync on tdpt_partc_sync pp_1
                                             Index Cond: ((participantid)::numeric = (d_1.ownerid)::numeric)
                                 ->  Index Scan using papi_prs_icard_xie1papi_prs_icard on papi_prs_icard lp_1
                                       Index Cond: ((spid)::numeric = '777'::numeric)
                                       Filter: (((flmain)::smallint = 1) AND ((fldead)::smallint = 0))
                           ->  Index Scan using tdpt_partc_sync_xpktdpt_partc_sync on tdpt_partc_sync pc_1
                                 Index Cond: ((participantid)::numeric = (d_1.agentid)::numeric)
                     ->  Index Scan using papi_prs_icard_xpkpapi_prs_icard on papi_prs_icard lc_1
                           Index Cond: ((spid)::numeric = '777'::numeric)
(78 rows)
 
--zip_12633.sql
explain (costs off)
    INSERT INTO pAPI_ChAcc_FndLstIDChange
    (
        SPID,
        ChartAccID,
        ChangeKind,
        ChangeDate
    )
    SELECT /*+ IndexScan(aa taudit_xie4taudit)
               IndexScan(r tresource_xpktresource) */
           /*! ForceOrder() */
           999,
           r.ResourceID,
           CASE WHEN aa.Action = 1 THEN 1 WHEN aa.Action = 2 THEN 3 ELSE 2 END,
           aa.InDateTime
      FROM tAudit aa
    INNER JOIN tResource r
            ON r.ResourceID = aa.ObjectID AND r.ResourceType = 0
     WHERE aa.InDateTime BETWEEN '20000101' AND '20010101' AND lower(aa.ObjectName)::DSFIELDNAMEVAR = 'tresource' AND aa.Action IN (1, 2)
     UNION
    SELECT /*+ IndexScan(aa taudit_xie4taudit)
               IndexScan(r hresource_xpkhresource) */
           /*! ForceOrder() */
           999,
           r.ResourceID,
           CASE WHEN aa.Action = 1 THEN 1 WHEN aa.Action = 2 THEN 3 ELSE 2 END,
           aa.InDateTime
      FROM tAudit aa
    INNER JOIN hResource r
            ON r.HistoryHeaderID = aa.AuditID AND r.ResourceType = 0
     WHERE aa.InDateTime BETWEEN '20000101' AND '20010101' AND lower(aa.ObjectName)::DSFIELDNAMEVAR = 'tresource' AND aa.Action IN (1, 2)
     UNION
    SELECT /*+ IndexScan(aa taudit_xie4taudit)
               IndexScan(r hresource_xpkhresource) */
           /*! ForceOrder() */
           999,
           aa.ObjectID,
           4,
           aa.InDateTime
      FROM tAudit aa
    INNER JOIN hResource r
            ON r.HistoryHeaderID = aa.AuditID AND r.ResourceType = 0
     WHERE aa.InDateTime BETWEEN '20000101' AND '20010101' AND lower(aa.ObjectName)::DSFIELDNAMEVAR = 'tresource' AND aa.Action = 3
;
                                                                                                                           QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on papi_chacc_fndlstidchange
   ->  Subquery Scan on "*SELECT*"
         ->  HashAggregate
               Group Key: (999), r.resourceid, (CASE WHEN ((aa.action)::smallint = 1) THEN 1 WHEN ((aa.action)::smallint = 2) THEN 3 ELSE 2 END), aa.indatetime
               ->  Append
                     ->  Nested Loop
                           ->  Index Scan using taudit_xie4taudit on taudit aa
                                 Index Cond: (((indatetime)::timestamp without time zone >= 'Sat Jan 01 00:00:00 2000'::timestamp without time zone) AND ((indatetime)::timestamp without time zone <= 'Mon Jan 01 00:00:00 2001'::timestamp without time zone))
                                 Filter: (((action)::smallint = ANY ('{1,2}'::integer[])) AND ((lower((objectname)::text))::text = 'tresource'::text))
                           ->  Index Scan using tresource_xpktresource on tresource r
                                 Index Cond: ((resourceid)::numeric = (aa.objectid)::numeric)
                                 Filter: ((resourcetype)::smallint = 0)
                     ->  Nested Loop
                           ->  Index Scan using taudit_xie4taudit on taudit aa_1
                                 Index Cond: (((indatetime)::timestamp without time zone >= 'Sat Jan 01 00:00:00 2000'::timestamp without time zone) AND ((indatetime)::timestamp without time zone <= 'Mon Jan 01 00:00:00 2001'::timestamp without time zone))
                                 Filter: (((action)::smallint = ANY ('{1,2}'::integer[])) AND ((lower((objectname)::text))::text = 'tresource'::text))
                           ->  Index Scan using hresource_xpkhresource on hresource r_1
                                 Index Cond: ((historyheaderid)::numeric = (aa_1.auditid)::numeric)
                                 Filter: ((resourcetype)::smallint = 0)
                     ->  Nested Loop
                           ->  Index Scan using taudit_xie4taudit on taudit aa_2
                                 Index Cond: (((indatetime)::timestamp without time zone >= 'Sat Jan 01 00:00:00 2000'::timestamp without time zone) AND ((indatetime)::timestamp without time zone <= 'Mon Jan 01 00:00:00 2001'::timestamp without time zone))
                                 Filter: (((action)::smallint = 3) AND ((lower((objectname)::text))::text = 'tresource'::text))
                           ->  Index Scan using hresource_xpkhresource on hresource r_2
                                 Index Cond: ((historyheaderid)::numeric = (aa_2.auditid)::numeric)
                                 Filter: ((resourcetype)::smallint = 0)
(26 rows)
 
--zip_35843.sql
explain (costs off)
      UPDATE /*+ IndexScan(tpoolstorerest tpoolstorerest_xpktpoolstorerest) */
             tPoolStoreRest
         SET Flag = Flag & -2
            ,DocDealProtID = 0
       WHERE PoolStoreRestID IN (      SELECT /*+ IndexScan(tpoolstorerest tpoolstorerest_xie3tpoolstorerest) */
             PoolStoreRestID
        FROM tPoolStoreRest
       WHERE DocDealProtID = 777)
;
                                               QUERY PLAN
---------------------------------------------------------------------------------------------------------
 Update on tpoolstorerest
   ->  Nested Loop
         ->  HashAggregate
               Group Key: (tpoolstorerest_1.poolstorerestid)::numeric
               ->  Index Scan using tpoolstorerest_xie3tpoolstorerest on tpoolstorerest tpoolstorerest_1
                     Index Cond: ((docdealprotid)::numeric = '777'::numeric)
         ->  Index Scan using tpoolstorerest_xpktpoolstorerest on tpoolstorerest
               Index Cond: ((poolstorerestid)::numeric = (tpoolstorerest_1.poolstorerestid)::numeric)
(8 rows)
 
--zip_05675.sql
explain (costs off)
          INSERT INTO pAPI_SM_FindParamProtocol
          (
              SPID,
              ObjectID,
              ProtocolID,
              StateOrder,
              ActionID,
              ActionBrief,
              ActionName,
              ActionType,
              Date,
              AuditID,
              Incomplete,
              StateID
          )
          SELECT /*+ IndexScan(o padm_sm_paramobject_xak1padm_sm_paramobject)
                     IndexScan(p tprotocol_xak1tprotocol)
                     IndexScan(t ttransition_xpkttransition)
                     IndexScan(n1 tnode_xpktnode)
                     IndexScan(na1 tnodeattr_xpktnodeattr)
                     IndexScan(s tprotocolsuspend_xpktprotocolsuspend) */
                 /*! ForceOrder() */
                 777/*var__SPID_CONSTANT*/,
                 o.ID,
                 p.ProtocolID,
                 p.StateOrder,
                 coalesce(n1.NodeID, 0),
                 coalesce(n1.Brief, ''),
                 coalesce(n1.Name, ''),
                 coalesce(na1.PropVal, 0),
                 p.Date,
                 p.AuditID,
                 CASE WHEN coalesce(s.ProtocolID, 0) = 0 THEN 0 ELSE 1 END,
                 t.TargetStateID
            FROM pADM_SM_ParamObject o
          INNER JOIN tProtocol p
                  ON p.ObjectID = o.ObjectID AND p.Date BETWEEN o.DateStart AND o.DateEnd
          INNER JOIN tTransition t
                  ON t.TransitionID = p.TransitionID
          INNER JOIN tNode n1
                  ON n1.NodeID = t.TargetStateID
          LEFT OUTER JOIN tNodeAttr na1
                  ON na1.NodeID = n1.NodeID
          LEFT OUTER JOIN tProtocolSuspend s
                  ON s.ProtocolID = p.ProtocolID
           WHERE o.SPID = 776/*var__SPID_CONSTANT*/ AND o.IsPFO = 0 AND o.AutoID BETWEEN 111 AND 222 AND (
           EXISTS(          SELECT /*+ IndexScan(poa papi_sm_paramobjectaction_xpkpapi_sm_paramobjectaction) */
                 1
            FROM pAPI_SM_ParamObjectAction poa
           WHERE poa.spid = 777/*var__SPID_CONSTANT*/ AND poa.ActionID = n1.NodeID AND poa.ActionType = -1) OR
           EXISTS(          SELECT /*+ IndexScan(poa papi_sm_paramobjectaction_xak1papi_sm_paramobjectaction) */
                 1
            FROM pAPI_SM_ParamObjectAction poa
           WHERE poa.spid = 778/*var__SPID_CONSTANT*/ AND poa.ActionID = -1 AND poa.ActionType = na1.PropVal) OR
           EXISTS(          SELECT /*+ IndexScan(poa papi_sm_paramobjectaction_xpkpapi_sm_paramobjectaction) */
                 1
            FROM pAPI_SM_ParamObjectAction poa
           WHERE poa.spid = 779/*var__SPID_CONSTANT*/ AND poa.ActionID = n1.NodeID AND poa.ActionType = na1.PropVal))
;
                                                                                                        QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on papi_sm_findparamprotocol
   ->  Nested Loop Left Join
         ->  Nested Loop Left Join
               Filter: ((hashed SubPlan 2) OR (hashed SubPlan 4) OR (SubPlan 5))
               ->  Nested Loop
                     ->  Nested Loop
                           ->  Nested Loop
                                 ->  Index Scan using padm_sm_paramobject_xak1padm_sm_paramobject on padm_sm_paramobject o
                                       Index Cond: (((spid)::numeric = '776'::numeric) AND ((ispfo)::smallint = 0) AND ((autoid)::numeric >= '111'::numeric) AND ((autoid)::numeric <= '222'::numeric))
                                 ->  Index Scan using tprotocol_xak1tprotocol on tprotocol p
                                       Index Cond: ((objectid)::numeric = (o.objectid)::numeric)
                                       Filter: (((date)::timestamp without time zone >= (o.datestart)::timestamp without time zone) AND ((date)::timestamp without time zone <= (o.dateend)::timestamp without time zone))
                           ->  Index Scan using ttransition_xpkttransition on ttransition t
                                 Index Cond: ((transitionid)::numeric = (p.transitionid)::numeric)
                     ->  Index Scan using tnode_xpktnode on tnode n1
                           Index Cond: ((nodeid)::numeric = (t.targetstateid)::numeric)
               ->  Index Scan using tnodeattr_xpktnodeattr on tnodeattr na1
                     Index Cond: ((nodeid)::numeric = (n1.nodeid)::numeric)
               SubPlan 2
                 ->  Index Scan using papi_sm_paramobjectaction_xpkpapi_sm_paramobjectaction on papi_sm_paramobjectaction poa
                       Index Cond: (((spid)::numeric = '777'::numeric) AND ((actiontype)::integer = '-1'::integer))
               SubPlan 4
                 ->  Index Scan using papi_sm_paramobjectaction_xak1papi_sm_paramobjectaction on papi_sm_paramobjectaction poa_1
                       Index Cond: (((spid)::numeric = '778'::numeric) AND ((actionid)::numeric = '-1'::numeric))
               SubPlan 5
                 ->  Index Scan using papi_sm_paramobjectaction_xpkpapi_sm_paramobjectaction on papi_sm_paramobjectaction poa_2
                       Index Cond: (((spid)::numeric = '779'::numeric) AND ((actionid)::numeric = (n1.nodeid)::numeric) AND ((actiontype)::integer = (na1.propval)::integer))
         ->  Index Scan using tprotocolsuspend_xpktprotocolsuspend on tprotocolsuspend s
               Index Cond: ((protocolid)::numeric = (p.protocolid)::numeric)
(29 rows)
 
--06446.sql
explain (costs off)
        SELECT /*+ IndexScan(lb tlegalbase_xie1tlegalbase)
                   IndexScan(o tobject_xak2tobject)
                   IndexScan(p tprotocol_xpktprotocol)
                   IndexScan(t ttransition_xpkttransition)
                   IndexScan(n tnode_xpktnode) */
               /*! ForceOrder() */
               lb.LegalBaseID,
               lb.InstrumentID,
               lb.BranchID
          FROM tLegalBase lb, tObject o, tProtocol p, tTransition t, tNode n
         WHERE lb.InstParentID = 123 AND o.InstrumentID = lb.InstrumentID AND o.ID = lb.LegalBaseID AND p.ProtocolID = o.CurrProtocolID AND t.TransitionID = p.TransitionID AND n.NodeID = t.TargetStateID AND n.StateType <> 16
         UNION
        SELECT /*+ IndexScan(lb tlegalbase_xie3tlegalbase)
                   IndexScan(o tobject_xak2tobject)
                   IndexScan(p tprotocol_xpktprotocol)
                   IndexScan(t ttransition_xpkttransition)
                   IndexScan(n tnode_xpktnode) */
               /*! ForceOrder() */
               lb.LegalBaseID,
               lb.InstrumentID,
               lb.BranchID
          FROM tLegalBase lb, tObject o, tProtocol p, tTransition t, tNode n
         WHERE lb.InstChildID = 123 AND o.InstrumentID = lb.InstrumentID AND o.ID = lb.LegalBaseID AND p.ProtocolID = o.CurrProtocolID AND t.TransitionID = p.TransitionID AND n.NodeID = t.TargetStateID AND n.StateType <> 16
;
                                                                              QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Unique
   ->  Sort
         Sort Key: lb.legalbaseid, lb.instrumentid, lb.branchid
         ->  Append
               ->  Nested Loop
                     ->  Nested Loop
                           ->  Nested Loop
                                 ->  Nested Loop
                                       ->  Index Scan using tlegalbase_xie1tlegalbase on tlegalbase lb
                                             Index Cond: ((instparentid)::numeric = '123'::numeric)
                                       ->  Index Scan using tobject_xak2tobject on tobject o
                                             Index Cond: (((instrumentid)::numeric = (lb.instrumentid)::numeric) AND ((id)::numeric = (lb.legalbaseid)::numeric))
                                 ->  Index Scan using tprotocol_xpktprotocol on tprotocol p
                                       Index Cond: ((protocolid)::numeric = (o.currprotocolid)::numeric)
                           ->  Index Scan using ttransition_xpkttransition on ttransition t
                                 Index Cond: ((transitionid)::numeric = (p.transitionid)::numeric)
                     ->  Index Scan using tnode_xpktnode on tnode n
                           Index Cond: ((nodeid)::numeric = (t.targetstateid)::numeric)
                           Filter: ((statetype)::numeric <> '16'::numeric)
               ->  Nested Loop
                     ->  Nested Loop
                           ->  Nested Loop
                                 ->  Nested Loop
                                       ->  Index Scan using tlegalbase_xie3tlegalbase on tlegalbase lb_1
                                             Index Cond: ((instchildid)::numeric = '123'::numeric)
                                       ->  Index Scan using tobject_xak2tobject on tobject o_1
                                             Index Cond: (((instrumentid)::numeric = (lb_1.instrumentid)::numeric) AND ((id)::numeric = (lb_1.legalbaseid)::numeric))
                                 ->  Index Scan using tprotocol_xpktprotocol on tprotocol p_1
                                       Index Cond: ((protocolid)::numeric = (o_1.currprotocolid)::numeric)
                           ->  Index Scan using ttransition_xpkttransition on ttransition t_1
                                 Index Cond: ((transitionid)::numeric = (p_1.transitionid)::numeric)
                     ->  Index Scan using tnode_xpktnode on tnode n_1
                           Index Cond: ((nodeid)::numeric = (t_1.targetstateid)::numeric)
                           Filter: ((statetype)::numeric <> '16'::numeric)
(34 rows)
 
--06547.sql
explain (costs off)
    INSERT INTO pAPI_Lawsuit_Notification
    (
        spid,
        LawsuitID,
        NTFID,
        NTFMessage
    )
    SELECT /*+ IndexScan(p papi_lawsuit_massupdate_xpkpapi_lawsuit_massupdate) */
           spid,
           LawsuitID,
           500146,
           'aaa'
      FROM pAPI_Lawsuit_MassUpdate p
     WHERE p.spid = 999 AND (p.BranchBrief <> '' OR p.BranchID <> 0) AND NOT EXISTS(    SELECT /*+ IndexScan(n papi_lawsuit_notification_xpkpapi_lawsuit_notification) */
           1
      FROM pAPI_Lawsuit_Notification n
     WHERE n.spid = 999 AND n.LawsuitID = p.LawsuitID) AND NOT EXISTS(    SELECT /*+ IndexScan(i tinstitution_xpktinstitution) */
           1
      FROM tInstitution i
     WHERE i.InstitutionID = p.BranchID AND i.InstType IN (1, 2, 3)) AND NOT EXISTS(    SELECT /*+ IndexScan(i tinstitution_xak2tinstitution) */
           1
      FROM tInstitution i
     WHERE lower(i.Brief)::DSACCNUMBER = lower(p.BranchBrief)::DSACCNUMBER AND i.PropDealPart = 1 AND i.InstType IN (1, 2, 3))
;
                                                           QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------
 Insert on papi_lawsuit_notification
   ->  Nested Loop Anti Join
         Join Filter: ((lower((i_1.brief)::text))::bpchar = (lower((p.branchbrief)::text))::bpchar)
         ->  Nested Loop Anti Join
               ->  Nested Loop Anti Join
                     ->  Index Scan using papi_lawsuit_massupdate_xpkpapi_lawsuit_massupdate on papi_lawsuit_massupdate p
                           Index Cond: ((spid)::numeric = '999'::numeric)
                           Filter: (((branchbrief)::bpchar <> ''::bpchar) OR ((branchid)::numeric <> '0'::numeric))
                     ->  Index Scan using papi_lawsuit_notification_xpkpapi_lawsuit_notification on papi_lawsuit_notification n
                           Index Cond: (((spid)::numeric = '999'::numeric) AND ((lawsuitid)::numeric = (p.lawsuitid)::numeric))
               ->  Index Scan using tinstitution_xpktinstitution on tinstitution i
                     Index Cond: ((institutionid)::numeric = (p.branchid)::numeric)
                     Filter: ((insttype)::smallint = ANY ('{1,2,3}'::integer[]))
         ->  Index Scan using tinstitution_xak2tinstitution on tinstitution i_1
               Index Cond: ((propdealpart)::smallint = 1)
               Filter: ((insttype)::smallint = ANY ('{1,2,3}'::integer[]))
(16 rows)
 
--11623.sql
explain (costs off)
    INSERT INTO pGNA_FindListByParam
    (
        SPID,
        LinkID,
        TypeAccLinkID,
        CntTypeAccLink,
        LinkCrnID,
        ResidentFlag
    )
    SELECT /*+ IndexScan(p papi_gna_param_xpkpapi_gna_param)
               IndexScan(i tinstitution_xpktinstitution)
               IndexScan(ir papi_finoper_findlst_xpkpapi_finoper_findlst)
               IndexScan(ta ttypeacclink_xie3ttypeacclink)
               IndexScan(l tlinkedacctype_xpktlinkedacctype) */
           /*! ForceOrder() */
           999,
           p.LinkID,
           ta.TypeAccLinkID,
           1,
           p.LinkCrnID,
           ta.IsResident
      FROM pAPI_GNA_Param p
    INNER JOIN tInstitution i
            ON i.InstitutionID = p.BranchID
    INNER JOIN pAPI_FinOper_FindLst ir
            ON ir.SPID = 999 AND ir.FinOperID = p.RelTypeID AND ir.InterfaceObjectID <> 137
    INNER JOIN tTypeAccLink ta
            ON ta.RelType = p.RelType AND ta.LinkType = 1 AND ta.ObjectID = p.RelTypeID
    INNER JOIN tLinkedAccType l
            ON l.LinkedAccTypeID = ta.AccType
     WHERE p.SPID = 999 AND 1 = 1 AND NOT EXISTS(    SELECT /*+ IndexScan(e papi_gna_fndlstbyparamntf_xpkpapi_gna_fndlstbyparamntf) */
           1
      FROM pAPI_GNA_FndLstByParamNtf e
     WHERE e.SPID = 999 AND e.LinkID = p.LinkID) AND NOT EXISTS(    SELECT /*+ IndexScan(e pgna_findlistbyparam_xpkpgna_findlistbyparam) */
           1
      FROM pGNA_FindListByParam e
     WHERE e.SPID = 999 AND e.LinkID = p.LinkID) AND p.TypeID IN (0, ta.AccType) AND p.SysTypeID IN (0, l.PropVal) AND (444 = 1 OR (ta.DateFrom <= p.Date AND (ta.DateTo = CAST('19000101' AS TIMESTAMP) OR ta.DateTo >= p.Date))) AND (ta.BranchID = p.BranchID OR ta.BranchID = i.ParentID AND NOT EXISTS(    SELECT /*+ IndexScan(ta ttypeacclink_xie3ttypeacclink)
               IndexScan(fo papi_finoper_findlst_xpkpapi_finoper_findlst)
               IndexScan(l tlinkedacctype_xpktlinkedacctype) */
           1
      FROM tTypeAccLink ta
    INNER JOIN pAPI_FinOper_FindLst fo
            ON fo.SPID = 999 AND fo.FinOperID = ta.ObjectID AND fo.InterfaceObjectID <> 137
    INNER JOIN tLinkedAccType l
            ON l.LinkedAccTypeID = ta.AccType
     WHERE ta.RelType = p.RelType AND ta.LinkType = 1 AND ta.ObjectID = p.RelTypeID AND p.TypeID IN (0, ta.AccType) AND p.SysTypeID IN (0, l.PropVal) AND (444 = 1 OR (ta.DateFrom <= p.Date AND (ta.DateTo = CAST('19000101' AS TIMESTAMP) OR ta.DateTo >= p.Date))) AND ta.BranchID = p.BranchID) OR ta.BranchID = 0 AND NOT EXISTS(    SELECT /*+ IndexScan(ta ttypeacclink_xie3ttypeacclink)
               IndexScan(fo papi_finoper_findlst_xpkpapi_finoper_findlst)
               IndexScan(l tlinkedacctype_xpktlinkedacctype) */
           1
      FROM tTypeAccLink ta
    INNER JOIN pAPI_FinOper_FindLst fo
            ON fo.SPID = 999 AND fo.FinOperID = ta.ObjectID AND fo.InterfaceObjectID <> 137
    INNER JOIN tLinkedAccType l
            ON l.LinkedAccTypeID = ta.AccType
     WHERE ta.RelType = p.RelType AND ta.LinkType = 1 AND ta.ObjectID = p.RelTypeID AND p.TypeID IN (0, ta.AccType) AND p.SysTypeID IN (0, l.PropVal) AND (444 = 1 OR (ta.DateFrom <= p.Date AND (ta.DateTo = CAST('19000101' AS TIMESTAMP) OR ta.DateTo >= p.Date))) AND (ta.BranchID = p.BranchID OR ta.BranchID = i.ParentID))) AND ta.FundID = 0 AND (p.ResidentFlag = ta.IsResident OR p.ResidentFlag = 3)
;
                                                                                                                                                                                                                                                                       QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on pgna_findlistbyparam
   ->  Nested Loop Anti Join
         Join Filter: ((e_1.linkid)::numeric = (p.linkid)::numeric)
         ->  Nested Loop Anti Join
               ->  Nested Loop
                     Join Filter: (((p.systypeid)::numeric = '0'::numeric) OR ((p.systypeid)::numeric = (l.propval)::numeric))
                     ->  Nested Loop
                           Join Filter: (((ir.finoperid)::numeric = (ta.objectid)::numeric) AND (((ta.branchid)::numeric = (p.branchid)::numeric) OR (((ta.branchid)::numeric = (i.parentid)::numeric) AND (NOT (SubPlan 1))) OR (((ta.branchid)::numeric = '0'::numeric) AND (NOT (SubPlan 2)))))
                           ->  Nested Loop
                                 Join Filter: ((p.reltypeid)::numeric = (ir.finoperid)::numeric)
                                 ->  Nested Loop
                                       ->  Index Scan using papi_gna_param_xpkpapi_gna_param on papi_gna_param p
                                             Index Cond: ((spid)::numeric = '999'::numeric)
                                       ->  Index Scan using tinstitution_xpktinstitution on tinstitution i
                                             Index Cond: ((institutionid)::numeric = (p.branchid)::numeric)
                                 ->  Index Scan using papi_finoper_findlst_xpkpapi_finoper_findlst on papi_finoper_findlst ir
                                       Index Cond: ((spid)::numeric = '999'::numeric)
                                       Filter: ((interfaceobjectid)::numeric <> '137'::numeric)
                           ->  Index Scan using ttypeacclink_xie3ttypeacclink on ttypeacclink ta
                                 Index Cond: (((reltype)::numeric = (p.reltype)::numeric) AND ((linktype)::numeric = '1'::numeric) AND ((objectid)::numeric = (p.reltypeid)::numeric))
                                 Filter: (((fundid)::numeric = '0'::numeric) AND ((datefrom)::timestamp without time zone <= (p.date)::timestamp without time zone) AND (((p.typeid)::numeric = '0'::numeric) OR ((p.typeid)::numeric = (acctype)::numeric)) AND (((dateto)::timestamp without time zone = 'Mon Jan 01 00:00:00 1900'::timestamp without time zone) OR ((dateto)::timestamp without time zone >= (p.date)::timestamp without time zone)) AND (((p.residentflag)::numeric = (isresident)::numeric) OR ((p.residentflag)::smallint = 3)))
                           SubPlan 1
                             ->  Nested Loop
                                   ->  Nested Loop
                                         ->  Index Scan using ttypeacclink_xie3ttypeacclink on ttypeacclink ta_1
                                               Index Cond: (((reltype)::numeric = (p.reltype)::numeric) AND ((linktype)::numeric = '1'::numeric) AND ((objectid)::numeric = (p.reltypeid)::numeric))
                                               Filter: (((datefrom)::timestamp without time zone <= (p.date)::timestamp without time zone) AND ((branchid)::numeric = (p.branchid)::numeric) AND (((p.typeid)::numeric = '0'::numeric) OR ((p.typeid)::numeric = (acctype)::numeric)) AND (((dateto)::timestamp without time zone = 'Mon Jan 01 00:00:00 1900'::timestamp without time zone) OR ((dateto)::timestamp without time zone >= (p.date)::timestamp without time zone)))
                                         ->  Index Scan using papi_finoper_findlst_xpkpapi_finoper_findlst on papi_finoper_findlst fo
                                               Index Cond: (((spid)::numeric = '999'::numeric) AND ((finoperid)::numeric = (p.reltypeid)::numeric))
                                               Filter: ((interfaceobjectid)::numeric <> '137'::numeric)
                                   ->  Index Scan using tlinkedacctype_xpktlinkedacctype on tlinkedacctype l_1
                                         Index Cond: ((linkedacctypeid)::numeric = (ta_1.acctype)::numeric)
                                         Filter: (((p.systypeid)::numeric = '0'::numeric) OR ((p.systypeid)::numeric = (propval)::numeric))
                           SubPlan 2
                             ->  Nested Loop
                                   ->  Nested Loop
                                         ->  Index Scan using ttypeacclink_xie3ttypeacclink on ttypeacclink ta_2
                                               Index Cond: (((reltype)::numeric = (p.reltype)::numeric) AND ((linktype)::numeric = '1'::numeric) AND ((objectid)::numeric = (p.reltypeid)::numeric))
                                               Filter: (((datefrom)::timestamp without time zone <= (p.date)::timestamp without time zone) AND (((p.typeid)::numeric = '0'::numeric) OR ((p.typeid)::numeric = (acctype)::numeric)) AND (((dateto)::timestamp without time zone = 'Mon Jan 01 00:00:00 1900'::timestamp without time zone) OR ((dateto)::timestamp without time zone >= (p.date)::timestamp without time zone)) AND (((branchid)::numeric = (p.branchid)::numeric) OR ((branchid)::numeric = (i.parentid)::numeric)))
                                         ->  Index Scan using papi_finoper_findlst_xpkpapi_finoper_findlst on papi_finoper_findlst fo_1
                                               Index Cond: (((spid)::numeric = '999'::numeric) AND ((finoperid)::numeric = (p.reltypeid)::numeric))
                                               Filter: ((interfaceobjectid)::numeric <> '137'::numeric)
                                   ->  Index Scan using tlinkedacctype_xpktlinkedacctype on tlinkedacctype l_2
                                         Index Cond: ((linkedacctypeid)::numeric = (ta_2.acctype)::numeric)
                                         Filter: (((p.systypeid)::numeric = '0'::numeric) OR ((p.systypeid)::numeric = (propval)::numeric))
                     ->  Index Scan using tlinkedacctype_xpktlinkedacctype on tlinkedacctype l
                           Index Cond: ((linkedacctypeid)::numeric = (ta.acctype)::numeric)
               ->  Index Scan using papi_gna_fndlstbyparamntf_xpkpapi_gna_fndlstbyparamntf on papi_gna_fndlstbyparamntf e
                     Index Cond: (((spid)::numeric = '999'::numeric) AND ((linkid)::numeric = (p.linkid)::numeric))
         ->  Index Scan using pgna_findlistbyparam_xpkpgna_findlistbyparam on pgna_findlistbyparam e_1
               Index Cond: ((spid)::numeric = '999'::numeric)
(51 rows)
 
--18527.sql
explain (costs off)
  INSERT INTO tDocMark
  (
      SPID,
      Type,
      ID
  )
  SELECT /*+ IndexScan(p papi_prmd_attriblist_xpkpapi_prmd_attriblist) */
         /*! ForceOrder() */
         999,
         555,
         p.PrmDID
    FROM pAPI_PrmD_AttribList p
   WHERE p.SPID = 999 AND p.Date = coalesce(p.Date) AND p.FinOperID = coalesce(p.FinOperID) AND p.DocumentType = coalesce(p.DocumentType) AND 1 = (CASE 1 WHEN 0 THEN 1 ELSE CASE WHEN (EXISTS(  SELECT /*+ IndexScan(cs papi_cashorder_cashsymbol_xie1papi_cashorder_cashsymbol) */
         1
    FROM pAPI_CashOrder_CashSymbol cs
   WHERE cs.spid = 999 AND cs.CashOrderID = p.PrmDID AND cs.SymbolTypeFlag = 111)) OR EXISTS(  SELECT /*+ IndexScan(a tdptaccountlink_xie1tdptaccountlink) */
         1
    FROM tDPTAccountLink a
   WHERE a.ObjectID = 222 AND a.Flags > 100 AND a.AccountID = (CASE 111 WHEN 1 THEN p.CreditAccountID WHEN 2 THEN p.DebitAccountID ELSE 0 END)) OR EXISTS(  SELECT /*+ IndexScan(a pdpt_objectbytype_xpkpdpt_objectbytype) */
         1
    FROM pDPT_ObjectByType a
   WHERE a.spid = 999 AND a.ID = p.PrmDID AND a.Type = 111) THEN 1 ELSE 0 END END)
;
                                                                                                                                                           QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Insert on tdocmark
   InitPlan 3 (returns $2)
     ->  Index Scan using tdptaccountlink_xie1tdptaccountlink on tdptaccountlink a
           Index Cond: ((objectid)::numeric = '222'::numeric)
           Filter: (((flags)::integer > 100) AND ((accountid)::numeric = '0'::numeric))
   ->  Index Scan using papi_prmd_attriblist_xpkpapi_prmd_attriblist on papi_prmd_attriblist p
         Index Cond: ((spid)::numeric = '999'::numeric)
         Filter: (((date)::timestamp without time zone = (COALESCE(date))::timestamp without time zone) AND ((finoperid)::numeric = (COALESCE(finoperid))::numeric) AND ((documenttype)::smallint = (COALESCE(documenttype))::smallint) AND (1 = CASE WHEN ((hashed SubPlan 2) OR $2 OR (hashed SubPlan 5)) THEN 1 ELSE 0 END))
         SubPlan 2
           ->  Index Scan using papi_cashorder_cashsymbol_xie1papi_cashorder_cashsymbol on papi_cashorder_cashsymbol cs
                 Index Cond: ((spid)::numeric = '999'::numeric)
                 Filter: ((symboltypeflag)::smallint = 111)
         SubPlan 5
           ->  Index Scan using pdpt_objectbytype_xpkpdpt_objectbytype on pdpt_objectbytype a_1
                 Index Cond: (((spid)::numeric = '999'::numeric) AND ((type)::integer = 111))
(15 rows)
 
--21239.sql
explain (costs off)
        INSERT INTO pAPI_RuleDoc_CsOrdSubAccount
        (
            SPID,
            LinkID,
            Number,
            Amount,
            Text
        )
        SELECT /*+ IndexScan(sub pgaapallsubcontoresource_xak1allsubcontoresource)
                   IndexScan(d tdepartment_xpktdepartment)
                   IndexScan(p pdoccas_xpkpdoccas) */
               /*! ForceOrder() */
               999,
               p.DocLinkID,
               CASE WHEN 0 = 0 AND rtrim(d.Brief) = '543' THEN CAST(d.Brief AS int) ELSE 0 END,
               coalesce(p.CashQty1, 0),
               d.Name
          FROM pGAAPAllSubcontoResource sub, tDepartment d, pDocCas p
         WHERE sub.SPID = 999 AND p.SPID = 999 AND p.DocLinkID = sub.ID AND d.DepartmentID = sub.DepID1
         UNION ALL
        SELECT /*+ IndexScan(sub pgaapallsubcontoresource_xak1allsubcontoresource)
                   IndexScan(d tdepartment_xpktdepartment)
                   IndexScan(p pdoccas_xpkpdoccas) */
               /*! ForceOrder() */
               999,
               p.DocLinkID,
               CASE WHEN 0 = 0 AND rtrim(d.Brief) = '765' THEN CAST(d.Brief AS int) ELSE 0 END,
               coalesce(p.CashQty2, 0),
               d.Name
          FROM pGAAPAllSubcontoResource sub, tDepartment d, pDocCas p
         WHERE sub.SPID = 999 AND p.SPID = 999 AND p.DocLinkID = sub.ID AND d.DepartmentID = sub.DepID2
;
                                                               QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------
 Insert on papi_ruledoc_csordsubaccount
   ->  Result
         ->  Append
               ->  Subquery Scan on "*SELECT* 1"
                     ->  Nested Loop
                           Join Filter: ((sub.id)::numeric = (p.doclinkid)::numeric)
                           ->  Nested Loop
                                 ->  Index Scan using pgaapallsubcontoresource_xak1allsubcontoresource on pgaapallsubcontoresource sub
                                       Index Cond: ((spid)::numeric = '999'::numeric)
                                 ->  Index Scan using tdepartment_xpktdepartment on tdepartment d
                                       Index Cond: ((departmentid)::numeric = (sub.depid1)::numeric)
                           ->  Index Scan using pdoccas_xpkpdoccas on pdoccas p
                                 Index Cond: ((spid)::numeric = '999'::numeric)
               ->  Subquery Scan on "*SELECT* 2"
                     ->  Nested Loop
                           Join Filter: ((sub_1.id)::numeric = (p_1.doclinkid)::numeric)
                           ->  Nested Loop
                                 ->  Index Scan using pgaapallsubcontoresource_xak1allsubcontoresource on pgaapallsubcontoresource sub_1
                                       Index Cond: ((spid)::numeric = '999'::numeric)
                                 ->  Index Scan using tdepartment_xpktdepartment on tdepartment d_1
                                       Index Cond: ((departmentid)::numeric = (sub_1.depid2)::numeric)
                           ->  Index Scan using pdoccas_xpkpdoccas on pdoccas p_1
                                 Index Cond: ((spid)::numeric = '999'::numeric)
(23 rows)
 
--24543.sql
explain (costs off)
      DELETE /*! ForceOrder() */
        FROM pResList
       WHERE pResList.ctid IN (      SELECT /*+ IndexScan(t preslist_xpkpreslist)
                 IndexScan(r tresource_xpktresource)
                 IndexScan(ur tgl_userright_sync_xpktgl_userright_sync)
                 IndexScan(urf tgl_userright_sync_xpktgl_userright_sync)
                 IndexScan(urb tgl_userright_sync_xpktgl_userright_sync)
                 IndexScan(urb2 tgl_userright_sync_xpktgl_userright_sync) */
             t.ctid
        FROM pResList t
      INNER JOIN tResource r
              ON r.ResourceID = t.ResourceID
      LEFT OUTER JOIN tGL_UserRight_Sync ur
              ON ur.UserID = 111 AND ur.RightType = 0 AND ur.ObjectID = r.BalanceID
      LEFT OUTER JOIN tGL_UserRight_Sync urf
              ON urf.UserID = 111 AND urf.RightType = 1 AND urf.ObjectID = r.FundID
      LEFT OUTER JOIN tGL_UserRight_Sync urb
              ON urb.UserID = 111 AND urb.RightType = 9 AND urb.ObjectID = r.InstitutionID
      LEFT OUTER JOIN tGL_UserRight_Sync urb2
              ON urb2.UserID = 111 AND urb2.RightType = 9 AND urb2.ObjectID = r.SubDivisionID
       WHERE t.SPID = 222 AND (ur.ObjectID IS NULL OR urf.ObjectID IS NULL OR (urb.ObjectID IS NULL OR urb2.ObjectID IS NULL) OR NOT EXISTS(      SELECT /*+ IndexScan(ur2 tuserres_xpktuserres) */
             1
        FROM pTmp_UserPost p
      INNER JOIN tUserRes ur2
              ON ur2.UserID = p.PostID AND ur2.UserResType = 19 AND ur2.ResourceID = r.AccProfileID AND (ur2.AccessType & 4) > 0) OR (NOT EXISTS(      SELECT /*+ IndexScan(urf2 tuserres_xpktuserres) */
             1
        FROM pTmp_UserPost p
      INNER JOIN tUserRes urf2
              ON urf2.UserID = p.PostID AND urf2.UserResType = 1 AND urf2.ResourceID = r.FundID AND (urf2.AccessType & 4) > 0) AND NOT EXISTS(      SELECT /*+ IndexScan(urb2 tuserres_xpktuserres) */
             1
        FROM pTmp_UserPost p
      INNER JOIN tUserRes urb2
              ON urb2.UserID = p.PostID AND urb2.UserResType = 9 AND urb2.ResourceID = r.SubDivisionID AND (urb2.AccessType & 4) > 0) AND NOT EXISTS(      SELECT /*+ IndexScan(rb tresourcebind_xak1tresourcebind)
                 IndexScan(ur tuserres_xpktuserres) */
             1
        FROM pTmp_UserPost p
      INNER JOIN tResourceBind rb
              ON rb.ChildID = r.ResourceID
      INNER JOIN tUserRes ur
              ON ur.UserID = p.PostID AND ur.UserResType = 10 AND ur.ResourceID = rb.ParentID AND (ur.AccessType & 4) > 0))))
;
                                                                                                         QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Delete on preslist
   ->  Nested Loop
         ->  HashAggregate
               Group Key: t.ctid
               ->  Nested Loop Left Join
                     Filter: ((ur.objectid IS NULL) OR (urf.objectid IS NULL) OR (urb.objectid IS NULL) OR (urb2.objectid IS NULL) OR (NOT (SubPlan 1)) OR ((NOT (SubPlan 2)) AND (NOT (SubPlan 3)) AND (NOT (SubPlan 4))))
                     ->  Nested Loop Left Join
                           ->  Nested Loop Left Join
                                 ->  Nested Loop Left Join
                                       ->  Nested Loop
                                             ->  Index Scan using preslist_xpkpreslist on preslist t
                                                   Index Cond: ((spid)::numeric = '222'::numeric)
                                             ->  Index Scan using tresource_xpktresource on tresource r
                                                   Index Cond: ((resourceid)::numeric = (t.resourceid)::numeric)
                                       ->  Index Scan using tgl_userright_sync_xpktgl_userright_sync on tgl_userright_sync ur
                                             Index Cond: (((userid)::numeric = '111'::numeric) AND ((righttype)::numeric = '0'::numeric) AND ((objectid)::numeric = (r.balanceid)::numeric))
                                 ->  Index Scan using tgl_userright_sync_xpktgl_userright_sync on tgl_userright_sync urf
                                       Index Cond: (((userid)::numeric = '111'::numeric) AND ((righttype)::numeric = '1'::numeric) AND ((objectid)::numeric = (r.fundid)::numeric))
                           ->  Index Scan using tgl_userright_sync_xpktgl_userright_sync on tgl_userright_sync urb
                                 Index Cond: (((userid)::numeric = '111'::numeric) AND ((righttype)::numeric = '9'::numeric) AND ((objectid)::numeric = (r.institutionid)::numeric))
                     ->  Index Scan using tgl_userright_sync_xpktgl_userright_sync on tgl_userright_sync urb2
                           Index Cond: (((userid)::numeric = '111'::numeric) AND ((righttype)::numeric = '9'::numeric) AND ((objectid)::numeric = (r.subdivisionid)::numeric))
                     SubPlan 1
                       ->  Nested Loop
                             ->  Seq Scan on ptmp_userpost p
                             ->  Index Scan using tuserres_xpktuserres on tuserres ur2
                                   Index Cond: (((userid)::numeric = p.postid) AND ((userrestype)::numeric = '19'::numeric) AND ((resourceid)::numeric = (r.accprofileid)::numeric))
                                   Filter: (((accesstype)::integer & 4) > 0)
                     SubPlan 2
                       ->  Nested Loop
                             ->  Seq Scan on ptmp_userpost p_1
                             ->  Index Scan using tuserres_xpktuserres on tuserres urf2
                                   Index Cond: (((userid)::numeric = p_1.postid) AND ((userrestype)::numeric = '1'::numeric) AND ((resourceid)::numeric = (r.fundid)::numeric))
                                   Filter: (((accesstype)::integer & 4) > 0)
                     SubPlan 3
                       ->  Nested Loop
                             ->  Seq Scan on ptmp_userpost p_2
                             ->  Index Scan using tuserres_xpktuserres on tuserres urb2_1
                                   Index Cond: (((userid)::numeric = p_2.postid) AND ((userrestype)::numeric = '9'::numeric) AND ((resourceid)::numeric = (r.subdivisionid)::numeric))
                                   Filter: (((accesstype)::integer & 4) > 0)
                     SubPlan 4
                       ->  Nested Loop
                             Join Filter: ((rb.parentid)::numeric = (ur_1.resourceid)::numeric)
                             ->  Nested Loop
                                   ->  Index Scan using tresourcebind_xak1tresourcebind on tresourcebind rb
                                         Index Cond: ((childid)::numeric = (r.resourceid)::numeric)
                                   ->  Seq Scan on ptmp_userpost p_3
                             ->  Index Scan using tuserres_xpktuserres on tuserres ur_1
                                   Index Cond: (((userid)::numeric = p_3.postid) AND ((userrestype)::numeric = '10'::numeric))
                                   Filter: (((accesstype)::integer & 4) > 0)
         ->  Tid Scan on preslist
               TID Cond: (ctid = t.ctid)
(52 rows)
 
--32444.sql
explain (costs off)
  UPDATE /*+ IndexScan(d prko_f251_docum_xpkprko_f251_docum) */
         pRKO_f251_Docum tab__update
     SET InStrFlags = 0
    FROM pRKO_f251_Docum d
   WHERE tab__update.ctid = d.ctid AND (d.SPID = 999 AND (d.InStrFlags & 524288 = 524288) AND (d.InStrFlags & 65535 <> 0) AND NOT EXISTS(  SELECT /*+ IndexScan(d2 prko_f251_docum_xie2prko_f251_docum) */
         1
    FROM pRKO_f251_Docum d2
   WHERE d2.SPID = 999 AND d2.InStrFlags = 524288 AND d2.DealTransactID = d.DealTransactID) AND NOT EXISTS(  SELECT /*+ IndexScan(d2 prko_f251_docum_xie3prko_f251_docum) */
         1
    FROM pRKO_f251_Docum d2
   WHERE d2.SPID = 999 AND d2.InStrFlags = 524288 AND d2.OperID <> 0 AND d2.OperID = d.OperID))
;
                                                         QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
 Update on prko_f251_docum tab__update
   ->  Nested Loop Anti Join
         Join Filter: ((d2_1.operid)::numeric = (d.operid)::numeric)
         ->  Nested Loop Anti Join
               Join Filter: ((d2.dealtransactid)::numeric = (d.dealtransactid)::numeric)
               ->  Nested Loop
                     ->  Index Scan using prko_f251_docum_xpkprko_f251_docum on prko_f251_docum d
                           Index Cond: ((spid)::numeric = '999'::numeric)
                           Filter: ((((instrflags)::integer & 65535) <> 0) AND (((instrflags)::integer & 524288) = 524288))
                     ->  Tid Scan on prko_f251_docum tab__update
                           TID Cond: (ctid = d.ctid)
               ->  Index Scan using prko_f251_docum_xie2prko_f251_docum on prko_f251_docum d2
                     Index Cond: (((spid)::numeric = '999'::numeric) AND ((instrflags)::integer = 524288))
         ->  Index Scan using prko_f251_docum_xie3prko_f251_docum on prko_f251_docum d2_1
               Index Cond: ((spid)::numeric = '999'::numeric)
               Filter: (((operid)::numeric <> '0'::numeric) AND ((instrflags)::integer = 524288))
(16 rows)
 
--34749.sql
explain (costs off)
      INSERT INTO pRKOResource
      (
          SPID,
          ResourceID
      )
      SELECT /*+ IndexScan(p prkocomiss_docterm_xie0prkocomiss_docterm) */
             /*! ForceOrder() */
             999,
             p.ResourceID
        FROM pRKOComiss_DocTerm p
       WHERE p.spid = 999 AND p.AccountMethodID = 0
      GROUP BY
        p.ResourceID
       UNION
      SELECT /*+ IndexScan(p prkocomiss_docterm_xie0prkocomiss_docterm)
                 IndexScan(t papi_oper_fndlstbylstacc_xie1papi_oper_fndlstbylstacc) */
             /*! ForceOrder() */
             999,
             t.AccountDebitID
        FROM pRKOComiss_DocTerm p
      INNER JOIN pAPI_Oper_FndLstByLstAcc t
              ON t.spid = p.spid AND t.AccountDebitID = p.ResourceID
       WHERE p.spid = 999
       UNION
      SELECT /*+ IndexScan(p prkocomiss_docterm_xie0prkocomiss_docterm)
                 IndexScan(t papi_oper_fndlstbylstacc_xie1papi_oper_fndlstbylstacc) */
             /*! ForceOrder() */
             999,
             t.AccountCreditID
        FROM pRKOComiss_DocTerm p
      INNER JOIN pAPI_Oper_FndLstByLstAcc t
              ON t.spid = p.spid AND t.AccountDebitID = p.ResourceID
       WHERE p.spid = 999
       UNION
      SELECT /*+ IndexScan(p prkocomiss_docterm_xie0prkocomiss_docterm)
                 IndexScan(t papi_oper_fndlstbylstacc_xie2papi_oper_fndlstbylstacc) */
             /*! ForceOrder() */
             999,
             t.AccountDebitID
        FROM pRKOComiss_DocTerm p
      INNER JOIN pAPI_Oper_FndLstByLstAcc t
              ON t.spid = p.spid AND t.AccountCreditID = p.ResourceID
       WHERE p.spid = 999
       UNION
      SELECT /*+ IndexScan(p prkocomiss_docterm_xie0prkocomiss_docterm)
                 IndexScan(t papi_oper_fndlstbylstacc_xie2papi_oper_fndlstbylstacc) */
             /*! ForceOrder() */
             999,
             t.AccountCreditID
        FROM pRKOComiss_DocTerm p
      INNER JOIN pAPI_Oper_FndLstByLstAcc t
              ON t.spid = p.spid AND t.AccountCreditID = p.ResourceID
       WHERE p.spid = 999
;
                                                              QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
 Insert on prkoresource
   ->  Subquery Scan on "*SELECT*"
         ->  HashAggregate
               Group Key: (999), p.resourceid
               ->  Append
                     ->  Group
                           Group Key: p.resourceid
                           ->  Index Scan using prkocomiss_docterm_xie0prkocomiss_docterm on prkocomiss_docterm p
                                 Index Cond: (((spid)::numeric = '999'::numeric) AND ((accountmethodid)::numeric = '0'::numeric))
                     ->  Nested Loop
                           Join Filter: ((p_1.resourceid)::numeric = (t.accountdebitid)::numeric)
                           ->  Index Scan using prkocomiss_docterm_xie0prkocomiss_docterm on prkocomiss_docterm p_1
                                 Index Cond: ((spid)::numeric = '999'::numeric)
                           ->  Index Scan using papi_oper_fndlstbylstacc_xie1papi_oper_fndlstbylstacc on papi_oper_fndlstbylstacc t
                                 Index Cond: ((spid)::numeric = '999'::numeric)
                     ->  Nested Loop
                           Join Filter: ((p_2.resourceid)::numeric = (t_1.accountdebitid)::numeric)
                           ->  Index Scan using prkocomiss_docterm_xie0prkocomiss_docterm on prkocomiss_docterm p_2
                                 Index Cond: ((spid)::numeric = '999'::numeric)
                           ->  Index Scan using papi_oper_fndlstbylstacc_xie1papi_oper_fndlstbylstacc on papi_oper_fndlstbylstacc t_1
                                 Index Cond: ((spid)::numeric = '999'::numeric)
                     ->  Nested Loop
                           Join Filter: ((p_3.resourceid)::numeric = (t_2.accountcreditid)::numeric)
                           ->  Index Scan using prkocomiss_docterm_xie0prkocomiss_docterm on prkocomiss_docterm p_3
                                 Index Cond: ((spid)::numeric = '999'::numeric)
                           ->  Index Scan using papi_oper_fndlstbylstacc_xie2papi_oper_fndlstbylstacc on papi_oper_fndlstbylstacc t_2
                                 Index Cond: ((spid)::numeric = '999'::numeric)
                     ->  Nested Loop
                           Join Filter: ((p_4.resourceid)::numeric = (t_3.accountcreditid)::numeric)
                           ->  Index Scan using prkocomiss_docterm_xie0prkocomiss_docterm on prkocomiss_docterm p_4
                                 Index Cond: ((spid)::numeric = '999'::numeric)
                           ->  Index Scan using papi_oper_fndlstbylstacc_xie2papi_oper_fndlstbylstacc on papi_oper_fndlstbylstacc t_3
                                 Index Cond: ((spid)::numeric = '999'::numeric)
(33 rows)
 
--34922.sql
explain (costs off)
  INSERT INTO pRKOResource
  (
      SPID,
      ResourceID
  )
  SELECT /*+ IndexScan(p papi_oper_fndlstbylstacc_xie1papi_oper_fndlstbylstacc) */
         DISTINCT 999,
         p.AccountDebitID
    FROM pAPI_Oper_FndLstByLstAcc p
   WHERE p.spid = 999
   UNION
  SELECT /*+ IndexScan(p papi_oper_fndlstbylstacc_xie2papi_oper_fndlstbylstacc) */
         DISTINCT 999,
         p.AccountCreditID
    FROM pAPI_Oper_FndLstByLstAcc p
   WHERE p.spid = 999
;
                                                                 QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------
 Insert on prkoresource
   ->  Subquery Scan on "*SELECT*"
         ->  Unique
               ->  Sort
                     Sort Key: (999), p.accountdebitid
                     ->  Append
                           ->  Unique
                                 ->  Index Scan using papi_oper_fndlstbylstacc_xie1papi_oper_fndlstbylstacc on papi_oper_fndlstbylstacc p
                                       Index Cond: ((spid)::numeric = '999'::numeric)
                           ->  Unique
                                 ->  Index Scan using papi_oper_fndlstbylstacc_xie2papi_oper_fndlstbylstacc on papi_oper_fndlstbylstacc p_1
                                       Index Cond: ((spid)::numeric = '999'::numeric)
(12 rows)
 
--------------------auto type cast
---
set pg_hint_plan.force_cast_index_types = 0;
---
explain (costs off)
SELECT /*+ IndexScan(ob papi_accrual_objdate_xie1papi_accrual_objdate)*/
    max(ob.EndDate)
FROM pAPI_Accrual_ObjDate ob
WHERE SPID = '111'::integer
    AND ob.TemplateNumber = (select max(t1.tt1) from tmp_test_1 t1)::numeric
;
                                           QUERY PLAN
-------------------------------------------------------------------------------------------------
 Aggregate
   InitPlan 1 (returns $0)
     ->  Aggregate
           ->  Seq Scan on tmp_test_1 t1
   ->  Index Scan using papi_accrual_objdate_xie1papi_accrual_objdate on papi_accrual_objdate ob
         Index Cond: ((spid)::numeric = '111'::numeric)
         Filter: ((templatenumber)::numeric = $0)
(7 rows)
 
---
set pg_hint_plan.force_cast_index_types = 1;
---
explain (costs off)
SELECT /*+ IndexScan(ob papi_accrual_objdate_xie1papi_accrual_objdate)*/
    max(ob.EndDate)
FROM pAPI_Accrual_ObjDate ob
WHERE SPID = '111'::integer
    AND ob.TemplateNumber = (select max(t1.tt1) from tmp_test_1 t1)::numeric
;
                                           QUERY PLAN
-------------------------------------------------------------------------------------------------
 Aggregate
   InitPlan 1 (returns $0)
     ->  Aggregate
           ->  Seq Scan on tmp_test_1 t1
   ->  Index Scan using papi_accrual_objdate_xie1papi_accrual_objdate on papi_accrual_objdate ob
         Index Cond: ((spid)::numeric = '111'::numeric)
         Filter: ((templatenumber)::numeric = $0)
(7 rows)
 
---
set pg_hint_plan.force_cast_index_types = 0;
---
explain (costs off)
SELECT /*+ IndexScan(ob papi_accrual_objdate_xie1papi_accrual_objdate)*/
    max(ob.EndDate)
FROM pAPI_Accrual_ObjDate ob
WHERE SPID = '111'::integer
    AND ob.TemplateNumber = (select max(t1.tt1) from tmp_test_1 t1)
;
                                           QUERY PLAN
-------------------------------------------------------------------------------------------------
 Aggregate
   InitPlan 1 (returns $0)
     ->  Aggregate
           ->  Seq Scan on tmp_test_1 t1
   ->  Index Scan using papi_accrual_objdate_xie1papi_accrual_objdate on papi_accrual_objdate ob
         Index Cond: ((spid)::numeric = '111'::numeric)
         Filter: ((templatenumber)::numeric = $0)
(7 rows)
 
---
set pg_hint_plan.force_cast_index_types = 1;
---
explain (costs off)
SELECT /*+ IndexScan(ob papi_accrual_objdate_xie1papi_accrual_objdate)*/
    max(ob.EndDate)
FROM pAPI_Accrual_ObjDate ob
WHERE SPID = '111'::integer
    AND ob.TemplateNumber = (select max(t1.tt1) from tmp_test_1 t1)
;
                                                QUERY PLAN
----------------------------------------------------------------------------------------------------------
 Aggregate
   InitPlan 1 (returns $0)
     ->  Aggregate
           ->  Seq Scan on tmp_test_1 t1
   ->  Index Scan using papi_accrual_objdate_xie1papi_accrual_objdate on papi_accrual_objdate ob
         Index Cond: (((spid)::numeric = '111'::numeric) AND ((templatenumber)::integer = ($0)::integer))
(6 rows)
 
---
set pg_hint_plan.force_cast_index_types = 0;
---
explain (costs off)
SELECT /*+ IndexScan(ob papi_accrual_objdate_xie1papi_accrual_objdate) */
    max(ob.EndDate)
FROM pAPI_Accrual_ObjDate ob
WHERE SPID = '111'::integer
    AND ob.TemplateNumber = (select max(t1.tt1) from tmp_test_1 t1)::integer
;
                                                QUERY PLAN
----------------------------------------------------------------------------------------------------------
 Aggregate
   InitPlan 1 (returns $0)
     ->  Aggregate
           ->  Seq Scan on tmp_test_1 t1
   ->  Index Scan using papi_accrual_objdate_xie1papi_accrual_objdate on papi_accrual_objdate ob
         Index Cond: (((spid)::numeric = '111'::numeric) AND ((templatenumber)::integer = ($0)::integer))
(6 rows)
 
---
set pg_hint_plan.force_cast_index_types = 1;
---
explain (costs off)
SELECT /*+ IndexScan(ob papi_accrual_objdate_xie1papi_accrual_objdate) */
    max(ob.EndDate)
FROM pAPI_Accrual_ObjDate ob
WHERE SPID = '111'::integer
    AND ob.TemplateNumber = (select max(t1.tt1) from tmp_test_1 t1)::integer
;
                                                QUERY PLAN
----------------------------------------------------------------------------------------------------------
 Aggregate
   InitPlan 1 (returns $0)
     ->  Aggregate
           ->  Seq Scan on tmp_test_1 t1
   ->  Index Scan using papi_accrual_objdate_xie1papi_accrual_objdate on papi_accrual_objdate ob
         Index Cond: (((spid)::numeric = '111'::numeric) AND ((templatenumber)::integer = ($0)::integer))
(6 rows)
 
---
set pg_hint_plan.force_cast_index_types = 0;
---
explain (costs off)
UPDATE /*+ IndexScan(obc pdpt_accrual_objdatecorrect_xpkpdpt_accrual_objdatecorrect) */
         pDPT_Accrual_ObjDateCorrect tab__update
     SET MaxObjectDate = (  SELECT /*+ IndexScan(ob papi_accrual_objdate_xie1papi_accrual_objdate) */
         max(ob.EndDate)
    FROM pAPI_Accrual_ObjDate ob
   WHERE SPID = obc.SPID AND ob.TemplateNumber = (select max(t1.tt1) from tmp_test_1 t1) /*var_TemplateNumber*/ AND obc.ObjectID = ob.ObjectID)
    FROM pDPT_Accrual_ObjDateCorrect obc
   WHERE tab__update.ctid = obc.ctid AND (obc.SPID = 999/*var__SPID_CONSTANT*/)
;
                                                           QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------
 Update on pdpt_accrual_objdatecorrect tab__update
   ->  Nested Loop
         ->  Index Scan using pdpt_accrual_objdatecorrect_xpkpdpt_accrual_objdatecorrect on pdpt_accrual_objdatecorrect obc
               Index Cond: ((spid)::numeric = '999'::numeric)
         ->  Tid Scan on pdpt_accrual_objdatecorrect tab__update
               TID Cond: (ctid = obc.ctid)
         SubPlan 2
           ->  Aggregate
                 InitPlan 1 (returns $0)
                   ->  Aggregate
                         ->  Seq Scan on tmp_test_1 t1
                 ->  Index Scan using papi_accrual_objdate_xie1papi_accrual_objdate on papi_accrual_objdate ob
                       Index Cond: (((spid)::numeric = (obc.spid)::numeric) AND ((objectid)::numeric = (obc.objectid)::numeric))
                       Filter: ((templatenumber)::numeric = $0)
(14 rows)
 
---
set pg_hint_plan.force_cast_index_types = 1;
---
explain (costs off)
UPDATE /*+ IndexScan(obc pdpt_accrual_objdatecorrect_xpkpdpt_accrual_objdatecorrect) */
         pDPT_Accrual_ObjDateCorrect tab__update
     SET MaxObjectDate = (  SELECT /*+ IndexScan(ob papi_accrual_objdate_xie1papi_accrual_objdate) */
         max(ob.EndDate)
    FROM pAPI_Accrual_ObjDate ob
   WHERE SPID = obc.SPID AND ob.TemplateNumber = (select max(t1.tt1) from tmp_test_1 t1) /*var_TemplateNumber*/ AND obc.ObjectID = ob.ObjectID)
    FROM pDPT_Accrual_ObjDateCorrect obc
   WHERE tab__update.ctid = obc.ctid AND (obc.SPID = 999/*var__SPID_CONSTANT*/)
;
                                                                                   QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Update on pdpt_accrual_objdatecorrect tab__update
   ->  Nested Loop
         ->  Index Scan using pdpt_accrual_objdatecorrect_xpkpdpt_accrual_objdatecorrect on pdpt_accrual_objdatecorrect obc
               Index Cond: ((spid)::numeric = '999'::numeric)
         ->  Tid Scan on pdpt_accrual_objdatecorrect tab__update
               TID Cond: (ctid = obc.ctid)
         SubPlan 2
           ->  Aggregate
                 InitPlan 1 (returns $0)
                   ->  Aggregate
                         ->  Seq Scan on tmp_test_1 t1
                 ->  Index Scan using papi_accrual_objdate_xie1papi_accrual_objdate on papi_accrual_objdate ob
                       Index Cond: (((spid)::numeric = (obc.spid)::numeric) AND ((templatenumber)::integer = ($0)::integer) AND ((objectid)::numeric = (obc.objectid)::numeric))
(13 rows)
 
---
set pg_hint_plan.force_cast_index_types = 0;
---
explain (costs off)
UPDATE /*+ IndexScan(al pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre) */
           pDPT_Accrual_AdvLucre tab__update
       SET EndDate = coalesce((    SELECT /*+ IndexScan(adl pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre) */
           (CASE WHEN min(coalesce(adl.PrcDate, CAST('19000101' AS TIMESTAMP without time zone))) = CAST('19000101' AS TIMESTAMP without time zone) THEN al.EndDate ELSE min(adl.PrcDate) END)
      FROM pDPT_Accrual_AdvLucre adl
     WHERE adl.SPID = al.SPID AND adl.ObjectID = al.ObjectID AND adl.TemplateNumber = al.TemplateNumber AND adl.BeginDate = al.BeginDate AND adl.EndDate = al.EndDate AND adl.PreparedQty = al.PreparedQty AND adl.Value = al.Value AND adl.Prcnt = al.Prcnt AND adl.TemplateNumberPrc = al.TemplateNumberPrc AND adl.PrcDate <> CAST('19000101' AS TIMESTAMP)), al.EndDate)
      FROM pDPT_Accrual_AdvLucre al
     WHERE tab__update.ctid = al.ctid AND (al.SPID = 999/*var__SPID_CONSTANT*/ AND al.TemplateNumber = (select max(t1.tt1) from tmp_test_1 t1) /*var_TemplateNumber*/ AND al.PrcDate = CAST('19000101' AS TIMESTAMP))
;
                                                                                                                                                                                                                                                                             QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Update on pdpt_accrual_advlucre tab__update
   InitPlan 2 (returns $9)
     ->  Aggregate
           ->  Seq Scan on tmp_test_1 t1
   ->  Nested Loop
         ->  Index Scan using pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre on pdpt_accrual_advlucre al
               Index Cond: (((spid)::numeric = '999'::numeric) AND ((templatenumber)::numeric = $9))
               Filter: ((prcdate)::timestamp without time zone = 'Mon Jan 01 00:00:00 1900'::timestamp without time zone)
         ->  Tid Scan on pdpt_accrual_advlucre tab__update
               TID Cond: (ctid = al.ctid)
         SubPlan 1
           ->  Aggregate
                 ->  Index Scan using pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre on pdpt_accrual_advlucre adl
                       Index Cond: (((spid)::numeric = (al.spid)::numeric) AND ((objectid)::numeric = (al.objectid)::numeric) AND ((templatenumber)::numeric = (al.templatenumber)::numeric))
                       Filter: (((prcdate)::timestamp without time zone <> 'Mon Jan 01 00:00:00 1900'::timestamp without time zone) AND ((begindate)::timestamp without time zone = (al.begindate)::timestamp without time zone) AND ((enddate)::timestamp without time zone = (al.enddate)::timestamp without time zone) AND ((preparedqty)::numeric = (al.preparedqty)::numeric) AND ((value)::numeric = (al.value)::numeric) AND ((prcnt)::double precision = (al.prcnt)::double precision) AND ((templatenumberprc)::integer = (al.templatenumberprc)::integer))
(15 rows)
 
---
set pg_hint_plan.force_cast_index_types = 1;
---
explain (costs off)
UPDATE /*+ IndexScan(al pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre) */
           pDPT_Accrual_AdvLucre tab__update
       SET EndDate = coalesce((    SELECT /*+ IndexScan(adl pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre) */
           (CASE WHEN min(coalesce(adl.PrcDate, CAST('19000101' AS TIMESTAMP without time zone))) = CAST('19000101' AS TIMESTAMP without time zone) THEN al.EndDate ELSE min(adl.PrcDate) END)
      FROM pDPT_Accrual_AdvLucre adl
     WHERE adl.SPID = al.SPID AND adl.ObjectID = al.ObjectID AND adl.TemplateNumber = al.TemplateNumber AND adl.BeginDate = al.BeginDate AND adl.EndDate = al.EndDate AND adl.PreparedQty = al.PreparedQty AND adl.Value = al.Value AND adl.Prcnt = al.Prcnt AND adl.TemplateNumberPrc = al.TemplateNumberPrc AND adl.PrcDate <> CAST('19000101' AS TIMESTAMP)), al.EndDate)
      FROM pDPT_Accrual_AdvLucre al
     WHERE tab__update.ctid = al.ctid AND (al.SPID = 999/*var__SPID_CONSTANT*/ AND al.TemplateNumber = (select max(t1.tt1) from tmp_test_1 t1) /*var_TemplateNumber*/ AND al.PrcDate = CAST('19000101' AS TIMESTAMP))
;
                                                                                                                                                                                                                                                                             QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Update on pdpt_accrual_advlucre tab__update
   InitPlan 2 (returns $9)
     ->  Aggregate
           ->  Seq Scan on tmp_test_1 t1
   ->  Nested Loop
         ->  Index Scan using pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre on pdpt_accrual_advlucre al
               Index Cond: (((spid)::numeric = '999'::numeric) AND ((templatenumber)::numeric = $9))
               Filter: ((prcdate)::timestamp without time zone = 'Mon Jan 01 00:00:00 1900'::timestamp without time zone)
         ->  Tid Scan on pdpt_accrual_advlucre tab__update
               TID Cond: (ctid = al.ctid)
         SubPlan 1
           ->  Aggregate
                 ->  Index Scan using pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre on pdpt_accrual_advlucre adl
                       Index Cond: (((spid)::numeric = (al.spid)::numeric) AND ((objectid)::numeric = (al.objectid)::numeric) AND ((templatenumber)::numeric = (al.templatenumber)::numeric))
                       Filter: (((prcdate)::timestamp without time zone <> 'Mon Jan 01 00:00:00 1900'::timestamp without time zone) AND ((begindate)::timestamp without time zone = (al.begindate)::timestamp without time zone) AND ((enddate)::timestamp without time zone = (al.enddate)::timestamp without time zone) AND ((preparedqty)::numeric = (al.preparedqty)::numeric) AND ((value)::numeric = (al.value)::numeric) AND ((prcnt)::double precision = (al.prcnt)::double precision) AND ((templatenumberprc)::integer = (al.templatenumberprc)::integer))
(15 rows)