Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. SELECT d."Selling_date", d."Value_in_EUR", d."Value_in_currency", d."Site"
  2. FROM report.get_sa001('2016-01-01'::date, '2017-03-31'::date, 32) AS d
  3.  
  4. Select a."Selling_currency" FROM report."Axis_RefCustomer" AS a
  5.  
  6. SELECT d."Selling_date",
  7. a."Selling_currency",
  8. d."Value_in_EUR",
  9. d."Value_in_currency",
  10. d."Site"
  11. FROM report.get_sa001('2016-01-01'::date, '2017-03-31'::date, 32) AS d
  12. LEFT JOIN report."Axis_RefCustomer"
  13. AS a ON d."Site" = a."Site"
  14. AND d."Internal_reference" = a."Reference_internal"
  15. AND d."Customer_code" = a."Customer_code"
  16.  
  17. Function Scan on get_sa001 d (cost=0.25..10.25 rows=1000 width=104) (actual time=2522.959..2534.987 rows=53446 loops=1)
  18. Total runtime: 2537.926 ms
  19.  
  20. Hash Right Join (cost=3527.82..5840.32 rows=74513 width=4) (actual time=47.363..71.317 rows=77965 loops=1)
  21. Hash Cond: ((("T12_RefCustomer"."Site")::text = ("T01_References"."Site")::text) AND (("T12_RefCustomer"."Internal_reference")::text = ("T01_References"."Internal_reference")::text))
  22. -> Seq Scan on "T12_RefCustomer" (cost=0.00..348.81 rows=13181 width=29) (actual time=0.002..2.350 rows=13182 loops=1)
  23. -> Hash (cost=1973.13..1973.13 rows=74513 width=22) (actual time=46.591..46.591 rows=74513 loops=1)
  24. Buckets: 2048 Batches: 4 Memory Usage: 1019kB
  25. -> Seq Scan on "T01_References" (cost=0.00..1973.13 rows=74513 width=22) (actual time=0.014..18.580 rows=74513 loops=1)
  26. Total runtime: 72.540 ms
  27.  
  28. Nested Loop Left Join (cost=1.23..2375.17 rows=1000 width=108) (actual time=2406.131..42314.297 rows=53446 loops=1)
  29. -> Function Scan on get_sa001 d (cost=0.25..10.25 rows=1000 width=168) (actual time=2405.980..2429.250 rows=53446 loops=1)
  30. -> Nested Loop (cost=0.98..2.35 rows=1 width=28) (actual time=0.547..0.746 rows=1 loops=53446)
  31. Join Filter: (((d."Site")::text = ("T01_References"."Site")::text) AND ((d."Internal_reference")::text = ("T01_References"."Internal_reference")::text) AND (("T02_Customers"."Site")::text = ("T01_References"."Site")::text))
  32. Rows Removed by Join Filter: 126"
  33. -> Nested Loop (cost=0.57..1.42 rows=1 width=33) (actual time=0.011..0.057 rows=127 loops=53446)
  34. -> Index Scan using "T02_Customers_pkey" on "T02_Customers" (cost=0.28..0.77 rows=1 width=17) (actual time=0.004..0.004 rows=1 loops=53446)
  35. Index Cond: ((d."Customer_code")::text = ("Customer_code")::text)
  36. -> Index Scan using "T12_RefCustomer_pkey" on "T12_RefCustomer" (cost=0.29..0.64 rows=1 width=29) (actual time=0.007..0.027 rows=99 loops=68927)
  37. Index Cond: ((("Customer_code")::text = ("T02_Customers"."Customer_code")::text) AND (("Site")::text = ("T02_Customers"."Site")::text))
  38. -> Index Scan using "T01_References_pkey" on "T01_References" (cost=0.42..0.92 rows=1 width=22) (actual time=0.005..0.005 rows=1 loops=6795220)
  39. Index Cond: ((("Internal_reference")::text = ("T12_RefCustomer"."Internal_reference")::text) AND (("Site")::text = ("T12_RefCustomer"."Site")::text))
  40. Total runtime: 42318.196 ms
  41.  
  42. with
  43. __d as(
  44. select
  45. "Selling_date",
  46. "Value_in_EUR",
  47. "Value_in_currency",
  48. "Site",
  49. "Internal_reference",
  50. "Customer_code"
  51. from
  52. report.get_sa001('2016-01-01'::date, '2017-03-31'::date, 32)
  53. ),
  54. __a as(
  55. select
  56. "Selling_currency",
  57. "Site",
  58. "Reference_internal" as "Internal_reference",
  59. "Customer_code"
  60. from
  61. report."Axis_RefCustomer"
  62. where
  63. ("Site", "Reference_internal", "Customer_code") in(
  64. select
  65. "Site",
  66. "Internal_reference",
  67. "Customer_code"
  68. from
  69. __d
  70. )
  71. )
  72. select
  73. __d."Selling_date",
  74. __a."Selling_currency",
  75. __d."Value_in_EUR",
  76. __d."Value_in_currency",
  77. __d."Site"
  78. from
  79. __d
  80. left join __a using("Site", "Internal_reference", "Customer_code")
  81.  
  82. SELECT d."Selling_date"
  83. , a."Selling_currency"
  84. , d."Value_in_EUR"
  85. , d."Value_in_currency"
  86. , d."Site"
  87. FROM (
  88. SELECT *
  89. FROM report.get_sa001(date '2016-01-01', date '2017-03-31', 32)
  90. OFFSET 0 -- probably redundant
  91. ) d
  92. LEFT JOIN report."Axis_RefCustomer" a ON d."Site" = a."Site"
  93. AND d."Internal_reference" = a."Reference_internal"
  94. AND d."Customer_code" = a."Customer_code";
  95.  
  96. SELECT d."Selling_date"
  97. , ( SELECT "Selling_currency"
  98. FROM report."Axis_RefCustomer"
  99. WHERE d."Site" = a."Site"
  100. AND d."Internal_reference" = a."Reference_internal"
  101. AND d."Customer_code" = a."Customer_code")
  102. , d."Value_in_EUR"
  103. , d."Value_in_currency"
  104. , d."Site"
  105. FROM report.get_sa001(date '2016-01-01', date '2017-03-31', 32) d;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement