Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tucha=> \out plans
- tucha=> EXPLAIN ( ANALYZE, COSTS, VERBOSE, BUFFERS, format text )
- tucha-> SELECT
- tucha-> --next_ots.group_cost AS next_cost,
- tucha-> (SELECT next_ots FROM order_total_suma( next_range ) next_ots
- tucha(> WHERE next_ots.order_id = ots.order_id AND next_ots.consumed_period @> (ots.o).billed_to
- tucha(> ) AS next_suma,
- tucha-> ots.* FROM (
- tucha(> SELECT
- tucha(> tstzrange(
- tucha(> NULLIF( (ots.o).billed_to, 'infinity' ),
- tucha(> NULLIF( (ots.o).billed_to +p.interval, 'infinity' )
- tucha(> ) as next_range,
- tucha(> ots.*
- tucha(> FROM order_total_suma() ots
- tucha(> LEFT JOIN period p ON p.id = (ots.o).period_id
- tucha(> ) ots
- tucha-> --LEFT JOIN order_total_suma( next_range ) next_ots ON next_ots.order_id = 6154 --<< this is fine
- tucha-> -- AND next_ots.consumed_period @> (ots.o).billed_to
- tucha-> --LEFT JOIN order_total_suma( next_range ) next_ots ON next_ots.order_id = ots.order_id --<< this takes 11500ms
- tucha-> -- AND next_ots.consumed_period @> (ots.o).billed_to
- tucha-> WHERE ots.order_id IN ( 6154, 10805 )
- tucha-> ;
- tucha=> EXPLAIN ( ANALYZE, COSTS, VERBOSE, BUFFERS, format text )
- tucha-> SELECT
- to
- --) AS next_suma,
- ots.* FROM (
- SELECT
- tstzrange(
- NULLIF( (ots.o).billed_to, 'infinity' ),
- NULLIF( (ots.tucha-> --next_ots.group_cost AS next_cost,
- tucha-> --(SELECT next_ots FROM order_total_suma( next_range ) next_ots
- tucha-> --WHERE next_ots.order_id = ots.order_id AND next_ots.consumed_period @> (ots.o).billed_to
- tucha-> --) AS next_suma,
- tucha-> ots.* FROM (
- tucha(> SELECT
- tucha(> tstzrange(
- tucha(> NULLIF( (ots.o).billed_to, 'infinity' ),
- tucha(> NULLIF( (ots.o).billed_to +p.interval, 'infinity' )
- tucha(> ) as next_range,
- tucha(> ots.*
- tucha(> FROM order_total_suma() ots
- tucha(> LEFT JOIN period p ON p.id = (ots.o).period_id
- tucha(> ) ots
- tucha-> --LEFT JOIN order_total_suma( next_range ) next_ots ON next_ots.order_id = 6154 --<< this is fine
- tucha-> -- AND next_ots.consumed_period @> (ots.o).billed_to
- tucha-> LEFT JOIN order_total_suma( next_range ) next_ots ON next_ots.order_id = ots.order_id --<< this takes 11500ms
- tucha-> AND next_ots.consumed_period @> (ots.o).billed_to
- tucha-> WHERE ots.order_id IN ( 6154, 10805 )
- tucha-> ;
- QUERY PLAN
- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Hash Left Join (cost=369.35..1639.06 rows=6 width=292) (actual time=121.898..135.833 rows=2 loops=1)
- Output: (SubPlan 4), tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone)), (sum(t.group_suma) OVER (?)), t.group_cost, t.group_suma, t.consumed, t.consumed_period, t.o, t.order_id
- Inner Unique: true
- Hash Cond: ((t.o).period_id = p.id)
- Buffers: shared hit=3999
- -> WindowAgg (cost=368.21..368.32 rows=6 width=228) (actual time=31.797..31.802 rows=2 loops=1)
- Output: sum(t.group_suma) OVER (?), t.group_cost, t.group_suma, t.consumed, t.consumed_period, t.o, t.order_id
- Buffers: shared hit=759
- -> Sort (cost=368.21..368.23 rows=6 width=220) (actual time=31.790..31.791 rows=2 loops=1)
- Output: t.order_id, t.group_suma, t.group_cost, t.consumed, t.consumed_period, t.o
- Sort Key: t.order_id
- Sort Method: quicksort Memory: 25kB
- Buffers: shared hit=759
- -> Subquery Scan on t (cost=350.52..368.14 rows=6 width=220) (actual time=31.768..31.776 rows=2 loops=1)
- Output: t.order_id, t.group_suma, t.group_cost, t.consumed, t.consumed_period, t.o
- Buffers: shared hit=759
- -> GroupAggregate (cost=350.52..368.08 rows=6 width=220) (actual time=31.766..31.774 rows=2 loops=1)
- Output: sum(cis.item_cost), sum(cis.item_suma), max(ic.consumed), ic.consumed_period, o.*, o.id
- Group Key: o.*, o.id, ic.consumed_period
- Buffers: shared hit=759
- -> Sort (cost=350.52..353.02 rows=1000 width=220) (actual time=31.717..31.718 rows=10 loops=1)
- Output: ic.consumed_period, o.*, o.id, cis.item_cost, cis.item_suma, ic.consumed
- Sort Key: o.*, o.id, ic.consumed_period
- Sort Method: quicksort Memory: 27kB
- Buffers: shared hit=750
- -> Nested Loop Left Join (cost=43.38..300.69 rows=1000 width=220) (actual time=6.397..31.619 rows=10 loops=1)
- Output: ic.consumed_period, o.*, o.id, cis.item_cost, cis.item_suma, ic.consumed
- Buffers: shared hit=743
- -> Nested Loop Left Join (cost=43.13..280.44 rows=1 width=421) (actual time=5.986..16.317 rows=10 loops=1)
- Output: o.*, o.id, od.*, sp.*, ic.consumed, ic.consumed_period, ic.*
- Buffers: shared hit=263
- -> Nested Loop Left Join (cost=42.05..271.19 rows=1 width=392) (actual time=5.622..15.414 rows=10 loops=1)
- Output: o.*, o.id, o.app_period, split_period.split_period, od.app_period, od.*, sp.*
- Join Filter: (od.service_type_id = sp.service_type_id)
- Rows Removed by Join Filter: 643
- Buffers: shared hit=234
- -> Nested Loop (cost=41.80..258.38 rows=1 width=372) (actual time=2.258..5.545 rows=10 loops=1)
- Output: o.*, o.id, o.service_level_id, o.app_period, o.period_id, split_period.split_period, od.app_period, od.*, od.service_type_id
- Join Filter: ((od.app_period * o.app_period) && split_period.split_period)
- Rows Removed by Join Filter: 3
- Buffers: shared hit=87
- -> Nested Loop (cost=41.52..241.65 rows=1 width=226) (actual time=2.203..5.048 rows=2 loops=1)
- Output: o.*, o.id, o.service_level_id, o.app_period, o.period_id, split_period.split_period
- Buffers: shared hit=72
- -> Bitmap Heap Scan on public.order_bt o (cost=8.61..29.24 rows=6 width=194) (actual time=0.139..0.156 rows=6 loops=1)
- Output: o.*, o.id, o.service_level_id, o.app_period, o.period_id
- Recheck Cond: ((o.id = ANY ('{6154,10805}'::integer[])) AND (o.sys_period @> sys_time()))
- Heap Blocks: exact=2
- Buffers: shared hit=6
- -> Bitmap Index Scan on order_id_sys_period_app_period_excl (cost=0.00..8.61 rows=6 width=0) (actual time=0.114..0.114 rows=6 loops=1)
- Index Cond: ((o.id = ANY ('{6154,10805}'::integer[])) AND (o.sys_period @> sys_time()))
- Buffers: shared hit=4
- -> Subquery Scan on split_period (cost=32.91..35.39 rows=1 width=32) (actual time=0.811..0.813 rows=0 loops=6)
- Output: split_period.split_period
- Filter: ((o.app_period * app_period()) && split_period.split_period)
- Rows Removed by Filter: 1
- Buffers: shared hit=66
- -> Subquery Scan on x (cost=32.91..33.27 rows=8 width=32) (actual time=0.759..0.763 rows=1 loops=6)
- Output: x.app_period
- Filter: (x.boundary IS NOT NULL)
- Rows Removed by Filter: 1
- Buffers: shared hit=66
- CTE ranges
- -> HashAggregate (cost=32.37..32.41 rows=4 width=32) (actual time=0.732..0.732 rows=1 loops=6)
- Output: ((o_3.app_period * app_period()))
- Group Key: ((o_3.app_period * app_period()))
- Buffers: shared hit=63
- -> Append (cost=0.65..32.36 rows=4 width=32) (actual time=0.152..0.721 rows=6 loops=6)
- Buffers: shared hit=63
- -> Index Only Scan using order_id_sys_period_app_period_excl on public.order_bt o_3 (cost=0.65..13.20 rows=2 width=32) (actual time=0.079..0.080 rows=1 loops=6)
- Output: (o_3.app_period * app_period())
- Index Cond: ((o_3.id = $18) AND (o_3.sys_period @> sys_time()) AND (o_3.app_period && app_period()))
- Heap Fetches: 6
- Buffers: shared hit=18
- -> Index Scan using order_detail_idx_order_id on public.order_detail_bt od_3 (cost=0.29..19.13 rows=2 width=32) (actual time=0.172..0.564 rows=5 loops=6)
- Output: (od_3.app_period * app_period())
- Index Cond: (od_3.order_id = $18)
- Filter: ((od_3.sys_period @> sys_time()) AND (od_3.app_period && app_period()))
- Rows Removed by Filter: 10
- Buffers: shared hit=45
- CTE points
- -> Sort (cost=0.48..0.50 rows=8 width=8) (actual time=0.752..0.752 rows=2 loops=6)
- Output: (lower(ranges_2.app_period))
- Sort Key: (lower(ranges_2.app_period))
- Sort Method: quicksort Memory: 25kB
- Buffers: shared hit=66
- -> HashAggregate (cost=0.28..0.36 rows=8 width=8) (actual time=0.740..0.741 rows=2 loops=6)
- Output: (lower(ranges_2.app_period))
- Group Key: (lower(ranges_2.app_period))
- Buffers: shared hit=63
- -> Append (cost=0.00..0.26 rows=8 width=8) (actual time=0.735..0.738 rows=2 loops=6)
- Buffers: shared hit=63
- -> CTE Scan on ranges ranges_2 (cost=0.00..0.09 rows=4 width=8) (actual time=0.735..0.735 rows=1 loops=6)
- Output: lower(ranges_2.app_period)
- Buffers: shared hit=63
- -> CTE Scan on ranges ranges_3 (cost=0.00..0.09 rows=4 width=8) (actual time=0.001..0.001 rows=1 loops=6)
- Output: upper(ranges_3.app_period)
- -> WindowAgg (cost=0.00..0.28 rows=8 width=40) (actual time=0.758..0.761 rows=2 loops=6)
- Output: tstzrange(points.point, lead(points.point) OVER (?)), lead(points.point) OVER (?)
- Buffers: shared hit=66
- -> CTE Scan on points (cost=0.00..0.16 rows=8 width=8) (actual time=0.753..0.755 rows=2 loops=6)
- Output: points.point
- Buffers: shared hit=66
- -> Index Scan using order_detail_idx_order_id on public.order_detail_bt od (cost=0.29..16.69 rows=2 width=150) (actual time=0.115..0.233 rows=6 loops=2)
- Output: od.app_period, od.*, od.order_id, od.service_type_id
- Index Cond: (od.order_id = o.id)
- Filter: (od.sys_period @> sys_time())
- Rows Removed by Filter: 8
- Buffers: shared hit=15
- -> Function Scan on public.service_level_price sp (cost=0.25..12.75 rows=5 width=40) (actual time=0.938..0.975 rows=65 loops=10)
- Output: sp.*, sp.service_type_id, sp.period_id
- Function Call: service_level_price(o.service_level_id)
- Filter: (o.period_id = sp.period_id)
- Rows Removed by Filter: 38
- Buffers: shared hit=147
- -> Subquery Scan on ic (cost=1.07..9.24 rows=1 width=104) (actual time=0.087..0.088 rows=1 loops=10)
- Output: ic.consumed, ic.consumed_period, ic.*
- Buffers: shared hit=29
- -> Nested Loop Left Join (cost=1.07..9.23 rows=1 width=72) (actual time=0.085..0.085 rows=1 loops=10)
- Output: ROW(cr.id, cr.rate, cr.docdate, cr.from_currency_id, cr.to_currency_id, cr.app_period)::currency_rate, interval_length(((od.app_period * o.app_period) * split_period.split_period), $22), COALESCE(((od.app_period * o.app_period) * split_period.split_period), ((od.app_period * o.app_period) * split_period.split_period))
- Buffers: shared hit=29
- InitPlan 7 (returns $22)
- -> Seq Scan on public.period period_1 (cost=0.00..1.07 rows=1 width=16) (actual time=0.004..0.005 rows=1 loops=10)
- Output: period_1."interval"
- Filter: (period_1.id = ($21).period_id)
- Rows Removed by Filter: 5
- Buffers: shared hit=10
- -> Result (cost=0.00..0.01 rows=1 width=4) (actual time=0.000..0.001 rows=1 loops=10)
- Output: NULL::integer
- -> Seq Scan on public.currency_rate_bt cr (cost=0.00..7.86 rows=1 width=56) (actual time=0.045..0.045 rows=0 loops=10)
- Output: cr.id, cr.rate, cr.docdate, cr.from_currency_id, cr.to_currency_id, cr.sid, cr.app_period, cr.sys_period
- Filter: ((cr.from_currency_id = (sp.*).currency_id) AND (cr.app_period @> lower(((od.app_period * o.app_period) * split_period.split_period))) AND (cr.sys_period @> sys_time()) AND (cr.to_currency_id = app_currency()))
- Rows Removed by Filter: 13
- Buffers: shared hit=10
- -> Function Scan on public.calc_item_suma cis (cost=0.25..10.25 rows=1000 width=16) (actual time=1.527..1.527 rows=1 loops=10)
- Output: cis.item_qty, cis.item_price, cis.item_cost, cis.item_suma
- Function Call: calc_item_suma(o.*, od.*, sp.*, ic.*)
- Buffers: shared hit=480
- -> Hash (cost=1.06..1.06 rows=6 width=20) (actual time=0.009..0.009 rows=6 loops=1)
- Output: p."interval", p.id
- Buckets: 1024 Batches: 1 Memory Usage: 9kB
- Buffers: shared hit=1
- -> Seq Scan on public.period p (cost=0.00..1.06 rows=6 width=20) (actual time=0.005..0.006 rows=6 loops=1)
- Output: p."interval", p.id
- Buffers: shared hit=1
- SubPlan 4
- -> Subquery Scan on next_ots (cost=193.93..211.57 rows=1 width=244) (actual time=51.997..51.998 rows=1 loops=2)
- Output: next_ots.*
- Filter: (next_ots.consumed_period @> (t.o).billed_to)
- Rows Removed by Filter: 2
- Buffers: shared hit=3239
- -> WindowAgg (cost=193.93..211.53 rows=3 width=228) (actual time=51.989..51.991 rows=4 loops=2)
- Output: sum((sum(cis_1.item_suma))) OVER (?), (sum(cis_1.item_cost)), (sum(cis_1.item_suma)), (max(ic_1.consumed)), ic_1.consumed_period, o_2.*, o_2.id
- Buffers: shared hit=3239
- -> GroupAggregate (cost=193.93..211.46 rows=3 width=220) (actual time=51.956..51.977 rows=4 loops=2)
- Output: sum(cis_1.item_cost), sum(cis_1.item_suma), max(ic_1.consumed), ic_1.consumed_period, o_2.*, o_2.id
- Group Key: o_2.*, o_2.id, ic_1.consumed_period
- Buffers: shared hit=3239
- -> Sort (cost=193.93..196.43 rows=1000 width=220) (actual time=51.942..51.944 rows=18 loops=2)
- Output: ic_1.consumed_period, o_2.*, o_2.id, cis_1.item_cost, cis_1.item_suma, ic_1.consumed
- Sort Key: o_2.*, ic_1.consumed_period
- Sort Method: quicksort Memory: 27kB
- Buffers: shared hit=3239
- -> Nested Loop Left Join (cost=28.89..144.10 rows=1000 width=220) (actual time=5.566..51.884 rows=18 loops=2)
- Output: ic_1.consumed_period, o_2.*, o_2.id, cis_1.item_cost, cis_1.item_suma, ic_1.consumed
- Buffers: shared hit=3239
- -> Nested Loop Left Join (cost=28.64..123.85 rows=1 width=421) (actual time=5.509..19.876 rows=18 loops=2)
- Output: o_2.*, o_2.id, od_2.*, sp_1.*, ic_1.consumed, ic_1.consumed_period, ic_1.*
- Buffers: shared hit=1186
- -> Nested Loop Left Join (cost=27.57..114.60 rows=1 width=392) (actual time=5.113..17.561 rows=18 loops=2)
- Output: o_2.*, o_2.id, o_2.app_period, split_period_1.split_period, od_2.app_period, od_2.*, sp_1.*
- Join Filter: (od_2.service_type_id = sp_1.service_type_id)
- Rows Removed by Join Filter: 1123
- Buffers: shared hit=999
- -> Nested Loop (cost=27.32..101.79 rows=1 width=372) (actual time=4.347..6.992 rows=18 loops=2)
- Output: o_2.*, o_2.id, o_2.service_level_id, o_2.app_period, o_2.period_id, split_period_1.split_period, od_2.app_period, od_2.*, od_2.service_type_id
- Join Filter: ((od_2.app_period * o_2.app_period) && split_period_1.split_period)
- Rows Removed by Join Filter: 8
- Buffers: shared hit=859
- -> Nested Loop (cost=27.03..84.15 rows=1 width=226) (actual time=4.274..6.384 rows=4 loops=2)
- Output: o_2.*, o_2.id, o_2.service_level_id, o_2.app_period, o_2.period_id, split_period_1.split_period
- Buffers: shared hit=802
- -> Bitmap Heap Scan on public.order_bt o_2 (cost=4.43..15.47 rows=3 width=194) (actual time=0.044..0.050 rows=3 loops=2)
- Output: o_2.*, o_2.id, o_2.service_level_id, o_2.app_period, o_2.period_id
- Recheck Cond: ((o_2.id = t.order_id) AND (o_2.sys_period @> sys_time()))
- Heap Blocks: exact=3
- Buffers: shared hit=7
- -> Bitmap Index Scan on order_id_sys_period_app_period_excl (cost=0.00..4.43 rows=3 width=0) (actual time=0.015..0.015 rows=3 loops=2)
- Index Cond: ((o_2.id = t.order_id) AND (o_2.sys_period @> sys_time()))
- Buffers: shared hit=4
- -> Subquery Scan on split_period_1 (cost=22.60..22.88 rows=1 width=32) (actual time=2.096..2.107 rows=1 loops=6)
- Output: split_period_1.split_period
- Filter: ((o_2.app_period * tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone))) && split_period_1.split_period)
- Rows Removed by Filter: 2
- Buffers: shared hit=795
- -> Subquery Scan on x_1 (cost=22.60..22.78 rows=4 width=32) (actual time=2.088..2.098 rows=4 loops=6)
- Output: x_1.app_period
- Filter: (x_1.boundary IS NOT NULL)
- Rows Removed by Filter: 1
- Buffers: shared hit=795
- CTE ranges
- -> Unique (cost=22.36..22.37 rows=2 width=32) (actual time=2.059..2.062 rows=5 loops=6)
- Output: ((o_1.app_period * tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone))))
- Buffers: shared hit=795
- -> Sort (cost=22.36..22.37 rows=2 width=32) (actual time=2.058..2.058 rows=8 loops=6)
- Output: ((o_1.app_period * tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone))))
- Sort Key: ((o_1.app_period * tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone))))
- Sort Method: quicksort Memory: 25kB
- Buffers: shared hit=795
- -> Append (cost=0.41..22.35 rows=2 width=32) (actual time=0.039..2.049 rows=8 loops=6)
- Buffers: shared hit=795
- -> Index Only Scan using order_id_sys_period_app_period_excl on public.order_bt o_1 (cost=0.41..8.44 rows=1 width=32) (actual time=0.019..0.021 rows=2 loops=6)
- Output: (o_1.app_period * tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone)))
- Index Cond: ((o_1.id = $3) AND (o_1.sys_period @> sys_time()) AND (o_1.app_period && tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone))))
- Heap Fetches: 12
- Buffers: shared hit=21
- -> Bitmap Heap Scan on public.order_detail_bt od_1 (cost=9.60..13.89 rows=1 width=32) (actual time=1.993..2.003 rows=6 loops=6)
- Output: (od_1.app_period * tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone)))
- Recheck Cond: ((od_1.order_id = $3) AND (od_1.sys_period @> sys_time()) AND (od_1.app_period && tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone))))
- Heap Blocks: exact=24
- Buffers: shared hit=774
- -> BitmapAnd (cost=9.60..9.60 rows=1 width=0) (actual time=1.972..1.972 rows=0 loops=6)
- Buffers: shared hit=750
- -> Bitmap Index Scan on order_detail_idx_order_id (cost=0.00..4.32 rows=4 width=0) (actual time=0.007..0.007 rows=14 loops=6)
- Index Cond: (od_1.order_id = $3)
- Buffers: shared hit=12
- -> Bitmap Index Scan on order_detail_bt_id_sys_period_app_period_excl (cost=0.00..5.04 rows=50 width=0) (actual time=1.955..1.955 rows=4114 loops=6)
- Index Cond: ((od_1.sys_period @> sys_time()) AND (od_1.app_period && tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone))))
- Buffers: shared hit=738
- CTE points
- -> Sort (cost=0.22..0.23 rows=4 width=8) (actual time=2.081..2.082 rows=4 loops=6)
- Output: (lower(ranges.app_period))
- Sort Key: (lower(ranges.app_period))
- Sort Method: quicksort Memory: 25kB
- Buffers: shared hit=795
- -> HashAggregate (cost=0.14..0.18 rows=4 width=8) (actual time=2.075..2.076 rows=4 loops=6)
- Output: (lower(ranges.app_period))
- Group Key: (lower(ranges.app_period))
- Buffers: shared hit=795
- -> Append (cost=0.00..0.13 rows=4 width=8) (actual time=2.061..2.069 rows=10 loops=6)
- Buffers: shared hit=795
- -> CTE Scan on ranges (cost=0.00..0.04 rows=2 width=8) (actual time=2.061..2.065 rows=5 loops=6)
- Output: lower(ranges.app_period)
- Buffers: shared hit=795
- -> CTE Scan on ranges ranges_1 (cost=0.00..0.04 rows=2 width=8) (actual time=0.001..0.002 rows=5 loops=6)
- Output: upper(ranges_1.app_period)
- -> WindowAgg (cost=0.00..0.14 rows=4 width=40) (actual time=2.087..2.095 rows=4 loops=6)
- Output: tstzrange(points_1.point, lead(points_1.point) OVER (?)), lead(points_1.point) OVER (?)
- Buffers: shared hit=795
- -> CTE Scan on points points_1 (cost=0.00..0.08 rows=4 width=8) (actual time=2.083..2.086 rows=4 loops=6)
- Output: points_1.point
- Buffers: shared hit=795
- -> Index Scan using order_detail_idx_order_id on public.order_detail_bt od_2 (cost=0.29..17.61 rows=2 width=150) (actual time=0.050..0.162 rows=7 loops=7)
- Output: od_2.app_period, od_2.*, od_2.order_id, od_2.service_type_id
- Index Cond: (od_2.order_id = t.order_id)
- Filter: (od_2.sys_period @> sys_time())
- Rows Removed by Filter: 6
- Buffers: shared hit=57
- -> Function Scan on public.service_level_price sp_1 (cost=0.25..12.75 rows=5 width=40) (actual time=0.561..0.594 rows=65 loops=35)
- Output: sp_1.*, sp_1.service_type_id, sp_1.period_id
- Function Call: service_level_price(o_2.service_level_id)
- Filter: (o_2.period_id = sp_1.period_id)
- Rows Removed by Filter: 38
- Buffers: shared hit=140
- -> Subquery Scan on ic_1 (cost=1.07..9.24 rows=1 width=104) (actual time=0.128..0.130 rows=1 loops=35)
- Output: ic_1.consumed, ic_1.consumed_period, ic_1.*
- Buffers: shared hit=187
- -> Nested Loop Left Join (cost=1.07..9.23 rows=1 width=72) (actual time=0.126..0.128 rows=1 loops=35)
- Output: ROW(cr_1.id, cr_1.rate, cr_1.docdate, cr_1.from_currency_id, cr_1.to_currency_id, cr_1.app_period)::currency_rate, interval_length(((od_2.app_period * o_2.app_period) * split_period_1.split_period), $7), COALESCE(((od_2.app_period * o_2.app_period) * split_period_1.split_period), ((od_2.app_period * o_2.app_period) * split_period_1.split_period))
- Buffers: shared hit=187
- InitPlan 3 (returns $7)
- -> Seq Scan on public.period (cost=0.00..1.07 rows=1 width=16) (actual time=0.003..0.004 rows=1 loops=35)
- Output: period."interval"
- Filter: (period.id = ($6).period_id)
- Rows Removed by Filter: 5
- Buffers: shared hit=35
- -> Result (cost=0.00..0.01 rows=1 width=4) (actual time=0.000..0.000 rows=1 loops=35)
- Output: NULL::integer
- -> Seq Scan on public.currency_rate_bt cr_1 (cost=0.00..7.86 rows=1 width=56) (actual time=0.053..0.055 rows=1 loops=35)
- Output: cr_1.id, cr_1.rate, cr_1.docdate, cr_1.from_currency_id, cr_1.to_currency_id, cr_1.sid, cr_1.app_period, cr_1.sys_period
- Filter: ((cr_1.from_currency_id = (sp_1.*).currency_id) AND (cr_1.app_period @> lower(((od_2.app_period * o_2.app_period) * split_period_1.split_period))) AND (cr_1.sys_period @> sys_time()) AND (cr_1.to_currency_id = app_currency()))
- Rows Removed by Filter: 12
- Buffers: shared hit=35
- -> Function Scan on public.calc_item_suma cis_1 (cost=0.25..10.25 rows=1000 width=16) (actual time=1.827..1.827 rows=1 loops=35)
- Output: cis_1.item_qty, cis_1.item_price, cis_1.item_cost, cis_1.item_suma
- Function Call: calc_item_suma(o_2.*, od_2.*, sp_1.*, ic_1.*)
- Buffers: shared hit=2053
- Planning time: 7.571 ms
- Execution time: 137.647 ms
- (289 rows)
- QUERY PLAN
- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Nested Loop Left Join (cost=64607.17..386057.18 rows=6 width=260) (actual time=11007.771..22086.976 rows=2 loops=1)
- Output: tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone)), (sum(t.group_suma) OVER (?)), t.group_cost, t.group_suma, t.consumed, t.consumed_period, t.o, t.order_id
- Buffers: shared hit=842575
- -> Nested Loop Left Join (cost=368.21..369.93 rows=6 width=244) (actual time=29.214..29.232 rows=2 loops=1)
- Output: t.o, (sum(t.group_suma) OVER (?)), t.group_cost, t.group_suma, t.consumed, t.consumed_period, t.order_id, p."interval"
- Inner Unique: true
- Join Filter: (p.id = (t.o).period_id)
- Buffers: shared hit=582
- -> WindowAgg (cost=368.21..368.32 rows=6 width=228) (actual time=29.203..29.217 rows=2 loops=1)
- Output: sum(t.group_suma) OVER (?), t.group_cost, t.group_suma, t.consumed, t.consumed_period, t.o, t.order_id
- Buffers: shared hit=581
- -> Sort (cost=368.21..368.23 rows=6 width=220) (actual time=29.198..29.198 rows=2 loops=1)
- Output: t.order_id, t.group_suma, t.group_cost, t.consumed, t.consumed_period, t.o
- Sort Key: t.order_id
- Sort Method: quicksort Memory: 25kB
- Buffers: shared hit=581
- -> Subquery Scan on t (cost=350.52..368.14 rows=6 width=220) (actual time=29.182..29.190 rows=2 loops=1)
- Output: t.order_id, t.group_suma, t.group_cost, t.consumed, t.consumed_period, t.o
- Buffers: shared hit=581
- -> GroupAggregate (cost=350.52..368.08 rows=6 width=220) (actual time=29.180..29.188 rows=2 loops=1)
- Output: sum(cis.item_cost), sum(cis.item_suma), max(ic.consumed), ic.consumed_period, o.*, o.id
- Group Key: o.*, o.id, ic.consumed_period
- Buffers: shared hit=581
- -> Sort (cost=350.52..353.02 rows=1000 width=220) (actual time=29.165..29.166 rows=10 loops=1)
- Output: ic.consumed_period, o.*, o.id, cis.item_cost, cis.item_suma, ic.consumed
- Sort Key: o.*, o.id, ic.consumed_period
- Sort Method: quicksort Memory: 27kB
- Buffers: shared hit=581
- -> Nested Loop Left Join (cost=43.38..300.69 rows=1000 width=220) (actual time=3.893..29.121 rows=10 loops=1)
- Output: ic.consumed_period, o.*, o.id, cis.item_cost, cis.item_suma, ic.consumed
- Buffers: shared hit=581
- -> Nested Loop Left Join (cost=43.13..280.44 rows=1 width=421) (actual time=3.768..14.541 rows=10 loops=1)
- Output: o.*, o.id, od.*, sp.*, ic.consumed, ic.consumed_period, ic.*
- Buffers: shared hit=144
- -> Nested Loop Left Join (cost=42.05..271.19 rows=1 width=392) (actual time=3.579..13.671 rows=10 loops=1)
- Output: o.*, o.id, o.app_period, split_period.split_period, od.app_period, od.*, sp.*
- Join Filter: (od.service_type_id = sp.service_type_id)
- Rows Removed by Join Filter: 643
- Buffers: shared hit=124
- -> Nested Loop (cost=41.80..258.38 rows=1 width=372) (actual time=1.924..4.514 rows=10 loops=1)
- Output: o.*, o.id, o.service_level_id, o.app_period, o.period_id, split_period.split_period, od.app_period, od.*, od.service_type_id
- Join Filter: ((od.app_period * o.app_period) && split_period.split_period)
- Rows Removed by Join Filter: 3
- Buffers: shared hit=84
- -> Nested Loop (cost=41.52..241.65 rows=1 width=226) (actual time=1.877..4.057 rows=2 loops=1)
- Output: o.*, o.id, o.service_level_id, o.app_period, o.period_id, split_period.split_period
- Buffers: shared hit=69
- -> Bitmap Heap Scan on public.order_bt o (cost=8.61..29.24 rows=6 width=194) (actual time=0.087..0.102 rows=6 loops=1)
- Output: o.*, o.id, o.service_level_id, o.app_period, o.period_id
- Recheck Cond: ((o.id = ANY ('{6154,10805}'::integer[])) AND (o.sys_period @> sys_time()))
- Heap Blocks: exact=2
- Buffers: shared hit=6
- -> Bitmap Index Scan on order_id_sys_period_app_period_excl (cost=0.00..8.61 rows=6 width=0) (actual time=0.074..0.074 rows=6 loops=1)
- Index Cond: ((o.id = ANY ('{6154,10805}'::integer[])) AND (o.sys_period @> sys_time()))
- Buffers: shared hit=4
- -> Subquery Scan on split_period (cost=32.91..35.39 rows=1 width=32) (actual time=0.656..0.658 rows=0 loops=6)
- Output: split_period.split_period
- Filter: ((o.app_period * app_period()) && split_period.split_period)
- Rows Removed by Filter: 1
- Buffers: shared hit=63
- -> Subquery Scan on x (cost=32.91..33.27 rows=8 width=32) (actual time=0.618..0.621 rows=1 loops=6)
- Output: x.app_period
- Filter: (x.boundary IS NOT NULL)
- Rows Removed by Filter: 1
- Buffers: shared hit=63
- CTE ranges
- -> HashAggregate (cost=32.37..32.41 rows=4 width=32) (actual time=0.599..0.600 rows=1 loops=6)
- Output: ((o_3.app_period * app_period()))
- Group Key: ((o_3.app_period * app_period()))
- Buffers: shared hit=63
- -> Append (cost=0.65..32.36 rows=4 width=32) (actual time=0.101..0.590 rows=6 loops=6)
- Buffers: shared hit=63
- -> Index Only Scan using order_id_sys_period_app_period_excl on public.order_bt o_3 (cost=0.65..13.20 rows=2 width=32) (actual time=0.052..0.052 rows=1 loops=6)
- Output: (o_3.app_period * app_period())
- Index Cond: ((o_3.id = $10) AND (o_3.sys_period @> sys_time()) AND (o_3.app_period && app_period()))
- Heap Fetches: 6
- Buffers: shared hit=18
- -> Index Scan using order_detail_idx_order_id on public.order_detail_bt od_3 (cost=0.29..19.13 rows=2 width=32) (actual time=0.123..0.486 rows=5 loops=6)
- Output: (od_3.app_period * app_period())
- Index Cond: (od_3.order_id = $10)
- Filter: ((od_3.sys_period @> sys_time()) AND (od_3.app_period && app_period()))
- Rows Removed by Filter: 10
- Buffers: shared hit=45
- CTE points
- -> Sort (cost=0.48..0.50 rows=8 width=8) (actual time=0.612..0.612 rows=2 loops=6)
- Output: (lower(ranges_2.app_period))
- Sort Key: (lower(ranges_2.app_period))
- Sort Method: quicksort Memory: 25kB
- Buffers: shared hit=63
- -> HashAggregate (cost=0.28..0.36 rows=8 width=8) (actual time=0.606..0.606 rows=2 loops=6)
- Output: (lower(ranges_2.app_period))
- Group Key: (lower(ranges_2.app_period))
- Buffers: shared hit=63
- -> Append (cost=0.00..0.26 rows=8 width=8) (actual time=0.602..0.604 rows=2 loops=6)
- Buffers: shared hit=63
- -> CTE Scan on ranges ranges_2 (cost=0.00..0.09 rows=4 width=8) (actual time=0.601..0.602 rows=1 loops=6)
- Output: lower(ranges_2.app_period)
- Buffers: shared hit=63
- -> CTE Scan on ranges ranges_3 (cost=0.00..0.09 rows=4 width=8) (actual time=0.001..0.001 rows=1 loops=6)
- Output: upper(ranges_3.app_period)
- -> WindowAgg (cost=0.00..0.28 rows=8 width=40) (actual time=0.617..0.620 rows=2 loops=6)
- Output: tstzrange(points.point, lead(points.point) OVER (?)), lead(points.point) OVER (?)
- Buffers: shared hit=63
- -> CTE Scan on points (cost=0.00..0.16 rows=8 width=8) (actual time=0.613..0.614 rows=2 loops=6)
- Output: points.point
- Buffers: shared hit=63
- -> Index Scan using order_detail_idx_order_id on public.order_detail_bt od (cost=0.29..16.69 rows=2 width=150) (actual time=0.068..0.214 rows=6 loops=2)
- Output: od.app_period, od.*, od.order_id, od.service_type_id
- Index Cond: (od.order_id = o.id)
- Filter: (od.sys_period @> sys_time())
- Rows Removed by Filter: 8
- Buffers: shared hit=15
- -> Function Scan on public.service_level_price sp (cost=0.25..12.75 rows=5 width=40) (actual time=0.854..0.902 rows=65 loops=10)
- Output: sp.*, sp.service_type_id, sp.period_id
- Function Call: service_level_price(o.service_level_id)
- Filter: (o.period_id = sp.period_id)
- Rows Removed by Filter: 38
- Buffers: shared hit=40
- -> Subquery Scan on ic (cost=1.07..9.24 rows=1 width=104) (actual time=0.084..0.084 rows=1 loops=10)
- Output: ic.consumed, ic.consumed_period, ic.*
- Buffers: shared hit=20
- -> Nested Loop Left Join (cost=1.07..9.23 rows=1 width=72) (actual time=0.081..0.082 rows=1 loops=10)
- Output: ROW(cr.id, cr.rate, cr.docdate, cr.from_currency_id, cr.to_currency_id, cr.app_period)::currency_rate, interval_length(((od.app_period * o.app_period) * split_period.split_period), $14), COALESCE(((od.app_period * o.app_period) * split_period.split_period), ((od.app_period * o.app_period) * split_period.split_period))
- Buffers: shared hit=20
- InitPlan 6 (returns $14)
- -> Seq Scan on public.period period_1 (cost=0.00..1.07 rows=1 width=16) (actual time=0.004..0.005 rows=1 loops=10)
- Output: period_1."interval"
- Filter: (period_1.id = ($13).period_id)
- Rows Removed by Filter: 5
- Buffers: shared hit=10
- -> Result (cost=0.00..0.01 rows=1 width=4) (actual time=0.000..0.000 rows=1 loops=10)
- Output: NULL::integer
- -> Seq Scan on public.currency_rate_bt cr (cost=0.00..7.86 rows=1 width=56) (actual time=0.056..0.056 rows=0 loops=10)
- Output: cr.id, cr.rate, cr.docdate, cr.from_currency_id, cr.to_currency_id, cr.sid, cr.app_period, cr.sys_period
- Filter: ((cr.from_currency_id = (sp.*).currency_id) AND (cr.app_period @> lower(((od.app_period * o.app_period) * split_period.split_period))) AND (cr.sys_period @> sys_time()) AND (cr.to_currency_id = app_currency()))
- Rows Removed by Filter: 13
- Buffers: shared hit=10
- -> Function Scan on public.calc_item_suma cis (cost=0.25..10.25 rows=1000 width=16) (actual time=1.455..1.455 rows=1 loops=10)
- Output: cis.item_qty, cis.item_price, cis.item_cost, cis.item_suma
- Function Call: calc_item_suma(o.*, od.*, sp.*, ic.*)
- Buffers: shared hit=437
- -> Materialize (cost=0.00..1.09 rows=6 width=20) (actual time=0.004..0.004 rows=1 loops=2)
- Output: p."interval", p.id
- Buffers: shared hit=1
- -> Seq Scan on public.period p (cost=0.00..1.06 rows=6 width=20) (actual time=0.005..0.005 rows=1 loops=1)
- Output: p."interval", p.id
- Buffers: shared hit=1
- -> Subquery Scan on next_ots (cost=64238.95..64281.19 rows=1 width=36) (actual time=11025.949..11028.858 rows=1 loops=2)
- Output: next_ots.total_suma, next_ots.group_cost, next_ots.group_suma, next_ots.consumed, next_ots.consumed_period, next_ots.o, next_ots.order_id
- Filter: ((next_ots.consumed_period @> (t.o).billed_to) AND (next_ots.order_id = t.order_id))
- Rows Removed by Filter: 1722
- Buffers: shared hit=841993
- -> Subquery Scan on t_1 (cost=64238.95..64267.37 rows=921 width=100) (actual time=11020.538..11028.340 rows=1722 loops=2)
- Output: NULL::double precision, NULL::double precision, NULL::double precision, NULL::double precision, t_1.consumed_period, NULL::order_bt, t_1.order_id
- Buffers: shared hit=841993
- -> GroupAggregate (cost=64238.95..64258.16 rows=921 width=220) (actual time=11020.536..11027.952 rows=1722 loops=2)
- Output: NULL::double precision, NULL::double precision, NULL::double precision, ic_1.consumed_period, o_1.*, o_1.id
- Group Key: o_1.*, o_1.id, ic_1.consumed_period
- Buffers: shared hit=841993
- -> Sort (cost=64238.95..64241.45 rows=1000 width=196) (actual time=11020.481..11020.916 rows=5654 loops=2)
- Output: ic_1.consumed_period, o_1.*, o_1.id
- Sort Key: o_1.*, o_1.id, ic_1.consumed_period
- Sort Method: quicksort Memory: 1730kB
- Buffers: shared hit=841993
- -> Nested Loop Left Join (cost=24.86..64189.12 rows=1000 width=196) (actual time=3.107..10972.879 rows=5654 loops=2)
- Output: ic_1.consumed_period, o_1.*, o_1.id
- Buffers: shared hit=841993
- -> Nested Loop Left Join (cost=24.61..64168.87 rows=1 width=405) (actual time=3.045..10211.572 rows=5654 loops=2)
- Output: o_1.*, o_1.id, od_1.*, sp_1.*, ic_1.consumed_period, ic_1.*
- Buffers: shared hit=808763
- -> Nested Loop Left Join (cost=23.54..64159.63 rows=1 width=392) (actual time=2.955..9624.922 rows=5654 loops=2)
- Output: o_1.*, o_1.id, o_1.app_period, split_period_1.split_period, od_1.app_period, od_1.*, sp_1.*
- Join Filter: (od_1.service_type_id = sp_1.service_type_id)
- Rows Removed by Join Filter: 321286
- Buffers: shared hit=786149
- -> Nested Loop (cost=23.29..64146.81 rows=1 width=372) (actual time=2.306..6160.228 rows=5652 loops=2)
- Output: o_1.*, o_1.id, o_1.service_level_id, o_1.app_period, o_1.period_id, split_period_1.split_period, od_1.app_period, od_1.*, od_1.service_type_id
- Join Filter: ((od_1.app_period * o_1.app_period) && split_period_1.split_period)
- Rows Removed by Join Filter: 1620
- Buffers: shared hit=741197
- -> Nested Loop (cost=23.00..64055.95 rows=56 width=226) (actual time=2.241..5958.286 rows=1926 loops=2)
- Output: o_1.*, o_1.id, o_1.service_level_id, o_1.app_period, o_1.period_id, split_period_1.split_period
- Buffers: shared hit=719239
- -> Index Scan using order_id_sys_period_app_period_excl on public.order_bt o_1 (cost=0.40..504.98 rows=2776 width=194) (actual time=0.034..8.911 rows=2775 loops=2)
- Output: o_1.*, o_1.id, o_1.service_level_id, o_1.app_period, o_1.period_id
- Index Cond: (o_1.sys_period @> sys_time())
- Buffers: shared hit=1636
- -> Subquery Scan on split_period_1 (cost=22.60..22.88 rows=1 width=32) (actual time=2.138..2.142 rows=1 loops=5550)
- Output: split_period_1.split_period
- Filter: ((o_1.app_period * tstzrange(NULLIF((t.o).billed_to, 'infinity'::timestamp with time zone), NULLIF(((t.o).billed_to + p."interval"), 'infinity'::timestamp with time zone))) && split_period_1.split_period)
- Rows Removed by Filter: 1
- Buffers: shared hit=717603
- -> Subquery Scan on x_1 (cost=22.60..22.78 rows=4 width=32) (actual time=2.133..2.137 rows=2 loops=5550)
- Output: x_1.app_period
- Filter: (x_1.boundary IS NOT NULL)
- Rows Removed by Filter: 1
- Buffers: shared hit=717603
- CTE ranges
- -> Unique (cost=22.36..22.37 rows=2 width=32) (actual time=2.110..2.112 rows=3 loops=5550)
- Output: ((o_2.app_period * tstzrange(NULLIF(($0).billed_to, 'infinity'::timestamp with time zone), NULLIF((($0).billed_to + $1), 'infinity'::timestamp with time zone))))
- Buffers: shared hit=717603
- -> Sort (cost=22.36..22.37 rows=2 width=32) (actual time=2.109..2.110 rows=5 loops=5550)
- Output: ((o_2.app_period * tstzrange(NULLIF(($0).billed_to, 'infinity'::timestamp with time zone), NULLIF((($0).billed_to + $1), 'infinity'::timestamp with time zone))))
- Sort Key: ((o_2.app_period * tstzrange(NULLIF(($0).billed_to, 'infinity'::timestamp with time zone), NULLIF((($0).billed_to + $1), 'infinity'::timestamp with time zone))))
- Sort Method: quicksort Memory: 25kB
- Buffers: shared hit=717603
- -> Append (cost=0.41..22.35 rows=2 width=32) (actual time=0.035..2.103 rows=5 loops=5550)
- Buffers: shared hit=717603
- -> Index Only Scan using order_id_sys_period_app_period_excl on public.order_bt o_2 (cost=0.41..8.44 rows=1 width=32) (actual time=0.017..0.019 rows=2 loops=5550)
- Output: (o_2.app_period * tstzrange(NULLIF(($0).billed_to, 'infinity'::timestamp with time zone), NULLIF((($0).billed_to + $1), 'infinity'::timestamp with time zone)))
- Index Cond: ((o_2.id = $2) AND (o_2.sys_period @> sys_time()) AND (o_2.app_period && tstzrange(NULLIF(($0).billed_to, 'infinity'::timestamp with time zone), NULLIF((($0).billed_to + $1), 'infinity'::timestamp with time zone))))
- Heap Fetches: 11100
- Buffers: shared hit=17016
- -> Bitmap Heap Scan on public.order_detail_bt od_2 (cost=9.60..13.89 rows=1 width=32) (actual time=2.055..2.061 rows=3 loops=5550)
- Output: (od_2.app_period * tstzrange(NULLIF(($0).billed_to, 'infinity'::timestamp with time zone), NULLIF((($0).billed_to + $1), 'infinity'::timestamp with time zone)))
- Recheck Cond: ((od_2.order_id = $2) AND (od_2.sys_period @> sys_time()) AND (od_2.app_period && tstzrange(NULLIF(($0).billed_to, 'infinity'::timestamp with time zone), NULLIF((($0).billed_to + $1), 'infinity'::timestamp with time zone))))
- Heap Blocks: exact=14103
- Buffers: shared hit=700587
- -> BitmapAnd (cost=9.60..9.60 rows=1 width=0) (actual time=2.031..2.031 rows=0 loops=5550)
- Buffers: shared hit=686484
- -> Bitmap Index Scan on order_detail_idx_order_id (cost=0.00..4.32 rows=4 width=0) (actual time=0.006..0.006 rows=7 loops=5550)
- Index Cond: (od_2.order_id = $2)
- Buffers: shared hit=11214
- -> Bitmap Index Scan on order_detail_bt_id_sys_period_app_period_excl (cost=0.00..5.04 rows=50 width=0) (actual time=2.044..2.044 rows=4114 loops=5490)
- Index Cond: ((od_2.sys_period @> sys_time()) AND (od_2.app_period && tstzrange(NULLIF(($0).billed_to, 'infinity'::timestamp with time zone), NULLIF((($0).billed_to + $1), 'infinity'::timestamp with time zone))))
- Buffers: shared hit=675270
- CTE points
- -> Sort (cost=0.22..0.23 rows=4 width=8) (actual time=2.127..2.128 rows=3 loops=5550)
- Output: (lower(ranges.app_period))
- Sort Key: (lower(ranges.app_period))
- Sort Method: quicksort Memory: 25kB
- Buffers: shared hit=717603
- -> HashAggregate (cost=0.14..0.18 rows=4 width=8) (actual time=2.122..2.122 rows=3 loops=5550)
- Output: (lower(ranges.app_period))
- Group Key: (lower(ranges.app_period))
- Buffers: shared hit=717603
- -> Append (cost=0.00..0.13 rows=4 width=8) (actual time=2.112..2.117 rows=6 loops=5550)
- Buffers: shared hit=717603
- -> CTE Scan on ranges (cost=0.00..0.04 rows=2 width=8) (actual time=2.112..2.115 rows=3 loops=5550)
- Output: lower(ranges.app_period)
- Buffers: shared hit=717603
- -> CTE Scan on ranges ranges_1 (cost=0.00..0.04 rows=2 width=8) (actual time=0.001..0.001 rows=3 loops=5550)
- Output: upper(ranges_1.app_period)
- -> WindowAgg (cost=0.00..0.14 rows=4 width=40) (actual time=2.132..2.136 rows=3 loops=5550)
- Output: tstzrange(points_1.point, lead(points_1.point) OVER (?)), lead(points_1.point) OVER (?)
- Buffers: shared hit=717603
- -> CTE Scan on points points_1 (cost=0.00..0.08 rows=4 width=8) (actual time=2.128..2.130 rows=3 loops=5550)
- Output: points_1.point
- Buffers: shared hit=717603
- -> Index Scan using order_detail_idx_order_id on public.order_detail_bt od_1 (cost=0.29..1.59 rows=2 width=150) (actual time=0.033..0.098 rows=4 loops=3853)
- Output: od_1.app_period, od_1.*, od_1.order_id, od_1.service_type_id
- Index Cond: (od_1.order_id = o_1.id)
- Filter: (od_1.sys_period @> sys_time())
- Rows Removed by Filter: 3
- Buffers: shared hit=21958
- -> Function Scan on public.service_level_price sp_1 (cost=0.25..12.75 rows=5 width=40) (actual time=0.573..0.604 rows=58 loops=11304)
- Output: sp_1.*, sp_1.service_type_id, sp_1.period_id
- Function Call: service_level_price(o_1.service_level_id)
- Filter: (o_1.period_id = sp_1.period_id)
- Rows Removed by Filter: 43
- Buffers: shared hit=44952
- -> Subquery Scan on ic_1 (cost=1.07..9.24 rows=1 width=88) (actual time=0.099..0.102 rows=1 loops=11307)
- Output: ic_1.consumed_period, ic_1.*
- Buffers: shared hit=22614
- -> Nested Loop Left Join (cost=1.07..9.23 rows=1 width=72) (actual time=0.098..0.100 rows=1 loops=11307)
- Output: ROW(cr_1.id, cr_1.rate, cr_1.docdate, cr_1.from_currency_id, cr_1.to_currency_id, cr_1.app_period)::currency_rate, interval_length(((od_1.app_period * o_1.app_period) * split_period_1.split_period), $6), COALESCE(((od_1.app_period * o_1.app_period) * split_period_1.split_period), ((od_1.app_period * o_1.app_period) * split_period_1.split_period))
- Buffers: shared hit=22614
- InitPlan 3 (returns $6)
- -> Seq Scan on public.period (cost=0.00..1.07 rows=1 width=16) (actual time=0.003..0.004 rows=1 loops=11307)
- Output: period."interval"
- Filter: (period.id = ($5).period_id)
- Rows Removed by Filter: 5
- Buffers: shared hit=11307
- -> Result (cost=0.00..0.01 rows=1 width=4) (actual time=0.000..0.000 rows=1 loops=11307)
- Output: NULL::integer
- -> Seq Scan on public.currency_rate_bt cr_1 (cost=0.00..7.86 rows=1 width=56) (actual time=0.045..0.047 rows=1 loops=11307)
- Output: cr_1.id, cr_1.rate, cr_1.docdate, cr_1.from_currency_id, cr_1.to_currency_id, cr_1.sid, cr_1.app_period, cr_1.sys_period
- Filter: ((cr_1.from_currency_id = (sp_1.*).currency_id) AND (cr_1.app_period @> lower(((od_1.app_period * o_1.app_period) * split_period_1.split_period))) AND (cr_1.sys_period @> sys_time()) AND (cr_1.to_currency_id = app_currency()))
- Rows Removed by Filter: 12
- Buffers: shared hit=11307
- -> Function Scan on public.calc_item_suma cis_1 (cost=0.25..10.25 rows=1000 width=0) (actual time=0.133..0.133 rows=1 loops=11307)
- Output: cis_1.item_qty, cis_1.item_price, cis_1.item_cost, cis_1.item_suma
- Function Call: calc_item_suma(o_1.*, od_1.*, sp_1.*, ic_1.*)
- Buffers: shared hit=33230
- Planning time: 6.787 ms
- Execution time: 22087.594 ms
- (286 rows)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement