Our build-daily-dbt-models workflow started failing this morning due to an obscure error resulting from the reporting.res_report_summary view:
Query exhausted resources at this scale factor.
I traced the error back to the calculation of the modal class code within the view. The mode calculation seems pretty inefficient since it has to ORDER BY many small groups multiple times. Swapping the count -> sort method for the one from this SO post fixes the error and has the same query time/data amount.
Our
build-daily-dbt-models
workflow started failing this morning due to an obscure error resulting from thereporting.res_report_summary
view:I traced the error back to the calculation of the modal class code within the view. The mode calculation seems pretty inefficient since it has to ORDER BY many small groups multiple times. Swapping the count -> sort method for the one from this SO post fixes the error and has the same query time/data amount.