-
+
+
-
+
+ ++
Global information
++++ ++-
+
- Generated on Mon Mar 18 15:00:27 2019 +
- Log file: //var/log/postgresql/postgresql-2019-03-14_012706.log.1, ..., //var/log/postgresql/postgresql-2019-03-18_085726.log +
- Parsed 169,231 log entries in 26s +
- Log start from 2019-03-14 01:27:06 to 2019-03-18 16:00:04 +
+
+
+ -
+
+
Overview
+ +++ +Global Stats
+++-
+
- Queries +
- Events +
- Vacuums +
- Temporary files +
- Sessions +
- Connections +
++++-
+
- 5,822 Number of unique normalized queries +
- 68,477 Number of queries +
- 47m16s Total query duration +
- 2019-03-14 01:27:07 First query +
- 2019-03-18 16:00:04 Last query +
- 5,392 queries/s at 2019-03-15 16:35:01 Query peak +
++-
+
- 21 Number of events +
- 11 Number of unique normalized events +
- 4 Max number of times the same event was reported +
- 0 Number of cancellation +
++-
+
- 5 Total number of automatic vacuums +
- 9 Total number of automatic analyzes +
++-
+
- 21 Number temporary file +
- 778.25 MiB Max size of temporary file +
- 448.43 MiB Average size of temporary file +
++-
+
- 125 Total number of sessions +
- 9 sessions at 2019-03-15 16:48:38 Session peak +
- 2d7h17m58s Total duration of sessions +
- 26m32s Average duration of sessions +
- 547 Average queries per session +
- 22s691ms Average queries duration per session + +
++-
+
- 130 Total number of connections + +
- 5 connections/s at 2019-03-18 09:00:08 Connection peak + +
- 3 Total number of databases +
++ +SQL Traffic
+++Key values
+++-
+
- 5,392 queries/s Query Peak +
- 2019-03-15 16:35:01 Date +
+ + + ++++ +SELECT Traffic
+++Key values
+++-
+
- 2,501 queries/s Query Peak +
- 2019-03-15 16:35:05 Date +
+ + + ++++ +INSERT/UPDATE/DELETE Traffic
+++Key values
+++-
+
- 948 queries/s Query Peak +
- 2019-03-15 16:35:15 Date +
+ + + ++++ +Queries duration
+++Key values
+++-
+
- 47m16s Total query duration +
+ + + ++++ +Prepared queries ratio
+++Key values
+++-
+
- 0.98 Ratio of bind vs prepare +
- 2.52 % Ratio between prepared and "usual" statements +
+ + + ++++ +General Activity
+++ +-
+
- Queries +
- Read Queries +
- Write Queries +
- Prepared Queries +
- Connections +
- Sessions +
++ ↑ Back to the top of the General Activity table ++++ +
++ + + +Day +Hour +Count +Min duration +Max duration +Avg duration +Latency Percentile(90) +Latency Percentile(95) +Latency Percentile(99) ++ +Mar 14 +01 +22 +0ms +111ms +5ms +113ms +113ms +113ms + ++ +10 +114 +0ms +461ms +54ms +1s31ms +1s165ms +1s165ms + ++ +11 +99 +0ms +546ms +128ms +1s483ms +1s766ms +1s889ms + ++ +12 +43 +0ms +430ms +125ms +920ms +1s808ms +1s808ms + ++ +16 +32,112 +0ms +56s311ms +5ms +1m7s +1m7s +1m7s + ++ +17 +379 +0ms +27s560ms +785ms +1m46s +1m51s +1m51s + ++ +22 +0 +0ms +0ms +0ms +0ms +0ms +0ms + ++ +23 +0 +0ms +0ms +0ms +0ms +0ms +0ms + ++ +Mar 15 +00 +427 +0ms +4m7s +1s954ms +3m19s +8m14s +8m14s + ++ +01 +6 +0ms +25ms +4ms +27ms +27ms +27ms + ++ +09 +72 +0ms +2s267ms +64ms +4s570ms +4s570ms +4s570ms + ++ +10 +31 +244ms +1s361ms +280ms +569ms +5s394ms +5s394ms + ++ +11 +12 +279ms +393ms +163ms +573ms +573ms +573ms + ++ +12 +4 +271ms +283ms +138ms +283ms +283ms +283ms + ++ +13 +2 +0ms +0ms +0ms +0ms +0ms +0ms + ++ +14 +272 +0ms +2m30s +1s592ms +7s494ms +7m4s +7m4s + ++ +15 +37 +0ms +3s763ms +469ms +272ms +15s28ms +15s28ms + ++ +16 +32,403 +0ms +3m6s +22ms +1m2s +8m53s +8m53s + ++ +17 +78 +0ms +25s847ms +1s734ms +2m15s +2m15s +2m15s + ++ +19 +0 +0ms +0ms +0ms +0ms +0ms +0ms + ++ +21 +0 +0ms +0ms +0ms +0ms +0ms +0ms + ++ +Mar 16 +01 +9 +0ms +25ms +3ms +25ms +25ms +25ms + ++ +02 +0 +0ms +0ms +0ms +0ms +0ms +0ms + ++ +05 +0 +0ms +0ms +0ms +0ms +0ms +0ms + ++ +19 +0 +0ms +0ms +0ms +0ms +0ms +0ms + ++ +Mar 18 +08 +12 +0ms +26ms +2ms +30ms +30ms +30ms + ++ +09 +2,106 +0ms +8s419ms +36ms +921ms +30s166ms +31s463ms + ++ +10 +112 +0ms +10s935ms +853ms +1m35s +1m35s +1m35s + ++ +11 +14 +0ms +126ms +9ms +132ms +132ms +132ms + ++ +12 +16 +0ms +40ms +2ms +41ms +41ms +41ms + ++ +13 +21 +0ms +1s173ms +230ms +4s560ms +4s560ms +4s560ms + ++ +14 +30 +0ms +306ms +68ms +555ms +555ms +555ms + ++ +15 +38 +0ms +274ms +78ms +466ms +521ms +521ms + ++ + +16 +6 +0ms +49ms +8ms +50ms +50ms +50ms + ++++ +
++ + + +Day +Hour +SELECT +COPY TO +Average Duration +Latency Percentile(90) +Latency Percentile(95) +Latency Percentile(99) ++ +Mar 14 +01 +6 +0 +0ms +0ms +0ms +0ms + ++ +10 +21 +0 +0ms +0ms +0ms +0ms + ++ +11 +5 +0 +0ms +0ms +0ms +0ms + ++ +12 +0 +0 +0ms +0ms +0ms +0ms + ++ +16 +10,853 +2,595 +0ms +0ms +0ms +0ms + ++ +17 +13 +0 +0ms +0ms +0ms +0ms + ++ +22 +0 +0 +0ms +0ms +0ms +0ms + ++ +23 +0 +0 +0ms +0ms +0ms +0ms + ++ +Mar 15 +00 +55 +0 +0ms +0ms +0ms +0ms + ++ +01 +3 +0 +0ms +0ms +0ms +0ms + ++ +09 +19 +0 +119ms +0ms +2s267ms +2s267ms + ++ +10 +0 +0 +0ms +0ms +0ms +0ms + ++ +11 +0 +0 +0ms +0ms +0ms +0ms + ++ +12 +0 +0 +0ms +0ms +0ms +0ms + ++ +13 +1 +0 +0ms +0ms +0ms +0ms + ++ +14 +10 +0 +0ms +0ms +0ms +0ms + ++ +15 +3 +0 +0ms +0ms +0ms +0ms + ++ +16 +10,860 +2,595 +0ms +0ms +0ms +0ms + ++ +17 +12 +0 +0ms +0ms +0ms +0ms + ++ +19 +0 +0 +0ms +0ms +0ms +0ms + ++ +21 +0 +0 +0ms +0ms +0ms +0ms + ++ +Mar 16 +01 +5 +0 +0ms +0ms +0ms +0ms + ++ +02 +0 +0 +0ms +0ms +0ms +0ms + ++ +05 +0 +0 +0ms +0ms +0ms +0ms + ++ +19 +0 +0 +0ms +0ms +0ms +0ms + ++ +Mar 18 +08 +6 +0 +0ms +0ms +0ms +0ms + ++ +09 +1,012 +0 +0ms +0ms +0ms +0ms + ++ +10 +12 +0 +0ms +0ms +0ms +0ms + ++ +11 +3 +0 +0ms +0ms +0ms +0ms + ++ +12 +4 +0 +0ms +0ms +0ms +0ms + ++ +13 +3 +0 +0ms +0ms +0ms +0ms + ++ +14 +3 +0 +0ms +0ms +0ms +0ms + ++ +15 +3 +0 +0ms +0ms +0ms +0ms + ++ + +16 +3 +0 +0ms +0ms +0ms +0ms + ++++ +
++ + + +Day +Hour +INSERT +UPDATE +DELETE +COPY FROM +Average Duration +Latency Percentile(90) +Latency Percentile(95) +Latency Percentile(99) ++ +Mar 14 +01 +1 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +10 +0 +0 +2 +0 +0ms 0ms +0ms +0ms + ++ +11 +0 +0 +2 +0 +0ms 0ms +0ms +0ms + ++ +12 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +16 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +17 +106 +0 +5 +0 +45ms 0ms +0ms +3s265ms + ++ +22 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +23 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +Mar 15 +00 +106 +0 +5 +0 +2s376ms 0ms +0ms +4m7s + ++ +01 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +09 +1 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +10 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +11 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +12 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +13 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +14 +108 +0 +5 +0 +1s364ms 0ms +1s270ms +2m30s + ++ +15 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +16 +109 +0 +5 +0 +1s670ms 0ms +0ms +3m6s + ++ +17 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +19 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +21 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +Mar 16 +01 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +02 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +05 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +19 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +Mar 18 +08 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +09 +1 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +10 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +11 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +12 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +13 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +14 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ +15 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++ + +16 +0 +0 +0 +0 +0ms 0ms +0ms +0ms + ++++ +
++ + + +Day +Hour +Prepare +Bind +Bind/Prepare +Percentage of prepare ++ +Mar 14 +01 +4 +4 +1.00 +44.44% ++ +10 +37 +37 +1.00 +112.12% ++ +11 +9 +9 +1.00 +42.86% ++ +12 +0 +0 +0.00 +0.00% ++ +16 +0 +0 +0.00 +0.00% ++ +17 +161 +155 +0.96 +99.38% ++ +22 +0 +0 +0.00 +0.00% ++ +23 +0 +0 +0.00 +0.00% ++ +Mar 15 +00 +154 +152 +0.99 +81.48% ++ +01 +0 +0 +0.00 +0.00% ++ +09 +27 +27 +1.00 +112.50% ++ +10 +0 +0 +0.00 +0.00% ++ +11 +0 +0 +0.00 +0.00% ++ +12 +0 +0 +0.00 +0.00% ++ +13 +0 +0 +0.00 +0.00% ++ +14 +110 +110 +1.00 +83.33% ++ +15 +3 +3 +1.00 +60.00% ++ +16 +111 +111 +1.00 +0.82% ++ +17 +30 +28 +0.93 +107.14% ++ +19 +0 +0 +0.00 +0.00% ++ +21 +0 +0 +0.00 +0.00% ++ +Mar 16 +01 +0 +0 +0.00 +0.00% ++ +02 +0 +0 +0.00 +0.00% ++ +05 +0 +0 +0.00 +0.00% ++ +19 +0 +0 +0.00 +0.00% ++ +Mar 18 +08 +0 +0 +0.00 +0.00% ++ +09 +34 +32 +0.94 +3.29% ++ +10 +42 +38 +0.90 +116.67% ++ +11 +3 +3 +1.00 +60.00% ++ +12 +3 +3 +1.00 +50.00% ++ +13 +3 +3 +1.00 +60.00% ++ +14 +3 +3 +1.00 +60.00% ++ +15 +3 +3 +1.00 +60.00% ++ + +16 +3 +3 +1.00 +100.00% ++++ +
++ + + +Day +Hour +Count +Average / Second ++ +Mar 14 +01 +4 +0.00/s ++ +10 +7 +0.00/s ++ +11 +4 +0.00/s ++ +12 +4 +0.00/s ++ +16 +2 +0.00/s ++ +17 +8 +0.00/s ++ +22 +1 +0.00/s ++ +23 +0 +0.00/s ++ +Mar 15 +00 +15 +0.00/s ++ +01 +3 +0.00/s ++ +09 +8 +0.00/s ++ +10 +0 +0.00/s ++ +11 +0 +0.00/s ++ +12 +2 +0.00/s ++ +13 +2 +0.00/s ++ +14 +7 +0.00/s ++ +15 +1 +0.00/s ++ +16 +7 +0.00/s ++ +17 +4 +0.00/s ++ +19 +5 +0.00/s ++ +21 +2 +0.00/s ++ +Mar 16 +01 +10 +0.00/s ++ +02 +0 +0.00/s ++ +05 +1 +0.00/s ++ +19 +1 +0.00/s ++ +Mar 18 +08 +6 +0.00/s ++ +09 +13 +0.00/s ++ +10 +4 +0.00/s ++ +11 +1 +0.00/s ++ +12 +2 +0.00/s ++ +13 +2 +0.00/s ++ +14 +1 +0.00/s ++ +15 +2 +0.00/s ++ + +16 +1 +0.00/s ++++ +
++ + + +Day +Hour +Count +Average Duration ++ +Mar 14 +01 +4 +1m29s ++ +10 +4 +6m48s ++ +11 +5 +7m39s ++ +12 +4 +3m6s ++ +16 +1 +3m5s ++ +17 +9 +1h36m26s ++ +22 +0 +0ms ++ +23 +1 +11m14s ++ +Mar 15 +00 +15 +2m12s ++ +01 +3 +21ms ++ +09 +5 +56s996ms ++ +10 +0 +0ms ++ +11 +0 +0ms ++ +12 +3 +59m22s ++ +13 +2 +1m17s ++ +14 +8 +1h11m7s ++ +15 +1 +15s128ms ++ +16 +7 +21m55s ++ +17 +5 +12m23s ++ +19 +4 +24s653ms ++ +21 +2 +51m30s ++ +Mar 16 +01 +9 +30m ++ +02 +2 +31m53s ++ +05 +0 +0ms ++ +19 +2 +7h1m6s ++ +Mar 18 +08 +6 +14ms ++ +09 +13 +3m30s ++ +10 +4 +4m10s ++ +11 +1 +57s159ms ++ +12 +2 +1m3s ++ +13 +1 +34s394ms ++ +14 +1 +1m12s ++ +15 +1 +24s417ms ++ + +16 +0 +0ms +
+ -
+
Connections
+ + +++ +Established Connections
+++Key values
+++-
+
- 5 connections Connection Peak +
- 2019-03-18 09:00:08 Date +
+ + + ++++ +Connections per database
+++ +Key values
+++-
+
- ubm Main Database +
- 130 connections Total +
++ + + +Connections per user
+++ +Key values
+++-
+
- ptrowbridge_md5 Main User +
- 130 connections Total +
+ -
+
Sessions
+ + +++ +Simultaneous sessions
+++Key values
+++-
+
- 9 sessions Session Peak +
- 2019-03-15 16:48:38 Date +
+ + + ++++ +Histogram of session times
+++ +Key values
+++-
+
- 38 0-500ms duration +
++ +Sessions per database
+++ +Key values
+++-
+
- ubm Main Database +
- 125 sessions Total +
++ +Sessions per user
+++ +Key values
+++-
+
- ptrowbridge_md5 Main User +
- 125 sessions Total +
++ +Sessions per host
+++ +Key values
+++-
+
- USHCC10107.GBL.HC-companies.com Main Host +
- 125 sessions Total +
++ +Sessions per application
+++Key values
+++-
+
- psql Main Host +
- 125 sessions Total +
+++ +++++ + + +++++ +
++ + + +Application +Count +Total Duration +Average Duration +DBeaver 5.3.5 - Main 2 6h49m55s 3h24m57s DBeaver 5.3.5 - Metadata 2 6h49m55s 3h24m57s DBeaver 5.3.5 - Read PostgreSQL database list 2 2s56ms 1s28ms DBeaver 6.0.0 - Main 1 4h42m22s 4h42m22s DBeaver 6.0.0 - Metadata 1 4h42m22s 4h42m22s DBeaver 6.0.0 - Read PostgreSQL database list 1 101ms 101ms [unknown] 16 1h12m25s 4m31s osm_api 32 1d5h19m45s 54m59s pgAdmin 4 - DB:postgres 2 15m53s 7m56s pgAdmin 4 - DB:ubm 7 15m52s 2m16s pg_dump 2 6m4s 3m2s pg_dumpall 4 270ms 67ms psql 36 39m4s 1m5s + +runner 17 24m13s 1m25s
+ -
+
+
Checkpoints / Restartpoints
+ +++ +Checkpoints Buffers
+++Key values
+++-
+
- 85,051 buffers Checkpoint Peak +
- 2019-03-15 00:55:53 Date +
- 150.075 seconds Highest write time +
- 0.402 seconds Sync time +
+ + + ++++ +Checkpoints Wal files
+++Key values
+++-
+
- 42 files Wal files usage Peak +
- 2019-03-15 14:12:03 Date +
+ + + ++++ +Checkpoints distance
+++Key values
+++-
+
- 1,363.03 Mo Distance Peak +
- 2019-03-15 14:12:03 Date +
+ + + ++++ +Checkpoints Activity
++ ++ +++ ↑ Back to the top of the Checkpoint Activity table ++++ +
++ + +Day +Hour +Written buffers +Write time +Sync time +Total time +Mar 14 01 1 0.106s 0.072s 0.232s 10 17 1.706s 0.008s 1.731s 11 18 1.84s 0.063s 2.192s 12 17 1.728s 0.028s 1.88s 16 5 0.608s 0.14s 0.905s 17 10,965 227.98s 0.159s 228.782s 22 0 0s 0s 0s 23 0 0s 0s 0s Mar 15 00 89,908 266.772s 0.108s 268.024s 01 34,249 1.191s 0.402s 1.71s 09 6 0.608s 0.01s 0.653s 10 0 0s 0s 0s 11 0 0s 0s 0s 12 0 0s 0s 0s 13 0 0s 0s 0s 14 135,764 298.943s 0.092s 299.387s 15 0 0s 0s 0s 16 83,725 149.627s 0.051s 150.551s 17 26,524 150.075s 0.035s 150.292s 19 0 0s 0s 0s 21 0 0s 0s 0s Mar 16 01 0 0s 0s 0s 02 0 0s 0s 0s 05 0 0s 0s 0s 19 0 0s 0s 0s Mar 18 08 2 0.004s 0.094s 0.152s 09 63 6.38s 0.065s 6.587s 10 38 3.943s 0.019s 3.98s 11 8 0.837s 0.009s 0.857s 12 0 0s 0s 0s 13 0 0s 0s 0s 14 0 0s 0s 0s 15 0 0s 0s 0s + +16 0 0s 0s 0s +++ +
++ + +Day +Hour +Added +Removed +Recycled +Synced files +Longest sync +Average sync +Mar 14 01 0 0 0 1 0.072s 0.072s 10 0 0 0 2 0.008s 0.004s 11 0 0 0 9 0.011s 0.046s 12 0 0 0 6 0.010s 0.019s 16 0 1 0 6 0.109s 0.023s 17 0 4 0 90 0.015s 0.003s 22 0 0 0 0 0s 0s 23 0 0 0 0 0s 0s Mar 15 00 0 4 42 40 0.061s 0.003s 01 0 0 11 17 0.304s 0.023s 09 0 0 0 4 0.008s 0.002s 10 0 0 0 0 0s 0s 11 0 0 0 0 0s 0s 12 0 0 0 0 0s 0s 13 0 0 0 0 0s 0s 14 0 0 61 64 0.064s 0.003s 15 0 0 0 0 0s 0s 16 0 0 42 45 0.006s 0.002s 17 0 0 15 28 0.008s 0.001s 19 0 0 0 0 0s 0s 21 0 0 0 0 0s 0s Mar 16 01 0 0 0 0 0s 0s 02 0 0 0 0 0s 0s 05 0 0 0 0 0s 0s 19 0 0 0 0 0s 0s Mar 18 08 0 0 0 2 0.094s 0.047s 09 0 0 0 43 0.013s 0.013s 10 0 0 0 20 0.011s 0s 11 0 0 0 5 0.008s 0.001s 12 0 0 0 0 0s 0s 13 0 0 0 0 0s 0s 14 0 0 0 0 0s 0s 15 0 0 0 0 0s 0s + +16 0 0 0 0 0s 0s +++ +
++ + +Day +Hour +Count +Avg time (sec) +Mar 14 01 0 0s 10 0 0s 11 0 0s 12 0 0s 16 0 0s 17 0 0s 22 0 0s 23 0 0s Mar 15 00 0 0s 01 0 0s 09 0 0s 10 0 0s 11 0 0s 12 0 0s 13 0 0s 14 0 0s 15 0 0s 16 0 0s 17 0 0s 19 0 0s 21 0 0s Mar 16 01 0 0s 02 0 0s 05 0 0s 19 0 0s Mar 18 08 0 0s 09 0 0s 10 0 0s 11 0 0s 12 0 0s 13 0 0s 14 0 0s 15 0 0s + +16 0 0s +++ +
++ + +Day +Hour +Mean distance +Mean estimate +Mar 14 01 4.00 kB 4.00 kB 10 118.00 kB 118.00 kB 11 16.83 kB 87.83 kB 12 24.00 kB 60.00 kB 16 12,614.00 kB 12,614.00 kB 17 22,110.67 kB 24,047.67 kB 22 0.00 kB 0.00 kB 23 0.00 kB 0.00 kB Mar 15 00 379,405.50 kB 379,405.50 kB 01 0.00 kB 0.00 kB 09 4.00 kB 4.00 kB 10 0.00 kB 0.00 kB 11 0.00 kB 0.00 kB 12 0.00 kB 0.00 kB 13 0.00 kB 0.00 kB 14 497,784.00 kB 677,863.50 kB 15 0.00 kB 0.00 kB 16 345,627.00 kB 641,659.00 kB 17 254,722.00 kB 647,596.00 kB 19 0.00 kB 0.00 kB 21 0.00 kB 0.00 kB Mar 16 01 0.00 kB 0.00 kB 02 0.00 kB 0.00 kB 05 0.00 kB 0.00 kB 19 0.00 kB 0.00 kB Mar 18 08 0.00 kB 0.00 kB 09 69.00 kB 132.60 kB 10 255.00 kB 255.00 kB 11 0.00 kB 229.00 kB 12 0.00 kB 0.00 kB 13 0.00 kB 0.00 kB 14 0.00 kB 0.00 kB 15 0.00 kB 0.00 kB + +16 0.00 kB 0.00 kB
+ -
+
+
Temporary Files
+ +++ +Size of temporary files
+++Key values
+++-
+
- 2.31 GiB Temp Files size Peak +
- 2019-03-15 16:48:07 Date +
+ + + ++++ +Number of temporary files
+++Key values
+++-
+
- 6 per second Temp Files Peak +
- 2019-03-15 14:09:18 Date +
+ + + ++++ +Temporary Files Activity
+++ +-
+
- Temp Files +
++ ↑ Back to the top of the Temporary Files Activity table ++++ +
++ + +Day +Hour +Count +Total size +Average size +Mar 14 01 0 0 0 10 0 0 0 11 0 0 0 12 0 0 0 16 0 0 0 17 0 0 0 22 0 0 0 23 0 0 0 Mar 15 00 7 3.06 GiB 448.31 MiB 01 0 0 0 09 0 0 0 10 0 0 0 11 0 0 0 12 0 0 0 13 0 0 0 14 7 3.07 GiB 448.43 MiB 15 0 0 0 16 7 3.07 GiB 448.56 MiB 17 0 0 0 19 0 0 0 21 0 0 0 Mar 16 01 0 0 0 02 0 0 0 05 0 0 0 19 0 0 0 Mar 18 08 0 0 0 09 0 0 0 10 0 0 0 11 0 0 0 12 0 0 0 13 0 0 0 14 0 0 0 15 0 0 0 +16 0 0 0 +++ +Queries generating the most temporary files (N)
++++ +
++ + + + +Rank +Count +Total size +Min size +Max size +Avg size +Query ++ + + +1 +21 +9.20 GiB +285.24 MiB +778.25 MiB +448.43 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++ + +++ +-
+
+
-
+ INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++ +
+
Date: 2019-03-15 14:09:18 +Duration: 0ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ +Queries generating the largest temporary files
++++ +
++ + + + +Rank +Size +Query ++ + +1 +778.25 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 16:48:41 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +2 +777.94 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 14:09:42 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +3 +777.67 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 00:53:37 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +4 +464.89 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 16:48:07 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +5 +464.79 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 14:09:18 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +6 +464.70 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 00:52:54 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +7 +452.11 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 16:48:07 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +8 +452.01 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 14:09:18 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +9 +451.93 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 00:52:54 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +10 +435.58 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 16:48:07 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +11 +435.48 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 14:09:18 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +12 +435.39 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 00:52:54 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +13 +424.71 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 16:48:07 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +14 +424.62 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 14:09:18 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +15 +424.53 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 00:52:54 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +16 +298.93 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 16:48:07 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +17 +298.83 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 14:09:18 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +18 +298.74 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 00:52:54 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + +19 +285.42 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 16:48:07 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
++ + + +20 +285.32 MiB ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 14:09:18 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
+
+ -
+
+
Vacuums
+ +++ +Vacuums / Analyzes Distribution
+++Key values
+++-
+
- 0 sec Highest CPU-cost vacuum
Table
Database
+ - Date +
- 0 sec Highest CPU-cost analyze
Table
Database
+ - Date +
+ + + ++++ +Analyzes per table
+++ +Key values
+++-
+
- import.osmi (5) Main table analyzed (database ubm) +
- 9 analyzes Total +
++ +Vacuums per table
+++ +Key values
+++-
+
- import.osmi (4) Main table vacuumed on database ubm +
- 5 vacuums Total +
++ +Tuples removed per table
+++ +Key values
+++-
+
- import.osmi (103249) Main table with removed tuples on database ubm +
- 128920 tuples Total removed +
++ +Pages removed per table
+++ +Key values
+++-
+
- import.osmi (5638) Main table with removed pages on database ubm +
- 5638 pages Total removed +
++ +Autovacuum Activity
++ ++ +++ ↑ Back to the top of the Autovacuum Activity table ++++ +
++ + +Day +Hour +VACUUMs +ANALYZEs +Mar 14 01 0 0 10 0 0 11 0 0 12 0 0 16 0 0 17 0 1 22 0 0 23 0 0 Mar 15 00 2 3 01 0 0 09 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 2 3 15 0 0 16 1 2 17 0 0 19 0 0 21 0 0 Mar 16 01 0 0 02 0 0 05 0 0 19 0 0 Mar 18 08 0 0 09 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 +16 0 0 +
+ - 0 sec Highest CPU-cost vacuum
-
+
+
Locks
+++ +Locks by types
+++ +Key values
+++-
+
- unknown Main Lock Type +
- 0 locks Total +
++ +Most frequent waiting queries (N)
++++ +
++ + + +Rank +Count +Total time +Min time +Max time +Avg duration +Query + + +NO DATASET
++ +Queries that waited the most
++++ +
++ + + +Rank +Wait time +Query + + +NO DATASET
+ -
+
+
Queries
+++ +Queries by type
+++ +Key values
+++-
+
- 22,915 Total read queries +
- 5,838 Total write queries +
++ +Queries by database
+++Key values
+++-
+
- ubm Main database +
- 68,215 Requests +
- 42m15s (ubm) +
- Main time consuming database +
+++ +++++ + + +++++ +
++ + + +Database +Request type +Count +Duration +postgres Total 206 580ms OTHERS 2 0ms SELECT 101 0ms ubm Total 68,215 42m15s COPY TO 5,190 0ms CTE 30 0ms DDL 75 2s707ms DELETE 24 24s14ms INSERT 432 9m49s OTHERS 5,477 11m19s SELECT 22,814 2s267ms TCL 87 0ms unknown Total 56 5m + +OTHERS 56 5m ++ +Queries by user
+++Key values
+++-
+
- ptrowbridge Main user +
- 66,332 Requests +
++++-
+
- Queries Chart +
- Table +
+++ + + +++++ +
++ + + +User +Request type +Count +Duration +api Total 304 1m4s CTE 26 0ms OTHERS 130 12s165ms postgres Total 24 60ms SELECT 12 0ms ptrowbridge Total 66,332 5m57s COPY TO 5,190 0ms CTE 2 0ms OTHERS 5,217 0ms SELECT 22,756 0ms TCL 2 0ms ptrowbridge_md5 Total 1,353 28m29s CTE 2 0ms DDL 4 0ms DELETE 24 24s14ms INSERT 432 9m49s OTHERS 70 7m50s SELECT 99 2s267ms TCL 53 0ms report Total 408 6m44s DDL 71 2s707ms OTHERS 62 3m17s SELECT 48 0ms TCL 32 0ms unknown Total 56 5m + +OTHERS 56 5m ++ +Duration by user
+++Key values
+++-
+
- 28m29s (ptrowbridge_md5) Main time consuming user +
++++-
+
- Duration Chart +
- Table +
+++ + + +++++ +
++ + + +User +Request type +Count +Duration +api Total 304 1m4s CTE 26 0ms OTHERS 130 12s165ms postgres Total 24 60ms SELECT 12 0ms ptrowbridge Total 66,332 5m57s COPY TO 5,190 0ms CTE 2 0ms OTHERS 5,217 0ms SELECT 22,756 0ms TCL 2 0ms ptrowbridge_md5 Total 1,353 28m29s CTE 2 0ms DDL 4 0ms DELETE 24 24s14ms INSERT 432 9m49s OTHERS 70 7m50s SELECT 99 2s267ms TCL 53 0ms report Total 408 6m44s DDL 71 2s707ms OTHERS 62 3m17s SELECT 48 0ms TCL 32 0ms unknown Total 56 5m + +OTHERS 56 5m ++ +Queries by host
+++Key values
+++-
+
- USHCC10107.GBL.HC-companies.com Main host +
- 68,063 Requests +
- 41m42s (USHCC10107.GBL.HC-companies.com) +
- Main time consuming host +
+++ +++++ + + +++++ +
++ + + +Host +Request type +Count +Duration +USHCC10107 Total 68 109ms SELECT 34 0ms USHCC10107.GBL.HC-companies.com Total 68,063 41m42s COPY TO 5,190 0ms CTE 30 0ms DDL 75 2s707ms DELETE 24 24s14ms INSERT 432 9m49s OTHERS 5,424 11m8s SELECT 22,788 2s267ms TCL 87 0ms [local] Total 24 60ms SELECT 12 0ms ubreport Total 266 33s847ms OTHERS 55 10s837ms SELECT 81 0ms unknown Total 56 5m + +OTHERS 56 5m ++ +Queries by application
+++Key values
+++-
+
- pg_dump Main application +
- 64,216 Requests +
- 28m20s (psql) +
- Main time consuming application +
+++ +++++ + + +++++ +
++ + + +Application +Request type +Count +Duration +DBeaver 5.3.5 - Main Total 44 1s983ms CTE 2 0ms DELETE 4 0ms OTHERS 2 0ms SELECT 9 0ms TCL 4 0ms DBeaver 5.3.5 - Metadata Total 44 287ms OTHERS 2 0ms SELECT 19 0ms DBeaver 5.3.5 - Read PostgreSQL database list Total 6 1ms SELECT 2 0ms DBeaver 6.0.0 - Main Total 10 4s535ms OTHERS 1 0ms SELECT 2 2s267ms TCL 2 0ms DBeaver 6.0.0 - Metadata Total 19 34ms OTHERS 1 0ms SELECT 8 0ms DBeaver 6.0.0 - Read PostgreSQL database list Total 3 0ms SELECT 1 0ms PostgreSQL JDBC Driver Total 18 0ms OTHERS 9 0ms [unknown] Total 435 6m44s DDL 71 2s707ms OTHERS 80 3m17s SELECT 48 0ms TCL 32 0ms osm_api Total 304 1m4s CTE 26 0ms OTHERS 130 12s165ms pgAdmin 4 - DB:postgres Total 114 410ms OTHERS 2 0ms SELECT 55 0ms pgAdmin 4 - DB:ubm Total 1,904 14s46ms OTHERS 7 0ms SELECT 945 0ms pg_dump Total 64,216 5m42s COPY TO 5,190 0ms CTE 2 0ms OTHERS 5,208 0ms SELECT 21,706 0ms TCL 2 0ms pg_dumpall Total 68 109ms SELECT 34 0ms psql Total 156 28m20s DDL 4 0ms DELETE 20 24s14ms INSERT 14 9m49s OTHERS 3 7m50s SELECT 32 0ms TCL 13 0ms runner Total 1,080 2s983ms INSERT 418 0ms OTHERS 34 0ms SELECT 54 0ms TCL 34 0ms unknown Total 56 5m + +OTHERS 56 5m ++ +Number of cancelled queries
+++Key values
+++-
+
- 0 per second Cancelled query Peak +
- 2019-03-14 17:12:26 Date +
+ ++Number of cancelled queries (5 minutes period)
++ +NO DATASET
+ -
+
+
Top Queries
+++ +Histogram of query times
+++ +Key values
+++-
+
- 31,367 0-1ms duration +
++ +Slowest individual queries
++++ +
++ + + + +Rank +Duration +Query ++ + + +1 +4m7s ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 00:53:37 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
+ +++ +Insert on osm_ppfa_varto_mv (cost=0.25..10.25 rows=1000 width=1520) (actual time=247216.314..247216.314 rows=0 loops=1) + Buffers: shared hit=1716294 read=197994 dirtied=106936 written=127, local hit=5658761 read=4 dirtied=2, temp read=384787 written=401694 + I/O Timings: read=8265.132 write=1.395 + -> Function Scan on osm_ppfa_varto (cost=0.25..10.25 rows=1000 width=1520) (actual time=209413.211..214181.385 rows=1377873 loops=1) + Buffers: shared hit=106558 read=91107 dirtied=50, local hit=5658761 read=4 dirtied=2, temp read=384787 written=401694 + I/O Timings: read=8253.083 + +
++ + + +2 +3m19s ++ +PL/pgSQL function rlarp.osm_ppfa_varto() line 69 at RETURN QUERYWITH + ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- + SEG AS ( + SELECT + x.GLEC + ,x.SEGM + FROM + ( + VALUES + ('1CU','Retail'), + ('1GR','Greenhouse'), + ('1NU','Nursery'), + ('1RE','Retail'), + ('2WI','Greenhouse'), + ('3BM','Other'), + ('3CO','Other'), + ('3PE','Other'), + ('3PP','Other'), + ('4CO','Other'), + ('4RA','Other'), + ('9MI','Other'), + ('9SA','Other'), + ('9TO','Other') + ) X(GLEC, SEGM) + ) + ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- + ,MG AS ( + SELECT + X.F1, X.MING, X.GRP + FROM + ( + VALUES + ('L','000','Branded'), + ('L','B10','Branded'), + ('L','B11','Branded'), + ('L','B52','Branded'), + ('L','C10','Branded'), + ('L','D12','Branded'), + ('L','M11','Branded'), + ('L','P12','Branded'), + ('L','P13','Branded'), + ('L','S10','Branded'), + ('L','Y10','Branded'), + ('L','Y11','Branded'), + ('L','Y12','Branded'), + ('P','B10','Branded'), + ('P','B11','Branded'), + ('P','B52','Branded') + ) AS X (F1, MING, GRP) + ) + ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- + ,REPC AS ( + SELECT + LTRIM(RTRIM(C.A9)) RCODE + ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP + ,COALESCE(Q.DIR,'Other') DIRECTOR + FROM + LGDAT.CODE C + LEFT OUTER JOIN RLARP.QRH Q ON + Q.QR = LTRIM(RTRIM(C.A9)) + WHERE + C.A2 = 'MM' + ) + --MOLD DESCRIPTIONS + ,MD AS ( + SELECT + U.MOLD + ,MAX(U.DESCR) DESCR + FROM + ( + SELECT + SUBSTR(M.AVPART,1,8) MOLD + ,MAX(M.AVDES1) DESCR + FROM + LGDAT.STKMM M + WHERE + LENGTH(M.AVPART) > 8 + AND SUBSTR(M.AVGLED,1,1) <= '2' + GROUP BY + SUBSTR(M.AVPART,1,8) + UNION ALL + SELECT + SUBSTR(P.AWPART,1,8) MOLD + ,MAX(P.AWDES1) DESCR + FROM + LGDAT.STKMP P + WHERE + LENGTH(P.AWPART) > 8 + AND SUBSTR(P.AWGLED,1,1) <= '2' + GROUP BY + SUBSTR(P.AWPART,1,8) + ) U + GROUP BY + U.MOLD + ) + ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- + ,SJ AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = '' + ) + ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- + ,SI AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> '' + ) + ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ + ,seas AS( + SELECT + ssyr + ,daterange(MIN(sdat),MAX(edat),'[]') dr + ,current_date <@ daterange(MIN(sdat),MAX(edat),'[]') cy + FROM + gld + GROUP BY + ssyr + ORDER BY + ssyr DESC + ) + ,intv AS ( + SELECT current_date - lower(dr) dy from seas where cy = true + ) + ,std AS ( + SELECT + s.ssyr + ,s.dr + ,s.cy + ,daterange(lower(dr),dy + LOWER(dr),'[]') ytd + FROM + seas s + CROSS JOIN intv + ) + ---------------------------------------union actual and forecast--------------------------------------------------------------------------------------------------------------------------------------- + ,UN AS ( + --plan + SELECT + 'Budget' AS VERSION + ,'Budget' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE as ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(m.avNWHT,p.awNWHT) * CASE COALESCE(m.avNWUN, p.awNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMP OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = 'b19' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --staged forecast + SELECT + 'Forecast' AS VERSION + ,'Forecast' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMF OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = '5p7' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --actual + SELECT + 'Actual' AS VERSION + ,'Actual' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSM OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + --AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.CALC_STATUS <> 'CANCELED' + AND + ( + OSM.FSPR >= '1606' + OR OSM.ADJ_ORDERDATE >= '2016-06-01' + ) + GROUP BY + --VERSION + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + ) + ---------------------------------------aggregate actual and forecast----------------------------------------------------------------------------------------------------------------------------------- + ,AGG AS ( + SELECT + un.VERSION::text "version" + ,un.ITER::text "iter" + ,un.OSEAS::numeric oseas + ,un.ODATE::date odate + ,un.SSEAS::numeric sseas + ,un.SDATE::date sdate + ,un.RSEAS::numeric rseas + ,un.RDATE::date rdate + ,un.OM::text om + ,un.SM::text sm + ,un.RM::text rm + ,un.OY::text oy + ,(un.odate <@ _ytd)::boolean ocytd --current year to date + ,(un.odate <@ so.ytd)::boolean oytd --year to date recast for prior/forecast periods + ,un.SY::text sy + ,(un.sdate <@ _ytd)::boolean scytd + ,(un.sdate <@ ss.ytd)::boolean sytd + --had this order been placed yet? (current day prior year is greater than the order date) + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END status_py + ,un.RY::text ry + ,un.PLNT::text plnt + ,un.ACCOUNT::text bill_group + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text bill_cust + ,bc.bvctry bill_ctry + ,bc.bvprcd bill_prov + ,un.SHIPGRP::text ship_group + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text ship_cust + ,sc.bvctry ship_ctry + ,sc.bvprcd ship_prov + ,un.CHAN::text chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text mod_chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text mod_chansub + ,un.PROMO::text promo + ,un.MAJG||COALESCE(' - '||BQDES,'')::text majg + ,un.MING||COALESCE(' - '||BRDES,'')::text ming + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text majs + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text mins + ,un.PART::text part + ,un.PART_DESCR::text part_descr + ,un.PART_FAMILY::text part_family + ,un.PART_GROUP::text part_group + ,un.BRANDING::text branding + ,un.SEGM::text segm + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text quota_rep + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text director + ,SUM(un.QTY)::numeric qty + ,SUM(un.SALES)::numeric sales + ,SUM(un.STDCOST)::numeric stdcost + ,SUM(un.QTY * COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur + ,SUM(un.POUNDS)::numeric pounds + ,(un.VERSION||'-'||un.SY)::text flag_s + ,(un.VERSION||'-'||un.OY)::text flag_o + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text status + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text "options" + ,'Grand Total'::text grandtotal + FROM + UN + LEFT OUTER JOIN REPC ON + REPC.RCODE = un.QUOTA_REP + LEFT OUTER JOIN SI ON + SI.BSMJCD = UN.MAJS + AND SI.BSMNCD = UN.MINS + LEFT OUTER JOIN SJ ON + SJ.BSMJCD = UN.MAJS + LEFT OUTER JOIN LGDAT.MAJG ON + BQGRP = un.MAJG + LEFT OUTER JOIN LGDAT.MMGP ON + BRMGRP = un.MING + AND BRGRP = un.MAJG + LEFT OUTER JOIN LGDAT.CUST BC ON + BC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.CUST SC ON + SC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.ICSTM cm ON + cm.cgpart = un.part + AND cm.cgplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTP cp ON + cp.chpart = un.part + AND cp.chplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTR cr ON + cr.y0part = un.part + AND cr.y0plnt = un.plnt + LEFT OUTER JOIN STD so ON + so.ssyr = un.oseas + LEFT OUTER JOIN STD ss ON + ss.ssyr = un.sseas + GROUP BY + un.VERSION::text + ,un.ITER::text + ,un.OSEAS::numeric + ,un.ODATE::date + ,un.SSEAS::numeric + ,un.SDATE::date + ,un.RSEAS::numeric + ,un.RDATE::date + ,un.OM::text + ,un.SM::text + ,un.RM::text + ,un.OY::text + --current year to date + ,(un.odate <@ _ytd)::boolean + --year to date recast for prior/forecast periods + ,(un.odate <@ so.ytd)::boolean + ,un.SY::text + ,(un.sdate <@ _ytd)::boolean + ,(un.sdate <@ ss.ytd)::boolean + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END + ,un.RY::text + ,un.PLNT::text + ,un.ACCOUNT::text + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text + ,bc.bvctry + ,bc.bvprcd + ,un.SHIPGRP::text + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text + ,sc.bvctry + ,sc.bvprcd + ,un.CHAN::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text + ,un.PROMO::text + ,un.MAJG||COALESCE(' - '||BQDES,'')::text + ,un.MING||COALESCE(' - '||BRDES,'')::text + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text + ,un.PART::text + ,un.PART_DESCR::text + ,un.PART_FAMILY::text + ,un.PART_GROUP::text + ,un.BRANDING::text + ,un.SEGM::text + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text + ,(un.VERSION||'-'||un.SY)::text + ,(un.VERSION||'-'||un.OY)::text + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text + ,'Grand Total'::text + ) + SELECT + a.version + ,a.iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,a.qty + ,a.sales + ,a.stdcost + ,a.stdcost_cur + ,a.pounds + ,a.flag_s + ,a.flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + agg a + UNION ALL + SELECT + 'Var to Fcst' as version + ,'Var to Fcst' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Fcst'||'-'||a.scytd flag_s + ,'Var to Fcst'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Forecast') + AND (a.ocytd OR a.scytd) + + UNION ALL + SELECT + 'Var to Bdgt' as version + ,'Var to Bdgt' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Bdgt'||'-'||a.scytd flag_s + ,'Var to Bdgt'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Budget') + AND (a.ocytd OR a.scytd) +;+[ Date: 2019-03-15 00:52:54 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
+ +++ +Append (cost=4510966117154.68..4644894879274.93 rows=1921380827591 width=1520) (actual time=182826.066..198343.560 rows=1377873 loops=1) + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=285245 written=302150 + I/O Timings: read=8179.425 + CTE seg + -> Values Scan on "*VALUES*" (cost=0.00..0.18 rows=14 width=64) (actual time=0.001..0.004 rows=14 loops=1) + CTE mg + -> Values Scan on "*VALUES*_1" (cost=0.00..0.20 rows=16 width=96) (actual time=0.002..0.006 rows=16 loops=1) + CTE repc + -> Hash Left Join (cost=11.47..123.28 rows=120 width=96) (actual time=2.591..12.439 rows=120 loops=1) + Hash Cond: (ltrim(rtrim(c.a9)) = q.qr) + Buffers: shared read=26 + I/O Timings: read=11.445 + -> Bitmap Heap Scan on code c (cost=9.21..118.86 rows=120 width=25) (actual time=2.207..11.727 rows=120 loops=1) + Recheck Cond: (a2 = 'MM'::text) + Heap Blocks: exact=21 + Buffers: shared read=25 + I/O Timings: read=11.107 + -> Bitmap Index Scan on pk_code (cost=0.00..9.18 rows=120 width=0) (actual time=1.684..1.684 rows=120 loops=1) + Index Cond: (a2 = 'MM'::text) + Buffers: shared read=4 + I/O Timings: read=1.575 + -> Hash (cost=1.56..1.56 rows=56 width=12) (actual time=0.368..0.368 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.337 + -> Seq Scan on qrh q (cost=0.00..1.56 rows=56 width=12) (actual time=0.349..0.355 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.337 + CTE md + -> HashAggregate (cost=11936.00..11938.00 rows=200 width=64) (actual time=95.558..96.083 rows=3368 loops=1) + Group Key: (substr(m.avpart, 1, 8)) + Buffers: shared hit=9056 + -> Append (cost=8137.31..11870.54 rows=13091 width=64) (actual time=83.235..94.596 rows=3375 loops=1) + Buffers: shared hit=9056 + -> HashAggregate (cost=8137.31..8249.94 rows=9010 width=64) (actual time=83.233..84.126 rows=3285 loops=1) + Group Key: substr(m.avpart, 1, 8) + Buffers: shared hit=6448 + -> Seq Scan on stkmm m (cost=0.00..8092.26 rows=9010 width=59) (actual time=0.012..41.548 rows=76269 loops=1) + Filter: ((length(avpart) > 8) AND (substr(avgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 4728 + Buffers: shared hit=6448 + -> HashAggregate (cost=3373.23..3424.24 rows=4081 width=64) (actual time=10.241..10.276 rows=90 loops=1) + Group Key: substr(p.awpart, 1, 8) + Buffers: shared hit=2608 + -> Seq Scan on stkmp p (cost=0.00..3352.82 rows=4081 width=52) (actual time=0.579..10.168 rows=142 loops=1) + Filter: ((length(awpart) > 8) AND (substr(awgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 36557 + Buffers: shared hit=2608 + CTE sj + -> Seq Scan on mmsl (cost=0.00..1.84 rows=1 width=22) (actual time=0.006..0.010 rows=11 loops=1) + Filter: (COALESCE(bsmncd, ''::text) = ''::text) + Rows Removed by Filter: 56 + Buffers: shared hit=1 + CTE si + -> Seq Scan on mmsl mmsl_1 (cost=0.00..1.84 rows=66 width=22) (actual time=0.342..0.348 rows=56 loops=1) + Filter: (COALESCE(bsmncd, ''::text) <> ''::text) + Rows Removed by Filter: 11 + Buffers: shared read=1 + I/O Timings: read=0.330 + CTE seas + -> GroupAggregate (cost=10.22..16.31 rows=174 width=41) (actual time=0.064..0.094 rows=15 loops=1) + Group Key: gld.ssyr + Buffers: local hit=2 + -> Sort (cost=10.22..10.65 rows=174 width=16) (actual time=0.052..0.059 rows=174 loops=1) + Sort Key: gld.ssyr DESC + Sort Method: quicksort Memory: 33kB + Buffers: local hit=2 + -> Seq Scan on gld (cost=0.00..3.74 rows=174 width=16) (actual time=0.010..0.029 rows=174 loops=1) + Buffers: local hit=2 + CTE intv + -> CTE Scan on seas (cost=0.00..4.13 rows=87 width=4) (actual time=0.077..0.078 rows=1 loops=1) + Filter: cy + Rows Removed by Filter: 14 + Buffers: local hit=2 + CTE std + -> Nested Loop (cost=0.00..457.62 rows=15138 width=73) (actual time=0.080..0.112 rows=15 loops=1) + Buffers: local hit=2 + -> CTE Scan on intv (cost=0.00..1.74 rows=87 width=4) (actual time=0.078..0.079 rows=1 loops=1) + Buffers: local hit=2 + -> CTE Scan on seas s (cost=0.00..3.48 rows=174 width=41) (actual time=0.000..0.026 rows=15 loops=1) + CTE un + -> Append (cost=50003223.80..255856479.46 rows=330423099 width=697) (actual time=34264.289..81644.471 rows=812229 loops=1) + Buffers: shared hit=98372 read=72635, local hit=5658753 read=1 + I/O Timings: read=7746.456 + -> GroupAggregate (cost=50003223.80..63823292.65 rows=83757993 width=701) (actual time=34264.288..36465.643 rows=212793 loops=1) + Group Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Buffers: shared hit=45043 read=23493, local hit=2563791 read=1 + I/O Timings: read=3613.602 + -> Sort (cost=50003223.80..50212618.79 rows=83757993 width=594) (actual time=34264.218..34431.899 rows=641010 loops=1) + Sort Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Sort Method: quicksort Memory: 352782kB + Buffers: shared hit=45043 read=23493, local hit=2563791 read=1 + I/O Timings: read=3613.602 + -> Hash Left Join (cost=11749.79..16650773.71 rows=83757993 width=594) (actual time=523.585..12806.506 rows=641010 loops=1) + Hash Cond: ((osm.bill_class = l.bill) AND (osm.ship_class = l.ship)) + Buffers: shared hit=45040 read=23493, local hit=2563791 read=1 + I/O Timings: read=3613.602 + -> Hash Left Join (cost=11744.32..10583311.94 rows=83757993 width=583) (actual time=522.937..12019.634 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 8) = md.mold) + Buffers: shared hit=45040 read=23491, local hit=2563791 read=1 + I/O Timings: read=3613.055 + -> Hash Left Join (cost=11737.82..5348430.88 rows=83757993 width=551) (actual time=425.063..11458.763 rows=641010 loops=1) + Hash Cond: (osm.part = p_1.awpart) + Buffers: shared hit=35984 read=23491, local hit=2563791 read=1 + I/O Timings: read=3613.055 + -> Nested Loop Left Join (cost=8303.37..5125106.33 rows=83757993 width=527) (actual time=313.496..11101.481 rows=641010 loops=1) + Buffers: shared hit=35982 read=20885, local hit=2563791 read=1 + I/O Timings: read=3534.677 + -> Nested Loop Left Join (cost=8303.23..337594.45 rows=4332310 width=455) (actual time=313.488..8642.098 rows=641010 loops=1) + Buffers: shared hit=35982 read=20885, local hit=1281897 read=1 + I/O Timings: read=3534.677 + -> Hash Left Join (cost=8303.08..89964.52 rows=224085 width=383) (actual time=313.453..5992.381 rows=641010 loops=1) + Hash Cond: (osm.part = m_1.avpart) + Buffers: shared hit=35982 read=20885, local hit=2 + I/O Timings: read=3534.662 + -> Hash Left Join (cost=30.62..81103.81 rows=224085 width=348) (actual time=12.984..5414.171 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 3) = f.f3) + Buffers: shared hit=35980 read=14439, local hit=2 + I/O Timings: read=3281.743 + -> Hash Left Join (cost=6.93..77718.84 rows=224085 width=324) (actual time=0.106..4996.296 rows=641010 loops=1) + Hash Cond: ((substr(osm.part, 16, 1) = mg.f1) AND (osm.ming = mg.ming)) + Buffers: shared hit=35980 read=14430, local hit=2 + I/O Timings: read=3269.024 + -> Hash Left Join (cost=6.37..75750.09 rows=224085 width=292) (actual time=0.084..4563.487 rows=641010 loops=1) + Hash Cond: (osm.glec = seg.glec) + Buffers: shared hit=35980 read=14430, local hit=2 + I/O Timings: read=3269.024 + -> Hash Left Join (cost=5.92..72674.81 rows=224085 width=264) (actual time=0.070..4318.873 rows=641010 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=35980 read=14430, local hit=2 + I/O Timings: read=3269.024 + -> Seq Scan on osmp osm (cost=0.00..69587.73 rows=224085 width=184) (actual time=0.017..4055.770 rows=641010 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = 'b19'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 57051 + Buffers: shared hit=35980 read=14430 + I/O Timings: read=3269.024 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.048..0.048 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=112) (actual time=0.003..0.024 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.011..0.011 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.008 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.015..0.015 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.012 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=12.868..12.868 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared read=9 + I/O Timings: read=12.719 + -> Seq Scan on family f (cost=0.00..15.53 rows=653 width=24) (actual time=12.733..12.786 rows=653 loops=1) + Buffers: shared read=9 + I/O Timings: read=12.719 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=300.407..300.407 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=2 read=6446 + I/O Timings: read=252.919 + -> Seq Scan on stkmm m_1 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.600..277.166 rows=80997 loops=1) + Buffers: shared hit=2 read=6446 + I/O Timings: read=252.919 + -> Index Scan using se_dat on gld od (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1281895 read=1 + I/O Timings: read=0.015 + -> Index Scan using se_dat on gld rd (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_requestdate >= sdat) AND (osm.adj_requestdate <= edat)) + Buffers: local hit=1281894 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=108.057..108.057 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2 read=2606 + I/O Timings: read=78.378 + -> Seq Scan on stkmp p_1 (cost=0.00..2975.31 rows=36731 width=33) (actual time=1.096..89.328 rows=36699 loops=1) + Buffers: shared hit=2 read=2606 + I/O Timings: read=78.378 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=97.843..97.843 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + Buffers: shared hit=9056 + -> CTE Scan on md (cost=0.00..4.00 rows=200 width=64) (actual time=95.561..97.114 rows=3368 loops=1) + Buffers: shared hit=9056 + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.629..0.629 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=2 + I/O Timings: read=0.546 + -> Seq Scan on ffchnl l (cost=0.00..3.39 rows=139 width=25) (actual time=0.574..0.596 rows=139 loops=1) + Buffers: shared read=2 + I/O Timings: read=0.546 + -> GroupAggregate (cost=33445583.00..42801951.72 rows=56705265 width=699) (actual time=21899.780..27106.566 rows=250477 loops=1) + Group Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Buffers: shared hit=35412, local hit=1627258 + -> Sort (cost=33445583.00..33587346.16 rows=56705265 width=595) (actual time=21899.740..22369.501 rows=406814 loops=1) + Sort Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Sort Method: quicksort Memory: 222052kB + Buffers: shared hit=35412, local hit=1627258 + -> Hash Left Join (cost=11749.79..11025086.80 rows=56705265 width=595) (actual time=82.385..8358.833 rows=406814 loops=1) + Hash Cond: ((osm_1.bill_class = l_1.bill) AND (osm_1.ship_class = l_1.ship)) + Buffers: shared hit=35412, local hit=1627258 + -> Hash Left Join (cost=11744.32..6967724.27 rows=55168846 width=584) (actual time=82.294..7619.217 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 8) = md_1.mold) + Buffers: shared hit=35410, local hit=1627258 + -> Hash Left Join (cost=11737.82..3519664.90 rows=55168846 width=552) (actual time=81.174..7139.198 rows=406814 loops=1) + Hash Cond: (osm_1.part = p_2.awpart) + Buffers: shared hit=35410, local hit=1627258 + -> Nested Loop Left Join (cost=8303.37..3371395.52 rows=55168846 width=528) (actual time=50.759..6837.840 rows=406814 loops=1) + Buffers: shared hit=32802, local hit=1627258 + -> Nested Loop Left Join (cost=8303.23..217901.28 rows=2853561 width=456) (actual time=50.749..4566.299 rows=406814 loops=1) + Buffers: shared hit=32802, local hit=813630 + -> Hash Left Join (cost=8303.08..54789.49 rows=147598 width=384) (actual time=50.729..2196.620 rows=406814 loops=1) + Hash Cond: (osm_1.part = m_2.avpart) + Buffers: shared hit=32802, local hit=2 + -> Hash Left Join (cost=30.62..46129.57 rows=147598 width=349) (actual time=0.257..1813.794 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 3) = f_1.f3) + Buffers: shared hit=26354, local hit=2 + -> Hash Left Join (cost=6.93..43891.91 rows=147598 width=325) (actual time=0.121..1436.906 rows=406814 loops=1) + Hash Cond: ((substr(osm_1.part, 16, 1) = mg_1.f1) AND (osm_1.ming = mg_1.ming)) + Buffers: shared hit=26345, local hit=2 + -> Hash Left Join (cost=6.37..42594.49 rows=147598 width=293) (actual time=0.110..1056.449 rows=406814 loops=1) + Hash Cond: (osm_1.glec = seg_1.glec) + Buffers: shared hit=26345, local hit=2 + -> Hash Left Join (cost=5.92..40564.57 rows=147598 width=265) (actual time=0.098..857.465 rows=406814 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=26345, local hit=2 + -> Seq Scan on osmf osm_1 (cost=0.00..38529.18 rows=147598 width=185) (actual time=0.026..619.289 rows=406814 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = '5p7'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 358 + Buffers: shared hit=26345 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.065..0.065 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=112) (actual time=0.008..0.035 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.007..0.007 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_1 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.004 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.007..0.007 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_1 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.003 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.131..0.131 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_1 (cost=0.00..15.53 rows=653 width=24) (actual time=0.010..0.054 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=50.417..50.417 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_2 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.005..27.523 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=406814) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=813628 + -> Index Scan using se_dat on gld rd_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.005 rows=1 loops=406814) + Index Cond: ((osm_1.adj_requestdate >= sdat) AND (osm_1.adj_requestdate <= edat)) + Buffers: local hit=813628 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=30.201..30.201 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_2 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.009..17.401 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=1.104..1.104 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_1 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.386 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.063..0.063 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_1 (cost=0.00..3.39 rows=139 width=25) (actual time=0.011..0.032 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=112931514.84..144274888.60 rows=189959841 width=695) (actual time=16710.998..17936.290 rows=348959 loops=1) + Group Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Buffers: shared hit=17917 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Sort (cost=112931514.84..113406414.44 rows=189959841 width=584) (actual time=16710.946..16814.969 rows=367211 loops=1) + Sort Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Sort Method: quicksort Memory: 201623kB + Buffers: shared hit=17917 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=11749.79..37465936.67 rows=189959841 width=584) (actual time=154.009..11372.141 rows=367211 loops=1) + Hash Cond: ((osm_2.bill_class = l_2.bill) AND (osm_2.ship_class = l_2.ship)) + Buffers: shared hit=17917 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=11744.32..23902628.82 rows=189959841 width=574) (actual time=153.913..10698.691 rows=367211 loops=1) + Hash Cond: (substr(osm_2.part, 1, 8) = md_2.mold) + Buffers: shared hit=17915 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=11737.82..12030132.26 rows=189959841 width=542) (actual time=148.767..10299.042 rows=367211 loops=1) + Hash Cond: (osm_2.part = p_3.awpart) + Buffers: shared hit=17915 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Nested Loop Left Join (cost=8303.37..11527995.69 rows=189959841 width=518) (actual time=102.067..10041.030 rows=367211 loops=1) + Buffers: shared hit=15307 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Nested Loop Left Join (cost=8303.23..670498.91 rows=9825509 width=446) (actual time=102.059..8236.690 rows=367211 loops=1) + Buffers: shared hit=15307 read=49142, local hit=733854 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=8303.08..108904.23 rows=508216 width=374) (actual time=102.031..6271.278 rows=367211 loops=1) + Hash Cond: (osm_2.part = m_3.avpart) + Buffers: shared hit=15307 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=30.62..99297.64 rows=508216 width=339) (actual time=6.361..5913.268 rows=367211 loops=1) + Hash Cond: (substr(osm_2.part, 1, 3) = f_2.f3) + Buffers: shared hit=8859 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=6.93..91650.71 rows=508216 width=315) (actual time=6.219..5568.521 rows=367211 loops=1) + Hash Cond: ((substr(osm_2.part, 16, 1) = mg_2.f1) AND (osm_2.ming = mg_2.ming)) + Buffers: shared hit=8850 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=6.37..87189.88 rows=508216 width=283) (actual time=6.207..5231.289 rows=367211 loops=1) + Hash Cond: (osm_2.glec = seg_2.glec) + Buffers: shared hit=8850 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=5.92..80265.15 rows=508216 width=255) (actual time=6.193..5042.515 rows=367211 loops=1) + Hash Cond: (osm_2.fspr = sd_2.fspr) + Buffers: shared hit=8850 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Seq Scan on osm osm_2 (cost=0.00..73663.10 rows=508216 width=175) (actual time=6.115..4852.376 rows=367211 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND ((fspr >= '1606'::text) OR (adj_orderdate >= '2016-06-01'::date))) + Rows Removed by Filter: 417318 + Buffers: shared hit=8850 read=49142 + I/O Timings: read=4132.855 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.064..0.064 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_2 (cost=0.00..3.74 rows=174 width=112) (actual time=0.009..0.036 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_2 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.003 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.006..0.006 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_2 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.131..0.131 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_2 (cost=0.00..15.53 rows=653 width=24) (actual time=0.010..0.051 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=95.611..95.611 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_3 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.005..42.484 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=367211) + Index Cond: ((osm_2.adj_orderdate >= sdat) AND (osm_2.adj_orderdate <= edat)) + Buffers: local hit=733852 + -> Index Scan using se_dat on gld rd_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=367211) + Index Cond: ((osm_2.adj_requestdate >= sdat) AND (osm_2.adj_requestdate <= edat)) + Buffers: local hit=733850 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=46.657..46.657 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_3 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.010..23.613 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=5.110..5.110 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_2 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.405 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.068..0.068 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_2 (cost=0.00..3.39 rows=139 width=25) (actual time=0.021..0.039 rows=139 loops=1) + Buffers: shared hit=2 + CTE agg + -> GroupAggregate (cost=3990139087947.22..4510710248131.84 rows=1892986037035 width=1404) (actual time=182825.587..189012.716 rows=809487 loops=1) + Group Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)), 'Grand Total'::text + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=169551 written=244303 + I/O Timings: read=8179.425 + -> Sort (cost=3990139087947.22..3994871553039.80 rows=1892986037035 width=1346) (actual time=182817.706..183828.314 rows=812229 loops=1) + Sort Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)) + Sort Method: external merge Disk: 475848kB + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=169551 written=244303 + I/O Timings: read=8179.425 + -> Merge Right Join (cost=33563712447.31..265517026370.70 rows=1892986037035 width=1346) (actual time=117209.936..123600.017 rows=812229 loops=1) + Merge Cond: (ss.ssyr = un.sseas) + Buffers: shared hit=101597 read=90963, local hit=5658755 read=1, temp read=110070 written=184821 + I/O Timings: read=8179.425 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.122..0.740 rows=15 loops=1) + Sort Key: ss.ssyr + Sort Method: quicksort Memory: 26kB + Buffers: local hit=2 + -> CTE Scan on std ss (cost=0.00..302.76 rows=15138 width=40) (actual time=0.081..0.117 rows=15 loops=1) + Buffers: local hit=2 + -> Materialize (cost=33563711093.53..33688759715.34 rows=25009724363 width=1300) (actual time=117198.447..119674.219 rows=812229 loops=1) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=110070 written=184821 + I/O Timings: read=8179.425 + -> Sort (cost=33563711093.53..33626235404.44 rows=25009724363 width=1300) (actual time=117198.083..117976.508 rows=812229 loops=1) + Sort Key: un.sseas + Sort Method: external merge Disk: 445840kB + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=110070 written=146582 + I/O Timings: read=8179.425 + -> Merge Right Join (cost=488162845.81..864134844.69 rows=25009724363 width=1300) (actual time=105501.163..109753.807 rows=812229 loops=1) + Merge Cond: (so.ssyr = un.oseas) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=54340 written=90851 + I/O Timings: read=8179.425 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.005..0.009 rows=13 loops=1) + Sort Key: so.ssyr + Sort Method: quicksort Memory: 26kB + -> CTE Scan on std so (cost=0.00..302.76 rows=15138 width=40) (actual time=0.000..0.002 rows=15 loops=1) + -> Materialize (cost=488161492.03..489813607.52 rows=330423099 width=1268) (actual time=105468.884..108956.573 rows=812229 loops=1) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=54340 written=90851 + I/O Timings: read=8179.425 + -> Sort (cost=488161492.03..488987549.77 rows=330423099 width=1268) (actual time=105419.215..105977.954 rows=812229 loops=1) + Sort Key: un.oseas + Sort Method: external merge Disk: 434720kB + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=54340 written=54341 + I/O Timings: read=8179.425 + -> Hash Left Join (cost=30326.40..75489285.22 rows=330423099 width=1268) (actual time=34892.831..94537.687 rows=812229 loops=1) + Hash Cond: ((un.part = cr.y0part) AND (un.plnt = cr.y0plnt)) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1 + I/O Timings: read=8179.425 + -> Hash Left Join (cost=22414.65..56426266.97 rows=330423099 width=1262) (actual time=34668.780..93298.840 rows=812229 loops=1) + Hash Cond: ((un.part = cp.chpart) AND (un.plnt = cp.chplnt)) + Buffers: shared hit=101597 read=85711, local hit=5658753 read=1 + I/O Timings: read=8003.465 + -> Hash Left Join (cost=14299.03..36533966.06 rows=330423099 width=1256) (actual time=34522.917..92143.759 rows=812229 loops=1) + Hash Cond: ((un.part = cm.cgpart) AND (un.plnt = cm.cgplnt)) + Buffers: shared hit=101597 read=80395, local hit=5658753 read=1 + I/O Timings: read=7920.833 + -> Hash Left Join (cost=7433.88..34026391.85 rows=330423099 width=1250) (actual time=34383.160..90732.988 rows=812229 loops=1) + Hash Cond: (un.bill_cust = sc.bvcust) + Buffers: shared hit=101597 read=75888, local hit=5658753 read=1 + I/O Timings: read=7833.063 + -> Hash Left Join (cost=3723.16..29479363.52 rows=330423099 width=1223) (actual time=34366.365..89923.315 rows=812229 loops=1) + Hash Cond: (un.bill_cust = bc.bvcust) + Buffers: shared hit=98373 read=75888, local hit=5658753 read=1 + I/O Timings: read=7833.063 + -> Hash Left Join (cost=12.44..24932335.18 rows=330423099 width=1196) (actual time=34277.988..88987.624 rows=812229 loops=1) + Hash Cond: ((un.ming = mmgp.brmgrp) AND (un.majg = mmgp.brgrp)) + Buffers: shared hit=98373 read=72664, local hit=5658753 read=1 + I/O Timings: read=7758.824 + -> Hash Left Join (cost=7.51..15006668.18 rows=330423099 width=1186) (actual time=34277.622..88269.216 rows=812229 loops=1) + Hash Cond: (un.majg = majg.bqgrp) + Buffers: shared hit=98373 read=72663, local hit=5658753 read=1 + I/O Timings: read=7758.524 + -> Hash Left Join (cost=6.24..13569326.43 rows=330423099 width=1176) (actual time=34277.304..87627.015 rows=812229 loops=1) + Hash Cond: (un.majs = sj.bsmjcd) + Buffers: shared hit=98373 read=72662, local hit=5658753 read=1 + I/O Timings: read=7758.231 + -> Hash Left Join (cost=6.21..12313718.62 rows=330423099 width=1144) (actual time=34277.281..87019.163 rows=812229 loops=1) + Hash Cond: ((un.majs = si.bsmjcd) AND (un.mins = si.bsmncd)) + Buffers: shared hit=98372 read=72662, local hit=5658753 read=1 + I/O Timings: read=7758.231 + -> Hash Left Join (cost=3.90..9830091.09 rows=330423099 width=1112) (actual time=34276.887..86204.919 rows=812229 loops=1) + Hash Cond: (un.quota_rep = repc.rcode) + Buffers: shared hit=98372 read=72661, local hit=5658753 read=1 + I/O Timings: read=7757.901 + -> CTE Scan on un (cost=0.00..6608461.98 rows=330423099 width=1048) (actual time=34264.293..85100.705 rows=812229 loops=1) + Buffers: shared hit=98372 read=72635, local hit=5658753 read=1 + I/O Timings: read=7746.456 + -> Hash (cost=2.40..2.40 rows=120 width=96) (actual time=12.582..12.582 rows=120 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 17kB + Buffers: shared read=26 + I/O Timings: read=11.445 + -> CTE Scan on repc (cost=0.00..2.40 rows=120 width=96) (actual time=2.594..12.537 rows=120 loops=1) + Buffers: shared read=26 + I/O Timings: read=11.445 + -> Hash (cost=1.32..1.32 rows=66 width=96) (actual time=0.382..0.382 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.330 + -> CTE Scan on si (cost=0.00..1.32 rows=66 width=96) (actual time=0.344..0.363 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.330 + -> Hash (cost=0.02..0.02 rows=1 width=64) (actual time=0.016..0.016 rows=11 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=1 + -> CTE Scan on sj (cost=0.00..0.02 rows=1 width=64) (actual time=0.007..0.013 rows=11 loops=1) + Buffers: shared hit=1 + -> Hash (cost=1.12..1.12 rows=12 width=14) (actual time=0.312..0.312 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared read=1 + I/O Timings: read=0.293 + -> Seq Scan on majg (cost=0.00..1.12 rows=12 width=14) (actual time=0.301..0.303 rows=12 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.293 + -> Hash (cost=2.57..2.57 rows=157 width=18) (actual time=0.359..0.359 rows=157 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=1 + I/O Timings: read=0.300 + -> Seq Scan on mmgp (cost=0.00..2.57 rows=157 width=18) (actual time=0.309..0.326 rows=157 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.300 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=88.356..88.356 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared read=3224 + I/O Timings: read=74.239 + -> Seq Scan on cust bc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.900..82.368 rows=21632 loops=1) + Buffers: shared read=3224 + I/O Timings: read=74.239 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=16.771..16.771 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared hit=3224 + -> Seq Scan on cust sc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.007..10.557 rows=21632 loops=1) + Buffers: shared hit=3224 + -> Hash (cost=5450.26..5450.26 rows=94326 width=29) (actual time=139.654..139.654 rows=94326 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6699kB + Buffers: shared read=4507 + I/O Timings: read=87.770 + -> Seq Scan on icstm cm (cost=0.00..5450.26 rows=94326 width=29) (actual time=1.271..114.520 rows=94326 loops=1) + Buffers: shared read=4507 + I/O Timings: read=87.770 + -> Hash (cost=6435.85..6435.85 rows=111985 width=20) (actual time=145.806..145.806 rows=111985 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6768kB + Buffers: shared read=5316 + I/O Timings: read=82.632 + -> Seq Scan on icstp cp (cost=0.00..6435.85 rows=111985 width=20) (actual time=3.411..114.774 rows=111985 loops=1) + Buffers: shared read=5316 + I/O Timings: read=82.632 + -> Hash (cost=6315.90..6315.90 rows=106390 width=27) (actual time=223.650..223.650 rows=106390 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7334kB + Buffers: shared read=5252 + I/O Timings: read=175.960 + -> Seq Scan on icstr cr (cost=0.00..6315.90 rows=106390 width=27) (actual time=1.134..193.496 rows=106390 loops=1) + Buffers: shared read=5252 + I/O Timings: read=175.960 + -> CTE Scan on agg a (cost=0.00..37859720740.70 rows=1892986037035 width=1520) (actual time=182825.842..192275.884 rows=809487 loops=1) + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=169551 written=302149 + I/O Timings: read=8179.425 + -> CTE Scan on agg a_1 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=336.760..2113.121 rows=298364 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Forecast}'::text[]))) + Rows Removed by Filter: 511123 + Buffers: temp read=57847 written=1 + -> CTE Scan on agg a_2 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=218.764..3615.793 rows=270022 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Budget}'::text[]))) + Rows Removed by Filter: 539465 + Buffers: temp read=57847 + +
++ + + +3 +3m6s ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 16:48:41 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
+ +++ +Insert on osm_ppfa_varto_mv (cost=0.25..10.25 rows=1000 width=1520) (actual time=186692.239..186692.239 rows=0 loops=1) + Buffers: shared hit=1652058 read=262701 dirtied=107023 written=340, local hit=5660301 read=4 dirtied=2, temp read=384981 written=401910 + I/O Timings: read=5890.327 write=3.241 + -> Function Scan on osm_ppfa_varto (cost=0.25..10.25 rows=1000 width=1520) (actual time=152354.359..164471.890 rows=1378962 loops=1) + Buffers: shared hit=40911 read=155742 dirtied=65, local hit=5660301 read=4 dirtied=2, temp read=384981 written=401910 + I/O Timings: read=5888.364 + +
++ + + +4 +2m30s ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++[ Date: 2019-03-15 14:09:42 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
+ +++ +Insert on osm_ppfa_varto_mv (cost=0.25..10.25 rows=1000 width=1520) (actual time=150711.860..150711.860 rows=0 loops=1) + Buffers: shared hit=1649817 read=264466 dirtied=106965 written=88, local hit=5659525 read=4 dirtied=2, temp read=384879 written=401797 + I/O Timings: read=5508.081 write=14.599 + -> Function Scan on osm_ppfa_varto (cost=0.25..10.25 rows=1000 width=1520) (actual time=127165.594..135951.084 rows=1378380 loops=1) + Buffers: shared hit=39318 read=157546 dirtied=46, local hit=5659525 read=4 dirtied=2, temp read=384879 written=401797 + I/O Timings: read=5507.907 + +
++ + + +5 +2m28s ++ +PL/pgSQL function rlarp.osm_ppfa_varto() line 69 at RETURN QUERYWITH + ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- + SEG AS ( + SELECT + x.GLEC + ,x.SEGM + FROM + ( + VALUES + ('1CU','Retail'), + ('1GR','Greenhouse'), + ('1NU','Nursery'), + ('1RE','Retail'), + ('2WI','Greenhouse'), + ('3BM','Other'), + ('3CO','Other'), + ('3PE','Other'), + ('3PP','Other'), + ('4CO','Other'), + ('4RA','Other'), + ('9MI','Other'), + ('9SA','Other'), + ('9TO','Other') + ) X(GLEC, SEGM) + ) + ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- + ,MG AS ( + SELECT + X.F1, X.MING, X.GRP + FROM + ( + VALUES + ('L','000','Branded'), + ('L','B10','Branded'), + ('L','B11','Branded'), + ('L','B52','Branded'), + ('L','C10','Branded'), + ('L','D12','Branded'), + ('L','M11','Branded'), + ('L','P12','Branded'), + ('L','P13','Branded'), + ('L','S10','Branded'), + ('L','Y10','Branded'), + ('L','Y11','Branded'), + ('L','Y12','Branded'), + ('P','B10','Branded'), + ('P','B11','Branded'), + ('P','B52','Branded') + ) AS X (F1, MING, GRP) + ) + ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- + ,REPC AS ( + SELECT + LTRIM(RTRIM(C.A9)) RCODE + ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP + ,COALESCE(Q.DIR,'Other') DIRECTOR + FROM + LGDAT.CODE C + LEFT OUTER JOIN RLARP.QRH Q ON + Q.QR = LTRIM(RTRIM(C.A9)) + WHERE + C.A2 = 'MM' + ) + --MOLD DESCRIPTIONS + ,MD AS ( + SELECT + U.MOLD + ,MAX(U.DESCR) DESCR + FROM + ( + SELECT + SUBSTR(M.AVPART,1,8) MOLD + ,MAX(M.AVDES1) DESCR + FROM + LGDAT.STKMM M + WHERE + LENGTH(M.AVPART) > 8 + AND SUBSTR(M.AVGLED,1,1) <= '2' + GROUP BY + SUBSTR(M.AVPART,1,8) + UNION ALL + SELECT + SUBSTR(P.AWPART,1,8) MOLD + ,MAX(P.AWDES1) DESCR + FROM + LGDAT.STKMP P + WHERE + LENGTH(P.AWPART) > 8 + AND SUBSTR(P.AWGLED,1,1) <= '2' + GROUP BY + SUBSTR(P.AWPART,1,8) + ) U + GROUP BY + U.MOLD + ) + ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- + ,SJ AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = '' + ) + ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- + ,SI AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> '' + ) + ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ + ,seas AS( + SELECT + ssyr + ,daterange(MIN(sdat),MAX(edat),'[]') dr + ,current_date <@ daterange(MIN(sdat),MAX(edat),'[]') cy + FROM + gld + GROUP BY + ssyr + ORDER BY + ssyr DESC + ) + ,intv AS ( + SELECT current_date - lower(dr) dy from seas where cy = true + ) + ,std AS ( + SELECT + s.ssyr + ,s.dr + ,s.cy + ,daterange(lower(dr),dy + LOWER(dr),'[]') ytd + FROM + seas s + CROSS JOIN intv + ) + ---------------------------------------union actual and forecast--------------------------------------------------------------------------------------------------------------------------------------- + ,UN AS ( + --plan + SELECT + 'Budget' AS VERSION + ,'Budget' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE as ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(m.avNWHT,p.awNWHT) * CASE COALESCE(m.avNWUN, p.awNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMP OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = 'b19' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --staged forecast + SELECT + 'Forecast' AS VERSION + ,'Forecast' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMF OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = '5p7' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --actual + SELECT + 'Actual' AS VERSION + ,'Actual' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSM OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + --AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.CALC_STATUS <> 'CANCELED' + AND + ( + OSM.FSPR >= '1606' + OR OSM.ADJ_ORDERDATE >= '2016-06-01' + ) + GROUP BY + --VERSION + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + ) + ---------------------------------------aggregate actual and forecast----------------------------------------------------------------------------------------------------------------------------------- + ,AGG AS ( + SELECT + un.VERSION::text "version" + ,un.ITER::text "iter" + ,un.OSEAS::numeric oseas + ,un.ODATE::date odate + ,un.SSEAS::numeric sseas + ,un.SDATE::date sdate + ,un.RSEAS::numeric rseas + ,un.RDATE::date rdate + ,un.OM::text om + ,un.SM::text sm + ,un.RM::text rm + ,un.OY::text oy + ,(un.odate <@ _ytd)::boolean ocytd --current year to date + ,(un.odate <@ so.ytd)::boolean oytd --year to date recast for prior/forecast periods + ,un.SY::text sy + ,(un.sdate <@ _ytd)::boolean scytd + ,(un.sdate <@ ss.ytd)::boolean sytd + --had this order been placed yet? (current day prior year is greater than the order date) + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END status_py + ,un.RY::text ry + ,un.PLNT::text plnt + ,un.ACCOUNT::text bill_group + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text bill_cust + ,bc.bvctry bill_ctry + ,bc.bvprcd bill_prov + ,un.SHIPGRP::text ship_group + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text ship_cust + ,sc.bvctry ship_ctry + ,sc.bvprcd ship_prov + ,un.CHAN::text chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text mod_chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text mod_chansub + ,un.PROMO::text promo + ,un.MAJG||COALESCE(' - '||BQDES,'')::text majg + ,un.MING||COALESCE(' - '||BRDES,'')::text ming + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text majs + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text mins + ,un.PART::text part + ,un.PART_DESCR::text part_descr + ,un.PART_FAMILY::text part_family + ,un.PART_GROUP::text part_group + ,un.BRANDING::text branding + ,un.SEGM::text segm + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text quota_rep + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text director + ,SUM(un.QTY)::numeric qty + ,SUM(un.SALES)::numeric sales + ,SUM(un.STDCOST)::numeric stdcost + ,SUM(un.QTY * COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur + ,SUM(un.POUNDS)::numeric pounds + ,(un.VERSION||'-'||un.SY)::text flag_s + ,(un.VERSION||'-'||un.OY)::text flag_o + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text status + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text "options" + ,'Grand Total'::text grandtotal + FROM + UN + LEFT OUTER JOIN REPC ON + REPC.RCODE = un.QUOTA_REP + LEFT OUTER JOIN SI ON + SI.BSMJCD = UN.MAJS + AND SI.BSMNCD = UN.MINS + LEFT OUTER JOIN SJ ON + SJ.BSMJCD = UN.MAJS + LEFT OUTER JOIN LGDAT.MAJG ON + BQGRP = un.MAJG + LEFT OUTER JOIN LGDAT.MMGP ON + BRMGRP = un.MING + AND BRGRP = un.MAJG + LEFT OUTER JOIN LGDAT.CUST BC ON + BC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.CUST SC ON + SC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.ICSTM cm ON + cm.cgpart = un.part + AND cm.cgplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTP cp ON + cp.chpart = un.part + AND cp.chplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTR cr ON + cr.y0part = un.part + AND cr.y0plnt = un.plnt + LEFT OUTER JOIN STD so ON + so.ssyr = un.oseas + LEFT OUTER JOIN STD ss ON + ss.ssyr = un.sseas + GROUP BY + un.VERSION::text + ,un.ITER::text + ,un.OSEAS::numeric + ,un.ODATE::date + ,un.SSEAS::numeric + ,un.SDATE::date + ,un.RSEAS::numeric + ,un.RDATE::date + ,un.OM::text + ,un.SM::text + ,un.RM::text + ,un.OY::text + --current year to date + ,(un.odate <@ _ytd)::boolean + --year to date recast for prior/forecast periods + ,(un.odate <@ so.ytd)::boolean + ,un.SY::text + ,(un.sdate <@ _ytd)::boolean + ,(un.sdate <@ ss.ytd)::boolean + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END + ,un.RY::text + ,un.PLNT::text + ,un.ACCOUNT::text + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text + ,bc.bvctry + ,bc.bvprcd + ,un.SHIPGRP::text + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text + ,sc.bvctry + ,sc.bvprcd + ,un.CHAN::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text + ,un.PROMO::text + ,un.MAJG||COALESCE(' - '||BQDES,'')::text + ,un.MING||COALESCE(' - '||BRDES,'')::text + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text + ,un.PART::text + ,un.PART_DESCR::text + ,un.PART_FAMILY::text + ,un.PART_GROUP::text + ,un.BRANDING::text + ,un.SEGM::text + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text + ,(un.VERSION||'-'||un.SY)::text + ,(un.VERSION||'-'||un.OY)::text + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text + ,'Grand Total'::text + ) + SELECT + a.version + ,a.iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,a.qty + ,a.sales + ,a.stdcost + ,a.stdcost_cur + ,a.pounds + ,a.flag_s + ,a.flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + agg a + UNION ALL + SELECT + 'Var to Fcst' as version + ,'Var to Fcst' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Fcst'||'-'||a.scytd flag_s + ,'Var to Fcst'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Forecast') + AND (a.ocytd OR a.scytd) + + UNION ALL + SELECT + 'Var to Bdgt' as version + ,'Var to Bdgt' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Bdgt'||'-'||a.scytd flag_s + ,'Var to Bdgt'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Budget') + AND (a.ocytd OR a.scytd) +;+[ Date: 2019-03-15 16:48:07 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
+ +++ +Append (cost=4309162605406.33..4437117814888.42 rows=1835682510591 width=1520) (actual time=130217.190..147603.781 rows=1378962 loops=1) + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=285365 written=302292 + I/O Timings: read=5796.575 + CTE seg + -> Values Scan on "*VALUES*" (cost=0.00..0.18 rows=14 width=64) (actual time=0.003..0.006 rows=14 loops=1) + CTE mg + -> Values Scan on "*VALUES*_1" (cost=0.00..0.20 rows=16 width=96) (actual time=0.003..0.011 rows=16 loops=1) + CTE repc + -> Hash Left Join (cost=11.47..123.28 rows=120 width=96) (actual time=7.419..15.669 rows=120 loops=1) + Hash Cond: (ltrim(rtrim(c.a9)) = q.qr) + Buffers: shared hit=1 read=25 + I/O Timings: read=14.644 + -> Bitmap Heap Scan on code c (cost=9.21..118.86 rows=120 width=25) (actual time=7.351..15.256 rows=120 loops=1) + Recheck Cond: (a2 = 'MM'::text) + Heap Blocks: exact=21 + Buffers: shared read=25 + I/O Timings: read=14.644 + -> Bitmap Index Scan on pk_code (cost=0.00..9.18 rows=120 width=0) (actual time=6.872..6.872 rows=120 loops=1) + Index Cond: (a2 = 'MM'::text) + Buffers: shared read=4 + I/O Timings: read=6.737 + -> Hash (cost=1.56..1.56 rows=56 width=12) (actual time=0.044..0.044 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared hit=1 + -> Seq Scan on qrh q (cost=0.00..1.56 rows=56 width=12) (actual time=0.016..0.024 rows=56 loops=1) + Buffers: shared hit=1 + CTE md + -> HashAggregate (cost=11936.00..11938.00 rows=200 width=64) (actual time=109.370..109.781 rows=3368 loops=1) + Group Key: (substr(m.avpart, 1, 8)) + Buffers: shared hit=9056 + -> Append (cost=8137.31..11870.54 rows=13091 width=64) (actual time=98.760..108.518 rows=3375 loops=1) + Buffers: shared hit=9056 + -> HashAggregate (cost=8137.31..8249.94 rows=9010 width=64) (actual time=98.758..99.319 rows=3285 loops=1) + Group Key: substr(m.avpart, 1, 8) + Buffers: shared hit=6448 + -> Seq Scan on stkmm m (cost=0.00..8092.26 rows=9010 width=59) (actual time=0.016..53.186 rows=76269 loops=1) + Filter: ((length(avpart) > 8) AND (substr(avgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 4728 + Buffers: shared hit=6448 + -> HashAggregate (cost=3373.23..3424.24 rows=4081 width=64) (actual time=8.960..8.993 rows=90 loops=1) + Group Key: substr(p.awpart, 1, 8) + Buffers: shared hit=2608 + -> Seq Scan on stkmp p (cost=0.00..3352.82 rows=4081 width=52) (actual time=0.460..8.898 rows=142 loops=1) + Filter: ((length(awpart) > 8) AND (substr(awgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 36557 + Buffers: shared hit=2608 + CTE sj + -> Seq Scan on mmsl (cost=0.00..1.84 rows=1 width=22) (actual time=0.005..0.011 rows=11 loops=1) + Filter: (COALESCE(bsmncd, ''::text) = ''::text) + Rows Removed by Filter: 56 + Buffers: shared hit=1 + CTE si + -> Seq Scan on mmsl mmsl_1 (cost=0.00..1.84 rows=66 width=22) (actual time=1.513..1.521 rows=56 loops=1) + Filter: (COALESCE(bsmncd, ''::text) <> ''::text) + Rows Removed by Filter: 11 + Buffers: shared read=1 + I/O Timings: read=1.503 + CTE seas + -> GroupAggregate (cost=10.22..16.31 rows=174 width=41) (actual time=0.067..0.097 rows=15 loops=1) + Group Key: gld.ssyr + Buffers: local hit=2 + -> Sort (cost=10.22..10.65 rows=174 width=16) (actual time=0.052..0.059 rows=174 loops=1) + Sort Key: gld.ssyr DESC + Sort Method: quicksort Memory: 33kB + Buffers: local hit=2 + -> Seq Scan on gld (cost=0.00..3.74 rows=174 width=16) (actual time=0.010..0.030 rows=174 loops=1) + Buffers: local hit=2 + CTE intv + -> CTE Scan on seas (cost=0.00..4.13 rows=87 width=4) (actual time=0.078..0.079 rows=1 loops=1) + Filter: cy + Rows Removed by Filter: 14 + Buffers: local hit=2 + CTE std + -> Nested Loop (cost=0.00..457.62 rows=15138 width=73) (actual time=0.081..0.114 rows=15 loops=1) + Buffers: local hit=2 + -> CTE Scan on intv (cost=0.00..1.74 rows=87 width=4) (actual time=0.078..0.079 rows=1 loops=1) + Buffers: local hit=2 + -> CTE Scan on seas s (cost=0.00..3.48 rows=174 width=41) (actual time=0.000..0.027 rows=15 loops=1) + CTE un + -> Append (cost=50003223.80..244355794.95 rows=315685415 width=697) (actual time=24427.622..55248.745 rows=812592 loops=1) + Buffers: shared hit=33769 read=137238 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5418.990 + -> GroupAggregate (cost=50003223.80..63823292.65 rows=83757993 width=701) (actual time=24427.621..26180.035 rows=212793 loops=1) + Group Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Buffers: shared hit=9106 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Sort (cost=50003223.80..50212618.79 rows=83757993 width=594) (actual time=24427.582..24584.713 rows=641010 loops=1) + Sort Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Sort Method: quicksort Memory: 352782kB + Buffers: shared hit=9106 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Hash Left Join (cost=11749.79..16650773.71 rows=83757993 width=594) (actual time=594.631..11450.131 rows=641010 loops=1) + Hash Cond: ((osm.bill_class = l.bill) AND (osm.ship_class = l.ship)) + Buffers: shared hit=9103 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Hash Left Join (cost=11744.32..10583311.94 rows=83757993 width=583) (actual time=594.565..10651.699 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 8) = md.mold) + Buffers: shared hit=9101 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Hash Left Join (cost=11737.82..5348430.88 rows=83757993 width=551) (actual time=483.328..10064.882 rows=641010 loops=1) + Hash Cond: (osm.part = p_1.awpart) + Buffers: shared hit=45 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Nested Loop Left Join (cost=8303.37..5125106.33 rows=83757993 width=527) (actual time=372.833..9705.810 rows=641010 loops=1) + Buffers: shared hit=43 read=56824, local hit=2563791 read=1 + I/O Timings: read=2158.329 + -> Nested Loop Left Join (cost=8303.23..337594.45 rows=4332310 width=455) (actual time=372.826..7154.118 rows=641010 loops=1) + Buffers: shared hit=43 read=56824, local hit=1281897 read=1 + I/O Timings: read=2158.329 + -> Hash Left Join (cost=8303.08..89964.52 rows=224085 width=383) (actual time=372.784..4519.221 rows=641010 loops=1) + Hash Cond: (osm.part = m_1.avpart) + Buffers: shared hit=43 read=56824, local hit=2 + I/O Timings: read=2158.311 + -> Hash Left Join (cost=30.62..81103.81 rows=224085 width=348) (actual time=1.380..3884.310 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 3) = f.f3) + Buffers: shared hit=41 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Hash Left Join (cost=6.93..77718.84 rows=224085 width=324) (actual time=1.257..3476.551 rows=641010 loops=1) + Hash Cond: ((substr(osm.part, 16, 1) = mg.f1) AND (osm.ming = mg.ming)) + Buffers: shared hit=32 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Hash Left Join (cost=6.37..75750.09 rows=224085 width=292) (actual time=1.228..3039.988 rows=641010 loops=1) + Hash Cond: (osm.glec = seg.glec) + Buffers: shared hit=32 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Hash Left Join (cost=5.92..72674.81 rows=224085 width=264) (actual time=1.210..2805.095 rows=641010 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=32 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Seq Scan on osmp osm (cost=0.00..69587.73 rows=224085 width=184) (actual time=1.134..2545.900 rows=641010 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = 'b19'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 57051 + Buffers: shared hit=32 read=50378 + I/O Timings: read=1843.013 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.058..0.058 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=112) (actual time=0.010..0.033 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.013..0.013 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg (cost=0.00..0.28 rows=14 width=64) (actual time=0.005..0.011 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.018..0.018 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.015 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.118..0.118 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f (cost=0.00..15.53 rows=653 width=24) (actual time=0.017..0.054 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=371.346..371.346 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=2 read=6446 + I/O Timings: read=315.299 + -> Seq Scan on stkmm m_1 (cost=0.00..7258.87 rows=81087 width=54) (actual time=1.087..344.662 rows=80997 loops=1) + Buffers: shared hit=2 read=6446 + I/O Timings: read=315.299 + -> Index Scan using se_dat on gld od (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1281895 read=1 + I/O Timings: read=0.018 + -> Index Scan using se_dat on gld rd (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_requestdate >= sdat) AND (osm.adj_requestdate <= edat)) + Buffers: local hit=1281894 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=110.296..110.296 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2 read=2606 + I/O Timings: read=81.053 + -> Seq Scan on stkmp p_1 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.977..97.487 rows=36699 loops=1) + Buffers: shared hit=2 read=2606 + I/O Timings: read=81.053 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=111.215..111.215 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + Buffers: shared hit=9056 + -> CTE Scan on md (cost=0.00..4.00 rows=200 width=64) (actual time=109.374..110.690 rows=3368 loops=1) + Buffers: shared hit=9056 + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.051..0.051 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l (cost=0.00..3.39 rows=139 width=25) (actual time=0.012..0.026 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=33445583.00..42801951.72 rows=56705265 width=699) (actual time=16460.682..17590.319 rows=250477 loops=1) + Group Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Sort (cost=33445583.00..33587346.16 rows=56705265 width=595) (actual time=16460.650..16563.021 rows=406814 loops=1) + Sort Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Sort Method: quicksort Memory: 222052kB + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=11749.79..11025086.80 rows=56705265 width=595) (actual time=61.424..7759.480 rows=406814 loops=1) + Hash Cond: ((osm_1.bill_class = l_1.bill) AND (osm_1.ship_class = l_1.ship)) + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=11744.32..6967724.27 rows=55168846 width=584) (actual time=61.349..7305.324 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 8) = md_1.mold) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=11737.82..3519664.90 rows=55168846 width=552) (actual time=60.509..6993.509 rows=406814 loops=1) + Hash Cond: (osm_1.part = p_2.awpart) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Nested Loop Left Join (cost=8303.37..3371395.52 rows=55168846 width=528) (actual time=43.514..6803.629 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Nested Loop Left Join (cost=8303.23..217901.28 rows=2853561 width=456) (actual time=43.508..5300.883 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=813630 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=8303.08..54789.49 rows=147598 width=384) (actual time=43.490..3729.138 rows=406814 loops=1) + Hash Cond: (osm_1.part = m_2.avpart) + Buffers: shared hit=6457 read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=30.62..46129.57 rows=147598 width=349) (actual time=5.697..3467.540 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 3) = f_1.f3) + Buffers: shared hit=9 read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=6.93..43891.91 rows=147598 width=325) (actual time=5.585..3211.131 rows=406814 loops=1) + Hash Cond: ((substr(osm_1.part, 16, 1) = mg_1.f1) AND (osm_1.ming = mg_1.ming)) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=6.37..42594.49 rows=147598 width=293) (actual time=5.575..2952.469 rows=406814 loops=1) + Hash Cond: (osm_1.glec = seg_1.glec) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=5.92..40564.57 rows=147598 width=265) (actual time=5.564..2812.752 rows=406814 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Seq Scan on osmf osm_1 (cost=0.00..38529.18 rows=147598 width=185) (actual time=5.391..2669.916 rows=406814 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = '5p7'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 358 + Buffers: shared read=26345 + I/O Timings: read=2275.461 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.158..0.158 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=112) (actual time=0.080..0.111 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_1 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.004 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.005..0.005 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_1 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.108..0.108 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_1 (cost=0.00..15.53 rows=653 width=24) (actual time=0.010..0.047 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=37.738..37.738 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_2 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.007..22.454 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=406814) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=813628 + -> Index Scan using se_dat on gld rd_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=406814) + Index Cond: ((osm_1.adj_requestdate >= sdat) AND (osm_1.adj_requestdate <= edat)) + Buffers: local hit=813628 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=16.826..16.826 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_2 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.007..9.949 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=0.825..0.825 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_1 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.290 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.045..0.045 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_1 (cost=0.00..3.39 rows=139 width=25) (actual time=0.008..0.022 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=104083613.45..132995269.35 rows=175222157 width=695) (actual time=10242.201..11403.381 rows=349322 loops=1) + Group Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Buffers: shared hit=15596 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Sort (cost=104083613.45..104521668.84 rows=175222157 width=584) (actual time=10242.147..10337.649 rows=367596 loops=1) + Sort Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Sort Method: quicksort Memory: 201821kB + Buffers: shared hit=15596 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Hash Left Join (cost=11749.79..34574966.31 rows=175222157 width=584) (actual time=54.045..5505.369 rows=367596 loops=1) + Hash Cond: ((osm_2.bill_class = l_2.bill) AND (osm_2.ship_class = l_2.ship)) + Buffers: shared hit=15596 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Hash Left Join (cost=11744.32..22053510.74 rows=175222157 width=572) (actual time=53.991..5099.469 rows=367596 loops=1) + Hash Cond: (substr(osm_2.part, 1, 8) = md_2.mold) + Buffers: shared hit=15594 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Hash Left Join (cost=11737.82..11102119.43 rows=175222157 width=540) (actual time=53.191..4854.338 rows=367596 loops=1) + Hash Cond: (osm_2.part = p_3.awpart) + Buffers: shared hit=15594 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Nested Loop Left Join (cost=8303.37..10638673.75 rows=175222157 width=516) (actual time=37.296..4707.080 rows=367596 loops=1) + Buffers: shared hit=12986 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Nested Loop Left Join (cost=8303.23..623511.84 rows=9063215 width=444) (actual time=37.291..3491.892 rows=367596 loops=1) + Buffers: shared hit=12986 read=51463 dirtied=4, local hit=734624 + I/O Timings: read=904.147 + -> Hash Left Join (cost=8303.08..105486.21 rows=468787 width=372) (actual time=37.263..2223.924 rows=367596 loops=1) + Hash Cond: (osm_2.part = m_3.avpart) + Buffers: shared hit=12986 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=30.62..95983.12 rows=468787 width=337) (actual time=0.270..2039.720 rows=367596 loops=1) + Hash Cond: (substr(osm_2.part, 1, 3) = f_2.f3) + Buffers: shared hit=6538 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=6.93..88927.62 rows=468787 width=313) (actual time=0.129..1823.936 rows=367596 loops=1) + Hash Cond: ((substr(osm_2.part, 16, 1) = mg_2.f1) AND (osm_2.ming = mg_2.ming)) + Buffers: shared hit=6529 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=6.37..84811.93 rows=468787 width=281) (actual time=0.119..1623.505 rows=367596 loops=1) + Hash Cond: (osm_2.glec = seg_2.glec) + Buffers: shared hit=6529 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=5.92..78421.13 rows=468787 width=253) (actual time=0.111..1504.191 rows=367596 loops=1) + Hash Cond: (osm_2.fspr = sd_2.fspr) + Buffers: shared hit=6529 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Seq Scan on osm osm_2 (cost=0.00..72340.04 rows=468787 width=173) (actual time=0.052..1372.311 rows=367596 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND ((fspr >= '1606'::text) OR (adj_orderdate >= '2016-06-01'::date))) + Rows Removed by Filter: 417392 + Buffers: shared hit=6529 read=51463 dirtied=4 + I/O Timings: read=904.147 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.053..0.053 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_2 (cost=0.00..3.74 rows=174 width=112) (actual time=0.007..0.029 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_2 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.003 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.006..0.006 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_2 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.136..0.136 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_2 (cost=0.00..15.53 rows=653 width=24) (actual time=0.008..0.047 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=36.937..36.937 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_3 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.006..22.525 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=367596) + Index Cond: ((osm_2.adj_orderdate >= sdat) AND (osm_2.adj_orderdate <= edat)) + Buffers: local hit=734622 + -> Index Scan using se_dat on gld rd_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=367596) + Index Cond: ((osm_2.adj_requestdate >= sdat) AND (osm_2.adj_requestdate <= edat)) + Buffers: local hit=734620 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=15.858..15.858 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_3 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.007..9.906 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=0.788..0.788 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_2 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.291 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.043..0.043 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_2 (cost=0.00..3.39 rows=139 width=25) (actual time=0.007..0.021 rows=139 loops=1) + Buffers: shared hit=2 + CTE agg + -> GroupAggregate (cost=3811565832720.57..4308918237067.99 rows=1808554197627 width=1404) (actual time=130217.184..134929.396 rows=809850 loops=1) + Group Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)), 'Grand Total'::text + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=169623 written=244421 + I/O Timings: read=5796.575 + -> Sort (cost=3811565832720.57..3816087218214.63 rows=1808554197627 width=1346) (actual time=130217.139..131170.872 rows=812592 loops=1) + Sort Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)) + Sort Method: external merge Disk: 476048kB + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=169623 written=244421 + I/O Timings: read=5796.575 + -> Merge Right Join (cost=32058721370.12..253666346227.77 rows=1808554197627 width=1346) (actual time=79725.467..85819.348 rows=812592 loops=1) + Merge Cond: (ss.ssyr = un.sseas) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660295 read=1, temp read=110117 written=184914 + I/O Timings: read=5796.575 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.123..0.131 rows=15 loops=1) + Sort Key: ss.ssyr + Sort Method: quicksort Memory: 26kB + Buffers: local hit=2 + -> CTE Scan on std ss (cost=0.00..302.76 rows=15138 width=40) (actual time=0.082..0.119 rows=15 loops=1) + Buffers: local hit=2 + -> Materialize (cost=32058720016.34..32178191161.64 rows=23894229061 width=1300) (actual time=79718.116..82479.293 rows=812592 loops=1) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=110117 written=184914 + I/O Timings: read=5796.575 + -> Sort (cost=32058720016.34..32118455588.99 rows=23894229061 width=1300) (actual time=79718.091..80948.227 rows=812592 loops=1) + Sort Key: un.sseas + Sort Method: external merge Disk: 446032kB + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=110117 written=146652 + I/O Timings: read=5796.575 + -> Merge Right Join (cost=466287095.31..825489820.45 rows=23894229061 width=1300) (actual time=67066.711..71526.574 rows=812592 loops=1) + Merge Cond: (so.ssyr = un.oseas) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=54363 written=90897 + I/O Timings: read=5796.575 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.004..0.008 rows=13 loops=1) + Sort Key: so.ssyr + Sort Method: quicksort Memory: 26kB + -> CTE Scan on std so (cost=0.00..302.76 rows=15138 width=40) (actual time=0.000..0.002 rows=15 loops=1) + -> Materialize (cost=466285741.52..467864168.60 rows=315685415 width=1268) (actual time=67055.329..70663.573 rows=812592 loops=1) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=54363 written=90897 + I/O Timings: read=5796.575 + -> Sort (cost=466285741.52..467074955.06 rows=315685415 width=1268) (actual time=67050.634..68022.803 rows=812592 loops=1) + Sort Key: un.oseas + Sort Method: external merge Disk: 434904kB + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=54363 written=54364 + I/O Timings: read=5796.575 + -> Hash Left Join (cost=30326.40..72123629.81 rows=315685415 width=1268) (actual time=24989.685..60611.536 rows=812592 loops=1) + Hash Cond: ((un.part = cr.y0part) AND (un.plnt = cr.y0plnt)) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5796.575 + -> Hash Left Join (cost=22414.65..53910516.25 rows=315685415 width=1262) (actual time=24857.162..60071.090 rows=812592 loops=1) + Hash Cond: ((un.part = cp.chpart) AND (un.plnt = cp.chplnt)) + Buffers: shared hit=36995 read=150313 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5704.175 + -> Hash Left Join (cost=14299.03..34905098.97 rows=315685415 width=1256) (actual time=24690.716..59482.739 rows=812592 loops=1) + Hash Cond: ((un.part = cm.cgpart) AND (un.plnt = cm.cgplnt)) + Buffers: shared hit=36995 read=144997 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5598.963 + -> Hash Left Join (cost=7433.88..32509062.54 rows=315685415 width=1250) (actual time=24542.324..58815.424 rows=812592 loops=1) + Hash Cond: (un.bill_cust = sc.bvcust) + Buffers: shared hit=36995 read=140490 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5507.001 + -> Hash Left Join (cost=3723.16..28164677.36 rows=315685415 width=1223) (actual time=24531.977..58466.240 rows=812592 loops=1) + Hash Cond: (un.bill_cust = bc.bvcust) + Buffers: shared hit=33771 read=140490 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5507.001 + -> Hash Left Join (cost=12.44..23820292.19 rows=315685415 width=1196) (actual time=24445.824..58031.724 rows=812592 loops=1) + Hash Cond: ((un.ming = mmgp.brmgrp) AND (un.majg = mmgp.brgrp)) + Buffers: shared hit=33771 read=137266 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.817 + -> Hash Left Join (cost=7.51..14337334.16 rows=315685415 width=1186) (actual time=24445.412..57697.186 rows=812592 loops=1) + Hash Cond: (un.majg = majg.bqgrp) + Buffers: shared hit=33771 read=137265 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.479 + -> Hash Left Join (cost=6.24..12964101.34 rows=315685415 width=1176) (actual time=24445.051..57415.327 rows=812592 loops=1) + Hash Cond: (un.majs = sj.bsmjcd) + Buffers: shared hit=33771 read=137264 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.137 + -> Hash Left Join (cost=6.21..11764496.73 rows=315685415 width=1144) (actual time=24445.027..57139.761 rows=812592 loops=1) + Hash Cond: ((un.majs = si.bsmjcd) AND (un.mins = si.bsmncd)) + Buffers: shared hit=33770 read=137264 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.137 + -> Hash Left Join (cost=3.90..9391645.00 rows=315685415 width=1112) (actual time=24443.462..56809.926 rows=812592 loops=1) + Hash Cond: (un.quota_rep = repc.rcode) + Buffers: shared hit=33770 read=137263 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5433.634 + -> CTE Scan on un (cost=0.00..6313708.30 rows=315685415 width=1048) (actual time=24427.626..56309.934 rows=812592 loops=1) + Buffers: shared hit=33769 read=137238 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5418.990 + -> Hash (cost=2.40..2.40 rows=120 width=96) (actual time=15.823..15.823 rows=120 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 17kB + Buffers: shared hit=1 read=25 + I/O Timings: read=14.644 + -> CTE Scan on repc (cost=0.00..2.40 rows=120 width=96) (actual time=7.422..15.771 rows=120 loops=1) + Buffers: shared hit=1 read=25 + I/O Timings: read=14.644 + -> Hash (cost=1.32..1.32 rows=66 width=96) (actual time=1.556..1.556 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=1.503 + -> CTE Scan on si (cost=0.00..1.32 rows=66 width=96) (actual time=1.516..1.541 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=1.503 + -> Hash (cost=0.02..0.02 rows=1 width=64) (actual time=0.017..0.017 rows=11 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=1 + -> CTE Scan on sj (cost=0.00..0.02 rows=1 width=64) (actual time=0.006..0.014 rows=11 loops=1) + Buffers: shared hit=1 + -> Hash (cost=1.12..1.12 rows=12 width=14) (actual time=0.357..0.357 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared read=1 + I/O Timings: read=0.342 + -> Seq Scan on majg (cost=0.00..1.12 rows=12 width=14) (actual time=0.349..0.351 rows=12 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.342 + -> Hash (cost=2.57..2.57 rows=157 width=18) (actual time=0.404..0.404 rows=157 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=1 + I/O Timings: read=0.338 + -> Seq Scan on mmgp (cost=0.00..2.57 rows=157 width=18) (actual time=0.350..0.369 rows=157 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.338 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=86.128..86.128 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared read=3224 + I/O Timings: read=71.184 + -> Seq Scan on cust bc (cost=0.00..3440.32 rows=21632 width=35) (actual time=1.719..80.386 rows=21632 loops=1) + Buffers: shared read=3224 + I/O Timings: read=71.184 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=10.320..10.320 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared hit=3224 + -> Seq Scan on cust sc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.007..6.682 rows=21632 loops=1) + Buffers: shared hit=3224 + -> Hash (cost=5450.26..5450.26 rows=94326 width=29) (actual time=148.322..148.322 rows=94326 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6699kB + Buffers: shared read=4507 + I/O Timings: read=91.962 + -> Seq Scan on icstm cm (cost=0.00..5450.26 rows=94326 width=29) (actual time=1.674..121.636 rows=94326 loops=1) + Buffers: shared read=4507 + I/O Timings: read=91.962 + -> Hash (cost=6435.85..6435.85 rows=111985 width=20) (actual time=166.382..166.382 rows=111985 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6768kB + Buffers: shared read=5316 + I/O Timings: read=105.211 + -> Seq Scan on icstp cp (cost=0.00..6435.85 rows=111985 width=20) (actual time=2.877..136.300 rows=111985 loops=1) + Buffers: shared read=5316 + I/O Timings: read=105.211 + -> Hash (cost=6315.90..6315.90 rows=106390 width=27) (actual time=132.044..132.044 rows=106390 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7334kB + Buffers: shared read=5252 + I/O Timings: read=92.401 + -> Seq Scan on icstr cr (cost=0.00..6315.90 rows=106390 width=27) (actual time=1.095..107.748 rows=106390 loops=1) + Buffers: shared read=5252 + I/O Timings: read=92.401 + -> CTE Scan on agg a (cost=0.00..36171083952.54 rows=1808554197627 width=1520) (actual time=130217.189..139003.919 rows=809850 loops=1) + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=169623 written=302291 + I/O Timings: read=5796.575 + -> CTE Scan on agg a_1 (cost=0.00..41167214923.48 rows=13564156482 width=1520) (actual time=313.638..4190.172 rows=298727 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Forecast}'::text[]))) + Rows Removed by Filter: 511123 + Buffers: temp read=57871 written=1 + -> CTE Scan on agg a_2 (cost=0.00..41167214923.48 rows=13564156482 width=1520) (actual time=77.645..4240.941 rows=270385 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Budget}'::text[]))) + Rows Removed by Filter: 539465 + Buffers: temp read=57871 + +
++ + + +6 +2m2s ++ +PL/pgSQL function rlarp.osm_ppfa_varto() line 69 at RETURN QUERYWITH + ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- + SEG AS ( + SELECT + x.GLEC + ,x.SEGM + FROM + ( + VALUES + ('1CU','Retail'), + ('1GR','Greenhouse'), + ('1NU','Nursery'), + ('1RE','Retail'), + ('2WI','Greenhouse'), + ('3BM','Other'), + ('3CO','Other'), + ('3PE','Other'), + ('3PP','Other'), + ('4CO','Other'), + ('4RA','Other'), + ('9MI','Other'), + ('9SA','Other'), + ('9TO','Other') + ) X(GLEC, SEGM) + ) + ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- + ,MG AS ( + SELECT + X.F1, X.MING, X.GRP + FROM + ( + VALUES + ('L','000','Branded'), + ('L','B10','Branded'), + ('L','B11','Branded'), + ('L','B52','Branded'), + ('L','C10','Branded'), + ('L','D12','Branded'), + ('L','M11','Branded'), + ('L','P12','Branded'), + ('L','P13','Branded'), + ('L','S10','Branded'), + ('L','Y10','Branded'), + ('L','Y11','Branded'), + ('L','Y12','Branded'), + ('P','B10','Branded'), + ('P','B11','Branded'), + ('P','B52','Branded') + ) AS X (F1, MING, GRP) + ) + ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- + ,REPC AS ( + SELECT + LTRIM(RTRIM(C.A9)) RCODE + ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP + ,COALESCE(Q.DIR,'Other') DIRECTOR + FROM + LGDAT.CODE C + LEFT OUTER JOIN RLARP.QRH Q ON + Q.QR = LTRIM(RTRIM(C.A9)) + WHERE + C.A2 = 'MM' + ) + --MOLD DESCRIPTIONS + ,MD AS ( + SELECT + U.MOLD + ,MAX(U.DESCR) DESCR + FROM + ( + SELECT + SUBSTR(M.AVPART,1,8) MOLD + ,MAX(M.AVDES1) DESCR + FROM + LGDAT.STKMM M + WHERE + LENGTH(M.AVPART) > 8 + AND SUBSTR(M.AVGLED,1,1) <= '2' + GROUP BY + SUBSTR(M.AVPART,1,8) + UNION ALL + SELECT + SUBSTR(P.AWPART,1,8) MOLD + ,MAX(P.AWDES1) DESCR + FROM + LGDAT.STKMP P + WHERE + LENGTH(P.AWPART) > 8 + AND SUBSTR(P.AWGLED,1,1) <= '2' + GROUP BY + SUBSTR(P.AWPART,1,8) + ) U + GROUP BY + U.MOLD + ) + ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- + ,SJ AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = '' + ) + ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- + ,SI AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> '' + ) + ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ + ,seas AS( + SELECT + ssyr + ,daterange(MIN(sdat),MAX(edat),'[]') dr + ,current_date <@ daterange(MIN(sdat),MAX(edat),'[]') cy + FROM + gld + GROUP BY + ssyr + ORDER BY + ssyr DESC + ) + ,intv AS ( + SELECT current_date - lower(dr) dy from seas where cy = true + ) + ,std AS ( + SELECT + s.ssyr + ,s.dr + ,s.cy + ,daterange(lower(dr),dy + LOWER(dr),'[]') ytd + FROM + seas s + CROSS JOIN intv + ) + ---------------------------------------union actual and forecast--------------------------------------------------------------------------------------------------------------------------------------- + ,UN AS ( + --plan + SELECT + 'Budget' AS VERSION + ,'Budget' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE as ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(m.avNWHT,p.awNWHT) * CASE COALESCE(m.avNWUN, p.awNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMP OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = 'b19' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --staged forecast + SELECT + 'Forecast' AS VERSION + ,'Forecast' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMF OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = '5p7' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --actual + SELECT + 'Actual' AS VERSION + ,'Actual' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSM OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + --AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.CALC_STATUS <> 'CANCELED' + AND + ( + OSM.FSPR >= '1606' + OR OSM.ADJ_ORDERDATE >= '2016-06-01' + ) + GROUP BY + --VERSION + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + ) + ---------------------------------------aggregate actual and forecast----------------------------------------------------------------------------------------------------------------------------------- + ,AGG AS ( + SELECT + un.VERSION::text "version" + ,un.ITER::text "iter" + ,un.OSEAS::numeric oseas + ,un.ODATE::date odate + ,un.SSEAS::numeric sseas + ,un.SDATE::date sdate + ,un.RSEAS::numeric rseas + ,un.RDATE::date rdate + ,un.OM::text om + ,un.SM::text sm + ,un.RM::text rm + ,un.OY::text oy + ,(un.odate <@ _ytd)::boolean ocytd --current year to date + ,(un.odate <@ so.ytd)::boolean oytd --year to date recast for prior/forecast periods + ,un.SY::text sy + ,(un.sdate <@ _ytd)::boolean scytd + ,(un.sdate <@ ss.ytd)::boolean sytd + --had this order been placed yet? (current day prior year is greater than the order date) + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END status_py + ,un.RY::text ry + ,un.PLNT::text plnt + ,un.ACCOUNT::text bill_group + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text bill_cust + ,bc.bvctry bill_ctry + ,bc.bvprcd bill_prov + ,un.SHIPGRP::text ship_group + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text ship_cust + ,sc.bvctry ship_ctry + ,sc.bvprcd ship_prov + ,un.CHAN::text chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text mod_chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text mod_chansub + ,un.PROMO::text promo + ,un.MAJG||COALESCE(' - '||BQDES,'')::text majg + ,un.MING||COALESCE(' - '||BRDES,'')::text ming + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text majs + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text mins + ,un.PART::text part + ,un.PART_DESCR::text part_descr + ,un.PART_FAMILY::text part_family + ,un.PART_GROUP::text part_group + ,un.BRANDING::text branding + ,un.SEGM::text segm + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text quota_rep + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text director + ,SUM(un.QTY)::numeric qty + ,SUM(un.SALES)::numeric sales + ,SUM(un.STDCOST)::numeric stdcost + ,SUM(un.QTY * COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur + ,SUM(un.POUNDS)::numeric pounds + ,(un.VERSION||'-'||un.SY)::text flag_s + ,(un.VERSION||'-'||un.OY)::text flag_o + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text status + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text "options" + ,'Grand Total'::text grandtotal + FROM + UN + LEFT OUTER JOIN REPC ON + REPC.RCODE = un.QUOTA_REP + LEFT OUTER JOIN SI ON + SI.BSMJCD = UN.MAJS + AND SI.BSMNCD = UN.MINS + LEFT OUTER JOIN SJ ON + SJ.BSMJCD = UN.MAJS + LEFT OUTER JOIN LGDAT.MAJG ON + BQGRP = un.MAJG + LEFT OUTER JOIN LGDAT.MMGP ON + BRMGRP = un.MING + AND BRGRP = un.MAJG + LEFT OUTER JOIN LGDAT.CUST BC ON + BC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.CUST SC ON + SC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.ICSTM cm ON + cm.cgpart = un.part + AND cm.cgplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTP cp ON + cp.chpart = un.part + AND cp.chplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTR cr ON + cr.y0part = un.part + AND cr.y0plnt = un.plnt + LEFT OUTER JOIN STD so ON + so.ssyr = un.oseas + LEFT OUTER JOIN STD ss ON + ss.ssyr = un.sseas + GROUP BY + un.VERSION::text + ,un.ITER::text + ,un.OSEAS::numeric + ,un.ODATE::date + ,un.SSEAS::numeric + ,un.SDATE::date + ,un.RSEAS::numeric + ,un.RDATE::date + ,un.OM::text + ,un.SM::text + ,un.RM::text + ,un.OY::text + --current year to date + ,(un.odate <@ _ytd)::boolean + --year to date recast for prior/forecast periods + ,(un.odate <@ so.ytd)::boolean + ,un.SY::text + ,(un.sdate <@ _ytd)::boolean + ,(un.sdate <@ ss.ytd)::boolean + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END + ,un.RY::text + ,un.PLNT::text + ,un.ACCOUNT::text + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text + ,bc.bvctry + ,bc.bvprcd + ,un.SHIPGRP::text + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text + ,sc.bvctry + ,sc.bvprcd + ,un.CHAN::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text + ,un.PROMO::text + ,un.MAJG||COALESCE(' - '||BQDES,'')::text + ,un.MING||COALESCE(' - '||BRDES,'')::text + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text + ,un.PART::text + ,un.PART_DESCR::text + ,un.PART_FAMILY::text + ,un.PART_GROUP::text + ,un.BRANDING::text + ,un.SEGM::text + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text + ,(un.VERSION||'-'||un.SY)::text + ,(un.VERSION||'-'||un.OY)::text + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text + ,'Grand Total'::text + ) + SELECT + a.version + ,a.iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,a.qty + ,a.sales + ,a.stdcost + ,a.stdcost_cur + ,a.pounds + ,a.flag_s + ,a.flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + agg a + UNION ALL + SELECT + 'Var to Fcst' as version + ,'Var to Fcst' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Fcst'||'-'||a.scytd flag_s + ,'Var to Fcst'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Forecast') + AND (a.ocytd OR a.scytd) + + UNION ALL + SELECT + 'Var to Bdgt' as version + ,'Var to Bdgt' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Bdgt'||'-'||a.scytd flag_s + ,'Var to Bdgt'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Budget') + AND (a.ocytd OR a.scytd) +;+[ Date: 2019-03-15 14:09:18 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
+ +++ +Append (cost=4510966117154.68..4644894879274.93 rows=1921380827591 width=1520) (actual time=112425.684..121699.211 rows=1378380 loops=1) + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=285302 written=302218 + I/O Timings: read=5431.112 + CTE seg + -> Values Scan on "*VALUES*" (cost=0.00..0.18 rows=14 width=64) (actual time=0.003..0.006 rows=14 loops=1) + CTE mg + -> Values Scan on "*VALUES*_1" (cost=0.00..0.20 rows=16 width=96) (actual time=0.002..0.007 rows=16 loops=1) + CTE repc + -> Hash Left Join (cost=11.47..123.28 rows=120 width=96) (actual time=4.005..11.391 rows=120 loops=1) + Hash Cond: (ltrim(rtrim(c.a9)) = q.qr) + Buffers: shared read=26 + I/O Timings: read=10.590 + -> Bitmap Heap Scan on code c (cost=9.21..118.86 rows=120 width=25) (actual time=3.631..10.743 rows=120 loops=1) + Recheck Cond: (a2 = 'MM'::text) + Heap Blocks: exact=21 + Buffers: shared read=25 + I/O Timings: read=10.256 + -> Bitmap Index Scan on pk_code (cost=0.00..9.18 rows=120 width=0) (actual time=2.484..2.484 rows=120 loops=1) + Index Cond: (a2 = 'MM'::text) + Buffers: shared read=4 + I/O Timings: read=2.398 + -> Hash (cost=1.56..1.56 rows=56 width=12) (actual time=0.359..0.359 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.334 + -> Seq Scan on qrh q (cost=0.00..1.56 rows=56 width=12) (actual time=0.342..0.348 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.334 + CTE md + -> HashAggregate (cost=11936.00..11938.00 rows=200 width=64) (actual time=141.238..141.651 rows=3368 loops=1) + Group Key: (substr(m.avpart, 1, 8)) + Buffers: shared hit=9056 + -> Append (cost=8137.31..11870.54 rows=13091 width=64) (actual time=131.283..140.399 rows=3375 loops=1) + Buffers: shared hit=9056 + -> HashAggregate (cost=8137.31..8249.94 rows=9010 width=64) (actual time=131.282..131.853 rows=3285 loops=1) + Group Key: substr(m.avpart, 1, 8) + Buffers: shared hit=6448 + -> Seq Scan on stkmm m (cost=0.00..8092.26 rows=9010 width=59) (actual time=0.026..38.556 rows=76269 loops=1) + Filter: ((length(avpart) > 8) AND (substr(avgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 4728 + Buffers: shared hit=6448 + -> HashAggregate (cost=3373.23..3424.24 rows=4081 width=64) (actual time=8.321..8.352 rows=90 loops=1) + Group Key: substr(p.awpart, 1, 8) + Buffers: shared hit=2608 + -> Seq Scan on stkmp p (cost=0.00..3352.82 rows=4081 width=52) (actual time=0.446..8.258 rows=142 loops=1) + Filter: ((length(awpart) > 8) AND (substr(awgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 36557 + Buffers: shared hit=2608 + CTE sj + -> Seq Scan on mmsl (cost=0.00..1.84 rows=1 width=22) (actual time=0.004..0.009 rows=11 loops=1) + Filter: (COALESCE(bsmncd, ''::text) = ''::text) + Rows Removed by Filter: 56 + Buffers: shared hit=1 + CTE si + -> Seq Scan on mmsl mmsl_1 (cost=0.00..1.84 rows=66 width=22) (actual time=0.307..0.314 rows=56 loops=1) + Filter: (COALESCE(bsmncd, ''::text) <> ''::text) + Rows Removed by Filter: 11 + Buffers: shared read=1 + I/O Timings: read=0.297 + CTE seas + -> GroupAggregate (cost=10.22..16.31 rows=174 width=41) (actual time=0.068..0.100 rows=15 loops=1) + Group Key: gld.ssyr + Buffers: local hit=2 + -> Sort (cost=10.22..10.65 rows=174 width=16) (actual time=0.054..0.061 rows=174 loops=1) + Sort Key: gld.ssyr DESC + Sort Method: quicksort Memory: 33kB + Buffers: local hit=2 + -> Seq Scan on gld (cost=0.00..3.74 rows=174 width=16) (actual time=0.010..0.030 rows=174 loops=1) + Buffers: local hit=2 + CTE intv + -> CTE Scan on seas (cost=0.00..4.13 rows=87 width=4) (actual time=0.080..0.081 rows=1 loops=1) + Filter: cy + Rows Removed by Filter: 14 + Buffers: local hit=2 + CTE std + -> Nested Loop (cost=0.00..457.62 rows=15138 width=73) (actual time=0.087..0.122 rows=15 loops=1) + Buffers: local hit=2 + -> CTE Scan on intv (cost=0.00..1.74 rows=87 width=4) (actual time=0.081..0.082 rows=1 loops=1) + Buffers: local hit=2 + -> CTE Scan on seas s (cost=0.00..3.48 rows=174 width=41) (actual time=0.000..0.028 rows=15 loops=1) + CTE un + -> Append (cost=50003223.80..255856479.46 rows=330423099 width=697) (actual time=26363.405..56340.259 rows=812398 loops=1) + Buffers: shared hit=32147 read=138860, local hit=5659517 read=1 + I/O Timings: read=5000.713 + -> GroupAggregate (cost=50003223.80..63823292.65 rows=83757993 width=701) (actual time=26363.404..28258.932 rows=212793 loops=1) + Group Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Buffers: shared hit=9063 read=59473, local hit=2563791 read=1 + I/O Timings: read=2714.560 + -> Sort (cost=50003223.80..50212618.79 rows=83757993 width=594) (actual time=26363.369..26503.583 rows=641010 loops=1) + Sort Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Sort Method: quicksort Memory: 352782kB + Buffers: shared hit=9063 read=59473, local hit=2563791 read=1 + I/O Timings: read=2714.560 + -> Hash Left Join (cost=11749.79..16650773.71 rows=83757993 width=594) (actual time=412.849..12408.886 rows=641010 loops=1) + Hash Cond: ((osm.bill_class = l.bill) AND (osm.ship_class = l.ship)) + Buffers: shared hit=9060 read=59473, local hit=2563791 read=1 + I/O Timings: read=2714.560 + -> Hash Left Join (cost=11744.32..10583311.94 rows=83757993 width=583) (actual time=412.362..11595.759 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 8) = md.mold) + Buffers: shared hit=9060 read=59471, local hit=2563791 read=1 + I/O Timings: read=2714.141 + -> Hash Left Join (cost=11737.82..5348430.88 rows=83757993 width=551) (actual time=269.279..10961.881 rows=641010 loops=1) + Hash Cond: (osm.part = p_1.awpart) + Buffers: shared hit=4 read=59471, local hit=2563791 read=1 + I/O Timings: read=2714.141 + -> Nested Loop Left Join (cost=8303.37..5125106.33 rows=83757993 width=527) (actual time=188.919..10630.169 rows=641010 loops=1) + Buffers: shared hit=2 read=56865, local hit=2563791 read=1 + I/O Timings: read=2652.319 + -> Nested Loop Left Join (cost=8303.23..337594.45 rows=4332310 width=455) (actual time=188.914..7884.956 rows=641010 loops=1) + Buffers: shared hit=2 read=56865, local hit=1281897 read=1 + I/O Timings: read=2652.319 + -> Hash Left Join (cost=8303.08..89964.52 rows=224085 width=383) (actual time=188.885..5089.482 rows=641010 loops=1) + Hash Cond: (osm.part = m_1.avpart) + Buffers: shared hit=2 read=56865, local hit=2 + I/O Timings: read=2652.306 + -> Hash Left Join (cost=30.62..81103.81 rows=224085 width=348) (actual time=3.518..4614.841 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 3) = f.f3) + Buffers: shared read=50419, local hit=2 + I/O Timings: read=2511.680 + -> Hash Left Join (cost=6.93..77718.84 rows=224085 width=324) (actual time=2.296..4183.537 rows=641010 loops=1) + Hash Cond: ((substr(osm.part, 16, 1) = mg.f1) AND (osm.ming = mg.ming)) + Buffers: shared read=50410, local hit=2 + I/O Timings: read=2510.588 + -> Hash Left Join (cost=6.37..75750.09 rows=224085 width=292) (actual time=2.277..3733.098 rows=641010 loops=1) + Hash Cond: (osm.glec = seg.glec) + Buffers: shared read=50410, local hit=2 + I/O Timings: read=2510.588 + -> Hash Left Join (cost=5.92..72674.81 rows=224085 width=264) (actual time=2.259..3490.071 rows=641010 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared read=50410, local hit=2 + I/O Timings: read=2510.588 + -> Seq Scan on osmp osm (cost=0.00..69587.73 rows=224085 width=184) (actual time=2.186..3227.306 rows=641010 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = 'b19'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 57051 + Buffers: shared read=50410 + I/O Timings: read=2510.588 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.060..0.060 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=112) (actual time=0.008..0.034 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.014..0.014 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg (cost=0.00..0.28 rows=14 width=64) (actual time=0.005..0.011 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.015..0.015 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.011 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=1.217..1.217 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared read=9 + I/O Timings: read=1.092 + -> Seq Scan on family f (cost=0.00..15.53 rows=653 width=24) (actual time=0.985..1.149 rows=653 loops=1) + Buffers: shared read=9 + I/O Timings: read=1.092 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=185.313..185.313 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=2 read=6446 + I/O Timings: read=140.626 + -> Seq Scan on stkmm m_1 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.508..163.116 rows=80997 loops=1) + Buffers: shared hit=2 read=6446 + I/O Timings: read=140.626 + -> Index Scan using se_dat on gld od (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=641010) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1281895 read=1 + I/O Timings: read=0.013 + -> Index Scan using se_dat on gld rd (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.004 rows=1 loops=641010) + Index Cond: ((osm.adj_requestdate >= sdat) AND (osm.adj_requestdate <= edat)) + Buffers: local hit=1281894 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=80.171..80.171 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2 read=2606 + I/O Timings: read=61.823 + -> Seq Scan on stkmp p_1 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.342..70.937 rows=36699 loops=1) + Buffers: shared hit=2 read=2606 + I/O Timings: read=61.823 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=143.065..143.065 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + Buffers: shared hit=9056 + -> CTE Scan on md (cost=0.00..4.00 rows=200 width=64) (actual time=141.241..142.539 rows=3368 loops=1) + Buffers: shared hit=9056 + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.472..0.472 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=2 + I/O Timings: read=0.418 + -> Seq Scan on ffchnl l (cost=0.00..3.39 rows=139 width=25) (actual time=0.424..0.443 rows=139 loops=1) + Buffers: shared read=2 + I/O Timings: read=0.418 + -> GroupAggregate (cost=33445583.00..42801951.72 rows=56705265 width=699) (actual time=17060.209..18105.019 rows=250477 loops=1) + Group Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Sort (cost=33445583.00..33587346.16 rows=56705265 width=595) (actual time=17060.177..17152.591 rows=406814 loops=1) + Sort Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Sort Method: quicksort Memory: 222052kB + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=11749.79..11025086.80 rows=56705265 width=595) (actual time=160.607..8900.120 rows=406814 loops=1) + Hash Cond: ((osm_1.bill_class = l_1.bill) AND (osm_1.ship_class = l_1.ship)) + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=11744.32..6967724.27 rows=55168846 width=584) (actual time=160.531..8303.160 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 8) = md_1.mold) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=11737.82..3519664.90 rows=55168846 width=552) (actual time=159.458..7928.685 rows=406814 loops=1) + Hash Cond: (osm_1.part = p_2.awpart) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Nested Loop Left Join (cost=8303.37..3371395.52 rows=55168846 width=528) (actual time=139.481..7719.889 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Nested Loop Left Join (cost=8303.23..217901.28 rows=2853561 width=456) (actual time=139.471..5838.942 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=813630 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=8303.08..54789.49 rows=147598 width=384) (actual time=139.449..3929.023 rows=406814 loops=1) + Hash Cond: (osm_1.part = m_2.avpart) + Buffers: shared hit=6457 read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=30.62..46129.57 rows=147598 width=349) (actual time=79.183..3618.398 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 3) = f_1.f3) + Buffers: shared hit=9 read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=6.93..43891.91 rows=147598 width=325) (actual time=78.806..3313.087 rows=406814 loops=1) + Hash Cond: ((substr(osm_1.part, 16, 1) = mg_1.f1) AND (osm_1.ming = mg_1.ming)) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=6.37..42594.49 rows=147598 width=293) (actual time=78.771..2997.016 rows=406814 loops=1) + Hash Cond: (osm_1.glec = seg_1.glec) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=5.92..40564.57 rows=147598 width=265) (actual time=78.706..2840.808 rows=406814 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Seq Scan on osmf osm_1 (cost=0.00..38529.18 rows=147598 width=185) (actual time=78.437..2657.330 rows=406814 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = '5p7'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 358 + Buffers: shared read=26345 + I/O Timings: read=2202.796 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.200..0.200 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=112) (actual time=0.053..0.147 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.039..0.039 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_1 (cost=0.00..0.28 rows=14 width=64) (actual time=0.009..0.015 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.014..0.014 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_1 (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.008 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.350..0.350 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_1 (cost=0.00..15.53 rows=653 width=24) (actual time=0.090..0.194 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=59.937..59.937 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_2 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.021..34.499 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=813628 + -> Index Scan using se_dat on gld rd_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm_1.adj_requestdate >= sdat) AND (osm_1.adj_requestdate <= edat)) + Buffers: local hit=813628 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=19.766..19.766 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_2 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.008..10.901 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=1.056..1.056 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_1 (cost=0.00..4.00 rows=200 width=64) (actual time=0.003..0.385 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.055..0.055 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_1 (cost=0.00..3.39 rows=139 width=25) (actual time=0.007..0.025 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=112931514.84..144274888.60 rows=189959841 width=695) (actual time=8819.747..9896.203 rows=349128 loops=1) + Group Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Buffers: shared hit=14017 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Sort (cost=112931514.84..113406414.44 rows=189959841 width=584) (actual time=8819.714..8895.706 rows=367402 loops=1) + Sort Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Sort Method: quicksort Memory: 201721kB + Buffers: shared hit=14017 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Hash Left Join (cost=11749.79..37465936.67 rows=189959841 width=584) (actual time=50.604..4494.745 rows=367402 loops=1) + Hash Cond: ((osm_2.bill_class = l_2.bill) AND (osm_2.ship_class = l_2.ship)) + Buffers: shared hit=14017 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Hash Left Join (cost=11744.32..23902628.82 rows=189959841 width=574) (actual time=50.549..4122.287 rows=367402 loops=1) + Hash Cond: (substr(osm_2.part, 1, 8) = md_2.mold) + Buffers: shared hit=14015 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Hash Left Join (cost=11737.82..12030132.26 rows=189959841 width=542) (actual time=49.780..3891.847 rows=367402 loops=1) + Hash Cond: (osm_2.part = p_3.awpart) + Buffers: shared hit=14015 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Nested Loop Left Join (cost=8303.37..11527995.69 rows=189959841 width=518) (actual time=34.804..3756.178 rows=367402 loops=1) + Buffers: shared hit=11407 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Nested Loop Left Join (cost=8303.23..670498.91 rows=9825509 width=446) (actual time=34.797..2623.310 rows=367402 loops=1) + Buffers: shared hit=11407 read=53042, local hit=734236 + I/O Timings: read=83.358 + -> Hash Left Join (cost=8303.08..108904.23 rows=508216 width=374) (actual time=34.774..1278.961 rows=367402 loops=1) + Hash Cond: (osm_2.part = m_3.avpart) + Buffers: shared hit=11407 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=30.62..99297.64 rows=508216 width=339) (actual time=0.327..1108.708 rows=367402 loops=1) + Hash Cond: (substr(osm_2.part, 1, 3) = f_2.f3) + Buffers: shared hit=4959 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=6.93..91650.71 rows=508216 width=315) (actual time=0.203..921.418 rows=367402 loops=1) + Hash Cond: ((substr(osm_2.part, 16, 1) = mg_2.f1) AND (osm_2.ming = mg_2.ming)) + Buffers: shared hit=4950 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=6.37..87189.88 rows=508216 width=283) (actual time=0.191..727.591 rows=367402 loops=1) + Hash Cond: (osm_2.glec = seg_2.glec) + Buffers: shared hit=4950 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=5.92..80265.15 rows=508216 width=255) (actual time=0.180..611.979 rows=367402 loops=1) + Hash Cond: (osm_2.fspr = sd_2.fspr) + Buffers: shared hit=4950 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Seq Scan on osm osm_2 (cost=0.00..73663.10 rows=508216 width=175) (actual time=0.106..492.248 rows=367402 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND ((fspr >= '1606'::text) OR (adj_orderdate >= '2016-06-01'::date))) + Rows Removed by Filter: 417370 + Buffers: shared hit=4950 read=53042 + I/O Timings: read=83.358 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.065..0.065 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_2 (cost=0.00..3.74 rows=174 width=112) (actual time=0.018..0.041 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_2 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.003 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.006..0.006 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_2 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.119..0.119 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_2 (cost=0.00..15.53 rows=653 width=24) (actual time=0.014..0.051 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=34.398..34.398 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_3 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.006..21.130 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=367402) + Index Cond: ((osm_2.adj_orderdate >= sdat) AND (osm_2.adj_orderdate <= edat)) + Buffers: local hit=734234 + -> Index Scan using se_dat on gld rd_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.002..0.003 rows=1 loops=367402) + Index Cond: ((osm_2.adj_requestdate >= sdat) AND (osm_2.adj_requestdate <= edat)) + Buffers: local hit=734232 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=14.938..14.938 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_3 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.006..9.060 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=0.757..0.757 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_2 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.289 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.042..0.042 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_2 (cost=0.00..3.39 rows=139 width=25) (actual time=0.006..0.020 rows=139 loops=1) + Buffers: shared hit=2 + CTE agg + -> GroupAggregate (cost=3990139087947.22..4510710248131.84 rows=1892986037035 width=1404) (actual time=112425.677..116271.291 rows=809656 loops=1) + Group Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)), 'Grand Total'::text + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=169586 written=244360 + I/O Timings: read=5431.112 + -> Sort (cost=3990139087947.22..3994871553039.80 rows=1892986037035 width=1346) (actual time=112425.642..112859.948 rows=812398 loops=1) + Sort Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)) + Sort Method: external merge Disk: 475944kB + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=169586 written=244360 + I/O Timings: read=5431.112 + -> Merge Right Join (cost=33563712447.31..265517026370.70 rows=1892986037035 width=1346) (actual time=69370.743..73383.296 rows=812398 loops=1) + Merge Cond: (ss.ssyr = un.sseas) + Buffers: shared hit=35372 read=157188, local hit=5659519 read=1, temp read=110093 written=184866 + I/O Timings: read=5431.112 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.187..0.194 rows=15 loops=1) + Sort Key: ss.ssyr + Sort Method: quicksort Memory: 26kB + Buffers: local hit=2 + -> CTE Scan on std ss (cost=0.00..302.76 rows=15138 width=40) (actual time=0.143..0.183 rows=15 loops=1) + Buffers: local hit=2 + -> Materialize (cost=33563711093.53..33688759715.34 rows=25009724363 width=1300) (actual time=69363.504..70242.785 rows=812398 loops=1) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=110093 written=184866 + I/O Timings: read=5431.112 + -> Sort (cost=33563711093.53..33626235404.44 rows=25009724363 width=1300) (actual time=69363.500..69636.493 rows=812398 loops=1) + Sort Key: un.sseas + Sort Method: external merge Disk: 445936kB + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=110093 written=146616 + I/O Timings: read=5431.112 + -> Merge Right Join (cost=488162845.81..864134844.69 rows=25009724363 width=1300) (actual time=64619.072..67097.961 rows=812398 loops=1) + Merge Cond: (so.ssyr = un.oseas) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=54351 written=90873 + I/O Timings: read=5431.112 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.005..0.009 rows=13 loops=1) + Sort Key: so.ssyr + Sort Method: quicksort Memory: 26kB + -> CTE Scan on std so (cost=0.00..302.76 rows=15138 width=40) (actual time=0.001..0.002 rows=15 loops=1) + -> Materialize (cost=488161492.03..489813607.52 rows=330423099 width=1268) (actual time=64619.055..66543.724 rows=812398 loops=1) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=54351 written=90873 + I/O Timings: read=5431.112 + -> Sort (cost=488161492.03..488987549.77 rows=330423099 width=1268) (actual time=64619.051..65222.574 rows=812398 loops=1) + Sort Key: un.oseas + Sort Method: external merge Disk: 434808kB + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=54351 written=54352 + I/O Timings: read=5431.112 + -> Hash Left Join (cost=30326.40..75489285.22 rows=330423099 width=1268) (actual time=26974.130..61679.511 rows=812398 loops=1) + Hash Cond: ((un.part = cr.y0part) AND (un.plnt = cr.y0plnt)) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1 + I/O Timings: read=5431.112 + -> Hash Left Join (cost=22414.65..56426266.97 rows=330423099 width=1262) (actual time=26803.460..61130.886 rows=812398 loops=1) + Hash Cond: ((un.part = cp.chpart) AND (un.plnt = cp.chplnt)) + Buffers: shared hit=35372 read=151936, local hit=5659517 read=1 + I/O Timings: read=5307.518 + -> Hash Left Join (cost=14299.03..36533966.06 rows=330423099 width=1256) (actual time=26596.173..60544.080 rows=812398 loops=1) + Hash Cond: ((un.part = cm.cgpart) AND (un.plnt = cm.cgplnt)) + Buffers: shared hit=35372 read=146620, local hit=5659517 read=1 + I/O Timings: read=5163.164 + -> Hash Left Join (cost=7433.88..34026391.85 rows=330423099 width=1250) (actual time=26466.230..59938.193 rows=812398 loops=1) + Hash Cond: (un.bill_cust = sc.bvcust) + Buffers: shared hit=35372 read=142113, local hit=5659517 read=1 + I/O Timings: read=5079.788 + -> Hash Left Join (cost=3723.16..29479363.52 rows=330423099 width=1223) (actual time=26455.847..59596.315 rows=812398 loops=1) + Hash Cond: (un.bill_cust = bc.bvcust) + Buffers: shared hit=32148 read=142113, local hit=5659517 read=1 + I/O Timings: read=5079.788 + -> Hash Left Join (cost=12.44..24932335.18 rows=330423099 width=1196) (actual time=26376.451..59161.607 rows=812398 loops=1) + Hash Cond: ((un.ming = mmgp.brmgrp) AND (un.majg = mmgp.brgrp)) + Buffers: shared hit=32148 read=138889, local hit=5659517 read=1 + I/O Timings: read=5012.664 + -> Hash Left Join (cost=7.51..15006668.18 rows=330423099 width=1186) (actual time=26375.626..58843.583 rows=812398 loops=1) + Hash Cond: (un.majg = majg.bqgrp) + Buffers: shared hit=32148 read=138888, local hit=5659517 read=1 + I/O Timings: read=5011.904 + -> Hash Left Join (cost=6.24..13569326.43 rows=330423099 width=1176) (actual time=26375.306..58564.379 rows=812398 loops=1) + Hash Cond: (un.majs = sj.bsmjcd) + Buffers: shared hit=32148 read=138887, local hit=5659517 read=1 + I/O Timings: read=5011.601 + -> Hash Left Join (cost=6.21..12313718.62 rows=330423099 width=1144) (actual time=26375.285..58278.120 rows=812398 loops=1) + Hash Cond: ((un.majs = si.bsmjcd) AND (un.mins = si.bsmncd)) + Buffers: shared hit=32147 read=138887, local hit=5659517 read=1 + I/O Timings: read=5011.601 + -> Hash Left Join (cost=3.90..9830091.09 rows=330423099 width=1112) (actual time=26374.932..57946.951 rows=812398 loops=1) + Hash Cond: (un.quota_rep = repc.rcode) + Buffers: shared hit=32147 read=138886, local hit=5659517 read=1 + I/O Timings: read=5011.303 + -> CTE Scan on un (cost=0.00..6608461.98 rows=330423099 width=1048) (actual time=26363.408..57457.121 rows=812398 loops=1) + Buffers: shared hit=32147 read=138860, local hit=5659517 read=1 + I/O Timings: read=5000.713 + -> Hash (cost=2.40..2.40 rows=120 width=96) (actual time=11.512..11.512 rows=120 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 17kB + Buffers: shared read=26 + I/O Timings: read=10.590 + -> CTE Scan on repc (cost=0.00..2.40 rows=120 width=96) (actual time=4.008..11.473 rows=120 loops=1) + Buffers: shared read=26 + I/O Timings: read=10.590 + -> Hash (cost=1.32..1.32 rows=66 width=96) (actual time=0.343..0.343 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.297 + -> CTE Scan on si (cost=0.00..1.32 rows=66 width=96) (actual time=0.310..0.330 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.297 + -> Hash (cost=0.02..0.02 rows=1 width=64) (actual time=0.014..0.014 rows=11 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=1 + -> CTE Scan on sj (cost=0.00..0.02 rows=1 width=64) (actual time=0.006..0.012 rows=11 loops=1) + Buffers: shared hit=1 + -> Hash (cost=1.12..1.12 rows=12 width=14) (actual time=0.316..0.316 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared read=1 + I/O Timings: read=0.303 + -> Seq Scan on majg (cost=0.00..1.12 rows=12 width=14) (actual time=0.309..0.310 rows=12 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.303 + -> Hash (cost=2.57..2.57 rows=157 width=18) (actual time=0.818..0.818 rows=157 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=1 + I/O Timings: read=0.760 + -> Seq Scan on mmgp (cost=0.00..2.57 rows=157 width=18) (actual time=0.771..0.787 rows=157 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.760 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=79.377..79.377 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared read=3224 + I/O Timings: read=67.124 + -> Seq Scan on cust bc (cost=0.00..3440.32 rows=21632 width=35) (actual time=1.226..74.190 rows=21632 loops=1) + Buffers: shared read=3224 + I/O Timings: read=67.124 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=10.361..10.361 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared hit=3224 + -> Seq Scan on cust sc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.007..6.549 rows=21632 loops=1) + Buffers: shared hit=3224 + -> Hash (cost=5450.26..5450.26 rows=94326 width=29) (actual time=129.891..129.891 rows=94326 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6699kB + Buffers: shared read=4507 + I/O Timings: read=83.376 + -> Seq Scan on icstm cm (cost=0.00..5450.26 rows=94326 width=29) (actual time=1.628..106.590 rows=94326 loops=1) + Buffers: shared read=4507 + I/O Timings: read=83.376 + -> Hash (cost=6435.85..6435.85 rows=111985 width=20) (actual time=207.238..207.238 rows=111985 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6768kB + Buffers: shared read=5316 + I/O Timings: read=144.354 + -> Seq Scan on icstp cp (cost=0.00..6435.85 rows=111985 width=20) (actual time=12.877..174.296 rows=111985 loops=1) + Buffers: shared read=5316 + I/O Timings: read=144.354 + -> Hash (cost=6315.90..6315.90 rows=106390 width=27) (actual time=167.190..167.190 rows=106390 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7334kB + Buffers: shared read=5252 + I/O Timings: read=123.594 + -> Seq Scan on icstr cr (cost=0.00..6315.90 rows=106390 width=27) (actual time=1.618..138.920 rows=106390 loops=1) + Buffers: shared read=5252 + I/O Timings: read=123.594 + -> CTE Scan on agg a (cost=0.00..37859720740.70 rows=1892986037035 width=1520) (actual time=112425.683..119325.832 rows=809656 loops=1) + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=169586 written=302217 + I/O Timings: read=5431.112 + -> CTE Scan on agg a_1 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=10.640..1070.930 rows=298533 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Forecast}'::text[]))) + Rows Removed by Filter: 511123 + Buffers: temp read=57858 written=1 + -> CTE Scan on agg a_2 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=24.901..1109.287 rows=270191 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Budget}'::text[]))) + Rows Removed by Filter: 539465 + Buffers: temp read=57858 + +
++ + + +7 +27s560ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-14 17:15:07 ]
+ +++ +Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.033..24368.549 rows=190996 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 227 + Buffers: shared hit=12201 + +
++ + + +8 +27s559ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-14 17:15:07 ]
+ +++ +Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.018..23110.458 rows=167047 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 120 + Buffers: shared hit=10779 + +
++ + + +9 +25s847ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-15 17:30:45 - Database: ubm - User: report - Remote: USHCC10107.GBL.HC-companies.com - Application: [unknown] ]
+ +++ +Sort (cost=113023.45..113023.95 rows=200 width=232) (actual time=25846.751..25846.759 rows=129 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=20260 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + CTE un + -> Append (cost=46404.12..112987.32 rows=496 width=232) (actual time=25114.996..25846.141 rows=151 loops=1) + Buffers: shared hit=20257 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + -> GroupAggregate (cost=46404.12..46410.90 rows=129 width=232) (actual time=25114.995..25208.334 rows=81 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=20125 read=37204 written=3367, local hit=211099 read=1 + I/O Timings: read=23025.573 write=75.759 + -> Sort (cost=46404.12..46404.45 rows=129 width=182) (actual time=25114.970..25120.224 rows=105549 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 17915kB + Buffers: shared hit=20125 read=37204 written=3367, local hit=211099 read=1 + I/O Timings: read=23025.573 write=75.759 + -> Nested Loop (cost=1445.79..46399.60 rows=129 width=182) (actual time=37.452..24985.218 rows=105549 loops=1) + Buffers: shared hit=20125 read=37204 written=3367, local hit=211099 read=1 + I/O Timings: read=23025.573 write=75.759 + -> Nested Loop (cost=1445.65..46391.77 rows=7 width=110) (actual time=37.425..24330.405 rows=105573 loops=1) + Buffers: shared hit=20125 read=37204 written=3367, local hit=2 + I/O Timings: read=23025.565 write=75.759 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.021..0.037 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Bitmap Heap Scan on osmp osm (cost=1445.65..46387.13 rows=46 width=39) (actual time=1.955..638.928 rows=2778 loops=38) + Recheck Cond: (fspr = sd.fspr) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 70 + Heap Blocks: exact=56851 + Buffers: shared hit=20125 read=37204 written=3367 + I/O Timings: read=23025.565 write=75.759 + -> Bitmap Index Scan on osmp_fspr (cost=0.00..1445.64 rows=27895 width=0) (actual time=1.650..1.650 rows=2848 loops=38) + Index Cond: (fspr = sd.fspr) + Buffers: shared hit=108 read=370 written=62 + I/O Timings: read=51.006 write=0.514 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=105573) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=211097 read=1 + I/O Timings: read=0.008 + -> GroupAggregate (cost=66549.72..66568.99 rows=367 width=232) (actual time=630.211..637.789 rows=70 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=132 read=57866, local hit=10350 + I/O Timings: read=298.856 + -> Sort (cost=66549.72..66550.64 rows=367 width=178) (actual time=630.192..630.748 rows=5174 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 920kB + Buffers: shared hit=132 read=57866, local hit=10350 + I/O Timings: read=298.856 + -> Nested Loop (cost=1004.74..66534.08 rows=367 width=178) (actual time=593.533..627.538 rows=5174 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 895102 + Buffers: shared hit=132 read=57866, local hit=10350 + I/O Timings: read=298.856 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.013..0.081 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..66472.54 rows=19 width=106) (actual time=0.030..3.144 rows=5174 loops=174) + Buffers: shared hit=132 read=57866, local hit=10348 + I/O Timings: read=298.856 + -> Nested Loop Left Join (cost=1004.74..66472.44 rows=19 width=106) (actual time=5.277..509.890 rows=5174 loops=1) + Buffers: shared hit=132 read=57866, local hit=10348 + I/O Timings: read=298.856 + -> Gather (cost=1000.00..66465.04 rows=1 width=34) (actual time=5.247..458.234 rows=5174 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=132 read=57866 + I/O Timings: read=298.856 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..65464.94 rows=1 width=34) (actual time=1.669..482.765 rows=1725 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259938 + Buffers: shared hit=132 read=57866 + I/O Timings: read=298.856 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.009..0.009 rows=1 loops=5174) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5174 + Buffers: local hit=10348 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.007..0.007 rows=1 loops=5174) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5174 + -> HashAggregate (cost=25.98..28.48 rows=200 width=232) (actual time=25846.428..25846.522 rows=129 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=20257 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + -> CTE Scan on un (cost=0.00..11.16 rows=494 width=232) (actual time=25115.000..25846.302 rows=129 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=20257 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + +
++ + + +10 +23s808ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-14 17:09:40 - Database: ubm - User: report - Remote: USHCC10107.GBL.HC-companies.com - Application: [unknown] ]
+ +++ +Sort (cost=113712.54..113713.04 rows=200 width=232) (actual time=23807.981..23807.985 rows=128 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=24173 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + CTE un + -> Append (cost=46404.12..113676.42 rows=496 width=232) (actual time=20688.511..23807.529 rows=150 loops=1) + Buffers: shared hit=24170 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + -> GroupAggregate (cost=46404.12..46410.90 rows=129 width=232) (actual time=20688.510..20789.478 rows=81 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=21002 read=36327, local hit=211099 read=1 + I/O Timings: read=18300.701 + -> Sort (cost=46404.12..46404.45 rows=129 width=182) (actual time=20688.486..20694.576 rows=105549 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 17915kB + Buffers: shared hit=21002 read=36327, local hit=211099 read=1 + I/O Timings: read=18300.701 + -> Nested Loop (cost=1445.79..46399.60 rows=129 width=182) (actual time=37.496..20515.988 rows=105549 loops=1) + Buffers: shared hit=21002 read=36327, local hit=211099 read=1 + I/O Timings: read=18300.701 + -> Nested Loop (cost=1445.65..46391.77 rows=7 width=110) (actual time=37.467..19809.839 rows=105573 loops=1) + Buffers: shared hit=21002 read=36327, local hit=2 + I/O Timings: read=18300.692 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.020..0.038 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Bitmap Heap Scan on osmp osm (cost=1445.65..46387.13 rows=46 width=39) (actual time=2.140..520.028 rows=2778 loops=38) + Recheck Cond: (fspr = sd.fspr) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 70 + Heap Blocks: exact=56851 + Buffers: shared hit=21002 read=36327 + I/O Timings: read=18300.692 + -> Bitmap Index Scan on osmp_fspr (cost=0.00..1445.64 rows=27895 width=0) (actual time=1.908..1.908 rows=2848 loops=38) + Index Cond: (fspr = sd.fspr) + Buffers: shared hit=110 read=368 + I/O Timings: read=57.208 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=105573) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=211097 read=1 + I/O Timings: read=0.009 + -> GroupAggregate (cost=67238.81..67258.08 rows=367 width=232) (actual time=3013.320..3018.033 rows=69 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=3168 read=54830, local hit=10926 + I/O Timings: read=7983.465 + -> Sort (cost=67238.81..67239.73 rows=367 width=178) (actual time=3013.300..3013.513 rows=5462 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 961kB + Buffers: shared hit=3168 read=54830, local hit=10926 + I/O Timings: read=7983.465 + -> Nested Loop (cost=1004.74..67223.18 rows=367 width=178) (actual time=2972.945..3010.611 rows=5462 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 944926 + Buffers: shared hit=3168 read=54830, local hit=10926 + I/O Timings: read=7983.465 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.017..0.072 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..67161.63 rows=19 width=106) (actual time=13.102..16.813 rows=5462 loops=174) + Buffers: shared hit=3168 read=54830, local hit=10924 + I/O Timings: read=7983.465 + -> Nested Loop Left Join (cost=1004.74..67161.54 rows=19 width=106) (actual time=2279.747..2880.350 rows=5462 loops=1) + Buffers: shared hit=3168 read=54830, local hit=10924 + I/O Timings: read=7983.465 + -> Gather (cost=1000.00..67154.13 rows=1 width=34) (actual time=2279.720..2819.147 rows=5462 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=3168 read=54830 + I/O Timings: read=7983.465 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..66154.03 rows=1 width=34) (actual time=2269.482..2837.169 rows=1821 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259313 + Buffers: shared hit=3168 read=54830 + I/O Timings: read=7983.465 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.008..0.008 rows=1 loops=5462) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5462 + Buffers: local hit=10924 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.007..0.007 rows=1 loops=5462) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5462 + -> HashAggregate (cost=25.98..28.48 rows=200 width=232) (actual time=23807.814..23807.857 rows=128 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=24170 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + -> CTE Scan on un (cost=0.00..11.16 rows=494 width=232) (actual time=20688.515..23807.691 rows=128 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=24170 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + +
++ + + +11 +21s242ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-15 17:30:39 - Database: ubm - User: report - Remote: USHCC10107.GBL.HC-companies.com - Application: [unknown] ]
+ +++ +Sort (cost=99922.38..99922.88 rows=200 width=232) (actual time=21211.683..21211.708 rows=317 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 69kB + Buffers: shared hit=4 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + CTE un + -> Append (cost=32534.94..99887.14 rows=502 width=232) (actual time=5942.671..21209.531 rows=317 loops=1) + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + -> GroupAggregate (cost=32534.94..32547.80 rows=245 width=232) (actual time=5942.670..6367.056 rows=197 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Sort (cost=32534.94..32535.55 rows=245 width=185) (actual time=5942.642..5990.837 rows=406814 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 69497kB + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Nested Loop (cost=1006.06..32525.21 rows=245 width=185) (actual time=3.834..5526.120 rows=406814 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Hash Left Join (cost=1005.91..31588.56 rows=738 width=113) (actual time=3.809..3558.965 rows=406814 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared read=26345 written=122, local hit=2 + I/O Timings: read=10489.166 write=1.431 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=3.660..3400.209 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared read=26345 written=122 + I/O Timings: read=10489.166 write=1.431 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.781..3631.234 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared read=26345 written=122 + I/O Timings: read=10489.166 write=1.431 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.083..0.083 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.013..0.049 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=813627 read=1 + I/O Timings: read=0.006 + -> GroupAggregate (cost=67318.31..67331.81 rows=257 width=232) (actual time=14757.926..14842.413 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Sort (cost=67318.31..67318.96 rows=257 width=178) (actual time=14757.905..14766.226 rows=94732 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16394kB + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Nested Loop (cost=1006.06..67308.03 rows=257 width=178) (actual time=65.185..14658.975 rows=94732 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Hash Left Join (cost=1005.91..65849.40 rows=1114 width=122) (actual time=65.171..12232.663 rows=628518 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=1 read=57991 written=2, local hit=2 + I/O Timings: read=37441.627 write=0.074 + -> Gather (cost=1000.00..65829.04 rows=1114 width=51) (actual time=65.104..11994.997 rows=628518 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=1 read=57991 written=2 + I/O Timings: read=37441.627 write=0.074 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..64717.64 rows=464 width=51) (actual time=56.186..12707.976 rows=209506 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52157 + Buffers: shared hit=1 read=57991 written=2 + I/O Timings: read=37441.627 write=0.074 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.055..0.055 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.009..0.031 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=628518) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1255196 + -> HashAggregate (cost=25.10..27.60 rows=200 width=232) (actual time=21210.361..21210.698 rows=317 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + -> CTE Scan on un (cost=0.00..10.04 rows=502 width=232) (actual time=5942.675..21209.793 rows=317 loops=1) + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + +
++ + + +12 +20s978ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-15 00:50:56 - Database: ubm - User: report - Remote: USHCC10107.GBL.HC-companies.com - Application: [unknown] ]
+ +++ +Sort (cost=100695.96..100696.46 rows=200 width=232) (actual time=20966.035..20966.048 rows=317 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 69kB + Buffers: shared hit=34962 read=49378, local hit=2068057 read=1 + I/O Timings: read=13976.237 + CTE un + -> Append (cost=32534.94..100659.46 rows=527 width=232) (actual time=11106.509..20964.625 rows=317 loops=1) + Buffers: shared hit=34959 read=49378, local hit=2068057 read=1 + I/O Timings: read=13976.237 + -> GroupAggregate (cost=32534.94..32547.80 rows=245 width=232) (actual time=11106.508..12179.134 rows=197 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.011 + -> Sort (cost=32534.94..32535.55 rows=245 width=185) (actual time=11106.482..11206.114 rows=406814 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 69497kB + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.011 + -> Nested Loop (cost=1006.06..32525.21 rows=245 width=185) (actual time=44.964..9990.465 rows=406814 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.011 + -> Hash Left Join (cost=1005.91..31588.56 rows=738 width=113) (actual time=44.931..5527.200 rows=406814 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=26345, local hit=2 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=44.776..5096.175 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=26345 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.024..211.973 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared hit=26345 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.138..0.138 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.015..0.075 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.009..0.010 rows=1 loops=406814) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=813627 read=1 + I/O Timings: read=0.011 + -> GroupAggregate (cost=68088.95..68103.76 rows=282 width=232) (actual time=8646.936..8785.428 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=8614 read=49378, local hit=1254428 + I/O Timings: read=13976.227 + -> Sort (cost=68088.95..68089.66 rows=282 width=178) (actual time=8646.892..8657.832 rows=94347 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16340kB + Buffers: shared hit=8614 read=49378, local hit=1254428 + I/O Timings: read=13976.227 + -> Nested Loop (cost=1006.06..68077.48 rows=282 width=178) (actual time=5.392..8512.755 rows=94347 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=8614 read=49378, local hit=1254428 + I/O Timings: read=13976.227 + -> Hash Left Join (cost=1005.91..66481.58 rows=1220 width=122) (actual time=5.370..5411.006 rows=628133 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=8614 read=49378, local hit=2 + I/O Timings: read=13976.227 + -> Gather (cost=1000.00..66459.83 rows=1220 width=51) (actual time=5.260..5127.669 rows=628133 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=8614 read=49378 + I/O Timings: read=13976.227 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..65337.83 rows=508 width=51) (actual time=11.068..4902.983 rows=209378 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52132 + Buffers: shared hit=8614 read=49378 + I/O Timings: read=13976.227 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.086..0.086 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.015..0.048 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=628133) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1254426 + -> HashAggregate (cost=26.35..28.85 rows=200 width=232) (actual time=20965.583..20965.696 rows=317 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=34959 read=49378, local hit=2068057 read=1 + I/O Timings: read=13976.237 + -> CTE Scan on un (cost=0.00..10.54 rows=527 width=232) (actual time=11106.512..20964.985 rows=317 loops=1) + Buffers: shared hit=34959 read=49378, local hit=2068057 read=1 + I/O Timings: read=13976.237 + +
++ + + +13 +18s342ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-14 17:21:12 - Database: ubm - User: report - Remote: USHCC10107.GBL.HC-companies.com - Application: [unknown] ]
+ +++ +Sort (cost=113712.54..113713.04 rows=200 width=232) (actual time=18341.790..18341.795 rows=128 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=24593 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + CTE un + -> Append (cost=46404.12..113676.42 rows=496 width=232) (actual time=17686.530..18341.413 rows=150 loops=1) + Buffers: shared hit=24590 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + -> GroupAggregate (cost=46404.12..46410.90 rows=129 width=232) (actual time=17686.530..17780.512 rows=81 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=20982 read=36347, local hit=211099 read=1 + I/O Timings: read=16170.335 + -> Sort (cost=46404.12..46404.45 rows=129 width=182) (actual time=17686.507..17691.642 rows=105549 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 17915kB + Buffers: shared hit=20982 read=36347, local hit=211099 read=1 + I/O Timings: read=16170.335 + -> Nested Loop (cost=1445.79..46399.60 rows=129 width=182) (actual time=336.691..17577.973 rows=105549 loops=1) + Buffers: shared hit=20982 read=36347, local hit=211099 read=1 + I/O Timings: read=16170.335 + -> Nested Loop (cost=1445.65..46391.77 rows=7 width=110) (actual time=336.406..17026.558 rows=105573 loops=1) + Buffers: shared hit=20982 read=36347, local hit=2 + I/O Timings: read=16170.091 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.019..0.035 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Bitmap Heap Scan on osmp osm (cost=1445.65..46387.13 rows=46 width=39) (actual time=9.729..447.136 rows=2778 loops=38) + Recheck Cond: (fspr = sd.fspr) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 70 + Heap Blocks: exact=56851 + Buffers: shared hit=20982 read=36347 + I/O Timings: read=16170.091 + -> Bitmap Index Scan on osmp_fspr (cost=0.00..1445.64 rows=27895 width=0) (actual time=6.416..6.416 rows=2848 loops=38) + Index Cond: (fspr = sd.fspr) + Buffers: shared hit=110 read=368 + I/O Timings: read=223.920 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=105573) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=211097 read=1 + I/O Timings: read=0.244 + -> GroupAggregate (cost=67238.81..67258.08 rows=367 width=232) (actual time=556.403..560.886 rows=69 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=3608 read=54390, local hit=10926 + I/O Timings: read=210.804 + -> Sort (cost=67238.81..67239.73 rows=367 width=178) (actual time=556.386..556.605 rows=5462 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 961kB + Buffers: shared hit=3608 read=54390, local hit=10926 + I/O Timings: read=210.804 + -> Nested Loop (cost=1004.74..67223.18 rows=367 width=178) (actual time=518.705..553.668 rows=5462 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 944926 + Buffers: shared hit=3608 read=54390, local hit=10926 + I/O Timings: read=210.804 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.013..0.055 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..67161.63 rows=19 width=106) (actual time=2.013..2.722 rows=5462 loops=174) + Buffers: shared hit=3608 read=54390, local hit=10924 + I/O Timings: read=210.804 + -> Nested Loop Left Join (cost=1004.74..67161.54 rows=19 width=106) (actual time=350.244..437.677 rows=5462 loops=1) + Buffers: shared hit=3608 read=54390, local hit=10924 + I/O Timings: read=210.804 + -> Gather (cost=1000.00..67154.13 rows=1 width=34) (actual time=350.219..407.718 rows=5462 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=3608 read=54390 + I/O Timings: read=210.804 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..66154.03 rows=1 width=34) (actual time=333.708..384.567 rows=1821 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259313 + Buffers: shared hit=3608 read=54390 + I/O Timings: read=210.804 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=5462) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5462 + Buffers: local hit=10924 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.004..0.004 rows=1 loops=5462) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5462 + -> HashAggregate (cost=25.98..28.48 rows=200 width=232) (actual time=18341.605..18341.654 rows=128 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=24590 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + -> CTE Scan on un (cost=0.00..11.16 rows=494 width=232) (actual time=17686.534..18341.509 rows=128 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=24590 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + +
++ + + +14 +16s584ms ++ +DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS INT) + FROM ( + SELECT + DISTINCT "diinv#" + FROM + import.osmi + WHERE + "ddord#" = 0) n + WHERE + n. "diinv#" = osm. "diinv#"); + ++[ Date: 2019-03-15 00:49:30 - Database: ubm - User: ptrowbridge_md5 - Remote: USHCC10107.GBL.HC-companies.com - Application: psql ]
+ +++ +Delete on osm (cost=2579.44..36736.43 rows=16 width=36) (actual time=16584.934..16584.934 rows=0 loops=1) + Buffers: shared hit=1558922 read=6078 dirtied=71 + I/O Timings: read=735.005 + -> Nested Loop (cost=2579.44..36736.43 rows=16 width=36) (actual time=99.141..16583.640 rows=159 loops=1) + Buffers: shared hit=1558763 read=6078 dirtied=66 + I/O Timings: read=735.005 + -> Subquery Scan on n (cost=2579.01..2579.03 rows=1 width=36) (actual time=5.671..7.407 rows=223 loops=1) + Buffers: shared hit=2579 + -> Unique (cost=2579.01..2579.02 rows=1 width=6) (actual time=5.664..6.608 rows=223 loops=1) + Buffers: shared hit=2579 + -> Sort (cost=2579.01..2579.02 rows=1 width=6) (actual time=5.662..5.909 rows=252 loops=1) + Sort Key: osmi."diinv#" + Sort Method: quicksort Memory: 36kB + Buffers: shared hit=2579 + -> Seq Scan on osmi (cost=0.00..2579.00 rows=1 width=6) (actual time=0.047..5.580 rows=252 loops=1) + Filter: ("ddord#" = '0'::numeric) + Rows Removed by Filter: 25396 + Buffers: shared hit=2579 + -> Index Scan using osm_pk on osm (cost=0.42..34157.24 rows=16 width=12) (actual time=24.619..74.328 rows=1 loops=223) + Index Cond: ("diinv#" = n."diinv#") + Buffers: shared hit=1556184 read=6078 dirtied=66 + I/O Timings: read=735.005 + +
++ + + +15 +14s707ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-15 17:30:39 ]
+ +++ +Parallel Seq Scan on osm (cost=0.00..64717.64 rows=464 width=51) (actual time=60.452..13291.376 rows=311798 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 78830 + Buffers: shared read=28119 + I/O Timings: read=12959.156 + +
++ + + +16 +14s703ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-15 17:30:39 ]
+ +++ +Parallel Seq Scan on osm (cost=0.00..64717.64 rows=464 width=51) (actual time=43.842..13321.716 rows=311459 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 76258 + Buffers: shared hit=1 read=27922 written=2 + I/O Timings: read=12990.013 write=0.074 + +
++ + + +17 +13s556ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-14 17:09:25 - Database: ubm - User: report - Remote: USHCC10107.GBL.HC-companies.com - Application: [unknown] ]
+ +++ +Sort (cost=100695.96..100696.46 rows=200 width=232) (actual time=13556.122..13556.143 rows=317 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 69kB + Buffers: shared hit=29386 read=54954, local hit=2066721 read=1 + I/O Timings: read=22022.804 + CTE un + -> Append (cost=32534.94..100659.46 rows=527 width=232) (actual time=2423.610..13554.284 rows=317 loops=1) + Buffers: shared hit=29383 read=54954, local hit=2066721 read=1 + I/O Timings: read=22022.804 + -> GroupAggregate (cost=32534.94..32547.80 rows=245 width=232) (actual time=2423.609..2805.689 rows=197 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.017 + -> Sort (cost=32534.94..32535.55 rows=245 width=185) (actual time=2423.587..2464.362 rows=406814 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 69497kB + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.017 + -> Nested Loop (cost=1006.06..32525.21 rows=245 width=185) (actual time=1.445..2052.334 rows=406814 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.017 + -> Hash Left Join (cost=1005.91..31588.56 rows=738 width=113) (actual time=1.407..615.418 rows=406814 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=26345, local hit=2 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=1.271..501.468 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=26345 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.021..99.366 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared hit=26345 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.123..0.125 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.010..0.040 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=406814) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=813627 read=1 + I/O Timings: read=0.017 + -> GroupAggregate (cost=68088.95..68103.76 rows=282 width=232) (actual time=10608.602..10748.536 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=3038 read=54954, local hit=1253092 + I/O Timings: read=22022.787 + -> Sort (cost=68088.95..68089.66 rows=282 width=178) (actual time=10608.560..10626.817 rows=93679 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16246kB + Buffers: shared hit=3038 read=54954, local hit=1253092 + I/O Timings: read=22022.787 + -> Nested Loop (cost=1006.06..68077.48 rows=282 width=178) (actual time=17.729..10405.013 rows=93679 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=3038 read=54954, local hit=1253092 + I/O Timings: read=22022.787 + -> Hash Left Join (cost=1005.91..66481.58 rows=1220 width=122) (actual time=17.712..7561.990 rows=627465 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=3038 read=54954, local hit=2 + I/O Timings: read=22022.787 + -> Gather (cost=1000.00..66459.83 rows=1220 width=51) (actual time=17.642..7272.901 rows=627465 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=3038 read=54954 + I/O Timings: read=22022.787 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..65337.83 rows=508 width=51) (actual time=10.170..7586.736 rows=209155 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 51978 + Buffers: shared hit=3038 read=54954 + I/O Timings: read=22022.787 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.057..0.057 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.010..0.032 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=627465) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1253090 + -> HashAggregate (cost=26.35..28.85 rows=200 width=232) (actual time=13555.499..13555.686 rows=317 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=29383 read=54954, local hit=2066721 read=1 + I/O Timings: read=22022.804 + -> CTE Scan on un (cost=0.00..10.54 rows=527 width=232) (actual time=2423.614..13554.682 rows=317 loops=1) + Buffers: shared hit=29383 read=54954, local hit=2066721 read=1 + I/O Timings: read=22022.804 + +
++ + + +18 +12s281ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-14 17:21:01 - Database: ubm - User: report - Remote: USHCC10107.GBL.HC-companies.com - Application: [unknown] ]
+ +++ +Sort (cost=100695.96..100696.46 rows=200 width=232) (actual time=12281.541..12281.555 rows=317 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 69kB + Buffers: shared hit=3482 read=80858 dirtied=3478, local hit=2066721 read=1 + I/O Timings: read=20311.283 + CTE un + -> Append (cost=32534.94..100659.46 rows=527 width=232) (actual time=3453.641..12280.132 rows=317 loops=1) + Buffers: shared hit=3479 read=80858 dirtied=3478, local hit=2066721 read=1 + I/O Timings: read=20311.283 + -> GroupAggregate (cost=32534.94..32547.80 rows=245 width=232) (actual time=3453.640..3952.327 rows=197 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared read=26345, local hit=813629 read=1 + I/O Timings: read=2285.213 + -> Sort (cost=32534.94..32535.55 rows=245 width=185) (actual time=3453.601..3511.523 rows=406814 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 69497kB + Buffers: shared read=26345, local hit=813629 read=1 + I/O Timings: read=2285.213 + -> Nested Loop (cost=1006.06..32525.21 rows=245 width=185) (actual time=5.988..3065.499 rows=406814 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Buffers: shared read=26345, local hit=813629 read=1 + I/O Timings: read=2285.213 + -> Hash Left Join (cost=1005.91..31588.56 rows=738 width=113) (actual time=5.952..1146.761 rows=406814 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2285.196 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=5.851..991.768 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared read=26345 + I/O Timings: read=2285.196 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=7.005..891.537 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared read=26345 + I/O Timings: read=2285.196 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.072..0.072 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.014..0.041 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=813627 read=1 + I/O Timings: read=0.017 + -> GroupAggregate (cost=68088.95..68103.76 rows=282 width=232) (actual time=8247.608..8327.739 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=3479 read=54513 dirtied=3478, local hit=1253092 + I/O Timings: read=18026.070 + -> Sort (cost=68088.95..68089.66 rows=282 width=178) (actual time=8247.589..8255.395 rows=93679 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16246kB + Buffers: shared hit=3479 read=54513 dirtied=3478, local hit=1253092 + I/O Timings: read=18026.070 + -> Nested Loop (cost=1006.06..68077.48 rows=282 width=178) (actual time=31.734..8170.368 rows=93679 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=3479 read=54513 dirtied=3478, local hit=1253092 + I/O Timings: read=18026.070 + -> Hash Left Join (cost=1005.91..66481.58 rows=1220 width=122) (actual time=31.701..5807.059 rows=627465 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=3479 read=54513 dirtied=3478, local hit=2 + I/O Timings: read=18026.070 + -> Gather (cost=1000.00..66459.83 rows=1220 width=51) (actual time=31.495..5563.385 rows=627465 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=3479 read=54513 dirtied=3478 + I/O Timings: read=18026.070 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..65337.83 rows=508 width=51) (actual time=21.425..6223.191 rows=209155 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 51978 + Buffers: shared hit=3479 read=54513 dirtied=3478 + I/O Timings: read=18026.070 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.143..0.143 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.019..0.061 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=627465) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1253090 + -> HashAggregate (cost=26.35..28.85 rows=200 width=232) (actual time=12281.089..12281.196 rows=317 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=3479 read=80858 dirtied=3478, local hit=2066721 read=1 + I/O Timings: read=20311.283 + -> CTE Scan on un (cost=0.00..10.54 rows=527 width=232) (actual time=3453.645..12280.486 rows=317 loops=1) + Buffers: shared hit=3479 read=80858 dirtied=3478, local hit=2066721 read=1 + I/O Timings: read=20311.283 + +
++ + + +19 +10s935ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-18 10:06:54 - Database: ubm - User: report - Remote: USHCC10107.GBL.HC-companies.com - Application: [unknown] ]
+ +++ +Sort (cost=99922.38..99922.88 rows=200 width=232) (actual time=10935.222..10935.243 rows=317 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 69kB + Buffers: shared hit=28739 read=55601, local hit=2068827 read=1 + I/O Timings: read=141.169 + CTE un + -> Append (cost=32534.94..99887.14 rows=502 width=232) (actual time=5060.751..10933.585 rows=317 loops=1) + Buffers: shared hit=28736 read=55601, local hit=2068827 read=1 + I/O Timings: read=141.169 + -> GroupAggregate (cost=32534.94..32547.80 rows=245 width=232) (actual time=5060.750..6055.287 rows=197 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.004 + -> Sort (cost=32534.94..32535.55 rows=245 width=185) (actual time=5060.730..5194.382 rows=406814 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 69497kB + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.004 + -> Nested Loop (cost=1006.06..32525.21 rows=245 width=185) (actual time=1.212..4434.425 rows=406814 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.004 + -> Hash Left Join (cost=1005.91..31588.56 rows=738 width=113) (actual time=1.197..2705.824 rows=406814 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=26345, local hit=2 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=1.136..2556.469 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=26345 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.018..114.801 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared hit=26345 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.053..0.053 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.005..0.028 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=813627 read=1 + I/O Timings: read=0.004 + -> GroupAggregate (cost=67318.31..67331.81 rows=257 width=232) (actual time=4765.996..4878.228 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=2391 read=55601, local hit=1255198 + I/O Timings: read=141.165 + -> Sort (cost=67318.31..67318.96 rows=257 width=178) (actual time=4765.969..4779.799 rows=94732 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16394kB + Buffers: shared hit=2391 read=55601, local hit=1255198 + I/O Timings: read=141.165 + -> Nested Loop (cost=1006.06..67308.03 rows=257 width=178) (actual time=2.962..4672.656 rows=94732 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=2391 read=55601, local hit=1255198 + I/O Timings: read=141.165 + -> Hash Left Join (cost=1005.91..65849.40 rows=1114 width=122) (actual time=2.719..2606.200 rows=628518 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=2391 read=55601, local hit=2 + I/O Timings: read=141.165 + -> Gather (cost=1000.00..65829.04 rows=1114 width=51) (actual time=2.603..2182.415 rows=628518 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=2391 read=55601 + I/O Timings: read=141.165 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..64717.64 rows=464 width=51) (actual time=0.034..233.358 rows=209506 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52157 + Buffers: shared hit=2391 read=55601 + I/O Timings: read=141.165 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.095..0.095 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.013..0.056 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=628518) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1255196 + -> HashAggregate (cost=25.10..27.60 rows=200 width=232) (actual time=10934.569..10934.735 rows=317 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=28736 read=55601, local hit=2068827 read=1 + I/O Timings: read=141.169 + -> CTE Scan on un (cost=0.00..10.04 rows=502 width=232) (actual time=5060.754..10933.963 rows=317 loops=1) + Buffers: shared hit=28736 read=55601, local hit=2068827 read=1 + I/O Timings: read=141.169 + +
++ + + + +20 +10s695ms ++ +--CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++[ Date: 2019-03-18 10:06:52 - Database: ubm - User: report - Remote: USHCC10107.GBL.HC-companies.com - Application: [unknown] ]
+ +++ +Sort (cost=99922.38..99922.88 rows=200 width=232) (actual time=10689.845..10689.860 rows=317 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 69kB + Buffers: shared hit=28334 read=56003, local hit=2068827 read=1 + I/O Timings: read=116.017 + CTE un + -> Append (cost=32534.94..99887.14 rows=502 width=232) (actual time=3391.868..10681.595 rows=317 loops=1) + Buffers: shared hit=28334 read=56003, local hit=2068827 read=1 + I/O Timings: read=116.017 + -> GroupAggregate (cost=32534.94..32547.80 rows=245 width=232) (actual time=3391.867..4415.240 rows=197 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.009 + -> Sort (cost=32534.94..32535.55 rows=245 width=185) (actual time=3391.847..3496.465 rows=406814 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 69497kB + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.009 + -> Nested Loop (cost=1006.06..32525.21 rows=245 width=185) (actual time=1.350..2775.860 rows=406814 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Buffers: shared hit=26345, local hit=813629 read=1 + I/O Timings: read=0.009 + -> Hash Left Join (cost=1005.91..31588.56 rows=738 width=113) (actual time=1.313..1179.345 rows=406814 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=26345, local hit=2 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=1.240..1046.018 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=26345 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.014..109.458 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared hit=26345 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.061..0.062 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.008..0.034 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=406814) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=813627 read=1 + I/O Timings: read=0.009 + -> GroupAggregate (cost=67318.31..67331.81 rows=257 width=232) (actual time=6073.565..6266.298 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=1989 read=56003, local hit=1255198 + I/O Timings: read=116.008 + -> Sort (cost=67318.31..67318.96 rows=257 width=178) (actual time=6073.544..6091.287 rows=94732 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16394kB + Buffers: shared hit=1989 read=56003, local hit=1255198 + I/O Timings: read=116.008 + -> Nested Loop (cost=1006.06..67308.03 rows=257 width=178) (actual time=2.958..5927.325 rows=94732 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=1989 read=56003, local hit=1255198 + I/O Timings: read=116.008 + -> Hash Left Join (cost=1005.91..65849.40 rows=1114 width=122) (actual time=2.927..3753.366 rows=628518 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=1989 read=56003, local hit=2 + I/O Timings: read=116.008 + -> Gather (cost=1000.00..65829.04 rows=1114 width=51) (actual time=2.864..3530.159 rows=628518 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=1989 read=56003 + I/O Timings: read=116.008 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..64717.64 rows=464 width=51) (actual time=0.049..218.145 rows=209506 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52157 + Buffers: shared hit=1989 read=56003 + I/O Timings: read=116.008 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.052..0.052 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.007..0.030 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=628518) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1255196 + -> HashAggregate (cost=25.10..27.60 rows=200 width=232) (actual time=10689.360..10689.485 rows=317 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=28334 read=56003, local hit=2068827 read=1 + I/O Timings: read=116.017 + -> CTE Scan on un (cost=0.00..10.04 rows=502 width=232) (actual time=3391.870..10681.897 rows=317 loops=1) + Buffers: shared hit=28334 read=56003, local hit=2068827 read=1 + I/O Timings: read=116.017 + +
+++ +Time consuming queries
++++ +
++ + + + +Rank +Total duration +Times executed +Min duration +Max duration +Avg duration +Query ++ + +1 +9m44s +3 + + +2m30s +4m7s +3m14s ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++ +++Times Reported Time consuming queries #1
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 15 00 1 4m7s 4m7s 14 1 2m30s 2m30s + +16 1 3m6s 3m6s ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 9m44s - Times executed: 3 ] +
+ +++ + + +-
+
+
[ Application: psql - Total duration: 9m44s - Times executed: 3 ] +
+ +++ +-
+
+
-
+ INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++
+
-
+ INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++
+
-
+ INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++
+
Date: 2019-03-15 00:53:37 +Duration: 4m7s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm_ppfa_varto_mv (cost=0.25..10.25 rows=1000 width=1520) (actual time=247216.314..247216.314 rows=0 loops=1) + Buffers: shared hit=1716294 read=197994 dirtied=106936 written=127, local hit=5658761 read=4 dirtied=2, temp read=384787 written=401694 + I/O Timings: read=8265.132 write=1.395 + -> Function Scan on osm_ppfa_varto (cost=0.25..10.25 rows=1000 width=1520) (actual time=209413.211..214181.385 rows=1377873 loops=1) + Buffers: shared hit=106558 read=91107 dirtied=50, local hit=5658761 read=4 dirtied=2, temp read=384787 written=401694 + I/O Timings: read=8253.083 + +
+Date: 2019-03-15 16:48:41 +Duration: 3m6s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm_ppfa_varto_mv (cost=0.25..10.25 rows=1000 width=1520) (actual time=186692.239..186692.239 rows=0 loops=1) + Buffers: shared hit=1652058 read=262701 dirtied=107023 written=340, local hit=5660301 read=4 dirtied=2, temp read=384981 written=401910 + I/O Timings: read=5890.327 write=3.241 + -> Function Scan on osm_ppfa_varto (cost=0.25..10.25 rows=1000 width=1520) (actual time=152354.359..164471.890 rows=1378962 loops=1) + Buffers: shared hit=40911 read=155742 dirtied=65, local hit=5660301 read=4 dirtied=2, temp read=384981 written=401910 + I/O Timings: read=5888.364 + +
+Date: 2019-03-15 14:09:42 +Duration: 2m30s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm_ppfa_varto_mv (cost=0.25..10.25 rows=1000 width=1520) (actual time=150711.860..150711.860 rows=0 loops=1) + Buffers: shared hit=1649817 read=264466 dirtied=106965 written=88, local hit=5659525 read=4 dirtied=2, temp read=384879 written=401797 + I/O Timings: read=5508.081 write=14.599 + -> Function Scan on osm_ppfa_varto (cost=0.25..10.25 rows=1000 width=1520) (actual time=127165.594..135951.084 rows=1378380 loops=1) + Buffers: shared hit=39318 read=157546 dirtied=46, local hit=5659525 read=4 dirtied=2, temp read=384879 written=401797 + I/O Timings: read=5507.907 + +
++ + +2 +7m50s +3 + + +2m2s +3m19s +2m36s ++ +pl / pgsql FUNCTION rlarp.osm_ppfa_varto () +line ? at RETURN querywith ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- seg AS ( SELECT x.glec ,x.segm FROM ( VALUES (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?) ) x(glec, segm) ) ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- ,mg AS ( SELECT x.f1, x.ming, x.grp FROM ( VALUES (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?) ) AS x (f1, ming, grp) ) ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- ,repc AS ( SELECT ltrim(rtrim(c.a9)) rcode ,ltrim(rtrim(c.a9)) || ? || c.a30 repp ,coalesce(q.dir,?) director FROM lgdat.code c LEFT OUTER JOIN rlarp.qrh q ON q.qr = ltrim(rtrim(c.a9)) WHERE c.a2 = ? ) --mold descriptions ,md AS ( SELECT u.mold ,max(u.descr) descr FROM ( SELECT substr(m.avpart,?,?) mold ,max(m.avdes1) descr FROM lgdat.stkmm m WHERE length(m.avpart) > ? AND substr(m.avgled,?,?) <= ? GROUP BY substr(m.avpart,?,?) UNION ALL SELECT substr(p.awpart,?,?) mold ,max(p.awdes1) descr FROM lgdat.stkmp p WHERE length(p.awpart) > ? AND substr(p.awgled,?,?) <= ? GROUP BY substr(p.awpart,?,?) ) u GROUP BY u.mold ) ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- ,sj AS ( SELECT * FROM lgdat.mmsl WHERE coalesce(bsmncd,?) = ? ) ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- ,si AS ( SELECT * FROM lgdat.mmsl WHERE coalesce(bsmncd,?) <> ? ) ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ ,seas AS( SELECT ssyr ,daterange(min(sdat),max(edat),?) dr ,current_date <@ daterange(min(sdat),max(edat),?) cy FROM gld GROUP BY ssyr ORDER BY ssyr DESC ) ,intv AS ( SELECT current_date - lower(dr) dy FROM seas WHERE cy = TRUE ) ,std AS ( SELECT s.ssyr ,s.dr ,s.cy ,daterange(lower(dr),dy + lower(dr),?) ytd FROM seas s CROSS JOIN intv ) ---------------------------------------union actual AND forecast--------------------------------------------------------------------------------------------------------------------------------------- ,un AS ( --plan SELECT ? AS version ,? iter ,od.ssyr oseas ,osm.adj_orderdate AS odate ,sd.ssyr sseas ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) sdate ,rd.ssyr rseas ,osm.adj_requestdate rdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,coalesce(rd.cy,?) ry ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) part_descr ,f.f3||?||f.descr part_family ,substr(osm.part,?,?)||?||md.descr part_group ,coalesce(mg.grp,?) branding ,coalesce(seg.segm,?) segm ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END calc_status ,osm.c_rate ,sum( osm.fb_qty ) qty ,sum( osm.fb_val_loc * osm.r_rate) sales ,sum( osm.fb_cst_loc * osm.c_rate) stdcost ,sum( osm.fb_cst_loc_cur * osm.c_rate) stdcost_cur ,sum( osm.fb_qty * coalesce(m.avnwht,p.awnwht) * CASE coalesce(m.avnwun, p.awnwun) WHEN ? THEN ?.? ELSE ? END) pounds FROM rlarp.osmp osm LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr LEFT OUTER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld rd ON osm.adj_requestdate BETWEEN rd.sdat AND rd.edat LEFT OUTER JOIN seg ON seg.glec = osm.glec --and seg.segm <> ? LEFT OUTER JOIN mg ON mg.f1 = substr(osm.part,?,?) AND mg.ming = osm.ming LEFT OUTER JOIN rlarp.family f ON f.f3 = substr(osm.part,?,?) LEFT OUTER JOIN lgdat.stkmm m ON m.avpart = osm.part LEFT OUTER JOIN lgdat.stkmp p ON p.awpart = osm.part LEFT OUTER JOIN md ON md.mold = substr(osm.part,?,?) LEFT OUTER JOIN rlarp.ffchnl l ON l.bill = osm.bill_class AND l.ship = osm.ship_class WHERE osm.fs_line = ? AND osm.calc_status <> ? AND substr(osm.glec,?,?) <= ? AND osm.version = ? AND ( osm.fspr >= ? OR osm.adj_orderdate >= ? ) GROUP BY --version --iter od.ssyr ,osm.adj_orderdate ,sd.ssyr ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) ,rd.ssyr ,osm.adj_requestdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ,coalesce(rd.cy,?) ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) ,f.f3||?||f.descr ,substr(osm.part,?,?)||?||md.descr ,coalesce(mg.grp,?) ,coalesce(seg.segm,?) ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END ,osm.c_rate UNION ALL --staged forecast SELECT ? AS version ,? iter ,od.ssyr oseas ,osm.adj_orderdate odate ,sd.ssyr sseas ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) sdate ,rd.ssyr rseas ,osm.adj_requestdate rdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,coalesce(rd.cy,?) ry ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) part_descr ,f.f3||?||f.descr part_family ,substr(osm.part,?,?)||?||md.descr part_group ,coalesce(mg.grp,?) branding ,coalesce(seg.segm,?) segm ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END calc_status ,osm.c_rate ,sum( osm.fb_qty ) qty ,sum( osm.fb_val_loc * osm.r_rate) sales ,sum( osm.fb_cst_loc * osm.c_rate) stdcost ,sum( osm.fb_cst_loc_cur * osm.c_rate) stdcost_cur ,sum( osm.fb_qty * coalesce(m.avnwht,p.awnwht) * CASE coalesce(m.avnwun, p.awnwun) WHEN ? THEN ?.? ELSE ? END) pounds FROM rlarp.osmf osm LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr LEFT OUTER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld rd ON osm.adj_requestdate BETWEEN rd.sdat AND rd.edat LEFT OUTER JOIN seg ON seg.glec = osm.glec --and seg.segm <> ? LEFT OUTER JOIN mg ON mg.f1 = substr(osm.part,?,?) AND mg.ming = osm.ming LEFT OUTER JOIN rlarp.family f ON f.f3 = substr(osm.part,?,?) LEFT OUTER JOIN lgdat.stkmm m ON m.avpart = osm.part LEFT OUTER JOIN lgdat.stkmp p ON p.awpart = osm.part LEFT OUTER JOIN md ON md.mold = substr(osm.part,?,?) LEFT OUTER JOIN rlarp.ffchnl l ON l.bill = osm.bill_class AND l.ship = osm.ship_class WHERE osm.fs_line = ? AND osm.calc_status <> ? AND substr(osm.glec,?,?) <= ? AND osm.version = ? AND ( osm.fspr >= ? OR osm.adj_orderdate >= ? ) GROUP BY --version --iter od.ssyr ,osm.adj_orderdate ,sd.ssyr ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) ,rd.ssyr ,osm.adj_requestdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ,coalesce(rd.cy,?) ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) ,f.f3||?||f.descr ,substr(osm.part,?,?)||?||md.descr ,coalesce(mg.grp,?) ,coalesce(seg.segm,?) ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END ,osm.c_rate UNION ALL --actual SELECT ? AS version ,? iter ,od.ssyr oseas ,osm.adj_orderdate odate ,sd.ssyr sseas ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) sdate ,rd.ssyr rseas ,osm.adj_requestdate rdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,coalesce(rd.cy,?) ry ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) part_descr ,f.f3||?||f.descr part_family ,substr(osm.part,?,?)||?||md.descr part_group ,coalesce(mg.grp,?) branding ,coalesce(seg.segm,?) segm ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END calc_status ,osm.c_rate ,sum( osm.fb_qty ) qty ,sum( osm.fb_val_loc * osm.r_rate) sales ,sum( osm.fb_cst_loc * osm.c_rate) stdcost ,sum( osm.fb_cst_loc_cur * osm.c_rate) stdcost_cur ,sum( osm.fb_qty * coalesce(m.avnwht,p.awnwht) * CASE coalesce(m.avnwun, p.awnwun) WHEN ? THEN ?.? ELSE ? END) pounds FROM rlarp.osm osm LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr LEFT OUTER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld rd ON osm.adj_requestdate BETWEEN rd.sdat AND rd.edat LEFT OUTER JOIN seg ON seg.glec = osm.glec --and seg.segm <> ? LEFT OUTER JOIN mg ON mg.f1 = substr(osm.part,?,?) AND mg.ming = osm.ming LEFT OUTER JOIN rlarp.family f ON f.f3 = substr(osm.part,?,?) LEFT OUTER JOIN lgdat.stkmm m ON m.avpart = osm.part LEFT OUTER JOIN lgdat.stkmp p ON p.awpart = osm.part LEFT OUTER JOIN md ON md.mold = substr(osm.part,?,?) LEFT OUTER JOIN rlarp.ffchnl l ON l.bill = osm.bill_class AND l.ship = osm.ship_class WHERE osm.fs_line = ? --and substr(osm.glec,?,?) <= ? AND osm.calc_status <> ? AND ( osm.fspr >= ? OR osm.adj_orderdate >= ? ) GROUP BY --version od.ssyr ,osm.adj_orderdate ,sd.ssyr ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) ,rd.ssyr ,osm.adj_requestdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ,coalesce(rd.cy,?) ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) ,f.f3||?||f.descr ,substr(osm.part,?,?)||?||md.descr ,coalesce(mg.grp,?) ,coalesce(seg.segm,?) ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END ,osm.c_rate ) ---------------------------------------aggregate actual AND forecast----------------------------------------------------------------------------------------------------------------------------------- ,agg AS ( SELECT un.version::text "version" ,un.iter::text "iter" ,un.oseas::numeric oseas ,un.odate::date odate ,un.sseas::numeric sseas ,un.sdate::date sdate ,un.rseas::numeric rseas ,un.rdate::date rdate ,un.om::text om ,un.sm::text sm ,un.rm::text rm ,un.oy::text oy ,(un.odate <@ _ytd)::boolean ocytd --current year TO date ,(un.odate <@ so.ytd)::boolean oytd --year TO date recast FOR prior/forecast periods ,un.sy::text sy ,(un.sdate <@ _ytd)::boolean scytd ,(un.sdate <@ ss.ytd)::boolean sytd --had this ORDER been placed yet? (current day prior year IS greater than the ORDER date) ,case WHEN (upper(so.ytd) - interval ?) >= un.odate THEN --was the ORDER OPEN at this time LAST year? (FOR orders that were placed BY this time, was the ship date greater THEN the ORDER date) CASE WHEN ((un.sdate > (upper(so.ytd) - interval ?)) OR (un.sy = ?)) --for orders that were placed AND OPEN at this time LAST year, was the ORDER considered past due? (current date prior year > request date) THEN CASE WHEN (upper(so.ytd) - interval ?) > un.rdate THEN ? ELSE ? END ELSE ? END ELSE ? END status_py ,un.ry::text ry ,un.plnt::text plnt ,un.account::text bill_group ,(un.bill_cust || ? || rtrim(bc.bvname))::text bill_cust ,bc.bvctry bill_ctry ,bc.bvprcd bill_prov ,un.shipgrp::text ship_group ,(un.ship_cust || ? || rtrim(sc.bvname))::text ship_cust ,sc.bvctry ship_ctry ,sc.bvprcd ship_prov ,un.chan::text chan ,case un.segm WHEN ? THEN un.retail ELSE un.chan END::text mod_chan ,case un.segm WHEN ? THEN un.retailsub ELSE ? END::text mod_chansub ,un.promo::text promo ,un.majg||coalesce(?||bqdes,?)::text majg ,un.ming||coalesce(?||brdes,?)::text ming ,un.majs||coalesce(?||sj.bsdes1,?)::text majs ,un.mins||coalesce(?||si.bsdes1,?)::text mins ,un.part::text part ,un.part_descr::text part_descr ,un.part_family::text part_family ,un.part_group::text part_group ,un.branding::text branding ,un.segm::text segm ,coalesce(repc.repp,un.quota_rep)::text quota_rep ,coalesce(repc.director,un.quota_rep)::text director ,sum(un.qty)::numeric qty ,sum(un.sales)::numeric sales ,sum(un.stdcost)::numeric stdcost ,sum(un.qty * coalesce(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur ,sum(un.pounds)::numeric pounds ,(un.version||?||un.sy)::text flag_s ,(un.version||?||un.oy)::text flag_o ,case WHEN un.calc_status IN (...) THEN CASE WHEN un.rdate < current_date THEN ? ELSE ? END ELSE un.calc_status END::text status ,(substr(un.part,?,?)||?||un.branding)::text "options" ,?::text grandtotal FROM un LEFT OUTER JOIN repc ON repc.rcode = un.quota_rep LEFT OUTER JOIN si ON si.bsmjcd = un.majs AND si.bsmncd = un.mins LEFT OUTER JOIN sj ON sj.bsmjcd = un.majs LEFT OUTER JOIN lgdat.majg ON bqgrp = un.majg LEFT OUTER JOIN lgdat.mmgp ON brmgrp = un.ming AND brgrp = un.majg LEFT OUTER JOIN lgdat.cust bc ON bc.bvcust = un.bill_cust LEFT OUTER JOIN lgdat.cust sc ON sc.bvcust = un.bill_cust LEFT OUTER JOIN lgdat.icstm cm ON cm.cgpart = un.part AND cm.cgplnt = un.plnt LEFT OUTER JOIN lgdat.icstp cp ON cp.chpart = un.part AND cp.chplnt = un.plnt LEFT OUTER JOIN lgdat.icstr cr ON cr.y0part = un.part AND cr.y0plnt = un.plnt LEFT OUTER JOIN std so ON so.ssyr = un.oseas LEFT OUTER JOIN std ss ON ss.ssyr = un.sseas GROUP BY un.version::text ,un.iter::text ,un.oseas::numeric ,un.odate::date ,un.sseas::numeric ,un.sdate::date ,un.rseas::numeric ,un.rdate::date ,un.om::text ,un.sm::text ,un.rm::text ,un.oy::text --current year TO date ,(un.odate <@ _ytd)::boolean --year TO date recast FOR prior/forecast periods ,(un.odate <@ so.ytd)::boolean ,un.sy::text ,(un.sdate <@ _ytd)::boolean ,(un.sdate <@ ss.ytd)::boolean ,case WHEN (upper(so.ytd) - interval ?) >= un.odate THEN --was the ORDER OPEN at this time LAST year? (FOR orders that were placed BY this time, was the ship date greater THEN the ORDER date) CASE WHEN ((un.sdate > (upper(so.ytd) - interval ?)) OR (un.sy = ?)) --for orders that were placed AND OPEN at this time LAST year, was the ORDER considered past due? (current date prior year > request date) THEN CASE WHEN (upper(so.ytd) - interval ?) > un.rdate THEN ? ELSE ? END ELSE ? END ELSE ? END ,un.ry::text ,un.plnt::text ,un.account::text ,(un.bill_cust || ? || rtrim(bc.bvname))::text ,bc.bvctry ,bc.bvprcd ,un.shipgrp::text ,(un.ship_cust || ? || rtrim(sc.bvname))::text ,sc.bvctry ,sc.bvprcd ,un.chan::text ,case un.segm WHEN ? THEN un.retail ELSE un.chan END::text ,case un.segm WHEN ? THEN un.retailsub ELSE ? END::text ,un.promo::text ,un.majg||coalesce(?||bqdes,?)::text ,un.ming||coalesce(?||brdes,?)::text ,un.majs||coalesce(?||sj.bsdes1,?)::text ,un.mins||coalesce(?||si.bsdes1,?)::text ,un.part::text ,un.part_descr::text ,un.part_family::text ,un.part_group::text ,un.branding::text ,un.segm::text ,coalesce(repc.repp,un.quota_rep)::text ,coalesce(repc.director,un.quota_rep)::text ,(un.version||?||un.sy)::text ,(un.version||?||un.oy)::text ,case WHEN un.calc_status IN (...) THEN CASE WHEN un.rdate < current_date THEN ? ELSE ? END ELSE un.calc_status END::text ,(substr(un.part,?,?)||?||un.branding)::text ,?::text ) SELECT a.version ,a.iter ,a.oseas ,a.odate ,a.sseas ,a.sdate ,a.rseas ,a.rdate ,a.om ,a.sm ,a.rm ,a.oy ,a.ocytd ,a.oytd ,a.sy ,a.scytd ,a.sytd ,a.status_py ,a.ry ,a.plnt ,a.bill_group ,a.bill_cust ,a.bill_ctry ,a.bill_prov ,a.ship_group ,a.ship_cust ,a.ship_ctry ,a.ship_prov ,a.chan ,a.mod_chan ,a.mod_chansub ,a.promo ,a.majg ,a.ming ,a.majs ,a.mins ,a.part ,a.part_descr ,a.part_family ,a.part_group ,a.branding ,a.segm ,a.quota_rep ,a.director ,a.qty ,a.sales ,a.stdcost ,a.stdcost_cur ,a.pounds ,a.flag_s ,a.flag_o ,a.status ,a.options ,a.grandtotal FROM agg a UNION ALL SELECT ? AS version ,? AS iter ,a.oseas ,a.odate ,a.sseas ,a.sdate ,a.rseas ,a.rdate ,a.om ,a.sm ,a.rm ,a.oy ,a.ocytd ,a.oytd ,a.sy ,a.scytd ,a.sytd ,a.status_py ,a.ry ,a.plnt ,a.bill_group ,a.bill_cust ,a.bill_ctry ,a.bill_prov ,a.ship_group ,a.ship_cust ,a.ship_ctry ,a.ship_prov ,a.chan ,a.mod_chan ,a.mod_chansub ,a.promo ,a.majg ,a.ming ,a.majs ,a.mins ,a.part ,a.part_descr ,a.part_family ,a.part_group ,a.branding ,a.segm ,a.quota_rep ,a.director ,case a.version WHEN ? THEN a.qty ELSE -a.qty END::numeric qty ,case a.version WHEN ? THEN a.sales ELSE -a.sales END::numeric sales ,case a.version WHEN ? THEN a.stdcost ELSE -a.stdcost END::numeric stdcost ,case a.version WHEN ? THEN a.stdcost_cur ELSE -a.stdcost_cur END::numeric stdcost_cur ,case a.version WHEN ? THEN a.pounds ELSE -a.pounds END::numeric pounds ,?||?||a.scytd flag_s ,?||?||a.ocytd flag_o ,a.status ,a.options ,a.grandtotal FROM agg a WHERE a.version IN (...) AND (a.ocytd OR a.scytd) UNION ALL SELECT ? AS version ,? AS iter ,a.oseas ,a.odate ,a.sseas ,a.sdate ,a.rseas ,a.rdate ,a.om ,a.sm ,a.rm ,a.oy ,a.ocytd ,a.oytd ,a.sy ,a.scytd ,a.sytd ,a.status_py ,a.ry ,a.plnt ,a.bill_group ,a.bill_cust ,a.bill_ctry ,a.bill_prov ,a.ship_group ,a.ship_cust ,a.ship_ctry ,a.ship_prov ,a.chan ,a.mod_chan ,a.mod_chansub ,a.promo ,a.majg ,a.ming ,a.majs ,a.mins ,a.part ,a.part_descr ,a.part_family ,a.part_group ,a.branding ,a.segm ,a.quota_rep ,a.director ,case a.version WHEN ? THEN a.qty ELSE -a.qty END::numeric qty ,case a.version WHEN ? THEN a.sales ELSE -a.sales END::numeric sales ,case a.version WHEN ? THEN a.stdcost ELSE -a.stdcost END::numeric stdcost ,case a.version WHEN ? THEN a.stdcost_cur ELSE -a.stdcost_cur END::numeric stdcost_cur ,case a.version WHEN ? THEN a.pounds ELSE -a.pounds END::numeric pounds ,?||?||a.scytd flag_s ,?||?||a.ocytd flag_o ,a.status ,a.options ,a.grandtotal FROM agg a WHERE a.version IN (...) AND (a.ocytd OR a.scytd) ; ++ +++Times Reported Time consuming queries #2
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 15 00 1 3m19s 3m19s 14 1 2m2s 2m2s + +16 1 2m28s 2m28s ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 7m50s - Times executed: 3 ] +
+ +++ + + +-
+
+
[ Application: psql - Total duration: 7m50s - Times executed: 3 ] +
+ +++ +-
+
+
-
+ PL/pgSQL function rlarp.osm_ppfa_varto() line 69 at RETURN QUERYWITH + ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- + SEG AS ( + SELECT + x.GLEC + ,x.SEGM + FROM + ( + VALUES + ('1CU','Retail'), + ('1GR','Greenhouse'), + ('1NU','Nursery'), + ('1RE','Retail'), + ('2WI','Greenhouse'), + ('3BM','Other'), + ('3CO','Other'), + ('3PE','Other'), + ('3PP','Other'), + ('4CO','Other'), + ('4RA','Other'), + ('9MI','Other'), + ('9SA','Other'), + ('9TO','Other') + ) X(GLEC, SEGM) + ) + ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- + ,MG AS ( + SELECT + X.F1, X.MING, X.GRP + FROM + ( + VALUES + ('L','000','Branded'), + ('L','B10','Branded'), + ('L','B11','Branded'), + ('L','B52','Branded'), + ('L','C10','Branded'), + ('L','D12','Branded'), + ('L','M11','Branded'), + ('L','P12','Branded'), + ('L','P13','Branded'), + ('L','S10','Branded'), + ('L','Y10','Branded'), + ('L','Y11','Branded'), + ('L','Y12','Branded'), + ('P','B10','Branded'), + ('P','B11','Branded'), + ('P','B52','Branded') + ) AS X (F1, MING, GRP) + ) + ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- + ,REPC AS ( + SELECT + LTRIM(RTRIM(C.A9)) RCODE + ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP + ,COALESCE(Q.DIR,'Other') DIRECTOR + FROM + LGDAT.CODE C + LEFT OUTER JOIN RLARP.QRH Q ON + Q.QR = LTRIM(RTRIM(C.A9)) + WHERE + C.A2 = 'MM' + ) + --MOLD DESCRIPTIONS + ,MD AS ( + SELECT + U.MOLD + ,MAX(U.DESCR) DESCR + FROM + ( + SELECT + SUBSTR(M.AVPART,1,8) MOLD + ,MAX(M.AVDES1) DESCR + FROM + LGDAT.STKMM M + WHERE + LENGTH(M.AVPART) > 8 + AND SUBSTR(M.AVGLED,1,1) <= '2' + GROUP BY + SUBSTR(M.AVPART,1,8) + UNION ALL + SELECT + SUBSTR(P.AWPART,1,8) MOLD + ,MAX(P.AWDES1) DESCR + FROM + LGDAT.STKMP P + WHERE + LENGTH(P.AWPART) > 8 + AND SUBSTR(P.AWGLED,1,1) <= '2' + GROUP BY + SUBSTR(P.AWPART,1,8) + ) U + GROUP BY + U.MOLD + ) + ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- + ,SJ AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = '' + ) + ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- + ,SI AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> '' + ) + ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ + ,seas AS( + SELECT + ssyr + ,daterange(MIN(sdat),MAX(edat),'[]') dr + ,current_date <@ daterange(MIN(sdat),MAX(edat),'[]') cy + FROM + gld + GROUP BY + ssyr + ORDER BY + ssyr DESC + ) + ,intv AS ( + SELECT current_date - lower(dr) dy from seas where cy = true + ) + ,std AS ( + SELECT + s.ssyr + ,s.dr + ,s.cy + ,daterange(lower(dr),dy + LOWER(dr),'[]') ytd + FROM + seas s + CROSS JOIN intv + ) + ---------------------------------------union actual and forecast--------------------------------------------------------------------------------------------------------------------------------------- + ,UN AS ( + --plan + SELECT + 'Budget' AS VERSION + ,'Budget' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE as ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(m.avNWHT,p.awNWHT) * CASE COALESCE(m.avNWUN, p.awNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMP OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = 'b19' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --staged forecast + SELECT + 'Forecast' AS VERSION + ,'Forecast' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMF OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = '5p7' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --actual + SELECT + 'Actual' AS VERSION + ,'Actual' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSM OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + --AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.CALC_STATUS <> 'CANCELED' + AND + ( + OSM.FSPR >= '1606' + OR OSM.ADJ_ORDERDATE >= '2016-06-01' + ) + GROUP BY + --VERSION + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + ) + ---------------------------------------aggregate actual and forecast----------------------------------------------------------------------------------------------------------------------------------- + ,AGG AS ( + SELECT + un.VERSION::text "version" + ,un.ITER::text "iter" + ,un.OSEAS::numeric oseas + ,un.ODATE::date odate + ,un.SSEAS::numeric sseas + ,un.SDATE::date sdate + ,un.RSEAS::numeric rseas + ,un.RDATE::date rdate + ,un.OM::text om + ,un.SM::text sm + ,un.RM::text rm + ,un.OY::text oy + ,(un.odate <@ _ytd)::boolean ocytd --current year to date + ,(un.odate <@ so.ytd)::boolean oytd --year to date recast for prior/forecast periods + ,un.SY::text sy + ,(un.sdate <@ _ytd)::boolean scytd + ,(un.sdate <@ ss.ytd)::boolean sytd + --had this order been placed yet? (current day prior year is greater than the order date) + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END status_py + ,un.RY::text ry + ,un.PLNT::text plnt + ,un.ACCOUNT::text bill_group + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text bill_cust + ,bc.bvctry bill_ctry + ,bc.bvprcd bill_prov + ,un.SHIPGRP::text ship_group + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text ship_cust + ,sc.bvctry ship_ctry + ,sc.bvprcd ship_prov + ,un.CHAN::text chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text mod_chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text mod_chansub + ,un.PROMO::text promo + ,un.MAJG||COALESCE(' - '||BQDES,'')::text majg + ,un.MING||COALESCE(' - '||BRDES,'')::text ming + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text majs + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text mins + ,un.PART::text part + ,un.PART_DESCR::text part_descr + ,un.PART_FAMILY::text part_family + ,un.PART_GROUP::text part_group + ,un.BRANDING::text branding + ,un.SEGM::text segm + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text quota_rep + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text director + ,SUM(un.QTY)::numeric qty + ,SUM(un.SALES)::numeric sales + ,SUM(un.STDCOST)::numeric stdcost + ,SUM(un.QTY * COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur + ,SUM(un.POUNDS)::numeric pounds + ,(un.VERSION||'-'||un.SY)::text flag_s + ,(un.VERSION||'-'||un.OY)::text flag_o + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text status + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text "options" + ,'Grand Total'::text grandtotal + FROM + UN + LEFT OUTER JOIN REPC ON + REPC.RCODE = un.QUOTA_REP + LEFT OUTER JOIN SI ON + SI.BSMJCD = UN.MAJS + AND SI.BSMNCD = UN.MINS + LEFT OUTER JOIN SJ ON + SJ.BSMJCD = UN.MAJS + LEFT OUTER JOIN LGDAT.MAJG ON + BQGRP = un.MAJG + LEFT OUTER JOIN LGDAT.MMGP ON + BRMGRP = un.MING + AND BRGRP = un.MAJG + LEFT OUTER JOIN LGDAT.CUST BC ON + BC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.CUST SC ON + SC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.ICSTM cm ON + cm.cgpart = un.part + AND cm.cgplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTP cp ON + cp.chpart = un.part + AND cp.chplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTR cr ON + cr.y0part = un.part + AND cr.y0plnt = un.plnt + LEFT OUTER JOIN STD so ON + so.ssyr = un.oseas + LEFT OUTER JOIN STD ss ON + ss.ssyr = un.sseas + GROUP BY + un.VERSION::text + ,un.ITER::text + ,un.OSEAS::numeric + ,un.ODATE::date + ,un.SSEAS::numeric + ,un.SDATE::date + ,un.RSEAS::numeric + ,un.RDATE::date + ,un.OM::text + ,un.SM::text + ,un.RM::text + ,un.OY::text + --current year to date + ,(un.odate <@ _ytd)::boolean + --year to date recast for prior/forecast periods + ,(un.odate <@ so.ytd)::boolean + ,un.SY::text + ,(un.sdate <@ _ytd)::boolean + ,(un.sdate <@ ss.ytd)::boolean + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END + ,un.RY::text + ,un.PLNT::text + ,un.ACCOUNT::text + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text + ,bc.bvctry + ,bc.bvprcd + ,un.SHIPGRP::text + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text + ,sc.bvctry + ,sc.bvprcd + ,un.CHAN::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text + ,un.PROMO::text + ,un.MAJG||COALESCE(' - '||BQDES,'')::text + ,un.MING||COALESCE(' - '||BRDES,'')::text + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text + ,un.PART::text + ,un.PART_DESCR::text + ,un.PART_FAMILY::text + ,un.PART_GROUP::text + ,un.BRANDING::text + ,un.SEGM::text + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text + ,(un.VERSION||'-'||un.SY)::text + ,(un.VERSION||'-'||un.OY)::text + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text + ,'Grand Total'::text + ) + SELECT + a.version + ,a.iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,a.qty + ,a.sales + ,a.stdcost + ,a.stdcost_cur + ,a.pounds + ,a.flag_s + ,a.flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + agg a + UNION ALL + SELECT + 'Var to Fcst' as version + ,'Var to Fcst' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Fcst'||'-'||a.scytd flag_s + ,'Var to Fcst'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Forecast') + AND (a.ocytd OR a.scytd) + + UNION ALL + SELECT + 'Var to Bdgt' as version + ,'Var to Bdgt' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Bdgt'||'-'||a.scytd flag_s + ,'Var to Bdgt'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Budget') + AND (a.ocytd OR a.scytd) +;+
+
-
+ PL/pgSQL function rlarp.osm_ppfa_varto() line 69 at RETURN QUERYWITH + ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- + SEG AS ( + SELECT + x.GLEC + ,x.SEGM + FROM + ( + VALUES + ('1CU','Retail'), + ('1GR','Greenhouse'), + ('1NU','Nursery'), + ('1RE','Retail'), + ('2WI','Greenhouse'), + ('3BM','Other'), + ('3CO','Other'), + ('3PE','Other'), + ('3PP','Other'), + ('4CO','Other'), + ('4RA','Other'), + ('9MI','Other'), + ('9SA','Other'), + ('9TO','Other') + ) X(GLEC, SEGM) + ) + ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- + ,MG AS ( + SELECT + X.F1, X.MING, X.GRP + FROM + ( + VALUES + ('L','000','Branded'), + ('L','B10','Branded'), + ('L','B11','Branded'), + ('L','B52','Branded'), + ('L','C10','Branded'), + ('L','D12','Branded'), + ('L','M11','Branded'), + ('L','P12','Branded'), + ('L','P13','Branded'), + ('L','S10','Branded'), + ('L','Y10','Branded'), + ('L','Y11','Branded'), + ('L','Y12','Branded'), + ('P','B10','Branded'), + ('P','B11','Branded'), + ('P','B52','Branded') + ) AS X (F1, MING, GRP) + ) + ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- + ,REPC AS ( + SELECT + LTRIM(RTRIM(C.A9)) RCODE + ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP + ,COALESCE(Q.DIR,'Other') DIRECTOR + FROM + LGDAT.CODE C + LEFT OUTER JOIN RLARP.QRH Q ON + Q.QR = LTRIM(RTRIM(C.A9)) + WHERE + C.A2 = 'MM' + ) + --MOLD DESCRIPTIONS + ,MD AS ( + SELECT + U.MOLD + ,MAX(U.DESCR) DESCR + FROM + ( + SELECT + SUBSTR(M.AVPART,1,8) MOLD + ,MAX(M.AVDES1) DESCR + FROM + LGDAT.STKMM M + WHERE + LENGTH(M.AVPART) > 8 + AND SUBSTR(M.AVGLED,1,1) <= '2' + GROUP BY + SUBSTR(M.AVPART,1,8) + UNION ALL + SELECT + SUBSTR(P.AWPART,1,8) MOLD + ,MAX(P.AWDES1) DESCR + FROM + LGDAT.STKMP P + WHERE + LENGTH(P.AWPART) > 8 + AND SUBSTR(P.AWGLED,1,1) <= '2' + GROUP BY + SUBSTR(P.AWPART,1,8) + ) U + GROUP BY + U.MOLD + ) + ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- + ,SJ AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = '' + ) + ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- + ,SI AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> '' + ) + ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ + ,seas AS( + SELECT + ssyr + ,daterange(MIN(sdat),MAX(edat),'[]') dr + ,current_date <@ daterange(MIN(sdat),MAX(edat),'[]') cy + FROM + gld + GROUP BY + ssyr + ORDER BY + ssyr DESC + ) + ,intv AS ( + SELECT current_date - lower(dr) dy from seas where cy = true + ) + ,std AS ( + SELECT + s.ssyr + ,s.dr + ,s.cy + ,daterange(lower(dr),dy + LOWER(dr),'[]') ytd + FROM + seas s + CROSS JOIN intv + ) + ---------------------------------------union actual and forecast--------------------------------------------------------------------------------------------------------------------------------------- + ,UN AS ( + --plan + SELECT + 'Budget' AS VERSION + ,'Budget' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE as ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(m.avNWHT,p.awNWHT) * CASE COALESCE(m.avNWUN, p.awNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMP OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = 'b19' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --staged forecast + SELECT + 'Forecast' AS VERSION + ,'Forecast' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMF OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = '5p7' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --actual + SELECT + 'Actual' AS VERSION + ,'Actual' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSM OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + --AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.CALC_STATUS <> 'CANCELED' + AND + ( + OSM.FSPR >= '1606' + OR OSM.ADJ_ORDERDATE >= '2016-06-01' + ) + GROUP BY + --VERSION + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + ) + ---------------------------------------aggregate actual and forecast----------------------------------------------------------------------------------------------------------------------------------- + ,AGG AS ( + SELECT + un.VERSION::text "version" + ,un.ITER::text "iter" + ,un.OSEAS::numeric oseas + ,un.ODATE::date odate + ,un.SSEAS::numeric sseas + ,un.SDATE::date sdate + ,un.RSEAS::numeric rseas + ,un.RDATE::date rdate + ,un.OM::text om + ,un.SM::text sm + ,un.RM::text rm + ,un.OY::text oy + ,(un.odate <@ _ytd)::boolean ocytd --current year to date + ,(un.odate <@ so.ytd)::boolean oytd --year to date recast for prior/forecast periods + ,un.SY::text sy + ,(un.sdate <@ _ytd)::boolean scytd + ,(un.sdate <@ ss.ytd)::boolean sytd + --had this order been placed yet? (current day prior year is greater than the order date) + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END status_py + ,un.RY::text ry + ,un.PLNT::text plnt + ,un.ACCOUNT::text bill_group + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text bill_cust + ,bc.bvctry bill_ctry + ,bc.bvprcd bill_prov + ,un.SHIPGRP::text ship_group + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text ship_cust + ,sc.bvctry ship_ctry + ,sc.bvprcd ship_prov + ,un.CHAN::text chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text mod_chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text mod_chansub + ,un.PROMO::text promo + ,un.MAJG||COALESCE(' - '||BQDES,'')::text majg + ,un.MING||COALESCE(' - '||BRDES,'')::text ming + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text majs + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text mins + ,un.PART::text part + ,un.PART_DESCR::text part_descr + ,un.PART_FAMILY::text part_family + ,un.PART_GROUP::text part_group + ,un.BRANDING::text branding + ,un.SEGM::text segm + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text quota_rep + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text director + ,SUM(un.QTY)::numeric qty + ,SUM(un.SALES)::numeric sales + ,SUM(un.STDCOST)::numeric stdcost + ,SUM(un.QTY * COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur + ,SUM(un.POUNDS)::numeric pounds + ,(un.VERSION||'-'||un.SY)::text flag_s + ,(un.VERSION||'-'||un.OY)::text flag_o + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text status + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text "options" + ,'Grand Total'::text grandtotal + FROM + UN + LEFT OUTER JOIN REPC ON + REPC.RCODE = un.QUOTA_REP + LEFT OUTER JOIN SI ON + SI.BSMJCD = UN.MAJS + AND SI.BSMNCD = UN.MINS + LEFT OUTER JOIN SJ ON + SJ.BSMJCD = UN.MAJS + LEFT OUTER JOIN LGDAT.MAJG ON + BQGRP = un.MAJG + LEFT OUTER JOIN LGDAT.MMGP ON + BRMGRP = un.MING + AND BRGRP = un.MAJG + LEFT OUTER JOIN LGDAT.CUST BC ON + BC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.CUST SC ON + SC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.ICSTM cm ON + cm.cgpart = un.part + AND cm.cgplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTP cp ON + cp.chpart = un.part + AND cp.chplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTR cr ON + cr.y0part = un.part + AND cr.y0plnt = un.plnt + LEFT OUTER JOIN STD so ON + so.ssyr = un.oseas + LEFT OUTER JOIN STD ss ON + ss.ssyr = un.sseas + GROUP BY + un.VERSION::text + ,un.ITER::text + ,un.OSEAS::numeric + ,un.ODATE::date + ,un.SSEAS::numeric + ,un.SDATE::date + ,un.RSEAS::numeric + ,un.RDATE::date + ,un.OM::text + ,un.SM::text + ,un.RM::text + ,un.OY::text + --current year to date + ,(un.odate <@ _ytd)::boolean + --year to date recast for prior/forecast periods + ,(un.odate <@ so.ytd)::boolean + ,un.SY::text + ,(un.sdate <@ _ytd)::boolean + ,(un.sdate <@ ss.ytd)::boolean + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END + ,un.RY::text + ,un.PLNT::text + ,un.ACCOUNT::text + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text + ,bc.bvctry + ,bc.bvprcd + ,un.SHIPGRP::text + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text + ,sc.bvctry + ,sc.bvprcd + ,un.CHAN::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text + ,un.PROMO::text + ,un.MAJG||COALESCE(' - '||BQDES,'')::text + ,un.MING||COALESCE(' - '||BRDES,'')::text + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text + ,un.PART::text + ,un.PART_DESCR::text + ,un.PART_FAMILY::text + ,un.PART_GROUP::text + ,un.BRANDING::text + ,un.SEGM::text + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text + ,(un.VERSION||'-'||un.SY)::text + ,(un.VERSION||'-'||un.OY)::text + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text + ,'Grand Total'::text + ) + SELECT + a.version + ,a.iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,a.qty + ,a.sales + ,a.stdcost + ,a.stdcost_cur + ,a.pounds + ,a.flag_s + ,a.flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + agg a + UNION ALL + SELECT + 'Var to Fcst' as version + ,'Var to Fcst' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Fcst'||'-'||a.scytd flag_s + ,'Var to Fcst'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Forecast') + AND (a.ocytd OR a.scytd) + + UNION ALL + SELECT + 'Var to Bdgt' as version + ,'Var to Bdgt' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Bdgt'||'-'||a.scytd flag_s + ,'Var to Bdgt'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Budget') + AND (a.ocytd OR a.scytd) +;+
+
-
+ PL/pgSQL function rlarp.osm_ppfa_varto() line 69 at RETURN QUERYWITH + ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- + SEG AS ( + SELECT + x.GLEC + ,x.SEGM + FROM + ( + VALUES + ('1CU','Retail'), + ('1GR','Greenhouse'), + ('1NU','Nursery'), + ('1RE','Retail'), + ('2WI','Greenhouse'), + ('3BM','Other'), + ('3CO','Other'), + ('3PE','Other'), + ('3PP','Other'), + ('4CO','Other'), + ('4RA','Other'), + ('9MI','Other'), + ('9SA','Other'), + ('9TO','Other') + ) X(GLEC, SEGM) + ) + ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- + ,MG AS ( + SELECT + X.F1, X.MING, X.GRP + FROM + ( + VALUES + ('L','000','Branded'), + ('L','B10','Branded'), + ('L','B11','Branded'), + ('L','B52','Branded'), + ('L','C10','Branded'), + ('L','D12','Branded'), + ('L','M11','Branded'), + ('L','P12','Branded'), + ('L','P13','Branded'), + ('L','S10','Branded'), + ('L','Y10','Branded'), + ('L','Y11','Branded'), + ('L','Y12','Branded'), + ('P','B10','Branded'), + ('P','B11','Branded'), + ('P','B52','Branded') + ) AS X (F1, MING, GRP) + ) + ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- + ,REPC AS ( + SELECT + LTRIM(RTRIM(C.A9)) RCODE + ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP + ,COALESCE(Q.DIR,'Other') DIRECTOR + FROM + LGDAT.CODE C + LEFT OUTER JOIN RLARP.QRH Q ON + Q.QR = LTRIM(RTRIM(C.A9)) + WHERE + C.A2 = 'MM' + ) + --MOLD DESCRIPTIONS + ,MD AS ( + SELECT + U.MOLD + ,MAX(U.DESCR) DESCR + FROM + ( + SELECT + SUBSTR(M.AVPART,1,8) MOLD + ,MAX(M.AVDES1) DESCR + FROM + LGDAT.STKMM M + WHERE + LENGTH(M.AVPART) > 8 + AND SUBSTR(M.AVGLED,1,1) <= '2' + GROUP BY + SUBSTR(M.AVPART,1,8) + UNION ALL + SELECT + SUBSTR(P.AWPART,1,8) MOLD + ,MAX(P.AWDES1) DESCR + FROM + LGDAT.STKMP P + WHERE + LENGTH(P.AWPART) > 8 + AND SUBSTR(P.AWGLED,1,1) <= '2' + GROUP BY + SUBSTR(P.AWPART,1,8) + ) U + GROUP BY + U.MOLD + ) + ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- + ,SJ AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = '' + ) + ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- + ,SI AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> '' + ) + ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ + ,seas AS( + SELECT + ssyr + ,daterange(MIN(sdat),MAX(edat),'[]') dr + ,current_date <@ daterange(MIN(sdat),MAX(edat),'[]') cy + FROM + gld + GROUP BY + ssyr + ORDER BY + ssyr DESC + ) + ,intv AS ( + SELECT current_date - lower(dr) dy from seas where cy = true + ) + ,std AS ( + SELECT + s.ssyr + ,s.dr + ,s.cy + ,daterange(lower(dr),dy + LOWER(dr),'[]') ytd + FROM + seas s + CROSS JOIN intv + ) + ---------------------------------------union actual and forecast--------------------------------------------------------------------------------------------------------------------------------------- + ,UN AS ( + --plan + SELECT + 'Budget' AS VERSION + ,'Budget' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE as ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(m.avNWHT,p.awNWHT) * CASE COALESCE(m.avNWUN, p.awNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMP OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = 'b19' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --staged forecast + SELECT + 'Forecast' AS VERSION + ,'Forecast' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMF OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = '5p7' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --actual + SELECT + 'Actual' AS VERSION + ,'Actual' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSM OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + --AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.CALC_STATUS <> 'CANCELED' + AND + ( + OSM.FSPR >= '1606' + OR OSM.ADJ_ORDERDATE >= '2016-06-01' + ) + GROUP BY + --VERSION + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + ) + ---------------------------------------aggregate actual and forecast----------------------------------------------------------------------------------------------------------------------------------- + ,AGG AS ( + SELECT + un.VERSION::text "version" + ,un.ITER::text "iter" + ,un.OSEAS::numeric oseas + ,un.ODATE::date odate + ,un.SSEAS::numeric sseas + ,un.SDATE::date sdate + ,un.RSEAS::numeric rseas + ,un.RDATE::date rdate + ,un.OM::text om + ,un.SM::text sm + ,un.RM::text rm + ,un.OY::text oy + ,(un.odate <@ _ytd)::boolean ocytd --current year to date + ,(un.odate <@ so.ytd)::boolean oytd --year to date recast for prior/forecast periods + ,un.SY::text sy + ,(un.sdate <@ _ytd)::boolean scytd + ,(un.sdate <@ ss.ytd)::boolean sytd + --had this order been placed yet? (current day prior year is greater than the order date) + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END status_py + ,un.RY::text ry + ,un.PLNT::text plnt + ,un.ACCOUNT::text bill_group + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text bill_cust + ,bc.bvctry bill_ctry + ,bc.bvprcd bill_prov + ,un.SHIPGRP::text ship_group + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text ship_cust + ,sc.bvctry ship_ctry + ,sc.bvprcd ship_prov + ,un.CHAN::text chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text mod_chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text mod_chansub + ,un.PROMO::text promo + ,un.MAJG||COALESCE(' - '||BQDES,'')::text majg + ,un.MING||COALESCE(' - '||BRDES,'')::text ming + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text majs + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text mins + ,un.PART::text part + ,un.PART_DESCR::text part_descr + ,un.PART_FAMILY::text part_family + ,un.PART_GROUP::text part_group + ,un.BRANDING::text branding + ,un.SEGM::text segm + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text quota_rep + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text director + ,SUM(un.QTY)::numeric qty + ,SUM(un.SALES)::numeric sales + ,SUM(un.STDCOST)::numeric stdcost + ,SUM(un.QTY * COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur + ,SUM(un.POUNDS)::numeric pounds + ,(un.VERSION||'-'||un.SY)::text flag_s + ,(un.VERSION||'-'||un.OY)::text flag_o + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text status + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text "options" + ,'Grand Total'::text grandtotal + FROM + UN + LEFT OUTER JOIN REPC ON + REPC.RCODE = un.QUOTA_REP + LEFT OUTER JOIN SI ON + SI.BSMJCD = UN.MAJS + AND SI.BSMNCD = UN.MINS + LEFT OUTER JOIN SJ ON + SJ.BSMJCD = UN.MAJS + LEFT OUTER JOIN LGDAT.MAJG ON + BQGRP = un.MAJG + LEFT OUTER JOIN LGDAT.MMGP ON + BRMGRP = un.MING + AND BRGRP = un.MAJG + LEFT OUTER JOIN LGDAT.CUST BC ON + BC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.CUST SC ON + SC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.ICSTM cm ON + cm.cgpart = un.part + AND cm.cgplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTP cp ON + cp.chpart = un.part + AND cp.chplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTR cr ON + cr.y0part = un.part + AND cr.y0plnt = un.plnt + LEFT OUTER JOIN STD so ON + so.ssyr = un.oseas + LEFT OUTER JOIN STD ss ON + ss.ssyr = un.sseas + GROUP BY + un.VERSION::text + ,un.ITER::text + ,un.OSEAS::numeric + ,un.ODATE::date + ,un.SSEAS::numeric + ,un.SDATE::date + ,un.RSEAS::numeric + ,un.RDATE::date + ,un.OM::text + ,un.SM::text + ,un.RM::text + ,un.OY::text + --current year to date + ,(un.odate <@ _ytd)::boolean + --year to date recast for prior/forecast periods + ,(un.odate <@ so.ytd)::boolean + ,un.SY::text + ,(un.sdate <@ _ytd)::boolean + ,(un.sdate <@ ss.ytd)::boolean + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END + ,un.RY::text + ,un.PLNT::text + ,un.ACCOUNT::text + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text + ,bc.bvctry + ,bc.bvprcd + ,un.SHIPGRP::text + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text + ,sc.bvctry + ,sc.bvprcd + ,un.CHAN::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text + ,un.PROMO::text + ,un.MAJG||COALESCE(' - '||BQDES,'')::text + ,un.MING||COALESCE(' - '||BRDES,'')::text + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text + ,un.PART::text + ,un.PART_DESCR::text + ,un.PART_FAMILY::text + ,un.PART_GROUP::text + ,un.BRANDING::text + ,un.SEGM::text + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text + ,(un.VERSION||'-'||un.SY)::text + ,(un.VERSION||'-'||un.OY)::text + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text + ,'Grand Total'::text + ) + SELECT + a.version + ,a.iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,a.qty + ,a.sales + ,a.stdcost + ,a.stdcost_cur + ,a.pounds + ,a.flag_s + ,a.flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + agg a + UNION ALL + SELECT + 'Var to Fcst' as version + ,'Var to Fcst' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Fcst'||'-'||a.scytd flag_s + ,'Var to Fcst'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Forecast') + AND (a.ocytd OR a.scytd) + + UNION ALL + SELECT + 'Var to Bdgt' as version + ,'Var to Bdgt' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Bdgt'||'-'||a.scytd flag_s + ,'Var to Bdgt'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Budget') + AND (a.ocytd OR a.scytd) +;+
+
Date: 2019-03-15 00:52:54 +Duration: 3m19s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Append (cost=4510966117154.68..4644894879274.93 rows=1921380827591 width=1520) (actual time=182826.066..198343.560 rows=1377873 loops=1) + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=285245 written=302150 + I/O Timings: read=8179.425 + CTE seg + -> Values Scan on "*VALUES*" (cost=0.00..0.18 rows=14 width=64) (actual time=0.001..0.004 rows=14 loops=1) + CTE mg + -> Values Scan on "*VALUES*_1" (cost=0.00..0.20 rows=16 width=96) (actual time=0.002..0.006 rows=16 loops=1) + CTE repc + -> Hash Left Join (cost=11.47..123.28 rows=120 width=96) (actual time=2.591..12.439 rows=120 loops=1) + Hash Cond: (ltrim(rtrim(c.a9)) = q.qr) + Buffers: shared read=26 + I/O Timings: read=11.445 + -> Bitmap Heap Scan on code c (cost=9.21..118.86 rows=120 width=25) (actual time=2.207..11.727 rows=120 loops=1) + Recheck Cond: (a2 = 'MM'::text) + Heap Blocks: exact=21 + Buffers: shared read=25 + I/O Timings: read=11.107 + -> Bitmap Index Scan on pk_code (cost=0.00..9.18 rows=120 width=0) (actual time=1.684..1.684 rows=120 loops=1) + Index Cond: (a2 = 'MM'::text) + Buffers: shared read=4 + I/O Timings: read=1.575 + -> Hash (cost=1.56..1.56 rows=56 width=12) (actual time=0.368..0.368 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.337 + -> Seq Scan on qrh q (cost=0.00..1.56 rows=56 width=12) (actual time=0.349..0.355 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.337 + CTE md + -> HashAggregate (cost=11936.00..11938.00 rows=200 width=64) (actual time=95.558..96.083 rows=3368 loops=1) + Group Key: (substr(m.avpart, 1, 8)) + Buffers: shared hit=9056 + -> Append (cost=8137.31..11870.54 rows=13091 width=64) (actual time=83.235..94.596 rows=3375 loops=1) + Buffers: shared hit=9056 + -> HashAggregate (cost=8137.31..8249.94 rows=9010 width=64) (actual time=83.233..84.126 rows=3285 loops=1) + Group Key: substr(m.avpart, 1, 8) + Buffers: shared hit=6448 + -> Seq Scan on stkmm m (cost=0.00..8092.26 rows=9010 width=59) (actual time=0.012..41.548 rows=76269 loops=1) + Filter: ((length(avpart) > 8) AND (substr(avgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 4728 + Buffers: shared hit=6448 + -> HashAggregate (cost=3373.23..3424.24 rows=4081 width=64) (actual time=10.241..10.276 rows=90 loops=1) + Group Key: substr(p.awpart, 1, 8) + Buffers: shared hit=2608 + -> Seq Scan on stkmp p (cost=0.00..3352.82 rows=4081 width=52) (actual time=0.579..10.168 rows=142 loops=1) + Filter: ((length(awpart) > 8) AND (substr(awgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 36557 + Buffers: shared hit=2608 + CTE sj + -> Seq Scan on mmsl (cost=0.00..1.84 rows=1 width=22) (actual time=0.006..0.010 rows=11 loops=1) + Filter: (COALESCE(bsmncd, ''::text) = ''::text) + Rows Removed by Filter: 56 + Buffers: shared hit=1 + CTE si + -> Seq Scan on mmsl mmsl_1 (cost=0.00..1.84 rows=66 width=22) (actual time=0.342..0.348 rows=56 loops=1) + Filter: (COALESCE(bsmncd, ''::text) <> ''::text) + Rows Removed by Filter: 11 + Buffers: shared read=1 + I/O Timings: read=0.330 + CTE seas + -> GroupAggregate (cost=10.22..16.31 rows=174 width=41) (actual time=0.064..0.094 rows=15 loops=1) + Group Key: gld.ssyr + Buffers: local hit=2 + -> Sort (cost=10.22..10.65 rows=174 width=16) (actual time=0.052..0.059 rows=174 loops=1) + Sort Key: gld.ssyr DESC + Sort Method: quicksort Memory: 33kB + Buffers: local hit=2 + -> Seq Scan on gld (cost=0.00..3.74 rows=174 width=16) (actual time=0.010..0.029 rows=174 loops=1) + Buffers: local hit=2 + CTE intv + -> CTE Scan on seas (cost=0.00..4.13 rows=87 width=4) (actual time=0.077..0.078 rows=1 loops=1) + Filter: cy + Rows Removed by Filter: 14 + Buffers: local hit=2 + CTE std + -> Nested Loop (cost=0.00..457.62 rows=15138 width=73) (actual time=0.080..0.112 rows=15 loops=1) + Buffers: local hit=2 + -> CTE Scan on intv (cost=0.00..1.74 rows=87 width=4) (actual time=0.078..0.079 rows=1 loops=1) + Buffers: local hit=2 + -> CTE Scan on seas s (cost=0.00..3.48 rows=174 width=41) (actual time=0.000..0.026 rows=15 loops=1) + CTE un + -> Append (cost=50003223.80..255856479.46 rows=330423099 width=697) (actual time=34264.289..81644.471 rows=812229 loops=1) + Buffers: shared hit=98372 read=72635, local hit=5658753 read=1 + I/O Timings: read=7746.456 + -> GroupAggregate (cost=50003223.80..63823292.65 rows=83757993 width=701) (actual time=34264.288..36465.643 rows=212793 loops=1) + Group Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Buffers: shared hit=45043 read=23493, local hit=2563791 read=1 + I/O Timings: read=3613.602 + -> Sort (cost=50003223.80..50212618.79 rows=83757993 width=594) (actual time=34264.218..34431.899 rows=641010 loops=1) + Sort Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Sort Method: quicksort Memory: 352782kB + Buffers: shared hit=45043 read=23493, local hit=2563791 read=1 + I/O Timings: read=3613.602 + -> Hash Left Join (cost=11749.79..16650773.71 rows=83757993 width=594) (actual time=523.585..12806.506 rows=641010 loops=1) + Hash Cond: ((osm.bill_class = l.bill) AND (osm.ship_class = l.ship)) + Buffers: shared hit=45040 read=23493, local hit=2563791 read=1 + I/O Timings: read=3613.602 + -> Hash Left Join (cost=11744.32..10583311.94 rows=83757993 width=583) (actual time=522.937..12019.634 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 8) = md.mold) + Buffers: shared hit=45040 read=23491, local hit=2563791 read=1 + I/O Timings: read=3613.055 + -> Hash Left Join (cost=11737.82..5348430.88 rows=83757993 width=551) (actual time=425.063..11458.763 rows=641010 loops=1) + Hash Cond: (osm.part = p_1.awpart) + Buffers: shared hit=35984 read=23491, local hit=2563791 read=1 + I/O Timings: read=3613.055 + -> Nested Loop Left Join (cost=8303.37..5125106.33 rows=83757993 width=527) (actual time=313.496..11101.481 rows=641010 loops=1) + Buffers: shared hit=35982 read=20885, local hit=2563791 read=1 + I/O Timings: read=3534.677 + -> Nested Loop Left Join (cost=8303.23..337594.45 rows=4332310 width=455) (actual time=313.488..8642.098 rows=641010 loops=1) + Buffers: shared hit=35982 read=20885, local hit=1281897 read=1 + I/O Timings: read=3534.677 + -> Hash Left Join (cost=8303.08..89964.52 rows=224085 width=383) (actual time=313.453..5992.381 rows=641010 loops=1) + Hash Cond: (osm.part = m_1.avpart) + Buffers: shared hit=35982 read=20885, local hit=2 + I/O Timings: read=3534.662 + -> Hash Left Join (cost=30.62..81103.81 rows=224085 width=348) (actual time=12.984..5414.171 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 3) = f.f3) + Buffers: shared hit=35980 read=14439, local hit=2 + I/O Timings: read=3281.743 + -> Hash Left Join (cost=6.93..77718.84 rows=224085 width=324) (actual time=0.106..4996.296 rows=641010 loops=1) + Hash Cond: ((substr(osm.part, 16, 1) = mg.f1) AND (osm.ming = mg.ming)) + Buffers: shared hit=35980 read=14430, local hit=2 + I/O Timings: read=3269.024 + -> Hash Left Join (cost=6.37..75750.09 rows=224085 width=292) (actual time=0.084..4563.487 rows=641010 loops=1) + Hash Cond: (osm.glec = seg.glec) + Buffers: shared hit=35980 read=14430, local hit=2 + I/O Timings: read=3269.024 + -> Hash Left Join (cost=5.92..72674.81 rows=224085 width=264) (actual time=0.070..4318.873 rows=641010 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=35980 read=14430, local hit=2 + I/O Timings: read=3269.024 + -> Seq Scan on osmp osm (cost=0.00..69587.73 rows=224085 width=184) (actual time=0.017..4055.770 rows=641010 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = 'b19'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 57051 + Buffers: shared hit=35980 read=14430 + I/O Timings: read=3269.024 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.048..0.048 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=112) (actual time=0.003..0.024 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.011..0.011 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.008 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.015..0.015 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.012 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=12.868..12.868 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared read=9 + I/O Timings: read=12.719 + -> Seq Scan on family f (cost=0.00..15.53 rows=653 width=24) (actual time=12.733..12.786 rows=653 loops=1) + Buffers: shared read=9 + I/O Timings: read=12.719 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=300.407..300.407 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=2 read=6446 + I/O Timings: read=252.919 + -> Seq Scan on stkmm m_1 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.600..277.166 rows=80997 loops=1) + Buffers: shared hit=2 read=6446 + I/O Timings: read=252.919 + -> Index Scan using se_dat on gld od (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1281895 read=1 + I/O Timings: read=0.015 + -> Index Scan using se_dat on gld rd (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_requestdate >= sdat) AND (osm.adj_requestdate <= edat)) + Buffers: local hit=1281894 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=108.057..108.057 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2 read=2606 + I/O Timings: read=78.378 + -> Seq Scan on stkmp p_1 (cost=0.00..2975.31 rows=36731 width=33) (actual time=1.096..89.328 rows=36699 loops=1) + Buffers: shared hit=2 read=2606 + I/O Timings: read=78.378 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=97.843..97.843 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + Buffers: shared hit=9056 + -> CTE Scan on md (cost=0.00..4.00 rows=200 width=64) (actual time=95.561..97.114 rows=3368 loops=1) + Buffers: shared hit=9056 + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.629..0.629 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=2 + I/O Timings: read=0.546 + -> Seq Scan on ffchnl l (cost=0.00..3.39 rows=139 width=25) (actual time=0.574..0.596 rows=139 loops=1) + Buffers: shared read=2 + I/O Timings: read=0.546 + -> GroupAggregate (cost=33445583.00..42801951.72 rows=56705265 width=699) (actual time=21899.780..27106.566 rows=250477 loops=1) + Group Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Buffers: shared hit=35412, local hit=1627258 + -> Sort (cost=33445583.00..33587346.16 rows=56705265 width=595) (actual time=21899.740..22369.501 rows=406814 loops=1) + Sort Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Sort Method: quicksort Memory: 222052kB + Buffers: shared hit=35412, local hit=1627258 + -> Hash Left Join (cost=11749.79..11025086.80 rows=56705265 width=595) (actual time=82.385..8358.833 rows=406814 loops=1) + Hash Cond: ((osm_1.bill_class = l_1.bill) AND (osm_1.ship_class = l_1.ship)) + Buffers: shared hit=35412, local hit=1627258 + -> Hash Left Join (cost=11744.32..6967724.27 rows=55168846 width=584) (actual time=82.294..7619.217 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 8) = md_1.mold) + Buffers: shared hit=35410, local hit=1627258 + -> Hash Left Join (cost=11737.82..3519664.90 rows=55168846 width=552) (actual time=81.174..7139.198 rows=406814 loops=1) + Hash Cond: (osm_1.part = p_2.awpart) + Buffers: shared hit=35410, local hit=1627258 + -> Nested Loop Left Join (cost=8303.37..3371395.52 rows=55168846 width=528) (actual time=50.759..6837.840 rows=406814 loops=1) + Buffers: shared hit=32802, local hit=1627258 + -> Nested Loop Left Join (cost=8303.23..217901.28 rows=2853561 width=456) (actual time=50.749..4566.299 rows=406814 loops=1) + Buffers: shared hit=32802, local hit=813630 + -> Hash Left Join (cost=8303.08..54789.49 rows=147598 width=384) (actual time=50.729..2196.620 rows=406814 loops=1) + Hash Cond: (osm_1.part = m_2.avpart) + Buffers: shared hit=32802, local hit=2 + -> Hash Left Join (cost=30.62..46129.57 rows=147598 width=349) (actual time=0.257..1813.794 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 3) = f_1.f3) + Buffers: shared hit=26354, local hit=2 + -> Hash Left Join (cost=6.93..43891.91 rows=147598 width=325) (actual time=0.121..1436.906 rows=406814 loops=1) + Hash Cond: ((substr(osm_1.part, 16, 1) = mg_1.f1) AND (osm_1.ming = mg_1.ming)) + Buffers: shared hit=26345, local hit=2 + -> Hash Left Join (cost=6.37..42594.49 rows=147598 width=293) (actual time=0.110..1056.449 rows=406814 loops=1) + Hash Cond: (osm_1.glec = seg_1.glec) + Buffers: shared hit=26345, local hit=2 + -> Hash Left Join (cost=5.92..40564.57 rows=147598 width=265) (actual time=0.098..857.465 rows=406814 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=26345, local hit=2 + -> Seq Scan on osmf osm_1 (cost=0.00..38529.18 rows=147598 width=185) (actual time=0.026..619.289 rows=406814 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = '5p7'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 358 + Buffers: shared hit=26345 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.065..0.065 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=112) (actual time=0.008..0.035 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.007..0.007 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_1 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.004 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.007..0.007 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_1 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.003 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.131..0.131 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_1 (cost=0.00..15.53 rows=653 width=24) (actual time=0.010..0.054 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=50.417..50.417 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_2 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.005..27.523 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=406814) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=813628 + -> Index Scan using se_dat on gld rd_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.005 rows=1 loops=406814) + Index Cond: ((osm_1.adj_requestdate >= sdat) AND (osm_1.adj_requestdate <= edat)) + Buffers: local hit=813628 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=30.201..30.201 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_2 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.009..17.401 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=1.104..1.104 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_1 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.386 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.063..0.063 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_1 (cost=0.00..3.39 rows=139 width=25) (actual time=0.011..0.032 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=112931514.84..144274888.60 rows=189959841 width=695) (actual time=16710.998..17936.290 rows=348959 loops=1) + Group Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Buffers: shared hit=17917 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Sort (cost=112931514.84..113406414.44 rows=189959841 width=584) (actual time=16710.946..16814.969 rows=367211 loops=1) + Sort Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Sort Method: quicksort Memory: 201623kB + Buffers: shared hit=17917 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=11749.79..37465936.67 rows=189959841 width=584) (actual time=154.009..11372.141 rows=367211 loops=1) + Hash Cond: ((osm_2.bill_class = l_2.bill) AND (osm_2.ship_class = l_2.ship)) + Buffers: shared hit=17917 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=11744.32..23902628.82 rows=189959841 width=574) (actual time=153.913..10698.691 rows=367211 loops=1) + Hash Cond: (substr(osm_2.part, 1, 8) = md_2.mold) + Buffers: shared hit=17915 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=11737.82..12030132.26 rows=189959841 width=542) (actual time=148.767..10299.042 rows=367211 loops=1) + Hash Cond: (osm_2.part = p_3.awpart) + Buffers: shared hit=17915 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Nested Loop Left Join (cost=8303.37..11527995.69 rows=189959841 width=518) (actual time=102.067..10041.030 rows=367211 loops=1) + Buffers: shared hit=15307 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Nested Loop Left Join (cost=8303.23..670498.91 rows=9825509 width=446) (actual time=102.059..8236.690 rows=367211 loops=1) + Buffers: shared hit=15307 read=49142, local hit=733854 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=8303.08..108904.23 rows=508216 width=374) (actual time=102.031..6271.278 rows=367211 loops=1) + Hash Cond: (osm_2.part = m_3.avpart) + Buffers: shared hit=15307 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=30.62..99297.64 rows=508216 width=339) (actual time=6.361..5913.268 rows=367211 loops=1) + Hash Cond: (substr(osm_2.part, 1, 3) = f_2.f3) + Buffers: shared hit=8859 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=6.93..91650.71 rows=508216 width=315) (actual time=6.219..5568.521 rows=367211 loops=1) + Hash Cond: ((substr(osm_2.part, 16, 1) = mg_2.f1) AND (osm_2.ming = mg_2.ming)) + Buffers: shared hit=8850 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=6.37..87189.88 rows=508216 width=283) (actual time=6.207..5231.289 rows=367211 loops=1) + Hash Cond: (osm_2.glec = seg_2.glec) + Buffers: shared hit=8850 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=5.92..80265.15 rows=508216 width=255) (actual time=6.193..5042.515 rows=367211 loops=1) + Hash Cond: (osm_2.fspr = sd_2.fspr) + Buffers: shared hit=8850 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Seq Scan on osm osm_2 (cost=0.00..73663.10 rows=508216 width=175) (actual time=6.115..4852.376 rows=367211 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND ((fspr >= '1606'::text) OR (adj_orderdate >= '2016-06-01'::date))) + Rows Removed by Filter: 417318 + Buffers: shared hit=8850 read=49142 + I/O Timings: read=4132.855 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.064..0.064 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_2 (cost=0.00..3.74 rows=174 width=112) (actual time=0.009..0.036 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_2 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.003 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.006..0.006 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_2 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.131..0.131 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_2 (cost=0.00..15.53 rows=653 width=24) (actual time=0.010..0.051 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=95.611..95.611 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_3 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.005..42.484 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=367211) + Index Cond: ((osm_2.adj_orderdate >= sdat) AND (osm_2.adj_orderdate <= edat)) + Buffers: local hit=733852 + -> Index Scan using se_dat on gld rd_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=367211) + Index Cond: ((osm_2.adj_requestdate >= sdat) AND (osm_2.adj_requestdate <= edat)) + Buffers: local hit=733850 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=46.657..46.657 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_3 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.010..23.613 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=5.110..5.110 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_2 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.405 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.068..0.068 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_2 (cost=0.00..3.39 rows=139 width=25) (actual time=0.021..0.039 rows=139 loops=1) + Buffers: shared hit=2 + CTE agg + -> GroupAggregate (cost=3990139087947.22..4510710248131.84 rows=1892986037035 width=1404) (actual time=182825.587..189012.716 rows=809487 loops=1) + Group Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)), 'Grand Total'::text + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=169551 written=244303 + I/O Timings: read=8179.425 + -> Sort (cost=3990139087947.22..3994871553039.80 rows=1892986037035 width=1346) (actual time=182817.706..183828.314 rows=812229 loops=1) + Sort Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)) + Sort Method: external merge Disk: 475848kB + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=169551 written=244303 + I/O Timings: read=8179.425 + -> Merge Right Join (cost=33563712447.31..265517026370.70 rows=1892986037035 width=1346) (actual time=117209.936..123600.017 rows=812229 loops=1) + Merge Cond: (ss.ssyr = un.sseas) + Buffers: shared hit=101597 read=90963, local hit=5658755 read=1, temp read=110070 written=184821 + I/O Timings: read=8179.425 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.122..0.740 rows=15 loops=1) + Sort Key: ss.ssyr + Sort Method: quicksort Memory: 26kB + Buffers: local hit=2 + -> CTE Scan on std ss (cost=0.00..302.76 rows=15138 width=40) (actual time=0.081..0.117 rows=15 loops=1) + Buffers: local hit=2 + -> Materialize (cost=33563711093.53..33688759715.34 rows=25009724363 width=1300) (actual time=117198.447..119674.219 rows=812229 loops=1) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=110070 written=184821 + I/O Timings: read=8179.425 + -> Sort (cost=33563711093.53..33626235404.44 rows=25009724363 width=1300) (actual time=117198.083..117976.508 rows=812229 loops=1) + Sort Key: un.sseas + Sort Method: external merge Disk: 445840kB + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=110070 written=146582 + I/O Timings: read=8179.425 + -> Merge Right Join (cost=488162845.81..864134844.69 rows=25009724363 width=1300) (actual time=105501.163..109753.807 rows=812229 loops=1) + Merge Cond: (so.ssyr = un.oseas) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=54340 written=90851 + I/O Timings: read=8179.425 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.005..0.009 rows=13 loops=1) + Sort Key: so.ssyr + Sort Method: quicksort Memory: 26kB + -> CTE Scan on std so (cost=0.00..302.76 rows=15138 width=40) (actual time=0.000..0.002 rows=15 loops=1) + -> Materialize (cost=488161492.03..489813607.52 rows=330423099 width=1268) (actual time=105468.884..108956.573 rows=812229 loops=1) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=54340 written=90851 + I/O Timings: read=8179.425 + -> Sort (cost=488161492.03..488987549.77 rows=330423099 width=1268) (actual time=105419.215..105977.954 rows=812229 loops=1) + Sort Key: un.oseas + Sort Method: external merge Disk: 434720kB + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=54340 written=54341 + I/O Timings: read=8179.425 + -> Hash Left Join (cost=30326.40..75489285.22 rows=330423099 width=1268) (actual time=34892.831..94537.687 rows=812229 loops=1) + Hash Cond: ((un.part = cr.y0part) AND (un.plnt = cr.y0plnt)) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1 + I/O Timings: read=8179.425 + -> Hash Left Join (cost=22414.65..56426266.97 rows=330423099 width=1262) (actual time=34668.780..93298.840 rows=812229 loops=1) + Hash Cond: ((un.part = cp.chpart) AND (un.plnt = cp.chplnt)) + Buffers: shared hit=101597 read=85711, local hit=5658753 read=1 + I/O Timings: read=8003.465 + -> Hash Left Join (cost=14299.03..36533966.06 rows=330423099 width=1256) (actual time=34522.917..92143.759 rows=812229 loops=1) + Hash Cond: ((un.part = cm.cgpart) AND (un.plnt = cm.cgplnt)) + Buffers: shared hit=101597 read=80395, local hit=5658753 read=1 + I/O Timings: read=7920.833 + -> Hash Left Join (cost=7433.88..34026391.85 rows=330423099 width=1250) (actual time=34383.160..90732.988 rows=812229 loops=1) + Hash Cond: (un.bill_cust = sc.bvcust) + Buffers: shared hit=101597 read=75888, local hit=5658753 read=1 + I/O Timings: read=7833.063 + -> Hash Left Join (cost=3723.16..29479363.52 rows=330423099 width=1223) (actual time=34366.365..89923.315 rows=812229 loops=1) + Hash Cond: (un.bill_cust = bc.bvcust) + Buffers: shared hit=98373 read=75888, local hit=5658753 read=1 + I/O Timings: read=7833.063 + -> Hash Left Join (cost=12.44..24932335.18 rows=330423099 width=1196) (actual time=34277.988..88987.624 rows=812229 loops=1) + Hash Cond: ((un.ming = mmgp.brmgrp) AND (un.majg = mmgp.brgrp)) + Buffers: shared hit=98373 read=72664, local hit=5658753 read=1 + I/O Timings: read=7758.824 + -> Hash Left Join (cost=7.51..15006668.18 rows=330423099 width=1186) (actual time=34277.622..88269.216 rows=812229 loops=1) + Hash Cond: (un.majg = majg.bqgrp) + Buffers: shared hit=98373 read=72663, local hit=5658753 read=1 + I/O Timings: read=7758.524 + -> Hash Left Join (cost=6.24..13569326.43 rows=330423099 width=1176) (actual time=34277.304..87627.015 rows=812229 loops=1) + Hash Cond: (un.majs = sj.bsmjcd) + Buffers: shared hit=98373 read=72662, local hit=5658753 read=1 + I/O Timings: read=7758.231 + -> Hash Left Join (cost=6.21..12313718.62 rows=330423099 width=1144) (actual time=34277.281..87019.163 rows=812229 loops=1) + Hash Cond: ((un.majs = si.bsmjcd) AND (un.mins = si.bsmncd)) + Buffers: shared hit=98372 read=72662, local hit=5658753 read=1 + I/O Timings: read=7758.231 + -> Hash Left Join (cost=3.90..9830091.09 rows=330423099 width=1112) (actual time=34276.887..86204.919 rows=812229 loops=1) + Hash Cond: (un.quota_rep = repc.rcode) + Buffers: shared hit=98372 read=72661, local hit=5658753 read=1 + I/O Timings: read=7757.901 + -> CTE Scan on un (cost=0.00..6608461.98 rows=330423099 width=1048) (actual time=34264.293..85100.705 rows=812229 loops=1) + Buffers: shared hit=98372 read=72635, local hit=5658753 read=1 + I/O Timings: read=7746.456 + -> Hash (cost=2.40..2.40 rows=120 width=96) (actual time=12.582..12.582 rows=120 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 17kB + Buffers: shared read=26 + I/O Timings: read=11.445 + -> CTE Scan on repc (cost=0.00..2.40 rows=120 width=96) (actual time=2.594..12.537 rows=120 loops=1) + Buffers: shared read=26 + I/O Timings: read=11.445 + -> Hash (cost=1.32..1.32 rows=66 width=96) (actual time=0.382..0.382 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.330 + -> CTE Scan on si (cost=0.00..1.32 rows=66 width=96) (actual time=0.344..0.363 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.330 + -> Hash (cost=0.02..0.02 rows=1 width=64) (actual time=0.016..0.016 rows=11 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=1 + -> CTE Scan on sj (cost=0.00..0.02 rows=1 width=64) (actual time=0.007..0.013 rows=11 loops=1) + Buffers: shared hit=1 + -> Hash (cost=1.12..1.12 rows=12 width=14) (actual time=0.312..0.312 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared read=1 + I/O Timings: read=0.293 + -> Seq Scan on majg (cost=0.00..1.12 rows=12 width=14) (actual time=0.301..0.303 rows=12 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.293 + -> Hash (cost=2.57..2.57 rows=157 width=18) (actual time=0.359..0.359 rows=157 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=1 + I/O Timings: read=0.300 + -> Seq Scan on mmgp (cost=0.00..2.57 rows=157 width=18) (actual time=0.309..0.326 rows=157 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.300 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=88.356..88.356 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared read=3224 + I/O Timings: read=74.239 + -> Seq Scan on cust bc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.900..82.368 rows=21632 loops=1) + Buffers: shared read=3224 + I/O Timings: read=74.239 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=16.771..16.771 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared hit=3224 + -> Seq Scan on cust sc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.007..10.557 rows=21632 loops=1) + Buffers: shared hit=3224 + -> Hash (cost=5450.26..5450.26 rows=94326 width=29) (actual time=139.654..139.654 rows=94326 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6699kB + Buffers: shared read=4507 + I/O Timings: read=87.770 + -> Seq Scan on icstm cm (cost=0.00..5450.26 rows=94326 width=29) (actual time=1.271..114.520 rows=94326 loops=1) + Buffers: shared read=4507 + I/O Timings: read=87.770 + -> Hash (cost=6435.85..6435.85 rows=111985 width=20) (actual time=145.806..145.806 rows=111985 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6768kB + Buffers: shared read=5316 + I/O Timings: read=82.632 + -> Seq Scan on icstp cp (cost=0.00..6435.85 rows=111985 width=20) (actual time=3.411..114.774 rows=111985 loops=1) + Buffers: shared read=5316 + I/O Timings: read=82.632 + -> Hash (cost=6315.90..6315.90 rows=106390 width=27) (actual time=223.650..223.650 rows=106390 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7334kB + Buffers: shared read=5252 + I/O Timings: read=175.960 + -> Seq Scan on icstr cr (cost=0.00..6315.90 rows=106390 width=27) (actual time=1.134..193.496 rows=106390 loops=1) + Buffers: shared read=5252 + I/O Timings: read=175.960 + -> CTE Scan on agg a (cost=0.00..37859720740.70 rows=1892986037035 width=1520) (actual time=182825.842..192275.884 rows=809487 loops=1) + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=169551 written=302149 + I/O Timings: read=8179.425 + -> CTE Scan on agg a_1 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=336.760..2113.121 rows=298364 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Forecast}'::text[]))) + Rows Removed by Filter: 511123 + Buffers: temp read=57847 written=1 + -> CTE Scan on agg a_2 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=218.764..3615.793 rows=270022 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Budget}'::text[]))) + Rows Removed by Filter: 539465 + Buffers: temp read=57847 + +
+Date: 2019-03-15 16:48:07 +Duration: 2m28s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Append (cost=4309162605406.33..4437117814888.42 rows=1835682510591 width=1520) (actual time=130217.190..147603.781 rows=1378962 loops=1) + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=285365 written=302292 + I/O Timings: read=5796.575 + CTE seg + -> Values Scan on "*VALUES*" (cost=0.00..0.18 rows=14 width=64) (actual time=0.003..0.006 rows=14 loops=1) + CTE mg + -> Values Scan on "*VALUES*_1" (cost=0.00..0.20 rows=16 width=96) (actual time=0.003..0.011 rows=16 loops=1) + CTE repc + -> Hash Left Join (cost=11.47..123.28 rows=120 width=96) (actual time=7.419..15.669 rows=120 loops=1) + Hash Cond: (ltrim(rtrim(c.a9)) = q.qr) + Buffers: shared hit=1 read=25 + I/O Timings: read=14.644 + -> Bitmap Heap Scan on code c (cost=9.21..118.86 rows=120 width=25) (actual time=7.351..15.256 rows=120 loops=1) + Recheck Cond: (a2 = 'MM'::text) + Heap Blocks: exact=21 + Buffers: shared read=25 + I/O Timings: read=14.644 + -> Bitmap Index Scan on pk_code (cost=0.00..9.18 rows=120 width=0) (actual time=6.872..6.872 rows=120 loops=1) + Index Cond: (a2 = 'MM'::text) + Buffers: shared read=4 + I/O Timings: read=6.737 + -> Hash (cost=1.56..1.56 rows=56 width=12) (actual time=0.044..0.044 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared hit=1 + -> Seq Scan on qrh q (cost=0.00..1.56 rows=56 width=12) (actual time=0.016..0.024 rows=56 loops=1) + Buffers: shared hit=1 + CTE md + -> HashAggregate (cost=11936.00..11938.00 rows=200 width=64) (actual time=109.370..109.781 rows=3368 loops=1) + Group Key: (substr(m.avpart, 1, 8)) + Buffers: shared hit=9056 + -> Append (cost=8137.31..11870.54 rows=13091 width=64) (actual time=98.760..108.518 rows=3375 loops=1) + Buffers: shared hit=9056 + -> HashAggregate (cost=8137.31..8249.94 rows=9010 width=64) (actual time=98.758..99.319 rows=3285 loops=1) + Group Key: substr(m.avpart, 1, 8) + Buffers: shared hit=6448 + -> Seq Scan on stkmm m (cost=0.00..8092.26 rows=9010 width=59) (actual time=0.016..53.186 rows=76269 loops=1) + Filter: ((length(avpart) > 8) AND (substr(avgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 4728 + Buffers: shared hit=6448 + -> HashAggregate (cost=3373.23..3424.24 rows=4081 width=64) (actual time=8.960..8.993 rows=90 loops=1) + Group Key: substr(p.awpart, 1, 8) + Buffers: shared hit=2608 + -> Seq Scan on stkmp p (cost=0.00..3352.82 rows=4081 width=52) (actual time=0.460..8.898 rows=142 loops=1) + Filter: ((length(awpart) > 8) AND (substr(awgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 36557 + Buffers: shared hit=2608 + CTE sj + -> Seq Scan on mmsl (cost=0.00..1.84 rows=1 width=22) (actual time=0.005..0.011 rows=11 loops=1) + Filter: (COALESCE(bsmncd, ''::text) = ''::text) + Rows Removed by Filter: 56 + Buffers: shared hit=1 + CTE si + -> Seq Scan on mmsl mmsl_1 (cost=0.00..1.84 rows=66 width=22) (actual time=1.513..1.521 rows=56 loops=1) + Filter: (COALESCE(bsmncd, ''::text) <> ''::text) + Rows Removed by Filter: 11 + Buffers: shared read=1 + I/O Timings: read=1.503 + CTE seas + -> GroupAggregate (cost=10.22..16.31 rows=174 width=41) (actual time=0.067..0.097 rows=15 loops=1) + Group Key: gld.ssyr + Buffers: local hit=2 + -> Sort (cost=10.22..10.65 rows=174 width=16) (actual time=0.052..0.059 rows=174 loops=1) + Sort Key: gld.ssyr DESC + Sort Method: quicksort Memory: 33kB + Buffers: local hit=2 + -> Seq Scan on gld (cost=0.00..3.74 rows=174 width=16) (actual time=0.010..0.030 rows=174 loops=1) + Buffers: local hit=2 + CTE intv + -> CTE Scan on seas (cost=0.00..4.13 rows=87 width=4) (actual time=0.078..0.079 rows=1 loops=1) + Filter: cy + Rows Removed by Filter: 14 + Buffers: local hit=2 + CTE std + -> Nested Loop (cost=0.00..457.62 rows=15138 width=73) (actual time=0.081..0.114 rows=15 loops=1) + Buffers: local hit=2 + -> CTE Scan on intv (cost=0.00..1.74 rows=87 width=4) (actual time=0.078..0.079 rows=1 loops=1) + Buffers: local hit=2 + -> CTE Scan on seas s (cost=0.00..3.48 rows=174 width=41) (actual time=0.000..0.027 rows=15 loops=1) + CTE un + -> Append (cost=50003223.80..244355794.95 rows=315685415 width=697) (actual time=24427.622..55248.745 rows=812592 loops=1) + Buffers: shared hit=33769 read=137238 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5418.990 + -> GroupAggregate (cost=50003223.80..63823292.65 rows=83757993 width=701) (actual time=24427.621..26180.035 rows=212793 loops=1) + Group Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Buffers: shared hit=9106 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Sort (cost=50003223.80..50212618.79 rows=83757993 width=594) (actual time=24427.582..24584.713 rows=641010 loops=1) + Sort Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Sort Method: quicksort Memory: 352782kB + Buffers: shared hit=9106 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Hash Left Join (cost=11749.79..16650773.71 rows=83757993 width=594) (actual time=594.631..11450.131 rows=641010 loops=1) + Hash Cond: ((osm.bill_class = l.bill) AND (osm.ship_class = l.ship)) + Buffers: shared hit=9103 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Hash Left Join (cost=11744.32..10583311.94 rows=83757993 width=583) (actual time=594.565..10651.699 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 8) = md.mold) + Buffers: shared hit=9101 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Hash Left Join (cost=11737.82..5348430.88 rows=83757993 width=551) (actual time=483.328..10064.882 rows=641010 loops=1) + Hash Cond: (osm.part = p_1.awpart) + Buffers: shared hit=45 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Nested Loop Left Join (cost=8303.37..5125106.33 rows=83757993 width=527) (actual time=372.833..9705.810 rows=641010 loops=1) + Buffers: shared hit=43 read=56824, local hit=2563791 read=1 + I/O Timings: read=2158.329 + -> Nested Loop Left Join (cost=8303.23..337594.45 rows=4332310 width=455) (actual time=372.826..7154.118 rows=641010 loops=1) + Buffers: shared hit=43 read=56824, local hit=1281897 read=1 + I/O Timings: read=2158.329 + -> Hash Left Join (cost=8303.08..89964.52 rows=224085 width=383) (actual time=372.784..4519.221 rows=641010 loops=1) + Hash Cond: (osm.part = m_1.avpart) + Buffers: shared hit=43 read=56824, local hit=2 + I/O Timings: read=2158.311 + -> Hash Left Join (cost=30.62..81103.81 rows=224085 width=348) (actual time=1.380..3884.310 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 3) = f.f3) + Buffers: shared hit=41 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Hash Left Join (cost=6.93..77718.84 rows=224085 width=324) (actual time=1.257..3476.551 rows=641010 loops=1) + Hash Cond: ((substr(osm.part, 16, 1) = mg.f1) AND (osm.ming = mg.ming)) + Buffers: shared hit=32 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Hash Left Join (cost=6.37..75750.09 rows=224085 width=292) (actual time=1.228..3039.988 rows=641010 loops=1) + Hash Cond: (osm.glec = seg.glec) + Buffers: shared hit=32 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Hash Left Join (cost=5.92..72674.81 rows=224085 width=264) (actual time=1.210..2805.095 rows=641010 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=32 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Seq Scan on osmp osm (cost=0.00..69587.73 rows=224085 width=184) (actual time=1.134..2545.900 rows=641010 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = 'b19'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 57051 + Buffers: shared hit=32 read=50378 + I/O Timings: read=1843.013 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.058..0.058 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=112) (actual time=0.010..0.033 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.013..0.013 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg (cost=0.00..0.28 rows=14 width=64) (actual time=0.005..0.011 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.018..0.018 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.015 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.118..0.118 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f (cost=0.00..15.53 rows=653 width=24) (actual time=0.017..0.054 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=371.346..371.346 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=2 read=6446 + I/O Timings: read=315.299 + -> Seq Scan on stkmm m_1 (cost=0.00..7258.87 rows=81087 width=54) (actual time=1.087..344.662 rows=80997 loops=1) + Buffers: shared hit=2 read=6446 + I/O Timings: read=315.299 + -> Index Scan using se_dat on gld od (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1281895 read=1 + I/O Timings: read=0.018 + -> Index Scan using se_dat on gld rd (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_requestdate >= sdat) AND (osm.adj_requestdate <= edat)) + Buffers: local hit=1281894 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=110.296..110.296 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2 read=2606 + I/O Timings: read=81.053 + -> Seq Scan on stkmp p_1 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.977..97.487 rows=36699 loops=1) + Buffers: shared hit=2 read=2606 + I/O Timings: read=81.053 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=111.215..111.215 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + Buffers: shared hit=9056 + -> CTE Scan on md (cost=0.00..4.00 rows=200 width=64) (actual time=109.374..110.690 rows=3368 loops=1) + Buffers: shared hit=9056 + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.051..0.051 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l (cost=0.00..3.39 rows=139 width=25) (actual time=0.012..0.026 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=33445583.00..42801951.72 rows=56705265 width=699) (actual time=16460.682..17590.319 rows=250477 loops=1) + Group Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Sort (cost=33445583.00..33587346.16 rows=56705265 width=595) (actual time=16460.650..16563.021 rows=406814 loops=1) + Sort Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Sort Method: quicksort Memory: 222052kB + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=11749.79..11025086.80 rows=56705265 width=595) (actual time=61.424..7759.480 rows=406814 loops=1) + Hash Cond: ((osm_1.bill_class = l_1.bill) AND (osm_1.ship_class = l_1.ship)) + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=11744.32..6967724.27 rows=55168846 width=584) (actual time=61.349..7305.324 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 8) = md_1.mold) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=11737.82..3519664.90 rows=55168846 width=552) (actual time=60.509..6993.509 rows=406814 loops=1) + Hash Cond: (osm_1.part = p_2.awpart) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Nested Loop Left Join (cost=8303.37..3371395.52 rows=55168846 width=528) (actual time=43.514..6803.629 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Nested Loop Left Join (cost=8303.23..217901.28 rows=2853561 width=456) (actual time=43.508..5300.883 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=813630 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=8303.08..54789.49 rows=147598 width=384) (actual time=43.490..3729.138 rows=406814 loops=1) + Hash Cond: (osm_1.part = m_2.avpart) + Buffers: shared hit=6457 read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=30.62..46129.57 rows=147598 width=349) (actual time=5.697..3467.540 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 3) = f_1.f3) + Buffers: shared hit=9 read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=6.93..43891.91 rows=147598 width=325) (actual time=5.585..3211.131 rows=406814 loops=1) + Hash Cond: ((substr(osm_1.part, 16, 1) = mg_1.f1) AND (osm_1.ming = mg_1.ming)) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=6.37..42594.49 rows=147598 width=293) (actual time=5.575..2952.469 rows=406814 loops=1) + Hash Cond: (osm_1.glec = seg_1.glec) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=5.92..40564.57 rows=147598 width=265) (actual time=5.564..2812.752 rows=406814 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Seq Scan on osmf osm_1 (cost=0.00..38529.18 rows=147598 width=185) (actual time=5.391..2669.916 rows=406814 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = '5p7'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 358 + Buffers: shared read=26345 + I/O Timings: read=2275.461 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.158..0.158 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=112) (actual time=0.080..0.111 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_1 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.004 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.005..0.005 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_1 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.108..0.108 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_1 (cost=0.00..15.53 rows=653 width=24) (actual time=0.010..0.047 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=37.738..37.738 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_2 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.007..22.454 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=406814) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=813628 + -> Index Scan using se_dat on gld rd_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=406814) + Index Cond: ((osm_1.adj_requestdate >= sdat) AND (osm_1.adj_requestdate <= edat)) + Buffers: local hit=813628 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=16.826..16.826 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_2 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.007..9.949 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=0.825..0.825 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_1 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.290 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.045..0.045 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_1 (cost=0.00..3.39 rows=139 width=25) (actual time=0.008..0.022 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=104083613.45..132995269.35 rows=175222157 width=695) (actual time=10242.201..11403.381 rows=349322 loops=1) + Group Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Buffers: shared hit=15596 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Sort (cost=104083613.45..104521668.84 rows=175222157 width=584) (actual time=10242.147..10337.649 rows=367596 loops=1) + Sort Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Sort Method: quicksort Memory: 201821kB + Buffers: shared hit=15596 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Hash Left Join (cost=11749.79..34574966.31 rows=175222157 width=584) (actual time=54.045..5505.369 rows=367596 loops=1) + Hash Cond: ((osm_2.bill_class = l_2.bill) AND (osm_2.ship_class = l_2.ship)) + Buffers: shared hit=15596 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Hash Left Join (cost=11744.32..22053510.74 rows=175222157 width=572) (actual time=53.991..5099.469 rows=367596 loops=1) + Hash Cond: (substr(osm_2.part, 1, 8) = md_2.mold) + Buffers: shared hit=15594 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Hash Left Join (cost=11737.82..11102119.43 rows=175222157 width=540) (actual time=53.191..4854.338 rows=367596 loops=1) + Hash Cond: (osm_2.part = p_3.awpart) + Buffers: shared hit=15594 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Nested Loop Left Join (cost=8303.37..10638673.75 rows=175222157 width=516) (actual time=37.296..4707.080 rows=367596 loops=1) + Buffers: shared hit=12986 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Nested Loop Left Join (cost=8303.23..623511.84 rows=9063215 width=444) (actual time=37.291..3491.892 rows=367596 loops=1) + Buffers: shared hit=12986 read=51463 dirtied=4, local hit=734624 + I/O Timings: read=904.147 + -> Hash Left Join (cost=8303.08..105486.21 rows=468787 width=372) (actual time=37.263..2223.924 rows=367596 loops=1) + Hash Cond: (osm_2.part = m_3.avpart) + Buffers: shared hit=12986 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=30.62..95983.12 rows=468787 width=337) (actual time=0.270..2039.720 rows=367596 loops=1) + Hash Cond: (substr(osm_2.part, 1, 3) = f_2.f3) + Buffers: shared hit=6538 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=6.93..88927.62 rows=468787 width=313) (actual time=0.129..1823.936 rows=367596 loops=1) + Hash Cond: ((substr(osm_2.part, 16, 1) = mg_2.f1) AND (osm_2.ming = mg_2.ming)) + Buffers: shared hit=6529 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=6.37..84811.93 rows=468787 width=281) (actual time=0.119..1623.505 rows=367596 loops=1) + Hash Cond: (osm_2.glec = seg_2.glec) + Buffers: shared hit=6529 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=5.92..78421.13 rows=468787 width=253) (actual time=0.111..1504.191 rows=367596 loops=1) + Hash Cond: (osm_2.fspr = sd_2.fspr) + Buffers: shared hit=6529 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Seq Scan on osm osm_2 (cost=0.00..72340.04 rows=468787 width=173) (actual time=0.052..1372.311 rows=367596 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND ((fspr >= '1606'::text) OR (adj_orderdate >= '2016-06-01'::date))) + Rows Removed by Filter: 417392 + Buffers: shared hit=6529 read=51463 dirtied=4 + I/O Timings: read=904.147 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.053..0.053 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_2 (cost=0.00..3.74 rows=174 width=112) (actual time=0.007..0.029 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_2 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.003 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.006..0.006 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_2 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.136..0.136 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_2 (cost=0.00..15.53 rows=653 width=24) (actual time=0.008..0.047 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=36.937..36.937 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_3 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.006..22.525 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=367596) + Index Cond: ((osm_2.adj_orderdate >= sdat) AND (osm_2.adj_orderdate <= edat)) + Buffers: local hit=734622 + -> Index Scan using se_dat on gld rd_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=367596) + Index Cond: ((osm_2.adj_requestdate >= sdat) AND (osm_2.adj_requestdate <= edat)) + Buffers: local hit=734620 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=15.858..15.858 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_3 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.007..9.906 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=0.788..0.788 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_2 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.291 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.043..0.043 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_2 (cost=0.00..3.39 rows=139 width=25) (actual time=0.007..0.021 rows=139 loops=1) + Buffers: shared hit=2 + CTE agg + -> GroupAggregate (cost=3811565832720.57..4308918237067.99 rows=1808554197627 width=1404) (actual time=130217.184..134929.396 rows=809850 loops=1) + Group Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)), 'Grand Total'::text + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=169623 written=244421 + I/O Timings: read=5796.575 + -> Sort (cost=3811565832720.57..3816087218214.63 rows=1808554197627 width=1346) (actual time=130217.139..131170.872 rows=812592 loops=1) + Sort Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)) + Sort Method: external merge Disk: 476048kB + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=169623 written=244421 + I/O Timings: read=5796.575 + -> Merge Right Join (cost=32058721370.12..253666346227.77 rows=1808554197627 width=1346) (actual time=79725.467..85819.348 rows=812592 loops=1) + Merge Cond: (ss.ssyr = un.sseas) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660295 read=1, temp read=110117 written=184914 + I/O Timings: read=5796.575 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.123..0.131 rows=15 loops=1) + Sort Key: ss.ssyr + Sort Method: quicksort Memory: 26kB + Buffers: local hit=2 + -> CTE Scan on std ss (cost=0.00..302.76 rows=15138 width=40) (actual time=0.082..0.119 rows=15 loops=1) + Buffers: local hit=2 + -> Materialize (cost=32058720016.34..32178191161.64 rows=23894229061 width=1300) (actual time=79718.116..82479.293 rows=812592 loops=1) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=110117 written=184914 + I/O Timings: read=5796.575 + -> Sort (cost=32058720016.34..32118455588.99 rows=23894229061 width=1300) (actual time=79718.091..80948.227 rows=812592 loops=1) + Sort Key: un.sseas + Sort Method: external merge Disk: 446032kB + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=110117 written=146652 + I/O Timings: read=5796.575 + -> Merge Right Join (cost=466287095.31..825489820.45 rows=23894229061 width=1300) (actual time=67066.711..71526.574 rows=812592 loops=1) + Merge Cond: (so.ssyr = un.oseas) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=54363 written=90897 + I/O Timings: read=5796.575 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.004..0.008 rows=13 loops=1) + Sort Key: so.ssyr + Sort Method: quicksort Memory: 26kB + -> CTE Scan on std so (cost=0.00..302.76 rows=15138 width=40) (actual time=0.000..0.002 rows=15 loops=1) + -> Materialize (cost=466285741.52..467864168.60 rows=315685415 width=1268) (actual time=67055.329..70663.573 rows=812592 loops=1) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=54363 written=90897 + I/O Timings: read=5796.575 + -> Sort (cost=466285741.52..467074955.06 rows=315685415 width=1268) (actual time=67050.634..68022.803 rows=812592 loops=1) + Sort Key: un.oseas + Sort Method: external merge Disk: 434904kB + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=54363 written=54364 + I/O Timings: read=5796.575 + -> Hash Left Join (cost=30326.40..72123629.81 rows=315685415 width=1268) (actual time=24989.685..60611.536 rows=812592 loops=1) + Hash Cond: ((un.part = cr.y0part) AND (un.plnt = cr.y0plnt)) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5796.575 + -> Hash Left Join (cost=22414.65..53910516.25 rows=315685415 width=1262) (actual time=24857.162..60071.090 rows=812592 loops=1) + Hash Cond: ((un.part = cp.chpart) AND (un.plnt = cp.chplnt)) + Buffers: shared hit=36995 read=150313 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5704.175 + -> Hash Left Join (cost=14299.03..34905098.97 rows=315685415 width=1256) (actual time=24690.716..59482.739 rows=812592 loops=1) + Hash Cond: ((un.part = cm.cgpart) AND (un.plnt = cm.cgplnt)) + Buffers: shared hit=36995 read=144997 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5598.963 + -> Hash Left Join (cost=7433.88..32509062.54 rows=315685415 width=1250) (actual time=24542.324..58815.424 rows=812592 loops=1) + Hash Cond: (un.bill_cust = sc.bvcust) + Buffers: shared hit=36995 read=140490 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5507.001 + -> Hash Left Join (cost=3723.16..28164677.36 rows=315685415 width=1223) (actual time=24531.977..58466.240 rows=812592 loops=1) + Hash Cond: (un.bill_cust = bc.bvcust) + Buffers: shared hit=33771 read=140490 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5507.001 + -> Hash Left Join (cost=12.44..23820292.19 rows=315685415 width=1196) (actual time=24445.824..58031.724 rows=812592 loops=1) + Hash Cond: ((un.ming = mmgp.brmgrp) AND (un.majg = mmgp.brgrp)) + Buffers: shared hit=33771 read=137266 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.817 + -> Hash Left Join (cost=7.51..14337334.16 rows=315685415 width=1186) (actual time=24445.412..57697.186 rows=812592 loops=1) + Hash Cond: (un.majg = majg.bqgrp) + Buffers: shared hit=33771 read=137265 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.479 + -> Hash Left Join (cost=6.24..12964101.34 rows=315685415 width=1176) (actual time=24445.051..57415.327 rows=812592 loops=1) + Hash Cond: (un.majs = sj.bsmjcd) + Buffers: shared hit=33771 read=137264 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.137 + -> Hash Left Join (cost=6.21..11764496.73 rows=315685415 width=1144) (actual time=24445.027..57139.761 rows=812592 loops=1) + Hash Cond: ((un.majs = si.bsmjcd) AND (un.mins = si.bsmncd)) + Buffers: shared hit=33770 read=137264 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.137 + -> Hash Left Join (cost=3.90..9391645.00 rows=315685415 width=1112) (actual time=24443.462..56809.926 rows=812592 loops=1) + Hash Cond: (un.quota_rep = repc.rcode) + Buffers: shared hit=33770 read=137263 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5433.634 + -> CTE Scan on un (cost=0.00..6313708.30 rows=315685415 width=1048) (actual time=24427.626..56309.934 rows=812592 loops=1) + Buffers: shared hit=33769 read=137238 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5418.990 + -> Hash (cost=2.40..2.40 rows=120 width=96) (actual time=15.823..15.823 rows=120 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 17kB + Buffers: shared hit=1 read=25 + I/O Timings: read=14.644 + -> CTE Scan on repc (cost=0.00..2.40 rows=120 width=96) (actual time=7.422..15.771 rows=120 loops=1) + Buffers: shared hit=1 read=25 + I/O Timings: read=14.644 + -> Hash (cost=1.32..1.32 rows=66 width=96) (actual time=1.556..1.556 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=1.503 + -> CTE Scan on si (cost=0.00..1.32 rows=66 width=96) (actual time=1.516..1.541 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=1.503 + -> Hash (cost=0.02..0.02 rows=1 width=64) (actual time=0.017..0.017 rows=11 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=1 + -> CTE Scan on sj (cost=0.00..0.02 rows=1 width=64) (actual time=0.006..0.014 rows=11 loops=1) + Buffers: shared hit=1 + -> Hash (cost=1.12..1.12 rows=12 width=14) (actual time=0.357..0.357 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared read=1 + I/O Timings: read=0.342 + -> Seq Scan on majg (cost=0.00..1.12 rows=12 width=14) (actual time=0.349..0.351 rows=12 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.342 + -> Hash (cost=2.57..2.57 rows=157 width=18) (actual time=0.404..0.404 rows=157 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=1 + I/O Timings: read=0.338 + -> Seq Scan on mmgp (cost=0.00..2.57 rows=157 width=18) (actual time=0.350..0.369 rows=157 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.338 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=86.128..86.128 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared read=3224 + I/O Timings: read=71.184 + -> Seq Scan on cust bc (cost=0.00..3440.32 rows=21632 width=35) (actual time=1.719..80.386 rows=21632 loops=1) + Buffers: shared read=3224 + I/O Timings: read=71.184 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=10.320..10.320 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared hit=3224 + -> Seq Scan on cust sc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.007..6.682 rows=21632 loops=1) + Buffers: shared hit=3224 + -> Hash (cost=5450.26..5450.26 rows=94326 width=29) (actual time=148.322..148.322 rows=94326 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6699kB + Buffers: shared read=4507 + I/O Timings: read=91.962 + -> Seq Scan on icstm cm (cost=0.00..5450.26 rows=94326 width=29) (actual time=1.674..121.636 rows=94326 loops=1) + Buffers: shared read=4507 + I/O Timings: read=91.962 + -> Hash (cost=6435.85..6435.85 rows=111985 width=20) (actual time=166.382..166.382 rows=111985 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6768kB + Buffers: shared read=5316 + I/O Timings: read=105.211 + -> Seq Scan on icstp cp (cost=0.00..6435.85 rows=111985 width=20) (actual time=2.877..136.300 rows=111985 loops=1) + Buffers: shared read=5316 + I/O Timings: read=105.211 + -> Hash (cost=6315.90..6315.90 rows=106390 width=27) (actual time=132.044..132.044 rows=106390 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7334kB + Buffers: shared read=5252 + I/O Timings: read=92.401 + -> Seq Scan on icstr cr (cost=0.00..6315.90 rows=106390 width=27) (actual time=1.095..107.748 rows=106390 loops=1) + Buffers: shared read=5252 + I/O Timings: read=92.401 + -> CTE Scan on agg a (cost=0.00..36171083952.54 rows=1808554197627 width=1520) (actual time=130217.189..139003.919 rows=809850 loops=1) + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=169623 written=302291 + I/O Timings: read=5796.575 + -> CTE Scan on agg a_1 (cost=0.00..41167214923.48 rows=13564156482 width=1520) (actual time=313.638..4190.172 rows=298727 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Forecast}'::text[]))) + Rows Removed by Filter: 511123 + Buffers: temp read=57871 written=1 + -> CTE Scan on agg a_2 (cost=0.00..41167214923.48 rows=13564156482 width=1520) (actual time=77.645..4240.941 rows=270385 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Budget}'::text[]))) + Rows Removed by Filter: 539465 + Buffers: temp read=57871 + +
+Date: 2019-03-15 14:09:18 +Duration: 2m2s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Append (cost=4510966117154.68..4644894879274.93 rows=1921380827591 width=1520) (actual time=112425.684..121699.211 rows=1378380 loops=1) + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=285302 written=302218 + I/O Timings: read=5431.112 + CTE seg + -> Values Scan on "*VALUES*" (cost=0.00..0.18 rows=14 width=64) (actual time=0.003..0.006 rows=14 loops=1) + CTE mg + -> Values Scan on "*VALUES*_1" (cost=0.00..0.20 rows=16 width=96) (actual time=0.002..0.007 rows=16 loops=1) + CTE repc + -> Hash Left Join (cost=11.47..123.28 rows=120 width=96) (actual time=4.005..11.391 rows=120 loops=1) + Hash Cond: (ltrim(rtrim(c.a9)) = q.qr) + Buffers: shared read=26 + I/O Timings: read=10.590 + -> Bitmap Heap Scan on code c (cost=9.21..118.86 rows=120 width=25) (actual time=3.631..10.743 rows=120 loops=1) + Recheck Cond: (a2 = 'MM'::text) + Heap Blocks: exact=21 + Buffers: shared read=25 + I/O Timings: read=10.256 + -> Bitmap Index Scan on pk_code (cost=0.00..9.18 rows=120 width=0) (actual time=2.484..2.484 rows=120 loops=1) + Index Cond: (a2 = 'MM'::text) + Buffers: shared read=4 + I/O Timings: read=2.398 + -> Hash (cost=1.56..1.56 rows=56 width=12) (actual time=0.359..0.359 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.334 + -> Seq Scan on qrh q (cost=0.00..1.56 rows=56 width=12) (actual time=0.342..0.348 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.334 + CTE md + -> HashAggregate (cost=11936.00..11938.00 rows=200 width=64) (actual time=141.238..141.651 rows=3368 loops=1) + Group Key: (substr(m.avpart, 1, 8)) + Buffers: shared hit=9056 + -> Append (cost=8137.31..11870.54 rows=13091 width=64) (actual time=131.283..140.399 rows=3375 loops=1) + Buffers: shared hit=9056 + -> HashAggregate (cost=8137.31..8249.94 rows=9010 width=64) (actual time=131.282..131.853 rows=3285 loops=1) + Group Key: substr(m.avpart, 1, 8) + Buffers: shared hit=6448 + -> Seq Scan on stkmm m (cost=0.00..8092.26 rows=9010 width=59) (actual time=0.026..38.556 rows=76269 loops=1) + Filter: ((length(avpart) > 8) AND (substr(avgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 4728 + Buffers: shared hit=6448 + -> HashAggregate (cost=3373.23..3424.24 rows=4081 width=64) (actual time=8.321..8.352 rows=90 loops=1) + Group Key: substr(p.awpart, 1, 8) + Buffers: shared hit=2608 + -> Seq Scan on stkmp p (cost=0.00..3352.82 rows=4081 width=52) (actual time=0.446..8.258 rows=142 loops=1) + Filter: ((length(awpart) > 8) AND (substr(awgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 36557 + Buffers: shared hit=2608 + CTE sj + -> Seq Scan on mmsl (cost=0.00..1.84 rows=1 width=22) (actual time=0.004..0.009 rows=11 loops=1) + Filter: (COALESCE(bsmncd, ''::text) = ''::text) + Rows Removed by Filter: 56 + Buffers: shared hit=1 + CTE si + -> Seq Scan on mmsl mmsl_1 (cost=0.00..1.84 rows=66 width=22) (actual time=0.307..0.314 rows=56 loops=1) + Filter: (COALESCE(bsmncd, ''::text) <> ''::text) + Rows Removed by Filter: 11 + Buffers: shared read=1 + I/O Timings: read=0.297 + CTE seas + -> GroupAggregate (cost=10.22..16.31 rows=174 width=41) (actual time=0.068..0.100 rows=15 loops=1) + Group Key: gld.ssyr + Buffers: local hit=2 + -> Sort (cost=10.22..10.65 rows=174 width=16) (actual time=0.054..0.061 rows=174 loops=1) + Sort Key: gld.ssyr DESC + Sort Method: quicksort Memory: 33kB + Buffers: local hit=2 + -> Seq Scan on gld (cost=0.00..3.74 rows=174 width=16) (actual time=0.010..0.030 rows=174 loops=1) + Buffers: local hit=2 + CTE intv + -> CTE Scan on seas (cost=0.00..4.13 rows=87 width=4) (actual time=0.080..0.081 rows=1 loops=1) + Filter: cy + Rows Removed by Filter: 14 + Buffers: local hit=2 + CTE std + -> Nested Loop (cost=0.00..457.62 rows=15138 width=73) (actual time=0.087..0.122 rows=15 loops=1) + Buffers: local hit=2 + -> CTE Scan on intv (cost=0.00..1.74 rows=87 width=4) (actual time=0.081..0.082 rows=1 loops=1) + Buffers: local hit=2 + -> CTE Scan on seas s (cost=0.00..3.48 rows=174 width=41) (actual time=0.000..0.028 rows=15 loops=1) + CTE un + -> Append (cost=50003223.80..255856479.46 rows=330423099 width=697) (actual time=26363.405..56340.259 rows=812398 loops=1) + Buffers: shared hit=32147 read=138860, local hit=5659517 read=1 + I/O Timings: read=5000.713 + -> GroupAggregate (cost=50003223.80..63823292.65 rows=83757993 width=701) (actual time=26363.404..28258.932 rows=212793 loops=1) + Group Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Buffers: shared hit=9063 read=59473, local hit=2563791 read=1 + I/O Timings: read=2714.560 + -> Sort (cost=50003223.80..50212618.79 rows=83757993 width=594) (actual time=26363.369..26503.583 rows=641010 loops=1) + Sort Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Sort Method: quicksort Memory: 352782kB + Buffers: shared hit=9063 read=59473, local hit=2563791 read=1 + I/O Timings: read=2714.560 + -> Hash Left Join (cost=11749.79..16650773.71 rows=83757993 width=594) (actual time=412.849..12408.886 rows=641010 loops=1) + Hash Cond: ((osm.bill_class = l.bill) AND (osm.ship_class = l.ship)) + Buffers: shared hit=9060 read=59473, local hit=2563791 read=1 + I/O Timings: read=2714.560 + -> Hash Left Join (cost=11744.32..10583311.94 rows=83757993 width=583) (actual time=412.362..11595.759 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 8) = md.mold) + Buffers: shared hit=9060 read=59471, local hit=2563791 read=1 + I/O Timings: read=2714.141 + -> Hash Left Join (cost=11737.82..5348430.88 rows=83757993 width=551) (actual time=269.279..10961.881 rows=641010 loops=1) + Hash Cond: (osm.part = p_1.awpart) + Buffers: shared hit=4 read=59471, local hit=2563791 read=1 + I/O Timings: read=2714.141 + -> Nested Loop Left Join (cost=8303.37..5125106.33 rows=83757993 width=527) (actual time=188.919..10630.169 rows=641010 loops=1) + Buffers: shared hit=2 read=56865, local hit=2563791 read=1 + I/O Timings: read=2652.319 + -> Nested Loop Left Join (cost=8303.23..337594.45 rows=4332310 width=455) (actual time=188.914..7884.956 rows=641010 loops=1) + Buffers: shared hit=2 read=56865, local hit=1281897 read=1 + I/O Timings: read=2652.319 + -> Hash Left Join (cost=8303.08..89964.52 rows=224085 width=383) (actual time=188.885..5089.482 rows=641010 loops=1) + Hash Cond: (osm.part = m_1.avpart) + Buffers: shared hit=2 read=56865, local hit=2 + I/O Timings: read=2652.306 + -> Hash Left Join (cost=30.62..81103.81 rows=224085 width=348) (actual time=3.518..4614.841 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 3) = f.f3) + Buffers: shared read=50419, local hit=2 + I/O Timings: read=2511.680 + -> Hash Left Join (cost=6.93..77718.84 rows=224085 width=324) (actual time=2.296..4183.537 rows=641010 loops=1) + Hash Cond: ((substr(osm.part, 16, 1) = mg.f1) AND (osm.ming = mg.ming)) + Buffers: shared read=50410, local hit=2 + I/O Timings: read=2510.588 + -> Hash Left Join (cost=6.37..75750.09 rows=224085 width=292) (actual time=2.277..3733.098 rows=641010 loops=1) + Hash Cond: (osm.glec = seg.glec) + Buffers: shared read=50410, local hit=2 + I/O Timings: read=2510.588 + -> Hash Left Join (cost=5.92..72674.81 rows=224085 width=264) (actual time=2.259..3490.071 rows=641010 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared read=50410, local hit=2 + I/O Timings: read=2510.588 + -> Seq Scan on osmp osm (cost=0.00..69587.73 rows=224085 width=184) (actual time=2.186..3227.306 rows=641010 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = 'b19'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 57051 + Buffers: shared read=50410 + I/O Timings: read=2510.588 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.060..0.060 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=112) (actual time=0.008..0.034 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.014..0.014 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg (cost=0.00..0.28 rows=14 width=64) (actual time=0.005..0.011 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.015..0.015 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.011 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=1.217..1.217 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared read=9 + I/O Timings: read=1.092 + -> Seq Scan on family f (cost=0.00..15.53 rows=653 width=24) (actual time=0.985..1.149 rows=653 loops=1) + Buffers: shared read=9 + I/O Timings: read=1.092 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=185.313..185.313 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=2 read=6446 + I/O Timings: read=140.626 + -> Seq Scan on stkmm m_1 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.508..163.116 rows=80997 loops=1) + Buffers: shared hit=2 read=6446 + I/O Timings: read=140.626 + -> Index Scan using se_dat on gld od (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=641010) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1281895 read=1 + I/O Timings: read=0.013 + -> Index Scan using se_dat on gld rd (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.004 rows=1 loops=641010) + Index Cond: ((osm.adj_requestdate >= sdat) AND (osm.adj_requestdate <= edat)) + Buffers: local hit=1281894 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=80.171..80.171 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2 read=2606 + I/O Timings: read=61.823 + -> Seq Scan on stkmp p_1 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.342..70.937 rows=36699 loops=1) + Buffers: shared hit=2 read=2606 + I/O Timings: read=61.823 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=143.065..143.065 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + Buffers: shared hit=9056 + -> CTE Scan on md (cost=0.00..4.00 rows=200 width=64) (actual time=141.241..142.539 rows=3368 loops=1) + Buffers: shared hit=9056 + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.472..0.472 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=2 + I/O Timings: read=0.418 + -> Seq Scan on ffchnl l (cost=0.00..3.39 rows=139 width=25) (actual time=0.424..0.443 rows=139 loops=1) + Buffers: shared read=2 + I/O Timings: read=0.418 + -> GroupAggregate (cost=33445583.00..42801951.72 rows=56705265 width=699) (actual time=17060.209..18105.019 rows=250477 loops=1) + Group Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Sort (cost=33445583.00..33587346.16 rows=56705265 width=595) (actual time=17060.177..17152.591 rows=406814 loops=1) + Sort Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Sort Method: quicksort Memory: 222052kB + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=11749.79..11025086.80 rows=56705265 width=595) (actual time=160.607..8900.120 rows=406814 loops=1) + Hash Cond: ((osm_1.bill_class = l_1.bill) AND (osm_1.ship_class = l_1.ship)) + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=11744.32..6967724.27 rows=55168846 width=584) (actual time=160.531..8303.160 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 8) = md_1.mold) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=11737.82..3519664.90 rows=55168846 width=552) (actual time=159.458..7928.685 rows=406814 loops=1) + Hash Cond: (osm_1.part = p_2.awpart) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Nested Loop Left Join (cost=8303.37..3371395.52 rows=55168846 width=528) (actual time=139.481..7719.889 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Nested Loop Left Join (cost=8303.23..217901.28 rows=2853561 width=456) (actual time=139.471..5838.942 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=813630 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=8303.08..54789.49 rows=147598 width=384) (actual time=139.449..3929.023 rows=406814 loops=1) + Hash Cond: (osm_1.part = m_2.avpart) + Buffers: shared hit=6457 read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=30.62..46129.57 rows=147598 width=349) (actual time=79.183..3618.398 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 3) = f_1.f3) + Buffers: shared hit=9 read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=6.93..43891.91 rows=147598 width=325) (actual time=78.806..3313.087 rows=406814 loops=1) + Hash Cond: ((substr(osm_1.part, 16, 1) = mg_1.f1) AND (osm_1.ming = mg_1.ming)) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=6.37..42594.49 rows=147598 width=293) (actual time=78.771..2997.016 rows=406814 loops=1) + Hash Cond: (osm_1.glec = seg_1.glec) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=5.92..40564.57 rows=147598 width=265) (actual time=78.706..2840.808 rows=406814 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Seq Scan on osmf osm_1 (cost=0.00..38529.18 rows=147598 width=185) (actual time=78.437..2657.330 rows=406814 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = '5p7'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 358 + Buffers: shared read=26345 + I/O Timings: read=2202.796 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.200..0.200 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=112) (actual time=0.053..0.147 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.039..0.039 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_1 (cost=0.00..0.28 rows=14 width=64) (actual time=0.009..0.015 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.014..0.014 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_1 (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.008 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.350..0.350 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_1 (cost=0.00..15.53 rows=653 width=24) (actual time=0.090..0.194 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=59.937..59.937 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_2 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.021..34.499 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=813628 + -> Index Scan using se_dat on gld rd_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm_1.adj_requestdate >= sdat) AND (osm_1.adj_requestdate <= edat)) + Buffers: local hit=813628 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=19.766..19.766 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_2 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.008..10.901 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=1.056..1.056 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_1 (cost=0.00..4.00 rows=200 width=64) (actual time=0.003..0.385 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.055..0.055 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_1 (cost=0.00..3.39 rows=139 width=25) (actual time=0.007..0.025 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=112931514.84..144274888.60 rows=189959841 width=695) (actual time=8819.747..9896.203 rows=349128 loops=1) + Group Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Buffers: shared hit=14017 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Sort (cost=112931514.84..113406414.44 rows=189959841 width=584) (actual time=8819.714..8895.706 rows=367402 loops=1) + Sort Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Sort Method: quicksort Memory: 201721kB + Buffers: shared hit=14017 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Hash Left Join (cost=11749.79..37465936.67 rows=189959841 width=584) (actual time=50.604..4494.745 rows=367402 loops=1) + Hash Cond: ((osm_2.bill_class = l_2.bill) AND (osm_2.ship_class = l_2.ship)) + Buffers: shared hit=14017 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Hash Left Join (cost=11744.32..23902628.82 rows=189959841 width=574) (actual time=50.549..4122.287 rows=367402 loops=1) + Hash Cond: (substr(osm_2.part, 1, 8) = md_2.mold) + Buffers: shared hit=14015 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Hash Left Join (cost=11737.82..12030132.26 rows=189959841 width=542) (actual time=49.780..3891.847 rows=367402 loops=1) + Hash Cond: (osm_2.part = p_3.awpart) + Buffers: shared hit=14015 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Nested Loop Left Join (cost=8303.37..11527995.69 rows=189959841 width=518) (actual time=34.804..3756.178 rows=367402 loops=1) + Buffers: shared hit=11407 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Nested Loop Left Join (cost=8303.23..670498.91 rows=9825509 width=446) (actual time=34.797..2623.310 rows=367402 loops=1) + Buffers: shared hit=11407 read=53042, local hit=734236 + I/O Timings: read=83.358 + -> Hash Left Join (cost=8303.08..108904.23 rows=508216 width=374) (actual time=34.774..1278.961 rows=367402 loops=1) + Hash Cond: (osm_2.part = m_3.avpart) + Buffers: shared hit=11407 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=30.62..99297.64 rows=508216 width=339) (actual time=0.327..1108.708 rows=367402 loops=1) + Hash Cond: (substr(osm_2.part, 1, 3) = f_2.f3) + Buffers: shared hit=4959 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=6.93..91650.71 rows=508216 width=315) (actual time=0.203..921.418 rows=367402 loops=1) + Hash Cond: ((substr(osm_2.part, 16, 1) = mg_2.f1) AND (osm_2.ming = mg_2.ming)) + Buffers: shared hit=4950 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=6.37..87189.88 rows=508216 width=283) (actual time=0.191..727.591 rows=367402 loops=1) + Hash Cond: (osm_2.glec = seg_2.glec) + Buffers: shared hit=4950 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=5.92..80265.15 rows=508216 width=255) (actual time=0.180..611.979 rows=367402 loops=1) + Hash Cond: (osm_2.fspr = sd_2.fspr) + Buffers: shared hit=4950 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Seq Scan on osm osm_2 (cost=0.00..73663.10 rows=508216 width=175) (actual time=0.106..492.248 rows=367402 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND ((fspr >= '1606'::text) OR (adj_orderdate >= '2016-06-01'::date))) + Rows Removed by Filter: 417370 + Buffers: shared hit=4950 read=53042 + I/O Timings: read=83.358 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.065..0.065 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_2 (cost=0.00..3.74 rows=174 width=112) (actual time=0.018..0.041 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_2 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.003 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.006..0.006 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_2 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.119..0.119 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_2 (cost=0.00..15.53 rows=653 width=24) (actual time=0.014..0.051 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=34.398..34.398 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_3 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.006..21.130 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=367402) + Index Cond: ((osm_2.adj_orderdate >= sdat) AND (osm_2.adj_orderdate <= edat)) + Buffers: local hit=734234 + -> Index Scan using se_dat on gld rd_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.002..0.003 rows=1 loops=367402) + Index Cond: ((osm_2.adj_requestdate >= sdat) AND (osm_2.adj_requestdate <= edat)) + Buffers: local hit=734232 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=14.938..14.938 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_3 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.006..9.060 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=0.757..0.757 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_2 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.289 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.042..0.042 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_2 (cost=0.00..3.39 rows=139 width=25) (actual time=0.006..0.020 rows=139 loops=1) + Buffers: shared hit=2 + CTE agg + -> GroupAggregate (cost=3990139087947.22..4510710248131.84 rows=1892986037035 width=1404) (actual time=112425.677..116271.291 rows=809656 loops=1) + Group Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)), 'Grand Total'::text + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=169586 written=244360 + I/O Timings: read=5431.112 + -> Sort (cost=3990139087947.22..3994871553039.80 rows=1892986037035 width=1346) (actual time=112425.642..112859.948 rows=812398 loops=1) + Sort Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)) + Sort Method: external merge Disk: 475944kB + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=169586 written=244360 + I/O Timings: read=5431.112 + -> Merge Right Join (cost=33563712447.31..265517026370.70 rows=1892986037035 width=1346) (actual time=69370.743..73383.296 rows=812398 loops=1) + Merge Cond: (ss.ssyr = un.sseas) + Buffers: shared hit=35372 read=157188, local hit=5659519 read=1, temp read=110093 written=184866 + I/O Timings: read=5431.112 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.187..0.194 rows=15 loops=1) + Sort Key: ss.ssyr + Sort Method: quicksort Memory: 26kB + Buffers: local hit=2 + -> CTE Scan on std ss (cost=0.00..302.76 rows=15138 width=40) (actual time=0.143..0.183 rows=15 loops=1) + Buffers: local hit=2 + -> Materialize (cost=33563711093.53..33688759715.34 rows=25009724363 width=1300) (actual time=69363.504..70242.785 rows=812398 loops=1) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=110093 written=184866 + I/O Timings: read=5431.112 + -> Sort (cost=33563711093.53..33626235404.44 rows=25009724363 width=1300) (actual time=69363.500..69636.493 rows=812398 loops=1) + Sort Key: un.sseas + Sort Method: external merge Disk: 445936kB + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=110093 written=146616 + I/O Timings: read=5431.112 + -> Merge Right Join (cost=488162845.81..864134844.69 rows=25009724363 width=1300) (actual time=64619.072..67097.961 rows=812398 loops=1) + Merge Cond: (so.ssyr = un.oseas) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=54351 written=90873 + I/O Timings: read=5431.112 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.005..0.009 rows=13 loops=1) + Sort Key: so.ssyr + Sort Method: quicksort Memory: 26kB + -> CTE Scan on std so (cost=0.00..302.76 rows=15138 width=40) (actual time=0.001..0.002 rows=15 loops=1) + -> Materialize (cost=488161492.03..489813607.52 rows=330423099 width=1268) (actual time=64619.055..66543.724 rows=812398 loops=1) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=54351 written=90873 + I/O Timings: read=5431.112 + -> Sort (cost=488161492.03..488987549.77 rows=330423099 width=1268) (actual time=64619.051..65222.574 rows=812398 loops=1) + Sort Key: un.oseas + Sort Method: external merge Disk: 434808kB + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=54351 written=54352 + I/O Timings: read=5431.112 + -> Hash Left Join (cost=30326.40..75489285.22 rows=330423099 width=1268) (actual time=26974.130..61679.511 rows=812398 loops=1) + Hash Cond: ((un.part = cr.y0part) AND (un.plnt = cr.y0plnt)) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1 + I/O Timings: read=5431.112 + -> Hash Left Join (cost=22414.65..56426266.97 rows=330423099 width=1262) (actual time=26803.460..61130.886 rows=812398 loops=1) + Hash Cond: ((un.part = cp.chpart) AND (un.plnt = cp.chplnt)) + Buffers: shared hit=35372 read=151936, local hit=5659517 read=1 + I/O Timings: read=5307.518 + -> Hash Left Join (cost=14299.03..36533966.06 rows=330423099 width=1256) (actual time=26596.173..60544.080 rows=812398 loops=1) + Hash Cond: ((un.part = cm.cgpart) AND (un.plnt = cm.cgplnt)) + Buffers: shared hit=35372 read=146620, local hit=5659517 read=1 + I/O Timings: read=5163.164 + -> Hash Left Join (cost=7433.88..34026391.85 rows=330423099 width=1250) (actual time=26466.230..59938.193 rows=812398 loops=1) + Hash Cond: (un.bill_cust = sc.bvcust) + Buffers: shared hit=35372 read=142113, local hit=5659517 read=1 + I/O Timings: read=5079.788 + -> Hash Left Join (cost=3723.16..29479363.52 rows=330423099 width=1223) (actual time=26455.847..59596.315 rows=812398 loops=1) + Hash Cond: (un.bill_cust = bc.bvcust) + Buffers: shared hit=32148 read=142113, local hit=5659517 read=1 + I/O Timings: read=5079.788 + -> Hash Left Join (cost=12.44..24932335.18 rows=330423099 width=1196) (actual time=26376.451..59161.607 rows=812398 loops=1) + Hash Cond: ((un.ming = mmgp.brmgrp) AND (un.majg = mmgp.brgrp)) + Buffers: shared hit=32148 read=138889, local hit=5659517 read=1 + I/O Timings: read=5012.664 + -> Hash Left Join (cost=7.51..15006668.18 rows=330423099 width=1186) (actual time=26375.626..58843.583 rows=812398 loops=1) + Hash Cond: (un.majg = majg.bqgrp) + Buffers: shared hit=32148 read=138888, local hit=5659517 read=1 + I/O Timings: read=5011.904 + -> Hash Left Join (cost=6.24..13569326.43 rows=330423099 width=1176) (actual time=26375.306..58564.379 rows=812398 loops=1) + Hash Cond: (un.majs = sj.bsmjcd) + Buffers: shared hit=32148 read=138887, local hit=5659517 read=1 + I/O Timings: read=5011.601 + -> Hash Left Join (cost=6.21..12313718.62 rows=330423099 width=1144) (actual time=26375.285..58278.120 rows=812398 loops=1) + Hash Cond: ((un.majs = si.bsmjcd) AND (un.mins = si.bsmncd)) + Buffers: shared hit=32147 read=138887, local hit=5659517 read=1 + I/O Timings: read=5011.601 + -> Hash Left Join (cost=3.90..9830091.09 rows=330423099 width=1112) (actual time=26374.932..57946.951 rows=812398 loops=1) + Hash Cond: (un.quota_rep = repc.rcode) + Buffers: shared hit=32147 read=138886, local hit=5659517 read=1 + I/O Timings: read=5011.303 + -> CTE Scan on un (cost=0.00..6608461.98 rows=330423099 width=1048) (actual time=26363.408..57457.121 rows=812398 loops=1) + Buffers: shared hit=32147 read=138860, local hit=5659517 read=1 + I/O Timings: read=5000.713 + -> Hash (cost=2.40..2.40 rows=120 width=96) (actual time=11.512..11.512 rows=120 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 17kB + Buffers: shared read=26 + I/O Timings: read=10.590 + -> CTE Scan on repc (cost=0.00..2.40 rows=120 width=96) (actual time=4.008..11.473 rows=120 loops=1) + Buffers: shared read=26 + I/O Timings: read=10.590 + -> Hash (cost=1.32..1.32 rows=66 width=96) (actual time=0.343..0.343 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.297 + -> CTE Scan on si (cost=0.00..1.32 rows=66 width=96) (actual time=0.310..0.330 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.297 + -> Hash (cost=0.02..0.02 rows=1 width=64) (actual time=0.014..0.014 rows=11 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=1 + -> CTE Scan on sj (cost=0.00..0.02 rows=1 width=64) (actual time=0.006..0.012 rows=11 loops=1) + Buffers: shared hit=1 + -> Hash (cost=1.12..1.12 rows=12 width=14) (actual time=0.316..0.316 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared read=1 + I/O Timings: read=0.303 + -> Seq Scan on majg (cost=0.00..1.12 rows=12 width=14) (actual time=0.309..0.310 rows=12 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.303 + -> Hash (cost=2.57..2.57 rows=157 width=18) (actual time=0.818..0.818 rows=157 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=1 + I/O Timings: read=0.760 + -> Seq Scan on mmgp (cost=0.00..2.57 rows=157 width=18) (actual time=0.771..0.787 rows=157 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.760 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=79.377..79.377 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared read=3224 + I/O Timings: read=67.124 + -> Seq Scan on cust bc (cost=0.00..3440.32 rows=21632 width=35) (actual time=1.226..74.190 rows=21632 loops=1) + Buffers: shared read=3224 + I/O Timings: read=67.124 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=10.361..10.361 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared hit=3224 + -> Seq Scan on cust sc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.007..6.549 rows=21632 loops=1) + Buffers: shared hit=3224 + -> Hash (cost=5450.26..5450.26 rows=94326 width=29) (actual time=129.891..129.891 rows=94326 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6699kB + Buffers: shared read=4507 + I/O Timings: read=83.376 + -> Seq Scan on icstm cm (cost=0.00..5450.26 rows=94326 width=29) (actual time=1.628..106.590 rows=94326 loops=1) + Buffers: shared read=4507 + I/O Timings: read=83.376 + -> Hash (cost=6435.85..6435.85 rows=111985 width=20) (actual time=207.238..207.238 rows=111985 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6768kB + Buffers: shared read=5316 + I/O Timings: read=144.354 + -> Seq Scan on icstp cp (cost=0.00..6435.85 rows=111985 width=20) (actual time=12.877..174.296 rows=111985 loops=1) + Buffers: shared read=5316 + I/O Timings: read=144.354 + -> Hash (cost=6315.90..6315.90 rows=106390 width=27) (actual time=167.190..167.190 rows=106390 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7334kB + Buffers: shared read=5252 + I/O Timings: read=123.594 + -> Seq Scan on icstr cr (cost=0.00..6315.90 rows=106390 width=27) (actual time=1.618..138.920 rows=106390 loops=1) + Buffers: shared read=5252 + I/O Timings: read=123.594 + -> CTE Scan on agg a (cost=0.00..37859720740.70 rows=1892986037035 width=1520) (actual time=112425.683..119325.832 rows=809656 loops=1) + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=169586 written=302217 + I/O Timings: read=5431.112 + -> CTE Scan on agg a_1 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=10.640..1070.930 rows=298533 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Forecast}'::text[]))) + Rows Removed by Filter: 511123 + Buffers: temp read=57858 written=1 + -> CTE Scan on agg a_2 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=24.901..1109.287 rows=270191 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Budget}'::text[]))) + Rows Removed by Filter: 539465 + Buffers: temp read=57858 + +
++ + +3 +5m27s +37 + + +2s217ms +27s560ms +8s855ms ++ +--create INDEX flag ON gld(plan, rolling); WITH un AS ( SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osmf osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.glec,?,?) <= ? AND substr(osm.fs_line,?,?) = ? AND calc_status <> ? AND ( --all orders OR shipments FOR the period ( --current year TO date orders od.cy = ? --current year TO date shipments OR sd.cy = ? ) OR --open orders sd.cm = ? --this works FOR forecast it indicates a future fspr ) GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) UNION ALL SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osm osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.fs_line,?,?) = ? AND substr(osm.glec,?,?) <= ? AND calc_status <> ? AND ( --all ORDER OR shipments FOR the period ( --current year TO date orders od.cy = ? --current year TO date shipments OR sd.cy = ? ) OR --open orders (calc_status IN (...) AND flag = ?) ) GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ) SELECT srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ,sum(qty) units ,sum(stdcost) "cost" ,sum(sales) sales FROM un GROUP BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ORDER BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ; ++ +++Times Reported Time consuming queries #3
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 17 17 2m29s 8s786ms Mar 15 00 5 58s394ms 11s678ms 17 5 1m2s 12s403ms + +Mar 18 10 10 57s886ms 5s788ms ++ + + +-
+
+
[ User: report - Total duration: 1m37s - Times executed: 7 ] +
+ +++ + + +-
+
+
[ Application: [unknown] - Total duration: 1m37s - Times executed: 7 ] +
+ +++ +-
+
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
Date: 2019-03-14 17:15:07 +Duration: 27s560ms +
+ +++ + +Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.033..24368.549 rows=190996 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 227 + Buffers: shared hit=12201 + +
+Date: 2019-03-14 17:15:07 +Duration: 27s559ms +
+ +++ + +Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.018..23110.458 rows=167047 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 120 + Buffers: shared hit=10779 + +
+Date: 2019-03-15 17:30:39 +Duration: 21s242ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=99922.38..99922.88 rows=200 width=232) (actual time=21211.683..21211.708 rows=317 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 69kB + Buffers: shared hit=4 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + CTE un + -> Append (cost=32534.94..99887.14 rows=502 width=232) (actual time=5942.671..21209.531 rows=317 loops=1) + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + -> GroupAggregate (cost=32534.94..32547.80 rows=245 width=232) (actual time=5942.670..6367.056 rows=197 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Sort (cost=32534.94..32535.55 rows=245 width=185) (actual time=5942.642..5990.837 rows=406814 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 69497kB + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Nested Loop (cost=1006.06..32525.21 rows=245 width=185) (actual time=3.834..5526.120 rows=406814 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Hash Left Join (cost=1005.91..31588.56 rows=738 width=113) (actual time=3.809..3558.965 rows=406814 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared read=26345 written=122, local hit=2 + I/O Timings: read=10489.166 write=1.431 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=3.660..3400.209 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared read=26345 written=122 + I/O Timings: read=10489.166 write=1.431 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.781..3631.234 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared read=26345 written=122 + I/O Timings: read=10489.166 write=1.431 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.083..0.083 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.013..0.049 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=813627 read=1 + I/O Timings: read=0.006 + -> GroupAggregate (cost=67318.31..67331.81 rows=257 width=232) (actual time=14757.926..14842.413 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Sort (cost=67318.31..67318.96 rows=257 width=178) (actual time=14757.905..14766.226 rows=94732 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16394kB + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Nested Loop (cost=1006.06..67308.03 rows=257 width=178) (actual time=65.185..14658.975 rows=94732 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Hash Left Join (cost=1005.91..65849.40 rows=1114 width=122) (actual time=65.171..12232.663 rows=628518 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=1 read=57991 written=2, local hit=2 + I/O Timings: read=37441.627 write=0.074 + -> Gather (cost=1000.00..65829.04 rows=1114 width=51) (actual time=65.104..11994.997 rows=628518 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=1 read=57991 written=2 + I/O Timings: read=37441.627 write=0.074 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..64717.64 rows=464 width=51) (actual time=56.186..12707.976 rows=209506 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52157 + Buffers: shared hit=1 read=57991 written=2 + I/O Timings: read=37441.627 write=0.074 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.055..0.055 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.009..0.031 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=628518) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1255196 + -> HashAggregate (cost=25.10..27.60 rows=200 width=232) (actual time=21210.361..21210.698 rows=317 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + -> CTE Scan on un (cost=0.00..10.04 rows=502 width=232) (actual time=5942.675..21209.793 rows=317 loops=1) + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + +
++ + +4 +1m33s +9 + + +2s718ms +25s847ms +10s409ms ++ +--create INDEX flag ON gld(plan, rolling); WITH un AS ( SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osmp osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.glec,?,?) <= ? AND substr(osm.fs_line,?,?) = ? AND calc_status <> ? --open orders AND sd.cm = ? --this works FOR forecast it indicates a future fspr GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) UNION ALL SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osm osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON greatest(osm.adj_requestdate,current_date) BETWEEN sd.sdat AND sd.edat WHERE substr(osm.fs_line,?,?) = ? AND substr(osm.glec,?,?) <= ? AND calc_status IN (...) AND flag = ? GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ) SELECT srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ,sum(qty) units ,sum(stdcost) "cost" ,sum(sales) sales FROM un WHERE om <> ? GROUP BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ORDER BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ; ++ +++Times Reported Time consuming queries #4
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 17 5 50s600ms 10s120ms Mar 15 00 3 17s236ms 5s745ms + +17 1 25s847ms 25s847ms ++ + + +-
+
+
[ User: report - Total duration: 1m18s - Times executed: 5 ] +
+ +++ + + +-
+
+
[ Application: [unknown] - Total duration: 1m18s - Times executed: 5 ] +
+ +++ +-
+
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
Date: 2019-03-15 17:30:45 +Duration: 25s847ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=113023.45..113023.95 rows=200 width=232) (actual time=25846.751..25846.759 rows=129 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=20260 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + CTE un + -> Append (cost=46404.12..112987.32 rows=496 width=232) (actual time=25114.996..25846.141 rows=151 loops=1) + Buffers: shared hit=20257 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + -> GroupAggregate (cost=46404.12..46410.90 rows=129 width=232) (actual time=25114.995..25208.334 rows=81 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=20125 read=37204 written=3367, local hit=211099 read=1 + I/O Timings: read=23025.573 write=75.759 + -> Sort (cost=46404.12..46404.45 rows=129 width=182) (actual time=25114.970..25120.224 rows=105549 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 17915kB + Buffers: shared hit=20125 read=37204 written=3367, local hit=211099 read=1 + I/O Timings: read=23025.573 write=75.759 + -> Nested Loop (cost=1445.79..46399.60 rows=129 width=182) (actual time=37.452..24985.218 rows=105549 loops=1) + Buffers: shared hit=20125 read=37204 written=3367, local hit=211099 read=1 + I/O Timings: read=23025.573 write=75.759 + -> Nested Loop (cost=1445.65..46391.77 rows=7 width=110) (actual time=37.425..24330.405 rows=105573 loops=1) + Buffers: shared hit=20125 read=37204 written=3367, local hit=2 + I/O Timings: read=23025.565 write=75.759 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.021..0.037 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Bitmap Heap Scan on osmp osm (cost=1445.65..46387.13 rows=46 width=39) (actual time=1.955..638.928 rows=2778 loops=38) + Recheck Cond: (fspr = sd.fspr) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 70 + Heap Blocks: exact=56851 + Buffers: shared hit=20125 read=37204 written=3367 + I/O Timings: read=23025.565 write=75.759 + -> Bitmap Index Scan on osmp_fspr (cost=0.00..1445.64 rows=27895 width=0) (actual time=1.650..1.650 rows=2848 loops=38) + Index Cond: (fspr = sd.fspr) + Buffers: shared hit=108 read=370 written=62 + I/O Timings: read=51.006 write=0.514 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=105573) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=211097 read=1 + I/O Timings: read=0.008 + -> GroupAggregate (cost=66549.72..66568.99 rows=367 width=232) (actual time=630.211..637.789 rows=70 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=132 read=57866, local hit=10350 + I/O Timings: read=298.856 + -> Sort (cost=66549.72..66550.64 rows=367 width=178) (actual time=630.192..630.748 rows=5174 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 920kB + Buffers: shared hit=132 read=57866, local hit=10350 + I/O Timings: read=298.856 + -> Nested Loop (cost=1004.74..66534.08 rows=367 width=178) (actual time=593.533..627.538 rows=5174 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 895102 + Buffers: shared hit=132 read=57866, local hit=10350 + I/O Timings: read=298.856 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.013..0.081 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..66472.54 rows=19 width=106) (actual time=0.030..3.144 rows=5174 loops=174) + Buffers: shared hit=132 read=57866, local hit=10348 + I/O Timings: read=298.856 + -> Nested Loop Left Join (cost=1004.74..66472.44 rows=19 width=106) (actual time=5.277..509.890 rows=5174 loops=1) + Buffers: shared hit=132 read=57866, local hit=10348 + I/O Timings: read=298.856 + -> Gather (cost=1000.00..66465.04 rows=1 width=34) (actual time=5.247..458.234 rows=5174 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=132 read=57866 + I/O Timings: read=298.856 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..65464.94 rows=1 width=34) (actual time=1.669..482.765 rows=1725 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259938 + Buffers: shared hit=132 read=57866 + I/O Timings: read=298.856 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.009..0.009 rows=1 loops=5174) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5174 + Buffers: local hit=10348 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.007..0.007 rows=1 loops=5174) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5174 + -> HashAggregate (cost=25.98..28.48 rows=200 width=232) (actual time=25846.428..25846.522 rows=129 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=20257 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + -> CTE Scan on un (cost=0.00..11.16 rows=494 width=232) (actual time=25115.000..25846.302 rows=129 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=20257 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + +
+Date: 2019-03-14 17:09:40 +Duration: 23s808ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=113712.54..113713.04 rows=200 width=232) (actual time=23807.981..23807.985 rows=128 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=24173 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + CTE un + -> Append (cost=46404.12..113676.42 rows=496 width=232) (actual time=20688.511..23807.529 rows=150 loops=1) + Buffers: shared hit=24170 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + -> GroupAggregate (cost=46404.12..46410.90 rows=129 width=232) (actual time=20688.510..20789.478 rows=81 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=21002 read=36327, local hit=211099 read=1 + I/O Timings: read=18300.701 + -> Sort (cost=46404.12..46404.45 rows=129 width=182) (actual time=20688.486..20694.576 rows=105549 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 17915kB + Buffers: shared hit=21002 read=36327, local hit=211099 read=1 + I/O Timings: read=18300.701 + -> Nested Loop (cost=1445.79..46399.60 rows=129 width=182) (actual time=37.496..20515.988 rows=105549 loops=1) + Buffers: shared hit=21002 read=36327, local hit=211099 read=1 + I/O Timings: read=18300.701 + -> Nested Loop (cost=1445.65..46391.77 rows=7 width=110) (actual time=37.467..19809.839 rows=105573 loops=1) + Buffers: shared hit=21002 read=36327, local hit=2 + I/O Timings: read=18300.692 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.020..0.038 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Bitmap Heap Scan on osmp osm (cost=1445.65..46387.13 rows=46 width=39) (actual time=2.140..520.028 rows=2778 loops=38) + Recheck Cond: (fspr = sd.fspr) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 70 + Heap Blocks: exact=56851 + Buffers: shared hit=21002 read=36327 + I/O Timings: read=18300.692 + -> Bitmap Index Scan on osmp_fspr (cost=0.00..1445.64 rows=27895 width=0) (actual time=1.908..1.908 rows=2848 loops=38) + Index Cond: (fspr = sd.fspr) + Buffers: shared hit=110 read=368 + I/O Timings: read=57.208 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=105573) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=211097 read=1 + I/O Timings: read=0.009 + -> GroupAggregate (cost=67238.81..67258.08 rows=367 width=232) (actual time=3013.320..3018.033 rows=69 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=3168 read=54830, local hit=10926 + I/O Timings: read=7983.465 + -> Sort (cost=67238.81..67239.73 rows=367 width=178) (actual time=3013.300..3013.513 rows=5462 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 961kB + Buffers: shared hit=3168 read=54830, local hit=10926 + I/O Timings: read=7983.465 + -> Nested Loop (cost=1004.74..67223.18 rows=367 width=178) (actual time=2972.945..3010.611 rows=5462 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 944926 + Buffers: shared hit=3168 read=54830, local hit=10926 + I/O Timings: read=7983.465 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.017..0.072 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..67161.63 rows=19 width=106) (actual time=13.102..16.813 rows=5462 loops=174) + Buffers: shared hit=3168 read=54830, local hit=10924 + I/O Timings: read=7983.465 + -> Nested Loop Left Join (cost=1004.74..67161.54 rows=19 width=106) (actual time=2279.747..2880.350 rows=5462 loops=1) + Buffers: shared hit=3168 read=54830, local hit=10924 + I/O Timings: read=7983.465 + -> Gather (cost=1000.00..67154.13 rows=1 width=34) (actual time=2279.720..2819.147 rows=5462 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=3168 read=54830 + I/O Timings: read=7983.465 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..66154.03 rows=1 width=34) (actual time=2269.482..2837.169 rows=1821 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259313 + Buffers: shared hit=3168 read=54830 + I/O Timings: read=7983.465 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.008..0.008 rows=1 loops=5462) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5462 + Buffers: local hit=10924 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.007..0.007 rows=1 loops=5462) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5462 + -> HashAggregate (cost=25.98..28.48 rows=200 width=232) (actual time=23807.814..23807.857 rows=128 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=24170 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + -> CTE Scan on un (cost=0.00..11.16 rows=494 width=232) (actual time=20688.515..23807.691 rows=128 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=24170 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + +
+Date: 2019-03-14 17:21:12 +Duration: 18s342ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=113712.54..113713.04 rows=200 width=232) (actual time=18341.790..18341.795 rows=128 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=24593 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + CTE un + -> Append (cost=46404.12..113676.42 rows=496 width=232) (actual time=17686.530..18341.413 rows=150 loops=1) + Buffers: shared hit=24590 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + -> GroupAggregate (cost=46404.12..46410.90 rows=129 width=232) (actual time=17686.530..17780.512 rows=81 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=20982 read=36347, local hit=211099 read=1 + I/O Timings: read=16170.335 + -> Sort (cost=46404.12..46404.45 rows=129 width=182) (actual time=17686.507..17691.642 rows=105549 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 17915kB + Buffers: shared hit=20982 read=36347, local hit=211099 read=1 + I/O Timings: read=16170.335 + -> Nested Loop (cost=1445.79..46399.60 rows=129 width=182) (actual time=336.691..17577.973 rows=105549 loops=1) + Buffers: shared hit=20982 read=36347, local hit=211099 read=1 + I/O Timings: read=16170.335 + -> Nested Loop (cost=1445.65..46391.77 rows=7 width=110) (actual time=336.406..17026.558 rows=105573 loops=1) + Buffers: shared hit=20982 read=36347, local hit=2 + I/O Timings: read=16170.091 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.019..0.035 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Bitmap Heap Scan on osmp osm (cost=1445.65..46387.13 rows=46 width=39) (actual time=9.729..447.136 rows=2778 loops=38) + Recheck Cond: (fspr = sd.fspr) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 70 + Heap Blocks: exact=56851 + Buffers: shared hit=20982 read=36347 + I/O Timings: read=16170.091 + -> Bitmap Index Scan on osmp_fspr (cost=0.00..1445.64 rows=27895 width=0) (actual time=6.416..6.416 rows=2848 loops=38) + Index Cond: (fspr = sd.fspr) + Buffers: shared hit=110 read=368 + I/O Timings: read=223.920 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=105573) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=211097 read=1 + I/O Timings: read=0.244 + -> GroupAggregate (cost=67238.81..67258.08 rows=367 width=232) (actual time=556.403..560.886 rows=69 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=3608 read=54390, local hit=10926 + I/O Timings: read=210.804 + -> Sort (cost=67238.81..67239.73 rows=367 width=178) (actual time=556.386..556.605 rows=5462 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 961kB + Buffers: shared hit=3608 read=54390, local hit=10926 + I/O Timings: read=210.804 + -> Nested Loop (cost=1004.74..67223.18 rows=367 width=178) (actual time=518.705..553.668 rows=5462 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 944926 + Buffers: shared hit=3608 read=54390, local hit=10926 + I/O Timings: read=210.804 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.013..0.055 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..67161.63 rows=19 width=106) (actual time=2.013..2.722 rows=5462 loops=174) + Buffers: shared hit=3608 read=54390, local hit=10924 + I/O Timings: read=210.804 + -> Nested Loop Left Join (cost=1004.74..67161.54 rows=19 width=106) (actual time=350.244..437.677 rows=5462 loops=1) + Buffers: shared hit=3608 read=54390, local hit=10924 + I/O Timings: read=210.804 + -> Gather (cost=1000.00..67154.13 rows=1 width=34) (actual time=350.219..407.718 rows=5462 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=3608 read=54390 + I/O Timings: read=210.804 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..66154.03 rows=1 width=34) (actual time=333.708..384.567 rows=1821 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259313 + Buffers: shared hit=3608 read=54390 + I/O Timings: read=210.804 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=5462) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5462 + Buffers: local hit=10924 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.004..0.004 rows=1 loops=5462) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5462 + -> HashAggregate (cost=25.98..28.48 rows=200 width=232) (actual time=18341.605..18341.654 rows=128 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=24590 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + -> CTE Scan on un (cost=0.00..11.16 rows=494 width=232) (actual time=17686.534..18341.509 rows=128 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=24590 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + +
++ + +5 +44s960ms +10 + + +3s112ms +8s419ms +4s496ms ++ +--create INDEX flag ON gld(plan, rolling); WITH un AS ( SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osmp osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.glec,?,?) <= ? AND substr(osm.fs_line,?,?) = ? AND calc_status <> ? AND ( --all orders OR shipments FOR the period ( --current year TO date orders od.cy = ? --current year TO date shipments OR sd.cy = ? ) OR --open orders sd.cm = ? --this works FOR forecast it indicates a future fspr ) GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) UNION ALL SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osm osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.fs_line,?,?) = ? AND substr(osm.glec,?,?) <= ? AND calc_status <> ? AND ( --all ORDER OR shipments FOR the period ( --current year TO date orders od.cy = ? --current year TO date shipments OR sd.cy = ? ) OR --open orders (calc_status IN (...) AND flag = ?) ) GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ) SELECT srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ,sum(qty) units ,sum(stdcost) "cost" ,sum(sales) sales FROM un GROUP BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ORDER BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ; ++ +++Times Reported Time consuming queries #5
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 18 09 10 44s960ms 4s496ms ++ + + +-
+
+
[ User: report - Total duration: 16s549ms - Times executed: 2 ] +
+ +++ + + +-
+
+
[ Application: [unknown] - Total duration: 16s549ms - Times executed: 2 ] +
+ +++ +-
+
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
Date: 2019-03-18 09:26:51 +Duration: 8s419ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=126971.98..126972.48 rows=200 width=232) (actual time=8418.853..8418.865 rows=323 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 70kB + Buffers: shared hit=5 read=108400, local hit=2604991 read=1 + I/O Timings: read=3855.140 + CTE un + -> Append (cost=59568.08..126929.73 rows=642 width=232) (actual time=4498.390..8417.556 rows=323 loops=1) + Buffers: shared hit=2 read=108400, local hit=2604991 read=1 + I/O Timings: read=3855.140 + -> GroupAggregate (cost=59568.08..59588.30 rows=385 width=232) (actual time=4498.389..5166.228 rows=203 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=1 read=50409, local hit=1349793 read=1 + I/O Timings: read=2445.383 + -> Sort (cost=59568.08..59569.05 rows=385 width=182) (actual time=4498.367..4585.150 rows=640948 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 114710kB + Buffers: shared hit=1 read=50409, local hit=1349793 read=1 + I/O Timings: read=2445.383 + -> Nested Loop (cost=1006.06..59551.55 rows=385 width=182) (actual time=1.902..3949.029 rows=640948 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Rows Removed by Join Filter: 33948 + Buffers: shared hit=1 read=50409, local hit=1349793 read=1 + I/O Timings: read=2445.383 + -> Hash Left Join (cost=1005.91..58085.96 rows=1162 width=110) (actual time=1.882..1591.245 rows=674964 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=1 read=50409, local hit=2 + I/O Timings: read=2445.379 + -> Gather (cost=1000.00..58064.06 rows=1162 width=39) (actual time=1.801..1402.607 rows=674964 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=1 read=50409 + I/O Timings: read=2445.379 + -> Parallel Seq Scan on osmp osm (cost=0.00..56947.86 rows=484 width=39) (actual time=6.288..971.309 rows=224988 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 7699 + Buffers: shared hit=1 read=50409 + I/O Timings: read=2445.379 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.066..0.066 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.009..0.036 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=674964) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1349791 read=1 + I/O Timings: read=0.005 + -> GroupAggregate (cost=67318.31..67331.81 rows=257 width=232) (actual time=3164.534..3251.283 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=1 read=57991, local hit=1255198 + I/O Timings: read=1409.756 + -> Sort (cost=67318.31..67318.96 rows=257 width=178) (actual time=3164.500..3172.177 rows=94732 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16394kB + Buffers: shared hit=1 read=57991, local hit=1255198 + I/O Timings: read=1409.756 + -> Nested Loop (cost=1006.06..67308.03 rows=257 width=178) (actual time=8.854..3088.890 rows=94732 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=1 read=57991, local hit=1255198 + I/O Timings: read=1409.756 + -> Hash Left Join (cost=1005.91..65849.40 rows=1114 width=122) (actual time=8.837..1127.273 rows=628518 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=1 read=57991, local hit=2 + I/O Timings: read=1409.756 + -> Gather (cost=1000.00..65829.04 rows=1114 width=51) (actual time=8.721..913.379 rows=628518 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=1 read=57991 + I/O Timings: read=1409.756 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..64717.64 rows=464 width=51) (actual time=5.247..636.800 rows=209506 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52157 + Buffers: shared hit=1 read=57991 + I/O Timings: read=1409.756 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.068..0.068 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.018..0.042 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=628518) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1255196 + -> HashAggregate (cost=32.10..34.60 rows=200 width=232) (actual time=8418.331..8418.469 rows=323 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=2 read=108400, local hit=2604991 read=1 + I/O Timings: read=3855.140 + -> CTE Scan on un (cost=0.00..12.84 rows=642 width=232) (actual time=4498.393..8417.842 rows=323 loops=1) + Buffers: shared hit=2 read=108400, local hit=2604991 read=1 + I/O Timings: read=3855.140 + +
+Date: 2019-03-18 09:27:40 +Duration: 8s130ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=126971.98..126972.48 rows=200 width=232) (actual time=8129.861..8129.875 rows=323 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 70kB + Buffers: shared hit=239 read=108163, local hit=2604991 read=1 + I/O Timings: read=247.658 + CTE un + -> Append (cost=59568.08..126929.73 rows=642 width=232) (actual time=4183.799..8128.440 rows=323 loops=1) + Buffers: shared hit=239 read=108163, local hit=2604991 read=1 + I/O Timings: read=247.658 + -> GroupAggregate (cost=59568.08..59588.30 rows=385 width=232) (actual time=4183.798..4870.543 rows=203 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=113 read=50297, local hit=1349793 read=1 + I/O Timings: read=119.690 + -> Sort (cost=59568.08..59569.05 rows=385 width=182) (actual time=4183.776..4278.632 rows=640948 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 114710kB + Buffers: shared hit=113 read=50297, local hit=1349793 read=1 + I/O Timings: read=119.690 + -> Nested Loop (cost=1006.06..59551.55 rows=385 width=182) (actual time=1.055..3609.932 rows=640948 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Rows Removed by Join Filter: 33948 + Buffers: shared hit=113 read=50297, local hit=1349793 read=1 + I/O Timings: read=119.690 + -> Hash Left Join (cost=1005.91..58085.96 rows=1162 width=110) (actual time=1.036..1145.096 rows=674964 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=113 read=50297, local hit=2 + I/O Timings: read=119.684 + -> Gather (cost=1000.00..58064.06 rows=1162 width=39) (actual time=0.966..952.386 rows=674964 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=113 read=50297 + I/O Timings: read=119.684 + -> Parallel Seq Scan on osmp osm (cost=0.00..56947.86 rows=484 width=39) (actual time=0.027..208.907 rows=224988 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 7699 + Buffers: shared hit=113 read=50297 + I/O Timings: read=119.684 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.062..0.062 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.007..0.035 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=674964) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1349791 read=1 + I/O Timings: read=0.006 + -> GroupAggregate (cost=67318.31..67331.81 rows=257 width=232) (actual time=3170.956..3257.844 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=126 read=57866, local hit=1255198 + I/O Timings: read=127.968 + -> Sort (cost=67318.31..67318.96 rows=257 width=178) (actual time=3170.933..3179.265 rows=94732 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16394kB + Buffers: shared hit=126 read=57866, local hit=1255198 + I/O Timings: read=127.968 + -> Nested Loop (cost=1006.06..67308.03 rows=257 width=178) (actual time=1.140..3098.754 rows=94732 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=126 read=57866, local hit=1255198 + I/O Timings: read=127.968 + -> Hash Left Join (cost=1005.91..65849.40 rows=1114 width=122) (actual time=1.106..1185.199 rows=628518 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=126 read=57866, local hit=2 + I/O Timings: read=127.968 + -> Gather (cost=1000.00..65829.04 rows=1114 width=51) (actual time=1.044..983.106 rows=628518 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=126 read=57866 + I/O Timings: read=127.968 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..64717.64 rows=464 width=51) (actual time=0.044..218.820 rows=209506 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52157 + Buffers: shared hit=126 read=57866 + I/O Timings: read=127.968 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.052..0.052 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.006..0.029 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=628518) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1255196 + -> HashAggregate (cost=32.10..34.60 rows=200 width=232) (actual time=8129.291..8129.422 rows=323 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=239 read=108163, local hit=2604991 read=1 + I/O Timings: read=247.658 + -> CTE Scan on un (cost=0.00..12.84 rows=642 width=232) (actual time=4183.801..8128.793 rows=323 loops=1) + Buffers: shared hit=239 read=108163, local hit=2604991 read=1 + I/O Timings: read=247.658 + +
+Date: 2019-03-18 09:26:47 +Duration: 4s142ms +
+ +++ + +Parallel Seq Scan on osmp osm (cost=0.00..56947.86 rows=484 width=39) (actual time=9.803..884.885 rows=131112 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 5198 + Buffers: shared read=10827 + I/O Timings: read=792.174 + +
++ + +6 +16s934ms +7 + + +1s357ms +3s762ms +2s419ms ++ +--\timing --explain (ANALYZE, buffers) WITH mseq AS ( SELECT * FROM ( VALUES (?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ) x(m,s) ) --select * FROM mseq ,base AS ( SELECT order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ,sum(units) units ,sum(value_usd) value_usd FROM rlarp.osm_fcpool WHERE quota_rep_descr = ? AND segm = ? AND mod_chan = ? AND part_descr = ? GROUP BY order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ) ,months AS ( SELECT order_season ,version ,iter ,order_month ,mseq.s seq ,sum(units) units ,sum(value_usd) value_usd FROM base INNER JOIN mseq ON mseq.m = base.order_month GROUP BY order_season ,version ,iter ,order_month ,s ) ,mpvt AS ( SELECT order_month ,seq ,sum(units) filter (WHERE order_season = ?) "? qty" ,sum(units) filter (WHERE order_season = ? AND iter = ?) "? base qty" ,sum(units) filter (WHERE order_season = ? AND iter <> ?) "? adj qty" ,sum(units) filter (WHERE order_season = ?) "? tot qty" ,sum(value_usd) filter (WHERE order_season = ?) "? value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter = ?) "? base value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter <> ?) "? adj value_usd" ,sum(value_usd) filter (WHERE order_season = ?) "? tot value_usd" FROM months GROUP BY order_month ,seq ORDER BY seq ASC ) ,mlist AS ( SELECT mseq.m order_month ,"? qty" ,"? base qty" ,"? adj qty" ,"? tot qty" ,"? value_usd" ,"? base value_usd" ,"? adj value_usd" ,"? tot value_usd" FROM mseq LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m ORDER BY mseq.s ASC ) ,totals AS ( SELECT order_season ,version ,iter ,sum(units) units ,sum(value_usd) value_usd FROM months GROUP BY order_season ,version ,iter ) SELECT jsonb_build_object( ? ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) ,? ,(SELECT jsonb_agg(row_to_json(mlist)::jsonb) FROM mlist) ,? ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) ,? ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) ) package ; ++ +++Times Reported Time consuming queries #6
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 15 15 3 11s264ms 3s754ms + +16 4 5s669ms 1s417ms ++ + + +-
+
+
[ User: api - Total duration: 6s706ms - Times executed: 3 ] +
+ +++ + + +-
+
+
[ Application: osm_api - Total duration: 6s706ms - Times executed: 3 ] +
+ +++ +-
+
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
Date: 2019-03-15 15:01:25 +Duration: 3s762ms +Database: ubm +User: api +Remote: ubreport +Application: osm_api +
+ +++ + +Result (cost=43058.76..43058.77 rows=1 width=32) (actual time=3759.847..3759.850 rows=1 loops=1) + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + CTE mseq + -> Values Scan on "*VALUES*" (cost=0.00..0.15 rows=12 width=36) (actual time=0.001..0.007 rows=12 loops=1) + CTE base + -> GroupAggregate (cost=43056.99..43057.03 rows=1 width=176) (actual time=3758.393..3758.433 rows=43 loops=1) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> Sort (cost=43056.99..43056.99 rows=1 width=149) (actual time=3758.380..3758.383 rows=72 loops=1) + Sort Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Sort Method: quicksort Memory: 44kB + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> Gather (cost=1000.00..43056.97 rows=1 width=149) (actual time=175.512..3758.230 rows=72 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=169.788..3752.390 rows=24 loops=3) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 100422 + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + CTE months + -> HashAggregate (cost=0.35..0.36 rows=1 width=152) (actual time=3758.529..3758.536 rows=17 loops=1) + Group Key: base.order_season, base.version, base.iter, base.order_month, mseq.s + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> Hash Join (cost=0.03..0.33 rows=1 width=148) (actual time=3758.487..3758.505 rows=43 loops=1) + Hash Cond: (mseq.m = base.order_month) + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> CTE Scan on mseq (cost=0.00..0.24 rows=12 width=36) (actual time=0.003..0.011 rows=12 loops=1) + -> Hash (cost=0.02..0.02 rows=1 width=144) (actual time=3758.477..3758.477 rows=43 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 12kB + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> CTE Scan on base (cost=0.00..0.02 rows=1 width=144) (actual time=3758.396..3758.461 rows=43 loops=1) + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + CTE mpvt + -> GroupAggregate (cost=0.03..0.11 rows=1 width=196) (actual time=0.019..0.035 rows=7 loops=1) + Group Key: months.seq, months.order_month + -> Sort (cost=0.03..0.04 rows=1 width=116) (actual time=0.011..0.012 rows=17 loops=1) + Sort Key: months.seq, months.order_month + Sort Method: quicksort Memory: 26kB + -> CTE Scan on months (cost=0.00..0.02 rows=1 width=116) (actual time=0.001..0.003 rows=17 loops=1) + CTE mlist + -> Sort (cost=0.54..0.57 rows=12 width=196) (actual time=0.072..0.072 rows=12 loops=1) + Sort Key: mseq_1.s + Sort Method: quicksort Memory: 26kB + -> Hash Left Join (cost=0.03..0.33 rows=12 width=196) (actual time=0.058..0.062 rows=12 loops=1) + Hash Cond: (mseq_1.m = mpvt.order_month) + -> CTE Scan on mseq mseq_1 (cost=0.00..0.24 rows=12 width=36) (actual time=0.000..0.001 rows=12 loops=1) + -> Hash (cost=0.02..0.02 rows=1 width=192) (actual time=0.048..0.048 rows=7 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mpvt (cost=0.00..0.02 rows=1 width=192) (actual time=0.021..0.043 rows=7 loops=1) + CTE totals + -> HashAggregate (cost=0.03..0.05 rows=1 width=112) (actual time=0.016..0.018 rows=6 loops=1) + Group Key: months_1.order_season, months_1.version, months_1.iter + -> CTE Scan on months months_1 (cost=0.00..0.02 rows=1 width=112) (actual time=0.001..0.003 rows=17 loops=1) + InitPlan 7 (returns $7) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=3758.733..3758.733 rows=1 loops=1) + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> CTE Scan on months months_2 (cost=0.00..0.02 rows=1 width=24) (actual time=3758.536..3758.554 rows=17 loops=1) + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + InitPlan 8 (returns $8) + -> Aggregate (cost=0.36..0.37 rows=1 width=32) (actual time=0.247..0.247 rows=1 loops=1) + -> CTE Scan on mlist (cost=0.00..0.24 rows=12 width=24) (actual time=0.075..0.083 rows=12 loops=1) + InitPlan 9 (returns $9) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=0.637..0.638 rows=1 loops=1) + -> CTE Scan on base base_1 (cost=0.00..0.02 rows=1 width=24) (actual time=0.003..0.022 rows=43 loops=1) + InitPlan 10 (returns $10) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=0.073..0.073 rows=1 loops=1) + -> CTE Scan on totals (cost=0.00..0.02 rows=1 width=24) (actual time=0.018..0.024 rows=6 loops=1) + +
+Date: 2019-03-15 15:01:25 +Duration: 3s752ms +
+ +++ + +Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=148.955..3752.933 rows=15 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 100266 + Buffers: shared hit=1 read=13062 + I/O Timings: read=3634.126 + +
+Date: 2019-03-15 15:01:25 +Duration: 3s749ms +
+ +++ + +Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=185.551..3749.831 rows=32 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 100674 + Buffers: shared hit=13 read=13176 + I/O Timings: read=3641.547 + +
++ + +7 +16s584ms +1 + + +16s584ms +16s584ms +16s584ms ++ +DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS int) + FROM ( + SELECT + DISTINCT "diinv#" + FROM + import.osmi + WHERE + "ddord#" = ?) n + WHERE + n. "diinv#" = osm. "diinv#"); + ++ +++Times Reported Time consuming queries #7
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 15 00 1 16s584ms 16s584ms ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 16s584ms - Times executed: 1 ] +
+ +++ + + +-
+
+
[ Application: psql - Total duration: 16s584ms - Times executed: 1 ] +
+ +++ +-
+
+
-
+ DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS INT) + FROM ( + SELECT + DISTINCT "diinv#" + FROM + import.osmi + WHERE + "ddord#" = 0) n + WHERE + n. "diinv#" = osm. "diinv#"); + ++
+
Date: 2019-03-15 00:49:30 +Duration: 16s584ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Delete on osm (cost=2579.44..36736.43 rows=16 width=36) (actual time=16584.934..16584.934 rows=0 loops=1) + Buffers: shared hit=1558922 read=6078 dirtied=71 + I/O Timings: read=735.005 + -> Nested Loop (cost=2579.44..36736.43 rows=16 width=36) (actual time=99.141..16583.640 rows=159 loops=1) + Buffers: shared hit=1558763 read=6078 dirtied=66 + I/O Timings: read=735.005 + -> Subquery Scan on n (cost=2579.01..2579.03 rows=1 width=36) (actual time=5.671..7.407 rows=223 loops=1) + Buffers: shared hit=2579 + -> Unique (cost=2579.01..2579.02 rows=1 width=6) (actual time=5.664..6.608 rows=223 loops=1) + Buffers: shared hit=2579 + -> Sort (cost=2579.01..2579.02 rows=1 width=6) (actual time=5.662..5.909 rows=252 loops=1) + Sort Key: osmi."diinv#" + Sort Method: quicksort Memory: 36kB + Buffers: shared hit=2579 + -> Seq Scan on osmi (cost=0.00..2579.00 rows=1 width=6) (actual time=0.047..5.580 rows=252 loops=1) + Filter: ("ddord#" = '0'::numeric) + Rows Removed by Filter: 25396 + Buffers: shared hit=2579 + -> Index Scan using osm_pk on osm (cost=0.42..34157.24 rows=16 width=12) (actual time=24.619..74.328 rows=1 loops=223) + Index Cond: ("diinv#" = n."diinv#") + Buffers: shared hit=1556184 read=6078 dirtied=66 + I/O Timings: read=735.005 + +
++ + +8 +11s756ms +6 + + +1s121ms +2s988ms +1s959ms ++ +--\timing --explain (ANALYZE, buffers) WITH mseq AS ( SELECT * FROM ( VALUES (?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ) x(m,s) ) --select * FROM mseq ,base AS ( SELECT order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ,sum(units) units ,sum(value_usd) value_usd FROM rlarp.osm_fcpool WHERE quota_rep_descr = ? AND segm = ? AND mod_chan = ? AND part_descr = ? GROUP BY order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ) ,months AS ( SELECT order_season ,version ,iter ,order_month ,mseq.s seq ,sum(units) units ,sum(value_usd) value_usd FROM base INNER JOIN mseq ON mseq.m = base.order_month GROUP BY order_season ,version ,iter ,order_month ,s ) ,mpvt AS ( SELECT order_month ,seq ,sum(units) filter (WHERE order_season = ?) "? qty" ,sum(units) filter (WHERE order_season = ? AND iter IN (...)) "? base qty" ,sum(units) filter (WHERE order_season = ? AND iter NOT IN (...)) "? adj qty" ,sum(units) filter (WHERE order_season = ?) "? tot qty" ,sum(value_usd) filter (WHERE order_season = ?) "? value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter IN (...)) "? base value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter NOT IN (...)) "? adj value_usd" ,sum(value_usd) filter (WHERE order_season = ?) "? tot value_usd" FROM months GROUP BY order_month ,seq ORDER BY seq ASC ) ,mlist AS ( SELECT mseq.m order_month ,"? qty" ,"? base qty" ,"? adj qty" ,"? tot qty" ,"? value_usd" ,"? base value_usd" ,"? adj value_usd" ,"? tot value_usd" FROM mseq LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m ORDER BY mseq.s ASC ) ,totals AS ( SELECT order_season ,version ,iter ,sum(units) units ,sum(value_usd) value_usd FROM months GROUP BY order_season ,version ,iter ) SELECT jsonb_build_object( ? ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) ,? ,(SELECT jsonb_agg(row_to_json(mlist)::jsonb) FROM mlist) ,? ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) ,? ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) ) package ; ++ +++Times Reported Time consuming queries #8
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 15 16 3 8s369ms 2s789ms + +Mar 18 13 3 3s387ms 1s129ms ++ + + +-
+
+
[ User: api - Total duration: 4s131ms - Times executed: 2 ] +
+ +++ + + +-
+
+
[ Application: osm_api - Total duration: 4s131ms - Times executed: 2 ] +
+ +++ +-
+
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
Date: 2019-03-15 16:48:48 +Duration: 2s988ms +Database: ubm +User: api +Remote: ubreport +Application: osm_api +
+ +++ + +Result (cost=43058.77..43058.78 rows=1 width=32) (actual time=2986.772..2986.773 rows=1 loops=1) + Buffers: shared hit=9 read=39543 + I/O Timings: read=8023.323 + CTE mseq + -> Values Scan on "*VALUES*" (cost=0.00..0.15 rows=12 width=36) (actual time=0.002..0.010 rows=12 loops=1) + CTE base + -> GroupAggregate (cost=43056.99..43057.03 rows=1 width=176) (actual time=2980.662..2980.715 rows=43 loops=1) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> Sort (cost=43056.99..43056.99 rows=1 width=149) (actual time=2980.648..2980.652 rows=72 loops=1) + Sort Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Sort Method: quicksort Memory: 44kB + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> Gather (cost=1000.00..43056.97 rows=1 width=149) (actual time=37.232..2980.519 rows=72 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared read=39543 + I/O Timings: read=8023.323 + -> Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=103.278..2786.395 rows=24 loops=3) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 100422 + Buffers: shared read=39543 + I/O Timings: read=8023.323 + CTE months + -> HashAggregate (cost=0.35..0.36 rows=1 width=152) (actual time=2980.841..2980.865 rows=17 loops=1) + Group Key: base.order_season, base.version, base.iter, base.order_month, mseq.s + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> Hash Join (cost=0.03..0.33 rows=1 width=148) (actual time=2980.782..2980.808 rows=43 loops=1) + Hash Cond: (mseq.m = base.order_month) + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> CTE Scan on mseq (cost=0.00..0.24 rows=12 width=36) (actual time=0.004..0.017 rows=12 loops=1) + -> Hash (cost=0.02..0.02 rows=1 width=144) (actual time=2980.767..2980.767 rows=43 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 12kB + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> CTE Scan on base (cost=0.00..0.02 rows=1 width=144) (actual time=2980.665..2980.749 rows=43 loops=1) + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + CTE mpvt + -> GroupAggregate (cost=0.03..0.11 rows=1 width=196) (actual time=0.036..0.056 rows=7 loops=1) + Group Key: months.seq, months.order_month + -> Sort (cost=0.03..0.04 rows=1 width=116) (actual time=0.021..0.022 rows=17 loops=1) + Sort Key: months.seq, months.order_month + Sort Method: quicksort Memory: 26kB + -> CTE Scan on months (cost=0.00..0.02 rows=1 width=116) (actual time=0.002..0.005 rows=17 loops=1) + CTE mlist + -> Sort (cost=0.54..0.57 rows=12 width=196) (actual time=0.159..0.162 rows=12 loops=1) + Sort Key: mseq_1.s + Sort Method: quicksort Memory: 26kB + Buffers: shared hit=3 + -> Hash Left Join (cost=0.03..0.33 rows=12 width=196) (actual time=0.101..0.107 rows=12 loops=1) + Hash Cond: (mseq_1.m = mpvt.order_month) + -> CTE Scan on mseq mseq_1 (cost=0.00..0.24 rows=12 width=36) (actual time=0.001..0.003 rows=12 loops=1) + -> Hash (cost=0.02..0.02 rows=1 width=192) (actual time=0.071..0.071 rows=7 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mpvt (cost=0.00..0.02 rows=1 width=192) (actual time=0.038..0.063 rows=7 loops=1) + CTE totals + -> HashAggregate (cost=0.03..0.05 rows=1 width=112) (actual time=0.021..0.024 rows=6 loops=1) + Group Key: months_1.order_season, months_1.version, months_1.iter + -> CTE Scan on months months_1 (cost=0.00..0.02 rows=1 width=112) (actual time=0.001..0.004 rows=17 loops=1) + InitPlan 7 (returns $7) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=2985.173..2985.173 rows=1 loops=1) + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> CTE Scan on months months_2 (cost=0.00..0.02 rows=1 width=24) (actual time=2981.027..2981.083 rows=17 loops=1) + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + InitPlan 8 (returns $8) + -> Aggregate (cost=0.36..0.37 rows=1 width=32) (actual time=0.435..0.435 rows=1 loops=1) + Buffers: shared hit=3 + -> CTE Scan on mlist (cost=0.00..0.24 rows=12 width=24) (actual time=0.179..0.197 rows=12 loops=1) + Buffers: shared hit=3 + InitPlan 9 (returns $9) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=0.845..0.845 rows=1 loops=1) + -> CTE Scan on base base_1 (cost=0.00..0.02 rows=1 width=24) (actual time=0.007..0.034 rows=43 loops=1) + InitPlan 10 (returns $10) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=0.109..0.109 rows=1 loops=1) + -> CTE Scan on totals (cost=0.00..0.02 rows=1 width=24) (actual time=0.030..0.038 rows=6 loops=1) + +
+Date: 2019-03-15 16:48:48 +Duration: 2s690ms +
+ +++ + +Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=195.353..2690.533 rows=16 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 76890 + Buffers: shared read=10399 + I/O Timings: read=2598.181 + +
+Date: 2019-03-15 16:48:48 +Duration: 2s690ms +
+ +++ + +Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=77.724..2690.442 rows=19 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 76638 + Buffers: shared read=10361 + I/O Timings: read=2590.846 + +
++ + +9 +11s11ms +6 + + +1s444ms +3s349ms +1s835ms ++ +--create INDEX flag ON gld(plan, rolling); WITH un AS ( SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osmf osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.glec,?,?) <= ? AND substr(osm.fs_line,?,?) = ? AND calc_status <> ? --open orders AND sd.cm = ? --this works FOR forecast it indicates a future fspr GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) UNION ALL SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osm osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON greatest(osm.adj_requestdate,current_date) BETWEEN sd.sdat AND sd.edat WHERE substr(osm.fs_line,?,?) = ? AND substr(osm.glec,?,?) <= ? AND calc_status IN (...) AND flag = ? GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ) SELECT srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ,sum(qty) units ,sum(stdcost) "cost" ,sum(sales) sales FROM un WHERE om <> ? GROUP BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ORDER BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ; ++ +++Times Reported Time consuming queries #9
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 18 10 6 11s11ms 1s835ms ++ + + +-
+
+
[ User: report - Total duration: 4s793ms - Times executed: 2 ] +
+ +++ + + +-
+
+
[ Application: [unknown] - Total duration: 4s793ms - Times executed: 2 ] +
+ +++ +-
+
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
Date: 2019-03-18 10:06:25 +Duration: 3s349ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=98200.29..98200.79 rows=200 width=232) (actual time=3348.705..3348.710 rows=132 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=235 read=84111, local hit=161423 read=1 + I/O Timings: read=7279.164 + CTE un + -> Append (cost=31586.61..98166.63 rows=449 width=232) (actual time=1488.149..3348.297 rows=154 loops=1) + Buffers: shared hit=232 read=84111, local hit=161423 read=1 + I/O Timings: read=7279.164 + -> GroupAggregate (cost=31586.61..31590.91 rows=82 width=232) (actual time=1488.148..1554.309 rows=84 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared read=26345, local hit=151073 read=1 + I/O Timings: read=2987.288 + -> Sort (cost=31586.61..31586.81 rows=82 width=185) (actual time=1488.111..1493.540 rows=75536 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 13695kB + Buffers: shared read=26345, local hit=151073 read=1 + I/O Timings: read=2987.288 + -> Nested Loop (cost=1004.33..31584.00 rows=82 width=185) (actual time=21.103..1425.083 rows=75536 loops=1) + Buffers: shared read=26345, local hit=151073 read=1 + I/O Timings: read=2987.288 + -> Hash Join (cost=1004.19..31579.49 rows=4 width=113) (actual time=21.078..1001.628 rows=75536 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2987.281 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=21.024..908.420 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared read=26345 + I/O Timings: read=2987.281 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=11.969..1113.675 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared read=26345 + I/O Timings: read=2987.281 + -> Hash (cost=4.18..4.18 rows=1 width=108) (actual time=0.033..0.034 rows=38 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 10kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.021..0.027 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=75536) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=151071 read=1 + I/O Timings: read=0.007 + -> GroupAggregate (cost=66549.72..66568.99 rows=367 width=232) (actual time=1789.692..1793.972 rows=70 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=232 read=57766, local hit=10350 + I/O Timings: read=4291.876 + -> Sort (cost=66549.72..66550.64 rows=367 width=178) (actual time=1789.672..1789.874 rows=5174 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 920kB + Buffers: shared hit=232 read=57766, local hit=10350 + I/O Timings: read=4291.876 + -> Nested Loop (cost=1004.74..66534.08 rows=367 width=178) (actual time=1752.458..1786.814 rows=5174 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 895102 + Buffers: shared hit=232 read=57766, local hit=10350 + I/O Timings: read=4291.876 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.013..0.078 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..66472.54 rows=19 width=106) (actual time=0.073..9.810 rows=5174 loops=174) + Buffers: shared hit=232 read=57766, local hit=10348 + I/O Timings: read=4291.876 + -> Nested Loop Left Join (cost=1004.74..66472.44 rows=19 width=106) (actual time=12.621..1668.315 rows=5174 loops=1) + Buffers: shared hit=232 read=57766, local hit=10348 + I/O Timings: read=4291.876 + -> Gather (cost=1000.00..66465.04 rows=1 width=34) (actual time=12.587..1608.241 rows=5174 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=232 read=57766 + I/O Timings: read=4291.876 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..65464.94 rows=1 width=34) (actual time=4.136..1641.056 rows=1725 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259938 + Buffers: shared hit=232 read=57766 + I/O Timings: read=4291.876 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.011..0.011 rows=1 loops=5174) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5174 + Buffers: local hit=10348 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.010..0.010 rows=1 loops=5174) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5174 + -> HashAggregate (cost=23.51..26.01 rows=200 width=232) (actual time=3348.532..3348.577 rows=132 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=232 read=84111, local hit=161423 read=1 + I/O Timings: read=7279.164 + -> CTE Scan on un (cost=0.00..10.10 rows=447 width=232) (actual time=1488.153..3348.409 rows=132 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=232 read=84111, local hit=161423 read=1 + I/O Timings: read=7279.164 + +
+Date: 2019-03-18 10:06:25 +Duration: 1s661ms +
+ +++ + +Parallel Seq Scan on osm (cost=0.00..65464.94 rows=1 width=34) (actual time=0.035..1661.025 rows=2679 loops=1) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 312636 + Buffers: shared hit=57 read=22167 + I/O Timings: read=1426.762 + +
+Date: 2019-03-18 10:06:25 +Duration: 1s659ms +
+ +++ + +Parallel Seq Scan on osm (cost=0.00..65464.94 rows=1 width=34) (actual time=0.588..1658.922 rows=1702 loops=1) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 291296 + Buffers: shared hit=39 read=21772 + I/O Timings: read=1413.782 + +
++ + +10 +7s429ms +3 + + +2s10ms +3s265ms +2s476ms ++ +DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS int) + FROM ( + SELECT + DISTINCT "ddord#" + FROM + import.osmi + WHERE + "ddord#" <> ?) n + WHERE + n. "ddord#" = osm. "ddord#"); + ++ +++Times Reported Time consuming queries #10
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 17 1 3s265ms 3s265ms Mar 15 14 1 2s153ms 2s153ms + +16 1 2s10ms 2s10ms ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 7s429ms - Times executed: 3 ] +
+ +++ + + +-
+
+
[ Application: psql - Total duration: 7s429ms - Times executed: 3 ] +
+ +++ +-
+
+
-
+ DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS INT) + FROM ( + SELECT + DISTINCT "ddord#" + FROM + import.osmi + WHERE + "ddord#" <> 0) n + WHERE + n. "ddord#" = osm. "ddord#"); + ++
+
-
+ DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS INT) + FROM ( + SELECT + DISTINCT "ddord#" + FROM + import.osmi + WHERE + "ddord#" <> 0) n + WHERE + n. "ddord#" = osm. "ddord#"); + ++
+
-
+ DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS INT) + FROM ( + SELECT + DISTINCT "ddord#" + FROM + import.osmi + WHERE + "ddord#" <> 0) n + WHERE + n. "ddord#" = osm. "ddord#"); + ++
+
Date: 2019-03-14 17:12:43 +Duration: 3s265ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Delete on osm (cost=1968.07..69852.70 rows=67171 width=36) (actual time=3265.512..3265.512 rows=0 loops=1) + Buffers: shared hit=29163 read=54721 dirtied=1562 + I/O Timings: read=2859.895 + -> Hash Join (cost=1968.07..69852.70 rows=67171 width=36) (actual time=75.167..3248.670 rows=24360 loops=1) + Hash Cond: (osm."ddord#" = n."ddord#") + Buffers: shared hit=4780 read=54721 dirtied=82 + I/O Timings: read=2859.895 + -> Seq Scan on osm (cost=0.00..65827.55 rows=783555 width=12) (actual time=1.473..3059.153 rows=783400 loops=1) + Buffers: shared hit=3271 read=54721 + I/O Timings: read=2859.895 + -> Hash (cost=1930.65..1930.65 rows=2994 width=36) (actual time=18.828..18.828 rows=3245 loops=1) + Buckets: 4096 Batches: 1 Memory Usage: 245kB + Buffers: shared hit=1509 dirtied=82 + -> Subquery Scan on n (cost=1870.77..1930.65 rows=2994 width=36) (actual time=16.917..18.065 rows=3245 loops=1) + Buffers: shared hit=1509 dirtied=82 + -> HashAggregate (cost=1870.77..1900.71 rows=2994 width=6) (actual time=16.897..17.477 rows=3245 loops=1) + Group Key: osmi."ddord#" + Buffers: shared hit=1509 dirtied=82 + -> Seq Scan on osmi (cost=0.00..1810.80 rows=23987 width=6) (actual time=0.026..9.823 rows=25374 loops=1) + Filter: ("ddord#" <> '0'::numeric) + Rows Removed by Filter: 252 + Buffers: shared hit=1509 dirtied=82 + +
+Date: 2019-03-15 14:07:09 +Duration: 2s153ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Delete on osm (cost=1986.94..69871.57 rows=69213 width=36) (actual time=2153.612..2153.612 rows=0 loops=1) + Buffers: shared hit=26955 read=57942 dirtied=1625 + I/O Timings: read=1847.789 + -> Hash Join (cost=1986.94..69871.57 rows=69213 width=36) (actual time=1997.260..2135.913 rows=25383 loops=1) + Hash Cond: (osm."ddord#" = n."ddord#") + Buffers: shared hit=1572 read=57942 + I/O Timings: read=1847.789 + -> Seq Scan on osm (cost=0.00..65827.55 rows=783555 width=12) (actual time=0.460..1982.573 rows=784529 loops=1) + Buffers: shared hit=50 read=57942 + I/O Timings: read=1847.789 + -> Hash (cost=1948.38..1948.38 rows=3085 width=36) (actual time=14.780..14.780 rows=3290 loops=1) + Buckets: 4096 Batches: 1 Memory Usage: 248kB + Buffers: shared hit=1522 + -> Subquery Scan on n (cost=1886.68..1948.38 rows=3085 width=36) (actual time=13.217..14.151 rows=3290 loops=1) + Buffers: shared hit=1522 + -> HashAggregate (cost=1886.68..1917.53 rows=3085 width=6) (actual time=13.202..13.591 rows=3290 loops=1) + Group Key: osmi."ddord#" + Buffers: shared hit=1522 + -> Seq Scan on osmi (cost=0.00..1826.40 rows=24113 width=6) (actual time=0.010..7.688 rows=25613 loops=1) + Filter: ("ddord#" <> '0'::numeric) + Rows Removed by Filter: 265 + Buffers: shared hit=1522 + +
+Date: 2019-03-15 16:45:32 +Duration: 2s10ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Delete on osm (cost=2006.51..69055.94 rows=62283 width=36) (actual time=2010.489..2010.489 rows=0 loops=1) + Buffers: shared hit=28858 read=57960 dirtied=1674 + I/O Timings: read=1634.275 + -> Hash Join (cost=2006.51..69055.94 rows=62283 width=36) (actual time=1663.729..1988.641 rows=25616 loops=1) + Hash Cond: (osm."ddord#" = n."ddord#") + Buffers: shared hit=1569 read=57960 + I/O Timings: read=1634.275 + -> Seq Scan on osm (cost=0.00..65166.02 rows=717402 width=12) (actual time=0.449..1815.192 rows=784772 loops=1) + Buffers: shared hit=32 read=57960 + I/O Timings: read=1634.275 + -> Hash (cost=1967.58..1967.58 rows=3115 width=36) (actual time=16.883..16.883 rows=3334 loops=1) + Buckets: 4096 Batches: 1 Memory Usage: 251kB + Buffers: shared hit=1537 + -> Subquery Scan on n (cost=1905.28..1967.58 rows=3115 width=36) (actual time=15.539..16.337 rows=3334 loops=1) + Buffers: shared hit=1537 + -> HashAggregate (cost=1905.28..1936.43 rows=3115 width=6) (actual time=15.524..15.848 rows=3334 loops=1) + Group Key: osmi."ddord#" + Buffers: shared hit=1537 + -> Seq Scan on osmi (cost=0.00..1844.40 rows=24350 width=6) (actual time=0.011..9.183 rows=25826 loops=1) + Filter: ("ddord#" <> '0'::numeric) + Rows Removed by Filter: 271 + Buffers: shared hit=1537 + +
++ + +11 +4s848ms +3 + + +1s270ms +1s826ms +1s616ms ++ +INSERT INTO rlarp.osm +SELECT + * +FROM + import.osmi; + ++ +++Times Reported Time consuming queries #11
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 17 1 1s826ms 1s826ms Mar 15 14 1 1s270ms 1s270ms + +16 1 1s752ms 1s752ms ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 4s848ms - Times executed: 3 ] +
+ +++ + + +-
+
+
[ Application: psql - Total duration: 4s848ms - Times executed: 3 ] +
+ +++ +-
+
+
-
+ INSERT INTO rlarp.osm +SELECT + * +FROM + import.osmi; + ++
+
-
+ INSERT INTO rlarp.osm +SELECT + * +FROM + import.osmi; + ++
+
-
+ INSERT INTO rlarp.osm +SELECT + * +FROM + import.osmi; + ++
+
Date: 2019-03-14 17:12:46 +Duration: 1s826ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm (cost=0.00..1750.44 rows=24144 width=457) (actual time=1826.337..1826.337 rows=0 loops=1) + Buffers: shared hit=419286 read=3669 dirtied=3584 + I/O Timings: read=1345.135 + -> Seq Scan on osmi (cost=0.00..1750.44 rows=24144 width=457) (actual time=0.007..7.078 rows=25626 loops=1) + Buffers: shared hit=1509 + +
+Date: 2019-03-15 16:45:34 +Duration: 1s752ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm (cost=0.00..1782.92 rows=24592 width=457) (actual time=1752.635..1752.635 rows=0 loops=1) + Buffers: shared hit=406744 read=6293 dirtied=6259 + I/O Timings: read=1296.982 + -> Seq Scan on osmi (cost=0.00..1782.92 rows=24592 width=457) (actual time=0.005..6.976 rows=26097 loops=1) + Buffers: shared hit=1537 + +
+Date: 2019-03-15 14:07:11 +Duration: 1s270ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm (cost=0.00..1765.52 rows=24352 width=457) (actual time=1270.004..1270.004 rows=0 loops=1) + Buffers: shared hit=421843 read=4791 dirtied=3283 + I/O Timings: read=823.790 + -> Seq Scan on osmi (cost=0.00..1765.52 rows=24352 width=457) (actual time=0.006..6.130 rows=25878 loops=1) + Buffers: shared hit=1522 + +
++ + +12 +3s720ms +3 + + +1s194ms +1s327ms +1s240ms ++ +--\timing --explain (ANALYZE, buffers) WITH mseq AS ( SELECT * FROM ( VALUES (?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ) x(m,s) ) --select * FROM mseq ,base AS ( SELECT order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ,sum(units) units ,sum(value_usd) value_usd FROM rlarp.osm_fcpool WHERE quota_rep_descr = ? AND segm = ? AND mod_chan = ? AND bill_cust_descr = ? GROUP BY order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ) ,months AS ( SELECT order_season ,version ,iter ,order_month ,mseq.s seq ,sum(units) units ,sum(value_usd) value_usd FROM base INNER JOIN mseq ON mseq.m = base.order_month GROUP BY order_season ,version ,iter ,order_month ,s ) ,mpvt AS ( SELECT order_month ,seq ,sum(units) filter (WHERE order_season = ?) "? qty" ,sum(units) filter (WHERE order_season = ? AND iter = ?) "? base qty" ,sum(units) filter (WHERE order_season = ? AND iter <> ?) "? adj qty" ,sum(units) filter (WHERE order_season = ?) "? tot qty" ,sum(value_usd) filter (WHERE order_season = ?) "? value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter = ?) "? base value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter <> ?) "? adj value_usd" ,sum(value_usd) filter (WHERE order_season = ?) "? tot value_usd" FROM months GROUP BY order_month ,seq ORDER BY seq ASC ) ,mlist AS ( SELECT mseq.m order_month ,"? qty" ,"? base qty" ,"? adj qty" ,"? tot qty" ,"? value_usd" ,"? base value_usd" ,"? adj value_usd" ,"? tot value_usd" FROM mseq LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m ORDER BY mseq.s ASC ) ,totals AS ( SELECT order_season ,version ,iter ,sum(units) units ,sum(value_usd) value_usd FROM months GROUP BY order_season ,version ,iter ) SELECT jsonb_build_object( ? ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) ,? ,(SELECT jsonb_agg(row_to_json(mlist)::jsonb) FROM mlist) ,? ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) ,? ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) ) package ; ++ +++Times Reported Time consuming queries #12
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 15 10 3 3s720ms 1s240ms ++ + + +-
+
+
[ User: api - Total duration: 1s327ms - Times executed: 1 ] +
+ +++ + + +-
+
+
[ Application: osm_api - Total duration: 1s327ms - Times executed: 1 ] +
+ +++ +-
+
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
Date: 2019-03-15 10:02:03 +Duration: 1s327ms +Database: ubm +User: api +Remote: USHCC10107.GBL.HC-companies.com +Application: osm_api +
+ +++ + +Result (cost=43067.02..43067.03 rows=1 width=32) (actual time=1322.834..1322.949 rows=1 loops=1) + Buffers: shared hit=3 read=15116 + I/O Timings: read=1154.285 + CTE mseq + -> Values Scan on "*VALUES*" (cost=0.00..0.15 rows=12 width=36) (actual time=0.008..0.012 rows=12 loops=1) + CTE base + -> Finalize GroupAggregate (cost=43057.06..43060.56 rows=25 width=176) (actual time=1287.168..1296.146 rows=1095 loops=1) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared read=15116 + I/O Timings: read=1154.285 + -> Gather Merge (cost=43057.06..43059.75 rows=20 width=176) (actual time=1287.150..1294.990 rows=1214 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=112 read=39543 + I/O Timings: read=3332.221 + -> Partial GroupAggregate (cost=42057.04..42057.42 rows=10 width=176) (actual time=1222.013..1222.459 rows=405 loops=3) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared hit=112 read=39543 + I/O Timings: read=3332.221 + -> Sort (cost=42057.04..42057.07 rows=10 width=149) (actual time=1221.999..1222.047 rows=447 loops=3) + Sort Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.ship_cust_descr + Sort Method: quicksort Memory: 145kB + Worker 0: Sort Method: quicksort Memory: 145kB + Worker 1: Sort Method: quicksort Memory: 140kB + Buffers: shared hit=112 read=39543 + I/O Timings: read=3332.221 + -> Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=10 width=149) (actual time=24.365..1220.140 rows=447 loops=3) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC'::text)) + Rows Removed by Filter: 99999 + Buffers: shared read=39543 + I/O Timings: read=3332.221 + CTE months + -> HashAggregate (cost=1.31..1.46 rows=12 width=152) (actual time=1297.764..1297.785 rows=28 loops=1) + Group Key: base.order_season, base.version, base.iter, base.order_month, mseq.s + Buffers: shared read=15116 + I/O Timings: read=1154.285 + -> Hash Join (cost=0.39..1.10 rows=12 width=148) (actual time=1287.272..1297.191 rows=1095 loops=1) + Hash Cond: (base.order_month = mseq.m) + Buffers: shared read=15116 + I/O Timings: read=1154.285 + -> CTE Scan on base (cost=0.00..0.50 rows=25 width=144) (actual time=1287.170..1296.717 rows=1095 loops=1) + Buffers: shared read=15116 + I/O Timings: read=1154.285 + -> Hash (cost=0.24..0.24 rows=12 width=36) (actual time=0.028..0.028 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mseq (cost=0.00..0.24 rows=12 width=36) (actual time=0.013..0.021 rows=12 loops=1) + CTE mpvt + -> GroupAggregate (cost=0.46..1.39 rows=12 width=196) (actual time=0.043..0.069 rows=12 loops=1) + Group Key: months.seq, months.order_month + -> Sort (cost=0.46..0.49 rows=12 width=116) (actual time=0.029..0.031 rows=28 loops=1) + Sort Key: months.seq, months.order_month + Sort Method: quicksort Memory: 27kB + -> CTE Scan on months (cost=0.00..0.24 rows=12 width=116) (actual time=0.001..0.006 rows=28 loops=1) + CTE mlist + -> Sort (cost=1.01..1.04 rows=12 width=196) (actual time=0.167..0.168 rows=12 loops=1) + Sort Key: mseq_1.s + Sort Method: quicksort Memory: 26kB + Buffers: shared hit=3 + -> Hash Left Join (cost=0.39..0.80 rows=12 width=196) (actual time=0.110..0.115 rows=12 loops=1) + Hash Cond: (mseq_1.m = mpvt.order_month) + -> CTE Scan on mseq mseq_1 (cost=0.00..0.24 rows=12 width=36) (actual time=0.001..0.002 rows=12 loops=1) + -> Hash (cost=0.24..0.24 rows=12 width=192) (actual time=0.092..0.092 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 10kB + -> CTE Scan on mpvt (cost=0.00..0.24 rows=12 width=192) (actual time=0.049..0.082 rows=12 loops=1) + CTE totals + -> HashAggregate (cost=0.39..0.54 rows=12 width=112) (actual time=0.037..0.040 rows=6 loops=1) + Group Key: months_1.order_season, months_1.version, months_1.iter + -> CTE Scan on months months_1 (cost=0.00..0.24 rows=12 width=112) (actual time=0.003..0.008 rows=28 loops=1) + InitPlan 7 (returns $7) + -> Aggregate (cost=0.36..0.37 rows=1 width=32) (actual time=1298.799..1298.799 rows=1 loops=1) + Buffers: shared read=15116 + I/O Timings: read=1154.285 + -> CTE Scan on months months_2 (cost=0.00..0.24 rows=12 width=24) (actual time=1297.953..1298.003 rows=28 loops=1) + Buffers: shared read=15116 + I/O Timings: read=1154.285 + InitPlan 8 (returns $8) + -> Aggregate (cost=0.36..0.37 rows=1 width=32) (actual time=0.466..0.467 rows=1 loops=1) + Buffers: shared hit=3 + -> CTE Scan on mlist (cost=0.00..0.24 rows=12 width=24) (actual time=0.181..0.192 rows=12 loops=1) + Buffers: shared hit=3 + InitPlan 9 (returns $9) + -> Aggregate (cost=0.75..0.76 rows=1 width=32) (actual time=19.795..19.795 rows=1 loops=1) + -> CTE Scan on base base_1 (cost=0.00..0.50 rows=25 width=24) (actual time=0.006..0.656 rows=1095 loops=1) + InitPlan 10 (returns $10) + -> Aggregate (cost=0.36..0.37 rows=1 width=32) (actual time=0.165..0.165 rows=1 loops=1) + -> CTE Scan on totals (cost=0.00..0.24 rows=12 width=24) (actual time=0.059..0.067 rows=6 loops=1) + +
+Date: 2019-03-15 10:02:03 +Duration: 1s198ms +
+ +++ + +Partial GroupAggregate (cost=42057.04..42057.42 rows=10 width=176) (actual time=1191.374..1191.759 rows=387 loops=1) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared hit=56 read=12331 + I/O Timings: read=1091.338 + -> Sort (cost=42057.04..42057.07 rows=10 width=149) (actual time=1191.355..1191.388 rows=435 loops=1) + Sort Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.ship_cust_descr + Sort Method: quicksort Memory: 140kB + Worker 0: Sort Method: quicksort Memory: 145kB + Worker 1: Sort Method: quicksort Memory: 140kB + Buffers: shared hit=56 read=12331 + I/O Timings: read=1091.338 + -> Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=10 width=149) (actual time=11.309..1189.560 rows=435 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC'::text)) + Rows Removed by Filter: 92425 + Buffers: shared read=12331 + I/O Timings: read=1091.338 + +
+Date: 2019-03-15 10:02:03 +Duration: 1s194ms +
+ +++ + +Partial GroupAggregate (cost=42057.04..42057.42 rows=10 width=176) (actual time=1190.430..1190.830 rows=411 loops=1) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared hit=56 read=12096 + I/O Timings: read=1086.598 + -> Sort (cost=42057.04..42057.07 rows=10 width=149) (actual time=1190.420..1190.459 rows=452 loops=1) + Sort Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.ship_cust_descr + Sort Method: quicksort Memory: 145kB + Worker 0: Sort Method: quicksort Memory: 145kB + Worker 1: Sort Method: quicksort Memory: 140kB + Buffers: shared hit=56 read=12096 + I/O Timings: read=1086.598 + -> Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=10 width=149) (actual time=24.972..1188.569 rows=452 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC'::text)) + Rows Removed by Filter: 91018 + Buffers: shared read=12096 + I/O Timings: read=1086.598 + +
++ + +13 +2s707ms +1 + + +2s707ms +2s707ms +2s707ms ++ +CREATE temp TABLE gld AS ( + WITH seg AS ( + SELECT + glec, + segm + FROM ( + VALUES (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?)) x (glec, + segm)), + ord_cutoff AS ( + SELECT + min(adj_orderdate) fc_odat + FROM + rlarp.osmp + WHERE + iter <> ? + AND version = ? + AND adj_orderdate >= ?), sales_cutoff AS ( + SELECT + max(fspr) max_fspr + FROM + rlarp.osm), + gld AS ( + SELECT + n1comp comp, + n1ccyy fsyr, + kpmaxp perds, + n1fspp perd, + to_char(n1fsyp, ?) fspr, + n1sd01 sdat, + n1ed01 edat, + to_char(n1ed01, ?) capr, + n1ed01 - n1sd01 + ? ndays, + CASE WHEN extract(month FROM n1ed01) >= ? THEN + extract(year FROM n1ed01) + ? + ELSE + extract(year FROM n1ed01) + END ssyr, + to_char( + CASE WHEN extract(month FROM n1ed01) >= ? THEN + extract(month FROM n1ed01) ? + ELSE + extract(month FROM n1ed01) + ? + END, ?) sspr --if the period date IS less than the FIRST forecasted ORDER it IS actual FROM perspective of the plan ,case WHEN max_fspr = to_char(n1fsyp,?) THEN ? ELSE CASE WHEN sales_cutoff.max_fspr > to_char(n1fsyp,?) THEN ? ELSE ? END END cm ,case WHEN max_fspr = to_char(n1fsyp,?) THEN ? ELSE CASE WHEN sales_cutoff.max_fspr > to_char(n1fsyp,?) THEN CASE WHEN substr(sales_cutoff.max_fspr,?,?) > substr(to_char(n1fsyp,?),?,?) THEN ? ELSE ? END ELSE ? END END cy FROM lgdat.gldatref INNER JOIN lgdat.gldate ON kpcomp = n1comp AND kpccyy = n1ccyy CROSS JOIN ord_cutoff CROSS JOIN sales_cutoff WHERE n1comp = ? --and digits(n1fsyp) = ? ) SELECT * FROM gld ) ; ++ +++Times Reported Time consuming queries #13
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 14 17 1 2s707ms 2s707ms ++ + + +-
+
+
[ User: report - Total duration: 2s707ms - Times executed: 1 ] +
+ +++ + + +-
+
+
[ Application: [unknown] - Total duration: 2s707ms - Times executed: 1 ] +
+ +++ +-
+
+
-
+ CREATE TEMP TABLE GLD AS ( + WITH SEG AS ( + SELECT + GLEC, + SEGM + FROM ( + VALUES ('1CU', + 'Retail'), + ('1GR', + 'Greenhouse'), + ('1NU', + 'Nursery'), + ('1RE', + 'Retail'), + ('2WI', + 'Greenhouse'), + ('3BM', + 'Other'), + ('3CO', + 'Other'), + ('3PE', + 'Other'), + ('3PP', + 'Other'), + ('4CO', + 'Other'), + ('4RA', + 'Other'), + ('9MI', + 'Other'), + ('9SA', + 'Other'), + ('9TO', + 'Other')) X (GLEC, + SEGM)), + ORD_CUTOFF AS ( + SELECT + min(ADJ_ORDERDATE) FC_ODAT + FROM + RLARP.OSMP + WHERE + ITER <> 'Open Orders' + AND version = 'b19' + AND ADJ_ORDERDATE >= '2018-06-01'), SALES_CUTOFF AS ( + SELECT + max(FSPR) MAX_FSPR + FROM + RLARP.OSM), + GLD AS ( + SELECT + N1COMP COMP, + N1CCYY FSYR, + KPMAXP PERDS, + N1FSPP PERD, + to_char(N1FSYP, 'FM0000') FSPR, + N1SD01 SDAT, + N1ED01 EDAT, + to_char(N1ED01, 'yymm') CAPR, + N1ED01 - N1SD01 + 1 NDAYS, + CASE WHEN extract(MONTH FROM N1ED01) >= 6 THEN + extract(YEAR FROM N1ED01) + 1 + ELSE + extract(YEAR FROM N1ED01) + END SSYR, + to_char( + CASE WHEN extract(MONTH FROM N1ED01) >= 6 THEN + extract(MONTH FROM N1ED01) - 5 + ELSE + extract(MONTH FROM N1ED01) + 7 + END, '00') SSPR --if the period date IS less than the FIRST forecasted ORDER it IS actual FROM perspective of the plan +, + CASE WHEN MAX_FSPR = to_char(N1FSYP, 'FM0000') THEN + 'C' + ELSE + CASE WHEN SALES_CUTOFF.MAX_FSPR > to_char(N1FSYP, 'FM0000') THEN + 'P' + ELSE + 'F' + END + END CM, + CASE WHEN MAX_FSPR = to_char(N1FSYP, 'FM0000') THEN + 'C' + ELSE + CASE WHEN SALES_CUTOFF.MAX_FSPR > to_char(N1FSYP, 'FM0000') THEN + CASE WHEN substr(SALES_CUTOFF.MAX_FSPR, 1, 2) > substr(to_char(N1FSYP, 'FM0000'), 1, 2) THEN + 'P' + ELSE + 'C' + END + ELSE + 'F' + END + END CY + FROM + LGDAT.GLDATREF + INNER JOIN LGDAT.GLDATE ON KPCOMP = N1COMP + AND KPCCYY = N1CCYY + CROSS JOIN ORD_CUTOFF + CROSS JOIN SALES_CUTOFF + WHERE + N1COMP = 93 --AND DIGITS(N1FSYP) = '1901' +) + SELECT + * + FROM + GLD +); + ++
+
Date: 2019-03-14 17:14:38 +Duration: 2s707ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +CTE Scan on gld (cost=90.94..95.22 rows=214 width=228) (actual time=301.996..349.721 rows=174 loops=1) + Buffers: shared hit=78 + CTE ord_cutoff + -> Result (cost=0.81..0.82 rows=1 width=4) (actual time=19.020..19.020 rows=1 loops=1) + Buffers: shared hit=4 + InitPlan 1 (returns $0) + -> Limit (cost=0.42..0.81 rows=1 width=4) (actual time=19.007..19.009 rows=1 loops=1) + Buffers: shared hit=4 + -> Index Scan using osmp_adj_orderdate on osmp (cost=0.42..245805.19 rows=634345 width=4) (actual time=18.973..18.973 rows=1 loops=1) + Index Cond: ((adj_orderdate IS NOT NULL) AND (adj_orderdate >= '2018-06-01'::date)) + Filter: ((iter <> 'Open Orders'::text) AND (version = 'b19'::text)) + Buffers: shared hit=4 + CTE sales_cutoff + -> Result (cost=0.52..0.53 rows=1 width=32) (actual time=13.133..13.134 rows=1 loops=1) + Buffers: shared hit=56 + InitPlan 3 (returns $2) + -> Limit (cost=0.42..0.52 rows=1 width=5) (actual time=13.126..13.128 rows=1 loops=1) + Buffers: shared hit=56 + -> Index Only Scan Backward using osm_fspr on osm (cost=0.42..72296.40 rows=723143 width=5) (actual time=13.125..13.125 rows=1 loops=1) + Index Cond: (fspr IS NOT NULL) + Heap Fetches: 1 + Buffers: shared hit=56 + CTE gld + -> Hash Join (cost=28.27..89.59 rows=214 width=200) (actual time=290.797..305.496 rows=174 loops=1) + Hash Cond: (gldatref.n1ccyy = gldate.kpccyy) + Buffers: shared hit=78 + -> Nested Loop (cost=13.63..55.59 rows=174 width=60) (actual time=154.995..163.518 rows=174 loops=1) + Buffers: shared hit=66 + -> Nested Loop (cost=0.00..0.05 rows=1 width=32) (actual time=32.162..32.165 rows=1 loops=1) + Buffers: shared hit=60 + -> CTE Scan on ord_cutoff (cost=0.00..0.02 rows=1 width=0) (actual time=19.023..19.024 rows=1 loops=1) + Buffers: shared hit=4 + -> CTE Scan on sales_cutoff (cost=0.00..0.02 rows=1 width=32) (actual time=13.135..13.136 rows=1 loops=1) + Buffers: shared hit=56 + -> Bitmap Heap Scan on gldatref (cost=13.63..53.80 rows=174 width=28) (actual time=122.815..131.244 rows=174 loops=1) + Recheck Cond: (n1comp = '93'::numeric) + Heap Blocks: exact=2 + Buffers: shared hit=6 + -> Bitmap Index Scan on pk_gldatref (cost=0.00..13.58 rows=174 width=0) (actual time=116.762..116.762 rows=174 loops=1) + Index Cond: (n1comp = '93'::numeric) + Buffers: shared hit=4 + -> Hash (cost=14.45..14.45 rows=15 width=15) (actual time=57.253..57.253 rows=15 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=12 + -> Seq Scan on gldate (cost=0.00..14.45 rows=15 width=15) (actual time=13.900..46.977 rows=15 loops=1) + Filter: (kpcomp = '93'::numeric) + Rows Removed by Filter: 181 + Buffers: shared hit=12 + +
++ + +14 +2s267ms +1 + + +2s267ms +2s267ms +2s267ms ++ +SELECT + sum(fb_val_loc * r_rate) +FROM + rlarp.osm; + ++ +++Times Reported Time consuming queries #14
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 15 09 1 2s267ms 2s267ms ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 2s267ms - Times executed: 1 ] +
+ +++ + + +-
+
+
[ Application: DBeaver 6.0.0 - Main - Total duration: 2s267ms - Times executed: 1 ] +
+ +++ +-
+
+
-
+ SELECT + sum(fb_val_loc * r_rate) +FROM + rlarp.osm; + ++
+
Date: 2019-03-15 09:19:53 +Duration: 2s267ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: DBeaver 6.0.0 - Main +
+ +++ + +Finalize Aggregate (cost=64705.63..64705.64 rows=1 width=8) (actual time=2267.421..2267.421 rows=1 loops=1) + Buffers: shared read=57992 + I/O Timings: read=1653.381 + -> Gather (cost=64705.42..64705.63 rows=2 width=8) (actual time=2267.407..2267.411 rows=1 loops=1) + Workers Planned: 2 + Workers Launched: 0 + Buffers: shared read=57992 + I/O Timings: read=1653.381 + -> Partial Aggregate (cost=63705.42..63705.43 rows=1 width=8) (actual time=2267.403..2267.404 rows=1 loops=1) + Buffers: shared read=57992 + I/O Timings: read=1653.381 + -> Parallel Seq Scan on osm (cost=0.00..61256.81 rows=326481 width=10) (actual time=0.619..1766.451 rows=784529 loops=1) + Buffers: shared read=57992 + I/O Timings: read=1653.381 + +
++ + +15 +0ms +2 + + +0ms +0ms +0ms ++ +COPY lgdat.pdrq (vcpart, + "vcseq#", + vcqtyr, + vcunit, + vcdate, + vctime, + vctmzn, + vcsrce, + "vcref#", + vcstat, + vcplnt) +TO STDOUT; + ++ +++Times Reported Time consuming queries #15
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ + +16 +0ms +2 + + +0ms +0ms +0ms ++ +LOCK TABLE lgdat.serin IN access share mode; + ++ +++Times Reported Time consuming queries #16
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ + +17 +0ms +2 + + +0ms +0ms +0ms ++ +COPY lgdat.vrtf (g7type, + g7flda, + g7fldn, + g7fldt, + g7desc) +TO STDOUT; + ++ +++Times Reported Time consuming queries #17
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ + +18 +0ms +2 + + +0ms +0ms +0ms ++ +LOCK TABLE lgdat.altmh IN access share mode; + ++ +++Times Reported Time consuming queries #18
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ + +19 +0ms +2 + + +0ms +0ms +0ms ++ +COPY lgdat.lbrd (n4btid, + "n4ent#", + "n4tag#", + n4empd, + n4empl, + n4mode, + n4dept, + n4resc, + n4rbtd, + n4part, + "n4seq#", + "n4job#", + "n4ref#", + n4indc, + n4sdat, + n4stim, + n4edat, + n4etim, + n4tmzn, + n4post, + n4ratf, + n4attc, + n4cdep, + n4cres, + n4proc, + n4rseq, + n4rent, + n4nhrs, + n4fut01, + n4fut02, + n4fut03, + n4fut04, + n4fut05, + n4fut06, + n4fut07, + n4fut08, + n4fut09, + n4fut10, + n4edttm, + n4inuse) +TO STDOUT; + ++ +++Times Reported Time consuming queries #19
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ + + +20 +0ms +2 + + +0ms +0ms +0ms ++ +LOCK TABLE lgdat.glcrc IN access share mode; + ++ +++Times Reported Time consuming queries #20
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
++ +Most frequent queries (N)
++++ +
++ + + + +Rank +Times executed +Total duration +Min duration +Max duration +Avg duration +Query ++ + +1 +5,220 + + +0ms +0ms +0ms +0ms ++ +SELECT + oid, + tableoid, + pol.polname, + pol.polcmd, + pol.polpermissive, + CASE WHEN pol.polroles = ? THEN + NULL + ELSE + pg_catalog.array_to_string(ARRAY ( + SELECT + pg_catalog.quote_ident(rolname) + FROM pg_catalog.pg_roles + WHERE + oid = ANY (pol.polroles)), ?) + END AS polroles, pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck + FROM + pg_catalog.pg_policy pol + WHERE + polrelid = ?; + ++ +++Times Reported Time consuming queries #1
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 2,610 0ms 0ms + +Mar 15 16 2,610 0ms 0ms ++ +-
+
+
+ + +2 +5,212 + + +0ms +0ms +0ms +0ms ++ +SELECT + a.attnum, + a.attname, + a.atttypmod, + a.attstattarget, + a.attstorage, + t.typstorage, + a.attnotnull, + a.atthasdef, + a.attisdropped, + a.attlen, + a.attalign, + a.attislocal, + pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname, + array_to_string(a.attoptions, ?) AS attoptions, + CASE WHEN a.attcollation <> t.typcollation THEN + a.attcollation + ELSE + ? + END AS attcollation, + a.attidentity, + pg_catalog.array_to_string(ARRAY ( + SELECT + pg_catalog.quote_ident(option_name) || ? || pg_catalog.quote_literal(option_value) + FROM pg_catalog.pg_options_to_table(attfdwoptions) + ORDER BY + option_name), e ?) AS attfdwoptions, + CASE WHEN a.atthasmissing + AND NOT a.attisdropped THEN + a.attmissingval + ELSE + NULL + END AS attmissingval + FROM + pg_catalog.pg_attribute a + LEFT JOIN pg_catalog.pg_type t ON a.atttypid = t.oid +WHERE + a.attrelid = ?::pg_catalog.oid + AND a.attnum > ?::pg_catalog.int2 +ORDER BY + a.attnum; + ++ +++Times Reported Time consuming queries #2
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 2,606 0ms 0ms + +Mar 15 16 2,606 0ms 0ms ++ +-
+
+
+ + +3 +5,190 + + +0ms +0ms +0ms +0ms ++ +SELECT + pr.tableoid, + pr.oid, + p.pubname +FROM + pg_publication_rel pr, + pg_publication p +WHERE + pr.prrelid = ? + AND p.oid = pr.prpubid; + ++ +++Times Reported Time consuming queries #3
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 2,595 0ms 0ms + +Mar 15 16 2,595 0ms 0ms ++ +-
+
+
+ + +4 +5,160 + + +0ms +0ms +0ms +0ms ++ +SELECT + at.attname, + ( + SELECT + pg_catalog.array_agg(acl + ORDER BY + row_n) + FROM ( + SELECT + acl, + row_n + FROM + pg_catalog.unnest(coalesce(at.attacl, pg_catalog.acldefault(?, c.relowner))) + WITH ordinality AS perm (acl, + row_n) + WHERE + NOT EXISTS ( + SELECT + ? + FROM + pg_catalog.unnest(coalesce(pip.initprivs, pg_catalog.acldefault(?, c.relowner))) AS init (init_acl) + WHERE + acl = init_acl)) AS foo) AS attacl, ( + SELECT + pg_catalog.array_agg(acl + ORDER BY + row_n) + FROM ( + SELECT + acl, + row_n + FROM + pg_catalog.unnest(coalesce(pip.initprivs, pg_catalog.acldefault(?, c.relowner))) + WITH ordinality AS initp (acl, + row_n) + WHERE + NOT EXISTS ( + SELECT + ? + FROM + pg_catalog.unnest(coalesce(at.attacl, pg_catalog.acldefault(?, c.relowner))) AS permp (orig_acl) + WHERE + acl = orig_acl)) AS foo) AS rattacl, NULL AS initattacl, NULL AS initrattacl +FROM + pg_catalog.pg_attribute at + JOIN pg_catalog.pg_class c ON (at.attrelid = c.oid) + LEFT JOIN pg_catalog.pg_init_privs pip ON (at.attrelid = pip.objoid + AND pip.classoid = ?::pg_catalog.regclass + AND at.attnum = pip.objsubid) +WHERE + at.attrelid = ?::pg_catalog.oid + AND NOT at.attisdropped + AND (( + SELECT + pg_catalog.array_agg(acl + ORDER BY + row_n) + FROM ( + SELECT + acl, + row_n + FROM + pg_catalog.unnest(coalesce(at.attacl, pg_catalog.acldefault(?, c.relowner))) + WITH ordinality AS perm (acl, + row_n) + WHERE + NOT EXISTS ( + SELECT + ? + FROM + pg_catalog.unnest(coalesce(pip.initprivs, pg_catalog.acldefault(?, c.relowner))) AS init (init_acl) + WHERE + acl = init_acl)) AS foo) + IS NOT NULL + OR ( + SELECT + pg_catalog.array_agg(acl + ORDER BY + row_n) + FROM ( + SELECT + acl, + row_n + FROM + pg_catalog.unnest(coalesce(pip.initprivs, pg_catalog.acldefault(?, c.relowner))) + WITH ordinality AS initp (acl, + row_n) + WHERE + NOT EXISTS ( + SELECT + ? + FROM + pg_catalog.unnest(coalesce(at.attacl, pg_catalog.acldefault(?, c.relowner))) AS permp (orig_acl) + WHERE + acl = orig_acl)) AS foo) + IS NOT NULL + OR NULL IS NOT NULL + OR NULL IS NOT NULL) + ORDER BY + at.attnum; + ++ +++Times Reported Time consuming queries #4
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 2,580 0ms 0ms + +Mar 15 16 2,580 0ms 0ms ++ +-
+
+
+ + +5 +912 + + +0ms +0ms +0ms +0ms ++ +SELECT + ? AS chart_name, + row_to_json(t) AS chart_data +FROM ( + SELECT + ( + SELECT + count(*) + FROM + pg_stat_activity + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Total", ( + SELECT + count(*) + FROM + pg_stat_activity + WHERE + state = ? + AND datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Active", ( + SELECT + count(*) + FROM + pg_stat_activity + WHERE + state = ? + AND datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Idle") t +UNION ALL +SELECT + ? AS chart_name, + row_to_json(t) AS chart_data +FROM ( + SELECT + ( + SELECT + sum(xact_commit) + sum(xact_rollback) + FROM + pg_stat_database + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Transactions", ( + SELECT + sum(xact_commit) + FROM + pg_stat_database + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Commits", ( + SELECT + sum(xact_rollback) + FROM + pg_stat_database + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Rollbacks") t +UNION ALL +SELECT + ? AS chart_name, + row_to_json(t) AS chart_data +FROM ( + SELECT + ( + SELECT + sum(tup_inserted) + FROM + pg_stat_database + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Inserts", ( + SELECT + sum(tup_updated) + FROM + pg_stat_database + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Updates", ( + SELECT + sum(tup_deleted) + FROM + pg_stat_database + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Deletes") t +UNION ALL +SELECT + ? AS chart_name, + row_to_json(t) AS chart_data +FROM ( + SELECT + ( + SELECT + sum(tup_fetched) + FROM + pg_stat_database + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Fetched", ( + SELECT + sum(tup_returned) + FROM + pg_stat_database + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Returned") t +UNION ALL +SELECT + ? AS chart_name, + row_to_json(t) AS chart_data +FROM ( + SELECT + ( + SELECT + sum(blks_read) + FROM + pg_stat_database + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Reads", ( + SELECT + sum(blks_hit) + FROM + pg_stat_database + WHERE + datname = ( + SELECT + datname + FROM + pg_database + WHERE + oid = ?)) AS "Hits") t; + ++ +++Times Reported Time consuming queries #5
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 18 09 912 0ms 0ms ++ +-
+
+
+ + +6 +378 + + +0ms +0ms +0ms +0ms ++ +SELECT + pg_catalog.format_type(?::pg_catalog.oid, NULL); + ++ +++Times Reported Time consuming queries #6
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 189 0ms 0ms + +Mar 15 16 189 0ms 0ms ++ +-
+
+
+ + +7 +190 + + +0ms +0ms +0ms +0ms ++ +SELECT + proretset, + prosrc, + probin, + pg_catalog.pg_get_function_arguments(oid) AS funcargs, + pg_catalog.pg_get_function_identity_arguments(oid) AS funciargs, + pg_catalog.pg_get_function_result(oid) AS funcresult, + array_to_string(protrftypes, ?) AS protrftypes, + prokind, + provolatile, + proisstrict, + prosecdef, + proleakproof, + proconfig, + procost, + prorows, + proparallel, + ( + SELECT + lanname + FROM + pg_catalog.pg_language + WHERE + oid = prolang) AS lanname + FROM + pg_catalog.pg_proc + WHERE + oid = ?::pg_catalog.oid; + ++ +++Times Reported Time consuming queries #7
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 95 0ms 0ms + +Mar 15 16 95 0ms 0ms ++ +-
+
+
+ + +8 +98 + + +0ms +0ms +0ms +0ms ++ +SELECT + oprkind, + oprcode::pg_catalog.regprocedure, + oprleft::pg_catalog.regtype, + oprright::pg_catalog.regtype, + oprcom, + oprnegate, + oprrest::pg_catalog.regprocedure, + oprjoin::pg_catalog.regprocedure, + oprcanmerge, + oprcanhash +FROM + pg_catalog.pg_operator +WHERE + oid = ?::pg_catalog.oid; + ++ +++Times Reported Time consuming queries #8
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 49 0ms 0ms + +Mar 15 16 49 0ms 0ms ++ +-
+
+
+ + +9 +46 + + +0ms +0ms +0ms +0ms ++ +discard ALL; + ++ +++Times Reported Time consuming queries #9
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 01 1 0ms 0ms 17 11 0ms 0ms Mar 15 00 7 0ms 0ms 09 1 0ms 0ms 14 2 0ms 0ms 15 1 0ms 0ms 16 2 0ms 0ms 17 5 0ms 0ms Mar 18 09 4 0ms 0ms 10 7 0ms 0ms 11 1 0ms 0ms 12 1 0ms 0ms 13 1 0ms 0ms 14 1 0ms 0ms + +15 1 0ms 0ms ++ +-
+
+
+ + +10 +42 + + +0ms +0ms +0ms +0ms ++ +SELECT + t.tableoid, + t.oid, + t.relname AS indexname, + inh.inhparent AS parentidx, + pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, + i.indnkeyatts AS indnkeyatts, + i.indnatts AS indnatts, + i.indkey, + i.indisclustered, + i.indisreplident, + t.relpages, + c.contype, + c.conname, + c.condeferrable, + c.condeferred, + c.tableoid AS contableoid, + c.oid AS conoid, + pg_catalog.pg_get_constraintdef(c.oid, FALSE) AS condef, + ( + SELECT + spcname + FROM + pg_catalog.pg_tablespace s + WHERE + s.oid = t.reltablespace) AS TABLESPACE, t.reloptions AS indreloptions, ( + SELECT + pg_catalog.array_agg(attnum + ORDER BY + attnum) + FROM + pg_catalog.pg_attribute + WHERE + attrelid = i.indexrelid + AND attstattarget >= ?) AS indstatcols, ( + SELECT + pg_catalog.array_agg(attstattarget + ORDER BY + attnum) + FROM + pg_catalog.pg_attribute + WHERE + attrelid = i.indexrelid + AND attstattarget >= ?) AS indstatvals + FROM + pg_catalog.pg_index i + JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) + JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) + LEFT JOIN pg_catalog.pg_constraint c ON (i.indrelid = c.conrelid + AND i.indexrelid = c.conindid + AND c.contype IN (...)) + LEFT JOIN pg_catalog.pg_inherits inh ON (inh.inhrelid = indexrelid) + WHERE + i.indrelid = ?::pg_catalog.oid + AND (i.indisvalid + OR t2.relkind = ?) + AND i.indisready + ORDER BY + indexname; + ++ +++Times Reported Time consuming queries #10
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 21 0ms 0ms + +Mar 15 16 21 0ms 0ms ++ +-
+
+
+ + +11 +37 + + +5m27s +2s217ms +27s560ms +8s855ms ++ +--create INDEX flag ON gld(plan, rolling); WITH un AS ( SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osmf osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.glec,?,?) <= ? AND substr(osm.fs_line,?,?) = ? AND calc_status <> ? AND ( --all orders OR shipments FOR the period ( --current year TO date orders od.cy = ? --current year TO date shipments OR sd.cy = ? ) OR --open orders sd.cm = ? --this works FOR forecast it indicates a future fspr ) GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) UNION ALL SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osm osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.fs_line,?,?) = ? AND substr(osm.glec,?,?) <= ? AND calc_status <> ? AND ( --all ORDER OR shipments FOR the period ( --current year TO date orders od.cy = ? --current year TO date shipments OR sd.cy = ? ) OR --open orders (calc_status IN (...) AND flag = ?) ) GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ) SELECT srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ,sum(qty) units ,sum(stdcost) "cost" ,sum(sales) sales FROM un GROUP BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ORDER BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ; ++ +++Times Reported Time consuming queries #11
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 17 17 2m29s 8s786ms Mar 15 00 5 58s394ms 11s678ms 17 5 1m2s 12s403ms + +Mar 18 10 10 57s886ms 5s788ms ++ + + +-
+
+
[ User: report - Total duration: 1m37s - Times executed: 7 ] +
+ +++ + + + +-
+
+
[ Application: [unknown] - Total duration: 1m37s - Times executed: 7 ] +
+ +++ +-
+
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
Date: 2019-03-14 17:15:07 +Duration: 27s560ms +
+ +++ + +Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.033..24368.549 rows=190996 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 227 + Buffers: shared hit=12201 + +
+Date: 2019-03-14 17:15:07 +Duration: 27s559ms +
+ +++ + +Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.018..23110.458 rows=167047 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 120 + Buffers: shared hit=10779 + +
+Date: 2019-03-15 17:30:39 +Duration: 21s242ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=99922.38..99922.88 rows=200 width=232) (actual time=21211.683..21211.708 rows=317 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 69kB + Buffers: shared hit=4 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + CTE un + -> Append (cost=32534.94..99887.14 rows=502 width=232) (actual time=5942.671..21209.531 rows=317 loops=1) + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + -> GroupAggregate (cost=32534.94..32547.80 rows=245 width=232) (actual time=5942.670..6367.056 rows=197 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Sort (cost=32534.94..32535.55 rows=245 width=185) (actual time=5942.642..5990.837 rows=406814 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 69497kB + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Nested Loop (cost=1006.06..32525.21 rows=245 width=185) (actual time=3.834..5526.120 rows=406814 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Hash Left Join (cost=1005.91..31588.56 rows=738 width=113) (actual time=3.809..3558.965 rows=406814 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared read=26345 written=122, local hit=2 + I/O Timings: read=10489.166 write=1.431 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=3.660..3400.209 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared read=26345 written=122 + I/O Timings: read=10489.166 write=1.431 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.781..3631.234 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared read=26345 written=122 + I/O Timings: read=10489.166 write=1.431 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.083..0.083 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.013..0.049 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=813627 read=1 + I/O Timings: read=0.006 + -> GroupAggregate (cost=67318.31..67331.81 rows=257 width=232) (actual time=14757.926..14842.413 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Sort (cost=67318.31..67318.96 rows=257 width=178) (actual time=14757.905..14766.226 rows=94732 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16394kB + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Nested Loop (cost=1006.06..67308.03 rows=257 width=178) (actual time=65.185..14658.975 rows=94732 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Hash Left Join (cost=1005.91..65849.40 rows=1114 width=122) (actual time=65.171..12232.663 rows=628518 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=1 read=57991 written=2, local hit=2 + I/O Timings: read=37441.627 write=0.074 + -> Gather (cost=1000.00..65829.04 rows=1114 width=51) (actual time=65.104..11994.997 rows=628518 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=1 read=57991 written=2 + I/O Timings: read=37441.627 write=0.074 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..64717.64 rows=464 width=51) (actual time=56.186..12707.976 rows=209506 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52157 + Buffers: shared hit=1 read=57991 written=2 + I/O Timings: read=37441.627 write=0.074 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.055..0.055 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.009..0.031 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=628518) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1255196 + -> HashAggregate (cost=25.10..27.60 rows=200 width=232) (actual time=21210.361..21210.698 rows=317 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + -> CTE Scan on un (cost=0.00..10.04 rows=502 width=232) (actual time=5942.675..21209.793 rows=317 loops=1) + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + +
++ + +12 +34 + + +0ms +0ms +0ms +0ms ++ +SELECT + typ.oid, + att.attname, + att.atttypid +FROM + pg_type AS typ + JOIN pg_namespace AS ns ON (ns.oid = typ.typnamespace) + JOIN pg_class AS cls ON (cls.oid = typ.typrelid) + JOIN pg_attribute AS att ON (att.attrelid = typ.typrelid) +WHERE (typ.typtype = ? + AND cls.relkind = ?) +AND attnum > ? +AND NOT attisdropped +ORDER BY + typ.typname, + att.attnum; + ++ +++Times Reported Time consuming queries #12
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 01 1 0ms 0ms 17 4 0ms 0ms Mar 15 00 5 0ms 0ms 09 1 0ms 0ms 14 2 0ms 0ms 15 1 0ms 0ms 16 2 0ms 0ms 17 4 0ms 0ms Mar 18 09 4 0ms 0ms 10 4 0ms 0ms 11 1 0ms 0ms 12 1 0ms 0ms 13 1 0ms 0ms 14 1 0ms 0ms 15 1 0ms 0ms + +16 1 0ms 0ms ++ +-
+
+
+ + +13 +34 + + +0ms +0ms +0ms +0ms ++ +SELECT + pg_type.oid, + enumlabel +FROM + pg_enum + JOIN pg_type ON pg_type.oid = enumtypid +ORDER BY + oid, + enumsortorder; + ++ +++Times Reported Time consuming queries #13
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 01 1 0ms 0ms 17 4 0ms 0ms Mar 15 00 5 0ms 0ms 09 1 0ms 0ms 14 2 0ms 0ms 15 1 0ms 0ms 16 2 0ms 0ms 17 4 0ms 0ms Mar 18 09 4 0ms 0ms 10 4 0ms 0ms 11 1 0ms 0ms 12 1 0ms 0ms 13 1 0ms 0ms 14 1 0ms 0ms 15 1 0ms 0ms + +16 1 0ms 0ms ++ +-
+
+
+ + +14 +28 + + +0ms +0ms +0ms +0ms ++ +--\timing --explain (ANALYZE, buffers) WITH mseq AS ( SELECT * FROM ( VALUES (?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ) x(m,s) ) --select * FROM mseq ,base AS ( SELECT order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ,sum(units) units ,sum(value_usd) value_usd FROM rlarp.osm_fcpool WHERE quota_rep_descr = ? AND segm = ? AND mod_chan = ? AND shipto_group = ? GROUP BY order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ) ,months AS ( SELECT order_season ,version ,iter ,order_month ,mseq.s seq ,sum(units) units ,sum(value_usd) value_usd FROM base INNER JOIN mseq ON mseq.m = base.order_month GROUP BY order_season ,version ,iter ,order_month ,s ) ,mpvt AS ( SELECT order_month ,seq ,sum(units) filter (WHERE order_season = ?) "? qty" ,sum(units) filter (WHERE order_season = ? AND iter = ?) "? base qty" ,sum(units) filter (WHERE order_season = ? AND iter <> ?) "? adj qty" ,sum(units) filter (WHERE order_season = ?) "? tot qty" ,sum(value_usd) filter (WHERE order_season = ?) "? value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter = ?) "? base value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter <> ?) "? adj value_usd" ,sum(value_usd) filter (WHERE order_season = ?) "? tot value_usd" FROM months GROUP BY order_month ,seq ORDER BY seq ASC ) ,mlist AS ( SELECT mseq.m order_month ,"? qty" ,"? base qty" ,"? adj qty" ,"? tot qty" ,"? value_usd" ,"? base value_usd" ,"? adj value_usd" ,"? tot value_usd" FROM mseq LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m ORDER BY mseq.s ASC ) ,totals AS ( SELECT order_season ,version ,iter ,sum(units) units ,sum(value_usd) value_usd FROM months GROUP BY order_season ,version ,iter ) SELECT jsonb_build_object( ? ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) ,? ,(SELECT jsonb_agg(row_to_json(mlist)::jsonb) FROM mlist) ,? ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) ,? ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) ) package; ++ +++Times Reported Time consuming queries #14
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 10 13 0ms 0ms 11 14 0ms 0ms + +12 1 0ms 0ms ++ +-
+
+
+ + +15 +25 + + +0ms +0ms +0ms +0ms ++ +BEGIN; + ++ +++Times Reported Time consuming queries #15
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 01 1 0ms 0ms 10 1 0ms 0ms 11 1 0ms 0ms 16 1 0ms 0ms 17 1 0ms 0ms Mar 15 00 2 0ms 0ms 09 2 0ms 0ms 14 3 0ms 0ms 15 1 0ms 0ms 16 4 0ms 0ms 17 1 0ms 0ms Mar 18 09 1 0ms 0ms 10 1 0ms 0ms 11 1 0ms 0ms 12 1 0ms 0ms 13 1 0ms 0ms 14 1 0ms 0ms + +15 1 0ms 0ms ++ +-
+
+
+ + +16 +25 + + +0ms +0ms +0ms +0ms ++ +COMMIT; + ++ +++Times Reported Time consuming queries #16
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 01 1 0ms 0ms 11 1 0ms 0ms 17 1 0ms 0ms Mar 15 00 3 0ms 0ms 09 2 0ms 0ms 14 4 0ms 0ms 15 1 0ms 0ms 16 4 0ms 0ms 17 1 0ms 0ms Mar 18 09 1 0ms 0ms 10 1 0ms 0ms 11 1 0ms 0ms 12 1 0ms 0ms 13 1 0ms 0ms 14 1 0ms 0ms + +15 1 0ms 0ms ++ +-
+
+
+ + +17 +24 + + +0ms +0ms +0ms +0ms ++ +--\timing --explain (ANALYZE, buffers) WITH mseq AS ( SELECT * FROM ( VALUES (?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ) x(m,s) ) --select * FROM mseq ,base AS ( SELECT order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ,sum(units) units ,sum(value_usd) value_usd FROM rlarp.osm_fcpool WHERE quota_rep_descr = ? AND segm = ? AND mod_chan = ? AND shipto_group = ? AND part_descr = ? GROUP BY order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ) ,months AS ( SELECT order_season ,version ,iter ,order_month ,mseq.s seq ,sum(units) units ,sum(value_usd) value_usd FROM base INNER JOIN mseq ON mseq.m = base.order_month GROUP BY order_season ,version ,iter ,order_month ,s ) ,mpvt AS ( SELECT order_month ,seq ,sum(units) filter (WHERE order_season = ?) "? qty" ,sum(units) filter (WHERE order_season = ? AND iter = ?) "? base qty" ,sum(units) filter (WHERE order_season = ? AND iter <> ?) "? adj qty" ,sum(units) filter (WHERE order_season = ?) "? tot qty" ,sum(value_usd) filter (WHERE order_season = ?) "? value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter = ?) "? base value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter <> ?) "? adj value_usd" ,sum(value_usd) filter (WHERE order_season = ?) "? tot value_usd" FROM months GROUP BY order_month ,seq ORDER BY seq ASC ) ,mlist AS ( SELECT mseq.m order_month ,"? qty" ,"? base qty" ,"? adj qty" ,"? tot qty" ,"? value_usd" ,"? base value_usd" ,"? adj value_usd" ,"? tot value_usd" FROM mseq LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m ORDER BY mseq.s ASC ) ,totals AS ( SELECT order_season ,version ,iter ,sum(units) units ,sum(value_usd) value_usd FROM months GROUP BY order_season ,version ,iter ) SELECT jsonb_build_object( ? ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) ,? ,(SELECT jsonb_agg(row_to_json(mlist)::jsonb) FROM mlist) ,? ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) ,? ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) ) package; ++ +++Times Reported Time consuming queries #17
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 11 11 0ms 0ms + +12 13 0ms 0ms ++ +-
+
+
+ + +18 +22 + + +0ms +0ms +0ms +0ms ++ +SELECT + pg_catalog.pg_get_viewdef(?::pg_catalog.oid) AS viewdef; + ++ +++Times Reported Time consuming queries #18
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 11 0ms 0ms + +Mar 15 16 11 0ms 0ms ++ +-
+
+
+ + +19 +22 + + +0ms +0ms +0ms +0ms ++ +--\timing --explain (ANALYZE, buffers) WITH mseq AS ( SELECT * FROM ( VALUES (?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ) x(m,s) ) --select * FROM mseq ,base AS ( SELECT order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ,sum(units) units ,sum(value_usd) value_usd FROM rlarp.osm_fcpool WHERE quota_rep_descr = ? AND segm = ? AND mod_chan = ? AND part_descr = ? GROUP BY order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ) ,months AS ( SELECT order_season ,version ,iter ,order_month ,mseq.s seq ,sum(units) units ,sum(value_usd) value_usd FROM base INNER JOIN mseq ON mseq.m = base.order_month GROUP BY order_season ,version ,iter ,order_month ,s ) ,mpvt AS ( SELECT order_month ,seq ,sum(units) filter (WHERE order_season = ?) "? qty" ,sum(units) filter (WHERE order_season = ? AND iter = ?) "? base qty" ,sum(units) filter (WHERE order_season = ? AND iter <> ?) "? adj qty" ,sum(units) filter (WHERE order_season = ?) "? tot qty" ,sum(value_usd) filter (WHERE order_season = ?) "? value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter = ?) "? base value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter <> ?) "? adj value_usd" ,sum(value_usd) filter (WHERE order_season = ?) "? tot value_usd" FROM months GROUP BY order_month ,seq ORDER BY seq ASC ) ,mlist AS ( SELECT mseq.m order_month ,"? qty" ,"? base qty" ,"? adj qty" ,"? tot qty" ,"? value_usd" ,"? base value_usd" ,"? adj value_usd" ,"? tot value_usd" FROM mseq LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m ORDER BY mseq.s ASC ) ,totals AS ( SELECT order_season ,version ,iter ,sum(units) units ,sum(value_usd) value_usd FROM months GROUP BY order_season ,version ,iter ) SELECT jsonb_build_object( ? ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) ,? ,(SELECT jsonb_agg(row_to_json(mlist)::jsonb) FROM mlist) ,? ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) ,? ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) ) package; ++ +++Times Reported Time consuming queries #19
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 15 11 1 0ms 0ms 14 1 0ms 0ms 15 10 0ms 0ms + +16 10 0ms 0ms ++ +-
+
+
+ + + +20 +20 + + +0ms +0ms +0ms +0ms ++ +SELECT + tgname, + tgfoid::pg_catalog.regproc AS tgfname, + pg_catalog.pg_get_triggerdef(oid, FALSE) AS tgdef, + tgenabled, + tableoid, + oid +FROM + pg_catalog.pg_trigger t +WHERE + tgrelid = ?::pg_catalog.oid + AND NOT tgisinternal; + ++ +++Times Reported Time consuming queries #20
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 10 0ms 0ms + +Mar 15 16 10 0ms 0ms ++ +-
+
+
++ +Normalized slowest queries (N)
++++ +
++ + + + +Rank +Min duration +Max duration +Avg duration +Times executed +Total duration +Query ++ + +1 +2m30s +4m7s +3m14s +3 + + +9m44s ++ +INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++ +++Times Reported Time consuming queries #1
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 15 00 1 4m7s 4m7s 14 1 2m30s 2m30s + +16 1 3m6s 3m6s ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 9m44s - Times executed: 3 ] +
+ +++ + + + +-
+
+
[ Application: psql - Total duration: 9m44s - Times executed: 3 ] +
+ +++ +-
+
+
-
+ INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++
+
-
+ INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++
+
-
+ INSERT INTO rlarp.osm_ppfa_varto_mv +SELECT + * +FROM + rlarp.osm_ppfa_varto (); + ++
+
Date: 2019-03-15 00:53:37 +Duration: 4m7s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm_ppfa_varto_mv (cost=0.25..10.25 rows=1000 width=1520) (actual time=247216.314..247216.314 rows=0 loops=1) + Buffers: shared hit=1716294 read=197994 dirtied=106936 written=127, local hit=5658761 read=4 dirtied=2, temp read=384787 written=401694 + I/O Timings: read=8265.132 write=1.395 + -> Function Scan on osm_ppfa_varto (cost=0.25..10.25 rows=1000 width=1520) (actual time=209413.211..214181.385 rows=1377873 loops=1) + Buffers: shared hit=106558 read=91107 dirtied=50, local hit=5658761 read=4 dirtied=2, temp read=384787 written=401694 + I/O Timings: read=8253.083 + +
+Date: 2019-03-15 16:48:41 +Duration: 3m6s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm_ppfa_varto_mv (cost=0.25..10.25 rows=1000 width=1520) (actual time=186692.239..186692.239 rows=0 loops=1) + Buffers: shared hit=1652058 read=262701 dirtied=107023 written=340, local hit=5660301 read=4 dirtied=2, temp read=384981 written=401910 + I/O Timings: read=5890.327 write=3.241 + -> Function Scan on osm_ppfa_varto (cost=0.25..10.25 rows=1000 width=1520) (actual time=152354.359..164471.890 rows=1378962 loops=1) + Buffers: shared hit=40911 read=155742 dirtied=65, local hit=5660301 read=4 dirtied=2, temp read=384981 written=401910 + I/O Timings: read=5888.364 + +
+Date: 2019-03-15 14:09:42 +Duration: 2m30s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm_ppfa_varto_mv (cost=0.25..10.25 rows=1000 width=1520) (actual time=150711.860..150711.860 rows=0 loops=1) + Buffers: shared hit=1649817 read=264466 dirtied=106965 written=88, local hit=5659525 read=4 dirtied=2, temp read=384879 written=401797 + I/O Timings: read=5508.081 write=14.599 + -> Function Scan on osm_ppfa_varto (cost=0.25..10.25 rows=1000 width=1520) (actual time=127165.594..135951.084 rows=1378380 loops=1) + Buffers: shared hit=39318 read=157546 dirtied=46, local hit=5659525 read=4 dirtied=2, temp read=384879 written=401797 + I/O Timings: read=5507.907 + +
++ + +2 +2m2s +3m19s +2m36s +3 + + +7m50s ++ +pl / pgsql FUNCTION rlarp.osm_ppfa_varto () +line ? at RETURN querywith ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- seg AS ( SELECT x.glec ,x.segm FROM ( VALUES (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?), (?,?) ) x(glec, segm) ) ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- ,mg AS ( SELECT x.f1, x.ming, x.grp FROM ( VALUES (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?), (?,?,?) ) AS x (f1, ming, grp) ) ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- ,repc AS ( SELECT ltrim(rtrim(c.a9)) rcode ,ltrim(rtrim(c.a9)) || ? || c.a30 repp ,coalesce(q.dir,?) director FROM lgdat.code c LEFT OUTER JOIN rlarp.qrh q ON q.qr = ltrim(rtrim(c.a9)) WHERE c.a2 = ? ) --mold descriptions ,md AS ( SELECT u.mold ,max(u.descr) descr FROM ( SELECT substr(m.avpart,?,?) mold ,max(m.avdes1) descr FROM lgdat.stkmm m WHERE length(m.avpart) > ? AND substr(m.avgled,?,?) <= ? GROUP BY substr(m.avpart,?,?) UNION ALL SELECT substr(p.awpart,?,?) mold ,max(p.awdes1) descr FROM lgdat.stkmp p WHERE length(p.awpart) > ? AND substr(p.awgled,?,?) <= ? GROUP BY substr(p.awpart,?,?) ) u GROUP BY u.mold ) ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- ,sj AS ( SELECT * FROM lgdat.mmsl WHERE coalesce(bsmncd,?) = ? ) ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- ,si AS ( SELECT * FROM lgdat.mmsl WHERE coalesce(bsmncd,?) <> ? ) ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ ,seas AS( SELECT ssyr ,daterange(min(sdat),max(edat),?) dr ,current_date <@ daterange(min(sdat),max(edat),?) cy FROM gld GROUP BY ssyr ORDER BY ssyr DESC ) ,intv AS ( SELECT current_date - lower(dr) dy FROM seas WHERE cy = TRUE ) ,std AS ( SELECT s.ssyr ,s.dr ,s.cy ,daterange(lower(dr),dy + lower(dr),?) ytd FROM seas s CROSS JOIN intv ) ---------------------------------------union actual AND forecast--------------------------------------------------------------------------------------------------------------------------------------- ,un AS ( --plan SELECT ? AS version ,? iter ,od.ssyr oseas ,osm.adj_orderdate AS odate ,sd.ssyr sseas ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) sdate ,rd.ssyr rseas ,osm.adj_requestdate rdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,coalesce(rd.cy,?) ry ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) part_descr ,f.f3||?||f.descr part_family ,substr(osm.part,?,?)||?||md.descr part_group ,coalesce(mg.grp,?) branding ,coalesce(seg.segm,?) segm ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END calc_status ,osm.c_rate ,sum( osm.fb_qty ) qty ,sum( osm.fb_val_loc * osm.r_rate) sales ,sum( osm.fb_cst_loc * osm.c_rate) stdcost ,sum( osm.fb_cst_loc_cur * osm.c_rate) stdcost_cur ,sum( osm.fb_qty * coalesce(m.avnwht,p.awnwht) * CASE coalesce(m.avnwun, p.awnwun) WHEN ? THEN ?.? ELSE ? END) pounds FROM rlarp.osmp osm LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr LEFT OUTER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld rd ON osm.adj_requestdate BETWEEN rd.sdat AND rd.edat LEFT OUTER JOIN seg ON seg.glec = osm.glec --and seg.segm <> ? LEFT OUTER JOIN mg ON mg.f1 = substr(osm.part,?,?) AND mg.ming = osm.ming LEFT OUTER JOIN rlarp.family f ON f.f3 = substr(osm.part,?,?) LEFT OUTER JOIN lgdat.stkmm m ON m.avpart = osm.part LEFT OUTER JOIN lgdat.stkmp p ON p.awpart = osm.part LEFT OUTER JOIN md ON md.mold = substr(osm.part,?,?) LEFT OUTER JOIN rlarp.ffchnl l ON l.bill = osm.bill_class AND l.ship = osm.ship_class WHERE osm.fs_line = ? AND osm.calc_status <> ? AND substr(osm.glec,?,?) <= ? AND osm.version = ? AND ( osm.fspr >= ? OR osm.adj_orderdate >= ? ) GROUP BY --version --iter od.ssyr ,osm.adj_orderdate ,sd.ssyr ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) ,rd.ssyr ,osm.adj_requestdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ,coalesce(rd.cy,?) ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) ,f.f3||?||f.descr ,substr(osm.part,?,?)||?||md.descr ,coalesce(mg.grp,?) ,coalesce(seg.segm,?) ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END ,osm.c_rate UNION ALL --staged forecast SELECT ? AS version ,? iter ,od.ssyr oseas ,osm.adj_orderdate odate ,sd.ssyr sseas ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) sdate ,rd.ssyr rseas ,osm.adj_requestdate rdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,coalesce(rd.cy,?) ry ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) part_descr ,f.f3||?||f.descr part_family ,substr(osm.part,?,?)||?||md.descr part_group ,coalesce(mg.grp,?) branding ,coalesce(seg.segm,?) segm ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END calc_status ,osm.c_rate ,sum( osm.fb_qty ) qty ,sum( osm.fb_val_loc * osm.r_rate) sales ,sum( osm.fb_cst_loc * osm.c_rate) stdcost ,sum( osm.fb_cst_loc_cur * osm.c_rate) stdcost_cur ,sum( osm.fb_qty * coalesce(m.avnwht,p.awnwht) * CASE coalesce(m.avnwun, p.awnwun) WHEN ? THEN ?.? ELSE ? END) pounds FROM rlarp.osmf osm LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr LEFT OUTER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld rd ON osm.adj_requestdate BETWEEN rd.sdat AND rd.edat LEFT OUTER JOIN seg ON seg.glec = osm.glec --and seg.segm <> ? LEFT OUTER JOIN mg ON mg.f1 = substr(osm.part,?,?) AND mg.ming = osm.ming LEFT OUTER JOIN rlarp.family f ON f.f3 = substr(osm.part,?,?) LEFT OUTER JOIN lgdat.stkmm m ON m.avpart = osm.part LEFT OUTER JOIN lgdat.stkmp p ON p.awpart = osm.part LEFT OUTER JOIN md ON md.mold = substr(osm.part,?,?) LEFT OUTER JOIN rlarp.ffchnl l ON l.bill = osm.bill_class AND l.ship = osm.ship_class WHERE osm.fs_line = ? AND osm.calc_status <> ? AND substr(osm.glec,?,?) <= ? AND osm.version = ? AND ( osm.fspr >= ? OR osm.adj_orderdate >= ? ) GROUP BY --version --iter od.ssyr ,osm.adj_orderdate ,sd.ssyr ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) ,rd.ssyr ,osm.adj_requestdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ,coalesce(rd.cy,?) ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) ,f.f3||?||f.descr ,substr(osm.part,?,?)||?||md.descr ,coalesce(mg.grp,?) ,coalesce(seg.segm,?) ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END ,osm.c_rate UNION ALL --actual SELECT ? AS version ,? iter ,od.ssyr oseas ,osm.adj_orderdate odate ,sd.ssyr sseas ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) sdate ,rd.ssyr rseas ,osm.adj_requestdate rdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,coalesce(rd.cy,?) ry ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) part_descr ,f.f3||?||f.descr part_family ,substr(osm.part,?,?)||?||md.descr part_group ,coalesce(mg.grp,?) branding ,coalesce(seg.segm,?) segm ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END calc_status ,osm.c_rate ,sum( osm.fb_qty ) qty ,sum( osm.fb_val_loc * osm.r_rate) sales ,sum( osm.fb_cst_loc * osm.c_rate) stdcost ,sum( osm.fb_cst_loc_cur * osm.c_rate) stdcost_cur ,sum( osm.fb_qty * coalesce(m.avnwht,p.awnwht) * CASE coalesce(m.avnwun, p.awnwun) WHEN ? THEN ?.? ELSE ? END) pounds FROM rlarp.osm osm LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr LEFT OUTER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld rd ON osm.adj_requestdate BETWEEN rd.sdat AND rd.edat LEFT OUTER JOIN seg ON seg.glec = osm.glec --and seg.segm <> ? LEFT OUTER JOIN mg ON mg.f1 = substr(osm.part,?,?) AND mg.ming = osm.ming LEFT OUTER JOIN rlarp.family f ON f.f3 = substr(osm.part,?,?) LEFT OUTER JOIN lgdat.stkmm m ON m.avpart = osm.part LEFT OUTER JOIN lgdat.stkmp p ON p.awpart = osm.part LEFT OUTER JOIN md ON md.mold = substr(osm.part,?,?) LEFT OUTER JOIN rlarp.ffchnl l ON l.bill = osm.bill_class AND l.ship = osm.ship_class WHERE osm.fs_line = ? --and substr(osm.glec,?,?) <= ? AND osm.calc_status <> ? AND ( osm.fspr >= ? OR osm.adj_orderdate >= ? ) GROUP BY --version od.ssyr ,osm.adj_orderdate ,sd.ssyr ,least(greatest(osm.adj_shipdate,sd.sdat),sd.edat) ,rd.ssyr ,osm.adj_requestdate --if the ORDER period IS NULL, THEN there isn?f?f?t one, just assign TO invoice period ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ,coalesce(rd.cy,?) ,osm.plnt ,osm.account ,osm.bill_cust ,osm.shipgrp ,osm.ship_cust ,osm.chan ,l.retail ,l.retailsub ,osm.promo ,osm.majg ,osm.ming ,osm.majs ,osm.mins ,osm.part ,osm.part || ? || rtrim(coalesce(m.avdes1,p.awdes1)) ,f.f3||?||f.descr ,substr(osm.part,?,?)||?||md.descr ,coalesce(mg.grp,?) ,coalesce(seg.segm,?) ,osm.quota_rep ,case osm.fspr WHEN ? THEN ? ELSE osm.calc_status END ,osm.c_rate ) ---------------------------------------aggregate actual AND forecast----------------------------------------------------------------------------------------------------------------------------------- ,agg AS ( SELECT un.version::text "version" ,un.iter::text "iter" ,un.oseas::numeric oseas ,un.odate::date odate ,un.sseas::numeric sseas ,un.sdate::date sdate ,un.rseas::numeric rseas ,un.rdate::date rdate ,un.om::text om ,un.sm::text sm ,un.rm::text rm ,un.oy::text oy ,(un.odate <@ _ytd)::boolean ocytd --current year TO date ,(un.odate <@ so.ytd)::boolean oytd --year TO date recast FOR prior/forecast periods ,un.sy::text sy ,(un.sdate <@ _ytd)::boolean scytd ,(un.sdate <@ ss.ytd)::boolean sytd --had this ORDER been placed yet? (current day prior year IS greater than the ORDER date) ,case WHEN (upper(so.ytd) - interval ?) >= un.odate THEN --was the ORDER OPEN at this time LAST year? (FOR orders that were placed BY this time, was the ship date greater THEN the ORDER date) CASE WHEN ((un.sdate > (upper(so.ytd) - interval ?)) OR (un.sy = ?)) --for orders that were placed AND OPEN at this time LAST year, was the ORDER considered past due? (current date prior year > request date) THEN CASE WHEN (upper(so.ytd) - interval ?) > un.rdate THEN ? ELSE ? END ELSE ? END ELSE ? END status_py ,un.ry::text ry ,un.plnt::text plnt ,un.account::text bill_group ,(un.bill_cust || ? || rtrim(bc.bvname))::text bill_cust ,bc.bvctry bill_ctry ,bc.bvprcd bill_prov ,un.shipgrp::text ship_group ,(un.ship_cust || ? || rtrim(sc.bvname))::text ship_cust ,sc.bvctry ship_ctry ,sc.bvprcd ship_prov ,un.chan::text chan ,case un.segm WHEN ? THEN un.retail ELSE un.chan END::text mod_chan ,case un.segm WHEN ? THEN un.retailsub ELSE ? END::text mod_chansub ,un.promo::text promo ,un.majg||coalesce(?||bqdes,?)::text majg ,un.ming||coalesce(?||brdes,?)::text ming ,un.majs||coalesce(?||sj.bsdes1,?)::text majs ,un.mins||coalesce(?||si.bsdes1,?)::text mins ,un.part::text part ,un.part_descr::text part_descr ,un.part_family::text part_family ,un.part_group::text part_group ,un.branding::text branding ,un.segm::text segm ,coalesce(repc.repp,un.quota_rep)::text quota_rep ,coalesce(repc.director,un.quota_rep)::text director ,sum(un.qty)::numeric qty ,sum(un.sales)::numeric sales ,sum(un.stdcost)::numeric stdcost ,sum(un.qty * coalesce(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur ,sum(un.pounds)::numeric pounds ,(un.version||?||un.sy)::text flag_s ,(un.version||?||un.oy)::text flag_o ,case WHEN un.calc_status IN (...) THEN CASE WHEN un.rdate < current_date THEN ? ELSE ? END ELSE un.calc_status END::text status ,(substr(un.part,?,?)||?||un.branding)::text "options" ,?::text grandtotal FROM un LEFT OUTER JOIN repc ON repc.rcode = un.quota_rep LEFT OUTER JOIN si ON si.bsmjcd = un.majs AND si.bsmncd = un.mins LEFT OUTER JOIN sj ON sj.bsmjcd = un.majs LEFT OUTER JOIN lgdat.majg ON bqgrp = un.majg LEFT OUTER JOIN lgdat.mmgp ON brmgrp = un.ming AND brgrp = un.majg LEFT OUTER JOIN lgdat.cust bc ON bc.bvcust = un.bill_cust LEFT OUTER JOIN lgdat.cust sc ON sc.bvcust = un.bill_cust LEFT OUTER JOIN lgdat.icstm cm ON cm.cgpart = un.part AND cm.cgplnt = un.plnt LEFT OUTER JOIN lgdat.icstp cp ON cp.chpart = un.part AND cp.chplnt = un.plnt LEFT OUTER JOIN lgdat.icstr cr ON cr.y0part = un.part AND cr.y0plnt = un.plnt LEFT OUTER JOIN std so ON so.ssyr = un.oseas LEFT OUTER JOIN std ss ON ss.ssyr = un.sseas GROUP BY un.version::text ,un.iter::text ,un.oseas::numeric ,un.odate::date ,un.sseas::numeric ,un.sdate::date ,un.rseas::numeric ,un.rdate::date ,un.om::text ,un.sm::text ,un.rm::text ,un.oy::text --current year TO date ,(un.odate <@ _ytd)::boolean --year TO date recast FOR prior/forecast periods ,(un.odate <@ so.ytd)::boolean ,un.sy::text ,(un.sdate <@ _ytd)::boolean ,(un.sdate <@ ss.ytd)::boolean ,case WHEN (upper(so.ytd) - interval ?) >= un.odate THEN --was the ORDER OPEN at this time LAST year? (FOR orders that were placed BY this time, was the ship date greater THEN the ORDER date) CASE WHEN ((un.sdate > (upper(so.ytd) - interval ?)) OR (un.sy = ?)) --for orders that were placed AND OPEN at this time LAST year, was the ORDER considered past due? (current date prior year > request date) THEN CASE WHEN (upper(so.ytd) - interval ?) > un.rdate THEN ? ELSE ? END ELSE ? END ELSE ? END ,un.ry::text ,un.plnt::text ,un.account::text ,(un.bill_cust || ? || rtrim(bc.bvname))::text ,bc.bvctry ,bc.bvprcd ,un.shipgrp::text ,(un.ship_cust || ? || rtrim(sc.bvname))::text ,sc.bvctry ,sc.bvprcd ,un.chan::text ,case un.segm WHEN ? THEN un.retail ELSE un.chan END::text ,case un.segm WHEN ? THEN un.retailsub ELSE ? END::text ,un.promo::text ,un.majg||coalesce(?||bqdes,?)::text ,un.ming||coalesce(?||brdes,?)::text ,un.majs||coalesce(?||sj.bsdes1,?)::text ,un.mins||coalesce(?||si.bsdes1,?)::text ,un.part::text ,un.part_descr::text ,un.part_family::text ,un.part_group::text ,un.branding::text ,un.segm::text ,coalesce(repc.repp,un.quota_rep)::text ,coalesce(repc.director,un.quota_rep)::text ,(un.version||?||un.sy)::text ,(un.version||?||un.oy)::text ,case WHEN un.calc_status IN (...) THEN CASE WHEN un.rdate < current_date THEN ? ELSE ? END ELSE un.calc_status END::text ,(substr(un.part,?,?)||?||un.branding)::text ,?::text ) SELECT a.version ,a.iter ,a.oseas ,a.odate ,a.sseas ,a.sdate ,a.rseas ,a.rdate ,a.om ,a.sm ,a.rm ,a.oy ,a.ocytd ,a.oytd ,a.sy ,a.scytd ,a.sytd ,a.status_py ,a.ry ,a.plnt ,a.bill_group ,a.bill_cust ,a.bill_ctry ,a.bill_prov ,a.ship_group ,a.ship_cust ,a.ship_ctry ,a.ship_prov ,a.chan ,a.mod_chan ,a.mod_chansub ,a.promo ,a.majg ,a.ming ,a.majs ,a.mins ,a.part ,a.part_descr ,a.part_family ,a.part_group ,a.branding ,a.segm ,a.quota_rep ,a.director ,a.qty ,a.sales ,a.stdcost ,a.stdcost_cur ,a.pounds ,a.flag_s ,a.flag_o ,a.status ,a.options ,a.grandtotal FROM agg a UNION ALL SELECT ? AS version ,? AS iter ,a.oseas ,a.odate ,a.sseas ,a.sdate ,a.rseas ,a.rdate ,a.om ,a.sm ,a.rm ,a.oy ,a.ocytd ,a.oytd ,a.sy ,a.scytd ,a.sytd ,a.status_py ,a.ry ,a.plnt ,a.bill_group ,a.bill_cust ,a.bill_ctry ,a.bill_prov ,a.ship_group ,a.ship_cust ,a.ship_ctry ,a.ship_prov ,a.chan ,a.mod_chan ,a.mod_chansub ,a.promo ,a.majg ,a.ming ,a.majs ,a.mins ,a.part ,a.part_descr ,a.part_family ,a.part_group ,a.branding ,a.segm ,a.quota_rep ,a.director ,case a.version WHEN ? THEN a.qty ELSE -a.qty END::numeric qty ,case a.version WHEN ? THEN a.sales ELSE -a.sales END::numeric sales ,case a.version WHEN ? THEN a.stdcost ELSE -a.stdcost END::numeric stdcost ,case a.version WHEN ? THEN a.stdcost_cur ELSE -a.stdcost_cur END::numeric stdcost_cur ,case a.version WHEN ? THEN a.pounds ELSE -a.pounds END::numeric pounds ,?||?||a.scytd flag_s ,?||?||a.ocytd flag_o ,a.status ,a.options ,a.grandtotal FROM agg a WHERE a.version IN (...) AND (a.ocytd OR a.scytd) UNION ALL SELECT ? AS version ,? AS iter ,a.oseas ,a.odate ,a.sseas ,a.sdate ,a.rseas ,a.rdate ,a.om ,a.sm ,a.rm ,a.oy ,a.ocytd ,a.oytd ,a.sy ,a.scytd ,a.sytd ,a.status_py ,a.ry ,a.plnt ,a.bill_group ,a.bill_cust ,a.bill_ctry ,a.bill_prov ,a.ship_group ,a.ship_cust ,a.ship_ctry ,a.ship_prov ,a.chan ,a.mod_chan ,a.mod_chansub ,a.promo ,a.majg ,a.ming ,a.majs ,a.mins ,a.part ,a.part_descr ,a.part_family ,a.part_group ,a.branding ,a.segm ,a.quota_rep ,a.director ,case a.version WHEN ? THEN a.qty ELSE -a.qty END::numeric qty ,case a.version WHEN ? THEN a.sales ELSE -a.sales END::numeric sales ,case a.version WHEN ? THEN a.stdcost ELSE -a.stdcost END::numeric stdcost ,case a.version WHEN ? THEN a.stdcost_cur ELSE -a.stdcost_cur END::numeric stdcost_cur ,case a.version WHEN ? THEN a.pounds ELSE -a.pounds END::numeric pounds ,?||?||a.scytd flag_s ,?||?||a.ocytd flag_o ,a.status ,a.options ,a.grandtotal FROM agg a WHERE a.version IN (...) AND (a.ocytd OR a.scytd) ; ++ +++Times Reported Time consuming queries #2
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 15 00 1 3m19s 3m19s 14 1 2m2s 2m2s + +16 1 2m28s 2m28s ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 7m50s - Times executed: 3 ] +
+ +++ + + + +-
+
+
[ Application: psql - Total duration: 7m50s - Times executed: 3 ] +
+ +++ +-
+
+
-
+ PL/pgSQL function rlarp.osm_ppfa_varto() line 69 at RETURN QUERYWITH + ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- + SEG AS ( + SELECT + x.GLEC + ,x.SEGM + FROM + ( + VALUES + ('1CU','Retail'), + ('1GR','Greenhouse'), + ('1NU','Nursery'), + ('1RE','Retail'), + ('2WI','Greenhouse'), + ('3BM','Other'), + ('3CO','Other'), + ('3PE','Other'), + ('3PP','Other'), + ('4CO','Other'), + ('4RA','Other'), + ('9MI','Other'), + ('9SA','Other'), + ('9TO','Other') + ) X(GLEC, SEGM) + ) + ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- + ,MG AS ( + SELECT + X.F1, X.MING, X.GRP + FROM + ( + VALUES + ('L','000','Branded'), + ('L','B10','Branded'), + ('L','B11','Branded'), + ('L','B52','Branded'), + ('L','C10','Branded'), + ('L','D12','Branded'), + ('L','M11','Branded'), + ('L','P12','Branded'), + ('L','P13','Branded'), + ('L','S10','Branded'), + ('L','Y10','Branded'), + ('L','Y11','Branded'), + ('L','Y12','Branded'), + ('P','B10','Branded'), + ('P','B11','Branded'), + ('P','B52','Branded') + ) AS X (F1, MING, GRP) + ) + ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- + ,REPC AS ( + SELECT + LTRIM(RTRIM(C.A9)) RCODE + ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP + ,COALESCE(Q.DIR,'Other') DIRECTOR + FROM + LGDAT.CODE C + LEFT OUTER JOIN RLARP.QRH Q ON + Q.QR = LTRIM(RTRIM(C.A9)) + WHERE + C.A2 = 'MM' + ) + --MOLD DESCRIPTIONS + ,MD AS ( + SELECT + U.MOLD + ,MAX(U.DESCR) DESCR + FROM + ( + SELECT + SUBSTR(M.AVPART,1,8) MOLD + ,MAX(M.AVDES1) DESCR + FROM + LGDAT.STKMM M + WHERE + LENGTH(M.AVPART) > 8 + AND SUBSTR(M.AVGLED,1,1) <= '2' + GROUP BY + SUBSTR(M.AVPART,1,8) + UNION ALL + SELECT + SUBSTR(P.AWPART,1,8) MOLD + ,MAX(P.AWDES1) DESCR + FROM + LGDAT.STKMP P + WHERE + LENGTH(P.AWPART) > 8 + AND SUBSTR(P.AWGLED,1,1) <= '2' + GROUP BY + SUBSTR(P.AWPART,1,8) + ) U + GROUP BY + U.MOLD + ) + ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- + ,SJ AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = '' + ) + ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- + ,SI AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> '' + ) + ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ + ,seas AS( + SELECT + ssyr + ,daterange(MIN(sdat),MAX(edat),'[]') dr + ,current_date <@ daterange(MIN(sdat),MAX(edat),'[]') cy + FROM + gld + GROUP BY + ssyr + ORDER BY + ssyr DESC + ) + ,intv AS ( + SELECT current_date - lower(dr) dy from seas where cy = true + ) + ,std AS ( + SELECT + s.ssyr + ,s.dr + ,s.cy + ,daterange(lower(dr),dy + LOWER(dr),'[]') ytd + FROM + seas s + CROSS JOIN intv + ) + ---------------------------------------union actual and forecast--------------------------------------------------------------------------------------------------------------------------------------- + ,UN AS ( + --plan + SELECT + 'Budget' AS VERSION + ,'Budget' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE as ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(m.avNWHT,p.awNWHT) * CASE COALESCE(m.avNWUN, p.awNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMP OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = 'b19' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --staged forecast + SELECT + 'Forecast' AS VERSION + ,'Forecast' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMF OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = '5p7' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --actual + SELECT + 'Actual' AS VERSION + ,'Actual' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSM OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + --AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.CALC_STATUS <> 'CANCELED' + AND + ( + OSM.FSPR >= '1606' + OR OSM.ADJ_ORDERDATE >= '2016-06-01' + ) + GROUP BY + --VERSION + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + ) + ---------------------------------------aggregate actual and forecast----------------------------------------------------------------------------------------------------------------------------------- + ,AGG AS ( + SELECT + un.VERSION::text "version" + ,un.ITER::text "iter" + ,un.OSEAS::numeric oseas + ,un.ODATE::date odate + ,un.SSEAS::numeric sseas + ,un.SDATE::date sdate + ,un.RSEAS::numeric rseas + ,un.RDATE::date rdate + ,un.OM::text om + ,un.SM::text sm + ,un.RM::text rm + ,un.OY::text oy + ,(un.odate <@ _ytd)::boolean ocytd --current year to date + ,(un.odate <@ so.ytd)::boolean oytd --year to date recast for prior/forecast periods + ,un.SY::text sy + ,(un.sdate <@ _ytd)::boolean scytd + ,(un.sdate <@ ss.ytd)::boolean sytd + --had this order been placed yet? (current day prior year is greater than the order date) + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END status_py + ,un.RY::text ry + ,un.PLNT::text plnt + ,un.ACCOUNT::text bill_group + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text bill_cust + ,bc.bvctry bill_ctry + ,bc.bvprcd bill_prov + ,un.SHIPGRP::text ship_group + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text ship_cust + ,sc.bvctry ship_ctry + ,sc.bvprcd ship_prov + ,un.CHAN::text chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text mod_chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text mod_chansub + ,un.PROMO::text promo + ,un.MAJG||COALESCE(' - '||BQDES,'')::text majg + ,un.MING||COALESCE(' - '||BRDES,'')::text ming + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text majs + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text mins + ,un.PART::text part + ,un.PART_DESCR::text part_descr + ,un.PART_FAMILY::text part_family + ,un.PART_GROUP::text part_group + ,un.BRANDING::text branding + ,un.SEGM::text segm + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text quota_rep + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text director + ,SUM(un.QTY)::numeric qty + ,SUM(un.SALES)::numeric sales + ,SUM(un.STDCOST)::numeric stdcost + ,SUM(un.QTY * COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur + ,SUM(un.POUNDS)::numeric pounds + ,(un.VERSION||'-'||un.SY)::text flag_s + ,(un.VERSION||'-'||un.OY)::text flag_o + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text status + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text "options" + ,'Grand Total'::text grandtotal + FROM + UN + LEFT OUTER JOIN REPC ON + REPC.RCODE = un.QUOTA_REP + LEFT OUTER JOIN SI ON + SI.BSMJCD = UN.MAJS + AND SI.BSMNCD = UN.MINS + LEFT OUTER JOIN SJ ON + SJ.BSMJCD = UN.MAJS + LEFT OUTER JOIN LGDAT.MAJG ON + BQGRP = un.MAJG + LEFT OUTER JOIN LGDAT.MMGP ON + BRMGRP = un.MING + AND BRGRP = un.MAJG + LEFT OUTER JOIN LGDAT.CUST BC ON + BC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.CUST SC ON + SC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.ICSTM cm ON + cm.cgpart = un.part + AND cm.cgplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTP cp ON + cp.chpart = un.part + AND cp.chplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTR cr ON + cr.y0part = un.part + AND cr.y0plnt = un.plnt + LEFT OUTER JOIN STD so ON + so.ssyr = un.oseas + LEFT OUTER JOIN STD ss ON + ss.ssyr = un.sseas + GROUP BY + un.VERSION::text + ,un.ITER::text + ,un.OSEAS::numeric + ,un.ODATE::date + ,un.SSEAS::numeric + ,un.SDATE::date + ,un.RSEAS::numeric + ,un.RDATE::date + ,un.OM::text + ,un.SM::text + ,un.RM::text + ,un.OY::text + --current year to date + ,(un.odate <@ _ytd)::boolean + --year to date recast for prior/forecast periods + ,(un.odate <@ so.ytd)::boolean + ,un.SY::text + ,(un.sdate <@ _ytd)::boolean + ,(un.sdate <@ ss.ytd)::boolean + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END + ,un.RY::text + ,un.PLNT::text + ,un.ACCOUNT::text + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text + ,bc.bvctry + ,bc.bvprcd + ,un.SHIPGRP::text + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text + ,sc.bvctry + ,sc.bvprcd + ,un.CHAN::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text + ,un.PROMO::text + ,un.MAJG||COALESCE(' - '||BQDES,'')::text + ,un.MING||COALESCE(' - '||BRDES,'')::text + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text + ,un.PART::text + ,un.PART_DESCR::text + ,un.PART_FAMILY::text + ,un.PART_GROUP::text + ,un.BRANDING::text + ,un.SEGM::text + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text + ,(un.VERSION||'-'||un.SY)::text + ,(un.VERSION||'-'||un.OY)::text + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text + ,'Grand Total'::text + ) + SELECT + a.version + ,a.iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,a.qty + ,a.sales + ,a.stdcost + ,a.stdcost_cur + ,a.pounds + ,a.flag_s + ,a.flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + agg a + UNION ALL + SELECT + 'Var to Fcst' as version + ,'Var to Fcst' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Fcst'||'-'||a.scytd flag_s + ,'Var to Fcst'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Forecast') + AND (a.ocytd OR a.scytd) + + UNION ALL + SELECT + 'Var to Bdgt' as version + ,'Var to Bdgt' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Bdgt'||'-'||a.scytd flag_s + ,'Var to Bdgt'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Budget') + AND (a.ocytd OR a.scytd) +;+
+
-
+ PL/pgSQL function rlarp.osm_ppfa_varto() line 69 at RETURN QUERYWITH + ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- + SEG AS ( + SELECT + x.GLEC + ,x.SEGM + FROM + ( + VALUES + ('1CU','Retail'), + ('1GR','Greenhouse'), + ('1NU','Nursery'), + ('1RE','Retail'), + ('2WI','Greenhouse'), + ('3BM','Other'), + ('3CO','Other'), + ('3PE','Other'), + ('3PP','Other'), + ('4CO','Other'), + ('4RA','Other'), + ('9MI','Other'), + ('9SA','Other'), + ('9TO','Other') + ) X(GLEC, SEGM) + ) + ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- + ,MG AS ( + SELECT + X.F1, X.MING, X.GRP + FROM + ( + VALUES + ('L','000','Branded'), + ('L','B10','Branded'), + ('L','B11','Branded'), + ('L','B52','Branded'), + ('L','C10','Branded'), + ('L','D12','Branded'), + ('L','M11','Branded'), + ('L','P12','Branded'), + ('L','P13','Branded'), + ('L','S10','Branded'), + ('L','Y10','Branded'), + ('L','Y11','Branded'), + ('L','Y12','Branded'), + ('P','B10','Branded'), + ('P','B11','Branded'), + ('P','B52','Branded') + ) AS X (F1, MING, GRP) + ) + ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- + ,REPC AS ( + SELECT + LTRIM(RTRIM(C.A9)) RCODE + ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP + ,COALESCE(Q.DIR,'Other') DIRECTOR + FROM + LGDAT.CODE C + LEFT OUTER JOIN RLARP.QRH Q ON + Q.QR = LTRIM(RTRIM(C.A9)) + WHERE + C.A2 = 'MM' + ) + --MOLD DESCRIPTIONS + ,MD AS ( + SELECT + U.MOLD + ,MAX(U.DESCR) DESCR + FROM + ( + SELECT + SUBSTR(M.AVPART,1,8) MOLD + ,MAX(M.AVDES1) DESCR + FROM + LGDAT.STKMM M + WHERE + LENGTH(M.AVPART) > 8 + AND SUBSTR(M.AVGLED,1,1) <= '2' + GROUP BY + SUBSTR(M.AVPART,1,8) + UNION ALL + SELECT + SUBSTR(P.AWPART,1,8) MOLD + ,MAX(P.AWDES1) DESCR + FROM + LGDAT.STKMP P + WHERE + LENGTH(P.AWPART) > 8 + AND SUBSTR(P.AWGLED,1,1) <= '2' + GROUP BY + SUBSTR(P.AWPART,1,8) + ) U + GROUP BY + U.MOLD + ) + ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- + ,SJ AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = '' + ) + ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- + ,SI AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> '' + ) + ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ + ,seas AS( + SELECT + ssyr + ,daterange(MIN(sdat),MAX(edat),'[]') dr + ,current_date <@ daterange(MIN(sdat),MAX(edat),'[]') cy + FROM + gld + GROUP BY + ssyr + ORDER BY + ssyr DESC + ) + ,intv AS ( + SELECT current_date - lower(dr) dy from seas where cy = true + ) + ,std AS ( + SELECT + s.ssyr + ,s.dr + ,s.cy + ,daterange(lower(dr),dy + LOWER(dr),'[]') ytd + FROM + seas s + CROSS JOIN intv + ) + ---------------------------------------union actual and forecast--------------------------------------------------------------------------------------------------------------------------------------- + ,UN AS ( + --plan + SELECT + 'Budget' AS VERSION + ,'Budget' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE as ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(m.avNWHT,p.awNWHT) * CASE COALESCE(m.avNWUN, p.awNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMP OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = 'b19' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --staged forecast + SELECT + 'Forecast' AS VERSION + ,'Forecast' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMF OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = '5p7' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --actual + SELECT + 'Actual' AS VERSION + ,'Actual' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSM OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + --AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.CALC_STATUS <> 'CANCELED' + AND + ( + OSM.FSPR >= '1606' + OR OSM.ADJ_ORDERDATE >= '2016-06-01' + ) + GROUP BY + --VERSION + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + ) + ---------------------------------------aggregate actual and forecast----------------------------------------------------------------------------------------------------------------------------------- + ,AGG AS ( + SELECT + un.VERSION::text "version" + ,un.ITER::text "iter" + ,un.OSEAS::numeric oseas + ,un.ODATE::date odate + ,un.SSEAS::numeric sseas + ,un.SDATE::date sdate + ,un.RSEAS::numeric rseas + ,un.RDATE::date rdate + ,un.OM::text om + ,un.SM::text sm + ,un.RM::text rm + ,un.OY::text oy + ,(un.odate <@ _ytd)::boolean ocytd --current year to date + ,(un.odate <@ so.ytd)::boolean oytd --year to date recast for prior/forecast periods + ,un.SY::text sy + ,(un.sdate <@ _ytd)::boolean scytd + ,(un.sdate <@ ss.ytd)::boolean sytd + --had this order been placed yet? (current day prior year is greater than the order date) + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END status_py + ,un.RY::text ry + ,un.PLNT::text plnt + ,un.ACCOUNT::text bill_group + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text bill_cust + ,bc.bvctry bill_ctry + ,bc.bvprcd bill_prov + ,un.SHIPGRP::text ship_group + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text ship_cust + ,sc.bvctry ship_ctry + ,sc.bvprcd ship_prov + ,un.CHAN::text chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text mod_chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text mod_chansub + ,un.PROMO::text promo + ,un.MAJG||COALESCE(' - '||BQDES,'')::text majg + ,un.MING||COALESCE(' - '||BRDES,'')::text ming + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text majs + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text mins + ,un.PART::text part + ,un.PART_DESCR::text part_descr + ,un.PART_FAMILY::text part_family + ,un.PART_GROUP::text part_group + ,un.BRANDING::text branding + ,un.SEGM::text segm + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text quota_rep + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text director + ,SUM(un.QTY)::numeric qty + ,SUM(un.SALES)::numeric sales + ,SUM(un.STDCOST)::numeric stdcost + ,SUM(un.QTY * COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur + ,SUM(un.POUNDS)::numeric pounds + ,(un.VERSION||'-'||un.SY)::text flag_s + ,(un.VERSION||'-'||un.OY)::text flag_o + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text status + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text "options" + ,'Grand Total'::text grandtotal + FROM + UN + LEFT OUTER JOIN REPC ON + REPC.RCODE = un.QUOTA_REP + LEFT OUTER JOIN SI ON + SI.BSMJCD = UN.MAJS + AND SI.BSMNCD = UN.MINS + LEFT OUTER JOIN SJ ON + SJ.BSMJCD = UN.MAJS + LEFT OUTER JOIN LGDAT.MAJG ON + BQGRP = un.MAJG + LEFT OUTER JOIN LGDAT.MMGP ON + BRMGRP = un.MING + AND BRGRP = un.MAJG + LEFT OUTER JOIN LGDAT.CUST BC ON + BC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.CUST SC ON + SC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.ICSTM cm ON + cm.cgpart = un.part + AND cm.cgplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTP cp ON + cp.chpart = un.part + AND cp.chplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTR cr ON + cr.y0part = un.part + AND cr.y0plnt = un.plnt + LEFT OUTER JOIN STD so ON + so.ssyr = un.oseas + LEFT OUTER JOIN STD ss ON + ss.ssyr = un.sseas + GROUP BY + un.VERSION::text + ,un.ITER::text + ,un.OSEAS::numeric + ,un.ODATE::date + ,un.SSEAS::numeric + ,un.SDATE::date + ,un.RSEAS::numeric + ,un.RDATE::date + ,un.OM::text + ,un.SM::text + ,un.RM::text + ,un.OY::text + --current year to date + ,(un.odate <@ _ytd)::boolean + --year to date recast for prior/forecast periods + ,(un.odate <@ so.ytd)::boolean + ,un.SY::text + ,(un.sdate <@ _ytd)::boolean + ,(un.sdate <@ ss.ytd)::boolean + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END + ,un.RY::text + ,un.PLNT::text + ,un.ACCOUNT::text + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text + ,bc.bvctry + ,bc.bvprcd + ,un.SHIPGRP::text + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text + ,sc.bvctry + ,sc.bvprcd + ,un.CHAN::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text + ,un.PROMO::text + ,un.MAJG||COALESCE(' - '||BQDES,'')::text + ,un.MING||COALESCE(' - '||BRDES,'')::text + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text + ,un.PART::text + ,un.PART_DESCR::text + ,un.PART_FAMILY::text + ,un.PART_GROUP::text + ,un.BRANDING::text + ,un.SEGM::text + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text + ,(un.VERSION||'-'||un.SY)::text + ,(un.VERSION||'-'||un.OY)::text + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text + ,'Grand Total'::text + ) + SELECT + a.version + ,a.iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,a.qty + ,a.sales + ,a.stdcost + ,a.stdcost_cur + ,a.pounds + ,a.flag_s + ,a.flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + agg a + UNION ALL + SELECT + 'Var to Fcst' as version + ,'Var to Fcst' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Fcst'||'-'||a.scytd flag_s + ,'Var to Fcst'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Forecast') + AND (a.ocytd OR a.scytd) + + UNION ALL + SELECT + 'Var to Bdgt' as version + ,'Var to Bdgt' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Bdgt'||'-'||a.scytd flag_s + ,'Var to Bdgt'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Budget') + AND (a.ocytd OR a.scytd) +;+
+
-
+ PL/pgSQL function rlarp.osm_ppfa_varto() line 69 at RETURN QUERYWITH + ---------------------------------------segments-------------------------------------------------------------------------------------------------------------------------------------------------------- + SEG AS ( + SELECT + x.GLEC + ,x.SEGM + FROM + ( + VALUES + ('1CU','Retail'), + ('1GR','Greenhouse'), + ('1NU','Nursery'), + ('1RE','Retail'), + ('2WI','Greenhouse'), + ('3BM','Other'), + ('3CO','Other'), + ('3PE','Other'), + ('3PP','Other'), + ('4CO','Other'), + ('4RA','Other'), + ('9MI','Other'), + ('9SA','Other'), + ('9TO','Other') + ) X(GLEC, SEGM) + ) + ---------------------------------------branding flag--------------------------------------------------------------------------------------------------------------------------------------------------- + ,MG AS ( + SELECT + X.F1, X.MING, X.GRP + FROM + ( + VALUES + ('L','000','Branded'), + ('L','B10','Branded'), + ('L','B11','Branded'), + ('L','B52','Branded'), + ('L','C10','Branded'), + ('L','D12','Branded'), + ('L','M11','Branded'), + ('L','P12','Branded'), + ('L','P13','Branded'), + ('L','S10','Branded'), + ('L','Y10','Branded'), + ('L','Y11','Branded'), + ('L','Y12','Branded'), + ('P','B10','Branded'), + ('P','B11','Branded'), + ('P','B52','Branded') + ) AS X (F1, MING, GRP) + ) + ---------------------------------------directors------------------------------------------------------------------------------------------------------------------------------------------------------- + ,REPC AS ( + SELECT + LTRIM(RTRIM(C.A9)) RCODE + ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP + ,COALESCE(Q.DIR,'Other') DIRECTOR + FROM + LGDAT.CODE C + LEFT OUTER JOIN RLARP.QRH Q ON + Q.QR = LTRIM(RTRIM(C.A9)) + WHERE + C.A2 = 'MM' + ) + --MOLD DESCRIPTIONS + ,MD AS ( + SELECT + U.MOLD + ,MAX(U.DESCR) DESCR + FROM + ( + SELECT + SUBSTR(M.AVPART,1,8) MOLD + ,MAX(M.AVDES1) DESCR + FROM + LGDAT.STKMM M + WHERE + LENGTH(M.AVPART) > 8 + AND SUBSTR(M.AVGLED,1,1) <= '2' + GROUP BY + SUBSTR(M.AVPART,1,8) + UNION ALL + SELECT + SUBSTR(P.AWPART,1,8) MOLD + ,MAX(P.AWDES1) DESCR + FROM + LGDAT.STKMP P + WHERE + LENGTH(P.AWPART) > 8 + AND SUBSTR(P.AWGLED,1,1) <= '2' + GROUP BY + SUBSTR(P.AWPART,1,8) + ) U + GROUP BY + U.MOLD + ) + ----------------------------------------------------sales major codes---------------------------------------------------------------------------------------------------------------------------------- + ,SJ AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') = '' + ) + ----------------------------------------------------sales minor codes---------------------------------------------------------------------------------------------------------------------------------- + ,SI AS ( + SELECT * FROM LGDAT.MMSL WHERE COALESCE(BSMNCD,'') <> '' + ) + ----------------------------------------------------date ranges per season------------------------------------------------------------------------------------------------------------------------------ + ,seas AS( + SELECT + ssyr + ,daterange(MIN(sdat),MAX(edat),'[]') dr + ,current_date <@ daterange(MIN(sdat),MAX(edat),'[]') cy + FROM + gld + GROUP BY + ssyr + ORDER BY + ssyr DESC + ) + ,intv AS ( + SELECT current_date - lower(dr) dy from seas where cy = true + ) + ,std AS ( + SELECT + s.ssyr + ,s.dr + ,s.cy + ,daterange(lower(dr),dy + LOWER(dr),'[]') ytd + FROM + seas s + CROSS JOIN intv + ) + ---------------------------------------union actual and forecast--------------------------------------------------------------------------------------------------------------------------------------- + ,UN AS ( + --plan + SELECT + 'Budget' AS VERSION + ,'Budget' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE as ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(m.avNWHT,p.awNWHT) * CASE COALESCE(m.avNWUN, p.awNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMP OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = 'b19' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(m.avDES1,p.awDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --staged forecast + SELECT + 'Forecast' AS VERSION + ,'Forecast' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSMF OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + AND OSM.CALC_STATUS <> 'CANCELED' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.VERSION = '5p7' + AND + ( + OSM.FSPR >= '1901' + OR OSM.ADJ_ORDERDATE >= '2018-06-01' + ) + GROUP BY + --VERSION + --ITER + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + UNION ALL + --actual + SELECT + 'Actual' AS VERSION + ,'Actual' ITER + ,OD.SSYR OSEAS + ,OSM.ADJ_ORDERDATE ODATE + ,SD.SSYR SSEAS + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) SDATE + ,RD.SSYR RSEAS + ,OSM.ADJ_REQUESTDATE RDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(RD.CM,'F') RM + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,COALESCE(RD.CY,'F') RY + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) PART_DESCR + ,F.F3||' - '||F.DESCR PART_FAMILY + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR PART_GROUP + ,COALESCE(MG.GRP,'Unbranded') BRANDING + ,COALESCE(SEG.SEGM,'Other') SEGM + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END calc_status + ,osm.c_rate + ,SUM( OSM.FB_QTY ) QTY + ,SUM( OSM.FB_VAL_LOC * OSM.R_RATE) SALES + ,SUM( OSM.FB_CST_LOC * OSM.C_RATE) STDCOST + ,SUM( OSM.FB_CST_LOC_CUR * OSM.C_RATE) STDCOST_CUR + ,SUM( OSM.FB_QTY * COALESCE(M.AVNWHT,P.AWNWHT) * CASE COALESCE(M.AVNWUN, P.AWNWUN) WHEN 'KG' THEN 2.2046 ELSE 1 END) POUNDS + FROM + RLARP.OSM OSM + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + LEFT OUTER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD RD ON + OSM.ADJ_REQUESTDATE BETWEEN RD.SDAT AND RD.EDAT + LEFT OUTER JOIN SEG ON + SEG.GLEC = OSM.GLEC + --AND SEG.SEGM <> 'Other' + LEFT OUTER JOIN MG ON + MG.F1 = SUBSTR(OSM.PART,16,1) + AND MG.MING = OSM.MING + LEFT OUTER JOIN RLARP.FAMILY F ON + F.F3 = SUBSTR(OSM.PART,1,3) + LEFT OUTER JOIN LGDAT.STKMM M ON + M.AVPART = OSM.PART + LEFT OUTER JOIN LGDAT.STKMP P ON + P.AWPART = OSM.PART + LEFT OUTER JOIN MD ON + MD.MOLD = SUBSTR(OSM.PART,1,8) + LEFT OUTER JOIN RLARP.FFCHNL L ON + L.BILL = OSM.BILL_CLASS + AND L.SHIP = OSM.SHIP_CLASS + WHERE + OSM.FS_LINE = '41010' + --AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND OSM.CALC_STATUS <> 'CANCELED' + AND + ( + OSM.FSPR >= '1606' + OR OSM.ADJ_ORDERDATE >= '2016-06-01' + ) + GROUP BY + --VERSION + OD.SSYR + ,OSM.ADJ_ORDERDATE + ,SD.SSYR + ,least(greatest(osm.adj_shipdate,SD.SDAT),SD.EDAT) + ,RD.SSYR + ,OSM.ADJ_REQUESTDATE + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(RD.CM,'F') + --if the order period is null, then there isn't one, just assign to invoice period + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ,COALESCE(RD.CY,'F') + ,OSM.PLNT + ,OSM.ACCOUNT + ,OSM.BILL_CUST + ,OSM.SHIPGRP + ,OSM.SHIP_CUST + ,OSM.CHAN + ,L.RETAIL + ,L.RETAILSUB + ,OSM.PROMO + ,OSM.MAJG + ,OSM.MING + ,OSM.MAJS + ,OSM.MINS + ,osm.PART + ,osm.PART || ' - ' || RTRIM(COALESCE(M.AVDES1,P.AWDES1)) + ,F.F3||' - '||F.DESCR + ,SUBSTR(osm.PART,1,8)||' - '||MD.DESCR + ,COALESCE(MG.GRP,'Unbranded') + ,COALESCE(SEG.SEGM,'Other') + ,OSM.QUOTA_REP + ,CASE osm.fspr WHEN '0000' THEN 'SHIP NOT BILLED' ELSE osm.CALC_STATUS END + ,osm.c_rate + ) + ---------------------------------------aggregate actual and forecast----------------------------------------------------------------------------------------------------------------------------------- + ,AGG AS ( + SELECT + un.VERSION::text "version" + ,un.ITER::text "iter" + ,un.OSEAS::numeric oseas + ,un.ODATE::date odate + ,un.SSEAS::numeric sseas + ,un.SDATE::date sdate + ,un.RSEAS::numeric rseas + ,un.RDATE::date rdate + ,un.OM::text om + ,un.SM::text sm + ,un.RM::text rm + ,un.OY::text oy + ,(un.odate <@ _ytd)::boolean ocytd --current year to date + ,(un.odate <@ so.ytd)::boolean oytd --year to date recast for prior/forecast periods + ,un.SY::text sy + ,(un.sdate <@ _ytd)::boolean scytd + ,(un.sdate <@ ss.ytd)::boolean sytd + --had this order been placed yet? (current day prior year is greater than the order date) + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END status_py + ,un.RY::text ry + ,un.PLNT::text plnt + ,un.ACCOUNT::text bill_group + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text bill_cust + ,bc.bvctry bill_ctry + ,bc.bvprcd bill_prov + ,un.SHIPGRP::text ship_group + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text ship_cust + ,sc.bvctry ship_ctry + ,sc.bvprcd ship_prov + ,un.CHAN::text chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text mod_chan + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text mod_chansub + ,un.PROMO::text promo + ,un.MAJG||COALESCE(' - '||BQDES,'')::text majg + ,un.MING||COALESCE(' - '||BRDES,'')::text ming + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text majs + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text mins + ,un.PART::text part + ,un.PART_DESCR::text part_descr + ,un.PART_FAMILY::text part_family + ,un.PART_GROUP::text part_group + ,un.BRANDING::text branding + ,un.SEGM::text segm + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text quota_rep + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text director + ,SUM(un.QTY)::numeric qty + ,SUM(un.SALES)::numeric sales + ,SUM(un.STDCOST)::numeric stdcost + ,SUM(un.QTY * COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) * un.c_rate)::numeric stdcost_cur + ,SUM(un.POUNDS)::numeric pounds + ,(un.VERSION||'-'||un.SY)::text flag_s + ,(un.VERSION||'-'||un.OY)::text flag_o + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text status + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text "options" + ,'Grand Total'::text grandtotal + FROM + UN + LEFT OUTER JOIN REPC ON + REPC.RCODE = un.QUOTA_REP + LEFT OUTER JOIN SI ON + SI.BSMJCD = UN.MAJS + AND SI.BSMNCD = UN.MINS + LEFT OUTER JOIN SJ ON + SJ.BSMJCD = UN.MAJS + LEFT OUTER JOIN LGDAT.MAJG ON + BQGRP = un.MAJG + LEFT OUTER JOIN LGDAT.MMGP ON + BRMGRP = un.MING + AND BRGRP = un.MAJG + LEFT OUTER JOIN LGDAT.CUST BC ON + BC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.CUST SC ON + SC.BVCUST = UN.BILL_CUST + LEFT OUTER JOIN LGDAT.ICSTM cm ON + cm.cgpart = un.part + AND cm.cgplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTP cp ON + cp.chpart = un.part + AND cp.chplnt = un.plnt + LEFT OUTER JOIN LGDAT.ICSTR cr ON + cr.y0part = un.part + AND cr.y0plnt = un.plnt + LEFT OUTER JOIN STD so ON + so.ssyr = un.oseas + LEFT OUTER JOIN STD ss ON + ss.ssyr = un.sseas + GROUP BY + un.VERSION::text + ,un.ITER::text + ,un.OSEAS::numeric + ,un.ODATE::date + ,un.SSEAS::numeric + ,un.SDATE::date + ,un.RSEAS::numeric + ,un.RDATE::date + ,un.OM::text + ,un.SM::text + ,un.RM::text + ,un.OY::text + --current year to date + ,(un.odate <@ _ytd)::boolean + --year to date recast for prior/forecast periods + ,(un.odate <@ so.ytd)::boolean + ,un.SY::text + ,(un.sdate <@ _ytd)::boolean + ,(un.sdate <@ ss.ytd)::boolean + ,CASE WHEN (upper(so.ytd) - interval '1 day') >= un.odate THEN + --was the order open at this time last year? (for orders that were placed by this time, was the ship date greater then the order date) + CASE WHEN ((un.sdate > (upper(so.ytd) - interval '1 day')) OR (un.SY = 'F')) + --for orders that were placed and open at this time last year, was the order considered past due? (current date prior year > request date) + THEN + CASE WHEN (upper(so.ytd) - interval '1 day') > un.rdate + THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE 'Shipped' + END + ELSE 'Not Yet Placed' + END + ,un.RY::text + ,un.PLNT::text + ,un.ACCOUNT::text + ,(un.BILL_CUST || ' - ' || RTRIM(BC.BVNAME))::text + ,bc.bvctry + ,bc.bvprcd + ,un.SHIPGRP::text + ,(un.SHIP_CUST || ' - ' || RTRIM(SC.BVNAME))::text + ,sc.bvctry + ,sc.bvprcd + ,un.CHAN::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAIL + ELSE un.CHAN + END::text + ,CASE un.SEGM + WHEN 'Retail' THEN un.RETAILSUB + ELSE '' + END::text + ,un.PROMO::text + ,un.MAJG||COALESCE(' - '||BQDES,'')::text + ,un.MING||COALESCE(' - '||BRDES,'')::text + ,un.MAJS||COALESCE(' - '||SJ.BSDES1,'')::text + ,un.MINS||COALESCE(' - '||SI.BSDES1,'')::text + ,un.PART::text + ,un.PART_DESCR::text + ,un.PART_FAMILY::text + ,un.PART_GROUP::text + ,un.BRANDING::text + ,un.SEGM::text + ,COALESCE(REPC.REPP,un.QUOTA_REP)::text + ,COALESCE(REPC.DIRECTOR,un.QUOTA_REP)::text + ,(un.VERSION||'-'||un.SY)::text + ,(un.VERSION||'-'||un.OY)::text + ,CASE + WHEN un.calc_status IN ('BACKORDER','OPEN') THEN + CASE + WHEN un.rdate < current_date THEN 'Open - Past Due' + ELSE 'Open - Current' + END + ELSE un.calc_status + END::text + ,(SUBSTR(UN.PART,9,3)||'-'||un.BRANDING)::text + ,'Grand Total'::text + ) + SELECT + a.version + ,a.iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,a.qty + ,a.sales + ,a.stdcost + ,a.stdcost_cur + ,a.pounds + ,a.flag_s + ,a.flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + agg a + UNION ALL + SELECT + 'Var to Fcst' as version + ,'Var to Fcst' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Fcst'||'-'||a.scytd flag_s + ,'Var to Fcst'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Forecast') + AND (a.ocytd OR a.scytd) + + UNION ALL + SELECT + 'Var to Bdgt' as version + ,'Var to Bdgt' as iter + ,a.oseas + ,a.odate + ,a.sseas + ,a.sdate + ,a.rseas + ,a.rdate + ,a.om + ,a.sm + ,a.rm + ,a.oy + ,a.ocytd + ,a.oytd + ,a.sy + ,a.scytd + ,a.sytd + ,a.status_py + ,a.ry + ,a.plnt + ,a.bill_group + ,a.bill_cust + ,a.bill_ctry + ,a.bill_prov + ,a.ship_group + ,a.ship_cust + ,a.ship_ctry + ,a.ship_prov + ,a.chan + ,a.mod_chan + ,a.mod_chansub + ,a.promo + ,a.majg + ,a.ming + ,a.majs + ,a.mins + ,a.part + ,a.part_descr + ,a.part_family + ,a.part_group + ,a.branding + ,a.segm + ,a.quota_rep + ,a.director + ,CASE a.VERSION WHEN 'Actual' THEN a.QTY ELSE -a.QTY END::numeric QTY + ,CASE a.VERSION WHEN 'Actual' THEN a.SALES ELSE -a.SALES END::numeric SALES + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST ELSE -a.STDCOST END::numeric STDCOST + ,CASE a.VERSION WHEN 'Actual' THEN a.STDCOST_CUR ELSE -a.STDCOST_CUR END::numeric STDCOST_CUR + ,CASE a.VERSION WHEN 'Actual' THEN a.POUNDS ELSE -a.POUNDS END::numeric POUNDS + ,'Var to Bdgt'||'-'||a.scytd flag_s + ,'Var to Bdgt'||'-'||a.ocytd flag_o + ,a.status + ,a.options + ,a.grandtotal + FROM + AGG a + WHERE + a.VERSION IN ('Actual','Budget') + AND (a.ocytd OR a.scytd) +;+
+
Date: 2019-03-15 00:52:54 +Duration: 3m19s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Append (cost=4510966117154.68..4644894879274.93 rows=1921380827591 width=1520) (actual time=182826.066..198343.560 rows=1377873 loops=1) + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=285245 written=302150 + I/O Timings: read=8179.425 + CTE seg + -> Values Scan on "*VALUES*" (cost=0.00..0.18 rows=14 width=64) (actual time=0.001..0.004 rows=14 loops=1) + CTE mg + -> Values Scan on "*VALUES*_1" (cost=0.00..0.20 rows=16 width=96) (actual time=0.002..0.006 rows=16 loops=1) + CTE repc + -> Hash Left Join (cost=11.47..123.28 rows=120 width=96) (actual time=2.591..12.439 rows=120 loops=1) + Hash Cond: (ltrim(rtrim(c.a9)) = q.qr) + Buffers: shared read=26 + I/O Timings: read=11.445 + -> Bitmap Heap Scan on code c (cost=9.21..118.86 rows=120 width=25) (actual time=2.207..11.727 rows=120 loops=1) + Recheck Cond: (a2 = 'MM'::text) + Heap Blocks: exact=21 + Buffers: shared read=25 + I/O Timings: read=11.107 + -> Bitmap Index Scan on pk_code (cost=0.00..9.18 rows=120 width=0) (actual time=1.684..1.684 rows=120 loops=1) + Index Cond: (a2 = 'MM'::text) + Buffers: shared read=4 + I/O Timings: read=1.575 + -> Hash (cost=1.56..1.56 rows=56 width=12) (actual time=0.368..0.368 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.337 + -> Seq Scan on qrh q (cost=0.00..1.56 rows=56 width=12) (actual time=0.349..0.355 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.337 + CTE md + -> HashAggregate (cost=11936.00..11938.00 rows=200 width=64) (actual time=95.558..96.083 rows=3368 loops=1) + Group Key: (substr(m.avpart, 1, 8)) + Buffers: shared hit=9056 + -> Append (cost=8137.31..11870.54 rows=13091 width=64) (actual time=83.235..94.596 rows=3375 loops=1) + Buffers: shared hit=9056 + -> HashAggregate (cost=8137.31..8249.94 rows=9010 width=64) (actual time=83.233..84.126 rows=3285 loops=1) + Group Key: substr(m.avpart, 1, 8) + Buffers: shared hit=6448 + -> Seq Scan on stkmm m (cost=0.00..8092.26 rows=9010 width=59) (actual time=0.012..41.548 rows=76269 loops=1) + Filter: ((length(avpart) > 8) AND (substr(avgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 4728 + Buffers: shared hit=6448 + -> HashAggregate (cost=3373.23..3424.24 rows=4081 width=64) (actual time=10.241..10.276 rows=90 loops=1) + Group Key: substr(p.awpart, 1, 8) + Buffers: shared hit=2608 + -> Seq Scan on stkmp p (cost=0.00..3352.82 rows=4081 width=52) (actual time=0.579..10.168 rows=142 loops=1) + Filter: ((length(awpart) > 8) AND (substr(awgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 36557 + Buffers: shared hit=2608 + CTE sj + -> Seq Scan on mmsl (cost=0.00..1.84 rows=1 width=22) (actual time=0.006..0.010 rows=11 loops=1) + Filter: (COALESCE(bsmncd, ''::text) = ''::text) + Rows Removed by Filter: 56 + Buffers: shared hit=1 + CTE si + -> Seq Scan on mmsl mmsl_1 (cost=0.00..1.84 rows=66 width=22) (actual time=0.342..0.348 rows=56 loops=1) + Filter: (COALESCE(bsmncd, ''::text) <> ''::text) + Rows Removed by Filter: 11 + Buffers: shared read=1 + I/O Timings: read=0.330 + CTE seas + -> GroupAggregate (cost=10.22..16.31 rows=174 width=41) (actual time=0.064..0.094 rows=15 loops=1) + Group Key: gld.ssyr + Buffers: local hit=2 + -> Sort (cost=10.22..10.65 rows=174 width=16) (actual time=0.052..0.059 rows=174 loops=1) + Sort Key: gld.ssyr DESC + Sort Method: quicksort Memory: 33kB + Buffers: local hit=2 + -> Seq Scan on gld (cost=0.00..3.74 rows=174 width=16) (actual time=0.010..0.029 rows=174 loops=1) + Buffers: local hit=2 + CTE intv + -> CTE Scan on seas (cost=0.00..4.13 rows=87 width=4) (actual time=0.077..0.078 rows=1 loops=1) + Filter: cy + Rows Removed by Filter: 14 + Buffers: local hit=2 + CTE std + -> Nested Loop (cost=0.00..457.62 rows=15138 width=73) (actual time=0.080..0.112 rows=15 loops=1) + Buffers: local hit=2 + -> CTE Scan on intv (cost=0.00..1.74 rows=87 width=4) (actual time=0.078..0.079 rows=1 loops=1) + Buffers: local hit=2 + -> CTE Scan on seas s (cost=0.00..3.48 rows=174 width=41) (actual time=0.000..0.026 rows=15 loops=1) + CTE un + -> Append (cost=50003223.80..255856479.46 rows=330423099 width=697) (actual time=34264.289..81644.471 rows=812229 loops=1) + Buffers: shared hit=98372 read=72635, local hit=5658753 read=1 + I/O Timings: read=7746.456 + -> GroupAggregate (cost=50003223.80..63823292.65 rows=83757993 width=701) (actual time=34264.288..36465.643 rows=212793 loops=1) + Group Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Buffers: shared hit=45043 read=23493, local hit=2563791 read=1 + I/O Timings: read=3613.602 + -> Sort (cost=50003223.80..50212618.79 rows=83757993 width=594) (actual time=34264.218..34431.899 rows=641010 loops=1) + Sort Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Sort Method: quicksort Memory: 352782kB + Buffers: shared hit=45043 read=23493, local hit=2563791 read=1 + I/O Timings: read=3613.602 + -> Hash Left Join (cost=11749.79..16650773.71 rows=83757993 width=594) (actual time=523.585..12806.506 rows=641010 loops=1) + Hash Cond: ((osm.bill_class = l.bill) AND (osm.ship_class = l.ship)) + Buffers: shared hit=45040 read=23493, local hit=2563791 read=1 + I/O Timings: read=3613.602 + -> Hash Left Join (cost=11744.32..10583311.94 rows=83757993 width=583) (actual time=522.937..12019.634 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 8) = md.mold) + Buffers: shared hit=45040 read=23491, local hit=2563791 read=1 + I/O Timings: read=3613.055 + -> Hash Left Join (cost=11737.82..5348430.88 rows=83757993 width=551) (actual time=425.063..11458.763 rows=641010 loops=1) + Hash Cond: (osm.part = p_1.awpart) + Buffers: shared hit=35984 read=23491, local hit=2563791 read=1 + I/O Timings: read=3613.055 + -> Nested Loop Left Join (cost=8303.37..5125106.33 rows=83757993 width=527) (actual time=313.496..11101.481 rows=641010 loops=1) + Buffers: shared hit=35982 read=20885, local hit=2563791 read=1 + I/O Timings: read=3534.677 + -> Nested Loop Left Join (cost=8303.23..337594.45 rows=4332310 width=455) (actual time=313.488..8642.098 rows=641010 loops=1) + Buffers: shared hit=35982 read=20885, local hit=1281897 read=1 + I/O Timings: read=3534.677 + -> Hash Left Join (cost=8303.08..89964.52 rows=224085 width=383) (actual time=313.453..5992.381 rows=641010 loops=1) + Hash Cond: (osm.part = m_1.avpart) + Buffers: shared hit=35982 read=20885, local hit=2 + I/O Timings: read=3534.662 + -> Hash Left Join (cost=30.62..81103.81 rows=224085 width=348) (actual time=12.984..5414.171 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 3) = f.f3) + Buffers: shared hit=35980 read=14439, local hit=2 + I/O Timings: read=3281.743 + -> Hash Left Join (cost=6.93..77718.84 rows=224085 width=324) (actual time=0.106..4996.296 rows=641010 loops=1) + Hash Cond: ((substr(osm.part, 16, 1) = mg.f1) AND (osm.ming = mg.ming)) + Buffers: shared hit=35980 read=14430, local hit=2 + I/O Timings: read=3269.024 + -> Hash Left Join (cost=6.37..75750.09 rows=224085 width=292) (actual time=0.084..4563.487 rows=641010 loops=1) + Hash Cond: (osm.glec = seg.glec) + Buffers: shared hit=35980 read=14430, local hit=2 + I/O Timings: read=3269.024 + -> Hash Left Join (cost=5.92..72674.81 rows=224085 width=264) (actual time=0.070..4318.873 rows=641010 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=35980 read=14430, local hit=2 + I/O Timings: read=3269.024 + -> Seq Scan on osmp osm (cost=0.00..69587.73 rows=224085 width=184) (actual time=0.017..4055.770 rows=641010 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = 'b19'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 57051 + Buffers: shared hit=35980 read=14430 + I/O Timings: read=3269.024 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.048..0.048 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=112) (actual time=0.003..0.024 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.011..0.011 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.008 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.015..0.015 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.012 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=12.868..12.868 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared read=9 + I/O Timings: read=12.719 + -> Seq Scan on family f (cost=0.00..15.53 rows=653 width=24) (actual time=12.733..12.786 rows=653 loops=1) + Buffers: shared read=9 + I/O Timings: read=12.719 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=300.407..300.407 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=2 read=6446 + I/O Timings: read=252.919 + -> Seq Scan on stkmm m_1 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.600..277.166 rows=80997 loops=1) + Buffers: shared hit=2 read=6446 + I/O Timings: read=252.919 + -> Index Scan using se_dat on gld od (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1281895 read=1 + I/O Timings: read=0.015 + -> Index Scan using se_dat on gld rd (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_requestdate >= sdat) AND (osm.adj_requestdate <= edat)) + Buffers: local hit=1281894 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=108.057..108.057 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2 read=2606 + I/O Timings: read=78.378 + -> Seq Scan on stkmp p_1 (cost=0.00..2975.31 rows=36731 width=33) (actual time=1.096..89.328 rows=36699 loops=1) + Buffers: shared hit=2 read=2606 + I/O Timings: read=78.378 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=97.843..97.843 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + Buffers: shared hit=9056 + -> CTE Scan on md (cost=0.00..4.00 rows=200 width=64) (actual time=95.561..97.114 rows=3368 loops=1) + Buffers: shared hit=9056 + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.629..0.629 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=2 + I/O Timings: read=0.546 + -> Seq Scan on ffchnl l (cost=0.00..3.39 rows=139 width=25) (actual time=0.574..0.596 rows=139 loops=1) + Buffers: shared read=2 + I/O Timings: read=0.546 + -> GroupAggregate (cost=33445583.00..42801951.72 rows=56705265 width=699) (actual time=21899.780..27106.566 rows=250477 loops=1) + Group Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Buffers: shared hit=35412, local hit=1627258 + -> Sort (cost=33445583.00..33587346.16 rows=56705265 width=595) (actual time=21899.740..22369.501 rows=406814 loops=1) + Sort Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Sort Method: quicksort Memory: 222052kB + Buffers: shared hit=35412, local hit=1627258 + -> Hash Left Join (cost=11749.79..11025086.80 rows=56705265 width=595) (actual time=82.385..8358.833 rows=406814 loops=1) + Hash Cond: ((osm_1.bill_class = l_1.bill) AND (osm_1.ship_class = l_1.ship)) + Buffers: shared hit=35412, local hit=1627258 + -> Hash Left Join (cost=11744.32..6967724.27 rows=55168846 width=584) (actual time=82.294..7619.217 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 8) = md_1.mold) + Buffers: shared hit=35410, local hit=1627258 + -> Hash Left Join (cost=11737.82..3519664.90 rows=55168846 width=552) (actual time=81.174..7139.198 rows=406814 loops=1) + Hash Cond: (osm_1.part = p_2.awpart) + Buffers: shared hit=35410, local hit=1627258 + -> Nested Loop Left Join (cost=8303.37..3371395.52 rows=55168846 width=528) (actual time=50.759..6837.840 rows=406814 loops=1) + Buffers: shared hit=32802, local hit=1627258 + -> Nested Loop Left Join (cost=8303.23..217901.28 rows=2853561 width=456) (actual time=50.749..4566.299 rows=406814 loops=1) + Buffers: shared hit=32802, local hit=813630 + -> Hash Left Join (cost=8303.08..54789.49 rows=147598 width=384) (actual time=50.729..2196.620 rows=406814 loops=1) + Hash Cond: (osm_1.part = m_2.avpart) + Buffers: shared hit=32802, local hit=2 + -> Hash Left Join (cost=30.62..46129.57 rows=147598 width=349) (actual time=0.257..1813.794 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 3) = f_1.f3) + Buffers: shared hit=26354, local hit=2 + -> Hash Left Join (cost=6.93..43891.91 rows=147598 width=325) (actual time=0.121..1436.906 rows=406814 loops=1) + Hash Cond: ((substr(osm_1.part, 16, 1) = mg_1.f1) AND (osm_1.ming = mg_1.ming)) + Buffers: shared hit=26345, local hit=2 + -> Hash Left Join (cost=6.37..42594.49 rows=147598 width=293) (actual time=0.110..1056.449 rows=406814 loops=1) + Hash Cond: (osm_1.glec = seg_1.glec) + Buffers: shared hit=26345, local hit=2 + -> Hash Left Join (cost=5.92..40564.57 rows=147598 width=265) (actual time=0.098..857.465 rows=406814 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=26345, local hit=2 + -> Seq Scan on osmf osm_1 (cost=0.00..38529.18 rows=147598 width=185) (actual time=0.026..619.289 rows=406814 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = '5p7'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 358 + Buffers: shared hit=26345 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.065..0.065 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=112) (actual time=0.008..0.035 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.007..0.007 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_1 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.004 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.007..0.007 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_1 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.003 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.131..0.131 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_1 (cost=0.00..15.53 rows=653 width=24) (actual time=0.010..0.054 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=50.417..50.417 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_2 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.005..27.523 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=406814) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=813628 + -> Index Scan using se_dat on gld rd_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.005 rows=1 loops=406814) + Index Cond: ((osm_1.adj_requestdate >= sdat) AND (osm_1.adj_requestdate <= edat)) + Buffers: local hit=813628 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=30.201..30.201 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_2 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.009..17.401 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=1.104..1.104 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_1 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.386 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.063..0.063 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_1 (cost=0.00..3.39 rows=139 width=25) (actual time=0.011..0.032 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=112931514.84..144274888.60 rows=189959841 width=695) (actual time=16710.998..17936.290 rows=348959 loops=1) + Group Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Buffers: shared hit=17917 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Sort (cost=112931514.84..113406414.44 rows=189959841 width=584) (actual time=16710.946..16814.969 rows=367211 loops=1) + Sort Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Sort Method: quicksort Memory: 201623kB + Buffers: shared hit=17917 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=11749.79..37465936.67 rows=189959841 width=584) (actual time=154.009..11372.141 rows=367211 loops=1) + Hash Cond: ((osm_2.bill_class = l_2.bill) AND (osm_2.ship_class = l_2.ship)) + Buffers: shared hit=17917 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=11744.32..23902628.82 rows=189959841 width=574) (actual time=153.913..10698.691 rows=367211 loops=1) + Hash Cond: (substr(osm_2.part, 1, 8) = md_2.mold) + Buffers: shared hit=17915 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=11737.82..12030132.26 rows=189959841 width=542) (actual time=148.767..10299.042 rows=367211 loops=1) + Hash Cond: (osm_2.part = p_3.awpart) + Buffers: shared hit=17915 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Nested Loop Left Join (cost=8303.37..11527995.69 rows=189959841 width=518) (actual time=102.067..10041.030 rows=367211 loops=1) + Buffers: shared hit=15307 read=49142, local hit=1467704 + I/O Timings: read=4132.855 + -> Nested Loop Left Join (cost=8303.23..670498.91 rows=9825509 width=446) (actual time=102.059..8236.690 rows=367211 loops=1) + Buffers: shared hit=15307 read=49142, local hit=733854 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=8303.08..108904.23 rows=508216 width=374) (actual time=102.031..6271.278 rows=367211 loops=1) + Hash Cond: (osm_2.part = m_3.avpart) + Buffers: shared hit=15307 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=30.62..99297.64 rows=508216 width=339) (actual time=6.361..5913.268 rows=367211 loops=1) + Hash Cond: (substr(osm_2.part, 1, 3) = f_2.f3) + Buffers: shared hit=8859 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=6.93..91650.71 rows=508216 width=315) (actual time=6.219..5568.521 rows=367211 loops=1) + Hash Cond: ((substr(osm_2.part, 16, 1) = mg_2.f1) AND (osm_2.ming = mg_2.ming)) + Buffers: shared hit=8850 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=6.37..87189.88 rows=508216 width=283) (actual time=6.207..5231.289 rows=367211 loops=1) + Hash Cond: (osm_2.glec = seg_2.glec) + Buffers: shared hit=8850 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Hash Left Join (cost=5.92..80265.15 rows=508216 width=255) (actual time=6.193..5042.515 rows=367211 loops=1) + Hash Cond: (osm_2.fspr = sd_2.fspr) + Buffers: shared hit=8850 read=49142, local hit=2 + I/O Timings: read=4132.855 + -> Seq Scan on osm osm_2 (cost=0.00..73663.10 rows=508216 width=175) (actual time=6.115..4852.376 rows=367211 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND ((fspr >= '1606'::text) OR (adj_orderdate >= '2016-06-01'::date))) + Rows Removed by Filter: 417318 + Buffers: shared hit=8850 read=49142 + I/O Timings: read=4132.855 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.064..0.064 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_2 (cost=0.00..3.74 rows=174 width=112) (actual time=0.009..0.036 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_2 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.003 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.006..0.006 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_2 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.131..0.131 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_2 (cost=0.00..15.53 rows=653 width=24) (actual time=0.010..0.051 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=95.611..95.611 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_3 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.005..42.484 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=367211) + Index Cond: ((osm_2.adj_orderdate >= sdat) AND (osm_2.adj_orderdate <= edat)) + Buffers: local hit=733852 + -> Index Scan using se_dat on gld rd_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=367211) + Index Cond: ((osm_2.adj_requestdate >= sdat) AND (osm_2.adj_requestdate <= edat)) + Buffers: local hit=733850 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=46.657..46.657 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_3 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.010..23.613 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=5.110..5.110 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_2 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.405 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.068..0.068 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_2 (cost=0.00..3.39 rows=139 width=25) (actual time=0.021..0.039 rows=139 loops=1) + Buffers: shared hit=2 + CTE agg + -> GroupAggregate (cost=3990139087947.22..4510710248131.84 rows=1892986037035 width=1404) (actual time=182825.587..189012.716 rows=809487 loops=1) + Group Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)), 'Grand Total'::text + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=169551 written=244303 + I/O Timings: read=8179.425 + -> Sort (cost=3990139087947.22..3994871553039.80 rows=1892986037035 width=1346) (actual time=182817.706..183828.314 rows=812229 loops=1) + Sort Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)) + Sort Method: external merge Disk: 475848kB + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=169551 written=244303 + I/O Timings: read=8179.425 + -> Merge Right Join (cost=33563712447.31..265517026370.70 rows=1892986037035 width=1346) (actual time=117209.936..123600.017 rows=812229 loops=1) + Merge Cond: (ss.ssyr = un.sseas) + Buffers: shared hit=101597 read=90963, local hit=5658755 read=1, temp read=110070 written=184821 + I/O Timings: read=8179.425 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.122..0.740 rows=15 loops=1) + Sort Key: ss.ssyr + Sort Method: quicksort Memory: 26kB + Buffers: local hit=2 + -> CTE Scan on std ss (cost=0.00..302.76 rows=15138 width=40) (actual time=0.081..0.117 rows=15 loops=1) + Buffers: local hit=2 + -> Materialize (cost=33563711093.53..33688759715.34 rows=25009724363 width=1300) (actual time=117198.447..119674.219 rows=812229 loops=1) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=110070 written=184821 + I/O Timings: read=8179.425 + -> Sort (cost=33563711093.53..33626235404.44 rows=25009724363 width=1300) (actual time=117198.083..117976.508 rows=812229 loops=1) + Sort Key: un.sseas + Sort Method: external merge Disk: 445840kB + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=110070 written=146582 + I/O Timings: read=8179.425 + -> Merge Right Join (cost=488162845.81..864134844.69 rows=25009724363 width=1300) (actual time=105501.163..109753.807 rows=812229 loops=1) + Merge Cond: (so.ssyr = un.oseas) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=54340 written=90851 + I/O Timings: read=8179.425 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.005..0.009 rows=13 loops=1) + Sort Key: so.ssyr + Sort Method: quicksort Memory: 26kB + -> CTE Scan on std so (cost=0.00..302.76 rows=15138 width=40) (actual time=0.000..0.002 rows=15 loops=1) + -> Materialize (cost=488161492.03..489813607.52 rows=330423099 width=1268) (actual time=105468.884..108956.573 rows=812229 loops=1) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=54340 written=90851 + I/O Timings: read=8179.425 + -> Sort (cost=488161492.03..488987549.77 rows=330423099 width=1268) (actual time=105419.215..105977.954 rows=812229 loops=1) + Sort Key: un.oseas + Sort Method: external merge Disk: 434720kB + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1, temp read=54340 written=54341 + I/O Timings: read=8179.425 + -> Hash Left Join (cost=30326.40..75489285.22 rows=330423099 width=1268) (actual time=34892.831..94537.687 rows=812229 loops=1) + Hash Cond: ((un.part = cr.y0part) AND (un.plnt = cr.y0plnt)) + Buffers: shared hit=101597 read=90963, local hit=5658753 read=1 + I/O Timings: read=8179.425 + -> Hash Left Join (cost=22414.65..56426266.97 rows=330423099 width=1262) (actual time=34668.780..93298.840 rows=812229 loops=1) + Hash Cond: ((un.part = cp.chpart) AND (un.plnt = cp.chplnt)) + Buffers: shared hit=101597 read=85711, local hit=5658753 read=1 + I/O Timings: read=8003.465 + -> Hash Left Join (cost=14299.03..36533966.06 rows=330423099 width=1256) (actual time=34522.917..92143.759 rows=812229 loops=1) + Hash Cond: ((un.part = cm.cgpart) AND (un.plnt = cm.cgplnt)) + Buffers: shared hit=101597 read=80395, local hit=5658753 read=1 + I/O Timings: read=7920.833 + -> Hash Left Join (cost=7433.88..34026391.85 rows=330423099 width=1250) (actual time=34383.160..90732.988 rows=812229 loops=1) + Hash Cond: (un.bill_cust = sc.bvcust) + Buffers: shared hit=101597 read=75888, local hit=5658753 read=1 + I/O Timings: read=7833.063 + -> Hash Left Join (cost=3723.16..29479363.52 rows=330423099 width=1223) (actual time=34366.365..89923.315 rows=812229 loops=1) + Hash Cond: (un.bill_cust = bc.bvcust) + Buffers: shared hit=98373 read=75888, local hit=5658753 read=1 + I/O Timings: read=7833.063 + -> Hash Left Join (cost=12.44..24932335.18 rows=330423099 width=1196) (actual time=34277.988..88987.624 rows=812229 loops=1) + Hash Cond: ((un.ming = mmgp.brmgrp) AND (un.majg = mmgp.brgrp)) + Buffers: shared hit=98373 read=72664, local hit=5658753 read=1 + I/O Timings: read=7758.824 + -> Hash Left Join (cost=7.51..15006668.18 rows=330423099 width=1186) (actual time=34277.622..88269.216 rows=812229 loops=1) + Hash Cond: (un.majg = majg.bqgrp) + Buffers: shared hit=98373 read=72663, local hit=5658753 read=1 + I/O Timings: read=7758.524 + -> Hash Left Join (cost=6.24..13569326.43 rows=330423099 width=1176) (actual time=34277.304..87627.015 rows=812229 loops=1) + Hash Cond: (un.majs = sj.bsmjcd) + Buffers: shared hit=98373 read=72662, local hit=5658753 read=1 + I/O Timings: read=7758.231 + -> Hash Left Join (cost=6.21..12313718.62 rows=330423099 width=1144) (actual time=34277.281..87019.163 rows=812229 loops=1) + Hash Cond: ((un.majs = si.bsmjcd) AND (un.mins = si.bsmncd)) + Buffers: shared hit=98372 read=72662, local hit=5658753 read=1 + I/O Timings: read=7758.231 + -> Hash Left Join (cost=3.90..9830091.09 rows=330423099 width=1112) (actual time=34276.887..86204.919 rows=812229 loops=1) + Hash Cond: (un.quota_rep = repc.rcode) + Buffers: shared hit=98372 read=72661, local hit=5658753 read=1 + I/O Timings: read=7757.901 + -> CTE Scan on un (cost=0.00..6608461.98 rows=330423099 width=1048) (actual time=34264.293..85100.705 rows=812229 loops=1) + Buffers: shared hit=98372 read=72635, local hit=5658753 read=1 + I/O Timings: read=7746.456 + -> Hash (cost=2.40..2.40 rows=120 width=96) (actual time=12.582..12.582 rows=120 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 17kB + Buffers: shared read=26 + I/O Timings: read=11.445 + -> CTE Scan on repc (cost=0.00..2.40 rows=120 width=96) (actual time=2.594..12.537 rows=120 loops=1) + Buffers: shared read=26 + I/O Timings: read=11.445 + -> Hash (cost=1.32..1.32 rows=66 width=96) (actual time=0.382..0.382 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.330 + -> CTE Scan on si (cost=0.00..1.32 rows=66 width=96) (actual time=0.344..0.363 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.330 + -> Hash (cost=0.02..0.02 rows=1 width=64) (actual time=0.016..0.016 rows=11 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=1 + -> CTE Scan on sj (cost=0.00..0.02 rows=1 width=64) (actual time=0.007..0.013 rows=11 loops=1) + Buffers: shared hit=1 + -> Hash (cost=1.12..1.12 rows=12 width=14) (actual time=0.312..0.312 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared read=1 + I/O Timings: read=0.293 + -> Seq Scan on majg (cost=0.00..1.12 rows=12 width=14) (actual time=0.301..0.303 rows=12 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.293 + -> Hash (cost=2.57..2.57 rows=157 width=18) (actual time=0.359..0.359 rows=157 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=1 + I/O Timings: read=0.300 + -> Seq Scan on mmgp (cost=0.00..2.57 rows=157 width=18) (actual time=0.309..0.326 rows=157 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.300 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=88.356..88.356 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared read=3224 + I/O Timings: read=74.239 + -> Seq Scan on cust bc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.900..82.368 rows=21632 loops=1) + Buffers: shared read=3224 + I/O Timings: read=74.239 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=16.771..16.771 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared hit=3224 + -> Seq Scan on cust sc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.007..10.557 rows=21632 loops=1) + Buffers: shared hit=3224 + -> Hash (cost=5450.26..5450.26 rows=94326 width=29) (actual time=139.654..139.654 rows=94326 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6699kB + Buffers: shared read=4507 + I/O Timings: read=87.770 + -> Seq Scan on icstm cm (cost=0.00..5450.26 rows=94326 width=29) (actual time=1.271..114.520 rows=94326 loops=1) + Buffers: shared read=4507 + I/O Timings: read=87.770 + -> Hash (cost=6435.85..6435.85 rows=111985 width=20) (actual time=145.806..145.806 rows=111985 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6768kB + Buffers: shared read=5316 + I/O Timings: read=82.632 + -> Seq Scan on icstp cp (cost=0.00..6435.85 rows=111985 width=20) (actual time=3.411..114.774 rows=111985 loops=1) + Buffers: shared read=5316 + I/O Timings: read=82.632 + -> Hash (cost=6315.90..6315.90 rows=106390 width=27) (actual time=223.650..223.650 rows=106390 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7334kB + Buffers: shared read=5252 + I/O Timings: read=175.960 + -> Seq Scan on icstr cr (cost=0.00..6315.90 rows=106390 width=27) (actual time=1.134..193.496 rows=106390 loops=1) + Buffers: shared read=5252 + I/O Timings: read=175.960 + -> CTE Scan on agg a (cost=0.00..37859720740.70 rows=1892986037035 width=1520) (actual time=182825.842..192275.884 rows=809487 loops=1) + Buffers: shared hit=101605 read=90963, local hit=5658755 read=1, temp read=169551 written=302149 + I/O Timings: read=8179.425 + -> CTE Scan on agg a_1 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=336.760..2113.121 rows=298364 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Forecast}'::text[]))) + Rows Removed by Filter: 511123 + Buffers: temp read=57847 written=1 + -> CTE Scan on agg a_2 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=218.764..3615.793 rows=270022 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Budget}'::text[]))) + Rows Removed by Filter: 539465 + Buffers: temp read=57847 + +
+Date: 2019-03-15 16:48:07 +Duration: 2m28s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Append (cost=4309162605406.33..4437117814888.42 rows=1835682510591 width=1520) (actual time=130217.190..147603.781 rows=1378962 loops=1) + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=285365 written=302292 + I/O Timings: read=5796.575 + CTE seg + -> Values Scan on "*VALUES*" (cost=0.00..0.18 rows=14 width=64) (actual time=0.003..0.006 rows=14 loops=1) + CTE mg + -> Values Scan on "*VALUES*_1" (cost=0.00..0.20 rows=16 width=96) (actual time=0.003..0.011 rows=16 loops=1) + CTE repc + -> Hash Left Join (cost=11.47..123.28 rows=120 width=96) (actual time=7.419..15.669 rows=120 loops=1) + Hash Cond: (ltrim(rtrim(c.a9)) = q.qr) + Buffers: shared hit=1 read=25 + I/O Timings: read=14.644 + -> Bitmap Heap Scan on code c (cost=9.21..118.86 rows=120 width=25) (actual time=7.351..15.256 rows=120 loops=1) + Recheck Cond: (a2 = 'MM'::text) + Heap Blocks: exact=21 + Buffers: shared read=25 + I/O Timings: read=14.644 + -> Bitmap Index Scan on pk_code (cost=0.00..9.18 rows=120 width=0) (actual time=6.872..6.872 rows=120 loops=1) + Index Cond: (a2 = 'MM'::text) + Buffers: shared read=4 + I/O Timings: read=6.737 + -> Hash (cost=1.56..1.56 rows=56 width=12) (actual time=0.044..0.044 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared hit=1 + -> Seq Scan on qrh q (cost=0.00..1.56 rows=56 width=12) (actual time=0.016..0.024 rows=56 loops=1) + Buffers: shared hit=1 + CTE md + -> HashAggregate (cost=11936.00..11938.00 rows=200 width=64) (actual time=109.370..109.781 rows=3368 loops=1) + Group Key: (substr(m.avpart, 1, 8)) + Buffers: shared hit=9056 + -> Append (cost=8137.31..11870.54 rows=13091 width=64) (actual time=98.760..108.518 rows=3375 loops=1) + Buffers: shared hit=9056 + -> HashAggregate (cost=8137.31..8249.94 rows=9010 width=64) (actual time=98.758..99.319 rows=3285 loops=1) + Group Key: substr(m.avpart, 1, 8) + Buffers: shared hit=6448 + -> Seq Scan on stkmm m (cost=0.00..8092.26 rows=9010 width=59) (actual time=0.016..53.186 rows=76269 loops=1) + Filter: ((length(avpart) > 8) AND (substr(avgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 4728 + Buffers: shared hit=6448 + -> HashAggregate (cost=3373.23..3424.24 rows=4081 width=64) (actual time=8.960..8.993 rows=90 loops=1) + Group Key: substr(p.awpart, 1, 8) + Buffers: shared hit=2608 + -> Seq Scan on stkmp p (cost=0.00..3352.82 rows=4081 width=52) (actual time=0.460..8.898 rows=142 loops=1) + Filter: ((length(awpart) > 8) AND (substr(awgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 36557 + Buffers: shared hit=2608 + CTE sj + -> Seq Scan on mmsl (cost=0.00..1.84 rows=1 width=22) (actual time=0.005..0.011 rows=11 loops=1) + Filter: (COALESCE(bsmncd, ''::text) = ''::text) + Rows Removed by Filter: 56 + Buffers: shared hit=1 + CTE si + -> Seq Scan on mmsl mmsl_1 (cost=0.00..1.84 rows=66 width=22) (actual time=1.513..1.521 rows=56 loops=1) + Filter: (COALESCE(bsmncd, ''::text) <> ''::text) + Rows Removed by Filter: 11 + Buffers: shared read=1 + I/O Timings: read=1.503 + CTE seas + -> GroupAggregate (cost=10.22..16.31 rows=174 width=41) (actual time=0.067..0.097 rows=15 loops=1) + Group Key: gld.ssyr + Buffers: local hit=2 + -> Sort (cost=10.22..10.65 rows=174 width=16) (actual time=0.052..0.059 rows=174 loops=1) + Sort Key: gld.ssyr DESC + Sort Method: quicksort Memory: 33kB + Buffers: local hit=2 + -> Seq Scan on gld (cost=0.00..3.74 rows=174 width=16) (actual time=0.010..0.030 rows=174 loops=1) + Buffers: local hit=2 + CTE intv + -> CTE Scan on seas (cost=0.00..4.13 rows=87 width=4) (actual time=0.078..0.079 rows=1 loops=1) + Filter: cy + Rows Removed by Filter: 14 + Buffers: local hit=2 + CTE std + -> Nested Loop (cost=0.00..457.62 rows=15138 width=73) (actual time=0.081..0.114 rows=15 loops=1) + Buffers: local hit=2 + -> CTE Scan on intv (cost=0.00..1.74 rows=87 width=4) (actual time=0.078..0.079 rows=1 loops=1) + Buffers: local hit=2 + -> CTE Scan on seas s (cost=0.00..3.48 rows=174 width=41) (actual time=0.000..0.027 rows=15 loops=1) + CTE un + -> Append (cost=50003223.80..244355794.95 rows=315685415 width=697) (actual time=24427.622..55248.745 rows=812592 loops=1) + Buffers: shared hit=33769 read=137238 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5418.990 + -> GroupAggregate (cost=50003223.80..63823292.65 rows=83757993 width=701) (actual time=24427.621..26180.035 rows=212793 loops=1) + Group Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Buffers: shared hit=9106 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Sort (cost=50003223.80..50212618.79 rows=83757993 width=594) (actual time=24427.582..24584.713 rows=641010 loops=1) + Sort Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Sort Method: quicksort Memory: 352782kB + Buffers: shared hit=9106 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Hash Left Join (cost=11749.79..16650773.71 rows=83757993 width=594) (actual time=594.631..11450.131 rows=641010 loops=1) + Hash Cond: ((osm.bill_class = l.bill) AND (osm.ship_class = l.ship)) + Buffers: shared hit=9103 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Hash Left Join (cost=11744.32..10583311.94 rows=83757993 width=583) (actual time=594.565..10651.699 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 8) = md.mold) + Buffers: shared hit=9101 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Hash Left Join (cost=11737.82..5348430.88 rows=83757993 width=551) (actual time=483.328..10064.882 rows=641010 loops=1) + Hash Cond: (osm.part = p_1.awpart) + Buffers: shared hit=45 read=59430, local hit=2563791 read=1 + I/O Timings: read=2239.382 + -> Nested Loop Left Join (cost=8303.37..5125106.33 rows=83757993 width=527) (actual time=372.833..9705.810 rows=641010 loops=1) + Buffers: shared hit=43 read=56824, local hit=2563791 read=1 + I/O Timings: read=2158.329 + -> Nested Loop Left Join (cost=8303.23..337594.45 rows=4332310 width=455) (actual time=372.826..7154.118 rows=641010 loops=1) + Buffers: shared hit=43 read=56824, local hit=1281897 read=1 + I/O Timings: read=2158.329 + -> Hash Left Join (cost=8303.08..89964.52 rows=224085 width=383) (actual time=372.784..4519.221 rows=641010 loops=1) + Hash Cond: (osm.part = m_1.avpart) + Buffers: shared hit=43 read=56824, local hit=2 + I/O Timings: read=2158.311 + -> Hash Left Join (cost=30.62..81103.81 rows=224085 width=348) (actual time=1.380..3884.310 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 3) = f.f3) + Buffers: shared hit=41 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Hash Left Join (cost=6.93..77718.84 rows=224085 width=324) (actual time=1.257..3476.551 rows=641010 loops=1) + Hash Cond: ((substr(osm.part, 16, 1) = mg.f1) AND (osm.ming = mg.ming)) + Buffers: shared hit=32 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Hash Left Join (cost=6.37..75750.09 rows=224085 width=292) (actual time=1.228..3039.988 rows=641010 loops=1) + Hash Cond: (osm.glec = seg.glec) + Buffers: shared hit=32 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Hash Left Join (cost=5.92..72674.81 rows=224085 width=264) (actual time=1.210..2805.095 rows=641010 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=32 read=50378, local hit=2 + I/O Timings: read=1843.013 + -> Seq Scan on osmp osm (cost=0.00..69587.73 rows=224085 width=184) (actual time=1.134..2545.900 rows=641010 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = 'b19'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 57051 + Buffers: shared hit=32 read=50378 + I/O Timings: read=1843.013 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.058..0.058 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=112) (actual time=0.010..0.033 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.013..0.013 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg (cost=0.00..0.28 rows=14 width=64) (actual time=0.005..0.011 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.018..0.018 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.015 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.118..0.118 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f (cost=0.00..15.53 rows=653 width=24) (actual time=0.017..0.054 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=371.346..371.346 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=2 read=6446 + I/O Timings: read=315.299 + -> Seq Scan on stkmm m_1 (cost=0.00..7258.87 rows=81087 width=54) (actual time=1.087..344.662 rows=80997 loops=1) + Buffers: shared hit=2 read=6446 + I/O Timings: read=315.299 + -> Index Scan using se_dat on gld od (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1281895 read=1 + I/O Timings: read=0.018 + -> Index Scan using se_dat on gld rd (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=641010) + Index Cond: ((osm.adj_requestdate >= sdat) AND (osm.adj_requestdate <= edat)) + Buffers: local hit=1281894 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=110.296..110.296 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2 read=2606 + I/O Timings: read=81.053 + -> Seq Scan on stkmp p_1 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.977..97.487 rows=36699 loops=1) + Buffers: shared hit=2 read=2606 + I/O Timings: read=81.053 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=111.215..111.215 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + Buffers: shared hit=9056 + -> CTE Scan on md (cost=0.00..4.00 rows=200 width=64) (actual time=109.374..110.690 rows=3368 loops=1) + Buffers: shared hit=9056 + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.051..0.051 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l (cost=0.00..3.39 rows=139 width=25) (actual time=0.012..0.026 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=33445583.00..42801951.72 rows=56705265 width=699) (actual time=16460.682..17590.319 rows=250477 loops=1) + Group Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Sort (cost=33445583.00..33587346.16 rows=56705265 width=595) (actual time=16460.650..16563.021 rows=406814 loops=1) + Sort Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Sort Method: quicksort Memory: 222052kB + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=11749.79..11025086.80 rows=56705265 width=595) (actual time=61.424..7759.480 rows=406814 loops=1) + Hash Cond: ((osm_1.bill_class = l_1.bill) AND (osm_1.ship_class = l_1.ship)) + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=11744.32..6967724.27 rows=55168846 width=584) (actual time=61.349..7305.324 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 8) = md_1.mold) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=11737.82..3519664.90 rows=55168846 width=552) (actual time=60.509..6993.509 rows=406814 loops=1) + Hash Cond: (osm_1.part = p_2.awpart) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Nested Loop Left Join (cost=8303.37..3371395.52 rows=55168846 width=528) (actual time=43.514..6803.629 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=1627258 + I/O Timings: read=2275.461 + -> Nested Loop Left Join (cost=8303.23..217901.28 rows=2853561 width=456) (actual time=43.508..5300.883 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=813630 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=8303.08..54789.49 rows=147598 width=384) (actual time=43.490..3729.138 rows=406814 loops=1) + Hash Cond: (osm_1.part = m_2.avpart) + Buffers: shared hit=6457 read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=30.62..46129.57 rows=147598 width=349) (actual time=5.697..3467.540 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 3) = f_1.f3) + Buffers: shared hit=9 read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=6.93..43891.91 rows=147598 width=325) (actual time=5.585..3211.131 rows=406814 loops=1) + Hash Cond: ((substr(osm_1.part, 16, 1) = mg_1.f1) AND (osm_1.ming = mg_1.ming)) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=6.37..42594.49 rows=147598 width=293) (actual time=5.575..2952.469 rows=406814 loops=1) + Hash Cond: (osm_1.glec = seg_1.glec) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Hash Left Join (cost=5.92..40564.57 rows=147598 width=265) (actual time=5.564..2812.752 rows=406814 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2275.461 + -> Seq Scan on osmf osm_1 (cost=0.00..38529.18 rows=147598 width=185) (actual time=5.391..2669.916 rows=406814 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = '5p7'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 358 + Buffers: shared read=26345 + I/O Timings: read=2275.461 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.158..0.158 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=112) (actual time=0.080..0.111 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_1 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.004 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.005..0.005 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_1 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.108..0.108 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_1 (cost=0.00..15.53 rows=653 width=24) (actual time=0.010..0.047 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=37.738..37.738 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_2 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.007..22.454 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=406814) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=813628 + -> Index Scan using se_dat on gld rd_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=406814) + Index Cond: ((osm_1.adj_requestdate >= sdat) AND (osm_1.adj_requestdate <= edat)) + Buffers: local hit=813628 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=16.826..16.826 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_2 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.007..9.949 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=0.825..0.825 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_1 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.290 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.045..0.045 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_1 (cost=0.00..3.39 rows=139 width=25) (actual time=0.008..0.022 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=104083613.45..132995269.35 rows=175222157 width=695) (actual time=10242.201..11403.381 rows=349322 loops=1) + Group Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Buffers: shared hit=15596 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Sort (cost=104083613.45..104521668.84 rows=175222157 width=584) (actual time=10242.147..10337.649 rows=367596 loops=1) + Sort Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Sort Method: quicksort Memory: 201821kB + Buffers: shared hit=15596 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Hash Left Join (cost=11749.79..34574966.31 rows=175222157 width=584) (actual time=54.045..5505.369 rows=367596 loops=1) + Hash Cond: ((osm_2.bill_class = l_2.bill) AND (osm_2.ship_class = l_2.ship)) + Buffers: shared hit=15596 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Hash Left Join (cost=11744.32..22053510.74 rows=175222157 width=572) (actual time=53.991..5099.469 rows=367596 loops=1) + Hash Cond: (substr(osm_2.part, 1, 8) = md_2.mold) + Buffers: shared hit=15594 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Hash Left Join (cost=11737.82..11102119.43 rows=175222157 width=540) (actual time=53.191..4854.338 rows=367596 loops=1) + Hash Cond: (osm_2.part = p_3.awpart) + Buffers: shared hit=15594 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Nested Loop Left Join (cost=8303.37..10638673.75 rows=175222157 width=516) (actual time=37.296..4707.080 rows=367596 loops=1) + Buffers: shared hit=12986 read=51463 dirtied=4, local hit=1469244 + I/O Timings: read=904.147 + -> Nested Loop Left Join (cost=8303.23..623511.84 rows=9063215 width=444) (actual time=37.291..3491.892 rows=367596 loops=1) + Buffers: shared hit=12986 read=51463 dirtied=4, local hit=734624 + I/O Timings: read=904.147 + -> Hash Left Join (cost=8303.08..105486.21 rows=468787 width=372) (actual time=37.263..2223.924 rows=367596 loops=1) + Hash Cond: (osm_2.part = m_3.avpart) + Buffers: shared hit=12986 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=30.62..95983.12 rows=468787 width=337) (actual time=0.270..2039.720 rows=367596 loops=1) + Hash Cond: (substr(osm_2.part, 1, 3) = f_2.f3) + Buffers: shared hit=6538 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=6.93..88927.62 rows=468787 width=313) (actual time=0.129..1823.936 rows=367596 loops=1) + Hash Cond: ((substr(osm_2.part, 16, 1) = mg_2.f1) AND (osm_2.ming = mg_2.ming)) + Buffers: shared hit=6529 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=6.37..84811.93 rows=468787 width=281) (actual time=0.119..1623.505 rows=367596 loops=1) + Hash Cond: (osm_2.glec = seg_2.glec) + Buffers: shared hit=6529 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Hash Left Join (cost=5.92..78421.13 rows=468787 width=253) (actual time=0.111..1504.191 rows=367596 loops=1) + Hash Cond: (osm_2.fspr = sd_2.fspr) + Buffers: shared hit=6529 read=51463 dirtied=4, local hit=2 + I/O Timings: read=904.147 + -> Seq Scan on osm osm_2 (cost=0.00..72340.04 rows=468787 width=173) (actual time=0.052..1372.311 rows=367596 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND ((fspr >= '1606'::text) OR (adj_orderdate >= '2016-06-01'::date))) + Rows Removed by Filter: 417392 + Buffers: shared hit=6529 read=51463 dirtied=4 + I/O Timings: read=904.147 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.053..0.053 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_2 (cost=0.00..3.74 rows=174 width=112) (actual time=0.007..0.029 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_2 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.003 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.006..0.006 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_2 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.136..0.136 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_2 (cost=0.00..15.53 rows=653 width=24) (actual time=0.008..0.047 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=36.937..36.937 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_3 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.006..22.525 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=367596) + Index Cond: ((osm_2.adj_orderdate >= sdat) AND (osm_2.adj_orderdate <= edat)) + Buffers: local hit=734622 + -> Index Scan using se_dat on gld rd_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=367596) + Index Cond: ((osm_2.adj_requestdate >= sdat) AND (osm_2.adj_requestdate <= edat)) + Buffers: local hit=734620 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=15.858..15.858 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_3 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.007..9.906 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=0.788..0.788 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_2 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.291 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.043..0.043 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_2 (cost=0.00..3.39 rows=139 width=25) (actual time=0.007..0.021 rows=139 loops=1) + Buffers: shared hit=2 + CTE agg + -> GroupAggregate (cost=3811565832720.57..4308918237067.99 rows=1808554197627 width=1404) (actual time=130217.184..134929.396 rows=809850 loops=1) + Group Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)), 'Grand Total'::text + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=169623 written=244421 + I/O Timings: read=5796.575 + -> Sort (cost=3811565832720.57..3816087218214.63 rows=1808554197627 width=1346) (actual time=130217.139..131170.872 rows=812592 loops=1) + Sort Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)) + Sort Method: external merge Disk: 476048kB + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=169623 written=244421 + I/O Timings: read=5796.575 + -> Merge Right Join (cost=32058721370.12..253666346227.77 rows=1808554197627 width=1346) (actual time=79725.467..85819.348 rows=812592 loops=1) + Merge Cond: (ss.ssyr = un.sseas) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660295 read=1, temp read=110117 written=184914 + I/O Timings: read=5796.575 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.123..0.131 rows=15 loops=1) + Sort Key: ss.ssyr + Sort Method: quicksort Memory: 26kB + Buffers: local hit=2 + -> CTE Scan on std ss (cost=0.00..302.76 rows=15138 width=40) (actual time=0.082..0.119 rows=15 loops=1) + Buffers: local hit=2 + -> Materialize (cost=32058720016.34..32178191161.64 rows=23894229061 width=1300) (actual time=79718.116..82479.293 rows=812592 loops=1) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=110117 written=184914 + I/O Timings: read=5796.575 + -> Sort (cost=32058720016.34..32118455588.99 rows=23894229061 width=1300) (actual time=79718.091..80948.227 rows=812592 loops=1) + Sort Key: un.sseas + Sort Method: external merge Disk: 446032kB + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=110117 written=146652 + I/O Timings: read=5796.575 + -> Merge Right Join (cost=466287095.31..825489820.45 rows=23894229061 width=1300) (actual time=67066.711..71526.574 rows=812592 loops=1) + Merge Cond: (so.ssyr = un.oseas) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=54363 written=90897 + I/O Timings: read=5796.575 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.004..0.008 rows=13 loops=1) + Sort Key: so.ssyr + Sort Method: quicksort Memory: 26kB + -> CTE Scan on std so (cost=0.00..302.76 rows=15138 width=40) (actual time=0.000..0.002 rows=15 loops=1) + -> Materialize (cost=466285741.52..467864168.60 rows=315685415 width=1268) (actual time=67055.329..70663.573 rows=812592 loops=1) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=54363 written=90897 + I/O Timings: read=5796.575 + -> Sort (cost=466285741.52..467074955.06 rows=315685415 width=1268) (actual time=67050.634..68022.803 rows=812592 loops=1) + Sort Key: un.oseas + Sort Method: external merge Disk: 434904kB + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1, temp read=54363 written=54364 + I/O Timings: read=5796.575 + -> Hash Left Join (cost=30326.40..72123629.81 rows=315685415 width=1268) (actual time=24989.685..60611.536 rows=812592 loops=1) + Hash Cond: ((un.part = cr.y0part) AND (un.plnt = cr.y0plnt)) + Buffers: shared hit=36995 read=155565 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5796.575 + -> Hash Left Join (cost=22414.65..53910516.25 rows=315685415 width=1262) (actual time=24857.162..60071.090 rows=812592 loops=1) + Hash Cond: ((un.part = cp.chpart) AND (un.plnt = cp.chplnt)) + Buffers: shared hit=36995 read=150313 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5704.175 + -> Hash Left Join (cost=14299.03..34905098.97 rows=315685415 width=1256) (actual time=24690.716..59482.739 rows=812592 loops=1) + Hash Cond: ((un.part = cm.cgpart) AND (un.plnt = cm.cgplnt)) + Buffers: shared hit=36995 read=144997 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5598.963 + -> Hash Left Join (cost=7433.88..32509062.54 rows=315685415 width=1250) (actual time=24542.324..58815.424 rows=812592 loops=1) + Hash Cond: (un.bill_cust = sc.bvcust) + Buffers: shared hit=36995 read=140490 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5507.001 + -> Hash Left Join (cost=3723.16..28164677.36 rows=315685415 width=1223) (actual time=24531.977..58466.240 rows=812592 loops=1) + Hash Cond: (un.bill_cust = bc.bvcust) + Buffers: shared hit=33771 read=140490 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5507.001 + -> Hash Left Join (cost=12.44..23820292.19 rows=315685415 width=1196) (actual time=24445.824..58031.724 rows=812592 loops=1) + Hash Cond: ((un.ming = mmgp.brmgrp) AND (un.majg = mmgp.brgrp)) + Buffers: shared hit=33771 read=137266 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.817 + -> Hash Left Join (cost=7.51..14337334.16 rows=315685415 width=1186) (actual time=24445.412..57697.186 rows=812592 loops=1) + Hash Cond: (un.majg = majg.bqgrp) + Buffers: shared hit=33771 read=137265 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.479 + -> Hash Left Join (cost=6.24..12964101.34 rows=315685415 width=1176) (actual time=24445.051..57415.327 rows=812592 loops=1) + Hash Cond: (un.majs = sj.bsmjcd) + Buffers: shared hit=33771 read=137264 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.137 + -> Hash Left Join (cost=6.21..11764496.73 rows=315685415 width=1144) (actual time=24445.027..57139.761 rows=812592 loops=1) + Hash Cond: ((un.majs = si.bsmjcd) AND (un.mins = si.bsmncd)) + Buffers: shared hit=33770 read=137264 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5435.137 + -> Hash Left Join (cost=3.90..9391645.00 rows=315685415 width=1112) (actual time=24443.462..56809.926 rows=812592 loops=1) + Hash Cond: (un.quota_rep = repc.rcode) + Buffers: shared hit=33770 read=137263 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5433.634 + -> CTE Scan on un (cost=0.00..6313708.30 rows=315685415 width=1048) (actual time=24427.626..56309.934 rows=812592 loops=1) + Buffers: shared hit=33769 read=137238 dirtied=4, local hit=5660293 read=1 + I/O Timings: read=5418.990 + -> Hash (cost=2.40..2.40 rows=120 width=96) (actual time=15.823..15.823 rows=120 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 17kB + Buffers: shared hit=1 read=25 + I/O Timings: read=14.644 + -> CTE Scan on repc (cost=0.00..2.40 rows=120 width=96) (actual time=7.422..15.771 rows=120 loops=1) + Buffers: shared hit=1 read=25 + I/O Timings: read=14.644 + -> Hash (cost=1.32..1.32 rows=66 width=96) (actual time=1.556..1.556 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=1.503 + -> CTE Scan on si (cost=0.00..1.32 rows=66 width=96) (actual time=1.516..1.541 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=1.503 + -> Hash (cost=0.02..0.02 rows=1 width=64) (actual time=0.017..0.017 rows=11 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=1 + -> CTE Scan on sj (cost=0.00..0.02 rows=1 width=64) (actual time=0.006..0.014 rows=11 loops=1) + Buffers: shared hit=1 + -> Hash (cost=1.12..1.12 rows=12 width=14) (actual time=0.357..0.357 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared read=1 + I/O Timings: read=0.342 + -> Seq Scan on majg (cost=0.00..1.12 rows=12 width=14) (actual time=0.349..0.351 rows=12 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.342 + -> Hash (cost=2.57..2.57 rows=157 width=18) (actual time=0.404..0.404 rows=157 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=1 + I/O Timings: read=0.338 + -> Seq Scan on mmgp (cost=0.00..2.57 rows=157 width=18) (actual time=0.350..0.369 rows=157 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.338 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=86.128..86.128 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared read=3224 + I/O Timings: read=71.184 + -> Seq Scan on cust bc (cost=0.00..3440.32 rows=21632 width=35) (actual time=1.719..80.386 rows=21632 loops=1) + Buffers: shared read=3224 + I/O Timings: read=71.184 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=10.320..10.320 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared hit=3224 + -> Seq Scan on cust sc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.007..6.682 rows=21632 loops=1) + Buffers: shared hit=3224 + -> Hash (cost=5450.26..5450.26 rows=94326 width=29) (actual time=148.322..148.322 rows=94326 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6699kB + Buffers: shared read=4507 + I/O Timings: read=91.962 + -> Seq Scan on icstm cm (cost=0.00..5450.26 rows=94326 width=29) (actual time=1.674..121.636 rows=94326 loops=1) + Buffers: shared read=4507 + I/O Timings: read=91.962 + -> Hash (cost=6435.85..6435.85 rows=111985 width=20) (actual time=166.382..166.382 rows=111985 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6768kB + Buffers: shared read=5316 + I/O Timings: read=105.211 + -> Seq Scan on icstp cp (cost=0.00..6435.85 rows=111985 width=20) (actual time=2.877..136.300 rows=111985 loops=1) + Buffers: shared read=5316 + I/O Timings: read=105.211 + -> Hash (cost=6315.90..6315.90 rows=106390 width=27) (actual time=132.044..132.044 rows=106390 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7334kB + Buffers: shared read=5252 + I/O Timings: read=92.401 + -> Seq Scan on icstr cr (cost=0.00..6315.90 rows=106390 width=27) (actual time=1.095..107.748 rows=106390 loops=1) + Buffers: shared read=5252 + I/O Timings: read=92.401 + -> CTE Scan on agg a (cost=0.00..36171083952.54 rows=1808554197627 width=1520) (actual time=130217.189..139003.919 rows=809850 loops=1) + Buffers: shared hit=37003 read=155565 dirtied=4, local hit=5660295 read=1, temp read=169623 written=302291 + I/O Timings: read=5796.575 + -> CTE Scan on agg a_1 (cost=0.00..41167214923.48 rows=13564156482 width=1520) (actual time=313.638..4190.172 rows=298727 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Forecast}'::text[]))) + Rows Removed by Filter: 511123 + Buffers: temp read=57871 written=1 + -> CTE Scan on agg a_2 (cost=0.00..41167214923.48 rows=13564156482 width=1520) (actual time=77.645..4240.941 rows=270385 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Budget}'::text[]))) + Rows Removed by Filter: 539465 + Buffers: temp read=57871 + +
+Date: 2019-03-15 14:09:18 +Duration: 2m2s +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Append (cost=4510966117154.68..4644894879274.93 rows=1921380827591 width=1520) (actual time=112425.684..121699.211 rows=1378380 loops=1) + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=285302 written=302218 + I/O Timings: read=5431.112 + CTE seg + -> Values Scan on "*VALUES*" (cost=0.00..0.18 rows=14 width=64) (actual time=0.003..0.006 rows=14 loops=1) + CTE mg + -> Values Scan on "*VALUES*_1" (cost=0.00..0.20 rows=16 width=96) (actual time=0.002..0.007 rows=16 loops=1) + CTE repc + -> Hash Left Join (cost=11.47..123.28 rows=120 width=96) (actual time=4.005..11.391 rows=120 loops=1) + Hash Cond: (ltrim(rtrim(c.a9)) = q.qr) + Buffers: shared read=26 + I/O Timings: read=10.590 + -> Bitmap Heap Scan on code c (cost=9.21..118.86 rows=120 width=25) (actual time=3.631..10.743 rows=120 loops=1) + Recheck Cond: (a2 = 'MM'::text) + Heap Blocks: exact=21 + Buffers: shared read=25 + I/O Timings: read=10.256 + -> Bitmap Index Scan on pk_code (cost=0.00..9.18 rows=120 width=0) (actual time=2.484..2.484 rows=120 loops=1) + Index Cond: (a2 = 'MM'::text) + Buffers: shared read=4 + I/O Timings: read=2.398 + -> Hash (cost=1.56..1.56 rows=56 width=12) (actual time=0.359..0.359 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.334 + -> Seq Scan on qrh q (cost=0.00..1.56 rows=56 width=12) (actual time=0.342..0.348 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.334 + CTE md + -> HashAggregate (cost=11936.00..11938.00 rows=200 width=64) (actual time=141.238..141.651 rows=3368 loops=1) + Group Key: (substr(m.avpart, 1, 8)) + Buffers: shared hit=9056 + -> Append (cost=8137.31..11870.54 rows=13091 width=64) (actual time=131.283..140.399 rows=3375 loops=1) + Buffers: shared hit=9056 + -> HashAggregate (cost=8137.31..8249.94 rows=9010 width=64) (actual time=131.282..131.853 rows=3285 loops=1) + Group Key: substr(m.avpart, 1, 8) + Buffers: shared hit=6448 + -> Seq Scan on stkmm m (cost=0.00..8092.26 rows=9010 width=59) (actual time=0.026..38.556 rows=76269 loops=1) + Filter: ((length(avpart) > 8) AND (substr(avgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 4728 + Buffers: shared hit=6448 + -> HashAggregate (cost=3373.23..3424.24 rows=4081 width=64) (actual time=8.321..8.352 rows=90 loops=1) + Group Key: substr(p.awpart, 1, 8) + Buffers: shared hit=2608 + -> Seq Scan on stkmp p (cost=0.00..3352.82 rows=4081 width=52) (actual time=0.446..8.258 rows=142 loops=1) + Filter: ((length(awpart) > 8) AND (substr(awgled, 1, 1) <= '2'::text)) + Rows Removed by Filter: 36557 + Buffers: shared hit=2608 + CTE sj + -> Seq Scan on mmsl (cost=0.00..1.84 rows=1 width=22) (actual time=0.004..0.009 rows=11 loops=1) + Filter: (COALESCE(bsmncd, ''::text) = ''::text) + Rows Removed by Filter: 56 + Buffers: shared hit=1 + CTE si + -> Seq Scan on mmsl mmsl_1 (cost=0.00..1.84 rows=66 width=22) (actual time=0.307..0.314 rows=56 loops=1) + Filter: (COALESCE(bsmncd, ''::text) <> ''::text) + Rows Removed by Filter: 11 + Buffers: shared read=1 + I/O Timings: read=0.297 + CTE seas + -> GroupAggregate (cost=10.22..16.31 rows=174 width=41) (actual time=0.068..0.100 rows=15 loops=1) + Group Key: gld.ssyr + Buffers: local hit=2 + -> Sort (cost=10.22..10.65 rows=174 width=16) (actual time=0.054..0.061 rows=174 loops=1) + Sort Key: gld.ssyr DESC + Sort Method: quicksort Memory: 33kB + Buffers: local hit=2 + -> Seq Scan on gld (cost=0.00..3.74 rows=174 width=16) (actual time=0.010..0.030 rows=174 loops=1) + Buffers: local hit=2 + CTE intv + -> CTE Scan on seas (cost=0.00..4.13 rows=87 width=4) (actual time=0.080..0.081 rows=1 loops=1) + Filter: cy + Rows Removed by Filter: 14 + Buffers: local hit=2 + CTE std + -> Nested Loop (cost=0.00..457.62 rows=15138 width=73) (actual time=0.087..0.122 rows=15 loops=1) + Buffers: local hit=2 + -> CTE Scan on intv (cost=0.00..1.74 rows=87 width=4) (actual time=0.081..0.082 rows=1 loops=1) + Buffers: local hit=2 + -> CTE Scan on seas s (cost=0.00..3.48 rows=174 width=41) (actual time=0.000..0.028 rows=15 loops=1) + CTE un + -> Append (cost=50003223.80..255856479.46 rows=330423099 width=697) (actual time=26363.405..56340.259 rows=812398 loops=1) + Buffers: shared hit=32147 read=138860, local hit=5659517 read=1 + I/O Timings: read=5000.713 + -> GroupAggregate (cost=50003223.80..63823292.65 rows=83757993 width=701) (actual time=26363.404..28258.932 rows=212793 loops=1) + Group Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Buffers: shared hit=9063 read=59473, local hit=2563791 read=1 + I/O Timings: read=2714.560 + -> Sort (cost=50003223.80..50212618.79 rows=83757993 width=594) (actual time=26363.369..26503.583 rows=641010 loops=1) + Sort Key: od.ssyr, osm.adj_orderdate, sd.ssyr, (LEAST(GREATEST(osm.adj_shipdate, sd.sdat), sd.edat)), rd.ssyr, osm.adj_requestdate, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(rd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)), (COALESCE(rd.cy, 'F'::text)), osm.plnt, osm.account, osm.bill_cust, osm.shipgrp, osm.ship_cust, osm.chan, l.retail, l.retailsub, osm.promo, osm.majg, osm.ming, osm.majs, osm.mins, osm.part, (((osm.part || ' - '::text) || rtrim(COALESCE(m_1.avdes1, p_1.awdes1)))), (((f.f3 || ' - '::text) || f.descr)), (((substr(osm.part, 1, 8) || ' - '::text) || md.descr)), (COALESCE(mg.grp, 'Unbranded'::text)), (COALESCE(seg.segm, 'Other'::text)), osm.quota_rep, (CASE osm.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm.calc_status END), osm.c_rate + Sort Method: quicksort Memory: 352782kB + Buffers: shared hit=9063 read=59473, local hit=2563791 read=1 + I/O Timings: read=2714.560 + -> Hash Left Join (cost=11749.79..16650773.71 rows=83757993 width=594) (actual time=412.849..12408.886 rows=641010 loops=1) + Hash Cond: ((osm.bill_class = l.bill) AND (osm.ship_class = l.ship)) + Buffers: shared hit=9060 read=59473, local hit=2563791 read=1 + I/O Timings: read=2714.560 + -> Hash Left Join (cost=11744.32..10583311.94 rows=83757993 width=583) (actual time=412.362..11595.759 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 8) = md.mold) + Buffers: shared hit=9060 read=59471, local hit=2563791 read=1 + I/O Timings: read=2714.141 + -> Hash Left Join (cost=11737.82..5348430.88 rows=83757993 width=551) (actual time=269.279..10961.881 rows=641010 loops=1) + Hash Cond: (osm.part = p_1.awpart) + Buffers: shared hit=4 read=59471, local hit=2563791 read=1 + I/O Timings: read=2714.141 + -> Nested Loop Left Join (cost=8303.37..5125106.33 rows=83757993 width=527) (actual time=188.919..10630.169 rows=641010 loops=1) + Buffers: shared hit=2 read=56865, local hit=2563791 read=1 + I/O Timings: read=2652.319 + -> Nested Loop Left Join (cost=8303.23..337594.45 rows=4332310 width=455) (actual time=188.914..7884.956 rows=641010 loops=1) + Buffers: shared hit=2 read=56865, local hit=1281897 read=1 + I/O Timings: read=2652.319 + -> Hash Left Join (cost=8303.08..89964.52 rows=224085 width=383) (actual time=188.885..5089.482 rows=641010 loops=1) + Hash Cond: (osm.part = m_1.avpart) + Buffers: shared hit=2 read=56865, local hit=2 + I/O Timings: read=2652.306 + -> Hash Left Join (cost=30.62..81103.81 rows=224085 width=348) (actual time=3.518..4614.841 rows=641010 loops=1) + Hash Cond: (substr(osm.part, 1, 3) = f.f3) + Buffers: shared read=50419, local hit=2 + I/O Timings: read=2511.680 + -> Hash Left Join (cost=6.93..77718.84 rows=224085 width=324) (actual time=2.296..4183.537 rows=641010 loops=1) + Hash Cond: ((substr(osm.part, 16, 1) = mg.f1) AND (osm.ming = mg.ming)) + Buffers: shared read=50410, local hit=2 + I/O Timings: read=2510.588 + -> Hash Left Join (cost=6.37..75750.09 rows=224085 width=292) (actual time=2.277..3733.098 rows=641010 loops=1) + Hash Cond: (osm.glec = seg.glec) + Buffers: shared read=50410, local hit=2 + I/O Timings: read=2510.588 + -> Hash Left Join (cost=5.92..72674.81 rows=224085 width=264) (actual time=2.259..3490.071 rows=641010 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared read=50410, local hit=2 + I/O Timings: read=2510.588 + -> Seq Scan on osmp osm (cost=0.00..69587.73 rows=224085 width=184) (actual time=2.186..3227.306 rows=641010 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = 'b19'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 57051 + Buffers: shared read=50410 + I/O Timings: read=2510.588 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.060..0.060 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=112) (actual time=0.008..0.034 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.014..0.014 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg (cost=0.00..0.28 rows=14 width=64) (actual time=0.005..0.011 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.015..0.015 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.011 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=1.217..1.217 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared read=9 + I/O Timings: read=1.092 + -> Seq Scan on family f (cost=0.00..15.53 rows=653 width=24) (actual time=0.985..1.149 rows=653 loops=1) + Buffers: shared read=9 + I/O Timings: read=1.092 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=185.313..185.313 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=2 read=6446 + I/O Timings: read=140.626 + -> Seq Scan on stkmm m_1 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.508..163.116 rows=80997 loops=1) + Buffers: shared hit=2 read=6446 + I/O Timings: read=140.626 + -> Index Scan using se_dat on gld od (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=641010) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1281895 read=1 + I/O Timings: read=0.013 + -> Index Scan using se_dat on gld rd (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.004 rows=1 loops=641010) + Index Cond: ((osm.adj_requestdate >= sdat) AND (osm.adj_requestdate <= edat)) + Buffers: local hit=1281894 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=80.171..80.171 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2 read=2606 + I/O Timings: read=61.823 + -> Seq Scan on stkmp p_1 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.342..70.937 rows=36699 loops=1) + Buffers: shared hit=2 read=2606 + I/O Timings: read=61.823 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=143.065..143.065 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + Buffers: shared hit=9056 + -> CTE Scan on md (cost=0.00..4.00 rows=200 width=64) (actual time=141.241..142.539 rows=3368 loops=1) + Buffers: shared hit=9056 + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.472..0.472 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=2 + I/O Timings: read=0.418 + -> Seq Scan on ffchnl l (cost=0.00..3.39 rows=139 width=25) (actual time=0.424..0.443 rows=139 loops=1) + Buffers: shared read=2 + I/O Timings: read=0.418 + -> GroupAggregate (cost=33445583.00..42801951.72 rows=56705265 width=699) (actual time=17060.209..18105.019 rows=250477 loops=1) + Group Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Sort (cost=33445583.00..33587346.16 rows=56705265 width=595) (actual time=17060.177..17152.591 rows=406814 loops=1) + Sort Key: od_1.ssyr, osm_1.adj_orderdate, sd_1.ssyr, (LEAST(GREATEST(osm_1.adj_shipdate, sd_1.sdat), sd_1.edat)), rd_1.ssyr, osm_1.adj_requestdate, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(rd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)), (COALESCE(rd_1.cy, 'F'::text)), osm_1.plnt, osm_1.account, osm_1.bill_cust, osm_1.shipgrp, osm_1.ship_cust, osm_1.chan, l_1.retail, l_1.retailsub, osm_1.promo, osm_1.majg, osm_1.ming, osm_1.majs, osm_1.mins, osm_1.part, (((osm_1.part || ' - '::text) || rtrim(COALESCE(m_2.avdes1, p_2.awdes1)))), (((f_1.f3 || ' - '::text) || f_1.descr)), (((substr(osm_1.part, 1, 8) || ' - '::text) || md_1.descr)), (COALESCE(mg_1.grp, 'Unbranded'::text)), (COALESCE(seg_1.segm, 'Other'::text)), osm_1.quota_rep, (CASE osm_1.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_1.calc_status END), osm_1.c_rate + Sort Method: quicksort Memory: 222052kB + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=11749.79..11025086.80 rows=56705265 width=595) (actual time=160.607..8900.120 rows=406814 loops=1) + Hash Cond: ((osm_1.bill_class = l_1.bill) AND (osm_1.ship_class = l_1.ship)) + Buffers: shared hit=9067 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=11744.32..6967724.27 rows=55168846 width=584) (actual time=160.531..8303.160 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 8) = md_1.mold) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=11737.82..3519664.90 rows=55168846 width=552) (actual time=159.458..7928.685 rows=406814 loops=1) + Hash Cond: (osm_1.part = p_2.awpart) + Buffers: shared hit=9065 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Nested Loop Left Join (cost=8303.37..3371395.52 rows=55168846 width=528) (actual time=139.481..7719.889 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=1627258 + I/O Timings: read=2202.796 + -> Nested Loop Left Join (cost=8303.23..217901.28 rows=2853561 width=456) (actual time=139.471..5838.942 rows=406814 loops=1) + Buffers: shared hit=6457 read=26345, local hit=813630 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=8303.08..54789.49 rows=147598 width=384) (actual time=139.449..3929.023 rows=406814 loops=1) + Hash Cond: (osm_1.part = m_2.avpart) + Buffers: shared hit=6457 read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=30.62..46129.57 rows=147598 width=349) (actual time=79.183..3618.398 rows=406814 loops=1) + Hash Cond: (substr(osm_1.part, 1, 3) = f_1.f3) + Buffers: shared hit=9 read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=6.93..43891.91 rows=147598 width=325) (actual time=78.806..3313.087 rows=406814 loops=1) + Hash Cond: ((substr(osm_1.part, 16, 1) = mg_1.f1) AND (osm_1.ming = mg_1.ming)) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=6.37..42594.49 rows=147598 width=293) (actual time=78.771..2997.016 rows=406814 loops=1) + Hash Cond: (osm_1.glec = seg_1.glec) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Hash Left Join (cost=5.92..40564.57 rows=147598 width=265) (actual time=78.706..2840.808 rows=406814 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2202.796 + -> Seq Scan on osmf osm_1 (cost=0.00..38529.18 rows=147598 width=185) (actual time=78.437..2657.330 rows=406814 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND (version = '5p7'::text) AND (substr(glec, 1, 1) <= '2'::text) AND ((fspr >= '1901'::text) OR (adj_orderdate >= '2018-06-01'::date))) + Rows Removed by Filter: 358 + Buffers: shared read=26345 + I/O Timings: read=2202.796 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.200..0.200 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=112) (actual time=0.053..0.147 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.039..0.039 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_1 (cost=0.00..0.28 rows=14 width=64) (actual time=0.009..0.015 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.014..0.014 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_1 (cost=0.00..0.32 rows=16 width=96) (actual time=0.003..0.008 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.350..0.350 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_1 (cost=0.00..15.53 rows=653 width=24) (actual time=0.090..0.194 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=59.937..59.937 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_2 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.021..34.499 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=813628 + -> Index Scan using se_dat on gld rd_1 (cost=0.14..0.92 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm_1.adj_requestdate >= sdat) AND (osm_1.adj_requestdate <= edat)) + Buffers: local hit=813628 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=19.766..19.766 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_2 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.008..10.901 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=1.056..1.056 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_1 (cost=0.00..4.00 rows=200 width=64) (actual time=0.003..0.385 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.055..0.055 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_1 (cost=0.00..3.39 rows=139 width=25) (actual time=0.007..0.025 rows=139 loops=1) + Buffers: shared hit=2 + -> GroupAggregate (cost=112931514.84..144274888.60 rows=189959841 width=695) (actual time=8819.747..9896.203 rows=349128 loops=1) + Group Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Buffers: shared hit=14017 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Sort (cost=112931514.84..113406414.44 rows=189959841 width=584) (actual time=8819.714..8895.706 rows=367402 loops=1) + Sort Key: od_2.ssyr, osm_2.adj_orderdate, sd_2.ssyr, (LEAST(GREATEST(osm_2.adj_shipdate, sd_2.sdat), sd_2.edat)), rd_2.ssyr, osm_2.adj_requestdate, (COALESCE(od_2.cm, sd_2.cm)), (COALESCE(sd_2.cm, 'F'::text)), (COALESCE(rd_2.cm, 'F'::text)), (COALESCE(od_2.cy, sd_2.cy)), (COALESCE(sd_2.cy, 'F'::text)), (COALESCE(rd_2.cy, 'F'::text)), osm_2.plnt, osm_2.account, osm_2.bill_cust, osm_2.shipgrp, osm_2.ship_cust, osm_2.chan, l_2.retail, l_2.retailsub, osm_2.promo, osm_2.majg, osm_2.ming, osm_2.majs, osm_2.mins, osm_2.part, (((osm_2.part || ' - '::text) || rtrim(COALESCE(m_3.avdes1, p_3.awdes1)))), (((f_2.f3 || ' - '::text) || f_2.descr)), (((substr(osm_2.part, 1, 8) || ' - '::text) || md_2.descr)), (COALESCE(mg_2.grp, 'Unbranded'::text)), (COALESCE(seg_2.segm, 'Other'::text)), osm_2.quota_rep, (CASE osm_2.fspr WHEN '0000'::text THEN 'SHIP NOT BILLED'::text ELSE osm_2.calc_status END), osm_2.c_rate + Sort Method: quicksort Memory: 201721kB + Buffers: shared hit=14017 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Hash Left Join (cost=11749.79..37465936.67 rows=189959841 width=584) (actual time=50.604..4494.745 rows=367402 loops=1) + Hash Cond: ((osm_2.bill_class = l_2.bill) AND (osm_2.ship_class = l_2.ship)) + Buffers: shared hit=14017 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Hash Left Join (cost=11744.32..23902628.82 rows=189959841 width=574) (actual time=50.549..4122.287 rows=367402 loops=1) + Hash Cond: (substr(osm_2.part, 1, 8) = md_2.mold) + Buffers: shared hit=14015 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Hash Left Join (cost=11737.82..12030132.26 rows=189959841 width=542) (actual time=49.780..3891.847 rows=367402 loops=1) + Hash Cond: (osm_2.part = p_3.awpart) + Buffers: shared hit=14015 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Nested Loop Left Join (cost=8303.37..11527995.69 rows=189959841 width=518) (actual time=34.804..3756.178 rows=367402 loops=1) + Buffers: shared hit=11407 read=53042, local hit=1468468 + I/O Timings: read=83.358 + -> Nested Loop Left Join (cost=8303.23..670498.91 rows=9825509 width=446) (actual time=34.797..2623.310 rows=367402 loops=1) + Buffers: shared hit=11407 read=53042, local hit=734236 + I/O Timings: read=83.358 + -> Hash Left Join (cost=8303.08..108904.23 rows=508216 width=374) (actual time=34.774..1278.961 rows=367402 loops=1) + Hash Cond: (osm_2.part = m_3.avpart) + Buffers: shared hit=11407 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=30.62..99297.64 rows=508216 width=339) (actual time=0.327..1108.708 rows=367402 loops=1) + Hash Cond: (substr(osm_2.part, 1, 3) = f_2.f3) + Buffers: shared hit=4959 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=6.93..91650.71 rows=508216 width=315) (actual time=0.203..921.418 rows=367402 loops=1) + Hash Cond: ((substr(osm_2.part, 16, 1) = mg_2.f1) AND (osm_2.ming = mg_2.ming)) + Buffers: shared hit=4950 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=6.37..87189.88 rows=508216 width=283) (actual time=0.191..727.591 rows=367402 loops=1) + Hash Cond: (osm_2.glec = seg_2.glec) + Buffers: shared hit=4950 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Hash Left Join (cost=5.92..80265.15 rows=508216 width=255) (actual time=0.180..611.979 rows=367402 loops=1) + Hash Cond: (osm_2.fspr = sd_2.fspr) + Buffers: shared hit=4950 read=53042, local hit=2 + I/O Timings: read=83.358 + -> Seq Scan on osm osm_2 (cost=0.00..73663.10 rows=508216 width=175) (actual time=0.106..492.248 rows=367402 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (fs_line = '41010'::text) AND ((fspr >= '1606'::text) OR (adj_orderdate >= '2016-06-01'::date))) + Rows Removed by Filter: 417370 + Buffers: shared hit=4950 read=53042 + I/O Timings: read=83.358 + -> Hash (cost=3.74..3.74 rows=174 width=112) (actual time=0.065..0.065 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_2 (cost=0.00..3.74 rows=174 width=112) (actual time=0.018..0.041 rows=174 loops=1) + Buffers: local hit=2 + -> Hash (cost=0.28..0.28 rows=14 width=64) (actual time=0.006..0.006 rows=14 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on seg seg_2 (cost=0.00..0.28 rows=14 width=64) (actual time=0.002..0.003 rows=14 loops=1) + -> Hash (cost=0.32..0.32 rows=16 width=96) (actual time=0.006..0.006 rows=16 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mg mg_2 (cost=0.00..0.32 rows=16 width=96) (actual time=0.001..0.002 rows=16 loops=1) + -> Hash (cost=15.53..15.53 rows=653 width=24) (actual time=0.119..0.119 rows=653 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 44kB + Buffers: shared hit=9 + -> Seq Scan on family f_2 (cost=0.00..15.53 rows=653 width=24) (actual time=0.014..0.051 rows=653 loops=1) + Buffers: shared hit=9 + -> Hash (cost=7258.87..7258.87 rows=81087 width=54) (actual time=34.398..34.398 rows=80997 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7997kB + Buffers: shared hit=6448 + -> Seq Scan on stkmm m_3 (cost=0.00..7258.87 rows=81087 width=54) (actual time=0.006..21.130 rows=80997 loops=1) + Buffers: shared hit=6448 + -> Index Scan using se_dat on gld od_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=367402) + Index Cond: ((osm_2.adj_orderdate >= sdat) AND (osm_2.adj_orderdate <= edat)) + Buffers: local hit=734234 + -> Index Scan using se_dat on gld rd_2 (cost=0.14..0.92 rows=19 width=80) (actual time=0.002..0.003 rows=1 loops=367402) + Index Cond: ((osm_2.adj_requestdate >= sdat) AND (osm_2.adj_requestdate <= edat)) + Buffers: local hit=734232 + -> Hash (cost=2975.31..2975.31 rows=36731 width=33) (actual time=14.938..14.938 rows=36699 loops=1) + Buckets: 65536 Batches: 1 Memory Usage: 2881kB + Buffers: shared hit=2608 + -> Seq Scan on stkmp p_3 (cost=0.00..2975.31 rows=36731 width=33) (actual time=0.006..9.060 rows=36699 loops=1) + Buffers: shared hit=2608 + -> Hash (cost=4.00..4.00 rows=200 width=64) (actual time=0.757..0.757 rows=3368 loops=1) + Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 255kB + -> CTE Scan on md md_2 (cost=0.00..4.00 rows=200 width=64) (actual time=0.002..0.289 rows=3368 loops=1) + -> Hash (cost=3.39..3.39 rows=139 width=25) (actual time=0.042..0.042 rows=139 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared hit=2 + -> Seq Scan on ffchnl l_2 (cost=0.00..3.39 rows=139 width=25) (actual time=0.006..0.020 rows=139 loops=1) + Buffers: shared hit=2 + CTE agg + -> GroupAggregate (cost=3990139087947.22..4510710248131.84 rows=1892986037035 width=1404) (actual time=112425.677..116271.291 rows=809656 loops=1) + Group Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)), 'Grand Total'::text + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=169586 written=244360 + I/O Timings: read=5431.112 + -> Sort (cost=3990139087947.22..3994871553039.80 rows=1892986037035 width=1346) (actual time=112425.642..112859.948 rows=812398 loops=1) + Sort Key: un.version, un.iter, ((un.oseas)::numeric), un.odate, ((un.sseas)::numeric), un.sdate, ((un.rseas)::numeric), un.rdate, un.om, un.sm, un.rm, un.oy, ((un.odate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.odate <@ so.ytd)), un.sy, ((un.sdate <@ '[2018-06-01,2019-03-16)'::daterange)), ((un.sdate <@ ss.ytd)), (CASE WHEN ((upper(so.ytd) - '1 day'::interval) >= un.odate) THEN CASE WHEN ((un.sdate > (upper(so.ytd) - '1 day'::interval)) OR (un.sy = 'F'::text)) THEN CASE WHEN ((upper(so.ytd) - '1 day'::interval) > un.rdate) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE 'Shipped'::text END ELSE 'Not Yet Placed'::text END), un.ry, un.plnt, un.account, (((un.bill_cust || ' - '::text) || rtrim(bc.bvname))), bc.bvctry, bc.bvprcd, un.shipgrp, (((un.ship_cust || ' - '::text) || rtrim(sc.bvname))), sc.bvctry, sc.bvprcd, un.chan, (CASE un.segm WHEN 'Retail'::text THEN un.retail ELSE un.chan END), (CASE un.segm WHEN 'Retail'::text THEN un.retailsub ELSE ''::text END), un.promo, ((un.majg || COALESCE((' - '::text || majg.bqdes), ''::text))), ((un.ming || COALESCE((' - '::text || mmgp.brdes), ''::text))), ((un.majs || COALESCE((' - '::text || sj.bsdes1), ''::text))), ((un.mins || COALESCE((' - '::text || si.bsdes1), ''::text))), un.part, un.part_descr, un.part_family, un.part_group, un.branding, un.segm, (COALESCE(repc.repp, un.quota_rep)), (COALESCE(repc.director, un.quota_rep)), (((un.version || '-'::text) || un.sy)), (((un.version || '-'::text) || un.oy)), (CASE WHEN (un.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) THEN CASE WHEN (un.rdate < CURRENT_DATE) THEN 'Open - Past Due'::text ELSE 'Open - Current'::text END ELSE un.calc_status END), (((substr(un.part, 9, 3) || '-'::text) || un.branding)) + Sort Method: external merge Disk: 475944kB + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=169586 written=244360 + I/O Timings: read=5431.112 + -> Merge Right Join (cost=33563712447.31..265517026370.70 rows=1892986037035 width=1346) (actual time=69370.743..73383.296 rows=812398 loops=1) + Merge Cond: (ss.ssyr = un.sseas) + Buffers: shared hit=35372 read=157188, local hit=5659519 read=1, temp read=110093 written=184866 + I/O Timings: read=5431.112 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.187..0.194 rows=15 loops=1) + Sort Key: ss.ssyr + Sort Method: quicksort Memory: 26kB + Buffers: local hit=2 + -> CTE Scan on std ss (cost=0.00..302.76 rows=15138 width=40) (actual time=0.143..0.183 rows=15 loops=1) + Buffers: local hit=2 + -> Materialize (cost=33563711093.53..33688759715.34 rows=25009724363 width=1300) (actual time=69363.504..70242.785 rows=812398 loops=1) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=110093 written=184866 + I/O Timings: read=5431.112 + -> Sort (cost=33563711093.53..33626235404.44 rows=25009724363 width=1300) (actual time=69363.500..69636.493 rows=812398 loops=1) + Sort Key: un.sseas + Sort Method: external merge Disk: 445936kB + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=110093 written=146616 + I/O Timings: read=5431.112 + -> Merge Right Join (cost=488162845.81..864134844.69 rows=25009724363 width=1300) (actual time=64619.072..67097.961 rows=812398 loops=1) + Merge Cond: (so.ssyr = un.oseas) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=54351 written=90873 + I/O Timings: read=5431.112 + -> Sort (cost=1353.78..1391.63 rows=15138 width=40) (actual time=0.005..0.009 rows=13 loops=1) + Sort Key: so.ssyr + Sort Method: quicksort Memory: 26kB + -> CTE Scan on std so (cost=0.00..302.76 rows=15138 width=40) (actual time=0.001..0.002 rows=15 loops=1) + -> Materialize (cost=488161492.03..489813607.52 rows=330423099 width=1268) (actual time=64619.055..66543.724 rows=812398 loops=1) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=54351 written=90873 + I/O Timings: read=5431.112 + -> Sort (cost=488161492.03..488987549.77 rows=330423099 width=1268) (actual time=64619.051..65222.574 rows=812398 loops=1) + Sort Key: un.oseas + Sort Method: external merge Disk: 434808kB + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1, temp read=54351 written=54352 + I/O Timings: read=5431.112 + -> Hash Left Join (cost=30326.40..75489285.22 rows=330423099 width=1268) (actual time=26974.130..61679.511 rows=812398 loops=1) + Hash Cond: ((un.part = cr.y0part) AND (un.plnt = cr.y0plnt)) + Buffers: shared hit=35372 read=157188, local hit=5659517 read=1 + I/O Timings: read=5431.112 + -> Hash Left Join (cost=22414.65..56426266.97 rows=330423099 width=1262) (actual time=26803.460..61130.886 rows=812398 loops=1) + Hash Cond: ((un.part = cp.chpart) AND (un.plnt = cp.chplnt)) + Buffers: shared hit=35372 read=151936, local hit=5659517 read=1 + I/O Timings: read=5307.518 + -> Hash Left Join (cost=14299.03..36533966.06 rows=330423099 width=1256) (actual time=26596.173..60544.080 rows=812398 loops=1) + Hash Cond: ((un.part = cm.cgpart) AND (un.plnt = cm.cgplnt)) + Buffers: shared hit=35372 read=146620, local hit=5659517 read=1 + I/O Timings: read=5163.164 + -> Hash Left Join (cost=7433.88..34026391.85 rows=330423099 width=1250) (actual time=26466.230..59938.193 rows=812398 loops=1) + Hash Cond: (un.bill_cust = sc.bvcust) + Buffers: shared hit=35372 read=142113, local hit=5659517 read=1 + I/O Timings: read=5079.788 + -> Hash Left Join (cost=3723.16..29479363.52 rows=330423099 width=1223) (actual time=26455.847..59596.315 rows=812398 loops=1) + Hash Cond: (un.bill_cust = bc.bvcust) + Buffers: shared hit=32148 read=142113, local hit=5659517 read=1 + I/O Timings: read=5079.788 + -> Hash Left Join (cost=12.44..24932335.18 rows=330423099 width=1196) (actual time=26376.451..59161.607 rows=812398 loops=1) + Hash Cond: ((un.ming = mmgp.brmgrp) AND (un.majg = mmgp.brgrp)) + Buffers: shared hit=32148 read=138889, local hit=5659517 read=1 + I/O Timings: read=5012.664 + -> Hash Left Join (cost=7.51..15006668.18 rows=330423099 width=1186) (actual time=26375.626..58843.583 rows=812398 loops=1) + Hash Cond: (un.majg = majg.bqgrp) + Buffers: shared hit=32148 read=138888, local hit=5659517 read=1 + I/O Timings: read=5011.904 + -> Hash Left Join (cost=6.24..13569326.43 rows=330423099 width=1176) (actual time=26375.306..58564.379 rows=812398 loops=1) + Hash Cond: (un.majs = sj.bsmjcd) + Buffers: shared hit=32148 read=138887, local hit=5659517 read=1 + I/O Timings: read=5011.601 + -> Hash Left Join (cost=6.21..12313718.62 rows=330423099 width=1144) (actual time=26375.285..58278.120 rows=812398 loops=1) + Hash Cond: ((un.majs = si.bsmjcd) AND (un.mins = si.bsmncd)) + Buffers: shared hit=32147 read=138887, local hit=5659517 read=1 + I/O Timings: read=5011.601 + -> Hash Left Join (cost=3.90..9830091.09 rows=330423099 width=1112) (actual time=26374.932..57946.951 rows=812398 loops=1) + Hash Cond: (un.quota_rep = repc.rcode) + Buffers: shared hit=32147 read=138886, local hit=5659517 read=1 + I/O Timings: read=5011.303 + -> CTE Scan on un (cost=0.00..6608461.98 rows=330423099 width=1048) (actual time=26363.408..57457.121 rows=812398 loops=1) + Buffers: shared hit=32147 read=138860, local hit=5659517 read=1 + I/O Timings: read=5000.713 + -> Hash (cost=2.40..2.40 rows=120 width=96) (actual time=11.512..11.512 rows=120 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 17kB + Buffers: shared read=26 + I/O Timings: read=10.590 + -> CTE Scan on repc (cost=0.00..2.40 rows=120 width=96) (actual time=4.008..11.473 rows=120 loops=1) + Buffers: shared read=26 + I/O Timings: read=10.590 + -> Hash (cost=1.32..1.32 rows=66 width=96) (actual time=0.343..0.343 rows=56 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 11kB + Buffers: shared read=1 + I/O Timings: read=0.297 + -> CTE Scan on si (cost=0.00..1.32 rows=66 width=96) (actual time=0.310..0.330 rows=56 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.297 + -> Hash (cost=0.02..0.02 rows=1 width=64) (actual time=0.014..0.014 rows=11 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=1 + -> CTE Scan on sj (cost=0.00..0.02 rows=1 width=64) (actual time=0.006..0.012 rows=11 loops=1) + Buffers: shared hit=1 + -> Hash (cost=1.12..1.12 rows=12 width=14) (actual time=0.316..0.316 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared read=1 + I/O Timings: read=0.303 + -> Seq Scan on majg (cost=0.00..1.12 rows=12 width=14) (actual time=0.309..0.310 rows=12 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.303 + -> Hash (cost=2.57..2.57 rows=157 width=18) (actual time=0.818..0.818 rows=157 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 16kB + Buffers: shared read=1 + I/O Timings: read=0.760 + -> Seq Scan on mmgp (cost=0.00..2.57 rows=157 width=18) (actual time=0.771..0.787 rows=157 loops=1) + Buffers: shared read=1 + I/O Timings: read=0.760 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=79.377..79.377 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared read=3224 + I/O Timings: read=67.124 + -> Seq Scan on cust bc (cost=0.00..3440.32 rows=21632 width=35) (actual time=1.226..74.190 rows=21632 loops=1) + Buffers: shared read=3224 + I/O Timings: read=67.124 + -> Hash (cost=3440.32..3440.32 rows=21632 width=35) (actual time=10.361..10.361 rows=21632 loops=1) + Buckets: 32768 Batches: 1 Memory Usage: 1721kB + Buffers: shared hit=3224 + -> Seq Scan on cust sc (cost=0.00..3440.32 rows=21632 width=35) (actual time=0.007..6.549 rows=21632 loops=1) + Buffers: shared hit=3224 + -> Hash (cost=5450.26..5450.26 rows=94326 width=29) (actual time=129.891..129.891 rows=94326 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6699kB + Buffers: shared read=4507 + I/O Timings: read=83.376 + -> Seq Scan on icstm cm (cost=0.00..5450.26 rows=94326 width=29) (actual time=1.628..106.590 rows=94326 loops=1) + Buffers: shared read=4507 + I/O Timings: read=83.376 + -> Hash (cost=6435.85..6435.85 rows=111985 width=20) (actual time=207.238..207.238 rows=111985 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 6768kB + Buffers: shared read=5316 + I/O Timings: read=144.354 + -> Seq Scan on icstp cp (cost=0.00..6435.85 rows=111985 width=20) (actual time=12.877..174.296 rows=111985 loops=1) + Buffers: shared read=5316 + I/O Timings: read=144.354 + -> Hash (cost=6315.90..6315.90 rows=106390 width=27) (actual time=167.190..167.190 rows=106390 loops=1) + Buckets: 131072 Batches: 1 Memory Usage: 7334kB + Buffers: shared read=5252 + I/O Timings: read=123.594 + -> Seq Scan on icstr cr (cost=0.00..6315.90 rows=106390 width=27) (actual time=1.618..138.920 rows=106390 loops=1) + Buffers: shared read=5252 + I/O Timings: read=123.594 + -> CTE Scan on agg a (cost=0.00..37859720740.70 rows=1892986037035 width=1520) (actual time=112425.683..119325.832 rows=809656 loops=1) + Buffers: shared hit=35380 read=157188, local hit=5659519 read=1, temp read=169586 written=302217 + I/O Timings: read=5431.112 + -> CTE Scan on agg a_1 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=10.640..1070.930 rows=298533 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Forecast}'::text[]))) + Rows Removed by Filter: 511123 + Buffers: temp read=57858 written=1 + -> CTE Scan on agg a_2 (cost=0.00..43089094668.02 rows=14197395278 width=1520) (actual time=24.901..1109.287 rows=270191 loops=1) + Filter: ((ocytd OR scytd) AND (version = ANY ('{Actual,Budget}'::text[]))) + Rows Removed by Filter: 539465 + Buffers: temp read=57858 + +
++ + +3 +16s584ms +16s584ms +16s584ms +1 + + +16s584ms ++ +DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS int) + FROM ( + SELECT + DISTINCT "diinv#" + FROM + import.osmi + WHERE + "ddord#" = ?) n + WHERE + n. "diinv#" = osm. "diinv#"); + ++ +++Times Reported Time consuming queries #3
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 15 00 1 16s584ms 16s584ms ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 16s584ms - Times executed: 1 ] +
+ +++ + + + +-
+
+
[ Application: psql - Total duration: 16s584ms - Times executed: 1 ] +
+ +++ +-
+
+
-
+ DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS INT) + FROM ( + SELECT + DISTINCT "diinv#" + FROM + import.osmi + WHERE + "ddord#" = 0) n + WHERE + n. "diinv#" = osm. "diinv#"); + ++
+
Date: 2019-03-15 00:49:30 +Duration: 16s584ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Delete on osm (cost=2579.44..36736.43 rows=16 width=36) (actual time=16584.934..16584.934 rows=0 loops=1) + Buffers: shared hit=1558922 read=6078 dirtied=71 + I/O Timings: read=735.005 + -> Nested Loop (cost=2579.44..36736.43 rows=16 width=36) (actual time=99.141..16583.640 rows=159 loops=1) + Buffers: shared hit=1558763 read=6078 dirtied=66 + I/O Timings: read=735.005 + -> Subquery Scan on n (cost=2579.01..2579.03 rows=1 width=36) (actual time=5.671..7.407 rows=223 loops=1) + Buffers: shared hit=2579 + -> Unique (cost=2579.01..2579.02 rows=1 width=6) (actual time=5.664..6.608 rows=223 loops=1) + Buffers: shared hit=2579 + -> Sort (cost=2579.01..2579.02 rows=1 width=6) (actual time=5.662..5.909 rows=252 loops=1) + Sort Key: osmi."diinv#" + Sort Method: quicksort Memory: 36kB + Buffers: shared hit=2579 + -> Seq Scan on osmi (cost=0.00..2579.00 rows=1 width=6) (actual time=0.047..5.580 rows=252 loops=1) + Filter: ("ddord#" = '0'::numeric) + Rows Removed by Filter: 25396 + Buffers: shared hit=2579 + -> Index Scan using osm_pk on osm (cost=0.42..34157.24 rows=16 width=12) (actual time=24.619..74.328 rows=1 loops=223) + Index Cond: ("diinv#" = n."diinv#") + Buffers: shared hit=1556184 read=6078 dirtied=66 + I/O Timings: read=735.005 + +
++ + +4 +2s718ms +25s847ms +10s409ms +9 + + +1m33s ++ +--create INDEX flag ON gld(plan, rolling); WITH un AS ( SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osmp osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.glec,?,?) <= ? AND substr(osm.fs_line,?,?) = ? AND calc_status <> ? --open orders AND sd.cm = ? --this works FOR forecast it indicates a future fspr GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) UNION ALL SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osm osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON greatest(osm.adj_requestdate,current_date) BETWEEN sd.sdat AND sd.edat WHERE substr(osm.fs_line,?,?) = ? AND substr(osm.glec,?,?) <= ? AND calc_status IN (...) AND flag = ? GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ) SELECT srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ,sum(qty) units ,sum(stdcost) "cost" ,sum(sales) sales FROM un WHERE om <> ? GROUP BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ORDER BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ; ++ +++Times Reported Time consuming queries #4
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 17 5 50s600ms 10s120ms Mar 15 00 3 17s236ms 5s745ms + +17 1 25s847ms 25s847ms ++ + + +-
+
+
[ User: report - Total duration: 1m18s - Times executed: 5 ] +
+ +++ + + + +-
+
+
[ Application: [unknown] - Total duration: 1m18s - Times executed: 5 ] +
+ +++ +-
+
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
Date: 2019-03-15 17:30:45 +Duration: 25s847ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=113023.45..113023.95 rows=200 width=232) (actual time=25846.751..25846.759 rows=129 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=20260 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + CTE un + -> Append (cost=46404.12..112987.32 rows=496 width=232) (actual time=25114.996..25846.141 rows=151 loops=1) + Buffers: shared hit=20257 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + -> GroupAggregate (cost=46404.12..46410.90 rows=129 width=232) (actual time=25114.995..25208.334 rows=81 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=20125 read=37204 written=3367, local hit=211099 read=1 + I/O Timings: read=23025.573 write=75.759 + -> Sort (cost=46404.12..46404.45 rows=129 width=182) (actual time=25114.970..25120.224 rows=105549 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 17915kB + Buffers: shared hit=20125 read=37204 written=3367, local hit=211099 read=1 + I/O Timings: read=23025.573 write=75.759 + -> Nested Loop (cost=1445.79..46399.60 rows=129 width=182) (actual time=37.452..24985.218 rows=105549 loops=1) + Buffers: shared hit=20125 read=37204 written=3367, local hit=211099 read=1 + I/O Timings: read=23025.573 write=75.759 + -> Nested Loop (cost=1445.65..46391.77 rows=7 width=110) (actual time=37.425..24330.405 rows=105573 loops=1) + Buffers: shared hit=20125 read=37204 written=3367, local hit=2 + I/O Timings: read=23025.565 write=75.759 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.021..0.037 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Bitmap Heap Scan on osmp osm (cost=1445.65..46387.13 rows=46 width=39) (actual time=1.955..638.928 rows=2778 loops=38) + Recheck Cond: (fspr = sd.fspr) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 70 + Heap Blocks: exact=56851 + Buffers: shared hit=20125 read=37204 written=3367 + I/O Timings: read=23025.565 write=75.759 + -> Bitmap Index Scan on osmp_fspr (cost=0.00..1445.64 rows=27895 width=0) (actual time=1.650..1.650 rows=2848 loops=38) + Index Cond: (fspr = sd.fspr) + Buffers: shared hit=108 read=370 written=62 + I/O Timings: read=51.006 write=0.514 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=105573) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=211097 read=1 + I/O Timings: read=0.008 + -> GroupAggregate (cost=66549.72..66568.99 rows=367 width=232) (actual time=630.211..637.789 rows=70 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=132 read=57866, local hit=10350 + I/O Timings: read=298.856 + -> Sort (cost=66549.72..66550.64 rows=367 width=178) (actual time=630.192..630.748 rows=5174 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 920kB + Buffers: shared hit=132 read=57866, local hit=10350 + I/O Timings: read=298.856 + -> Nested Loop (cost=1004.74..66534.08 rows=367 width=178) (actual time=593.533..627.538 rows=5174 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 895102 + Buffers: shared hit=132 read=57866, local hit=10350 + I/O Timings: read=298.856 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.013..0.081 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..66472.54 rows=19 width=106) (actual time=0.030..3.144 rows=5174 loops=174) + Buffers: shared hit=132 read=57866, local hit=10348 + I/O Timings: read=298.856 + -> Nested Loop Left Join (cost=1004.74..66472.44 rows=19 width=106) (actual time=5.277..509.890 rows=5174 loops=1) + Buffers: shared hit=132 read=57866, local hit=10348 + I/O Timings: read=298.856 + -> Gather (cost=1000.00..66465.04 rows=1 width=34) (actual time=5.247..458.234 rows=5174 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=132 read=57866 + I/O Timings: read=298.856 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..65464.94 rows=1 width=34) (actual time=1.669..482.765 rows=1725 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259938 + Buffers: shared hit=132 read=57866 + I/O Timings: read=298.856 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.009..0.009 rows=1 loops=5174) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5174 + Buffers: local hit=10348 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.007..0.007 rows=1 loops=5174) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5174 + -> HashAggregate (cost=25.98..28.48 rows=200 width=232) (actual time=25846.428..25846.522 rows=129 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=20257 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + -> CTE Scan on un (cost=0.00..11.16 rows=494 width=232) (actual time=25115.000..25846.302 rows=129 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=20257 read=95070 written=3367, local hit=221449 read=1 + I/O Timings: read=23324.429 write=75.759 + +
+Date: 2019-03-14 17:09:40 +Duration: 23s808ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=113712.54..113713.04 rows=200 width=232) (actual time=23807.981..23807.985 rows=128 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=24173 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + CTE un + -> Append (cost=46404.12..113676.42 rows=496 width=232) (actual time=20688.511..23807.529 rows=150 loops=1) + Buffers: shared hit=24170 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + -> GroupAggregate (cost=46404.12..46410.90 rows=129 width=232) (actual time=20688.510..20789.478 rows=81 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=21002 read=36327, local hit=211099 read=1 + I/O Timings: read=18300.701 + -> Sort (cost=46404.12..46404.45 rows=129 width=182) (actual time=20688.486..20694.576 rows=105549 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 17915kB + Buffers: shared hit=21002 read=36327, local hit=211099 read=1 + I/O Timings: read=18300.701 + -> Nested Loop (cost=1445.79..46399.60 rows=129 width=182) (actual time=37.496..20515.988 rows=105549 loops=1) + Buffers: shared hit=21002 read=36327, local hit=211099 read=1 + I/O Timings: read=18300.701 + -> Nested Loop (cost=1445.65..46391.77 rows=7 width=110) (actual time=37.467..19809.839 rows=105573 loops=1) + Buffers: shared hit=21002 read=36327, local hit=2 + I/O Timings: read=18300.692 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.020..0.038 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Bitmap Heap Scan on osmp osm (cost=1445.65..46387.13 rows=46 width=39) (actual time=2.140..520.028 rows=2778 loops=38) + Recheck Cond: (fspr = sd.fspr) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 70 + Heap Blocks: exact=56851 + Buffers: shared hit=21002 read=36327 + I/O Timings: read=18300.692 + -> Bitmap Index Scan on osmp_fspr (cost=0.00..1445.64 rows=27895 width=0) (actual time=1.908..1.908 rows=2848 loops=38) + Index Cond: (fspr = sd.fspr) + Buffers: shared hit=110 read=368 + I/O Timings: read=57.208 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=105573) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=211097 read=1 + I/O Timings: read=0.009 + -> GroupAggregate (cost=67238.81..67258.08 rows=367 width=232) (actual time=3013.320..3018.033 rows=69 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=3168 read=54830, local hit=10926 + I/O Timings: read=7983.465 + -> Sort (cost=67238.81..67239.73 rows=367 width=178) (actual time=3013.300..3013.513 rows=5462 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 961kB + Buffers: shared hit=3168 read=54830, local hit=10926 + I/O Timings: read=7983.465 + -> Nested Loop (cost=1004.74..67223.18 rows=367 width=178) (actual time=2972.945..3010.611 rows=5462 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 944926 + Buffers: shared hit=3168 read=54830, local hit=10926 + I/O Timings: read=7983.465 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.017..0.072 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..67161.63 rows=19 width=106) (actual time=13.102..16.813 rows=5462 loops=174) + Buffers: shared hit=3168 read=54830, local hit=10924 + I/O Timings: read=7983.465 + -> Nested Loop Left Join (cost=1004.74..67161.54 rows=19 width=106) (actual time=2279.747..2880.350 rows=5462 loops=1) + Buffers: shared hit=3168 read=54830, local hit=10924 + I/O Timings: read=7983.465 + -> Gather (cost=1000.00..67154.13 rows=1 width=34) (actual time=2279.720..2819.147 rows=5462 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=3168 read=54830 + I/O Timings: read=7983.465 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..66154.03 rows=1 width=34) (actual time=2269.482..2837.169 rows=1821 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259313 + Buffers: shared hit=3168 read=54830 + I/O Timings: read=7983.465 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.008..0.008 rows=1 loops=5462) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5462 + Buffers: local hit=10924 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.007..0.007 rows=1 loops=5462) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5462 + -> HashAggregate (cost=25.98..28.48 rows=200 width=232) (actual time=23807.814..23807.857 rows=128 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=24170 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + -> CTE Scan on un (cost=0.00..11.16 rows=494 width=232) (actual time=20688.515..23807.691 rows=128 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=24170 read=91157, local hit=222025 read=1 + I/O Timings: read=26284.166 + +
+Date: 2019-03-14 17:21:12 +Duration: 18s342ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=113712.54..113713.04 rows=200 width=232) (actual time=18341.790..18341.795 rows=128 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=24593 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + CTE un + -> Append (cost=46404.12..113676.42 rows=496 width=232) (actual time=17686.530..18341.413 rows=150 loops=1) + Buffers: shared hit=24590 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + -> GroupAggregate (cost=46404.12..46410.90 rows=129 width=232) (actual time=17686.530..17780.512 rows=81 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=20982 read=36347, local hit=211099 read=1 + I/O Timings: read=16170.335 + -> Sort (cost=46404.12..46404.45 rows=129 width=182) (actual time=17686.507..17691.642 rows=105549 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 17915kB + Buffers: shared hit=20982 read=36347, local hit=211099 read=1 + I/O Timings: read=16170.335 + -> Nested Loop (cost=1445.79..46399.60 rows=129 width=182) (actual time=336.691..17577.973 rows=105549 loops=1) + Buffers: shared hit=20982 read=36347, local hit=211099 read=1 + I/O Timings: read=16170.335 + -> Nested Loop (cost=1445.65..46391.77 rows=7 width=110) (actual time=336.406..17026.558 rows=105573 loops=1) + Buffers: shared hit=20982 read=36347, local hit=2 + I/O Timings: read=16170.091 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.019..0.035 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Bitmap Heap Scan on osmp osm (cost=1445.65..46387.13 rows=46 width=39) (actual time=9.729..447.136 rows=2778 loops=38) + Recheck Cond: (fspr = sd.fspr) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 70 + Heap Blocks: exact=56851 + Buffers: shared hit=20982 read=36347 + I/O Timings: read=16170.091 + -> Bitmap Index Scan on osmp_fspr (cost=0.00..1445.64 rows=27895 width=0) (actual time=6.416..6.416 rows=2848 loops=38) + Index Cond: (fspr = sd.fspr) + Buffers: shared hit=110 read=368 + I/O Timings: read=223.920 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=105573) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=211097 read=1 + I/O Timings: read=0.244 + -> GroupAggregate (cost=67238.81..67258.08 rows=367 width=232) (actual time=556.403..560.886 rows=69 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=3608 read=54390, local hit=10926 + I/O Timings: read=210.804 + -> Sort (cost=67238.81..67239.73 rows=367 width=178) (actual time=556.386..556.605 rows=5462 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 961kB + Buffers: shared hit=3608 read=54390, local hit=10926 + I/O Timings: read=210.804 + -> Nested Loop (cost=1004.74..67223.18 rows=367 width=178) (actual time=518.705..553.668 rows=5462 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 944926 + Buffers: shared hit=3608 read=54390, local hit=10926 + I/O Timings: read=210.804 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.013..0.055 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..67161.63 rows=19 width=106) (actual time=2.013..2.722 rows=5462 loops=174) + Buffers: shared hit=3608 read=54390, local hit=10924 + I/O Timings: read=210.804 + -> Nested Loop Left Join (cost=1004.74..67161.54 rows=19 width=106) (actual time=350.244..437.677 rows=5462 loops=1) + Buffers: shared hit=3608 read=54390, local hit=10924 + I/O Timings: read=210.804 + -> Gather (cost=1000.00..67154.13 rows=1 width=34) (actual time=350.219..407.718 rows=5462 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=3608 read=54390 + I/O Timings: read=210.804 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..66154.03 rows=1 width=34) (actual time=333.708..384.567 rows=1821 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259313 + Buffers: shared hit=3608 read=54390 + I/O Timings: read=210.804 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=5462) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5462 + Buffers: local hit=10924 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.004..0.004 rows=1 loops=5462) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5462 + -> HashAggregate (cost=25.98..28.48 rows=200 width=232) (actual time=18341.605..18341.654 rows=128 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=24590 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + -> CTE Scan on un (cost=0.00..11.16 rows=494 width=232) (actual time=17686.534..18341.509 rows=128 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=24590 read=90737, local hit=222025 read=1 + I/O Timings: read=16381.140 + +
++ + +5 +2s217ms +27s560ms +8s855ms +37 + + +5m27s ++ +--create INDEX flag ON gld(plan, rolling); WITH un AS ( SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osmf osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.glec,?,?) <= ? AND substr(osm.fs_line,?,?) = ? AND calc_status <> ? AND ( --all orders OR shipments FOR the period ( --current year TO date orders od.cy = ? --current year TO date shipments OR sd.cy = ? ) OR --open orders sd.cm = ? --this works FOR forecast it indicates a future fspr ) GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) UNION ALL SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osm osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.fs_line,?,?) = ? AND substr(osm.glec,?,?) <= ? AND calc_status <> ? AND ( --all ORDER OR shipments FOR the period ( --current year TO date orders od.cy = ? --current year TO date shipments OR sd.cy = ? ) OR --open orders (calc_status IN (...) AND flag = ?) ) GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ) SELECT srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ,sum(qty) units ,sum(stdcost) "cost" ,sum(sales) sales FROM un GROUP BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ORDER BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ; ++ +++Times Reported Time consuming queries #5
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 17 17 2m29s 8s786ms Mar 15 00 5 58s394ms 11s678ms 17 5 1m2s 12s403ms + +Mar 18 10 10 57s886ms 5s788ms ++ + + +-
+
+
[ User: report - Total duration: 1m37s - Times executed: 7 ] +
+ +++ + + + +-
+
+
[ Application: [unknown] - Total duration: 1m37s - Times executed: 7 ] +
+ +++ +-
+
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
Date: 2019-03-14 17:15:07 +Duration: 27s560ms +
+ +++ + +Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.033..24368.549 rows=190996 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 227 + Buffers: shared hit=12201 + +
+Date: 2019-03-14 17:15:07 +Duration: 27s559ms +
+ +++ + +Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.018..23110.458 rows=167047 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 120 + Buffers: shared hit=10779 + +
+Date: 2019-03-15 17:30:39 +Duration: 21s242ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=99922.38..99922.88 rows=200 width=232) (actual time=21211.683..21211.708 rows=317 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 69kB + Buffers: shared hit=4 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + CTE un + -> Append (cost=32534.94..99887.14 rows=502 width=232) (actual time=5942.671..21209.531 rows=317 loops=1) + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + -> GroupAggregate (cost=32534.94..32547.80 rows=245 width=232) (actual time=5942.670..6367.056 rows=197 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Sort (cost=32534.94..32535.55 rows=245 width=185) (actual time=5942.642..5990.837 rows=406814 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 69497kB + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Nested Loop (cost=1006.06..32525.21 rows=245 width=185) (actual time=3.834..5526.120 rows=406814 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Buffers: shared read=26345 written=122, local hit=813629 read=1 + I/O Timings: read=10489.172 write=1.431 + -> Hash Left Join (cost=1005.91..31588.56 rows=738 width=113) (actual time=3.809..3558.965 rows=406814 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared read=26345 written=122, local hit=2 + I/O Timings: read=10489.166 write=1.431 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=3.660..3400.209 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared read=26345 written=122 + I/O Timings: read=10489.166 write=1.431 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=0.781..3631.234 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared read=26345 written=122 + I/O Timings: read=10489.166 write=1.431 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.083..0.083 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.013..0.049 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.004..0.004 rows=1 loops=406814) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=813627 read=1 + I/O Timings: read=0.006 + -> GroupAggregate (cost=67318.31..67331.81 rows=257 width=232) (actual time=14757.926..14842.413 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Sort (cost=67318.31..67318.96 rows=257 width=178) (actual time=14757.905..14766.226 rows=94732 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16394kB + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Nested Loop (cost=1006.06..67308.03 rows=257 width=178) (actual time=65.185..14658.975 rows=94732 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=1 read=57991 written=2, local hit=1255198 + I/O Timings: read=37441.627 write=0.074 + -> Hash Left Join (cost=1005.91..65849.40 rows=1114 width=122) (actual time=65.171..12232.663 rows=628518 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=1 read=57991 written=2, local hit=2 + I/O Timings: read=37441.627 write=0.074 + -> Gather (cost=1000.00..65829.04 rows=1114 width=51) (actual time=65.104..11994.997 rows=628518 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=1 read=57991 written=2 + I/O Timings: read=37441.627 write=0.074 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..64717.64 rows=464 width=51) (actual time=56.186..12707.976 rows=209506 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52157 + Buffers: shared hit=1 read=57991 written=2 + I/O Timings: read=37441.627 write=0.074 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.055..0.055 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.009..0.031 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=628518) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1255196 + -> HashAggregate (cost=25.10..27.60 rows=200 width=232) (actual time=21210.361..21210.698 rows=317 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + -> CTE Scan on un (cost=0.00..10.04 rows=502 width=232) (actual time=5942.675..21209.793 rows=317 loops=1) + Buffers: shared hit=1 read=84336 written=124, local hit=2068827 read=1 + I/O Timings: read=47930.799 write=1.505 + +
++ + +6 +3s112ms +8s419ms +4s496ms +10 + + +44s960ms ++ +--create INDEX flag ON gld(plan, rolling); WITH un AS ( SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osmp osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.glec,?,?) <= ? AND substr(osm.fs_line,?,?) = ? AND calc_status <> ? AND ( --all orders OR shipments FOR the period ( --current year TO date orders od.cy = ? --current year TO date shipments OR sd.cy = ? ) OR --open orders sd.cm = ? --this works FOR forecast it indicates a future fspr ) GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) UNION ALL SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osm osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.fs_line,?,?) = ? AND substr(osm.glec,?,?) <= ? AND calc_status <> ? AND ( --all ORDER OR shipments FOR the period ( --current year TO date orders od.cy = ? --current year TO date shipments OR sd.cy = ? ) OR --open orders (calc_status IN (...) AND flag = ?) ) GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ) SELECT srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ,sum(qty) units ,sum(stdcost) "cost" ,sum(sales) sales FROM un GROUP BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ORDER BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ; ++ +++Times Reported Time consuming queries #6
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 18 09 10 44s960ms 4s496ms ++ + + +-
+
+
[ User: report - Total duration: 16s549ms - Times executed: 2 ] +
+ +++ + + + +-
+
+
[ Application: [unknown] - Total duration: 16s549ms - Times executed: 2 ] +
+ +++ +-
+
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDERS OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND ( --ALL ORDER OR SHIPMENTS FOR THE PERIOD + ( --CURRENT YEAR TO date ORDERS + OD.CY = 'C' --CURRENT YEAR TO date SHIPMENTS + OR SD.CY = 'C') + OR --OPEN ORDERS + (CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER')) +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
Date: 2019-03-18 09:26:51 +Duration: 8s419ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=126971.98..126972.48 rows=200 width=232) (actual time=8418.853..8418.865 rows=323 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 70kB + Buffers: shared hit=5 read=108400, local hit=2604991 read=1 + I/O Timings: read=3855.140 + CTE un + -> Append (cost=59568.08..126929.73 rows=642 width=232) (actual time=4498.390..8417.556 rows=323 loops=1) + Buffers: shared hit=2 read=108400, local hit=2604991 read=1 + I/O Timings: read=3855.140 + -> GroupAggregate (cost=59568.08..59588.30 rows=385 width=232) (actual time=4498.389..5166.228 rows=203 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=1 read=50409, local hit=1349793 read=1 + I/O Timings: read=2445.383 + -> Sort (cost=59568.08..59569.05 rows=385 width=182) (actual time=4498.367..4585.150 rows=640948 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 114710kB + Buffers: shared hit=1 read=50409, local hit=1349793 read=1 + I/O Timings: read=2445.383 + -> Nested Loop (cost=1006.06..59551.55 rows=385 width=182) (actual time=1.902..3949.029 rows=640948 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Rows Removed by Join Filter: 33948 + Buffers: shared hit=1 read=50409, local hit=1349793 read=1 + I/O Timings: read=2445.383 + -> Hash Left Join (cost=1005.91..58085.96 rows=1162 width=110) (actual time=1.882..1591.245 rows=674964 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=1 read=50409, local hit=2 + I/O Timings: read=2445.379 + -> Gather (cost=1000.00..58064.06 rows=1162 width=39) (actual time=1.801..1402.607 rows=674964 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=1 read=50409 + I/O Timings: read=2445.379 + -> Parallel Seq Scan on osmp osm (cost=0.00..56947.86 rows=484 width=39) (actual time=6.288..971.309 rows=224988 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 7699 + Buffers: shared hit=1 read=50409 + I/O Timings: read=2445.379 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.066..0.066 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.009..0.036 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=674964) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1349791 read=1 + I/O Timings: read=0.005 + -> GroupAggregate (cost=67318.31..67331.81 rows=257 width=232) (actual time=3164.534..3251.283 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=1 read=57991, local hit=1255198 + I/O Timings: read=1409.756 + -> Sort (cost=67318.31..67318.96 rows=257 width=178) (actual time=3164.500..3172.177 rows=94732 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16394kB + Buffers: shared hit=1 read=57991, local hit=1255198 + I/O Timings: read=1409.756 + -> Nested Loop (cost=1006.06..67308.03 rows=257 width=178) (actual time=8.854..3088.890 rows=94732 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=1 read=57991, local hit=1255198 + I/O Timings: read=1409.756 + -> Hash Left Join (cost=1005.91..65849.40 rows=1114 width=122) (actual time=8.837..1127.273 rows=628518 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=1 read=57991, local hit=2 + I/O Timings: read=1409.756 + -> Gather (cost=1000.00..65829.04 rows=1114 width=51) (actual time=8.721..913.379 rows=628518 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=1 read=57991 + I/O Timings: read=1409.756 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..64717.64 rows=464 width=51) (actual time=5.247..636.800 rows=209506 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52157 + Buffers: shared hit=1 read=57991 + I/O Timings: read=1409.756 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.068..0.068 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.018..0.042 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=628518) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1255196 + -> HashAggregate (cost=32.10..34.60 rows=200 width=232) (actual time=8418.331..8418.469 rows=323 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=2 read=108400, local hit=2604991 read=1 + I/O Timings: read=3855.140 + -> CTE Scan on un (cost=0.00..12.84 rows=642 width=232) (actual time=4498.393..8417.842 rows=323 loops=1) + Buffers: shared hit=2 read=108400, local hit=2604991 read=1 + I/O Timings: read=3855.140 + +
+Date: 2019-03-18 09:27:40 +Duration: 8s130ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=126971.98..126972.48 rows=200 width=232) (actual time=8129.861..8129.875 rows=323 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 70kB + Buffers: shared hit=239 read=108163, local hit=2604991 read=1 + I/O Timings: read=247.658 + CTE un + -> Append (cost=59568.08..126929.73 rows=642 width=232) (actual time=4183.799..8128.440 rows=323 loops=1) + Buffers: shared hit=239 read=108163, local hit=2604991 read=1 + I/O Timings: read=247.658 + -> GroupAggregate (cost=59568.08..59588.30 rows=385 width=232) (actual time=4183.798..4870.543 rows=203 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared hit=113 read=50297, local hit=1349793 read=1 + I/O Timings: read=119.690 + -> Sort (cost=59568.08..59569.05 rows=385 width=182) (actual time=4183.776..4278.632 rows=640948 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 114710kB + Buffers: shared hit=113 read=50297, local hit=1349793 read=1 + I/O Timings: read=119.690 + -> Nested Loop (cost=1006.06..59551.55 rows=385 width=182) (actual time=1.055..3609.932 rows=640948 loops=1) + Join Filter: ((od.cy = 'C'::text) OR (sd.cy = 'C'::text) OR (sd.cm = 'F'::text)) + Rows Removed by Join Filter: 33948 + Buffers: shared hit=113 read=50297, local hit=1349793 read=1 + I/O Timings: read=119.690 + -> Hash Left Join (cost=1005.91..58085.96 rows=1162 width=110) (actual time=1.036..1145.096 rows=674964 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared hit=113 read=50297, local hit=2 + I/O Timings: read=119.684 + -> Gather (cost=1000.00..58064.06 rows=1162 width=39) (actual time=0.966..952.386 rows=674964 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=113 read=50297 + I/O Timings: read=119.684 + -> Parallel Seq Scan on osmp osm (cost=0.00..56947.86 rows=484 width=39) (actual time=0.027..208.907 rows=224988 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 7699 + Buffers: shared hit=113 read=50297 + I/O Timings: read=119.684 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.062..0.062 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..3.74 rows=174 width=108) (actual time=0.007..0.035 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=674964) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=1349791 read=1 + I/O Timings: read=0.006 + -> GroupAggregate (cost=67318.31..67331.81 rows=257 width=232) (actual time=3170.956..3257.844 rows=120 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=126 read=57866, local hit=1255198 + I/O Timings: read=127.968 + -> Sort (cost=67318.31..67318.96 rows=257 width=178) (actual time=3170.933..3179.265 rows=94732 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 16394kB + Buffers: shared hit=126 read=57866, local hit=1255198 + I/O Timings: read=127.968 + -> Nested Loop (cost=1006.06..67308.03 rows=257 width=178) (actual time=1.140..3098.754 rows=94732 loops=1) + Join Filter: ((od_1.cy = 'C'::text) OR (sd_1.cy = 'C'::text) OR ((osm_1.calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (osm_1.flag = 'REMAINDER'::text))) + Rows Removed by Join Filter: 532866 + Buffers: shared hit=126 read=57866, local hit=1255198 + I/O Timings: read=127.968 + -> Hash Left Join (cost=1005.91..65849.40 rows=1114 width=122) (actual time=1.106..1185.199 rows=628518 loops=1) + Hash Cond: (osm_1.fspr = sd_1.fspr) + Buffers: shared hit=126 read=57866, local hit=2 + I/O Timings: read=127.968 + -> Gather (cost=1000.00..65829.04 rows=1114 width=51) (actual time=1.044..983.106 rows=628518 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=126 read=57866 + I/O Timings: read=127.968 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..64717.64 rows=464 width=51) (actual time=0.044..218.820 rows=209506 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 52157 + Buffers: shared hit=126 read=57866 + I/O Timings: read=127.968 + -> Hash (cost=3.74..3.74 rows=174 width=108) (actual time=0.052..0.052 rows=174 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 18kB + Buffers: local hit=2 + -> Seq Scan on gld sd_1 (cost=0.00..3.74 rows=174 width=108) (actual time=0.006..0.029 rows=174 loops=1) + Buffers: local hit=2 + -> Index Scan using dats on gld od_1 (cost=0.14..0.93 rows=19 width=80) (actual time=0.003..0.003 rows=1 loops=628518) + Index Cond: ((osm_1.adj_orderdate >= sdat) AND (osm_1.adj_orderdate <= edat)) + Buffers: local hit=1255196 + -> HashAggregate (cost=32.10..34.60 rows=200 width=232) (actual time=8129.291..8129.422 rows=323 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=239 read=108163, local hit=2604991 read=1 + I/O Timings: read=247.658 + -> CTE Scan on un (cost=0.00..12.84 rows=642 width=232) (actual time=4183.801..8128.793 rows=323 loops=1) + Buffers: shared hit=239 read=108163, local hit=2604991 read=1 + I/O Timings: read=247.658 + +
+Date: 2019-03-18 09:26:47 +Duration: 4s142ms +
+ +++ + +Parallel Seq Scan on osmp osm (cost=0.00..56947.86 rows=484 width=39) (actual time=9.803..884.885 rows=131112 loops=1) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 5198 + Buffers: shared read=10827 + I/O Timings: read=792.174 + +
++ + +7 +2s707ms +2s707ms +2s707ms +1 + + +2s707ms ++ +CREATE temp TABLE gld AS ( + WITH seg AS ( + SELECT + glec, + segm + FROM ( + VALUES (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?), + (?, + ?)) x (glec, + segm)), + ord_cutoff AS ( + SELECT + min(adj_orderdate) fc_odat + FROM + rlarp.osmp + WHERE + iter <> ? + AND version = ? + AND adj_orderdate >= ?), sales_cutoff AS ( + SELECT + max(fspr) max_fspr + FROM + rlarp.osm), + gld AS ( + SELECT + n1comp comp, + n1ccyy fsyr, + kpmaxp perds, + n1fspp perd, + to_char(n1fsyp, ?) fspr, + n1sd01 sdat, + n1ed01 edat, + to_char(n1ed01, ?) capr, + n1ed01 - n1sd01 + ? ndays, + CASE WHEN extract(month FROM n1ed01) >= ? THEN + extract(year FROM n1ed01) + ? + ELSE + extract(year FROM n1ed01) + END ssyr, + to_char( + CASE WHEN extract(month FROM n1ed01) >= ? THEN + extract(month FROM n1ed01) ? + ELSE + extract(month FROM n1ed01) + ? + END, ?) sspr --if the period date IS less than the FIRST forecasted ORDER it IS actual FROM perspective of the plan ,case WHEN max_fspr = to_char(n1fsyp,?) THEN ? ELSE CASE WHEN sales_cutoff.max_fspr > to_char(n1fsyp,?) THEN ? ELSE ? END END cm ,case WHEN max_fspr = to_char(n1fsyp,?) THEN ? ELSE CASE WHEN sales_cutoff.max_fspr > to_char(n1fsyp,?) THEN CASE WHEN substr(sales_cutoff.max_fspr,?,?) > substr(to_char(n1fsyp,?),?,?) THEN ? ELSE ? END ELSE ? END END cy FROM lgdat.gldatref INNER JOIN lgdat.gldate ON kpcomp = n1comp AND kpccyy = n1ccyy CROSS JOIN ord_cutoff CROSS JOIN sales_cutoff WHERE n1comp = ? --and digits(n1fsyp) = ? ) SELECT * FROM gld ) ; ++ +++Times Reported Time consuming queries #7
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 14 17 1 2s707ms 2s707ms ++ + + +-
+
+
[ User: report - Total duration: 2s707ms - Times executed: 1 ] +
+ +++ + + + +-
+
+
[ Application: [unknown] - Total duration: 2s707ms - Times executed: 1 ] +
+ +++ +-
+
+
-
+ CREATE TEMP TABLE GLD AS ( + WITH SEG AS ( + SELECT + GLEC, + SEGM + FROM ( + VALUES ('1CU', + 'Retail'), + ('1GR', + 'Greenhouse'), + ('1NU', + 'Nursery'), + ('1RE', + 'Retail'), + ('2WI', + 'Greenhouse'), + ('3BM', + 'Other'), + ('3CO', + 'Other'), + ('3PE', + 'Other'), + ('3PP', + 'Other'), + ('4CO', + 'Other'), + ('4RA', + 'Other'), + ('9MI', + 'Other'), + ('9SA', + 'Other'), + ('9TO', + 'Other')) X (GLEC, + SEGM)), + ORD_CUTOFF AS ( + SELECT + min(ADJ_ORDERDATE) FC_ODAT + FROM + RLARP.OSMP + WHERE + ITER <> 'Open Orders' + AND version = 'b19' + AND ADJ_ORDERDATE >= '2018-06-01'), SALES_CUTOFF AS ( + SELECT + max(FSPR) MAX_FSPR + FROM + RLARP.OSM), + GLD AS ( + SELECT + N1COMP COMP, + N1CCYY FSYR, + KPMAXP PERDS, + N1FSPP PERD, + to_char(N1FSYP, 'FM0000') FSPR, + N1SD01 SDAT, + N1ED01 EDAT, + to_char(N1ED01, 'yymm') CAPR, + N1ED01 - N1SD01 + 1 NDAYS, + CASE WHEN extract(MONTH FROM N1ED01) >= 6 THEN + extract(YEAR FROM N1ED01) + 1 + ELSE + extract(YEAR FROM N1ED01) + END SSYR, + to_char( + CASE WHEN extract(MONTH FROM N1ED01) >= 6 THEN + extract(MONTH FROM N1ED01) - 5 + ELSE + extract(MONTH FROM N1ED01) + 7 + END, '00') SSPR --if the period date IS less than the FIRST forecasted ORDER it IS actual FROM perspective of the plan +, + CASE WHEN MAX_FSPR = to_char(N1FSYP, 'FM0000') THEN + 'C' + ELSE + CASE WHEN SALES_CUTOFF.MAX_FSPR > to_char(N1FSYP, 'FM0000') THEN + 'P' + ELSE + 'F' + END + END CM, + CASE WHEN MAX_FSPR = to_char(N1FSYP, 'FM0000') THEN + 'C' + ELSE + CASE WHEN SALES_CUTOFF.MAX_FSPR > to_char(N1FSYP, 'FM0000') THEN + CASE WHEN substr(SALES_CUTOFF.MAX_FSPR, 1, 2) > substr(to_char(N1FSYP, 'FM0000'), 1, 2) THEN + 'P' + ELSE + 'C' + END + ELSE + 'F' + END + END CY + FROM + LGDAT.GLDATREF + INNER JOIN LGDAT.GLDATE ON KPCOMP = N1COMP + AND KPCCYY = N1CCYY + CROSS JOIN ORD_CUTOFF + CROSS JOIN SALES_CUTOFF + WHERE + N1COMP = 93 --AND DIGITS(N1FSYP) = '1901' +) + SELECT + * + FROM + GLD +); + ++
+
Date: 2019-03-14 17:14:38 +Duration: 2s707ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +CTE Scan on gld (cost=90.94..95.22 rows=214 width=228) (actual time=301.996..349.721 rows=174 loops=1) + Buffers: shared hit=78 + CTE ord_cutoff + -> Result (cost=0.81..0.82 rows=1 width=4) (actual time=19.020..19.020 rows=1 loops=1) + Buffers: shared hit=4 + InitPlan 1 (returns $0) + -> Limit (cost=0.42..0.81 rows=1 width=4) (actual time=19.007..19.009 rows=1 loops=1) + Buffers: shared hit=4 + -> Index Scan using osmp_adj_orderdate on osmp (cost=0.42..245805.19 rows=634345 width=4) (actual time=18.973..18.973 rows=1 loops=1) + Index Cond: ((adj_orderdate IS NOT NULL) AND (adj_orderdate >= '2018-06-01'::date)) + Filter: ((iter <> 'Open Orders'::text) AND (version = 'b19'::text)) + Buffers: shared hit=4 + CTE sales_cutoff + -> Result (cost=0.52..0.53 rows=1 width=32) (actual time=13.133..13.134 rows=1 loops=1) + Buffers: shared hit=56 + InitPlan 3 (returns $2) + -> Limit (cost=0.42..0.52 rows=1 width=5) (actual time=13.126..13.128 rows=1 loops=1) + Buffers: shared hit=56 + -> Index Only Scan Backward using osm_fspr on osm (cost=0.42..72296.40 rows=723143 width=5) (actual time=13.125..13.125 rows=1 loops=1) + Index Cond: (fspr IS NOT NULL) + Heap Fetches: 1 + Buffers: shared hit=56 + CTE gld + -> Hash Join (cost=28.27..89.59 rows=214 width=200) (actual time=290.797..305.496 rows=174 loops=1) + Hash Cond: (gldatref.n1ccyy = gldate.kpccyy) + Buffers: shared hit=78 + -> Nested Loop (cost=13.63..55.59 rows=174 width=60) (actual time=154.995..163.518 rows=174 loops=1) + Buffers: shared hit=66 + -> Nested Loop (cost=0.00..0.05 rows=1 width=32) (actual time=32.162..32.165 rows=1 loops=1) + Buffers: shared hit=60 + -> CTE Scan on ord_cutoff (cost=0.00..0.02 rows=1 width=0) (actual time=19.023..19.024 rows=1 loops=1) + Buffers: shared hit=4 + -> CTE Scan on sales_cutoff (cost=0.00..0.02 rows=1 width=32) (actual time=13.135..13.136 rows=1 loops=1) + Buffers: shared hit=56 + -> Bitmap Heap Scan on gldatref (cost=13.63..53.80 rows=174 width=28) (actual time=122.815..131.244 rows=174 loops=1) + Recheck Cond: (n1comp = '93'::numeric) + Heap Blocks: exact=2 + Buffers: shared hit=6 + -> Bitmap Index Scan on pk_gldatref (cost=0.00..13.58 rows=174 width=0) (actual time=116.762..116.762 rows=174 loops=1) + Index Cond: (n1comp = '93'::numeric) + Buffers: shared hit=4 + -> Hash (cost=14.45..14.45 rows=15 width=15) (actual time=57.253..57.253 rows=15 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + Buffers: shared hit=12 + -> Seq Scan on gldate (cost=0.00..14.45 rows=15 width=15) (actual time=13.900..46.977 rows=15 loops=1) + Filter: (kpcomp = '93'::numeric) + Rows Removed by Filter: 181 + Buffers: shared hit=12 + +
++ + +8 +2s10ms +3s265ms +2s476ms +3 + + +7s429ms ++ +DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS int) + FROM ( + SELECT + DISTINCT "ddord#" + FROM + import.osmi + WHERE + "ddord#" <> ?) n + WHERE + n. "ddord#" = osm. "ddord#"); + ++ +++Times Reported Time consuming queries #8
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 17 1 3s265ms 3s265ms Mar 15 14 1 2s153ms 2s153ms + +16 1 2s10ms 2s10ms ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 7s429ms - Times executed: 3 ] +
+ +++ + + + +-
+
+
[ Application: psql - Total duration: 7s429ms - Times executed: 3 ] +
+ +++ +-
+
+
-
+ DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS INT) + FROM ( + SELECT + DISTINCT "ddord#" + FROM + import.osmi + WHERE + "ddord#" <> 0) n + WHERE + n. "ddord#" = osm. "ddord#"); + ++
+
-
+ DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS INT) + FROM ( + SELECT + DISTINCT "ddord#" + FROM + import.osmi + WHERE + "ddord#" <> 0) n + WHERE + n. "ddord#" = osm. "ddord#"); + ++
+
-
+ DELETE FROM rlarp.osm osm +WHERE EXISTS ( + SELECT + cast(NULL AS INT) + FROM ( + SELECT + DISTINCT "ddord#" + FROM + import.osmi + WHERE + "ddord#" <> 0) n + WHERE + n. "ddord#" = osm. "ddord#"); + ++
+
Date: 2019-03-14 17:12:43 +Duration: 3s265ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Delete on osm (cost=1968.07..69852.70 rows=67171 width=36) (actual time=3265.512..3265.512 rows=0 loops=1) + Buffers: shared hit=29163 read=54721 dirtied=1562 + I/O Timings: read=2859.895 + -> Hash Join (cost=1968.07..69852.70 rows=67171 width=36) (actual time=75.167..3248.670 rows=24360 loops=1) + Hash Cond: (osm."ddord#" = n."ddord#") + Buffers: shared hit=4780 read=54721 dirtied=82 + I/O Timings: read=2859.895 + -> Seq Scan on osm (cost=0.00..65827.55 rows=783555 width=12) (actual time=1.473..3059.153 rows=783400 loops=1) + Buffers: shared hit=3271 read=54721 + I/O Timings: read=2859.895 + -> Hash (cost=1930.65..1930.65 rows=2994 width=36) (actual time=18.828..18.828 rows=3245 loops=1) + Buckets: 4096 Batches: 1 Memory Usage: 245kB + Buffers: shared hit=1509 dirtied=82 + -> Subquery Scan on n (cost=1870.77..1930.65 rows=2994 width=36) (actual time=16.917..18.065 rows=3245 loops=1) + Buffers: shared hit=1509 dirtied=82 + -> HashAggregate (cost=1870.77..1900.71 rows=2994 width=6) (actual time=16.897..17.477 rows=3245 loops=1) + Group Key: osmi."ddord#" + Buffers: shared hit=1509 dirtied=82 + -> Seq Scan on osmi (cost=0.00..1810.80 rows=23987 width=6) (actual time=0.026..9.823 rows=25374 loops=1) + Filter: ("ddord#" <> '0'::numeric) + Rows Removed by Filter: 252 + Buffers: shared hit=1509 dirtied=82 + +
+Date: 2019-03-15 14:07:09 +Duration: 2s153ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Delete on osm (cost=1986.94..69871.57 rows=69213 width=36) (actual time=2153.612..2153.612 rows=0 loops=1) + Buffers: shared hit=26955 read=57942 dirtied=1625 + I/O Timings: read=1847.789 + -> Hash Join (cost=1986.94..69871.57 rows=69213 width=36) (actual time=1997.260..2135.913 rows=25383 loops=1) + Hash Cond: (osm."ddord#" = n."ddord#") + Buffers: shared hit=1572 read=57942 + I/O Timings: read=1847.789 + -> Seq Scan on osm (cost=0.00..65827.55 rows=783555 width=12) (actual time=0.460..1982.573 rows=784529 loops=1) + Buffers: shared hit=50 read=57942 + I/O Timings: read=1847.789 + -> Hash (cost=1948.38..1948.38 rows=3085 width=36) (actual time=14.780..14.780 rows=3290 loops=1) + Buckets: 4096 Batches: 1 Memory Usage: 248kB + Buffers: shared hit=1522 + -> Subquery Scan on n (cost=1886.68..1948.38 rows=3085 width=36) (actual time=13.217..14.151 rows=3290 loops=1) + Buffers: shared hit=1522 + -> HashAggregate (cost=1886.68..1917.53 rows=3085 width=6) (actual time=13.202..13.591 rows=3290 loops=1) + Group Key: osmi."ddord#" + Buffers: shared hit=1522 + -> Seq Scan on osmi (cost=0.00..1826.40 rows=24113 width=6) (actual time=0.010..7.688 rows=25613 loops=1) + Filter: ("ddord#" <> '0'::numeric) + Rows Removed by Filter: 265 + Buffers: shared hit=1522 + +
+Date: 2019-03-15 16:45:32 +Duration: 2s10ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Delete on osm (cost=2006.51..69055.94 rows=62283 width=36) (actual time=2010.489..2010.489 rows=0 loops=1) + Buffers: shared hit=28858 read=57960 dirtied=1674 + I/O Timings: read=1634.275 + -> Hash Join (cost=2006.51..69055.94 rows=62283 width=36) (actual time=1663.729..1988.641 rows=25616 loops=1) + Hash Cond: (osm."ddord#" = n."ddord#") + Buffers: shared hit=1569 read=57960 + I/O Timings: read=1634.275 + -> Seq Scan on osm (cost=0.00..65166.02 rows=717402 width=12) (actual time=0.449..1815.192 rows=784772 loops=1) + Buffers: shared hit=32 read=57960 + I/O Timings: read=1634.275 + -> Hash (cost=1967.58..1967.58 rows=3115 width=36) (actual time=16.883..16.883 rows=3334 loops=1) + Buckets: 4096 Batches: 1 Memory Usage: 251kB + Buffers: shared hit=1537 + -> Subquery Scan on n (cost=1905.28..1967.58 rows=3115 width=36) (actual time=15.539..16.337 rows=3334 loops=1) + Buffers: shared hit=1537 + -> HashAggregate (cost=1905.28..1936.43 rows=3115 width=6) (actual time=15.524..15.848 rows=3334 loops=1) + Group Key: osmi."ddord#" + Buffers: shared hit=1537 + -> Seq Scan on osmi (cost=0.00..1844.40 rows=24350 width=6) (actual time=0.011..9.183 rows=25826 loops=1) + Filter: ("ddord#" <> '0'::numeric) + Rows Removed by Filter: 271 + Buffers: shared hit=1537 + +
++ + +9 +1s357ms +3s762ms +2s419ms +7 + + +16s934ms ++ +--\timing --explain (ANALYZE, buffers) WITH mseq AS ( SELECT * FROM ( VALUES (?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ) x(m,s) ) --select * FROM mseq ,base AS ( SELECT order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ,sum(units) units ,sum(value_usd) value_usd FROM rlarp.osm_fcpool WHERE quota_rep_descr = ? AND segm = ? AND mod_chan = ? AND part_descr = ? GROUP BY order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ) ,months AS ( SELECT order_season ,version ,iter ,order_month ,mseq.s seq ,sum(units) units ,sum(value_usd) value_usd FROM base INNER JOIN mseq ON mseq.m = base.order_month GROUP BY order_season ,version ,iter ,order_month ,s ) ,mpvt AS ( SELECT order_month ,seq ,sum(units) filter (WHERE order_season = ?) "? qty" ,sum(units) filter (WHERE order_season = ? AND iter = ?) "? base qty" ,sum(units) filter (WHERE order_season = ? AND iter <> ?) "? adj qty" ,sum(units) filter (WHERE order_season = ?) "? tot qty" ,sum(value_usd) filter (WHERE order_season = ?) "? value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter = ?) "? base value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter <> ?) "? adj value_usd" ,sum(value_usd) filter (WHERE order_season = ?) "? tot value_usd" FROM months GROUP BY order_month ,seq ORDER BY seq ASC ) ,mlist AS ( SELECT mseq.m order_month ,"? qty" ,"? base qty" ,"? adj qty" ,"? tot qty" ,"? value_usd" ,"? base value_usd" ,"? adj value_usd" ,"? tot value_usd" FROM mseq LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m ORDER BY mseq.s ASC ) ,totals AS ( SELECT order_season ,version ,iter ,sum(units) units ,sum(value_usd) value_usd FROM months GROUP BY order_season ,version ,iter ) SELECT jsonb_build_object( ? ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) ,? ,(SELECT jsonb_agg(row_to_json(mlist)::jsonb) FROM mlist) ,? ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) ,? ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) ) package ; ++ +++Times Reported Time consuming queries #9
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 15 15 3 11s264ms 3s754ms + +16 4 5s669ms 1s417ms ++ + + +-
+
+
[ User: api - Total duration: 6s706ms - Times executed: 3 ] +
+ +++ + + + +-
+
+
[ Application: osm_api - Total duration: 6s706ms - Times executed: 3 ] +
+ +++ +-
+
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
Date: 2019-03-15 15:01:25 +Duration: 3s762ms +Database: ubm +User: api +Remote: ubreport +Application: osm_api +
+ +++ + +Result (cost=43058.76..43058.77 rows=1 width=32) (actual time=3759.847..3759.850 rows=1 loops=1) + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + CTE mseq + -> Values Scan on "*VALUES*" (cost=0.00..0.15 rows=12 width=36) (actual time=0.001..0.007 rows=12 loops=1) + CTE base + -> GroupAggregate (cost=43056.99..43057.03 rows=1 width=176) (actual time=3758.393..3758.433 rows=43 loops=1) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> Sort (cost=43056.99..43056.99 rows=1 width=149) (actual time=3758.380..3758.383 rows=72 loops=1) + Sort Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Sort Method: quicksort Memory: 44kB + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> Gather (cost=1000.00..43056.97 rows=1 width=149) (actual time=175.512..3758.230 rows=72 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=169.788..3752.390 rows=24 loops=3) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 100422 + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + CTE months + -> HashAggregate (cost=0.35..0.36 rows=1 width=152) (actual time=3758.529..3758.536 rows=17 loops=1) + Group Key: base.order_season, base.version, base.iter, base.order_month, mseq.s + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> Hash Join (cost=0.03..0.33 rows=1 width=148) (actual time=3758.487..3758.505 rows=43 loops=1) + Hash Cond: (mseq.m = base.order_month) + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> CTE Scan on mseq (cost=0.00..0.24 rows=12 width=36) (actual time=0.003..0.011 rows=12 loops=1) + -> Hash (cost=0.02..0.02 rows=1 width=144) (actual time=3758.477..3758.477 rows=43 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 12kB + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> CTE Scan on base (cost=0.00..0.02 rows=1 width=144) (actual time=3758.396..3758.461 rows=43 loops=1) + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + CTE mpvt + -> GroupAggregate (cost=0.03..0.11 rows=1 width=196) (actual time=0.019..0.035 rows=7 loops=1) + Group Key: months.seq, months.order_month + -> Sort (cost=0.03..0.04 rows=1 width=116) (actual time=0.011..0.012 rows=17 loops=1) + Sort Key: months.seq, months.order_month + Sort Method: quicksort Memory: 26kB + -> CTE Scan on months (cost=0.00..0.02 rows=1 width=116) (actual time=0.001..0.003 rows=17 loops=1) + CTE mlist + -> Sort (cost=0.54..0.57 rows=12 width=196) (actual time=0.072..0.072 rows=12 loops=1) + Sort Key: mseq_1.s + Sort Method: quicksort Memory: 26kB + -> Hash Left Join (cost=0.03..0.33 rows=12 width=196) (actual time=0.058..0.062 rows=12 loops=1) + Hash Cond: (mseq_1.m = mpvt.order_month) + -> CTE Scan on mseq mseq_1 (cost=0.00..0.24 rows=12 width=36) (actual time=0.000..0.001 rows=12 loops=1) + -> Hash (cost=0.02..0.02 rows=1 width=192) (actual time=0.048..0.048 rows=7 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mpvt (cost=0.00..0.02 rows=1 width=192) (actual time=0.021..0.043 rows=7 loops=1) + CTE totals + -> HashAggregate (cost=0.03..0.05 rows=1 width=112) (actual time=0.016..0.018 rows=6 loops=1) + Group Key: months_1.order_season, months_1.version, months_1.iter + -> CTE Scan on months months_1 (cost=0.00..0.02 rows=1 width=112) (actual time=0.001..0.003 rows=17 loops=1) + InitPlan 7 (returns $7) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=3758.733..3758.733 rows=1 loops=1) + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + -> CTE Scan on months months_2 (cost=0.00..0.02 rows=1 width=24) (actual time=3758.536..3758.554 rows=17 loops=1) + Buffers: shared hit=99 read=39444 + I/O Timings: read=10910.610 + InitPlan 8 (returns $8) + -> Aggregate (cost=0.36..0.37 rows=1 width=32) (actual time=0.247..0.247 rows=1 loops=1) + -> CTE Scan on mlist (cost=0.00..0.24 rows=12 width=24) (actual time=0.075..0.083 rows=12 loops=1) + InitPlan 9 (returns $9) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=0.637..0.638 rows=1 loops=1) + -> CTE Scan on base base_1 (cost=0.00..0.02 rows=1 width=24) (actual time=0.003..0.022 rows=43 loops=1) + InitPlan 10 (returns $10) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=0.073..0.073 rows=1 loops=1) + -> CTE Scan on totals (cost=0.00..0.02 rows=1 width=24) (actual time=0.018..0.024 rows=6 loops=1) + +
+Date: 2019-03-15 15:01:25 +Duration: 3s752ms +
+ +++ + +Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=148.955..3752.933 rows=15 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 100266 + Buffers: shared hit=1 read=13062 + I/O Timings: read=3634.126 + +
+Date: 2019-03-15 15:01:25 +Duration: 3s749ms +
+ +++ + +Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=185.551..3749.831 rows=32 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 100674 + Buffers: shared hit=13 read=13176 + I/O Timings: read=3641.547 + +
++ + +10 +2s267ms +2s267ms +2s267ms +1 + + +2s267ms ++ +SELECT + sum(fb_val_loc * r_rate) +FROM + rlarp.osm; + ++ +++Times Reported Time consuming queries #10
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 15 09 1 2s267ms 2s267ms ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 2s267ms - Times executed: 1 ] +
+ +++ + + + +-
+
+
[ Application: DBeaver 6.0.0 - Main - Total duration: 2s267ms - Times executed: 1 ] +
+ +++ +-
+
+
-
+ SELECT + sum(fb_val_loc * r_rate) +FROM + rlarp.osm; + ++
+
Date: 2019-03-15 09:19:53 +Duration: 2s267ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: DBeaver 6.0.0 - Main +
+ +++ + +Finalize Aggregate (cost=64705.63..64705.64 rows=1 width=8) (actual time=2267.421..2267.421 rows=1 loops=1) + Buffers: shared read=57992 + I/O Timings: read=1653.381 + -> Gather (cost=64705.42..64705.63 rows=2 width=8) (actual time=2267.407..2267.411 rows=1 loops=1) + Workers Planned: 2 + Workers Launched: 0 + Buffers: shared read=57992 + I/O Timings: read=1653.381 + -> Partial Aggregate (cost=63705.42..63705.43 rows=1 width=8) (actual time=2267.403..2267.404 rows=1 loops=1) + Buffers: shared read=57992 + I/O Timings: read=1653.381 + -> Parallel Seq Scan on osm (cost=0.00..61256.81 rows=326481 width=10) (actual time=0.619..1766.451 rows=784529 loops=1) + Buffers: shared read=57992 + I/O Timings: read=1653.381 + +
++ + +11 +1s121ms +2s988ms +1s959ms +6 + + +11s756ms ++ +--\timing --explain (ANALYZE, buffers) WITH mseq AS ( SELECT * FROM ( VALUES (?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ) x(m,s) ) --select * FROM mseq ,base AS ( SELECT order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ,sum(units) units ,sum(value_usd) value_usd FROM rlarp.osm_fcpool WHERE quota_rep_descr = ? AND segm = ? AND mod_chan = ? AND part_descr = ? GROUP BY order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ) ,months AS ( SELECT order_season ,version ,iter ,order_month ,mseq.s seq ,sum(units) units ,sum(value_usd) value_usd FROM base INNER JOIN mseq ON mseq.m = base.order_month GROUP BY order_season ,version ,iter ,order_month ,s ) ,mpvt AS ( SELECT order_month ,seq ,sum(units) filter (WHERE order_season = ?) "? qty" ,sum(units) filter (WHERE order_season = ? AND iter IN (...)) "? base qty" ,sum(units) filter (WHERE order_season = ? AND iter NOT IN (...)) "? adj qty" ,sum(units) filter (WHERE order_season = ?) "? tot qty" ,sum(value_usd) filter (WHERE order_season = ?) "? value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter IN (...)) "? base value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter NOT IN (...)) "? adj value_usd" ,sum(value_usd) filter (WHERE order_season = ?) "? tot value_usd" FROM months GROUP BY order_month ,seq ORDER BY seq ASC ) ,mlist AS ( SELECT mseq.m order_month ,"? qty" ,"? base qty" ,"? adj qty" ,"? tot qty" ,"? value_usd" ,"? base value_usd" ,"? adj value_usd" ,"? tot value_usd" FROM mseq LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m ORDER BY mseq.s ASC ) ,totals AS ( SELECT order_season ,version ,iter ,sum(units) units ,sum(value_usd) value_usd FROM months GROUP BY order_season ,version ,iter ) SELECT jsonb_build_object( ? ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) ,? ,(SELECT jsonb_agg(row_to_json(mlist)::jsonb) FROM mlist) ,? ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) ,? ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) ) package ; ++ +++Times Reported Time consuming queries #11
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 15 16 3 8s369ms 2s789ms + +Mar 18 13 3 3s387ms 1s129ms ++ + + +-
+
+
[ User: api - Total duration: 4s131ms - Times executed: 2 ] +
+ +++ + + + +-
+
+
[ Application: osm_api - Total duration: 4s131ms - Times executed: 2 ] +
+ +++ +-
+
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter IN ('copy', 'short ship', 'bad_ship')) "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter NOT IN ('copy', 'short ship', 'bad_ship')) "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
Date: 2019-03-15 16:48:48 +Duration: 2s988ms +Database: ubm +User: api +Remote: ubreport +Application: osm_api +
+ +++ + +Result (cost=43058.77..43058.78 rows=1 width=32) (actual time=2986.772..2986.773 rows=1 loops=1) + Buffers: shared hit=9 read=39543 + I/O Timings: read=8023.323 + CTE mseq + -> Values Scan on "*VALUES*" (cost=0.00..0.15 rows=12 width=36) (actual time=0.002..0.010 rows=12 loops=1) + CTE base + -> GroupAggregate (cost=43056.99..43057.03 rows=1 width=176) (actual time=2980.662..2980.715 rows=43 loops=1) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> Sort (cost=43056.99..43056.99 rows=1 width=149) (actual time=2980.648..2980.652 rows=72 loops=1) + Sort Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Sort Method: quicksort Memory: 44kB + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> Gather (cost=1000.00..43056.97 rows=1 width=149) (actual time=37.232..2980.519 rows=72 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared read=39543 + I/O Timings: read=8023.323 + -> Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=103.278..2786.395 rows=24 loops=3) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 100422 + Buffers: shared read=39543 + I/O Timings: read=8023.323 + CTE months + -> HashAggregate (cost=0.35..0.36 rows=1 width=152) (actual time=2980.841..2980.865 rows=17 loops=1) + Group Key: base.order_season, base.version, base.iter, base.order_month, mseq.s + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> Hash Join (cost=0.03..0.33 rows=1 width=148) (actual time=2980.782..2980.808 rows=43 loops=1) + Hash Cond: (mseq.m = base.order_month) + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> CTE Scan on mseq (cost=0.00..0.24 rows=12 width=36) (actual time=0.004..0.017 rows=12 loops=1) + -> Hash (cost=0.02..0.02 rows=1 width=144) (actual time=2980.767..2980.767 rows=43 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 12kB + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> CTE Scan on base (cost=0.00..0.02 rows=1 width=144) (actual time=2980.665..2980.749 rows=43 loops=1) + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + CTE mpvt + -> GroupAggregate (cost=0.03..0.11 rows=1 width=196) (actual time=0.036..0.056 rows=7 loops=1) + Group Key: months.seq, months.order_month + -> Sort (cost=0.03..0.04 rows=1 width=116) (actual time=0.021..0.022 rows=17 loops=1) + Sort Key: months.seq, months.order_month + Sort Method: quicksort Memory: 26kB + -> CTE Scan on months (cost=0.00..0.02 rows=1 width=116) (actual time=0.002..0.005 rows=17 loops=1) + CTE mlist + -> Sort (cost=0.54..0.57 rows=12 width=196) (actual time=0.159..0.162 rows=12 loops=1) + Sort Key: mseq_1.s + Sort Method: quicksort Memory: 26kB + Buffers: shared hit=3 + -> Hash Left Join (cost=0.03..0.33 rows=12 width=196) (actual time=0.101..0.107 rows=12 loops=1) + Hash Cond: (mseq_1.m = mpvt.order_month) + -> CTE Scan on mseq mseq_1 (cost=0.00..0.24 rows=12 width=36) (actual time=0.001..0.003 rows=12 loops=1) + -> Hash (cost=0.02..0.02 rows=1 width=192) (actual time=0.071..0.071 rows=7 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mpvt (cost=0.00..0.02 rows=1 width=192) (actual time=0.038..0.063 rows=7 loops=1) + CTE totals + -> HashAggregate (cost=0.03..0.05 rows=1 width=112) (actual time=0.021..0.024 rows=6 loops=1) + Group Key: months_1.order_season, months_1.version, months_1.iter + -> CTE Scan on months months_1 (cost=0.00..0.02 rows=1 width=112) (actual time=0.001..0.004 rows=17 loops=1) + InitPlan 7 (returns $7) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=2985.173..2985.173 rows=1 loops=1) + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + -> CTE Scan on months months_2 (cost=0.00..0.02 rows=1 width=24) (actual time=2981.027..2981.083 rows=17 loops=1) + Buffers: shared hit=6 read=39543 + I/O Timings: read=8023.323 + InitPlan 8 (returns $8) + -> Aggregate (cost=0.36..0.37 rows=1 width=32) (actual time=0.435..0.435 rows=1 loops=1) + Buffers: shared hit=3 + -> CTE Scan on mlist (cost=0.00..0.24 rows=12 width=24) (actual time=0.179..0.197 rows=12 loops=1) + Buffers: shared hit=3 + InitPlan 9 (returns $9) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=0.845..0.845 rows=1 loops=1) + -> CTE Scan on base base_1 (cost=0.00..0.02 rows=1 width=24) (actual time=0.007..0.034 rows=43 loops=1) + InitPlan 10 (returns $10) + -> Aggregate (cost=0.03..0.04 rows=1 width=32) (actual time=0.109..0.109 rows=1 loops=1) + -> CTE Scan on totals (cost=0.00..0.02 rows=1 width=24) (actual time=0.030..0.038 rows=6 loops=1) + +
+Date: 2019-03-15 16:48:48 +Duration: 2s690ms +
+ +++ + +Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=195.353..2690.533 rows=16 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 76890 + Buffers: shared read=10399 + I/O Timings: read=2598.181 + +
+Date: 2019-03-15 16:48:48 +Duration: 2s690ms +
+ +++ + +Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=1 width=149) (actual time=77.724..2690.442 rows=19 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (part_descr = 'AZG06000B66B200 - 06.00 AZ TW 300GN @20000 BULK'::text)) + Rows Removed by Filter: 76638 + Buffers: shared read=10361 + I/O Timings: read=2590.846 + +
++ + +12 +1s444ms +3s349ms +1s835ms +6 + + +11s11ms ++ +--create INDEX flag ON gld(plan, rolling); WITH un AS ( SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osmf osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON osm.fspr = sd.fspr WHERE substr(osm.glec,?,?) <= ? AND substr(osm.fs_line,?,?) = ? AND calc_status <> ? --open orders AND sd.cm = ? --this works FOR forecast it indicates a future fspr GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) UNION ALL SELECT ? srce ,od.ssyr oseas ,od.sdat odate ,sd.ssyr sseas ,sd.sdat sdate ,coalesce(od.cm,sd.cm) om ,coalesce(sd.cm,?) sm ,coalesce(od.cy,sd.cy) oy ,coalesce(sd.cy,?) sy ,sum( fb_qty ) qty ,sum( fb_val_loc * r_rate ) sales ,sum( fb_cst_loc * c_rate ) stdcost FROM rlarp.osm osm INNER JOIN gld od ON osm.adj_orderdate BETWEEN od.sdat AND od.edat LEFT OUTER JOIN gld sd ON greatest(osm.adj_requestdate,current_date) BETWEEN sd.sdat AND sd.edat WHERE substr(osm.fs_line,?,?) = ? AND substr(osm.glec,?,?) <= ? AND calc_status IN (...) AND flag = ? GROUP BY od.ssyr ,od.sdat ,sd.ssyr ,sd.sdat ,coalesce(od.cm,sd.cm) ,coalesce(sd.cm,?) ,coalesce(od.cy,sd.cy) ,coalesce(sd.cy,?) ) SELECT srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ,sum(qty) units ,sum(stdcost) "cost" ,sum(sales) sales FROM un WHERE om <> ? GROUP BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ORDER BY srce ,oseas ,odate ,sseas ,sdate ,om ,sm ,oy ,sy ; ++ +++Times Reported Time consuming queries #12
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 18 10 6 11s11ms 1s835ms ++ + + +-
+
+
[ User: report - Total duration: 4s793ms - Times executed: 2 ] +
+ +++ + + + +-
+
+
[ Application: [unknown] - Total duration: 4s793ms - Times executed: 2 ] +
+ +++ +-
+
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
-
+ --CREATE INDEX flag ON GLD(plan, rolling); +WITH UN AS ( + SELECT + 'FC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST + FROM + RLARP.OSMF OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON OSM.FSPR = SD.FSPR +WHERE + substr(OSM.GLEC, 1, 1) <= '2' + AND substr(OSM.FS_LINE, 1, 5) = '41010' + AND CALC_STATUS <> 'CANCELED' --OPEN ORDERS + AND SD.CM = 'F' --this works FOR forecast it indicates a future FSPR +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +UNION ALL +SELECT + 'AC' SRCE, + OD.SSYR OSEAS, + OD.SDAT ODATE, + SD.SSYR SSEAS, + SD.SDAT SDATE, + coalesce(OD.CM, SD.CM) OM, + coalesce(SD.CM, 'F') SM, + coalesce(OD.CY, SD.CY) OY, + coalesce(SD.CY, 'F') SY, + sum(FB_QTY) QTY, + sum(FB_VAL_LOC * R_RATE) SALES, + sum(FB_CST_LOC * C_RATE) STDCOST +FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON OSM.ADJ_ORDERDATE BETWEEN OD.SDAT + AND OD.EDAT + LEFT OUTER JOIN GLD SD ON GREATEST (OSM.adj_requestdate, + current_date) BETWEEN SD.SDAT + AND SD.EDAT +WHERE + substr(OSM.FS_LINE, 1, 5) = '41010' + AND substr(OSM.GLEC, 1, 1) <= '2' + AND CALC_STATUS IN ('BACKORDER', 'OPEN') + AND FLAG = 'REMAINDER' +GROUP BY + OD.SSYR, + OD.SDAT, + SD.SSYR, + SD.SDAT, + coalesce(OD.CM, SD.CM), + coalesce(SD.CM, 'F'), + coalesce(OD.CY, SD.CY), + coalesce(SD.CY, 'F') +) +SELECT + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY, + sum(QTY) UNITS, + sum(STDCOST) "cost", + sum(SALES) SALES +FROM + UN +WHERE + OM <> 'F' +GROUP BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY +ORDER BY + SRCE, + OSEAS, + ODATE, + SSEAS, + SDATE, + OM, + SM, + OY, + SY; + ++
+
Date: 2019-03-18 10:06:25 +Duration: 3s349ms +Database: ubm +User: report +Remote: USHCC10107.GBL.HC-companies.com +Application: [unknown] +
+ +++ + +Sort (cost=98200.29..98200.79 rows=200 width=232) (actual time=3348.705..3348.710 rows=132 loops=1) + Sort Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Sort Method: quicksort Memory: 43kB + Buffers: shared hit=235 read=84111, local hit=161423 read=1 + I/O Timings: read=7279.164 + CTE un + -> Append (cost=31586.61..98166.63 rows=449 width=232) (actual time=1488.149..3348.297 rows=154 loops=1) + Buffers: shared hit=232 read=84111, local hit=161423 read=1 + I/O Timings: read=7279.164 + -> GroupAggregate (cost=31586.61..31590.91 rows=82 width=232) (actual time=1488.148..1554.309 rows=84 loops=1) + Group Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Buffers: shared read=26345, local hit=151073 read=1 + I/O Timings: read=2987.288 + -> Sort (cost=31586.61..31586.81 rows=82 width=185) (actual time=1488.111..1493.540 rows=75536 loops=1) + Sort Key: od.ssyr, od.sdat, sd.ssyr, sd.sdat, (COALESCE(od.cm, sd.cm)), (COALESCE(sd.cm, 'F'::text)), (COALESCE(od.cy, sd.cy)), (COALESCE(sd.cy, 'F'::text)) + Sort Method: quicksort Memory: 13695kB + Buffers: shared read=26345, local hit=151073 read=1 + I/O Timings: read=2987.288 + -> Nested Loop (cost=1004.33..31584.00 rows=82 width=185) (actual time=21.103..1425.083 rows=75536 loops=1) + Buffers: shared read=26345, local hit=151073 read=1 + I/O Timings: read=2987.288 + -> Hash Join (cost=1004.19..31579.49 rows=4 width=113) (actual time=21.078..1001.628 rows=75536 loops=1) + Hash Cond: (osm.fspr = sd.fspr) + Buffers: shared read=26345, local hit=2 + I/O Timings: read=2987.281 + -> Gather (cost=1000.00..31572.50 rows=738 width=42) (actual time=21.024..908.420 rows=406814 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared read=26345 + I/O Timings: read=2987.281 + -> Parallel Seq Scan on osmf osm (cost=0.00..30498.70 rows=308 width=42) (actual time=11.969..1113.675 rows=135605 loops=3) + Filter: ((calc_status <> 'CANCELED'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 119 + Buffers: shared read=26345 + I/O Timings: read=2987.281 + -> Hash (cost=4.18..4.18 rows=1 width=108) (actual time=0.033..0.034 rows=38 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 10kB + Buffers: local hit=2 + -> Seq Scan on gld sd (cost=0.00..4.18 rows=1 width=108) (actual time=0.021..0.027 rows=38 loops=1) + Filter: (cm = 'F'::text) + Rows Removed by Filter: 136 + Buffers: local hit=2 + -> Index Scan using dats on gld od (cost=0.14..0.94 rows=19 width=80) (actual time=0.005..0.005 rows=1 loops=75536) + Index Cond: ((osm.adj_orderdate >= sdat) AND (osm.adj_orderdate <= edat)) + Buffers: local hit=151071 read=1 + I/O Timings: read=0.007 + -> GroupAggregate (cost=66549.72..66568.99 rows=367 width=232) (actual time=1789.692..1793.972 rows=70 loops=1) + Group Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Buffers: shared hit=232 read=57766, local hit=10350 + I/O Timings: read=4291.876 + -> Sort (cost=66549.72..66550.64 rows=367 width=178) (actual time=1789.672..1789.874 rows=5174 loops=1) + Sort Key: od_1.ssyr, od_1.sdat, sd_1.ssyr, sd_1.sdat, (COALESCE(od_1.cm, sd_1.cm)), (COALESCE(sd_1.cm, 'F'::text)), (COALESCE(od_1.cy, sd_1.cy)), (COALESCE(sd_1.cy, 'F'::text)) + Sort Method: quicksort Memory: 920kB + Buffers: shared hit=232 read=57766, local hit=10350 + I/O Timings: read=4291.876 + -> Nested Loop (cost=1004.74..66534.08 rows=367 width=178) (actual time=1752.458..1786.814 rows=5174 loops=1) + Join Filter: ((osm_1.adj_orderdate >= od_1.sdat) AND (osm_1.adj_orderdate <= od_1.edat)) + Rows Removed by Join Filter: 895102 + Buffers: shared hit=232 read=57766, local hit=10350 + I/O Timings: read=4291.876 + -> Seq Scan on gld od_1 (cost=0.00..3.74 rows=174 width=80) (actual time=0.013..0.078 rows=174 loops=1) + Buffers: local hit=2 + -> Materialize (cost=1004.74..66472.54 rows=19 width=106) (actual time=0.073..9.810 rows=5174 loops=174) + Buffers: shared hit=232 read=57766, local hit=10348 + I/O Timings: read=4291.876 + -> Nested Loop Left Join (cost=1004.74..66472.44 rows=19 width=106) (actual time=12.621..1668.315 rows=5174 loops=1) + Buffers: shared hit=232 read=57766, local hit=10348 + I/O Timings: read=4291.876 + -> Gather (cost=1000.00..66465.04 rows=1 width=34) (actual time=12.587..1608.241 rows=5174 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=232 read=57766 + I/O Timings: read=4291.876 + -> Parallel Seq Scan on osm osm_1 (cost=0.00..65464.94 rows=1 width=34) (actual time=4.136..1641.056 rows=1725 loops=3) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 259938 + Buffers: shared hit=232 read=57766 + I/O Timings: read=4291.876 + -> Bitmap Heap Scan on gld sd_1 (cost=4.74..7.21 rows=19 width=80) (actual time=0.011..0.011 rows=1 loops=5174) + Recheck Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Heap Blocks: exact=5174 + Buffers: local hit=10348 + -> Bitmap Index Scan on dats (cost=0.00..4.73 rows=19 width=0) (actual time=0.010..0.010 rows=1 loops=5174) + Index Cond: ((GREATEST(osm_1.adj_requestdate, CURRENT_DATE) >= sdat) AND (GREATEST(osm_1.adj_requestdate, CURRENT_DATE) <= edat)) + Buffers: local hit=5174 + -> HashAggregate (cost=23.51..26.01 rows=200 width=232) (actual time=3348.532..3348.577 rows=132 loops=1) + Group Key: un.srce, un.oseas, un.odate, un.sseas, un.sdate, un.om, un.sm, un.oy, un.sy + Buffers: shared hit=232 read=84111, local hit=161423 read=1 + I/O Timings: read=7279.164 + -> CTE Scan on un (cost=0.00..10.10 rows=447 width=232) (actual time=1488.153..3348.409 rows=132 loops=1) + Filter: (om <> 'F'::text) + Rows Removed by Filter: 22 + Buffers: shared hit=232 read=84111, local hit=161423 read=1 + I/O Timings: read=7279.164 + +
+Date: 2019-03-18 10:06:25 +Duration: 1s661ms +
+ +++ + +Parallel Seq Scan on osm (cost=0.00..65464.94 rows=1 width=34) (actual time=0.035..1661.025 rows=2679 loops=1) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 312636 + Buffers: shared hit=57 read=22167 + I/O Timings: read=1426.762 + +
+Date: 2019-03-18 10:06:25 +Duration: 1s659ms +
+ +++ + +Parallel Seq Scan on osm (cost=0.00..65464.94 rows=1 width=34) (actual time=0.588..1658.922 rows=1702 loops=1) + Filter: ((calc_status = ANY ('{BACKORDER,OPEN}'::text[])) AND (flag = 'REMAINDER'::text) AND (substr(glec, 1, 1) <= '2'::text) AND (substr(fs_line, 1, 5) = '41010'::text)) + Rows Removed by Filter: 291296 + Buffers: shared hit=39 read=21772 + I/O Timings: read=1413.782 + +
++ + +13 +1s270ms +1s826ms +1s616ms +3 + + +4s848ms ++ +INSERT INTO rlarp.osm +SELECT + * +FROM + import.osmi; + ++ +++Times Reported Time consuming queries #13
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 17 1 1s826ms 1s826ms Mar 15 14 1 1s270ms 1s270ms + +16 1 1s752ms 1s752ms ++ + + +-
+
+
[ User: ptrowbridge_md5 - Total duration: 4s848ms - Times executed: 3 ] +
+ +++ + + + +-
+
+
[ Application: psql - Total duration: 4s848ms - Times executed: 3 ] +
+ +++ +-
+
+
-
+ INSERT INTO rlarp.osm +SELECT + * +FROM + import.osmi; + ++
+
-
+ INSERT INTO rlarp.osm +SELECT + * +FROM + import.osmi; + ++
+
-
+ INSERT INTO rlarp.osm +SELECT + * +FROM + import.osmi; + ++
+
Date: 2019-03-14 17:12:46 +Duration: 1s826ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm (cost=0.00..1750.44 rows=24144 width=457) (actual time=1826.337..1826.337 rows=0 loops=1) + Buffers: shared hit=419286 read=3669 dirtied=3584 + I/O Timings: read=1345.135 + -> Seq Scan on osmi (cost=0.00..1750.44 rows=24144 width=457) (actual time=0.007..7.078 rows=25626 loops=1) + Buffers: shared hit=1509 + +
+Date: 2019-03-15 16:45:34 +Duration: 1s752ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm (cost=0.00..1782.92 rows=24592 width=457) (actual time=1752.635..1752.635 rows=0 loops=1) + Buffers: shared hit=406744 read=6293 dirtied=6259 + I/O Timings: read=1296.982 + -> Seq Scan on osmi (cost=0.00..1782.92 rows=24592 width=457) (actual time=0.005..6.976 rows=26097 loops=1) + Buffers: shared hit=1537 + +
+Date: 2019-03-15 14:07:11 +Duration: 1s270ms +Database: ubm +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Application: psql +
+ +++ + +Insert on osm (cost=0.00..1765.52 rows=24352 width=457) (actual time=1270.004..1270.004 rows=0 loops=1) + Buffers: shared hit=421843 read=4791 dirtied=3283 + I/O Timings: read=823.790 + -> Seq Scan on osmi (cost=0.00..1765.52 rows=24352 width=457) (actual time=0.006..6.130 rows=25878 loops=1) + Buffers: shared hit=1522 + +
++ + +14 +1s194ms +1s327ms +1s240ms +3 + + +3s720ms ++ +--\timing --explain (ANALYZE, buffers) WITH mseq AS ( SELECT * FROM ( VALUES (?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ,(?,?) ) x(m,s) ) --select * FROM mseq ,base AS ( SELECT order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ,sum(units) units ,sum(value_usd) value_usd FROM rlarp.osm_fcpool WHERE quota_rep_descr = ? AND segm = ? AND mod_chan = ? AND bill_cust_descr = ? GROUP BY order_season ,order_month ,version ,iter ,part_descr ,bill_cust_descr ,ship_cust_descr ) ,months AS ( SELECT order_season ,version ,iter ,order_month ,mseq.s seq ,sum(units) units ,sum(value_usd) value_usd FROM base INNER JOIN mseq ON mseq.m = base.order_month GROUP BY order_season ,version ,iter ,order_month ,s ) ,mpvt AS ( SELECT order_month ,seq ,sum(units) filter (WHERE order_season = ?) "? qty" ,sum(units) filter (WHERE order_season = ? AND iter = ?) "? base qty" ,sum(units) filter (WHERE order_season = ? AND iter <> ?) "? adj qty" ,sum(units) filter (WHERE order_season = ?) "? tot qty" ,sum(value_usd) filter (WHERE order_season = ?) "? value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter = ?) "? base value_usd" ,sum(value_usd) filter (WHERE order_season = ? AND iter <> ?) "? adj value_usd" ,sum(value_usd) filter (WHERE order_season = ?) "? tot value_usd" FROM months GROUP BY order_month ,seq ORDER BY seq ASC ) ,mlist AS ( SELECT mseq.m order_month ,"? qty" ,"? base qty" ,"? adj qty" ,"? tot qty" ,"? value_usd" ,"? base value_usd" ,"? adj value_usd" ,"? tot value_usd" FROM mseq LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m ORDER BY mseq.s ASC ) ,totals AS ( SELECT order_season ,version ,iter ,sum(units) units ,sum(value_usd) value_usd FROM months GROUP BY order_season ,version ,iter ) SELECT jsonb_build_object( ? ,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months) ,? ,(SELECT jsonb_agg(row_to_json(mlist)::jsonb) FROM mlist) ,? ,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base) ,? ,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals) ) package ; ++ +++Times Reported Time consuming queries #14
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration + + +Mar 15 10 3 3s720ms 1s240ms ++ + + +-
+
+
[ User: api - Total duration: 1s327ms - Times executed: 1 ] +
+ +++ + + + +-
+
+
[ Application: osm_api - Total duration: 1s327ms - Times executed: 1 ] +
+ +++ +-
+
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
-
+ --\timing +--explain (ANALYZE, buffers) +WITH mseq AS ( + SELECT + * + FROM ( + VALUES ('Jun', + 1), + ('Jul', + 2), + ('Aug', + 3), + ('Sep', + 4), + ('Oct', + 5), + ('Nov', + 6), + ('Dec', + 7), + ('Jan', + 8), + ('Feb', + 9), + ('Mar', + 10), + ('Apr', + 11), + ('May', + 12)) x (m, + s) +) --select * FROM mseq +, +base AS ( + SELECT + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr, + sum(units) units, + sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + WHERE + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DISTRIBUTOR' + AND bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC' + GROUP BY + order_season, + order_month, + version, + iter, + part_descr, + bill_cust_descr, + ship_cust_descr), + months AS ( + SELECT + order_season, + version, + iter, + order_month, + mseq.s seq, + sum(units) units, + sum(value_usd) value_usd + FROM + base + INNER JOIN mseq ON mseq.m = base.order_month + GROUP BY + order_season, + version, + iter, + order_month, + s), + mpvt AS ( + SELECT + order_month, + seq, + sum(units) FILTER ( + WHERE + order_season = 2019) "2019 qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base qty", sum(units) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj qty", sum(units) FILTER ( + WHERE + order_season = 2020) "2020 tot qty", sum(value_usd) FILTER ( + WHERE + order_season = 2019) "2019 value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter = 'copy') "2020 base value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020 + AND iter <> 'copy') "2020 adj value_usd", sum(value_usd) FILTER ( + WHERE + order_season = 2020) "2020 tot value_usd" + FROM + months + GROUP BY + order_month, seq + ORDER BY + seq ASC), mlist AS ( + SELECT + mseq.m order_month, "2019 qty", "2020 base qty", "2020 adj qty", "2020 tot qty", "2019 value_usd", "2020 base value_usd", "2020 adj value_usd", "2020 tot value_usd" + FROM + mseq + LEFT OUTER JOIN mpvt ON mpvt.order_month = mseq.m + ORDER BY + mseq.s ASC), totals AS ( + SELECT + order_season, version, iter, sum(units) units, sum(value_usd) value_usd + FROM + months + GROUP BY + order_season, version, iter +) + SELECT + jsonb_build_object ('months', ( + SELECT + jsonb_agg (row_to_json(months)::jsonb) + FROM + months), + 'mpvt', + ( + SELECT + jsonb_agg (row_to_json(mlist)::jsonb) + FROM + mlist), + 'base', + ( + SELECT + jsonb_agg (row_to_json(base)::jsonb) + FROM + base), + 'totals', + ( + SELECT + jsonb_agg (row_to_json(totals)::jsonb) + FROM + totals)) package; + ++
+
Date: 2019-03-15 10:02:03 +Duration: 1s327ms +Database: ubm +User: api +Remote: USHCC10107.GBL.HC-companies.com +Application: osm_api +
+ +++ + +Result (cost=43067.02..43067.03 rows=1 width=32) (actual time=1322.834..1322.949 rows=1 loops=1) + Buffers: shared hit=3 read=15116 + I/O Timings: read=1154.285 + CTE mseq + -> Values Scan on "*VALUES*" (cost=0.00..0.15 rows=12 width=36) (actual time=0.008..0.012 rows=12 loops=1) + CTE base + -> Finalize GroupAggregate (cost=43057.06..43060.56 rows=25 width=176) (actual time=1287.168..1296.146 rows=1095 loops=1) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared read=15116 + I/O Timings: read=1154.285 + -> Gather Merge (cost=43057.06..43059.75 rows=20 width=176) (actual time=1287.150..1294.990 rows=1214 loops=1) + Workers Planned: 2 + Workers Launched: 2 + Buffers: shared hit=112 read=39543 + I/O Timings: read=3332.221 + -> Partial GroupAggregate (cost=42057.04..42057.42 rows=10 width=176) (actual time=1222.013..1222.459 rows=405 loops=3) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared hit=112 read=39543 + I/O Timings: read=3332.221 + -> Sort (cost=42057.04..42057.07 rows=10 width=149) (actual time=1221.999..1222.047 rows=447 loops=3) + Sort Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.ship_cust_descr + Sort Method: quicksort Memory: 145kB + Worker 0: Sort Method: quicksort Memory: 145kB + Worker 1: Sort Method: quicksort Memory: 140kB + Buffers: shared hit=112 read=39543 + I/O Timings: read=3332.221 + -> Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=10 width=149) (actual time=24.365..1220.140 rows=447 loops=3) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC'::text)) + Rows Removed by Filter: 99999 + Buffers: shared read=39543 + I/O Timings: read=3332.221 + CTE months + -> HashAggregate (cost=1.31..1.46 rows=12 width=152) (actual time=1297.764..1297.785 rows=28 loops=1) + Group Key: base.order_season, base.version, base.iter, base.order_month, mseq.s + Buffers: shared read=15116 + I/O Timings: read=1154.285 + -> Hash Join (cost=0.39..1.10 rows=12 width=148) (actual time=1287.272..1297.191 rows=1095 loops=1) + Hash Cond: (base.order_month = mseq.m) + Buffers: shared read=15116 + I/O Timings: read=1154.285 + -> CTE Scan on base (cost=0.00..0.50 rows=25 width=144) (actual time=1287.170..1296.717 rows=1095 loops=1) + Buffers: shared read=15116 + I/O Timings: read=1154.285 + -> Hash (cost=0.24..0.24 rows=12 width=36) (actual time=0.028..0.028 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 9kB + -> CTE Scan on mseq (cost=0.00..0.24 rows=12 width=36) (actual time=0.013..0.021 rows=12 loops=1) + CTE mpvt + -> GroupAggregate (cost=0.46..1.39 rows=12 width=196) (actual time=0.043..0.069 rows=12 loops=1) + Group Key: months.seq, months.order_month + -> Sort (cost=0.46..0.49 rows=12 width=116) (actual time=0.029..0.031 rows=28 loops=1) + Sort Key: months.seq, months.order_month + Sort Method: quicksort Memory: 27kB + -> CTE Scan on months (cost=0.00..0.24 rows=12 width=116) (actual time=0.001..0.006 rows=28 loops=1) + CTE mlist + -> Sort (cost=1.01..1.04 rows=12 width=196) (actual time=0.167..0.168 rows=12 loops=1) + Sort Key: mseq_1.s + Sort Method: quicksort Memory: 26kB + Buffers: shared hit=3 + -> Hash Left Join (cost=0.39..0.80 rows=12 width=196) (actual time=0.110..0.115 rows=12 loops=1) + Hash Cond: (mseq_1.m = mpvt.order_month) + -> CTE Scan on mseq mseq_1 (cost=0.00..0.24 rows=12 width=36) (actual time=0.001..0.002 rows=12 loops=1) + -> Hash (cost=0.24..0.24 rows=12 width=192) (actual time=0.092..0.092 rows=12 loops=1) + Buckets: 1024 Batches: 1 Memory Usage: 10kB + -> CTE Scan on mpvt (cost=0.00..0.24 rows=12 width=192) (actual time=0.049..0.082 rows=12 loops=1) + CTE totals + -> HashAggregate (cost=0.39..0.54 rows=12 width=112) (actual time=0.037..0.040 rows=6 loops=1) + Group Key: months_1.order_season, months_1.version, months_1.iter + -> CTE Scan on months months_1 (cost=0.00..0.24 rows=12 width=112) (actual time=0.003..0.008 rows=28 loops=1) + InitPlan 7 (returns $7) + -> Aggregate (cost=0.36..0.37 rows=1 width=32) (actual time=1298.799..1298.799 rows=1 loops=1) + Buffers: shared read=15116 + I/O Timings: read=1154.285 + -> CTE Scan on months months_2 (cost=0.00..0.24 rows=12 width=24) (actual time=1297.953..1298.003 rows=28 loops=1) + Buffers: shared read=15116 + I/O Timings: read=1154.285 + InitPlan 8 (returns $8) + -> Aggregate (cost=0.36..0.37 rows=1 width=32) (actual time=0.466..0.467 rows=1 loops=1) + Buffers: shared hit=3 + -> CTE Scan on mlist (cost=0.00..0.24 rows=12 width=24) (actual time=0.181..0.192 rows=12 loops=1) + Buffers: shared hit=3 + InitPlan 9 (returns $9) + -> Aggregate (cost=0.75..0.76 rows=1 width=32) (actual time=19.795..19.795 rows=1 loops=1) + -> CTE Scan on base base_1 (cost=0.00..0.50 rows=25 width=24) (actual time=0.006..0.656 rows=1095 loops=1) + InitPlan 10 (returns $10) + -> Aggregate (cost=0.36..0.37 rows=1 width=32) (actual time=0.165..0.165 rows=1 loops=1) + -> CTE Scan on totals (cost=0.00..0.24 rows=12 width=24) (actual time=0.059..0.067 rows=6 loops=1) + +
+Date: 2019-03-15 10:02:03 +Duration: 1s198ms +
+ +++ + +Partial GroupAggregate (cost=42057.04..42057.42 rows=10 width=176) (actual time=1191.374..1191.759 rows=387 loops=1) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared hit=56 read=12331 + I/O Timings: read=1091.338 + -> Sort (cost=42057.04..42057.07 rows=10 width=149) (actual time=1191.355..1191.388 rows=435 loops=1) + Sort Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.ship_cust_descr + Sort Method: quicksort Memory: 140kB + Worker 0: Sort Method: quicksort Memory: 145kB + Worker 1: Sort Method: quicksort Memory: 140kB + Buffers: shared hit=56 read=12331 + I/O Timings: read=1091.338 + -> Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=10 width=149) (actual time=11.309..1189.560 rows=435 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC'::text)) + Rows Removed by Filter: 92425 + Buffers: shared read=12331 + I/O Timings: read=1091.338 + +
+Date: 2019-03-15 10:02:03 +Duration: 1s194ms +
+ +++ + +Partial GroupAggregate (cost=42057.04..42057.42 rows=10 width=176) (actual time=1190.430..1190.830 rows=411 loops=1) + Group Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.bill_cust_descr, osm_fcpool.ship_cust_descr + Buffers: shared hit=56 read=12096 + I/O Timings: read=1086.598 + -> Sort (cost=42057.04..42057.07 rows=10 width=149) (actual time=1190.420..1190.459 rows=452 loops=1) + Sort Key: osm_fcpool.order_season, osm_fcpool.order_month, osm_fcpool.version, osm_fcpool.iter, osm_fcpool.part_descr, osm_fcpool.ship_cust_descr + Sort Method: quicksort Memory: 145kB + Worker 0: Sort Method: quicksort Memory: 145kB + Worker 1: Sort Method: quicksort Memory: 140kB + Buffers: shared hit=56 read=12096 + I/O Timings: read=1086.598 + -> Parallel Seq Scan on osm_fcpool (cost=0.00..42056.88 rows=10 width=149) (actual time=24.972..1188.569 rows=452 loops=1) + Filter: ((quota_rep_descr = '10032 - BRYAN HILL'::text) AND (segm = 'Greenhouse'::text) AND (mod_chan = 'DISTRIBUTOR'::text) AND (bill_cust_descr = 'BWIC0001 - BWI COMPANIES INC'::text)) + Rows Removed by Filter: 91018 + Buffers: shared read=12096 + I/O Timings: read=1086.598 + +
++ + +15 +0ms +0ms +0ms +2 + + +0ms ++ +COPY lgdat.pdrq (vcpart, + "vcseq#", + vcqtyr, + vcunit, + vcdate, + vctime, + vctmzn, + vcsrce, + "vcref#", + vcstat, + vcplnt) +TO STDOUT; + ++ +++Times Reported Time consuming queries #15
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ + +16 +0ms +0ms +0ms +2 + + +0ms ++ +LOCK TABLE lgdat.serin IN access share mode; + ++ +++Times Reported Time consuming queries #16
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ + +17 +0ms +0ms +0ms +2 + + +0ms ++ +COPY lgdat.vrtf (g7type, + g7flda, + g7fldn, + g7fldt, + g7desc) +TO STDOUT; + ++ +++Times Reported Time consuming queries #17
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ + +18 +0ms +0ms +0ms +2 + + +0ms ++ +LOCK TABLE lgdat.altmh IN access share mode; + ++ +++Times Reported Time consuming queries #18
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ + +19 +0ms +0ms +0ms +2 + + +0ms ++ +COPY lgdat.lbrd (n4btid, + "n4ent#", + "n4tag#", + n4empd, + n4empl, + n4mode, + n4dept, + n4resc, + n4rbtd, + n4part, + "n4seq#", + "n4job#", + "n4ref#", + n4indc, + n4sdat, + n4stim, + n4edat, + n4etim, + n4tmzn, + n4post, + n4ratf, + n4attc, + n4cdep, + n4cres, + n4proc, + n4rseq, + n4rent, + n4nhrs, + n4fut01, + n4fut02, + n4fut03, + n4fut04, + n4fut05, + n4fut06, + n4fut07, + n4fut08, + n4fut09, + n4fut10, + n4edttm, + n4inuse) +TO STDOUT; + ++ +++Times Reported Time consuming queries #19
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ + + +20 +0ms +0ms +0ms +2 + + +0ms ++ +LOCK TABLE lgdat.glcrc IN access share mode; + ++ +++Times Reported Time consuming queries #20
+ + + ++ +
+ ++ + + +Day +Hour +Count +Duration +Avg duration +Mar 14 16 1 0ms 0ms + +Mar 15 16 1 0ms 0ms ++ +-
+
+
+ -
+
+
Events
+ +++ +Log levels
+++ +Key values
+++-
+
- 70,640 Log entries +
++ + +Events distribution
+++Key values
+++-
+
- 0 PANIC entries +
- 1 FATAL entries +
- 16 ERROR entries +
- 4 WARNING entries +
+ + + ++++ +Most Frequent Errors/Events
+++Key values
+++-
+
- 4 Max number of times the same event was reported +
- 21 Total events found +
+++ +
++ + + + +Rank +Times reported +Error ++ + +1 +4 + + ++ +++ +WARNING: terminating connection because of crash of another server process
+++ + + + +Times Reported Most Frequent Error / Event #1
+ + + ++ +
+ ++ + + +Day +Hour +Count + + +Mar 14 17 4 ++ +-
+
+
- WARNING: terminating connection because of crash of another server process +
Detail: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
+
Hint: In a moment you should be able to reconnect to the database and repeat your command.Date: 2019-03-14 17:18:18 +
+ ++ + +2 +4 + + ++ +++ +LOG: database system was shut down at ...
+++ + + + +Times Reported Most Frequent Error / Event #2
+ + + ++ +
+ ++ + + +Day +Hour +Count +Mar 14 01 1 Mar 15 01 1 + +Mar 18 08 2 ++ +-
+
+
- LOG: database system was shut down at 2019-03-14 01:27:06 EDT + +
- LOG: database system was shut down at 2019-03-15 01:16:43 EDT + +
- LOG: database system was shut down at 2019-03-18 08:57:22 EDT + +
Date: 2019-03-14 01:27:06 +
+ +Date: 2019-03-15 01:16:44 +
+ +Date: 2019-03-18 08:57:22 +
+ ++ + +3 +3 + + ++ +++ +ERROR: syntax error at or near "..."
+++ + + + +Times Reported Most Frequent Error / Event #3
+ + + ++ +
+ ++ + + +Day +Hour +Count +Mar 14 10 2 + +Mar 18 09 1 ++ +-
+
+
- ERROR: syntax error at or near "ltree" at character 238 +
- ERROR: syntax error at or near "as" at character 238 +
- ERROR: syntax error at or near "GROUP" at character 722 +
Statement: SELECT * FROM ( VALUES + ('setup.forecast'), + ('setup.forecast.shortship'), + ('seutp.forecast.baddate'), + ('setup.copy'), + ('setup.copy.shortship'), + ('setup.copy.baddate'), + ('ui.adjust.volume'), + ('ui.adjust.price') + ) x("setup.actual" ltree)
+Date: 2019-03-14 10:21:19 +Database: ubm +Application: DBeaver 5.3.5 - Main +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Code: +
+ +Statement: SELECT * FROM ( VALUES + ('setup.forecast'), + ('setup.forecast.shortship'), + ('seutp.forecast.baddate'), + ('setup.copy'), + ('setup.copy.shortship'), + ('setup.copy.baddate'), + ('ui.adjust.volume'), + ('ui.adjust.price') + ) x("setup.actual" as ltree)
+Date: 2019-03-14 10:21:23 +Database: ubm +Application: DBeaver 5.3.5 - Main +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Code: +
+ +Statement: --CREATE INDEX flag ON GLD(plan, rolling); + + WITH + UN AS ( + SELECT + 'FC' SRCE + ,OD.SSYR OSEAS + ,OD.SDAT ODATE + ,SD.SSYR SSEAS + ,SD.SDAT SDATE + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,SUM( FB_QTY ) QTY + ,SUM( FB_VAL_LOC * R_RATE ) SALES + ,SUM( FB_CST_LOC * C_RATE ) STDCOST + FROM + RLARP.OSMP OSM + INNER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + WHERE + SUBSTR(OSM.GLEC,1,1) <= '2' + AND SUBSTR(OSM.FS_LINE,1,5) = '41010' + AND CALC_STATUS <> 'CANCELED' + AND (adj_orderdate BETWEEN '2018-06-01' AND '2018-02-28' OR FSPR BETWEEN '1901' AND '1909' + GROUP BY + OD.SSYR + ,OD.SDAT + ,SD.SSYR + ,SD.SDAT + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + UNION ALL + SELECT + 'AC' SRCE + ,OD.SSYR OSEAS + ,OD.SDAT ODATE + ,SD.SSYR SSEAS + ,SD.SDAT SDATE + ,COALESCE(OD.CM,SD.CM) OM + ,COALESCE(SD.CM,'F') SM + ,COALESCE(OD.CY,SD.CY) OY + ,COALESCE(SD.CY,'F') SY + ,SUM( FB_QTY ) QTY + ,SUM( FB_VAL_LOC * R_RATE ) SALES + ,SUM( FB_CST_LOC * C_RATE ) STDCOST + FROM + RLARP.OSM OSM + INNER JOIN GLD OD ON + OSM.ADJ_ORDERDATE BETWEEN OD.SDAT AND OD.EDAT + LEFT OUTER JOIN GLD SD ON + OSM.FSPR = SD.FSPR + WHERE + SUBSTR(OSM.FS_LINE,1,5) = '41010' + AND SUBSTR(OSM.GLEC,1,1) <= '2' + AND CALC_STATUS <> 'CANCELED' + AND (adj_orderdate BETWEEN '2018-06-01' AND '2018-02-28' OR FSPR BETWEEN '1901' AND '1909' + GROUP BY + OD.SSYR + ,OD.SDAT + ,SD.SSYR + ,SD.SDAT + ,COALESCE(OD.CM,SD.CM) + ,COALESCE(SD.CM,'F') + ,COALESCE(OD.CY,SD.CY) + ,COALESCE(SD.CY,'F') + ) + SELECT + SRCE + ,OSEAS + ,ODATE + ,SSEAS + ,SDATE + ,OM + ,SM + ,OY + ,SY + ,SUM(QTY) UNITS + ,SUM(STDCOST) "cost" + ,SUM(SALES) SALES + FROM + UN + GROUP BY + SRCE + ,OSEAS + ,ODATE + ,SSEAS + ,SDATE + ,OM + ,SM + ,OY + ,SY + ORDER BY + SRCE + ,OSEAS + ,ODATE + ,SSEAS + ,SDATE + ,OM + ,SM + ,OY + ,SY; + + DROP TABLE gld; + --SELECT * FROM gld;
+Date: 2019-03-18 09:32:25 +Database: ubm +Application: [unknown] +User: report +Remote: USHCC10107.GBL.HC-companies.com +Code: +
+ ++ + +4 +2 + + ++ +++ +ERROR: syntax error at position 0
+++ + + + +Times Reported Most Frequent Error / Event #4
+ + + ++ +
+ ++ + + +Day +Hour +Count + + +Mar 14 10 2 ++ +-
+
+
- ERROR: syntax error at position 0 at character 442 +
Statement: with llist as ( + SELECT + x.llist::ltree item + FROM + ( + VALUES + ('setup.actual'), + ('setup.forecast'), + ('setup.forecast.shortship'), + ('seutp.forecast.baddate'), + ('setup.copy'), + ('setup.copy.shortship'), + ('setup.copy.baddate'), + ('ui.adjust.volume'), + ('ui.adjust.price') + ) x("llist") + ) + select + item + from + llist + where + item <@ '*.volume.*'
+Date: 2019-03-14 10:23:50 +Database: ubm +Application: DBeaver 5.3.5 - Main +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Code: +
+ ++ + +5 +2 + + ++ +++ +ERROR: division by zero
+++ + + + +Times Reported Most Frequent Error / Event #5
+ + + ++ +
+ ++ + + +Day +Hour +Count +Mar 14 11 1 + +12 1 ++ +-
+
+
- ERROR: division by zero +
Statement: WITH + /* + the volume must be expressed in terms of units, since that is what it will be scaling + */ + target AS (select 0 vincr, -1561.8281112 pincr) + ,GLD AS ( + SELECT + N1COMP COMP + ,N1CCYY FSYR + ,KPMAXP PERDS + ,N1FSPP PERD + ,to_char(N1FSYP,'FM0000') FSPR + ,N1SD01 SDAT + ,N1ED01 EDAT + ,to_char(N1ED01,'yymm') CAPR + ,N1ED01 - N1SD01 +1 NDAYS + ,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR + ,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR + FROM + LGDAT.GLDATREF + INNER JOIN LGDAT.GLDATE ON + KPCOMP = N1COMP AND + KPCCYY = N1CCYY + WHERE + N1COMP = 93 + --AND DIGITS(N1FSYP) = '1901' + ) + ,mseq AS ( + SELECT * FROM + ( + VALUES + ('Jun',1,6,-1) + ,('Jul',2,7,-1) + ,('Aug',3,8,-1) + ,('Sep',4,9,-1) + ,('Oct',5,10,-1) + ,('Nov',6,11,-1) + ,('Dec',7,12,-1) + ,('Jan',8,1,0) + ,('Feb',9,2,0) + ,('Mar',10,3,0) + ,('Apr',11,4,0) + ,('May',12,5,0) + ) x(m,s,cal,yr) + ) + ,alldates AS ( + SELECT + promo + ,terms + ,order_month + ,mseq.s seq + ,orderdate + ,requestdate + ,shipdate + ,sum(value_usd) value_usd + FROM + rlarp.osm_fcpool + LEFT OUTER JOIN mseq ON + mseq.m = order_month + WHERE + -----------------scenario---------------------------- + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DIRECT' + AND shipto_group = 'FRIENDSHIP FOLIAGE' + AND part_descr = 'STG06000B66B146 - 06.00 STD TW 300GN @14625 BULK' + AND version = 'b20' + AND iter IN ('copy','adj volume','adj price') + -----------------additional params------------------- + AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments + AND adj_orderdate <= adj_shipdate + GROUP BY + promo + ,terms + ,order_month + ,mseq.s + ,orderdate + ,requestdate + ,shipdate + HAVING + sum(value_usd) <> 0 + ) + --select * from alldates + ,dom AS ( + SELECT + extract(day FROM orderdate) DOM + ,sum(value_usd) value_usd + FROM + alldates + GROUP BY + extract(day FROM orderdate) + ) + ---------------------may want ot look at a top-5 mix solution in the future facilitated by sum() over (order by sales desc)--------------- + ,mmix AS ( + SELECT + to_char(orderdate,'Mon') _month + ,seq + ,promo + ,sum(extract(day from orderdate)*value_usd) dom_wa + --,requestdate-orderdate rlag + ,sum((requestdate-orderdate)*(value_usd)) rlag_wa + --,shipdate - requestdate slag + ,sum((shipdate - requestdate)*(value_usd)) slag_wa + ,sum(value_usd) value_usd + FROM + alldates + GROUP BY + to_char(orderdate,'Mon') + ,seq + ,promo + --,extract(day from orderdate) + --,requestdate-orderdate + --,shipdate - requestdate + ) + ,targm AS (select s, m from mseq where m = 'Apr' ) + ,mmixp AS ( + SELECT + _month + ,seq + ,promo + ,round((dom_wa/value_usd)::numeric,0)::int odom + ,round((rlag_wa/value_usd)::numeric,0)::int rlag + ,round((slag_wa/value_usd)::numeric,0)::int slag + ,value_usd/sum(value_usd) over (partition by _month) momix + --,value_usd/SUM(value_usd) over (PARTITION BY _month) vperc + FROM + mmix + ) + ,closest AS ( + SELECT + _month, targm.s, m + FROM + mmixp + CROSS JOIN targm + ORDER BY + abs(seq - targm.s) ASC + LIMIT 1 + ) + --SELECT * FROM mmixp order by seq asc, vperc desc + ,basemix AS ( + SELECT + plnt ---master data + ,0::numeric(11,0) "ddord#" --0 + ,0::numeric(11,0) "dditm#" --0 + ,0::numeric(11,0) "fgbol#" --0 + ,0::numeric(11,0) "fgent#" --0 + ,0::numeric(9,0) "diinv#" --0 + ,0::numeric(3,0) "dilin#" --0 + ,null::text promo --history date mix + ,null::text return_reas --0 + ,terms + ,''::text custpo --0 + ,'I' dhincr --0 + ,sum(diext) diext + ,sum(ditdis) ditdis + ,null::date dcodat --calculated date mix + ,null::date ddqdat --calculated date mix + ,null::date dcmdat --calculated date mix + ,null::date dhidat --calculated date mix + ,null::text fspr --calculated date mix + ,remit_to --master data + ,bill_class --master data + ,bill_cust --history cust mix + ,bill_rep --master data + ,bill_terr --master data + ,ship_class --master data + ,ship_cust --history cust mix + ,ship_rep --master data + ,ship_terr --master data + ,quota_rep --master data + ,account --master data + ,shipgrp --master data + ,geo --master data + ,chan --master data + ,orig_ctry --master data + ,orig_prov --master data + ,orig_post --master data + ,dest_ctry --master data + ,dest_prov --master data + ,dest_post --master data + ,part --history part mix + ,ord_gldc --master data + ,majg --master data + ,ming --master data + ,majs --master data + ,mins --master data + ,gldc --master data + ,glec --master data + ,harm --master data + ,clss --master data + ,brand --master data + ,assc --master data + ,fs_line --master data + ,r_currency --history cust mix + ,r_rate --master data + ,c_currency --master data + ,c_rate --master data + ,0::numeric(15,5) ddqtoi --0 + ,0::numeric(15,5) ddqtsi --0 + ,0::numeric(15,5) fgqshp --0 + ,0::numeric(15,5) diqtsh --0 + ,sum(coalesce(fb_qty,0)) fb_qty --history value + ,sum(coalesce(fb_cst_loc,0)) fb_cst_loc --history part mix + ,sum(coalesce(fb_cst_loc_cur,0)) fb_cst_loc_cur --master data + ,sum(coalesce(fb_cst_loc_fut,0)) fb_cst_loc_fut --master data + ,sum(coalesce(fb_val_loc,0)) fb_val_loc --history value + ,sum(coalesce(fb_val_loc_pl,0)) fb_val_loc_pl --0 + ,calc_status --0 + ,flag --0 + ,null::date orderdate --history date mix + ,null::date requestdate --history date mix + ,null::date shipdate --history date mix + ,null::date adj_orderdate --history + ,null::date adj_requestdate --history + ,null::date adj_shipdate --history + ,'b20' "version" --calculated + ,'adjustment' iter --calculated + ---------------ui columns------------------------- + ,null::numeric order_season + ,null::text order_month + ,null::numeric ship_season + ,null::text ship_month + ,null::numeric request_season + ,null::text request_month + ,part_descr + ,part_family + ,part_group + ,branding + ,color + ,segm + ,bill_cust_descr + ,billto_group + ,ship_cust_descr + ,shipto_group + ,majg_descr + ,ming_descr + ,majs_descr + ,mins_descr + ,mod_chan + ,mod_chansub + ,quota_rep_descr + ,director_descr + ,null value_loc + ,null value_usd + ,null cost_loc + ,null cost_usd + ,null units + FROM + rlarp.osm_fcpool + WHERE + -----------------scenario---------------------------- + quota_rep_descr = '10032 - BRYAN HILL' + AND segm = 'Greenhouse' + AND mod_chan = 'DIRECT' + AND shipto_group = 'FRIENDSHIP FOLIAGE' + AND part_descr = 'STG06000B66B146 - 06.00 STD TW 300GN @14625 BULK' + AND version = 'b20' + AND iter IN ('copy','adj volume','adj price') + -----------------additional params------------------- + AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments + AND adj_orderdate <= adj_shipdate + GROUP BY + plnt ---master data + ,terms + ,remit_to --master data + ,bill_class --master data + ,bill_cust --history cust mix + ,bill_rep --master data + ,bill_terr --master data + ,ship_class --master data + ,ship_cust --history cust mix + ,ship_rep --master data + ,ship_terr --master data + ,quota_rep --master data + ,account --master data + ,shipgrp --master data + ,geo --master data + ,chan --master data + ,orig_ctry --master data + ,orig_prov --master data + ,orig_post --master data + ,dest_ctry --master data + ,dest_prov --master data + ,dest_post --master data + ,part --history part mix + ,ord_gldc --master data + ,majg --master data + ,ming --master data + ,majs --master data + ,mins --master data + ,gldc --master data + ,glec --master data + ,harm --master data + ,clss --master data + ,brand --master data + ,assc --master data + ,fs_line --master data + ,r_currency --history cust mix + ,r_rate --master data + ,c_currency --master data + ,c_rate --master data + ,calc_status + ,flag + ,part_descr + ,part_family + ,part_group + ,branding + ,color + ,segm + ,bill_cust_descr + ,billto_group + ,ship_cust_descr + ,shipto_group + ,majg_descr + ,ming_descr + ,majs_descr + ,mins_descr + ,mod_chan + ,mod_chansub + ,quota_rep_descr + ,director_descr + ) + ,vscale AS ( + SELECT + (SELECT vincr::numeric FROM target) incr + ,(SELECT sum(fb_qty) FROM basemix) base + ,(SELECT vincr::numeric FROM target)/(SELECT sum(fb_qty) FROM basemix) factor + ) + --select * from SCALE + ,volume AS ( + SELECT + b.plnt --master data + ,b."ddord#" --0 + ,b."dditm#" --0 + ,b."fgbol#" --0 + ,b."fgent#" --0 + ,b."diinv#" --0 + ,b."dilin#" --0 + ,b.promo --history date mix + ,b.return_reas --0 + ,b.terms --history cust mix + ,b.custpo --0 + ,b.dhincr --0 + ,b.diext --0 + ,b.ditdis --0 + ,b.dcodat --calculated date mix + ,b.ddqdat --calculated date mix + ,b.dcmdat --calculated date mix + ,b.dhidat --calculated date mix + ,b.fspr --calculated date mix + ,b.remit_to --master data + ,b.bill_class --master data + ,b.bill_cust --history cust mix + ,b.bill_rep --master data + ,b.bill_terr --master data + ,b.ship_class --master data + ,b.ship_cust --history cust mix + ,b.ship_rep --master data + ,b.ship_terr --master data + ,b.quota_rep --master data + ,b.account --master data + ,b.shipgrp --master data + ,b.geo --master data + ,b.chan --master data + ,b.orig_ctry --master data + ,b.orig_prov --master data + ,b.orig_post --master data + ,b.dest_ctry --master data + ,b.dest_prov --master data + ,b.dest_post --master data + ,b.part --history part mix + ,b.ord_gldc --master data + ,b.majg --master data + ,b.ming --master data + ,b.majs --master data + ,b.mins --master data + ,b.gldc --master data + ,b.glec --master data + ,b.harm --master data + ,b.clss --master data + ,b.brand --master data + ,b.assc --master data + ,b.fs_line --master data + ,b.r_currency --history cust mix + ,b.r_rate --master data + ,b.c_currency --master data + ,b.c_rate --master data + ,b.ddqtoi --0 + ,b.ddqtsi --0 + ,b.fgqshp --0 + ,b.diqtsh --0 + ,b.fb_qty*s.factor*m.momix fb_qty + ,b.fb_cst_loc*s.factor*m.momix fb_cst_loc + ,b.fb_cst_loc_cur*s.factor*m.momix fb_cst_loc_cur + ,b.fb_cst_loc_fut*s.factor*m.momix fb_cst_loc_fut + ,b.fb_val_loc*s.factor*m.momix fb_val_loc + ,b.fb_val_loc_pl*s.factor*m.momix fb_val_loc_pl + ,b.calc_status --0 + ,b.flag --0 + ,make_date(mseq.yr + 2020,mseq.cal,m.odom) orderdate + ,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag requestdate + ,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag shipdate + ,make_date(mseq.yr + 2020,mseq.cal,m.odom) adj_orderdate + ,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_requestdate + ,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag adj_shipdate + ,'b20' "version" --calculated + ,'adj'||' volume' iter + -----------------------ui columns-------------------------------- + ,'replace_iterdet' iterdet + ,$${"scenario":{"quota_rep_descr":"10032 - BRYAN HILL","segm":"Greenhouse","mod_chan":"DIRECT","shipto_group":"FRIENDSHIP FOLIAGE","part_descr":"STG06000B66B146 - 06.00 STD TW 300GN @14625 BULK","version":"b20","iter":["copy","adj volume","adj price"]},"stamp":"2019-03-14 11:39:23","user":"Trowbridge, Paul","source":"adj","type":"addmonth_vp","month":"Apr","qty":0,"amount":-1561.8281112}$$::jsonb iterdef + ,od.ssyr order_season + ,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month + ,sd.ssyr ship_season + ,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month + ,rd.ssyr request_season + ,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag,'Mon') request_month + ,b.part_descr + ,b.part_family + ,b.part_group + ,b.branding + ,b.color + ,b.segm + ,b.bill_cust_descr + ,b.billto_group + ,b.ship_cust_descr + ,b.shipto_group + ,b.majg_descr + ,b.ming_descr + ,b.majs_descr + ,b.mins_descr + ,b.mod_chan + ,b.mod_chansub + ,b.quota_rep_descr + ,b.director_descr + ,b.fb_val_loc*s.factor*m.momix value_loc + ,b.fb_val_loc*s.factor*m.momix*r_rate value_usd + ,b.fb_cst_loc*s.factor*m.momix cost_loc + ,b.fb_cst_loc*s.factor*m.momix*c_rate cost_usd + ,(b.fb_qty*s.factor*m.momix) units + FROM + basemix b + CROSS JOIN vscale s + CROSS JOIN mmixp m + CROSS JOIN closest + LEFT OUTER JOIN mseq ON + mseq.m = closest.m + LEFT OUTER JOIN gld od ON + make_date(mseq.yr + 2020,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat + LEFT OUTER JOIN gld rd ON + make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat + LEFT OUTER JOIN gld sd ON + make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat + WHERE + m._month = (SELECT _month FROM closest) + ) + ,pscale AS ( + SELECT + (SELECT pincr::numeric FROM target) incr + ,(SELECT sum(fb_val_loc * r_rate) FROM volume) base + ,(SELECT pincr::numeric FROM target)/(SELECT sum(fb_val_loc) FROM volume) factor + ) + ,price AS ( + SELECT + b.plnt --master data + ,b."ddord#" --0 + ,b."dditm#" --0 + ,b."fgbol#" --0 + ,b."fgent#" --0 + ,b."diinv#" --0 + ,b."dilin#" --0 + ,b.promo --history date mix + ,b.return_reas --0 + ,b.terms --history cust mix + ,b.custpo --0 + ,b.dhincr --0 + ,b.diext --0 + ,b.ditdis --0 + ,b.dcodat --calculated date mix + ,b.ddqdat --calculated date mix + ,b.dcmdat --calculated date mix + ,b.dhidat --calculated date mix + ,b.fspr --calculated date mix + ,b.remit_to --master data + ,b.bill_class --master data + ,b.bill_cust --history cust mix + ,b.bill_rep --master data + ,b.bill_terr --master data + ,b.ship_class --master data + ,b.ship_cust --history cust mix + ,b.ship_rep --master data + ,b.ship_terr --master data + ,b.quota_rep --master data + ,b.account --master data + ,b.shipgrp --master data + ,b.geo --master data + ,b.chan --master data + ,b.orig_ctry --master data + ,b.orig_prov --master data + ,b.orig_post --master data + ,b.dest_ctry --master data + ,b.dest_prov --master data + ,b.dest_post --master data + ,b.part --history part mix + ,b.ord_gldc --master data + ,b.majg --master data + ,b.ming --master data + ,b.majs --master data + ,b.mins --master data + ,b.gldc --master data + ,b.glec --master data + ,b.harm --master data + ,b.clss --master data + ,b.brand --master data + ,b.assc --master data + ,b.fs_line --master data + ,b.r_currency --history cust mix + ,b.r_rate --master data + ,b.c_currency --master data + ,b.c_rate --master data + ,b.ddqtoi --0 + ,b.ddqtsi --0 + ,b.fgqshp --0 + ,b.diqtsh --0 + ,0 fb_qty + ,0 fb_cst_loc + ,0 fb_cst_loc_cur + ,0 fb_cst_loc_fut + ,b.fb_val_loc*p.factor fb_val_loc + ,b.fb_val_loc_pl*p.factor fb_val_loc_pl + ,b.calc_status --0 + ,b.flag --0 + ,b.orderdate + ,b.requestdate + ,b.shipdate + ,b.adj_orderdate + ,b.adj_requestdate + ,b.adj_shipdate + ,'b20' "version" --calculated + ,'adj'||' price' iter --calculateds + ,'replace_iterdet' iterdet + ,$${"scenario":{"quota_rep_descr":"10032 - BRYAN HILL","segm":"Greenhouse","mod_chan":"DIRECT","shipto_group":"FRIENDSHIP FOLIAGE","part_descr":"STG06000B66B146 - 06.00 STD TW 300GN @14625 BULK","version":"b20","iter":["copy","adj volume","adj price"]},"stamp":"2019-03-14 11:39:23","user":"Trowbridge, Paul","source":"adj","type":"addmonth_vp","month":"Apr","qty":0,"amount":-1561.8281112}$$::jsonb iterdef + ,b.order_season + ,b.order_month + ,b.ship_season + ,b.ship_month + ,b.request_season + ,b.request_month + ,b.part_descr + ,b.part_family + ,b.part_group + ,b.branding + ,b.color + ,b.segm + ,b.bill_cust_descr + ,b.billto_group + ,b.ship_cust_descr + ,b.shipto_group + ,b.majg_descr + ,b.ming_descr + ,b.majs_descr + ,b.mins_descr + ,b.mod_chan + ,b.mod_chansub + ,b.quota_rep_descr + ,b.director_descr + ,b.fb_val_loc*p.factor value_loc + ,b.fb_val_loc*p.factor*r_rate value_usd + ,0 cost_loc + ,0 cost_usd + ,0 units + FROM + volume b + CROSS JOIN pscale p + ) + , ins AS ( + INSERT INTO rlarp.osm_fcpool (SELECT * FROM price UNION ALL SELECT * FROM volume) RETURNING * + ) + ,insagg AS ( + SELECT + bill_cust_descr + ,billto_group + ,ship_cust_descr + ,shipto_group + ,quota_rep_descr + ,director_descr + ,segm + ,mod_chan + ,mod_chansub + ,majg_descr + ,ming_descr + ,majs_descr + ,mins_descr + ,brand + ,part_family + ,part_group + ,branding + ,color + ,part_descr + ,order_season + ,order_month + ,ship_season + ,ship_month + ,request_season + ,request_month + ,promo + ,version + ,iter + ,sum(value_loc) value_loc + ,sum(value_usd) value_usd + ,sum(cost_loc) cost_loc + ,sum(cost_usd) cost_usd + ,sum(units) units + FROM + ins + GROUP BY + bill_cust_descr + ,billto_group + ,ship_cust_descr + ,shipto_group + ,quota_rep_descr + ,director_descr + ,segm + ,mod_chan + ,mod_chansub + ,majg_descr + ,ming_descr + ,majs_descr + ,mins_descr + ,brand + ,part_family + ,part_group + ,branding + ,color + ,part_descr + ,order_season + ,order_month + ,ship_season + ,ship_month + ,request_season + ,request_month + ,promo + ,version + ,iter + ) + --SELECT * FROM insagg + SELECT json_agg(row_to_json(insagg)) x from insagg +
+Date: 2019-03-14 11:39:37 +Database: ubm +Application: osm_api +User: api +Remote: USHCC10107.GBL.HC-companies.com +Code: +
+ ++ + +6 +1 + + ++ +++ +ERROR: pg_stat_statements must be loaded via shared_preload_libraries
+++ + + + +Times Reported Most Frequent Error / Event #6
+ + + ++ +
+ ++ + + +Day +Hour +Count + + +Mar 16 01 1 ++ +-
+
+
- ERROR: pg_stat_statements must be loaded via shared_preload_libraries +
Statement: select * from pg_stat_statements
+Date: 2019-03-16 01:28:18 +Database: ubm +Application: psql +User: ptrowbridge +Remote: ubreport +Code: +
+ ++ + +7 +1 + + ++ +++ +ERROR: relation "..." does not exist
+++ + + + +Times Reported Most Frequent Error / Event #7
+ + + ++ +
+ ++ + + +Day +Hour +Count + + +Mar 15 09 1 ++ +-
+
+
- ERROR: relation "pg_stat_acticity" does not exist at character 15 +
Statement: select * from pg_stat_acticity
+Date: 2019-03-15 09:53:17 +Database: ubm +Application: psql +User: ptrowbridge +Remote: USHCC10107.GBL.HC-companies.com +Code: +
+ ++ + +8 +1 + + ++ +++ +LOG: database system was not properly shut down; automatic recovery in progress
+++ + + + +Times Reported Most Frequent Error / Event #8
+ + + ++ +
+ ++ + + +Day +Hour +Count + + +Mar 14 17 1 ++ +-
+
+
- LOG: database system was not properly shut down; automatic recovery in progress + +
Date: 2019-03-14 17:18:21 +
+ ++ + +9 +1 + + ++ +++ +FATAL: password authentication failed for user "..."
+++ + + + +Times Reported Most Frequent Error / Event #9
+ + + ++ +
+ ++ + + +Day +Hour +Count + + +Mar 15 13 1 ++ +-
+
+
- FATAL: password authentication failed for user "ptrowbridge" +
Detail: Connection matched pg_hba.conf line 102: " host all all 0.0.0.0/0 scram-sha-256"
+Date: 2019-03-15 13:23:45 +Database: ubm +Application: [unknown] +User: ptrowbridge +Remote: ubreport +Code: +
+ ++ + +10 +1 + + ++ +++ +LOG: database system was interrupted; last known up at ...
+++ + + + +Times Reported Most Frequent Error / Event #10
+ + + ++ +
+ ++ + + +Day +Hour +Count + + +Mar 14 17 1 ++ +-
+
+
- LOG: database system was interrupted; last known up at 2019-03-14 17:13:48 EDT + +
Date: 2019-03-14 17:18:19 +
+ ++ + + +11 +1 + + ++ +++ +ERROR: current transaction is aborted, commands ignored until end of transaction block
+++ + + + +Times Reported Most Frequent Error / Event #11
+ + + ++ +
+ ++ + + +Day +Hour +Count + + +Mar 14 10 1 ++ +-
+
+
- ERROR: current transaction is aborted, commands ignored until end of transaction block +
Statement: SELECT + x.llist::ltree + FROM + ( + VALUES + ('setup.actual'), + ('setup.forecast'), + ('setup.forecast.shortship'), + ('seutp.forecast.baddate'), + ('setup.copy'), + ('setup.copy.shortship'), + ('setup.copy.baddate'), + ('ui.adjust.volume'), + ('ui.adjust.price') + ) x("llist")
+Date: 2019-03-14 10:22:08 +Database: ubm +Application: DBeaver 5.3.5 - Main +User: ptrowbridge_md5 +Remote: USHCC10107.GBL.HC-companies.com +Code: +
+ +
+