Here is the querie:
- Code: Select all
SELECT id_player, id_site, str_player_name, tourney_date_start, tourney_no, id_gametype, id_table_type, sum(amt_buyin_curr_conv), sum(amt_fee_curr_conv), amt_bounty_per, tourney_currency, sum(amt_bounty_per_curr_conv), cnt_bounties, cnt_rebuys, amt_rebuy_per, amt_rebuy_per_curr_conv, amt_rebuy, amt_rebuy_curr_conv, cnt_addons, amt_addon, sum(amt_addon_curr_conv), sum(amt_addon_rebuy_curr_conv), sum(amt_buyin_ttl_curr_conv), sum(cnt_tourney_players), val_finish, id_player_results, tourney_date_end, id_tourney_type, flg_sat_seat, amt_addon_per, sum(amt_addon_per_curr_conv), sum(amt_won_curr_conv), date_end_summary, date_start_summary FROM ( SELECT (tourney_hand_player_statistics.id_player) as "id_player", (player_real.id_site) as "id_site", (player.player_name) as "str_player_name", (timezone('UTC', tourney_summary.date_start + INTERVAL '0 HOURS')) as "tourney_date_start", (tourney_summary.tourney_no) as "tourney_no", (tourney_hand_player_statistics.id_gametype) as "id_gametype", (tourney_summary.id_table_type) as "id_table_type", (((case when(tourney_summary.val_curr_conv!=0) then tourney_summary.val_curr_conv * tourney_summary.amt_buyin else 0.0 end))) as "amt_buyin_curr_conv", (( (case when(tourney_summary.val_curr_conv!=0) then tourney_summary.val_curr_conv * tourney_summary.amt_fee else 0.0 end) )) as "amt_fee_curr_conv", (tourney_summary.amt_bounty) as "amt_bounty_per", (tourney_summary.currency) as "tourney_currency", (((case when(tourney_summary.val_curr_conv!=0) then tourney_summary.val_curr_conv * tourney_summary.amt_bounty else 0.0 end))) as "amt_bounty_per_curr_conv", (tourney_results.cnt_bounty) as "cnt_bounties", (tourney_results.cnt_rebuy) as "cnt_rebuys", (tourney_summary.amt_rebuy) as "amt_rebuy_per", ((case when(tourney_summary.val_curr_conv != 0) then tourney_summary.val_curr_conv * tourney_summary.amt_rebuy else 0.0 end)) as "amt_rebuy_per_curr_conv", (tourney_summary.amt_rebuy * tourney_results.cnt_rebuy) as "amt_rebuy", ((case when(tourney_summary.val_curr_conv!=0) then tourney_summary.val_curr_conv * (tourney_summary.amt_rebuy * tourney_results.cnt_rebuy) else 0.0 end)) as "amt_rebuy_curr_conv", (tourney_results.cnt_addon) as "cnt_addons", (tourney_summary.amt_addon * tourney_results.cnt_addon) as "amt_addon", (((case when(tourney_summary.val_curr_conv!=0) then tourney_summary.val_curr_conv * (tourney_summary.amt_addon * tourney_results.cnt_addon) else 0.0 end))) as "amt_addon_curr_conv", (((case when(tourney_summary.val_curr_conv != 0) then tourney_summary.val_curr_conv * (tourney_summary.amt_addon * tourney_results.cnt_addon + tourney_summary.amt_rebuy * tourney_results.cnt_rebuy) else 0.0 end))) as "amt_addon_rebuy_curr_conv", (((case when(tourney_summary.val_curr_conv != 0) then tourney_summary.val_curr_conv * (tourney_summary.amt_buyin + tourney_summary.amt_fee + tourney_summary.amt_rebuy * tourney_results.cnt_rebuy + tourney_summary.amt_addon * tourney_results.cnt_addon + tourney_summary.amt_bounty) else 0.0 end))) as "amt_buyin_ttl_curr_conv", ((tourney_summary.cnt_players)) as "cnt_tourney_players", (tourney_results.val_finish) as "val_finish", (tourney_results.id_player) as "id_player_results", (timezone('UTC', tourney_summary.date_end + INTERVAL '0 HOURS')) as "tourney_date_end", (tourney_summary.id_tourney_type) as "id_tourney_type", (tourney_results.flg_sat_seat) as "flg_sat_seat", (tourney_summary.amt_addon) as "amt_addon_per", (((case when(tourney_summary.val_curr_conv!=0) then tourney_summary.val_curr_conv * tourney_summary.amt_addon else 0.0 end))) as "amt_addon_per_curr_conv", (((case when(tourney_summary.val_curr_conv != 0) then tourney_summary.val_curr_conv * (tourney_results.amt_won + tourney_results.cnt_bounty * tourney_summary.amt_bounty) else 0.0 end))) as "amt_won_curr_conv", (timezone('UTC', tourney_summary.date_end + INTERVAL '-9 HOURS')) as "date_end_summary", (timezone('UTC', tourney_summary.date_start + INTERVAL '-9 HOURS')) as "date_start_summary" FROM tourney_hand_player_statistics, player, tourney_summary, tourney_results , player player_real WHERE (player.id_player = tourney_hand_player_statistics.id_player) AND (tourney_summary.id_tourney = tourney_hand_player_statistics.id_tourney) AND (tourney_results.id_tourney = tourney_hand_player_statistics.id_tourney AND tourney_results.id_player = tourney_hand_player_statistics.id_player) AND (player_real.id_player = tourney_hand_player_statistics.id_player_real) AND (player.id_player = tourney_results.id_player) AND (tourney_results.id_tourney = tourney_summary.id_tourney) AND (player_real.id_player = tourney_results.id_player_real) AND (tourney_results.id_player = (SELECT id_player FROM player WHERE player_name_search='dutchraise72' AND id_site='200')) AND (((tourney_results.id_gametype in(1)))) GROUP BY tourney_summary.id_tourney, tourney_results.amt_won, tourney_results.flg_sat_seat, tourney_results.id_player, tourney_results.val_finish, tourney_results.cnt_addon, tourney_results.cnt_rebuy, tourney_results.cnt_bounty, tourney_summary.id_tourney_type, tourney_summary.date_end, tourney_summary.cnt_players, tourney_summary.amt_addon, tourney_summary.amt_rebuy, tourney_summary.amt_bounty, tourney_summary.amt_fee, tourney_summary.currency, tourney_summary.amt_buyin, tourney_summary.val_curr_conv, tourney_summary.id_table_type, tourney_summary.tourney_no, tourney_summary.date_start, (tourney_hand_player_statistics.id_player), (player_real.id_site), (player.player_name), (timezone('UTC', tourney_summary.date_start + INTERVAL '0 HOURS')), (tourney_summary.tourney_no), (tourney_hand_player_statistics.id_gametype), (tourney_summary.id_table_type), (tourney_summary.amt_bounty), (tourney_summary.currency), (tourney_results.cnt_bounty), (tourney_results.cnt_rebuy), (tourney_summary.amt_rebuy), ((case when(tourney_summary.val_curr_conv != 0) then tourney_summary.val_curr_conv * tourney_summary.amt_rebuy else 0.0 end)), (tourney_summary.amt_rebuy * tourney_results.cnt_rebuy), ((case when(tourney_summary.val_curr_conv!=0) then tourney_summary.val_curr_conv * (tourney_summary.amt_rebuy * tourney_results.cnt_rebuy) else 0.0 end)), (tourney_results.cnt_addon), (tourney_summary.amt_addon * tourney_results.cnt_addon), (tourney_results.val_finish), (tourney_results.id_player), (timezone('UTC', tourney_summary.date_end + INTERVAL '0 HOURS')), (tourney_summary.id_tourney_type), (tourney_results.flg_sat_seat), (tourney_summary.amt_addon), (timezone('UTC', tourney_summary.date_end + INTERVAL '-9 HOURS')), (timezone('UTC', tourney_summary.date_start + INTERVAL '-9 HOURS')) ) AS tnySumGroup GROUP BY id_player, id_site, str_player_name, tourney_date_start, tourney_no, id_gametype, id_table_type, amt_bounty_per, tourney_currency, cnt_bounties, cnt_rebuys, amt_rebuy_per, amt_rebuy_per_curr_conv, amt_rebuy, amt_rebuy_curr_conv, cnt_addons, amt_addon, val_finish, id_player_results, tourney_date_end, id_tourney_type, flg_sat_seat, amt_addon_per, date_end_summary, date_start_summary
And here is the result of the explain analyze.
- Code: Select all
"HashAggregate (cost=78.51..78.54 rows=1 width=613) (actual time=1108053.826..1108067.439 rows=4757 loops=1)"
" -> HashAggregate (cost=78.28..78.42 rows=1 width=114) (actual time=1107981.581..1108026.341 rows=4757 loops=1)"
" InitPlan 1 (returns $0)"
" -> Index Scan using "idx1:player_name_search" on player (cost=0.00..6.28 rows=1 width=4) (actual time=0.030..0.035 rows=1 loops=1)"
" Index Cond: (player_name_search = 'dutchraise72'::text)"
" Filter: (id_site = 200::smallint)"
" -> Nested Loop (cost=19.61..71.91 rows=1 width=114) (actual time=169.469..1104964.144 rows=357035 loops=1)"
" -> Nested Loop (cost=19.61..65.58 rows=1 width=120) (actual time=169.331..1097820.575 rows=357035 loops=1)"
" -> Nested Loop (cost=19.61..59.30 rows=1 width=51) (actual time=169.307..1090745.345 rows=357035 loops=1)"
" -> Nested Loop (cost=19.61..53.02 rows=1 width=42) (actual time=169.277..1084922.194 rows=357035 loops=1)"
" Join Filter: (tourney_hand_player_statistics.id_player_real = tourney_results.id_player_real)"
" -> Index Scan using "tor:idx2-id_player" on tourney_results (cost=0.00..7.75 rows=2 width=28) (actual time=0.066..2733.642 rows=4759 loops=1)"
" Index Cond: (id_player = $0)"
" Filter: (id_gametype = 1)"
" -> Bitmap Heap Scan on tourney_hand_player_statistics (cost=19.61..22.62 rows=1 width=14) (actual time=202.852..225.710 rows=75 loops=4759)"
" Recheck Cond: ((tourney_hand_player_statistics.id_player = $0) AND (tourney_hand_player_statistics.id_tourney = tourney_results.id_tourney))"
" -> BitmapAnd (cost=19.61..19.61 rows=1 width=0) (actual time=197.103..197.103 rows=0 loops=4759)"
" -> Bitmap Index Scan on "thps:idx2-id_player" (cost=0.00..4.27 rows=102 width=0) (actual time=129.650..129.650 rows=357165 loops=4759)"
" Index Cond: (tourney_hand_player_statistics.id_player = $0)"
" -> Bitmap Index Scan on "thps:idx4-id_tourney" (cost=0.00..15.07 rows=742 width=0) (actual time=3.900..3.900 rows=640 loops=4759)"
" Index Cond: (tourney_hand_player_statistics.id_tourney = tourney_results.id_tourney)"
" -> Index Scan using player_primary_key on player (cost=0.00..6.28 rows=1 width=13) (actual time=0.006..0.007 rows=1 loops=357035)"
" Index Cond: (public.player.id_player = $0)"
" -> Index Scan using tourney_summary_primary_key on tourney_summary (cost=0.00..6.27 rows=1 width=77) (actual time=0.009..0.010 rows=1 loops=357035)"
" Index Cond: (tourney_summary.id_tourney = tourney_hand_player_statistics.id_tourney)"
" -> Index Scan using player_primary_key on player player_real (cost=0.00..6.28 rows=1 width=6) (actual time=0.004..0.006 rows=1 loops=357035)"
" Index Cond: (player_real.id_player = tourney_hand_player_statistics.id_player_real)"
"Total runtime: 1108075.386 ms"
There are a few line with more then 4700 loops, That can't be good. What is wrong and why does it not work anymore?
I did re index and vacuum the database.