Sql Query Performing Poorly Nested Joins Lateral Join Postgresql

Sql Query Performing Poorly Nested Joins Lateral Join Postgresql