Postgresql – Query Optimization for Large Dataset with Complex Join and Aggregation
Table A: (columns: id (integer), name (varchar), ...) Table B: (columns: id (integer), a_id (integer), value (numeric), ...) Table C: (columns: id (integer), a_id (integer), b_id (integer), date (date), ...) SELECT A.name, SUM(B.value) AS total_value, COUNT(DISTINCT C.date) AS distinct_dates FROM…