Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More transaction list query tuning #783

Open
lbeaufort opened this issue Mar 21, 2024 · 2 comments
Open

More transaction list query tuning #783

lbeaufort opened this issue Mar 21, 2024 · 2 comments
Assignees

Comments

@lbeaufort
Copy link
Member

lbeaufort commented Mar 21, 2024

Placeholder ticket

See conversation in Slack: https://fecgov.slack.com/archives/C02TE9RJEBE/p1710974659859459

Business Reason

As a [role], I will be able to [blank] so that I can [business reason]

Acceptance Criteria

If [precedent] When [action] Then [result]

QA Notes

null

DEV Notes

null

Design

null

See full ticket and images here: FECFILE-1405

@lbeaufort
Copy link
Member Author

lbeaufort commented Mar 22, 2024

Example query and explain analyze:

Part 1 of 2 comments (split for Exalate sync):

cost=152720.95..152720.95

SELECT "transactions_transaction"."deleted",
       "transactions_transaction"."committee_account_id",
       "transactions_transaction"."report_id",
       "transactions_transaction"."id",
       "transactions_transaction"."transaction_type_identifier",
       "transactions_transaction"."aggregation_group",
       "transactions_transaction"."parent_transaction_id",
       "transactions_transaction"."debt_id",
       "transactions_transaction"."loan_id",
       "transactions_transaction"."reatt_redes_id",
       "transactions_transaction"."_form_type",
       "transactions_transaction"."transaction_id",
       "transactions_transaction"."entity_type",
       "transactions_transaction"."memo_code",
       "transactions_transaction"."force_itemized",
       "transactions_transaction"."force_unaggregated",
       "transactions_transaction"."created",
       "transactions_transaction"."updated",
       "transactions_transaction"."contact_1_id",
       "transactions_transaction"."contact_2_id",
       "transactions_transaction"."contact_3_id",
       "transactions_transaction"."memo_text_id",
       "transactions_transaction"."schedule_a_id",
       "transactions_transaction"."schedule_b_id",
       "transactions_transaction"."schedule_c_id",
       "transactions_transaction"."schedule_c1_id",
       "transactions_transaction"."schedule_c2_id",
       "transactions_transaction"."schedule_d_id",
       "transactions_transaction"."schedule_e_id",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."transaction_ptr_id",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."parent_transaction_id",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."report_id",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."schedule",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."line_label_order_key",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."_itemized",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."amount",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."date",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."effective_amount",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."aggregate",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."_calendar_ytd_per_election_office",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."back_reference_tran_id_number",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."loan_key",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."loan_payment_to_date",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."incurred_prior",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."payment_prior",
       "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."payment_amount",
       CASE
           WHEN "transactions_transaction"."schedule_d_id" IS NOT NULL THEN ("transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."incurred_prior" - "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."payment_prior")
           ELSE NULL
       END AS "beginning_balance",
       CASE
           WHEN "transactions_transaction"."schedule_d_id" IS NOT NULL THEN ((CASE
                                                                                  WHEN "transactions_transaction"."schedule_d_id" IS NOT NULL THEN ("transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."incurred_prior" - "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."payment_prior")
                                                                                  ELSE NULL
                                                                              END + "transactions_scheduled"."incurred_amount") - "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."payment_amount")
           ELSE NULL
       END AS "balance_at_close",
       CASE
           WHEN "transactions_transaction"."schedule_d_id" IS NOT NULL THEN COALESCE(CASE
                                                                                         WHEN "transactions_transaction"."schedule_d_id" IS NOT NULL THEN ((CASE
                                                                                                                                                                WHEN "transactions_transaction"."schedule_d_id" IS NOT NULL THEN ("transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."incurred_prior" - "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."payment_prior")
                                                                                                                                                                ELSE NULL
                                                                                                                                                            END + "transactions_scheduled"."incurred_amount") - "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."payment_amount")
                                                                                         ELSE NULL
                                                                                     END, 0)
           ELSE NULL
       END AS "balance",
       COALESCE(T5."_itemized", T4."_itemized", "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."_itemized") AS "itemized",
       COALESCE(T4."_calendar_ytd_per_election_office", "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."_calendar_ytd_per_election_office") AS "calendar_ytd_per_election_office"
FROM "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"
INNER JOIN "transactions_transaction" ON ("transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."transaction_ptr_id" = "transactions_transaction"."id")
LEFT OUTER JOIN "transactions_scheduled" ON ("transactions_transaction"."schedule_d_id" = "transactions_scheduled"."id")
LEFT OUTER JOIN "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9" T4 ON ("transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."parent_transaction_id" = T4."transaction_ptr_id")
LEFT OUTER JOIN "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9" T5 ON (T4."parent_transaction_id" = T5."transaction_ptr_id")
WHERE ("transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."report_id" = f871b1b2-166e-4a96-859c-8e225d51dc47
       AND "transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9"."schedule" IN (A))
ORDER BY "transactions_transaction"."created" DESC
LIMIT 5
556.9770000000001ms
4 joins
Query PlanLimit  (cost=152720.95..152720.95 rows=1 width=897)
  ->  Sort  (cost=152720.95..152720.95 rows=1 width=897)
        Sort Key: transactions_transaction.created DESC
        ->  Nested Loop Left Join  (cost=1315.75..152720.94 rows=1 width=897)
              Join Filter: (transactions_transaction_2.parent_transaction_id = transactions_transaction_3.id)
              ->  Nested Loop Left Join  (cost=989.89..152184.81 rows=1 width=833)
                    Join Filter: (transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9.parent_transaction_id = transactions_transaction_2.id)
                    ->  Nested Loop Left Join  (cost=596.97..151559.89 rows=1 width=784)
                          Join Filter: (transactions_transaction.schedule_d_id = transactions_scheduled.id)
                          ->  Nested Loop  (cost=596.97..151535.27 rows=1 width=768)
                                Join Filter: (transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9.transaction_ptr_id = transactions_transaction.id)
                                ->  Index Scan using transactions_transaction_schedule_d_id_08d80917 on transactions_transaction  (cost=0.15..91.03 rows=725 width=373)
                                ->  Materialize  (cost=596.82..151433.37 rows=1 width=395)
                                      ->  Subquery Scan on transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9  (cost=596.82..151433.36 rows=1 width=395)
                                            Filter: ((transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9.report_id = 'f871b1b2-166e-4a96-859c-8e225d51dc47'::uuid) AND (transaction_view__c94c5d1a_9e73_464d_ad72_b73b5d8667a9.schedule = 'A'::text))
                                            ->  WindowAgg  (cost=596.82..151422.49 rows=725 width=982)
                                                  ->  Sort  (cost=596.77..598.58 rows=725 width=681)
                                                        Sort Key: transactions_transaction_1.contact_1_id, (EXTRACT(year FROM COALESCE(transactions_schedulea.contribution_date, transactions_scheduleb.expenditure_date, transactions_schedulec.loan_incurred_date, transactions_schedulee.disbursement_date, transactions_schedulee.dissemination_date))), transactions_transaction_1.aggregation_group, (COALESCE(transactions_schedulea.contribution_date, transactions_scheduleb.expenditure_date, transactions_schedulec.loan_incurred_date, transactions_schedulee.disbursement_date, transactions_schedulee.dissemination_date)), transactions_transaction_1.created
                                                        ->  WindowAgg  (cost=499.79..562.32 rows=725 width=681)
                                                              ->  Sort  (cost=499.79..501.61 rows=725 width=649)
                                                                    Sort Key: transactions_schedulee.election_code, t15.candidate_office, t15.candidate_state, t15.candidate_district, (EXTRACT(year FROM COALESCE(transactions_schedulea.contribution_date, transactions_scheduleb.expenditure_date, transactions_schedulec.loan_incurred_date, transactions_schedulee.disbursement_date, transactions_schedulee.dissemination_date))), transactions_transaction_1.aggregation_group, (COALESCE(transactions_schedulea.contribution_date, transactions_scheduleb.expenditure_date, transactions_schedulec.loan_incurred_date, transactions_schedulee.disbursement_date, transactions_schedulee.dissemination_date)), transactions_transaction_1.created
                                                                    ->  WindowAgg  (cost=413.69..465.35 rows=725 width=649)
                                                                          ->  Sort  (cost=413.69..415.51 rows=725 width=617)
                                                                                Sort Key: transactions_transaction_1.debt_id, (CASE WHEN ((transactions_transaction_1.loan_id IS NOT NULL) AND (CASE WHEN (transactions_transaction_1.schedule_a_id IS NOT NULL) THEN 'A'::text WHEN (transactions_transaction_1.schedule_b_id IS NOT NULL) THEN 'B'::text WHEN (transactions_transaction_1.schedule_c_id IS NOT NULL) THEN 'C'::text WHEN (transactions_transaction_1.schedule_c1_id IS NOT NULL) THEN 'C2'::text WHEN (transactions_transaction_1.schedule_c2_id IS NOT NULL) THEN 'C1'::text WHEN (transactions_transaction_1.schedule_d_id IS NOT NULL) THEN 'D'::text WHEN (transactions_transaction_1.schedule_e_id IS NOT NULL) THEN 'E'::text ELSE NULL::text END = ANY ('{A,B,E}'::text[])) AND (transactions_transaction_1.transaction_type_identifier = ANY ('{''LOAN_REPAYMENT_RECEIVED'',''LOAN_REPAYMENT_MADE''}'::text[]))) THEN concat(t14.transaction_id, (COALESCE(transactions_schedulea.contribution_date, transactions_scheduleb.expenditure_date, transactions_schedulec.loan_incurred_date, transactions_schedulee.disbursement_date, transactions_schedulee.dissemination_date))::text) WHEN (transactions_transaction_1.schedule_c_id IS NOT NULL) THEN concat(transactions_transaction_1.transaction_id, (reports_report.coverage_from_date)::text) ELSE NULL::text END)
                                                                                ->  Hash Left Join  (cost=308.60..379.25 rows=725 width=617)
                                                                                      Hash Cond: (transactions_transaction_1.report_id = reports_report.id)
                                                                                      ->  Hash Left Join  (cost=307.49..357.40 rows=725 width=581)
                                                                                            Hash Cond: (transactions_transaction_1.contact_2_id = t15.id)
                                                                                            ->  Hash Left Join  (cost=295.01..343.02 rows=725 width=525)
                                                                                                  Hash Cond: (transactions_transaction_1.loan_id = t14.id)
                                                                                                  ->  Hash Left Join  (cost=260.70..306.81 rows=725 width=504)
                                                                                                        Hash Cond: (transactions_transaction_1.parent_transaction_id = t13.id)
                                                                                                        ->  Hash Left Join  (cost=226.39..270.59 rows=725 width=483)
                                                                                                              Hash Cond: (transactions_transaction_1.reatt_redes_id = t12.id)
                                                                                                              ->  Hash Left Join  (cost=192.08..234.38 rows=725 width=478)
                                                                                                                    Hash Cond: (t9.schedule_d_id = t10.id)
                                                                                                                    ->  Hash Left Join  (cost=167.45..207.85 rows=725 width=478)
                                                                                                                          Hash Cond: (transactions_transaction_1.debt_id = t9.id)
                                                                                                                          ->  Hash Left Join  (cost=133.14..171.63 rows=725 width=441)
                                                                                                                                Hash Cond: (transactions_transaction_1.schedule_e_id = transactions_schedulee.id)
                                                                                                                                ->  Hash Left Join  (cost=119.31..155.90 rows=725 width=385)
                                                                                                                                      Hash Cond: (transactions_transaction_1.schedule_d_id = transactions_scheduled_1.id)
                                                                                                                                      ->  Hash Left Join  (cost=94.69..129.38 rows=725 width=369)
                                                                                                                                            Hash Cond: (transactions_transaction_1.schedule_c2_id = transactions_schedulec2.id)
                                                                                                                                            ->  Hash Left Join  (cost=54.09..86.87 rows=725 width=353)
                                                                                                                                                  Hash Cond: (transactions_transaction_1.schedule_c_id = transactions_schedulec.id)
                                                                                                                                                  ->  Hash Left Join  (cost=37.11..67.99 rows=725 width=333)
                                                                                                                                                        Hash Cond: (transactions_transaction_1.schedule_b_id = transactions_scheduleb.id)
                                                                                                                                                        ->  Hash Left Join  (cost=23.29..52.27 rows=725 width=313)
                                                                                                                                                              Hash Cond: (transactions_transaction_1.schedule_a_id = transactions_schedulea.id)
                                                                                                                                                              ->  Seq Scan on transactions_transaction transactions_transaction_1  (cost=0.00..27.06 rows=725 width=304)
                                                                                                                                                                    Filter: ((deleted IS NULL) AND (committee_account_id = 'c94c5d1a-9e73-464d-ad72-b73b5d8667a9'::uuid))
                                                                                                                                                              ->  Hash  (cost=14.24..14.24 rows=724 width=25)
                                                                                                                                                                    ->  Seq Scan on transactions_schedulea  (cost=0.00..14.24 rows=724 width=25)
                                                                                                                                                        ->  Hash  (cost=11.70..11.70 rows=170 width=36)
                                                                                                                                                              ->  Seq Scan on transactions_scheduleb  (cost=0.00..11.70 rows=170 width=36)
                                                                                                                                                  ->  Hash  (cost=13.10..13.10 rows=310 width=36)
                                                                                                                                                        ->  Seq Scan on transactions_schedulec  (cost=0.00..13.10 rows=310 width=36)
                                                                                                                                            ->  Hash  (cost=23.60..23.60 rows=1360 width=32)
                                                                                                                                                  ->  Seq Scan on transactions_schedulec2  (cost=0.00..23.60 rows=1360 width=32)
                                                                                                                                      ->  Hash  (cost=16.50..16.50 rows=650 width=32)
                                                                                                                                            ->  Seq Scan on transactions_scheduled transactions_scheduled_1  (cost=0.00..16.50 rows=650 width=32)
                                                                                                                                ->  Hash  (cost=11.70..11.70 rows=170 width=72)
                                                                                                                                      ->  Seq Scan on transactions_schedulee  (cost=0.00..11.70 rows=170 width=72)
                                                                                                                          ->  Hash  (cost=25.25..25.25 rows=725 width=53)
                                                                                                                                ->  Seq Scan on transactions_transaction t9  (cost=0.00..25.25 rows=725 width=53)
                                                                                                                    ->  Hash  (cost=16.50..16.50 rows=650 width=32)
                                                                                                                          ->  Seq Scan on transactions_scheduled t10  (cost=0.00..16.50 rows=650 width=32)
                                                                                                              ->  Hash  (cost=25.25..25.25 rows=725 width=37)
                                                                                                                    ->  Seq Scan on transactions_transaction t12  (cost=0.00..25.25 rows=725 width=37)
                                                                                                        ->  Hash  (cost=25.25..25.25 rows=725 width=37)
                                                                                                              ->  Seq Scan on transactions_transaction t13  (cost=0.00..25.25 rows=725 width=37)
                                                                                                  ->  Hash  (cost=25.25..25.25 rows=725 width=37)
                                                                                                        ->  Seq Scan on transactions_transaction t14  (cost=0.00..25.25 rows=725 width=37)
                                                                                            ->  Hash  (cost=11.10..11.10 rows=110 width=88)
                                                                                                  ->  Seq Scan on contacts t15  (cost=0.00..11.10 rows=110 width=88)
                                                                                      ->  Hash  (cost=1.05..1.05 rows=5 width=20)
                                                                                            ->  Seq Scan on reports_report  (cost=0.00..1.05 rows=5 width=20)

@AureliaKhorsand
Copy link
Contributor

AureliaKhorsand commented May 24, 2024

Part 2 of 2 comments (split for Exalate sync):

SubPlan 1
                                                    ->  GroupAggregate  (cost=46.16..46.18 rows=1 width=48)
                                                          Group Key: u0.committee_account_id
                                                          ->  Sort  (cost=46.16..46.16 rows=1 width=32)
                                                                Sort Key: u0.committee_account_id
                                                                ->  Nested Loop Left Join  (cost=0.15..46.15 rows=1 width=32)
                                                                      ->  Nested Loop  (cost=0.00..29.96 rows=1 width=32)
                                                                            Join Filter: (u0.report_id = u2.id)
                                                                            ->  Seq Scan on transactions_transaction u0  (cost=0.00..28.88 rows=1 width=48)
                                                                                  Filter: ((deleted IS NULL) AND ((debt_id <> transactions_transaction_1.id) OR (debt_id IS NULL)) AND (transaction_id = transactions_transaction_1.transaction_id))
                                                                            ->  Seq Scan on reports_report u2  (cost=0.00..1.06 rows=2 width=16)
                                                                                  Filter: (coverage_through_date < reports_report.coverage_from_date)
                                                                      ->  Index Scan using transactions_scheduled_pkey on transactions_scheduled u4  (cost=0.15..8.17 rows=1 width=32)
                                                                            Index Cond: (id = u0.schedule_d_id)
                                                  SubPlan 2
                                                    ->  GroupAggregate  (cost=53.19..53.21 rows=1 width=48)
                                                          Group Key: u0_1.committee_account_id
                                                          ->  Sort  (cost=53.19..53.20 rows=1 width=117)
                                                                Sort Key: u0_1.committee_account_id
                                                                ->  Nested Loop Left Join  (cost=1.31..53.18 rows=1 width=117)
                                                                      ->  Nested Loop Left Join  (cost=1.17..52.88 rows=1 width=117)
                                                                            ->  Nested Loop Left Join  (cost=1.02..36.69 rows=1 width=117)
                                                                                  ->  Nested Loop Left Join  (cost=0.86..36.38 rows=1 width=117)
                                                                                        Filter: (COALESCE(u1.contribution_date, u2_1.expenditure_date, u3.loan_incurred_date, u4_1.disbursement_date, u4_1.dissemination_date) < reports_report.coverage_from_date)
                                                                                        ->  Nested Loop Left Join  (cost=0.72..36.15 rows=1 width=129)
                                                                                              ->  Nested Loop Left Join  (cost=0.57..35.84 rows=1 width=125)
                                                                                                    ->  Nested Loop Left Join  (cost=0.43..35.61 rows=1 width=121)
                                                                                                          ->  Nested Loop  (cost=0.15..35.24 rows=1 width=128)
                                                                                                                ->  Seq Scan on transactions_transaction u6  (cost=0.00..27.06 rows=1 width=32)
                                                                                                                      Filter: (transaction_id = transactions_transaction_1.transaction_id)
                                                                                                                ->  Index Scan using transactions_transaction_debt_id_840b64a9 on transactions_transaction u0_1  (cost=0.15..8.17 rows=1 width=128)
                                                                                                                      Index Cond: (debt_id = u6.id)
                                                                                                                      Filter: ((deleted IS NULL) AND (schedule_d_id IS NULL) AND ((debt_id <> transactions_transaction_1.id) OR (debt_id IS NULL)))
                                                                                                          ->  Index Scan using transactions_schedulea_pkey on transactions_schedulea u1  (cost=0.28..0.37 rows=1 width=25)
                                                                                                                Index Cond: (id = u0_1.schedule_a_id)
                                                                                                    ->  Index Scan using transactions_scheduleb_pkey on transactions_scheduleb u2_1  (cost=0.14..0.23 rows=1 width=36)
                                                                                                          Index Cond: (id = u0_1.schedule_b_id)
                                                                                              ->  Index Scan using transactions_schedulec_pkey on transactions_schedulec u3  (cost=0.15..0.23 rows=1 width=36)
                                                                                                    Index Cond: (id = u0_1.schedule_c_id)
                                                                                        ->  Index Scan using transactions_schedulee_pkey on transactions_schedulee u4_1  (cost=0.14..0.22 rows=1 width=40)
                                                                                              Index Cond: (id = u0_1.schedule_e_id)
                                                                                  ->  Index Scan using transactions_schedulec2_pkey on transactions_schedulec2 u5  (cost=0.15..0.23 rows=1 width=32)
                                                                                        Index Cond: (id = u0_1.schedule_c2_id)
                                                                            ->  Index Scan using transactions_scheduled_pkey on transactions_scheduled u7  (cost=0.15..8.17 rows=1 width=32)
                                                                                  Index Cond: (id = u6.schedule_d_id)
                                                                      ->  Index Scan using transactions_scheduled_pkey on transactions_scheduled u8  (cost=0.15..0.23 rows=1 width=32)
                                                                            Index Cond: (id = u0_1.schedule_d_id)
                                                  SubPlan 3
                                                    ->  GroupAggregate  (cost=108.25..108.28 rows=1 width=48)
                                                          Group Key: u0_2.committee_account_id
                                                          ->  Sort  (cost=108.25..108.26 rows=1 width=117)
                                                                Sort Key: u0_2.committee_account_id
                                                                ->  Hash Right Join  (cost=95.90..108.24 rows=1 width=117)
                                                                      Hash Cond: (u8_1.id = u0_2.schedule_e_id)
                                                                      ->  Seq Scan on transactions_schedulee u8_1  (cost=0.00..11.70 rows=170 width=32)
                                                                      ->  Hash  (cost=95.88..95.88 rows=1 width=117)
                                                                            ->  Nested Loop Left Join  (cost=9.33..95.88 rows=1 width=117)
                                                                                  ->  Nested Loop Left Join  (cost=9.18..79.70 rows=1 width=117)
                                                                                        ->  Nested Loop Left Join  (cost=9.03..63.51 rows=1 width=117)
                                                                                              ->  Nested Loop Left Join  (cost=8.88..55.25 rows=1 width=117)
                                                                                                    ->  Nested Loop Left Join  (cost=8.61..46.94 rows=1 width=128)
                                                                                                          ->  Nested Loop  (cost=8.46..30.76 rows=1 width=128)
                                                                                                                ->  Hash Right Join  (cost=8.18..22.45 rows=1 width=128)
                                                                                                                      Hash Cond: (u5_1.id = u0_2.schedule_c_id)
                                                                                                                      ->  Seq Scan on transactions_schedulec u5_1  (cost=0.00..13.10 rows=310 width=32)
                                                                                                                      ->  Hash  (cost=8.17..8.17 rows=1 width=128)
                                                                                                                            ->  Index Scan using transactions_transaction_debt_id_840b64a9 on transactions_transaction u0_2  (cost=0.15..8.17 rows=1 width=128)
                                                                                                                                  Index Cond: (debt_id = transactions_transaction_1.id)
                                                                                                                                  Filter: ((deleted IS NULL) AND (schedule_d_id IS NULL))
                                                                                                                ->  Index Scan using transactions_transaction_pkey on transactions_transaction u1_1  (cost=0.28..8.29 rows=1 width=32)
                                                                                                                      Index Cond: (id = transactions_transaction_1.id)
                                                                                                          ->  Index Scan using transactions_scheduled_pkey on transactions_scheduled u2_2  (cost=0.15..8.17 rows=1 width=32)
                                                                                                                Index Cond: (id = u0_2.schedule_d_id)
                                                                                                    ->  Index Scan using transactions_schedulea_pkey on transactions_schedulea u3_1  (cost=0.28..8.29 rows=1 width=21)
                                                                                                          Index Cond: (id = u0_2.schedule_a_id)
                                                                                              ->  Index Scan using transactions_scheduleb_pkey on transactions_scheduleb u4_2  (cost=0.14..8.16 rows=1 width=32)
                                                                                                    Index Cond: (id = u0_2.schedule_b_id)
                                                                                        ->  Index Scan using transactions_schedulec2_pkey on transactions_schedulec2 u6_1  (cost=0.15..8.17 rows=1 width=32)
                                                                                              Index Cond: (id = u0_2.schedule_c2_id)
                                                                                  ->  Index Scan using transactions_scheduled_pkey on transactions_scheduled u7_1  (cost=0.15..8.17 rows=1 width=32)
                                                                                        Index Cond: (id = u1_1.schedule_d_id)
                          ->  Seq Scan on transactions_scheduled  (cost=0.00..16.50 rows=650 width=32)
                    ->  WindowAgg  (cost=392.92..608.61 rows=725 width=1008)
                          ->  Sort  (cost=392.92..394.74 rows=725 width=568)
                                Sort Key: transactions_transaction_2.contact_1_id, (EXTRACT(year FROM COALESCE(transactions_schedulea_1.contribution_date, transactions_scheduleb_1.expenditure_date, transactions_schedulec_1.loan_incurred_date, transactions_schedulee_1.disbursement_date, transactions_schedulee_1.dissemination_date))), transactions_transaction_2.aggregation_group, (COALESCE(transactions_schedulea_1.contribution_date, transactions_scheduleb_1.expenditure_date, transactions_schedulec_1.loan_incurred_date, transactions_schedulee_1.disbursement_date, transactions_schedulee_1.dissemination_date)), transactions_transaction_2.created
                                ->  WindowAgg  (cost=325.91..358.48 rows=725 width=568)
                                      ->  Sort  (cost=325.86..327.67 rows=725 width=536)
                                            Sort Key: transactions_schedulee_1.election_code, t15_1.candidate_office, t15_1.candidate_state, t15_1.candidate_district, (EXTRACT(year FROM COALESCE(transactions_schedulea_1.contribution_date, transactions_scheduleb_1.expenditure_date, transactions_schedulec_1.loan_incurred_date, transactions_schedulee_1.disbursement_date, transactions_schedulee_1.dissemination_date))), transactions_transaction_2.aggregation_group, (COALESCE(transactions_schedulea_1.contribution_date, transactions_scheduleb_1.expenditure_date, transactions_schedulec_1.loan_incurred_date, transactions_schedulee_1.disbursement_date, transactions_schedulee_1.dissemination_date)), transactions_transaction_2.created
                                            ->  Hash Left Join  (cost=239.98..291.41 rows=725 width=536)
                                                  Hash Cond: (transactions_transaction_2.report_id = reports_report_1.id)
                                                  ->  Hash Left Join  (cost=238.86..284.97 rows=725 width=512)
                                                        Hash Cond: (transactions_transaction_2.contact_2_id = t15_1.id)
                                                        ->  Hash Left Join  (cost=226.39..270.59 rows=725 width=456)
                                                              Hash Cond: (transactions_transaction_2.loan_id = t14_1.id)
                                                              ->  Hash Left Join  (cost=192.08..234.38 rows=725 width=435)
                                                                    Hash Cond: (t9_1.schedule_d_id = t10_1.id)
                                                                    ->  Hash Left Join  (cost=167.45..207.85 rows=725 width=435)
                                                                          Hash Cond: (transactions_transaction_2.debt_id = t9_1.id)
                                                                          ->  Hash Left Join  (cost=133.14..171.63 rows=725 width=419)
                                                                                Hash Cond: (transactions_transaction_2.schedule_e_id = transactions_schedulee_1.id)
                                                                                ->  Hash Left Join  (cost=119.31..155.90 rows=725 width=363)
                                                                                      Hash Cond: (transactions_transaction_2.schedule_d_id = transactions_scheduled_2.id)
                                                                                      ->  Hash Left Join  (cost=94.69..129.38 rows=725 width=347)
                                                                                            Hash Cond: (transactions_transaction_2.schedule_c2_id = transactions_schedulec2_1.id)
                                                                                            ->  Hash Left Join  (cost=54.09..86.87 rows=725 width=331)
                                                                                                  Hash Cond: (transactions_transaction_2.schedule_c_id = transactions_schedulec_1.id)
                                                                                                  ->  Hash Left Join  (cost=37.11..67.99 rows=725 width=311)
                                                                                                        Hash Cond: (transactions_transaction_2.schedule_b_id = transactions_scheduleb_1.id)
                                                                                                        ->  Hash Left Join  (cost=23.29..52.27 rows=725 width=291)
                                                                                                              Hash Cond: (transactions_transaction_2.schedule_a_id = transactions_schedulea_1.id)
                                                                                                              ->  Seq Scan on transactions_transaction transactions_transaction_2  (cost=0.00..27.06 rows=725 width=298)
                                                                                                                    Filter: ((deleted IS NULL) AND (committee_account_id = 'c94c5d1a-9e73-464d-ad72-b73b5d8667a9'::uuid))
                                                                                                              ->  Hash  (cost=14.24..14.24 rows=724 width=25)
                                                                                                                    ->  Seq Scan on transactions_schedulea transactions_schedulea_1  (cost=0.00..14.24 rows=724 width=25)
                                                                                                        ->  Hash  (cost=11.70..11.70 rows=170 width=36)
                                                                                                              ->  Seq Scan on transactions_scheduleb transactions_scheduleb_1  (cost=0.00..11.70 rows=170 width=36)
                                                                                                  ->  Hash  (cost=13.10..13.10 rows=310 width=36)
                                                                                                        ->  Seq Scan on transactions_schedulec transactions_schedulec_1  (cost=0.00..13.10 rows=310 width=36)
                                                                                            ->  Hash  (cost=23.60..23.60 rows=1360 width=32)
                                                                                                  ->  Seq Scan on transactions_schedulec2 transactions_schedulec2_1  (cost=0.00..23.60 rows=1360 width=32)
                                                                                      ->  Hash  (cost=16.50..16.50 rows=650 width=32)
                                                                                            ->  Seq Scan on transactions_scheduled transactions_scheduled_2  (cost=0.00..16.50 rows=650 width=32)
                                                                                ->  Hash  (cost=11.70..11.70 rows=170 width=72)
                                                                                      ->  Seq Scan on transactions_schedulee transactions_schedulee_1  (cost=0.00..11.70 rows=170 width=72)
                                                                          ->  Hash  (cost=25.25..25.25 rows=725 width=32)
                                                                                ->  Seq Scan on transactions_transaction t9_1  (cost=0.00..25.25 rows=725 width=32)
                                                                    ->  Hash  (cost=16.50..16.50 rows=650 width=32)
                                                                          ->  Seq Scan on transactions_scheduled t10_1  (cost=0.00..16.50 rows=650 width=32)
                                                              ->  Hash  (cost=25.25..25.25 rows=725 width=37)
                                                                    ->  Seq Scan on transactions_transaction t14_1  (cost=0.00..25.25 rows=725 width=37)
                                                        ->  Hash  (cost=11.10..11.10 rows=110 width=88)
                                                              ->  Seq Scan on contacts t15_1  (cost=0.00..11.10 rows=110 width=88)
                                                  ->  Hash  (cost=1.05..1.05 rows=5 width=20)
                                                        ->  Seq Scan on reports_report reports_report_1  (cost=0.00..1.05 rows=5 width=20)
              ->  WindowAgg  (cost=325.86..519.79 rows=725 width=1008)
                    ->  Sort  (cost=325.86..327.67 rows=725 width=520)
                          Sort Key: transactions_transaction_3.contact_1_id, (EXTRACT(year FROM COALESCE(transactions_schedulea_2.contribution_date, transactions_scheduleb_2.expenditure_date, transactions_schedulec_2.loan_incurred_date, transactions_schedulee_2.disbursement_date, transactions_schedulee_2.dissemination_date))), transactions_transaction_3.aggregation_group, (COALESCE(transactions_schedulea_2.contribution_date, transactions_scheduleb_2.expenditure_date, transactions_schedulec_2.loan_incurred_date, transactions_schedulee_2.disbursement_date, transactions_schedulee_2.dissemination_date)), transactions_transaction_3.created
                          ->  Hash Left Join  (cost=239.98..291.41 rows=725 width=520)
                                Hash Cond: (transactions_transaction_3.report_id = reports_report_2.id)
                                ->  Hash Left Join  (cost=238.86..284.97 rows=725 width=496)
                                      Hash Cond: (transactions_transaction_3.contact_2_id = t15_2.id)
                                      ->  Hash Left Join  (cost=226.39..270.59 rows=725 width=440)
                                            Hash Cond: (transactions_transaction_3.loan_id = t14_2.id)
                                            ->  Hash Left Join  (cost=192.08..234.38 rows=725 width=419)
                                                  Hash Cond: (t9_2.schedule_d_id = t10_2.id)
                                                  ->  Hash Left Join  (cost=167.45..207.85 rows=725 width=419)
                                                        Hash Cond: (transactions_transaction_3.debt_id = t9_2.id)
                                                        ->  Hash Left Join  (cost=133.14..171.63 rows=725 width=403)
                                                              Hash Cond: (transactions_transaction_3.schedule_e_id = transactions_schedulee_2.id)
                                                              ->  Hash Left Join  (cost=119.31..155.90 rows=725 width=347)
                                                                    Hash Cond: (transactions_transaction_3.schedule_d_id = transactions_scheduled_3.id)
                                                                    ->  Hash Left Join  (cost=94.69..129.38 rows=725 width=331)
                                                                          Hash Cond: (transactions_transaction_3.schedule_c2_id = transactions_schedulec2_2.id)
                                                                          ->  Hash Left Join  (cost=54.09..86.87 rows=725 width=315)
                                                                                Hash Cond: (transactions_transaction_3.schedule_c_id = transactions_schedulec_2.id)
                                                                                ->  Hash Left Join  (cost=37.11..67.99 rows=725 width=295)
                                                                                      Hash Cond: (transactions_transaction_3.schedule_b_id = transactions_scheduleb_2.id)
                                                                                      ->  Hash Left Join  (cost=23.29..52.27 rows=725 width=275)
                                                                                            Hash Cond: (transactions_transaction_3.schedule_a_id = transactions_schedulea_2.id)
                                                                                            ->  Seq Scan on transactions_transaction transactions_transaction_3  (cost=0.00..27.06 rows=725 width=298)
                                                                                                  Filter: ((deleted IS NULL) AND (committee_account_id = 'c94c5d1a-9e73-464d-ad72-b73b5d8667a9'::uuid))
                                                                                            ->  Hash  (cost=14.24..14.24 rows=724 width=25)
                                                                                                  ->  Seq Scan on transactions_schedulea transactions_schedulea_2  (cost=0.00..14.24 rows=724 width=25)
                                                                                      ->  Hash  (cost=11.70..11.70 rows=170 width=36)
                                                                                            ->  Seq Scan on transactions_scheduleb transactions_scheduleb_2  (cost=0.00..11.70 rows=170 width=36)
                                                                                ->  Hash  (cost=13.10..13.10 rows=310 width=36)
                                                                                      ->  Seq Scan on transactions_schedulec transactions_schedulec_2  (cost=0.00..13.10 rows=310 width=36)
                                                                          ->  Hash  (cost=23.60..23.60 rows=1360 width=32)
                                                                                ->  Seq Scan on transactions_schedulec2 transactions_schedulec2_2  (cost=0.00..23.60 rows=1360 width=32)
                                                                    ->  Hash  (cost=16.50..16.50 rows=650 width=32)
                                                                          ->  Seq Scan on transactions_scheduled transactions_scheduled_3  (cost=0.00..16.50 rows=650 width=32)
                                                              ->  Hash  (cost=11.70..11.70 rows=170 width=72)
                                                                    ->  Seq Scan on transactions_schedulee transactions_schedulee_2  (cost=0.00..11.70 rows=170 width=72)
                                                        ->  Hash  (cost=25.25..25.25 rows=725 width=32)
                                                              ->  Seq Scan on transactions_transaction t9_2  (cost=0.00..25.25 rows=725 width=32)
                                                  ->  Hash  (cost=16.50..16.50 rows=650 width=32)
                                                        ->  Seq Scan on transactions_scheduled t10_2  (cost=0.00..16.50 rows=650 width=32)
                                            ->  Hash  (cost=25.25..25.25 rows=725 width=37)
                                                  ->  Seq Scan on transactions_transaction t14_2  (cost=0.00..25.25 rows=725 width=37)
                                      ->  Hash  (cost=11.10..11.10 rows=110 width=88)
                                            ->  Seq Scan on contacts t15_2  (cost=0.00..11.10 rows=110 width=88)
                                ->  Hash  (cost=1.05..1.05 rows=5 width=20)
                                      ->  Seq Scan on reports_report reports_report_2  (cost=0.00..1.05 rows=5 width=20)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants